From ff219ce696366e9d84427fae4027cd76b6587210 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Mon, 23 Oct 2023 00:32:59 -0400 Subject: [PATCH] Respawn thread configured --- src/engine/mobileAI/MobAI.java | 7 +- .../mobileAI/Threads/MobRespawnThread.java | 66 ------------------- src/engine/mobileAI/Threads/Respawner.java | 44 +++++++++++++ src/engine/objects/Zone.java | 2 - src/engine/server/world/WorldServer.java | 4 +- 5 files changed, 49 insertions(+), 74 deletions(-) delete mode 100644 src/engine/mobileAI/Threads/MobRespawnThread.java create mode 100644 src/engine/mobileAI/Threads/Respawner.java diff --git a/src/engine/mobileAI/MobAI.java b/src/engine/mobileAI/MobAI.java index cc5158cd..169a7157 100644 --- a/src/engine/mobileAI/MobAI.java +++ b/src/engine/mobileAI/MobAI.java @@ -15,6 +15,7 @@ import engine.gameManager.*; import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.mobileAI.Threads.MobAIThread; +import engine.mobileAI.Threads.Respawner; import engine.mobileAI.utilities.CombatUtilities; import engine.mobileAI.utilities.MovementUtilities; import engine.net.DispatchMessage; @@ -814,10 +815,8 @@ public class MobAI { } } } else if (System.currentTimeMillis() > (aiAgent.deathTime + (aiAgent.spawnDelay * 1000))) { - - if (Zone.respawnQue.contains(aiAgent) == false) { - Zone.respawnQue.add(aiAgent); - } + aiAgent.respawnTime = aiAgent.deathTime + (aiAgent.spawnDelay * 1000); + Respawner.respawnQueue.put(aiAgent); } } catch (Exception e) { Logger.info(aiAgent.getObjectUUID() + " " + aiAgent.getName() + " Failed At: CheckForRespawn" + " " + e.getMessage()); diff --git a/src/engine/mobileAI/Threads/MobRespawnThread.java b/src/engine/mobileAI/Threads/MobRespawnThread.java deleted file mode 100644 index 24e2f281..00000000 --- a/src/engine/mobileAI/Threads/MobRespawnThread.java +++ /dev/null @@ -1,66 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - - -package engine.mobileAI.Threads; -import engine.gameManager.ZoneManager; -import engine.objects.Mob; -import engine.objects.Zone; -import org.pmw.tinylog.Logger; - -/** - * Thread blocks until MagicBane dispatch messages are - * enqueued then processes them in FIFO order. The collection - * is thread safe. - *

- * Any large messages not time sensitive such as load object - * sent to more than a single individual should be spawned - * individually on a DispatchMessageThread. - */ - -public class MobRespawnThread implements Runnable { - - - public MobRespawnThread() { - Logger.info(" MobRespawnThread thread has started!"); - - } - - @Override - public void run() { - - while (true) { - - try { - for (Zone zone : ZoneManager.getAllZones()) { - - if (zone.respawnQue.isEmpty() == false && zone.lastRespawn + 100 < System.currentTimeMillis()) { - - Mob respawner = zone.respawnQue.iterator().next(); - - if (respawner == null) - continue; - - respawner.respawn(); - zone.respawnQue.remove(respawner); - zone.lastRespawn = System.currentTimeMillis(); - } - } - } catch (Exception e) { - Logger.error(e); - } - - } - } - public static void startRespawnThread() { - Thread respawnThread; - respawnThread = new Thread(new MobRespawnThread()); - respawnThread.setName("respawnThread"); - respawnThread.start(); - } -} diff --git a/src/engine/mobileAI/Threads/Respawner.java b/src/engine/mobileAI/Threads/Respawner.java new file mode 100644 index 00000000..1da3778a --- /dev/null +++ b/src/engine/mobileAI/Threads/Respawner.java @@ -0,0 +1,44 @@ +// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . +// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· +// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ +// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ +// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ +// Magicbane Emulator Project © 2013 - 2022 +// www.magicbane.com + + +package engine.mobileAI.Threads; +import engine.objects.Mob; +import org.pmw.tinylog.Logger; + +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.DelayQueue; + +public enum Respawner implements Runnable { + Respawner; + + public static BlockingQueue respawnQueue = new DelayQueue(); + + @Override + public void run() { + + while (true) { + + try { + Mob mobile = respawnQueue.take(); + mobile.respawn(); + } catch (InterruptedException e) { + Logger.error(e.toString()); + } + + } + + } + + public static void startRespawnThread() { + Thread respawnThread; + respawnThread = new Thread(Respawner); + respawnThread.setName("respawnThread"); + respawnThread.start(); + } +} diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index 37092cee..229d18ef 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -29,8 +29,6 @@ import java.util.concurrent.ConcurrentHashMap; public class Zone extends AbstractWorldObject { - public static final Set respawnQue = Collections.newSetFromMap(new ConcurrentHashMap<>()); - public static long lastRespawn = 0; public final Set zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 627d495b..f1cb0d0c 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -23,7 +23,7 @@ import engine.job.JobContainer; import engine.job.JobScheduler; import engine.jobs.LogoutCharacterJob; import engine.mobileAI.Threads.MobAIThread; -import engine.mobileAI.Threads.MobRespawnThread; +import engine.mobileAI.Threads.Respawner; import engine.net.Dispatch; import engine.net.DispatchMessage; import engine.net.ItemProductionManager; @@ -486,7 +486,7 @@ public class WorldServer { //intiate mob respawn thread Logger.info("Starting Mob Respawn Thread"); - MobRespawnThread.startRespawnThread(); + Respawner.startRespawnThread(); // Run maintenance