Browse Source

Refactor warehouse part two.

combat-2
MagicBot 8 months ago
parent
commit
f3bfdd8a36
  1. 18
      src/engine/db/handlers/dbWarehouseHandler.java
  2. 13
      src/engine/devcmd/cmds/RemoveObjectCmd.java
  3. 7
      src/engine/gameManager/BuildingManager.java
  4. 67
      src/engine/gameManager/MaintenanceManager.java
  5. 11
      src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java
  6. 7
      src/engine/net/client/handlers/ManageCityAssetMsgHandler.java
  7. 2
      src/engine/net/client/handlers/PlaceAssetMsgHandler.java
  8. 6
      src/engine/net/client/handlers/TaxCityMsgHandler.java
  9. 2
      src/engine/net/client/msg/ViewResourcesMessage.java
  10. 12
      src/engine/objects/Building.java
  11. 10
      src/engine/objects/CharacterItemManager.java
  12. 31
      src/engine/objects/ItemFactory.java
  13. 49
      src/engine/objects/Realm.java
  14. 30
      src/engine/objects/Warehouse.java
  15. 2
      src/engine/server/world/WorldServer.java

18
src/engine/db/handlers/dbWarehouseHandler.java

@ -82,6 +82,24 @@ public class dbWarehouseHandler extends dbHandlerBase {
return transactionsList; 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() { public void LOAD_WAREHOUSES() {
JSONParser jsonParser = new JSONParser(); JSONParser jsonParser = new JSONParser();

13
src/engine/devcmd/cmds/RemoveObjectCmd.java

@ -13,7 +13,10 @@ import engine.Enum.BuildingGroup;
import engine.Enum.DbObjectType; import engine.Enum.DbObjectType;
import engine.InterestManagement.WorldGrid; import engine.InterestManagement.WorldGrid;
import engine.devcmd.AbstractDevCmd; 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.math.Vector3fImmutable;
import engine.objects.*; import engine.objects.*;
@ -128,10 +131,10 @@ public class RemoveObjectCmd extends AbstractDevCmd {
if ((building.getBlueprint() != null) && (building.getBlueprint().getBuildingGroup() == BuildingGroup.WAREHOUSE)) { if ((building.getBlueprint() != null) && (building.getBlueprint().getBuildingGroup() == BuildingGroup.WAREHOUSE)) {
City city = City.getCity(building.getParentZone().playerCityUUID); City city = City.getCity(building.getParentZone().playerCityUUID);
if (city != null) {
city.setWarehouseBuildingID(0); if (city != null)
} city.warehouse = null;
Warehouse.warehouseByBuildingUUID.remove(building.getObjectUUID());
} }
//remove cached shrines. //remove cached shrines.

7
src/engine/gameManager/BuildingManager.java

@ -219,7 +219,12 @@ public enum BuildingManager {
break; break;
case WAREHOUSE: 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) if (warehouse == null)
return false; return false;

67
src/engine/gameManager/MaintenanceManager.java

@ -155,7 +155,7 @@ public enum MaintenanceManager {
city = building.getCity(); city = building.getCity();
if (city != null) if (city != null)
warehouse = city.getWarehouse(); warehouse = city.warehouse;
// Cache maintenance cost value // Cache maintenance cost value
@ -199,22 +199,22 @@ public enum MaintenanceManager {
hasResources = false; hasResources = false;
else { else {
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580000)); resourceValue = warehouse.resources.get(Enum.ResourceType.STONE);
if (resourceValue < 1500) if (resourceValue < 1500)
hasResources = false; hasResources = false;
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580004)); resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER);
if (resourceValue < 1500) if (resourceValue < 1500)
hasResources = false; hasResources = false;
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580017)); resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR);
if (resourceValue < 5) if (resourceValue < 5)
hasResources = false; hasResources = false;
resourceValue = warehouse.resources.get(ItemBase.getItemBase(1580018)); resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD);
if (resourceValue < 5) if (resourceValue < 5)
hasResources = false; hasResources = false;
@ -248,14 +248,15 @@ public enum MaintenanceManager {
if (overDraft > 0) { if (overDraft > 0) {
resourceValue = warehouse.resources.get(ItemBase.getItemBase(7)); resourceValue = warehouse.resources.get(ItemBase.getItemBase(7));
warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - overDraft);
if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - overDraft) == true) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - overDraft); warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, overDraft); Logger.error("gold update failed for warehouse of city:" + warehouse.city.getName());
} else {
Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return true; 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 // Early exit as we're done if we're not an R8 tree
@ -268,48 +269,54 @@ public enum MaintenanceManager {
// Withdraw Stone // Withdraw Stone
resourceValue = warehouse.resources.get(Enum.ResourceType.STONE); resourceValue = warehouse.resources.get(Enum.ResourceType.STONE);
warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 1500);
if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 1500) == true) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 1500); warehouse.resources.put(Enum.ResourceType.STONE, resourceValue);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.STONE, 1500); Logger.error("stone update failed for warehouse of city:" + warehouse.city.getName());
} else {
Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return true; return true;
} }
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.STONE, 1500);
// Withdraw Lumber // Withdraw Lumber
resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER); resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER);
warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 1500);
if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 1500) == true) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 1500); warehouse.resources.put(Enum.ResourceType.STONE, resourceValue);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.LUMBER, 1500); Logger.error("lumber update failed for warehouse of city:" + warehouse.city.getName());
} else {
Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return true; return true;
} }
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.LUMBER, 1500);
// Withdraw Galvor // Withdraw Galvor
resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR); resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR);
warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 5);
if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 5) == true) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 5); warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GALVOR, 5); Logger.error("GALVOR update failed for warehouse of city:" + warehouse.city.getName());
} else {
Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return true; 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); resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD);
warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 5);
if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 5) == true) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 5); warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue);
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.WORMWOOD, 5); Logger.error("wyrmwood update failed for warehouse of city:" + warehouse.city.getName());
} else { return true;
Logger.error("wyrmwood update failed for warehouse of UUID:" + warehouse.getObjectUUID());
} }
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, building.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.WORMWOOD, 5);
return true; return true;
} }

