From 96387aa4f40c4a12da505eb562c6c11edb34d52b Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 19 Aug 2024 19:48:52 -0400 Subject: [PATCH] Auto-leveling camp modifications --- .../mobileAI/Threads/MobRespawnThread.java | 77 +++++++++++-------- src/engine/objects/Zone.java | 2 + src/engine/util/ZoneLevel.java | 1 + 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/src/engine/mobileAI/Threads/MobRespawnThread.java b/src/engine/mobileAI/Threads/MobRespawnThread.java index 1d0b72fb..066ccbbe 100644 --- a/src/engine/mobileAI/Threads/MobRespawnThread.java +++ b/src/engine/mobileAI/Threads/MobRespawnThread.java @@ -26,7 +26,6 @@ import org.pmw.tinylog.Logger; public class MobRespawnThread implements Runnable { - public MobRespawnThread() { Logger.info(" MobRespawnThread thread has started!"); @@ -35,9 +34,14 @@ public class MobRespawnThread implements Runnable { @Override public void run() { + long startTime = System.currentTimeMillis(); + long rollingKeepFraction = (Zone.rollingAvgMobsAliveDepth - 1) / Zone.rollingAvgMobsAliveDepth; + long rollingAddFraction = 1 / Zone.rollingAvgMobsAliveDepth; + while (true) { try { + for (Zone zone : ZoneManager.getAllZones()) { /* @@ -51,53 +55,64 @@ public class MobRespawnThread implements Runnable { } */ + int aliveCount = 0; int deadCount = 0; for (Mob mob : zone.zoneMobSet) { - if (!mob.isAlive()) { + if (mob.isAlive()) { + aliveCount = aliveCount + 1; + } + else { deadCount = deadCount + 1; } } - if (deadCount > Math.floor(zone.zoneMobSet.size() / 2.0)) { - if (zone.levelUpTimer == 0) { - zone.levelUpTimer = System.currentTimeMillis(); - } - else if (zone.levelUpTimer + ZoneLevel.msTolevelUp < System.currentTimeMillis()) { - zone.setCampLvl(zone.getCampLvl() + 1); - - zone.levelUpTimer = 0; - } - } - else if (deadCount == 0) { + zone.rollingAvgMobsAlive = + ((zone.rollingAvgMobsAlive * (Zone.rollingAvgMobsAliveDepth - 1) + aliveCount) / Zone.rollingAvgMobsAliveDepth); - if (zone.levelDownTimer == 0) { - zone.levelDownTimer = System.currentTimeMillis(); - } - else if (zone.levelDownTimer + ZoneLevel.msToLevelDown < System.currentTimeMillis()) { - if (zone.getCampLvl() > 0) { + /* + if (startTime + ZoneLevel.msDelayToCampLevel < System.currentTimeMillis()) { + if (aliveCount > Math.floor(zone.zoneMobSet.size() / 2.0)) { + if (zone.levelUpTimer == 0) { + zone.levelUpTimer = System.currentTimeMillis(); + } else if (zone.levelUpTimer + ZoneLevel.msTolevelUp < System.currentTimeMillis()) { zone.setCampLvl(zone.getCampLvl() + 1); - zone.levelDownTimer = 0; + zone.levelUpTimer = 0; } + } else if (aliveCount == 0) { + + if (zone.levelDownTimer == 0) { + zone.levelDownTimer = System.currentTimeMillis(); + } else if (zone.levelDownTimer + ZoneLevel.msToLevelDown < System.currentTimeMillis()) { + if (zone.getCampLvl() > 0) { + zone.setCampLvl(zone.getCampLvl() + 1); + + zone.levelDownTimer = 0; + } + } + } else { + zone.levelUpTimer = 0; + zone.levelDownTimer = 0; } } - else { - zone.levelUpTimer = 0; - zone.levelDownTimer = 0; - } + */ + } - if (zone.respawnQue.isEmpty() == false && zone.lastRespawn + 100 < System.currentTimeMillis()) { + // -------------------------------------------------------------------------------------------------------------------- + // Manage mob respawn + // -------------------------------------------------------------------------------------------------------------------- + if (!Zone.respawnQue.isEmpty() && Zone.lastRespawn + 100 < System.currentTimeMillis()) { - Mob respawner = zone.respawnQue.iterator().next(); + Mob respawner = Zone.respawnQue.iterator().next(); - if (respawner == null) - continue; + if (respawner == null) + continue; - respawner.respawn(); - zone.respawnQue.remove(respawner); - zone.lastRespawn = System.currentTimeMillis(); - } + respawner.respawn(); + Zone.respawnQue.remove(respawner); + Zone.lastRespawn = System.currentTimeMillis(); } + } catch (Exception e) { Logger.error(e); } diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index 6f37660c..db505b07 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -68,6 +68,8 @@ public class Zone extends AbstractGameObject { private int campLvl = 0; public long levelUpTimer = 0; public long levelDownTimer = 0; + public int rollingAvgMobsAlive = 0; + public static final int rollingAvgMobsAliveDepth = 100; /** * ResultSet Constructor diff --git a/src/engine/util/ZoneLevel.java b/src/engine/util/ZoneLevel.java index 884f3c2f..2b5ebe28 100644 --- a/src/engine/util/ZoneLevel.java +++ b/src/engine/util/ZoneLevel.java @@ -16,6 +16,7 @@ public class ZoneLevel { public static final int queueLengthToLevelUp = 5; public static final int msToLevelDown = 60 * 1000; public static final int msTolevelUp = 60 * 1000; + public static final long msDelayToCampLevel = 60 * 1000; private static final String[] nameMap = {