TrinityCore
BattlePetPackets.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 "BattlePetPackets.h"
19
21{
22 data << (slot.Pet.Guid.IsEmpty() ? ObjectGuid::Create<HighGuid::BattlePet>(0) : slot.Pet.Guid);
23 data << uint32(slot.CollarID);
24 data << uint8(slot.Index);
25 data.WriteBit(slot.Locked);
26 data.FlushBits();
27
28 return data;
29}
30
32{
33 data << pet.Guid;
34 data << uint32(pet.Species);
35 data << uint32(pet.CreatureID);
36 data << uint32(pet.DisplayID);
37 data << uint16(pet.Breed);
38 data << uint16(pet.Level);
39 data << uint16(pet.Exp);
40 data << uint16(pet.Flags);
41 data << uint32(pet.Power);
42 data << uint32(pet.Health);
43 data << uint32(pet.MaxHealth);
44 data << uint32(pet.Speed);
45 data << uint8(pet.Quality);
46 data.WriteBits(pet.Name.size(), 7);
47 data.WriteBit(pet.OwnerInfo.has_value());
48 data.WriteBit(false); // NoRename
49 data.FlushBits();
50
51 data.WriteString(pet.Name);
52
53 if (pet.OwnerInfo)
54 {
55 data << pet.OwnerInfo->Guid;
56 data << uint32(pet.OwnerInfo->PlayerVirtualRealm);
57 data << uint32(pet.OwnerInfo->PlayerNativeRealm);
58 }
59
60 return data;
61}
62
64{
66 _worldPacket << uint32(Slots.size());
67 _worldPacket << uint32(Pets.size());
70
71 for (BattlePetSlot const& slot : Slots)
72 _worldPacket << slot;
73
74 for (BattlePet const& pet : Pets)
75 _worldPacket << pet;
76
77 return &_worldPacket;
78}
79
81{
82 _worldPacket << uint32(Pets.size());
83 _worldPacket.WriteBit(PetAdded);
84 _worldPacket.FlushBits();
85
86 for (BattlePet const& pet : Pets)
87 _worldPacket << pet;
88
89 return &_worldPacket;
90}
91
93{
94 _worldPacket << uint32(Slots.size());
95 _worldPacket.WriteBit(NewSlot);
96 _worldPacket.WriteBit(AutoSlotted);
97 _worldPacket.FlushBits();
98
99 for (auto const& slot : Slots)
100 _worldPacket << slot;
101
102 return &_worldPacket;
103}
104
106{
107 _worldPacket >> PetGuid;
108 _worldPacket >> Slot;
109}
110
112{
113 _worldPacket >> PetGuid;
114 uint32 nameLength = _worldPacket.ReadBits(7);
115 bool hasDeclinedNames = _worldPacket.ReadBit();
116
117 if (hasDeclinedNames)
118 {
119 DeclinedNames = std::make_unique<DeclinedName>();
120 uint8 declinedNameLengths[MAX_DECLINED_NAME_CASES];
121
122 for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
123 declinedNameLengths[i] = _worldPacket.ReadBits(7);
124
125 for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
126 DeclinedNames->name[i] = _worldPacket.ReadString(declinedNameLengths[i]);
127 }
128
129 Name = _worldPacket.ReadString(nameLength);
130}
131
133{
134 _worldPacket >> BattlePetID;
135 _worldPacket >> UnitGUID;
136}
137
139{
140 _worldPacket << BattlePetID;
141 _worldPacket << int32(CreatureID);
142 _worldPacket << Timestamp;
143
144 _worldPacket.WriteBit(Allow);
145
146 if (Allow)
147 {
148 _worldPacket.WriteBits(Name.length(), 8);
149 _worldPacket.WriteBit(HasDeclined);
150
151 for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
152 _worldPacket.WriteBits(DeclinedNames.name[i].length(), 7);
153
154 for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
155 _worldPacket.WriteString(DeclinedNames.name[i]);
156
157 _worldPacket.WriteString(Name);
158 }
159
160 _worldPacket.FlushBits();
161
162 return &_worldPacket;
163}
164
166{
167 _worldPacket >> PetGuid;
168}
169
171{
172 _worldPacket >> PetGuid;
173 _worldPacket >> Flags;
174 ControlType = _worldPacket.ReadBits(2);
175}
176
178{
179 _worldPacket >> PetGuid;
180}
181
183{
184 _worldPacket >> PetGuid;
185}
186
188{
189 _worldPacket << PetGuid;
190
191 return &_worldPacket;
192}
193
195{
196 _worldPacket.WriteBits(Result, 4);
197 _worldPacket << int32(CreatureID);
198
199 return &_worldPacket;
200}
201
203{
204 _worldPacket >> PetGuid;
205}
206
208{
209 _worldPacket >> PetGuid;
210}
ByteBuffer & operator<<(ByteBuffer &data, WorldPackets::BattlePet::BattlePetSlot const &slot)
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
#define MAX_DECLINED_NAME_CASES
Definition: UnitDefines.h:484
void WriteString(std::string const &str)
Definition: ByteBuffer.h:500
bool WriteBit(bool bit)
Definition: ByteBuffer.h:175
void WriteBits(std::size_t value, int32 bits)
Definition: ByteBuffer.h:203
void FlushBits()
Definition: ByteBuffer.h:155
bool IsEmpty() const
Definition: ObjectGuid.h:319
WorldPacket const * Write() override
WorldPacket const * Write() override
WorldPacket const * Write() override
std::vector< std::reference_wrapper< BattlePet > > Pets
std::vector< std::reference_wrapper< BattlePetSlot > > Slots
WorldPacket const * Write() override
WorldPacket _worldPacket
Definition: Packet.h:43
Optional< BattlePetOwnerInfo > OwnerInfo