Browse Source

Initial refactor: deleted all old code and replaced with something sensible. Driven from the guild's mine hour instead of calculating dates.

master
MagicBot 2 years ago
parent
commit
6672f750d9
  1. 5
      src/engine/devcmd/cmds/InfoCmd.java
  2. 94
      src/engine/devcmd/cmds/setOpenDateCmd.java
  3. 1
      src/engine/gameManager/DevCmdManager.java
  4. 71
      src/engine/jobs/MineActiveJob.java
  5. 112
      src/engine/objects/Mine.java
  6. 6
      src/engine/server/world/WorldServer.java
  7. 17
      src/engine/workthreads/HourlyJobThread.java

5
src/engine/devcmd/cmds/InfoCmd.java

@ -201,11 +201,6 @@ public class InfoCmd extends AbstractDevCmd {
output+= newline; output+= newline;
output+= "Production type: " +mine.getProduction().name(); output+= "Production type: " +mine.getProduction().name();
output+= newline;
output+= "Open Date: "+ ( mine.openDate).toString();
output+= newline;
output+= "Open Date: "+ (mine.openDate).toString();
} }
} }
output += newline; output += newline;

94
src/engine/devcmd/cmds/setOpenDateCmd.java

@ -1,94 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.devcmd.cmds;
import engine.Enum.BuildingGroup;
import engine.Enum.GameObjectType;
import engine.devcmd.AbstractDevCmd;
import engine.gameManager.BuildingManager;
import engine.objects.*;
public class setOpenDateCmd extends AbstractDevCmd {
public setOpenDateCmd() {
super("minedate");
}
@Override
protected void _doCmd(PlayerCharacter pcSender, String[] words,
AbstractGameObject target) {
if (words[0].equalsIgnoreCase("list")){
for (int buildingID : Mine.towerMap.keySet()){
Building building = BuildingManager.getBuildingFromCache(buildingID);
if (building == null){
this.throwbackError(pcSender, "null building for ID " + buildingID);
continue;
}
Zone zone = building.getParentZone();
Zone parentZone = zone.getParent();
Mine mine = Mine.towerMap.get(buildingID);
this.throwbackInfo(pcSender, "Mine UUID : " + mine.getObjectUUID() + " Mine Type: " + zone.getName() + " Zone : " + parentZone.getName()
+ " Open Date : " + mine.openDate);
}
}
if (target == null){
this.throwbackError(pcSender, "null target");
return;
}
if (target.getObjectType().equals(GameObjectType.Building) == false){
this.throwbackError(pcSender, "target must be object type building");
return;
}
Building building = (Building)target;
if (building.getBlueprint() == null){
this.throwbackError(pcSender, "null blueprint");
return;
}
if (building.getBlueprint().getBuildingGroup().equals(BuildingGroup.MINE) == false){
this.throwbackError(pcSender, "target not mine");
return;
}
Mine mine = Mine.getMineFromTower(building.getObjectUUID());
if (mine == null){
this.throwbackError(pcSender, "null mine");
return;
}
int days = Integer.parseInt(words[0]);
int hours = Integer.parseInt(words[1]);
mine.openDate = mine.openDate.plusDays(days).plusHours(hours);
this.throwbackInfo(pcSender, "Mine Open Date Changed to " + mine.openDate.toString());
}
@Override
protected String _getUsageString() {
return "' /bounds'";
}
@Override
protected String _getHelpString() {
return "Audits all the mobs in a zone.";
}
}

1
src/engine/gameManager/DevCmdManager.java

@ -151,7 +151,6 @@ public enum DevCmdManager {
DevCmdManager.registerDevCmd(new RegionCmd()); DevCmdManager.registerDevCmd(new RegionCmd());
DevCmdManager.registerDevCmd(new SetMaintCmd()); DevCmdManager.registerDevCmd(new SetMaintCmd());
DevCmdManager.registerDevCmd(new ApplyBonusCmd()); DevCmdManager.registerDevCmd(new ApplyBonusCmd());
DevCmdManager.registerDevCmd(new setOpenDateCmd());
DevCmdManager.registerDevCmd(new AuditFailedItemsCmd()); DevCmdManager.registerDevCmd(new AuditFailedItemsCmd());
} }

