Browse Source

Workorder method moved to workorder

combat-2
MagicBot 8 months ago
parent
commit
0fe04041f6
  1. 46
      src/engine/gameManager/ForgeManager.java
  2. 41
      src/engine/loot/WorkOrder.java

46
src/engine/gameManager/ForgeManager.java

@ -14,7 +14,10 @@ import engine.loot.WorkOrder;
import engine.mbEnums; import engine.mbEnums;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.client.msg.ItemProductionMsg; import engine.net.client.msg.ItemProductionMsg;
import engine.objects.*; import engine.objects.City;
import engine.objects.Item;
import engine.objects.ItemTemplate;
import engine.objects.NPC;
import engine.powers.EffectsBase; import engine.powers.EffectsBase;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -143,7 +146,7 @@ public enum ForgeManager implements Runnable {
// Debit gold and resource costs // Debit gold and resource costs
if (!debitWorkOrderCost(workOrder)) if (!WorkOrder.debitWorkOrderCost(workOrder))
return 58; //58: The formula is beyond the means of this facility return 58; //58: The formula is beyond the means of this facility
// Create new batch of virtual items // Create new batch of virtual items
@ -389,43 +392,4 @@ public enum ForgeManager implements Runnable {
return modifier; return modifier;
} }
public static boolean debitWorkOrderCost(WorkOrder workOrder) {
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 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);
return true;
}
} }

41
src/engine/loot/WorkOrder.java

@ -8,6 +8,7 @@
package engine.loot; package engine.loot;
import engine.gameManager.DbManager;
import engine.gameManager.ForgeManager; import engine.gameManager.ForgeManager;
import engine.mbEnums; import engine.mbEnums;
import engine.objects.Item; import engine.objects.Item;
@ -157,6 +158,46 @@ public class WorkOrder implements Delayed {
return validation_result; return validation_result;
} }
public static boolean debitWorkOrderCost(WorkOrder workOrder) {
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 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);
return true;
}
@Override @Override
public long getDelay(TimeUnit unit) { public long getDelay(TimeUnit unit) {

Loading…
Cancel
Save