TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BattlePetMgr Class Reference

#include <BattlePetMgr.h>

Classes

struct  BattlePet
 

Public Member Functions

 BattlePetMgr (WorldSession *owner)
 
void LoadFromDB (PreparedQueryResult pets, PreparedQueryResult slots)
 
void SaveToDB (SQLTransaction &trans)
 
BattlePetGetPet (ObjectGuid guid)
 
void AddPet (uint32 species, uint32 creatureId, uint16 breed, uint8 quality, uint16 level=1)
 
void RemovePet (ObjectGuid guid)
 
uint8 GetPetCount (uint32 species) const
 
WorldPackets::BattlePet::BattlePetSlotGetSlot (uint8 slot)
 
void UnlockSlot (uint8 slot)
 
WorldSessionGetOwner () const
 
uint16 GetTrapLevel () const
 
std::vector< BattlePetGetLearnedPets () const
 
std::vector
< WorldPackets::BattlePet::BattlePetSlot
GetSlots () const
 
void CageBattlePet (ObjectGuid guid)
 
void HealBattlePetsPct (uint8 pct)
 
void SummonPet (ObjectGuid guid)
 
void SendUpdates (std::vector< BattlePet > pets, bool petAdded)
 
void SendError (BattlePetError error, uint32 creatureId)
 

Static Public Member Functions

static void Initialize ()
 
static uint16 RollPetBreed (uint32 species)
 
static uint8 GetDefaultPetQuality (uint32 species)
 

Static Private Member Functions

static void LoadAvailablePetBreeds ()
 
static void LoadDefaultPetQualities ()
 

Private Attributes

WorldSession_owner
 
uint16 _trapLevel = 0
 
std::unordered_map< uint64,
BattlePet
_pets
 
std::vector
< WorldPackets::BattlePet::BattlePetSlot
_slots
 

Static Private Attributes

static std::unordered_map
< uint16, std::unordered_map
< BattlePetState, int32,
std::hash
< std::underlying_type
< BattlePetState >::type > > > 
_battlePetBreedStates
 
static std::unordered_map
< uint32, std::unordered_map
< BattlePetState, int32,
std::hash
< std::underlying_type
< BattlePetState >::type > > > 
_battlePetSpeciesStates
 
static std::unordered_map
< uint32, std::unordered_set
< uint8 > > 
_availableBreedsPerSpecies
 
static std::unordered_map
< uint32, uint8
_defaultQualityPerSpecies
 

Constructor & Destructor Documentation

BattlePetMgr::BattlePetMgr ( WorldSession owner)
explicit
173 {
174  _owner = owner;
175  for (uint8 i = 0; i < MAX_PET_BATTLE_SLOTS; ++i)
176  {
178  slot.Index = i;
179  _slots.push_back(slot);
180  }
181 }
uint8 Index
Definition: BattlePetPackets.h:52
WorldSession * _owner
Definition: BattlePetMgr.h:128
Definition: BattlePetMgr.h:26
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:131
Definition: BattlePetPackets.h:48
uint8_t uint8
Definition: Define.h:152

Member Function Documentation