11
src/engine/net/client/handlers/ArcViewAssetTransactionsMsgHandler.java

@ -2,12 +2,15 @@ package engine.net.client.handlers;
import engine.Enum; import engine.Enum;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.BuildingManager;
import engine.gameManager.SessionManager; import engine.gameManager.SessionManager;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.msg.ArcViewAssetTransactionsMsg; import engine.net.client.msg.ArcViewAssetTransactionsMsg;
import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ClientNetMsg;
import engine.objects.Building;
import engine.objects.City;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import engine.objects.Warehouse; import engine.objects.Warehouse;
@ -37,7 +40,13 @@ public class ArcViewAssetTransactionsMsgHandler extends AbstractClientMsgHandler
msg = (ArcViewAssetTransactionsMsg) baseMsg; 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) if (warehouse == null)
return true; return true;

7
src/engine/net/client/handlers/ManageCityAssetMsgHandler.java

@ -166,7 +166,12 @@ public class ManageCityAssetMsgHandler extends AbstractClientMsgHandler {
return true; 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) if (warehouse == null)
return true; return true;

2
src/engine/net/client/handlers/PlaceAssetMsgHandler.java

@ -529,7 +529,7 @@ public class PlaceAssetMsgHandler extends AbstractClientMsgHandler {
if (validateCityBuildingPlacement(serverZone, msg, origin, player, buildingList) == false) if (validateCityBuildingPlacement(serverZone, msg, origin, player, buildingList) == false)
return false; return false;
if (cityObject.getWarehouse() != null) { if (cityObject.warehouse != null) {
PlaceAssetMsg.sendPlaceAssetError(origin, 50, ""); //"You can only have one warehouse" PlaceAssetMsg.sendPlaceAssetError(origin, 50, ""); //"You can only have one warehouse"
return false; return false;
} }

6
src/engine/net/client/handlers/TaxCityMsgHandler.java

@ -41,7 +41,7 @@ public class TaxCityMsgHandler extends AbstractClientMsgHandler {
return true; return true;
} }
if (city.getWarehouse() == null) { if (city.warehouse == null) {
ErrorPopupMsg.sendErrorMsg(player, "This city does not have a warehouse!"); ErrorPopupMsg.sendErrorMsg(player, "This city does not have a warehouse!");
return true; return true;
} }
@ -57,7 +57,7 @@ public class TaxCityMsgHandler extends AbstractClientMsgHandler {
return true; return true;
} }
if (playerGuild.getOwnedCity().getWarehouse() == null) { if (playerGuild.getOwnedCity().warehouse == null) {
ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a warehouse!"); ErrorPopupMsg.sendErrorMsg(player, "Your Guild needs to own a warehouse!");
return true; return true;
} }
@ -111,7 +111,7 @@ public class TaxCityMsgHandler extends AbstractClientMsgHandler {
ViewResourcesMessage vrm = new ViewResourcesMessage(player); ViewResourcesMessage vrm = new ViewResourcesMessage(player);
vrm.setGuild(building.getGuild()); vrm.setGuild(building.getGuild());
vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().getWarehouse().buildingUID)); vrm.setWarehouseBuilding(BuildingManager.getBuildingFromCache(building.getCity().warehouse.buildingUID));
vrm.configure(); vrm.configure();
Dispatch dispatch = Dispatch.borrow(player, msg); Dispatch dispatch = Dispatch.borrow(player, msg);
DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY);

