forked from MagicBane/Server
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());
|
throwbackInfo(pc, "New hotzone: " + hotzoneInfo());
|
||||||
HotzoneChangeMsg hcm = new HotzoneChangeMsg(zone.getObjectType().ordinal(), zone.getObjectUUID());
|
HotzoneChangeMsg hcm = new HotzoneChangeMsg(zone.getObjectType().ordinal(), zone.getObjectUUID());
|
||||||
WorldServer.setLastHZChange(System.currentTimeMillis());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import engine.server.world.WorldServer;
|
|||||||
import org.pmw.tinylog.Logger;
|
import org.pmw.tinylog.Logger;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -129,7 +130,7 @@ public enum ZoneManager {
|
|||||||
ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config.
|
ZoneManager.hotZoneCycle = 1; // Used with HOTZONE_DURATION from config.
|
||||||
zone.hasBeenHotzone = true;
|
zone.hasBeenHotzone = true;
|
||||||
zone.becameHotzone = LocalDateTime.now();
|
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.City;
|
||||||
import engine.objects.Mine;
|
import engine.objects.Mine;
|
||||||
import engine.objects.PlayerCharacter;
|
import engine.objects.PlayerCharacter;
|
||||||
import engine.objects.Zone;
|
|
||||||
import engine.server.world.WorldServer;
|
import engine.server.world.WorldServer;
|
||||||
import engine.session.Session;
|
import engine.session.Session;
|
||||||
|
|
||||||
|
import java.time.ZoneId;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @Author:
|
* @Author:
|
||||||
* @Summary: Processes application protocol message which displays
|
* @Summary: Processes application protocol message which displays
|
||||||
@@ -35,7 +36,6 @@ public class CityDataHandler extends AbstractClientMsgHandler {
|
|||||||
boolean updateCity = false;
|
boolean updateCity = false;
|
||||||
Session playerSession;
|
Session playerSession;
|
||||||
PlayerCharacter playerCharacter;
|
PlayerCharacter playerCharacter;
|
||||||
Zone hotZone;
|
|
||||||
Dispatch dispatch;
|
Dispatch dispatch;
|
||||||
|
|
||||||
playerCharacter = origin.getPlayerCharacter();
|
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 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());
|
HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID());
|
||||||
dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg);
|
dispatch = Dispatch.borrow(playerCharacter, hotzoneChangeMsg);
|
||||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||||
|
|||||||
@@ -10,17 +10,23 @@
|
|||||||
package engine.net.client.msg;
|
package engine.net.client.msg;
|
||||||
|
|
||||||
|
|
||||||
|
import engine.gameManager.ConfigManager;
|
||||||
import engine.math.FastMath;
|
import engine.math.FastMath;
|
||||||
import engine.net.AbstractConnection;
|
import engine.net.AbstractConnection;
|
||||||
import engine.net.ByteBufferReader;
|
import engine.net.ByteBufferReader;
|
||||||
import engine.net.ByteBufferWriter;
|
import engine.net.ByteBufferWriter;
|
||||||
import engine.net.client.Protocol;
|
import engine.net.client.Protocol;
|
||||||
|
import engine.server.world.WorldServer;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
|
||||||
public class HotzoneChangeMsg extends ClientNetMsg {
|
public class HotzoneChangeMsg extends ClientNetMsg {
|
||||||
|
|
||||||
private int zoneType;
|
private int zoneType;
|
||||||
private int zoneID;
|
private int zoneID;
|
||||||
|
private Duration endOfCycle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the general purpose constructor.
|
* This is the general purpose constructor.
|
||||||
@@ -29,6 +35,11 @@ public class HotzoneChangeMsg extends ClientNetMsg {
|
|||||||
super(Protocol.ARCHOTZONECHANGE);
|
super(Protocol.ARCHOTZONECHANGE);
|
||||||
this.zoneType = zoneType;
|
this.zoneType = zoneType;
|
||||||
this.zoneID = zoneID;
|
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) {
|
protected void _serialize(ByteBufferWriter writer) {
|
||||||
writer.putInt(this.zoneType);
|
writer.putInt(this.zoneType);
|
||||||
writer.putInt(this.zoneID);
|
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.net.InetAddress;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -70,7 +72,7 @@ import static java.lang.System.exit;
|
|||||||
public class WorldServer {
|
public class WorldServer {
|
||||||
|
|
||||||
private static LocalDateTime bootTime = LocalDateTime.now();
|
private static LocalDateTime bootTime = LocalDateTime.now();
|
||||||
private static long lastHZChange = System.currentTimeMillis();
|
public static Instant hotZoneLastUpdate;
|
||||||
public boolean isRunning = false;
|
public boolean isRunning = false;
|
||||||
|
|
||||||
// Member variable declaration
|
// 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) {
|
public static void trainerInfo(TrainerInfoMsg msg, ClientConnection origin) {
|
||||||
|
|
||||||
NPC npc = NPC.getFromCache(msg.getObjectID());
|
NPC npc = NPC.getFromCache(msg.getObjectID());
|
||||||
@@ -430,13 +424,9 @@ public class WorldServer {
|
|||||||
Logger.info("Running Heraldry Audit for Deleted Players");
|
Logger.info("Running Heraldry Audit for Deleted Players");
|
||||||
Heraldry.AuditHeraldry();
|
Heraldry.AuditHeraldry();
|
||||||
|
|
||||||
if (ZoneManager.hotZone != null)
|
|
||||||
WorldServer.setLastHZChange(System.currentTimeMillis());
|
|
||||||
|
|
||||||
Logger.info("Starting Mobile AI FSM");
|
Logger.info("Starting Mobile AI FSM");
|
||||||
MobileFSMManager.getInstance();
|
MobileFSMManager.getInstance();
|
||||||
|
|
||||||
|
|
||||||
for (Zone zone : ZoneManager.getAllZones()) {
|
for (Zone zone : ZoneManager.getAllZones()) {
|
||||||
if (zone.getHeightMap() != null) {
|
if (zone.getHeightMap() != null) {
|
||||||
if (zone.getHeightMap().getBucketWidthX() == 0) {
|
if (zone.getHeightMap().getBucketWidthX() == 0) {
|
||||||
|
|||||||
@@ -41,17 +41,17 @@ public class HourlyJobThread implements Runnable {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
//no hotzone? set one.
|
|
||||||
|
|
||||||
if (ZoneManager.hotZone == null)
|
if (ZoneManager.hotZone == null)
|
||||||
ZoneManager.generateAndSetRandomHotzone();
|
ZoneManager.generateAndSetRandomHotzone();
|
||||||
|
|
||||||
|
// Use the same hotZone this hour up and until
|
||||||
|
// the HotZone_Duration from the ConfigManager
|
||||||
|
|
||||||
ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1;
|
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();
|
ZoneManager.generateAndSetRandomHotzone();
|
||||||
|
|
||||||
|
|
||||||
if (ZoneManager.hotZone == null) {
|
if (ZoneManager.hotZone == null) {
|
||||||
Logger.error("Null HotZone returned from ZoneManager");
|
Logger.error("Null HotZone returned from ZoneManager");
|
||||||
} else {
|
} else {
|
||||||
@@ -91,7 +91,6 @@ public class HourlyJobThread implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Mines can only be claimed once per cycle.
|
// Mines can only be claimed once per cycle.
|
||||||
// This will reset at 1am after the last mine
|
// This will reset at 1am after the last mine
|
||||||
// window closes.
|
// window closes.
|
||||||
|
|||||||
Reference in New Issue
Block a user