From e747716230ef6fddff10399bbef6e00ef7e87b52 Mon Sep 17 00:00:00 2001 From: UltraNix <80540499+UltraNix@users.noreply.github.com> Date: Fri, 19 Nov 2021 19:53:59 +0100 Subject: [PATCH] feat(Core/SmartScripts): `SMART_ACTION_CALL_FOR_HELP` should properly call assistance in case of polymorphed creature. (#9231) Updates #9120 --- src/server/game/AI/SmartScripts/SmartScript.cpp | 4 +++- src/server/game/Entities/Creature/Creature.cpp | 14 ++++++++++---- src/server/game/Entities/Creature/Creature.h | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index 8910b15eb..10c425cd8 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -1271,15 +1271,17 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u break; for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr) + { if (IsCreature(*itr)) { - (*itr)->ToCreature()->CallForHelp((float)e.action.callHelp.range); + (*itr)->ToCreature()->CallForHelp((float)e.action.callHelp.range, e.GetEventType() == SMART_EVENT_AGGRO ? unit : nullptr); if (e.action.callHelp.withEmote) { Acore::BroadcastTextBuilder builder(*itr, CHAT_MSG_MONSTER_EMOTE, BROADCAST_TEXT_CALL_FOR_HELP, LANG_UNIVERSAL, nullptr); sCreatureTextMgr->SendChatPacket(*itr, builder, CHAT_MSG_MONSTER_EMOTE); } } + } delete targets; break; diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index c6ea81df3..c878b4321 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -2237,14 +2237,20 @@ void Creature::CallAssistance(Unit* target /*= nullptr*/) } } -void Creature::CallForHelp(float radius) +void Creature::CallForHelp(float radius, Unit* target /*= nullptr*/) { - if (radius <= 0.0f || !GetVictim() || IsPet() || IsCharmed()) + if (radius <= 0.0f || IsPet() || IsCharmed()) + { return; + } - Acore::CallOfHelpCreatureInRangeDo u_do(this, GetVictim(), radius); + if (!target) + { + target = GetVictim(); + } + + Acore::CallOfHelpCreatureInRangeDo u_do(this, target, radius); Acore::CreatureWorker worker(this, u_do); - Cell::VisitGridObjects(this, worker, radius); } diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index a62813dac..822903765 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -247,7 +247,7 @@ public: [[nodiscard]] Unit* SelectNearestTargetInAttackDistance(float dist) const; void DoFleeToGetAssistance(); - void CallForHelp(float fRadius); + void CallForHelp(float fRadius, Unit* target = nullptr); void CallAssistance(Unit* target = nullptr); void SetNoCallAssistance(bool val) { m_AlreadyCallAssistance = val; } void SetNoSearchAssistance(bool val) { m_AlreadySearchedAssistance = val; }