Upgrading and also oops I did getting up wrong

This commit is contained in:
Bishop 2026-07-22 23:37:03 -05:00
parent af167f1431
commit 688442e7f0
5 changed files with 67 additions and 42 deletions

View file

@ -50,7 +50,7 @@ public final class BuildOptionPlugin extends OptionHandler {
player.getDialogueInterpreter().open("con:removedec", object);
return true;
}
player.setAttribute("con:hsobject", node);
setAttribute(player, ConstructionInterface.attributeHsObject, node);
if (BuildingUtils.isDoorHotspot(object)) {
int[] pos = BuildingUtils.roomExists(player, object);
if (pos != null) {
@ -83,8 +83,8 @@ public final class BuildOptionPlugin extends OptionHandler {
int dy = h.getCurrentY() - object.getLocation().getChunkOffsetY();
Scenery primaryObj = RegionManager.getObject(object.getLocation().transform(dx, dy, 0));
if (primaryObj != null) {
setAttribute(player, "con:hsobject", primaryObj);
setAttribute(player, "con:hotspot", h);
setAttribute(player, ConstructionInterface.attributeHsObject, primaryObj);
setAttribute(player, ConstructionInterface.attributeHotspot, h);
BuildingUtils.openBuildInterface(player, linked[0]);
}
return true;
@ -93,7 +93,7 @@ public final class BuildOptionPlugin extends OptionHandler {
return true;
}
player.setAttribute("con:hotspot", hotspot);
setAttribute(player, ConstructionInterface.attributeHotspot, hotspot);
BuildingUtils.openBuildInterface(player, hotspot.getHotspot());
return true;
}

View file

@ -18,6 +18,8 @@ import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import static core.api.ContentAPIKt.getAttribute;
/**
* Handles the building a room dialogue.
* @author Emperor
@ -105,7 +107,7 @@ public final class BuildRoomDialogue extends DialoguePlugin {
stage = 2;
return true;
}
this.door = (Scenery) player.getAttribute("con:hsobject");
this.door = (Scenery) getAttribute(player, ConstructionInterface.attributeHsObject, null);
int[] pos = BuildingUtils.getRoomPosition(player, door);
roomX = pos[0];
roomY = pos[1];

View file

@ -63,7 +63,7 @@ public final class BuildingUtils {
/**
* The removing a decoration animation.
*/
private static final Animation REMOVE_ANIMATION = Animation.create(3685);
public static final Animation REMOVE_ANIMATION = Animation.create(3685);
/**
* The plank item.

View file

@ -18,16 +18,19 @@ class ConstructionInterface : InterfaceListener {
companion object {
const val decorationInterface = 396
const val pohMenuInterface = 398
const val roomInterface = 402
const val pohMenuInterface = 398
const val roomInterface = 402
const val attributeHotspot = "con:hotspot"
const val attributeHsObject = "con:hsobject"
}
override fun defineInterfaceListeners() {
on(decorationInterface) { player, _, _, buttonID, slot, _ ->
when (buttonID) {
132 -> {
val hotspot = getAttribute<Hotspot?>(player, "con:hotspot", null)
val `object` = getAttribute<Scenery?>(player, "con:hsobject", null)
val hotspot = getAttribute<Hotspot?>(player, attributeHotspot, null)
val `object` = getAttribute<Scenery?>(player, attributeHsObject, null)
val flatpackMode = getAttribute(player, WorkbenchListeners.attributeFlatpackMode, false)
if (!flatpackMode) {
closeInterface(player)

View file

@ -1,9 +1,6 @@
package content.global.skill.construction.decoration.workshop
import content.global.skill.construction.BuildHotspot
import content.global.skill.construction.BuildingUtils
import content.global.skill.construction.ConstructionInterface
import content.global.skill.construction.Decoration
import content.global.skill.construction.*
import core.api.*
import core.game.interaction.IntType
import core.game.interaction.InteractionListener
@ -28,11 +25,11 @@ class WorkbenchListeners : InteractionListener, InterfaceListener {
companion object {
const val workbenchInterface = 397
const val attributeWorkbenchId = "con:workbench"
const val attributeFlatpackMode = "con:flatpack:active"
const val attributeSelection = "con:flatpack:hotspot"
const val attributeReturnDir = "con:flatpack:direction"
const val attributeSuccess = "con:flatpack:success"
const val attributeWorkbenchId = "con:workbench:id"
const val attributeFlatpackMode = "con:workbench:active"
const val attributeDirections = "con:workbench:directions"
const val attributeSelection = "con:workbench:hotspot"
const val attributeSitting = "con:workbench:sitting"
const val animationSitDown = 4103
const val animationStandUp = 4105
@ -73,36 +70,33 @@ class WorkbenchListeners : InteractionListener, InterfaceListener {
BuildHotspot.TOY_BOX, // 126
)
/**
* Returns the maximum construction level of decoration that can be built at a given workbench by id
*/
fun getBenchLevel(workbenchId: Int): Int {
return (workbenches.indexOf(workbenchId) + 1) * 20
}
fun produceFlatpack(player: Player, deco: Decoration) {
val reward = deco.flatpackItemID
val directions = getAttribute(player, attributeReturnDir, arrayOf(Direction.WEST, Direction.NORTH, Direction.EAST))
val animation = if (getScenery(player.location)?.id == Scenery.STOOL_13720) { animationCraftOak } else { animationCraft }
if (reward == -1) return
if (removeItemsIfPlayerHasEnough(player, *deco.items) || player.isAdmin) {
setAttribute(player, attributeSuccess, true)
closeInterface(player)
lock(player, Animation(animation).duration)
animate(player, animation)
rewardXP(player, Skills.CONSTRUCTION, deco.experience.toDouble())
addItemOrDrop(player, reward)
animate(player, animation)
lock(player, Animation(animation).duration + 1)
queueScript(player, Animation(animation).duration, QueueStrength.SOFT) {
forceMove(player, player.location, player.location.transform(directions[2], 1),
0, ticksToCycles(1), directions[1], animationStandUp)
return@queueScript stopExecuting(player)
}
}
}
private fun standUp(player: Player) {
val directions = getAttribute(player, attributeReturnDir, arrayOf(Direction.WEST, Direction.NORTH, Direction.EAST))
lock(player, 2)
queueScript(player, 1, QueueStrength.SOFT) {
val directions = getAttribute(player, attributeDirections, arrayOf(Direction.WEST, Direction.NORTH, Direction.EAST))
lock(player, animationStandUp)
queueScript(player, 0, QueueStrength.SOFT) {
forceMove(player, player.location, player.location.transform(directions[2], 1),
0, ticksToCycles(1), directions[1], animationStandUp)
0, ticksToCycles(1), directions[2], animationStandUp)
removeAttributes(player, attributeSitting, attributeDirections)
return@queueScript stopExecuting(player)
}
}
@ -110,6 +104,13 @@ class WorkbenchListeners : InteractionListener, InterfaceListener {
override fun defineListeners() {
on(workbenches, IntType.SCENERY, "work-at") { player, node ->
setAttribute(player, attributeWorkbenchId, node.id)
if (getAttribute(player, attributeSitting, false)) {
val animation = if (getScenery(player.location)?.id == Scenery.STOOL_13720) { animationSitOak } else { animationSit }
animate(player, animation)
openInterface(player, workbenchInterface)
return@on true
}
val baseX = node.location.x - node.location.chunkOffsetX
val baseY = node.location.y - node.location.chunkOffsetY
for (x in 3..4) {
@ -122,11 +123,11 @@ class WorkbenchListeners : InteractionListener, InterfaceListener {
Pair(4,3) -> arrayOf(Direction.SOUTH, Direction.WEST, Direction.NORTH)
else -> arrayOf(Direction.EAST, Direction.SOUTH, Direction.WEST)
}
setAttribute(player, attributeWorkbenchId, node.id)
setAttribute(player, attributeReturnDir, directions)
setAttribute(player, attributeDirections, directions)
forceMove(player, player.location, player.location.transform(directions[0], 1),
0, ticksToCycles(1), directions[1], animationSitDown) {
animate(player, if (obj.id == Scenery.STOOL_13720) animationSitOak else animationSit)
setAttribute(player, attributeSitting, true)
openInterface(player, workbenchInterface)
}
return@on true
@ -135,13 +136,36 @@ class WorkbenchListeners : InteractionListener, InterfaceListener {
}
return@on true
}
on(workbenches, IntType.SCENERY, "upgrade") { player, node ->
if (!inInventory(player, Items.OAK_PLANK_8778, 2) || !inInventory(player, Items.STEEL_BAR_2353)) {
sendDialogue(player, "You need two oak planks and a steel bar to upgrade this workbench.") // TODO: find authentic dialogue
return@on false
return@on true
}
if (removeItem(player, Item(Items.OAK_PLANK_8778, 2)) && removeItem(player, Items.STEEL_BAR_2353)) {
// TODO: upgrading
val hotspotSearchTile = node.location
// only the 2nd and 3rd best workbenches have upgrade options
val resultDeco = if (node.id == Scenery.WORKBENCH_13706) { // steel framed
Decoration.forObjectId(Scenery.WORKBENCH_13707) // with vice
} else {
Decoration.forObjectId(Scenery.WORKBENCH_13708) // with lathe
}
queueScript(player, 0, QueueStrength.SOFT) { stage ->
when (stage) {
0 -> {
lock(player, BuildingUtils.REMOVE_ANIMATION.duration + BuildingUtils.BUILD_MID_ANIM.duration)
BuildingUtils.removeDecoration(player, node as core.game.node.scenery.Scenery)
return@queueScript delayScript(player, BuildingUtils.REMOVE_ANIMATION.duration)
}
1 -> {
val hotspot = Hotspot(BuildHotspot.WORKBENCH, 3, 4, 4, 4)
val hotspotObj = getScenery(hotspotSearchTile)
BuildingUtils.buildDecoration(player, hotspot, resultDeco, hotspotObj)
return@queueScript delayScript(player, BuildingUtils.BUILD_MID_ANIM.duration)
}
else -> return@queueScript stopExecuting(player)
}
}
}
return@on true
}
@ -160,17 +184,13 @@ class WorkbenchListeners : InteractionListener, InterfaceListener {
onClose(workbenchInterface) { player, _ ->
if (!getAttribute(player, attributeFlatpackMode, false)) {
standUp(player)
removeAttributes(player, attributeFlatpackMode, attributeReturnDir, attributeSelection, attributeSuccess, attributeWorkbenchId)
removeAttributes(player, attributeFlatpackMode, attributeSelection, attributeWorkbenchId)
}
return@onClose true
}
onClose(ConstructionInterface.decorationInterface) { player, _ ->
if (getAttribute(player, attributeFlatpackMode, false) && !getAttribute(player, attributeSuccess, false)) {
standUp(player)
}
removeAttributes(player, attributeFlatpackMode, attributeReturnDir, attributeSelection, attributeSuccess, attributeWorkbenchId)
removeAttributes(player, attributeFlatpackMode, attributeSelection, attributeWorkbenchId)
return@onClose true
}
}