diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index 9a29a29f..0cd17868 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -124,6 +124,28 @@ public enum ForgeManager implements Runnable { workOrder.production_cost_total.putAll(workOrder.production_cost); workOrder.production_cost_total.forEach((key, value) -> workOrder.production_cost_total.compute(key, (k, v) -> v * workOrder.total_to_produce)); + // Deduct gold cost from building + + 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 1; + + Warehouse warehouse = workOrder.vendor.building.getCity().warehouse; + + if (warehouse == null) + return 1; + + workOrder.production_cost_total.forEach((key, value) -> warehouse.resources.compute(key, (k, v) -> warehouse.resources.get(key) - value)); + } + // Create in-memory items and add to collections forgeWorkerOrderBatch(workOrder);