From a7ed30130d791fe810256546078f720372e21bef Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 25 Mar 2024 05:59:59 -0400 Subject: [PATCH] Value is set as items as used or damaged. Not calculated on the fly. --- src/engine/net/client/handlers/RepairMsgHandler.java | 5 +++++ .../net/client/handlers/VendorSellMsgHandler.java | 12 +----------- src/engine/objects/CharacterItemManager.java | 4 +++- src/engine/objects/Item.java | 4 +++- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/engine/net/client/handlers/RepairMsgHandler.java b/src/engine/net/client/handlers/RepairMsgHandler.java index 66bd860f..16db2b43 100644 --- a/src/engine/net/client/handlers/RepairMsgHandler.java +++ b/src/engine/net/client/handlers/RepairMsgHandler.java @@ -140,6 +140,11 @@ public class RepairMsgHandler extends AbstractClientMsgHandler { if (!DbManager.ItemQueries.SET_DURABILITY(toRepair, max)) return true; + toRepair.value = (int) (toRepair.template.item_value * (toRepair.combat_health_current / toRepair.template.combat_health_full)); + + if (!DbManager.ItemQueries.UPDATE_VALUE(toRepair, toRepair.value)) + return true; + //repair the item toRepair.setCombat_health_current(max); diff --git a/src/engine/net/client/handlers/VendorSellMsgHandler.java b/src/engine/net/client/handlers/VendorSellMsgHandler.java index bab117e3..6c9e5ebd 100644 --- a/src/engine/net/client/handlers/VendorSellMsgHandler.java +++ b/src/engine/net/client/handlers/VendorSellMsgHandler.java @@ -105,17 +105,7 @@ public class VendorSellMsgHandler extends AbstractClientMsgHandler { //get goldItem cost to sell - cost = sell.template.item_value; - - //apply damaged value reduction - float damagedModifier = sell.combat_health_current / sell.template.combat_health_full; - float chargeModifier = 1.0f; - - if (sell.chargesRemaining != 0) - chargeModifier = sell.chargesRemaining * 1.0f / sell.template.item_initial_charges; - - cost *= damagedModifier; - cost *= chargeModifier; + cost = sell.value; float bargain = player.getBargain(); float profit = npc.getBuyPercent(player) + bargain; diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index c72b83ca..0a46b40a 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -2358,7 +2358,9 @@ public class CharacterItemManager { if (!DbManager.ItemQueries.SET_DURABILITY(item, dur)) return; item.setCombat_health_current((short) dur); - + item.value = (int) (item.template.item_value * (item.combat_health_current / item.template.combat_health_full)); + if (!DbManager.ItemQueries.UPDATE_VALUE(item, item.value)) + return; } if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) == false) diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index bd4a2c86..91382174 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -52,7 +52,7 @@ public class Item extends AbstractWorldObject { public Enum.EquipSlotType equipSlot; private boolean canDestroy; private boolean isRandom = false; - private int value; + public int value; public OwnerType ownerType; public int templateID; private long dateToUpgrade; @@ -781,6 +781,8 @@ public class Item extends AbstractWorldObject { if (this.chargesRemaining < 0) this.chargesRemaining = 0; DbManager.ItemQueries.UPDATE_REMAINING_CHARGES(this); + this.value = this.value * (this.chargesRemaining / this.template.item_initial_charges); + DbManager.ItemQueries.UPDATE_VALUE(this, this.value); } public void zeroItem() {