Browse Source

Rework of item forge method collection usage

combat-2
MagicBot 8 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 { @@ -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 { @@ -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 { @@ -256,20 +260,20 @@ public enum ForgeManager implements Runnable {
ArrayList<Item> 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 { @@ -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 { @@ -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);

Loading…
Cancel
Save