From 0b68ae39607bd908f4515b45ce26ac01584ae7fd Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 11 Mar 2024 17:10:34 -0400 Subject: [PATCH] Resource.hash refactored --- src/engine/Enum.java | 63 ++++++++++--------- .../net/client/msg/ViewResourcesMessage.java | 6 +- src/engine/objects/ItemBase.java | 13 ---- src/engine/objects/Warehouse.java | 40 ++++++------ 4 files changed, 59 insertions(+), 63 deletions(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index 1d622a17..6f0c4a58 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -2663,41 +2663,48 @@ public class Enum { public enum ResourceType implements EnumBitSetHelper { - STONE(1580000), - TRUESTEEL(1580001), - IRON(1580002), - ADAMANT(1580003), - LUMBER(1580004), - OAK(1580005), - BRONZEWOOD(1580006), - MANDRAKE(1580007), - COAL(1580008), - AGATE(1580009), - DIAMOND(1580010), - ONYX(1580011), - AZOTH(1580012), - ORICHALK(1580013), - ANTIMONY(1580014), - SULFUR(1580015), - QUICKSILVER(1580016), - GALVOR(1580017), - WORMWOOD(1580018), - OBSIDIAN(1580019), - BLOODSTONE(1580020), - MITHRIL(1580021), - GOLD(7); + STONE(1580000, 74856115), + TRUESTEEL(1580001, -317484979), + IRON(1580002, 2504297), + ADAMANT(1580003, -1741189964), + LUMBER(1580004, -1603256692), + OAK(1580005, 74767), + BRONZEWOOD(1580006, 1334770447), + MANDRAKE(1580007, 1191391799), + COAL(1580008, 2559427), + AGATE(1580009, 75173057), + DIAMOND(1580010, -1730704107), + ONYX(1580011, 2977263), + AZOTH(1580012, 78329697), + ORICHALK(1580013, -2036290524), + ANTIMONY(1580014, 452320058), + SULFUR(1580015, -1586349421), + QUICKSILVER(1580016, -472884509), + GALVOR(1580017, -1596311545), + WORMWOOD(1580018, 1532478436), + OBSIDIAN(1580019, -697973233), + BLOODSTONE(1580020, -1569826353), + MITHRIL(1580021, -1761257186), + GOLD(7, 2308551); public static HashMap resourceLookup = new HashMap<>(); - public int itemID; + public static HashMap hashLookup = new HashMap<>(); + public int templateID; + public int hash; - ResourceType(int itemID) { - this.itemID = itemID; + ResourceType(int templateID, int hash) { + this.templateID = templateID; + this.hash = hash; } public static void InitializeResourceTypes() { - for (ResourceType resourceType : ResourceType.values()) - resourceLookup.put(resourceType.itemID, resourceType); + for (ResourceType resourceType : ResourceType.values()) { + resourceLookup.put(resourceType.templateID, resourceType); + hashLookup.put(resourceType.hash, resourceType); + } + + } } diff --git a/src/engine/net/client/msg/ViewResourcesMessage.java b/src/engine/net/client/msg/ViewResourcesMessage.java index 5b636477..f4ad9552 100644 --- a/src/engine/net/client/msg/ViewResourcesMessage.java +++ b/src/engine/net/client/msg/ViewResourcesMessage.java @@ -93,7 +93,8 @@ public class ViewResourcesMessage extends ClientNetMsg { for (ItemBase ib : (warehouseObject.resources.keySet())) { - writer.putInt(ib.getHashID()); + Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID()); + writer.putInt(resourceType.hash); writer.putInt((warehouseObject.resources.get(ib))); @@ -106,7 +107,8 @@ public class ViewResourcesMessage extends ClientNetMsg { writer.putInt(warehouseObject.resources.size()); for (ItemBase ib : warehouseObject.resources.keySet()) { - writer.putInt(ib.getHashID()); + Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID()); + writer.putInt(resourceType.hash); writer.putInt(0); //available? writer.putInt(Warehouse.getMaxResources().get(ib.getUUID())); //max? } diff --git a/src/engine/objects/ItemBase.java b/src/engine/objects/ItemBase.java index e86038bc..8edad6e3 100644 --- a/src/engine/objects/ItemBase.java +++ b/src/engine/objects/ItemBase.java @@ -30,7 +30,6 @@ public class ItemBase { public final int uuid; private final int modTable; - private int hashID; private final short percentRequired; private final short defense; private final float dexPenalty; @@ -47,8 +46,6 @@ public class ItemBase { this.uuid = rs.getInt("ID"); this.modTable = rs.getInt("modTable"); - this.hashID = rs.getInt("itemHashID"); - this.isConsumable = false; this.percentRequired = rs.getShort("percentRequired"); this.defense = rs.getShort("defense"); @@ -82,7 +79,6 @@ public class ItemBase { this.isConsumable = true; break; } - initializeHashes(); } @@ -149,19 +145,10 @@ public class ItemBase { return ID > 7000099 && ID < 7000281; } - public final void initializeHashes() { - itemHashIDMap.put(this.hashID, uuid); - - } - public int getModTable() { return modTable; } - public int getHashID() { - return hashID; - } - public final int getUUID() { return uuid; } diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index 59778be3..ed52c6a5 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -213,22 +213,18 @@ public class Warehouse extends AbstractWorldObject { if (wh == null) return; - int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); - ItemBase ib = ItemBase.getItemBase(itemBaseID); - - if (ib == null) - return; + Enum.ResourceType resourceType = Enum.ResourceType.hashLookup.get(hashID); - if (isResourceLocked(wh, ib)) { + if (isResourceLocked(wh, ItemBase.getItemBase(resourceType.templateID))) { boolean worked; EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class); - bitSet.remove(Enum.ResourceType.resourceLookup.get(itemBaseID)); + bitSet.remove(Enum.ResourceType.resourceLookup.get(ItemBase.getItemBase(resourceType.templateID))); worked = DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong()); if (worked) { - wh.lockedResourceTypes.remove(Enum.ResourceType.resourceLookup.get(itemBaseID)); + wh.lockedResourceTypes.remove(Enum.ResourceType.resourceLookup.get(ItemBase.getItemBase(resourceType.templateID))); ViewResourcesMessage vrm = new ViewResourcesMessage(player); vrm.setGuild(player.getGuild()); vrm.setWarehouseBuilding(warehouse); @@ -241,12 +237,12 @@ public class Warehouse extends AbstractWorldObject { EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class); - bitSet.add(Enum.ResourceType.resourceLookup.get(itemBaseID)); + bitSet.add(Enum.ResourceType.resourceLookup.get(ItemBase.getItemBase(resourceType.templateID))); if (!DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong())) return; - wh.lockedResourceTypes.add(Enum.ResourceType.resourceLookup.get(itemBaseID)); + wh.lockedResourceTypes.add(Enum.ResourceType.resourceLookup.get(ItemBase.getItemBase(resourceType.templateID))); ViewResourcesMessage vrm = new ViewResourcesMessage(player); vrm.setGuild(player.getGuild()); vrm.setWarehouseBuilding(warehouse); @@ -538,7 +534,8 @@ public class Warehouse extends AbstractWorldObject { if (oldAmount < amount) return false; - int hashID = ib.getHashID(); + Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID()); + int hashID = resourceType.hash; int newAmount = oldAmount - amount; boolean worked = false; @@ -658,7 +655,8 @@ public class Warehouse extends AbstractWorldObject { int amount = (int) (warehouse.resources.get(ib) * taxPercent); if (amount <= 0) { - msg.getResources().put(ib.getHashID(), 0); + Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID()); + msg.getResources().put(resourceType.hash, 0); continue; } @@ -672,23 +670,25 @@ public class Warehouse extends AbstractWorldObject { if (newAmount < amount) continue; - if (!WithdrawApproved(ib,amount,warehouse)) { - msg.getResources().put(ib.getHashID(), 0); + Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(ib.getUUID()); + + if (!WithdrawApproved(ib, amount, warehouse)) { + msg.getResources().put(resourceType.hash, 0); continue; } - msg.getResources().put(ib.getHashID(), amount); + msg.getResources().put(resourceType.hash, amount); warehouse.resources.put(ib, newAmount); depositRealmTaxes(taxer, ib, amount, warehouse); - Resource resourceType; + Resource resource; - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; + if (resourceType.equals(Enum.ResourceType.GOLD)) + resource = Resource.GOLD; else - resourceType = Resource.valueOf(template.item_base_name.toUpperCase()); + resource = Resource.valueOf(template.item_base_name.toUpperCase()); - AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resourceType, amount); + AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resource, amount); } }