void BattlePetMgr::AddPet ( uint32  species,
uint32  creatureId,
uint16  breed,
uint8  quality,
uint16  level = 1 
)
311 {
312  BattlePetSpeciesEntry const* battlePetSpecies = sBattlePetSpeciesStore.LookupEntry(species);
313  if (!battlePetSpecies) // should never happen
314  return;
315 
316  BattlePet pet;
317  pet.PacketInfo.Guid = ObjectGuid::Create<HighGuid::BattlePet>(sObjectMgr->GetGenerator<HighGuid::BattlePet>().Generate());
318  pet.PacketInfo.Species = species;
319  pet.PacketInfo.CreatureID = creatureId;
320  pet.PacketInfo.Level = level;
321  pet.PacketInfo.Exp = 0;
322  pet.PacketInfo.Flags = 0;
323  pet.PacketInfo.Breed = breed;
324  pet.PacketInfo.Quality = quality;
325  pet.PacketInfo.Name = "";
326  pet.CalculateStats();
327  pet.PacketInfo.Health = pet.PacketInfo.MaxHealth;
328  pet.SaveInfo = BATTLE_PET_NEW;
329 
330  _pets[pet.PacketInfo.Guid.GetCounter()] = pet;
331 
332  std::vector<BattlePet> updates;
333  updates.push_back(pet);
334  SendUpdates(updates, true);
335 
336  _owner->GetPlayer()->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_OWN_BATTLE_PET, species);
337 }
Definition: DB2Structure.h:89
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:130
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesFormat, HOTFIX_SEL_BATTLE_PET_SPECIES)
Player * GetPlayer() const
Definition: WorldSession.h:927
#define sObjectMgr
Definition: ObjectMgr.h:1567
WorldSession * _owner
Definition: BattlePetMgr.h:128
Definition: BattlePetMgr.h:79
void SendUpdates(std::vector< BattlePet > pets, bool petAdded)
Definition: BattlePetMgr.cpp:453

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlePetMgr::CageBattlePet ( ObjectGuid  guid)
388 {
389  BattlePet* pet = GetPet(guid);
390  if (!pet)
391  return;
392 
393  ItemPosCountVec dest;
394 
395  if (_owner->GetPlayer()->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, BATTLE_PET_CAGE_ITEM_ID, 1) != EQUIP_ERR_OK)
396  return;
397 
398  Item* item = _owner->GetPlayer()->StoreNewItem(dest, BATTLE_PET_CAGE_ITEM_ID, true);
399  if (!item)
400  return;
401 
402  item->SetModifier(ITEM_MODIFIER_BATTLE_PET_SPECIES_ID, pet->PacketInfo.Species);
403  item->SetModifier(ITEM_MODIFIER_BATTLE_PET_BREED_DATA, pet->PacketInfo.Breed | (pet->PacketInfo.Quality << 24));
404  item->SetModifier(ITEM_MODIFIER_BATTLE_PET_LEVEL, pet->PacketInfo.Level);
405  item->SetModifier(ITEM_MODIFIER_BATTLE_PET_DISPLAY_ID, pet->PacketInfo.CreatureID);
406 
407  // FIXME: "You create: ." - item name missing in chat
408  _owner->GetPlayer()->SendNewItem(item, 1, true, true);
409 
410  RemovePet(guid);
411 
413  deletePet.PetGuid = guid;
414  _owner->SendPacket(deletePet.Write());
415 }
ObjectGuid PetGuid
Definition: BattlePetPackets.h:170
Definition: Unit.h:379
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldPacket const * Write() override
Definition: BattlePetPackets.cpp:152
Definition: Item.h:48
Definition: Unit.h:378
WorldSession * _owner
Definition: BattlePetMgr.h:128
void RemovePet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:339
Definition: Item.h:259
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:211
void SetModifier(ItemModifier modifier, uint32 value)
Definition: Item.cpp:1909
Definition: Item.h:229
Definition: BattlePetPackets.h:163
Definition: BattlePetMgr.h:28
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:301

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint8 BattlePetMgr::GetDefaultPetQuality ( uint32  species)
static
164 {
165  auto itr = _defaultQualityPerSpecies.find(species);
166  if (itr == _defaultQualityPerSpecies.end())
167  return 0; // default poor
168 
169  return itr->second;
170 }
static std::unordered_map< uint32, uint8 > _defaultQualityPerSpecies
Definition: BattlePetMgr.h:140

+ Here is the caller graph for this function:

std::vector< BattlePetMgr::BattlePet > BattlePetMgr::GetLearnedPets ( ) const
378 {
379  std::vector<BattlePet> pets;
380  for (auto& pet : _pets)
381  if (pet.second.SaveInfo != BATTLE_PET_REMOVED)
382  pets.push_back(pet.second);
383 
384  return pets;
385 }
Definition: BattlePetMgr.h:80
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:130

+ Here is the caller graph for this function:

WorldSession* BattlePetMgr::GetOwner ( ) const
inline
113 { return _owner; }
WorldSession * _owner
Definition: BattlePetMgr.h:128
BattlePetMgr::BattlePet * BattlePetMgr::GetPet ( ObjectGuid  guid)
302 {
303  auto itr = _pets.find(guid.GetCounter());
304  if (itr != _pets.end())
305  return &itr->second;
306 
307  return nullptr;
308 }
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:130
LowType GetCounter() const
Definition: ObjectGuid.h:221

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint8 BattlePetMgr::GetPetCount ( uint32  species) const
354 {
355  uint8 count = 0;
356  for (auto& itr : _pets)
357  if (itr.second.PacketInfo.Species == species && itr.second.SaveInfo != BATTLE_PET_REMOVED)
358  count++;
359 
360  return count;
361 }
Definition: BattlePetMgr.h:80
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:130
uint8_t uint8
Definition: Define.h:152

+ Here is the caller graph for this function:

WorldPackets::BattlePet::BattlePetSlot* BattlePetMgr::GetSlot ( uint8  slot)
inline
110 { return &_slots[slot]; }
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:131

+ Here is the caller graph for this function:

std::vector<WorldPackets::BattlePet::BattlePetSlot> BattlePetMgr::GetSlots ( ) const
inline
117 { return _slots; }
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:131

+ Here is the caller graph for this function:

uint16 BattlePetMgr::GetTrapLevel ( ) const
inline
115 { return _trapLevel; }
uint16 _trapLevel
Definition: BattlePetMgr.h:129

+ Here is the caller graph for this function:

void BattlePetMgr::HealBattlePetsPct ( uint8  pct)
418 {
419  // TODO: After each Pet Battle, any injured companion will automatically
420  // regain 50 % of the damage that was taken during combat
421  std::vector<BattlePet> updates;
422 
423  for (auto& pet : _pets)
424  if (pet.second.PacketInfo.Health != pet.second.PacketInfo.MaxHealth)
425  {
426  pet.second.PacketInfo.Health += CalculatePct(pet.second.PacketInfo.MaxHealth, pct);
427  // don't allow Health to be greater than MaxHealth
428  pet.second.PacketInfo.Health = std::min(pet.second.PacketInfo.Health, pet.second.PacketInfo.MaxHealth);
429  if (pet.second.SaveInfo != BATTLE_PET_NEW)
430  pet.second.SaveInfo = BATTLE_PET_CHANGED;
431  updates.push_back(pet.second);
432  }
433 
434  SendUpdates(updates, false);
435 }
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:130
T min(const T &x, const T &y)
Definition: g3dmath.h:305
T CalculatePct(T base, U pct)
Definition: Util.h:92
Definition: BattlePetMgr.h:79
Definition: BattlePetMgr.h:78
void SendUpdates(std::vector< BattlePet > pets, bool petAdded)
Definition: BattlePetMgr.cpp:453

+ Here is the call graph for this function:

