aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/AI/CreatureAI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/game/AI/CreatureAI.cpp')
-rw-r--r--src/server/game/AI/CreatureAI.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp
index 784cf560592..93c0076a2fa 100644
--- a/src/server/game/AI/CreatureAI.cpp
+++ b/src/server/game/AI/CreatureAI.cpp
@@ -37,7 +37,7 @@
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), _isEngaged(false), _moveInLOSLocked(false)
{
}
@@ -200,6 +200,12 @@ void CreatureAI::JustAppeared()
}
}
+void CreatureAI::JustEnteredCombat(Unit* who)
+{
+ if (!IsEngaged() && !me->CanHaveThreatList())
+ EngagementStart(who);
+}
+
void CreatureAI::EnterEvadeMode(EvadeReason why)
{
if (!_EnterEvadeMode(why))
@@ -228,7 +234,7 @@ void CreatureAI::EnterEvadeMode(EvadeReason why)
bool CreatureAI::UpdateVictim()
{
- if (!me->IsEngaged())
+ if (!IsEngaged())
return false;
if (!me->HasReactState(REACT_PASSIVE))
@@ -250,23 +256,53 @@ bool CreatureAI::UpdateVictim()
return true;
}
+void CreatureAI::EngagementStart(Unit* who)
+{
+ if (_isEngaged)
+ {
+ TC_LOG_ERROR("scripts.ai", "CreatureAI::EngagementStart called even though creature is already engaged. Creature debug info:\n%s", me->GetDebugInfo().c_str());
+ return;
+ }
+ _isEngaged = true;
+
+ me->AtEngage(who);
+}
+
+void CreatureAI::EngagementOver()
+{
+ if (!_isEngaged)
+ {
+ TC_LOG_ERROR("scripts.ai", "CreatureAI::EngagementOver called even though creature is not currently engaged. Creature debug info:\n%s", me->GetDebugInfo().c_str());
+ return;
+ }
+ _isEngaged = false;
+
+ me->AtDisengage();
+}
+
bool CreatureAI::_EnterEvadeMode(EvadeReason /*why*/)
{
+ if (me->IsInEvadeMode())
+ return false;
+
if (!me->IsAlive())
+ {
+ EngagementOver();
return false;
+ }
me->RemoveAurasOnEvade();
me->CombatStop(true);
- me->GetThreatManager().NotifyDisengaged();
me->LoadCreaturesAddon();
me->SetLootRecipient(nullptr);
me->ResetPlayerDamageReq();
me->SetLastDamagedTime(0);
me->SetCannotReachTarget(false);
me->DoNotReacquireTarget();
+ EngagementOver();
- return !me->IsInEvadeMode();
+ return true;
}
static const uint32 BOUNDARY_VISUALIZE_CREATURE = 15425;