TrinityCore
BattlePets::BattlePetMgr Class Reference

#include <BattlePetMgr.h>

Public Member Functions

 BattlePetMgr (WorldSession *owner)
 
 BattlePetMgr (BattlePetMgr const &right)=delete
 
 BattlePetMgr (BattlePetMgr &&right)=delete
 
void LoadFromDB (PreparedQueryResult pets, PreparedQueryResult slots)
 
void SaveToDB (LoginDatabaseTransaction trans)
 
BattlePetGetPet (ObjectGuid guid)
 
void AddPet (uint32 species, uint32 display, uint16 breed, BattlePetBreedQuality quality, uint16 level=1)
 
void RemovePet (ObjectGuid guid)
 
void ClearFanfare (ObjectGuid guid)
 
void ModifyName (ObjectGuid guid, std::string const &name, std::unique_ptr< DeclinedName > declinedName)
 
bool IsPetInSlot (ObjectGuid guid)
 
uint8 GetPetCount (BattlePetSpeciesEntry const *battlePetSpecies, ObjectGuid ownerGuid) const
 
bool HasMaxPetCount (BattlePetSpeciesEntry const *battlePetSpecies, ObjectGuid ownerGuid) const
 
uint32 GetPetUniqueSpeciesCount () const
 
WorldPackets::BattlePet::BattlePetSlotGetSlot (BattlePetSlot slot)
 
void UnlockSlot (BattlePetSlot slot)
 
WorldSessionGetOwner () const
 
uint16 GetTrapLevel () const
 
uint16 GetMaxPetLevel () const
 
std::vector< WorldPackets::BattlePet::BattlePetSlot > const & GetSlots () const
 
void CageBattlePet (ObjectGuid guid)
 
void ChangeBattlePetQuality (ObjectGuid guid, BattlePetBreedQuality quality)
 
void GrantBattlePetExperience (ObjectGuid guid, uint16 xp, BattlePetXpSource xpSource)
 
void GrantBattlePetLevel (ObjectGuid guid, uint16 grantedLevels)
 
void HealBattlePetsPct (uint8 pct)
 
void UpdateBattlePetData (ObjectGuid guid)
 
void SummonPet (ObjectGuid guid)
 
void DismissPet ()
 
void SendJournal ()
 
void SendUpdates (std::vector< std::reference_wrapper< BattlePet >> pets, bool petAdded)
 
void SendError (BattlePetError error, uint32 creatureId)
 
void SendJournalLockStatus ()
 
bool IsJournalLockAcquired () const
 
bool HasJournalLock () const
 
void ToggleJournalLock (bool lock)
 
bool IsBattlePetSystemEnabled ()
 

Static Public Member Functions

static void Initialize ()
 
static void AddBattlePetSpeciesBySpell (uint32 spellId, BattlePetSpeciesEntry const *speciesEntry)
 
static BattlePetSpeciesEntry const * GetBattlePetSpeciesByCreature (uint32 creatureId)
 
static BattlePetSpeciesEntry const * GetBattlePetSpeciesBySpell (uint32 spellId)
 
static uint16 RollPetBreed (uint32 species)
 
static BattlePetBreedQuality GetDefaultPetQuality (uint32 species)
 
static uint32 SelectPetDisplay (BattlePetSpeciesEntry const *speciesEntry)
 

Static Private Member Functions

static void LoadAvailablePetBreeds ()
 
static void LoadDefaultPetQualities ()
 

Private Attributes

WorldSession_owner
 
bool _hasJournalLock = false
 
uint16 _trapLevel = 0
 
std::unordered_map< uint64, BattlePet_pets
 
std::vector< WorldPackets::BattlePet::BattlePetSlot_slots
 

Constructor & Destructor Documentation

◆ BattlePetMgr() [1/3]

BattlePets::BattlePetMgr::BattlePetMgr ( WorldSession owner)
explicit
230 {
231  _owner = owner;
232  for (uint8 i = 0; i < AsUnderlyingType(BattlePetSlot::Count); ++i)
233  {
235  slot.Index = i;
236  _slots.push_back(slot);
237  }
238 }
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:473
uint8 Index
Definition: BattlePetPackets.h:62
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:212
WorldSession * _owner
Definition: BattlePetMgr.h:208
Definition: BattlePetPackets.h:58
uint8_t uint8
Definition: Define.h:145
+ Here is the call graph for this function:

◆ BattlePetMgr() [2/3]

BattlePets::BattlePetMgr::BattlePetMgr ( BattlePetMgr const &  right)
delete

◆ BattlePetMgr() [3/3]

BattlePets::BattlePetMgr::BattlePetMgr ( BattlePetMgr &&  right)
delete

Member Function Documentation

◆ AddBattlePetSpeciesBySpell()

void BattlePets::BattlePetMgr::AddBattlePetSpeciesBySpell ( uint32  spellId,
BattlePetSpeciesEntry const *  speciesEntry 
)
static
187 {
188  _battlePetSpeciesBySpell[spellId] = speciesEntry;
189 }
+ Here is the caller graph for this function:

◆ AddPet()

void BattlePets::BattlePetMgr::AddPet ( uint32  species,
uint32  display,
uint16  breed,
BattlePetBreedQuality  quality,
uint16  level = 1 
)
450 {
451  BattlePetSpeciesEntry const* battlePetSpecies = sBattlePetSpeciesStore.LookupEntry(species);
452  if (!battlePetSpecies) // should never happen
453  return;
454 
455  if (!battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::WellKnown)) // Not learnable
456  return;
457 
458  BattlePet pet;
459  pet.PacketInfo.Guid = ObjectGuid::Create<HighGuid::BattlePet>(sObjectMgr->GetGenerator<HighGuid::BattlePet>().Generate());
460  pet.PacketInfo.Species = species;
461  pet.PacketInfo.CreatureID = battlePetSpecies->CreatureID;
462  pet.PacketInfo.DisplayID = display;
463  pet.PacketInfo.Level = level;
464  pet.PacketInfo.Exp = 0;
465  pet.PacketInfo.Flags = 0;
466  pet.PacketInfo.Breed = breed;
467  pet.PacketInfo.Quality = AsUnderlyingType(quality);
468  pet.PacketInfo.Name = "";
469  pet.CalculateStats();
470  pet.PacketInfo.Health = pet.PacketInfo.MaxHealth;
471 
472  Player* player = _owner->GetPlayer();
473  if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::NotAccountWide))
474  {
475  pet.PacketInfo.OwnerInfo.emplace();
476  pet.PacketInfo.OwnerInfo->Guid = player->GetGUID();
477  pet.PacketInfo.OwnerInfo->PlayerVirtualRealm = pet.PacketInfo.OwnerInfo->PlayerNativeRealm = GetVirtualRealmAddress();
478  }
479 
480  pet.SaveInfo = BATTLE_PET_NEW;
481 
482  _pets[pet.PacketInfo.Guid.GetCounter()] = std::move(pet);
483 
484  std::vector<std::reference_wrapper<BattlePet>> updates;
485  updates.push_back(std::ref(pet));
486  SendUpdates(std::move(updates), true);
487 
490 }
Definition: DB2Structure.h:468
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:473
int32 CreatureID
Definition: DB2Structure.h:473
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesLoadInfo::Instance())
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:156
Definition: BattlePetMgr.h:133
#define sObjectMgr
Definition: ObjectMgr.h:1967
void UpdateCriteria(CriteriaType type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, WorldObject *ref=nullptr)
Definition: Player.cpp:26905
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:211
WorldSession * _owner
Definition: BattlePetMgr.h:208
void SendUpdates(std::vector< std::reference_wrapper< BattlePet >> pets, bool petAdded)
Definition: BattlePetMgr.cpp:890
EnumFlag< BattlePetSpeciesFlags > GetFlags() const
Definition: DB2Structure.h:483
Player * GetPlayer() const
Definition: WorldSession.h:1001
uint32 GetVirtualRealmAddress()
Definition: World.cpp:3960
Definition: Player.h:1131
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CageBattlePet()

