forked from MagicBane/Server
Refactor WOO change timer mechanics to use the same system as the mine claims. Moved both resets to the hourly job.
This commit is contained in:
@@ -115,13 +115,6 @@ public class dbGuildHandler extends dbHandlerBase {
|
|||||||
return outputStr;
|
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) {
|
public ArrayList<Guild> GET_GUILD_ALLIES(final int id) {
|
||||||
prepareCallable("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
|
prepareCallable("SELECT g.* FROM `obj_guild` g, `dyn_guild_allianceenemylist` l "
|
||||||
+ "WHERE l.isAlliance = 1 && l.OtherGuildID = g.UID && l.GuildID=?");
|
+ "WHERE l.isAlliance = 1 && l.OtherGuildID = g.UID && l.GuildID=?");
|
||||||
|
|||||||
@@ -81,10 +81,10 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler {
|
|||||||
if (newMineTime == 24)
|
if (newMineTime == 24)
|
||||||
newMineTime = 0;
|
newMineTime = 0;
|
||||||
|
|
||||||
// Enforce 15hr restriction between WOO edits
|
// Enforce time restriction between WOO edits
|
||||||
|
|
||||||
if (LocalDateTime.now().isBefore(mineGuild.lastWooEditTime.plusHours(14))) {
|
if (mineGuild.wooWasModified) {
|
||||||
ErrorPopupMsg.sendErrorMsg(playerCharacter, "You must wait 15 hours between WOO changes.");
|
ErrorPopupMsg.sendErrorMsg(playerCharacter, "You can only modify your WOO once per day.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,19 +110,11 @@ public class MineWindowChangeHandler extends AbstractClientMsgHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mineGuild.setMineTime(newMineTime);
|
mineGuild.setMineTime(newMineTime);
|
||||||
mineGuild.lastWooEditTime = LocalDateTime.now();
|
mineGuild.wooWasModified = true;
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatManager.chatGuildInfo(playerCharacter, "Mine time updated.");
|
ChatManager.chatGuildInfo(playerCharacter, "Mine time updated.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1022
-1044
File diff suppressed because it is too large
Load Diff
@@ -793,7 +793,7 @@ public class MBServerStatics {
|
|||||||
public static final int MAX_PLAYER_LOAD_SIZE = 1000;
|
public static final int MAX_PLAYER_LOAD_SIZE = 1000;
|
||||||
|
|
||||||
// Mine related
|
// 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
|
public static final int MINE_LATE_WINDOW = 0; // Midnight
|
||||||
|
|
||||||
// Race
|
// Race
|
||||||
|
|||||||
@@ -22,127 +22,147 @@ 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.server.MBServerStatics.MINE_LATE_WINDOW;
|
||||||
|
|
||||||
public class HourlyJobThread implements Runnable {
|
public class HourlyJobThread implements Runnable {
|
||||||
|
|
||||||
private static int hotzoneCount = 0;
|
private static final int hotzoneCount = 0;
|
||||||
|
|
||||||
public HourlyJobThread() {
|
public HourlyJobThread() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
// *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG
|
// *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG
|
||||||
|
|
||||||
Logger.info("Hourly job is now running.");
|
Logger.info("Hourly job is now running.");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ZoneManager.generateAndSetRandomHotzone();
|
ZoneManager.generateAndSetRandomHotzone();
|
||||||
Zone hotzone = ZoneManager.getHotZone();
|
Zone hotzone = ZoneManager.getHotZone();
|
||||||
|
|
||||||
if (hotzone == null) {
|
if (hotzone == null) {
|
||||||
Logger.error( "Null hotzone returned from mapmanager");
|
Logger.error("Null hotzone returned from mapmanager");
|
||||||
} else {
|
} else {
|
||||||
Logger.info( "new hotzone: " + hotzone.getName());
|
Logger.info("new hotzone: " + hotzone.getName());
|
||||||
WorldServer.setLastHZChange(System.currentTimeMillis());
|
WorldServer.setLastHZChange(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Logger.error( e.toString());
|
Logger.error(e.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open or Close mines for the current mine window.
|
// Open or Close mines for the current mine window.
|
||||||
|
|
||||||
processMineWindow();
|
processMineWindow();
|
||||||
|
|
||||||
for (Mine mine : Mine.getMines()) {
|
// Deposit mine resources to Guilds
|
||||||
|
|
||||||
try {
|
for (Mine mine : Mine.getMines()) {
|
||||||
mine.depositMineResources();
|
|
||||||
} catch (Exception e) {
|
try {
|
||||||
Logger.info(e.getMessage() + " for Mine " + mine.getObjectUUID());
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update city population values
|
// Mines can only be claimed once per cycle.
|
||||||
|
// This will reset at 1am after the last mine
|
||||||
|
// window closes.
|
||||||
|
|
||||||
ConcurrentHashMap<Integer, AbstractGameObject> map = DbManager.getMap(Enum.GameObjectType.City);
|
if (LocalDateTime.now().getHour() == MINE_LATE_WINDOW + 1) {
|
||||||
|
|
||||||
if (map != null) {
|
for (Mine mine : Mine.getMines()) {
|
||||||
|
|
||||||
for (AbstractGameObject ago : map.values()){
|
if (mine.wasClaimed == true)
|
||||||
|
mine.wasClaimed = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
City city = (City)ago;
|
// Update city population values
|
||||||
|
|
||||||
if (city != null)
|
ConcurrentHashMap<Integer, AbstractGameObject> map = DbManager.getMap(Enum.GameObjectType.City);
|
||||||
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
|
if (map != null) {
|
||||||
Logger.info( WorldServer.getUptimeString());
|
|
||||||
Logger.info( SimulationManager.getPopulationString());
|
|
||||||
Logger.info( MessageDispatcher.getNetstatString());
|
|
||||||
Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void processMineWindow() {
|
for (AbstractGameObject ago : map.values()) {
|
||||||
|
|
||||||
try {
|
City city = (City) ago;
|
||||||
|
|
||||||
ArrayList<Mine> mines = Mine.getMines();
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
for (Mine mine : mines) {
|
// Log metrics to console
|
||||||
try {
|
Logger.info(WorldServer.getUptimeString());
|
||||||
|
Logger.info(SimulationManager.getPopulationString());
|
||||||
|
Logger.info(MessageDispatcher.getNetstatString());
|
||||||
|
Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted");
|
||||||
|
}
|
||||||
|
|
||||||
// Mines can only be claimed once a cycle.
|
public static void processMineWindow() {
|
||||||
// The cycle resets at 01:00hrs after the
|
|
||||||
// Last mine window closes.
|
|
||||||
|
|
||||||
if (mine.wasClaimed == true) {
|
try {
|
||||||
|
|
||||||
if (LocalDateTime.now().getHour() == 01)
|
ArrayList<Mine> mines = Mine.getMines();
|
||||||
mine.wasClaimed = false;
|
|
||||||
|
|
||||||
continue;
|
for (Mine mine : mines) {
|
||||||
}
|
|
||||||
|
|
||||||
// Open Errant Mines
|
try {
|
||||||
|
|
||||||
if (mine.getOwningGuild().isErrant()) {
|
// Open Errant Mines
|
||||||
mine.handleStartMineWindow();
|
|
||||||
Mine.setLastChange(System.currentTimeMillis());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open Mines with a current guild hour
|
if (mine.getOwningGuild().isErrant()) {
|
||||||
|
mine.handleStartMineWindow();
|
||||||
|
Mine.setLastChange(System.currentTimeMillis());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (mine.getOwningGuild().getNation().getMineTime() ==
|
// Open Mines with a current guild hour
|
||||||
LocalDateTime.now().getHour()) {
|
|
||||||
mine.handleStartMineWindow();
|
|
||||||
Mine.setLastChange(System.currentTimeMillis());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close all remaining mines
|
if (mine.getOwningGuild().getNation().getMineTime() ==
|
||||||
|
LocalDateTime.now().getHour()) {
|
||||||
|
mine.handleStartMineWindow();
|
||||||
|
Mine.setLastChange(System.currentTimeMillis());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (mine.handleEndMineWindow())
|
// Close all remaining mines
|
||||||
Mine.setLastChange(System.currentTimeMillis());
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
if (mine.handleEndMineWindow())
|
||||||
Logger.error ("mineID: " + mine.getObjectUUID(), e.toString());
|
Mine.setLastChange(System.currentTimeMillis());
|
||||||
}
|
|
||||||
}
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
Logger.error("mineID: " + mine.getObjectUUID(), e.toString());
|
||||||
Logger.error( e.toString());
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
Logger.error(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user