diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 57ce15bb7f..88b0d90df4 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -1974,19 +1974,19 @@ void Object::ForceValuesUpdateAtIndex(uint32 i) AddToObjectUpdateIfNeeded(); } -void WorldObject::SendMessageToSet(WorldPacket* data, bool self) const +void WorldObject::SendMessageToSet(WorldPacket const* data, bool self) const { if (IsInWorld()) SendMessageToSetInRange(data, GetVisibilityRange(), self); } -void WorldObject::SendMessageToSetInRange(WorldPacket* data, float dist, bool /*self*/) const +void WorldObject::SendMessageToSetInRange(WorldPacket const* data, float dist, bool /*self*/) const { Trinity::MessageDistDeliverer notifier(this, data, dist); Cell::VisitWorldObjects(this, notifier, dist); } -void WorldObject::SendMessageToSet(WorldPacket* data, Player const* skipped_rcvr) const +void WorldObject::SendMessageToSet(WorldPacket const* data, Player const* skipped_rcvr) const { Trinity::MessageDistDeliverer notifier(this, data, GetVisibilityRange(), false, skipped_rcvr); Cell::VisitWorldObjects(this, notifier, GetVisibilityRange()); diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 40cd9f02ac..32be64c460 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -367,9 +367,9 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation virtual void CleanupsBeforeDelete(bool finalCleanup = true); // used in destructor or explicitly before mass creature delete to remove cross-references to already deleted units - virtual void SendMessageToSet(WorldPacket* data, bool self) const; - virtual void SendMessageToSetInRange(WorldPacket* data, float dist, bool self) const; - virtual void SendMessageToSet(WorldPacket* data, Player const* skipped_rcvr) const; + virtual void SendMessageToSet(WorldPacket const* data, bool self) const; + virtual void SendMessageToSetInRange(WorldPacket const* data, float dist, bool self) const; + virtual void SendMessageToSet(WorldPacket const* data, Player const* skipped_rcvr) const; virtual uint8 getLevelForTarget(WorldObject const* /*target*/) const { return 1; } diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index f34eb8411e..74b0199414 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -6222,7 +6222,7 @@ bool Player::UpdatePosition(float x, float y, float z, float orientation, bool t return true; } -void Player::SendMessageToSetInRange(WorldPacket* data, float dist, bool self) const +void Player::SendMessageToSetInRange(WorldPacket const* data, float dist, bool self) const { if (self) SendDirectMessage(data); @@ -6231,7 +6231,7 @@ void Player::SendMessageToSetInRange(WorldPacket* data, float dist, bool self) c Cell::VisitWorldObjects(this, notifier, dist); } -void Player::SendMessageToSetInRange(WorldPacket* data, float dist, bool self, bool own_team_only) const +void Player::SendMessageToSetInRange(WorldPacket const* data, float dist, bool self, bool own_team_only) const { if (self) SendDirectMessage(data); @@ -6240,7 +6240,7 @@ void Player::SendMessageToSetInRange(WorldPacket* data, float dist, bool self, b Cell::VisitWorldObjects(this, notifier, dist); } -void Player::SendMessageToSet(WorldPacket* data, Player const* skipped_rcvr) const +void Player::SendMessageToSet(WorldPacket const* data, Player const* skipped_rcvr) const { if (skipped_rcvr != this) SendDirectMessage(data); diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 65226ec1a1..ee37510350 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -1868,10 +1868,10 @@ class TC_GAME_API Player : public Unit, public GridObject bool UpdatePosition(Position const& pos, bool teleport = false) override { return UpdatePosition(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), teleport); } void ProcessTerrainStatusUpdate(ZLiquidStatus status, Optional const& liquidData) override; - void SendMessageToSet(WorldPacket* data, bool self) const override { SendMessageToSetInRange(data, GetVisibilityRange(), self); } - void SendMessageToSetInRange(WorldPacket* data, float dist, bool self) const override; - void SendMessageToSetInRange(WorldPacket* data, float dist, bool self, bool own_team_only) const; - void SendMessageToSet(WorldPacket* data, Player const* skipped_rcvr) const override; + void SendMessageToSet(WorldPacket const* data, bool self) const override { SendMessageToSetInRange(data, GetVisibilityRange(), self); } + void SendMessageToSetInRange(WorldPacket const* data, float dist, bool self) const override; + void SendMessageToSetInRange(WorldPacket const* data, float dist, bool self, bool own_team_only) const; + void SendMessageToSet(WorldPacket const* data, Player const* skipped_rcvr) const override; Corpse* GetCorpse() const; void SpawnCorpseBones(bool triggerSave = true); diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h index 80314d4c0f..edfbf0efd1 100644 --- a/src/server/game/Grids/Notifiers/GridNotifiers.h +++ b/src/server/game/Grids/Notifiers/GridNotifiers.h @@ -118,11 +118,11 @@ namespace Trinity struct TC_GAME_API MessageDistDeliverer { WorldObject const* i_source; - WorldPacket* i_message; + WorldPacket const* i_message; float i_distSq; uint32 team; Player const* skipped_receiver; - MessageDistDeliverer(WorldObject const* src, WorldPacket* msg, float dist, bool own_team_only = false, Player const* skipped = nullptr) + MessageDistDeliverer(WorldObject const* src, WorldPacket const* msg, float dist, bool own_team_only = false, Player const* skipped = nullptr) : i_source(src), i_message(msg), i_distSq(dist * dist) , team(0) , skipped_receiver(skipped) diff --git a/src/server/game/Server/Packets/SpellPackets.cpp b/src/server/game/Server/Packets/SpellPackets.cpp new file mode 100644 index 0000000000..0d23e4600f --- /dev/null +++ b/src/server/game/Server/Packets/SpellPackets.cpp @@ -0,0 +1,169 @@ +/* + * 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 "SpellPackets.h" + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::SpellHealPrediction const& predict) +{ + data << int32(predict.Points); + data << int32(predict.Type); + if (predict.BeaconGUID.is_initialized()) + data << predict.BeaconGUID->WriteAsPacked(); + return data; +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::CreatureImmunities const& immunities) +{ + data << int32(immunities.School); + data << int32(immunities.Value); + return data; +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::MissileTrajectoryResult const& missileTrajectory) +{ + data << float(missileTrajectory.Pitch); + data << int32(missileTrajectory.TravelTime); + return data; +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::SpellAmmo const& spellAmmo) +{ + data << int32(spellAmmo.DisplayID); + data << int32(spellAmmo.InventoryType); + return data; +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::RuneData const& runeData) +{ + data << uint8(runeData.Start); + data << uint8(runeData.Count); + if (!runeData.Cooldowns.empty()) + data.append(runeData.Cooldowns.data(), runeData.Cooldowns.size()); + + return data; +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::TargetLocation const& targetLocation) +{ + data << targetLocation.Transport.WriteAsPacked(); + data << targetLocation.Location.PositionXYZStream(); + return data; +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::ProjectileVisual const& projectileVisual) +{ + data << int32(projectileVisual.Id[0]); + data << int32(projectileVisual.Id[1]); + return data; +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::SpellTargetData const& spellTargetData) +{ + data << uint32(spellTargetData.Flags); + + if (spellTargetData.Unit.is_initialized()) + data << spellTargetData.Unit->WriteAsPacked(); + + if (spellTargetData.Item.is_initialized()) + data << spellTargetData.Item->WriteAsPacked(); + + if (spellTargetData.SrcLocation) + data << *spellTargetData.SrcLocation; + + if (spellTargetData.DstLocation) + data << *spellTargetData.DstLocation; + + if (spellTargetData.Name.is_initialized()) + data << *spellTargetData.Name; + + return data; +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::SpellHitInfo const& spellHitInfo) +{ + data << uint8(spellHitInfo.HitTargets.size()); + for (ObjectGuid const& hitTarget : spellHitInfo.HitTargets) + data << hitTarget; + + data << uint8(spellHitInfo.MissStatus.size()); + for (WorldPackets::Spells::SpellMissStatus const& missTarget : spellHitInfo.MissStatus) + { + data << missTarget.MissTarget; + data << uint8(missTarget.Reason); + if (missTarget.ReflectStatus) + data << uint8(missTarget.ReflectStatus); + } + return data; +} + +ByteBuffer& operator<<(ByteBuffer& data, WorldPackets::Spells::SpellCastData const& spellCastData) +{ + data << spellCastData.CasterGUID.WriteAsPacked(); + data << spellCastData.CasterUnit.WriteAsPacked(); + data << uint8(spellCastData.CastID); + data << uint32(spellCastData.SpellID); + data << uint32(spellCastData.CastFlags); + data << uint32(0); // m_timer Todo: research + data << uint32(spellCastData.CastTime); + + if (spellCastData.HitInfo) + data << *spellCastData.HitInfo; + + data << spellCastData.Target; + + if (spellCastData.RemainingPower.is_initialized()) + data << uint32(*spellCastData.RemainingPower); + + if (spellCastData.RemainingRunes) + data << *spellCastData.RemainingRunes; + + if (spellCastData.MissileTrajectory) + data << *spellCastData.MissileTrajectory; + + if (spellCastData.Ammo) + data << *spellCastData.Ammo; + + if (spellCastData.ProjectileVisuals) + data << *spellCastData.ProjectileVisuals; + + if (spellCastData.DestLocSpellCastIndex.is_initialized()) + data << uint8(*spellCastData.DestLocSpellCastIndex); + + // Todo: TARGET_FLAG_EXTRA_TARGETS (unused as it seems though) + + if (spellCastData.Immunities) + data << *spellCastData.Immunities; + + if (spellCastData.Predict) + data << *spellCastData.Predict; + + return data; +} + +WorldPacket const* WorldPackets::Spells::SpellStart::Write() +{ + _worldPacket << Cast; + + return &_worldPacket; +} + +WorldPacket const* WorldPackets::Spells::SpellGo::Write() +{ + _worldPacket << Cast; + + return &_worldPacket; +} diff --git a/src/server/game/Server/Packets/SpellPackets.h b/src/server/game/Server/Packets/SpellPackets.h new file mode 100644 index 0000000000..d739e84034 --- /dev/null +++ b/src/server/game/Server/Packets/SpellPackets.h @@ -0,0 +1,148 @@ +/* + * 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 SpellPackets_h__ +#define SpellPackets_h__ + +#include "Packet.h" +#include "ObjectGuid.h" +#include "Optional.h" +#include "Position.h" +#include "SharedDefines.h" + +namespace WorldPackets +{ + namespace Spells + { + struct SpellMissStatus + { + SpellMissStatus() { } + SpellMissStatus(ObjectGuid missTarget, uint8 reason, uint8 reflectStatus) : MissTarget(missTarget), Reason(reason), ReflectStatus(reflectStatus) { } + + ObjectGuid MissTarget; + uint8 Reason = 0; + uint8 ReflectStatus = 0; + }; + + struct RuneData + { + uint8 Start = 0; + uint8 Count = 0; + std::vector Cooldowns; + }; + + struct MissileTrajectoryResult + { + uint32 TravelTime = 0; + float Pitch = 0.0f; + }; + + struct SpellAmmo + { + uint32 DisplayID = 0; + uint32 InventoryType = 0; + }; + + struct CreatureImmunities + { + uint32 School = 0; + uint32 Value = 0; + }; + + struct TargetLocation + { + ObjectGuid Transport; + Position Location; + }; + + struct ProjectileVisual + { + std::array Id = { }; + }; + + class SpellPowerData + { + int32 Cost = 0; + int8 Type = 0; + }; + + struct SpellTargetData + { + uint32 Flags = 0; + Optional Unit; + Optional Item; + Optional SrcLocation; + Optional DstLocation; + Optional Name; + }; + + struct SpellHealPrediction + { + Optional BeaconGUID; + uint32 Points = 0; + uint8 Type = 0; + }; + + struct SpellHitInfo + { + std::vector HitTargets; + std::vector MissStatus; + }; + + struct SpellCastData + { + ObjectGuid CasterGUID; + ObjectGuid CasterUnit; + uint8 CastID = 0; + uint32 SpellID = 0; + uint32 CastFlags = 0; + uint32 CastTime = 0; + SpellTargetData Target; + Optional HitInfo; + Optional DestLocSpellCastIndex; + Optional Predict; + Optional Immunities; + Optional Ammo; + Optional MissileTrajectory; + Optional RemainingPower; + Optional RemainingRunes; + Optional ProjectileVisuals; + }; + + class SpellStart final : public ServerPacket + { + public: + SpellStart() : ServerPacket(SMSG_SPELL_START) { } + + WorldPacket const* Write() override; + + SpellCastData Cast; + }; + + class SpellGo final : public ServerPacket + { + public: + SpellGo() : ServerPacket(SMSG_SPELL_GO) { } + + WorldPacket const* Write() override; + + SpellCastData Cast; + }; + } +} + +#endif diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index ca9e421774..fbafe58bed 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -47,6 +47,7 @@ #include "SpellHistory.h" #include "SpellInfo.h" #include "SpellMgr.h" +#include "SpellPackets.h" #include "SpellScript.h" #include "TemporarySummon.h" #include "TradeData.h" @@ -175,41 +176,38 @@ void SpellCastTargets::Read(ByteBuffer& data, Unit* caster) Update(caster); } -void SpellCastTargets::Write(ByteBuffer& data) +void SpellCastTargets::Write(WorldPackets::Spells::SpellTargetData& data) { - data << uint32(m_targetMask); + data.Flags = m_targetMask; if (m_targetMask & (TARGET_FLAG_UNIT | TARGET_FLAG_CORPSE_ALLY | TARGET_FLAG_GAMEOBJECT | TARGET_FLAG_CORPSE_ENEMY | TARGET_FLAG_UNIT_MINIPET)) - data << m_objectTargetGUID.WriteAsPacked(); + data.Unit = m_objectTargetGUID; - if (m_targetMask & (TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM)) - { - if (m_itemTarget) - data << m_itemTarget->GetPackGUID(); - else - data << uint8(0); - } + if (m_targetMask & (TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM) && m_itemTarget) + data.Item = m_itemTarget->GetGUID(); if (m_targetMask & TARGET_FLAG_SOURCE_LOCATION) { - data << m_src._transportGUID.WriteAsPacked(); // relative position guid here - transport for example - if (m_src._transportGUID) - data << m_src._transportOffset.PositionXYZStream(); + data.SrcLocation = boost::in_place(); + data.SrcLocation->Transport = m_src._transportGUID; // relative position guid here - transport for example + if (!m_src._transportGUID.IsEmpty()) + data.SrcLocation->Location = m_src._transportOffset; else - data << m_src._position.PositionXYZStream(); + data.SrcLocation->Location = m_src._position; } if (m_targetMask & TARGET_FLAG_DEST_LOCATION) { - data << m_dst._transportGUID.WriteAsPacked(); // relative position guid here - transport for example - if (m_dst._transportGUID) - data << m_dst._transportOffset.PositionXYZStream(); + data.DstLocation = boost::in_place(); + data.DstLocation->Transport = m_dst._transportGUID; // relative position guid here - transport for example + if (!m_dst._transportGUID.IsEmpty()) + data.DstLocation->Location = m_dst._transportOffset; else - data << m_dst._position.PositionXYZStream(); + data.DstLocation->Location = m_dst._position; } if (m_targetMask & TARGET_FLAG_STRING) - data << m_strTarget; + data.Name = m_strTarget; } ObjectGuid SpellCastTargets::GetOrigUnitTargetGUID() const @@ -4168,86 +4166,89 @@ void Spell::SendSpellStart() m_spellInfo->HasAura(SPELL_AURA_PERIODIC_HEAL)) castFlags |= CAST_FLAG_HEAL_PREDICTION; - WorldPacket data(SMSG_SPELL_START, (8+8+4+4+2)); + WorldPackets::Spells::SpellStart packet; + WorldPackets::Spells::SpellCastData& castData = packet.Cast; + if (m_CastItem) - data << m_CastItem->GetPackGUID(); + castData.CasterGUID = m_CastItem->GetGUID(); else - data << m_caster->GetPackGUID(); + castData.CasterGUID = m_caster->GetGUID(); - data << m_caster->GetPackGUID(); - data << uint8(m_cast_count); // pending spell cast? - data << uint32(m_spellInfo->Id); // spellId - data << uint32(castFlags); // cast flags - data << uint32(m_timer); // delay? - data << uint32(m_casttime); + castData.CasterUnit = m_caster->GetGUID(); + castData.CastID = m_cast_count; + castData.SpellID = m_spellInfo->Id; + castData.CastFlags = castFlags; + castData.CastTime = m_casttime; - m_targets.Write(data); + //data << uint32(m_timer); // delay? + + m_targets.Write(castData.Target); if (castFlags & CAST_FLAG_POWER_LEFT_SELF) - data << uint32(m_caster->GetPower((Powers)m_spellInfo->PowerType)); + castData.RemainingPower = m_caster->GetPower(Powers(m_spellInfo->PowerType)); if (castFlags & CAST_FLAG_RUNE_LIST) // rune cooldowns list { + castData.RemainingRunes = boost::in_place(); + //TODO: There is a crash caused by a spell with CAST_FLAG_RUNE_LIST casted by a creature //The creature is the mover of a player, so HandleCastSpellOpcode uses it as the caster if (Player* player = m_caster->ToPlayer()) { - data << uint8(m_runesState); // runes state before - data << uint8(player->GetRunesState()); // runes state after + castData.RemainingRunes->Start = m_runesState; // runes state before + castData.RemainingRunes->Count = player->GetRunesState(); // runes state after for (uint8 i = 0; i < MAX_RUNES; ++i) { // float casts ensure the division is performed on floats as we need float result float baseCd = float(uint32(RUNE_BASE_COOLDOWN)); - data << uint8((baseCd - float(player->GetRuneCooldown(i))) / baseCd * 255); // rune cooldown passed + castData.RemainingRunes->Cooldowns.push_back((baseCd - float(player->GetRuneCooldown(i))) / baseCd * 255); // rune cooldown passed } } else { - data << uint8(0); - data << uint8(0); + castData.RemainingRunes->Start = 0; + castData.RemainingRunes->Count = 0; for (uint8 i = 0; i < MAX_RUNES; ++i) - data << uint8(0); + castData.RemainingRunes->Cooldowns.push_back(0); } } if (castFlags & CAST_FLAG_PROJECTILE) { - uint32 projectileDisplayId = 0; - uint32 projectileInventoryType = 0; - GetProjectileData(projectileDisplayId, projectileInventoryType); - data << uint32(projectileDisplayId); + castData.Ammo = boost::in_place(); + UpdateSpellCastDataAmmo(*castData.Ammo); } if (castFlags & CAST_FLAG_IMMUNITY) { - data << uint32(schoolImmunityMask); - data << uint32(mechanicImmunityMask); + castData.Immunities = boost::in_place(); + castData.Immunities->School = schoolImmunityMask; + castData.Immunities->Value = mechanicImmunityMask; } if (castFlags & CAST_FLAG_HEAL_PREDICTION) { - uint8 type = DOT; - int32 amt = 0; + uint8 predictionType = DOT; + int32 amount = 0; for (uint8 i = 0; i < MAX_SPELL_EFFECTS; i++) { if (m_spellInfo->Effects[i].Effect == SPELL_EFFECT_HEAL || m_spellInfo->Effects[i].Effect == SPELL_EFFECT_HEAL_PCT) { - type = 0; Unit* target = m_targets.GetUnitTarget() ? m_targets.GetUnitTarget() : m_caster; - amt = CalculateDamage(i, target); - amt = m_caster->SpellHealingBonusDone(target, m_spellInfo, amt, HEAL, i); - break; + int32 heal = CalculateDamage(i, target); + amount += m_caster->SpellHealingBonusDone(target, m_spellInfo, heal, HEAL, i); + predictionType = DIRECT_DAMAGE; } } - data << uint32(amt); - data << uint8(type); - if (type == DOT) - data.appendPackGUID(m_caster->GetGUID()); + castData.Predict = boost::in_place(); + castData.Predict->Points = amount; + castData.Predict->Type = predictionType; + castData.Predict->BeaconGUID = m_caster->GetGUID(); } - m_caster->SendMessageToSet(&data, true); + m_caster->SendMessageToSet(packet.Write(), true); } void Spell::SendSpellGo() @@ -4291,73 +4292,82 @@ void Spell::SendSpellGo() if (!m_spellInfo->StartRecoveryTime) castFlags |= CAST_FLAG_NO_GCD; - WorldPacket data(SMSG_SPELL_GO, 50); // guess size + WorldPackets::Spells::SpellGo packet; + WorldPackets::Spells::SpellCastData& castData = packet.Cast; if (m_CastItem) - data << m_CastItem->GetPackGUID(); + castData.CasterGUID = m_CastItem->GetGUID(); else - data << m_caster->GetPackGUID(); + castData.CasterGUID = m_caster->GetGUID(); - data << m_caster->GetPackGUID(); - data << uint8(m_cast_count); // pending spell cast? - data << uint32(m_spellInfo->Id); // spellId - data << uint32(castFlags); // cast flags - data << uint32(m_timer); - data << uint32(GameTime::GetGameTimeMS()); // timestamp + castData.CasterUnit = m_caster->GetGUID(); + castData.CastID = m_cast_count; + castData.SpellID = m_spellInfo->Id; + castData.CastFlags = castFlags; + castData.CastTime = GameTime::GetGameTimeMS(); - WriteSpellGoTargets(&data); + castData.HitInfo = boost::in_place(); + UpdateSpellCastDataTargets(*castData.HitInfo); + m_targets.Write(castData.Target); - m_targets.Write(data); + if (castFlags & CAST_FLAG_PROJECTILE) + { + castData.Ammo = boost::in_place(); + UpdateSpellCastDataAmmo(*castData.Ammo); + } if (castFlags & CAST_FLAG_POWER_LEFT_SELF) - data << uint32(m_caster->GetPower((Powers)m_spellInfo->PowerType)); + castData.RemainingPower = m_caster->GetPower((Powers)m_spellInfo->PowerType); if (castFlags & CAST_FLAG_RUNE_LIST) // rune cooldowns list { + castData.RemainingRunes = boost::in_place(); + /// @todo There is a crash caused by a spell with CAST_FLAG_RUNE_LIST cast by a creature //The creature is the mover of a player, so HandleCastSpellOpcode uses it as the caster if (Player* player = m_caster->ToPlayer()) { - data << uint8(m_runesState); // runes state before - data << uint8(player->GetRunesState()); // runes state after + castData.RemainingRunes->Start = m_runesState; // runes state before + castData.RemainingRunes->Count = player->GetRunesState(); // runes state after for (uint8 i = 0; i < MAX_RUNES; ++i) { // float casts ensure the division is performed on floats as we need float result float baseCd = float(uint32(RUNE_BASE_COOLDOWN)); - data << uint8((baseCd - float(player->GetRuneCooldown(i))) / baseCd * 255); // rune cooldown passed + castData.RemainingRunes->Cooldowns.push_back((baseCd - float(player->GetRuneCooldown(i))) / baseCd * 255); // rune cooldown passed } } + else + { + castData.RemainingRunes->Start = 0; + castData.RemainingRunes->Count = 0; + for (uint8 i = 0; i < MAX_RUNES; ++i) + castData.RemainingRunes->Cooldowns.push_back(0); + } } if (castFlags & CAST_FLAG_ADJUST_MISSILE) { - data << m_targets.GetElevation(); - data << uint32(m_delayMoment); - } - - if (castFlags & CAST_FLAG_PROJECTILE) - { - uint32 projectileDisplayId = 0; - uint32 projectileInventoryType = 0; - GetProjectileData(projectileDisplayId, projectileInventoryType); - data << uint32(projectileDisplayId); - data << uint32(projectileInventoryType); + castData.MissileTrajectory = boost::in_place(); + castData.MissileTrajectory->TravelTime = m_delayMoment; + castData.MissileTrajectory->Pitch = m_targets.GetElevation(); } if (castFlags & CAST_FLAG_VISUAL_CHAIN) { - data << uint32(0); - data << uint32(0); + castData.ProjectileVisuals = boost::in_place(); + /* + castData.ProjectileVisuals->Id[0] = 0; + castData.ProjectileVisuals->Id[1] = 0; + */ } - if (m_targets.GetTargetMask() & TARGET_FLAG_DEST_LOCATION) - { - data << uint8(0); - } + if (castData.Target.Flags & TARGET_FLAG_DEST_LOCATION) + castData.DestLocSpellCastIndex = 0; - if (m_targets.GetTargetMask() & TARGET_FLAG_EXTRA_TARGETS) + /* + if (castData.Target.Flags & TARGET_FLAG_EXTRA_TARGETS) { - data << uint32(0); // Extra targets count + data << uint32(0); // Extra targets count /* for (uint8 i = 0; i < count; ++i) { @@ -4366,147 +4376,97 @@ void Spell::SendSpellGo() data << float(0); // Target Position Z data << uint64(0); // Target Guid } - */ } + */ - m_caster->SendMessageToSet(&data, true); + m_caster->SendMessageToSet(packet.Write(), true); } -void Spell::GetProjectileData(uint32& projectileDisplayId, uint32& projectileInventoryType) +/// Writes miss and hit targets for a SMSG_SPELL_GO packet +void Spell::UpdateSpellCastDataTargets(WorldPackets::Spells::SpellHitInfo& data) +{ + // This function also fill data for channeled spells: + // m_needAliveTargetMask req for stop channeling if one target die + for (TargetInfo& targetInfo : m_UniqueTargetInfo) + { + if (targetInfo.effectMask == 0) // No effect apply - all immune add state + // possibly SPELL_MISS_IMMUNE2 for this?? + targetInfo.missCondition = SPELL_MISS_IMMUNE2; + + if (targetInfo.missCondition == SPELL_MISS_NONE) // hits + { + data.HitTargets.push_back(targetInfo.targetGUID); + m_channelTargetEffectMask |= targetInfo.effectMask; + } + else // misses + data.MissStatus.emplace_back(targetInfo.targetGUID, targetInfo.missCondition, targetInfo.reflectResult); + } + + for (GOTargetInfo const& targetInfo : m_UniqueGOTargetInfo) + data.HitTargets.push_back(targetInfo.targetGUID); // Always hits + + // Reset m_needAliveTargetMask for non channeled spell + if (!m_spellInfo->IsChanneled()) + m_channelTargetEffectMask = 0; +} + +void Spell::UpdateSpellCastDataAmmo(WorldPackets::Spells::SpellAmmo& ammo) { uint32 ammoInventoryType = 0; uint32 ammoDisplayID = 0; - uint32 nonRangedAmmoDisplayID = 0; - uint32 nonRangedAmmoInventoryType = 0; - - ItemEntry const* itemEntry = nullptr; if (m_caster->GetTypeId() == TYPEID_PLAYER) { - if (Item* item = m_caster->ToPlayer()->GetWeaponForAttack(RANGED_ATTACK)) - itemEntry = sItemStore.LookupEntry(item->GetTemplate()->ItemId); + Item* pItem = m_caster->ToPlayer()->GetWeaponForAttack(RANGED_ATTACK); + if (pItem) + { + ammoInventoryType = pItem->GetTemplate()->InventoryType; + if (ammoInventoryType == INVTYPE_THROWN) + ammoDisplayID = pItem->GetTemplate()->DisplayInfoID; + else if (m_caster->HasAura(46699)) // Requires No Ammo + { + ammoDisplayID = 5996; // normal arrow + ammoInventoryType = INVTYPE_AMMO; + } + } } - else if (m_caster->GetTypeId() == TYPEID_UNIT) + else { for (uint8 i = BASE_ATTACK; i < MAX_ATTACK; ++i) { if (uint32 item_id = m_caster->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID + i)) { - if (ItemEntry const* entry = sItemStore.LookupEntry(item_id)) + if (ItemEntry const* itemEntry = sItemStore.LookupEntry(item_id)) { - if (entry->Class == ITEM_CLASS_WEAPON) + if (itemEntry->Class == ITEM_CLASS_WEAPON) { - switch (entry->SubClass) + switch (itemEntry->SubClass) { case ITEM_SUBCLASS_WEAPON_THROWN: + ammoDisplayID = itemEntry->DisplayId; + ammoInventoryType = itemEntry->InventoryType; + break; case ITEM_SUBCLASS_WEAPON_BOW: case ITEM_SUBCLASS_WEAPON_CROSSBOW: - case ITEM_SUBCLASS_WEAPON_GUN: - itemEntry = entry; + ammoDisplayID = 5996; // is this need fixing? + ammoInventoryType = INVTYPE_AMMO; break; - default: + case ITEM_SUBCLASS_WEAPON_GUN: + ammoDisplayID = 5998; // is this need fixing? + ammoInventoryType = INVTYPE_AMMO; break; } + + if (ammoDisplayID) + break; } } } - - if (itemEntry) - break; } } - if (!itemEntry) - return; - - switch (itemEntry->SubClass) - { - case ITEM_SUBCLASS_WEAPON_THROWN: - ammoDisplayID = itemEntry->DisplayId; - ammoInventoryType = itemEntry->InventoryType; - break; - case ITEM_SUBCLASS_WEAPON_BOW: - case ITEM_SUBCLASS_WEAPON_CROSSBOW: - ammoDisplayID = 5996; - ammoInventoryType = INVTYPE_AMMO; - break; - case ITEM_SUBCLASS_WEAPON_GUN: - ammoDisplayID = 5998; - ammoInventoryType = INVTYPE_AMMO; - break; - default: - nonRangedAmmoDisplayID = itemEntry->DisplayId; - nonRangedAmmoInventoryType = itemEntry->InventoryType; - break; - } - - if (!ammoDisplayID && !ammoInventoryType) - { - ammoDisplayID = nonRangedAmmoDisplayID; - ammoInventoryType = nonRangedAmmoInventoryType; - } - - projectileDisplayId = ammoDisplayID; - projectileInventoryType = ammoInventoryType; -} - -/// Writes miss and hit targets for a SMSG_SPELL_GO packet -void Spell::WriteSpellGoTargets(WorldPacket* data) -{ - // This function also fill data for channeled spells: - // m_needAliveTargetMask req for stop channelig if one target die - for (std::list::iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit) - { - if ((*ihit).effectMask == 0) // No effect apply - all immuned add state - // possibly SPELL_MISS_IMMUNE2 for this?? - ihit->missCondition = SPELL_MISS_IMMUNE2; - } - - // Hit and miss target counts are both uint8, that limits us to 255 targets for each - // sending more than 255 targets crashes the client (since count sent would be wrong) - // Spells like 40647 (with a huge radius) can easily reach this limit (spell might need - // target conditions but we still need to limit the number of targets sent and keeping - // correct count for both hit and miss). - - uint32 hit = 0; - size_t hitPos = data->wpos(); - *data << (uint8)0; // placeholder - for (std::list::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end() && hit < 255; ++ihit) - { - if ((*ihit).missCondition == SPELL_MISS_NONE) // Add only hits - { - *data << uint64(ihit->targetGUID); - m_channelTargetEffectMask |=ihit->effectMask; - ++hit; - } - } - - for (std::list::const_iterator ighit = m_UniqueGOTargetInfo.begin(); ighit != m_UniqueGOTargetInfo.end() && hit < 255; ++ighit) - { - *data << uint64(ighit->targetGUID); // Always hits - ++hit; - } - - uint32 miss = 0; - size_t missPos = data->wpos(); - *data << (uint8)0; // placeholder - for (std::list::const_iterator ihit = m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end() && miss < 255; ++ihit) - { - if (ihit->missCondition != SPELL_MISS_NONE) // Add only miss - { - *data << uint64(ihit->targetGUID); - *data << uint8(ihit->missCondition); - if (ihit->missCondition == SPELL_MISS_REFLECT) - *data << uint8(ihit->reflectResult); - ++miss; - } - } - // Reset m_needAliveTargetMask for non channeled spell - if (!m_spellInfo->IsChanneled()) - m_channelTargetEffectMask = 0; - - data->put(hitPos, (uint8)hit); - data->put(missPos, (uint8)miss); + ammo.DisplayID = ammoDisplayID; + ammo.InventoryType = ammoInventoryType; } void Spell::SendLogExecute() diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 5566b1e4d3..1ace1c3e10 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -25,6 +25,16 @@ #include "SharedDefines.h" #include +namespace WorldPackets +{ + namespace Spells + { + struct SpellTargetData; + struct SpellAmmo; + struct SpellHitInfo; + } +} + class Aura; class AuraEffect; class ByteBuffer; @@ -129,7 +139,7 @@ class TC_GAME_API SpellCastTargets ~SpellCastTargets(); void Read(ByteBuffer& data, Unit* caster); - void Write(ByteBuffer& data); + void Write(WorldPackets::Spells::SpellTargetData& data); uint32 GetTargetMask() const { return m_targetMask; } void SetTargetMask(uint32 newMask) { m_targetMask = newMask; } @@ -467,8 +477,6 @@ class TC_GAME_API Spell void setState(uint32 state) { m_spellState = state; } void DoCreateItem(uint32 i, uint32 itemtype); - void WriteSpellGoTargets(WorldPacket* data); - void GetProjectileData(uint32& projectileDisplayId, uint32& projectileInventoryType); bool CheckEffectTarget(Unit const* target, uint32 eff, Position const* losPosition) const; bool CanAutoCast(Unit* target); @@ -729,6 +737,9 @@ class TC_GAME_API Spell void SummonGuardian(uint32 i, uint32 entry, SummonPropertiesEntry const* properties, uint32 numSummons); void CalculateJumpSpeeds(uint8 i, float dist, float & speedxy, float & speedz); + void UpdateSpellCastDataTargets(WorldPackets::Spells::SpellHitInfo& data); + void UpdateSpellCastDataAmmo(WorldPackets::Spells::SpellAmmo& data); + SpellCastResult CanOpenLock(uint32 effIndex, uint32 lockid, SkillType& skillid, int32& reqSkillValue, int32& skillValue); // -------------------------------------------