Browse Source

Refactor WOO change timer mechanics to use the same system as the mine claims. Moved both resets to the hourly job.

master
MagicBot 2 years ago
parent
commit
6a1b461735
  1. 7
      src/engine/db/handlers/dbGuildHandler.java
  2. 18
      src/engine/net/client/handlers/MineWindowChangeHandler.java
  3. 2294
      src/engine/objects/Guild.java
  4. 2
      src/engine/server/MBServerStatics.java
  5. 190
      src/engine/workthreads/HourlyJobThread.java

7
src/engine/db/handlers/dbGuildHandler.java

@ -115,13 +115,6 @@ public class dbGuildHandler extends dbHandlerBase { @@ -115,13 +115,6 @@ public class dbGuildHandler extends dbHandlerBase {
return outputStr;
}
public boolean SET_LAST_WOO_UPDATE(Guild guild, LocalDateTime lastEditTime) {
prepareCallable("UPDATE `obj_guild` SET `lastWooEditTime`=? WHERE `UID`=?");
setLocalDateTime(1, lastEditTime);
setLong(2, (long) guild.getObjectUUID());
return (executeUpdate() > 0);
}
public ArrayList<Guild> GET_GUILD_ALLIES(final int id) {
prepareCallable("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
+ "WHERE l.isAlliance = 1 && l.OtherGuildID = g.UID && l.GuildID=?");

18
src/engine/net/client/handlers/MineWindowChangeHandler.java

@ -81,10 +81,10 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { @@ -81,10 +81,10 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler {
if (newMineTime == 24)
newMineTime = 0;
// Enforce 15hr restriction between WOO edits
// Enforce time restriction between WOO edits
if (LocalDateTime.now().isBefore(mineGuild.lastWooEditTime.plusHours(14))) {
ErrorPopupMsg.sendErrorMsg(playerCharacter, "You must wait 15 hours between WOO changes.");
if (mineGuild.wooWasModified) {
ErrorPopupMsg.sendErrorMsg(playerCharacter, "You can only modify your WOO once per day.");
return true;
}
@ -110,19 +110,11 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler { @@ -110,19 +110,11 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler {
}
mineGuild.setMineTime(newMineTime);
mineGuild.lastWooEditTime = LocalDateTime.now();
// Update guild WOO timer for reboot persistence
if (!DbManager.GuildQueries.SET_LAST_WOO_UPDATE(mineGuild, mineGuild.lastWooEditTime)) {
Logger.error("MineWindowChange", "Failed to update woo timer for guild " + mineGuild.getObjectUUID());
ChatManager.chatGuildError(playerCharacter, "A Serious error has for to occurred.");
return true;
}
mineGuild.wooWasModified = true;
ChatManager.chatGuildInfo(playerCharacter, "Mine time updated.");
return true;
return true;
}
}

2294
src/engine/objects/Guild.java

File diff suppressed because it is too large Load Diff

2
src/engine/server/MBServerStatics.java

@ -793,7 +793,7 @@ public class MBServerStatics { @@ -793,7 +793,7 @@ public class MBServerStatics {
public static final int MAX_PLAYER_LOAD_SIZE = 1000;
// Mine related
public static final int MINE_EARLY_WINDOW = 16; // 3pm
public static final int MINE_EARLY_WINDOW = 16; // 4pm
public static final int MINE_LATE_WINDOW = 0; // Midnight
// Race

190
src/engine/workthreads/HourlyJobThread.java

@ -22,127 +22,147 @@ import java.time.LocalDateTime; @@ -22,127 +22,147 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import static engine.server.MBServerStatics.MINE_LATE_WINDOW;
public class HourlyJobThread implements Runnable {
private static int hotzoneCount = 0;
private static final int hotzoneCount = 0;
public HourlyJobThread() {
}
public void run() {
// *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG
Logger.info("Hourly job is now running.");
try {
public HourlyJobThread() {
ZoneManager.generateAndSetRandomHotzone();
Zone hotzone = ZoneManager.getHotZone();
}
if (hotzone == null) {
Logger.error("Null hotzone returned from mapmanager");
} else {
Logger.info("new hotzone: " + hotzone.getName());
WorldServer.setLastHZChange(System.currentTimeMillis());
}
public void run() {
} catch (Exception e) {
Logger.error(e.toString());
}
// *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG
// Open or Close mines for the current mine window.
Logger.info("Hourly job is now running.");
processMineWindow();
try {
// Deposit mine resources to Guilds
ZoneManager.generateAndSetRandomHotzone();
Zone hotzone = ZoneManager.getHotZone();
for (Mine mine : Mine.getMines()) {
if (hotzone == null) {
Logger.error( "Null hotzone returned from mapmanager");
} else {
Logger.info( "new hotzone: " + hotzone.getName());
WorldServer.setLastHZChange(System.currentTimeMillis());
}
try {
mine.depositMineResources();
} catch (Exception e) {
Logger.info(e.getMessage() + " for Mine " + mine.getObjectUUID());
}
}
} catch (Exception e) {
Logger.error( e.toString());
}
// Reset time-gated access to WOO slider.
// *** Do this after the mines open/close!
// Open or Close mines for the current mine window.
if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW) {
Guild guild;
processMineWindow();
for (AbstractGameObject dbObject : DbManager.getList(Enum.GameObjectType.Guild)) {
guild = (Guild) dbObject;
for (Mine mine : Mine.getMines()) {
if (guild != null)
guild.wooWasModified = false;
}
}
try {
mine.depositMineResources();
} catch (Exception e) {
Logger.info(e.getMessage() + " for Mine " + mine.getObjectUUID());
}
}
// Mines can only be claimed once per cycle.
// This will reset at 1am after the last mine
// window closes.
// Update city population values
if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW + 1) {
ConcurrentHashMap<Integer, AbstractGameObject> map = DbManager.getMap(Enum.GameObjectType.City);
for (Mine mine : Mine.getMines()) {
if (map != null) {
if (mine.wasClaimed == true)
mine.wasClaimed = false;
}
}
for (AbstractGameObject ago : map.values()){
// Update city population values
City city = (City)ago;
ConcurrentHashMap<Integer, AbstractGameObject> map = DbManager.getMap(Enum.GameObjectType.City);
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");
}
if (map != null) {
// Log metrics to console
Logger.info( WorldServer.getUptimeString());
Logger.info( SimulationManager.getPopulationString());
Logger.info( MessageDispatcher.getNetstatString());
Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted");
}
for (AbstractGameObject ago : map.values()) {
public static void processMineWindow() {
City city = (City) ago;
try {
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");
}
ArrayList<Mine> mines = Mine.getMines();
// Log metrics to console
Logger.info(WorldServer.getUptimeString());
Logger.info(SimulationManager.getPopulationString());
Logger.info(MessageDispatcher.getNetstatString());
Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted");
}
for (Mine mine : mines) {
try {
public static void processMineWindow() {
// Mines can only be claimed once a cycle.
// The cycle resets at 01:00hrs after the
// Last mine window closes.
try {
if (mine.wasClaimed == true) {
ArrayList<Mine> mines = Mine.getMines();
if (LocalDateTime.now().getHour() == 01)
mine.wasClaimed = false;
for (Mine mine : mines) {
continue;
}
try {
// Open Errant Mines
// Open Errant Mines
if (mine.getOwningGuild().isErrant()) {
mine.handleStartMineWindow();
Mine.setLastChange(System.currentTimeMillis());
continue;
}
if (mine.getOwningGuild().isErrant()) {
mine.handleStartMineWindow();
Mine.setLastChange(System.currentTimeMillis());
continue;
}
// Open Mines with a current guild hour
// Open Mines with a current guild hour
if (mine.getOwningGuild().getNation().getMineTime() ==
LocalDateTime.now().getHour()) {
mine.handleStartMineWindow();
Mine.setLastChange(System.currentTimeMillis());
continue;
}
if (mine.getOwningGuild().getNation().getMineTime() ==
LocalDateTime.now().getHour()) {
mine.handleStartMineWindow();
Mine.setLastChange(System.currentTimeMillis());
continue;
}
// Close all remaining mines
// Close all remaining mines
if (mine.handleEndMineWindow())
Mine.setLastChange(System.currentTimeMillis());
if (mine.handleEndMineWindow())
Mine.setLastChange(System.currentTimeMillis());
} catch (Exception e) {
Logger.error ("mineID: " + mine.getObjectUUID(), e.toString());
}
}
} catch (Exception e) {
Logger.error( e.toString());
}
}
} catch (Exception e) {
Logger.error("mineID: " + mine.getObjectUUID(), e.toString());
}
}
} catch (Exception e) {
Logger.error(e.toString());
}
}
}

Loading…
Cancel
Save