|
16 | 16 | */ |
17 | 17 |
|
18 | 18 | #include "ThreatManager.h" |
| 19 | +#include "CombatPackets.h" |
19 | 20 | #include "Creature.h" |
20 | 21 | #include "CreatureAI.h" |
21 | 22 | #include "CreatureGroups.h" |
@@ -833,31 +834,42 @@ void ThreatManager::SendClearAllThreatToClients() const |
833 | 834 |
|
834 | 835 | void ThreatManager::SendRemoveToClients(Unit const* victim) const |
835 | 836 | { |
836 | | - WorldPacket data(SMSG_THREAT_REMOVE, 16); |
837 | | - data << _owner->GetPackGUID(); |
838 | | - data << victim->GetPackGUID(); |
839 | | - _owner->SendMessageToSet(&data, false); |
| 837 | + WorldPackets::Combat::ThreatRemove threatRemove; |
| 838 | + threatRemove.UnitGUID = _owner->GetGUID(); |
| 839 | + threatRemove.AboutGUID = victim->GetGUID(); |
| 840 | + _owner->SendMessageToSet(threatRemove.Write(), false); |
840 | 841 | } |
841 | 842 |
|
842 | 843 | void ThreatManager::SendThreatListToClients(bool newHighest) const |
843 | 844 | { |
844 | | - WorldPacket data(newHighest ? SMSG_HIGHEST_THREAT_UPDATE : SMSG_THREAT_UPDATE, (_sortedThreatList->size() + 2) * 8); // guess |
845 | | - data << _owner->GetPackGUID(); |
| 845 | + auto fillSharedPacketDataAndSend = [&](auto& packet) |
| 846 | + { |
| 847 | + packet.UnitGUID = _owner->GetGUID(); |
| 848 | + packet.ThreatList.reserve(_sortedThreatList->size()); |
| 849 | + for (ThreatReference const* ref : *_sortedThreatList) |
| 850 | + { |
| 851 | + if (!ref->IsAvailable()) |
| 852 | + continue; |
| 853 | + |
| 854 | + WorldPackets::Combat::ThreatInfo threatInfo; |
| 855 | + threatInfo.UnitGUID = ref->GetVictim()->GetGUID(); |
| 856 | + threatInfo.Threat = int32(ref->GetThreat() * 100); |
| 857 | + packet.ThreatList.push_back(threatInfo); |
| 858 | + } |
| 859 | + _owner->SendMessageToSet(packet.Write(), false); |
| 860 | + }; |
| 861 | + |
846 | 862 | if (newHighest) |
847 | | - data << _currentVictimRef->GetVictim()->GetPackGUID(); |
848 | | - size_t countPos = data.wpos(); |
849 | | - data << uint32(0); // placeholder |
850 | | - uint32 count = 0; |
851 | | - for (ThreatReference const* ref : *_sortedThreatList) |
852 | 863 | { |
853 | | - if (!ref->IsAvailable()) |
854 | | - continue; |
855 | | - data << ref->GetVictim()->GetPackGUID(); |
856 | | - data << uint32(ref->GetThreat() * 100); |
857 | | - ++count; |
| 864 | + WorldPackets::Combat::HighestThreatUpdate highestThreatUpdate; |
| 865 | + highestThreatUpdate.HighestThreatGUID = _currentVictimRef->GetVictim()->GetGUID(); |
| 866 | + fillSharedPacketDataAndSend(highestThreatUpdate); |
| 867 | + } |
| 868 | + else |
| 869 | + { |
| 870 | + WorldPackets::Combat::ThreatUpdate threatUpdate; |
| 871 | + fillSharedPacketDataAndSend(threatUpdate); |
858 | 872 | } |
859 | | - data.put<uint32>(countPos, count); |
860 | | - _owner->SendMessageToSet(&data, false); |
861 | 873 | } |
862 | 874 |
|
863 | 875 | void ThreatManager::PutThreatListRef(ObjectGuid const& guid, ThreatReference* ref) |
|
0 commit comments