Core/Threat: Only send SMSG_THREAT_UPDATE if the threat list actually changed

Port From (https://github.com/TrinityCore/TrinityCore/commit/b6f4b5340792bfdf5f73c6bccd3a5f4a926f00fa)
This commit is contained in:
hondacrx
2021-11-02 13:30:59 -04:00
parent 0e1eeba55a
commit ed85016d00
+12 -3
View File
@@ -33,7 +33,8 @@ namespace Game.Combat
public Unit _owner; public Unit _owner;
bool _ownerCanHaveThreatList; bool _ownerCanHaveThreatList;
bool _ownerEngaged; bool _ownerEngaged;
public bool NeedClientUpdate;
uint _updateTimer; uint _updateTimer;
List<ThreatReference> _sortedThreatList = new(); List<ThreatReference> _sortedThreatList = new();
Dictionary<ObjectGuid, ThreatReference> _myThreatListEntries = new(); Dictionary<ObjectGuid, ThreatReference> _myThreatListEntries = new();
@@ -415,10 +416,14 @@ namespace Game.Combat
void UpdateVictim() void UpdateVictim()
{ {
ThreatReference newVictim = ReselectVictim(); ThreatReference newVictim = ReselectVictim();
bool newHighest = (newVictim != _currentVictimRef); bool newHighest = newVictim != null && (newVictim != _currentVictimRef);
_currentVictimRef = newVictim; _currentVictimRef = newVictim;
SendThreatListToClients(newVictim != null && newHighest); if (newHighest || NeedClientUpdate)
{
SendThreatListToClients(newHighest);
NeedClientUpdate = false;
}
} }
@@ -688,6 +693,7 @@ namespace Game.Combat
void PutThreatListRef(ObjectGuid guid, ThreatReference refe) void PutThreatListRef(ObjectGuid guid, ThreatReference refe)
{ {
NeedClientUpdate = true;
Cypher.Assert(!_myThreatListEntries.ContainsKey(guid), $"Duplicate threat reference being inserted on {_owner.GetGUID()} for {guid}!"); Cypher.Assert(!_myThreatListEntries.ContainsKey(guid), $"Duplicate threat reference being inserted on {_owner.GetGUID()} for {guid}!");
_myThreatListEntries[guid] = refe; _myThreatListEntries[guid] = refe;
_sortedThreatList.Add(refe); _sortedThreatList.Add(refe);
@@ -813,6 +819,7 @@ namespace Game.Combat
_baseAmount = Math.Max(_baseAmount + amount, 0.0f); _baseAmount = Math.Max(_baseAmount + amount, 0.0f);
ListNotifyChanged(); ListNotifyChanged();
_mgr.NeedClientUpdate = true;
} }
public void ScaleThreat(float factor) public void ScaleThreat(float factor)
@@ -822,6 +829,7 @@ namespace Game.Combat
_baseAmount *= factor; _baseAmount *= factor;
ListNotifyChanged(); ListNotifyChanged();
_mgr.NeedClientUpdate = true;
} }
public void UpdateOffline() public void UpdateOffline()
@@ -897,6 +905,7 @@ namespace Game.Combat
Extensions.Swap(ref state, ref _taunted); Extensions.Swap(ref state, ref _taunted);
ListNotifyChanged(); ListNotifyChanged();
_mgr.NeedClientUpdate = true;
} }
public void ClearThreat() public void ClearThreat()