Fixing bad quickslot behaviour where it would unequip things when the selection changed

This commit is contained in:
minjaesong
2020-03-09 04:01:03 +09:00
parent 8894be303a
commit 48b431f4b7
2 changed files with 11 additions and 6 deletions

View File

@@ -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)
}

View File

@@ -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)
}