Browse Source

Deduct cost from warehouse

combat-2
MagicBot 7 months ago
parent
commit
919b29c38f
  1. 22
      src/engine/gameManager/ForgeManager.java

22
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.putAll(workOrder.production_cost);
workOrder.production_cost_total.forEach((key, value) -> workOrder.production_cost_total.compute(key, (k, v) -> v * workOrder.total_to_produce)); 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 // Create in-memory items and add to collections
forgeWorkerOrderBatch(workOrder); forgeWorkerOrderBatch(workOrder);

Loading…
Cancel
Save