2
src/engine/net/client/msg/ViewResourcesMessage.java

@ -78,7 +78,7 @@ public class ViewResourcesMessage extends ClientNetMsg {
if (this.city == null) if (this.city == null)
return false; return false;
this.warehouseObject = this.city.getWarehouse(); this.warehouseObject = this.city.warehouse;
return this.warehouseObject != null; return this.warehouseObject != null;
} }

12
src/engine/objects/Building.java

@ -1426,21 +1426,21 @@ public class Building extends AbstractWorldObject {
if (this.getCity() == null) if (this.getCity() == null)
return amount; return amount;
if (this.getCity().getWarehouse() == null) if (this.getCity().warehouse == null)
return amount; 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; return amount;
int profitAmount = (int) (amount * (taxAmount * .01f)); int profitAmount = (int) (amount * (taxAmount * .01f));
if (this.getCity().getWarehouse().resources.get(ResourceType.GOLD) + profitAmount <= ResourceType.GOLD.deposit_limit) { if (this.getCity().warehouse.resources.get(ResourceType.GOLD) + profitAmount <= ResourceType.GOLD.deposit_limit) {
Warehouse.depositProfitTax(ResourceType.GOLD, profitAmount, this, this.getCity().getWarehouse()); Warehouse.depositProfitTax(ResourceType.GOLD, profitAmount, this, this.getCity().warehouse);
return amount - profitAmount; return amount - profitAmount;
} }
//overDrafting //overDrafting
int warehouseDeposit = ResourceType.GOLD.deposit_limit - this.getCity().getWarehouse().resources.get(ResourceType.GOLD); int warehouseDeposit = ResourceType.GOLD.deposit_limit - this.getCity().warehouse.resources.get(ResourceType.GOLD);
Warehouse.depositProfitTax(ResourceType.GOLD, warehouseDeposit, this, this.getCity().getWarehouse()); Warehouse.depositProfitTax(ResourceType.GOLD, warehouseDeposit, this, this.getCity().warehouse);
return amount - warehouseDeposit; return amount - warehouseDeposit;
} }

10
src/engine/objects/CharacterItemManager.java

