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