Browse Source

lastChanged is unused as cannot omit mines from map.

master
MagicBot 2 years ago
parent
commit
6a948fbe2e
  1. 60
      src/engine/devcmd/cmds/MineActiveCmd.java
  2. 95
      src/engine/devcmd/cmds/SetMineExpansion.java
  3. 59
      src/engine/devcmd/cmds/SetMineTypeCmd.java
  4. 62
      src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java
  5. 278
      src/engine/objects/Mine.java
  6. 218
      src/engine/workthreads/HourlyJobThread.java

60
src/engine/devcmd/cmds/MineActiveCmd.java

@ -23,46 +23,44 @@ import engine.workthreads.HourlyJobThread;
*/ */
public class MineActiveCmd extends AbstractDevCmd { public class MineActiveCmd extends AbstractDevCmd {
public MineActiveCmd() { public MineActiveCmd() {
super("mineactive"); super("mineactive");
} }
@Override @Override
protected void _doCmd(PlayerCharacter pcSender, String[] args, protected void _doCmd(PlayerCharacter pcSender, String[] args,
AbstractGameObject target) { AbstractGameObject target) {
Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID());
if (mineBuilding == null) if (mineBuilding == null)
return; return;
Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID());
if (mine == null) if (mine == null)
return; return;
String trigger = args[0]; String trigger = args[0];
switch (trigger){ switch (trigger) {
case "true": case "true":
HourlyJobThread.mineWindowOpen(mine); HourlyJobThread.mineWindowOpen(mine);
Mine.setLastChange(System.currentTimeMillis()); break;
break; case "false":
case "false": HourlyJobThread.mineWindowClose(mine);
HourlyJobThread.mineWindowClose(mine); break;
Mine.setLastChange(System.currentTimeMillis()); default:
break; this.sendUsage(pcSender);
default: break;
this.sendUsage(pcSender);
break;
} }
} }
@Override @Override
protected String _getUsageString() { protected String _getUsageString() {
return "' /mineactive true|false"; return "' /mineactive true|false";
} }
@Override @Override
protected String _getHelpString() { protected String _getHelpString() {
return "Temporarily add visual effects to Character"; return "Temporarily add visual effects to Character";
} }
} }

95
src/engine/devcmd/cmds/SetMineExpansion.java

@ -21,67 +21,60 @@ import engine.objects.Mine;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
/** /**
*
* @author Eighty * @author Eighty
*
*/ */
public class SetMineExpansion extends AbstractDevCmd { public class SetMineExpansion extends AbstractDevCmd {
public SetMineExpansion() { public SetMineExpansion() {
super("setexpansion"); super("setexpansion");
this.addCmdString("setexpansion"); this.addCmdString("setexpansion");
} }
@Override @Override
protected void _doCmd(PlayerCharacter pcSender, String[] args, protected void _doCmd(PlayerCharacter pcSender, String[] args,
AbstractGameObject target) { AbstractGameObject target) {
if (target.getObjectType() != GameObjectType.Building) if (target.getObjectType() != GameObjectType.Building)
return; return;
Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID());
if (mineBuilding == null) if (mineBuilding == null)
return; return;
Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID());
if (mine == null) if (mine == null)
return; return;
int bit = 2; int bit = 2;
switch (args[0].toUpperCase()) { switch (args[0].toUpperCase()) {
case "ON": case "ON":
bit |= mine.getFlags(); bit |= mine.getFlags();
if (!DbManager.MineQueries.SET_FLAGS(mine, bit)) if (!DbManager.MineQueries.SET_FLAGS(mine, bit))
return; return;
mine.setFlags(bit); mine.setFlags(bit);
ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is now an expansion mine."); ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is now an expansion mine.");
Mine.setLastChange(System.currentTimeMillis()); break;
break;
case "OFF":
case "OFF": bit &= ~mine.getFlags();
bit &= ~mine.getFlags(); if (!DbManager.MineQueries.SET_FLAGS(mine, bit))
if (!DbManager.MineQueries.SET_FLAGS(mine, bit)) return;
return; mine.setFlags(bit);
mine.setFlags(bit); ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is no longer an expansion mine.");
ChatManager.chatSystemInfo(pcSender, mine.getZoneName() + "'s " + mine.getMineType().name + " is no longer an expansion mine."); break;
Mine.setLastChange(System.currentTimeMillis());
break; }
}
}
@Override
protected String _getUsageString() {
}
@Override
protected String _getUsageString() {
return "' /setmineexpansion on|off"; return "' /setmineexpansion on|off";
} }
@Override @Override
protected String _getHelpString() { protected String _getHelpString() {
return "enables or disables an expansion type for a mine."; return "enables or disables an expansion type for a mine.";
} }
} }

