From 176fdb51daf93a6bb9b05be7c0e3435ffca9d72a Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 00:32:18 -0500 Subject: [PATCH] HotZone availability reset at 01am. --- src/engine/devcmd/cmds/HotzoneCmd.java | 3 +-- src/engine/gameManager/ZoneManager.java | 28 +++++++++++++++++++-- src/engine/objects/Zone.java | 1 - src/engine/workthreads/HourlyJobThread.java | 7 ++++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/engine/devcmd/cmds/HotzoneCmd.java b/src/engine/devcmd/cmds/HotzoneCmd.java index dc9fce73..8dc61b5a 100644 --- a/src/engine/devcmd/cmds/HotzoneCmd.java +++ b/src/engine/devcmd/cmds/HotzoneCmd.java @@ -54,8 +54,7 @@ public class HotzoneCmd extends AbstractDevCmd { } if (input.equalsIgnoreCase("reset")) - for (Zone zone: ZoneManager.getAllZones()) - zone.hasBeenHotzone = false; + ZoneManager.resetHotZones(); return; } diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index 147affe2..8f8a7072 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -44,9 +44,10 @@ public enum ZoneManager { 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); - private static final Set macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); + public static final Set macroZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static final Set npcCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); private static final Set playerCityZones = Collections.newSetFromMap(new ConcurrentHashMap<>()); + // Find all zones coordinates fit into, starting with Sea Floor public static ArrayList getAllZonesIn(final Vector3fImmutable loc) { @@ -108,6 +109,30 @@ public enum ZoneManager { } + // Returns the number of available hotZones + // remaining in this cycle (1am) + public static int availableHotZones() { + + int count = 0; + + for (Zone zone : ZoneManager.macroZones) + if (zone.hasBeenHotzone) + count = count + 1; + + return count; + } + + // Resets the availability of hotZones + // for this cycle + + public static void resetHotZones() { + + for (Zone zone : ZoneManager.macroZones) + if (zone.hasBeenHotzone) + zone.hasBeenHotzone = false; + + } + public static Zone getZoneByUUID(final int zoneUUID) { return ZoneManager.zonesByUUID.get(zoneUUID); } @@ -129,7 +154,6 @@ public enum ZoneManager { ZoneManager.hotZone = zone; ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config. zone.hasBeenHotzone = true; - zone.becameHotzone = LocalDateTime.now(); WorldServer.hotZoneLastUpdate = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); } diff --git a/src/engine/objects/Zone.java b/src/engine/objects/Zone.java index c1b9389e..10ca5136 100644 --- a/src/engine/objects/Zone.java +++ b/src/engine/objects/Zone.java @@ -61,7 +61,6 @@ 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 LocalDateTime becameHotzone = null; /** * ResultSet Constructor */ diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index dbf17e0c..5500a715 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -191,6 +191,13 @@ public class HourlyJobThread implements Runnable { try { + // Reset zone availability at 1am + // or if we run out of hotZones + + if (LocalDateTime.now().getHour() == 01 || + ZoneManager.availableHotZones() == 0) + ZoneManager.resetHotZones(); + // Use the same hotZone this hour up and until // the HotZone_Duration from the ConfigManager