Browse Source

Work on virtual item handling

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

30
src/engine/gameManager/ForgeManager.java

@ -74,19 +74,22 @@ public enum ForgeManager implements Runnable { @@ -74,19 +74,22 @@ public enum ForgeManager implements Runnable {
if (workOrder.runCompleted)
continue;
// Persist virtual items that were currently cooking
// Move current cooking batch to vendor inventory
persistItems(workOrder);
completeWorkOrderBatch(workOrder);
// Create new set of in-memory only virtual items
forgeItems(workOrder);
forgeWorkerOrderBatch(workOrder);
// enQueue this workOrder again; back into the oven
// until all items for this workOrder are completed.
workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration;
forge.add(workOrder);
// Debugging
Logger.info(workOrder.toString());
}
}
@ -125,7 +128,7 @@ public enum ForgeManager implements Runnable { @@ -125,7 +128,7 @@ public enum ForgeManager implements Runnable {
// Create in-memory items and add to collections
forgeItems(workOrder);
forgeWorkerOrderBatch(workOrder);
Logger.info(workOrder.toString());
forge.add(workOrder);
@ -299,15 +302,12 @@ public enum ForgeManager implements Runnable { @@ -299,15 +302,12 @@ public enum ForgeManager implements Runnable {
return forgedItem;
}
public static void persistItems(WorkOrder workOrder) {
public static void completeWorkOrderBatch(WorkOrder workOrder) {
ArrayList<Item> toRemove = new ArrayList<>();
Item completed_item;
for (Item workOrderItem : workOrder.cooking) {
toRemove.add(workOrderItem);
// Remove the virtual items from the forge window
ItemProductionMsg outMsg = new ItemProductionMsg(workOrder.vendor.building, workOrder.vendor, workOrderItem, mbEnums.ProductionActionType.CONFIRM_SETPRICE, true);
@ -315,23 +315,25 @@ public enum ForgeManager implements Runnable { @@ -315,23 +315,25 @@ public enum ForgeManager implements Runnable {
ItemProductionMsg outMsg1 = new ItemProductionMsg(workOrder.vendor.building, workOrder.vendor, workOrderItem, mbEnums.ProductionActionType.CONFIRM_DEPOSIT, true);
DispatchMessage.dispatchMsgToInterestArea(workOrder.vendor, outMsg1, mbEnums.DispatchChannel.SECONDARY, 700, false, false);
// Turn the virtual item into a real one and add to the vendor inventory
// add to the vendor inventory
workOrder.vendor.charItemManager.addItemToInventory(workOrderItem);
completed_item = DbManager.ItemQueries.PERSIST(workOrderItem);
workOrder.vendor.charItemManager.addItemToInventory(completed_item);
toRemove.add(workOrderItem);
}
// Remove the negativeID virtual item from all collections.
// Remove the negativeID virtual item from all collections
// other than the virtual item lookup map. Item will be
// persisted when bought/taken from vendor.
for (Item memoryItem : toRemove) {
workOrder.cooking.remove(memoryItem);
inMemoryItemLookup.remove(memoryItem.objectUUID);
vendorItemLookup.get(workOrder.vendor).remove(memoryItem);
itemWorkOrderLookup.remove(memoryItem);
}
}
public static void forgeItems(WorkOrder workOrder) {
public static void forgeWorkerOrderBatch(WorkOrder workOrder) {
for (int i = 0; i < workOrder.slots_used; ++i) {

Loading…
Cancel
Save