From e06657e53fcb21c1123e11763e3b556612de468b Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 17 Mar 2024 10:06:26 -0400 Subject: [PATCH] Loading of warehouse data --- src/engine/objects/Warehouse.java | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index df69028d..a3d509cd 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -18,6 +18,7 @@ import engine.net.client.ClientConnection; import engine.net.client.msg.*; import engine.server.MBServerStatics; import org.joda.time.DateTime; +import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.pmw.tinylog.Logger; @@ -28,7 +29,7 @@ import java.util.concurrent.ConcurrentHashMap; public class Warehouse { - public EnumSet lockedResourceTypes; + public EnumSet locked; public int buildingUID; public City city; public ArrayList transactions = new ArrayList<>(); @@ -45,6 +46,12 @@ public class Warehouse { resources.put(resourceType, value); } + JSONArray lockedResources = (JSONArray) warehouse.get("locked"); + + if (lockedResources.isEmpty() == false) + for (Object o : lockedResources) + this.locked.add(Enum.ResourceType.valueOf((String) o)); + } public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc) { @@ -162,10 +169,10 @@ public class Warehouse { // toggle lock - if (warehouse.lockedResourceTypes.contains(resourceType)) { + if (warehouse.locked.contains(resourceType)) { boolean worked; - warehouse.lockedResourceTypes.remove(resourceType); + warehouse.locked.remove(resourceType); worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse); if (worked) { @@ -176,17 +183,17 @@ public class Warehouse { dispatch = Dispatch.borrow(player, vrm); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); } else - warehouse.lockedResourceTypes.add(resourceType); + warehouse.locked.add(resourceType); return; } boolean worked; - warehouse.lockedResourceTypes.add(resourceType); + warehouse.locked.add(resourceType); worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse); if (worked) { - warehouse.lockedResourceTypes.add(resourceType); + warehouse.locked.add(resourceType); ViewResourcesMessage vrm = new ViewResourcesMessage(player); vrm.setGuild(player.getGuild()); vrm.setWarehouseBuilding(warehouseBuilding); @@ -194,7 +201,7 @@ public class Warehouse { dispatch = Dispatch.borrow(player, vrm); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); } else - warehouse.lockedResourceTypes.remove(resourceType); + warehouse.locked.remove(resourceType); } @@ -602,7 +609,7 @@ public class Warehouse { } public static boolean isResourceLocked(Warehouse warehouse, Enum.ResourceType resourceType) { - return resourceType.elementOf(warehouse.lockedResourceTypes); + return resourceType.elementOf(warehouse.locked); } } \ No newline at end of file