@ -25,10 +25,7 @@ import engine.net.client.msg.*;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -350,10 +347,11 @@ public class CharacterItemManager {
break; break;
case Warehouse: case Warehouse:
Warehouse warehouse = (Warehouse) object; Building warehouseBuilding = (Building) object;
Warehouse warehouse = Objects.requireNonNull(warehouseBuilding.getCity()).warehouse;
if (amount < 0) { 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); ErrorPopupMsg.sendErrorPopup((PlayerCharacter) this.absCharacter, 203);
return false; return false;

31
src/engine/objects/ItemFactory.java

@ -116,7 +116,7 @@ public class ItemFactory {
city.transactionLock.writeLock().lock(); city.transactionLock.writeLock().lock();
try { try {
Warehouse cityWarehouse = city.getWarehouse(); Warehouse cityWarehouse = city.warehouse;
if (cityWarehouse != null && forge.assetIsProtected()) if (cityWarehouse != null && forge.assetIsProtected())
useWarehouse = true; useWarehouse = true;
@ -163,7 +163,7 @@ public class ItemFactory {
if (overdraft > 0) if (overdraft > 0)
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { 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; return null;
} }
@ -431,8 +431,7 @@ public class ItemFactory {
if (overdraft > 0 && useWarehouse) if (overdraft > 0 && useWarehouse)
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) {
//ChatManager.chatGuildError(pc, "Failed to create Item"); Logger.error("Warehouse for city " + cityWarehouse.city.getName() + " Failed to Create Item." + template.item_base_name);
Logger.error("Warehouse With UID of " + cityWarehouse.UID + " Failed to Create Item." + template.item_base_name);
return null; return null;
} }
@ -460,7 +459,7 @@ public class ItemFactory {
if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) { if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) {
//ChatManager.chatGuildError(pc, "Failed to create Item"); //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; return null;
} }
} }
@ -484,7 +483,7 @@ public class ItemFactory {
if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) { if (!Warehouse.withdraw(cityWarehouse, npc, ibResources, amount, true)) {
//ChatManager.chatGuildError(pc, "Failed to create Item"); //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; return null;
} }
} }
@ -538,7 +537,7 @@ public class ItemFactory {
if (overdraft > 0) if (overdraft > 0)
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) {
//ChatManager.chatGuildError(pc, "Failed to create Item"); //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; return null;
} }
@ -547,7 +546,7 @@ public class ItemFactory {
if (galvorAmount > 0) { if (galvorAmount > 0) {
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GALVOR, galvorAmount, true)) { if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GALVOR, galvorAmount, true)) {
ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + template.item_base_name); 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; return null;
} }
} }
@ -555,7 +554,7 @@ public class ItemFactory {
if (wormwoodAmount > 0) { if (wormwoodAmount > 0) {
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.WORMWOOD, wormwoodAmount, true)) { if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.WORMWOOD, wormwoodAmount, true)) {
ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse!" + template.item_base_name); 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; return null;
} }
} }
@ -790,7 +789,7 @@ public class ItemFactory {
try { try {
Warehouse cityWarehouse = city.getWarehouse(); Warehouse cityWarehouse = city.warehouse;
if (cityWarehouse != null && forge.assetIsProtected()) if (cityWarehouse != null && forge.assetIsProtected())
useWarehouse = true; useWarehouse = true;
@ -916,12 +915,12 @@ public class ItemFactory {
if (overdraft > 0) { if (overdraft > 0) {
if (pc != null) { if (pc != null) {
if (!Warehouse.withdraw(cityWarehouse, pc, Enum.ResourceType.GOLD, overdraft, false, true)) { 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; return null;
} }
} else { } else {
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { 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; return null;
} }
} }
@ -967,12 +966,12 @@ public class ItemFactory {
if (pc != null) { if (pc != null) {
if (!Warehouse.withdraw(cityWarehouse, pc, Enum.ResourceType.GOLD, overdraft, false, true)) { 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; return null;
} }
} else { } else {
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GOLD, overdraft, true)) { 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; return null;
} }
} }
@ -983,7 +982,7 @@ public class ItemFactory {
//ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse"); //ChatManager.chatGuildInfo(pc, "Withdrawing " + galvorAmount + " galvor from warehouse");
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GALVOR, galvorAmount, true)) { if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.GALVOR, galvorAmount, true)) {
ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Galvor from warehouse!" + template.item_base_name); 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; return null;
} }
} }
@ -992,7 +991,7 @@ public class ItemFactory {
//ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse"); //ChatManager.chatGuildInfo(pc, "Withdrawing " + wormwoodAmount + " wormwood from warehouse");
if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.WORMWOOD, wormwoodAmount, true)) { if (!Warehouse.withdraw(cityWarehouse, npc, Enum.ResourceType.WORMWOOD, wormwoodAmount, true)) {
ErrorPopupMsg.sendErrorMsg(pc, "Failed to withdraw Wormwood from warehouse for " + template.item_base_name); 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; return null;
} }

