Browse Source

forged items are persisted

combat-2
MagicBot 9 months ago
parent
commit
d5bd500f39
  1. 41
      src/engine/gameManager/ForgeManager.java
  2. 3
      src/engine/loot/WorkOrder.java

41
src/engine/gameManager/ForgeManager.java

@ -62,25 +62,40 @@ public enum ForgeManager implements Runnable {
if (workOrder.runCanceled || workOrder.runCompleted) if (workOrder.runCanceled || workOrder.runCompleted)
continue; continue;
// Create in memory items to add to collections // Persist current items that are currently cooking for this
// workOrder
forgeItems(workOrder); ArrayList<Item> 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; workOrder.runCompleted = true;
continue; continue;
} }
// Create new set in memory items
forgeItems(workOrder);
// enQueue this workOrder again; back into the oven // enQueue this workOrder again; back into the oven
// until all items for this workOrder are completed. // until all items for this workOrder are completed.
@ -296,13 +311,13 @@ public enum ForgeManager implements Runnable {
// Add item to in-memory caches // Add item to in-memory caches
ForgeManager.inMemoryItemLookup.put(forged_item.objectUUID, forged_item); workOrder.cooking.add(forged_item);
ForgeManager.vendorItemLookup.computeIfAbsent(workOrder.vendor, k -> new ArrayList<>());
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); vendorItemLookup.get(workOrder.vendor).add(forged_item);
ForgeManager.vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder); vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder);
// Update NPC window // Update NPC window

3
src/engine/loot/WorkOrder.java

@ -9,12 +9,14 @@
package engine.loot; package engine.loot;
import engine.mbEnums; import engine.mbEnums;
import engine.objects.Item;
import engine.objects.NPC; import engine.objects.NPC;
import java.time.Duration; import java.time.Duration;
import java.time.Instant; import java.time.Instant;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.Delayed; import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -37,6 +39,7 @@ public class WorkOrder implements Delayed {
public long completionTime; public long completionTime;
public boolean runCompleted = false; public boolean runCompleted = false;
public boolean runCanceled = false; public boolean runCanceled = false;
public ArrayList<Item> cooking = new ArrayList<>();
public WorkOrder() { public WorkOrder() {

Loading…
Cancel
Save