diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index d2905bcd..fcf7b158 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -335,7 +335,7 @@ public enum BuildingManager { if (ForgeManager.vendorWorkOrderLookup.get(hirelingNPC) != null) for (WorkOrder workOrder : ForgeManager.vendorWorkOrderLookup.get(hirelingNPC)) { - workOrder.runCompleted = true; + workOrder.runCompleted.set(true); workOrder.vendor = null; DbManager.WarehouseQueries.DELETE_WORKORDER(workOrder); } diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index cd621c01..41618f31 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -65,7 +65,7 @@ public enum ForgeManager implements Runnable { // Early exit for completed workOrders loaded from disk // or vendors who were re-deeded with items cooking. - if (workOrder.vendor == null && workOrder.runCompleted) + if (workOrder.vendor == null && workOrder.runCompleted.get()) continue; // This workOrder has completed production. @@ -82,7 +82,7 @@ public enum ForgeManager implements Runnable { DispatchMessage.dispatchMsgToInterestArea(workOrder.vendor, outMsg, mbEnums.DispatchChannel.SECONDARY, 700, false, false); } - workOrder.runCompleted = true; + workOrder.runCompleted.set(true); // Update workOrder on disk @@ -150,9 +150,9 @@ public enum ForgeManager implements Runnable { workOrder.workOrderID = workOrderCounter.incrementAndGet(); workOrder.rollingDuration = ForgeManager.calcRollingDuration(workOrder); workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration; - workOrder.slots_used = calcAvailableSlots(workOrder); + workOrder.slots_used.set(calcAvailableSlots(workOrder)); - if (workOrder.slots_used == 0) + if (workOrder.slots_used.get() == 0) return 58; workOrder.total_produced = 0; @@ -164,7 +164,7 @@ public enum ForgeManager implements Runnable { // Set total cost for production run - workOrder.total_to_produce *= workOrder.slots_used; + workOrder.total_to_produce *= workOrder.slots_used.get(); workOrder.production_cost = calcProductionCost(workOrder); workOrder.production_cost.forEach((key, value) -> workOrder.production_cost_total.put(key, value * workOrder.total_to_produce)); @@ -366,7 +366,7 @@ public enum ForgeManager implements Runnable { workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration; - for (int i = 0; i < workOrder.slots_used; ++i) { + for (int i = 0; i < workOrder.slots_used.get(); ++i) { Item forged_item = forgeItem(workOrder); diff --git a/src/engine/loot/WorkOrder.java b/src/engine/loot/WorkOrder.java index 1d0ead4f..90053de2 100644 --- a/src/engine/loot/WorkOrder.java +++ b/src/engine/loot/WorkOrder.java @@ -29,6 +29,8 @@ import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Delayed; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; public class WorkOrder implements Delayed { @@ -41,7 +43,7 @@ public class WorkOrder implements Delayed { public int workOrderID; public NPC vendor; - public volatile int slots_used; + public AtomicInteger slots_used = new AtomicInteger(0); public int total_to_produce; public int total_produced; public boolean multiple_slot_request; @@ -53,7 +55,7 @@ public class WorkOrder implements Delayed { public int suffixToken; public long rollingDuration; public long completionTime; - public volatile boolean runCompleted = false; + public AtomicBoolean runCompleted = new AtomicBoolean(false); // This collection is serialized to the vendor rolling window in ManageNPCMsg. @@ -70,7 +72,7 @@ public class WorkOrder implements Delayed { this.workOrderID = jsonWorkOrder.getInt("workOrderID"); this.vendor = NPC.getNPC(jsonWorkOrder.getInt("vendor")); - this.slots_used = jsonWorkOrder.getInt("slots_used"); + this.slots_used.set(jsonWorkOrder.getInt("slots_used")); this.total_to_produce = jsonWorkOrder.getInt("total_to_produce"); this.total_produced = jsonWorkOrder.getInt("total_produced"); this.multiple_slot_request = jsonWorkOrder.getBoolean("multiple_slot_request"); @@ -78,10 +80,9 @@ public class WorkOrder implements Delayed { this.item_name_override = jsonWorkOrder.getString("item_name_override"); this.prefixToken = jsonWorkOrder.getInt("prefixToken"); this.suffixToken = jsonWorkOrder.getInt("suffixToken"); - this.slots_used = jsonWorkOrder.getInt("slots_used"); this.rollingDuration = jsonWorkOrder.getLong("rollingDuration"); this.completionTime = jsonWorkOrder.getLong("completionTime"); - this.runCompleted = jsonWorkOrder.getBoolean("runCompleted"); + this.runCompleted.set(jsonWorkOrder.getBoolean("runCompleted")); JSONObject productionCostMap = jsonWorkOrder.getJSONObject("production_cost"); diff --git a/src/engine/net/client/handlers/ItemProductionMsgHandler.java b/src/engine/net/client/handlers/ItemProductionMsgHandler.java index cdc5ce81..3629105c 100644 --- a/src/engine/net/client/handlers/ItemProductionMsgHandler.java +++ b/src/engine/net/client/handlers/ItemProductionMsgHandler.java @@ -150,7 +150,7 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { ForgeManager.itemWorkOrderLookup.remove(virtualItem); DbManager.removeFromCache(virtualItem); - workOrder.slots_used = workOrder.slots_used - 1; + workOrder.slots_used.set(workOrder.slots_used.get() - 1); // Update workOrder on disk @@ -421,15 +421,15 @@ public class ItemProductionMsgHandler extends AbstractClientMsgHandler { // Update total_to_produce accounting for the slot being // removed while workOrder is not completed. - if (!workOrder.runCompleted) - if (workOrder.multiple_slot_request && workOrder.slots_used > 1) { - int itemsPerSlot = workOrder.total_to_produce / workOrder.slots_used; + if (!workOrder.runCompleted.get()) + if (workOrder.multiple_slot_request && workOrder.slots_used.get() > 1) { + int itemsPerSlot = workOrder.total_to_produce / workOrder.slots_used.get(); workOrder.total_to_produce = workOrder.total_to_produce - itemsPerSlot; } // Slot is no longer allocated to this workOrder. - workOrder.slots_used = workOrder.slots_used - 1; + workOrder.slots_used.set(workOrder.slots_used.get() - 1); // Update workOrder on disk