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 e1d53238c89..7d617a9c384 100644
--- a/src/server/game/AI/CreatureAI.cpp
+++ b/src/server/game/AI/CreatureAI.cpp
@@ -43,7 +43,7 @@ AISpellInfoType* GetAISpellInfo(uint32 spellId, Difficulty difficulty)
CreatureAI::CreatureAI(Creature* creature, uint32 scriptId)
: UnitAI(creature), me(creature), _boundary(nullptr),
- _negateBoundary(false), _scriptId(scriptId ? scriptId : creature->GetScriptId()), _moveInLOSLocked(false)
+ _negateBoundary(false), _scriptId(scriptId ? scriptId : creature->GetScriptId()), _isEngaged(false), _moveInLOSLocked(false)
{
ASSERT(_scriptId, "A CreatureAI was initialized with an invalid scriptId!");
}
@@ -207,6 +207,12 @@ void CreatureAI::JustAppeared()
}
}
+void CreatureAI::JustEnteredCombat(Unit* who)
+{
+ if (!IsEngaged() && !me->CanHaveThreatList())
+ EngagementStart(who);
+}
+
void CreatureAI::EnterEvadeMode(EvadeReason why)
{
if (!_EnterEvadeMode(why))
@@ -235,7 +241,7 @@ void CreatureAI::EnterEvadeMode(EvadeReason why)
bool CreatureAI::UpdateVictim()
{
- if (!me->IsEngaged())
+ if (!IsEngaged())
return false;
if (!me->HasReactState(REACT_PASSIVE))
@@ -257,22 +263,52 @@ 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->SetLootRecipient(nullptr);
me->ResetPlayerDamageReq();
me->SetLastDamagedTime(0);
me->SetCannotReachTarget(false);
me->DoNotReacquireTarget();
+ EngagementOver();
- return !me->IsInEvadeMode();
+ return true;
}
Optional<QuestGiverStatus> CreatureAI::GetDialogStatus(Player* /*player*/)