aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/AI/CreatureAI.cpp
diff options
context:
space:
mode:
authorGiacomo Pozzoni <giacomopoz@gmail.com>2019-06-22 20:03:49 +0200
committerGitHub <noreply@github.com>2019-06-22 20:03:49 +0200
commitc234604e82f291752f9095babe60e1780fd07569 (patch)
tree9b05c5295f28afe4ccdd050acc633ef5d9edcf93 /src/server/game/AI/CreatureAI.cpp
parent678e0e606aa38e18fd361c33bc91833fdae76735 (diff)
Core/AI: Fix Guardians not following the owner after finishing combat (#23466)
CreatureAI::UpdateVictim() was not triggering EnterEvadeMode() after the Creature ended combat because IsEngaged() would return false. These changes save the value of IsEngaged() to be used next tick to check if the Creature was in combat, is not anymore now and needs to evade (or select another enemy). EnterEvadeMode() sets the stored previous value to false to ensure the Creature will not try to evade while already evading.
Diffstat (limited to 'src/server/game/AI/CreatureAI.cpp')
-rw-r--r--src/server/game/AI/CreatureAI.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp
index 1a468a4e8a1..47b0ba40812 100644
--- a/src/server/game/AI/CreatureAI.cpp
+++ b/src/server/game/AI/CreatureAI.cpp
@@ -36,7 +36,9 @@
AISpellInfoType* UnitAI::AISpellInfo;
AISpellInfoType* GetAISpellInfo(uint32 i) { return &UnitAI::AISpellInfo[i]; }
-CreatureAI::CreatureAI(Creature* creature) : UnitAI(creature), me(creature), _boundary(nullptr), _negateBoundary(false), _moveInLOSLocked(false)
+CreatureAI::CreatureAI(Creature* creature)
+ : UnitAI(creature), me(creature), _boundary(nullptr), _negateBoundary(false), _moveInLOSLocked(false),
+ _wasEngaged(false)
{
}
@@ -153,6 +155,9 @@ void CreatureAI::TriggerAlert(Unit const* who) const
void CreatureAI::EnterEvadeMode(EvadeReason why)
{
+ // Set the WasEngaged flag to false to ensure we don't evade twice
+ SetWasEngaged(false);
+
if (!_EnterEvadeMode(why))
return;
@@ -179,7 +184,11 @@ void CreatureAI::EnterEvadeMode(EvadeReason why)
bool CreatureAI::UpdateVictim()
{
- if (!me->IsEngaged())
+ bool wasEngaged = SetWasEngaged(me->IsEngaged());
+
+ // Don't skip the checks below if we were engaged in the tick before and are not engaged anymore now
+ // (and we didn't evade yet. Notice that EnterEvadeMode() calls SetWasEngaged(false) )
+ if (!wasEngaged && !me->IsEngaged())
return false;
if (!me->HasReactState(REACT_PASSIVE))
@@ -357,3 +366,10 @@ Creature* CreatureAI::DoSummonFlyer(uint32 entry, WorldObject* obj, float flight
pos.m_positionZ += flightZ;
return me->SummonCreature(entry, pos, summonType, despawnTime);
}
+
+bool CreatureAI::SetWasEngaged(bool value)
+{
+ bool previousValue = _wasEngaged;
+ _wasEngaged = value;
+ return previousValue;
+}