From 6a948fbe2e0068b1f314206b438c3e031e20cac3 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Fri, 24 Feb 2023 00:09:57 -0500 Subject: [PATCH] lastChanged is unused as cannot omit mines from map. --- src/engine/devcmd/cmds/MineActiveCmd.java | 60 ++-- src/engine/devcmd/cmds/SetMineExpansion.java | 95 +++--- src/engine/devcmd/cmds/SetMineTypeCmd.java | 59 ++-- .../ArcMineChangeProductionMsgHandler.java | 62 ++-- src/engine/objects/Mine.java | 278 +++++++++--------- src/engine/workthreads/HourlyJobThread.java | 218 +++++++------- 6 files changed, 371 insertions(+), 401 deletions(-) diff --git a/src/engine/devcmd/cmds/MineActiveCmd.java b/src/engine/devcmd/cmds/MineActiveCmd.java index 2263128c..6f36030a 100644 --- a/src/engine/devcmd/cmds/MineActiveCmd.java +++ b/src/engine/devcmd/cmds/MineActiveCmd.java @@ -23,46 +23,44 @@ import engine.workthreads.HourlyJobThread; */ public class MineActiveCmd extends AbstractDevCmd { - public MineActiveCmd() { + public MineActiveCmd() { super("mineactive"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); - if (mineBuilding == null) - return; + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); + if (mineBuilding == null) + return; - Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); - if (mine == null) - return; + Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); + if (mine == null) + return; - String trigger = args[0]; - switch (trigger){ - case "true": - HourlyJobThread.mineWindowOpen(mine); - Mine.setLastChange(System.currentTimeMillis()); - break; - case "false": - HourlyJobThread.mineWindowClose(mine); - Mine.setLastChange(System.currentTimeMillis()); - break; - default: - this.sendUsage(pcSender); - break; + String trigger = args[0]; + switch (trigger) { + case "true": + HourlyJobThread.mineWindowOpen(mine); + break; + case "false": + HourlyJobThread.mineWindowClose(mine); + break; + default: + this.sendUsage(pcSender); + break; - } - } + } + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /mineactive true|false"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Temporarily add visual effects to Character"; - } + } } diff --git a/src/engine/devcmd/cmds/SetMineExpansion.java b/src/engine/devcmd/cmds/SetMineExpansion.java index 0bffe902..192329d5 100644 --- a/src/engine/devcmd/cmds/SetMineExpansion.java +++ b/src/engine/devcmd/cmds/SetMineExpansion.java @@ -21,67 +21,60 @@ import engine.objects.Mine; import engine.objects.PlayerCharacter; /** - * * @author Eighty - * */ public class SetMineExpansion extends AbstractDevCmd { - public SetMineExpansion() { + public SetMineExpansion() { super("setexpansion"); this.addCmdString("setexpansion"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - - - if (target.getObjectType() != GameObjectType.Building) - return; - Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); - if (mineBuilding == null) - return; - Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); - if (mine == null) - return; - int bit = 2; - switch (args[0].toUpperCase()) { - case "ON": - - bit |= mine.getFlags(); - if (!DbManager.MineQueries.SET_FLAGS(mine, bit)) - return; - mine.setFlags(bit); - ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is now an expansion mine."); - Mine.setLastChange(System.currentTimeMillis()); - break; - - case "OFF": - bit &= ~mine.getFlags(); - if (!DbManager.MineQueries.SET_FLAGS(mine, bit)) - return; - mine.setFlags(bit); - ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is no longer an expansion mine."); - Mine.setLastChange(System.currentTimeMillis()); - break; - - } - - - - - - } - - @Override - protected String _getUsageString() { + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + + + if (target.getObjectType() != GameObjectType.Building) + return; + Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); + if (mineBuilding == null) + return; + Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); + if (mine == null) + return; + int bit = 2; + switch (args[0].toUpperCase()) { + case "ON": + + bit |= mine.getFlags(); + if (!DbManager.MineQueries.SET_FLAGS(mine, bit)) + return; + mine.setFlags(bit); + ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is now an expansion mine."); + break; + + case "OFF": + bit &= ~mine.getFlags(); + if (!DbManager.MineQueries.SET_FLAGS(mine, bit)) + return; + mine.setFlags(bit); + ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is no longer an expansion mine."); + break; + + } + + + } + + @Override + protected String _getUsageString() { return "' /setmineexpansion on|off"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "enables or disables an expansion type for a mine."; - } + } } diff --git a/src/engine/devcmd/cmds/SetMineTypeCmd.java b/src/engine/devcmd/cmds/SetMineTypeCmd.java index c932923e..a469fe07 100644 --- a/src/engine/devcmd/cmds/SetMineTypeCmd.java +++ b/src/engine/devcmd/cmds/SetMineTypeCmd.java @@ -18,48 +18,45 @@ import engine.gameManager.DbManager; import engine.objects.*; /** - * * @author Eighty - * */ public class SetMineTypeCmd extends AbstractDevCmd { - public SetMineTypeCmd() { + public SetMineTypeCmd() { super("setminetype"); this.addCmdString("setminetype"); } - @Override - protected void _doCmd(PlayerCharacter pcSender, String[] args, - AbstractGameObject target) { - - MineProduction mineType = MineProduction.valueOf(args[0].toUpperCase()); - if (mineType == null) - return; - - if (target.getObjectType() != GameObjectType.Building) - return; - Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); - if (mineBuilding == null) - return; - Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); - if (mine == null) - return; - if (!DbManager.MineQueries.CHANGE_TYPE(mine, mineType)) - return; - mine.setMineType(mineType.name()); - ChatManager.chatSystemInfo(pcSender, "The mine in " + mine.getZoneName() + " is now a(n) " + mine.getMineType().name); - Mine.setLastChange(System.currentTimeMillis()); - } + @Override + protected void _doCmd(PlayerCharacter pcSender, String[] args, + AbstractGameObject target) { + + MineProduction mineType = MineProduction.valueOf(args[0].toUpperCase()); + if (mineType == null) + return; + + if (target.getObjectType() != GameObjectType.Building) + return; + Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); + if (mineBuilding == null) + return; + Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); + if (mine == null) + return; + if (!DbManager.MineQueries.CHANGE_TYPE(mine, mineType)) + return; + mine.setMineType(mineType.name()); + ChatManager.chatSystemInfo(pcSender, "The mine in " + mine.getZoneName() + " is now a(n) " + mine.getMineType().name); + } - @Override - protected String _getUsageString() { + @Override + protected String _getUsageString() { return "' /setminetype gold|ore|magic|lumber"; - } + } - @Override - protected String _getHelpString() { + @Override + protected String _getHelpString() { return "Changes the mine type of the current mine."; - } + } } diff --git a/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java b/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java index c2198b7e..67e42527 100644 --- a/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java +++ b/src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java @@ -7,7 +7,6 @@ import engine.net.DispatchMessage; import engine.net.client.ClientConnection; import engine.net.client.msg.ArcMineChangeProductionMsg; import engine.net.client.msg.ClientNetMsg; -import engine.net.client.msg.KeepAliveServerClientMsg; import engine.objects.GuildStatusController; import engine.objects.Mine; import engine.objects.PlayerCharacter; @@ -21,49 +20,48 @@ import engine.objects.Resource; public class ArcMineChangeProductionMsgHandler extends AbstractClientMsgHandler { - public ArcMineChangeProductionMsgHandler() { - super(ArcMineChangeProductionMsg.class); - } + public ArcMineChangeProductionMsgHandler() { + super(ArcMineChangeProductionMsg.class); + } - @Override - protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - - PlayerCharacter playerCharacter = origin.getPlayerCharacter(); - ArcMineChangeProductionMsg changeProductionMsg = (ArcMineChangeProductionMsg) baseMsg; + @Override + protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { - if (playerCharacter == null) - return true; + PlayerCharacter playerCharacter = origin.getPlayerCharacter(); + ArcMineChangeProductionMsg changeProductionMsg = (ArcMineChangeProductionMsg) baseMsg; - //TODO verify this against the warehouse? + if (playerCharacter == null) + return true; - if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) // is this only GL? - return true; + //TODO verify this against the warehouse? - Mine mine = Mine.getMine(changeProductionMsg.getMineID()); + if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) // is this only GL? + return true; - if (mine == null) - return true; + Mine mine = Mine.getMine(changeProductionMsg.getMineID()); - //make sure mine belongs to guild + if (mine == null) + return true; - if (mine.getOwningGuild().isEmptyGuild() || - mine.getOwningGuild().getObjectUUID() != playerCharacter.getGuild().getObjectUUID()) - return true; + //make sure mine belongs to guild - //make sure valid resource + if (mine.getOwningGuild().isEmptyGuild() || + mine.getOwningGuild().getObjectUUID() != playerCharacter.getGuild().getObjectUUID()) + return true; - Resource resource = Resource.resourceByHash.get(changeProductionMsg.getResourceHash()); + //make sure valid resource - if (resource == null) - return true; + Resource resource = Resource.resourceByHash.get(changeProductionMsg.getResourceHash()); - //update resource + if (resource == null) + return true; - mine.changeProductionType(resource); - Mine.setLastChange(System.currentTimeMillis()); - Dispatch dispatch = Dispatch.borrow(playerCharacter, changeProductionMsg); - DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); - return true; - } + //update resource + + mine.changeProductionType(resource); + Dispatch dispatch = Dispatch.borrow(playerCharacter, changeProductionMsg); + DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); + return true; + } } \ No newline at end of file diff --git a/src/engine/objects/Mine.java b/src/engine/objects/Mine.java index b43bf21e..d58b46ad 100644 --- a/src/engine/objects/Mine.java +++ b/src/engine/objects/Mine.java @@ -20,7 +20,10 @@ package engine.objects; import engine.Enum; import engine.InterestManagement.WorldGrid; -import engine.gameManager.*; +import engine.gameManager.BuildingManager; +import engine.gameManager.ChatManager; +import engine.gameManager.DbManager; +import engine.gameManager.ZoneManager; import engine.net.ByteBufferWriter; import engine.net.client.msg.ErrorPopupMsg; import engine.server.MBServerStatics; @@ -33,38 +36,34 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; -import static engine.gameManager.DbManager.*; +import static engine.gameManager.DbManager.MineQueries; +import static engine.gameManager.DbManager.getObject; import static engine.math.FastMath.sqr; public class Mine extends AbstractGameObject { - private String zoneName; - private Resource production; + public static ConcurrentHashMap mineMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + public static ConcurrentHashMap towerMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); public boolean isActive = false; - - private float latitude; - private float longitude; - private float altitude; - private Guild owningGuild; public PlayerCharacter lastClaimer; public boolean wasClaimed = false; - private int flags; - private int buildingID; - private Zone parentZone; - private MineProduction mineType; - - //flags 1: never been claimed (make active). - - // Not persisted to DB public String guildName; public GuildTag guildTag; public String nationName; public GuildTag nationTag; - public static ConcurrentHashMap mineMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); - public static ConcurrentHashMap towerMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); + private final String zoneName; + private Resource production; + private final float latitude; + private final float longitude; - private static long lastChange = System.currentTimeMillis(); + //flags 1: never been claimed (make active). + private final float altitude; + private Guild owningGuild; + private int flags; + private int buildingID; + private final Zone parentZone; + private MineProduction mineType; /** * ResultSet Constructor @@ -139,6 +138,7 @@ public class Mine extends AbstractGameObject { } } + public static void SendMineAttackMessage(Building mine) { if (mine.getBlueprint() == null) @@ -186,90 +186,10 @@ public class Mine extends AbstractGameObject { * Getters */ - public boolean changeProductionType(Resource resource) { - if (!this.validForMine(resource)) - return false; - //update resource in database; - if (!MineQueries.CHANGE_RESOURCE(this, resource)) - return false; - - this.production = resource; - return true; - } - - public MineProduction getMineType() { - return this.mineType; - } - - public String getZoneName() { - return this.zoneName; - } - - public Resource getProduction() { - return this.production; - } - - public boolean getIsActive() { - return this.isActive; - } - - public float getAltitude() { - return this.altitude; - } - - public Guild getOwningGuild() { - if (this.owningGuild == null) - return Guild.getErrantGuild(); - else - return this.owningGuild; - } - - public int getFlags() { - return flags; - } - - public void setFlags(int flags) { - this.flags = flags; - } - - public Zone getParentZone() { - return parentZone; - } - - public GuildTag getGuildTag() { - return guildTag; - } - - public void setMineType(String type) { - this.mineType = MineProduction.getByName(type); - } - - public void setActive(boolean isAc) { - - this.isActive = isAc; - Building building = BuildingManager.getBuildingFromCache(this.buildingID); - if (building != null && !this.isActive) - building.isDeranking.compareAndSet(true, false); - } - - public void setOwningGuild(Guild owningGuild) { - this.owningGuild = owningGuild; - } - public static Mine getMineFromTower(int towerID) { return Mine.towerMap.get(towerID); } - public boolean validForMine(Resource r) { - if (this.mineType == null) - return false; - return this.mineType.validForMine(r, this.isExpansion()); - } - - /* - * Serialization - */ - public static void serializeForClientMsg(Mine mine, ByteBufferWriter writer) { writer.putInt(mine.getObjectType().ordinal()); writer.putInt(mine.getObjectUUID()); @@ -284,15 +204,15 @@ public class Mine extends AbstractGameObject { // Errant mines are currently open. Set time to now. LocalDateTime mineOpenTime = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0); - + // Mine times are those of the nation not individual guild. - + Guild mineNatonGuild = mine.getOwningGuild().getNation(); // Adjust the serialized mine time based upon whether // the Guild's mine window has passed or not and if it was claimed. - // If a mine is active serialize current datetime irrespective - // of any claim. + // If a mine is active serialize current datetime irrespective + // of any claim. if (mineNatonGuild.isEmptyGuild() == false && mine.isActive == false) { @@ -321,20 +241,6 @@ public class Mine extends AbstractGameObject { GuildTag._serializeForDisplay(mine.nationTag, writer); } - public void serializeForMineProduction(ByteBufferWriter writer) { - writer.putInt(this.getObjectType().ordinal()); - writer.putInt(this.getObjectUUID()); - writer.putInt(this.getObjectUUID()); //actually a hash of mine - // writer.putInt(0x215C92BB); //this.unknown1); - writer.putString(this.mineType.name); - writer.putString(this.zoneName); - writer.putInt(this.production.hash); - writer.putInt(this.production.baseProduction); - writer.putInt(this.getModifiedProductionAmount()); //TODO calculate range penalty here - writer.putInt(3600); //window in seconds - writer.putInt(this.isExpansion() ? this.mineType.xpacHash : this.mineType.hash); - } - public static ArrayList getMinesForGuild(int guildID) { ArrayList mineList = new ArrayList<>(); @@ -343,20 +249,12 @@ public class Mine extends AbstractGameObject { for (Mine mine : Mine.mineMap.keySet()) { if (mine.owningGuild.getObjectUUID() == guildID && - mine.isActive == false) + mine.isActive == false) mineList.add(mine); } return mineList; } - public static long getLastChange() { - return lastChange; - } - - public static void setLastChange(long lastChange) { - Mine.lastChange = lastChange; - } - /* * Database */ @@ -369,19 +267,6 @@ public class Mine extends AbstractGameObject { return new ArrayList<>(mineMap.keySet()); } - @Override - public void updateDatabase() { - // TODO Create update logic. - } - - public int getBuildingID() { - return buildingID; - } - - public void setBuildingID(int buildingID) { - this.buildingID = buildingID; - } - public static boolean validateClaimer(PlayerCharacter playerCharacter) { // Method validates that the claimer meets @@ -407,7 +292,7 @@ public class Mine extends AbstractGameObject { if (playerGuild.getNation().isEmptyGuild()) return false; - // Guild must own a city to hold a mine. + // Guild must own a city to hold a mine. City guildCity = playerGuild.getOwnedCity(); @@ -433,7 +318,7 @@ public class Mine extends AbstractGameObject { if (treeRank < 1) return false; - if (guildUnderMineLimit(playerGuild.getNation(), treeRank) == false){ + if (guildUnderMineLimit(playerGuild.getNation(), treeRank) == false) { ErrorPopupMsg.sendErrorMsg(playerCharacter, "Your nation cannot support another mine."); return false; } @@ -450,11 +335,116 @@ public class Mine extends AbstractGameObject { for (Guild guild : playerGuild.getSubGuildList()) mineCnt += Mine.getMinesForGuild(guild.getObjectUUID()).size(); - if (mineCnt > tolRank) + return mineCnt <= tolRank; + } + + public boolean changeProductionType(Resource resource) { + if (!this.validForMine(resource)) + return false; + //update resource in database; + if (!MineQueries.CHANGE_RESOURCE(this, resource)) return false; + this.production = resource; return true; } + + public MineProduction getMineType() { + return this.mineType; + } + + public void setMineType(String type) { + this.mineType = MineProduction.getByName(type); + } + + public String getZoneName() { + return this.zoneName; + } + + public Resource getProduction() { + return this.production; + } + + public boolean getIsActive() { + return this.isActive; + } + + public float getAltitude() { + return this.altitude; + } + + public Guild getOwningGuild() { + if (this.owningGuild == null) + return Guild.getErrantGuild(); + else + return this.owningGuild; + } + + public void setOwningGuild(Guild owningGuild) { + this.owningGuild = owningGuild; + } + + /* + * Serialization + */ + + public int getFlags() { + return flags; + } + + public void setFlags(int flags) { + this.flags = flags; + } + + public Zone getParentZone() { + return parentZone; + } + + public GuildTag getGuildTag() { + return guildTag; + } + + public void setActive(boolean isAc) { + + this.isActive = isAc; + Building building = BuildingManager.getBuildingFromCache(this.buildingID); + if (building != null && !this.isActive) + building.isDeranking.compareAndSet(true, false); + } + + public boolean validForMine(Resource r) { + if (this.mineType == null) + return false; + return this.mineType.validForMine(r, this.isExpansion()); + } + + public void serializeForMineProduction(ByteBufferWriter writer) { + writer.putInt(this.getObjectType().ordinal()); + writer.putInt(this.getObjectUUID()); + writer.putInt(this.getObjectUUID()); //actually a hash of mine + // writer.putInt(0x215C92BB); //this.unknown1); + writer.putString(this.mineType.name); + writer.putString(this.zoneName); + writer.putInt(this.production.hash); + writer.putInt(this.production.baseProduction); + writer.putInt(this.getModifiedProductionAmount()); //TODO calculate range penalty here + writer.putInt(3600); //window in seconds + writer.putInt(this.isExpansion() ? this.mineType.xpacHash : this.mineType.hash); + } + + @Override + public void updateDatabase() { + // TODO Create update logic. + } + + public int getBuildingID() { + return buildingID; + } + + public void setBuildingID(int buildingID) { + this.buildingID = buildingID; + } + public void handleDestroyMine() { if (!this.isActive) @@ -465,7 +455,6 @@ public class Mine extends AbstractGameObject { this.guildName = ""; this.nationName = ""; this.owningGuild = Guild.getErrantGuild(); - Mine.setLastChange(System.currentTimeMillis()); this.lastClaimer = null; this.wasClaimed = false; @@ -513,6 +502,7 @@ public class Mine extends AbstractGameObject { return true; } + public boolean depositMineResources() { if (this.owningGuild.isEmptyGuild()) diff --git a/src/engine/workthreads/HourlyJobThread.java b/src/engine/workthreads/HourlyJobThread.java index 04538d29..dbf17e0c 100644 --- a/src/engine/workthreads/HourlyJobThread.java +++ b/src/engine/workthreads/HourlyJobThread.java @@ -33,111 +33,6 @@ public class HourlyJobThread implements Runnable { } - public void run() { - - // *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG - - Logger.info("Hourly job is now running."); - - try { - - // Use the same hotZone this hour up and until - // the HotZone_Duration from the ConfigManager - - if (ZoneManager.hotZone == null) - ZoneManager.generateAndSetRandomHotzone(); - else - ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1; - - if (ZoneManager.hotZoneCycle > Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue())) - ZoneManager.generateAndSetRandomHotzone(); - - if (ZoneManager.hotZone == null) { - Logger.error("Null HotZone returned from ZoneManager"); - } else { - Logger.info("HotZone switched to: " + ZoneManager.hotZone.getName()); - } - - } catch (Exception e) { - Logger.error(e.toString()); - } - - // Open or Close mines for the current mine window. - - processMineWindow(); - - // Deposit mine resources to Guilds - - for (Mine mine : Mine.getMines()) { - - try { - mine.depositMineResources(); - } catch (Exception e) { - Logger.info(e.getMessage() + " for Mine " + mine.getObjectUUID()); - } - } - - // Reset time-gated access to WOO slider. - // *** Do this after the mines open/close! - - if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) { - Guild guild; - - for (AbstractGameObject dbObject : DbManager.getList(Enum.GameObjectType.Guild)) { - guild = (Guild) dbObject; - - if (guild != null) - guild.wooWasModified = false; - } - } - - // Mines can only be claimed once per cycle. - // This will reset at 1am after the last mine - // window closes. - - if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW + 1) { - - for (Mine mine : Mine.getMines()) { - - if (mine.wasClaimed == true) - mine.wasClaimed = false; - } - } - - // Decay Shrines at midnight every day - - if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) - decayShrines(); - - // Update city population values - - ConcurrentHashMap map = DbManager.getMap(Enum.GameObjectType.City); - - if (map != null) { - - for (AbstractGameObject ago : map.values()) { - - City city = (City) ago; - - if (city != null) - if (city.getGuild() != null) { - ArrayList guildList = Guild.GuildRoster(city.getGuild()); - city.setPopulation(guildList.size()); - } - } - City.lastCityUpdate = System.currentTimeMillis(); - } else { - Logger.error("missing city map"); - } - - // Log metrics to console - Logger.info(WorldServer.getUptimeString()); - Logger.info(SimulationManager.getPopulationString()); - Logger.info(MessageDispatcher.getNetstatString()); - Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted"); - } - - public static void decayShrines() { ArrayList shrineList = new ArrayList<>(); @@ -194,7 +89,6 @@ public class HourlyJobThread implements Runnable { if (mine.getOwningGuild().isEmptyGuild()) { HourlyJobThread.mineWindowOpen(mine); - Mine.setLastChange(System.currentTimeMillis()); continue; } @@ -204,14 +98,12 @@ public class HourlyJobThread implements Runnable { if (mine.getOwningGuild().getNation().getMineTime() == LocalDateTime.now().getHour() && mine.wasClaimed == false) { HourlyJobThread.mineWindowOpen(mine); - Mine.setLastChange(System.currentTimeMillis()); continue; } - // Close all the remaining mines + // Close the mine if it reaches this far - if (mineWindowClose(mine)) - Mine.setLastChange(System.currentTimeMillis()); + mineWindowClose(mine); } catch (Exception e) { Logger.error("mineID: " + mine.getObjectUUID(), e.toString()); @@ -271,8 +163,6 @@ public class HourlyJobThread implements Runnable { mine.nationName = nation.getName(); mine.nationTag = nation.getGuildTag(); - Mine.setLastChange(System.currentTimeMillis()); - mineBuilding.rebuildMine(); WorldGrid.updateObject(mineBuilding); @@ -292,4 +182,108 @@ public class HourlyJobThread implements Runnable { mine.wasClaimed = true; return true; } + + public void run() { + + // *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG + + Logger.info("Hourly job is now running."); + + try { + + // Use the same hotZone this hour up and until + // the HotZone_Duration from the ConfigManager + + if (ZoneManager.hotZone == null) + ZoneManager.generateAndSetRandomHotzone(); + else + ZoneManager.hotZoneCycle = ZoneManager.hotZoneCycle + 1; + + if (ZoneManager.hotZoneCycle > Integer.parseInt(ConfigManager.MB_HOTZONE_DURATION.getValue())) + ZoneManager.generateAndSetRandomHotzone(); + + if (ZoneManager.hotZone == null) { + Logger.error("Null HotZone returned from ZoneManager"); + } else { + Logger.info("HotZone switched to: " + ZoneManager.hotZone.getName()); + } + + } catch (Exception e) { + Logger.error(e.toString()); + } + + // Open or Close mines for the current mine window. + + processMineWindow(); + + // Deposit mine resources to Guilds + + for (Mine mine : Mine.getMines()) { + + try { + mine.depositMineResources(); + } catch (Exception e) { + Logger.info(e.getMessage() + " for Mine " + mine.getObjectUUID()); + } + } + + // Reset time-gated access to WOO slider. + // *** Do this after the mines open/close! + + if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) { + Guild guild; + + for (AbstractGameObject dbObject : DbManager.getList(Enum.GameObjectType.Guild)) { + guild = (Guild) dbObject; + + if (guild != null) + guild.wooWasModified = false; + } + } + + // Mines can only be claimed once per cycle. + // This will reset at 1am after the last mine + // window closes. + + if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW + 1) { + + for (Mine mine : Mine.getMines()) { + + if (mine.wasClaimed == true) + mine.wasClaimed = false; + } + } + + // Decay Shrines at midnight every day + + if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) + decayShrines(); + + // Update city population values + + ConcurrentHashMap map = DbManager.getMap(Enum.GameObjectType.City); + + if (map != null) { + + for (AbstractGameObject ago : map.values()) { + + City city = (City) ago; + + if (city != null) + if (city.getGuild() != null) { + ArrayList guildList = Guild.GuildRoster(city.getGuild()); + city.setPopulation(guildList.size()); + } + } + City.lastCityUpdate = System.currentTimeMillis(); + } else { + Logger.error("missing city map"); + } + + // Log metrics to console + Logger.info(WorldServer.getUptimeString()); + Logger.info(SimulationManager.getPopulationString()); + Logger.info(MessageDispatcher.getNetstatString()); + Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted"); + } }