From 8d91f200e79afcb24b0ca97086fc23e8871aa98c Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 28 Feb 2024 16:42:07 -0500 Subject: [PATCH] Refactor itembase.name to template. --- src/engine/objects/ItemBase.java | 11 +++++------ src/engine/objects/ItemFactory.java | 2 +- src/engine/objects/Warehouse.java | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/engine/objects/ItemBase.java b/src/engine/objects/ItemBase.java index 08f505f0..d10cd932 100644 --- a/src/engine/objects/ItemBase.java +++ b/src/engine/objects/ItemBase.java @@ -37,8 +37,8 @@ public class ItemBase { private static final HashMap _IDsByNames = new HashMap<>(); private static final ArrayList _resourceList = new ArrayList<>(); private final int uuid; - private String name; - //requirements/restrictions +// private String name; +//requirements/restrictions public EnumSet restrictedRaces; public EnumSet requiredRaces; public EnumSet restrictedClasses; @@ -179,7 +179,9 @@ public class ItemBase { if (itemBase.type.equals(ItemType.RESOURCE)) _resourceList.add(itemBase); - _IDsByNames.put(itemBase.name.toLowerCase().replace(" ", "_"), itemBase.uuid); + ItemTemplate template = ItemTemplate.itemTemplates.get(itemBase.uuid); + + _IDsByNames.put(template.item_base_name.toLowerCase().replace(" ", "_"), itemBase.uuid); } public static HashMap getItemHashIDMap() { @@ -254,9 +256,6 @@ public class ItemBase { /* * Getters */ - public String getName() { - return this.name; - } public float getDurability() { return this.durability; diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index 343be310..7237f3ea 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -491,7 +491,7 @@ public class ItemFactory { int creationAmount = suffixResourceCosts.get(ibResources); if (Warehouse.isResourceLocked(cityWarehouse, ibResources) == true) { - ChatManager.chatSystemError(pc, ibResources.getName() + " is locked!" + template.item_base_name); + ChatManager.chatSystemError(pc, "Resource is locked!" + template.item_base_name); return null; } diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index 6e252b00..f42374f5 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -354,24 +354,24 @@ public class Warehouse extends AbstractWorldObject { public static synchronized boolean depositFromMine(Mine mine, ItemBase resource, int amount, Warehouse warehouse) { - - int oldAmount = warehouse.resources.get(resource); int newAmount = oldAmount + amount; if (newAmount > getMaxResources().get(resource.getUUID())) return false; - if (!DepositApproved(resource,amount,warehouse)) + if (!DepositApproved(resource, amount, warehouse)) return false; warehouse.resources.put(resource, newAmount); Resource resourceType; + ItemTemplate template = ItemTemplate.itemTemplates.get(resource.getUUID()); + if (resource.getUUID() == 7) resourceType = Resource.GOLD; else - resourceType = Resource.valueOf(resource.getName().toUpperCase()); + resourceType = Resource.valueOf(template.item_base_name.toUpperCase()); if (mine != null) AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, mine.getBuildingID(), Enum.TransactionType.MINE, resourceType, amount);