Browse Source

lastChanged is unused as cannot omit mines from map.

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

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

@ -42,11 +42,9 @@ public class MineActiveCmd extends AbstractDevCmd { @@ -42,11 +42,9 @@ public class MineActiveCmd extends AbstractDevCmd {
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);

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

@ -21,9 +21,7 @@ import engine.objects.Mine; @@ -21,9 +21,7 @@ import engine.objects.Mine;
import engine.objects.PlayerCharacter;
/**
*
* @author Eighty
*
*/
public class SetMineExpansion extends AbstractDevCmd {
@ -54,7 +52,6 @@ public class SetMineExpansion extends AbstractDevCmd { @@ -54,7 +52,6 @@ public class SetMineExpansion extends AbstractDevCmd {
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":
@ -63,15 +60,11 @@ public class SetMineExpansion extends AbstractDevCmd { @@ -63,15 +60,11 @@ public class SetMineExpansion extends AbstractDevCmd {
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

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

@ -18,9 +18,7 @@ import engine.gameManager.DbManager; @@ -18,9 +18,7 @@ import engine.gameManager.DbManager;
import engine.objects.*;
/**
*
* @author Eighty
*
*/
public class SetMineTypeCmd extends AbstractDevCmd {
@ -49,7 +47,6 @@ public class SetMineTypeCmd extends AbstractDevCmd { @@ -49,7 +47,6 @@ public class SetMineTypeCmd extends AbstractDevCmd {
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

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

@ -7,7 +7,6 @@ import engine.net.DispatchMessage; @@ -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;
@ -60,7 +59,6 @@ public class ArcMineChangeProductionMsgHandler extends AbstractClientMsgHandler @@ -60,7 +59,6 @@ public class ArcMineChangeProductionMsgHandler extends AbstractClientMsgHandler
//update resource
mine.changeProductionType(resource);
Mine.setLastChange(System.currentTimeMillis());
Dispatch dispatch = Dispatch.borrow(playerCharacter, changeProductionMsg);
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
return true;

264
src/engine/objects/Mine.java

@ -20,7 +20,10 @@ package engine.objects; @@ -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; @@ -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<Mine, Integer> mineMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
public static ConcurrentHashMap<Integer, Mine> 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<Mine, Integer> mineMap = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
public static ConcurrentHashMap<Integer, Mine> 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 { @@ -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 { @@ -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());
@ -321,20 +241,6 @@ public class Mine extends AbstractGameObject { @@ -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<Mine> getMinesForGuild(int guildID) {
ArrayList<Mine> mineList = new ArrayList<>();
@ -349,14 +255,6 @@ public class Mine extends AbstractGameObject { @@ -349,14 +255,6 @@ public class Mine extends AbstractGameObject {
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 { @@ -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
@ -450,11 +335,116 @@ public class Mine extends AbstractGameObject { @@ -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 { @@ -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 { @@ -513,6 +502,7 @@ public class Mine extends AbstractGameObject {
return true;
}
public boolean depositMineResources() {
if (this.owningGuild.isEmptyGuild())

218
src/engine/workthreads/HourlyJobThread.java

@ -33,111 +33,6 @@ public class HourlyJobThread implements Runnable { @@ -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() {
ArrayList<Shrine> shrineList = new ArrayList<>();
@ -194,7 +89,6 @@ public class HourlyJobThread implements Runnable { @@ -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 { @@ -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 { @@ -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 { @@ -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<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