From 426ef989f86b07505e8da3a2fd025f993e8189c1 Mon Sep 17 00:00:00 2001 From: FatBoy-DOTC Date: Sun, 10 Sep 2023 16:45:17 -0500 Subject: [PATCH] can no longer run to invalid targets --- .../client/handlers/AttackCmdMsgHandler.java | 5 ++- .../client/handlers/MoveToPointHandler.java | 42 +++++++++++++------ 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/engine/net/client/handlers/AttackCmdMsgHandler.java b/src/engine/net/client/handlers/AttackCmdMsgHandler.java index 141ed7cb..a849cb92 100644 --- a/src/engine/net/client/handlers/AttackCmdMsgHandler.java +++ b/src/engine/net/client/handlers/AttackCmdMsgHandler.java @@ -56,9 +56,12 @@ public class AttackCmdMsgHandler extends AbstractClientMsgHandler { case Building: target = BuildingManager.getBuilding(msg.getTargetID()); break; + case NPC: + target = NPC.getNPC(msg.getTargetID()); + break; } - if(target == null) { + playerCharacter.setCombatTarget(null); return true; // cannot attack a null target } //set sources target diff --git a/src/engine/net/client/handlers/MoveToPointHandler.java b/src/engine/net/client/handlers/MoveToPointHandler.java index 5be53e00..6e083cad 100644 --- a/src/engine/net/client/handlers/MoveToPointHandler.java +++ b/src/engine/net/client/handlers/MoveToPointHandler.java @@ -33,20 +33,38 @@ public class MoveToPointHandler extends AbstractClientMsgHandler { if (pc == null) return false; - AbstractWorldObject target = null; - Enum.GameObjectType targetType; - - targetType = Enum.GameObjectType.values()[msg.getTargetType()]; - switch(targetType){ - case Building: - int i = 1; - break; - case NPC: - int j = 1; - break; + if(pc.combatTarget == null){ + MovementManager.movement(msg, pc); + return true; + } else{ + Enum.GameObjectType combatTargetType = pc.combatTarget.getObjectType(); + if(combatTargetType.equals(Enum.GameObjectType.NPC)){ + msg.clearTarget(); + pc.setCombatTarget(null); + origin.sendMsg(msg); + } + + if(combatTargetType.equals(Enum.GameObjectType.Mob) || combatTargetType.equals(Enum.GameObjectType.PlayerCharacter)){ + MovementManager.movement(msg, pc); + return true; + } else if(combatTargetType.equals(Enum.GameObjectType.Building)) { + Building targetBuilding = BuildingManager.getBuilding(pc.combatTarget.getObjectUUID()); + if (targetBuilding != null) { + if (targetBuilding.isVulnerable() && targetBuilding.getRank() > -1) { + MovementManager.movement(msg, pc); + return true; + } else{ + msg.clearTarget(); + pc.setCombatTarget(null); + origin.sendMsg(msg); + } + } + } } - MovementManager.movement(msg, pc); + pc.teleport(pc.loc); + msg.setEndCoord(pc.loc); + origin.sendMsg(msg); return true; } }