aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Combat/ThreatManager.cpp
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2019-07-21 01:49:58 +0200
committerShauren <shauren.trinity@gmail.com>2021-12-17 00:23:33 +0100
commitc13d83796f7b2111c5dcf8546bdd84eccd232ae3 (patch)
tree03c4220a955113e46b3aa2f9cc270574ba3a79c4 /src/server/game/Combat/ThreatManager.cpp
parentf9fe00bf8c4c913bcfedd8df7d8e1001129962a0 (diff)
Core/AI: Finally move the "is creature engaged" flag to be a property of the creature AI, where it honestly always belonged. Fixes #17981 and #23602 for real this time.
(cherry picked from commit 0e7c66cb4c7ff7d44e232d0b50703a48605ffd24)
Diffstat (limited to 'src/server/game/Combat/ThreatManager.cpp')
-rw-r--r--src/server/game/Combat/ThreatManager.cpp39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/server/game/Combat/ThreatManager.cpp b/src/server/game/Combat/ThreatManager.cpp
index 183142f1cd7..6ad8de0aabb 100644
--- a/src/server/game/Combat/ThreatManager.cpp
+++ b/src/server/game/Combat/ThreatManager.cpp
@@ -71,6 +71,7 @@ void ThreatReference::UpdateOffline()
{
_online = ShouldBeSuppressed() ? ONLINE_STATE_SUPPRESSED : ONLINE_STATE_ONLINE;
HeapNotifyIncreased();
+ _mgr.RegisterForAIUpdate(this);
}
}
@@ -199,10 +200,11 @@ Unit* ThreatManager::GetCurrentVictim()
{
if (!_currentVictimRef || _currentVictimRef->ShouldBeOffline())
UpdateVictim();
- return const_cast<ThreatManager const*>(this)->GetCurrentVictim();
+ ASSERT(!_currentVictimRef || _currentVictimRef->IsAvailable());
+ return _currentVictimRef ? _currentVictimRef->GetVictim() : nullptr;
}
-Unit* ThreatManager::GetCurrentVictim() const
+Unit* ThreatManager::GetLastVictim() const
{
if (_currentVictimRef && !_currentVictimRef->ShouldBeOffline())
return _currentVictimRef->GetVictim();
@@ -244,7 +246,7 @@ float ThreatManager::GetThreat(Unit const* who, bool includeOffline) const
return (includeOffline || it->second->IsAvailable()) ? it->second->GetThreat() : 0.0f;
}
-std::vector<ThreatReference*> ThreatManager::GetModifiableThreatList() const
+std::vector<ThreatReference*> ThreatManager::GetModifiableThreatList()
{
std::vector<ThreatReference*> list;
list.reserve(_myThreatListEntries.size());
@@ -394,16 +396,14 @@ void ThreatManager::AddThreat(Unit* target, float amount, SpellInfo const* spell
PutThreatListRef(target->GetGUID(), ref);
target->GetThreatManager().PutThreatenedByMeRef(_owner->GetGUID(), ref);
- // afterwards, we evaluate whether this is an online reference (it might not be an acceptable target, but we need to add it to our threat list before we check!)
ref->UpdateOffline();
- if (ref->IsOnline()) // ...and if the ref is online it also gets the threat it should have
+ if (ref->IsOnline()) // we only add the threat if the ref is currently available
ref->AddThreat(amount);
- if (!_owner->IsEngaged())
- {
- _owner->AtEngage(target);
+ if (!_currentVictimRef)
UpdateVictim();
- }
+ else
+ ProcessAIUpdates();
}
void ThreatManager::ScaleThreat(Unit* target, float factor)
@@ -488,14 +488,6 @@ void ThreatManager::ClearAllThreat()
}
}
-void ThreatManager::NotifyDisengaged()
-{
- // note: i don't really like having this here
- // (maybe engage flag should be in creature ai? it's inherently an AI property...)
- if (_owner->IsEngaged())
- _owner->AtDisengage();
-}
-
void ThreatManager::FixateTarget(Unit* target)
{
if (target)
@@ -530,6 +522,7 @@ void ThreatManager::UpdateVictim()
_needClientUpdate = false;
}
+ ProcessAIUpdates();
}
ThreatReference const* ThreatManager::ReselectVictim()
@@ -538,7 +531,7 @@ ThreatReference const* ThreatManager::ReselectVictim()
return nullptr;
for (auto const& pair : _myThreatListEntries)
- pair.second->UpdateOffline();
+ pair.second->UpdateOffline(); // AI notifies are processed in ::UpdateVictim caller
// fixated target is always preferred
if (_fixateRef && _fixateRef->IsAvailable())
@@ -587,6 +580,16 @@ ThreatReference const* ThreatManager::ReselectVictim()
return nullptr;
}
+void ThreatManager::ProcessAIUpdates()
+{
+ CreatureAI* ai = ASSERT_NOTNULL(_owner->ToCreature())->AI();
+ std::vector<ThreatReference const*> v(std::move(_needsAIUpdate)); // _needClientUpdate is now empty in case this triggers a recursive call
+ if (!ai)
+ return;
+ for (ThreatReference const* ref : v)
+ ai->JustStartedThreateningMe(ref->GetVictim());
+}
+
// returns true if a is LOWER on the threat list than b
/*static*/ bool ThreatManager::CompareReferencesLT(ThreatReference const* a, ThreatReference const* b, float aWeight)
{