From 6224558c8c35d05d9adbdce5ce1a474dfa446b3f Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Mon, 12 Sep 2022 12:18:23 +0200 Subject: [PATCH] Core/Packets: converted SMSG_SPELL_MISS_LOG to packet class --- src/server/game/Entities/Object/Object.cpp | 16 ++++------ .../game/Server/Packets/CombatLogPackets.cpp | 29 +++++++++++++++++++ .../game/Server/Packets/CombatLogPackets.h | 27 +++++++++++++++++ src/server/game/Server/Protocol/Opcodes.cpp | 2 +- src/server/game/Server/Protocol/Opcodes.h | 2 +- 5 files changed, 64 insertions(+), 12 deletions(-) diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 57a54d73c8..d1c080987c 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -21,6 +21,7 @@ #include "CellImpl.h" #include "Chat.h" #include "CinematicMgr.h" +#include "CombatLogPackets.h" #include "Common.h" #include "Creature.h" #include "DBCStores.h" @@ -2733,16 +2734,11 @@ SpellMissInfo WorldObject::SpellHitResult(Unit* victim, SpellInfo const* spellIn void WorldObject::SendSpellMiss(Unit* target, uint32 spellID, SpellMissInfo missInfo) { - WorldPacket data(SMSG_SPELLLOGMISS, (4 + 8 + 1 + 4 + 8 + 1)); - data << uint32(spellID); - data << uint64(GetGUID()); - data << uint8(0); // can be 0 or 1 - data << uint32(1); // target count - // for (i = 0; i < target count; ++i) - data << uint64(target->GetGUID()); // target GUID - data << uint8(missInfo); - // end loop - SendMessageToSet(&data, true); + WorldPackets::CombatLog::SpellMissLog spellMissLog; + spellMissLog.SpellID = spellID; + spellMissLog.Caster = GetGUID(); + spellMissLog.Entries.emplace_back(target->GetGUID(), missInfo); + SendMessageToSet(spellMissLog.Write(), true); } FactionTemplateEntry const* WorldObject::GetFactionTemplateEntry() const diff --git a/src/server/game/Server/Packets/CombatLogPackets.cpp b/src/server/game/Server/Packets/CombatLogPackets.cpp index e1b404c830..a420bbcdb1 100644 --- a/src/server/game/Server/Packets/CombatLogPackets.cpp +++ b/src/server/game/Server/Packets/CombatLogPackets.cpp @@ -103,3 +103,32 @@ WorldPacket const* WorldPackets::CombatLog::SpellDamageShield::Write() return &_worldPacket; } + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::CombatLog::SpellLogMissDebug const& debug) +{ + data << float(debug.HitRoll); + data << float(debug.HitRollNeeded); +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::CombatLog::SpellLogMissEntry const& entry) +{ + data << entry.Victim; + data << uint8(entry.MissReason); + if (entry.Debug.has_value()) + data << *entry.Debug; + + return data; +} + +WorldPacket const* WorldPackets::CombatLog::SpellMissLog::Write() +{ + _worldPacket << int32(SpellID); + _worldPacket << Caster; + _worldPacket << uint8(0); // Debug + _worldPacket << uint32(Entries.size()); + + for (SpellLogMissEntry const& entry : Entries) + _worldPacket << entry; + + return &_worldPacket; +} diff --git a/src/server/game/Server/Packets/CombatLogPackets.h b/src/server/game/Server/Packets/CombatLogPackets.h index 5e93231f35..6ae3bc31dc 100644 --- a/src/server/game/Server/Packets/CombatLogPackets.h +++ b/src/server/game/Server/Packets/CombatLogPackets.h @@ -117,6 +117,33 @@ namespace WorldPackets int32 SchoolMask = 0; int32 LogAbsorbed = 0; }; + + struct SpellLogMissDebug + { + float HitRoll = 0.0f; + float HitRollNeeded = 0.0f; + }; + + struct SpellLogMissEntry + { + SpellLogMissEntry(ObjectGuid const& victim, uint8 missReason) : Victim(victim), MissReason(missReason) { } + + ObjectGuid Victim; + uint8 MissReason = 0; + Optional Debug; + }; + + class SpellMissLog final : public ServerPacket + { + public: + SpellMissLog() : ServerPacket(SMSG_SPELL_MISS_LOG) { } + + WorldPacket const* Write() override; + + int32 SpellID = 0; + ObjectGuid Caster; + std::vector Entries; + }; } } diff --git a/src/server/game/Server/Protocol/Opcodes.cpp b/src/server/game/Server/Protocol/Opcodes.cpp index dd24c28837..3bd4d9f85b 100644 --- a/src/server/game/Server/Protocol/Opcodes.cpp +++ b/src/server/game/Server/Protocol/Opcodes.cpp @@ -1226,7 +1226,7 @@ void OpcodeTable::Initialize() DEFINE_SERVER_OPCODE_HANDLER(SMSG_SPELLINSTAKILLLOG, STATUS_NEVER, CONNECTION_TYPE_INSTANCE); DEFINE_SERVER_OPCODE_HANDLER(SMSG_SPELLINTERRUPTLOG, STATUS_NEVER, CONNECTION_TYPE_INSTANCE); DEFINE_SERVER_OPCODE_HANDLER(SMSG_SPELLLOGEXECUTE, STATUS_NEVER, CONNECTION_TYPE_INSTANCE); - DEFINE_SERVER_OPCODE_HANDLER(SMSG_SPELLLOGMISS, STATUS_NEVER, CONNECTION_TYPE_INSTANCE); + DEFINE_SERVER_OPCODE_HANDLER(SMSG_SPELL_MISS_LOG, STATUS_NEVER, CONNECTION_TYPE_INSTANCE); DEFINE_SERVER_OPCODE_HANDLER(SMSG_SPELLNONMELEEDAMAGELOG, STATUS_NEVER, CONNECTION_TYPE_INSTANCE); DEFINE_SERVER_OPCODE_HANDLER(SMSG_SPELLORDAMAGE_IMMUNE, STATUS_NEVER, CONNECTION_TYPE_INSTANCE); DEFINE_SERVER_OPCODE_HANDLER(SMSG_SPELLSTEALLOG, STATUS_NEVER, CONNECTION_TYPE_INSTANCE); diff --git a/src/server/game/Server/Protocol/Opcodes.h b/src/server/game/Server/Protocol/Opcodes.h index 1159d823c9..d5e8e506bd 100644 --- a/src/server/game/Server/Protocol/Opcodes.h +++ b/src/server/game/Server/Protocol/Opcodes.h @@ -1185,7 +1185,7 @@ enum OpcodeServer SMSG_SPELLINSTAKILLLOG = 0x6216, SMSG_SPELLINTERRUPTLOG = 0x1DA7, SMSG_SPELLLOGEXECUTE = 0x0626, - SMSG_SPELLLOGMISS = 0x0625, + SMSG_SPELL_MISS_LOG = 0x0625, SMSG_SPELLNONMELEEDAMAGELOG = 0x4315, SMSG_SPELLORDAMAGE_IMMUNE = 0x4507, SMSG_SPELLSTEALLOG = 0x4E26,