Use of Instant to track hotzone refresh times.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user