TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BattlePetMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
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 "DB2Stores.h"
22 #include "BattlePetPackets.h"
23 
25 {
30 };
31 
32 // TODO: fix undefined values in this enum
34 {
38 
39  // wrong order
47 };
48 
49 // taken from BattlePetState.db2 - it seems to store some initial values for battle pets
50 // there are only values used in BattlePetSpeciesState.db2 and BattlePetBreedState.db2
51 // TODO: expand this enum if needed
53 {
60  STATE_GENDER = 78, // 1 - male, 2 - female
68  // these are not in BattlePetState.db2 but are used in BattlePetSpeciesState.db2
71  //
73 };
74 
76 {
81 };
82 
84 {
85 public:
86  struct BattlePet
87  {
88  void CalculateStats();
89 
92  };
93 
94  explicit BattlePetMgr(WorldSession* owner);
95 
96  static void Initialize();
97 
98  static uint16 RollPetBreed(uint32 species);
99  static uint8 GetDefaultPetQuality(uint32 species);
100 
102  void SaveToDB(SQLTransaction& trans);
103 
104  BattlePet* GetPet(ObjectGuid guid);
105  void AddPet(uint32 species, uint32 creatureId, uint16 breed, uint8 quality, uint16 level = 1);
106  void RemovePet(ObjectGuid guid);
107 
108  uint8 GetPetCount(uint32 species) const;
109 
111  void UnlockSlot(uint8 slot);
112 
113  WorldSession* GetOwner() const { return _owner; }
114 
115  uint16 GetTrapLevel() const { return _trapLevel; }
116  std::vector<BattlePet> GetLearnedPets() const;
117  std::vector<WorldPackets::BattlePet::BattlePetSlot> GetSlots() const { return _slots; }
118 
119  void CageBattlePet(ObjectGuid guid);
120  void HealBattlePetsPct(uint8 pct);
121 
122  void SummonPet(ObjectGuid guid);
123 
124  void SendUpdates(std::vector<BattlePet> pets, bool petAdded);
125  void SendError(BattlePetError error, uint32 creatureId);
126 
127 private:
130  std::unordered_map<uint64 /*battlePetGuid*/, BattlePet> _pets;
131  std::vector<WorldPackets::BattlePet::BattlePetSlot> _slots;
132 
133  static void LoadAvailablePetBreeds();
134  static void LoadDefaultPetQualities();
135 
136  // hash no longer required in C++14
137  static std::unordered_map<uint16 /*BreedID*/, std::unordered_map<BattlePetState /*state*/, int32 /*value*/, std::hash<std::underlying_type<BattlePetState>::type> >> _battlePetBreedStates;
138  static std::unordered_map<uint32 /*SpeciesID*/, std::unordered_map<BattlePetState /*state*/, int32 /*value*/, std::hash<std::underlying_type<BattlePetState>::type> >> _battlePetSpeciesStates;
139  static std::unordered_map<uint32 /*SpeciesID*/, std::unordered_set<uint8 /*breed*/>> _availableBreedsPerSpecies;
140  static std::unordered_map<uint32 /*SpeciesID*/, uint8 /*quality*/> _defaultQualityPerSpecies;
141 };
142 
143 #endif // BattlePetMgr_h__
Definition: BattlePetMgr.h:56
void AddPet(uint32 species, uint32 creatureId, uint16 breed, uint8 quality, uint16 level=1)
Definition: BattlePetMgr.cpp:310
uint16 GetTrapLevel() const
Definition: BattlePetMgr.h:115
Definition: BattlePetMgr.h:27
void SaveToDB(SQLTransaction &trans)
Definition: BattlePetMgr.cpp:235
Definition: BattlePetMgr.h:80
std::unordered_map< uint64, BattlePet > _pets
Definition: BattlePetMgr.h:130
std::vector< BattlePet > GetLearnedPets() const
Definition: BattlePetMgr.cpp:377
WorldPackets::BattlePet::BattlePet PacketInfo
Definition: BattlePetMgr.h:90
Definition: BattlePetMgr.h:36
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
static void LoadDefaultPetQualities()
Definition: BattlePetMgr.cpp:125
Definition: BattlePetMgr.h:57
Definition: BattlePetMgr.h:66
BattlePetSaveInfo SaveInfo
Definition: BattlePetMgr.h:91
Definition: BattlePetMgr.h:41
Definition: BattlePetMgr.h:64
static std::unordered_map< uint32, uint8 > _defaultQualityPerSpecies
Definition: BattlePetMgr.h:140
WorldSession * GetOwner() const
Definition: BattlePetMgr.h:113
static uint16 RollPetBreed(uint32 species)
Definition: BattlePetMgr.cpp:154
BattlePetSaveInfo
Definition: BattlePetMgr.h:75
void HealBattlePetsPct(uint8 pct)
Definition: BattlePetMgr.cpp:417
Definition: BattlePetPackets.h:29
Definition: BattlePetMgr.h:46
Definition: BattlePetMgr.h:69
WorldPackets::BattlePet::BattlePetSlot * GetSlot(uint8 slot)
Definition: BattlePetMgr.h:110
Definition: BattlePetMgr.h:44
BattlePetMgr(WorldSession *owner)
Definition: BattlePetMgr.cpp:172
Definition: BattlePetMgr.h:72
Definition: BattlePetMgr.h:62
BattlePetError
Definition: BattlePetMgr.h:33
Definition: BattlePetMgr.h:77
static std::unordered_map< uint32, std::unordered_map< BattlePetState, int32, std::hash< std::underlying_type< BattlePetState >::type > > > _battlePetSpeciesStates
Definition: BattlePetMgr.h:138
Definition: BattlePetMgr.h:63
void LoadFromDB(PreparedQueryResult pets, PreparedQueryResult slots)
Definition: BattlePetMgr.cpp:183
void SendError(BattlePetError error, uint32 creatureId)
Definition: BattlePetMgr.cpp:463
WorldSession * _owner
Definition: BattlePetMgr.h:128
Definition: BattlePetMgr.h:37
Definition: BattlePetMgr.h:60
void RemovePet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:339
Definition: BattlePetMgr.h:65
Definition: BattlePetMgr.h:26
int32_t int32
Definition: Define.h:146
Definition: BattlePetMgr.h:55
Definition: BattlePetMgr.h:67
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
Definition: BattlePetMgr.h:42
uint16_t uint16
Definition: Define.h:151
Definition: BattlePetMgr.h:45
uint8 GetPetCount(uint32 species) const
Definition: BattlePetMgr.cpp:353
void UnlockSlot(uint8 slot)
Definition: BattlePetMgr.cpp:363
Definition: BattlePetMgr.h:61
Definition: BattlePetMgr.h:43
std::vector< WorldPackets::BattlePet::BattlePetSlot > GetSlots() const
Definition: BattlePetMgr.h:117
Definition: BattlePetMgr.h:83
Definition: BattlePetMgr.h:79
Definition: BattlePetMgr.h:86
Definition: BattlePetMgr.h:29
void CageBattlePet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:387
std::vector< WorldPackets::BattlePet::BattlePetSlot > _slots
Definition: BattlePetMgr.h:131
Definition: BattlePetPackets.h:48
uint16 _trapLevel
Definition: BattlePetMgr.h:129
static uint8 GetDefaultPetQuality(uint32 species)
Definition: BattlePetMgr.cpp:163
Definition: BattlePetMgr.h:54
static std::unordered_map< uint16, std::unordered_map< BattlePetState, int32, std::hash< std::underlying_type< BattlePetState >::type > > > _battlePetBreedStates
Definition: BattlePetMgr.h:137
Definition: BattlePetMgr.h:70
uint8_t uint8
Definition: Define.h:152
void SummonPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:437
void CalculateStats()
Definition: BattlePetMgr.cpp:25
static void LoadAvailablePetBreeds()
Definition: BattlePetMgr.cpp:94
Player session in the World.
Definition: WorldSession.h:882
Definition: ObjectGuid.h:189
Definition: BattlePetMgr.h:78
Definition: BattlePetMgr.h:59
BattlePetMisc
Definition: BattlePetMgr.h:24
static std::unordered_map< uint32, std::unordered_set< uint8 > > _availableBreedsPerSpecies
Definition: BattlePetMgr.h:139
void SendUpdates(std::vector< BattlePet > pets, bool petAdded)
Definition: BattlePetMgr.cpp:453
Definition: BattlePetMgr.h:40
BattlePetState
Definition: BattlePetMgr.h:52
Definition: BattlePetMgr.h:58
Definition: BattlePetMgr.h:28
BattlePet * GetPet(ObjectGuid guid)
Definition: BattlePetMgr.cpp:301
static void Initialize()
Definition: BattlePetMgr.cpp:79
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58