Browse Source

early exits for attack message handler

feature-workorder
FatBoy-DOTC 1 year ago
parent
commit
47fe764cb0
  1. 29
      src/engine/net/client/handlers/AttackCmdMsgHandler.java

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

@ -9,6 +9,7 @@ import engine.net.client.msg.AttackCmdMsg;
import engine.net.client.msg.ClientNetMsg; 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.Mob; import engine.objects.Mob;
import engine.objects.PlayerCharacter; import engine.objects.PlayerCharacter;
import org.pmw.tinylog.Logger; import org.pmw.tinylog.Logger;
@ -39,7 +40,6 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
msg = (AttackCmdMsg) baseMsg; msg = (AttackCmdMsg) baseMsg;
int targetType; int targetType;
AbstractWorldObject target;
if (TargetedActionMsg.un2cnt == 60 || TargetedActionMsg.un2cnt == 70) if (TargetedActionMsg.un2cnt == 60 || TargetedActionMsg.un2cnt == 70)
return true; return true;
@ -54,25 +54,20 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler {
return true; return true;
} }
targetType = msg.getTargetType(); AbstractWorldObject target = playerCharacter.combatTarget;
if(target == null)
return true; // cannot attack a null target
if (targetType == Enum.GameObjectType.PlayerCharacter.ordinal()) { switch(target.getObjectType()){
target = PlayerCharacter.getFromCache(msg.getTargetID()); case NPC:
} else if (targetType == Enum.GameObjectType.Building.ordinal()) { playerCharacter.setCombatTarget(null);
target = BuildingManager.getBuildingFromCache(msg.getTargetID()); return true; //cannot attack NPCs
} else if (targetType == Enum.GameObjectType.Mob.ordinal()) { case Building:
target = Mob.getFromCache(msg.getTargetID()); Building targetBuilding = (Building) target;
} else { if(!targetBuilding.isVulnerable() || targetBuilding.getRank() < 0)
playerCharacter.setCombatTarget(null); playerCharacter.setCombatTarget(null);
return true; //not valid type to attack
}
// quit of the combat target is already the current combat target
// or there is no combat target
if (target == null)
return true; return true;
; }
//set sources target //set sources target

Loading…
Cancel
Save