forked from MagicBane/Server
Cleanup of logic.
This commit is contained in:
@@ -7,9 +7,6 @@
|
||||
// www.magicbane.com
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
@@ -29,19 +26,18 @@ import engine.gameManager.*;
|
||||
import engine.net.ByteBufferWriter;
|
||||
import engine.net.client.msg.ErrorPopupMsg;
|
||||
import engine.server.MBServerStatics;
|
||||
import engine.server.world.WorldServer;
|
||||
import engine.session.SessionID;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
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 {
|
||||
@@ -64,9 +60,6 @@ public class Mine extends AbstractGameObject {
|
||||
//flags 1: never been claimed (make active).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Not persisted to DB
|
||||
private String guildName;
|
||||
private GuildTag guildTag;
|
||||
@@ -101,7 +94,7 @@ public class Mine extends AbstractGameObject {
|
||||
else
|
||||
this.zoneName = this.parentZone.getName();
|
||||
} else {
|
||||
Logger.error( "Missing parentZone of ID " + parent);
|
||||
Logger.error("Missing parentZone of ID " + parent);
|
||||
this.latitude = -1000;
|
||||
this.longitude = 1000;
|
||||
this.altitude = 0;
|
||||
@@ -121,7 +114,7 @@ public class Mine extends AbstractGameObject {
|
||||
this.owningGuild = Guild.getErrantGuild();
|
||||
}
|
||||
|
||||
if(!nation.isErrant()) {
|
||||
if (!nation.isErrant()) {
|
||||
this.nationName = nation.getName();
|
||||
this.nationTag = nation.getGuildTag();
|
||||
} else {
|
||||
@@ -136,7 +129,7 @@ public class Mine extends AbstractGameObject {
|
||||
|
||||
}
|
||||
|
||||
public static void SendMineAttackMessage(Building mine){
|
||||
public static void SendMineAttackMessage(Building mine) {
|
||||
|
||||
if (mine.getBlueprint() == null)
|
||||
return;
|
||||
@@ -161,7 +154,7 @@ public class Mine extends AbstractGameObject {
|
||||
|
||||
public static void loadAllMines() {
|
||||
|
||||
try{
|
||||
try {
|
||||
|
||||
//Load mine resources
|
||||
MineProduction.addResources();
|
||||
@@ -174,20 +167,20 @@ try{
|
||||
Mine.towerMap.put(mine.buildingID, mine);
|
||||
}
|
||||
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Getters
|
||||
*/
|
||||
|
||||
public boolean changeProductionType(Resource resource){
|
||||
public boolean changeProductionType(Resource resource) {
|
||||
if (!this.validForMine(resource))
|
||||
return false;
|
||||
//update resource in database;
|
||||
if(!MineQueries.CHANGE_RESOURCE(this, resource))
|
||||
if (!MineQueries.CHANGE_RESOURCE(this, resource))
|
||||
return false;
|
||||
|
||||
this.production = resource;
|
||||
@@ -264,7 +257,7 @@ try{
|
||||
* Serialization
|
||||
*/
|
||||
|
||||
public static void serializeForClientMsg(Mine mine,ByteBufferWriter writer) {
|
||||
public static void serializeForClientMsg(Mine mine, ByteBufferWriter writer) {
|
||||
writer.putInt(mine.getObjectType().ordinal());
|
||||
writer.putInt(mine.getObjectUUID());
|
||||
writer.putInt(mine.getObjectUUID()); //actually a hash of mine
|
||||
@@ -305,9 +298,9 @@ try{
|
||||
writer.putInt(mine.isExpansion() ? mine.mineType.xpacHash : mine.mineType.hash);
|
||||
|
||||
writer.putString(mine.guildName);
|
||||
GuildTag._serializeForDisplay(mine.guildTag,writer);
|
||||
GuildTag._serializeForDisplay(mine.guildTag, writer);
|
||||
writer.putString(mine.nationName);
|
||||
GuildTag._serializeForDisplay(mine.nationTag,writer);
|
||||
GuildTag._serializeForDisplay(mine.nationTag, writer);
|
||||
}
|
||||
|
||||
public void serializeForMineProduction(ByteBufferWriter writer) {
|
||||
@@ -344,7 +337,7 @@ try{
|
||||
/*
|
||||
* Database
|
||||
*/
|
||||
public static Mine getMine(int UID){
|
||||
public static Mine getMine(int UID) {
|
||||
return MineQueries.GET_MINE(UID);
|
||||
|
||||
}
|
||||
@@ -419,7 +412,7 @@ try{
|
||||
|
||||
mineCnt += Mine.getMinesForGuild(playerGuild.getObjectUUID()).size();
|
||||
|
||||
for (Guild guild: playerGuild.getSubGuildList())
|
||||
for (Guild guild : playerGuild.getSubGuildList())
|
||||
mineCnt += Mine.getMinesForGuild(guild.getObjectUUID()).size();
|
||||
|
||||
if (mineCnt > rank)
|
||||
@@ -449,8 +442,8 @@ try{
|
||||
|
||||
Building mineBuilding = BuildingManager.getBuildingFromCache(this.buildingID);
|
||||
|
||||
if (mineBuilding == null){
|
||||
Logger.debug( "Null mine building " + this.getObjectUUID() +". Unable to Load Building with UID " +this.buildingID);
|
||||
if (mineBuilding == null) {
|
||||
Logger.debug("Null mine building " + this.getObjectUUID() + ". Unable to Load Building with UID " + this.buildingID);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -463,7 +456,7 @@ try{
|
||||
BuildingManager.cleanupHirelings(building);
|
||||
}
|
||||
|
||||
public boolean handleEndMineWindow(){
|
||||
public boolean handleEndMineWindow() {
|
||||
|
||||
// No need to end the window of a mine which never opened.
|
||||
|
||||
@@ -472,8 +465,8 @@ try{
|
||||
|
||||
Building mineBuilding = BuildingManager.getBuildingFromCache(this.buildingID);
|
||||
|
||||
if (mineBuilding == null){
|
||||
Logger.debug( "Null mine building for Mine " + this.getObjectUUID() +" Building " +this.buildingID);
|
||||
if (mineBuilding == null) {
|
||||
Logger.debug("Null mine building for Mine " + this.getObjectUUID() + " Building " + this.buildingID);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -481,11 +474,19 @@ try{
|
||||
//never knocked down, let's just move on.
|
||||
//hasn't been claimed since server start.
|
||||
this.setActive(false);
|
||||
this.lastClaimerSessionID = null;
|
||||
this.lastClaimer = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!validClaimer(this.lastClaimer))
|
||||
// This mine does not have a valid claimer
|
||||
// we will therefore set it to errant
|
||||
|
||||
if (!validClaimer(this.lastClaimer)) {
|
||||
this.lastClaimerSessionID = null;
|
||||
this.lastClaimer = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.owningGuild == null || this.owningGuild.isErrant() || this.owningGuild.getNation().isErrant())
|
||||
return false;
|
||||
@@ -500,14 +501,6 @@ try{
|
||||
|
||||
setLastChange(System.currentTimeMillis());
|
||||
|
||||
if (mineBuilding.getRank() < 1){
|
||||
|
||||
if (this.lastClaimer == null){
|
||||
this.lastClaimerSessionID = null;
|
||||
updateGuildOwner(null);
|
||||
return false;
|
||||
}
|
||||
|
||||
mineBuilding.rebuildMine();
|
||||
WorldGrid.updateObject(mineBuilding);
|
||||
ChatManager.chatSystemChannel(this.lastClaimer.getName() + " has claimed the mine in " + this.parentZone.getParent().getName() + " for " + this.owningGuild.getName() + ". The mine is no longer active.");
|
||||
@@ -517,10 +510,7 @@ try{
|
||||
MineRecord mineRecord = MineRecord.borrow(this, this.lastClaimer, Enum.RecordEventType.CAPTURE);
|
||||
DataWarehouse.pushToWarehouse(mineRecord);
|
||||
|
||||
}else{
|
||||
mineBuilding.setRank(mineBuilding.getRank());
|
||||
}
|
||||
|
||||
this.setActive(false);
|
||||
return true;
|
||||
}
|
||||
@@ -559,7 +549,7 @@ try{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean depositMineResources(){
|
||||
public boolean depositMineResources() {
|
||||
|
||||
if (this.owningGuild == null)
|
||||
return false;
|
||||
@@ -571,18 +561,18 @@ try{
|
||||
return false;
|
||||
|
||||
ItemBase resourceIB = ItemBase.getItemBase(this.production.UUID);
|
||||
return this.owningGuild.getOwnedCity().getWarehouse().depositFromMine(this,resourceIB, this.getModifiedProductionAmount());
|
||||
return this.owningGuild.getOwnedCity().getWarehouse().depositFromMine(this, resourceIB, this.getModifiedProductionAmount());
|
||||
}
|
||||
|
||||
public boolean updateGuildOwner(PlayerCharacter pc){
|
||||
public boolean updateGuildOwner(PlayerCharacter pc) {
|
||||
|
||||
Building mineBuilding = BuildingManager.getBuildingFromCache(this.buildingID);
|
||||
|
||||
//should never return null, but let's check just in case.
|
||||
|
||||
if (mineBuilding == null){
|
||||
if (mineBuilding == null) {
|
||||
ChatManager.chatSystemError(pc, "Unable to find mine tower.");
|
||||
Logger.debug("Failed to Update Mine with UID " + this.getObjectUUID() +". Unable to Load Building with UID " +this.buildingID );
|
||||
Logger.debug("Failed to Update Mine with UID " + this.getObjectUUID() + ". Unable to Load Building with UID " + this.buildingID);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -638,11 +628,11 @@ try{
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isExpansion(){
|
||||
public boolean isExpansion() {
|
||||
return (this.flags & 2) != 0;
|
||||
}
|
||||
|
||||
public int getModifiedProductionAmount(){
|
||||
public int getModifiedProductionAmount() {
|
||||
//TODO Calculate Distance modifications.
|
||||
|
||||
//calculate base values.
|
||||
@@ -655,7 +645,7 @@ try{
|
||||
Building mineBuilding = BuildingManager.getBuilding(this.buildingID);
|
||||
if (mineBuilding == null)
|
||||
return this.production.baseProduction;
|
||||
for (AbstractCharacter harvester:mineBuilding.getHirelings().keySet()){
|
||||
for (AbstractCharacter harvester : mineBuilding.getHirelings().keySet()) {
|
||||
totalModded += baseModValue;
|
||||
totalModded += rankModValue * harvester.getRank();
|
||||
}
|
||||
@@ -665,12 +655,12 @@ try{
|
||||
if (this.isExpansion())
|
||||
return (int) totalModded;
|
||||
|
||||
if (this.owningGuild != null){
|
||||
if(this.owningGuild.getOwnedCity() != null){
|
||||
if (this.owningGuild != null) {
|
||||
if (this.owningGuild.getOwnedCity() != null) {
|
||||
float distanceSquared = this.owningGuild.getOwnedCity().getLoc().distanceSquared2D(mineBuilding.getLoc());
|
||||
|
||||
if (distanceSquared > sqr(10000 * 3))
|
||||
totalModded *=.25f;
|
||||
totalModded *= .25f;
|
||||
else if (distanceSquared > sqr(10000 * 2))
|
||||
totalModded *= .50f;
|
||||
else if (distanceSquared > sqr(10000))
|
||||
|
||||
Reference in New Issue
Block a user