void BattlePets::BattlePetMgr::CageBattlePet ( ObjectGuid  guid)
613 {
614  if (!HasJournalLock())
615  return;
616 
617  BattlePet* pet = GetPet(guid);
618  if (!pet)
619  return;
620 
621  if (BattlePetSpeciesEntry const* battlePetSpecies = sBattlePetSpeciesStore.LookupEntry(pet->PacketInfo.Species))
622  if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::NotTradable))
623  return;
624 
625  if (IsPetInSlot(guid))
626  return;
627 
628  if (pet->PacketInfo.Health < pet->PacketInfo.MaxHealth)
629  return;
630 
631  ItemPosCountVec dest;
632 
634  return;
635 
636  Item* item = _owner->GetPlayer()->StoreNewItem(dest, BATTLE_PET_CAGE_ITEM_ID, true);
637  if (!item)
638  return;
639 
640  item->SetModifier(ITEM_MODIFIER_BATTLE_PET_SPECIES_ID, pet->PacketInfo.Species);
641  item->SetModifier(ITEM_MODIFIER_BATTLE_PET_BREED_DATA, pet->PacketInfo.Breed | (pet->PacketInfo.Quality << 24));
642  item->SetModifier(ITEM_MODIFIER_BATTLE_PET_LEVEL, pet->PacketInfo.Level);
643  item->SetModifier(ITEM_MODIFIER_BATTLE_PET_DISPLAY_ID, pet->PacketInfo.DisplayID);
644 
645  _owner->GetPlayer()->SendNewItem(item, 1, true, false);
646 
647  RemovePet(guid);
648 
650  deletePet.PetGuid = guid;
651  _owner->SendPacket(deletePet.Write());
652 
653  // Battle pet despawns if it's summoned
654  Player* player = _owner->GetPlayer();
655  if (Creature* summonedBattlePet = player->GetSummonedBattlePet())
656  {
657  if (summonedBattlePet->GetBattlePetCompanionGUID() == guid)
658  {
659  summonedBattlePet->DespawnOrUnsummon();
660  player->SetBattlePetData(nullptr);
661  }
662  }
663 }
Definition: DB2Structure.h:468
void RemovePet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:492
Definition: ItemDefines.h:207
ObjectGuid PetGuid
Definition: BattlePetPackets.h:234
Definition: Unit.h:66
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesLoadInfo::Instance())
void SendNewItem(Item *item, uint32 quantity, bool received, bool created, bool broadcast=false)
Definition: Player.cpp:14428
Definition: ItemDefines.h:204
WorldPacket const * Write() override
Definition: BattlePetPackets.cpp:187
Item * StoreNewItem(ItemPosCountVec const &pos, uint32 itemId, bool update, ItemRandomBonusListId randomBonusListId=0, GuidSet const &allowedLooters=GuidSet(), ItemContext context=ItemContext::NONE, std::vector< int32 > const &bonusListIDs=std::vector< int32 >(), bool addToCollection=true)
Definition: Player.cpp:11983
Definition: Creature.h:69
Definition: ItemDefines.h:205
Definition: Unit.h:65
WorldSession * _owner
Definition: BattlePetMgr.h:208
Definition: Item.h:169
bool IsPetInSlot(ObjectGuid guid)
Definition: BattlePetMgr.cpp:539
bool HasJournalLock() const
Definition: BattlePetMgr.h:202
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:444
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:214
void SetModifier(ItemModifier modifier, uint32 value)
Definition: Item.cpp:2416
Creature * GetSummonedBattlePet()
Definition: Player.cpp:21942
std::vector< ItemPosCount > ItemPosCountVec
Definition: Player.h:731
Player * GetPlayer() const
Definition: WorldSession.h:1001
Definition: ItemDefines.h:26
Definition: BattlePetMgr.h:33
Definition: ItemDefines.h:206
InventoryResult CanStoreNewItem(uint8 bag, uint8 slot, ItemPosCountVec &dest, uint32 item, uint32 count, uint32 *no_space_count=nullptr) const
Definition: Player.cpp:10465
void SetBattlePetData(BattlePets::BattlePet const *pet=nullptr)
Definition: Player.cpp:21951
Definition: Player.h:1131
Definition: BattlePetPackets.h:227
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ChangeBattlePetQuality()

void BattlePets::BattlePetMgr::ChangeBattlePetQuality ( ObjectGuid  guid,
BattlePetBreedQuality  quality 
)
666 {
667  if (!HasJournalLock())
668  return;
669 
670  BattlePet* pet = GetPet(guid);
671  if (!pet)
672  return;
673 
674  if (quality > BattlePetBreedQuality::Rare)
675  return;
676 
677  if (BattlePetSpeciesEntry const* battlePetSpecies = sBattlePetSpeciesStore.LookupEntry(pet->PacketInfo.Species))
678  if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::CantBattle))
679  return;
680 
681  uint8 qualityValue = AsUnderlyingType(quality);
682  if (pet->PacketInfo.Quality >= qualityValue)
683  return;
684 
685  pet->PacketInfo.Quality = qualityValue;
686  pet->CalculateStats();
687  pet->PacketInfo.Health = pet->PacketInfo.MaxHealth;
688 
689  if (pet->SaveInfo != BATTLE_PET_NEW)
690  pet->SaveInfo = BATTLE_PET_CHANGED;
691 
692  std::vector<std::reference_wrapper<BattlePet>> updates;
693  updates.push_back(std::ref(*pet));
694  SendUpdates(std::move(updates), false);
695 
696  // UF::PlayerData::CurrentBattlePetBreedQuality isn't updated (Intended)
697  // _owner->GetPlayer()->SetCurrentBattlePetBreedQuality(qualityValue);
698 }
Definition: DB2Structure.h:468
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:473
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesLoadInfo::Instance())
Definition: BattlePetMgr.h:133
void SendUpdates(std::vector< std::reference_wrapper< BattlePet >> pets, bool petAdded)
Definition: BattlePetMgr.cpp:890
bool HasJournalLock() const
Definition: BattlePetMgr.h:202
Definition: BattlePetMgr.h:132
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:444
uint8_t uint8
Definition: Define.h:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ClearFanfare()

void BattlePets::BattlePetMgr::ClearFanfare ( ObjectGuid  guid)
505 {
506  BattlePet* pet = GetPet(guid);
507  if (!pet)
508  return;
509 
510  pet->PacketInfo.Flags &= ~AsUnderlyingType(BattlePetDbFlags::FanfareNeeded);
511 
512  if (pet->SaveInfo != BATTLE_PET_NEW)
513  pet->SaveInfo = BATTLE_PET_CHANGED;
514 }
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:473
Definition: BattlePetMgr.h:133
Definition: BattlePetMgr.h:132
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:444
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DismissPet()

void BattlePets::BattlePetMgr::DismissPet ( )
862 {
863  Player* player = _owner->GetPlayer();
864  if (Creature* summonedBattlePet = player->GetSummonedBattlePet())
865  {
866  summonedBattlePet->DespawnOrUnsummon();
867  player->SetBattlePetData(nullptr);
868  }
869 }
Definition: Creature.h:69
WorldSession * _owner
Definition: BattlePetMgr.h:208
Creature * GetSummonedBattlePet()
Definition: Player.cpp:21942
Player * GetPlayer() const
Definition: WorldSession.h:1001
void SetBattlePetData(BattlePets::BattlePet const *pet=nullptr)
Definition: Player.cpp:21951
Definition: Player.h:1131
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetBattlePetSpeciesByCreature()

