TrinityCore
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
33typedef std::unordered_map<uint32, PetSpell> PetSpellMap;
34typedef std::vector<uint32> AutoSpellList;
35
36class Player;
37class PetAura;
38
39class TC_GAME_API Pet final : public Guardian
40{
41 public:
42 explicit Pet(Player* owner, PetType type = MAX_PET_TYPE);
43 virtual ~Pet();
44
45 void AddToWorld() override;
46 void RemoveFromWorld() override;
47
48 float GetNativeObjectScale() const override;
49 void SetDisplayId(uint32 modelId, bool setNative = false) override;
50
51 PetType getPetType() const { return m_petType; }
52 void setPetType(PetType type) { m_petType = type; }
53 bool isControlled() const { return getPetType() == SUMMON_PET || getPetType() == HUNTER_PET; }
54 bool isTemporarySummoned() const { return m_duration > 0; }
55
56 bool IsPermanentPetFor(Player* owner) const; // pet have tab in character windows and set UNIT_FIELD_PETNUMBER
57
58 bool Create(ObjectGuid::LowType guidlow, Map* map, uint32 Entry, uint32 pet_number);
59 bool CreateBaseAtCreature(Creature* creature);
60 bool CreateBaseAtCreatureInfo(CreatureTemplate const* cinfo, Unit* owner);
61 bool CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map);
62 static std::pair<PetStable::PetInfo const*, PetSaveMode> GetLoadPetInfo(PetStable const& stable, uint32 petEntry, uint32 petnumber, Optional<PetSaveMode> slot);
63 bool LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool current, Optional<PetSaveMode> forcedSlot = {});
64 bool IsLoading() const override { return m_loading;}
65 void SavePetToDB(PetSaveMode mode);
66 void FillPetInfo(PetStable::PetInfo* petInfo, Optional<ReactStates> forcedReactState = {}) const;
67 void Remove(PetSaveMode mode, bool returnreagent = false);
68 static void DeleteFromDB(uint32 petNumber);
69
70 void setDeathState(DeathState s) override; // overwrite virtual Creature::setDeathState and Unit::setDeathState
71 void Update(uint32 diff) override; // overwrite virtual Creature::Update and Unit::Update
72
73 uint8 GetPetAutoSpellSize() const override { return uint8(m_autospells.size()); }
74 uint32 GetPetAutoSpellOnPos(uint8 pos) const override
75 {
76 if (pos >= m_autospells.size())
77 return 0;
78 else
79 return m_autospells[pos];
80 }
81
82 void GivePetXP(uint32 xp);
83 void GivePetLevel(uint8 level);
84 void SetPetExperience(uint32 xp) { SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::PetExperience), xp); }
86 void SynchronizeLevelWithOwner();
87 bool HaveInDiet(ItemTemplate const* item) const;
88 void SetDuration(int32 dur) { m_duration = dur; }
89 int32 GetDuration() const { return m_duration; }
90
91 /*
92 bool UpdateStats(Stats stat);
93 bool UpdateAllStats();
94 void UpdateResistances(uint32 school);
95 void UpdateArmor();
96 void UpdateMaxHealth();
97 void UpdateMaxPower(Powers power);
98 void UpdateAttackPowerAndDamage(bool ranged = false);
99 void UpdateDamagePhysical(WeaponAttackType attType) override;
100 */
101
102 void ToggleAutocast(SpellInfo const* spellInfo, bool apply);
103
104 bool HasSpell(uint32 spell) const override;
105
106 void LearnPetPassives();
107 void CastPetAuras(bool current);
108 void CastPetAura(PetAura const* aura);
109 bool IsPetAura(Aura const* aura);
110
111 void _LoadAuras(PreparedQueryResult auraResult, PreparedQueryResult effectResult, uint32 timediff);
112 void _SaveAuras(CharacterDatabaseTransaction trans);
113 void _LoadSpells(PreparedQueryResult result);
114 void _SaveSpells(CharacterDatabaseTransaction trans);
115
116 bool addSpell(uint32 spellId, ActiveStates active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, PetSpellType type = PETSPELL_NORMAL);
117 bool learnSpell(uint32 spell_id);
118 void learnSpells(std::vector<uint32> const& spellIds);
119 void learnSpellHighRank(uint32 spellid);
120 void InitLevelupSpellsForLevel();
121 bool unlearnSpell(uint32 spell_id, bool learn_prev, bool clear_ab = true);
122 void unlearnSpells(std::vector<uint32> const& spellIds, bool learn_prev, bool clear_ab = true);
123 bool removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab = true);
124 void CleanupActionBar();
125 std::string GenerateActionBarData() const;
126
129
130 void InitPetCreateSpells();
131
132 uint16 GetSpecialization() const { return m_petSpecialization; }
133 void SetSpecialization(uint16 spec);
134 void LearnSpecializationSpells();
135 void RemoveSpecializationSpells(bool clearActionBar);
136
137 uint32 GetGroupUpdateFlag() const { return m_groupUpdateMask; }
138 void SetGroupUpdateFlag(uint32 flag);
139 void ResetGroupUpdateFlag();
140
141 DeclinedName const* GetDeclinedNames() const { return m_declinedname.get(); }
142
143 bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
144
145 Player* GetOwner() const;
146
147 std::string GetDebugInfo() const override;
148
149 protected:
151 int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
155
156 std::unique_ptr<DeclinedName> m_declinedname;
157
159
160 private:
161 void SaveToDB(uint32, std::vector<Difficulty> const&) override // override of Creature::SaveToDB - must not be called
162 {
163 ABORT();
164 }
165};
166#endif
SQLTransaction< CharacterDatabaseConnection > CharacterDatabaseTransaction
std::shared_ptr< PreparedResultSet > PreparedQueryResult
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
#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:68
@ PETSPELL_NEW
Definition: PetDefines.h:71
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:76
@ PETSPELL_NORMAL
Definition: PetDefines.h:77
PetSaveMode
Definition: PetDefines.h:41
std::unordered_map< uint32, PetSpell > PetSpellMap
Definition: Pet.h:33
std::vector< uint32 > AutoSpellList
Definition: Pet.h:34
ActiveStates
Definition: UnitDefines.h:495
@ ACT_DECIDE
Definition: UnitDefines.h:501
DeathState
Definition: Unit.h:245
uint32 const Entry[5]
bool HasSpell(uint32 spellID) const override
Definition: Creature.cpp:2863
bool Create(ObjectGuid::LowType guidlow, Map *map, uint32 entry, Position const &pos, CreatureData const *data, uint32 vehId, bool dynamic=false)
Definition: Creature.cpp:1071
void AddToWorld() override
Definition: Creature.cpp:329
static bool DeleteFromDB(ObjectGuid::LowType spawnId)
Definition: Creature.cpp:2005
float GetNativeObjectScale() const override
Definition: Creature.cpp:3386
void SetDisplayId(uint32 displayId, bool setNative=false) override
Definition: Creature.cpp:3402
std::string GetDebugInfo() const override
Definition: Map.h:189
void setDeathState(DeathState s) override
void RemoveFromWorld() override
Unit * GetOwner() const
uint64 LowType
Definition: ObjectGuid.h:278
void SetUpdateFieldValue(UF::UpdateFieldSetter< T > setter, typename UF::UpdateFieldSetter< T >::value_type value)
Definition: Object.h:287
Definition: Pet.h:40
uint16 GetSpecialization() const
Definition: Pet.h:132
PetType m_petType
Definition: Pet.h:150
void SetDuration(int32 dur)
Definition: Pet.h:88
bool m_loading
Definition: Pet.h:152
uint16 m_petSpecialization
Definition: Pet.h:158
uint32 m_focusRegenTimer
Definition: Pet.h:153
void setPetType(PetType type)
Definition: Pet.h:52
PetType getPetType() const
Definition: Pet.h:51
std::unique_ptr< DeclinedName > m_declinedname
Definition: Pet.h:156
uint32 GetPetAutoSpellOnPos(uint8 pos) const override
Definition: Pet.h:74
AutoSpellList m_autospells
Definition: Pet.h:128
void SetPetExperience(uint32 xp)
Definition: Pet.h:84
DeclinedName const * GetDeclinedNames() const
Definition: Pet.h:141
bool isTemporarySummoned() const
Definition: Pet.h:54
int32 GetDuration() const
Definition: Pet.h:89
bool isControlled() const
Definition: Pet.h:53
virtual ~Pet()
bool IsLoading() const override
Definition: Pet.h:64
void SetPetNextLevelExperience(uint32 xp)
Definition: Pet.h:85
bool m_removed
Definition: Pet.h:143
uint32 GetGroupUpdateFlag() const
Definition: Pet.h:137
void SaveToDB(uint32, std::vector< Difficulty > const &) override
Definition: Pet.h:161
uint8 GetPetAutoSpellSize() const override
Definition: Pet.h:73
uint32 m_groupUpdateMask
Definition: Pet.h:154
PetSpellMap m_spells
Definition: Pet.h:127
int32 m_duration
Definition: Pet.h:151
void Update(uint32 diff) override
Definition: Unit.h:627
UF::UpdateField< UF::UnitData, 0, TYPEID_UNIT > m_unitData
Definition: Unit.h:1814
void apply(T *val)
Definition: ByteConverter.h:41
void Remove(VignetteData &vignette, WorldObject const *owner)
Definition: Vignette.cpp:100
Definition: Pet.h:27
PetSpellState state
Definition: Pet.h:29
PetSpellType type
Definition: Pet.h:30
ActiveStates active
Definition: Pet.h:28
UpdateField< uint32, 64, 69 > PetExperience
Definition: UpdateFields.h:333
UpdateField< uint32, 64, 70 > PetNextLevelExperience
Definition: UpdateFields.h:334