From 47fe764cb0f1c8a7bf31900e85a174f13750cb47 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 10 Sep 2023 12:58:24 -0500 Subject: [PATCH] early exits for attack message handler --- .../client/handlers/AttackCmdMsgHandler.java | 33 ++++++++----------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/src/engine/net/client/handlers/AttackCmdMsgHandler.java b/src/engine/net/client/handlers/AttackCmdMsgHandler.java index 774358f6..a08bec73 100644 --- a/src/engine/net/client/handlers/AttackCmdMsgHandler.java +++ b/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.TargetedActionMsg; import engine.objects.AbstractWorldObject; +import engine.objects.Building; import engine.objects.Mob; import engine.objects.PlayerCharacter; import org.pmw.tinylog.Logger; @@ -39,7 +40,6 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler { msg = (AttackCmdMsg) baseMsg; int targetType; - AbstractWorldObject target; if (TargetedActionMsg.un2cnt == 60 || TargetedActionMsg.un2cnt == 70) return true; @@ -54,26 +54,21 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler { return true; } - targetType = msg.getTargetType(); - - if (targetType == Enum.GameObjectType.PlayerCharacter.ordinal()) { - target = PlayerCharacter.getFromCache(msg.getTargetID()); - } else if (targetType == Enum.GameObjectType.Building.ordinal()) { - target = BuildingManager.getBuildingFromCache(msg.getTargetID()); - } else if (targetType == Enum.GameObjectType.Mob.ordinal()) { - target = Mob.getFromCache(msg.getTargetID()); - } else { - playerCharacter.setCombatTarget(null); - return true; //not valid type to attack + 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: + Building targetBuilding = (Building) target; + if(!targetBuilding.isVulnerable() || targetBuilding.getRank() < 0) + playerCharacter.setCombatTarget(null); + return true; } - // quit of the combat target is already the current combat target - // or there is no combat target - - if (target == null) - return true; - ; - //set sources target playerCharacter.setCombatTarget(target);