From d9775dbf4e9f9a23b58137bd53e44ee6ee1b484c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 28 Feb 2024 16:31:09 -0500 Subject: [PATCH] Refactor itembase.name to template. --- .../devcmd/cmds/AuditFailedItemsCmd.java | 3 +- src/engine/devcmd/cmds/InfoCmd.java | 3 +- src/engine/devcmd/cmds/PrintBankCmd.java | 3 +- src/engine/devcmd/cmds/PrintBonusesCmd.java | 3 +- src/engine/devcmd/cmds/PrintEquipCmd.java | 9 +- src/engine/devcmd/cmds/PrintInventoryCmd.java | 3 +- src/engine/devcmd/cmds/PrintVaultCmd.java | 3 +- src/engine/devcmd/cmds/SimulateBootyCmd.java | 3 +- src/engine/gameManager/BuildingManager.java | 7 +- src/engine/gameManager/ChatManager.java | 3 +- src/engine/gameManager/LootManager.java | 10 +- src/engine/objects/City.java | 6 +- src/engine/objects/Item.java | 11 +- src/engine/objects/ItemBase.java | 4 +- src/engine/objects/ItemFactory.java | 111 +++++++++--------- src/engine/objects/MobEquipment.java | 6 +- src/engine/objects/Warehouse.java | 33 ++++-- 17 files changed, 131 insertions(+), 90 deletions(-) diff --git a/src/engine/devcmd/cmds/AuditFailedItemsCmd.java b/src/engine/devcmd/cmds/AuditFailedItemsCmd.java index e92e0b87..67b0a2e8 100644 --- a/src/engine/devcmd/cmds/AuditFailedItemsCmd.java +++ b/src/engine/devcmd/cmds/AuditFailedItemsCmd.java @@ -65,9 +65,10 @@ public class AuditFailedItemsCmd extends AbstractDevCmd { playerName = roller.getName(); ItemBase ib = ItemBase.getItemBase(failedItem.getItemBaseID()); + ItemTemplate template = ItemTemplate.itemTemplates.get(failedItem.getItemBaseID()); if (ib != null) { - itemName = ib.getName(); + itemName = template.item_base_name; } if (failedItem.isRandom() == false) { diff --git a/src/engine/devcmd/cmds/InfoCmd.java b/src/engine/devcmd/cmds/InfoCmd.java index de86ac66..75963a1f 100644 --- a/src/engine/devcmd/cmds/InfoCmd.java +++ b/src/engine/devcmd/cmds/InfoCmd.java @@ -506,6 +506,7 @@ public class InfoCmd extends AbstractDevCmd { case MobLoot: Item item = (Item) target; ItemBase itemBase = item.getItemBase(); + ItemTemplate template = ItemTemplate.itemTemplates.get(item.getItemBaseID()); output += StringUtils.addWS("ItemBase: " + itemBase.getUUID(), 20); output += "Weight: " + itemBase.getWeight(); output += newline; @@ -515,7 +516,7 @@ public class InfoCmd extends AbstractDevCmd { output += "Charges: " + item.getChargesRemaining() + '/' + item.getChargesMax(); output += newline; - output += "Name: " + itemBase.getName(); + output += "Name: " + template.item_base_name; output += newline; output += item.getContainerInfo(); diff --git a/src/engine/devcmd/cmds/PrintBankCmd.java b/src/engine/devcmd/cmds/PrintBankCmd.java index 7074af52..09b793fb 100644 --- a/src/engine/devcmd/cmds/PrintBankCmd.java +++ b/src/engine/devcmd/cmds/PrintBankCmd.java @@ -51,7 +51,8 @@ public class PrintBankCmd extends AbstractDevCmd { ArrayList list = cim.getBank(); throwbackInfo(pc, "Bank for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); for (Item item : list) { - throwbackInfo(pc, " " + item.getItemBase().getName() + ", count: " + item.getNumOfItems()); + ItemTemplate template = ItemTemplate.itemTemplates.get(item.getItemBaseID()); + throwbackInfo(pc, " " + template.item_base_name + ", count: " + item.getNumOfItems()); } Item gold = cim.getGoldBank(); if (gold != null) diff --git a/src/engine/devcmd/cmds/PrintBonusesCmd.java b/src/engine/devcmd/cmds/PrintBonusesCmd.java index e642b712..d21c0853 100644 --- a/src/engine/devcmd/cmds/PrintBonusesCmd.java +++ b/src/engine/devcmd/cmds/PrintBonusesCmd.java @@ -33,7 +33,8 @@ public class PrintBonusesCmd extends AbstractDevCmd { if (target instanceof Item) { type = "Item"; tar = (Item) target; - name = ((Item) tar).getItemBase().getName(); + ItemTemplate template = ItemTemplate.itemTemplates.get(((Item) tar).getItemBaseID()); + name = template.item_base_name; } else if (target instanceof AbstractCharacter) { tar = (AbstractCharacter) target; name = ((AbstractCharacter) tar).getFirstName(); diff --git a/src/engine/devcmd/cmds/PrintEquipCmd.java b/src/engine/devcmd/cmds/PrintEquipCmd.java index 2bf192fe..c5b8ab27 100644 --- a/src/engine/devcmd/cmds/PrintEquipCmd.java +++ b/src/engine/devcmd/cmds/PrintEquipCmd.java @@ -65,7 +65,8 @@ public class PrintEquipCmd extends AbstractDevCmd { throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); for (int slot : tarMob.getEquip().keySet()) { MobEquipment equip = tarMob.getEquip().get(slot); - throwbackInfo(pc, equip.getItemBase().getUUID() + " : " + equip.getItemBase().getName() + ", slot: " + slot); + ItemTemplate template = ItemTemplate.itemTemplates.get(equip.getItemBase().getUUID()); + throwbackInfo(pc, equip.getItemBase().getUUID() + " : " + template.item_base_name + ", slot: " + slot); } return; } @@ -75,7 +76,8 @@ public class PrintEquipCmd extends AbstractDevCmd { throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); for (int slot : tarMob.getEquip().keySet()) { MobEquipment equip = tarMob.getEquip().get(slot); - throwbackInfo(pc, equip.getItemBase().getUUID() + " : " + equip.getItemBase().getName() + ", slot: " + slot); + ItemTemplate template = ItemTemplate.itemTemplates.get(equip.getItemBase().getUUID()); + throwbackInfo(pc, equip.getItemBase().getUUID() + " : " + template.item_base_name + ", slot: " + slot); } return; } @@ -85,7 +87,8 @@ public class PrintEquipCmd extends AbstractDevCmd { throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); for (Integer slot : list.keySet()) { Item item = list.get(slot); - throwbackInfo(pc, " " + item.getItemBase().getName() + ", slot: " + slot); + ItemTemplate template = ItemTemplate.itemTemplates.get(item.getItemBaseID()); + throwbackInfo(pc, " " + template.item_base_name + ", slot: " + slot); } } diff --git a/src/engine/devcmd/cmds/PrintInventoryCmd.java b/src/engine/devcmd/cmds/PrintInventoryCmd.java index 5535f22e..be5d70e1 100644 --- a/src/engine/devcmd/cmds/PrintInventoryCmd.java +++ b/src/engine/devcmd/cmds/PrintInventoryCmd.java @@ -82,7 +82,8 @@ public class PrintInventoryCmd extends AbstractDevCmd { byte charges = item.getChargesRemaining(); chargeInfo = " charges: " + charges + '/' + chargeMax; } - throwbackInfo(pc, " " + item.getItemBase().getName() + ", count: " + item.getNumOfItems() + chargeInfo); + ItemTemplate template = ItemTemplate.itemTemplates.get(item.getItemBaseID()); + throwbackInfo(pc, " " + template.item_base_name + ", count: " + item.getNumOfItems() + chargeInfo); } else goldCount += item.getNumOfItems(); } diff --git a/src/engine/devcmd/cmds/PrintVaultCmd.java b/src/engine/devcmd/cmds/PrintVaultCmd.java index b949f18d..40338799 100644 --- a/src/engine/devcmd/cmds/PrintVaultCmd.java +++ b/src/engine/devcmd/cmds/PrintVaultCmd.java @@ -50,7 +50,8 @@ public class PrintVaultCmd extends AbstractDevCmd { ArrayList list = cim.getVault(); throwbackInfo(pc, "Vault for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')'); for (Item item : list) { - throwbackInfo(pc, " " + item.getItemBase().getName() + ", count: " + item.getNumOfItems()); + ItemTemplate template = ItemTemplate.itemTemplates.get(item.getItemBaseID()); + throwbackInfo(pc, " " + template.item_base_name + ", count: " + item.getNumOfItems()); } Item gold = cim.getGoldVault(); if (gold != null) diff --git a/src/engine/devcmd/cmds/SimulateBootyCmd.java b/src/engine/devcmd/cmds/SimulateBootyCmd.java index f6ef0bb0..bf796b88 100644 --- a/src/engine/devcmd/cmds/SimulateBootyCmd.java +++ b/src/engine/devcmd/cmds/SimulateBootyCmd.java @@ -35,7 +35,8 @@ public class SimulateBootyCmd extends AbstractDevCmd { for (BootySetEntry entry : LootManager._bootySetMap.get(mob.bootySet)) { ItemBase item = ItemBase.getItemBase(entry.itemBase); if (item != null) { - output += "[" + entry.bootyType + "] " + item.getName() + " [Chance] " + entry.dropChance + newline; + ItemTemplate template = ItemTemplate.itemTemplates.get(entry.itemBase); + output += "[" + entry.bootyType + "] " + template.item_base_name + " [Chance] " + entry.dropChance + newline; } } } diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index f3733a62..53ff29bf 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -242,8 +242,11 @@ public enum BuildingManager { if (resourceAmount <= 0) continue; - if (Warehouse.loot(warehouse, player, resourceBase, resourceAmount, true)) - ChatManager.chatInfoInfo(player, "You have looted " + resourceAmount + ' ' + resourceBase.getName()); + if (Warehouse.loot(warehouse, player, resourceBase, resourceAmount, true)) { + ItemTemplate template = ItemTemplate.itemTemplates.get(resourceBase.getUUID()); + ChatManager.chatInfoInfo(player, "You have looted " + resourceAmount + ' ' + template.item_base_name); + } + } break; diff --git a/src/engine/gameManager/ChatManager.java b/src/engine/gameManager/ChatManager.java index 243cd9c6..16773a1b 100644 --- a/src/engine/gameManager/ChatManager.java +++ b/src/engine/gameManager/ChatManager.java @@ -612,7 +612,8 @@ public enum ChatManager { name = amount + " gold "; else { String vowels = "aeiou"; - String iName = item.getItemBase().getName(); + ItemTemplate template = ItemTemplate.itemTemplates.get(item.getItemBaseID()); + String iName = template.item_base_name; if (iName.length() > 0) if (vowels.indexOf(iName.substring(0, 1).toLowerCase()) >= 0) name = "an " + iName + ' '; diff --git a/src/engine/gameManager/LootManager.java b/src/engine/gameManager/LootManager.java index 16409aaf..e8e7256c 100644 --- a/src/engine/gameManager/LootManager.java +++ b/src/engine/gameManager/LootManager.java @@ -83,10 +83,14 @@ public enum LootManager { for (Item it : mob.getInventory()) { ItemBase ib = it.getItemBase(); - if(ib == null) + + if (ib == null) break; - if (ib.isDiscRune() || ib.getName().toLowerCase().contains("of the gods")) { - ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().zoneName + " has found the " + ib.getName() + ". Are you tough enough to take it?"); + + ItemTemplate template = ItemTemplate.itemTemplates.get(it.getItemBaseID()); + + if (ib.isDiscRune() || template.item_base_name.toLowerCase().contains("of the gods")) { + ChatSystemMsg chatMsg = new ChatSystemMsg(null, mob.getName() + " in " + mob.getParentZone().zoneName + " has found the " + template.item_base_name + ". Are you tough enough to take it?"); chatMsg.setMessageType(10); chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID()); DispatchMessage.dispatchMsgToAll(chatMsg); diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index d51c176f..139e5eb0 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -1381,10 +1381,14 @@ public class City extends AbstractWorldObject { for (Integer itemBaseID : resources) { ItemBase ib = ItemBase.getItemBase(itemBaseID); + if (ib == null) continue; + + ItemTemplate template = ItemTemplate.itemTemplates.get(itemBaseID); + if (Warehouse.isAboveCap(ruledWarehouse, ib, (int) (city.getWarehouse().resources.get(ib) * taxPercent))) { - ErrorPopupMsg.sendErrorMsg(player, "You're warehouse has enough " + ib.getName() + " already!"); + ErrorPopupMsg.sendErrorMsg(player, "You're warehouse has enough " + template.item_base_name + " already!"); return true; } diff --git a/src/engine/objects/Item.java b/src/engine/objects/Item.java index cc74c165..fd9bfc0b 100644 --- a/src/engine/objects/Item.java +++ b/src/engine/objects/Item.java @@ -1212,10 +1212,13 @@ public class Item extends AbstractWorldObject { @Override public String getName() { - if (this.customName.isEmpty()) - if (this.getItemBase() != null) - return this.getItemBase().getName(); - return this.customName; + + if (this.customName.isEmpty() == false) + return this.customName; + + ItemTemplate template = ItemTemplate.itemTemplates.get(this.getItemBaseID()); + return template.item_base_name; + } public void setName(String name) { diff --git a/src/engine/objects/ItemBase.java b/src/engine/objects/ItemBase.java index 220416b3..08f505f0 100644 --- a/src/engine/objects/ItemBase.java +++ b/src/engine/objects/ItemBase.java @@ -37,7 +37,7 @@ public class ItemBase { private static final HashMap _IDsByNames = new HashMap<>(); private static final ArrayList _resourceList = new ArrayList<>(); private final int uuid; - private final String name; + private String name; //requirements/restrictions public EnumSet restrictedRaces; public EnumSet requiredRaces; @@ -91,7 +91,7 @@ public class ItemBase { public ItemBase(ResultSet rs) throws SQLException { this.uuid = rs.getInt("ID"); - this.name = rs.getString("name"); + this.durability = rs.getInt("durability"); this.value = rs.getInt("value"); this.weight = rs.getShort("weight"); diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index 98461de6..343be310 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -83,6 +83,7 @@ public class ItemFactory { boolean useWarehouse = false; ItemBase ib = ItemBase.getItemBase(itemID); + ItemTemplate template = ItemTemplate.itemTemplates.get(itemID); if (ib == null) return null; @@ -127,19 +128,19 @@ public class ItemFactory { if (overdraft > 0 && !useWarehouse) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + " " + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + " " + template.item_base_name); return null; } if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + " " + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + " " + template.item_base_name); return null; } if (overdraft > resources.get(ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + " " + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + " " + template.item_base_name); return null; } @@ -156,11 +157,11 @@ public class ItemFactory { overdraft += buildingWithdraw; if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); return null; } else { if (overdraft > resources.get(ItemBase.GOLD_ITEM_BASE)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); return null; } } @@ -169,7 +170,7 @@ public class ItemFactory { if (overdraft > 0) if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName()); + Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); return null; } @@ -257,7 +258,7 @@ public class ItemFactory { if (galvorAmount > 0 || wormwoodAmount > 0) if (!useWarehouse) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "This item requires resources to roll! Please make sure the forge is protected to access the warehouse." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "This item requires resources to roll! Please make sure the forge is protected to access the warehouse." + template.item_base_name); return null; } @@ -265,13 +266,13 @@ public class ItemFactory { if (galvorAmount > 0) { if (Warehouse.isResourceLocked(cityWarehouse, galvor)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + template.item_base_name); return null; } if (cityWarehouse.resources.get(galvor) < galvorAmount) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + template.item_base_name); return null; } } @@ -279,13 +280,13 @@ public class ItemFactory { if (wormwoodAmount > 0) { if (Warehouse.isResourceLocked(cityWarehouse, wormwood)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Wormwood is locked." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Wormwood is locked." + template.item_base_name); return null; } if (cityWarehouse.resources.get(wormwood) < wormwoodAmount) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Wormwood in warehouse to roll this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Wormwood in warehouse to roll this item." + template.item_base_name); return null; } } @@ -296,7 +297,7 @@ public class ItemFactory { if (!useWarehouse) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Forge cannot access warehouse! Check to make sure forge is protected." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Forge cannot access warehouse! Check to make sure forge is protected." + template.item_base_name); return null; } prefix = PowersManager.getEffectByToken(pToken); @@ -316,19 +317,19 @@ public class ItemFactory { if (overdraft > 0 && !useWarehouse) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); return null; } if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } if (overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); return null; } prefixResourceCosts = prefix.getResourcesForEffect(); @@ -349,7 +350,7 @@ public class ItemFactory { if (!useWarehouse) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Forge cannot access warehouse! Check to make sure forge is protected." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Forge cannot access warehouse! Check to make sure forge is protected." + template.item_base_name); return null; } suffix = PowersManager.getEffectByToken(sToken); @@ -370,19 +371,19 @@ public class ItemFactory { if (overdraft > 0 && !useWarehouse) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); return null; } if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } if (overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); return null; } @@ -410,19 +411,19 @@ public class ItemFactory { if (overdraft > 0 && !useWarehouse) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); return null; } if (overdraft > 0 && useWarehouse && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } if (useWarehouse && overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); return null; } @@ -437,11 +438,11 @@ public class ItemFactory { overdraft += buildingWithdraw; if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); return null; } else { if (overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); return null; } } @@ -450,7 +451,7 @@ public class ItemFactory { if (overdraft > 0 && useWarehouse) if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName()); + Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); return null; } @@ -458,7 +459,7 @@ public class ItemFactory { if (prefix != null) { if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Cannot Resource Roll without access to the warehouse! Make sure the forge is currently protected." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Cannot Resource Roll without access to the warehouse! Make sure the forge is currently protected." + template.item_base_name); return null; } @@ -478,7 +479,7 @@ public class ItemFactory { if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName()); + Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); return null; } } @@ -490,7 +491,7 @@ public class ItemFactory { int creationAmount = suffixResourceCosts.get(ibResources); if (Warehouse.isResourceLocked(cityWarehouse, ibResources) == true) { - ChatManager.chatSystemError(pc, ibResources.getName() + " is locked!" + ib.getName()); + ChatManager.chatSystemError(pc, ibResources.getName() + " is locked!" + template.item_base_name); return null; } @@ -500,7 +501,7 @@ public class ItemFactory { amount = oldAmount; if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName()); + Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); return null; } } @@ -518,21 +519,21 @@ public class ItemFactory { if (overdraft > 0 && !useWarehouse) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); return null; } if (overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } if (useWarehouse && overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); return null; } } @@ -541,11 +542,11 @@ public class ItemFactory { overdraft += buildingWithdraw; if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); return null; } else { if (overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); return null; } } @@ -554,7 +555,7 @@ public class ItemFactory { if (overdraft > 0) if (!Warehouse.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName()); + Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); return null; } @@ -562,7 +563,7 @@ public class ItemFactory { if (galvorAmount > 0) { if (!Warehouse.withdraw(cityWarehouse, npc, galvor, galvorAmount, true)) { - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + template.item_base_name); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } @@ -570,7 +571,7 @@ public class ItemFactory { if (wormwoodAmount > 0) { if (!Warehouse.withdraw(cityWarehouse, npc, wormwood, wormwoodAmount, true)) { - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse!" + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse!" + template.item_base_name); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } @@ -657,6 +658,7 @@ public class ItemFactory { ModTableEntry suffixEntry = null; ItemBase ib = ItemBase.getItemBase(itemBaseID); + ItemTemplate template = ItemTemplate.itemTemplates.get(itemBaseID); if (ib == null) return null; @@ -689,7 +691,7 @@ public class ItemFactory { } if (prefixMod == 0 && suffixMod == 0) { - Logger.info("Failed to find modTables for item " + ib.getName()); + Logger.info("Failed to find modTables for item " + template.item_base_name); return null; } @@ -782,6 +784,7 @@ public class ItemFactory { return null; ItemBase ib = ItemBase.getItemBase(itemID); + ItemTemplate template = ItemTemplate.itemTemplates.get(itemID); if (ib == null) return null; @@ -853,24 +856,24 @@ public class ItemFactory { if (galvorAmount > 0) { if (Warehouse.isResourceLocked(cityWarehouse, galvor)) { - ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + template.item_base_name); return null; } if (cityWarehouse.resources.get(galvor) < galvorAmount) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + template.item_base_name); return null; } } if (wormwoodAmount > 0) { if (Warehouse.isResourceLocked(cityWarehouse, wormwood)) { - ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + template.item_base_name); return null; } if (cityWarehouse.resources.get(wormwood) < wormwoodAmount) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + template.item_base_name); return null; } } @@ -904,18 +907,18 @@ public class ItemFactory { int overdraft = BuildingManager.GetOverdraft(forge, costToCreate); if (overdraft > 0 && !useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); return null; } if (useWarehouse && overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } if (useWarehouse && overdraft > resources.get(goldIB)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); return null; } @@ -923,11 +926,11 @@ public class ItemFactory { overdraft += buildingWithdraw; if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); return null; } else { if (overdraft > resources.get(goldIB)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); return null; } } @@ -955,18 +958,18 @@ public class ItemFactory { int overdraft = BuildingManager.GetOverdraft(forge, total); if (overdraft > 0 && !useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough gold in building strongbox." + template.item_base_name); return null; } if (useWarehouse && overdraft > 0 && Warehouse.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) - ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + template.item_base_name); return null; } if (useWarehouse && overdraft > resources.get(goldIB)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + template.item_base_name); return null; } @@ -974,11 +977,11 @@ public class ItemFactory { overdraft += buildingWithdraw; if (!useWarehouse) { - ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + template.item_base_name); return null; } else { if (overdraft > resources.get(goldIB)) { - ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + template.item_base_name); return null; } } @@ -1003,7 +1006,7 @@ public class ItemFactory { if (galvorAmount > 0 && useWarehouse) { //ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse"); if (!Warehouse.withdraw(cityWarehouse, npc, galvor, galvorAmount, true)) { - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + template.item_base_name); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } @@ -1012,7 +1015,7 @@ public class ItemFactory { if (wormwoodAmount > 0 && useWarehouse) { //ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse"); if (!Warehouse.withdraw(cityWarehouse, npc, wormwood, wormwoodAmount, true)) { - ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse for " + ib.getName()); + ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse for " + template.item_base_name); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; diff --git a/src/engine/objects/MobEquipment.java b/src/engine/objects/MobEquipment.java index d15b6274..3d0ab031 100644 --- a/src/engine/objects/MobEquipment.java +++ b/src/engine/objects/MobEquipment.java @@ -215,17 +215,17 @@ public class MobEquipment extends AbstractGameObject { if (mobEquipment.itemBase == null) name = eb.getName(); else - name = eb.getName() + ' ' + mobEquipment.itemBase.getName(); + name = eb.getName() + ' ' + ItemTemplate.itemTemplates.get(mobEquipment.itemBase.getUUID()).item_base_name; } else if (eb.isSuffix()) { if (mobEquipment.itemBase == null) name = eb.getName(); else - name = mobEquipment.itemBase.getName() + ' ' + eb.getName(); + name = ItemTemplate.itemTemplates.get(mobEquipment.itemBase.getUUID()).item_base_name + ' ' + eb.getName(); } else { if (mobEquipment.itemBase == null) name = ""; else - name = mobEquipment.itemBase.getName(); + name = ItemTemplate.itemTemplates.get(mobEquipment.itemBase.getUUID()).item_base_name; } writer.putInt(eb.getToken()); diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index 7f500e76..6e252b00 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -21,6 +21,7 @@ import engine.net.client.msg.*; import engine.server.MBServerStatics; import org.joda.time.DateTime; import org.pmw.tinylog.Logger; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; @@ -173,13 +174,15 @@ public class Warehouse extends AbstractWorldObject { return; } + ItemTemplate template = ItemTemplate.itemTemplates.get(itemBaseID); + if (isResourceLocked(warehouse, ib)) { ChatManager.chatSystemInfo(player, "You cannot withdrawl a locked resource."); return; } if (!withdraw(warehouse, player, ib, withdrawAmount, true, true)) { - ChatManager.chatGuildError(player, "Failed to withdrawl " + ib.getName() + '.'); - Logger.debug(player.getName() + " Failed to withdrawl =" + ib.getName() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); + ChatManager.chatGuildError(player, "Failed to withdrawl " + template.item_base_name + '.'); + Logger.debug(player.getName() + " Failed to withdrawl =" + template.item_base_name + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); return; } @@ -341,7 +344,7 @@ public class Warehouse extends AbstractWorldObject { if (resource.getItemBase().getType().equals(Enum.ItemType.GOLD)) resourceType = Resource.GOLD; else - resourceType = Resource.valueOf(resource.getItemBase().getName().toUpperCase()); + resourceType = Resource.valueOf(ItemTemplate.itemTemplates.get(resource.getItemBaseID()).item_base_name.toUpperCase()); if (transaction) AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.DEPOSIT, resourceType, amount); @@ -468,7 +471,7 @@ public class Warehouse extends AbstractWorldObject { public static synchronized void depositRealmTaxes(PlayerCharacter taxer, ItemBase ib, int amount, Warehouse warehouse) { - if (!DepositApproved(ib,amount,warehouse)) + if (!DepositApproved(ib, amount, warehouse)) return; int oldAmount = warehouse.resources.get(ib); @@ -476,10 +479,12 @@ public class Warehouse extends AbstractWorldObject { warehouse.resources.put(ib, newAmount); Resource resourceType; + ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); + if (ib.getUUID() == 7) resourceType = Resource.GOLD; else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); + resourceType = Resource.valueOf(template.item_base_name.toUpperCase()); AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCEDEPOSIT, resourceType, amount); @@ -490,6 +495,8 @@ public class Warehouse extends AbstractWorldObject { if (ib == null) return; + ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); + if (warehouse.resources.get(ib) == null) return; @@ -508,7 +515,7 @@ public class Warehouse extends AbstractWorldObject { if (ib.getUUID() == 7) resourceType = Resource.GOLD; else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); + resourceType = Resource.valueOf(template.item_base_name.toUpperCase()); if (building != null) AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.DEPOSIT, resourceType, amount); @@ -615,16 +622,18 @@ public class Warehouse extends AbstractWorldObject { int newAmount = oldAmount - amount; - if (!WithdrawApproved(ib,amount, warehouse)) + if (!WithdrawApproved(ib, amount, warehouse)) return false; + ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); + warehouse.resources.put(ib, newAmount); Resource resourceType; if (ib.getUUID() == 7) resourceType = Resource.GOLD; else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); + resourceType = Resource.valueOf(template.item_base_name.toUpperCase()); if (transaction) AddTransactionToWarehouse(warehouse, npc.getObjectType(), npc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount); @@ -641,6 +650,8 @@ public class Warehouse extends AbstractWorldObject { if (ib == null) return; + ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); + if (warehouse.resources.get(ib) == null) return; @@ -675,7 +686,7 @@ public class Warehouse extends AbstractWorldObject { if (ib.getUUID() == 7) resourceType = Resource.GOLD; else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); + resourceType = Resource.valueOf(template.item_base_name.toUpperCase()); AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resourceType, amount); @@ -690,6 +701,8 @@ public class Warehouse extends AbstractWorldObject { if (ib == null) return false; + ItemTemplate template = ItemTemplate.itemTemplates.get(ib.getUUID()); + if (warehouse.resources.get(ib) == null) return false; @@ -763,7 +776,7 @@ public class Warehouse extends AbstractWorldObject { if (ib.getUUID() == 7) resourceType = Resource.GOLD; else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); + resourceType = Resource.valueOf(template.item_base_name.toUpperCase()); if (transaction) AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount);