Browse Source

New rolling duration method moved to manager singleton.

combat-2
MagicBot 8 months ago
parent
commit
94ff3cf222
  1. 25
      src/engine/gameManager/ForgeManager.java
  2. 22
      src/engine/gameManager/NPCManager.java
  3. 4
      src/engine/net/client/msg/ItemProductionMsg.java
  4. 2
      src/engine/net/client/msg/ManageNPCMsg.java
  5. 22
      src/engine/objects/NPC.java

25
src/engine/gameManager/ForgeManager.java

@ -23,7 +23,10 @@ import org.pmw.tinylog.Logger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.*; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
public enum ForgeManager implements Runnable { public enum ForgeManager implements Runnable {
@ -146,7 +149,7 @@ public enum ForgeManager implements Runnable {
try { try {
workOrder.workOrderID = workOrderCounter.incrementAndGet(); workOrder.workOrderID = workOrderCounter.incrementAndGet();
workOrder.rollingDuration = ForgeManager.calcRollingDuration(workOrder); workOrder.rollingDuration = NPCManager.calcRollingDuration(workOrder.vendor, workOrder.templateID);
workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration; workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration;
workOrder.slots_used.set(calcAvailableSlots(workOrder)); workOrder.slots_used.set(calcAvailableSlots(workOrder));
@ -197,24 +200,6 @@ public enum ForgeManager implements Runnable {
return validation_result; return validation_result;
} }
public static long calcRollingDuration(WorkOrder workOrder) {
float rollingDuration;
rollingDuration = workOrder.vendor.getBuilding().getRank() * -5L + 40;
rollingDuration = TimeUnit.MINUTES.toMillis((long) rollingDuration);
rollingDuration *= Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue());
ItemTemplate template = ItemTemplate.templates.get(workOrder.templateID);
// Bane circle special case
if (template.item_bane_rank > 0)
rollingDuration = (long) template.item_bane_rank * 60 * 60 * 3 * 1000 * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue());
return (long) rollingDuration;
}
public static int calcAvailableSlots(WorkOrder workOrder) { public static int calcAvailableSlots(WorkOrder workOrder) {
// Slots available in a forge are based on the npc rank // Slots available in a forge are based on the npc rank

22
src/engine/gameManager/NPCManager.java

@ -29,6 +29,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import static engine.math.FastMath.acos; import static engine.math.FastMath.acos;
@ -530,4 +531,25 @@ public enum NPCManager {
return itemList; return itemList;
} }
public static long calcRollingDuration(NPC vendor, int templateID) {
ItemTemplate template = ItemTemplate.templates.get(templateID);
float rollingDuration;
if (template == null)
return 0;
if (template.item_bane_rank > 0)
return (long) (template.item_bane_rank * 60 * 60 * 3 * 1000 * Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue()));
if (vendor.building == null)
return 600;
rollingDuration = vendor.getBuilding().getRank() * -5L + 40;
rollingDuration = TimeUnit.MINUTES.toMillis((long) rollingDuration);
rollingDuration *= Float.parseFloat(ConfigManager.MB_PRODUCTION_RATE.getValue());
return (long) rollingDuration;
}
} }

4
src/engine/net/client/msg/ItemProductionMsg.java

@ -11,6 +11,7 @@ package engine.net.client.msg;
import engine.gameManager.BuildingManager; import engine.gameManager.BuildingManager;
import engine.gameManager.ForgeManager; import engine.gameManager.ForgeManager;
import engine.gameManager.NPCManager;
import engine.loot.WorkOrder; import engine.loot.WorkOrder;
import engine.mbEnums; import engine.mbEnums;
import engine.mbEnums.GameObjectType; import engine.mbEnums.GameObjectType;
@ -259,6 +260,7 @@ public class ItemProductionMsg extends ClientNetMsg {
writer.putInt(toRoll.getValue()); writer.putInt(toRoll.getValue());
NPC vendor = NPC.getFromCache(this.npcUUID); NPC vendor = NPC.getFromCache(this.npcUUID);
if (vendor != null) { if (vendor != null) {
if (toRoll.isComplete()) { if (toRoll.isComplete()) {
writer.putInt(0); writer.putInt(0);
@ -268,7 +270,7 @@ public class ItemProductionMsg extends ClientNetMsg {
timeLeft /= 1000; timeLeft /= 1000;
writer.putInt((int) timeLeft); writer.putInt((int) timeLeft);
writer.putInt(vendor.getRollingTimeInSeconds(toRoll.templateID)); writer.putInt((int) (NPCManager.calcRollingDuration(vendor, toRoll.templateID) * .001));
} }
} else { } else {

2
src/engine/net/client/msg/ManageNPCMsg.java

@ -450,7 +450,7 @@ public class ManageNPCMsg extends ClientNetMsg {
timeLife /= 1000; timeLife /= 1000;
writer.putInt((int) timeLife); writer.putInt((int) timeLife);
writer.putInt(npc.getRollingTimeInSeconds(item.templateID)); writer.putInt((int) (NPCManager.calcRollingDuration(npc, item.templateID) * .001));
writer.putInt(1); writer.putInt(1);
if (item.isComplete()) if (item.isComplete())

22
src/engine/objects/NPC.java

@ -1014,28 +1014,6 @@ public class NPC extends AbstractCharacter {
return filteredItemList; return filteredItemList;
} }
public int getRollingTimeInSeconds(int itemID) {
ItemTemplate ib = ItemTemplate.templates.get(itemID);
if (ib == null)
return 0;
if (ItemTemplate.templates.get(itemID).item_type == ItemType.SCROLL)
return this.getRank() * 60 * 60 * 3;
float time;
if (this.building == null)
return 600;
float rank = this.building.getRank() - 1;
float rate = (float) (2.5 * rank);
time = (20 - rate);
time *= 60;
return (int) time;
}
public boolean remove() { public boolean remove() {
Building building; Building building;

Loading…
Cancel
Save