From cc1e0d89865e5bd6e037b8b16fbbde729df10c2e Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 24 Jan 2024 20:03:27 -0600 Subject: [PATCH] Warehosue cleanup --- .../db/handlers/dbWarehouseHandler.java | 51 +- src/engine/devcmd/cmds/MakeItemCmd.java | 5 +- src/engine/devcmd/cmds/RemoveObjectCmd.java | 7 +- src/engine/gameManager/BuildingManager.java | 8 +- .../gameManager/MaintenanceManager.java | 40 +- src/engine/gameManager/WarehouseManager.java | 846 +++++++++++ .../ArcViewAssetTransactionsMsgHandler.java | 3 +- .../handlers/ManageCityAssetMsgHandler.java | 5 +- .../client/handlers/MerchantMsgHandler.java | 6 +- .../handlers/ObjectActionMsgHandler.java | 40 +- .../client/handlers/PlaceAssetMsgHandler.java | 2 +- .../client/handlers/TaxCityMsgHandler.java | 2 +- .../msg/ArcViewAssetTransactionsMsg.java | 12 +- .../net/client/msg/ViewResourcesMessage.java | 15 +- src/engine/objects/Building.java | 11 +- src/engine/objects/CharacterItemManager.java | 9 +- src/engine/objects/City.java | 8 +- src/engine/objects/ItemFactory.java | 94 +- src/engine/objects/Mine.java | 7 +- src/engine/objects/Warehouse.java | 1292 +---------------- 20 files changed, 1038 insertions(+), 1425 deletions(-) create mode 100644 src/engine/gameManager/WarehouseManager.java diff --git a/src/engine/db/handlers/dbWarehouseHandler.java b/src/engine/db/handlers/dbWarehouseHandler.java index 677e67eb..b20d28d4 100644 --- a/src/engine/db/handlers/dbWarehouseHandler.java +++ b/src/engine/db/handlers/dbWarehouseHandler.java @@ -13,6 +13,7 @@ import engine.Enum.GameObjectType; import engine.Enum.ProtectionState; import engine.Enum.TransactionType; import engine.gameManager.DbManager; +import engine.gameManager.WarehouseManager; import engine.math.Vector3fImmutable; import engine.objects.*; import engine.server.MBServerStatics; @@ -109,7 +110,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_locks`=? WHERE `UID` = ?")) { preparedStatement.setLong(1, locks); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -125,7 +126,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_gold`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -141,7 +142,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_stone`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -157,7 +158,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_truesteel`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -173,7 +174,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_iron`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -189,7 +190,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_adamant`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -205,7 +206,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_lumber`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -221,7 +222,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_oak`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -237,7 +238,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_bronzewood`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -253,7 +254,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_mandrake`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -269,7 +270,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_coal`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -285,7 +286,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_agate`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -301,7 +302,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_diamond`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -317,7 +318,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_onyx`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -333,7 +334,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_azoth`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -349,7 +350,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_orichalk`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -365,7 +366,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_antimony`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -381,7 +382,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_sulfur`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -397,7 +398,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_quicksilver`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -413,7 +414,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_galvor`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -429,7 +430,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_wormwood`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -445,7 +446,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_obsidian`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -461,7 +462,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_bloodstone`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -477,7 +478,7 @@ public class dbWarehouseHandler extends dbHandlerBase { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_warehouse` SET `warehouse_mithril`=? WHERE `UID` = ?")) { preparedStatement.setInt(1, amount); - preparedStatement.setInt(2, wh.getUID()); + preparedStatement.setInt(2, wh.UID); return (preparedStatement.executeUpdate() > 0); @@ -545,7 +546,7 @@ public class dbWarehouseHandler extends dbHandlerBase { while (rs.next()) { warehouse = new Warehouse(rs); warehouse.runAfterLoad(); - warehouse.loadAllTransactions(); + WarehouseManager.loadAllTransactions(warehouse); } } catch (SQLException e) { diff --git a/src/engine/devcmd/cmds/MakeItemCmd.java b/src/engine/devcmd/cmds/MakeItemCmd.java index 835cdb27..11441fe1 100644 --- a/src/engine/devcmd/cmds/MakeItemCmd.java +++ b/src/engine/devcmd/cmds/MakeItemCmd.java @@ -14,6 +14,7 @@ import engine.Enum.ItemType; import engine.Enum.OwnerType; import engine.devcmd.AbstractDevCmd; import engine.gameManager.DbManager; +import engine.gameManager.WarehouseManager; import engine.objects.*; import engine.powers.EffectsBase; @@ -33,7 +34,7 @@ public class MakeItemCmd extends AbstractDevCmd { AbstractGameObject target) { if (words[0].equals("resources")) { - for (int ibID : Warehouse.getMaxResources().keySet()) { + for (int ibID : WarehouseManager.getMaxResources().keySet()) { if (ibID == 7) continue; @@ -53,7 +54,7 @@ public class MakeItemCmd extends AbstractDevCmd { true, false, ItemContainerType.INVENTORY, (byte) 0, new ArrayList<>(), ""); - item.setNumOfItems(Warehouse.getMaxResources().get(ibID)); + item.setNumOfItems(WarehouseManager.getMaxResources().get(ibID)); try { item = DbManager.ItemQueries.ADD_ITEM(item); diff --git a/src/engine/devcmd/cmds/RemoveObjectCmd.java b/src/engine/devcmd/cmds/RemoveObjectCmd.java index 944ccfc2..b3934a3a 100644 --- a/src/engine/devcmd/cmds/RemoveObjectCmd.java +++ b/src/engine/devcmd/cmds/RemoveObjectCmd.java @@ -13,10 +13,7 @@ import engine.Enum.BuildingGroup; import engine.Enum.DbObjectType; import engine.InterestManagement.WorldGrid; import engine.devcmd.AbstractDevCmd; -import engine.gameManager.BuildingManager; -import engine.gameManager.ChatManager; -import engine.gameManager.DbManager; -import engine.gameManager.ZoneManager; +import engine.gameManager.*; import engine.math.Vector3fImmutable; import engine.objects.*; @@ -134,7 +131,7 @@ public class RemoveObjectCmd extends AbstractDevCmd { if (city != null) { city.setWarehouseBuildingID(0); } - Warehouse.warehouseByBuildingUUID.remove(building.getObjectUUID()); + WarehouseManager.warehouseByBuildingUUID.remove(building.getObjectUUID()); } //remove cached shrines. diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index bde12730..198df911 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -224,7 +224,7 @@ public enum BuildingManager { break; case WAREHOUSE: - Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(building.getObjectUUID()); + Warehouse warehouse = WarehouseManager.warehouseByBuildingUUID.get(building.getObjectUUID()); if (warehouse == null) return false; @@ -234,15 +234,15 @@ public enum BuildingManager { ChatManager.chatSystemInfo(player, "You can not carry any more of that item."); return false; } - if (warehouse.getResources().get(resourceBase) == null) + if (warehouse.resources.get(resourceBase) == null) continue; - int resourceAmount = warehouse.getResources().get(resourceBase); + int resourceAmount = warehouse.resources.get(resourceBase); if (resourceAmount <= 0) continue; - if (warehouse.loot(player, resourceBase, resourceAmount, true)) + if (WarehouseManager.loot(warehouse, player, resourceBase, resourceAmount, true)) ChatManager.chatInfoInfo(player, "You have looted " + resourceAmount + ' ' + resourceBase.getName()); } break; diff --git a/src/engine/gameManager/MaintenanceManager.java b/src/engine/gameManager/MaintenanceManager.java index d72db7a5..2aef2707 100644 --- a/src/engine/gameManager/MaintenanceManager.java +++ b/src/engine/gameManager/MaintenanceManager.java @@ -184,7 +184,7 @@ public enum MaintenanceManager { if ((overDraft > 0)) if ((building.getBlueprint().getBuildingGroup().equals(Enum.BuildingGroup.SHRINE) == false) && (warehouse != null) && building.assetIsProtected() == true && - (warehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) >= overDraft) { + (warehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) >= overDraft) { hasFunds = true; } @@ -199,22 +199,22 @@ public enum MaintenanceManager { hasResources = false; else { - resourceValue = warehouse.getResources().get(Warehouse.stoneIB); + resourceValue = warehouse.resources.get(WarehouseManager.stoneIB); if (resourceValue < 1500) hasResources = false; - resourceValue = warehouse.getResources().get(Warehouse.lumberIB); + resourceValue = warehouse.resources.get(WarehouseManager.lumberIB); if (resourceValue < 1500) hasResources = false; - resourceValue = warehouse.getResources().get(Warehouse.galvorIB); + resourceValue = warehouse.resources.get(WarehouseManager.galvorIB); if (resourceValue < 5) hasResources = false; - resourceValue = warehouse.getResources().get(Warehouse.wormwoodIB); + resourceValue = warehouse.resources.get(WarehouseManager.wormwoodIB); if (resourceValue < 5) hasResources = false; @@ -247,11 +247,11 @@ public enum MaintenanceManager { if (overDraft > 0) { - resourceValue = warehouse.getResources().get(Warehouse.goldIB); + resourceValue = warehouse.resources.get(WarehouseManager.goldIB); if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - overDraft) == true) { - warehouse.getResources().put(Warehouse.goldIB, resourceValue - overDraft); - warehouse.AddTransactionToWarehouse(Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GOLD, overDraft); + warehouse.resources.put(WarehouseManager.goldIB, resourceValue - overDraft); + WarehouseManager.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GOLD, overDraft); } else { Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return true; @@ -267,11 +267,11 @@ public enum MaintenanceManager { // Withdraw Stone - resourceValue = warehouse.getResources().get(Warehouse.stoneIB); + resourceValue = warehouse.resources.get(WarehouseManager.stoneIB); if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 1500) == true) { - warehouse.getResources().put(Warehouse.stoneIB, resourceValue - 1500); - warehouse.AddTransactionToWarehouse(Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.STONE, 1500); + warehouse.resources.put(WarehouseManager.stoneIB, resourceValue - 1500); + WarehouseManager.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.STONE, 1500); } else { Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return true; @@ -279,11 +279,11 @@ public enum MaintenanceManager { // Withdraw Lumber - resourceValue = warehouse.getResources().get(Warehouse.lumberIB); + resourceValue = warehouse.resources.get(WarehouseManager.lumberIB); if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 1500) == true) { - warehouse.getResources().put(Warehouse.lumberIB, resourceValue - 1500); - warehouse.AddTransactionToWarehouse(Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.LUMBER, 1500); + warehouse.resources.put(WarehouseManager.lumberIB, resourceValue - 1500); + WarehouseManager.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.LUMBER, 1500); } else { Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return true; @@ -291,21 +291,21 @@ public enum MaintenanceManager { // Withdraw Galvor - resourceValue = warehouse.getResources().get(Warehouse.galvorIB); + resourceValue = warehouse.resources.get(WarehouseManager.galvorIB); if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 5) == true) { - warehouse.getResources().put(Warehouse.galvorIB, resourceValue - 5); - warehouse.AddTransactionToWarehouse(Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GALVOR, 5); + warehouse.resources.put(WarehouseManager.galvorIB, resourceValue - 5); + WarehouseManager.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GALVOR, 5); } else { Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return true; } - resourceValue = warehouse.getResources().get(Warehouse.wormwoodIB); + resourceValue = warehouse.resources.get(WarehouseManager.wormwoodIB); if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 5) == true) { - warehouse.getResources().put(Warehouse.wormwoodIB, resourceValue - 5); - warehouse.AddTransactionToWarehouse(Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.WORMWOOD, 5); + warehouse.resources.put(WarehouseManager.wormwoodIB, resourceValue - 5); + WarehouseManager.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.WORMWOOD, 5); } else { Logger.error("wyrmwood update failed for warehouse of UUID:" + warehouse.getObjectUUID()); } diff --git a/src/engine/gameManager/WarehouseManager.java b/src/engine/gameManager/WarehouseManager.java new file mode 100644 index 00000000..21fd04f3 --- /dev/null +++ b/src/engine/gameManager/WarehouseManager.java @@ -0,0 +1,846 @@ +package engine.gameManager; + +import ch.claude_martin.enumbitset.EnumBitSet; +import engine.Enum; +import engine.net.Dispatch; +import engine.net.DispatchMessage; +import engine.net.client.ClientConnection; +import engine.net.client.msg.*; +import engine.objects.*; +import engine.server.MBServerStatics; +import org.joda.time.DateTime; +import org.pmw.tinylog.Logger; +import java.util.ArrayList; +import java.util.concurrent.ConcurrentHashMap; + +public class WarehouseManager { + public static ItemBase goldIB = ItemBase.getItemBase(7); + public static ItemBase stoneIB = ItemBase.getItemBase(1580000); + public static ItemBase truesteelIB = ItemBase.getItemBase(1580001); + public static ItemBase ironIB = ItemBase.getItemBase(1580002); + public static ItemBase adamantIB = ItemBase.getItemBase(1580003); + public static ItemBase lumberIB = ItemBase.getItemBase(1580004); + public static ItemBase oakIB = ItemBase.getItemBase(1580005); + public static ItemBase bronzewoodIB = ItemBase.getItemBase(1580006); + public static ItemBase mandrakeIB = ItemBase.getItemBase(1580007); + public static ItemBase coalIB = ItemBase.getItemBase(1580008); + public static ItemBase agateIB = ItemBase.getItemBase(1580009); + public static ItemBase diamondIB = ItemBase.getItemBase(1580010); + public static ItemBase onyxIB = ItemBase.getItemBase(1580011); + public static ItemBase azothIB = ItemBase.getItemBase(1580012); + public static ItemBase orichalkIB = ItemBase.getItemBase(1580013); + public static ItemBase antimonyIB = ItemBase.getItemBase(1580014); + public static ItemBase sulferIB = ItemBase.getItemBase(1580015); + public static ItemBase quicksilverIB = ItemBase.getItemBase(1580016); + public static ItemBase galvorIB = ItemBase.getItemBase(1580017); + public static ItemBase wormwoodIB = ItemBase.getItemBase(1580018); + public static ItemBase obsidianIB = ItemBase.getItemBase(1580019); + public static ItemBase bloodstoneIB = ItemBase.getItemBase(1580020); + public static ItemBase mithrilIB = ItemBase.getItemBase(1580021); + public static ConcurrentHashMap maxResources = new ConcurrentHashMap<>(); + public static ConcurrentHashMap warehouseByBuildingUUID = new ConcurrentHashMap<>(); + + public static ConcurrentHashMap getMaxResources() { + if (maxResources.size() != 23) { + maxResources.put(7, 100000000); + maxResources.put(1580000, 10000); + maxResources.put(1580001, 2000); + maxResources.put(1580002, 2000); + maxResources.put(1580003, 1000); + maxResources.put(1580004, 10000); + maxResources.put(1580005, 3000); + maxResources.put(1580006, 3000); + maxResources.put(1580007, 1000); + maxResources.put(1580008, 3000); + maxResources.put(1580009, 2000); + maxResources.put(1580010, 2000); + maxResources.put(1580011, 1000); + maxResources.put(1580012, 2000); + maxResources.put(1580013, 3000); + maxResources.put(1580014, 1000); + maxResources.put(1580015, 1000); + maxResources.put(1580016, 1000); + maxResources.put(1580017, 500); + maxResources.put(1580018, 500); + maxResources.put(1580019, 500); + maxResources.put(1580020, 500); + maxResources.put(1580021, 500); + } + + return maxResources; + } + + public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc) { + + Building warehouseBuilding; + Warehouse warehouse; + int depositAmount; + Dispatch dispatch; + + Item resource = Item.getFromCache(msg.getItemID()); + + if (resource == null) + return; + + depositAmount = msg.getAmount(); + CharacterItemManager itemMan = player.getCharItemManager(); + + if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) + return; + + warehouseBuilding = npc.getBuilding(); + + if (warehouseBuilding == null) + return; + + warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); + + if (warehouse == null) + return; + + + if (!WarehouseManager.deposit(player, resource, depositAmount, true, true,warehouse)) { + return; + } + + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setGuild(player.getGuild()); + vrm.setWarehouseBuilding(warehouseBuilding); + vrm.configure(); + dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + + public static void warehouseWithdraw(MerchantMsg msg, PlayerCharacter player, NPC npc) { + + int withdrawAmount; + Building warehouseBuilding; + Warehouse warehouse; + Dispatch dispatch; + + withdrawAmount = msg.getAmount(); + warehouseBuilding = npc.getBuilding(); + + if (warehouseBuilding == null) + return; + + if (player.getGuild() != warehouseBuilding.getGuild() || !GuildStatusController.isInnerCouncil(player.getGuildStatus())) + return; + + warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); + + if (warehouse == null) + return; + + int hashID = msg.getHashID(); + int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); + ItemBase ib = ItemBase.getItemBase(itemBaseID); + + if (ib == null) { + Logger.debug("Failed to find Resource ItemBaseID with Hash ID = " + hashID); + return; + } + + if (isResourceLocked(warehouse, ib)) { + ChatManager.chatSystemInfo(player, "You cannot withdrawl a locked resource."); + return; + } + if (!withdraw(warehouse, player, ib, withdrawAmount, true, true)) { + ChatManager.chatGuildError(player, "Failed to withdrawl " + ib.getName() + '.'); + Logger.debug(player.getName() + " Failed to withdrawl =" + ib.getName() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); + return; + } + + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setGuild(player.getGuild()); + vrm.setWarehouseBuilding(warehouseBuilding); + vrm.configure(); + dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + + public static void warehouseLock(MerchantMsg msg, PlayerCharacter player, NPC npc) { + Building warehouse; + int hashID; + Dispatch dispatch; + + hashID = msg.getHashID(); + warehouse = npc.getBuilding(); + + if (warehouse == null) + return; + + if (player.getGuild() != warehouse.getGuild() || !GuildStatusController.isInnerCouncil(player.getGuildStatus())) + return; + + Warehouse wh = warehouseByBuildingUUID.get(warehouse.getObjectUUID()); + + if (wh == null) + return; + + int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); + ItemBase ib = ItemBase.getItemBase(itemBaseID); + + if (ib == null) + return; + + if (isResourceLocked(wh, ib)) { + boolean worked; + EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class); + + bitSet.remove(Enum.ResourceType.resourceLookup.get(itemBaseID)); + + worked = DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong()); + + if (worked) { + wh.lockedResourceTypes.remove(Enum.ResourceType.resourceLookup.get(itemBaseID)); + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setGuild(player.getGuild()); + vrm.setWarehouseBuilding(warehouse); + vrm.configure(); + dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + } + return; + } + + EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), Enum.ResourceType.class); + + bitSet.add(Enum.ResourceType.resourceLookup.get(itemBaseID)); + + if (!DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong())) + return; + + wh.lockedResourceTypes.add(Enum.ResourceType.resourceLookup.get(itemBaseID)); + ViewResourcesMessage vrm = new ViewResourcesMessage(player); + vrm.setGuild(player.getGuild()); + vrm.setWarehouseBuilding(warehouse); + vrm.configure(); + dispatch = Dispatch.borrow(player, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + } + + public static synchronized boolean deposit(PlayerCharacter pc, Item resource, int amount, boolean removeFromInventory, boolean transaction, Warehouse warehouse) { + + ClientConnection origin = pc.getClientConnection(); + if (origin == null) + return false; + + if (amount < 0) { + Logger.info(pc.getFirstName() + " Attempting to Dupe!!!!!!"); + return false; + } + + ItemBase ib = resource.getItemBase(); + + if (ib == null) + return false; + + if (warehouse.resources.get(ib) == null) + return false; + + CharacterItemManager itemMan = pc.getCharItemManager(); + + if (itemMan == null) + return false; + + + if (itemMan.getGoldTrading() > 0) { + ErrorPopupMsg.sendErrorPopup(pc, 195); + return false; + } + + + if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) + return false; + + if (!resource.validForInventory(origin, pc, itemMan)) + return false; + + if (resource.getNumOfItems() < amount) + return false; + + int oldAmount = warehouse.resources.get(ib); + + int newAmount = oldAmount + amount; + + if (newAmount > WarehouseManager.getMaxResources().get(ib.getUUID())) { + //ChatManager.chatSystemInfo(pc, "The Warehouse is at it's maximum for this type of resource."); + return false; + } + + + if (removeFromInventory) { + if (ib.getUUID() == 7) { + + if (itemMan.getGoldInventory().getNumOfItems() - amount < 0) + return false; + + if (itemMan.getGoldInventory().getNumOfItems() - amount > MBServerStatics.PLAYER_GOLD_LIMIT) + return false; + + if (!itemMan.modifyInventoryGold(-amount)) { + //ChatManager.chatSystemError(pc, "You do not have this Gold."); + return false; + } + + UpdateGoldMsg ugm = new UpdateGoldMsg(pc); + ugm.configure(); + Dispatch dispatch = Dispatch.borrow(pc, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); + + itemMan.updateInventory(); + + } else { + itemMan.delete(resource); + itemMan.updateInventory(); + } + } + itemMan.updateInventory(); + + if (!WarehouseManager.DepositApproved(ib,amount,warehouse)) + return false; + + warehouse.resources.put(ib, newAmount); + + Resource resourceType; + + if (resource.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(resource.getItemBase().getName().toUpperCase()); + + if (transaction) + AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.DEPOSIT, resourceType, amount); + + return true; + } + 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 > WarehouseManager.getMaxResources().get(resource.getUUID())) + return false; + + if (!WarehouseManager.DepositApproved(resource,amount,warehouse)) + return false; + + warehouse.resources.put(resource, newAmount); + Resource resourceType; + + if (resource.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(resource.getName().toUpperCase()); + + if (mine != null) + AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, mine.getBuildingID(), Enum.TransactionType.MINE, resourceType, amount); + + return true; + } + + public static boolean DepositApproved(ItemBase ib, int amount, Warehouse warehouse){ + if (ib == null) + return false; + + if (warehouse.resources.get(ib) == null) + return false; + + int oldAmount = warehouse.resources.get(ib); + int newAmount = oldAmount + amount; + + if (newAmount > WarehouseManager.getMaxResources().get(ib.getUUID())) + return false; + + int itemID = ib.getUUID(); + boolean worked = false; + + switch (itemID) { + case 7: + worked = DbManager.WarehouseQueries.updateGold(warehouse, newAmount); + break; + case 1580000: + worked = DbManager.WarehouseQueries.updateStone(warehouse, newAmount); + break; + case 1580001: + worked = DbManager.WarehouseQueries.updateTruesteel(warehouse, newAmount); + break; + case 1580002: + worked = DbManager.WarehouseQueries.updateIron(warehouse, newAmount); + break; + case 1580003: + worked = DbManager.WarehouseQueries.updateAdamant(warehouse, newAmount); + break; + case 1580004: + worked = DbManager.WarehouseQueries.updateLumber(warehouse, newAmount); + break; + case 1580005: + worked = DbManager.WarehouseQueries.updateOak(warehouse, newAmount); + break; + case 1580006: + worked = DbManager.WarehouseQueries.updateBronzewood(warehouse, newAmount); + break; + case 1580007: + worked = DbManager.WarehouseQueries.updateMandrake(warehouse, newAmount); + break; + case 1580008: + worked = DbManager.WarehouseQueries.updateCoal(warehouse, newAmount); + break; + case 1580009: + worked = DbManager.WarehouseQueries.updateAgate(warehouse, newAmount); + break; + case 1580010: + worked = DbManager.WarehouseQueries.updateDiamond(warehouse, newAmount); + break; + case 1580011: + worked = DbManager.WarehouseQueries.updateOnyx(warehouse, newAmount); + break; + case 1580012: + worked = DbManager.WarehouseQueries.updateAzoth(warehouse, newAmount); + break; + case 1580013: + worked = DbManager.WarehouseQueries.updateOrichalk(warehouse, newAmount); + break; + case 1580014: + worked = DbManager.WarehouseQueries.updateAntimony(warehouse, newAmount); + break; + case 1580015: + worked = DbManager.WarehouseQueries.updateSulfur(warehouse, newAmount); + break; + case 1580016: + worked = DbManager.WarehouseQueries.updateQuicksilver(warehouse, newAmount); + break; + case 1580017: + worked = DbManager.WarehouseQueries.updateGalvor(warehouse, newAmount); + break; + case 1580018: + worked = DbManager.WarehouseQueries.updateWormwood(warehouse, newAmount); + break; + case 1580019: + worked = DbManager.WarehouseQueries.updateObsidian(warehouse, newAmount); + break; + case 1580020: + worked = DbManager.WarehouseQueries.updateBloodstone(warehouse, newAmount); + break; + case 1580021: + worked = DbManager.WarehouseQueries.updateMithril(warehouse, newAmount); + break; + } + return worked; + } + + public static synchronized void depositRealmTaxes(PlayerCharacter taxer, ItemBase ib, int amount, Warehouse warehouse) { + + if (!DepositApproved(ib,amount,warehouse)) + return; + + int oldAmount = warehouse.resources.get(ib); + int newAmount = oldAmount + amount; + warehouse.resources.put(ib, newAmount); + Resource resourceType; + + if (ib.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(ib.getName().toUpperCase()); + + AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCEDEPOSIT, resourceType, amount); + + } + + public static synchronized void depositProfitTax(ItemBase ib, int amount, Building building, Warehouse warehouse) { + + if (ib == null) + return; + + if (warehouse.resources.get(ib) == null) + return; + + int oldAmount = warehouse.resources.get(ib); + int newAmount = oldAmount + amount; + + if (newAmount > getMaxResources().get(ib.getUUID())) + return; + + if (!DepositApproved(ib,amount,warehouse)) + return; + + warehouse.resources.put(ib, newAmount); + Resource resourceType; + + if (ib.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(ib.getName().toUpperCase()); + + if (building != null) + AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.DEPOSIT, resourceType, amount); + + } + + public static boolean WithdrawApproved(ItemBase ib, int amount, Warehouse warehouse){ + + if (ib == null) + return false; + + if (warehouse.resources.get(ib) == null) + return false; + + if (amount <= 0) + return false; + + int oldAmount = warehouse.resources.get(ib); + + if (oldAmount < amount) + return false; + + int hashID = ib.getHashID(); + int newAmount = oldAmount - amount; + boolean worked = false; + + switch (hashID) { + case 2308551: + worked = DbManager.WarehouseQueries.updateGold(warehouse, newAmount); + break; + case 74856115: + worked = DbManager.WarehouseQueries.updateStone(warehouse, newAmount); + break; + case -317484979: + worked = DbManager.WarehouseQueries.updateTruesteel(warehouse, newAmount); + break; + case 2504297: + worked = DbManager.WarehouseQueries.updateIron(warehouse, newAmount); + break; + case -1741189964: + worked = DbManager.WarehouseQueries.updateAdamant(warehouse, newAmount); + break; + case -1603256692: + worked = DbManager.WarehouseQueries.updateLumber(warehouse, newAmount); + break; + case 74767: + worked = DbManager.WarehouseQueries.updateOak(warehouse, newAmount); + break; + case 1334770447: + worked = DbManager.WarehouseQueries.updateBronzewood(warehouse, newAmount); + break; + case 1191391799: + worked = DbManager.WarehouseQueries.updateMandrake(warehouse, newAmount); + break; + case 2559427: + worked = DbManager.WarehouseQueries.updateCoal(warehouse, newAmount); + break; + case 75173057: + worked = DbManager.WarehouseQueries.updateAgate(warehouse, newAmount); + break; + case -1730704107: + worked = DbManager.WarehouseQueries.updateDiamond(warehouse, newAmount); + break; + case 2977263: + worked = DbManager.WarehouseQueries.updateOnyx(warehouse, newAmount); + break; + case 78329697: + worked = DbManager.WarehouseQueries.updateAzoth(warehouse, newAmount); + break; + case -2036290524: + worked = DbManager.WarehouseQueries.updateOrichalk(warehouse, newAmount); + break; + case 452320058: + worked = DbManager.WarehouseQueries.updateAntimony(warehouse, newAmount); + break; + case -1586349421: + worked = DbManager.WarehouseQueries.updateSulfur(warehouse, newAmount); + break; + case -472884509: + worked = DbManager.WarehouseQueries.updateQuicksilver(warehouse, newAmount); + break; + case -1596311545: + worked = DbManager.WarehouseQueries.updateGalvor(warehouse, newAmount); + break; + case 1532478436: + worked = DbManager.WarehouseQueries.updateWormwood(warehouse, newAmount); + break; + case -697973233: + worked = DbManager.WarehouseQueries.updateObsidian(warehouse, newAmount); + break; + case -1569826353: + worked = DbManager.WarehouseQueries.updateBloodstone(warehouse, newAmount); + break; + case -1761257186: + worked = DbManager.WarehouseQueries.updateMithril(warehouse, newAmount); + break; + } + return worked; + } + + public static synchronized boolean withdraw(Warehouse warehouse, NPC npc, ItemBase ib, int amount, boolean transaction) { + + int oldAmount = warehouse.resources.get(ib); + + int newAmount = oldAmount - amount; + + if (!WithdrawApproved(ib,amount, warehouse)) + return false; + + warehouse.resources.put(ib, newAmount); + Resource resourceType; + + if (ib.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(ib.getName().toUpperCase()); + + if (transaction) + AddTransactionToWarehouse(warehouse, npc.getObjectType(), npc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount); + + return true; + } + + public static synchronized void transferResources(Warehouse warehouse, PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList realmResources, float taxPercent) { + + for (int ibID : realmResources) { + + ItemBase ib = ItemBase.getItemBase(ibID); + + if (ib == null) + return; + + if (warehouse.resources.get(ib) == null) + return; + + int amount = (int) (warehouse.resources.get(ib) * taxPercent); + + if (amount <= 0) { + msg.getResources().put(ib.getHashID(), 0); + continue; + } + + int oldAmount = warehouse.resources.get(ib); + + if (oldAmount < amount) + amount = oldAmount; + + int newAmount = oldAmount - amount; + + if (newAmount < amount) + continue; + + if (!WithdrawApproved(ib,amount,warehouse)) { + msg.getResources().put(ib.getHashID(), 0); + continue; + } + + msg.getResources().put(ib.getHashID(), amount); + + warehouse.resources.put(ib, newAmount); + depositRealmTaxes(taxer, ib, amount, warehouse); + Resource resourceType; + + if (ib.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(ib.getName().toUpperCase()); + + AddTransactionToWarehouse(warehouse, taxer.getObjectType(), taxer.getObjectUUID(), Enum.TransactionType.TAXRESOURCE, resourceType, amount); + + } + } + + public static synchronized boolean withdraw(Warehouse warehouse, PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory, boolean transaction) { + + if (pc == null) + return false; + + if (ib == null) + return false; + + if (warehouse.resources.get(ib) == null) + return false; + + if (amount <= 0) + return false; + + CharacterItemManager itemMan = pc.getCharItemManager(); + + if (itemMan == null) + return false; + + if (addToInventory) + if (!itemMan.hasRoomInventory(ib.getWeight())) { + ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); + return false; + } + + if (addToInventory && ib.getUUID() == ItemBase.GOLD_BASE_ID) { + if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT) { + return false; + } + + if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount < 0) + return false; + } + int oldAmount = warehouse.resources.get(ib); + + if (oldAmount < amount) + return false; + + int newAmount = oldAmount - amount; + + + if (!WithdrawApproved(ib,amount,warehouse)) + return false; + + warehouse.resources.put(ib, newAmount); + + if (addToInventory) { + if (ib.getUUID() == 7) { + + itemMan.addGoldToInventory(amount, false); + UpdateGoldMsg ugm = new UpdateGoldMsg(pc); + ugm.configure(); + Dispatch dispatch = Dispatch.borrow(pc, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + itemMan.updateInventory(); + } else { + boolean itemWorked = false; + Item item = new Item(ib, pc.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) 0, (byte) 0, + (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + item.setNumOfItems(amount); + item.containerType = Enum.ItemContainerType.INVENTORY; + + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + itemWorked = true; + } catch (Exception e) { + Logger.error(e); + } + if (itemWorked) { + itemMan.addItemToInventory(item); + itemMan.updateInventory(); + } + } + } + Resource resourceType; + + if (ib.getUUID() == 7) + resourceType = Resource.GOLD; + else + resourceType = Resource.valueOf(ib.getName().toUpperCase()); + + if (transaction) + AddTransactionToWarehouse(warehouse, pc.getObjectType(), pc.getObjectUUID(), Enum.TransactionType.WITHDRAWL, resourceType, amount); + + return true; + } + + public static synchronized boolean loot(Warehouse warehouse, PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory) { + + if (pc == null) + return false; + + if (ib == null) + return false; + + if (warehouse.resources.get(ib) == null) + return false; + + if (amount <= 0) + return false; + + CharacterItemManager itemMan = pc.getCharItemManager(); + + if (itemMan == null) + return false; + + if (!itemMan.hasRoomInventory(ib.getWeight())) { + ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); + return false; + } + + int oldAmount = warehouse.resources.get(ib); + + if (oldAmount < amount) + return false; + + int newAmount = oldAmount - amount; + + warehouse.resources.put(ib, newAmount); + + if (addToInventory) { + if (ib.getUUID() == 7) { + + itemMan.addGoldToInventory(amount, false); + UpdateGoldMsg ugm = new UpdateGoldMsg(pc); + ugm.configure(); + Dispatch dispatch = Dispatch.borrow(pc, ugm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + + itemMan.updateInventory(); + } else { + boolean itemWorked = false; + Item item = new Item(ib, pc.getObjectUUID(), Enum.OwnerType.PlayerCharacter, (byte) 0, (byte) 0, + (short) 1, (short) 1, true, false, Enum.ItemContainerType.INVENTORY, (byte) 0, + new ArrayList<>(), ""); + item.setNumOfItems(amount); + item.containerType = Enum.ItemContainerType.INVENTORY; + + try { + item = DbManager.ItemQueries.ADD_ITEM(item); + itemWorked = true; + } catch (Exception e) { + Logger.error(e); + } + if (itemWorked) { + itemMan.addItemToInventory(item); + itemMan.updateInventory(); + } + } + } + + return true; + } + + public static boolean isEmpty(Warehouse warehouse) { + int amount = 0; + for (ItemBase ib : ItemBase.getResourceList()) { + if (amount > 0) + return false; + amount += warehouse.resources.get(ib); + } + return true; + } + + public static void loadAllTransactions(Warehouse warehouse) { + warehouse.transactions = DbManager.WarehouseQueries.GET_TRANSACTIONS_FOR_WAREHOUSE(warehouse.buildingUID); + } + + public static void AddTransactionToWarehouse(Warehouse warehouse, Enum.GameObjectType targetType, int targetUUID, Enum.TransactionType transactionType, Resource resource, int amount) { + + + if (!DbManager.WarehouseQueries.CREATE_TRANSACTION(warehouse.buildingUID, targetType, targetUUID, transactionType, resource, amount, DateTime.now())) + return; + + Transaction transaction = new Transaction(warehouse.buildingUID, targetType, targetUUID, transactionType, resource, amount, DateTime.now()); + warehouse.transactions.add(transaction); + } + + public static boolean isAboveCap(Warehouse warehouse, ItemBase ib, int deposit) { + int newAmount = warehouse.resources.get(ib) + deposit; + return newAmount > getMaxResources().get(ib.getUUID()); + + } + + public static boolean isResourceLocked(Warehouse warehouse, ItemBase itemBase) { + + Enum.ResourceType resourceType; + + resourceType = Enum.ResourceType.resourceLookup.get(itemBase.getUUID()); + + return resourceType.elementOf(warehouse.lockedResourceTypes); + } +} diff --git a/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java b/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java index 468a3796..81e58eb9 100644 --- a/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java +++ b/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java @@ -3,6 +3,7 @@ package engine.net.client.handlers; import engine.Enum; import engine.exception.MsgSendException; import engine.gameManager.SessionManager; +import engine.gameManager.WarehouseManager; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; @@ -37,7 +38,7 @@ public class ArcViewAssetTransactionsMsgHandler extends AbstractClientMsgHandler msg = (ArcViewAssetTransactionsMsg) baseMsg; - Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(msg.getWarehouseID()); + Warehouse warehouse = WarehouseManager.warehouseByBuildingUUID.get(msg.getWarehouseID()); if (warehouse == null) return true; diff --git a/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java b/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java index a2e7726b..5bc6b884 100644 --- a/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java +++ b/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java @@ -6,6 +6,7 @@ import engine.Enum.GameObjectType; import engine.exception.MsgSendException; import engine.gameManager.BuildingManager; import engine.gameManager.SessionManager; +import engine.gameManager.WarehouseManager; import engine.gameManager.ZoneManager; import engine.math.Bounds; import engine.net.Dispatch; @@ -166,12 +167,12 @@ public class ManageCityAssetMsgHandler extends AbstractClientMsgHandler { return true; } - Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(building.getObjectUUID()); + Warehouse warehouse = WarehouseManager.warehouseByBuildingUUID.get(building.getObjectUUID()); if (warehouse == null) return true; - if (warehouse.isEmpty()) { + if (WarehouseManager.isEmpty(warehouse)) { ErrorPopupMsg.sendErrorPopup(player, 167); // no more resources. return true; } diff --git a/src/engine/net/client/handlers/MerchantMsgHandler.java b/src/engine/net/client/handlers/MerchantMsgHandler.java index 94490a72..dde7cac0 100644 --- a/src/engine/net/client/handlers/MerchantMsgHandler.java +++ b/src/engine/net/client/handlers/MerchantMsgHandler.java @@ -437,13 +437,13 @@ public class MerchantMsgHandler extends AbstractClientMsgHandler { DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); break; case 17: - Warehouse.warehouseWithdraw(msg, player, npc, origin); + WarehouseManager.warehouseWithdraw(msg, player, npc); break; case 18: - Warehouse.warehouseDeposit(msg, player, npc, origin); + WarehouseManager.warehouseDeposit(msg, player, npc); break; case 19: - Warehouse.warehouseLock(msg, player, npc, origin); + WarehouseManager.warehouseLock(msg, player, npc); break; } diff --git a/src/engine/net/client/handlers/ObjectActionMsgHandler.java b/src/engine/net/client/handlers/ObjectActionMsgHandler.java index 6896f566..41bf9ae2 100644 --- a/src/engine/net/client/handlers/ObjectActionMsgHandler.java +++ b/src/engine/net/client/handlers/ObjectActionMsgHandler.java @@ -98,27 +98,27 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler { return false; } - resourceValue = warehouse.getResources().get(Warehouse.goldIB); + resourceValue = warehouse.resources.get(WarehouseManager.goldIB); if (resourceValue < 5000000) hasResources = false; - resourceValue = warehouse.getResources().get(Warehouse.stoneIB); + resourceValue = warehouse.resources.get(WarehouseManager.stoneIB); if (resourceValue < 8000) hasResources = false; - resourceValue = warehouse.getResources().get(Warehouse.lumberIB); + resourceValue = warehouse.resources.get(WarehouseManager.lumberIB); if (resourceValue < 8000) hasResources = false; - resourceValue = warehouse.getResources().get(Warehouse.galvorIB); + resourceValue = warehouse.resources.get(WarehouseManager.galvorIB); if (resourceValue < 15) hasResources = false; - resourceValue = warehouse.getResources().get(Warehouse.wormwoodIB); + resourceValue = warehouse.resources.get(WarehouseManager.wormwoodIB); if (resourceValue < 15) hasResources = false; @@ -130,51 +130,51 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler { // Remove resources from warehouse before claiming realm - resourceValue = warehouse.getResources().get(Warehouse.goldIB); + resourceValue = warehouse.resources.get(WarehouseManager.goldIB); if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - 5000000) == true) { - warehouse.getResources().put(Warehouse.goldIB, resourceValue - 5000000); - warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GOLD, 5000000); + warehouse.resources.put(WarehouseManager.goldIB, resourceValue - 5000000); + WarehouseManager.AddTransactionToWarehouse(warehouse, engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GOLD, 5000000); } else { Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return false; } - resourceValue = warehouse.getResources().get(Warehouse.stoneIB); + resourceValue = warehouse.resources.get(WarehouseManager.stoneIB); if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 8000) == true) { - warehouse.getResources().put(Warehouse.stoneIB, resourceValue - 8000); - warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.STONE, 8000); + warehouse.resources.put(WarehouseManager.stoneIB, resourceValue - 8000); + WarehouseManager.AddTransactionToWarehouse(warehouse, engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.STONE, 8000); } else { Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return false; } - resourceValue = warehouse.getResources().get(Warehouse.lumberIB); + resourceValue = warehouse.resources.get(WarehouseManager.lumberIB); if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 8000) == true) { - warehouse.getResources().put(Warehouse.lumberIB, resourceValue - 8000); - warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.LUMBER, 8000); + warehouse.resources.put(WarehouseManager.lumberIB, resourceValue - 8000); + WarehouseManager.AddTransactionToWarehouse(warehouse, engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.LUMBER, 8000); } else { Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return false; } - resourceValue = warehouse.getResources().get(Warehouse.galvorIB); + resourceValue = warehouse.resources.get(WarehouseManager.galvorIB); if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 15) == true) { - warehouse.getResources().put(Warehouse.galvorIB, resourceValue - 15); - warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GALVOR, 15); + warehouse.resources.put(WarehouseManager.galvorIB, resourceValue - 15); + WarehouseManager.AddTransactionToWarehouse(warehouse, engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.GALVOR, 15); } else { Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return false; } - resourceValue = warehouse.getResources().get(Warehouse.wormwoodIB); + resourceValue = warehouse.resources.get(WarehouseManager.wormwoodIB); if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 15) == true) { - warehouse.getResources().put(Warehouse.wormwoodIB, resourceValue - 15); - warehouse.AddTransactionToWarehouse(engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.WORMWOOD, 15); + warehouse.resources.put(WarehouseManager.wormwoodIB, resourceValue - 15); + WarehouseManager.AddTransactionToWarehouse(warehouse, engine.Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Resource.WORMWOOD, 15); } else { Logger.error("wormwood update failed for warehouse of UUID:" + warehouse.getObjectUUID()); return false; diff --git a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java index 76c26d3e..16920ae6 100644 --- a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java +++ b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java @@ -1359,7 +1359,7 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler { return true; city.setWarehouseBuildingID(newMesh.getObjectUUID()); - Warehouse.warehouseByBuildingUUID.put(newMesh.getObjectUUID(), warehouse); + WarehouseManager.warehouseByBuildingUUID.put(newMesh.getObjectUUID(), warehouse); } } diff --git a/src/engine/net/client/handlers/TaxCityMsgHandler.java b/src/engine/net/client/handlers/TaxCityMsgHandler.java index 4b9a1ef2..2cc4e825 100644 --- a/src/engine/net/client/handlers/TaxCityMsgHandler.java +++ b/src/engine/net/client/handlers/TaxCityMsgHandler.java @@ -111,7 +111,7 @@ public class TaxCityMsgHandler extends AbstractClientMsgHandler { ViewResourcesMessage vrm = new ViewResourcesMessage(player); vrm.setGuild(building.getGuild()); - vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().getBuildingUID())); + vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().buildingUID)); vrm.configure(); Dispatch dispatch = Dispatch.borrow(player, msg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); diff --git a/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java b/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java index af4cc873..60de5853 100644 --- a/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java +++ b/src/engine/net/client/msg/ArcViewAssetTransactionsMsg.java @@ -61,13 +61,13 @@ public class ArcViewAssetTransactionsMsg extends ClientNetMsg { public void configure() { - warehouseBuilding = BuildingManager.getBuilding(this.warehouse.getBuildingUID()); + warehouseBuilding = BuildingManager.getBuilding(this.warehouse.buildingUID); transactions = new ArrayList<>(50); - if (this.warehouse.getTransactions().size() > 150) { - transactions.addAll(this.warehouse.getTransactions().subList(this.warehouse.getTransactions().size() - 150, this.warehouse.getTransactions().size())); + if (this.warehouse.transactions.size() > 150) { + transactions.addAll(this.warehouse.transactions.subList(this.warehouse.transactions.size() - 150, this.warehouse.transactions.size())); } else - transactions = this.warehouse.getTransactions(); + transactions = this.warehouse.transactions; } @@ -78,7 +78,7 @@ public class ArcViewAssetTransactionsMsg extends ClientNetMsg { protected void _serialize(ByteBufferWriter writer) throws SerializationException { writer.putInt(this.transactionID); - writer.putInt(this.warehouse.getBuildingUID()); + writer.putInt(this.warehouse.buildingUID); writer.putInt(transactions.size()); //list Size for (Transaction transaction : transactions) { @@ -124,7 +124,7 @@ public class ArcViewAssetTransactionsMsg extends ClientNetMsg { writer.putInt(transaction.getTargetUUID()); //ID writer.putString(name); //Name of depositer/withdrawler or mine name writer.putInt(GameObjectType.Building.ordinal()); //Type - writer.putInt(warehouse.getBuildingUID()); //ID + writer.putInt(warehouse.buildingUID); //ID writer.putString(warehouseBuilding.getName()); //warehouse writer.putInt(transaction.getTransactionType().getID()); //79,80 withdrew, 81 mine produced, 82 deposit writer.putInt(transaction.getAmount()); //amount diff --git a/src/engine/net/client/msg/ViewResourcesMessage.java b/src/engine/net/client/msg/ViewResourcesMessage.java index 0bb3ff74..faa03494 100644 --- a/src/engine/net/client/msg/ViewResourcesMessage.java +++ b/src/engine/net/client/msg/ViewResourcesMessage.java @@ -11,6 +11,7 @@ package engine.net.client.msg; import engine.Enum; import engine.gameManager.DbManager; +import engine.gameManager.WarehouseManager; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; @@ -89,26 +90,26 @@ public class ViewResourcesMessage extends ClientNetMsg { @Override protected void _serialize(ByteBufferWriter writer) { - writer.putInt(warehouseObject.getResources().size()); + writer.putInt(warehouseObject.resources.size()); - for (ItemBase ib : (warehouseObject.getResources().keySet())) { + for (ItemBase ib : (warehouseObject.resources.keySet())) { writer.putInt(ib.getHashID()); - writer.putInt((warehouseObject.getResources().get(ib))); + writer.putInt((warehouseObject.resources.get(ib))); - if (warehouseObject.isResourceLocked(ib) == true) + if (WarehouseManager.isResourceLocked(warehouseObject, ib) == true) writer.put((byte) 1); else writer.put((byte) 0); } - writer.putInt(warehouseObject.getResources().size()); + writer.putInt(warehouseObject.resources.size()); - for (ItemBase ib : warehouseObject.getResources().keySet()) { + for (ItemBase ib : warehouseObject.resources.keySet()) { writer.putInt(ib.getHashID()); writer.putInt(0); //available? - writer.putInt(Warehouse.getMaxResources().get(ib.getUUID())); //max? + writer.putInt(WarehouseManager.getMaxResources().get(ib.getUUID())); //max? } GuildTag._serializeForDisplay(guild.getGuildTag(), writer); diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index b288f0e2..0a7b0db8 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -19,6 +19,7 @@ import engine.db.archive.DataWarehouse; import engine.db.archive.MineRecord; import engine.gameManager.BuildingManager; import engine.gameManager.DbManager; +import engine.gameManager.WarehouseManager; import engine.gameManager.ZoneManager; import engine.job.JobContainer; import engine.job.JobScheduler; @@ -1429,18 +1430,18 @@ public class Building extends AbstractWorldObject { if (this.getCity().getWarehouse() == null) return amount; - if (this.getCity().getWarehouse().getResources().get(ItemBase.getGoldItemBase()) >= Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID())) + if (this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase()) >= WarehouseManager.getMaxResources().get(ItemBase.getGoldItemBase().getUUID())) return amount; int profitAmount = (int) (amount * (taxAmount * .01f)); - if (this.getCity().getWarehouse().getResources().get(ItemBase.getGoldItemBase()) + profitAmount <= Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID())) { - this.getCity().getWarehouse().depositProfitTax(ItemBase.getGoldItemBase(), profitAmount, this); + if (this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase()) + profitAmount <= WarehouseManager.getMaxResources().get(ItemBase.getGoldItemBase().getUUID())) { + WarehouseManager.depositProfitTax(ItemBase.getGoldItemBase(), profitAmount, this,this.getCity().getWarehouse()); return amount - profitAmount; } //overDrafting - int warehouseDeposit = Warehouse.getMaxResources().get(ItemBase.getGoldItemBase().getUUID()) - this.getCity().getWarehouse().getResources().get(ItemBase.getGoldItemBase()); - this.getCity().getWarehouse().depositProfitTax(ItemBase.getGoldItemBase(), warehouseDeposit, this); + int warehouseDeposit = WarehouseManager.getMaxResources().get(ItemBase.getGoldItemBase().getUUID()) - this.getCity().getWarehouse().resources.get(ItemBase.getGoldItemBase()); + WarehouseManager.depositProfitTax(ItemBase.getGoldItemBase(), warehouseDeposit, this,this.getCity().getWarehouse()); return amount - warehouseDeposit; } diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index b4b6fcfa..d6ad49dc 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -12,10 +12,7 @@ package engine.objects; import engine.Enum; import engine.Enum.GameObjectType; import engine.Enum.ItemType; -import engine.gameManager.BuildingManager; -import engine.gameManager.ChatManager; -import engine.gameManager.ConfigManager; -import engine.gameManager.DbManager; +import engine.gameManager.*; import engine.math.Vector3fImmutable; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -345,13 +342,13 @@ public class CharacterItemManager { Warehouse warehouse = (Warehouse) object; if (amount < 0) { - if (!warehouse.deposit((PlayerCharacter) this.absCharacter, this.getGoldInventory(), amount * -1, true, true)) { + if (!WarehouseManager.deposit((PlayerCharacter) this.absCharacter, this.getGoldInventory(), amount * -1, true, true,warehouse)) { ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203); return false; } } else { - if (!warehouse.withdraw((PlayerCharacter) this.absCharacter, this.getGoldInventory().getItemBase(), amount * -1, true, true)) { + if (!WarehouseManager.withdraw(warehouse, (PlayerCharacter) this.absCharacter, this.getGoldInventory().getItemBase(), amount * -1, true, true)) { ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203); return false; diff --git a/src/engine/objects/City.java b/src/engine/objects/City.java index 1b12ee4d..88e7b2c1 100644 --- a/src/engine/objects/City.java +++ b/src/engine/objects/City.java @@ -875,7 +875,7 @@ public class City extends AbstractWorldObject { if (this.warehouseBuildingID == 0) return null; - return Warehouse.warehouseByBuildingUUID.get(this.warehouseBuildingID); + return WarehouseManager.warehouseByBuildingUUID.get(this.warehouseBuildingID); } public Realm getRealm() { @@ -1358,7 +1358,7 @@ public class City extends AbstractWorldObject { ItemBase ib = ItemBase.getItemBase(itemBaseID); if (ib == null) continue; - if (ruledWarehouse.isAboveCap(ib, (int) (city.getWarehouse().getResources().get(ib) * taxPercent))) { + if (WarehouseManager.isAboveCap(ruledWarehouse, ib, (int) (city.getWarehouse().resources.get(ib) * taxPercent))) { ErrorPopupMsg.sendErrorMsg(player, "You're warehouse has enough " + ib.getName() + " already!"); return true; } @@ -1371,7 +1371,7 @@ public class City extends AbstractWorldObject { } try { - city.getWarehouse().transferResources(player, msg, resources, taxPercent, ruledWarehouse); + WarehouseManager.transferResources(city.getWarehouse(), player, msg, resources, taxPercent); } catch (Exception e) { Logger.info(e.getMessage()); } @@ -1380,7 +1380,7 @@ public class City extends AbstractWorldObject { ViewResourcesMessage vrm = new ViewResourcesMessage(player); vrm.setGuild(building.getGuild()); - vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().getBuildingUID())); + vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().buildingUID)); vrm.configure(); Dispatch dispatch = Dispatch.borrow(player, vrm); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index abac878f..87660927 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -119,7 +119,7 @@ public class ItemFactory { // ROLL BANE SCROLL. if (ib.getUUID() > 910010 && ib.getUUID() < 910019) { - ConcurrentHashMap resources = cityWarehouse.getResources(); + ConcurrentHashMap resources = cityWarehouse.resources; int buildingWithdraw = BuildingManager.GetWithdrawAmountForRolling(forge, ib.getBaseValue()); @@ -131,7 +131,7 @@ public class ItemFactory { return null; } - if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + " " + ib.getName()); return null; @@ -167,9 +167,9 @@ public class ItemFactory { } if (overdraft > 0) - if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item." + ib.getName()); + Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName()); return null; } @@ -263,13 +263,13 @@ public class ItemFactory { } if (galvorAmount > 0) { - if (cityWarehouse.isResourceLocked(galvor)) { + if (WarehouseManager.isResourceLocked(cityWarehouse, galvor)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName()); return null; } - if (cityWarehouse.getResources().get(galvor) < galvorAmount) { + if (cityWarehouse.resources.get(galvor) < galvorAmount) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + ib.getName()); return null; @@ -277,13 +277,13 @@ public class ItemFactory { } if (wormwoodAmount > 0) { - if (cityWarehouse.isResourceLocked(wormwood)) { + if (WarehouseManager.isResourceLocked(cityWarehouse, wormwood)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Wormwood is locked." + ib.getName()); return null; } - if (cityWarehouse.getResources().get(wormwood) < wormwoodAmount) { + if (cityWarehouse.resources.get(wormwood) < wormwoodAmount) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Wormwood in warehouse to roll this item." + ib.getName()); return null; @@ -320,20 +320,20 @@ public class ItemFactory { return null; } - if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); return null; } - if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); return null; } prefixResourceCosts = prefix.getResourcesForEffect(); for (ItemBase ibResources : prefixResourceCosts.keySet()) { - int warehouseAmount = cityWarehouse.getResources().get(ibResources); + int warehouseAmount = cityWarehouse.resources.get(ibResources); int creationAmount = prefixResourceCosts.get(ibResources); //ChatManager.chatInfoError(pc, "Prefix : " + ibResources.getName() + " / " + creationAmount); if (warehouseAmount < creationAmount) { @@ -374,13 +374,13 @@ public class ItemFactory { return null; } - if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); return null; } - if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); return null; @@ -388,7 +388,7 @@ public class ItemFactory { for (ItemBase ibResources : suffixResourceCosts.keySet()) { - int warehouseAmount = cityWarehouse.getResources().get(ibResources); + int warehouseAmount = cityWarehouse.resources.get(ibResources); int creationAmount = suffixResourceCosts.get(ibResources); if (warehouseAmount < creationAmount) { // if (pc != null) @@ -414,13 +414,13 @@ public class ItemFactory { return null; } - if (overdraft > 0 && useWarehouse && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > 0 && useWarehouse && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); return null; } - if (useWarehouse && overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + if (useWarehouse && overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); return null; @@ -440,7 +440,7 @@ public class ItemFactory { ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); return null; } else { - if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); return null; } @@ -448,9 +448,9 @@ public class ItemFactory { } if (overdraft > 0 && useWarehouse) - if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item." + ib.getName()); + Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName()); return null; } @@ -467,18 +467,18 @@ public class ItemFactory { int creationAmount = prefixResourceCosts.get(ibResources); - if (cityWarehouse.isResourceLocked(ibResources) == true) + if (WarehouseManager.isResourceLocked(cityWarehouse, ibResources) == true) return null; - int oldAmount = cityWarehouse.getResources().get(ibResources); + int oldAmount = cityWarehouse.resources.get(ibResources); int amount = creationAmount; if (oldAmount < amount) amount = oldAmount; - if (!cityWarehouse.withdraw(npc, ibResources, amount, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, ibResources, amount, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item." + ib.getName()); + Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName()); return null; } } @@ -489,18 +489,18 @@ public class ItemFactory { for (ItemBase ibResources : suffixResourceCosts.keySet()) { int creationAmount = suffixResourceCosts.get(ibResources); - if (cityWarehouse.isResourceLocked(ibResources) == true) { + if (WarehouseManager.isResourceLocked(cityWarehouse, ibResources) == true) { ChatManager.chatSystemError(pc, ibResources.getName() + " is locked!" + ib.getName()); return null; } - int oldAmount = cityWarehouse.getResources().get(ibResources); + int oldAmount = cityWarehouse.resources.get(ibResources); int amount = creationAmount; if (oldAmount < amount) amount = oldAmount; - if (!cityWarehouse.withdraw(npc, ibResources, amount, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, ibResources, amount, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item." + ib.getName()); + Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName()); return null; } } @@ -522,14 +522,14 @@ public class ItemFactory { return null; } - if (overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); return null; } - if (useWarehouse && overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + if (useWarehouse && overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse for overdraft." + ib.getName()); @@ -544,7 +544,7 @@ public class ItemFactory { ErrorPopupMsg.sendErrorMsg(pc, "Building does not have enough gold to produce this item." + ib.getName()); return null; } else { - if (overdraft > cityWarehouse.getResources().get(ItemBase.GOLD_ITEM_BASE)) { + if (overdraft > cityWarehouse.resources.get(ItemBase.GOLD_ITEM_BASE)) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Gold in Warehouse to produce this item." + ib.getName()); return null; } @@ -552,16 +552,16 @@ public class ItemFactory { } if (overdraft > 0) - if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.getUID() + " Failed to Create Item." + ib.getName()); + Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + ib.getName()); return null; } // ChatManager.chatGuildInfo(pc, "Gold Cost = " + total); if (galvorAmount > 0) { - if (!cityWarehouse.withdraw(npc, galvor, galvorAmount, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, galvor, galvorAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + ib.getName()); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; @@ -569,7 +569,7 @@ public class ItemFactory { } if (wormwoodAmount > 0) { - if (!cityWarehouse.withdraw(npc, wormwood, wormwoodAmount, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, wormwood, wormwoodAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse!" + ib.getName()); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; @@ -815,7 +815,7 @@ public class ItemFactory { ConcurrentHashMap resources = null; if (useWarehouse) - resources = cityWarehouse.getResources(); + resources = cityWarehouse.resources; int galvorAmount = 0; int wormwoodAmount = 0; @@ -852,24 +852,24 @@ public class ItemFactory { return null; if (galvorAmount > 0) { - if (cityWarehouse.isResourceLocked(galvor)) { + if (WarehouseManager.isResourceLocked(cityWarehouse, galvor)) { ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName()); return null; } - if (cityWarehouse.getResources().get(galvor) < galvorAmount) { + if (cityWarehouse.resources.get(galvor) < galvorAmount) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + ib.getName()); return null; } } if (wormwoodAmount > 0) { - if (cityWarehouse.isResourceLocked(wormwood)) { + if (WarehouseManager.isResourceLocked(cityWarehouse, wormwood)) { ErrorPopupMsg.sendErrorMsg(pc, "Galvor is locked." + ib.getName()); return null; } - if (cityWarehouse.getResources().get(wormwood) < wormwoodAmount) { + if (cityWarehouse.resources.get(wormwood) < wormwoodAmount) { ErrorPopupMsg.sendErrorMsg(pc, "Not enough Galvor in warehouse to roll this item." + ib.getName()); return null; } @@ -908,7 +908,7 @@ public class ItemFactory { return null; } - if (useWarehouse && overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (useWarehouse && overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); return null; @@ -936,12 +936,12 @@ public class ItemFactory { // there was an overdraft, withdraw the rest from warehouse. if (overdraft > 0) { if (pc != null) { - if (!cityWarehouse.withdraw(pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } } else { - if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } @@ -959,7 +959,7 @@ public class ItemFactory { return null; } - if (useWarehouse && overdraft > 0 && cityWarehouse.isResourceLocked(ItemBase.GOLD_ITEM_BASE)) { + if (useWarehouse && overdraft > 0 && WarehouseManager.isResourceLocked(cityWarehouse, ItemBase.GOLD_ITEM_BASE)) { if (pc != null) ErrorPopupMsg.sendErrorMsg(pc, "Warehouse gold is barred! Overdraft cannot be withdrawn from warehouse." + ib.getName()); return null; @@ -987,12 +987,12 @@ public class ItemFactory { if (overdraft > 0 && useWarehouse) { if (pc != null) { - if (!cityWarehouse.withdraw(pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, pc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } } else { - if (!cityWarehouse.withdraw(npc, ItemBase.GOLD_ITEM_BASE, overdraft, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, ItemBase.GOLD_ITEM_BASE, overdraft, true)) { Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; } @@ -1002,7 +1002,7 @@ public class ItemFactory { if (galvorAmount > 0 && useWarehouse) { //ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse"); - if (!cityWarehouse.withdraw(npc, galvor, galvorAmount, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, galvor, galvorAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + ib.getName()); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); return null; @@ -1011,7 +1011,7 @@ public class ItemFactory { if (wormwoodAmount > 0 && useWarehouse) { //ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse"); - if (!cityWarehouse.withdraw(npc, wormwood, wormwoodAmount, false, true)) { + if (!WarehouseManager.withdraw(cityWarehouse, npc, wormwood, wormwoodAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse for " + ib.getName()); Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index 5a46af13..efe1fc43 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -11,10 +11,7 @@ package engine.objects; import engine.Enum; import engine.InterestManagement.WorldGrid; -import engine.gameManager.BuildingManager; -import engine.gameManager.ChatManager; -import engine.gameManager.DbManager; -import engine.gameManager.ZoneManager; +import engine.gameManager.*; import engine.net.ByteBufferWriter; import engine.net.client.msg.ErrorPopupMsg; import engine.server.MBServerStatics; @@ -483,7 +480,7 @@ public class Mine extends AbstractGameObject { return false; ItemBase resourceIB = ItemBase.getItemBase(this.production.UUID); - return this.owningGuild.getOwnedCity().getWarehouse().depositFromMine(this, resourceIB, this.getModifiedProductionAmount()); + return WarehouseManager.depositFromMine(this, resourceIB, this.getModifiedProductionAmount(),this.owningGuild.getOwnedCity().getWarehouse()); } public boolean updateGuildOwner(PlayerCharacter playerCharacter) { diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index 9b55a1f7..66c05101 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -11,18 +11,9 @@ package engine.objects; import ch.claude_martin.enumbitset.EnumBitSet; import engine.Enum; -import engine.Enum.*; import engine.gameManager.BuildingManager; -import engine.gameManager.ChatManager; -import engine.gameManager.DbManager; -import engine.net.Dispatch; -import engine.net.DispatchMessage; -import engine.net.client.ClientConnection; -import engine.net.client.msg.*; -import engine.server.MBServerStatics; -import org.joda.time.DateTime; +import engine.gameManager.WarehouseManager; import org.pmw.tinylog.Logger; - import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; @@ -31,36 +22,11 @@ import java.util.concurrent.ConcurrentHashMap; public class Warehouse extends AbstractWorldObject { - public static ItemBase goldIB = ItemBase.getItemBase(7); - public static ItemBase stoneIB = ItemBase.getItemBase(1580000); - public static ItemBase truesteelIB = ItemBase.getItemBase(1580001); - public static ItemBase ironIB = ItemBase.getItemBase(1580002); - public static ItemBase adamantIB = ItemBase.getItemBase(1580003); - public static ItemBase lumberIB = ItemBase.getItemBase(1580004); - public static ItemBase oakIB = ItemBase.getItemBase(1580005); - public static ItemBase bronzewoodIB = ItemBase.getItemBase(1580006); - public static ItemBase mandrakeIB = ItemBase.getItemBase(1580007); - public static ItemBase coalIB = ItemBase.getItemBase(1580008); - public static ItemBase agateIB = ItemBase.getItemBase(1580009); - public static ItemBase diamondIB = ItemBase.getItemBase(1580010); - public static ItemBase onyxIB = ItemBase.getItemBase(1580011); - public static ItemBase azothIB = ItemBase.getItemBase(1580012); - public static ItemBase orichalkIB = ItemBase.getItemBase(1580013); - public static ItemBase antimonyIB = ItemBase.getItemBase(1580014); - public static ItemBase sulferIB = ItemBase.getItemBase(1580015); - public static ItemBase quicksilverIB = ItemBase.getItemBase(1580016); - public static ItemBase galvorIB = ItemBase.getItemBase(1580017); - public static ItemBase wormwoodIB = ItemBase.getItemBase(1580018); - public static ItemBase obsidianIB = ItemBase.getItemBase(1580019); - public static ItemBase bloodstoneIB = ItemBase.getItemBase(1580020); - public static ItemBase mithrilIB = ItemBase.getItemBase(1580021); - public static ConcurrentHashMap maxResources = new ConcurrentHashMap<>(); - public static ConcurrentHashMap warehouseByBuildingUUID = new ConcurrentHashMap<>(); public EnumBitSet lockedResourceTypes; - private int UID; - private int buildingUID; - private ArrayList transactions = new ArrayList<>(); - private ConcurrentHashMap resources = new ConcurrentHashMap<>(); + public int UID; + public int buildingUID; + public ArrayList transactions = new ArrayList<>(); + public ConcurrentHashMap resources = new ConcurrentHashMap<>(); /** @@ -69,1181 +35,32 @@ public class Warehouse extends AbstractWorldObject { public Warehouse(ResultSet rs) throws SQLException { super(rs); this.UID = rs.getInt("UID"); - this.resources.put(stoneIB, rs.getInt("warehouse_stone")); - this.resources.put(truesteelIB, rs.getInt("warehouse_truesteel")); - this.resources.put(ironIB, rs.getInt("warehouse_iron")); - this.resources.put(adamantIB, rs.getInt("warehouse_adamant")); - this.resources.put(lumberIB, rs.getInt("warehouse_lumber")); - this.resources.put(oakIB, rs.getInt("warehouse_oak")); - this.resources.put(bronzewoodIB, rs.getInt("warehouse_bronzewood")); - this.resources.put(mandrakeIB, rs.getInt("warehouse_mandrake")); - this.resources.put(coalIB, rs.getInt("warehouse_coal")); - this.resources.put(agateIB, rs.getInt("warehouse_agate")); - this.resources.put(diamondIB, rs.getInt("warehouse_diamond")); - this.resources.put(onyxIB, rs.getInt("warehouse_onyx")); - this.resources.put(azothIB, rs.getInt("warehouse_azoth")); - this.resources.put(orichalkIB, rs.getInt("warehouse_orichalk")); - this.resources.put(antimonyIB, rs.getInt("warehouse_antimony")); - this.resources.put(sulferIB, rs.getInt("warehouse_sulfur")); - this.resources.put(quicksilverIB, rs.getInt("warehouse_quicksilver")); - this.resources.put(galvorIB, rs.getInt("warehouse_galvor")); - this.resources.put(wormwoodIB, rs.getInt("warehouse_wormwood")); - this.resources.put(obsidianIB, rs.getInt("warehouse_obsidian")); - this.resources.put(bloodstoneIB, rs.getInt("warehouse_bloodstone")); - this.resources.put(mithrilIB, rs.getInt("warehouse_mithril")); - this.resources.put(goldIB, rs.getInt("warehouse_gold")); + this.resources.put(WarehouseManager.stoneIB, rs.getInt("warehouse_stone")); + this.resources.put(WarehouseManager.truesteelIB, rs.getInt("warehouse_truesteel")); + this.resources.put(WarehouseManager.ironIB, rs.getInt("warehouse_iron")); + this.resources.put(WarehouseManager.adamantIB, rs.getInt("warehouse_adamant")); + this.resources.put(WarehouseManager.lumberIB, rs.getInt("warehouse_lumber")); + this.resources.put(WarehouseManager.oakIB, rs.getInt("warehouse_oak")); + this.resources.put(WarehouseManager.bronzewoodIB, rs.getInt("warehouse_bronzewood")); + this.resources.put(WarehouseManager.mandrakeIB, rs.getInt("warehouse_mandrake")); + this.resources.put(WarehouseManager.coalIB, rs.getInt("warehouse_coal")); + this.resources.put(WarehouseManager.agateIB, rs.getInt("warehouse_agate")); + this.resources.put(WarehouseManager.diamondIB, rs.getInt("warehouse_diamond")); + this.resources.put(WarehouseManager.onyxIB, rs.getInt("warehouse_onyx")); + this.resources.put(WarehouseManager.azothIB, rs.getInt("warehouse_azoth")); + this.resources.put(WarehouseManager.orichalkIB, rs.getInt("warehouse_orichalk")); + this.resources.put(WarehouseManager.antimonyIB, rs.getInt("warehouse_antimony")); + this.resources.put(WarehouseManager.sulferIB, rs.getInt("warehouse_sulfur")); + this.resources.put(WarehouseManager.quicksilverIB, rs.getInt("warehouse_quicksilver")); + this.resources.put(WarehouseManager.galvorIB, rs.getInt("warehouse_galvor")); + this.resources.put(WarehouseManager.wormwoodIB, rs.getInt("warehouse_wormwood")); + this.resources.put(WarehouseManager.obsidianIB, rs.getInt("warehouse_obsidian")); + this.resources.put(WarehouseManager.bloodstoneIB, rs.getInt("warehouse_bloodstone")); + this.resources.put(WarehouseManager.mithrilIB, rs.getInt("warehouse_mithril")); + this.resources.put(WarehouseManager.goldIB, rs.getInt("warehouse_gold")); this.lockedResourceTypes = EnumBitSet.asEnumBitSet(rs.getLong("warehouse_locks"), Enum.ResourceType.class); this.buildingUID = rs.getInt("parent"); - Warehouse.warehouseByBuildingUUID.put(this.buildingUID, this); - } - - public static ConcurrentHashMap getMaxResources() { - if (maxResources.size() != 23) { - maxResources.put(7, 100000000); - maxResources.put(1580000, 10000); - maxResources.put(1580001, 2000); - maxResources.put(1580002, 2000); - maxResources.put(1580003, 1000); - maxResources.put(1580004, 10000); - maxResources.put(1580005, 3000); - maxResources.put(1580006, 3000); - maxResources.put(1580007, 1000); - maxResources.put(1580008, 3000); - maxResources.put(1580009, 2000); - maxResources.put(1580010, 2000); - maxResources.put(1580011, 1000); - maxResources.put(1580012, 2000); - maxResources.put(1580013, 3000); - maxResources.put(1580014, 1000); - maxResources.put(1580015, 1000); - maxResources.put(1580016, 1000); - maxResources.put(1580017, 500); - maxResources.put(1580018, 500); - maxResources.put(1580019, 500); - maxResources.put(1580020, 500); - maxResources.put(1580021, 500); - } - - return maxResources; - } - - public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) { - - Building warehouseBuilding; - Warehouse warehouse; - int depositAmount; - Dispatch dispatch; - - Item resource = Item.getFromCache(msg.getItemID()); - - if (resource == null) - return; - - depositAmount = msg.getAmount(); - CharacterItemManager itemMan = player.getCharItemManager(); - - if (itemMan.doesCharOwnThisItem(resource.getObjectUUID()) == false) - return; - - warehouseBuilding = npc.getBuilding(); - - if (warehouseBuilding == null) - return; - - warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); - - if (warehouse == null) - return; - - ItemBase ib = resource.getItemBase(); - - if (!warehouse.deposit(player, resource, depositAmount, true, true)) { - // ChatManager.chatGuildError(player, "Failed to deposit " + ib.getName() +"."); - // Logger.debug("OpenWindow", player.getName() + " Failed to deposit Item with ID " + resource.getObjectUUID() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); - return; - } - - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(player.getGuild()); - vrm.setWarehouseBuilding(warehouseBuilding); - vrm.configure(); - dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - - public static void warehouseWithdraw(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) { - - int withdrawAmount; - Building warehouseBuilding; - Warehouse warehouse; - Dispatch dispatch; - - withdrawAmount = msg.getAmount(); - warehouseBuilding = npc.getBuilding(); - - if (warehouseBuilding == null) - return; - - if (player.getGuild() != warehouseBuilding.getGuild() || GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) - return; - - warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); - - if (warehouse == null) - return; - - int hashID = msg.getHashID(); - int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); - ItemBase ib = ItemBase.getItemBase(itemBaseID); - - if (ib == null) { - Logger.debug("Failed to find Resource ItemBaseID with Hash ID = " + hashID); - return; - } - - if (warehouse.isResourceLocked(ib) == true) { - ChatManager.chatSystemInfo(player, "You cannot withdrawl a locked resource."); - return; - } - if (!warehouse.withdraw(player, ib, withdrawAmount, true, true)) { - ChatManager.chatGuildError(player, "Failed to withdrawl " + ib.getName() + '.'); - Logger.debug(player.getName() + " Failed to withdrawl =" + ib.getName() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); - return; - } - - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(player.getGuild()); - vrm.setWarehouseBuilding(warehouseBuilding); - vrm.configure(); - dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - - public static void warehouseLock(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) { - Building warehouse; - int hashID; - Dispatch dispatch; - - hashID = msg.getHashID(); - warehouse = npc.getBuilding(); - - if (warehouse == null) - return; - - if (player.getGuild() != warehouse.getGuild() || GuildStatusController.isInnerCouncil(player.getGuildStatus()) == false) - return; - - Warehouse wh = warehouseByBuildingUUID.get(warehouse.getObjectUUID()); - - if (wh == null) - return; - - int itemBaseID = ItemBase.getItemHashIDMap().get(hashID); - ItemBase ib = ItemBase.getItemBase(itemBaseID); - - if (ib == null) - return; - - if (wh.isResourceLocked(ib) == true) { - boolean worked = false; - EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), ResourceType.class); - - bitSet.remove(ResourceType.resourceLookup.get(itemBaseID)); - - worked = DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong()); - - if (worked) { - wh.lockedResourceTypes.remove(Enum.ResourceType.resourceLookup.get(itemBaseID)); - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(player.getGuild()); - vrm.setWarehouseBuilding(warehouse); - vrm.configure(); - dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - } - return; - } - - EnumBitSet bitSet = EnumBitSet.asEnumBitSet(wh.lockedResourceTypes.toLong(), ResourceType.class); - - bitSet.add(ResourceType.resourceLookup.get(itemBaseID)); - - if (DbManager.WarehouseQueries.updateLocks(wh, bitSet.toLong()) == false) - return; - - wh.lockedResourceTypes.add(Enum.ResourceType.resourceLookup.get(itemBaseID)); - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(player.getGuild()); - vrm.setWarehouseBuilding(warehouse); - vrm.configure(); - dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - } - - public ConcurrentHashMap getResources() { - return resources; - } - - public int getUID() { - return UID; - } - - public void setUID(int uID) { - UID = uID; - } - - public synchronized boolean deposit(PlayerCharacter pc, Item resource, int amount, boolean removeFromInventory, boolean transaction) { - - ClientConnection origin = pc.getClientConnection(); - if (origin == null) - return false; - - if (amount < 0) { - Logger.info(pc.getFirstName() + " Attempting to Dupe!!!!!!"); - return false; - } - - ItemBase ib = resource.getItemBase(); - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - CharacterItemManager itemMan = pc.getCharItemManager(); - - if (itemMan == null) - return false; - - - if (itemMan.getGoldTrading() > 0) { - ErrorPopupMsg.sendErrorPopup(pc, 195); - return false; - } - - - if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) - return false; - - if (!resource.validForInventory(origin, pc, itemMan)) - return false; - - if (resource.getNumOfItems() < amount) - return false; - - int oldAmount = resources.get(ib); - - int newAmount = oldAmount + amount; - - if (newAmount > Warehouse.getMaxResources().get(ib.getUUID())) { - //ChatManager.chatSystemInfo(pc, "The Warehouse is at it's maximum for this type of resource."); - return false; - } - - - if (removeFromInventory) { - if (ib.getUUID() == 7) { - - if (itemMan.getGoldInventory().getNumOfItems() - amount < 0) - return false; - - if (itemMan.getGoldInventory().getNumOfItems() - amount > MBServerStatics.PLAYER_GOLD_LIMIT) - return false; - - if (!itemMan.modifyInventoryGold(-amount)) { - //ChatManager.chatSystemError(pc, "You do not have this Gold."); - return false; - } - - UpdateGoldMsg ugm = new UpdateGoldMsg(pc); - ugm.configure(); - Dispatch dispatch = Dispatch.borrow(pc, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, engine.Enum.DispatchChannel.SECONDARY); - - itemMan.updateInventory(); - - } else { - itemMan.delete(resource); - itemMan.updateInventory(); - } - } - itemMan.updateInventory(); - int itemID = ib.getUUID(); - boolean worked = false; - switch (itemID) { - case 7: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 1580000: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case 1580001: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 1580002: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case 1580003: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case 1580004: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 1580005: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1580006: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1580007: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 1580008: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 1580009: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case 1580010: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 1580011: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 1580012: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case 1580013: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 1580014: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case 1580015: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case 1580016: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case 1580017: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1580018: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case 1580019: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case 1580020: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case 1580021: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - - if (!worked) - return false; - - resources.put(ib, newAmount); - - Resource resourceType; - - if (resource.getItemBase().getType().equals(engine.Enum.ItemType.GOLD)) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(resource.getItemBase().getName().toUpperCase()); - - if (transaction) - this.AddTransactionToWarehouse(pc.getObjectType(), pc.getObjectUUID(), TransactionType.DEPOSIT, resourceType, amount); - - return true; - } - - //for mine deposit - public synchronized boolean depositFromMine(Mine mine, ItemBase resource, int amount) { - - if (resource == null) - return false; - - if (this.resources.get(resource) == null) - return false; - - int oldAmount = resources.get(resource); - int newAmount = oldAmount + amount; - - if (newAmount > Warehouse.getMaxResources().get(resource.getUUID())) - return false; - - int itemID = resource.getUUID(); - boolean worked = false; - - switch (itemID) { - case 7: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 1580000: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case 1580001: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 1580002: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case 1580003: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case 1580004: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 1580005: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1580006: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1580007: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 1580008: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 1580009: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case 1580010: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 1580011: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 1580012: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case 1580013: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 1580014: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case 1580015: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case 1580016: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case 1580017: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1580018: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case 1580019: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case 1580020: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case 1580021: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - if (!worked) - return false; - - this.resources.put(resource, newAmount); - Resource resourceType; - - if (resource.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(resource.getName().toUpperCase()); - - if (mine != null) - this.AddTransactionToWarehouse(GameObjectType.Building, mine.getBuildingID(), TransactionType.MINE, resourceType, amount); - - return true; - } - - public synchronized boolean depositRealmTaxes(PlayerCharacter taxer, ItemBase ib, int amount) { - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - int oldAmount = resources.get(ib); - int newAmount = oldAmount + amount; - - if (newAmount > Warehouse.getMaxResources().get(ib.getUUID())) - return false; - - int itemID = ib.getUUID(); - boolean worked = false; - - switch (itemID) { - case 7: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 1580000: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case 1580001: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 1580002: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case 1580003: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case 1580004: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 1580005: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1580006: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1580007: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 1580008: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 1580009: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case 1580010: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 1580011: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 1580012: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case 1580013: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 1580014: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case 1580015: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case 1580016: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case 1580017: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1580018: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case 1580019: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case 1580020: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case 1580021: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - - if (!worked) - return false; - - this.resources.put(ib, newAmount); - Resource resourceType; - - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); - - this.AddTransactionToWarehouse(taxer.getObjectType(), taxer.getObjectUUID(), TransactionType.TAXRESOURCEDEPOSIT, resourceType, amount); - - return true; - } - - public synchronized boolean depositProfitTax(ItemBase ib, int amount, Building building) { - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - int oldAmount = resources.get(ib); - int newAmount = oldAmount + amount; - - if (newAmount > Warehouse.getMaxResources().get(ib.getUUID())) - return false; - - int itemID = ib.getUUID(); - boolean worked = false; - - switch (itemID) { - case 7: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 1580000: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case 1580001: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 1580002: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case 1580003: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case 1580004: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 1580005: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1580006: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1580007: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 1580008: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 1580009: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case 1580010: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 1580011: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 1580012: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case 1580013: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 1580014: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case 1580015: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case 1580016: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case 1580017: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1580018: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case 1580019: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case 1580020: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case 1580021: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - - if (!worked) - return false; - - this.resources.put(ib, newAmount); - Resource resourceType; - - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); - - if (building != null) - this.AddTransactionToWarehouse(GameObjectType.Building, building.getObjectUUID(), TransactionType.DEPOSIT, resourceType, amount); - - return true; - } - - public synchronized boolean withdraw(PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory, boolean transaction) { - - if (pc == null) - return false; - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - if (amount <= 0) - return false; - - CharacterItemManager itemMan = pc.getCharItemManager(); - - if (itemMan == null) - return false; - - if (addToInventory) - if (!itemMan.hasRoomInventory(ib.getWeight())) { - ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); - return false; - } - - if (addToInventory && ib.getUUID() == ItemBase.GOLD_BASE_ID) { - if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount > MBServerStatics.PLAYER_GOLD_LIMIT) { - return false; - } - - if (pc.getCharItemManager().getGoldInventory().getNumOfItems() + amount < 0) - return false; - } - int oldAmount = this.resources.get(ib); - - if (oldAmount < amount) - return false; - - int hashID = ib.getHashID(); - int newAmount = oldAmount - amount; - - boolean worked = false; - - switch (hashID) { - case 2308551: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 74856115: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case -317484979: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 2504297: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case -1741189964: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case -1603256692: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 74767: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1334770447: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1191391799: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 2559427: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 75173057: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case -1730704107: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 2977263: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 78329697: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case -2036290524: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 452320058: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case -1586349421: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case -472884509: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case -1596311545: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1532478436: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case -697973233: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case -1569826353: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case -1761257186: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - if (!worked) - return false; - - this.resources.put(ib, newAmount); - - if (addToInventory) { - if (ib.getUUID() == 7) { - - itemMan.addGoldToInventory(amount, false); - UpdateGoldMsg ugm = new UpdateGoldMsg(pc); - ugm.configure(); - Dispatch dispatch = Dispatch.borrow(pc, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - itemMan.updateInventory(); - } else { - boolean itemWorked = false; - Item item = new Item(ib, pc.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, - (short) 1, (short) 1, true, false, ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(), ""); - item.setNumOfItems(amount); - item.containerType = Enum.ItemContainerType.INVENTORY; - - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - itemWorked = true; - } catch (Exception e) { - Logger.error(e); - } - if (itemWorked) { - itemMan.addItemToInventory(item); - itemMan.updateInventory(); - } - } - } - Resource resourceType; - - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); - - if (transaction) - this.AddTransactionToWarehouse(pc.getObjectType(), pc.getObjectUUID(), TransactionType.WITHDRAWL, resourceType, amount); - - return true; - } - - public synchronized boolean withdraw(NPC npc, ItemBase ib, int amount, boolean addToInventory, boolean transaction) { - - if (npc == null) - return false; - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - if (amount <= 0) - return false; - - int oldAmount = this.resources.get(ib); - - if (oldAmount < amount) - return false; - - int hashID = ib.getHashID(); - int newAmount = oldAmount - amount; - boolean worked = false; - - switch (hashID) { - case 2308551: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 74856115: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case -317484979: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 2504297: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case -1741189964: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case -1603256692: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 74767: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1334770447: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1191391799: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 2559427: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 75173057: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case -1730704107: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 2977263: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 78329697: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case -2036290524: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 452320058: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case -1586349421: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case -472884509: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case -1596311545: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1532478436: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case -697973233: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case -1569826353: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case -1761257186: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - - if (!worked) - return false; - - this.resources.put(ib, newAmount); - Resource resourceType; - - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); - - if (transaction) - this.AddTransactionToWarehouse(npc.getObjectType(), npc.getObjectUUID(), TransactionType.WITHDRAWL, resourceType, amount); - - return true; - } - - public synchronized boolean transferResources(PlayerCharacter taxer, TaxResourcesMsg msg, ArrayList realmResources, float taxPercent, Warehouse toWarehouse) { - - for (int ibID : realmResources) { - - ItemBase ib = ItemBase.getItemBase(ibID); - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - int amount = (int) (this.resources.get(ib) * taxPercent); - - if (amount <= 0) { - msg.getResources().put(ib.getHashID(), 0); - continue; - } - - int oldAmount = this.resources.get(ib); - - if (oldAmount < amount) - amount = oldAmount; - - int hashID = ib.getHashID(); - int newAmount = oldAmount - amount; - - if (newAmount < amount) - continue; - - boolean worked = false; - - switch (hashID) { - case 2308551: - worked = DbManager.WarehouseQueries.updateGold(this, newAmount); - break; - case 74856115: - worked = DbManager.WarehouseQueries.updateStone(this, newAmount); - break; - case -317484979: - worked = DbManager.WarehouseQueries.updateTruesteel(this, newAmount); - break; - case 2504297: - worked = DbManager.WarehouseQueries.updateIron(this, newAmount); - break; - case -1741189964: - worked = DbManager.WarehouseQueries.updateAdamant(this, newAmount); - break; - case -1603256692: - worked = DbManager.WarehouseQueries.updateLumber(this, newAmount); - break; - case 74767: - worked = DbManager.WarehouseQueries.updateOak(this, newAmount); - break; - case 1334770447: - worked = DbManager.WarehouseQueries.updateBronzewood(this, newAmount); - break; - case 1191391799: - worked = DbManager.WarehouseQueries.updateMandrake(this, newAmount); - break; - case 2559427: - worked = DbManager.WarehouseQueries.updateCoal(this, newAmount); - break; - case 75173057: - worked = DbManager.WarehouseQueries.updateAgate(this, newAmount); - break; - case -1730704107: - worked = DbManager.WarehouseQueries.updateDiamond(this, newAmount); - break; - case 2977263: - worked = DbManager.WarehouseQueries.updateOnyx(this, newAmount); - break; - case 78329697: - worked = DbManager.WarehouseQueries.updateAzoth(this, newAmount); - break; - case -2036290524: - worked = DbManager.WarehouseQueries.updateOrichalk(this, newAmount); - break; - case 452320058: - worked = DbManager.WarehouseQueries.updateAntimony(this, newAmount); - break; - case -1586349421: - worked = DbManager.WarehouseQueries.updateSulfur(this, newAmount); - break; - case -472884509: - worked = DbManager.WarehouseQueries.updateQuicksilver(this, newAmount); - break; - case -1596311545: - worked = DbManager.WarehouseQueries.updateGalvor(this, newAmount); - break; - case 1532478436: - worked = DbManager.WarehouseQueries.updateWormwood(this, newAmount); - break; - case -697973233: - worked = DbManager.WarehouseQueries.updateObsidian(this, newAmount); - break; - case -1569826353: - worked = DbManager.WarehouseQueries.updateBloodstone(this, newAmount); - break; - case -1761257186: - worked = DbManager.WarehouseQueries.updateMithril(this, newAmount); - break; - } - - if (!worked) { - msg.getResources().put(ib.getHashID(), 0); - continue; - } - - msg.getResources().put(ib.getHashID(), amount); - - this.resources.put(ib, newAmount); - toWarehouse.depositRealmTaxes(taxer, ib, amount); - Resource resourceType; - - if (ib.getUUID() == 7) - resourceType = Resource.GOLD; - else - resourceType = Resource.valueOf(ib.getName().toUpperCase()); - - this.AddTransactionToWarehouse(taxer.getObjectType(), taxer.getObjectUUID(), TransactionType.TAXRESOURCE, resourceType, amount); - - } - return true; - } - - public synchronized boolean loot(PlayerCharacter pc, ItemBase ib, int amount, boolean addToInventory) { - - if (pc == null) - return false; - - if (ib == null) - return false; - - if (this.resources.get(ib) == null) - return false; - - if (amount <= 0) - return false; - - CharacterItemManager itemMan = pc.getCharItemManager(); - - if (itemMan == null) - return false; - - if (!itemMan.hasRoomInventory(ib.getWeight())) { - ChatManager.chatSystemInfo(pc, "You can not carry any more of that item."); - return false; - } - - int oldAmount = this.resources.get(ib); - - if (oldAmount < amount) - return false; - - int newAmount = oldAmount - amount; - - this.resources.put(ib, newAmount); - - if (addToInventory) { - if (ib.getUUID() == 7) { - - itemMan.addGoldToInventory(amount, false); - UpdateGoldMsg ugm = new UpdateGoldMsg(pc); - ugm.configure(); - Dispatch dispatch = Dispatch.borrow(pc, ugm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); - - itemMan.updateInventory(); - } else { - boolean itemWorked = false; - Item item = new Item(ib, pc.getObjectUUID(), OwnerType.PlayerCharacter, (byte) 0, (byte) 0, - (short) 1, (short) 1, true, false, ItemContainerType.INVENTORY, (byte) 0, - new ArrayList<>(), ""); - item.setNumOfItems(amount); - item.containerType = Enum.ItemContainerType.INVENTORY; - - try { - item = DbManager.ItemQueries.ADD_ITEM(item); - itemWorked = true; - } catch (Exception e) { - Logger.error(e); - } - if (itemWorked) { - itemMan.addItemToInventory(item); - itemMan.updateInventory(); - } - } - } - - return true; + WarehouseManager.warehouseByBuildingUUID.put(this.buildingUID, this); } @Override @@ -1279,7 +96,7 @@ public class Warehouse extends AbstractWorldObject { return; } - warehouseByBuildingUUID.put(this.buildingUID, this); + WarehouseManager.warehouseByBuildingUUID.put(this.buildingUID, this); city.setWarehouseBuildingID(this.buildingUID); } catch (Exception E) { Logger.info(this.getObjectUUID() + " failed"); @@ -1287,51 +104,4 @@ public class Warehouse extends AbstractWorldObject { } } - public boolean isEmpty() { - int amount = 0; - for (ItemBase ib : ItemBase.getResourceList()) { - if (amount > 0) - return false; - amount += resources.get(ib); - } - return true; - } - - public int getBuildingUID() { - return buildingUID; - } - - public void loadAllTransactions() { - this.transactions = DbManager.WarehouseQueries.GET_TRANSACTIONS_FOR_WAREHOUSE(this.buildingUID); - } - - public boolean AddTransactionToWarehouse(GameObjectType targetType, int targetUUID, TransactionType transactionType, Resource resource, int amount) { - - - if (!DbManager.WarehouseQueries.CREATE_TRANSACTION(this.buildingUID, targetType, targetUUID, transactionType, resource, amount, DateTime.now())) - return false; - - Transaction transaction = new Transaction(this.buildingUID, targetType, targetUUID, transactionType, resource, amount, DateTime.now()); - this.transactions.add(transaction); - return true; - } - - public ArrayList getTransactions() { - return transactions; - } - - public boolean isAboveCap(ItemBase ib, int deposit) { - int newAmount = this.resources.get(ib) + deposit; - return newAmount > Warehouse.getMaxResources().get(ib.getUUID()); - - } - - public boolean isResourceLocked(ItemBase itemBase) { - - Enum.ResourceType resourceType; - - resourceType = Enum.ResourceType.resourceLookup.get(itemBase.getUUID()); - - return resourceType.elementOf(this.lockedResourceTypes); - } -} +} \ No newline at end of file