diff --git a/src/net/torvald/terrarum/AmmoMeterProxy.kt b/src/net/torvald/terrarum/AmmoMeterProxy.kt index 2df044fc2..319ddae76 100644 --- a/src/net/torvald/terrarum/AmmoMeterProxy.kt +++ b/src/net/torvald/terrarum/AmmoMeterProxy.kt @@ -19,8 +19,10 @@ object AmmoMeterProxy { } else { meter.vitalGetterVal = { - if (ItemCodex[currentItem.originalID].stackable) + if (ItemCodex[currentItem.originalID].stackable) { + //println("[AmmoMeterProxy] currentItem: $currentItem") actor.inventory.getByDynamicID(currentItem.dynamicID)!!.amount.toFloat() + } else currentItem.durability } diff --git a/src/net/torvald/terrarum/UIItemInventoryElem.kt b/src/net/torvald/terrarum/UIItemInventoryElem.kt index c7e7644a1..21689bcab 100644 --- a/src/net/torvald/terrarum/UIItemInventoryElem.kt +++ b/src/net/torvald/terrarum/UIItemInventoryElem.kt @@ -93,8 +93,8 @@ class UIItemInventoryElem( // this one-liner sets color g.color = item!!.nameColour mul if (mouseUp) mouseOverTextCol else inactiveTextCol g.drawString( - "$item" + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") + - //item!!.name + (if (amount > 0 && !item!!.isUnique) "$fwsp($amount)" else "") + + //"$item" + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") + + item!!.name + (if (amount > 0 && item!!.stackable) "$fwsp($amount)" else if (amount != 1) "$fwsp!!$amount!!" else "") + (if (equippedSlot != null) " ${0xE081.toChar()}\$$equippedSlot" else ""), posX + textOffsetX, posY + textOffsetY diff --git a/src/net/torvald/terrarum/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/gameactors/ActorInventory.kt index f40e8c7d8..64b3d2905 100644 --- a/src/net/torvald/terrarum/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/gameactors/ActorInventory.kt @@ -61,22 +61,12 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode // if the item already exists if (existingItem != null) { - val newCount = getByDynamicID(item.dynamicID)!!.amount + count - itemList.remove(existingItem) - itemList.add(InventoryPair(existingItem.item, newCount)) + // increment count + existingItem.amount += count } // new item else { - /*if (item.isDynamic) { - // assign new ID for each - repeat(count) { - val newItem = item.clone().generateUniqueDynamicID(this) - itemList.add(InventoryPair(newItem, 1)) - } - } - else {*/ - itemList.add(InventoryPair(item, count)) - //} + itemList.add(InventoryPair(item, count)) } insertionSortLastElem(itemList) } @@ -98,15 +88,14 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode val existingItem = getByDynamicID(item.dynamicID) if (existingItem != null) { // if the item already exists - val newCount = getByDynamicID(item.dynamicID)!!.amount - count + val newCount = existingItem.amount - count + if (newCount < 0) { - throw Error("Tried to remove $count of $item, but the inventory only contains ${getByDynamicID(item.dynamicID)!!.amount} of them.") + throw Error("Tried to remove $count of $item, but the inventory only contains ${existingItem.amount} of them.") } else if (newCount > 0) { // decrement count - val newCount = getByDynamicID(item.dynamicID)!!.amount - count - itemList.remove(existingItem) - itemList.add(InventoryPair(existingItem.item, newCount)) + existingItem.amount = newCount } else { // unequip, if applicable @@ -281,4 +270,4 @@ class ActorInventory(val actor: Pocketed, var maxCapacity: Int, var capacityMode } } -data class InventoryPair(val item: InventoryItem, val amount: Int) \ No newline at end of file +data class InventoryPair(val item: InventoryItem, var amount: Int) \ No newline at end of file