TrinityCore
Loading...
Searching...
No Matches
Pet.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 TRINITYCORE_PET_H
19#define TRINITYCORE_PET_H
20
21#include "PetDefines.h"
22#include "TemporarySummon.h"
23
24#define HAPPINESS_LEVEL_SIZE 333000
25
27{
31};
32
34{
37};
38
39typedef std::unordered_map<uint32, PetSpell> PetSpellMap;
40typedef std::vector<uint32> AutoSpellList;
41
42class Player;
43class PetAura;
44
45class TC_GAME_API Pet : public Guardian
46{
47 public:
48 explicit Pet(Player* owner, PetType type = MAX_PET_TYPE);
49 virtual ~Pet();
50
51 void AddToWorld() override;
52 void RemoveFromWorld() override;
53
54 float GetNativeObjectScale() const override;
55 void SetDisplayId(uint32 modelId, float displayScale = 1.f) 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, uint32 pet_number);
65 bool CreateBaseAtCreature(Creature* creature);
66 bool CreateBaseAtCreatureInfo(CreatureTemplate const* cinfo, Unit* owner);
67 bool CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map);
68 static std::pair<PetStable::PetInfo const*, PetSaveMode> GetLoadPetInfo(PetStable const& stable, uint32 petEntry, uint32 petnumber, Optional<PetSaveMode> slot);
69 bool LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool current, Optional<PetSaveMode> forcedSlot = {});
70 bool IsLoading() const override { return m_loading;}
71 void SavePetToDB(PetSaveMode mode);
72 void FillPetInfo(PetStable::PetInfo* petInfo) const;
73 void Remove(PetSaveMode mode, bool returnreagent = false);
74 static void DeleteFromDB(uint32 petNumber);
75
76 void setDeathState(DeathState s) override; // overwrite virtual Creature::setDeathState and Unit::setDeathState
77 void Update(uint32 diff) override; // overwrite virtual Creature::Update and Unit::Update
78
79 uint8 GetPetAutoSpellSize() const override { return uint8(m_autospells.size()); }
80 uint32 GetPetAutoSpellOnPos(uint8 pos) const override
81 {
82 if (pos >= m_autospells.size())
83 return 0;
84 else
85 return m_autospells[pos];
86 }
87
88 void GivePetXP(uint32 xp);
89 void GivePetLevel(uint8 level);
90 void SetPetExperience(uint32 xp) { SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::PetExperience), xp); }
92 void SynchronizeLevelWithOwner();
93 bool HaveInDiet(ItemTemplate const* item) const;
94 void SetDuration(int32 dur) { m_duration = dur; }
95 int32 GetDuration() const { return m_duration; }
96
97 /*
98 bool UpdateStats(Stats stat);
99 bool UpdateAllStats();
100 void UpdateResistances(uint32 school);
101 void UpdateArmor();
102 void UpdateMaxHealth();
103 void UpdateMaxPower(Powers power);
104 void UpdateAttackPowerAndDamage(bool ranged = false);
105 void UpdateDamagePhysical(WeaponAttackType attType) override;
106 */
107
108 void ToggleAutocast(SpellInfo const* spellInfo, bool apply);
109
110 bool HasSpell(uint32 spell) const override;
111
112 void LearnPetPassives();
113 void CastPetAuras(bool current);
114 void CastPetAura(PetAura const* aura);
115 bool IsPetAura(Aura const* aura);
116
117 void _LoadAuras(PreparedQueryResult auraResult, PreparedQueryResult effectResult, uint32 timediff);
118 void _SaveAuras(CharacterDatabaseTransaction trans);
119 void _LoadSpells(PreparedQueryResult result);
120 void _SaveSpells(CharacterDatabaseTransaction trans);
121
122 bool addSpell(uint32 spellId, ActiveStates active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, PetSpellType type = PETSPELL_NORMAL);
123 bool learnSpell(uint32 spell_id);
124 void learnSpells(std::vector<uint32> const& spellIds);
125 void learnSpellHighRank(uint32 spellid);
126 void InitLevelupSpellsForLevel();
127 bool unlearnSpell(uint32 spell_id, bool learn_prev, bool clear_ab = true);
128 void unlearnSpells(std::vector<uint32> const& spellIds, bool learn_prev, bool clear_ab = true);
129 bool removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab = true);
130 void CleanupActionBar();
131 std::string GenerateActionBarData() const;
132
135
136 void InitPetCreateSpells();
137
138 uint16 GetSpecialization() const { return m_petSpecialization; }
139 void SetSpecialization(uint16 spec);
140 void LearnSpecializationSpells();
141 void RemoveSpecializationSpells(bool clearActionBar);
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.get(); }
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 std::string GetDebugInfo() const override;
154
155 protected:
157 int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
161
162 std::unique_ptr<DeclinedName> m_declinedname;
163
165
166 private:
167 void SaveToDB(uint32, std::vector<Difficulty> const&) override // override of Creature::SaveToDB - must not be called
168 {
169 ABORT();
170 }
171};
172#endif
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
Definition: DatabaseEnvFwd.h:72
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: DatabaseEnvFwd.h:48
#define TC_GAME_API
Definition: Define.h:124
uint8_t uint8
Definition: Define.h:145
int32_t int32
Definition: Define.h:139
uint16_t uint16
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:143
#define ABORT
Definition: Errors.h:74
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
PetSpellState
Definition: PetDefines.h:62
@ PETSPELL_NEW
Definition: PetDefines.h:65
PetType
Definition: PetDefines.h:30
@ SUMMON_PET
Definition: PetDefines.h:31
@ HUNTER_PET
Definition: PetDefines.h:32
@ MAX_PET_TYPE
Definition: PetDefines.h:33
PetSpellType
Definition: PetDefines.h:70
@ PETSPELL_NORMAL
Definition: PetDefines.h:71
PetSaveMode
Definition: PetDefines.h:41
PetStableinfo
Definition: Pet.h:34
@ PET_STABLE_INACTIVE
Definition: Pet.h:36
@ PET_STABLE_ACTIVE
Definition: Pet.h:35
std::unordered_map< uint32, PetSpell > PetSpellMap
Definition: Pet.h:39
std::vector< uint32 > AutoSpellList
Definition: Pet.h:40
ActiveStates
Definition: UnitDefines.h:477
@ ACT_DECIDE
Definition: UnitDefines.h:483
DeathState
Definition: Unit.h:234
uint32 const Entry[5]
Definition: boss_nefarian.cpp:163
Definition: SpellAuras.h:123
Definition: Creature.h:70
bool HasSpell(uint32 spellID) const override
Definition: Creature.cpp:2737
void SetDisplayId(uint32 displayId, float displayScale=1.f) override
Definition: Creature.cpp:3259
bool Create(ObjectGuid::LowType guidlow, Map *map, uint32 entry, Position const &pos, CreatureData const *data, uint32 vehId, bool dynamic=false)
Definition: Creature.cpp:1061
void AddToWorld() override
Definition: Creature.cpp:324
static bool DeleteFromDB(ObjectGuid::LowType spawnId)
Definition: Creature.cpp:1925
float GetNativeObjectScale() const override
Definition: Creature.cpp:3243
Definition: TemporarySummon.h:117
std::string GetDebugInfo() const override
Definition: TemporarySummon.cpp:483
Definition: Map.h:185
void setDeathState(DeathState s) override
Definition: TemporarySummon.cpp:411
void RemoveFromWorld() override
Definition: TemporarySummon.cpp:402
Unit * GetOwner() const
Definition: TemporarySummon.h:89
uint64 LowType
Definition: ObjectGuid.h:268
void SetUpdateFieldValue(UF::UpdateFieldSetter< T > setter, typename UF::UpdateFieldSetter< T >::value_type value)
Definition: Object.h:271
Definition: SpellMgr.h:477
Definition: PetDefines.h:116
Definition: Pet.h:46
uint16 GetSpecialization() const
Definition: Pet.h:138
PetType m_petType
Definition: Pet.h:156
void SetDuration(int32 dur)
Definition: Pet.h:94
bool m_loading
Definition: Pet.h:158
uint16 m_petSpecialization
Definition: Pet.h:164
uint32 m_focusRegenTimer
Definition: Pet.h:159
void setPetType(PetType type)
Definition: Pet.h:58
PetType getPetType() const
Definition: Pet.h:57
std::unique_ptr< DeclinedName > m_declinedname
Definition: Pet.h:162
uint32 GetPetAutoSpellOnPos(uint8 pos) const override
Definition: Pet.h:80
AutoSpellList m_autospells
Definition: Pet.h:134
void SetPetExperience(uint32 xp)
Definition: Pet.h:90
DeclinedName const * GetDeclinedNames() const
Definition: Pet.h:147
bool isTemporarySummoned() const
Definition: Pet.h:60
int32 GetDuration() const
Definition: Pet.h:95
bool isControlled() const
Definition: Pet.h:59
virtual ~Pet()
bool IsLoading() const override
Definition: Pet.h:70
void SetPetNextLevelExperience(uint32 xp)
Definition: Pet.h:91
bool m_removed
Definition: Pet.h:149
uint32 GetGroupUpdateFlag() const
Definition: Pet.h:143
void SaveToDB(uint32, std::vector< Difficulty > const &) override
Definition: Pet.h:167
uint8 GetPetAutoSpellSize() const override
Definition: Pet.h:79
uint32 m_groupUpdateMask
Definition: Pet.h:160
PetSpellMap m_spells
Definition: Pet.h:133
int32 m_duration
Definition: Pet.h:157
Definition: Player.h:1125
Definition: SpellInfo.h:322
void Update(uint32 time) override
Definition: TemporarySummon.cpp:69
Definition: Unit.h:739
UF::UpdateField< UF::UnitData, 0, TYPEID_UNIT > m_unitData
Definition: Unit.h:1900
Definition: CreatureData.h:471
Definition: UnitDefines.h:472
Definition: ItemTemplate.h:754
Definition: Pet.h:27
PetSpellState state
Definition: Pet.h:29
PetSpellType type
Definition: Pet.h:30
ActiveStates active
Definition: Pet.h:28
Definition: PetDefines.h:119
UpdateField< uint32, 64, 69 > PetExperience
Definition: UpdateFields.h:332
UpdateField< uint32, 64, 70 > PetNextLevelExperience
Definition: UpdateFields.h:333