From 6499a16cc2907752a6cbdecf87fb3043d890b9d8 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 22 Apr 2024 08:53:33 -0400 Subject: [PATCH] Workorder to json work --- src/engine/gameManager/ForgeManager.java | 5 ++-- src/engine/loot/WorkOrder.java | 34 +++++++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 5ddf3064..6e796582 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -16,6 +16,7 @@ import engine.net.DispatchMessage; import engine.net.client.msg.ItemProductionMsg; import engine.objects.*; import engine.powers.EffectsBase; +import org.json.simple.JSONObject; import org.pmw.tinylog.Logger; import java.util.ArrayList; @@ -142,8 +143,8 @@ public enum ForgeManager implements Runnable { vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder); forge.add(workOrder); - String jsonWorkOrder = WorkOrder.toJson(workOrder); - jsonWorkOrder = jsonWorkOrder.trim(); + JSONObject jsonWorkOrder = WorkOrder.toJson(workOrder); + String stringOrder = jsonWorkOrder.toString(); } catch (Exception e) { Logger.error(e); diff --git a/src/engine/loot/WorkOrder.java b/src/engine/loot/WorkOrder.java index c90f9a15..76586f00 100644 --- a/src/engine/loot/WorkOrder.java +++ b/src/engine/loot/WorkOrder.java @@ -11,12 +11,13 @@ package engine.loot; import engine.mbEnums; import engine.objects.Item; import engine.objects.NPC; -import org.json.simple.JSONValue; +import org.json.simple.JSONObject; import java.time.Duration; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; +import java.util.ArrayList; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Delayed; @@ -50,10 +51,35 @@ public class WorkOrder implements Delayed { } - public static String toJson(WorkOrder workOrder) { + public static JSONObject toJson(WorkOrder workOrder) { - String jsonString = JSONValue.toJSONString(workOrder); - return jsonString; + JSONObject jsonWorkOrder = new JSONObject(); + + jsonWorkOrder.put("jsonWorkOrder", 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; } @Override