void BattlePetMgr::Initialize ( )
static
80 {
81  if (QueryResult result = LoginDatabase.Query("SELECT MAX(guid) FROM battle_pets"))
82  sObjectMgr->GetGenerator<HighGuid::BattlePet>().Set((*result)[0].GetUInt64() + 1);
83 
84  for (auto itr : sBattlePetBreedStateStore)
85  _battlePetBreedStates[itr->BreedID][BattlePetState(itr->State)] = itr->Value;
86 
87  for (auto itr : sBattlePetSpeciesStateStore)
88  _battlePetSpeciesStates[itr->SpeciesID][BattlePetState(itr->State)] = itr->Value;
89 
92 }
static void LoadDefaultPetQualities()
Definition: BattlePetMgr.cpp:125
#define sObjectMgr
Definition: ObjectMgr.h:1567
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
static std::unordered_map< uint32, std::unordered_map< BattlePetState, int32, std::hash< std::underlying_type< BattlePetState >::type > > > _battlePetSpeciesStates
Definition: BattlePetMgr.h:138
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
DB2Storage< BattlePetSpeciesStateEntry > sBattlePetSpeciesStateStore("BattlePetSpeciesState.db2", BattlePetSpeciesStateFormat, HOTFIX_SEL_BATTLE_PET_SPECIES_STATE)
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
static std::unordered_map< uint16, std::unordered_map< BattlePetState, int32, std::hash< std::underlying_type< BattlePetState >::type > > > _battlePetBreedStates
Definition: BattlePetMgr.h:137
static void LoadAvailablePetBreeds()
Definition: BattlePetMgr.cpp:94
DB2Storage< BattlePetBreedStateEntry > sBattlePetBreedStateStore("BattlePetBreedState.db2", BattlePetBreedStateFormat, HOTFIX_SEL_BATTLE_PET_BREED_STATE)
BattlePetState
Definition: BattlePetMgr.h:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlePetMgr::LoadAvailablePetBreeds ( )
staticprivate
95 {
96  QueryResult result = WorldDatabase.Query("SELECT speciesId, breedId FROM battle_pet_breeds");
97  if (!result)
98  {
99  TC_LOG_INFO("server.loading", ">> Loaded 0 battle pet breeds. DB table `battle_pet_breeds` is empty.");
100  return;
101  }
102 
103  uint32 count = 0;
104  do
105  {
106  Field* fields = result->Fetch();
107  uint32 speciesId = fields[0].GetUInt32();
108  uint16 breedId = fields[1].GetUInt16();
109 
110  if (!sBattlePetSpeciesStore.LookupEntry(speciesId))
111  {
112  TC_LOG_ERROR("sql.sql", "Non-existing BattlePetSpecies.db2 entry %u was referenced in `battle_pet_breeds` by row (%u, %u).", speciesId, speciesId, breedId);
113  continue;
114  }
115 
116  // TODO: verify breed id (3 - 12 (male) or 3 - 22 (male and female)) if needed
117 
118  _availableBreedsPerSpecies[speciesId].insert(breedId);
119  ++count;
120  } while (result->NextRow());
121 
122  TC_LOG_INFO("server.loading", ">> Loaded %u battle pet breeds.", count);
123 }
Class used to access individual fields of database query result.
Definition: Field.h:56
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesFormat, HOTFIX_SEL_BATTLE_PET_SPECIES)
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
uint16_t uint16
Definition: Define.h:151
uint16 GetUInt16() const
Definition: Field.h:108
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
static std::unordered_map< uint32, std::unordered_set< uint8 > > _availableBreedsPerSpecies
Definition: BattlePetMgr.h:139

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlePetMgr::LoadDefaultPetQualities ( )
staticprivate
126 {
127  QueryResult result = WorldDatabase.Query("SELECT speciesId, quality FROM battle_pet_quality");
128  if (!result)
129  {
130  TC_LOG_INFO("server.loading", ">> Loaded 0 battle pet qualities. DB table `battle_pet_quality` is empty.");
131  return;
132  }
133 
134  do
135  {
136  Field* fields = result->Fetch();
137  uint32 speciesId = fields[0].GetUInt32();
138  uint8 quality = fields[1].GetUInt8();
139 
140  if (!sBattlePetSpeciesStore.LookupEntry(speciesId))
141  {
142  TC_LOG_ERROR("sql.sql", "Non-existing BattlePetSpecies.db2 entry %u was referenced in `battle_pet_quality` by row (%u, %u).", speciesId, speciesId, quality);
143  continue;
144  }
145 
146  // TODO: verify quality (0 - 3 for player pets or 0 - 5 for both player and tamer pets) if needed
147 
148  _defaultQualityPerSpecies[speciesId] = quality;
149  } while (result->NextRow());
150 
151  TC_LOG_INFO("server.loading", ">> Loaded %u battle pet qualities.", uint32(_defaultQualityPerSpecies.size()));
152 }
static std::unordered_map< uint32, uint8 > _defaultQualityPerSpecies
Definition: BattlePetMgr.h:140
Class used to access individual fields of database query result.
Definition: Field.h:56
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesFormat, HOTFIX_SEL_BATTLE_PET_SPECIES)
WorldDatabaseWorkerPool WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
uint8 GetUInt8() const
Definition: Field.h:70
uint32_t uint32
Definition: Define.h:150
std::shared_ptr< ResultSet > QueryResult
Definition: QueryResult.h:61
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
uint32 GetUInt32() const
Definition: Field.h:146
uint8_t uint8
Definition: Define.h:152
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:201
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
uint32_t uint32
Definition: g3dmath.h:168

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlePetMgr::LoadFromDB ( PreparedQueryResult  pets,
PreparedQueryResult  slots 
)
184 {
185  if (pets)
186  {
187  do
188  {
189  Field* fields = pets->Fetch();
190  uint32 species = fields[1].GetUInt32();
191 
192  if (BattlePetSpeciesEntry const* speciesEntry = sBattlePetSpeciesStore.LookupEntry(species))
193  {
195  {
196  TC_LOG_ERROR("misc", "Battlenet account with id %u has more than 3 battle pets of species %u", _owner->GetBattlenetAccountId(), species);
197  continue;
198  }
199 
200  BattlePet pet;
201  pet.PacketInfo.Guid = ObjectGuid::Create<HighGuid::BattlePet>(fields[0].GetUInt64());
202  pet.PacketInfo.Species = species;
203  pet.PacketInfo.Breed = fields[2].GetUInt16();
204  pet.PacketInfo.Level = fields[3].GetUInt16();
205  pet.PacketInfo.Exp = fields[4].GetUInt16();
206  pet.PacketInfo.Health = fields[5].GetUInt32();
207  pet.PacketInfo.Quality = fields[6].GetUInt8();
208  pet.PacketInfo.Flags = fields[7].GetUInt16();
209  pet.PacketInfo.Name = fields[8].GetString();
210  pet.PacketInfo.CreatureID = speciesEntry->CreatureID;
211  pet.SaveInfo = BATTLE_PET_UNCHANGED;
212  pet.CalculateStats();
213  _pets[pet.PacketInfo.Guid.GetCounter()] = pet;
214  }
215  } while (pets->NextRow());
216  }
217 
218  if (slots)
219  {
220  uint8 i = 0; // slots->GetRowCount() should equal MAX_BATTLE_PET_SLOTS
221 
222  do
223  {
224  Field* fields = slots->Fetch();
225  _slots[i].Index = fields[0].GetUInt8();
226  auto itr = _pets.find(fields[1].GetUInt64());
227  if (itr != _pets.end())
228  _slots[i].Pet = itr->second.PacketInfo;
229  _slots[i].Locked = fields[2].GetBool();
230  i++;
231  } while (slots->NextRow());
232  }
233 }
Definition: DB2Structure.h:89
Definition: BattlePetMgr.h:27
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:130
uint64 GetUInt64() const
Definition: Field.h:184
Class used to access individual fields of database query result.
Definition: Field.h:56
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesFormat, HOTFIX_SEL_BATTLE_PET_SPECIES)
uint32 GetBattlenetAccountId() const
Definition: WorldSession.h:925
uint8 GetUInt8() const
Definition: Field.h:70
Definition: BattlePetMgr.h:77
WorldSession * _owner
Definition: BattlePetMgr.h:128
uint32_t uint32
Definition: Define.h:150
uint16 GetUInt16() const
Definition: Field.h:108
uint8 GetPetCount(uint32 species) const
Definition: BattlePetMgr.cpp:353
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:131
uint32 GetUInt32() const
Definition: Field.h:146
uint8_t uint8
Definition: Define.h:152
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:207
bool GetBool() const
Definition: Field.h:65
std::string GetString() const
Definition: Field.h:276
Definition: Pet.h:46

