From 10cd3636f722619c233f506970fea47dd0afaa06 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sat, 18 Feb 2023 15:04:34 -0600 Subject: [PATCH] hotzone cleanup --- src/engine/gameManager/ZoneManager.java | 2 ++ src/engine/objects/Zone.java | 3 ++- src/engine/workthreads/HourlyJobThread.java | 14 +++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 80adcd74..41cc0cf0 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -20,6 +20,7 @@ import engine.server.MBServerStatics; import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -127,6 +128,7 @@ public enum ZoneManager { return; ZoneManager.hotzone = zone; zone.hasBeenHotzone = true; + zone.becameHotzone = LocalDateTime.now(); } public static boolean inHotZone(final Vector3fImmutable loc) { diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index 0a9c23be..a758279d 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -23,6 +23,7 @@ import org.pmw.tinylog.Logger; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Collections; import java.util.Set; @@ -60,7 +61,7 @@ public class Zone extends AbstractGameObject { public final Set zoneNPCSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public final Set zoneMobSet = Collections.newSetFromMap(new ConcurrentHashMap<>()); public boolean hasBeenHotzone = false; - public int hoursAsHotzone = 0; + public LocalDateTime becameHotzone = null; /** * ResultSet Constructor */ diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 0983499d..77c86626 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -42,17 +42,21 @@ public class HourlyJobThread implements Runnable { Logger.info("Hourly job is now running."); try { - - ZoneManager.generateAndSetRandomHotzone(); Zone hotzone = ZoneManager.getHotZone(); + if(hotzone == null){ + //no hotzone? set one. + ZoneManager.generateAndSetRandomHotzone(); + } + int hotzoneDuration = Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue()); + if(((LocalDateTime.now().getHour()) - hotzone.becameHotzone.getHour()) >= hotzoneDuration) { + ZoneManager.generateAndSetRandomHotzone(); + hotzone = ZoneManager.getHotZone(); + } if (hotzone == null) { Logger.error("Null hotzone returned from mapmanager"); } else { - hotzone.hoursAsHotzone += 1; - if(hotzone.hoursAsHotzone >= Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue())) { Logger.info("new hotzone: " + hotzone.getName()); WorldServer.setLastHZChange(System.currentTimeMillis()); - } } } catch (Exception e) {