TrinityCore
Loading...
Searching...
No Matches
BattlePetMgr.h
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#ifndef BattlePetMgr_h__
19#define BattlePetMgr_h__
20
21#include "BattlePetPackets.h"
22#include "DatabaseEnvFwd.h"
23#include "EnumFlag.h"
24#include <unordered_map>
25
27
28namespace BattlePets
29{
40
41static constexpr uint16 MAX_BATTLE_PET_LEVEL = 25;
42
44{
45 Poor = 0,
46 Common = 1,
47 Uncommon = 2,
48 Rare = 3,
49 Epic = 4,
50 Legendary = 5,
51
52 Count
53};
54
56{
57 None = 0x000,
58 Favorite = 0x001,
59 Converted = 0x002,
60 Revoked = 0x004,
61 LockedForConvert = 0x008,
62 Ability0Selection = 0x010,
63 Ability1Selection = 0x020,
64 Ability2Selection = 0x040,
65 FanfareNeeded = 0x080,
66 DisplayOverridden = 0x100
67};
68
70
72{
73 CantHaveMorePetsOfType = 3, // You can't have any more pets of that type.
74 CantHaveMorePets = 4, // You can't have any more pets.
75 TooHighLevelToUncage = 7 // This pet is too high level for you to uncage.
76};
77
78enum class BattlePetSlot : uint8
79{
80 Slot0 = 0,
81 Slot1 = 1,
82 Slot2 = 2,
83
84 Count
85};
86
88{
89 PetBattle = 0,
90 SpellEffect = 1,
91
92 Count
93};
94
95// 6.2.4
101
102// taken from BattlePetState.db2 - it seems to store some initial values for battle pets
103// there are only values used in BattlePetSpeciesState.db2 and BattlePetBreedState.db2
104// TODO: expand this enum if needed
127
135
145
147{
148public:
149 explicit BattlePetMgr(WorldSession* owner);
150 BattlePetMgr(BattlePetMgr const& right) = delete;
151 BattlePetMgr(BattlePetMgr&& right) = delete;
152
153 static void Initialize();
154
155 static void AddBattlePetSpeciesBySpell(uint32 spellId, BattlePetSpeciesEntry const* speciesEntry);
156 static BattlePetSpeciesEntry const* GetBattlePetSpeciesByCreature(uint32 creatureId);
157 static BattlePetSpeciesEntry const* GetBattlePetSpeciesBySpell(uint32 spellId);
158 static uint16 RollPetBreed(uint32 species);
159 static BattlePetBreedQuality GetDefaultPetQuality(uint32 species);
160 static uint32 SelectPetDisplay(BattlePetSpeciesEntry const* speciesEntry);
161
162 void LoadFromDB(PreparedQueryResult pets, PreparedQueryResult slots);
164
165 BattlePet* GetPet(ObjectGuid guid);
166 void AddPet(uint32 species, uint32 display, uint16 breed, BattlePetBreedQuality quality, uint16 level = 1);
167 void RemovePet(ObjectGuid guid);
168 void ClearFanfare(ObjectGuid guid);
169 void ModifyName(ObjectGuid guid, std::string const& name, std::unique_ptr<DeclinedName> declinedName);
170 bool IsPetInSlot(ObjectGuid guid) const;
171
172 uint8 GetPetCount(BattlePetSpeciesEntry const* battlePetSpecies, ObjectGuid ownerGuid) const;
173 bool HasMaxPetCount(BattlePetSpeciesEntry const* battlePetSpecies, ObjectGuid ownerGuid) const;
174 uint32 GetPetUniqueSpeciesCount() const;
175
176 WorldPackets::BattlePet::BattlePetSlot* GetSlot(BattlePetSlot slot) { return slot < BattlePetSlot::Count ? &_slots[size_t(slot)] : nullptr; }
177 void UnlockSlot(BattlePetSlot slot);
178
179 WorldSession* GetOwner() const { return _owner; }
180
181 uint16 GetTrapLevel() const { return _trapLevel; }
182 uint16 GetMaxPetLevel() const;
183 std::vector<WorldPackets::BattlePet::BattlePetSlot> const& GetSlots() const { return _slots; }
184
185 void CageBattlePet(ObjectGuid guid);
186 void ChangeBattlePetQuality(ObjectGuid guid, BattlePetBreedQuality quality);
187 void GrantBattlePetExperience(ObjectGuid guid, uint16 xp, BattlePetXpSource xpSource);
188 void GrantBattlePetLevel(ObjectGuid guid, uint16 grantedLevels);
189 void HealBattlePetsPct(uint8 pct);
190 void UpdateBattlePetData(ObjectGuid guid);
191
192 void SummonPet(ObjectGuid guid);
193 void DismissPet();
194
195 void SendJournal();
196 void SendUpdates(std::span<std::reference_wrapper<BattlePet const> const> pets, bool petAdded);
197 void SendError(BattlePetError error, uint32 creatureId);
198
199 void SendJournalLockStatus();
200 bool IsJournalLockAcquired() const;
201 bool HasJournalLock() const { return _hasJournalLock; }
202 void ToggleJournalLock(bool lock) { _hasJournalLock = lock; }
203
204 bool IsBattlePetSystemEnabled() { return GetSlot(BattlePetSlot::Slot0)->Locked != true; }
205
206private:
208 bool _hasJournalLock = false;
209 uint16 _trapLevel = 0;
210 std::unordered_map<uint64 /*battlePetGuid*/, BattlePet> _pets;
211 std::vector<WorldPackets::BattlePet::BattlePetSlot> _slots;
212
213 static void LoadAvailablePetBreeds();
214 static void LoadDefaultPetQualities();
215};
216}
217#endif // BattlePetMgr_h__
SQLTransaction< LoginDatabaseConnection > LoginDatabaseTransaction
std::shared_ptr< PreparedResultSet > PreparedQueryResult
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
uint64_t uint64
Definition Define.h:153
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
#define DEFINE_ENUM_FLAG(enumType)
Definition EnumFlag.h:26
static void SaveToDB(QuestPool const &pool, CharacterDatabaseTransaction trans)
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
void ToggleJournalLock(bool lock)
uint16 GetTrapLevel() const
BattlePetMgr(BattlePetMgr const &right)=delete
std::unordered_map< uint64, BattlePet > _pets
WorldSession * GetOwner() const
WorldPackets::BattlePet::BattlePetSlot * GetSlot(BattlePetSlot slot)
std::vector< WorldPackets::BattlePet::BattlePetSlot > const & GetSlots() const
BattlePetMgr(BattlePetMgr &&right)=delete
Player session in the World.
@ FLAGS_CONTROL_TYPE_APPLY
@ FLAGS_CONTROL_TYPE_REMOVE
@ SPELL_SUMMON_BATTLE_PET
@ SPELL_REVIVE_BATTLE_PETS
@ DEFAULT_MAX_BATTLE_PETS_PER_SPECIES
@ SPELL_VISUAL_UNCAGE_PET
@ SPELL_BATTLE_PET_TRAINING
@ BATTLE_PET_CAGE_ITEM_ID
static constexpr uint16 MAX_BATTLE_PET_LEVEL
@ STATE_COSMETIC_WATER_BUBBLED
@ STATE_MOD_DAMAGE_DEALT_PERCENT
@ STATE_MAX_HEALTH_BONUS
@ STATE_COSMETIC_SPECTRAL_BLUE
@ STATE_SPECIAL_IS_COCKROACH
@ STATE_INTERNAL_INITIAL_LEVEL
@ STATE_START_WITH_BUFF_2
@ STATE_COSMETIC_FLY_TIER
@ STATE_START_WITH_BUFF
@ STATE_COSMETIC_TREASURE_GOBLIN
@ STATE_COSMETIC_BIGGLESWORTH
WorldPackets::BattlePet::BattlePet PacketInfo
std::unique_ptr<::DeclinedName > DeclinedName
BattlePetSaveInfo SaveInfo