Browse Source

json fix in constructor

combat-2
MagicBot 8 months ago
parent
commit
dbf42bfbef
  1. 66
      src/engine/loot/WorkOrder.java

66
src/engine/loot/WorkOrder.java

@ -87,7 +87,7 @@ public class WorkOrder implements Delayed { @@ -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 { @@ -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<Integer[]> 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 { @@ -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 { @@ -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 { @@ -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<Integer[]> 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)

Loading…
Cancel
Save