From 49c595319baf6465acc3d8299f57d0f3aaa91fa8 Mon Sep 17 00:00:00 2001 From: minjaesong Date: Sun, 11 Feb 2024 22:59:06 +0900 Subject: [PATCH] autoequip consumable tool --- assets/mods/musicplayer/metadata.properties | 2 +- .../modulebasegame/gameactors/ActorInventory.kt | 16 +++++++++++++++- .../terrarum/ui/UIItemInventoryElemWide.kt | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/assets/mods/musicplayer/metadata.properties b/assets/mods/musicplayer/metadata.properties index 4d48e7610..e8b133632 100644 --- a/assets/mods/musicplayer/metadata.properties +++ b/assets/mods/musicplayer/metadata.properties @@ -6,5 +6,5 @@ entrypoint=net.torvald.terrarum.musicplayer.EntryPoint releasedate=2024-02-10 version=1.0.0 jar=MusicPlayer.jar -jarhash=bd958d6d17b599a88fa34948a2d93ef47256d79f4556f558b2a3330c3c6cccff +jarhash=8e0220165a235b16f99bc93d40135a92f126a574f2ab306520fc811ebbddb85d dependency=basegame 0.4.0 diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt index d6dde8619..df6092a60 100644 --- a/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt +++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ActorInventory.kt @@ -127,9 +127,23 @@ class ActorInventory() : FixtureInventory() { // damage the item newItem.durability -= (baseDamagePerSwing * swingDmgToFrameDmg).toFloat() - if (newItem.durability <= 0) + if (newItem.durability <= 0) { remove(newItem, 1) + // auto pull the same item if the player has one + (actor as Pocketed).inventory.let { inv -> + inv.itemList.filter { ItemCodex[it.itm]?.originalID == newItem.originalID }.firstOrNull()?.let { (itm, qty) -> + println("AutoEquip item $itm") + + actor.equipItem(itm) + // also unequip on the quickslot + actor.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)?.let { + setQuickslotItem(it, itm) + } + } + } + } + //println("[ActorInventory] consumed; ${item.durability}") } } diff --git a/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt b/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt index 028783ecf..dca68029f 100644 --- a/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt +++ b/src/net/torvald/terrarum/ui/UIItemInventoryElemWide.kt @@ -114,7 +114,7 @@ class UIItemInventoryElemWide( batch.color = nameColour val hasSecondaryName = (item?.nameSecondary?.isNotBlank() == true) - val itemNameRow1Y = if (hasSecondaryName) 1f else if (item!!.maxDurability > 0.0) textOffsetY else ((height - App.fontGame.lineHeight) / 2).roundToFloat() + val itemNameRow1Y = if (hasSecondaryName) 1f else if (/*item!!.isCurrentlyDynamic &&*/ item!!.maxDurability > 0.0) textOffsetY else ((height - App.fontGame.lineHeight) / 2).roundToFloat() val itemNameRow2Y = App.fontGame.lineHeight.toInt() - 2*itemNameRow1Y // draw name of the item @@ -136,7 +136,7 @@ class UIItemInventoryElemWide( val percentage = if (item!!.maxDurability < 0.00001f) 0f else item!!.durability / item!!.maxDurability val durabilityCol = UIItemInventoryCellCommonRes.getHealthMeterColour(percentage, 0f, 1f) val durabilityBack = durabilityCol mul UIItemInventoryCellCommonRes.meterBackDarkening - if (item!!.maxDurability > 0.0) { + if (/*item!!.isCurrentlyDynamic &&*/ item!!.maxDurability > 0.0) { // it's more helpful for newly created tools to have durability meter batch.color = durabilityBack Toolkit.drawStraightLine(batch, barOffset, posY + durabilityBarOffY, barOffset + barFullLen, durabilityBarThickness, false) batch.color = durabilityCol