From a489aecb86dd4a07e9ee4882543aca783a15d0f2 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 15 Mar 2024 10:47:35 -0400 Subject: [PATCH] More refactor itembase out of warehouse --- src/engine/objects/City.java | 21 ++++++--------------- src/engine/objects/Warehouse.java | 27 +++++++++++---------------- 2 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 05f986ae..e1dfb8ae 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -1365,28 +1365,19 @@ public class City extends AbstractWorldObject { ItemBase.getItemHashIDMap(); - ArrayList resources = new ArrayList<>(); + ArrayList resources = new ArrayList<>(); float taxPercent = msg.getTaxPercent(); if (taxPercent > 20) taxPercent = .20f; - for (int resourceHash : msg.getResources().keySet()) { - if (ItemBase.getItemHashIDMap().get(resourceHash) != null) - resources.add(ItemBase.getItemHashIDMap().get(resourceHash)); - } - - for (Integer itemBaseID : resources) { - ItemBase ib = ItemBase.getItemBase(itemBaseID); - - if (ib == null) - continue; - - ItemTemplate template = ItemTemplate.itemTemplates.get(itemBaseID); + for (int resourceHash : msg.getResources().keySet()) + resources.add(ResourceType.hashLookup.get(resourceHash)); - if (Warehouse.isAboveCap(ruledWarehouse, ib, (int) (city.getWarehouse().resources.get(ib) * taxPercent))) { - ErrorPopupMsg.sendErrorMsg(player, "You're warehouse has enough " + template.item_base_name + " already!"); + for (ResourceType resourceType : resources) { + if (Warehouse.isAboveCap(ruledWarehouse, resourceType, (int) (city.getWarehouse().resources.get(resourceType) * taxPercent))) { + ErrorPopupMsg.sendErrorMsg(player, "Your warehouse has enough " + resourceType.name() + " already!"); return true; } diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index c3ae4e39..8a0dc65a 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -25,6 +25,7 @@ import org.pmw.tinylog.Logger; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.EnumSet; import java.util.concurrent.ConcurrentHashMap; public class Warehouse extends AbstractWorldObject { @@ -550,12 +551,9 @@ public class Warehouse extends AbstractWorldObject { return true; } - public static synchronized void transferResources(Warehouse warehouse, PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList realmResources, float taxPercent) { + public static synchronized void transferResources(Warehouse warehouse, PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList realmResources, float taxPercent) { - for (int templateID : realmResources) { - - ItemTemplate template = ItemTemplate.itemTemplates.get(templateID); - Enum.ResourceType resourceType = Enum.ResourceType.resourceLookup.get(templateID); + for (Enum.ResourceType resourceType : realmResources) { if (warehouse.resources.get(resourceType) == null) return; @@ -588,12 +586,7 @@ public class Warehouse extends AbstractWorldObject { depositRealmTaxes(taxer, resourceType, amount, warehouse); Enum.ResourceType resource; - if (resourceType.equals(Enum.ResourceType.GOLD)) - resource = Enum.ResourceType.GOLD; - else - resource = Enum.ResourceType.valueOf(template.item_base_name.toUpperCase()); - - AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resource, amount); + AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resourceType, amount); } } @@ -751,10 +744,12 @@ public class Warehouse extends AbstractWorldObject { public static boolean isEmpty(Warehouse warehouse) { int amount = 0; - for (ItemBase ib : ItemBase.getResourceList()) { + + for (Enum.ResourceType resourceType : EnumSet.allOf(Enum.ResourceType.class)) { + amount += warehouse.resources.get(resourceType); + if (amount > 0) return false; - amount += warehouse.resources.get(ib); } return true; } @@ -773,9 +768,9 @@ public class Warehouse extends AbstractWorldObject { warehouse.transactions.add(transaction); } - public static boolean isAboveCap(Warehouse warehouse, ItemBase ib, int deposit) { - int newAmount = warehouse.resources.get(ib) + deposit; - return newAmount > Enum.ResourceType.resourceLookup.get(ib.getUUID()).deposit_limit; + public static boolean isAboveCap(Warehouse warehouse, Enum.ResourceType resourceType, int deposit) { + int newAmount = warehouse.resources.get(resourceType) + deposit; + return newAmount > resourceType.deposit_limit; }