From f11fcc535aefff37a4e41e9af0abb00e4e0d67e0 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 3 Mar 2024 13:18:16 -0500 Subject: [PATCH] item_value refactored to template --- src/engine/net/client/msg/ManageNPCMsg.java | 7 ++++--- src/engine/objects/Item.java | 8 ++++---- src/engine/objects/ItemBase.java | 13 +------------ src/engine/objects/ItemFactory.java | 17 ++++++++--------- src/engine/objects/MobEquipment.java | 7 +++---- 5 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/engine/net/client/msg/ManageNPCMsg.java b/src/engine/net/client/msg/ManageNPCMsg.java index 62c1bf0e..475ec16a 100644 --- a/src/engine/net/client/msg/ManageNPCMsg.java +++ b/src/engine/net/client/msg/ManageNPCMsg.java @@ -423,10 +423,11 @@ public class ManageNPCMsg extends ClientNetMsg { for (int ib : rollableSet) { ItemBase item = ItemBase.getItemBase(ib); + ItemTemplate template = ItemTemplate.itemTemplates.get(ib); writer.put((byte) 1); writer.putInt(0); writer.putInt(ib); //itemID - writer.putInt(item.getBaseValue()); + writer.putInt(template.item_value); writer.putInt(600); writer.put((byte) 1); writer.put((byte) item.getModTable()); @@ -443,14 +444,14 @@ public class ManageNPCMsg extends ClientNetMsg { for (Item i : itemList) { ItemBase ib = i.getItemBase(); - + ItemTemplate template = ItemTemplate.itemTemplates.get(ib); writer.put((byte) 0); // ? Unknown45 writer.putInt(i.getObjectType().ordinal()); writer.putInt(i.getObjectUUID()); writer.putInt(0); writer.putInt(i.getTemplsteID()); - writer.putInt(ib.getBaseValue()); + writer.putInt(template.item_value); long timeLife = i.getDateToUpgrade() - System.currentTimeMillis(); diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index 8d0c3753..00c17479 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -234,7 +234,7 @@ public class Item extends AbstractWorldObject { } else writer.putInt(item.numberOfItems); // Amount of gold } else - writer.putInt(item.getItemBase().getBaseValue()); + writer.putInt(item.template.item_value); writer.putInt(item.getValue()); @@ -1049,7 +1049,7 @@ public class Item extends AbstractWorldObject { public final void loadEnchantments() { //dont load mobloot enchantments, they arent in db. if (this.getObjectType().equals(GameObjectType.MobLoot)) { - this.magicValue = this.getItemBase().getBaseValue() + calcMagicValue(); + this.magicValue = this.template.item_value + calcMagicValue(); return; } @@ -1063,7 +1063,7 @@ public class Item extends AbstractWorldObject { } } - this.magicValue = this.getItemBase().getBaseValue() + calcMagicValue(); + this.magicValue = this.template.item_value + calcMagicValue(); } public HashMap getBakedInStats() { @@ -1226,7 +1226,7 @@ public class Item extends AbstractWorldObject { public int getValue() { if (this.value == 0) - if (this.template.item_flags.contains(ItemFlags.Identified)) { + if (this.isID()) { return this.getMagicValue(); } else return this.template.item_value; diff --git a/src/engine/objects/ItemBase.java b/src/engine/objects/ItemBase.java index a949ec7a..1ed1f87e 100644 --- a/src/engine/objects/ItemBase.java +++ b/src/engine/objects/ItemBase.java @@ -45,7 +45,6 @@ public class ItemBase { public EnumSet requiredClasses; public EnumSet requiredDiscs; public EnumSet restrictedDiscs; - private final int value; private final short weight; private final short color; private final ItemType type; @@ -91,7 +90,6 @@ public class ItemBase { this.uuid = rs.getInt("ID"); - this.value = rs.getInt("value"); this.weight = rs.getShort("weight"); this.color = rs.getShort("color"); this.type = ItemType.valueOf(rs.getString("Type")); @@ -258,15 +256,6 @@ public class ItemBase { DbManager.ItemBaseQueries.LOAD_BAKEDINSTATS(this); } - //TODO fix this later. Shouldn't be gotten from item base - public int getMagicValue() { - return this.value; - } - - public int getBaseValue() { - return this.value; - } - public short getWeight() { return this.weight; } @@ -463,7 +452,7 @@ public class ItemBase { if (this.canCharacterEquip(abstractCharacter) == false) return false; - return item.getItemBase().value != 0 || Kit.IsNoobGear(item.getItemBase().uuid); + return item.template.item_value != 0 || Kit.IsNoobGear(item.getItemBase().uuid); //players can't wear 0 value items. } diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index be2cd3bf..d766d39a 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -124,9 +124,8 @@ public class ItemFactory { ConcurrentHashMap resources = cityWarehouse.resources; - int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, ib.getBaseValue()); - int overdraft = BuildingManager.GetOverdraft(forge, ib.getBaseValue()); - + int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, template.item_value); + int overdraft = BuildingManager.GetOverdraft(forge, template.item_value); if (overdraft > 0 && !useWarehouse) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + " " + template.item_base_name); @@ -308,7 +307,7 @@ public class ItemFactory { if (prefixValue == null) return null; - int baseCost = ib.getBaseValue(); + int baseCost = template.item_value; int effectCost = (int) prefixValue.getValue(); int total = baseCost * 10 + effectCost; @@ -361,7 +360,7 @@ public class ItemFactory { if (suffixValue == null) return null; suffixResourceCosts = suffix.getResourcesForEffect(); - int baseCost = ib.getBaseValue(); + int baseCost = template.item_value; int effectCost = (int) suffixValue.getValue(); suffixCost = effectCost; int total = baseCost * 10 + effectCost; @@ -405,7 +404,7 @@ public class ItemFactory { //Check if Total suffix and prefix costs + itemCost can be withdrawn. - int costToCreate = suffixCost + prefixCost + (ib.getBaseValue()); + int costToCreate = suffixCost + prefixCost + template.item_value; int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, costToCreate); int overdraft = BuildingManager.GetOverdraft(forge, costToCreate); @@ -510,7 +509,7 @@ public class ItemFactory { if (prefix == null && suffix == null) { - int baseCost = ib.getBaseValue(); + int baseCost = template.item_value; int total = (int) (baseCost + baseCost * (float) .10); buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, total); @@ -889,7 +888,7 @@ public class ItemFactory { ItemBase goldIB = ItemBase.getGoldItemBase(); - int baseCost = ib.getBaseValue(); + int baseCost = template.item_value; int total = (int) (baseCost + baseCost * .10); EffectsBase suffix = null; @@ -903,7 +902,7 @@ public class ItemFactory { //calculate gold costs and remove from the warehouse if (prefix != null || suffix != null) { - int costToCreate = (int) (ib.getBaseValue() + ib.getBaseValue() * .10f); + int costToCreate = (int) (template.item_value + template.item_value * .10f); int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, costToCreate); int overdraft = BuildingManager.GetOverdraft(forge, costToCreate); diff --git a/src/engine/objects/MobEquipment.java b/src/engine/objects/MobEquipment.java index 2e6ad892..9df3bff2 100644 --- a/src/engine/objects/MobEquipment.java +++ b/src/engine/objects/MobEquipment.java @@ -115,7 +115,6 @@ public class MobEquipment extends AbstractGameObject { public static void serializeForVendor(MobEquipment mobEquipment, ByteBufferWriter writer, float percent) throws SerializationException { _serializeForClientMsg(mobEquipment, writer, false); - int baseValue = mobEquipment.itemBase.getBaseValue() + mobEquipment.itemBase.getMagicValue(); writer.putInt(mobEquipment.magicValue); writer.putInt(mobEquipment.magicValue); } @@ -161,7 +160,7 @@ public class MobEquipment extends AbstractGameObject { writer.putInt(0); // Pad writer.putInt(0); // Pad - writer.putInt(mobEquipment.itemBase.getBaseValue()); + writer.putInt(mobEquipment.template.item_value); writer.putInt(mobEquipment.magicValue); serializeEffects(mobEquipment, writer); @@ -262,7 +261,7 @@ public class MobEquipment extends AbstractGameObject { public final void setMagicValue() { float value = 1; if (itemBase != null) - value = itemBase.getBaseValue(); + value = template.item_value; if (this.prefix != null) { if (this.prefix.getEffectsBase() != null) value += this.prefix.getEffectsBase().getValue(); @@ -300,7 +299,7 @@ public class MobEquipment extends AbstractGameObject { public int getMagicValue() { if (!this.isID) { - return itemBase.getBaseValue(); + return template.item_value; } return this.magicValue; }