Browse Source

early exits for attack message handler

feature-workorder
FatBoy-DOTC 1 year ago
parent
commit
18e1f4bd28
  1. 33
      src/engine/net/client/handlers/AttackCmdMsgHandler.java

33
src/engine/net/client/handlers/AttackCmdMsgHandler.java

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

Loading…
Cancel
Save