Browse Source

Calculate cost of workOrder

combat-2
MagicBot 9 months ago
parent
commit
f6c53e51ed
  1. 31
      src/engine/gameManager/ForgeManager.java
  2. 1
      src/engine/loot/WorkOrder.java

31
src/engine/gameManager/ForgeManager.java

@ -11,7 +11,9 @@ package engine.gameManager; @@ -11,7 +11,9 @@ package engine.gameManager;
import engine.loot.WorkOrder;
import engine.mbEnums;
import engine.objects.Item;
import engine.objects.ItemTemplate;
import engine.objects.PlayerCharacter;
import engine.powers.EffectsBase;
import org.pmw.tinylog.Logger;
import java.util.HashMap;
@ -89,9 +91,15 @@ public enum ForgeManager implements Runnable { @@ -89,9 +91,15 @@ public enum ForgeManager implements Runnable {
workOrder.workOrderID = wordOrderCounter.incrementAndGet();
workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration;
workOrder.slotCount = calcAvailableSlots(workOrder);
workOrder.production_cost = calcProductionCost(workOrder);
workOrder.rollingDuration = ForgeManager.calcRollingDuration(workOrder);
// Cost to execute this workOrder
workOrder.production_cost = calcProductionCost(workOrder);
for (mbEnums.ResourceType resourceType : workOrder.production_cost.keySet())
workOrder.production_cost.compute(resourceType, (k, resourceValue) -> resourceValue * workOrder.total_to_produce);
// Single item rolls are total_to_produce of 0;
if (workOrder.slotCount > 0 && workOrder.total_to_produce == 0)
@ -149,7 +157,28 @@ public enum ForgeManager implements Runnable { @@ -149,7 +157,28 @@ public enum ForgeManager implements Runnable {
}
public static HashMap<mbEnums.ResourceType, Integer> calcProductionCost(WorkOrder workOrder) {
HashMap<mbEnums.ResourceType, Integer> production_cost = new HashMap<>();
ItemTemplate template = ItemTemplate.templates.get(workOrder.templateID);
// Add gold and resource costs from template
production_cost.put(mbEnums.ResourceType.GOLD, template.item_value);
production_cost.putAll(template.item_resource_cost);
// Calculate cost of prefix and suffix
if (workOrder.prefixToken != 0) {
EffectsBase prefix = PowersManager.getEffectByToken(workOrder.prefixToken);
EffectsBase prefixValue = PowersManager.getEffectByIDString(prefix.getIDString() + 'A');
production_cost.putAll(prefixValue.getResourcesForEffect());
}
if (workOrder.suffixToken != 0) {
EffectsBase suffix = PowersManager.getEffectByToken(workOrder.suffixToken);
EffectsBase suffixValue = PowersManager.getEffectByIDString(suffix.getIDString() + 'A');
production_cost.putAll(suffixValue.getResourcesForEffect());
}
return production_cost;
}

1
src/engine/loot/WorkOrder.java

@ -28,6 +28,7 @@ public class WorkOrder implements Delayed { @@ -28,6 +28,7 @@ public class WorkOrder implements Delayed {
public int total_to_produce;
public int total_produced;
public HashMap<mbEnums.ResourceType, Integer> production_cost = new HashMap<>();
public HashMap<mbEnums.ResourceType, Integer> production_cost_total = new HashMap<>();
public int templateID;
public String itemName;
public int prefixToken;

Loading…
Cancel
Save