BattlePetSpeciesEntry const * BattlePets::BattlePetMgr::GetBattlePetSpeciesByCreature ( uint32  creatureId)
static
192 {
193  return Trinity::Containers::MapGetValuePtr(_battlePetSpeciesByCreature, creatureId);
194 }
auto MapGetValuePtr(M &map, typename M::key_type const &key) -> decltype(AddressOrSelf(map.find(key) ->second))
Definition: Containers.h:259
+ Here is the call graph for this function:

◆ GetBattlePetSpeciesBySpell()

BattlePetSpeciesEntry const * BattlePets::BattlePetMgr::GetBattlePetSpeciesBySpell ( uint32  spellId)
static
197 {
198  return Trinity::Containers::MapGetValuePtr(_battlePetSpeciesBySpell, spellId);
199 }
auto MapGetValuePtr(M &map, typename M::key_type const &key) -> decltype(AddressOrSelf(map.find(key) ->second))
Definition: Containers.h:259
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetDefaultPetQuality()

BattlePetBreedQuality BattlePets::BattlePetMgr::GetDefaultPetQuality ( uint32  species)
static
211 {
212  auto itr = _defaultQualityPerSpecies.find(species);
213  if (itr == _defaultQualityPerSpecies.end())
214  return BattlePetBreedQuality::Poor; // Default
215 
216  return BattlePetBreedQuality(itr->second);
217 }
BattlePetBreedQuality
Definition: BattlePetMgr.h:44
+ Here is the caller graph for this function:

◆ GetMaxPetLevel()

uint16 BattlePets::BattlePetMgr::GetMaxPetLevel ( ) const
603 {
604  uint16 level = 0;
605  for (auto& pet : _pets)
606  if (pet.second.SaveInfo != BATTLE_PET_REMOVED)
607  level = std::max(level, pet.second.PacketInfo.Level);
608 
609  return level;
610 }
Definition: BattlePetMgr.h:134
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:211
uint16_t uint16
Definition: Define.h:144
+ Here is the caller graph for this function:

◆ GetOwner()

WorldSession* BattlePets::BattlePetMgr::GetOwner ( ) const
inline
180 { return _owner; }
WorldSession * _owner
Definition: BattlePetMgr.h:208

◆ GetPet()

BattlePet * BattlePets::BattlePetMgr::GetPet ( ObjectGuid  guid)
445 {
447 }
auto MapGetValuePtr(M &map, typename M::key_type const &key) -> decltype(AddressOrSelf(map.find(key) ->second))
Definition: Containers.h:259
LowType GetCounter() const
Definition: ObjectGuid.h:284
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:211
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetPetCount()

uint8 BattlePets::BattlePetMgr::GetPetCount ( BattlePetSpeciesEntry const *  battlePetSpecies,
ObjectGuid  ownerGuid 
) const
549 {
550  return uint8(std::count_if(_pets.begin(), _pets.end(), [battlePetSpecies, ownerGuid](std::pair<uint64 const, BattlePet> const& pet)
551  {
552  if (pet.second.PacketInfo.Species != battlePetSpecies->ID)
553  return false;
554 
555  if (pet.second.SaveInfo == BATTLE_PET_REMOVED)
556  return false;
557 
558  if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::NotAccountWide))
559  if (!ownerGuid.IsEmpty() && pet.second.PacketInfo.OwnerInfo)
560  if (pet.second.PacketInfo.OwnerInfo->Guid != ownerGuid)
561  return false;
562 
563  return true;
564  }));
565 }
Definition: BattlePetMgr.h:134
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:211
bool IsEmpty() const
Definition: ObjectGuid.h:310
uint8_t uint8
Definition: Define.h:145
+ Here is the call graph for this function:

◆ GetPetUniqueSpeciesCount()

uint32 BattlePets::BattlePetMgr::GetPetUniqueSpeciesCount ( ) const
575 {
576  std::set<uint32> speciesIds;
577  std::transform(_pets.begin(), _pets.end(), std::inserter(speciesIds, speciesIds.end()), [](std::pair<uint64 const, BattlePet> const& pet)
578  {
579  return pet.second.PacketInfo.Species;
580  });
581  return speciesIds.size();
582 }
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:211
+ Here is the caller graph for this function:

◆ GetSlot()

WorldPackets::BattlePet::BattlePetSlot* BattlePets::BattlePetMgr::GetSlot ( BattlePetSlot  slot)
inline
177 { return slot < BattlePetSlot::Count ? &_slots[size_t(slot)] : nullptr; }
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:212

◆ GetSlots()

std::vector<WorldPackets::BattlePet::BattlePetSlot> const& BattlePets::BattlePetMgr::GetSlots ( ) const
inline
184 { return _slots; }
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:212
+ Here is the caller graph for this function:

◆ GetTrapLevel()

uint16 BattlePets::BattlePetMgr::GetTrapLevel ( ) const
inline
182 { return _trapLevel; }
uint16 _trapLevel
Definition: BattlePetMgr.h:210

◆ GrantBattlePetExperience()

void BattlePets::BattlePetMgr::GrantBattlePetExperience ( ObjectGuid  guid,
uint16  xp,
BattlePetXpSource  xpSource 
)
701 {
702  if (!HasJournalLock())
703  return;
704 
705  BattlePet* pet = GetPet(guid);
706  if (!pet)
707  return;
708 
709  if (xp <= 0 || xpSource >= BattlePetXpSource::Count)
710  return;
711 
712  if (BattlePetSpeciesEntry const* battlePetSpecies = sBattlePetSpeciesStore.LookupEntry(pet->PacketInfo.Species))
713  if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::CantBattle))
714  return;
715 
716  uint16 level = pet->PacketInfo.Level;
717  if (level >= MAX_BATTLE_PET_LEVEL)
718  return;
719 
720  GtBattlePetXPEntry const* xpEntry = sBattlePetXPGameTable.GetRow(level);
721  if (!xpEntry)
722  return;
723 
724  Player* player = _owner->GetPlayer();
725  uint16 nextLevelXp = uint16(GetBattlePetXPPerLevel(xpEntry));
726 
727  if (xpSource == BattlePetXpSource::PetBattle)
729 
730  xp += pet->PacketInfo.Exp;
731 
732  while (xp >= nextLevelXp && level < MAX_BATTLE_PET_LEVEL)
733  {
734  xp -= nextLevelXp;
735 
736  xpEntry = sBattlePetXPGameTable.GetRow(++level);
737  if (!xpEntry)
738  return;
739 
740  nextLevelXp = uint16(GetBattlePetXPPerLevel(xpEntry));
741 
742  player->UpdateCriteria(CriteriaType::BattlePetReachLevel, pet->PacketInfo.Species, level);
743  if (xpSource == BattlePetXpSource::PetBattle)
744  player->UpdateCriteria(CriteriaType::ActivelyEarnPetLevel, pet->PacketInfo.Species, level);
745  }
746 
747  pet->PacketInfo.Level = level;
748  pet->PacketInfo.Exp = level < MAX_BATTLE_PET_LEVEL ? xp : 0;
749  pet->CalculateStats();
750  pet->PacketInfo.Health = pet->PacketInfo.MaxHealth;
751 
752  if (pet->SaveInfo != BATTLE_PET_NEW)
753  pet->SaveInfo = BATTLE_PET_CHANGED;
754 
755  std::vector<std::reference_wrapper<BattlePet>> updates;
756  updates.push_back(std::ref(*pet));
757  SendUpdates(std::move(updates), false);
758 }
Definition: DB2Structure.h:468
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesLoadInfo::Instance())
Definition: GameTables.h:59
Definition: BattlePetMgr.h:133
Definition: SpellAuraDefines.h:514
void UpdateCriteria(CriteriaType type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, WorldObject *ref=nullptr)
Definition: Player.cpp:26905
WorldSession * _owner
Definition: BattlePetMgr.h:208
void SendUpdates(std::vector< std::reference_wrapper< BattlePet >> pets, bool petAdded)
Definition: BattlePetMgr.cpp:890
uint16_t uint16
Definition: Define.h:144
bool HasJournalLock() const
Definition: BattlePetMgr.h:202
Definition: BattlePetMgr.h:132
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:444
static constexpr uint16 MAX_BATTLE_PET_LEVEL
Definition: BattlePetMgr.h:41
GameTable< GtBattlePetXPEntry > sBattlePetXPGameTable
Definition: GameTables.cpp:31
float GetBattlePetXPPerLevel(GtBattlePetXPEntry const *row)
Definition: GameTables.h:289
Player * GetPlayer() const
Definition: WorldSession.h:1001
Definition: Player.h:1131
float GetTotalAuraMultiplier(AuraType auraType) const
Definition: Unit.cpp:4790
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GrantBattlePetLevel()

