diff --git a/src/engine/devcmd/cmds/HotzoneCmd.java b/src/engine/devcmd/cmds/HotzoneCmd.java index 2b6d64ef..dd2e8225 100644 --- a/src/engine/devcmd/cmds/HotzoneCmd.java +++ b/src/engine/devcmd/cmds/HotzoneCmd.java @@ -77,7 +77,6 @@ public class HotzoneCmd extends AbstractDevCmd { throwbackInfo(pc, "New hotzone: " + hotzoneInfo()); HotzoneChangeMsg hcm = new HotzoneChangeMsg(zone.getObjectType().ordinal(), zone.getObjectUUID()); - WorldServer.setLastHZChange(System.currentTimeMillis()); } @Override diff --git a/src/engine/gameManager/ZoneManager.java b/src/engine/gameManager/ZoneManager.java index df3e370c..d801bdda 100644 --- a/src/engine/gameManager/ZoneManager.java +++ b/src/engine/gameManager/ZoneManager.java @@ -21,6 +21,7 @@ import engine.server.world.WorldServer; import org.pmw.tinylog.Logger; import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -129,7 +130,7 @@ public enum ZoneManager { ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config. zone.hasBeenHotzone = true; zone.becameHotzone = LocalDateTime.now(); - WorldServer.setLastHZChange(System.currentTimeMillis()); + WorldServer.hotZoneLastUpdate = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); } diff --git a/src/engine/net/client/handlers/CityDataHandler.java b/src/engine/net/client/handlers/CityDataHandler.java index 4e9f7640..d12ecf91 100644 --- a/src/engine/net/client/handlers/CityDataHandler.java +++ b/src/engine/net/client/handlers/CityDataHandler.java @@ -12,10 +12,11 @@ import engine.net.client.msg.*; import engine.objects.City; import engine.objects.Mine; import engine.objects.PlayerCharacter; -import engine.objects.Zone; import engine.server.world.WorldServer; import engine.session.Session; +import java.time.ZoneId; + /* * @Author: * @Summary: Processes application protocol message which displays @@ -35,7 +36,6 @@ public class CityDataHandler extends AbstractClientMsgHandler { boolean updateCity = false; Session playerSession; PlayerCharacter playerCharacter; - Zone hotZone; Dispatch dispatch; playerCharacter = origin.getPlayerCharacter(); @@ -72,7 +72,7 @@ public class CityDataHandler extends AbstractClientMsgHandler { // If the hotZone has changed then update the client's map accordingly. - if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange() && ZoneManager.hotZone != null) { + if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.hotZoneLastUpdate.toEpochMilli() && ZoneManager.hotZone != null) { HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID()); dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); diff --git a/src/engine/net/client/msg/HotzoneChangeMsg.java b/src/engine/net/client/msg/HotzoneChangeMsg.java index c39f218d..d5874c41 100644 --- a/src/engine/net/client/msg/HotzoneChangeMsg.java +++ b/src/engine/net/client/msg/HotzoneChangeMsg.java @@ -10,17 +10,23 @@ package engine.net.client.msg; +import engine.gameManager.ConfigManager; import engine.math.FastMath; import engine.net.AbstractConnection; import engine.net.ByteBufferReader; import engine.net.ByteBufferWriter; import engine.net.client.Protocol; +import engine.server.world.WorldServer; + +import java.time.Duration; +import java.time.LocalDateTime; public class HotzoneChangeMsg extends ClientNetMsg { private int zoneType; private int zoneID; + private Duration endOfCycle; /** * This is the general purpose constructor. @@ -29,6 +35,11 @@ public class HotzoneChangeMsg extends ClientNetMsg { super(Protocol.ARCHOTZONECHANGE); this.zoneType = zoneType; this.zoneID = zoneID; + + int hotZoneDuration = Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue()); + + endOfCycle = Duration.between(WorldServer.hotZoneLastUpdate, WorldServer.hotZoneLastUpdate.plusSeconds(hotZoneDuration * 3600)); + } /** @@ -49,7 +60,7 @@ public class HotzoneChangeMsg extends ClientNetMsg { protected void _serialize(ByteBufferWriter writer) { writer.putInt(this.zoneType); writer.putInt(this.zoneID); - writer.putInt(FastMath.secondsUntilNextHour()); + writer.putInt((int) endOfCycle.getSeconds()); } /** diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 2e1a1361..d239a41b 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -58,7 +58,9 @@ import java.io.IOException; import java.net.InetAddress; import java.nio.file.Files; import java.nio.file.Paths; +import java.time.Instant; import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -70,7 +72,7 @@ import static java.lang.System.exit; public class WorldServer { private static LocalDateTime bootTime = LocalDateTime.now(); - private static long lastHZChange = System.currentTimeMillis(); + public static Instant hotZoneLastUpdate; public boolean isRunning = false; // Member variable declaration @@ -121,14 +123,6 @@ public class WorldServer { } } - public static long getLastHZChange() { - return lastHZChange; - } - - public static void setLastHZChange(long lastChange) { - lastHZChange = lastChange; - } - public static void trainerInfo(TrainerInfoMsg msg, ClientConnection origin) { NPC npc = NPC.getFromCache(msg.getObjectID()); @@ -430,13 +424,9 @@ public class WorldServer { Logger.info("Running Heraldry Audit for Deleted Players"); Heraldry.AuditHeraldry(); - if (ZoneManager.hotZone != null) - WorldServer.setLastHZChange(System.currentTimeMillis()); - Logger.info("Starting Mobile AI FSM"); MobileFSMManager.getInstance(); - for (Zone zone : ZoneManager.getAllZones()) { if (zone.getHeightMap() != null) { if (zone.getHeightMap().getBucketWidthX() == 0) { diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 25173743..031cebd8 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -41,17 +41,17 @@ public class HourlyJobThread implements Runnable { try { - //no hotzone? set one. - if (ZoneManager.hotZone == null) ZoneManager.generateAndSetRandomHotzone(); + // Use the same hotZone this hour up and until + // the HotZone_Duration from the ConfigManager + ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1; - if (ZoneManager.hotZoneCycle > Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue())) + if (ZoneManager.hotZoneCycle > Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue())) ZoneManager.generateAndSetRandomHotzone(); - if (ZoneManager.hotZone == null) { Logger.error("Null HotZone returned from ZoneManager"); } else { @@ -91,7 +91,6 @@ public class HourlyJobThread implements Runnable { } } - // Mines can only be claimed once per cycle. // This will reset at 1am after the last mine // window closes.