diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/AI/CreatureAI.cpp | 20 | ||||
-rw-r--r-- | src/server/game/AI/CreatureAI.h | 3 |
2 files changed, 21 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; +} diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index 5931b447d06..39014837555 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -243,8 +243,11 @@ class TC_GAME_API CreatureAI : public UnitAI private: void OnOwnerCombatInteraction(Unit* target); + // Returns the value of IsEngaged() from the previous tick + bool SetWasEngaged(bool value); bool _moveInLOSLocked; + bool _wasEngaged; }; #endif |