TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Pet.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef TRINITYCORE_PET_H
20 #define TRINITYCORE_PET_H
21 
22 #include "PetDefines.h"
23 #include "TemporarySummon.h"
24 
25 #define PET_FOCUS_REGEN_INTERVAL 4 * IN_MILLISECONDS
26 #define HAPPINESS_LEVEL_SIZE 333000
27 
28 struct PetSpell
29 {
33 };
34 
36 {
39 };
40 
41 typedef std::unordered_map<uint32, PetSpell> PetSpellMap;
42 typedef std::vector<uint32> AutoSpellList;
43 
44 class Player;
45 
46 class TC_GAME_API Pet : public Guardian
47 {
48  public:
49  explicit Pet(Player* owner, PetType type = MAX_PET_TYPE);
50  virtual ~Pet();
51 
52  void AddToWorld() override;
53  void RemoveFromWorld() override;
54 
55  void SetDisplayId(uint32 modelId) override;
56 
57  PetType getPetType() const { return m_petType; }
58  void setPetType(PetType type) { m_petType = type; }
59  bool isControlled() const { return getPetType() == SUMMON_PET || getPetType() == HUNTER_PET; }
60  bool isTemporarySummoned() const { return m_duration > 0; }
61 
62  bool IsPermanentPetFor(Player* owner) const; // pet have tab in character windows and set UNIT_FIELD_PETNUMBER
63 
64  bool Create(ObjectGuid::LowType guidlow, Map* map, uint32 Entry);
65  bool CreateBaseAtCreature(Creature* creature);
66  bool CreateBaseAtCreatureInfo(CreatureTemplate const* cinfo, Unit* owner);
67  bool CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map);
68  bool LoadPetFromDB(Player* owner, uint32 petentry = 0, uint32 petnumber = 0, bool current = false);
69  bool IsLoading() const override { return m_loading;}
70  void SavePetToDB(PetSaveMode mode);
71  void Remove(PetSaveMode mode, bool returnreagent = false);
72  static void DeleteFromDB(uint32 guidlow);
73 
74  void setDeathState(DeathState s) override; // overwrite virtual Creature::setDeathState and Unit::setDeathState
75  void Update(uint32 diff) override; // overwrite virtual Creature::Update and Unit::Update
76 
77  uint8 GetPetAutoSpellSize() const override { return uint8(m_autospells.size()); }
78  uint32 GetPetAutoSpellOnPos(uint8 pos) const override
79  {
80  if (pos >= m_autospells.size())
81  return 0;
82  else
83  return m_autospells[pos];
84  }
85 
86  void GivePetXP(uint32 xp);
87  void GivePetLevel(uint8 level);
88  void SynchronizeLevelWithOwner();
89  bool HaveInDiet(ItemTemplate const* item) const;
90  uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel) const;
91  void SetDuration(int32 dur) { m_duration = dur; }
92  int32 GetDuration() const { return m_duration; }
93 
94  /*
95  bool UpdateStats(Stats stat);
96  bool UpdateAllStats();
97  void UpdateResistances(uint32 school);
98  void UpdateArmor();
99  void UpdateMaxHealth();
100  void UpdateMaxPower(Powers power);
101  void UpdateAttackPowerAndDamage(bool ranged = false);
102  void UpdateDamagePhysical(WeaponAttackType attType) override;
103  */
104 
105  void ToggleAutocast(SpellInfo const* spellInfo, bool apply);
106 
107  bool HasSpell(uint32 spell) const override;
108 
109  void LearnPetPassives();
110  void CastPetAuras(bool current);
111  void CastPetAura(PetAura const* aura);
112  bool IsPetAura(Aura const* aura);
113 
114  void _LoadSpellCooldowns();
115  void _LoadAuras(uint32 timediff);
116  void _SaveAuras(SQLTransaction& trans);
117  void _LoadSpells();
118  void _SaveSpells(SQLTransaction& trans);
119 
120  bool addSpell(uint32 spellId, ActiveStates active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, PetSpellType type = PETSPELL_NORMAL);
121  bool learnSpell(uint32 spell_id);
122  void learnSpellHighRank(uint32 spellid);
123  void InitLevelupSpellsForLevel();
124  bool unlearnSpell(uint32 spell_id, bool learn_prev, bool clear_ab = true);
125  bool removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab = true);
126  void CleanupActionBar();
127 
130 
131  void InitPetCreateSpells();
132 
133  bool resetTalents();
134  static void resetTalentsForAllPetsOf(Player* owner, Pet* online_pet = nullptr);
135  void InitTalentForLevel();
136 
137  uint8 GetMaxTalentPointsForLevel(uint8 level) const;
140 
142 
143  uint32 GetGroupUpdateFlag() const { return m_groupUpdateMask; }
144  void SetGroupUpdateFlag(uint32 flag);
145  void ResetGroupUpdateFlag();
146 
147  DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
148 
149  bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
150 
151  Player* GetOwner() const;
152 
153  protected:
155  int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
156  bool m_loading;
159 
161 
162  private:
163  void SaveToDB(uint32, uint32, uint32) override // override of Creature::SaveToDB - must not be called
164  {
165  ABORT();
166  }
167  void DeleteFromDB() override // override of Creature::DeleteFromDB - must not be called
168  {
169  ABORT();
170  }
171 };
172 #endif
bool Remove(ContainerUnorderedMap< SPECIFIC_TYPE, KEY_TYPE > &elements, KEY_TYPE const &handle, SPECIFIC_TYPE *)
Definition: TypeContainerFunctions.h:104
PetSpellType type
Definition: Pet.h:32
Definition: TemporarySummon.h:83
Definition: PetDefines.h:24
void DeleteFromDB() override
Definition: Pet.h:167
void AddToWorld() override
Definition: Creature.cpp:218
Definition: SpellInfo.h:326
uint32 m_usedTalentCount
Definition: Pet.h:141
Definition: PetDefines.h:52
AutoSpellList m_autospells
Definition: Pet.h:129
void SaveToDB(uint32, uint32, uint32) override
Definition: Pet.h:163
void setPetType(PetType type)
Definition: Pet.h:58
bool Create(ObjectGuid::LowType guidlow, Map *map, uint32 phaseMask, uint32 entry, float x, float y, float z, float ang, CreatureData const *data=nullptr, uint32 vehId=0)
Definition: Creature.cpp:834
bool HasSpell(uint32 spellID) const override
Definition: Creature.cpp:2337
int32 m_duration
Definition: Pet.h:155
Definition: Creature.h:467
uint32 m_groupUpdateMask
Definition: Pet.h:158
bool m_loading
Definition: Pet.h:156
uint64 LowType
Definition: ObjectGuid.h:199
void apply(T *val)
Definition: ByteConverter.h:41
PetStableinfo
Definition: Pet.h:35
std::vector< uint32 > AutoSpellList
Definition: Pet.h:42
int32 GetDuration() const
Definition: Pet.h:92
bool IsLoading() const override
Definition: Pet.h:69
virtual void DeleteFromDB()
Definition: Creature.cpp:1474
Definition: PetDefines.h:25
Definition: Pet.h:28
std::unordered_map< uint32, PetSpell > PetSpellMap
Definition: Pet.h:41
Definition: Unit.h:1124
uint8 GetPetAutoSpellSize() const override
Definition: Pet.h:77
Definition: PetDefines.h:58
Unit * GetOwner() const
Definition: TemporarySummon.h:72
PetSaveMode
Definition: PetDefines.h:32
Entry
Definition: boss_headless_horseman.cpp:50
void setDeathState(DeathState s) override
Definition: Creature.cpp:1624
Definition: SpellMgr.h:433
bool isTemporarySummoned() const
Definition: Pet.h:60
void SetByteValue(uint16 index, uint8 offset, uint8 value)
Definition: Object.cpp:1080
uint8 GetFreeTalentPoints() const
Definition: Pet.h:138
bool isControlled() const
Definition: Pet.h:59
DeclinedName const * GetDeclinedNames() const
Definition: Pet.h:147
int32_t int32
Definition: Define.h:146
uint32 GetGroupUpdateFlag() const
Definition: Pet.h:143
uint32_t uint32
Definition: Define.h:150
Definition: PetDefines.h:26
void SetFreeTalentPoints(uint8 points)
Definition: Pet.h:139
void SetDuration(int32 dur)
Definition: Pet.h:91
Definition: Map.h:259
void RemoveFromWorld() override
Definition: TemporarySummon.cpp:310
PetSpellMap m_spells
Definition: Pet.h:128
DeathState
Definition: Unit.h:539
bool m_removed
Definition: Pet.h:149
ActiveStates
Definition: Unit.h:1117
uint8_t uint8
Definition: g3dmath.h:164
void SetDisplayId(uint32 modelId) override
Definition: Creature.cpp:2664
Definition: ItemTemplate.h:647
PetType m_petType
Definition: Pet.h:154
uint32 m_focusRegenTimer
Definition: Pet.h:157
PetSpellType
Definition: PetDefines.h:56
Definition: Pet.h:38
#define TC_GAME_API
Definition: Define.h:134
Definition: Pet.h:37
#define ABORT
Definition: Errors.h:56
Definition: UpdateFields.h:124
uint8_t uint8
Definition: Define.h:152
uint32 GetPetAutoSpellOnPos(uint8 pos) const override
Definition: Pet.h:78
void Update(uint32 time) override
Definition: TemporarySummon.cpp:47
Definition: Unit.h:1101
Definition: SpellAuras.h:116
ActiveStates active
Definition: Pet.h:30
PetSpellState
Definition: PetDefines.h:48
Definition: Unit.h:1305
PetType
Definition: PetDefines.h:22
Definition: Creature.h:79
uint8 GetByteValue(uint16 index, uint8 offset) const
Definition: Object.cpp:318
Definition: Pet.h:46
PetType getPetType() const
Definition: Pet.h:57
PetSpellState state
Definition: Pet.h:31
DeclinedName * m_declinedname
Definition: Pet.h:160
std::shared_ptr< Transaction > SQLTransaction
Definition: Transaction.h:58