forked from MagicBane/Server
Reformat and bonus code removal.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
|
||||
|
||||
package engine.ai;
|
||||
|
||||
import engine.gameManager.SessionManager;
|
||||
import engine.gameManager.ZoneManager;
|
||||
import engine.objects.Mob;
|
||||
@@ -22,90 +23,84 @@ import java.time.Instant;
|
||||
|
||||
public class MobileFSMManager {
|
||||
|
||||
private static final MobileFSMManager INSTANCE = new MobileFSMManager();
|
||||
private static final MobileFSMManager INSTANCE = new MobileFSMManager();
|
||||
public static Duration executionTime = Duration.ofNanos(1);
|
||||
public static Duration executionMax = Duration.ofNanos(1);
|
||||
private volatile boolean alive;
|
||||
private long timeOfKill = -1;
|
||||
|
||||
private volatile boolean alive;
|
||||
private long timeOfKill = -1;
|
||||
private MobileFSMManager() {
|
||||
|
||||
public static Duration executionTime = Duration.ofNanos(1);
|
||||
public static Duration executionMax = Duration.ofNanos(1);
|
||||
Runnable worker = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
execution();
|
||||
}
|
||||
};
|
||||
|
||||
private MobileFSMManager() {
|
||||
alive = true;
|
||||
|
||||
Runnable worker = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
execution();
|
||||
}
|
||||
};
|
||||
Thread t = new Thread(worker, "MobileFSMManager");
|
||||
t.start();
|
||||
}
|
||||
|
||||
alive = true;
|
||||
public static MobileFSMManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
Thread t = new Thread(worker, "MobileFSMManager");
|
||||
t.start();
|
||||
}
|
||||
|
||||
public static MobileFSMManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the MobileFSMManager
|
||||
*/
|
||||
public void shutdown() {
|
||||
if (alive) {
|
||||
alive = false;
|
||||
timeOfKill = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Stops the MobileFSMManager
|
||||
*/
|
||||
public void shutdown() {
|
||||
if (alive) {
|
||||
alive = false;
|
||||
timeOfKill = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public long getTimeOfKill() {
|
||||
return this.timeOfKill;
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
return this.alive;
|
||||
}
|
||||
public boolean isAlive() {
|
||||
return this.alive;
|
||||
}
|
||||
|
||||
|
||||
private void execution() {
|
||||
private void execution() {
|
||||
|
||||
//Load zone threshold once.
|
||||
//Load zone threshold once.
|
||||
|
||||
long mobPulse = System.currentTimeMillis() + MBServerStatics.AI_PULSE_MOB_THRESHOLD;
|
||||
Instant startTime;
|
||||
long mobPulse = System.currentTimeMillis() + MBServerStatics.AI_PULSE_MOB_THRESHOLD;
|
||||
Instant startTime;
|
||||
|
||||
while (alive) {
|
||||
while (alive) {
|
||||
|
||||
ThreadUtils.sleep(1);
|
||||
ThreadUtils.sleep(1);
|
||||
|
||||
if (System.currentTimeMillis() > mobPulse) {
|
||||
if (System.currentTimeMillis() > mobPulse) {
|
||||
|
||||
startTime = Instant.now();
|
||||
startTime = Instant.now();
|
||||
|
||||
for (Zone zone : ZoneManager.getAllZones()) {
|
||||
for (Zone zone : ZoneManager.getAllZones()) {
|
||||
|
||||
for (Mob mob : zone.zoneMobSet) {
|
||||
for (Mob mob : zone.zoneMobSet) {
|
||||
|
||||
try {
|
||||
if (mob != null && SessionManager.getActivePlayerCharacterCount() > 0)
|
||||
MobileFSM.DetermineAction(mob);
|
||||
} catch (Exception e) {
|
||||
Logger.error("Mob: " + mob.getName() + " UUID: " + mob.getObjectUUID() + " ERROR: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (mob != null && SessionManager.getActivePlayerCharacterCount() > 0)
|
||||
MobileFSM.DetermineAction(mob);
|
||||
} catch (Exception e) {
|
||||
Logger.error("Mob: " + mob.getName() + " UUID: " + mob.getObjectUUID() + " ERROR: " + e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.executionTime = Duration.between(startTime, Instant.now());
|
||||
executionTime = Duration.between(startTime, Instant.now());
|
||||
|
||||
if (executionTime.compareTo(executionMax) > 0)
|
||||
executionMax = executionTime;
|
||||
if (executionTime.compareTo(executionMax) > 0)
|
||||
executionMax = executionTime;
|
||||
|
||||
mobPulse = System.currentTimeMillis() + MBServerStatics.AI_PULSE_MOB_THRESHOLD;
|
||||
}
|
||||
}
|
||||
}
|
||||
mobPulse = System.currentTimeMillis() + MBServerStatics.AI_PULSE_MOB_THRESHOLD;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user