Withdraw logic cleanup

This commit is contained in:
2024-05-09 14:04:19 -04:00
parent f465ea4045
commit dd72e20ff9
+13 -5
View File
@@ -145,6 +145,8 @@ public class WorkOrder implements Delayed {
public static boolean withdrawWorkOrderCost(WorkOrder workOrder) { public static boolean withdrawWorkOrderCost(WorkOrder workOrder) {
HashMap<mbEnums.ResourceType, Integer> modified_production_cost = new HashMap<>(workOrder.production_cost_total);
if (workOrder.vendor.building.getCity() == null) if (workOrder.vendor.building.getCity() == null)
return false; 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) { 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.vendor.building.setStrongboxValue(strongbox - workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD));
workOrder.production_cost_total.put(mbEnums.ResourceType.GOLD, 0);
return true; return true;
} }
@@ -165,13 +166,20 @@ public class WorkOrder implements Delayed {
if (warehouse == null) if (warehouse == null)
return false; return false;
int overflowAmount = workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) - strongbox; // Take from strongbox first and deduct from production cost total
workOrder.vendor.building.setStrongboxValue(0);
workOrder.production_cost_total.put(mbEnums.ResourceType.GOLD, workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) - overflowAmount); 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 // 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); DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse);
return true; return true;