From dbf42bfbefe9224d2d32fa665f6f13348d502238 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Thu, 25 Apr 2024 09:39:03 -0400 Subject: [PATCH] json fix in constructor --- src/engine/loot/WorkOrder.java | 66 ++++++++++++++++------------------ 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/src/engine/loot/WorkOrder.java b/src/engine/loot/WorkOrder.java index 830791f1..19e8ce8d 100644 --- a/src/engine/loot/WorkOrder.java +++ b/src/engine/loot/WorkOrder.java @@ -87,7 +87,7 @@ public class WorkOrder implements Delayed { this.production_cost.put(resourceType, value); } - JSONObject productionTotalCostMap = jsonWorkOrder.getJSONObject("production_cost"); + JSONObject productionTotalCostMap = jsonWorkOrder.getJSONObject("production_cost_total"); for (String key : productionTotalCostMap.keySet()) { mbEnums.ResourceType resourceType = mbEnums.ResourceType.valueOf(key); @@ -109,37 +109,6 @@ public class WorkOrder implements Delayed { } } - public static JSONObject toJson(WorkOrder workOrder) { - - JSONObject jsonWorkOrder = new JSONObject(); - - jsonWorkOrder.put("workOrderID", workOrder.workOrderID); - jsonWorkOrder.put("vendor", workOrder.vendor.getObjectUUID()); - jsonWorkOrder.put("slots_used", workOrder.slots_used); - jsonWorkOrder.put("total_to_produce", workOrder.total_to_produce); - jsonWorkOrder.put("total_produced", workOrder.total_produced); - jsonWorkOrder.put("multiple_slot_request", workOrder.multiple_slot_request); - jsonWorkOrder.put("production_cost", workOrder.production_cost); - jsonWorkOrder.put("production_cost_total", workOrder.production_cost_total); - jsonWorkOrder.put("templateID", workOrder.templateID); - jsonWorkOrder.put("item_name_override", workOrder.item_name_override); - jsonWorkOrder.put("prefixToken", workOrder.prefixToken); - jsonWorkOrder.put("suffixToken", workOrder.suffixToken); - jsonWorkOrder.put("rollingDuration", workOrder.rollingDuration); - jsonWorkOrder.put("completionTime", workOrder.completionTime); - jsonWorkOrder.put("runCompleted", workOrder.runCompleted); - - ArrayList cookingTokens = new ArrayList<>(); - - for (Item item : workOrder.cooking) - cookingTokens.add(new Integer[]{item.prefixToken, item.suffixToken}); - - jsonWorkOrder.put("cookingTokens", cookingTokens); - - - return jsonWorkOrder; - } - public static int validate(WorkOrder workOrder) { // Validate that a workOrder can be completed by both @@ -188,7 +157,6 @@ public class WorkOrder implements Delayed { if (workOrder.production_cost_total.size() == 1) return true; - } else { int remainingAmount = workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) - strongbox; workOrder.vendor.building.setStrongboxValue(0); @@ -212,10 +180,8 @@ public class WorkOrder implements Delayed { @Override public long getDelay(TimeUnit unit) { - long timeRemaining = completionTime - System.currentTimeMillis(); return unit.convert(timeRemaining, TimeUnit.MILLISECONDS); - } @Override @@ -223,6 +189,36 @@ public class WorkOrder implements Delayed { return Long.compare(this.completionTime, ((WorkOrder) o).completionTime); } + public static JSONObject toJson(WorkOrder workOrder) { + + JSONObject jsonWorkOrder = new JSONObject(); + + jsonWorkOrder.put("workOrderID", workOrder.workOrderID); + jsonWorkOrder.put("vendor", workOrder.vendor.getObjectUUID()); + jsonWorkOrder.put("slots_used", workOrder.slots_used); + jsonWorkOrder.put("total_to_produce", workOrder.total_to_produce); + jsonWorkOrder.put("total_produced", workOrder.total_produced); + jsonWorkOrder.put("multiple_slot_request", workOrder.multiple_slot_request); + jsonWorkOrder.put("production_cost", workOrder.production_cost); + jsonWorkOrder.put("production_cost_total", workOrder.production_cost_total); + jsonWorkOrder.put("templateID", workOrder.templateID); + jsonWorkOrder.put("item_name_override", workOrder.item_name_override); + jsonWorkOrder.put("prefixToken", workOrder.prefixToken); + jsonWorkOrder.put("suffixToken", workOrder.suffixToken); + jsonWorkOrder.put("rollingDuration", workOrder.rollingDuration); + jsonWorkOrder.put("completionTime", workOrder.completionTime); + jsonWorkOrder.put("runCompleted", workOrder.runCompleted); + + ArrayList cookingTokens = new ArrayList<>(); + + for (Item item : workOrder.cooking) + cookingTokens.add(new Integer[]{item.prefixToken, item.suffixToken}); + + jsonWorkOrder.put("cookingTokens", cookingTokens); + + return jsonWorkOrder; + } + public String toString() { LocalDateTime localDateTime = Instant.ofEpochMilli(this.completionTime)