From 5a770d294500f74d4eb0d46224e3b314cdeb7fb2 Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Fri, 26 Mar 2021 14:27:00 +0100 Subject: [PATCH] fix(Core/AI): improve npc_escortAI (#4980) --- .../game/AI/ScriptedAI/ScriptedEscortAI.cpp | 35 +++++++++++++++++++ .../game/AI/ScriptedAI/ScriptedEscortAI.h | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index 727e10f4d..37a018435 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -62,19 +62,54 @@ void npc_escortAI::AttackStart(Unit* who) bool npc_escortAI::AssistPlayerInCombat(Unit* who) { if (!who || !who->GetVictim()) + { return false; + } + + if (me->HasReactState(REACT_PASSIVE)) + { + return false; + } //experimental (unknown) flag not present if (!(me->GetCreatureTemplate()->type_flags & CREATURE_TYPE_FLAG_CAN_ASSIST)) + { return false; + } //not a player if (!who->GetVictim()->GetCharmerOrOwnerPlayerOrPlayerItself()) + { return false; + } + + if (!who->isInAccessiblePlaceFor(me)) + { + return false; + } + + if (!CanAIAttack(who)) + { + return false; + } + + // we cannot attack in evade mode + if (me->IsInEvadeMode()) + { + return false; + } + + // or if enemy is in evade mode + if (who->GetTypeId() == TYPEID_UNIT && who->ToCreature()->IsInEvadeMode()) + { + return false; + } //never attack friendly if (!me->IsValidAttackTarget(who)) + { return false; + } //too far away and no free sight? if (me->IsWithinDistInMap(who, GetMaxPlayerDistance()) && me->IsWithinLOSInMap(who)) diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h index 47058e330..665fe9a94 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h @@ -9,7 +9,7 @@ #include "ScriptSystem.h" #include "ScriptedCreature.h" -#define DEFAULT_MAX_PLAYER_DISTANCE 50 +#define DEFAULT_MAX_PLAYER_DISTANCE 100 struct Escort_Waypoint {