+ Here is the call graph for this function:

void BattlePetMgr::RemovePet ( ObjectGuid  guid)
340 {
341  BattlePet* pet = GetPet(guid);
342  if (!pet)
343  return;
344 
345  pet->SaveInfo = BATTLE_PET_REMOVED;
346 
347  // spell is not unlearned on retail
348  /*if (GetPetCount(pet->PacketInfo.Species) == 0)
349  if (BattlePetSpeciesEntry const* speciesEntry = sBattlePetSpeciesStore.LookupEntry(pet->PacketInfo.Species))
350  _owner->GetPlayer()->RemoveSpell(speciesEntry->SummonSpellID);*/
351 }
Definition: BattlePetMgr.h:80
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:301

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint16 BattlePetMgr::RollPetBreed ( uint32  species)
static
155 {
156  auto itr = _availableBreedsPerSpecies.find(species);
157  if (itr == _availableBreedsPerSpecies.end())
158  return 3; // default B/B
159 
161 }
C::value_type const & SelectRandomContainerElement(C const &container)
Definition: Containers.h:68
static std::unordered_map< uint32, std::unordered_set< uint8 > > _availableBreedsPerSpecies
Definition: BattlePetMgr.h:139

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlePetMgr::SaveToDB ( SQLTransaction trans)
236 {
237  PreparedStatement* stmt = nullptr;
238 
239  for (auto itr = _pets.begin(); itr != _pets.end();)
240  {
241  switch (itr->second.SaveInfo)
242  {
243  case BATTLE_PET_NEW:
245  stmt->setUInt64(0, itr->first);
247  stmt->setUInt32(2, itr->second.PacketInfo.Species);
248  stmt->setUInt16(3, itr->second.PacketInfo.Breed);
249  stmt->setUInt16(4, itr->second.PacketInfo.Level);
250  stmt->setUInt16(5, itr->second.PacketInfo.Exp);
251  stmt->setUInt32(6, itr->second.PacketInfo.Health);
252  stmt->setUInt8(7, itr->second.PacketInfo.Quality);
253  stmt->setUInt16(8, itr->second.PacketInfo.Flags);
254  stmt->setString(9, itr->second.PacketInfo.Name);
255  trans->Append(stmt);
256  itr->second.SaveInfo = BATTLE_PET_UNCHANGED;
257  ++itr;
258  break;
259  case BATTLE_PET_CHANGED:
261  stmt->setUInt16(0, itr->second.PacketInfo.Level);
262  stmt->setUInt16(1, itr->second.PacketInfo.Exp);
263  stmt->setUInt32(2, itr->second.PacketInfo.Health);
264  stmt->setUInt8(3, itr->second.PacketInfo.Quality);
265  stmt->setUInt16(4, itr->second.PacketInfo.Flags);
266  stmt->setString(5, itr->second.PacketInfo.Name);
268  stmt->setUInt64(7, itr->first);
269  trans->Append(stmt);
270  itr->second.SaveInfo = BATTLE_PET_UNCHANGED;
271  ++itr;
272  break;
273  case BATTLE_PET_REMOVED:
276  stmt->setUInt64(1, itr->first);
277  trans->Append(stmt);
278  itr = _pets.erase(itr);
279  break;
280  default:
281  ++itr;
282  break;
283  }
284  }
285 
288  trans->Append(stmt);
289 
291  {
293  stmt->setUInt8(0, slot.Index);
295  stmt->setUInt64(2, slot.Pet.Guid.GetCounter());
296  stmt->setBool(3, slot.Locked);
297  trans->Append(stmt);
298  }
299 }
Definition: LoginDatabase.h:144
Definition: BattlePetMgr.h:80
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:130
void setUInt8(const uint8 index, const uint8 value)
Definition: PreparedStatement.cpp:97
Definition: LoginDatabase.h:141
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
uint32 GetBattlenetAccountId() const
Definition: WorldSession.h:925
Definition: PreparedStatement.h:74
Definition: LoginDatabase.h:143
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
void setBool(const uint8 index, const bool value)
Definition: PreparedStatement.cpp:88
Definition: BattlePetMgr.h:77
WorldSession * _owner
Definition: BattlePetMgr.h:128
Definition: LoginDatabase.h:140
void setUInt16(const uint8 index, const uint16 value)
Definition: PreparedStatement.cpp:106
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
Definition: BattlePetMgr.h:79
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:131
Definition: BattlePetPackets.h:48
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:124
Definition: LoginDatabase.h:139
Definition: BattlePetMgr.h:78

