From 937df192f61f760ad14e39dedabde07ea82a7f03 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Mon, 20 Apr 2020 10:45:49 +0200 Subject: [PATCH] Core/Packets: converted threat packets to packet class and fixed threat amount sent in them --- src/server/game/Entities/Unit/Unit.cpp | 53 ++++++------- src/server/game/Server/Packets/AllPackets.h | 1 + .../game/Server/Packets/CombatPackets.cpp | 59 ++++++++++++++ .../game/Server/Packets/CombatPackets.h | 79 +++++++++++++++++++ 4 files changed, 164 insertions(+), 28 deletions(-) create mode 100644 src/server/game/Server/Packets/CombatPackets.cpp create mode 100644 src/server/game/Server/Packets/CombatPackets.h diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 9599367f9a..5c3bfe4097 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -25,6 +25,7 @@ #include "CharacterCache.h" #include "Chat.h" #include "ChatTextBuilder.h" +#include "CombatPackets.h" #include "Common.h" #include "ConditionMgr.h" #include "CreatureAI.h" @@ -13987,19 +13988,18 @@ void Unit::SendThreatListUpdate() { if (!getThreatManager().isThreatListEmpty()) { - uint32 count = getThreatManager().getThreatList().size(); - - TC_LOG_DEBUG("entities.unit", "WORLD: Send SMSG_THREAT_UPDATE Message"); - WorldPacket data(SMSG_THREAT_UPDATE, 8 + count * 8); - data << GetPackGUID(); - data << uint32(count); + WorldPackets::Combat::ThreatUpdate packet; + packet.UnitGUID = GetGUID(); ThreatContainer::StorageType const& tlist = getThreatManager().getThreatList(); + packet.ThreatList.reserve(tlist.size()); for (ThreatContainer::StorageType::const_iterator itr = tlist.begin(); itr != tlist.end(); ++itr) { - data << (*itr)->getUnitGuid().WriteAsPacked(); - data << uint32((*itr)->getThreat() * 100); + WorldPackets::Combat::ThreatInfo info; + info.UnitGUID = (*itr)->getUnitGuid(); + info.Threat = uint32((*itr)->getThreat()); + packet.ThreatList.push_back(info); } - SendMessageToSet(&data, false); + SendMessageToSet(packet.Write(), false); } } @@ -14007,38 +14007,35 @@ void Unit::SendChangeCurrentVictimOpcode(HostileReference* pHostileReference) { if (!getThreatManager().isThreatListEmpty()) { - uint32 count = getThreatManager().getThreatList().size(); - - TC_LOG_DEBUG("entities.unit", "WORLD: Send SMSG_HIGHEST_THREAT_UPDATE Message"); - WorldPacket data(SMSG_HIGHEST_THREAT_UPDATE, 8 + 8 + count * 8); - data << GetPackGUID(); - data << pHostileReference->getUnitGuid().WriteAsPacked(); - data << uint32(count); + WorldPackets::Combat::HighestThreatUpdate packet; + packet.UnitGUID = GetGUID(); + packet.HighestThreatGUID = pHostileReference->getUnitGuid(); ThreatContainer::StorageType const& tlist = getThreatManager().getThreatList(); + packet.ThreatList.reserve(tlist.size()); for (ThreatContainer::StorageType::const_iterator itr = tlist.begin(); itr != tlist.end(); ++itr) { - data << (*itr)->getUnitGuid().WriteAsPacked(); - data << uint32((*itr)->getThreat() * 100); + WorldPackets::Combat::ThreatInfo info; + info.UnitGUID = (*itr)->getUnitGuid(); + info.Threat = uint32((*itr)->getThreat()); + packet.ThreatList.push_back(info); } - SendMessageToSet(&data, false); + SendMessageToSet(packet.Write(), false); } } void Unit::SendClearThreatListOpcode() { - TC_LOG_DEBUG("entities.unit", "WORLD: Send SMSG_THREAT_CLEAR Message"); - WorldPacket data(SMSG_THREAT_CLEAR, 8); - data << GetPackGUID(); - SendMessageToSet(&data, false); + WorldPackets::Combat::ThreatClear packet; + packet.UnitGUID = GetGUID(); + SendMessageToSet(packet.Write(), false); } void Unit::SendRemoveFromThreatListOpcode(HostileReference* pHostileReference) { - TC_LOG_DEBUG("entities.unit", "WORLD: Send SMSG_THREAT_REMOVE Message"); - WorldPacket data(SMSG_THREAT_REMOVE, 8 + 8); - data << GetPackGUID(); - data << pHostileReference->getUnitGuid().WriteAsPacked(); - SendMessageToSet(&data, false); + WorldPackets::Combat::ThreatRemove packet; + packet.UnitGUID = GetGUID(); + packet.AboutGUID = pHostileReference->getUnitGuid(); + SendMessageToSet(packet.Write(), false); } // baseRage means damage taken when attacker = false diff --git a/src/server/game/Server/Packets/AllPackets.h b/src/server/game/Server/Packets/AllPackets.h index 32b393e315..e965e7bc58 100644 --- a/src/server/game/Server/Packets/AllPackets.h +++ b/src/server/game/Server/Packets/AllPackets.h @@ -20,6 +20,7 @@ #include "AuthenticationPackets.h" #include "CharacterPackets.h" +#include "CombatPackets.h" #include "GuildPackets.h" #include "LFGPackets.h" #include "MiscPackets.h" diff --git a/src/server/game/Server/Packets/CombatPackets.cpp b/src/server/game/Server/Packets/CombatPackets.cpp new file mode 100644 index 0000000000..f03ca1295b --- /dev/null +++ b/src/server/game/Server/Packets/CombatPackets.cpp @@ -0,0 +1,59 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#include "CombatPackets.h" + +WorldPacket const* WorldPackets::Combat::ThreatUpdate::Write() +{ + _worldPacket << UnitGUID.WriteAsPacked(); + _worldPacket << uint32(ThreatList.size()); + for (WorldPackets::Combat::ThreatInfo const& threatInfo : ThreatList) + { + _worldPacket << threatInfo.UnitGUID.WriteAsPacked(); + _worldPacket << uint32(threatInfo.Threat); + } + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Combat::HighestThreatUpdate::Write() +{ + _worldPacket << UnitGUID.WriteAsPacked(); + _worldPacket << HighestThreatGUID.WriteAsPacked(); + _worldPacket << int32(ThreatList.size()); + for (WorldPackets::Combat::ThreatInfo const& threatInfo : ThreatList) + { + _worldPacket << threatInfo.UnitGUID.WriteAsPacked(); + _worldPacket << uint32(threatInfo.Threat); + } + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Combat::ThreatRemove::Write() +{ + _worldPacket << UnitGUID.WriteAsPacked(); + _worldPacket << AboutGUID.WriteAsPacked(); + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Combat::ThreatClear::Write() +{ + _worldPacket << UnitGUID.WriteAsPacked(); + return &_worldPacket; +} diff --git a/src/server/game/Server/Packets/CombatPackets.h b/src/server/game/Server/Packets/CombatPackets.h new file mode 100644 index 0000000000..1cdd93294c --- /dev/null +++ b/src/server/game/Server/Packets/CombatPackets.h @@ -0,0 +1,79 @@ +/* + * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef CombatPackets_h__ +#define CombatPackets_h__ + +#include "Packet.h" + +namespace WorldPackets +{ + namespace Combat + { + struct ThreatInfo + { + ObjectGuid UnitGUID; + int32 Threat = 0; + }; + + class ThreatUpdate final : public ServerPacket + { + public: + ThreatUpdate() : ServerPacket(SMSG_THREAT_UPDATE, 20) { } + + WorldPacket const* Write() override; + + ObjectGuid UnitGUID; + std::vector ThreatList; + }; + + class HighestThreatUpdate final : public ServerPacket + { + public: + HighestThreatUpdate() : ServerPacket(SMSG_HIGHEST_THREAT_UPDATE, 28) { } + + WorldPacket const* Write() override; + + ObjectGuid UnitGUID; + std::vector ThreatList; + ObjectGuid HighestThreatGUID; + }; + + class ThreatRemove final : public ServerPacket + { + public: + ThreatRemove() : ServerPacket(SMSG_THREAT_REMOVE, 16) { } + + WorldPacket const* Write() override; + + ObjectGuid AboutGUID; // Unit to remove threat from (e.g. player, pet, guardian) + ObjectGuid UnitGUID; // Unit being attacked (e.g. creature, boss) + }; + + class ThreatClear final : public ServerPacket + { + public: + ThreatClear() : ServerPacket(SMSG_THREAT_CLEAR, 8) { } + + WorldPacket const* Write() override; + + ObjectGuid UnitGUID; + }; + } +} + +#endif // CombatPackets_h__