void BattlePets::BattlePetMgr::GrantBattlePetLevel ( ObjectGuid  guid,
uint16  grantedLevels 
)
761 {
762  if (!HasJournalLock())
763  return;
764 
765  BattlePet* pet = GetPet(guid);
766  if (!pet)
767  return;
768 
769  if (BattlePetSpeciesEntry const* battlePetSpecies = sBattlePetSpeciesStore.LookupEntry(pet->PacketInfo.Species))
770  if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::CantBattle))
771  return;
772 
773  uint16 level = pet->PacketInfo.Level;
774  if (level >= MAX_BATTLE_PET_LEVEL)
775  return;
776 
777  while (grantedLevels > 0 && level < MAX_BATTLE_PET_LEVEL)
778  {
779  ++level;
780  --grantedLevels;
781 
782  _owner->GetPlayer()->UpdateCriteria(CriteriaType::BattlePetReachLevel, pet->PacketInfo.Species, level);
783  }
784 
785  pet->PacketInfo.Level = level;
786  if (level >= MAX_BATTLE_PET_LEVEL)
787  pet->PacketInfo.Exp = 0;
788  pet->CalculateStats();
789  pet->PacketInfo.Health = pet->PacketInfo.MaxHealth;
790 
791  if (pet->SaveInfo != BATTLE_PET_NEW)
792  pet->SaveInfo = BATTLE_PET_CHANGED;
793 
794  std::vector<std::reference_wrapper<BattlePet>> updates;
795  updates.push_back(std::ref(*pet));
796  SendUpdates(std::move(updates), false);
797 }
Definition: DB2Structure.h:468
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesLoadInfo::Instance())
Definition: BattlePetMgr.h:133
void UpdateCriteria(CriteriaType type, uint64 miscValue1=0, uint64 miscValue2=0, uint64 miscValue3=0, WorldObject *ref=nullptr)
Definition: Player.cpp:26905
WorldSession * _owner
Definition: BattlePetMgr.h:208
void SendUpdates(std::vector< std::reference_wrapper< BattlePet >> pets, bool petAdded)
Definition: BattlePetMgr.cpp:890
uint16_t uint16
Definition: Define.h:144
bool HasJournalLock() const
Definition: BattlePetMgr.h:202
Definition: BattlePetMgr.h:132
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:444
static constexpr uint16 MAX_BATTLE_PET_LEVEL
Definition: BattlePetMgr.h:41
Player * GetPlayer() const
Definition: WorldSession.h:1001
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HasJournalLock()

bool BattlePets::BattlePetMgr::HasJournalLock ( ) const
inline
202 { return _hasJournalLock; }
bool _hasJournalLock
Definition: BattlePetMgr.h:209
+ Here is the caller graph for this function:

◆ HasMaxPetCount()

bool BattlePets::BattlePetMgr::HasMaxPetCount ( BattlePetSpeciesEntry const *  battlePetSpecies,
ObjectGuid  ownerGuid 
) const
568 {
569  uint8 maxPetsPerSpecies = battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::LegacyAccountUnique) ? 1 : DEFAULT_MAX_BATTLE_PETS_PER_SPECIES;
570 
571  return GetPetCount(battlePetSpecies, ownerGuid) >= maxPetsPerSpecies;
572 }
uint8 GetPetCount(BattlePetSpeciesEntry const *battlePetSpecies, ObjectGuid ownerGuid) const
Definition: BattlePetMgr.cpp:548
uint8_t uint8
Definition: Define.h:145
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ HealBattlePetsPct()

void BattlePets::BattlePetMgr::HealBattlePetsPct ( uint8  pct)
800 {
801  // TODO: After each Pet Battle, any injured companion will automatically
802  // regain 50 % of the damage that was taken during combat
803  std::vector<std::reference_wrapper<BattlePet>> updates;
804 
805  for (auto& pet : _pets)
806  if (pet.second.PacketInfo.Health != pet.second.PacketInfo.MaxHealth)
807  {
808  pet.second.PacketInfo.Health += CalculatePct(pet.second.PacketInfo.MaxHealth, pct);
809  // don't allow Health to be greater than MaxHealth
810  pet.second.PacketInfo.Health = std::min(pet.second.PacketInfo.Health, pet.second.PacketInfo.MaxHealth);
811  if (pet.second.SaveInfo != BATTLE_PET_NEW)
812  pet.second.SaveInfo = BATTLE_PET_CHANGED;
813  updates.push_back(std::ref(pet.second));
814  }
815 
816  SendUpdates(std::move(updates), false);
817 }
Definition: BattlePetMgr.h:133
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:211
void SendUpdates(std::vector< std::reference_wrapper< BattlePet >> pets, bool petAdded)
Definition: BattlePetMgr.cpp:890
Definition: BattlePetMgr.h:132
T CalculatePct(T base, U pct)
Definition: Util.h:67
+ Here is the call graph for this function:

◆ Initialize()

void BattlePets::BattlePetMgr::Initialize ( )
static
97 {
98  if (QueryResult result = LoginDatabase.Query("SELECT MAX(guid) FROM battle_pets"))
99  sObjectMgr->GetGenerator<HighGuid::BattlePet>().Set((*result)[0].GetUInt64() + 1);
100 
101  for (BattlePetSpeciesEntry const* battlePetSpecies : sBattlePetSpeciesStore)
102  if (uint32 creatureId = battlePetSpecies->CreatureID)
103  _battlePetSpeciesByCreature[creatureId] = battlePetSpecies;
104 
105  for (BattlePetBreedStateEntry const* battlePetBreedState : sBattlePetBreedStateStore)
106  _battlePetBreedStates[battlePetBreedState->BattlePetBreedID][BattlePetState(battlePetBreedState->BattlePetStateID)] = battlePetBreedState->Value;
107 
108  for (BattlePetSpeciesStateEntry const* battlePetSpeciesState : sBattlePetSpeciesStateStore)
109  _battlePetSpeciesStates[battlePetSpeciesState->BattlePetSpeciesID][BattlePetState(battlePetSpeciesState->BattlePetStateID)] = battlePetSpeciesState->Value;
110 
113 }
Definition: DB2Structure.h:468
Definition: DB2Structure.h:486
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesLoadInfo::Instance())
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
#define sObjectMgr
Definition: ObjectMgr.h:1967
DB2Storage< BattlePetSpeciesStateEntry > sBattlePetSpeciesStateStore("BattlePetSpeciesState.db2", BattlePetSpeciesStateLoadInfo::Instance())
BattlePetState
Definition: BattlePetMgr.h:106
DB2Storage< BattlePetBreedStateEntry > sBattlePetBreedStateStore("BattlePetBreedState.db2", BattlePetBreedStateLoadInfo::Instance())
uint32_t uint32
Definition: Define.h:143
Definition: DB2Structure.h:460
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
static void LoadAvailablePetBreeds()
Definition: BattlePetMgr.cpp:115
static void LoadDefaultPetQualities()
Definition: BattlePetMgr.cpp:146
+ Here is the caller graph for this function:

