From 48b431f4b777241b4d61ab5021bf3b2ff29160f5 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Mon, 9 Mar 2020 04:01:03 +0900 Subject: [PATCH] Fixing bad quickslot behaviour where it would unequip things when the selection changed --- .../modulebasegame/gameactors/ActorInventory.kt | 6 ++++++ .../terrarum/modulebasegame/gameactors/Pocketed.kt | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt index 0323d7529..a9a8d57d5 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt @@ -122,6 +122,11 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c actor.unequipItem(existingItem.item) // depleted item; remove entry from inventory itemList.remove(existingItem) + + // also unequip on the quickslot + actor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let { + actor.inventory.setQuickBar(it, null) + } } } else { @@ -202,6 +207,7 @@ class ActorInventory(@Transient val actor: Pocketed, var maxCapacity: Int, var c add(newItem) itemEquipped[newItem.equipPosition] = newItem.dynamicID //invSearchByDynamicID(newItem.dynamicID)!!.item // will test if some sketchy code is written. Test fail: kotlinNullpointerException + // update quickslot designation as the item is being unpacked (e.g. using fresh new pickaxe) actor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let { setQuickBar(it, newItem.dynamicID) } diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/Pocketed.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/Pocketed.kt index cc4e8845d..c22d8ab86 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/Pocketed.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/Pocketed.kt @@ -1,6 +1,7 @@ package net.torvald.terrarum.modulebasegame.gameactors import net.torvald.terrarum.AppLoader +import net.torvald.terrarum.gameactors.ActorValue import net.torvald.terrarum.gameitem.GameItem import net.torvald.terrarum.itemproperties.ItemCodex import net.torvald.terrarum.gameitem.ItemID @@ -11,6 +12,7 @@ import net.torvald.terrarum.gameitem.ItemID interface Pocketed { var inventory: ActorInventory + val actorValue: ActorValue /** * Equips an item. If the item is not in the inventory, an error will be thrown. @@ -29,12 +31,9 @@ interface Pocketed { inventory.itemEquipped[item.equipPosition] = null - // remove it from the quickslot - inventory.quickSlot.forEachIndexed { index, itemID -> - if (itemID == item.dynamicID) { - inventory.setQuickBar(index, null) - } - } + // NOTE: DON'T TOUCH QUICKSLOT HERE + // Relevant Actorvalue is NOT being updated on time + // They're being safely handled by UIItemInventoryElem*.touchDown() and ActorInventory.remove item.effectOnUnequip(AppLoader.UPDATE_RATE) }