Browse Source

Respawn thread configured

combat-2
MagicBot 1 year ago
parent
commit
ff219ce696
  1. 7
      src/engine/mobileAI/MobAI.java
  2. 66
      src/engine/mobileAI/Threads/MobRespawnThread.java
  3. 44
      src/engine/mobileAI/Threads/Respawner.java
  4. 2
      src/engine/objects/Zone.java
  5. 4
      src/engine/server/world/WorldServer.java

7
src/engine/mobileAI/MobAI.java

@ -15,6 +15,7 @@ import engine.gameManager.*;
import engine.math.Vector3f; import engine.math.Vector3f;
import engine.math.Vector3fImmutable; import engine.math.Vector3fImmutable;
import engine.mobileAI.Threads.MobAIThread; import engine.mobileAI.Threads.MobAIThread;
import engine.mobileAI.Threads.Respawner;
import engine.mobileAI.utilities.CombatUtilities; import engine.mobileAI.utilities.CombatUtilities;
import engine.mobileAI.utilities.MovementUtilities; import engine.mobileAI.utilities.MovementUtilities;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
@ -814,10 +815,8 @@ public class MobAI {
} }
} }
} else if (System.currentTimeMillis() > (aiAgent.deathTime + (aiAgent.spawnDelay * 1000))) { } else if (System.currentTimeMillis() > (aiAgent.deathTime + (aiAgent.spawnDelay * 1000))) {
aiAgent.respawnTime = aiAgent.deathTime + (aiAgent.spawnDelay * 1000);
if (Zone.respawnQue.contains(aiAgent) == false) { Respawner.respawnQueue.put(aiAgent);
Zone.respawnQue.add(aiAgent);
}
} }
} catch (Exception e) { } catch (Exception e) {
Logger.info(aiAgent.getObjectUUID() + " " + aiAgent.getName() + " Failed At: CheckForRespawn" + " " + e.getMessage()); Logger.info(aiAgent.getObjectUUID() + " " + aiAgent.getName() + " Failed At: CheckForRespawn" + " " + e.getMessage());

66
src/engine/mobileAI/Threads/MobRespawnThread.java

@ -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.
* <p>
* 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();
}
}

44
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<Mob> 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();
}
}

2
src/engine/objects/Zone.java

@ -29,8 +29,6 @@ import java.util.concurrent.ConcurrentHashMap;
public class Zone extends AbstractWorldObject { public class Zone extends AbstractWorldObject {
public static final Set<Mob> respawnQue = Collections.newSetFromMap(new ConcurrentHashMap<>());
public static long lastRespawn = 0;
public final Set<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set<Building> zoneBuildingSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set<NPC> zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>());
public final Set<Mob> zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set<Mob> zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>());

4
src/engine/server/world/WorldServer.java

@ -23,7 +23,7 @@ import engine.job.JobContainer;
import engine.job.JobScheduler; import engine.job.JobScheduler;
import engine.jobs.LogoutCharacterJob; import engine.jobs.LogoutCharacterJob;
import engine.mobileAI.Threads.MobAIThread; import engine.mobileAI.Threads.MobAIThread;
import engine.mobileAI.Threads.MobRespawnThread; import engine.mobileAI.Threads.Respawner;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
import engine.net.ItemProductionManager; import engine.net.ItemProductionManager;
@ -486,7 +486,7 @@ public class WorldServer {
//intiate mob respawn thread //intiate mob respawn thread
Logger.info("Starting Mob Respawn Thread"); Logger.info("Starting Mob Respawn Thread");
MobRespawnThread.startRespawnThread(); Respawner.startRespawnThread();
// Run maintenance // Run maintenance

Loading…
Cancel
Save