◆ IsBattlePetSystemEnabled()

bool BattlePets::BattlePetMgr::IsBattlePetSystemEnabled ( )
inline
205 { return GetSlot(BattlePetSlot::Slot0)->Locked != true; }
WorldPackets::BattlePet::BattlePetSlot * GetSlot(BattlePetSlot slot)
Definition: BattlePetMgr.h:177
bool Locked
Definition: BattlePetPackets.h:63
+ Here is the caller graph for this function:

◆ IsJournalLockAcquired()

bool BattlePets::BattlePetMgr::IsJournalLockAcquired ( ) const
926 {
927  return sWorld->IsBattlePetJournalLockAcquired(_owner->GetBattlenetAccountGUID());
928 }
ObjectGuid GetBattlenetAccountGUID() const
Definition: WorldSession.h:1000
#define sWorld
Definition: World.h:946
WorldSession * _owner
Definition: BattlePetMgr.h:208

◆ IsPetInSlot()

bool BattlePets::BattlePetMgr::IsPetInSlot ( ObjectGuid  guid)
540 {
542  if (slot.Pet.Guid == guid)
543  return true;
544 
545  return false;
546 }
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:212
Definition: BattlePetPackets.h:58

◆ LoadAvailablePetBreeds()

void BattlePets::BattlePetMgr::LoadAvailablePetBreeds ( )
staticprivate
116 {
117  QueryResult result = WorldDatabase.Query("SELECT speciesId, breedId FROM battle_pet_breeds");
118  if (!result)
119  {
120  TC_LOG_INFO("server.loading", ">> Loaded 0 battle pet breeds. DB table `battle_pet_breeds` is empty.");
121  return;
122  }
123 
124  uint32 count = 0;
125  do
126  {
127  Field* fields = result->Fetch();
128  uint32 speciesId = fields[0].GetUInt32();
129  uint16 breedId = fields[1].GetUInt16();
130 
131  if (!sBattlePetSpeciesStore.LookupEntry(speciesId))
132  {
133  TC_LOG_ERROR("sql.sql", "Non-existing BattlePetSpecies.db2 entry %u was referenced in `battle_pet_breeds` by row (%u, %u).", speciesId, speciesId, breedId);
134  continue;
135  }
136 
137  // TODO: verify breed id (3 - 12 (male) or 3 - 22 (male and female)) if needed
138 
139  _availableBreedsPerSpecies[speciesId].insert(breedId);
140  ++count;
141  } while (result->NextRow());
142 
143  TC_LOG_INFO("server.loading", ">> Loaded %u battle pet breeds.", count);
144 }
uint16 GetUInt16() const
Definition: Field.cpp:69
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesLoadInfo::Instance())
Class used to access individual fields of database query result.
Definition: Field.h:83
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:185
uint32 GetUInt32() const
Definition: Field.cpp:105
uint32_t uint32
Definition: Define.h:143
uint16_t uint16
Definition: Define.h:144
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:179
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
+ Here is the call graph for this function:

◆ LoadDefaultPetQualities()

void BattlePets::BattlePetMgr::LoadDefaultPetQualities ( )
staticprivate
147 {
148  QueryResult result = WorldDatabase.Query("SELECT speciesId, quality FROM battle_pet_quality");
149  if (!result)
150  {
151  TC_LOG_INFO("server.loading", ">> Loaded 0 battle pet qualities. DB table `battle_pet_quality` is empty.");
152  return;
153  }
154 
155  do
156  {
157  Field* fields = result->Fetch();
158  uint32 speciesId = fields[0].GetUInt32();
159  uint8 quality = fields[1].GetUInt8();
160 
161  BattlePetSpeciesEntry const* battlePetSpecies = sBattlePetSpeciesStore.LookupEntry(speciesId);
162  if (!battlePetSpecies)
163  {
164  TC_LOG_ERROR("sql.sql", "Non-existing BattlePetSpecies.db2 entry %u was referenced in `battle_pet_quality` by row (%u, %u).", speciesId, speciesId, quality);
165  continue;
166  }
167 
169  {
170  TC_LOG_ERROR("sql.sql", "BattlePetSpecies.db2 entry %u was referenced in `battle_pet_quality` with non-existing quality %u).", speciesId, quality);
171  continue;
172  }
173 
174  if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::WellKnown) && quality > AsUnderlyingType(BattlePetBreedQuality::Rare))
175  {
176  TC_LOG_ERROR("sql.sql", "Learnable BattlePetSpecies.db2 entry %u was referenced in `battle_pet_quality` with invalid quality %u. Maximum allowed quality is BattlePetBreedQuality::Rare.", speciesId, quality);
177  continue;
178  }
179 
180  _defaultQualityPerSpecies[speciesId] = quality;
181  } while (result->NextRow());
182 
183  TC_LOG_INFO("server.loading", ">> Loaded %u battle pet qualities.", uint32(_defaultQualityPerSpecies.size()));
184 }
Definition: DB2Structure.h:468
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:473
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesLoadInfo::Instance())
Class used to access individual fields of database query result.
Definition: Field.h:83
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:185
uint32 GetUInt32() const
Definition: Field.cpp:105
uint32_t uint32
Definition: Define.h:143
EnumFlag< BattlePetSpeciesFlags > GetFlags() const
Definition: DB2Structure.h:483
#define TC_LOG_INFO(filterType__,...)
Definition: Log.h:179
std::shared_ptr< ResultSet > QueryResult
Definition: DatabaseEnvFwd.h:28
uint8 GetUInt8() const
Definition: Field.cpp:33
uint8_t uint8
Definition: Define.h:145
DatabaseWorkerPool< WorldDatabaseConnection > WorldDatabase
Accessor to the world database.
Definition: DatabaseEnv.cpp:20
+ Here is the call graph for this function:

◆ LoadFromDB()

