From 1e5790e6b9af2568679c258f78421d02bd5f3568 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 21 Apr 2024 08:23:58 -0400 Subject: [PATCH] Rework of item forge method collection usage --- src/engine/gameManager/ForgeManager.java | 39 +++++++++++------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 6250ce78..9aa853a1 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -219,11 +219,9 @@ public enum ForgeManager implements Runnable { ItemTemplate template = ItemTemplate.templates.get(workOrder.templateID); Item forgedItem = new Item(workOrder.templateID); - // Item gets a negative id; a virtual in-memory only item - // which is not persisted or added to the game cache. + // forgedItem gets a negative id; a virtual item which is not persisted forgedItem.objectUUID = ItemManager.lastNegativeID.getAndDecrement(); - forgedItem.containerType = mbEnums.ItemContainerType.FORGE; forgedItem.ownerID = workOrder.vendor.getObjectUUID(); @@ -249,6 +247,12 @@ public enum ForgeManager implements Runnable { if (workOrder.prefixToken == 0 && workOrder.suffixToken == 0) forgedItem.flags.remove(mbEnums.ItemFlags.Identified); + // Add virtual item to in-memory caches + + workOrder.cooking.add(forgedItem); + DbManager.addToCache(forgedItem); + itemWorkOrderLookup.put(forgedItem, workOrder); + return forgedItem; } @@ -256,20 +260,20 @@ public enum ForgeManager implements Runnable { ArrayList toRemove = new ArrayList<>(); - for (Item workOrderItem : workOrder.cooking) { + for (Item virutalItem : workOrder.cooking) { // Identify completed items - workOrderItem.flags.add(mbEnums.ItemFlags.Identified); + virutalItem.flags.add(mbEnums.ItemFlags.Identified); // Persist item - Item completedItem = DbManager.ItemQueries.PERSIST(workOrderItem); + Item completedItem = DbManager.ItemQueries.PERSIST(virutalItem); // Apply Item effects for Prefix and Suffix tokens - completedItem.prefixToken = workOrderItem.prefixToken; - completedItem.suffixToken = workOrderItem.suffixToken; + completedItem.prefixToken = virutalItem.prefixToken; + completedItem.suffixToken = virutalItem.suffixToken; ItemManager.applyItemEffects(completedItem); @@ -282,21 +286,21 @@ public enum ForgeManager implements Runnable { ItemProductionMsg outMsg2 = new ItemProductionMsg(workOrder.vendor.building, workOrder.vendor, completedItem, mbEnums.ProductionActionType.CONFIRM_DEPOSIT, true); DispatchMessage.dispatchMsgToInterestArea(workOrder.vendor, outMsg2, mbEnums.DispatchChannel.SECONDARY, 700, false, false); - toRemove.add(workOrderItem); + toRemove.add(virutalItem); } // Remove the negativeID virtual item from all collections - for (Item memoryItem : toRemove) { + for (Item virtualItem : toRemove) { // Remove the virtual items from the forge window - ItemProductionMsg outMsg = new ItemProductionMsg(workOrder.vendor.building, workOrder.vendor, memoryItem, mbEnums.ProductionActionType.CONFIRM_SETPRICE, true); + ItemProductionMsg outMsg = new ItemProductionMsg(workOrder.vendor.building, workOrder.vendor, virtualItem, mbEnums.ProductionActionType.CONFIRM_SETPRICE, true); DispatchMessage.dispatchMsgToInterestArea(workOrder.vendor, outMsg, mbEnums.DispatchChannel.SECONDARY, 700, false, false); - workOrder.cooking.remove(memoryItem); - itemWorkOrderLookup.remove(memoryItem); - DbManager.removeFromCache(memoryItem); + workOrder.cooking.remove(virtualItem); + itemWorkOrderLookup.remove(virtualItem); + DbManager.removeFromCache(virtualItem); } } @@ -310,13 +314,6 @@ public enum ForgeManager implements Runnable { Item forged_item = forgeItem(workOrder); - // Add virtual item to in-memory caches - - workOrder.cooking.add(forged_item); - DbManager.addToCache(forged_item); - vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder); - itemWorkOrderLookup.put(forged_item, workOrder); - // Update NPC window ItemProductionMsg outMsg = new ItemProductionMsg(workOrder.vendor.building, workOrder.vendor, forged_item, mbEnums.ProductionActionType.CONFIRM_PRODUCE, true);