From 8ae973f5f402afb1d6f3000583d7555eb51e7ad9 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Wed, 22 Feb 2023 16:40:11 -0500 Subject: [PATCH] Refactored usage of HotZone; added cycle counter. --- src/engine/devcmd/cmds/HotzoneCmd.java | 6 ++--- src/engine/gameManager/ZoneManager.java | 25 +++++++++-------- .../handlers/ArcLoginNotifyMsgHandler.java | 6 ++--- .../net/client/handlers/CityDataHandler.java | 8 ++---- src/engine/net/client/msg/WorldDataMsg.java | 2 +- src/engine/server/world/WorldServer.java | 2 +- src/engine/workthreads/HourlyJobThread.java | 27 +++++++++---------- 7 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/engine/devcmd/cmds/HotzoneCmd.java b/src/engine/devcmd/cmds/HotzoneCmd.java index ff206fe0..2b6d64ef 100644 --- a/src/engine/devcmd/cmds/HotzoneCmd.java +++ b/src/engine/devcmd/cmds/HotzoneCmd.java @@ -52,7 +52,7 @@ public class HotzoneCmd extends AbstractDevCmd { if (input.equalsIgnoreCase("random")) { throwbackInfo(pc, "Previous hotzone: " + hotzoneInfo()); ZoneManager.generateAndSetRandomHotzone(); - zone = ZoneManager.getHotZone(); + zone = ZoneManager.hotZone; } else { zone = ZoneManager.findMacroZoneByName(input); @@ -61,7 +61,7 @@ public class HotzoneCmd extends AbstractDevCmd { return; } - if (zone == ZoneManager.getHotZone()) { + if (zone == ZoneManager.hotZone) { throwbackInfo(pc, "That macrozone is already the Hotzone."); return; } @@ -92,7 +92,7 @@ public class HotzoneCmd extends AbstractDevCmd { private static String hotzoneInfo() { final int hotzoneTimeLeft = FastMath.secondsUntilNextHour(); - final Zone hotzone = ZoneManager.getHotZone(); + final Zone hotzone = ZoneManager.hotZone; String hotzoneInfo; if (hotzone == null) { diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index cd3ce6b4..df3e370c 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -38,7 +38,8 @@ public enum ZoneManager { /* Instance variables */ private static Zone seaFloor = null; - private static Zone hotzone = null; + public static Zone hotZone = null; + public static int hotZoneCycle = 0; // Used with HOTZONE_DURATION from config. private static final ConcurrentHashMap zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); private static final ConcurrentHashMap zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD); @@ -119,24 +120,25 @@ public enum ZoneManager { return ZoneManager.zonesByUUID.values(); } - public static final Zone getHotZone() { - return ZoneManager.hotzone; - } - public static final void setHotZone(final Zone zone) { + if (!zone.isMacroZone()) return; - ZoneManager.hotzone = zone; + + ZoneManager.hotZone = zone; + ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config. zone.hasBeenHotzone = true; zone.becameHotzone = LocalDateTime.now(); + WorldServer.setLastHZChange(System.currentTimeMillis()); + } public static boolean inHotZone(final Vector3fImmutable loc) { - if (ZoneManager.hotzone == null) + if (ZoneManager.hotZone == null) return false; - return (Bounds.collide(loc, ZoneManager.hotzone.getBounds()) == true); + return (Bounds.collide(loc, ZoneManager.hotZone.getBounds()) == true); } public static void setSeaFloor(final Zone value) { @@ -204,15 +206,12 @@ public enum ZoneManager { hotzone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex)); - if (hotzone == null) { Logger.error("Hotzone is null"); return; } - ZoneManager.setHotZone(hotzone); - WorldServer.setLastHZChange(System.currentTimeMillis()); } @@ -234,8 +233,8 @@ public enum ZoneManager { // if (this.hotzone.getUUID() == zone.getUUID()) // return true; //no same hotzone - if (ZoneManager.hotzone != null) - return ZoneManager.hotzone.getObjectUUID() != zone.getObjectUUID(); + if (ZoneManager.hotZone != null) + return ZoneManager.hotZone.getObjectUUID() != zone.getObjectUUID(); return true; } diff --git a/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java b/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java index 63d4ac49..c72b5cb8 100644 --- a/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java +++ b/src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java @@ -1,5 +1,6 @@ package engine.net.client.handlers; +import engine.Enum; import engine.Enum.DispatchChannel; import engine.exception.MsgSendException; import engine.gameManager.*; @@ -125,10 +126,9 @@ public class ArcLoginNotifyMsgHandler extends AbstractClientMsgHandler { } //Send current hotzone - Zone hotzone = ZoneManager.getHotZone(); - if (hotzone != null) { - HotzoneChangeMsg hcm = new HotzoneChangeMsg(hotzone.getObjectType().ordinal(), hotzone.getObjectUUID()); + if (ZoneManager.hotZone != null) { + HotzoneChangeMsg hcm = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); Dispatch dispatch = Dispatch.borrow(player, hcm); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); } diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index 1b304b30..4e9f7640 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -50,10 +50,6 @@ public class CityDataHandler extends AbstractClientMsgHandler { if (playerSession == null) return true; - // Cache current hotZone - - hotZone = ZoneManager.getHotZone(); - // No reason to serialize cities and mines everytime map is // opened. Wait until something has changed. @@ -76,8 +72,8 @@ public class CityDataHandler extends AbstractClientMsgHandler { // If the hotZone has changed then update the client's map accordingly. - if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange() && hotZone != null) { - HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), hotZone.getObjectUUID()); + if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange() && ZoneManager.hotZone != null) { + HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); diff --git a/src/engine/net/client/msg/WorldDataMsg.java b/src/engine/net/client/msg/WorldDataMsg.java index 119163c5..c9391d84 100644 --- a/src/engine/net/client/msg/WorldDataMsg.java +++ b/src/engine/net/client/msg/WorldDataMsg.java @@ -80,7 +80,7 @@ public class WorldDataMsg extends ClientNetMsg { writer.putInt(getTotalMapSize(root) + 1); Zone.serializeForClientMsg(root,writer); - Zone hotzone = ZoneManager.getHotZone(); + Zone hotzone = ZoneManager.hotZone;; if (hotzone == null) writer.putLong(0L); diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 70a5f3fa..2e1a1361 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -430,7 +430,7 @@ public class WorldServer { Logger.info("Running Heraldry Audit for Deleted Players"); Heraldry.AuditHeraldry(); - if (ZoneManager.getHotZone() != null) + if (ZoneManager.hotZone != null) WorldServer.setLastHZChange(System.currentTimeMillis()); Logger.info("Starting Mobile AI FSM"); diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index c7387576..25173743 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -29,8 +29,6 @@ import static engine.server.MBServerStatics.MINE_LATE_WINDOW; public class HourlyJobThread implements Runnable { - private static final int hotzoneCount = 0; - public HourlyJobThread() { } @@ -42,21 +40,22 @@ public class HourlyJobThread implements Runnable { Logger.info("Hourly job is now running."); try { - Zone hotzone = ZoneManager.getHotZone(); - if (hotzone == null) { - //no hotzone? set one. + + //no hotzone? set one. + + if (ZoneManager.hotZone == null) ZoneManager.generateAndSetRandomHotzone(); - } - int hotzoneDuration = Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue()); - if (((LocalDateTime.now().getHour()) - hotzone.becameHotzone.getHour()) >= hotzoneDuration) { + + ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1; + + if (ZoneManager.hotZoneCycle > Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue())) ZoneManager.generateAndSetRandomHotzone(); - hotzone = ZoneManager.getHotZone(); - } - if (hotzone == null) { - Logger.error("Null hotzone returned from mapmanager"); + + + if (ZoneManager.hotZone == null) { + Logger.error("Null HotZone returned from ZoneManager"); } else { - Logger.info("new hotzone: " + hotzone.getName()); - WorldServer.setLastHZChange(System.currentTimeMillis()); + Logger.info("HotZone switched to: " + ZoneManager.hotZone.getName()); } } catch (Exception e) {