From 18e1f4bd289210f791c3a2cf350b05422202e922 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 10 Sep 2023 13:25:08 -0500 Subject: [PATCH] early exits for attack message handler --- .../client/handlers/AttackCmdMsgHandler.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/engine/net/client/handlers/AttackCmdMsgHandler.java b/src/engine/net/client/handlers/AttackCmdMsgHandler.java index f724842d..c4c4952a 100644 --- a/src/engine/net/client/handlers/AttackCmdMsgHandler.java +++ b/src/engine/net/client/handlers/AttackCmdMsgHandler.java @@ -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; 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,26 +45,22 @@ 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: - Building targetBuilding = (Building) target; - if(!targetBuilding.isVulnerable() || targetBuilding.getRank() < 0) + 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) { 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