TrinityCore
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{
31{
35
39};
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
97{
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
106{
113 STATE_GENDER = 78, // 1 - male, 2 - female
121 // these are not in BattlePetState.db2 but are used in BattlePetSpeciesState.db2
124 //
127
129{
135
137{
138 void CalculateStats();
139
141 time_t NameTimestamp = time_t(0);
142 std::unique_ptr<::DeclinedName> DeclinedName;
144};
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
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);
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::vector<std::reference_wrapper<BattlePet>> 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:123
uint8_t uint8
Definition: Define.h:144
uint64_t uint64
Definition: Define.h:141
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
static void SaveToDB(QuestPool const &pool, CharacterDatabaseTransaction trans)
Definition: QuestPools.cpp:50
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:211
void ToggleJournalLock(bool lock)
Definition: BattlePetMgr.h:202
uint16 GetTrapLevel() const
Definition: BattlePetMgr.h:181
BattlePetMgr(BattlePetMgr const &right)=delete
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:210
WorldSession * GetOwner() const
Definition: BattlePetMgr.h:179
bool HasJournalLock() const
Definition: BattlePetMgr.h:201
WorldPackets::BattlePet::BattlePetSlot * GetSlot(BattlePetSlot slot)
Definition: BattlePetMgr.h:176
std::vector< WorldPackets::BattlePet::BattlePetSlot > const & GetSlots() const
Definition: BattlePetMgr.h:183
BattlePetMgr(BattlePetMgr &&right)=delete
Player session in the World.
Definition: WorldSession.h:963
@ FLAGS_CONTROL_TYPE_APPLY
Definition: BattlePetMgr.h:98
@ FLAGS_CONTROL_TYPE_REMOVE
Definition: BattlePetMgr.h:99
DEFINE_ENUM_FLAG(BattlePetDbFlags)
@ BATTLE_PET_UNCHANGED
Definition: BattlePetMgr.h:130
@ BATTLE_PET_REMOVED
Definition: BattlePetMgr.h:133
@ BATTLE_PET_CHANGED
Definition: BattlePetMgr.h:131
@ SPELL_SUMMON_BATTLE_PET
Definition: BattlePetMgr.h:38
@ SPELL_REVIVE_BATTLE_PETS
Definition: BattlePetMgr.h:37
@ DEFAULT_MAX_BATTLE_PETS_PER_SPECIES
Definition: BattlePetMgr.h:32
@ SPELL_VISUAL_UNCAGE_PET
Definition: BattlePetMgr.h:34
@ SPELL_BATTLE_PET_TRAINING
Definition: BattlePetMgr.h:36
@ BATTLE_PET_CAGE_ITEM_ID
Definition: BattlePetMgr.h:33
static constexpr uint16 MAX_BATTLE_PET_LEVEL
Definition: BattlePetMgr.h:41
@ STATE_COSMETIC_WATER_BUBBLED
Definition: BattlePetMgr.h:114
@ STATE_MOD_DAMAGE_DEALT_PERCENT
Definition: BattlePetMgr.h:112
@ STATE_MAX_HEALTH_BONUS
Definition: BattlePetMgr.h:107
@ STATE_COSMETIC_SPECTRAL_BLUE
Definition: BattlePetMgr.h:125
@ STATE_SPECIAL_IS_COCKROACH
Definition: BattlePetMgr.h:115
@ STATE_PASSIVE_ELITE
Definition: BattlePetMgr.h:118
@ STATE_STAT_STAMINA
Definition: BattlePetMgr.h:110
@ STATE_INTERNAL_INITIAL_LEVEL
Definition: BattlePetMgr.h:108
@ STATE_PASSIVE_BOSS
Definition: BattlePetMgr.h:119
@ STATE_START_WITH_BUFF_2
Definition: BattlePetMgr.h:123
@ STATE_COSMETIC_FLY_TIER
Definition: BattlePetMgr.h:116
@ STATE_START_WITH_BUFF
Definition: BattlePetMgr.h:122
@ STATE_COSMETIC_TREASURE_GOBLIN
Definition: BattlePetMgr.h:120
@ STATE_COSMETIC_BIGGLESWORTH
Definition: BattlePetMgr.h:117
TC_GAME_API Pet * GetPet(WorldObject const &, ObjectGuid const &guid)
WorldPackets::BattlePet::BattlePet PacketInfo
Definition: BattlePetMgr.h:140
std::unique_ptr<::DeclinedName > DeclinedName
Definition: BattlePetMgr.h:142
BattlePetSaveInfo SaveInfo
Definition: BattlePetMgr.h:143