Browse Source

Method moved to Warehouse

combat-2
MagicBot 8 months ago
parent
commit
7309fdc62f
  1. 38
      src/engine/gameManager/ForgeManager.java
  2. 36
      src/engine/objects/Warehouse.java

38
src/engine/gameManager/ForgeManager.java

@ -166,7 +166,7 @@ public enum ForgeManager implements Runnable {
if (!workOrder.vendor.getItemModTable().contains((template.modTable))) if (!workOrder.vendor.getItemModTable().contains((template.modTable)))
return 59; //59: This hireling does not have this formula 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 return 10; //18: You can't really afford that
// Forge must be protected in order to access warehouse. // Forge must be protected in order to access warehouse.
@ -244,42 +244,6 @@ public enum ForgeManager implements Runnable {
return production_cost; return production_cost;
} }
public static HashMap<mbEnums.ResourceType, Integer> calcCostOverrun(WorkOrder workOrder) {
HashMap<mbEnums.ResourceType, Integer> 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<mbEnums.ResourceType, Integer> 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) { public static Item forgeItem(WorkOrder workOrder) {
// Create new item from specified template // Create new item from specified template

36
src/engine/objects/Warehouse.java

@ -11,6 +11,7 @@ package engine.objects;
import engine.gameManager.ChatManager; import engine.gameManager.ChatManager;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
import engine.loot.WorkOrder;
import engine.mbEnums; import engine.mbEnums;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
@ -635,4 +636,39 @@ public class Warehouse {
return warehouse.locked.contains(resourceType); return warehouse.locked.contains(resourceType);
} }
public static HashMap<mbEnums.ResourceType, Integer> calcCostOverrun(WorkOrder workOrder) {
HashMap<mbEnums.ResourceType, Integer> 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<mbEnums.ResourceType, Integer> 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;
}
} }
Loading…
Cancel
Save