71
src/engine/jobs/MineActiveJob.java

@ -1,71 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.jobs;
import engine.job.AbstractJob;
import engine.objects.Mine;
import org.pmw.tinylog.Logger;
import java.time.LocalDateTime;
import java.util.ArrayList;
public class MineActiveJob extends AbstractJob {
public MineActiveJob() {
super();
}
@Override
protected void doJob() {
ArrayList<Mine> mines = Mine.getMines();
LocalDateTime now = LocalDateTime.now();
for (Mine mine : mines) {
try {
if (mine.getOwningGuild() == null){
mine.handleStartMineWindow();
Mine.setLastChange(System.currentTimeMillis());
continue;
}
//handle claimed mines
LocalDateTime mineWindow = mine.openDate.withMinute(0).withSecond(0).withNano(0);
if (mineWindow != null && now.plusMinutes(1).isAfter(mineWindow))
if (!mine.getIsActive()) {
Logger.info("activating mine. " + mineWindow.getHour() + " , " + now.getHour());
mine.handleStartMineWindow();
Mine.setLastChange(System.currentTimeMillis());
}else{
if (mine.handleEndMineWindow()){
Logger.info("Deactivating mine. " + mineWindow.getHour() + " , " + now.getHour());
Mine.setLastChange(System.currentTimeMillis());
}
}
}catch (Exception e) {
Logger.error( "mineID: " + mine.getObjectUUID() + e);
}
}
}
}

112
src/engine/objects/Mine.java

@ -59,7 +59,6 @@ public class Mine extends AbstractGameObject {
private int buildingID; private int buildingID;
private Zone parentZone; private Zone parentZone;
private MineProduction mineType; private MineProduction mineType;
public LocalDateTime openDate;
public boolean dirtyMine = false; public boolean dirtyMine = false;
//flags 1: never been claimed (make active). //flags 1: never been claimed (make active).
@ -139,12 +138,6 @@ public class Mine extends AbstractGameObject {
this.lastClaimerID = 0; this.lastClaimerID = 0;
this.lastClaimerSessionID = null; this.lastClaimerSessionID = null;
Timestamp mineOpenDateTime = rs.getTimestamp("mine_openDate");
if (mineOpenDateTime != null)
this.openDate = mineOpenDateTime.toLocalDateTime();
} }
public static void SendMineAttackMessage(Building mine){ public static void SendMineAttackMessage(Building mine){
@ -170,30 +163,6 @@ public class Mine extends AbstractGameObject {
ChatManager.chatNationInfo(mine.getGuild().getNation(), mine.getName() + " in " + mine.getParentZone().getParent().getName() + " is Under attack!"); ChatManager.chatNationInfo(mine.getGuild().getNation(), mine.getName() + " in " + mine.getParentZone().getParent().getName() + " is Under attack!");
} }
private void setNextMineWindow() {
int nextMineHour = MBServerStatics.MINE_EARLY_WINDOW;;
LocalDateTime nextOpenDate = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
// If errant use mine stays open.
if (this.owningGuild == null || this.owningGuild.isErrant() == true)
return;
// Use the new owners Mine WOO.
nextMineHour = this.owningGuild.getMineTime();
if ((this.openDate.getHour() == 0 || this.openDate.getHour() == 24) &&
(this.owningGuild.getMineTime() != 0 && this.owningGuild.getMineTime() != 24))
nextOpenDate = nextOpenDate.withHour(nextMineHour);
else
nextOpenDate = nextOpenDate.withHour(nextMineHour).plusDays(1);
DbManager.MineQueries.CHANGE_MINE_TIME(this, nextOpenDate);
this.openDate = nextOpenDate;
}
public static void loadAllMines() { public static void loadAllMines() {
try{ try{
@ -207,7 +176,6 @@ try{
for (Mine mine : serverMines) { for (Mine mine : serverMines) {
Mine.mineMap.put(mine, mine.buildingID); Mine.mineMap.put(mine, mine.buildingID);
Mine.towerMap.put(mine.buildingID, mine); Mine.towerMap.put(mine.buildingID, mine);
mine.initializeMineTime();
} }
}catch (Exception e){ }catch (Exception e){
@ -218,48 +186,6 @@ try{
/* /*
* Getters * Getters
*/ */
private void initializeMineTime(){
Guild nation = null;
// If errant use mine stays open.
if (this.owningGuild == null || this.owningGuild.isErrant() == true) {
// Update mesh
Building mineBuilding = BuildingManager.getBuildingFromCache(this.buildingID);
if (mineBuilding == null){
Logger.debug( "Null mine building " + this.getObjectUUID() +". Unable to Load Building with UID " +this.buildingID);
return;
}
mineBuilding.healthMax = (float) 1;
mineBuilding.meshUUID = mineBuilding.getBlueprint().getMeshForRank(-1);
mineBuilding.setRank(-1);
mineBuilding.setCurrentHitPoints((float) 1);
return;
}
nation = this.owningGuild.getNation();
int mineTime = (nation != null && !nation.isErrant()) ? nation.getMineTime() : MBServerStatics.MINE_EARLY_WINDOW;
this.openDate = this.openDate.withHour(mineTime).withMinute(0).withSecond(0).withNano(0);
//Failed to Update Database, default mine time.
if (!MineQueries.CHANGE_MINE_TIME(this, openDate)){
Logger.info("Mine with UUID " + this.getObjectUUID() + " failed to set Mine Window. Defaulting to Earliest.");
openDate = openDate.withHour(MBServerStatics.MINE_EARLY_WINDOW).withMinute(0).withSecond(0).withNano(0);
this.openDate = openDate;
return;
}
}
public boolean changeProductionType(Resource resource){ public boolean changeProductionType(Resource resource){
if (!this.validForMine(resource)) if (!this.validForMine(resource))
@ -354,11 +280,27 @@ try{
writer.putInt(mine.getModifiedProductionAmount()); //TODO calculate range penalty here writer.putInt(mine.getModifiedProductionAmount()); //TODO calculate range penalty here
writer.putInt(3600); //window in seconds writer.putInt(3600); //window in seconds
LocalDateTime mw = mine.openDate; // Errant mines are currently open. Set time to now.
LocalDateTime mineTime = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
Guild mineOwnerGuild = mine.getOwningGuild();
// Adjust the serialized mine time based upon whether
// the Guild's mine window has passed or not.
if (mineOwnerGuild != null) {
writer.putLocalDateTime(mw); int guildWOO = mineOwnerGuild.getMineTime();
mw = mw.plusHours(1); LocalDateTime guildMineTime = mineTime.withHour(guildWOO);
writer.putLocalDateTime(mw);
if (mineTime.isAfter(guildMineTime))
mineTime = guildMineTime.plusDays(1);
else
mineTime = guildMineTime;
}
writer.putLocalDateTime(mineTime);
writer.putLocalDateTime(mineTime.plusHours(1));
writer.put(mine.isActive ? (byte) 0x01 : (byte) 0x00); writer.put(mine.isActive ? (byte) 0x01 : (byte) 0x00);
writer.putFloat(mine.latitude); writer.putFloat(mine.latitude);
@ -570,18 +512,13 @@ try{
if (this.dirtyMine && this.lastClaimerID == 0 && (this.owningGuild == null || this.owningGuild.isErrant())) if (this.dirtyMine && this.lastClaimerID == 0 && (this.owningGuild == null || this.owningGuild.isErrant()))
return false; return false;
this.setActive(false); this.setActive(false);
setNextMineWindow();
return true; return true;
} }
PlayerCharacter claimer = PlayerCharacter.getFromCache(this.lastClaimerID); PlayerCharacter claimer = PlayerCharacter.getFromCache(this.lastClaimerID);
if (!validClaimer(claimer)){ if (!validClaimer(claimer))
LocalDateTime resetTime = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
this.openDate = resetTime;
return false; return false;
}
// //verify the player hasn't logged out since claim // //verify the player hasn't logged out since claim
@ -590,12 +527,8 @@ try{
// if (!SessionManager.getSession(claimer).getSessionID().equals(this.lastClaimerSessionID)) // if (!SessionManager.getSession(claimer).getSessionID().equals(this.lastClaimerSessionID))
// return false; // return false;
if (this.owningGuild == null || this.owningGuild.isErrant() || this.owningGuild.getNation().isErrant()){ if (this.owningGuild == null || this.owningGuild.isErrant() || this.owningGuild.getNation().isErrant())
LocalDateTime resetTime = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
this.openDate = resetTime;
return false; return false;
}
//Update ownership to map //Update ownership to map
@ -605,7 +538,6 @@ try{
this.nationName = nation.getName(); this.nationName = nation.getName();
this.nationTag = nation.getGuildTag(); this.nationTag = nation.getGuildTag();
setNextMineWindow();
setLastChange(System.currentTimeMillis()); setLastChange(System.currentTimeMillis());
if (mineBuilding.getRank() < 1){ if (mineBuilding.getRank() < 1){

6
src/engine/server/world/WorldServer.java

@ -25,7 +25,6 @@ import engine.gameManager.*;
import engine.job.JobContainer; import engine.job.JobContainer;
import engine.job.JobScheduler; import engine.job.JobScheduler;
import engine.jobs.LogoutCharacterJob; import engine.jobs.LogoutCharacterJob;
import engine.jobs.MineActiveJob;
import engine.loot.LootManager; import engine.loot.LootManager;
import engine.net.Dispatch; import engine.net.Dispatch;
import engine.net.DispatchMessage; import engine.net.DispatchMessage;
@ -436,11 +435,6 @@ public class WorldServer {
if (ZoneManager.getHotZone() != null) if (ZoneManager.getHotZone() != null)
WorldServer.setLastHZChange(System.currentTimeMillis()); WorldServer.setLastHZChange(System.currentTimeMillis());
//Start Mines.
MineActiveJob maj = new MineActiveJob();
maj.run();
Logger.info("Starting Mobile AI FSM"); Logger.info("Starting Mobile AI FSM");
MobileFSMManager.getInstance(); MobileFSMManager.getInstance();

17
src/engine/workthreads/HourlyJobThread.java

@ -56,28 +56,31 @@ public class HourlyJobThread implements Runnable {
try { try {
ArrayList<Mine> mines = Mine.getMines(); ArrayList<Mine> mines = Mine.getMines();
LocalDateTime now = LocalDateTime.now();
for (Mine mine : mines) { for (Mine mine : mines) {
try { try {
// Open Errant Mines
if (mine.getOwningGuild() == null) { if (mine.getOwningGuild() == null) {
mine.handleStartMineWindow(); mine.handleStartMineWindow();
Mine.setLastChange(System.currentTimeMillis()); Mine.setLastChange(System.currentTimeMillis());
continue; continue;
} }
//handle claimed mines // Open Mines with a current guild hour
LocalDateTime mineWindow = mine.openDate.withMinute(0).withSecond(0).withNano(0);
if (mineWindow != null && now.plusMinutes(1).isAfter(mineWindow)) if (mine.getOwningGuild().getMineTime() ==
if (!mine.getIsActive()) { LocalDateTime.now().getHour()) {
mine.handleStartMineWindow(); mine.handleStartMineWindow();
Mine.setLastChange(System.currentTimeMillis()); Mine.setLastChange(System.currentTimeMillis());
continue;
} }
else if (mine.handleEndMineWindow())
// Close all other mines
if (mine.handleEndMineWindow())
Mine.setLastChange(System.currentTimeMillis()); Mine.setLastChange(System.currentTimeMillis());
} catch (Exception e) { } catch (Exception e) {
Logger.error ("mineID: " + mine.getObjectUUID(), e.toString()); Logger.error ("mineID: " + mine.getObjectUUID(), e.toString());
} }

Loading…
Cancel
Save