Browse Source

Fixing Junk functionality

combat-2
MagicBot 7 months ago
parent
commit
12b6e41432
  1. 3
      src/engine/gameManager/ForgeManager.java
  2. 17
      src/engine/net/client/handlers/ItemProductionMsgHandler.java

3
src/engine/gameManager/ForgeManager.java

@ -37,6 +37,7 @@ public enum ForgeManager implements Runnable {
public static final HashMap<Integer, Item> inMemoryItemLookup = new HashMap<>(); public static final HashMap<Integer, Item> inMemoryItemLookup = new HashMap<>();
public static final HashMap<NPC, ArrayList<Item>> vendorItemLookup = new HashMap<>(); public static final HashMap<NPC, ArrayList<Item>> vendorItemLookup = new HashMap<>();
public static final HashMap<NPC, ArrayList<WorkOrder>> vendorWorkOrderLookup = new HashMap<>(); public static final HashMap<NPC, ArrayList<WorkOrder>> vendorWorkOrderLookup = new HashMap<>();
public static final HashMap<Item, WorkOrder> itemWorkOrderLookup = new HashMap<>();
@Override @Override
@ -317,6 +318,7 @@ public enum ForgeManager implements Runnable {
workOrder.cooking.remove(memoryItem); workOrder.cooking.remove(memoryItem);
inMemoryItemLookup.remove(memoryItem.objectUUID); inMemoryItemLookup.remove(memoryItem.objectUUID);
vendorItemLookup.get(workOrder.vendor).remove(memoryItem); 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.computeIfAbsent(workOrder.vendor, k -> new ArrayList<>());
vendorItemLookup.get(workOrder.vendor).add(forged_item); vendorItemLookup.get(workOrder.vendor).add(forged_item);
vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder); vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder);
itemWorkOrderLookup.put(forged_item, workOrder);
// Update NPC window // Update NPC window

17
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) { private static void junkItem(int itemUUID, NPC vendor, ClientConnection origin) {
MobLoot targetItem; Item targetItem;
ManageNPCMsg outMsg; ManageNPCMsg outMsg;
Dispatch dispatch; Dispatch dispatch;
if (origin.sellLock.tryLock()) { if (origin.sellLock.tryLock()) {
try { try {
targetItem = MobLoot.getFromCache(itemUUID);
targetItem = ForgeManager.inMemoryItemLookup.get(itemUUID);
PlayerCharacter player = origin.getPlayerCharacter(); PlayerCharacter player = origin.getPlayerCharacter();
@ -350,18 +352,17 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
if (targetItem == null) if (targetItem == null)
return; return;
if (!ForgeManager.vendorItemLookup.get(vendor).contains(targetItem))
return;
// Cannot junk items without a forge! // Cannot junk items without a forge!
if (vendor.getBuilding() == null) if (vendor.getBuilding() == null)
return; return;
// Delete the item and cancel any pending rolling timer jobs // Delete the item
targetItem.recycle(vendor); ForgeManager.inMemoryItemLookup.remove(targetItem.objectUUID);
// todo fix vendor.removeItemFromForge(targetItem); WorkOrder workOrder = ForgeManager.itemWorkOrderLookup.get(targetItem);
workOrder.cooking.remove(targetItem);
ForgeManager.vendorItemLookup.get(workOrder.vendor).remove(targetItem);
// Refresh vendor's inventory to client // Refresh vendor's inventory to client

Loading…
Cancel
Save