@ -1,11 +1,7 @@
@@ -1,11 +1,7 @@
package engine.net.client.handlers ;
import engine.Enum ;
import engine.Enum.BuildingGroup ;
import engine.Enum.DispatchChannel ;
import engine.Enum.ItemType ;
import engine.InterestManagement.RealmMap ;
import engine.InterestManagement.WorldGrid ;
import engine.exception.MsgSendException ;
import engine.gameManager.* ;
import engine.math.Bounds ;
@ -16,7 +12,6 @@ import engine.net.client.ClientConnection;
@@ -16,7 +12,6 @@ import engine.net.client.ClientConnection;
import engine.net.client.msg.* ;
import engine.objects.* ;
import engine.powers.PowersBase ;
import org.pmw.tinylog.Logger ;
import java.util.ArrayList ;
import java.util.concurrent.locks.ReentrantReadWriteLock ;
@ -35,233 +30,6 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
@@ -35,233 +30,6 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
public ObjectActionMsgHandler ( ) {
super ( ObjectActionMsg . class ) ;
}
private static boolean claimRealm ( PlayerCharacter player , int charterUUID ) {
Guild guild ;
Realm realm ;
City city ;
Building tol ;
float hPMod ;
Warehouse warehouse ;
boolean hasResources = true ;
int resourceValue ;
if ( GuildStatusController . isGuildLeader ( player . getGuildStatus ( ) ) = = false ) {
ErrorPopupMsg . sendErrorPopup ( player , 176 ) ; // Only guild leaders can claim a territory
return false ;
}
guild = player . getGuild ( ) ;
city = guild . getOwnedCity ( ) ;
if ( city = = null ) {
ErrorPopupMsg . sendErrorPopup ( player , 179 ) ; // Only landed guilds may claim a territory
return false ;
}
if ( city . isLocationOnCityGrid ( player . getLoc ( ) ) = = false ) {
ErrorPopupMsg . sendErrorPopup ( player , 186 ) ; // Your tree is not inside a territory!
return false ;
}
tol = city . getTOL ( ) ;
if ( tol . getRank ( ) ! = 7 ) {
ErrorPopupMsg . sendErrorPopup ( player , 181 ) ; // Your tree must be rank 7 before claiming a territory
return false ;
}
realm = RealmMap . getRealmForCity ( city ) ;
if ( realm . getCanBeClaimed ( ) = = false ) {
ErrorPopupMsg . sendErrorPopup ( player , 180 ) ; // This territory cannot be ruled by anyone
return false ;
}
if ( realm . isRuled ( ) = = true ) {
ErrorPopupMsg . sendErrorPopup ( player , 178 ) ; // This territory is already claimed
return false ;
}
if ( ! Realm . HasAllBlessings ( player ) ) {
ErrorPopupMsg . sendErrorPopup ( player , 185 ) ; // You must seek the blessing of the three sages before you can rule
return false ;
}
// Must have the required resources in warehouse to claim realm
warehouse = city . getWarehouse ( ) ;
if ( warehouse = = null ) {
ErrorPopupMsg . sendErrorPopup ( player , 188 ) ; // You must have a warehouse to become a capital
return false ;
}
resourceValue = warehouse . resources . get ( ItemBase . getItemBase ( 7 ) ) ;
if ( resourceValue < 5000000 )
hasResources = false ;
resourceValue = warehouse . resources . get ( ItemBase . getItemBase ( 1580000 ) ) ;
if ( resourceValue < 8000 )
hasResources = false ;
resourceValue = warehouse . resources . get ( ItemBase . getItemBase ( 1580004 ) ) ;
if ( resourceValue < 8000 )
hasResources = false ;
resourceValue = warehouse . resources . get ( ItemBase . getItemBase ( 1580017 ) ) ;
if ( resourceValue < 15 )
hasResources = false ;
resourceValue = warehouse . resources . get ( ItemBase . getItemBase ( 1580018 ) ) ;
if ( resourceValue < 15 )
hasResources = false ;
if ( hasResources = = false ) {
ErrorPopupMsg . sendErrorPopup ( player , 184 ) ; // Insufficient gold or resources to upgrade to capital
return false ;
}
// Remove resources from warehouse before claiming realm
resourceValue = warehouse . resources . get ( ItemBase . getItemBase ( 7 ) ) ;
if ( DbManager . WarehouseQueries . updateGold ( warehouse , resourceValue - 5000000 ) = = true ) {
warehouse . resources . put ( ItemBase . getItemBase ( 7 ) , resourceValue - 5000000 ) ;
Warehouse . AddTransactionToWarehouse ( warehouse , engine . Enum . GameObjectType . Building , tol . getObjectUUID ( ) , Enum . TransactionType . WITHDRAWL , Resource . GOLD , 5000000 ) ;
} else {
Logger . error ( "gold update failed for warehouse of UUID:" + warehouse . getObjectUUID ( ) ) ;
return false ;
}
resourceValue = warehouse . resources . get ( ItemBase . getItemBase ( 1580000 ) ) ;
if ( DbManager . WarehouseQueries . updateStone ( warehouse , resourceValue - 8000 ) = = true ) {
warehouse . resources . put ( ItemBase . getItemBase ( 1580000 ) , resourceValue - 8000 ) ;
Warehouse . AddTransactionToWarehouse ( warehouse , engine . Enum . GameObjectType . Building , tol . getObjectUUID ( ) , Enum . TransactionType . WITHDRAWL , Resource . STONE , 8000 ) ;
} else {
Logger . error ( "stone update failed for warehouse of UUID:" + warehouse . getObjectUUID ( ) ) ;
return false ;
}
resourceValue = warehouse . resources . get ( ItemBase . getItemBase ( 1580004 ) ) ;
if ( DbManager . WarehouseQueries . updateLumber ( warehouse , resourceValue - 8000 ) = = true ) {
warehouse . resources . put ( ItemBase . getItemBase ( 1580004 ) , resourceValue - 8000 ) ;
Warehouse . AddTransactionToWarehouse ( warehouse , engine . Enum . GameObjectType . Building , tol . getObjectUUID ( ) , Enum . TransactionType . WITHDRAWL , Resource . LUMBER , 8000 ) ;
} else {
Logger . error ( "lumber update failed for warehouse of UUID:" + warehouse . getObjectUUID ( ) ) ;
return false ;
}
resourceValue = warehouse . resources . get ( ItemBase . getItemBase ( 1580017 ) ) ;
if ( DbManager . WarehouseQueries . updateGalvor ( warehouse , resourceValue - 15 ) = = true ) {
warehouse . resources . put ( ItemBase . getItemBase ( 1580017 ) , resourceValue - 15 ) ;
Warehouse . AddTransactionToWarehouse ( warehouse , engine . Enum . GameObjectType . Building , tol . getObjectUUID ( ) , Enum . TransactionType . WITHDRAWL , Resource . GALVOR , 15 ) ;
} else {
Logger . error ( "galvor update failed for warehouse of UUID:" + warehouse . getObjectUUID ( ) ) ;
return false ;
}
resourceValue = warehouse . resources . get ( ItemBase . getItemBase ( 1580018 ) ) ;
if ( DbManager . WarehouseQueries . updateWormwood ( warehouse , resourceValue - 15 ) = = true ) {
warehouse . resources . put ( ItemBase . getItemBase ( 1580018 ) , resourceValue - 15 ) ;
Warehouse . AddTransactionToWarehouse ( warehouse , engine . Enum . GameObjectType . Building , tol . getObjectUUID ( ) , Enum . TransactionType . WITHDRAWL , Resource . WORMWOOD , 15 ) ;
} else {
Logger . error ( "wormwood update failed for warehouse of UUID:" + warehouse . getObjectUUID ( ) ) ;
return false ;
}
realm . claimRealmForCity ( city , charterUUID ) ;
BuildingManager . setRank ( tol , 8 ) ;
WorldGrid . updateObject ( tol ) ;
for ( Building building : city . getParent ( ) . zoneBuildingSet ) {
if ( building . getBlueprintUUID ( ) ! = 0 ) {
// TOL Health set through regular linear equation
if ( building . getBlueprint ( ) . getBuildingGroup ( ) = = BuildingGroup . TOL ) {
continue ;
}
hPMod = ( building . getMaxHitPoints ( ) * Realm . getRealmHealthMod ( city ) ) ;
building . setMaxHitPoints ( building . getMaxHitPoints ( ) + hPMod ) ;
}
}
if ( ! guild . getNation ( ) . equals ( guild ) ) {
guild . getNation ( ) . setRealmsOwned ( guild . getNation ( ) . getRealmsOwned ( ) + 1 ) ;
GuildManager . updateAllGuildTags ( guild . getNation ( ) ) ;
}
guild . setRealmsOwned ( guild . getRealmsOwned ( ) + 1 ) ;
GuildManager . updateAllGuildTags ( guild ) ;
removeAllBlessings ( player ) ;
return true ;
}
private static void removeAllBlessings ( PlayerCharacter player ) {
PowersBase [ ] powers = new PowersBase [ 3 ] ;
powers [ 0 ] = PowersManager . getPowerByIDString ( "BLS-POWER" ) ;
powers [ 1 ] = PowersManager . getPowerByIDString ( "BLS-FORTUNE" ) ;
powers [ 2 ] = PowersManager . getPowerByIDString ( "BLS-WISDOM" ) ;
for ( PowersBase power : powers ) {
PowersManager . removeEffect ( player , power . getActions ( ) . get ( 0 ) , true , false ) ;
}
}
private static void removeRune ( PlayerCharacter pc , ClientConnection origin , int runeID ) {
if ( pc = = null | | origin = = null ) {
return ;
}
//remove only if rune is discipline
if ( runeID < 3001 | | runeID > 3048 ) {
return ;
}
//see if pc has rune
ArrayList < CharacterRune > runes = pc . getRunes ( ) ;
if ( runes = = null )
return ;
CharacterRune found = pc . getRune ( runeID ) ;
if ( found = = null )
return ;
//TODO see if player needs to refine skills or powers first
//attempt remove rune from player
if ( ! CharacterRune . removeRune ( pc , runeID ) )
return ;
//update client with removed rune.
ApplyRuneMsg arm = new ApplyRuneMsg ( pc . getObjectType ( ) . ordinal ( ) , pc . getObjectUUID ( ) , runeID ) ;
Dispatch dispatch = Dispatch . borrow ( pc , arm ) ;
DispatchMessage . dispatchMsgDispatch ( dispatch , DispatchChannel . SECONDARY ) ;
}
// Handle activation of tears of seadron: Removes rune from player.
@Override
protected boolean _handleNetMsg ( ClientNetMsg baseMsg , ClientConnection origin ) throws MsgSendException {
@ -389,7 +157,7 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
@@ -389,7 +157,7 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
charterType = - 600065291 ;
break ;
}
if ( claimRealm ( player , charterType ) = = true ) {
if ( Realm . claimRealm ( player , charterType ) = = true ) {
itemMan . consume ( item ) ;
}
break ;
@ -485,7 +253,7 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
@@ -485,7 +253,7 @@ public class ObjectActionMsgHandler extends AbstractClientMsgHandler {
break ;
} else if ( uuid = = 910010 ) { //tears of saedron
if ( comps . size ( ) > 1 ) {
removeRune ( player , origin , comps . get ( 1 ) . intValue ( ) ) ;
AbstractCharacter . removeRune ( player , origin , comps . get ( 1 ) . intValue ( ) ) ;
}
break ;
} else if ( ( byte ) item . chargesRemaining > 0 ) {