forked from MagicBane/Server
Debit building first then warehouse
This commit is contained in:
@@ -141,7 +141,8 @@ public enum ForgeManager implements Runnable {
|
||||
workOrder.production_cost_total.putAll(workOrder.production_cost);
|
||||
workOrder.production_cost_total.forEach((key, value) -> workOrder.production_cost_total.put(key, value * workOrder.total_to_produce));
|
||||
|
||||
// Deduct gold cost from building
|
||||
// Debit gold and resource cost from forge
|
||||
// and / or warehouse
|
||||
|
||||
if (!debitWorkOrderCost(workOrder))
|
||||
return 58; //58: The formula is beyond the means of this facility
|
||||
@@ -387,17 +388,37 @@ public enum ForgeManager implements Runnable {
|
||||
|
||||
public static boolean debitWorkOrderCost(WorkOrder workOrder) {
|
||||
|
||||
int strongbox = workOrder.vendor.building.getStrongboxValue();
|
||||
|
||||
if (workOrder.vendor.building.getCity() == null)
|
||||
return false;
|
||||
|
||||
int strongbox = workOrder.vendor.building.getStrongboxValue();
|
||||
|
||||
// Strongbox can cover total gold cost;
|
||||
|
||||
if (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);
|
||||
|
||||
// Early exit for the forge covering gold only rolls
|
||||
|
||||
if (workOrder.production_cost_total.size() == 1)
|
||||
return true;
|
||||
|
||||
} else {
|
||||
int remainingAmount = 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.put(mbEnums.ResourceType.GOLD, workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD) - remainingAmount));
|
||||
}
|
||||
|
||||
// There is an overflow at this point and a warehouse is required
|
||||
|
||||
Warehouse warehouse = workOrder.vendor.building.getCity().warehouse;
|
||||
|
||||
if (warehouse == null)
|
||||
return false;
|
||||
|
||||
// Deduct total 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));
|
||||
DbManager.WarehouseQueries.UPDATE_WAREHOUSE(warehouse);
|
||||
|
||||
Reference in New Issue
Block a user