49
src/engine/objects/Realm.java

@ -227,7 +227,7 @@ public class Realm {
// Must have the required resources in warehouse to claim realm // Must have the required resources in warehouse to claim realm
warehouse = city.getWarehouse(); warehouse = city.warehouse;
if (warehouse == null) { if (warehouse == null) {
ErrorPopupMsg.sendErrorPopup(player, 188); // You must have a warehouse to become a capital 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 // Remove resources from warehouse before claiming realm
resourceValue = warehouse.resources.get(Enum.ResourceType.GOLD); resourceValue = warehouse.resources.get(Enum.ResourceType.GOLD);
warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - 5000000);
if (DbManager.WarehouseQueries.updateGold(warehouse, resourceValue - 5000000) == true) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue - 5000000); Logger.error("gold update failed for warehouse of city:" + warehouse.city.getName());
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, 5000000); warehouse.resources.put(Enum.ResourceType.GOLD, resourceValue);
} else {
Logger.error("gold update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false; return false;
} }
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GOLD, 5000000);
resourceValue = warehouse.resources.get(Enum.ResourceType.STONE); resourceValue = warehouse.resources.get(Enum.ResourceType.STONE);
warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 8000);
if (DbManager.WarehouseQueries.updateStone(warehouse, resourceValue - 8000) == true) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(Enum.ResourceType.STONE, resourceValue - 8000); Logger.error("stone update failed for warehouse of city:" + warehouse.city.getName());
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.STONE, 8000); warehouse.resources.put(Enum.ResourceType.STONE, resourceValue);
} else {
Logger.error("stone update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false; return false;
} }
resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER); resourceValue = warehouse.resources.get(Enum.ResourceType.LUMBER);
warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 8000);
if (DbManager.WarehouseQueries.updateLumber(warehouse, resourceValue - 8000) == true) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue - 8000); Logger.error("lumber update failed for warehouse of city:" + warehouse.city.getName());
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.LUMBER, 8000); warehouse.resources.put(Enum.ResourceType.LUMBER, resourceValue);
} else {
Logger.error("lumber update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false; return false;
} }
resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR); resourceValue = warehouse.resources.get(Enum.ResourceType.GALVOR);
warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 15);
if (DbManager.WarehouseQueries.updateGalvor(warehouse, resourceValue - 15) == true) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue - 15); Logger.error("GALVOR update failed for warehouse of city:" + warehouse.city.getName());
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.GALVOR, 15); warehouse.resources.put(Enum.ResourceType.GALVOR, resourceValue);
} else {
Logger.error("galvor update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false; return false;
} }
resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD); resourceValue = warehouse.resources.get(Enum.ResourceType.WORMWOOD);
warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 15);
if (DbManager.WarehouseQueries.updateWormwood(warehouse, resourceValue - 15) == true) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue - 15); Logger.error("WORMWOOD update failed for warehouse of city:" + warehouse.city.getName());
Warehouse.AddTransactionToWarehouse(warehouse, Enum.GameObjectType.Building, tol.getObjectUUID(), Enum.TransactionType.WITHDRAWL, Enum.ResourceType.WORMWOOD, 15); warehouse.resources.put(Enum.ResourceType.WORMWOOD, resourceValue);
} else {
Logger.error("wormwood update failed for warehouse of UUID:" + warehouse.getObjectUUID());
return false; return false;
} }

30
src/engine/objects/Warehouse.java

