diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 3487615d..8a283caa 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -37,6 +37,7 @@ public enum ForgeManager implements Runnable { public static final HashMap inMemoryItemLookup = new HashMap<>(); public static final HashMap> vendorItemLookup = new HashMap<>(); public static final HashMap> vendorWorkOrderLookup = new HashMap<>(); + public static final HashMap itemWorkOrderLookup = new HashMap<>(); @Override @@ -317,6 +318,7 @@ public enum ForgeManager implements Runnable { workOrder.cooking.remove(memoryItem); inMemoryItemLookup.remove(memoryItem.objectUUID); vendorItemLookup.get(workOrder.vendor).remove(memoryItem); + itemWorkOrderLookup.remove(memoryItem); } } @@ -334,6 +336,7 @@ public enum ForgeManager implements Runnable { vendorItemLookup.computeIfAbsent(workOrder.vendor, k -> new ArrayList<>()); vendorItemLookup.get(workOrder.vendor).add(forged_item); vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder); + itemWorkOrderLookup.put(forged_item, workOrder); // Update NPC window diff --git a/src/engine/net/client/handlers/ItemProductionMsgHandler.java b/src/engine/net/client/handlers/ItemProductionMsgHandler.java index 9f96a484..c9526bea 100644 --- a/src/engine/net/client/handlers/ItemProductionMsgHandler.java +++ b/src/engine/net/client/handlers/ItemProductionMsgHandler.java @@ -332,13 +332,15 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { private static void junkItem(int itemUUID, NPC vendor, ClientConnection origin) { - MobLoot targetItem; + Item targetItem; ManageNPCMsg outMsg; Dispatch dispatch; if (origin.sellLock.tryLock()) { + try { - targetItem = MobLoot.getFromCache(itemUUID); + + targetItem = ForgeManager.inMemoryItemLookup.get(itemUUID); PlayerCharacter player = origin.getPlayerCharacter(); @@ -350,18 +352,17 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { if (targetItem == null) return; - if (!ForgeManager.vendorItemLookup.get(vendor).contains(targetItem)) - return; - // Cannot junk items without a forge! if (vendor.getBuilding() == null) return; - // Delete the item and cancel any pending rolling timer jobs + // Delete the item - targetItem.recycle(vendor); - // todo fix vendor.removeItemFromForge(targetItem); + ForgeManager.inMemoryItemLookup.remove(targetItem.objectUUID); + WorkOrder workOrder = ForgeManager.itemWorkOrderLookup.get(targetItem); + workOrder.cooking.remove(targetItem); + ForgeManager.vendorItemLookup.get(workOrder.vendor).remove(targetItem); // Refresh vendor's inventory to client