Browse Source

Method moved to Warehouse

combat-2
MagicBot 7 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 { @@ -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 { @@ -244,42 +244,6 @@ public enum ForgeManager implements Runnable {
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) {
// Create new item from specified template

36
src/engine/objects/Warehouse.java

@ -11,6 +11,7 @@ package engine.objects; @@ -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 { @@ -635,4 +636,39 @@ public class Warehouse {
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