59
src/engine/devcmd/cmds/SetMineTypeCmd.java

@ -18,48 +18,45 @@ import engine.gameManager.DbManager;
import engine.objects.*; import engine.objects.*;
/** /**
*
* @author Eighty * @author Eighty
*
*/ */
public class SetMineTypeCmd extends AbstractDevCmd { public class SetMineTypeCmd extends AbstractDevCmd {
public SetMineTypeCmd() { public SetMineTypeCmd() {
super("setminetype"); super("setminetype");
this.addCmdString("setminetype"); this.addCmdString("setminetype");
} }
@Override @Override
protected void _doCmd(PlayerCharacter pcSender, String[] args, protected void _doCmd(PlayerCharacter pcSender, String[] args,
AbstractGameObject target) { AbstractGameObject target) {
MineProduction mineType = MineProduction.valueOf(args[0].toUpperCase()); MineProduction mineType = MineProduction.valueOf(args[0].toUpperCase());
if (mineType == null) if (mineType == null)
return; return;
if (target.getObjectType() != GameObjectType.Building) if (target.getObjectType() != GameObjectType.Building)
return; return;
Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID()); Building mineBuilding = BuildingManager.getBuilding(target.getObjectUUID());
if (mineBuilding == null) if (mineBuilding == null)
return; return;
Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID()); Mine mine = Mine.getMineFromTower(mineBuilding.getObjectUUID());
if (mine == null) if (mine == null)
return; return;
if (!DbManager.MineQueries.CHANGE_TYPE(mine, mineType)) if (!DbManager.MineQueries.CHANGE_TYPE(mine, mineType))
return; return;
mine.setMineType(mineType.name()); mine.setMineType(mineType.name());
ChatManager.chatSystemInfo(pcSender, "The mine in " + mine.getZoneName() + " is now a(n) " + mine.getMineType().name); ChatManager.chatSystemInfo(pcSender, "The mine in " + mine.getZoneName() + " is now a(n) " + mine.getMineType().name);
Mine.setLastChange(System.currentTimeMillis()); }
}
@Override @Override
protected String _getUsageString() { protected String _getUsageString() {
return "' /setminetype gold|ore|magic|lumber"; return "' /setminetype gold|ore|magic|lumber";
} }
@Override @Override
protected String _getHelpString() { protected String _getHelpString() {
return "Changes the mine type of the current mine."; return "Changes the mine type of the current mine.";
} }
} }

62
src/engine/net/client/handlers/ArcMineChangeProductionMsgHandler.java

@ -7,7 +7,6 @@ import engine.net.DispatchMessage;
import engine.net.client.ClientConnection; import engine.net.client.ClientConnection;
import engine.net.client.msg.ArcMineChangeProductionMsg; import engine.net.client.msg.ArcMineChangeProductionMsg;
import engine.net.client.msg.ClientNetMsg; import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.KeepAliveServerClientMsg;
import engine.objects.GuildStatusController; import engine.objects.GuildStatusController;
import engine.objects.Mine; import engine.objects.Mine;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
@ -21,49 +20,48 @@ import engine.objects.Resource;
public class ArcMineChangeProductionMsgHandler extends AbstractClientMsgHandler { public class ArcMineChangeProductionMsgHandler extends AbstractClientMsgHandler {
public ArcMineChangeProductionMsgHandler() { public ArcMineChangeProductionMsgHandler() {
super(ArcMineChangeProductionMsg.class); super(ArcMineChangeProductionMsg.class);
} }
@Override @Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException { protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
ArcMineChangeProductionMsg changeProductionMsg = (ArcMineChangeProductionMsg) baseMsg;
if (playerCharacter == null) PlayerCharacter playerCharacter = origin.getPlayerCharacter();
return true; 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? //TODO verify this against the warehouse?
return true;
Mine mine = Mine.getMine(changeProductionMsg.getMineID()); if (GuildStatusController.isInnerCouncil(playerCharacter.getGuildStatus()) == false) // is this only GL?
return true;
if (mine == null) Mine mine = Mine.getMine(changeProductionMsg.getMineID());
return true;
//make sure mine belongs to guild if (mine == null)
return true;
if (mine.getOwningGuild().isEmptyGuild() || //make sure mine belongs to guild
mine.getOwningGuild().getObjectUUID() != playerCharacter.getGuild().getObjectUUID())
return true;
//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) Resource resource = Resource.resourceByHash.get(changeProductionMsg.getResourceHash());
return true;
//update resource if (resource == null)
return true;
mine.changeProductionType(resource); //update resource
Mine.setLastChange(System.currentTimeMillis());
Dispatch dispatch = Dispatch.borrow(playerCharacter, changeProductionMsg); mine.changeProductionType(resource);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY); Dispatch dispatch = Dispatch.borrow(playerCharacter, changeProductionMsg);
return true; DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
} return true;
}
} }