void BattlePets::BattlePetMgr::LoadFromDB ( PreparedQueryResult  pets,
PreparedQueryResult  slots 
)
241 {
242  if (pets)
243  {
244  do
245  {
246  Field* fields = pets->Fetch();
247  uint32 species = fields[1].GetUInt32();
248  ObjectGuid ownerGuid = !fields[11].IsNull() ? ObjectGuid::Create<HighGuid::Player>(fields[11].GetInt64()) : ObjectGuid::Empty;
249 
250  if (BattlePetSpeciesEntry const* speciesEntry = sBattlePetSpeciesStore.LookupEntry(species))
251  {
252  if (speciesEntry->GetFlags().HasFlag(BattlePetSpeciesFlags::NotAccountWide))
253  {
254  if (ownerGuid.IsEmpty())
255  {
256  TC_LOG_ERROR("misc", "Battlenet account with id %u has battle pet of species %u with BattlePetSpeciesFlags::NotAccountWide but no owner", _owner->GetBattlenetAccountId(), species);
257  continue;
258  }
259  }
260  else
261  {
262  if (!ownerGuid.IsEmpty())
263  {
264  TC_LOG_ERROR("misc", "Battlenet account with id %u has battle pet of species %u without BattlePetSpeciesFlags::NotAccountWide but with owner", _owner->GetBattlenetAccountId(), species);
265  continue;
266  }
267  }
268 
269  if (HasMaxPetCount(speciesEntry, ownerGuid))
270  {
271  if (ownerGuid.IsEmpty())
272  TC_LOG_ERROR("misc", "Battlenet account with id %u has more than maximum battle pets of species %u", _owner->GetBattlenetAccountId(), species);
273  else
274  TC_LOG_ERROR("misc", "Battlenet account with id %u has more than maximum battle pets of species %u for player %s", _owner->GetBattlenetAccountId(), species, ownerGuid.ToString().c_str());
275 
276  continue;
277  }
278 
279  BattlePet pet;
280  pet.PacketInfo.Guid = ObjectGuid::Create<HighGuid::BattlePet>(fields[0].GetUInt64());
281  pet.PacketInfo.Species = species;
282  pet.PacketInfo.Breed = fields[2].GetUInt16();
283  pet.PacketInfo.DisplayID = fields[3].GetUInt32();
284  pet.PacketInfo.Level = fields[4].GetUInt16();
285  pet.PacketInfo.Exp = fields[5].GetUInt16();
286  pet.PacketInfo.Health = fields[6].GetUInt32();
287  pet.PacketInfo.Quality = fields[7].GetUInt8();
288  pet.PacketInfo.Flags = fields[8].GetUInt16();
289  pet.PacketInfo.Name = fields[9].GetString();
290  pet.NameTimestamp = fields[10].GetInt64();
291  pet.PacketInfo.CreatureID = speciesEntry->CreatureID;
292 
293  if (!fields[12].IsNull())
294  {
295  pet.DeclinedName = std::make_unique<DeclinedName>();
296  for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; ++i)
297  pet.DeclinedName->name[i] = fields[12 + i].GetString();
298  }
299 
300  if (!ownerGuid.IsEmpty())
301  {
302  pet.PacketInfo.OwnerInfo.emplace();
303  pet.PacketInfo.OwnerInfo->Guid = ownerGuid;
304  pet.PacketInfo.OwnerInfo->PlayerVirtualRealm = pet.PacketInfo.OwnerInfo->PlayerNativeRealm = GetVirtualRealmAddress();
305  }
306 
307  pet.SaveInfo = BATTLE_PET_UNCHANGED;
308  pet.CalculateStats();
309  _pets[pet.PacketInfo.Guid.GetCounter()] = std::move(pet);
310  }
311  } while (pets->NextRow());
312  }
313 
314  if (slots)
315  {
316  uint8 i = 0; // slots->GetRowCount() should equal MAX_BATTLE_PET_SLOTS
317 
318  do
319  {
320  Field* fields = slots->Fetch();
321  _slots[i].Index = fields[0].GetUInt8();
322  auto itr = _pets.find(fields[1].GetUInt64());
323  if (itr != _pets.end())
324  _slots[i].Pet = itr->second.PacketInfo;
325  _slots[i].Locked = fields[2].GetBool();
326  i++;
327  } while (slots->NextRow());
328  }
329 }
Definition: DB2Structure.h:468
static ObjectGuid const Empty
Definition: ObjectGuid.h:265
uint16 GetUInt16() const
Definition: Field.cpp:69
std::string ToString() const
Definition: ObjectGuid.cpp:531
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesLoadInfo::Instance())
bool HasMaxPetCount(BattlePetSpeciesEntry const *battlePetSpecies, ObjectGuid ownerGuid) const
Definition: BattlePetMgr.cpp:567
Class used to access individual fields of database query result.
Definition: Field.h:83
#define TC_LOG_ERROR(filterType__,...)
Definition: Log.h:185
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:212
bool IsNull() const
Definition: Field.h:119
uint32 GetUInt32() const
Definition: Field.cpp:105
uint64 GetUInt64() const
Definition: Field.cpp:141
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:211
WorldSession * _owner
Definition: BattlePetMgr.h:208
std::string GetString() const
Definition: Field.cpp:228
int64 GetInt64() const
Definition: Field.cpp:159
uint32_t uint32
Definition: Define.h:143
uint32 GetBattlenetAccountId() const
Definition: WorldSession.h:999
#define MAX_DECLINED_NAME_CASES
Definition: UnitDefines.h:453
bool IsEmpty() const
Definition: ObjectGuid.h:310
uint8 GetUInt8() const
Definition: Field.cpp:33
uint32 GetVirtualRealmAddress()
Definition: World.cpp:3960
uint8_t uint8
Definition: Define.h:145
Definition: ObjectGuid.h:258
bool GetBool() const
Definition: Field.h:92
Definition: BattlePetMgr.h:131
Definition: Pet.h:45
+ Here is the call graph for this function:

◆ ModifyName()

void BattlePets::BattlePetMgr::ModifyName ( ObjectGuid  guid,
std::string const &  name,
std::unique_ptr< DeclinedName declinedName 
)
517 {
518  if (!HasJournalLock())
519  return;
520 
521  BattlePet* pet = GetPet(guid);
522  if (!pet)
523  return;
524 
525  pet->PacketInfo.Name = name;
526  pet->NameTimestamp = GameTime::GetGameTime();
527 
528  pet->DeclinedName = std::move(declinedName);
529 
530  if (pet->SaveInfo != BATTLE_PET_NEW)
531  pet->SaveInfo = BATTLE_PET_CHANGED;
532 
533  // Update the timestamp if the battle pet is summoned
534  if (Creature* summonedBattlePet = _owner->GetPlayer()->GetSummonedBattlePet())
535  if (summonedBattlePet->GetBattlePetCompanionGUID() == guid)
536  summonedBattlePet->SetBattlePetCompanionNameTimestamp(pet->NameTimestamp);
537 }
Definition: BattlePetMgr.h:133
Definition: Creature.h:69
time_t GetGameTime()
Definition: GameTime.cpp:39
WorldSession * _owner
Definition: BattlePetMgr.h:208
bool HasJournalLock() const
Definition: BattlePetMgr.h:202
Definition: BattlePetMgr.h:132
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:444
Creature * GetSummonedBattlePet()
Definition: Player.cpp:21942
Player * GetPlayer() const
Definition: WorldSession.h:1001
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RemovePet()

void BattlePets::BattlePetMgr::RemovePet ( ObjectGuid  guid)
493 {
494  if (!HasJournalLock())
495  return;
496 
497  BattlePet* pet = GetPet(guid);
498  if (!pet)
499  return;
500 
501  pet->SaveInfo = BATTLE_PET_REMOVED;
502 }
Definition: BattlePetMgr.h:134
bool HasJournalLock() const
Definition: BattlePetMgr.h:202
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:444
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ RollPetBreed()

uint16 BattlePets::BattlePetMgr::RollPetBreed ( uint32  species)
static
202 {
203  auto itr = _availableBreedsPerSpecies.find(species);
204  if (itr == _availableBreedsPerSpecies.end())
205  return 3; // default B/B
206 
208 }
auto SelectRandomContainerElement(C const &container) -> typename std::add_const< decltype(*std::begin(container))>::type &
Definition: Containers.h:119
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SaveToDB()

