Browse Source

Withdraw logic cleanup

combat-2
MagicBot 6 months ago
parent
commit
dd72e20ff9
  1. 14
      src/engine/loot/WorkOrder.java

14
src/engine/loot/WorkOrder.java

@ -145,6 +145,8 @@ public class WorkOrder implements Delayed { @@ -145,6 +145,8 @@ public class WorkOrder implements Delayed {
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)
return false;
@ -154,7 +156,6 @@ public class WorkOrder implements Delayed { @@ -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 { @@ -165,13 +166,20 @@ public class WorkOrder implements Delayed {
if (warehouse == null)
return false;
// 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);
workOrder.production_cost_total.put(mbEnums.ResourceType.GOLD, workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) - overflowAmount);
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;

Loading…
Cancel
Save