From 113d74cffe360ac40789f09cfb30ff1cc72e89d6 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Wed, 15 Mar 2023 17:17:22 -0500 Subject: [PATCH] method to check if zone has players inside it mob ai check if zone has no players mobs need not perform actions --- src/engine/ai/MobileFSMManager.java | 12 ++++++++++-- src/engine/objects/Zone.java | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/engine/ai/MobileFSMManager.java b/src/engine/ai/MobileFSMManager.java index 8d8d0189..baaa9b02 100644 --- a/src/engine/ai/MobileFSMManager.java +++ b/src/engine/ai/MobileFSMManager.java @@ -9,6 +9,7 @@ package engine.ai; +import engine.gameManager.SessionManager; import engine.gameManager.ZoneManager; import engine.objects.Mob; import engine.objects.Zone; @@ -67,7 +68,10 @@ public class MobileFSMManager { private void execution() { - //Load zone threshold once. + //no players online means no mob action required + if(SessionManager.getActivePlayerCharacterCount() <= 0){ + return; + } long mobPulse = System.currentTimeMillis() + MBServerStatics.AI_PULSE_MOB_THRESHOLD; @@ -79,7 +83,11 @@ public class MobileFSMManager { if (System.currentTimeMillis() > mobPulse) { for (Zone zone : ZoneManager.getAllZones()) { - + //check if any players are in the zone + if(zone.hasPlayers() == false){ + //if zone has no players no need for mobs to do anything + return; + } for (Mob mob : zone.zoneMobSet) { try { diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index 10ca5136..1e4dc342 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -13,6 +13,7 @@ import engine.Enum; import engine.InterestManagement.HeightMap; import engine.db.archive.DataWarehouse; import engine.gameManager.DbManager; +import engine.gameManager.SessionManager; import engine.gameManager.ZoneManager; import engine.math.Bounds; import engine.math.Vector2f; @@ -25,6 +26,7 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -509,5 +511,15 @@ public class Zone extends AbstractGameObject { public float getWorldAltitude() { return worldAltitude; } + public boolean hasPlayers(){ + for(PlayerCharacter pc : SessionManager.getAllActivePlayers()){ + for(Zone zone : ZoneManager.getAllZonesIn(pc.getLoc())) { + if(zone.equals(this)){ + return true; + } + } + } + return false; + } }