OregonCore  revision fb2a440-git
Your Favourite TBC server
Pet.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 OREGONCORE_PET_H
19 #define OREGONCORE_PET_H
20 
21 #include "ObjectGuid.h"
22 #include "Unit.h"
23 #include "TemporarySummon.h"
24 
25 enum PetType
26 {
29  CLASS_PET = 2,
31 };
32 
34 {
40 };
41 
42 // Every pet has to have a designated status at all times
43 // The status is stored in 'Player.h'
45 {
46  PET_STATUS_NONE = 0, // No pet available
47  PET_STATUS_CURRENT = 1, // Pet is currently active and alive
48  PET_STATUS_DEAD = 2, // Pet is dead, but active in the world
49  PET_STATUS_DISMISSED = 3, // Pet has been dismissed
50  PET_STATUS_DEAD_AND_REMOVED = 4 // Pet is dead and it's corpse removed from the world
51 };
52 
54 {
55  PET_MODE_UNKNOWN_0 = 0x0000001,
56  PET_MODE_UNKNOWN_2 = 0x0000100,
58 
59  // autoset in client at summon
61 };
62 
64 {
65  UNHAPPY = 1,
66  CONTENT = 2,
67  HAPPY = 3
68 };
69 
71 {
73  UNRULY = 2,
76  FAITHFUL = 5,
78 };
79 
81 {
86 };
87 
89 {
92 };
93 
94 struct PetSpell
95 {
97 
100 };
101 
103 {
108 };
109 
111 {
114 };
115 
117 {
131 };
132 
133 typedef UNORDERED_MAP<uint16, PetSpell> PetSpellMap;
134 typedef std::map<uint32, uint32> TeachSpellMap;
135 typedef std::vector<uint32> AutoSpellList;
136 
137 #define HAPPINESS_LEVEL_SIZE 333000
138 
139 extern const uint32 LevelUpLoyalty[6];
140 extern const uint32 LevelStartLoyalty[6];
141 
142 #define ACTIVE_SPELLS_MAX 4
143 
144 class Player;
145 
146 class Pet : public Guardian
147 {
148  public:
149  explicit Pet(Player* owner, PetType type = MAX_PET_TYPE);
150  ~Pet() override;
151 
152  void AddToWorld() override;
153  void RemoveFromWorld() override;
154 
156  {
157  return m_petType;
158  }
160  {
161  m_petType = type;
162  }
163  bool isControlled() const
164  {
165  return getPetType() == SUMMON_PET || getPetType() == HUNTER_PET;
166  }
167  bool isTemporarySummoned() const
168  {
169  return m_duration > 0;
170  }
171 
172  bool IsPermanentPetFor(Player* owner); // pet have tab in character windows and set UNIT_FIELD_PETNUMBER
173 
174  bool Create (uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 pet_number);
175  bool CreateBaseAtCreature(Creature* creature);
176  bool LoadPetFromDB(Player* owner, uint32 petentry = 0, uint32 petnumber = 0, bool current = false);
177  void SavePetToDB(PetSaveMode mode);
178  void Remove(PetSaveMode mode, bool returnreagent = false);
179  static void DeleteFromDB(uint32 guidlow);
180 
181  void setDeathState(DeathState s) override; // overwrite virtual Creature::setDeathState and Unit::setDeathState
182  void Update(uint32 diff) override; // overwrite virtual Creature::Update and Unit::Update
183 
184  uint8 GetPetAutoSpellSize() const override
185  {
186  return m_autospells.size();
187  }
188  uint32 GetPetAutoSpellOnPos(uint8 pos) const override
189  {
190  if (pos >= m_autospells.size())
191  return 0;
192  else
193  return m_autospells[pos];
194  }
195 
196  void RegenerateFocus();
197  void LoseHappiness();
198  void TickLoyaltyChange();
199  void ModifyLoyalty(int32 addvalue);
200  HappinessState GetHappinessState();
201  uint32 GetMaxLoyaltyPoints(uint32 level);
202  uint32 GetStartLoyaltyPoints(uint32 level);
203  void KillLoyaltyBonus(uint32 level);
205  {
206  return GetByteValue(UNIT_FIELD_BYTES_1, 1);
207  }
208  void SetLoyaltyLevel(LoyaltyLevel level);
209  void GivePetXP(uint32 xp);
210  void GivePetLevel(uint32 level);
211  void InitPetAuras(const uint32 Entry);
212  bool HaveInDiet(ItemTemplate const* item) const;
213  uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel);
214  void SetDuration(int32 dur) { m_duration = dur; }
215 
216  bool CanSwim() const { return true; }
217 
218  bool CanTakeMoreActiveSpells(uint32 SpellIconID);
219  void ToggleAutocast(uint32 spellid, bool apply);
220  bool HasTPForSpell(uint32 spellid);
221  int32 GetTPForSpell(uint32 spellid);
222 
223  void ApplyModeFlags(PetModeFlags mode, bool apply);
224  PetModeFlags GetModeFlags() const { return m_petModeFlags; }
225 
226  bool HasSpell(uint32 spell) const override;
227  void AddTeachSpell(uint32 learned_id, uint32 source_id)
228  {
229  m_teachspells[learned_id] = source_id;
230  }
231 
232  void LearnPetPassives();
233  void CastPetAuras(bool current);
234  void CastPetAura(PetAura const* aura);
235 
236  void _LoadSpellCooldowns();
237  void _SaveSpellCooldowns();
238  void _LoadAuras(uint32 timediff);
239  void _SaveAuras();
240  void _LoadSpells();
241  void _SaveSpells();
242 
244  bool learnSpell(uint16 spell_id);
245  void removeSpell(uint16 spell_id);
246 
250 
251  void InitPetCreateSpells();
252  void CheckLearning(uint32 spellid);
253  uint32 resetTalentsCost() const;
254 
255  void SetTP(int32 TP);
256  int32 GetDispTP();
257 
261 
263  {
264  return m_auraUpdateMask;
265  }
267  {
268  m_auraUpdateMask |= (uint64(1) << slot);
269  }
271  {
272  m_auraUpdateMask &= ~(uint64(1) << slot);
273  }
275  {
276  m_auraUpdateMask = 0;
277  }
278 
280  {
281  return m_declinedname;
282  }
283 
284  bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
285 
287  {
288  return m_owner;
289  }
290  protected:
296  int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
299 
301 
304 
306  private:
307 
308  // silence hidden overloaded functions warnings below
309  using Creature::SaveToDB;
311 
312  void SaveToDB(uint32, uint8, uint32) override // overwrited of Creature::SaveToDB - don't must be called
313  {
314  assert(false);
315  }
316  void DeleteFromDB() override // overwrited of Creature::DeleteFromDB - don't must be called
317  {
318  assert(false);
319  }
320 };
321 #endif
322 
bool CanSwim() const
Definition: Pet.h:216
PetSaveMode
Definition: Pet.h:33
TeachSpellMap m_teachspells
Definition: Pet.h:248
PetSpellType type
Definition: Pet.h:99
PetType
Definition: Pet.h:25
void DeleteFromDB() override
Definition: Pet.h:316
Definition: Pet.h:67
time_t m_resetTalentsTime
Definition: Pet.h:260
PetNameInvalidReason
Definition: Pet.h:116
void AddTeachSpell(uint32 learned_id, uint32 source_id)
Definition: Pet.h:227
PetSpellType
Definition: Pet.h:88
void SaveToDB(uint32, uint8, uint32) override
Definition: Pet.h:312
Player * m_owner
Definition: Pet.h:291
AutoSpellList m_autospells
Definition: Pet.h:249
uint32 m_regenTimer
Definition: Pet.h:292
const uint32 LevelUpLoyalty[6]
Definition: Pet.cpp:34
void setPetType(PetType type)
Definition: Pet.h:159
virtual void SaveToDB()
Definition: Creature.cpp:1050
uint32 m_happinessTimer
Definition: Pet.h:293
ACE_INT32 int32
Definition: Define.h:67
int32 m_duration
Definition: Pet.h:296
Definition: Pet.h:28
void apply(T *val)
Definition: ByteConverter.h:41
std::vector< uint32 > AutoSpellList
Definition: Pet.h:135
PetModeFlags m_petModeFlags
Definition: Pet.h:305
virtual void DeleteFromDB()
Definition: Creature.cpp:1461
PetSpellState
Definition: Pet.h:80
Definition: Pet.h:94
std::map< uint32, uint32 > TeachSpellMap
Definition: Pet.h:134
const uint32 LevelStartLoyalty[6]
Definition: Pet.cpp:44
Definition: Pet.h:65
void SetAuraUpdateMask(uint8 slot)
Definition: Pet.h:266
void UnsetAuraUpdateMask(uint8 slot)
Definition: Pet.h:270
Definition: Pet.h:27
ACE_UINT8 uint8
Definition: Define.h:73
PetStatus
Definition: Pet.h:44
void ResetAuraUpdateMask()
Definition: Pet.h:274
bool isTemporarySummoned() const
Definition: Pet.h:167
uint64 GetAuraUpdateMask()
Definition: Pet.h:262
LoyaltyLevel
Definition: Pet.h:70
bool isControlled() const
Definition: Pet.h:163
bool m_wasOutdoors
Definition: Pet.h:302
DeclinedName const * GetDeclinedNames() const
Definition: Pet.h:279
Player * GetOwner()
Definition: Pet.h:286
int32 m_TrainingPoints
Definition: Pet.h:258
Definition: Pet.h:74
uint32 GetLoyaltyLevel()
Definition: Pet.h:204
void SetDuration(int32 dur)
Definition: Pet.h:214
PetModeFlags GetModeFlags() const
Definition: Pet.h:224
Definition: Map.h:266
uint32 m_outdoorBonusCheckTimer
Definition: Pet.h:303
PetSpellMap m_spells
Definition: Pet.h:247
uint32 m_loyaltyTimer
Definition: Pet.h:294
DeathState
Definition: Unit.h:435
bool m_removed
Definition: Pet.h:284
ACE_UINT64 uint64
Definition: Define.h:70
ActionFeedback
Definition: Pet.h:102
uint64 m_auraUpdateMask
Definition: Pet.h:298
PetType m_petType
Definition: Pet.h:295
uint32 GetPetAutoSpellOnPos(uint8 pos) const override
Definition: Pet.h:188
PetTalk
Definition: Pet.h:110
uint16 active
Definition: Pet.h:96
Definition: Pet.h:75
uint8 GetPetAutoSpellSize() const override
Definition: Pet.h:184
UNORDERED_MAP< uint16, PetSpell > PetSpellMap
Definition: Pet.h:133
Definition: Pet.h:73
ACE_UINT16 uint16
Definition: Define.h:72
ACE_UINT32 uint32
Definition: Define.h:71
Definition: Pet.h:29
Definition: Pet.h:76
PetModeFlags
Definition: Pet.h:53
Definition: Pet.h:72
uint32 m_resetTalentsCost
Definition: Pet.h:259
Definition: Pet.h:66
Definition: Player.h:922
Definition: Pet.h:146
PetType getPetType() const
Definition: Pet.h:155
PetSpellState state
Definition: Pet.h:98
HappinessState
Definition: Pet.h:63
DeclinedName * m_declinedname
Definition: Pet.h:300
int32 m_loyaltyPoints
Definition: Pet.h:297