Browse Source

Loading of warehouse data

combat-2
MagicBot 8 months ago
parent
commit
e06657e53f
  1. 23
      src/engine/objects/Warehouse.java

23
src/engine/objects/Warehouse.java

@ -18,6 +18,7 @@ import engine.net.client.ClientConnection; @@ -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; @@ -28,7 +29,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class Warehouse {
public EnumSet<Enum.ResourceType> lockedResourceTypes;
public EnumSet<Enum.ResourceType> locked;
public int buildingUID;
public City city;
public ArrayList<Transaction> transactions = new ArrayList<>();
@ -45,6 +46,12 @@ public class Warehouse { @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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);
}
}
Loading…
Cancel
Save