@ -1,6 +1,8 @@
@@ -1,6 +1,8 @@
package engine.net.client.handlers ;
import engine.Enum ;
import engine.exception.MsgSendException ;
import engine.gameManager.BuildingManager ;
import engine.gameManager.CombatManager ;
import engine.net.client.ClientConnection ;
import engine.net.client.msg.AttackCmdMsg ;
@ -8,6 +10,7 @@ import engine.net.client.msg.ClientNetMsg;
@@ -8,6 +10,7 @@ import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.TargetedActionMsg ;
import engine.objects.AbstractWorldObject ;
import engine.objects.Building ;
import engine.objects.Mob ;
import engine.objects.PlayerCharacter ;
import org.pmw.tinylog.Logger ;
@ -42,27 +45,23 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
@@ -42,27 +45,23 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
if ( playerCharacter = = null )
return true ;
//source must match player this account belongs to
AbstractWorldObject target ;
if ( playerCharacter . getObjectUUID ( ) ! = msg . getSourceID ( ) | | playerCharacter . getObjectType ( ) . ordinal ( ) ! = msg . getSourceType ( ) ) {
Logger . error ( "Msg Source ID " + msg . getSourceID ( ) + " Does not Match Player ID " + playerCharacter . getObjectUUID ( ) ) ;
return true ;
}
AbstractWorldObject target = playerCharacter . combatTarget ;
if ( target = = null )
return true ; // cannot attack a null target
switch ( target . getObjectType ( ) ) {
case NPC :
playerCharacter . setCombatTarget ( null ) ;
return true ; //cannot attack NPCs
case Building :
if ( msg . getTargetType ( ) = = Enum . GameObjectType . Mob . ordinal ( ) ) {
target = Mob . getMob ( msg . getTargetID ( ) ) ;
} else if ( msg . getTargetType ( ) = = Enum . GameObjectType . Building . ordinal ( ) ) {
target = BuildingManager . getBuilding ( msg . getTargetID ( ) ) ;
Building targetBuilding = ( Building ) target ;
if ( ! targetBuilding . isVulnerable ( ) | | targetBuilding . getRank ( ) < 0 )
if ( ! targetBuilding . isVulnerable ( ) | | targetBuilding . getRank ( ) < 0 ) {
playerCharacter . setCombatTarget ( null ) ;
return true ;
}
} else if ( msg . getTargetType ( ) = = Enum . GameObjectType . PlayerCharacter . ordinal ( ) ) {
target = PlayerCharacter . getPlayerCharacter ( msg . getTargetID ( ) ) ;
} else {
playerCharacter . setCombatTarget ( null ) ;
return true ; //cannot attack other things
}
//set sources target