void BattlePets::BattlePetMgr::SaveToDB ( LoginDatabaseTransaction  trans)
332 {
333  LoginDatabasePreparedStatement* stmt = nullptr;
334 
335  for (auto itr = _pets.begin(); itr != _pets.end();)
336  {
337  switch (itr->second.SaveInfo)
338  {
339  case BATTLE_PET_NEW:
340  stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_BATTLE_PETS);
341  stmt->setUInt64(0, itr->first);
343  stmt->setUInt32(2, itr->second.PacketInfo.Species);
344  stmt->setUInt16(3, itr->second.PacketInfo.Breed);
345  stmt->setUInt32(4, itr->second.PacketInfo.DisplayID);
346  stmt->setUInt16(5, itr->second.PacketInfo.Level);
347  stmt->setUInt16(6, itr->second.PacketInfo.Exp);
348  stmt->setUInt32(7, itr->second.PacketInfo.Health);
349  stmt->setUInt8(8, itr->second.PacketInfo.Quality);
350  stmt->setUInt16(9, itr->second.PacketInfo.Flags);
351  stmt->setString(10, itr->second.PacketInfo.Name);
352  stmt->setInt64(11, itr->second.NameTimestamp);
353  if (itr->second.PacketInfo.OwnerInfo)
354  {
355  stmt->setInt64(12, itr->second.PacketInfo.OwnerInfo->Guid.GetCounter());
356  stmt->setInt32(13, realm.Id.Realm);
357  }
358  else
359  {
360  stmt->setNull(12);
361  stmt->setNull(13);
362  }
363 
364  trans->Append(stmt);
365 
366  if (itr->second.DeclinedName)
367  {
368  stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_BATTLE_PET_DECLINED_NAME);
369  stmt->setUInt64(0, itr->first);
370 
371  for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; i++)
372  stmt->setString(i + 1, itr->second.DeclinedName->name[i]);
373 
374  trans->Append(stmt);
375  }
376 
377  itr->second.SaveInfo = BATTLE_PET_UNCHANGED;
378  ++itr;
379  break;
380  case BATTLE_PET_CHANGED:
381  stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_BATTLE_PETS);
382  stmt->setUInt16(0, itr->second.PacketInfo.Level);
383  stmt->setUInt16(1, itr->second.PacketInfo.Exp);
384  stmt->setUInt32(2, itr->second.PacketInfo.Health);
385  stmt->setUInt8(3, itr->second.PacketInfo.Quality);
386  stmt->setUInt16(4, itr->second.PacketInfo.Flags);
387  stmt->setString(5, itr->second.PacketInfo.Name);
388  stmt->setInt64(6, itr->second.NameTimestamp);
390  stmt->setUInt64(8, itr->first);
391  trans->Append(stmt);
392 
393  stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_BATTLE_PET_DECLINED_NAME);
394  stmt->setUInt64(0, itr->first);
395  trans->Append(stmt);
396 
397  if (itr->second.DeclinedName)
398  {
399  stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_BATTLE_PET_DECLINED_NAME);
400  stmt->setUInt64(0, itr->first);
401 
402  for (uint8 i = 0; i < MAX_DECLINED_NAME_CASES; i++)
403  stmt->setString(i + 1, itr->second.DeclinedName->name[i]);
404 
405  trans->Append(stmt);
406  }
407 
408  itr->second.SaveInfo = BATTLE_PET_UNCHANGED;
409  ++itr;
410  break;
411  case BATTLE_PET_REMOVED:
412  stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_BATTLE_PET_DECLINED_NAME);
413  stmt->setUInt64(0, itr->first);
414  trans->Append(stmt);
415 
416  stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_BATTLE_PETS);
418  stmt->setUInt64(1, itr->first);
419  trans->Append(stmt);
420 
421  itr = _pets.erase(itr);
422  break;
423  default:
424  ++itr;
425  break;
426  }
427  }
428 
429  stmt = LoginDatabase.GetPreparedStatement(LOGIN_DEL_BATTLE_PET_SLOTS);
431  trans->Append(stmt);
432 
434  {
435  stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_BATTLE_PET_SLOTS);
436  stmt->setUInt8(0, slot.Index);
438  stmt->setUInt64(2, slot.Pet.Guid.GetCounter());
439  stmt->setBool(3, slot.Locked);
440  trans->Append(stmt);
441  }
442 }
uint32 Realm
Definition: Realm.h:48
Definition: LoginDatabase.h:161
Definition: BattlePetMgr.h:134
Definition: LoginDatabase.h:158
Definition: LoginDatabase.h:159
Realm realm
Definition: World.cpp:3958
DatabaseWorkerPool< LoginDatabaseConnection > LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
Definition: BattlePetMgr.h:133
void setInt64(const uint8 index, const int64 value)
Definition: PreparedStatement.cpp:78
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:212
void setUInt8(const uint8 index, const uint8 value)
Definition: PreparedStatement.cpp:36
Definition: DatabaseEnvFwd.h:40
void setInt32(const uint8 index, const int32 value)
Definition: PreparedStatement.cpp:72
void setUInt16(const uint8 index, const uint16 value)
Definition: PreparedStatement.cpp:42
Definition: LoginDatabase.h:160
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:211
void setBool(const uint8 index, const bool value)
Definition: PreparedStatement.cpp:30
Battlenet::RealmHandle Id
Definition: Realm.h:79
WorldSession * _owner
Definition: BattlePetMgr.h:208
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:48
void setNull(const uint8 index)
Definition: PreparedStatement.cpp:114
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:96
Definition: BattlePetMgr.h:132
uint32 GetBattlenetAccountId() const
Definition: WorldSession.h:999
#define MAX_DECLINED_NAME_CASES
Definition: UnitDefines.h:453
Definition: LoginDatabase.h:154
Definition: LoginDatabase.h:156
Definition: BattlePetPackets.h:58
uint8_t uint8
Definition: Define.h:145
Definition: BattlePetMgr.h:131
Definition: LoginDatabase.h:153
void setUInt64(const uint8 index, const uint64 value)
Definition: PreparedStatement.cpp:54
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SelectPetDisplay()

uint32 BattlePets::BattlePetMgr::SelectPetDisplay ( BattlePetSpeciesEntry const *  speciesEntry)
static
220 {
221  if (CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(speciesEntry->CreatureID))
222  if (!speciesEntry->GetFlags().HasFlag(BattlePetSpeciesFlags::RandomDisplay))
223  if (CreatureModel const* creatureModel = creatureTemplate->GetRandomValidModel())
224  return creatureModel->CreatureDisplayID;
225 
226  return 0;
227 }
Definition: CreatureData.h:373
#define sObjectMgr
Definition: ObjectMgr.h:1967
Definition: CreatureData.h:397
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SendError()

void BattlePets::BattlePetMgr::SendError ( BattlePetError  error,
uint32  creatureId 
)
901 {
903  battlePetError.Result = AsUnderlyingType(error);
904  battlePetError.CreatureID = creatureId;
905  _owner->SendPacket(battlePetError.Write());
906 }
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:473
int32 CreatureID
Definition: BattlePetPackets.h:245
WorldSession * _owner
Definition: BattlePetMgr.h:208
uint8 Result
Definition: BattlePetPackets.h:244
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:214
Definition: BattlePetPackets.h:237
WorldPacket const * Write() override
Definition: BattlePetPackets.cpp:194
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SendJournal()

void BattlePets::BattlePetMgr::SendJournal ( )
872 {
873  if (!HasJournalLock())
875 
877  battlePetJournal.Trap = _trapLevel;
878  battlePetJournal.HasJournalLock = _hasJournalLock;
879 
880  for (auto& pet : _pets)
881  if (pet.second.SaveInfo != BATTLE_PET_REMOVED)
882  if (!pet.second.PacketInfo.OwnerInfo || pet.second.PacketInfo.OwnerInfo->Guid == _owner->GetPlayer()->GetGUID())
883  battlePetJournal.Pets.push_back(std::ref(pet.second.PacketInfo));
884 
885  battlePetJournal.Slots.reserve(_slots.size());
886  std::transform(_slots.begin(), _slots.end(), std::back_inserter(battlePetJournal.Slots), [](WorldPackets::BattlePet::BattlePetSlot& slot) { return std::ref(slot); });
887  _owner->SendPacket(battlePetJournal.Write());
888 }
Definition: BattlePetMgr.h:134
WorldPacket const * Write() override
Definition: BattlePetPackets.cpp:63
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:156
uint16 _trapLevel
Definition: BattlePetMgr.h:210
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:212
bool HasJournalLock
Definition: BattlePetPackets.h:74
bool _hasJournalLock
Definition: BattlePetMgr.h:209
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:211
Definition: BattlePetPackets.h:66
WorldSession * _owner
Definition: BattlePetMgr.h:208
bool HasJournalLock() const
Definition: BattlePetMgr.h:202
std::vector< std::reference_wrapper< BattlePet > > Pets
Definition: BattlePetPackets.h:76
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:214
std::vector< std::reference_wrapper< BattlePetSlot > > Slots
Definition: BattlePetPackets.h:75
Player * GetPlayer() const
Definition: WorldSession.h:1001
Definition: BattlePetPackets.h:58
void SendJournalLockStatus()
Definition: BattlePetMgr.cpp:908
uint16 Trap
Definition: BattlePetPackets.h:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SendJournalLockStatus()

