From f3bfdd8a3661da7b7f0e48d7c098906dad998e4f Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 17 Mar 2024 09:47:00 -0400 Subject: [PATCH] Refactor warehouse part two. --- .../db/handlers/dbWarehouseHandler.java | 18 +++++ src/engine/devcmd/cmds/RemoveObjectCmd.java | 13 ++-- src/engine/gameManager/BuildingManager.java | 7 +- .../gameManager/MaintenanceManager.java | 67 ++++++++++--------- .../ArcViewAssetTransactionsMsgHandler.java | 11 ++- .../handlers/ManageCityAssetMsgHandler.java | 7 +- .../client/handlers/PlaceAssetMsgHandler.java | 2 +- .../client/handlers/TaxCityMsgHandler.java | 6 +- .../net/client/msg/ViewResourcesMessage.java | 2 +- src/engine/objects/Building.java | 12 ++-- src/engine/objects/CharacterItemManager.java | 10 ++- src/engine/objects/ItemFactory.java | 31 +++++---- src/engine/objects/Realm.java | 49 +++++++------- src/engine/objects/Warehouse.java | 30 ++++----- src/engine/server/world/WorldServer.java | 2 +- 15 files changed, 151 insertions(+), 116 deletions(-) diff --git a/src/engine/db/handlers/dbWarehouseHandler.java b/src/engine/db/handlers/dbWarehouseHandler.java index 786f1557..025311eb 100644 --- a/src/engine/db/handlers/dbWarehouseHandler.java +++ b/src/engine/db/handlers/dbWarehouseHandler.java @@ -82,6 +82,24 @@ public class dbWarehouseHandler extends dbHandlerBase { return transactionsList; } + public boolean UPDATE_WAREHOUSE(Warehouse warehouse) { + + JSONObject warehouseJSON = new JSONObject(warehouse.resources); + + try (Connection connection = DbManager.getConnection(); + PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `dyn_warehouse` SET `warehouse` = ? WHERE `cityUID` = ?")) { + + preparedStatement.setString(2, warehouseJSON.toString()); + preparedStatement.setInt(1, warehouse.city.getObjectUUID()); + + return (preparedStatement.executeUpdate() > 0); + + } catch (SQLException e) { + Logger.error(e); + } + return false; + } + public void LOAD_WAREHOUSES() { JSONParser jsonParser = new JSONParser(); diff --git a/src/engine/devcmd/cmds/RemoveObjectCmd.java b/src/engine/devcmd/cmds/RemoveObjectCmd.java index 4221b06a..dea5fbf2 100644 --- a/src/engine/devcmd/cmds/RemoveObjectCmd.java +++ b/src/engine/devcmd/cmds/RemoveObjectCmd.java @@ -13,7 +13,10 @@ import engine.Enum.BuildingGroup; import engine.Enum.DbObjectType; import engine.InterestManagement.WorldGrid; import engine.devcmd.AbstractDevCmd; -import engine.gameManager.*; +import engine.gameManager.BuildingManager; +import engine.gameManager.ChatManager; +import engine.gameManager.DbManager; +import engine.gameManager.ZoneManager; import engine.math.Vector3fImmutable; import engine.objects.*; @@ -128,10 +131,10 @@ public class RemoveObjectCmd extends AbstractDevCmd { if ((building.getBlueprint() != null) && (building.getBlueprint().getBuildingGroup() == BuildingGroup.WAREHOUSE)) { City city = City.getCity(building.getParentZone().playerCityUUID); - if (city != null) { - city.setWarehouseBuildingID(0); - } - Warehouse.warehouseByBuildingUUID.remove(building.getObjectUUID()); + + if (city != null) + city.warehouse = null; + } //remove cached shrines. diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index d0307464..9475cab7 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -219,7 +219,12 @@ public enum BuildingManager { break; case WAREHOUSE: - Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(building.getObjectUUID()); + City city = building.getCity(); + + if (city == null) + return true; + + Warehouse warehouse = city.warehouse; if (warehouse == null) return false; diff --git a/src/engine/gameManager/MaintenanceManager.java b/src/engine/gameManager/MaintenanceManager.java index 86307f92..fd5475fe 100644 --- a/src/engine/gameManager/MaintenanceManager.java +++ b/src/engine/gameManager/MaintenanceManager.java @@ -155,7 +155,7 @@ public enum MaintenanceManager { city = building.getCity(); if (city != null) - warehouse = city.getWarehouse(); + warehouse = city.warehouse; // Cache maintenance cost value @@ -199,22 +199,22 @@ public enum MaintenanceManager { hasResources = false; else { - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580000)); + resourceValue = warehouse.resources.get(Enum.ResourceType.STONE); if (resourceValue < 1500) hasResources = false; - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580004)); + resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER); if (resourceValue < 1500) hasResources = false; - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580017)); + resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR); if (resourceValue < 5) hasResources = false; - resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580018)); + resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD); if (resourceValue < 5) hasResources = false; @@ -248,14 +248,15 @@ public enum MaintenanceManager { if (overDraft > 0) { resourceValue = warehouse.resources.get(ItemBase.getItemBase(7)); + warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - overDraft); - if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - overDraft) == true) { - warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - overDraft); - Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, overDraft); - } else { - Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { + warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue); + Logger.error("gold update failed for warehouse of city:" + warehouse.city.getName()); return true; } + + Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, overDraft); } // Early exit as we're done if we're not an R8 tree @@ -268,48 +269,54 @@ public enum MaintenanceManager { // Withdraw Stone resourceValue = warehouse.resources.get(Enum.ResourceType.STONE); + warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 1500); - if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 1500) == true) { - warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 1500); - Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.STONE, 1500); - } else { - Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { + warehouse.resources.put(Enum.ResourceType.STONE, resourceValue); + Logger.error("stone update failed for warehouse of city:" + warehouse.city.getName()); return true; } + Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.STONE, 1500); + // Withdraw Lumber resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER); + warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 1500); - if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 1500) == true) { - warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 1500); - Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.LUMBER, 1500); - } else { - Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { + warehouse.resources.put(Enum.ResourceType.STONE, resourceValue); + Logger.error("lumber update failed for warehouse of city:" + warehouse.city.getName()); return true; } + Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.LUMBER, 1500); + // Withdraw Galvor resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR); + warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 5); - if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 5) == true) { - warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 5); - Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GALVOR, 5); - } else { - Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { + warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue); + Logger.error("GALVOR update failed for warehouse of city:" + warehouse.city.getName()); return true; } + Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GALVOR, 5); + + // Withdraw GWORMWOOD resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD); + warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 5); - if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 5) == true) { - warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 5); - Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.WORMWOOD, 5); - } else { - Logger.error("wyrmwood update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { + warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue); + Logger.error("wyrmwood update failed for warehouse of city:" + warehouse.city.getName()); + return true; } + Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.WORMWOOD, 5); + return true; } diff --git a/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java b/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java index 468a3796..a0861e08 100644 --- a/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java +++ b/src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java @@ -2,12 +2,15 @@ package engine.net.client.handlers; import engine.Enum; import engine.exception.MsgSendException; +import engine.gameManager.BuildingManager; import engine.gameManager.SessionManager; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.ArcViewAssetTransactionsMsg; import engine.net.client.msg.ClientNetMsg; +import engine.objects.Building; +import engine.objects.City; import engine.objects.PlayerCharacter; import engine.objects.Warehouse; @@ -37,7 +40,13 @@ public class ArcViewAssetTransactionsMsgHandler extends AbstractClientMsgHandler msg = (ArcViewAssetTransactionsMsg) baseMsg; - Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(msg.getWarehouseID()); + Building warehouseBuilding = BuildingManager.getBuilding(msg.getWarehouseID()); + City city = warehouseBuilding.getCity(); + + if (city == null) + return true; + + Warehouse warehouse = city.warehouse; if (warehouse == null) return true; diff --git a/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java b/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java index 66d434bd..1ae22679 100644 --- a/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java +++ b/src/engine/net/client/handlers/ManageCityAssetMsgHandler.java @@ -166,7 +166,12 @@ public class ManageCityAssetMsgHandler extends AbstractClientMsgHandler { return true; } - Warehouse warehouse = Warehouse.warehouseByBuildingUUID.get(building.getObjectUUID()); + City city = building.getCity(); + + if (city == null) + return true; + + Warehouse warehouse = city.warehouse; if (warehouse == null) return true; diff --git a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java index 84adaf8b..7a7826e0 100644 --- a/src/engine/net/client/handlers/PlaceAssetMsgHandler.java +++ b/src/engine/net/client/handlers/PlaceAssetMsgHandler.java @@ -529,7 +529,7 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler { if (validateCityBuildingPlacement(serverZone, msg, origin, player, buildingList) == false) return false; - if (cityObject.getWarehouse() != null) { + if (cityObject.warehouse != null) { PlaceAssetMsg.sendPlaceAssetError(origin, 50, ""); //"You can only have one warehouse" return false; } diff --git a/src/engine/net/client/handlers/TaxCityMsgHandler.java b/src/engine/net/client/handlers/TaxCityMsgHandler.java index 2cc4e825..511d7fb5 100644 --- a/src/engine/net/client/handlers/TaxCityMsgHandler.java +++ b/src/engine/net/client/handlers/TaxCityMsgHandler.java @@ -41,7 +41,7 @@ public class TaxCityMsgHandler extends AbstractClientMsgHandler { return true; } - if (city.getWarehouse() == null) { + if (city.warehouse == null) { ErrorPopupMsg.sendErrorMsg(player, "This city does not have a warehouse!"); return true; } @@ -57,7 +57,7 @@ public class TaxCityMsgHandler extends AbstractClientMsgHandler { return true; } - if (playerGuild.getOwnedCity().getWarehouse() == null) { + if (playerGuild.getOwnedCity().warehouse == null) { ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a warehouse!"); return true; } @@ -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().buildingUID)); + vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().warehouse.buildingUID)); vrm.configure(); Dispatch dispatch = Dispatch.borrow(player, msg); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); diff --git a/src/engine/net/client/msg/ViewResourcesMessage.java b/src/engine/net/client/msg/ViewResourcesMessage.java index b68ab8bb..c39df54d 100644 --- a/src/engine/net/client/msg/ViewResourcesMessage.java +++ b/src/engine/net/client/msg/ViewResourcesMessage.java @@ -78,7 +78,7 @@ public class ViewResourcesMessage extends ClientNetMsg { if (this.city == null) return false; - this.warehouseObject = this.city.getWarehouse(); + this.warehouseObject = this.city.warehouse; return this.warehouseObject != null; } diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index e7bd922c..1edfd95f 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -1426,21 +1426,21 @@ public class Building extends AbstractWorldObject { if (this.getCity() == null) return amount; - if (this.getCity().getWarehouse() == null) + if (this.getCity().warehouse == null) return amount; - if (this.getCity().getWarehouse().resources.get(ResourceType.GOLD) >= ResourceType.GOLD.deposit_limit) + if (this.getCity().warehouse.resources.get(ResourceType.GOLD) >= ResourceType.GOLD.deposit_limit) return amount; int profitAmount = (int) (amount * (taxAmount * .01f)); - if (this.getCity().getWarehouse().resources.get(ResourceType.GOLD) + profitAmount <= ResourceType.GOLD.deposit_limit) { - Warehouse.depositProfitTax(ResourceType.GOLD, profitAmount, this, this.getCity().getWarehouse()); + if (this.getCity().warehouse.resources.get(ResourceType.GOLD) + profitAmount <= ResourceType.GOLD.deposit_limit) { + Warehouse.depositProfitTax(ResourceType.GOLD, profitAmount, this, this.getCity().warehouse); return amount - profitAmount; } //overDrafting - int warehouseDeposit = ResourceType.GOLD.deposit_limit - this.getCity().getWarehouse().resources.get(ResourceType.GOLD); - Warehouse.depositProfitTax(ResourceType.GOLD, warehouseDeposit, this, this.getCity().getWarehouse()); + int warehouseDeposit = ResourceType.GOLD.deposit_limit - this.getCity().warehouse.resources.get(ResourceType.GOLD); + Warehouse.depositProfitTax(ResourceType.GOLD, warehouseDeposit, this, this.getCity().warehouse); return amount - warehouseDeposit; } diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index bcdd7c01..6a86ea43 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -25,10 +25,7 @@ import engine.net.client.msg.*; import engine.server.MBServerStatics; import org.pmw.tinylog.Logger; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; @@ -350,10 +347,11 @@ public class CharacterItemManager { break; case Warehouse: - Warehouse warehouse = (Warehouse) object; + Building warehouseBuilding = (Building) object; + Warehouse warehouse = Objects.requireNonNull(warehouseBuilding.getCity()).warehouse; if (amount < 0) { - if (!Warehouse.deposit((PlayerCharacter) this.absCharacter, this.getGoldInventory(), amount * -1, true, true,warehouse)) { + if (!Warehouse.deposit((PlayerCharacter) this.absCharacter, this.getGoldInventory(), amount * -1, true, true, warehouse)) { ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203); return false; diff --git a/src/engine/objects/ItemFactory.java b/src/engine/objects/ItemFactory.java index 5bfb135d..4359726b 100644 --- a/src/engine/objects/ItemFactory.java +++ b/src/engine/objects/ItemFactory.java @@ -116,7 +116,7 @@ public class ItemFactory { city.transactionLock.writeLock().lock(); try { - Warehouse cityWarehouse = city.getWarehouse(); + Warehouse cityWarehouse = city.warehouse; if (cityWarehouse != null && forge.assetIsProtected()) useWarehouse = true; @@ -163,7 +163,7 @@ public class ItemFactory { if (overdraft > 0) if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { - Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name); return null; } @@ -431,8 +431,7 @@ public class ItemFactory { if (overdraft > 0 && useWarehouse) if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { - //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name); return null; } @@ -460,7 +459,7 @@ public class ItemFactory { if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name); return null; } } @@ -484,7 +483,7 @@ public class ItemFactory { if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name); return null; } } @@ -538,7 +537,7 @@ public class ItemFactory { if (overdraft > 0) if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { //ChatManager.chatGuildError(pc, "Failed to create Item"); - Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name); return null; } @@ -547,7 +546,7 @@ public class ItemFactory { if (galvorAmount > 0) { if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GALVOR, galvorAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + template.item_base_name); - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); return null; } } @@ -555,7 +554,7 @@ public class ItemFactory { if (wormwoodAmount > 0) { if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.WORMWOOD, wormwoodAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse!" + template.item_base_name); - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); return null; } } @@ -790,7 +789,7 @@ public class ItemFactory { try { - Warehouse cityWarehouse = city.getWarehouse(); + Warehouse cityWarehouse = city.warehouse; if (cityWarehouse != null && forge.assetIsProtected()) useWarehouse = true; @@ -916,12 +915,12 @@ public class ItemFactory { if (overdraft > 0) { if (pc != null) { if (!Warehouse.withdraw(cityWarehouse, pc, Enum.ResourceType.GOLD, overdraft, false, true)) { - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); return null; } } else { if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); return null; } } @@ -967,12 +966,12 @@ public class ItemFactory { if (pc != null) { if (!Warehouse.withdraw(cityWarehouse, pc, Enum.ResourceType.GOLD, overdraft, false, true)) { - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); return null; } } else { if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); return null; } } @@ -983,7 +982,7 @@ public class ItemFactory { //ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse"); if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GALVOR, galvorAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + template.item_base_name); - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); return null; } } @@ -992,7 +991,7 @@ public class ItemFactory { //ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse"); if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.WORMWOOD, wormwoodAmount, true)) { ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse for " + template.item_base_name); - Logger.error("Warehouse with UID of" + cityWarehouse.getObjectUUID() + "Failed to Withdrawl "); + Logger.error("Warehouse for city " + cityWarehouse.city.getName() + "Failed to Withdrawl "); return null; } diff --git a/src/engine/objects/Realm.java b/src/engine/objects/Realm.java index ba7e50b6..e254b762 100644 --- a/src/engine/objects/Realm.java +++ b/src/engine/objects/Realm.java @@ -227,7 +227,7 @@ public class Realm { // Must have the required resources in warehouse to claim realm - warehouse = city.getWarehouse(); + warehouse = city.warehouse; if (warehouse == null) { ErrorPopupMsg.sendErrorPopup(player, 188); // You must have a warehouse to become a capital @@ -267,52 +267,49 @@ public class Realm { // Remove resources from warehouse before claiming realm resourceValue = warehouse.resources.get(Enum.ResourceType.GOLD); + warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - 5000000); - if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - 5000000) == true) { - warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - 5000000); - Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, 5000000); - } else { - Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { + Logger.error("gold update failed for warehouse of city:" + warehouse.city.getName()); + warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue); return false; } + Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, 5000000); + resourceValue = warehouse.resources.get(Enum.ResourceType.STONE); + warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 8000); - if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 8000) == true) { - warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 8000); - Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.STONE, 8000); - } else { - Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { + Logger.error("stone update failed for warehouse of city:" + warehouse.city.getName()); + warehouse.resources.put(Enum.ResourceType.STONE, resourceValue); return false; } resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER); + warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 8000); - if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 8000) == true) { - warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 8000); - Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.LUMBER, 8000); - } else { - Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { + Logger.error("lumber update failed for warehouse of city:" + warehouse.city.getName()); + warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue); return false; } resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR); + warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 15); - if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 15) == true) { - warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 15); - Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GALVOR, 15); - } else { - Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { + Logger.error("GALVOR update failed for warehouse of city:" + warehouse.city.getName()); + warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue); return false; } resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD); + warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 15); - if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 15) == true) { - warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 15); - Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.WORMWOOD, 15); - } else { - Logger.error("wormwood update failed for warehouse of UUID:" + warehouse.getObjectUUID()); + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { + Logger.error("WORMWOOD update failed for warehouse of city:" + warehouse.city.getName()); + warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue); return false; } diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index 7c3e617f..df69028d 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -166,7 +166,7 @@ public class Warehouse { boolean worked; warehouse.lockedResourceTypes.remove(resourceType); - worked = DbManager.WarehouseQueries.updateWarehouse(warehouse); + worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse); if (worked) { ViewResourcesMessage vrm = new ViewResourcesMessage(player); @@ -183,7 +183,7 @@ public class Warehouse { boolean worked; warehouse.lockedResourceTypes.add(resourceType); - worked = DbManager.WarehouseQueries.updateWarehouse(warehouse); + worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse); if (worked) { warehouse.lockedResourceTypes.add(resourceType); @@ -273,7 +273,7 @@ public class Warehouse { warehouse.resources.put(resourceType, newAmount); - if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { warehouse.resources.put(resourceType, oldAmount); return false; } @@ -299,7 +299,7 @@ public class Warehouse { warehouse.resources.put(resourceType, newAmount); - if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { warehouse.resources.put(resourceType, oldAmount); return false; } @@ -316,7 +316,7 @@ public class Warehouse { int newAmount = oldAmount + amount; warehouse.resources.put(resourceType, newAmount); - if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { warehouse.resources.put(resourceType, oldAmount); return; } @@ -338,7 +338,7 @@ public class Warehouse { warehouse.resources.put(resourceType, newAmount); - if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { warehouse.resources.put(resourceType, oldAmount); return; } @@ -365,7 +365,7 @@ public class Warehouse { warehouse.resources.put(resourceType, newAmount); - if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { warehouse.resources.put(resourceType, oldAmount); return false; } @@ -400,13 +400,14 @@ public class Warehouse { if (newAmount < amount) continue; - if (!WithdrawApproved(resourceType, amount, warehouse)) { + msg.getResources().put(resourceType.hash, amount); + + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { msg.getResources().put(resourceType.hash, 0); + warehouse.resources.put(resourceType, oldAmount); continue; } - msg.getResources().put(resourceType.hash, amount); - warehouse.resources.put(resourceType, newAmount); depositRealmTaxes(taxer, resourceType, amount, warehouse); Enum.ResourceType resource; @@ -456,7 +457,7 @@ public class Warehouse { warehouse.resources.put(resourceType, newAmount); - if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { + if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) { warehouse.resources.put(resourceType, oldAmount); return false; } @@ -604,11 +605,4 @@ public class Warehouse { return resourceType.elementOf(warehouse.lockedResourceTypes); } - @Override - public void updateDatabase() { - // TODO Auto-generated method stub - - - } - } \ No newline at end of file diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 8bd8427a..de1084a0 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -453,7 +453,7 @@ public class WorldServer { Enum.ResourceType.InitializeResourceTypes(); Logger.info("Loading Warehouse data."); - DbManager.WarehouseQueries.LOAD_ALL_WAREHOUSES(); + DbManager.WarehouseQueries.LOAD_WAREHOUSES(); Logger.info("Loading Runegate data."); Runegate.loadAllRunegates();