forked from MagicBane/Server
lastChanged is unused as cannot omit mines from map.
This commit is contained in:
@@ -39,14 +39,12 @@ public class MineActiveCmd extends AbstractDevCmd {
|
||||
return;
|
||||
|
||||
String trigger = args[0];
|
||||
switch (trigger){
|
||||
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);
|
||||
|
||||
@@ -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 {
|
||||
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 {
|
||||
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
|
||||
|
||||
@@ -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 {
|
||||
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
|
||||
|
||||
@@ -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
|
||||
//update resource
|
||||
|
||||
mine.changeProductionType(resource);
|
||||
Mine.setLastChange(System.currentTimeMillis());
|
||||
Dispatch dispatch = Dispatch.borrow(playerCharacter, changeProductionMsg);
|
||||
DispatchMessage.dispatchMsgDispatch(dispatch, DispatchChannel.SECONDARY);
|
||||
return true;
|
||||
|
||||
+128
-138
@@ -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;
|
||||
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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendMineAttackMessage(Building mine) {
|
||||
|
||||
if (mine.getBlueprint() == null)
|
||||
@@ -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 {
|
||||
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 {
|
||||
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 {
|
||||
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
|
||||
@@ -433,7 +318,7 @@ public class Mine extends AbstractGameObject {
|
||||
if (treeRank < 1)
|
||||
return false;
|
||||
|
||||
if (guildUnderMineLimit(playerGuild.getNation(), treeRank) == false){
|
||||
if (guildUnderMineLimit(playerGuild.getNation(), treeRank) == false) {
|
||||
ErrorPopupMsg.sendErrorMsg(playerCharacter, "Your nation cannot support another mine.");
|
||||
return false;
|
||||
}
|
||||
@@ -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 {
|
||||
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 {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean depositMineResources() {
|
||||
|
||||
if (this.owningGuild.isEmptyGuild())
|
||||
|
||||
@@ -33,6 +33,156 @@ public class HourlyJobThread implements Runnable {
|
||||
|
||||
}
|
||||
|
||||
public static void decayShrines() {
|
||||
ArrayList<Shrine> shrineList = new ArrayList<>();
|
||||
|
||||
for (Shrine shrine : Shrine.shrinesByBuildingUUID.values()) {
|
||||
try {
|
||||
Building shrineBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, shrine.getBuildingID());
|
||||
|
||||
if (shrineBuilding == null)
|
||||
continue;
|
||||
|
||||
|
||||
if (shrineBuilding.getOwner().equals(shrineBuilding.getCity().getOwner()) == false)
|
||||
shrineBuilding.claim(shrineBuilding.getCity().getOwner());
|
||||
} catch (Exception e) {
|
||||
Logger.info("Shrine " + shrine.getBuildingID() + " Error " + e);
|
||||
}
|
||||
}
|
||||
|
||||
// Grab list of top two shrines of each type
|
||||
|
||||
for (Shrine shrine : Shrine.shrinesByBuildingUUID.values()) {
|
||||
|
||||
if (shrine.getRank() == 0 || shrine.getRank() == 1)
|
||||
shrineList.add(shrine);
|
||||
}
|
||||
|
||||
Logger.info("Decaying " + shrineList.size() + " shrines...");
|
||||
|
||||
// Top 2 shrines decay by 10% a day
|
||||
|
||||
for (Shrine shrine : shrineList) {
|
||||
|
||||
try {
|
||||
shrine.decay();
|
||||
} catch (Exception e) {
|
||||
Logger.info("Shrine " + shrine.getBuildingID() + " Error " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void processMineWindow() {
|
||||
|
||||
try {
|
||||
|
||||
ArrayList<Mine> mines = Mine.getMines();
|
||||
|
||||
for (Mine mine : mines) {
|
||||
if (LocalDateTime.now().getHour() == 1400) {
|
||||
mine.wasClaimed = false;
|
||||
}
|
||||
try {
|
||||
|
||||
// Open Errant Mines
|
||||
|
||||
if (mine.getOwningGuild().isEmptyGuild()) {
|
||||
HourlyJobThread.mineWindowOpen(mine);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Open Mines owned by nations having their WOO
|
||||
// set to the current mine window.
|
||||
|
||||
if (mine.getOwningGuild().getNation().getMineTime() ==
|
||||
LocalDateTime.now().getHour() && mine.wasClaimed == false) {
|
||||
HourlyJobThread.mineWindowOpen(mine);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Close the mine if it reaches this far
|
||||
|
||||
mineWindowClose(mine);
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error("mineID: " + mine.getObjectUUID(), e.toString());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void mineWindowOpen(Mine mine) {
|
||||
|
||||
mine.setActive(true);
|
||||
ChatManager.chatSystemChannel(mine.getZoneName() + "'s Mine is now Active!");
|
||||
Logger.info(mine.getZoneName() + "'s Mine is now Active!");
|
||||
}
|
||||
|
||||
public static boolean mineWindowClose(Mine mine) {
|
||||
|
||||
// No need to end the window of a mine which never opened.
|
||||
|
||||
if (mine.isActive == false)
|
||||
return false;
|
||||
|
||||
Building mineBuilding = BuildingManager.getBuildingFromCache(mine.getBuildingID());
|
||||
|
||||
if (mineBuilding == null) {
|
||||
Logger.debug("Null mine building for Mine " + mine.getObjectUUID() + " Building " + mine.getBuildingID());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Mine building still stands; nothing to do.
|
||||
// We can early exit here.
|
||||
|
||||
if (mineBuilding.getRank() > 0) {
|
||||
mine.setActive(false);
|
||||
mine.lastClaimer = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
// This mine does not have a valid claimer
|
||||
// we will therefore set it to errant
|
||||
// and keep the window open.
|
||||
|
||||
if (!Mine.validateClaimer(mine.lastClaimer)) {
|
||||
mine.lastClaimer = null;
|
||||
mine.updateGuildOwner(null);
|
||||
mine.setActive(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Update ownership to map
|
||||
|
||||
mine.guildName = mine.getOwningGuild().getName();
|
||||
mine.guildTag = mine.getOwningGuild().getGuildTag();
|
||||
Guild nation = mine.getOwningGuild().getNation();
|
||||
mine.nationName = nation.getName();
|
||||
mine.nationTag = nation.getGuildTag();
|
||||
|
||||
mineBuilding.rebuildMine();
|
||||
WorldGrid.updateObject(mineBuilding);
|
||||
|
||||
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mine.lastClaimer.getName() + " has claimed the mine in " + mine.getParentZone().getParent().getName() + " for " + mine.getOwningGuild().getName() + ". The mine is no longer active.");
|
||||
chatMsg.setMessageType(10);
|
||||
chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID());
|
||||
DispatchMessage.dispatchMsgToAll(chatMsg);
|
||||
|
||||
// Warehouse this claim event
|
||||
|
||||
MineRecord mineRecord = MineRecord.borrow(mine, mine.lastClaimer, Enum.RecordEventType.CAPTURE);
|
||||
DataWarehouse.pushToWarehouse(mineRecord);
|
||||
|
||||
mineBuilding.setRank(mineBuilding.getRank());
|
||||
mine.lastClaimer = null;
|
||||
mine.setActive(false);
|
||||
mine.wasClaimed = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
// *** REFACTOR: TRY TRY TRY TRY {{{{{{{{{{{ OMG
|
||||
@@ -136,160 +286,4 @@ public class HourlyJobThread implements Runnable {
|
||||
Logger.info(MessageDispatcher.getNetstatString());
|
||||
Logger.info(PurgeOprhans.recordsDeleted.toString() + "orphaned items deleted");
|
||||
}
|
||||
|
||||
|
||||
public static void decayShrines() {
|
||||
ArrayList<Shrine> shrineList = new ArrayList<>();
|
||||
|
||||
for (Shrine shrine : Shrine.shrinesByBuildingUUID.values()) {
|
||||
try {
|
||||
Building shrineBuilding = (Building) DbManager.getObject(Enum.GameObjectType.Building, shrine.getBuildingID());
|
||||
|
||||
if (shrineBuilding == null)
|
||||
continue;
|
||||
|
||||
|
||||
if (shrineBuilding.getOwner().equals(shrineBuilding.getCity().getOwner()) == false)
|
||||
shrineBuilding.claim(shrineBuilding.getCity().getOwner());
|
||||
} catch (Exception e) {
|
||||
Logger.info("Shrine " + shrine.getBuildingID() + " Error " + e);
|
||||
}
|
||||
}
|
||||
|
||||
// Grab list of top two shrines of each type
|
||||
|
||||
for (Shrine shrine : Shrine.shrinesByBuildingUUID.values()) {
|
||||
|
||||
if (shrine.getRank() == 0 || shrine.getRank() == 1)
|
||||
shrineList.add(shrine);
|
||||
}
|
||||
|
||||
Logger.info("Decaying " + shrineList.size() + " shrines...");
|
||||
|
||||
// Top 2 shrines decay by 10% a day
|
||||
|
||||
for (Shrine shrine : shrineList) {
|
||||
|
||||
try {
|
||||
shrine.decay();
|
||||
} catch (Exception e) {
|
||||
Logger.info("Shrine " + shrine.getBuildingID() + " Error " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void processMineWindow() {
|
||||
|
||||
try {
|
||||
|
||||
ArrayList<Mine> mines = Mine.getMines();
|
||||
|
||||
for (Mine mine : mines) {
|
||||
if (LocalDateTime.now().getHour() == 1400) {
|
||||
mine.wasClaimed = false;
|
||||
}
|
||||
try {
|
||||
|
||||
// Open Errant Mines
|
||||
|
||||
if (mine.getOwningGuild().isEmptyGuild()) {
|
||||
HourlyJobThread.mineWindowOpen(mine);
|
||||
Mine.setLastChange(System.currentTimeMillis());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Open Mines owned by nations having their WOO
|
||||
// set to the current mine window.
|
||||
|
||||
if (mine.getOwningGuild().getNation().getMineTime() ==
|
||||
LocalDateTime.now().getHour() && mine.wasClaimed == false) {
|
||||
HourlyJobThread.mineWindowOpen(mine);
|
||||
Mine.setLastChange(System.currentTimeMillis());
|
||||
continue;
|
||||
}
|
||||
|
||||
// Close all the remaining mines
|
||||
|
||||
if (mineWindowClose(mine))
|
||||
Mine.setLastChange(System.currentTimeMillis());
|
||||
|
||||
} catch (Exception e) {
|
||||
Logger.error("mineID: " + mine.getObjectUUID(), e.toString());
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Logger.error(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void mineWindowOpen(Mine mine) {
|
||||
|
||||
mine.setActive(true);
|
||||
ChatManager.chatSystemChannel(mine.getZoneName() + "'s Mine is now Active!");
|
||||
Logger.info(mine.getZoneName() + "'s Mine is now Active!");
|
||||
}
|
||||
|
||||
public static boolean mineWindowClose(Mine mine) {
|
||||
|
||||
// No need to end the window of a mine which never opened.
|
||||
|
||||
if (mine.isActive == false)
|
||||
return false;
|
||||
|
||||
Building mineBuilding = BuildingManager.getBuildingFromCache(mine.getBuildingID());
|
||||
|
||||
if (mineBuilding == null) {
|
||||
Logger.debug("Null mine building for Mine " + mine.getObjectUUID() + " Building " + mine.getBuildingID());
|
||||
return false;
|
||||
}
|
||||
|
||||
// Mine building still stands; nothing to do.
|
||||
// We can early exit here.
|
||||
|
||||
if (mineBuilding.getRank() > 0) {
|
||||
mine.setActive(false);
|
||||
mine.lastClaimer = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
// This mine does not have a valid claimer
|
||||
// we will therefore set it to errant
|
||||
// and keep the window open.
|
||||
|
||||
if (!Mine.validateClaimer(mine.lastClaimer)) {
|
||||
mine.lastClaimer = null;
|
||||
mine.updateGuildOwner(null);
|
||||
mine.setActive(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
//Update ownership to map
|
||||
|
||||
mine.guildName = mine.getOwningGuild().getName();
|
||||
mine.guildTag = mine.getOwningGuild().getGuildTag();
|
||||
Guild nation = mine.getOwningGuild().getNation();
|
||||
mine.nationName = nation.getName();
|
||||
mine.nationTag = nation.getGuildTag();
|
||||
|
||||
Mine.setLastChange(System.currentTimeMillis());
|
||||
|
||||
mineBuilding.rebuildMine();
|
||||
WorldGrid.updateObject(mineBuilding);
|
||||
|
||||
ChatSystemMsg chatMsg = new ChatSystemMsg(null, mine.lastClaimer.getName() + " has claimed the mine in " + mine.getParentZone().getParent().getName() + " for " + mine.getOwningGuild().getName() + ". The mine is no longer active.");
|
||||
chatMsg.setMessageType(10);
|
||||
chatMsg.setChannel(Enum.ChatChannelType.SYSTEM.getChannelID());
|
||||
DispatchMessage.dispatchMsgToAll(chatMsg);
|
||||
|
||||
// Warehouse this claim event
|
||||
|
||||
MineRecord mineRecord = MineRecord.borrow(mine, mine.lastClaimer, Enum.RecordEventType.CAPTURE);
|
||||
DataWarehouse.pushToWarehouse(mineRecord);
|
||||
|
||||
mineBuilding.setRank(mineBuilding.getRank());
|
||||
mine.lastClaimer = null;
|
||||
mine.setActive(false);
|
||||
mine.wasClaimed = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user