+ Here is the call graph for this function:

void BattlePetMgr::SendError ( BattlePetError  error,
uint32  creatureId 
)
464 {
466  battlePetError.Result = error;
467  battlePetError.CreatureID = creatureId;
468  _owner->SendPacket(battlePetError.Write());
469 }
WorldSession * _owner
Definition: BattlePetMgr.h:128
uint8 Result
Definition: BattlePetPackets.h:180
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:211
Definition: BattlePetPackets.h:173
WorldPacket const * Write() override
Definition: BattlePetPackets.cpp:159
uint32 CreatureID
Definition: BattlePetPackets.h:181

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlePetMgr::SendUpdates ( std::vector< BattlePet pets,
bool  petAdded 
)
454 {
456  for (auto pet : pets)
457  updates.Pets.push_back(pet.PacketInfo);
458 
459  updates.PetAdded = petAdded;
460  _owner->SendPacket(updates.Write());
461 }
Definition: BattlePetPackets.h:85
bool PetAdded
Definition: BattlePetPackets.h:93
std::vector< BattlePet > Pets
Definition: BattlePetPackets.h:92
WorldSession * _owner
Definition: BattlePetMgr.h:128
WorldPacket const * Write() override
Definition: BattlePetPackets.cpp:82
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:211

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlePetMgr::SummonPet ( ObjectGuid  guid)
438 {
439  BattlePet* pet = GetPet(guid);
440  if (!pet)
441  return;
442 
443  BattlePetSpeciesEntry const* speciesEntry = sBattlePetSpeciesStore.LookupEntry(pet->PacketInfo.Species);
444  if (!speciesEntry)
445  return;
446 
447  // TODO: set proper CreatureID for spell DEFAULT_SUMMON_BATTLE_PET_SPELL (default EffectMiscValueA is 40721 - Murkimus the Gladiator)
448  _owner->GetPlayer()->CastSpell(_owner->GetPlayer(), speciesEntry->SummonSpellID ? speciesEntry->SummonSpellID : uint32(DEFAULT_SUMMON_BATTLE_PET_SPELL));
449 
450  // TODO: set pet level, quality... update fields
451 }
Definition: DB2Structure.h:89
uint32 SummonSpellID
Definition: DB2Structure.h:94
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesFormat, HOTFIX_SEL_BATTLE_PET_SPECIES)
Player * GetPlayer() const
Definition: WorldSession.h:927
WorldSession * _owner
Definition: BattlePetMgr.h:128
Definition: BattlePetMgr.h:29
uint32_t uint32
Definition: g3dmath.h:168
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:301

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void BattlePetMgr::UnlockSlot ( uint8  slot)
364 {
365  if (!_slots[slot].Locked)
366  return;
367 
368  _slots[slot].Locked = false;
369 
371  updates.Slots.push_back(_slots[slot]);
372  updates.AutoSlotted = false; // what's this?
373  updates.NewSlot = true; // causes the "new slot unlocked" bubble to appear
374  _owner->SendPacket(updates.Write());
375 }
bool NewSlot
Definition: BattlePetPackets.h:105
WorldSession * _owner
Definition: BattlePetMgr.h:128
WorldPacket const * Write() override
Definition: BattlePetPackets.cpp:96
bool AutoSlotted
Definition: BattlePetPackets.h:104
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:211
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:131
Definition: BattlePetPackets.h:96
std::vector< BattlePetSlot > Slots
Definition: BattlePetPackets.h:103

+ Here is the call graph for this function:

Member Data Documentation

std::unordered_map< uint32, std::unordered_set< uint8 > > BattlePetMgr::_availableBreedsPerSpecies
staticprivate
std::unordered_map< uint16, std::unordered_map< BattlePetState, int32, std::hash< std::underlying_type< BattlePetState >::type > > > BattlePetMgr::_battlePetBreedStates
staticprivate
std::unordered_map< uint32, std::unordered_map< BattlePetState, int32, std::hash< std::underlying_type< BattlePetState >::type > > > BattlePetMgr::_battlePetSpeciesStates
staticprivate
std::unordered_map< uint32, uint8 > BattlePetMgr::_defaultQualityPerSpecies
staticprivate
WorldSession* BattlePetMgr::_owner
private
std::unordered_map<uint64 , BattlePet> BattlePetMgr::_pets
private
std::vector<WorldPackets::BattlePet::BattlePetSlot> BattlePetMgr::_slots
private
uint16 BattlePetMgr::_trapLevel = 0
private

The documentation for this class was generated from the following files: