forked from MagicBane/Server
Initial refactor: deleted all old code and replaced with something sensible. Driven from the guild's mine hour instead of calculating dates.
This commit is contained in:
@@ -201,11 +201,6 @@ public class InfoCmd extends AbstractDevCmd {
|
||||
output+= newline;
|
||||
output+= "Production type: " +mine.getProduction().name();
|
||||
|
||||
output+= newline;
|
||||
output+= "Open Date: "+ ( mine.openDate).toString();
|
||||
|
||||
output+= newline;
|
||||
output+= "Open Date: "+ (mine.openDate).toString();
|
||||
}
|
||||
}
|
||||
output += newline;
|
||||
|
||||
@@ -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.";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -151,7 +151,6 @@ public enum DevCmdManager {
|
||||
DevCmdManager.registerDevCmd(new RegionCmd());
|
||||
DevCmdManager.registerDevCmd(new SetMaintCmd());
|
||||
DevCmdManager.registerDevCmd(new ApplyBonusCmd());
|
||||
DevCmdManager.registerDevCmd(new setOpenDateCmd());
|
||||
DevCmdManager.registerDevCmd(new AuditFailedItemsCmd());
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,6 @@ public class Mine extends AbstractGameObject {
|
||||
private int buildingID;
|
||||
private Zone parentZone;
|
||||
private MineProduction mineType;
|
||||
public LocalDateTime openDate;
|
||||
|
||||
public boolean dirtyMine = false;
|
||||
//flags 1: never been claimed (make active).
|
||||
@@ -139,12 +138,6 @@ public class Mine extends AbstractGameObject {
|
||||
this.lastClaimerID = 0;
|
||||
this.lastClaimerSessionID = null;
|
||||
|
||||
|
||||
Timestamp mineOpenDateTime = rs.getTimestamp("mine_openDate");
|
||||
|
||||
if (mineOpenDateTime != null)
|
||||
this.openDate = mineOpenDateTime.toLocalDateTime();
|
||||
|
||||
}
|
||||
|
||||
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!");
|
||||
}
|
||||
|
||||
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() {
|
||||
|
||||
try{
|
||||
@@ -207,7 +176,6 @@ try{
|
||||
for (Mine mine : serverMines) {
|
||||
Mine.mineMap.put(mine, mine.buildingID);
|
||||
Mine.towerMap.put(mine.buildingID, mine);
|
||||
mine.initializeMineTime();
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
@@ -218,48 +186,6 @@ try{
|
||||
/*
|
||||
* 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){
|
||||
if (!this.validForMine(resource))
|
||||
@@ -354,11 +280,27 @@ try{
|
||||
writer.putInt(mine.getModifiedProductionAmount()); //TODO calculate range penalty here
|
||||
writer.putInt(3600); //window in seconds
|
||||
|
||||
LocalDateTime mw = mine.openDate;
|
||||
// Errant mines are currently open. Set time to now.
|
||||
|
||||
writer.putLocalDateTime(mw);
|
||||
mw = mw.plusHours(1);
|
||||
writer.putLocalDateTime(mw);
|
||||
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) {
|
||||
|
||||
int guildWOO = mineOwnerGuild.getMineTime();
|
||||
LocalDateTime guildMineTime = mineTime.withHour(guildWOO);
|
||||
|
||||
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.putFloat(mine.latitude);
|
||||
@@ -570,18 +512,13 @@ try{
|
||||
if (this.dirtyMine && this.lastClaimerID == 0 && (this.owningGuild == null || this.owningGuild.isErrant()))
|
||||
return false;
|
||||
this.setActive(false);
|
||||
setNextMineWindow();
|
||||
return true;
|
||||
}
|
||||
|
||||
PlayerCharacter claimer = PlayerCharacter.getFromCache(this.lastClaimerID);
|
||||
|
||||
if (!validClaimer(claimer)){
|
||||
LocalDateTime resetTime = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
|
||||
this.openDate = resetTime;
|
||||
if (!validClaimer(claimer))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// //verify the player hasn't logged out since claim
|
||||
|
||||
@@ -590,12 +527,8 @@ try{
|
||||
// if (!SessionManager.getSession(claimer).getSessionID().equals(this.lastClaimerSessionID))
|
||||
// return false;
|
||||
|
||||
if (this.owningGuild == null || this.owningGuild.isErrant() || this.owningGuild.getNation().isErrant()){
|
||||
LocalDateTime resetTime = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
|
||||
this.openDate = resetTime;
|
||||
if (this.owningGuild == null || this.owningGuild.isErrant() || this.owningGuild.getNation().isErrant())
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Update ownership to map
|
||||
|
||||
@@ -605,7 +538,6 @@ try{
|
||||
this.nationName = nation.getName();
|
||||
this.nationTag = nation.getGuildTag();
|
||||
|
||||
setNextMineWindow();
|
||||
setLastChange(System.currentTimeMillis());
|
||||
|
||||
if (mineBuilding.getRank() < 1){
|
||||
|
||||
@@ -25,7 +25,6 @@ import engine.gameManager.*;
|
||||
import engine.job.JobContainer;
|
||||
import engine.job.JobScheduler;
|
||||
import engine.jobs.LogoutCharacterJob;
|
||||
import engine.jobs.MineActiveJob;
|
||||
import engine.loot.LootManager;
|
||||
import engine.net.Dispatch;
|
||||
import engine.net.DispatchMessage;
|
||||
@@ -436,11 +435,6 @@ public class WorldServer {
|
||||
if (ZoneManager.getHotZone() != null)
|
||||
WorldServer.setLastHZChange(System.currentTimeMillis());
|
||||
|
||||
//Start Mines.
|
||||
|
||||
MineActiveJob maj = new MineActiveJob();
|
||||
maj.run();
|
||||
|
||||
Logger.info("Starting Mobile AI FSM");
|
||||
MobileFSMManager.getInstance();
|
||||
|
||||
|
||||
@@ -56,28 +56,31 @@ public class HourlyJobThread implements Runnable {
|
||||
try {
|
||||
|
||||
ArrayList<Mine> mines = Mine.getMines();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
for (Mine mine : mines) {
|
||||
try {
|
||||
|
||||
// Open Errant Mines
|
||||
|
||||
if (mine.getOwningGuild() == null) {
|
||||
mine.handleStartMineWindow();
|
||||
Mine.setLastChange(System.currentTimeMillis());
|
||||
continue;
|
||||
}
|
||||
|
||||
//handle claimed mines
|
||||
LocalDateTime mineWindow = mine.openDate.withMinute(0).withSecond(0).withNano(0);
|
||||
// Open Mines with a current guild hour
|
||||
|
||||
if (mineWindow != null && now.plusMinutes(1).isAfter(mineWindow))
|
||||
if (!mine.getIsActive()) {
|
||||
mine.handleStartMineWindow();
|
||||
if (mine.getOwningGuild().getMineTime() ==
|
||||
LocalDateTime.now().getHour()) {
|
||||
mine.handleStartMineWindow();
|
||||
Mine.setLastChange(System.currentTimeMillis());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Close all other mines
|
||||
if (mine.handleEndMineWindow())
|
||||
Mine.setLastChange(System.currentTimeMillis());
|
||||
|
||||
}
|
||||
else if (mine.handleEndMineWindow())
|
||||
Mine.setLastChange(System.currentTimeMillis());
|
||||
} catch (Exception e) {
|
||||
Logger.error ("mineID: " + mine.getObjectUUID(), e.toString());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user