Browse Source

Rework of item forge method collection usage

combat-2
MagicBot 7 months ago
parent
commit
1e5790e6b9
  1. 39
      src/engine/gameManager/ForgeManager.java

39
src/engine/gameManager/ForgeManager.java

@ -219,11 +219,9 @@ public enum ForgeManager implements Runnable {
ItemTemplate template = ItemTemplate.templates.get(workOrder.templateID); ItemTemplate template = ItemTemplate.templates.get(workOrder.templateID);
Item forgedItem = new Item(workOrder.templateID); Item forgedItem = new Item(workOrder.templateID);
// Item gets a negative id; a virtual in-memory only item // forgedItem gets a negative id; a virtual item which is not persisted
// which is not persisted or added to the game cache.
forgedItem.objectUUID = ItemManager.lastNegativeID.getAndDecrement(); forgedItem.objectUUID = ItemManager.lastNegativeID.getAndDecrement();
forgedItem.containerType = mbEnums.ItemContainerType.FORGE; forgedItem.containerType = mbEnums.ItemContainerType.FORGE;
forgedItem.ownerID = workOrder.vendor.getObjectUUID(); forgedItem.ownerID = workOrder.vendor.getObjectUUID();
@ -249,6 +247,12 @@ public enum ForgeManager implements Runnable {
if (workOrder.prefixToken == 0 && workOrder.suffixToken == 0) if (workOrder.prefixToken == 0 && workOrder.suffixToken == 0)
forgedItem.flags.remove(mbEnums.ItemFlags.Identified); 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; return forgedItem;
} }
@ -256,20 +260,20 @@ public enum ForgeManager implements Runnable {
ArrayList<Item> toRemove = new ArrayList<>(); ArrayList<Item> toRemove = new ArrayList<>();
for (Item workOrderItem : workOrder.cooking) { for (Item virutalItem : workOrder.cooking) {
// Identify completed items // Identify completed items
workOrderItem.flags.add(mbEnums.ItemFlags.Identified); virutalItem.flags.add(mbEnums.ItemFlags.Identified);
// Persist item // Persist item
Item completedItem = DbManager.ItemQueries.PERSIST(workOrderItem); Item completedItem = DbManager.ItemQueries.PERSIST(virutalItem);
// Apply Item effects for Prefix and Suffix tokens // Apply Item effects for Prefix and Suffix tokens
completedItem.prefixToken = workOrderItem.prefixToken; completedItem.prefixToken = virutalItem.prefixToken;
completedItem.suffixToken = workOrderItem.suffixToken; completedItem.suffixToken = virutalItem.suffixToken;
ItemManager.applyItemEffects(completedItem); 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); 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); 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 // Remove the negativeID virtual item from all collections
for (Item memoryItem : toRemove) { for (Item virtualItem : toRemove) {
// Remove the virtual items from the forge window // 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); DispatchMessage.dispatchMsgToInterestArea(workOrder.vendor, outMsg, mbEnums.DispatchChannel.SECONDARY, 700, false, false);
workOrder.cooking.remove(memoryItem); workOrder.cooking.remove(virtualItem);
itemWorkOrderLookup.remove(memoryItem); itemWorkOrderLookup.remove(virtualItem);
DbManager.removeFromCache(memoryItem); DbManager.removeFromCache(virtualItem);
} }
} }
@ -310,13 +314,6 @@ public enum ForgeManager implements Runnable {
Item forged_item = forgeItem(workOrder); 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 // Update NPC window
ItemProductionMsg outMsg = new ItemProductionMsg(workOrder.vendor.building, workOrder.vendor, forged_item, mbEnums.ProductionActionType.CONFIRM_PRODUCE, true); ItemProductionMsg outMsg = new ItemProductionMsg(workOrder.vendor.building, workOrder.vendor, forged_item, mbEnums.ProductionActionType.CONFIRM_PRODUCE, true);

Loading…
Cancel
Save