diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index db80987b..75c627fa 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -166,7 +166,7 @@ public enum ForgeManager implements Runnable { if (!workOrder.vendor.getItemModTable().contains((template.modTable))) return 59; //59: This hireling does not have this formula - if (!calcCostOverrun(workOrder).isEmpty()) + if (!Warehouse.calcCostOverrun(workOrder).isEmpty()) return 10; //18: You can't really afford that // Forge must be protected in order to access warehouse. @@ -244,42 +244,6 @@ public enum ForgeManager implements Runnable { return production_cost; } - public static HashMap calcCostOverrun(WorkOrder workOrder) { - - HashMap costMap = new HashMap<>(); - Warehouse warehouse; - - // See if we can meet gold only requirements and early exit - - if (workOrder.production_cost_total.size() == 1) { - if (workOrder.vendor.building.getStrongboxValue() > workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD)) - return costMap; - } - - // Gold deficit exists so a warehouse is required - - warehouse = workOrder.vendor.building.getCity() == null ? null : workOrder.vendor.building.getCity().warehouse; - - if (warehouse == null) - return workOrder.production_cost_total; - - // Method returns a map of resourceType that a transaction overdrafts. - - HashMap overflowMap = new HashMap<>(); - - for (mbEnums.ResourceType resourceType : workOrder.production_cost_total.keySet()) { - - int debit = warehouse.resources.get(resourceType) - workOrder.production_cost_total.get(resourceType); - - // Locked resources are always unavailable - - if (debit < 0 || warehouse.locked.contains(resourceType)) - overflowMap.put(resourceType, debit); - } - - return overflowMap; - } - public static Item forgeItem(WorkOrder workOrder) { // Create new item from specified template diff --git a/src/engine/objects/Warehouse.java b/src/engine/objects/Warehouse.java index 4891701e..53eebeba 100644 --- a/src/engine/objects/Warehouse.java +++ b/src/engine/objects/Warehouse.java @@ -11,6 +11,7 @@ package engine.objects; import engine.gameManager.ChatManager; import engine.gameManager.DbManager; +import engine.loot.WorkOrder; import engine.mbEnums; import engine.net.Dispatch; import engine.net.DispatchMessage; @@ -635,4 +636,39 @@ public class Warehouse { return warehouse.locked.contains(resourceType); } + public static HashMap calcCostOverrun(WorkOrder workOrder) { + + HashMap costMap = new HashMap<>(); + Warehouse warehouse; + + // See if we can meet gold only requirements and early exit + + if (workOrder.production_cost_total.size() == 1) { + if (workOrder.vendor.building.getStrongboxValue() > workOrder.production_cost_total.get(mbEnums.ResourceType.GOLD)) + return costMap; + } + + // Gold deficit exists so a warehouse is required + + warehouse = workOrder.vendor.building.getCity() == null ? null : workOrder.vendor.building.getCity().warehouse; + + if (warehouse == null) + return workOrder.production_cost_total; + + // Method returns a map of resourceType that a transaction overdrafts. + + HashMap overflowMap = new HashMap<>(); + + for (mbEnums.ResourceType resourceType : workOrder.production_cost_total.keySet()) { + + int debit = warehouse.resources.get(resourceType) - workOrder.production_cost_total.get(resourceType); + + // Locked resources are always unavailable + + if (debit < 0 || warehouse.locked.contains(resourceType)) + overflowMap.put(resourceType, debit); + } + + return overflowMap; + } } \ No newline at end of file