diff --git a/src/engine/loot/WorkOrder.java b/src/engine/loot/WorkOrder.java index 52631680..2871dd0d 100644 --- a/src/engine/loot/WorkOrder.java +++ b/src/engine/loot/WorkOrder.java @@ -145,6 +145,8 @@ public class WorkOrder implements Delayed { public static boolean withdrawWorkOrderCost(WorkOrder workOrder) { + HashMap modified_production_cost = new HashMap<>(workOrder.production_cost_total); + if (workOrder.vendor.building.getCity() == null) return false; @@ -154,7 +156,6 @@ public class WorkOrder implements Delayed { if (workOrder.production_cost_total.size() == 1 && workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) <= strongbox) { workOrder.vendor.building.setStrongboxValue(strongbox - workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD)); - workOrder.production_cost_total.put(mbEnums.ResourceType.GOLD, 0); return true; } @@ -165,13 +166,20 @@ public class WorkOrder implements Delayed { if (warehouse == null) return false; - int overflowAmount = workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) - strongbox; - workOrder.vendor.building.setStrongboxValue(0); - workOrder.production_cost_total.put(mbEnums.ResourceType.GOLD, workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) - overflowAmount); + // Take from strongbox first and deduct from production cost total + + if (workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) <= strongbox) { + workOrder.vendor.building.setStrongboxValue(strongbox - workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD)); + modified_production_cost.put(mbEnums.ResourceType.GOLD, 0); + } else { + int overflowAmount = workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) - strongbox; + workOrder.vendor.building.setStrongboxValue(0); + modified_production_cost.put(mbEnums.ResourceType.GOLD, workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) - overflowAmount); + } // Deduct total production cost from warehouse - workOrder.production_cost_total.forEach((key, value) -> warehouse.resources.put(key, warehouse.resources.get(key) - value)); + modified_production_cost.forEach((key, value) -> warehouse.resources.put(key, warehouse.resources.get(key) - value)); DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse); return true;