From 023057668ac30d201208d17da174ae198f40911b Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Mon, 20 May 2024 13:34:03 -0500 Subject: [PATCH] attempted warehouse delay issue resolution --- .../db/handlers/dbWarehouseHandler.java | 4 +- src/engine/objects/CharacterItemManager.java | 4 ++ src/engine/objects/PlayerCharacter.java | 17 ++++++ src/engine/objects/Warehouse.java | 56 ++++++++++--------- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/engine/db/handlers/dbWarehouseHandler.java b/src/engine/db/handlers/dbWarehouseHandler.java index 677e67eb..8d410a58 100644 --- a/src/engine/db/handlers/dbWarehouseHandler.java +++ b/src/engine/db/handlers/dbWarehouseHandler.java @@ -45,7 +45,7 @@ public class dbWarehouseHandler extends dbHandlerBase { list.add(building); break; case "warehouse": - Warehouse warehouse = new Warehouse(rs); + Warehouse warehouse = new Warehouse(rs, depositQueItem); DbManager.addToCache(warehouse); list.add(warehouse); break; @@ -543,7 +543,7 @@ public class dbWarehouseHandler extends dbHandlerBase { ResultSet rs = preparedStatement.executeQuery(); while (rs.next()) { - warehouse = new Warehouse(rs); + warehouse = new Warehouse(rs, depositQueItem); warehouse.runAfterLoad(); warehouse.loadAllTransactions(); } diff --git a/src/engine/objects/CharacterItemManager.java b/src/engine/objects/CharacterItemManager.java index 80c8950b..d33531b9 100644 --- a/src/engine/objects/CharacterItemManager.java +++ b/src/engine/objects/CharacterItemManager.java @@ -70,6 +70,8 @@ public class CharacterItemManager { */ private byte equipVer = (byte) 0; + public boolean updateLock = false; + public CharacterItemManager(AbstractCharacter ac) { super(); this.absCharacter = ac; @@ -2286,6 +2288,8 @@ public class CharacterItemManager { if (this.absCharacter.getObjectType().equals(GameObjectType.PlayerCharacter) == false) return; + if(this.updateLock) + return; PlayerCharacter pc = (PlayerCharacter) this.absCharacter; UpdateInventoryMsg updateInventoryMsg = new UpdateInventoryMsg(inventory, this.getBank(), this.getGoldInventory(), add); diff --git a/src/engine/objects/PlayerCharacter.java b/src/engine/objects/PlayerCharacter.java index c4e9abe2..31ff999c 100644 --- a/src/engine/objects/PlayerCharacter.java +++ b/src/engine/objects/PlayerCharacter.java @@ -178,6 +178,9 @@ public class PlayerCharacter extends AbstractCharacter { public float ZergMultiplier = 1.0f; public int mineAppliedID = 0; + public boolean depositingWarehouse = false; + public Building warehouseBuilding; + /** * No Id Constructor */ @@ -4885,6 +4888,20 @@ public class PlayerCharacter extends AbstractCharacter { this.updateLock.writeLock().unlock(); } } + if(this.depositingWarehouse){ + long sinceLast = System.currentTimeMillis() - this.getTimestamps().get("lastDepositWarehouse"); + if(sinceLast > 1000) { + this.depositingWarehouse = false; + ViewResourcesMessage vrm = new ViewResourcesMessage(this); + vrm.setGuild(this.getGuild()); + vrm.setWarehouseBuilding(this.warehouseBuilding); + vrm.configure(); + Dispatch dispatch = Dispatch.borrow(this, vrm); + DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + this.charItemManager.updateLock = false; + this.charItemManager.updateInventory(); + } + } } public static boolean checkIfBoxed(PlayerCharacter player){ diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index e1df816d..5db69727 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -128,42 +128,44 @@ public class Warehouse extends AbstractWorldObject { } public static void warehouseDeposit(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) { - Item resource = Item.getFromCache(msg.getItemID()); - if (resource == null) { + Building warehouseBuilding = npc.getBuilding(); + if (warehouseBuilding == null) { return; } - int depositAmount = msg.getAmount(); - CharacterItemManager itemMan = player.getCharItemManager(); + player.getTimestamps().put("lastDepositWarehouse", System.currentTimeMillis()); + player.depositingWarehouse = true; + player.warehouseBuilding = warehouseBuilding; + player.getCharItemManager().updateLock = true; + Item resource = Item.getFromCache(msg.getItemID()); - if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) { - return; - } + if (resource == null) { + return; + } - Building warehouseBuilding = npc.getBuilding(); - if (warehouseBuilding == null) { - return; - } + int depositAmount = msg.getAmount(); + CharacterItemManager itemMan = player.getCharItemManager(); - Warehouse warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); - if (warehouse == null) { - return; - } + if (!itemMan.doesCharOwnThisItem(resource.getObjectUUID())) { + return; + } - if (!warehouse.deposit(player, resource, depositAmount, true, true)) { - // Optional: Uncomment these lines for debugging/logging purposes. - // ChatManager.chatGuildError(player, "Failed to deposit " + resource.getItemBase().getName() + "."); - // Logger.debug("OpenWindow", player.getName() + " Failed to deposit Item with ID " + resource.getObjectUUID() + " from Warehouse With ID = " + warehouseBuilding.getObjectUUID()); - return; - } + Warehouse warehouse = warehouseByBuildingUUID.get(warehouseBuilding.getObjectUUID()); + if (warehouse == null) { + return; + } - ViewResourcesMessage vrm = new ViewResourcesMessage(player); - vrm.setGuild(player.getGuild()); - vrm.setWarehouseBuilding(warehouseBuilding); - vrm.configure(); - Dispatch dispatch = Dispatch.borrow(player, vrm); - DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); + if (!warehouse.deposit(player, resource, depositAmount, true, true)) { + return; + } + + //ViewResourcesMessage vrm = new ViewResourcesMessage(player); + //vrm.setGuild(player.getGuild()); + //vrm.setWarehouseBuilding(warehouseBuilding); + //vrm.configure(); + //Dispatch dispatch = Dispatch.borrow(player, vrm); + //DispatchMessage.dispatchMsgDispatch(dispatch, Enum.DispatchChannel.SECONDARY); } public static void warehouseWithdraw(MerchantMsg msg, PlayerCharacter player, NPC npc, ClientConnection origin) {