|
|
|
@ -14,7 +14,10 @@ import engine.loot.WorkOrder;
@@ -14,7 +14,10 @@ import engine.loot.WorkOrder;
|
|
|
|
|
import engine.mbEnums; |
|
|
|
|
import engine.net.DispatchMessage; |
|
|
|
|
import engine.net.client.msg.ItemProductionMsg; |
|
|
|
|
import engine.objects.*; |
|
|
|
|
import engine.objects.Item; |
|
|
|
|
import engine.objects.ItemTemplate; |
|
|
|
|
import engine.objects.NPC; |
|
|
|
|
import engine.objects.Warehouse; |
|
|
|
|
import engine.powers.EffectsBase; |
|
|
|
|
import org.pmw.tinylog.Logger; |
|
|
|
|
|
|
|
|
@ -100,18 +103,24 @@ public enum ForgeManager implements Runnable {
@@ -100,18 +103,24 @@ public enum ForgeManager implements Runnable {
|
|
|
|
|
|
|
|
|
|
public static int submit(WorkOrder workOrder) { |
|
|
|
|
|
|
|
|
|
// Make sure vendor can roll the formulae, warehouse can afford
|
|
|
|
|
// the wordOrder and other related checks.
|
|
|
|
|
|
|
|
|
|
int validation_result = ItemManager.validate(workOrder); |
|
|
|
|
|
|
|
|
|
// The return code is used by the submitter as a
|
|
|
|
|
// popup error message to the player.
|
|
|
|
|
|
|
|
|
|
if (validation_result != 0) |
|
|
|
|
return validation_result; |
|
|
|
|
|
|
|
|
|
// Configure this production run.
|
|
|
|
|
|
|
|
|
|
workOrder.workOrderID = wordOrderCounter.incrementAndGet(); |
|
|
|
|
workOrder.rollingDuration = ForgeManager.calcRollingDuration(workOrder); |
|
|
|
|
workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration; |
|
|
|
|
workOrder.slots_used = calcAvailableSlots(workOrder); |
|
|
|
|
|
|
|
|
|
// Configure this production run.
|
|
|
|
|
|
|
|
|
|
workOrder.total_produced = 0; |
|
|
|
|
workOrder.total_to_produce *= workOrder.slots_used; |
|
|
|
|
workOrder.production_cost = calcProductionCost(workOrder); |
|
|
|
@ -139,30 +148,6 @@ public enum ForgeManager implements Runnable {
@@ -139,30 +148,6 @@ public enum ForgeManager implements Runnable {
|
|
|
|
|
return validation_result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean debitWorkOrderCost(WorkOrder workOrder) { |
|
|
|
|
|
|
|
|
|
int strongbox = workOrder.vendor.building.getStrongboxValue(); |
|
|
|
|
int overflow = strongbox - workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD); |
|
|
|
|
|
|
|
|
|
if (overflow > 1 || workOrder.production_cost_total.size() > 1) { |
|
|
|
|
|
|
|
|
|
// Deduct total cost from warehouse
|
|
|
|
|
|
|
|
|
|
City city = workOrder.vendor.building.getCity(); |
|
|
|
|
|
|
|
|
|
if (city == null) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
Warehouse warehouse = workOrder.vendor.building.getCity().warehouse; |
|
|
|
|
|
|
|
|
|
if (warehouse == null) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
workOrder.production_cost_total.forEach((key, value) -> warehouse.resources.compute(key, (k, v) -> warehouse.resources.get(key) - value)); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static long calcRollingDuration(WorkOrder workOrder) { |
|
|
|
|
|
|
|
|
|
float rollingDuration; |
|
|
|
@ -377,4 +362,25 @@ public enum ForgeManager implements Runnable {
@@ -377,4 +362,25 @@ public enum ForgeManager implements Runnable {
|
|
|
|
|
return modifier; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static boolean debitWorkOrderCost(WorkOrder workOrder) { |
|
|
|
|
|
|
|
|
|
int strongbox = workOrder.vendor.building.getStrongboxValue(); |
|
|
|
|
int overflow = strongbox - workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD); |
|
|
|
|
|
|
|
|
|
if (overflow > 1 || workOrder.production_cost_total.size() > 1) { |
|
|
|
|
|
|
|
|
|
// Deduct total cost from warehouse
|
|
|
|
|
|
|
|
|
|
if (workOrder.vendor.building.getCity() == null) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
Warehouse warehouse = workOrder.vendor.building.getCity().warehouse; |
|
|
|
|
|
|
|
|
|
if (warehouse == null) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
workOrder.production_cost_total.forEach((key, value) -> warehouse.resources.compute(key, (k, v) -> warehouse.resources.get(key) - value)); |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|