Browse Source

Refactored usage of HotZone; added cycle counter.

master
MagicBot 2 years ago
parent
commit
8ae973f5f4
  1. 6
      src/engine/devcmd/cmds/HotzoneCmd.java
  2. 25
      src/engine/gameManager/ZoneManager.java
  3. 6
      src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java
  4. 8
      src/engine/net/client/handlers/CityDataHandler.java
  5. 2
      src/engine/net/client/msg/WorldDataMsg.java
  6. 2
      src/engine/server/world/WorldServer.java
  7. 25
      src/engine/workthreads/HourlyJobThread.java

6
src/engine/devcmd/cmds/HotzoneCmd.java

@ -52,7 +52,7 @@ public class HotzoneCmd extends AbstractDevCmd { @@ -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 { @@ -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 { @@ -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) {

25
src/engine/gameManager/ZoneManager.java

@ -38,7 +38,8 @@ public enum ZoneManager { @@ -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<Integer, Zone> zonesByID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<Integer, Zone> zonesByUUID = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
private static final ConcurrentHashMap<String, Zone> zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
@ -119,24 +120,25 @@ public enum ZoneManager { @@ -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 { @@ -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 { @@ -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;
}

6
src/engine/net/client/handlers/ArcLoginNotifyMsgHandler.java

@ -1,5 +1,6 @@ @@ -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 { @@ -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);
}

8
src/engine/net/client/handlers/CityDataHandler.java

@ -50,10 +50,6 @@ public class CityDataHandler extends AbstractClientMsgHandler { @@ -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 { @@ -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);

2
src/engine/net/client/msg/WorldDataMsg.java

@ -80,7 +80,7 @@ public class WorldDataMsg extends ClientNetMsg { @@ -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);

2
src/engine/server/world/WorldServer.java

@ -430,7 +430,7 @@ public class WorldServer { @@ -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");

25
src/engine/workthreads/HourlyJobThread.java

@ -29,8 +29,6 @@ import static engine.server.MBServerStatics.MINE_LATE_WINDOW; @@ -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 { @@ -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.
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) {

Loading…
Cancel
Save