diff --git a/src/server/game/Handlers/SpellHandler.cpp b/src/server/game/Handlers/SpellHandler.cpp index c579d2c8f3..340bf75689 100644 --- a/src/server/game/Handlers/SpellHandler.cpp +++ b/src/server/game/Handlers/SpellHandler.cpp @@ -36,6 +36,7 @@ #include "Spell.h" #include "SpellAuraEffects.h" #include "SpellMgr.h" +#include "SpellPackets.h" #include "Totem.h" #include "World.h" #include "WorldPacket.h" @@ -355,40 +356,19 @@ void WorldSession::HandleGameobjectReportUse(WorldPacket& recvPacket) } } -void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket) +void WorldSession::HandleCastSpellOpcode(WorldPackets::Spells::CastSpell& cast) { - uint32 spellId, glyphIndex; - uint8 castCount, castFlags; - - recvPacket >> castCount; - recvPacket >> spellId; - recvPacket >> glyphIndex; - recvPacket >> castFlags; - TriggerCastFlags triggerFlag = TRIGGERED_NONE; - - TC_LOG_DEBUG("network", "WORLD: got cast spell packet, castCount: %u, spellId: %u, castFlags: %u, data length = %u", castCount, spellId, castFlags, (uint32)recvPacket.size()); - // ignore for remote control state (for player case) Unit* mover = _player->m_unitMovedByMe; if (mover != _player && mover->GetTypeId() == TYPEID_PLAYER) - { - recvPacket.rfinish(); // prevent spam at ignore packet return; - } - SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); + SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(cast.Cast.SpellID); if (!spellInfo) - { - TC_LOG_ERROR("network", "WORLD: unknown spell id %u", spellId); - recvPacket.rfinish(); // prevent spam at ignore packet return; - } if (spellInfo->IsPassive()) - { - recvPacket.rfinish(); // prevent spam at ignore packet return; - } Unit* caster = mover; if (caster->GetTypeId() == TYPEID_UNIT && !caster->ToCreature()->HasSpell(spellInfo->Id)) @@ -396,18 +376,13 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket) // If the vehicle creature does not have the spell but it allows the passenger to cast own spells // change caster to player and let him cast if (!_player->IsOnVehicle(caster) || spellInfo->CheckVehicle(_player) != SPELL_CAST_OK) - { - recvPacket.rfinish(); // prevent spam at ignore packet return; - } caster = _player; } // client provided targets - SpellCastTargets targets; - targets.Read(recvPacket, caster); - HandleClientCastFlags(recvPacket, castFlags, targets); + SpellCastTargets targets(caster, cast.Cast); if (caster->GetTypeId() == TYPEID_PLAYER && !caster->ToPlayer()->HasActiveSpell(spellInfo->Id) && !spellInfo->IsRaidMarker() && !caster->ToPlayer()->HasArchProject(static_cast(spellInfo->ResearchProjectId))) @@ -444,16 +419,9 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket) // Skip it to prevent "interrupt" message // Also check targets! target may have changed and we need to interrupt current spell if (spellInfo->IsAutoRepeatRangedSpell()) - { if (Spell* spell = caster->GetCurrentSpell(CURRENT_AUTOREPEAT_SPELL)) - { if (spell->m_spellInfo == spellInfo && spell->m_targets.GetUnitTargetGUID() == targets.GetUnitTargetGUID()) - { - recvPacket.rfinish(); return; - } - } - } // auto-selection buff level base at target level (in spellInfo) // TODO: is this even necessary? client already seems to send correct rank for "standard" buffs @@ -467,9 +435,33 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket) spellInfo = actualSpellInfo; } - Spell* spell = new Spell(caster, spellInfo, triggerFlag, ObjectGuid::Empty, false); - spell->m_cast_count = castCount; // set count of casts - spell->m_glyphIndex = glyphIndex; + if (!cast.Cast.Weight.empty()) + { + ArchData archaeologyCastData; + for (WorldPackets::Spells::SpellWeight& weight : cast.Cast.Weight) + { + switch (weight.Type) + { + case 1: // Currency + archaeologyCastData.FragId = weight.ID; + archaeologyCastData.FragCount = weight.Quantity; + break; + case 2: // Item + archaeologyCastData.KeyId = weight.ID; + archaeologyCastData.KeyCount = weight.Quantity; + break; + default: + break; + } + } + + if (Player* player = GetPlayer()) + player->SetArchData(archaeologyCastData); + } + + Spell* spell = new Spell(caster, spellInfo, TRIGGERED_NONE, ObjectGuid::Empty, false); + spell->m_cast_count = cast.Cast.CastID; // set count of casts + spell->m_glyphIndex = cast.Cast.Misc; spell->prepare(targets); } diff --git a/src/server/game/Server/Packets/AllPackets.h b/src/server/game/Server/Packets/AllPackets.h index aecfd6f269..ee3f382ab3 100644 --- a/src/server/game/Server/Packets/AllPackets.h +++ b/src/server/game/Server/Packets/AllPackets.h @@ -34,6 +34,7 @@ #include "PartyPackets.h" #include "QuestPackets.h" #include "QueryPackets.h" +#include "SpellPackets.h" #include "SystemPackets.h" #include "VehiclePackets.h" #include "WhoPackets.h" diff --git a/src/server/game/Server/Packets/SpellPackets.cpp b/src/server/game/Server/Packets/SpellPackets.cpp index 35e9156665..faaa7e393b 100644 --- a/src/server/game/Server/Packets/SpellPackets.cpp +++ b/src/server/game/Server/Packets/SpellPackets.cpp @@ -16,6 +16,8 @@ */ #include "SpellPackets.h" +#include "Spell.h" +#include "SpellInfo.h" ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::SpellHealPrediction const& predict) { @@ -569,3 +571,220 @@ WorldPacket const* WorldPackets::Spells::SpellDelayed::Write() _worldPacket << int32(ActualDelay); return &_worldPacket; } + +ByteBuffer& operator>>(ByteBuffer& data, Optional& location) +{ + location.emplace(); + data >> location->Transport.ReadAsPacked(); + data >> location->Location.m_positionX; + data >> location->Location.m_positionY; + data >> location->Location.m_positionZ; + + return data; +} + +ByteBuffer& operator>>(ByteBuffer& data, WorldPackets::Spells::SpellTargetData& targetData) +{ + data >> targetData.Flags; + + if (targetData.Flags & (TARGET_FLAG_UNIT | TARGET_FLAG_UNIT_MINIPET | TARGET_FLAG_GAMEOBJECT | TARGET_FLAG_CORPSE_ENEMY | TARGET_FLAG_CORPSE_ALLY)) + { + targetData.Unit.emplace(); + data >> targetData.Unit->ReadAsPacked(); + } + + if (targetData.Flags & (TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM)) + { + targetData.Item.emplace(); + data >> targetData.Item->ReadAsPacked(); + } + + if (targetData.Flags & TARGET_FLAG_SOURCE_LOCATION) + data >> targetData.SrcLocation; + + if (targetData.Flags & TARGET_FLAG_DEST_LOCATION) + data >> targetData.DstLocation; + + if (targetData.Flags & TARGET_FLAG_STRING) + { + targetData.Name.emplace(); + data >> *targetData.Name; + } + + return data; +} + +ByteBuffer& operator>>(ByteBuffer& data, Optional& movementInfo) +{ + movementInfo.emplace(); + data >> movementInfo->pos.m_positionZ; + data >> movementInfo->pos.m_positionY; + data >> movementInfo->pos.m_positionX; + + bool hasFallData = data.ReadBit(); + bool hasTime = !data.ReadBit(); + bool hasFacing = !data.ReadBit(); + + data.ReadBit(); // HasSpline + data.ReadBit(); // HeightChangeFailed + + movementInfo->guid[6] = data.ReadBit(); + movementInfo->guid[4] = data.ReadBit(); + + bool hasExtraMovementFlags = !data.ReadBit(); + + movementInfo->guid[3] = data.ReadBit(); + movementInfo->guid[5] = data.ReadBit(); + + bool hasSplineElevation = !data.ReadBit(); + bool hasPitch = !data.ReadBit(); + + movementInfo->guid[7] = data.ReadBit(); + + bool hasTransportData = data.ReadBit(); + + movementInfo->guid[2] = data.ReadBit(); + + bool hasMovementFlags = !data.ReadBit(); + + movementInfo->guid[1] = data.ReadBit(); + movementInfo->guid[0] = data.ReadBit(); + + bool hasTransportTime2 = false; + bool hasVehicleRecId = false; + if (hasTransportData) + { + movementInfo->transport.guid[6] = data.ReadBit(); + movementInfo->transport.guid[2] = data.ReadBit(); + movementInfo->transport.guid[5] = data.ReadBit(); + hasTransportTime2 = data.ReadBit(); + movementInfo->transport.guid[7] = data.ReadBit(); + movementInfo->transport.guid[4] = data.ReadBit(); + hasVehicleRecId = data.ReadBit(); + movementInfo->transport.guid[0] = data.ReadBit(); + movementInfo->transport.guid[1] = data.ReadBit(); + movementInfo->transport.guid[3] = data.ReadBit(); + } + + if (hasExtraMovementFlags) + movementInfo->SetExtraMovementFlags(data.ReadBits(12)); + + if (hasMovementFlags) + movementInfo->SetMovementFlags(data.ReadBits(30)); + + bool hasFallDirection = false; + if (hasFallData) + hasFallDirection = data.ReadBit(); + + data.ReadByteSeq(movementInfo->guid[1]); + data.ReadByteSeq(movementInfo->guid[4]); + data.ReadByteSeq(movementInfo->guid[7]); + data.ReadByteSeq(movementInfo->guid[3]); + data.ReadByteSeq(movementInfo->guid[0]); + data.ReadByteSeq(movementInfo->guid[2]); + data.ReadByteSeq(movementInfo->guid[5]); + data.ReadByteSeq(movementInfo->guid[6]); + + if (hasTransportData) + { + data >> movementInfo->transport.seat; + movementInfo->transport.pos.SetOrientation(data.read()); + data >> movementInfo->transport.time; + + data.ReadByteSeq(movementInfo->transport.guid[6]); + data.ReadByteSeq(movementInfo->transport.guid[5]); + + if (hasTransportTime2) + data >> movementInfo->transport.time2; + + data >> movementInfo->transport.pos.m_positionX; + + data.ReadByteSeq(movementInfo->transport.guid[4]); + + data >> movementInfo->transport.pos.m_positionZ; + + data.ReadByteSeq(movementInfo->transport.guid[2]); + data.ReadByteSeq(movementInfo->transport.guid[0]); + + if (hasVehicleRecId) + data >> movementInfo->transport.vehicleId; + + data.ReadByteSeq(movementInfo->transport.guid[1]); + data.ReadByteSeq(movementInfo->transport.guid[3]); + + data >> movementInfo->transport.pos.m_positionY; + + data.ReadByteSeq(movementInfo->transport.guid[7]); + } + + if (hasFacing) + movementInfo->pos.SetOrientation(data.read()); + + if (hasSplineElevation) + data >> movementInfo->splineElevation; + + if (hasFallData) + { + data >> movementInfo->jump.fallTime; + if (hasFallDirection) + { + data >> movementInfo->jump.sinAngle; + data >> movementInfo->jump.cosAngle; + data >> movementInfo->jump.xyspeed; + } + data >> movementInfo->jump.zspeed; + } + + if (hasTime) + data >> movementInfo->time; + + if (hasPitch) + data >> movementInfo->pitch; + + return data; +} + +ByteBuffer& operator>>(ByteBuffer& data, WorldPackets::Spells::MissileTrajectoryRequest& missileTrajectory) +{ + data >> missileTrajectory.Pitch; + data >> missileTrajectory.Speed; + + return data; +} + +ByteBuffer& operator>>(ByteBuffer& data, WorldPackets::Spells::SpellCastRequest& castRequest) +{ + data >> castRequest.CastID; + data >> castRequest.SpellID; + data >> castRequest.Misc; + data >> castRequest.SendCastFlags; + data >> castRequest.Target; + + if (castRequest.SendCastFlags & CAST_FLAG_HAS_TRAJECTORY) + { + data >> castRequest.MissileTrajectory; + bool hasMovementData = data.read(); + if (hasMovementData) + data >> castRequest.MoveUpdate; + } + + if (castRequest.SendCastFlags & CAST_FLAG_HAS_WEIGHT) + { + uint32 weightCount = data.read(); + castRequest.Weight.resize(weightCount); + + for (WorldPackets::Spells::SpellWeight& weight : castRequest.Weight) + { + data >> weight.Type; + data >> weight.ID; + data >> weight.Quantity; + } + } + + return data; +} + +void WorldPackets::Spells::CastSpell::Read() +{ + _worldPacket >> Cast; +} diff --git a/src/server/game/Server/Packets/SpellPackets.h b/src/server/game/Server/Packets/SpellPackets.h index 54e61384ba..ae6b726b73 100644 --- a/src/server/game/Server/Packets/SpellPackets.h +++ b/src/server/game/Server/Packets/SpellPackets.h @@ -477,6 +477,41 @@ namespace WorldPackets ObjectGuid Caster; int32 ActualDelay = 0; }; + + struct MissileTrajectoryRequest + { + float Pitch = 0.0f; + float Speed = 0.0f; + }; + + struct SpellWeight + { + uint8 Type = 0; + int32 ID = 0; + uint32 Quantity = 0; + }; + + struct SpellCastRequest + { + uint8 CastID = 0; + uint8 SendCastFlags = 0; + int32 SpellID = 0; + int32 Misc = 0; + SpellTargetData Target; + MissileTrajectoryRequest MissileTrajectory; + Optional MoveUpdate; + std::vector Weight; + }; + + class CastSpell final : public ClientPacket + { + public: + CastSpell(WorldPacket&& packet) : ClientPacket(CMSG_CAST_SPELL, std::move(packet)) { } + + void Read() override; + + SpellCastRequest Cast; + }; } } diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 5d1473e726..91b2138897 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -195,6 +195,11 @@ namespace WorldPackets class DBQueryBulk; } + namespace Spells + { + class CastSpell; + } + namespace Who { class WhoRequestPkt; @@ -919,7 +924,7 @@ class TC_GAME_API WorldSession void HandleUseItemOpcode(WorldPacket& recvPacket); void HandleOpenItemOpcode(WorldPacket& recvPacket); void HandleOpenWrappedItemCallback(uint16 pos, ObjectGuid itemGuid, PreparedQueryResult result); - void HandleCastSpellOpcode(WorldPacket& recvPacket); + void HandleCastSpellOpcode(WorldPackets::Spells::CastSpell& castRequest); void HandleCancelCastOpcode(WorldPacket& recvPacket); void HandleCancelAuraOpcode(WorldPacket& recvPacket); void HandleCancelGrowthAuraOpcode(WorldPacket& recvPacket); diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 4c567c176c..bc50b32b8b 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -112,14 +112,52 @@ void SpellDestination::RelocateOffset(Position const& offset) _position.RelocateOffset(offset); } -SpellCastTargets::SpellCastTargets() : m_elevation(0), m_speed(0), m_strTarget() +SpellCastTargets::SpellCastTargets() : m_elevation(0.f), m_speed(0.f), m_strTarget(), m_objectTarget(nullptr), + m_itemTarget(nullptr), m_itemTargetEntry(0), m_targetMask(0) { - m_objectTarget = nullptr; - m_itemTarget = nullptr; +} - m_itemTargetEntry = 0; +SpellCastTargets::SpellCastTargets(Unit* caster, WorldPackets::Spells::SpellCastRequest const& spellCastRequest) : + m_targetMask(spellCastRequest.Target.Flags), m_objectTarget(nullptr), m_itemTarget(nullptr), + m_itemTargetEntry(0), m_elevation(0.0f), m_speed(0.0f) +{ + if (spellCastRequest.Target.Unit) + m_objectTargetGUID = *spellCastRequest.Target.Unit; - m_targetMask = 0; + if (spellCastRequest.Target.Item) + m_itemTargetGUID = *spellCastRequest.Target.Item; + + if (spellCastRequest.Target.Name) + m_strTarget = *spellCastRequest.Target.Name; + + if (spellCastRequest.Target.SrcLocation) + { + m_src._transportGUID = spellCastRequest.Target.SrcLocation->Transport; + Position* pos; + if (!m_src._transportGUID.IsEmpty()) + pos = &m_src._transportOffset; + else + pos = &m_src._position; + + pos->Relocate(spellCastRequest.Target.SrcLocation->Location); + } + + if (spellCastRequest.Target.DstLocation) + { + m_dst._transportGUID = spellCastRequest.Target.DstLocation->Transport; + Position* pos; + if (!m_dst._transportGUID.IsEmpty()) + pos = &m_dst._transportOffset; + else + pos = &m_dst._position; + + pos->Relocate(spellCastRequest.Target.DstLocation->Location); + } + + SetElevation(spellCastRequest.MissileTrajectory.Pitch); + SetSpeed(spellCastRequest.MissileTrajectory.Speed); + + Update(caster); } SpellCastTargets::~SpellCastTargets() { } diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 3e8ce2b61e..3283f85333 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -29,8 +29,10 @@ namespace WorldPackets { namespace Spells { + struct SpellCastRequest; struct SpellTargetData; struct SpellAmmo; + struct SpellCastData; struct SpellHitInfo; struct SpellHealPrediction; } @@ -73,7 +75,7 @@ enum SpellCastFlags CAST_FLAG_PENDING = 0x00000001, // aoe combat log? CAST_FLAG_HAS_TRAJECTORY = 0x00000002, CAST_FLAG_UNKNOWN_3 = 0x00000004, - CAST_FLAG_UNKNOWN_4 = 0x00000008, // ignore AOE visual + CAST_FLAG_HAS_WEIGHT = 0x00000008, CAST_FLAG_UNKNOWN_5 = 0x00000010, CAST_FLAG_PROJECTILE = 0x00000020, CAST_FLAG_UNKNOWN_7 = 0x00000040, @@ -137,6 +139,7 @@ class TC_GAME_API SpellCastTargets { public: SpellCastTargets(); + SpellCastTargets(Unit* caster, WorldPackets::Spells::SpellCastRequest const& spellCastRequest); ~SpellCastTargets(); void Read(ByteBuffer& data, Unit* caster);