From 94ff3cf2222071c7a758ec9c05c3eddf7ae12308 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 12 May 2024 08:14:06 -0400 Subject: [PATCH] New rolling duration method moved to manager singleton. --- src/engine/gameManager/ForgeManager.java | 25 ++++--------------- src/engine/gameManager/NPCManager.java | 22 ++++++++++++++++ .../net/client/msg/ItemProductionMsg.java | 4 ++- src/engine/net/client/msg/ManageNPCMsg.java | 2 +- src/engine/objects/NPC.java | 22 ---------------- 5 files changed, 31 insertions(+), 44 deletions(-) diff --git a/src/engine/gameManager/ForgeManager.java b/src/engine/gameManager/ForgeManager.java index f4996d6e..2e027b55 100644 --- a/src/engine/gameManager/ForgeManager.java +++ b/src/engine/gameManager/ForgeManager.java @@ -23,7 +23,10 @@ import org.pmw.tinylog.Logger; import java.util.ArrayList; 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; public enum ForgeManager implements Runnable { @@ -146,7 +149,7 @@ public enum ForgeManager implements Runnable { try { workOrder.workOrderID = workOrderCounter.incrementAndGet(); - workOrder.rollingDuration = ForgeManager.calcRollingDuration(workOrder); + workOrder.rollingDuration = NPCManager.calcRollingDuration(workOrder.vendor, workOrder.templateID); workOrder.completionTime = System.currentTimeMillis() + workOrder.rollingDuration; workOrder.slots_used.set(calcAvailableSlots(workOrder)); @@ -197,24 +200,6 @@ public enum ForgeManager implements Runnable { 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) { // Slots available in a forge are based on the npc rank diff --git a/src/engine/gameManager/NPCManager.java b/src/engine/gameManager/NPCManager.java index 59e348e0..d0eb031b 100644 --- a/src/engine/gameManager/NPCManager.java +++ b/src/engine/gameManager/NPCManager.java @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; +import java.util.concurrent.TimeUnit; import static engine.math.FastMath.acos; @@ -530,4 +531,25 @@ public enum NPCManager { 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; + } } diff --git a/src/engine/net/client/msg/ItemProductionMsg.java b/src/engine/net/client/msg/ItemProductionMsg.java index eaf49f60..4931f255 100644 --- a/src/engine/net/client/msg/ItemProductionMsg.java +++ b/src/engine/net/client/msg/ItemProductionMsg.java @@ -11,6 +11,7 @@ package engine.net.client.msg; import engine.gameManager.BuildingManager; import engine.gameManager.ForgeManager; +import engine.gameManager.NPCManager; import engine.loot.WorkOrder; import engine.mbEnums; import engine.mbEnums.GameObjectType; @@ -259,6 +260,7 @@ public class ItemProductionMsg extends ClientNetMsg { writer.putInt(toRoll.getValue()); NPC vendor = NPC.getFromCache(this.npcUUID); + if (vendor != null) { if (toRoll.isComplete()) { writer.putInt(0); @@ -268,7 +270,7 @@ public class ItemProductionMsg extends ClientNetMsg { timeLeft /= 1000; writer.putInt((int) timeLeft); - writer.putInt(vendor.getRollingTimeInSeconds(toRoll.templateID)); + writer.putInt((int) (NPCManager.calcRollingDuration(vendor, toRoll.templateID) * .001)); } } else { diff --git a/src/engine/net/client/msg/ManageNPCMsg.java b/src/engine/net/client/msg/ManageNPCMsg.java index 37bc04f7..69da4d8f 100644 --- a/src/engine/net/client/msg/ManageNPCMsg.java +++ b/src/engine/net/client/msg/ManageNPCMsg.java @@ -450,7 +450,7 @@ public class ManageNPCMsg extends ClientNetMsg { timeLife /= 1000; writer.putInt((int) timeLife); - writer.putInt(npc.getRollingTimeInSeconds(item.templateID)); + writer.putInt((int) (NPCManager.calcRollingDuration(npc, item.templateID) * .001)); writer.putInt(1); if (item.isComplete()) diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index b5c6db6e..74e3b2ca 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -1014,28 +1014,6 @@ public class NPC extends AbstractCharacter { 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() { Building building;