Browse Source

Workorder to json work

combat-2
MagicBot 8 months ago
parent
commit
6499a16cc2
  1. 5
      src/engine/gameManager/ForgeManager.java
  2. 34
      src/engine/loot/WorkOrder.java

5
src/engine/gameManager/ForgeManager.java

@ -16,6 +16,7 @@ import engine.net.DispatchMessage;
import engine.net.client.msg.ItemProductionMsg; import engine.net.client.msg.ItemProductionMsg;
import engine.objects.*; import engine.objects.*;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import org.json.simple.JSONObject;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
@ -142,8 +143,8 @@ public enum ForgeManager implements Runnable {
vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder); vendorWorkOrderLookup.get(workOrder.vendor).add(workOrder);
forge.add(workOrder); forge.add(workOrder);
String jsonWorkOrder = WorkOrder.toJson(workOrder); JSONObject jsonWorkOrder = WorkOrder.toJson(workOrder);
jsonWorkOrder = jsonWorkOrder.trim(); String stringOrder = jsonWorkOrder.toString();
} catch (Exception e) { } catch (Exception e) {
Logger.error(e); Logger.error(e);

34
src/engine/loot/WorkOrder.java

@ -11,12 +11,13 @@ package engine.loot;
import engine.mbEnums; import engine.mbEnums;
import engine.objects.Item; import engine.objects.Item;
import engine.objects.NPC; import engine.objects.NPC;
import org.json.simple.JSONValue; import org.json.simple.JSONObject;
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.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Delayed; 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); JSONObject jsonWorkOrder = new JSONObject();
return jsonString;
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<Integer[]> cookingTokens = new ArrayList<>();
for (Item item : workOrder.cooking)
cookingTokens.add(new Integer[]{item.prefixToken, item.suffixToken});
jsonWorkOrder.put("cookingTokens", cookingTokens);
return jsonWorkOrder;
} }
@Override @Override

Loading…
Cancel
Save