From d5bd500f39203090fbfd8feedb106073a7f73a2e Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 14 Apr 2024 16:29:17 -0400 Subject: [PATCH] forged items are persisted --- src/engine/gameManager/ForgeManager.java | 41 ++++++++++++++++-------- src/engine/loot/WorkOrder.java | 3 ++ 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 56efd89c..5b699ef4 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -62,25 +62,40 @@ public enum ForgeManager implements Runnable { if (workOrder.runCanceled || workOrder.runCompleted) continue; - // Create in memory items to add to collections + // Persist current items that are currently cooking for this + // workOrder - forgeItems(workOrder); + ArrayList toRemove = new ArrayList<>(); - Logger.info("item forged:" + workOrder.workOrderID + " (" + workOrder.total_produced + "/" + workOrder.total_to_produce + ")"); + for (Item cooked_item : workOrder.cooking) { + toRemove.add(cooked_item); + cooked_item.containerType = mbEnums.ItemContainerType.INVENTORY; + Item completed_item = DbManager.ItemQueries.PERSIST(cooked_item); + workOrder.vendor.charItemManager.addItemToInventory(completed_item); + } - if (workOrder.total_produced >= workOrder.total_to_produce) { + // Remove the fake negativeID item from all collections. - Logger.info("workOrder has completed: " + workOrder.workOrderID); + for (Item memoryItem : toRemove) { + workOrder.cooking.remove(memoryItem); + inMemoryItemLookup.remove(memoryItem.objectUUID); + vendorItemLookup.get(workOrder.vendor).remove(memoryItem); + } + + Logger.info("item forged:" + workOrder.workOrderID + " (" + workOrder.total_produced + "/" + workOrder.total_to_produce + ")"); - // Persist current items that are currently building for this - // worker after first removing the negative id item from all - // collections. + if (workOrder.total_produced >= workOrder.total_to_produce) { + Logger.info("workOrder has completed: " + workOrder.workOrderID); workOrder.runCompleted = true; continue; } + // Create new set in memory items + + forgeItems(workOrder); + // enQueue this workOrder again; back into the oven // until all items for this workOrder are completed. @@ -296,13 +311,13 @@ public enum ForgeManager implements Runnable { // Add item to in-memory caches - ForgeManager.inMemoryItemLookup.put(forged_item.objectUUID, forged_item); - - ForgeManager.vendorItemLookup.computeIfAbsent(workOrder.vendor, k -> new ArrayList<>()); + workOrder.cooking.add(forged_item); - ForgeManager.vendorItemLookup.get(workOrder.vendor).add(forged_item); + inMemoryItemLookup.put(forged_item.objectUUID, forged_item); + vendorItemLookup.computeIfAbsent(workOrder.vendor, k -> new ArrayList<>()); + vendorItemLookup.get(workOrder.vendor).add(forged_item); vendorItemLookup.get(workOrder.vendor).add(forged_item); - ForgeManager.vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder); + vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder); // Update NPC window diff --git a/src/engine/loot/WorkOrder.java b/src/engine/loot/WorkOrder.java index 0cae3497..5bfc1f84 100644 --- a/src/engine/loot/WorkOrder.java +++ b/src/engine/loot/WorkOrder.java @@ -9,12 +9,14 @@ package engine.loot; import engine.mbEnums; +import engine.objects.Item; import engine.objects.NPC; import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; +import java.util.ArrayList; import java.util.HashMap; import java.util.concurrent.Delayed; import java.util.concurrent.TimeUnit; @@ -37,6 +39,7 @@ public class WorkOrder implements Delayed { public long completionTime; public boolean runCompleted = false; public boolean runCanceled = false; + public ArrayList cooking = new ArrayList<>(); public WorkOrder() {