void BattlePets::BattlePetMgr::SendJournalLockStatus ( )
909 {
910  if (!IsJournalLockAcquired())
911  ToggleJournalLock(true);
912 
913  if (HasJournalLock())
914  {
915  WorldPackets::BattlePet::BattlePetJournalLockAcquired battlePetJournalLockAcquired;
916  _owner->SendPacket(battlePetJournalLockAcquired.Write());
917  }
918  else
919  {
920  WorldPackets::BattlePet::BattlePetJournalLockDenied BattlePetJournalLockDenied;
921  _owner->SendPacket(BattlePetJournalLockDenied.Write());
922  }
923 }
WorldPacket const * Write() override
Definition: BattlePetPackets.h:84
void ToggleJournalLock(bool lock)
Definition: BattlePetMgr.h:203
WorldPacket const * Write() override
Definition: BattlePetPackets.h:92
WorldSession * _owner
Definition: BattlePetMgr.h:208
bool HasJournalLock() const
Definition: BattlePetMgr.h:202
bool IsJournalLockAcquired() const
Definition: BattlePetMgr.cpp:925
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:214
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SendUpdates()

void BattlePets::BattlePetMgr::SendUpdates ( std::vector< std::reference_wrapper< BattlePet >>  pets,
bool  petAdded 
)
891 {
893  for (BattlePet& pet : pets)
894  updates.Pets.push_back(std::ref(pet.PacketInfo));
895 
896  updates.PetAdded = petAdded;
897  _owner->SendPacket(updates.Write());
898 }
Definition: BattlePetPackets.h:111
WorldPacket const * Write() override
Definition: BattlePetPackets.cpp:80
bool PetAdded
Definition: BattlePetPackets.h:119
std::vector< std::reference_wrapper< BattlePet > > Pets
Definition: BattlePetPackets.h:118
WorldSession * _owner
Definition: BattlePetMgr.h:208
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:214
+ Here is the call graph for this function:

◆ SummonPet()

void BattlePets::BattlePetMgr::SummonPet ( ObjectGuid  guid)
839 {
840  BattlePet* pet = GetPet(guid);
841  if (!pet)
842  return;
843 
844  BattlePetSpeciesEntry const* speciesEntry = sBattlePetSpeciesStore.LookupEntry(pet->PacketInfo.Species);
845  if (!speciesEntry)
846  return;
847 
848  Player* player = _owner->GetPlayer();
849  player->SetBattlePetData(pet);
850 
851  CastSpellExtraArgs args;
852  uint32 summonSpellId = speciesEntry->SummonSpellID;
853  if (!summonSpellId)
854  {
855  summonSpellId = uint32(SPELL_SUMMON_BATTLE_PET);
856  args.AddSpellBP0(speciesEntry->CreatureID);
857  }
858  player->CastSpell(_owner->GetPlayer(), summonSpellId, args);
859 }
Definition: DB2Structure.h:468
int32 CreatureID
Definition: DB2Structure.h:473
Definition: BattlePetMgr.h:38
DB2Storage< BattlePetSpeciesEntry > sBattlePetSpeciesStore("BattlePetSpecies.db2", BattlePetSpeciesLoadInfo::Instance())
int32 SummonSpellID
Definition: DB2Structure.h:474
WorldSession * _owner
Definition: BattlePetMgr.h:208
uint32_t uint32
Definition: Define.h:143
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:444
Player * GetPlayer() const
Definition: WorldSession.h:1001
Definition: SpellDefines.h:434
void SetBattlePetData(BattlePets::BattlePet const *pet=nullptr)
Definition: Player.cpp:21951
CastSpellExtraArgs & AddSpellBP0(int32 val)
Definition: SpellDefines.h:453
SpellCastResult CastSpell(CastSpellTargetArg const &targets, uint32 spellId, CastSpellExtraArgs const &args={ })
Definition: Object.cpp:2730
Definition: Player.h:1131
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ToggleJournalLock()

void BattlePets::BattlePetMgr::ToggleJournalLock ( bool  lock)
inline
203 { _hasJournalLock = lock; }
bool _hasJournalLock
Definition: BattlePetMgr.h:209

◆ UnlockSlot()

void BattlePets::BattlePetMgr::UnlockSlot ( BattlePetSlot  slot)
585 {
586  if (slot >= BattlePetSlot::Count)
587  return;
588 
589  uint8 slotIndex = AsUnderlyingType(slot);
590  if (!_slots[slotIndex].Locked)
591  return;
592 
593  _slots[slotIndex].Locked = false;
594 
596  updates.Slots.push_back(_slots[slotIndex]);
597  updates.AutoSlotted = false; // what's this?
598  updates.NewSlot = true; // causes the "new slot unlocked" bubble to appear
599  _owner->SendPacket(updates.Write());
600 }
constexpr std::underlying_type< E >::type AsUnderlyingType(E enumValue)
Definition: Util.h:473
bool NewSlot
Definition: BattlePetPackets.h:131
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:212
WorldPacket const * Write() override
Definition: BattlePetPackets.cpp:92
WorldSession * _owner
Definition: BattlePetMgr.h:208
bool AutoSlotted
Definition: BattlePetPackets.h:130
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
Definition: WorldSession.cpp:214
Definition: BattlePetPackets.h:122
uint8_t uint8
Definition: Define.h:145
std::vector< BattlePetSlot > Slots
Definition: BattlePetPackets.h:129
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UpdateBattlePetData()

void BattlePets::BattlePetMgr::UpdateBattlePetData ( ObjectGuid  guid)
820 {
821  BattlePet* pet = GetPet(guid);
822  if (!pet)
823  return;
824 
825  Player* player = _owner->GetPlayer();
826 
827  // Update battle pet related update fields
828  if (Creature* summonedBattlePet = player->GetSummonedBattlePet())
829  {
830  if (summonedBattlePet->GetBattlePetCompanionGUID() == guid)
831  {
832  summonedBattlePet->SetWildBattlePetLevel(pet->PacketInfo.Level);
833  player->SetBattlePetData(pet);
834  }
835  }
836 }
Definition: Creature.h:69
WorldSession * _owner
Definition: BattlePetMgr.h:208
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:444
Creature * GetSummonedBattlePet()
Definition: Player.cpp:21942
Player * GetPlayer() const
Definition: WorldSession.h:1001
void SetWildBattlePetLevel(uint32 wildBattlePetLevel)
Definition: Unit.h:1335
void SetBattlePetData(BattlePets::BattlePet const *pet=nullptr)
Definition: Player.cpp:21951
Definition: Player.h:1131
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ _hasJournalLock

bool BattlePets::BattlePetMgr::_hasJournalLock = false
private

◆ _owner

WorldSession* BattlePets::BattlePetMgr::_owner
private

◆ _pets

std::unordered_map<uint64 , BattlePet> BattlePets::BattlePetMgr::_pets
private

◆ _slots

std::vector<WorldPackets::BattlePet::BattlePetSlot> BattlePets::BattlePetMgr::_slots
private

◆ _trapLevel

uint16 BattlePets::BattlePetMgr::_trapLevel = 0
private

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