TrinityCore
Loading...
Searching...
No Matches
SpellPackets.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "SpellPackets.h"
19#include "SharedDefines.h"
20#include "Spell.h"
21#include "SpellInfo.h"
22#include <span>
23
25{
30
35
41
43{
44 data << uint32(initialSpell.SpellID);
45 data << uint16(initialSpell.ActionBarSlot);
46
47 return data;
48}
49
51{
52 data << uint32(historyEntry.SpellID);
53 data << uint16(historyEntry.ItemID);
54 data << uint16(historyEntry.Category);
55
56 // send infinity cooldown in special format
57 if (historyEntry.OnHold)
58 {
59 data << uint32(1);
60 data << uint32(0x80000000);
61 }
62 else
63 {
64 data << int32(historyEntry.RecoveryTime);
65 data << int32(historyEntry.CategoryRecoveryTime);
66 }
67
68 return data;
69}
70
72{
74 _worldPacket << uint16(Spells.size());
75 for (InitialSpell const& spell : Spells)
76 _worldPacket << spell;
77
81
82 return &_worldPacket;
83}
84
86{
87 data << targetLocation.Transport.WriteAsPacked(); // relative position guid here - transport for example
88 data << targetLocation.Location.PositionXYZStream();
89 return data;
90}
91
93{
94 data << uint32(spellTargetData.Flags);
95
96 if (spellTargetData.Unit)
97 data << spellTargetData.Unit->WriteAsPacked();
98
99 if (spellTargetData.Item)
100 data << spellTargetData.Item->WriteAsPacked();
101
102 if (spellTargetData.SrcLocation)
103 data << *spellTargetData.SrcLocation;
104
105 if (spellTargetData.DstLocation)
106 data << *spellTargetData.DstLocation;
107
108 if (spellTargetData.Name)
109 data << *spellTargetData.Name;
110
111 return data;
112}
113
115{
116 data << spellMissStatus.TargetGUID;
117 data << uint8(spellMissStatus.Reason);
119 data << uint8(spellMissStatus.ReflectStatus);
120
121 return data;
122}
123
125{
126 data << uint8(runeData.Start);
127 data << uint8(runeData.Count);
128 for (uint8 cooldown : runeData.Cooldowns)
129 data << uint8(cooldown);
130
131 return data;
132}
133
135{
136 data << float(traj.Pitch);
137 data << uint32(traj.TravelTime);
138 return data;
139}
140
142{
143 data << uint32(spellAmmo.DisplayID);
144 data << uint32(spellAmmo.InventoryType);
145 return data;
146}
147
149{
150 data << uint32(immunities.School);
151 data << uint32(immunities.Value);
152 return data;
153}
154
156{
157 data << spellCastData.CasterGUID.WriteAsPacked();
158 data << spellCastData.CasterUnit.WriteAsPacked();
159 data << uint8(spellCastData.CastID); // pending spell cast?
160 data << uint32(spellCastData.SpellID); // spellId
161 data << uint32(spellCastData.CastFlags); // cast flags
162 data << uint32(spellCastData.CastTime); // timestamp
163
164 if (spellCastData.HitTargets && spellCastData.MissStatus)
165 {
166 // Hit and miss target counts are both uint8, that limits us to 255 targets for each
167 // sending more than 255 targets crashes the client (since count sent would be wrong)
168 // Spells like 40647 (with a huge radius) can easily reach this limit (spell might need
169 // target conditions but we still need to limit the number of targets sent and keeping
170 // correct count for both hit and miss).
171 static constexpr std::size_t PACKET_TARGET_LIMIT = std::numeric_limits<uint8>::max();
172
173 std::span<ObjectGuid const> hitTargets(spellCastData.HitTargets->data(), std::min(spellCastData.HitTargets->size(), PACKET_TARGET_LIMIT));
174 data << uint8(hitTargets.size());
175 for (ObjectGuid const& target : hitTargets)
176 data << target;
177
178 std::span<SpellMissStatus const> missTargets(spellCastData.MissStatus->data(), std::min(spellCastData.MissStatus->size(), PACKET_TARGET_LIMIT));
179 data << uint8(missTargets.size());
180 for (SpellMissStatus const& status : missTargets)
181 data << status;
182 }
183
184 data << spellCastData.Target;
185
186 if (spellCastData.RemainingPower)
187 data << uint32(*spellCastData.RemainingPower);
188
189 if (spellCastData.RemainingRunes)
190 data << *spellCastData.RemainingRunes;
191
192 if (spellCastData.MissileTrajectory)
193 data << *spellCastData.MissileTrajectory;
194
195 if (spellCastData.Ammo)
196 data << *spellCastData.Ammo;
197
198 if (spellCastData.Immunities)
199 data << *spellCastData.Immunities;
200
202 {
203 data << uint32(0);
204 data << uint32(0);
205 }
206
207 if (spellCastData.DestLocSpellCastIndex)
208 data << uint8(*spellCastData.DestLocSpellCastIndex);
209
210 if (spellCastData.TargetPoints)
211 {
212 data << int32(spellCastData.TargetPoints->size());
213 for (TargetLocation const& targetPoint : *spellCastData.TargetPoints)
214 {
215 data << targetPoint.Location.PositionXYZStream();
216 data << targetPoint.Transport;
217 }
218 }
219
220 return data;
221}
222
224{
226
227 return &_worldPacket;
228}
229
231{
233
234 return &_worldPacket;
235}
236
244
246{
249}
250
252{
254 for (ResyncRune const& rune : Runes)
255 {
256 _worldPacket << rune.RuneType;
257 _worldPacket << rune.Cooldown;
258 }
259
260 return &_worldPacket;
261}
262
264{
266
267 return &_worldPacket;
268}
269}
uint8_t uint8
Definition Define.h:135
int32_t int32
Definition Define.h:129
uint16_t uint16
Definition Define.h:134
uint32_t uint32
Definition Define.h:133
Spells
Definition PlayerAI.cpp:32
@ SPELL_MISS_REFLECT
@ CAST_FLAG_VISUAL_CHAIN
Definition Spell.h:97
size_type size() const
WorldPacket _worldPacket
Definition Packet.h:42
std::vector< InitialSpell > Spells
std::vector< SpellHistoryEntry > SpellHistory
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket const * Write() override
std::vector< ResyncRune > Runes
WorldPacket const * Write() override
WorldPacket const * Write() override
ByteBuffer & operator<<(ByteBuffer &data, InitialSpell const &initialSpell)