Browse Source

Uses mainline cache for virtual items

combat-2
MagicBot 8 months ago
parent
commit
a46205b67b
  1. 4
      src/engine/gameManager/ForgeManager.java
  2. 8
      src/engine/net/client/handlers/ItemProductionMsgHandler.java
  3. 9
      src/engine/net/client/msg/ItemProductionMsg.java

4
src/engine/gameManager/ForgeManager.java

@ -33,7 +33,6 @@ public enum ForgeManager implements Runnable { @@ -33,7 +33,6 @@ public enum ForgeManager implements Runnable {
private static final BlockingQueue<WorkOrder> forge = new DelayQueue<>();
public static final AtomicInteger wordOrderCounter = new AtomicInteger(0);
public static final HashMap<Integer, Item> inMemoryItemLookup = new HashMap<>();
public static final HashMap<NPC, ArrayList<WorkOrder>> vendorWorkOrderLookup = new HashMap<>();
public static final HashMap<Item, WorkOrder> itemWorkOrderLookup = new HashMap<>();
@ -306,6 +305,7 @@ public enum ForgeManager implements Runnable { @@ -306,6 +305,7 @@ public enum ForgeManager implements Runnable {
workOrder.cooking.remove(memoryItem);
itemWorkOrderLookup.remove(memoryItem);
DbManager.removeFromCache(memoryItem);
}
}
@ -322,7 +322,7 @@ public enum ForgeManager implements Runnable { @@ -322,7 +322,7 @@ public enum ForgeManager implements Runnable {
// Add virtual item to in-memory caches
workOrder.cooking.add(forged_item);
inMemoryItemLookup.put(forged_item.objectUUID, forged_item);
DbManager.addToCache(forged_item);
vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder);
itemWorkOrderLookup.put(forged_item, workOrder);

8
src/engine/net/client/handlers/ItemProductionMsgHandler.java

@ -129,7 +129,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { @@ -129,7 +129,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
private static void completeItem(int itemUUID, NPC vendor) {
Item virtualItem = ForgeManager.inMemoryItemLookup.get(itemUUID);
Item virtualItem = Item.getFromCache(itemUUID);
WorkOrder workOrder = ForgeManager.itemWorkOrderLookup.get(virtualItem);
// Refresh the window. SetPrice is used only to force a window refresh.
@ -142,6 +142,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { @@ -142,6 +142,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
workOrder.cooking.remove(virtualItem);
ForgeManager.itemWorkOrderLookup.remove(virtualItem);
DbManager.removeFromCache(virtualItem);
// WorkOrder exists until all items are completed or junked
// this is to hold a reference to the virtual item for serialization (NPCMsgHandler)
@ -364,7 +365,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { @@ -364,7 +365,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
try {
targetItem = ForgeManager.inMemoryItemLookup.get(itemUUID);
targetItem = Item.getFromCache(itemUUID);
PlayerCharacter player = origin.getPlayerCharacter();
@ -381,10 +382,9 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { @@ -381,10 +382,9 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler {
if (vendor.getBuilding() == null)
return;
ForgeManager.inMemoryItemLookup.remove(targetItem.objectUUID);
WorkOrder workOrder = ForgeManager.itemWorkOrderLookup.get(targetItem);
workOrder.cooking.remove(targetItem);
DbManager.removeFromCache(targetItem);
// WorkOrder exists until all items are completed or junked
// this is to hold a reference to the virtual item for serialization (NPCMsgHandler)

9
src/engine/net/client/msg/ItemProductionMsg.java

@ -10,7 +10,6 @@ @@ -10,7 +10,6 @@
package engine.net.client.msg;
import engine.gameManager.BuildingManager;
import engine.gameManager.ForgeManager;
import engine.mbEnums;
import engine.mbEnums.GameObjectType;
import engine.net.*;
@ -142,11 +141,7 @@ public class ItemProductionMsg extends ClientNetMsg { @@ -142,11 +141,7 @@ public class ItemProductionMsg extends ClientNetMsg {
writer.putInt(0);
writer.put((byte) 1);
Item item;
if (this.itemUUID > 0)
item = Item.getFromCache(this.itemUUID);
else
item = ForgeManager.inMemoryItemLookup.get(this.itemUUID);
Item item = Item.getFromCache(this.itemUUID);
if (item != null)
Item.serializeForClientMsgWithoutSlot(item, writer);
@ -237,7 +232,7 @@ public class ItemProductionMsg extends ClientNetMsg { @@ -237,7 +232,7 @@ public class ItemProductionMsg extends ClientNetMsg {
writer.putInt(0);
writer.putInt(0);
writer.putInt(1);
Item toRoll = ForgeManager.inMemoryItemLookup.get(this.itemUUID);
Item toRoll = Item.getFromCache(this.itemUUID);
writer.putInt(-1497023830);
this.pToken = toRoll.prefixToken;

Loading…
Cancel
Save