@ -166,7 +166,7 @@ public class Warehouse {
boolean worked; boolean worked;
warehouse.lockedResourceTypes.remove(resourceType); warehouse.lockedResourceTypes.remove(resourceType);
worked = DbManager.WarehouseQueries.updateWarehouse(warehouse); worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse);
if (worked) { if (worked) {
ViewResourcesMessage vrm = new ViewResourcesMessage(player); ViewResourcesMessage vrm = new ViewResourcesMessage(player);
@ -183,7 +183,7 @@ public class Warehouse {
boolean worked; boolean worked;
warehouse.lockedResourceTypes.add(resourceType); warehouse.lockedResourceTypes.add(resourceType);
worked = DbManager.WarehouseQueries.updateWarehouse(warehouse); worked = DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse);
if (worked) { if (worked) {
warehouse.lockedResourceTypes.add(resourceType); warehouse.lockedResourceTypes.add(resourceType);
@ -273,7 +273,7 @@ public class Warehouse {
warehouse.resources.put(resourceType, newAmount); warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount); warehouse.resources.put(resourceType, oldAmount);
return false; return false;
} }
@ -299,7 +299,7 @@ public class Warehouse {
warehouse.resources.put(resourceType, newAmount); warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount); warehouse.resources.put(resourceType, oldAmount);
return false; return false;
} }
@ -316,7 +316,7 @@ public class Warehouse {
int newAmount = oldAmount + amount; int newAmount = oldAmount + amount;
warehouse.resources.put(resourceType, newAmount); warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount); warehouse.resources.put(resourceType, oldAmount);
return; return;
} }
@ -338,7 +338,7 @@ public class Warehouse {
warehouse.resources.put(resourceType, newAmount); warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount); warehouse.resources.put(resourceType, oldAmount);
return; return;
} }
@ -365,7 +365,7 @@ public class Warehouse {
warehouse.resources.put(resourceType, newAmount); warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount); warehouse.resources.put(resourceType, oldAmount);
return false; return false;
} }
@ -400,13 +400,14 @@ public class Warehouse {
if (newAmount < amount) if (newAmount < amount)
continue; continue;
if (!WithdrawApproved(resourceType, amount, warehouse)) { msg.getResources().put(resourceType.hash, amount);
if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
msg.getResources().put(resourceType.hash, 0); msg.getResources().put(resourceType.hash, 0);
warehouse.resources.put(resourceType, oldAmount);
continue; continue;
} }
msg.getResources().put(resourceType.hash, amount);
warehouse.resources.put(resourceType, newAmount); warehouse.resources.put(resourceType, newAmount);
depositRealmTaxes(taxer, resourceType, amount, warehouse); depositRealmTaxes(taxer, resourceType, amount, warehouse);
Enum.ResourceType resource; Enum.ResourceType resource;
@ -456,7 +457,7 @@ public class Warehouse {
warehouse.resources.put(resourceType, newAmount); warehouse.resources.put(resourceType, newAmount);
if (!DbManager.WarehouseQueries.updateWarehouse(warehouse)) { if (!DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse)) {
warehouse.resources.put(resourceType, oldAmount); warehouse.resources.put(resourceType, oldAmount);
return false; return false;
} }
@ -604,11 +605,4 @@ public class Warehouse {
return resourceType.elementOf(warehouse.lockedResourceTypes); return resourceType.elementOf(warehouse.lockedResourceTypes);
} }
@Override
public void updateDatabase() {
// TODO Auto-generated method stub
}
} }

2
src/engine/server/world/WorldServer.java

@ -453,7 +453,7 @@ public class WorldServer {
Enum.ResourceType.InitializeResourceTypes(); Enum.ResourceType.InitializeResourceTypes();
Logger.info("Loading Warehouse data."); Logger.info("Loading Warehouse data.");
DbManager.WarehouseQueries.LOAD_ALL_WAREHOUSES(); DbManager.WarehouseQueries.LOAD_WAREHOUSES();
Logger.info("Loading Runegate data."); Logger.info("Loading Runegate data.");
Runegate.loadAllRunegates(); Runegate.loadAllRunegates();

Loading…
Cancel
Save