278
src/engine/objects/Mine.java

@ -20,7 +20,10 @@ package engine.objects;
import engine.Enum; import engine.Enum;
import engine.InterestManagement.WorldGrid; 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.ByteBufferWriter;
import engine.net.client.msg.ErrorPopupMsg; import engine.net.client.msg.ErrorPopupMsg;
import engine.server.MBServerStatics; import engine.server.MBServerStatics;
@ -33,38 +36,34 @@ import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap; 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; import static engine.math.FastMath.sqr;
public class Mine extends AbstractGameObject { public class Mine extends AbstractGameObject {
private String zoneName; public static ConcurrentHashMap<Mine, Integer> mineMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
private Resource production; public static ConcurrentHashMap<Integer, Mine> towerMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
public boolean isActive = false; public boolean isActive = false;
private float latitude;
private float longitude;
private float altitude;
private Guild owningGuild;
public PlayerCharacter lastClaimer; public PlayerCharacter lastClaimer;
public boolean wasClaimed = false; 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 // Not persisted to DB
public String guildName; public String guildName;
public GuildTag guildTag; public GuildTag guildTag;
public String nationName; public String nationName;
public GuildTag nationTag; public GuildTag nationTag;
public static ConcurrentHashMap<Mine, Integer> mineMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); private final String zoneName;
public static ConcurrentHashMap<Integer, Mine> towerMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW); 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 * ResultSet Constructor
@ -139,6 +138,7 @@ public class Mine extends AbstractGameObject {
} }
} }
public static void SendMineAttackMessage(Building mine) { public static void SendMineAttackMessage(Building mine) {
if (mine.getBlueprint() == null) if (mine.getBlueprint() == null)
@ -186,90 +186,10 @@ public class Mine extends AbstractGameObject {
* Getters * 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) { public static Mine getMineFromTower(int towerID) {
return Mine.towerMap.get(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) { public static void serializeForClientMsg(Mine mine, ByteBufferWriter writer) {
writer.putInt(mine.getObjectType().ordinal()); writer.putInt(mine.getObjectType().ordinal());
writer.putInt(mine.getObjectUUID()); writer.putInt(mine.getObjectUUID());
@ -284,15 +204,15 @@ public class Mine extends AbstractGameObject {
// Errant mines are currently open. Set time to now. // Errant mines are currently open. Set time to now.
LocalDateTime mineOpenTime = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0); LocalDateTime mineOpenTime = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
// Mine times are those of the nation not individual guild. // Mine times are those of the nation not individual guild.
Guild mineNatonGuild = mine.getOwningGuild().getNation(); Guild mineNatonGuild = mine.getOwningGuild().getNation();
// Adjust the serialized mine time based upon whether // Adjust the serialized mine time based upon whether
// the Guild's mine window has passed or not and if it was claimed. // the Guild's mine window has passed or not and if it was claimed.
// If a mine is active serialize current datetime irrespective // If a mine is active serialize current datetime irrespective
// of any claim. // of any claim.
if (mineNatonGuild.isEmptyGuild() == false && mine.isActive == false) { if (mineNatonGuild.isEmptyGuild() == false && mine.isActive == false) {
@ -321,20 +241,6 @@ public class Mine extends AbstractGameObject {
GuildTag._serializeForDisplay(mine.nationTag, writer); 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<Mine> getMinesForGuild(int guildID) { public static ArrayList<Mine> getMinesForGuild(int guildID) {
ArrayList<Mine> mineList = new ArrayList<>(); ArrayList<Mine> mineList = new ArrayList<>();
@ -343,20 +249,12 @@ public class Mine extends AbstractGameObject {
for (Mine mine : Mine.mineMap.keySet()) { for (Mine mine : Mine.mineMap.keySet()) {
if (mine.owningGuild.getObjectUUID() == guildID && if (mine.owningGuild.getObjectUUID() == guildID &&
mine.isActive == false) mine.isActive == false)
mineList.add(mine); mineList.add(mine);
} }
return mineList; return mineList;
} }
public static long getLastChange() {
return lastChange;
}
public static void setLastChange(long lastChange) {
Mine.lastChange = lastChange;
}
/* /*
* Database * Database
*/ */
@ -369,19 +267,6 @@ public class Mine extends AbstractGameObject {
return new ArrayList<>(mineMap.keySet()); 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) { public static boolean validateClaimer(PlayerCharacter playerCharacter) {
// Method validates that the claimer meets // Method validates that the claimer meets
@ -407,7 +292,7 @@ public class Mine extends AbstractGameObject {
if (playerGuild.getNation().isEmptyGuild()) if (playerGuild.getNation().isEmptyGuild())
return false; return false;
// Guild must own a city to hold a mine. // Guild must own a city to hold a mine.
City guildCity = playerGuild.getOwnedCity(); City guildCity = playerGuild.getOwnedCity();
@ -433,7 +318,7 @@ public class Mine extends AbstractGameObject {
if (treeRank < 1) if (treeRank < 1)
return false; return false;
if (guildUnderMineLimit(playerGuild.getNation(), treeRank) == false){ if (guildUnderMineLimit(playerGuild.getNation(), treeRank) == false) {
ErrorPopupMsg.sendErrorMsg(playerCharacter, "Your nation cannot support another mine."); ErrorPopupMsg.sendErrorMsg(playerCharacter, "Your nation cannot support another mine.");
return false; return false;
} }
@ -450,11 +335,116 @@ public class Mine extends AbstractGameObject {
for (Guild guild : playerGuild.getSubGuildList()) for (Guild guild : playerGuild.getSubGuildList())
mineCnt += Mine.getMinesForGuild(guild.getObjectUUID()).size(); 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; return false;
this.production = resource;
return true; 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() { public void handleDestroyMine() {
if (!this.isActive) if (!this.isActive)
@ -465,7 +455,6 @@ public class Mine extends AbstractGameObject {
this.guildName = ""; this.guildName = "";
this.nationName = ""; this.nationName = "";
this.owningGuild = Guild.getErrantGuild(); this.owningGuild = Guild.getErrantGuild();
Mine.setLastChange(System.currentTimeMillis());
this.lastClaimer = null; this.lastClaimer = null;
this.wasClaimed = false; this.wasClaimed = false;
@ -513,6 +502,7 @@ public class Mine extends AbstractGameObject {
return true; return true;
} }
public boolean depositMineResources() { public boolean depositMineResources() {
if (this.owningGuild.isEmptyGuild()) if (this.owningGuild.isEmptyGuild())

218
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<Integer, AbstractGameObject> 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<PlayerCharacter> 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() { public static void decayShrines() {
ArrayList<Shrine> shrineList = new ArrayList<>(); ArrayList<Shrine> shrineList = new ArrayList<>();
@ -194,7 +89,6 @@ public class HourlyJobThread implements Runnable {
if (mine.getOwningGuild().isEmptyGuild()) { if (mine.getOwningGuild().isEmptyGuild()) {
HourlyJobThread.mineWindowOpen(mine); HourlyJobThread.mineWindowOpen(mine);
Mine.setLastChange(System.currentTimeMillis());
continue; continue;
} }
@ -204,14 +98,12 @@ public class HourlyJobThread implements Runnable {
if (mine.getOwningGuild().getNation().getMineTime() == if (mine.getOwningGuild().getNation().getMineTime() ==
LocalDateTime.now().getHour() && mine.wasClaimed == false) { LocalDateTime.now().getHour() && mine.wasClaimed == false) {
HourlyJobThread.mineWindowOpen(mine); HourlyJobThread.mineWindowOpen(mine);
Mine.setLastChange(System.currentTimeMillis());
continue; continue;
} }
// Close all the remaining mines // Close the mine if it reaches this far
if (mineWindowClose(mine)) mineWindowClose(mine);
Mine.setLastChange(System.currentTimeMillis());
} catch (Exception e) { } catch (Exception e) {
Logger.error("mineID: " + mine.getObjectUUID(), e.toString()); Logger.error("mineID: " + mine.getObjectUUID(), e.toString());
@ -271,8 +163,6 @@ public class HourlyJobThread implements Runnable {
mine.nationName = nation.getName(); mine.nationName = nation.getName();
mine.nationTag = nation.getGuildTag(); mine.nationTag = nation.getGuildTag();
Mine.setLastChange(System.currentTimeMillis());
mineBuilding.rebuildMine(); mineBuilding.rebuildMine();
WorldGrid.updateObject(mineBuilding); WorldGrid.updateObject(mineBuilding);
@ -292,4 +182,108 @@ public class HourlyJobThread implements Runnable {
mine.wasClaimed = true; mine.wasClaimed = true;
return 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<Integer, AbstractGameObject> 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<PlayerCharacter> 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");
}
} }

Loading…
Cancel
Save