Core/Combat: reset the ThreatManager update interval upon engaging the creature and move ThreatClear packet sending into the update cycle to mimic retail behavior

This commit is contained in:
Ovahlord committed 2025-03-09 00:40:56 +01:00
1 parent 6b67cd773e
commit 352ce7e1b3
3 files changed
+26 -5

No files matched your search

+18 -4
View File
@@ -195,7 +195,7 @@ void ThreatReference::HeapNotifyDecreased()
return true;
}
ThreatManager::ThreatManager(Unit* owner) : _owner(owner), _ownerCanHaveThreatList(false), _needClientUpdate(false), _updateTimer(THREAT_UPDATE_INTERVAL),
ThreatManager::ThreatManager(Unit* owner) : _owner(owner), _ownerCanHaveThreatList(false), _needClientUpdate(false), _needThreatClearUpdate(false), _updateTimer(THREAT_UPDATE_INTERVAL),
_sortedThreatList(std::make_unique<Heap>()), _currentVictimRef(nullptr), _fixateRef(nullptr)
{
for (int8 i = 0; i < MAX_SPELL_SCHOOL; ++i)
@@ -216,17 +216,31 @@ void ThreatManager::Initialize()
void ThreatManager::Update(uint32 tdiff)
{
if (!CanHaveThreatList() || IsThreatListEmpty(true))
if (!CanHaveThreatList())
return;
if (_updateTimer <= tdiff)
{
UpdateVictim();
if (_needThreatClearUpdate)
{
SendClearAllThreatToClients();
_needThreatClearUpdate = false;
}
if (!IsThreatListEmpty(true))
UpdateVictim();
_updateTimer = THREAT_UPDATE_INTERVAL;
}
else
_updateTimer -= tdiff;
}
void ThreatManager::ResetUpdateTimer()
{
_updateTimer = THREAT_UPDATE_INTERVAL;
}
Unit* ThreatManager::GetCurrentVictim()
{
if (!_currentVictimRef || _currentVictimRef->ShouldBeOffline())
@@ -535,7 +549,7 @@ void ThreatManager::ClearAllThreat()
{
if (!_myThreatListEntries.empty())
{
SendClearAllThreatToClients();
_needThreatClearUpdate = true;
do
_myThreatListEntries.begin()->second->UnregisterAndFree();
while (!_myThreatListEntries.empty());
+4
View File
@@ -94,6 +94,9 @@ class TC_GAME_API ThreatManager
// called from Creature::Update (only creatures can have their own threat list)
// should not be called from anywhere else
void Update(uint32 tdiff);
// called from Creature::AtEngage
// should not be called from anywhere else
void ResetUpdateTimer();
// never nullptr
Unit* GetOwner() const { return _owner; }
@@ -196,6 +199,7 @@ class TC_GAME_API ThreatManager
void PurgeThreatListRef(ObjectGuid const& guid);
bool _needClientUpdate;
bool _needThreatClearUpdate;
uint32 _updateTimer;
std::unique_ptr<Heap> _sortedThreatList;
std::unordered_map<ObjectGuid, ThreatReference*> _myThreatListEntries;
@@ -696,6 +696,8 @@ void Creature::Update(uint32 diff)
UpdateMovementFlags(false);
GetThreatManager().Update(diff);
switch (m_deathState)
{
case JUST_RESPAWNED:
@@ -788,7 +790,6 @@ void Creature::Update(uint32 diff)
if (!IsAlive())
break;
GetThreatManager().Update(diff);
if (_spellFocusInfo.ReacquiringTargetDelay)
{
if (_spellFocusInfo.ReacquiringTargetDelay <= diff)
@@ -3297,6 +3298,8 @@ void Creature::AtEngage(Unit* target)
{
Unit::AtEngage(target);
GetThreatManager().ResetUpdateTimer();
if (!(GetCreatureTemplate()->type_flags & CREATURE_TYPE_FLAG_MOUNTED_COMBAT_ALLOWED))
Dismount();