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