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 {
if (input.equalsIgnoreCase("random")) { if (input.equalsIgnoreCase("random")) {
throwbackInfo(pc, "Previous hotzone: " + hotzoneInfo()); throwbackInfo(pc, "Previous hotzone: " + hotzoneInfo());
ZoneManager.generateAndSetRandomHotzone(); ZoneManager.generateAndSetRandomHotzone();
zone = ZoneManager.getHotZone(); zone = ZoneManager.hotZone;
} else { } else {
zone = ZoneManager.findMacroZoneByName(input); zone = ZoneManager.findMacroZoneByName(input);
@ -61,7 +61,7 @@ public class HotzoneCmd extends AbstractDevCmd {
return; return;
} }
if (zone == ZoneManager.getHotZone()) { if (zone == ZoneManager.hotZone) {
throwbackInfo(pc, "That macrozone is already the Hotzone."); throwbackInfo(pc, "That macrozone is already the Hotzone.");
return; return;
} }
@ -92,7 +92,7 @@ public class HotzoneCmd extends AbstractDevCmd {
private static String hotzoneInfo() { private static String hotzoneInfo() {
final int hotzoneTimeLeft = FastMath.secondsUntilNextHour(); final int hotzoneTimeLeft = FastMath.secondsUntilNextHour();
final Zone hotzone = ZoneManager.getHotZone(); final Zone hotzone = ZoneManager.hotZone;
String hotzoneInfo; String hotzoneInfo;
if (hotzone == null) { if (hotzone == null) {

25
src/engine/gameManager/ZoneManager.java

@ -38,7 +38,8 @@ public enum ZoneManager {
/* Instance variables */ /* Instance variables */
private static Zone seaFloor = null; 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> 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<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); private static final ConcurrentHashMap<String, Zone> zonesByName = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD);
@ -119,24 +120,25 @@ public enum ZoneManager {
return ZoneManager.zonesByUUID.values(); return ZoneManager.zonesByUUID.values();
} }
public static final Zone getHotZone() {
return ZoneManager.hotzone;
}
public static final void setHotZone(final Zone zone) { public static final void setHotZone(final Zone zone) {
if (!zone.isMacroZone()) if (!zone.isMacroZone())
return; return;
ZoneManager.hotzone = zone;
ZoneManager.hotZone = zone;
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());
} }
public static boolean inHotZone(final Vector3fImmutable loc) { public static boolean inHotZone(final Vector3fImmutable loc) {
if (ZoneManager.hotzone == null) if (ZoneManager.hotZone == null)
return false; 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) { public static void setSeaFloor(final Zone value) {
@ -204,15 +206,12 @@ public enum ZoneManager {
hotzone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex)); hotzone = ZoneManager.getZoneByUUID(zoneArray.get(entryIndex));
if (hotzone == null) { if (hotzone == null) {
Logger.error("Hotzone is null"); Logger.error("Hotzone is null");
return; return;
} }
ZoneManager.setHotZone(hotzone); ZoneManager.setHotZone(hotzone);
WorldServer.setLastHZChange(System.currentTimeMillis());
} }
@ -234,8 +233,8 @@ public enum ZoneManager {
// if (this.hotzone.getUUID() == zone.getUUID()) // if (this.hotzone.getUUID() == zone.getUUID())
// return true; //no same hotzone // return true; //no same hotzone
if (ZoneManager.hotzone != null) if (ZoneManager.hotZone != null)
return ZoneManager.hotzone.getObjectUUID() != zone.getObjectUUID(); return ZoneManager.hotZone.getObjectUUID() != zone.getObjectUUID();
return true; return true;
} }

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

@ -1,5 +1,6 @@
package engine.net.client.handlers; package engine.net.client.handlers;
import engine.Enum;
import engine.Enum.DispatchChannel; import engine.Enum.DispatchChannel;
import engine.exception.MsgSendException; import engine.exception.MsgSendException;
import engine.gameManager.*; import engine.gameManager.*;
@ -125,10 +126,9 @@ public class ArcLoginNotifyMsgHandler extends AbstractClientMsgHandler {
} }
//Send current hotzone //Send current hotzone
Zone hotzone = ZoneManager.getHotZone();
if (hotzone != null) { if (ZoneManager.hotZone != null) {
HotzoneChangeMsg hcm = new HotzoneChangeMsg(hotzone.getObjectType().ordinal(), hotzone.getObjectUUID()); HotzoneChangeMsg hcm = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), ZoneManager.hotZone.getObjectUUID());
Dispatch dispatch = Dispatch.borrow(player, hcm); Dispatch dispatch = Dispatch.borrow(player, hcm);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
} }

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

@ -50,10 +50,6 @@ public class CityDataHandler extends AbstractClientMsgHandler {
if (playerSession == null) if (playerSession == null)
return true; return true;
// Cache current hotZone
hotZone = ZoneManager.getHotZone();
// No reason to serialize cities and mines everytime map is // No reason to serialize cities and mines everytime map is
// opened. Wait until something has changed. // opened. Wait until something has changed.
@ -76,8 +72,8 @@ 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() && hotZone != null) { if (playerCharacter.getTimeStamp("hotzoneupdate") <= WorldServer.getLastHZChange() && ZoneManager.hotZone != null) {
HotzoneChangeMsg hotzoneChangeMsg = new HotzoneChangeMsg(Enum.GameObjectType.Zone.ordinal(), 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);
playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100); playerCharacter.setTimeStamp("hotzoneupdate", System.currentTimeMillis() - 100);

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

@ -80,7 +80,7 @@ public class WorldDataMsg extends ClientNetMsg {
writer.putInt(getTotalMapSize(root) + 1); writer.putInt(getTotalMapSize(root) + 1);
Zone.serializeForClientMsg(root,writer); Zone.serializeForClientMsg(root,writer);
Zone hotzone = ZoneManager.getHotZone(); Zone hotzone = ZoneManager.hotZone;;
if (hotzone == null) if (hotzone == null)
writer.putLong(0L); writer.putLong(0L);

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

@ -430,7 +430,7 @@ 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.getHotZone() != null) if (ZoneManager.hotZone != null)
WorldServer.setLastHZChange(System.currentTimeMillis()); WorldServer.setLastHZChange(System.currentTimeMillis());
Logger.info("Starting Mobile AI FSM"); Logger.info("Starting Mobile AI FSM");

25
src/engine/workthreads/HourlyJobThread.java

@ -29,8 +29,6 @@ import static engine.server.MBServerStatics.MINE_LATE_WINDOW;
public class HourlyJobThread implements Runnable { public class HourlyJobThread implements Runnable {
private static final int hotzoneCount = 0;
public HourlyJobThread() { public HourlyJobThread() {
} }
@ -42,21 +40,22 @@ public class HourlyJobThread implements Runnable {
Logger.info("Hourly job is now running."); Logger.info("Hourly job is now running.");
try { try {
Zone hotzone = ZoneManager.getHotZone();
if (hotzone == null) {
//no hotzone? set one. //no hotzone? set one.
if (ZoneManager.hotZone == null)
ZoneManager.generateAndSetRandomHotzone(); ZoneManager.generateAndSetRandomHotzone();
}
int hotzoneDuration = Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue()); ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1;
if (((LocalDateTime.now().getHour()) - hotzone.becameHotzone.getHour()) >= hotzoneDuration) {
if (ZoneManager.hotZoneCycle > Integer.valueOf(ConfigManager.MB_HOTZONE_DURATION.getValue()))
ZoneManager.generateAndSetRandomHotzone(); ZoneManager.generateAndSetRandomHotzone();
hotzone = ZoneManager.getHotZone();
}
if (hotzone == null) { if (ZoneManager.hotZone == null) {
Logger.error("Null hotzone returned from mapmanager"); Logger.error("Null HotZone returned from ZoneManager");
} else { } else {
Logger.info("new hotzone: " + hotzone.getName()); Logger.info("HotZone switched to: " + ZoneManager.hotZone.getName());
WorldServer.setLastHZChange(System.currentTimeMillis());
} }
} catch (Exception e) { } catch (Exception e) {

Loading…
Cancel
Save