[8449] Deprecate healing/damage item mods and merge internal data in to spell power.
[getmangos.git] / src / game / Pet.h
blob303d3ba50fdaf1c55ab3cce1d86e835caab6266c
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOSSERVER_PET_H
20 #define MANGOSSERVER_PET_H
22 #include "ObjectDefines.h"
23 #include "Creature.h"
24 #include "Unit.h"
26 enum PetType
28 SUMMON_PET = 0,
29 HUNTER_PET = 1,
30 GUARDIAN_PET = 2,
31 MINI_PET = 3,
32 MAX_PET_TYPE = 4
35 extern char const* petTypeSuffix[MAX_PET_TYPE];
37 #define MAX_PET_STABLES 4
39 // stored in character_pet.slot
40 enum PetSaveMode
42 PET_SAVE_AS_DELETED = -1, // not saved in fact
43 PET_SAVE_AS_CURRENT = 0, // in current slot (with player)
44 PET_SAVE_FIRST_STABLE_SLOT = 1,
45 PET_SAVE_LAST_STABLE_SLOT = MAX_PET_STABLES, // last in DB stable slot index (including), all higher have same meaning as PET_SAVE_NOT_IN_SLOT
46 PET_SAVE_NOT_IN_SLOT = 100 // for avoid conflict with stable size grow will use 100
49 enum HappinessState
51 UNHAPPY = 1,
52 CONTENT = 2,
53 HAPPY = 3
56 enum PetSpellState
58 PETSPELL_UNCHANGED = 0,
59 PETSPELL_CHANGED = 1,
60 PETSPELL_NEW = 2,
61 PETSPELL_REMOVED = 3
64 enum PetSpellType
66 PETSPELL_NORMAL = 0,
67 PETSPELL_FAMILY = 1,
70 struct PetSpell
72 uint8 active; // use instead enum (not good use *uint8* limited enum in case when value in enum not possitive in *int8*)
74 PetSpellState state : 8;
75 PetSpellType type : 8;
78 enum ActionFeedback
80 FEEDBACK_NONE = 0,
81 FEEDBACK_PET_DEAD = 1,
82 FEEDBACK_NOTHING_TO_ATT = 2,
83 FEEDBACK_CANT_ATT_TARGET = 3
86 enum PetTalk
88 PET_TALK_SPECIAL_SPELL = 0,
89 PET_TALK_ATTACK = 1
92 enum PetNameInvalidReason
94 // custom, not send
95 PET_NAME_SUCCESS = 0,
97 PET_NAME_INVALID = 1,
98 PET_NAME_NO_NAME = 2,
99 PET_NAME_TOO_SHORT = 3,
100 PET_NAME_TOO_LONG = 4,
101 PET_NAME_MIXED_LANGUAGES = 6,
102 PET_NAME_PROFANE = 7,
103 PET_NAME_RESERVED = 8,
104 PET_NAME_THREE_CONSECUTIVE = 11,
105 PET_NAME_INVALID_SPACE = 12,
106 PET_NAME_CONSECUTIVE_SPACES = 13,
107 PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS = 14,
108 PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END = 15,
109 PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16
112 typedef UNORDERED_MAP<uint32, PetSpell> PetSpellMap;
113 typedef std::vector<uint32> AutoSpellList;
115 #define HAPPINESS_LEVEL_SIZE 333000
117 #define ACTIVE_SPELLS_MAX 4
119 #define OWNER_MAX_DISTANCE 100.0f
121 #define PET_FOLLOW_DIST 1
122 #define PET_FOLLOW_ANGLE (M_PI/2)
124 class Player;
126 class Pet : public Creature
128 public:
129 explicit Pet(PetType type = MAX_PET_TYPE);
130 virtual ~Pet();
132 void AddToWorld();
133 void RemoveFromWorld();
135 PetType getPetType() const { return m_petType; }
136 void setPetType(PetType type) { m_petType = type; }
137 bool isControlled() const { return getPetType()==SUMMON_PET || getPetType()==HUNTER_PET; }
138 bool isTemporarySummoned() const { return m_duration > 0; }
140 bool IsPermanentPetFor(Player* owner); // pet have tab in character windows and set UNIT_FIELD_PETNUMBER
142 bool Create (uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 pet_number);
143 bool CreateBaseAtCreature(Creature* creature);
144 bool LoadPetFromDB( Player* owner,uint32 petentry = 0,uint32 petnumber = 0, bool current = false );
145 void SavePetToDB(PetSaveMode mode);
146 void Remove(PetSaveMode mode, bool returnreagent = false);
147 static void DeleteFromDB(uint32 guidlow);
149 void setDeathState(DeathState s); // overwrite virtual Creature::setDeathState and Unit::setDeathState
150 void Update(uint32 diff); // overwrite virtual Creature::Update and Unit::Update
152 uint8 GetPetAutoSpellSize() const { return m_autospells.size(); }
153 uint32 GetPetAutoSpellOnPos(uint8 pos) const
155 if (pos >= m_autospells.size())
156 return 0;
157 else
158 return m_autospells[pos];
161 void Regenerate(Powers power);
162 void LooseHappiness();
163 HappinessState GetHappinessState();
164 void GivePetXP(uint32 xp);
165 void GivePetLevel(uint32 level);
166 void SynchronizeLevelWithOwner();
167 bool InitStatsForLevel(uint32 level, Unit* owner = NULL);
168 bool HaveInDiet(ItemPrototype const* item) const;
169 uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel);
170 void SetDuration(int32 dur) { m_duration = dur; }
172 int32 GetBonusDamage() { return m_bonusdamage; }
173 void SetBonusDamage(int32 damage) { m_bonusdamage = damage; }
175 bool UpdateStats(Stats stat);
176 bool UpdateAllStats();
177 void UpdateResistances(uint32 school);
178 void UpdateArmor();
179 void UpdateMaxHealth();
180 void UpdateMaxPower(Powers power);
181 void UpdateAttackPowerAndDamage(bool ranged = false);
182 void UpdateDamagePhysical(WeaponAttackType attType);
184 bool CanTakeMoreActiveSpells(uint32 SpellIconID);
185 void ToggleAutocast(uint32 spellid, bool apply);
187 bool HasSpell(uint32 spell) const;
189 void LearnPetPassives();
190 void CastPetAuras(bool current);
191 void CastPetAura(PetAura const* aura);
193 void _LoadSpellCooldowns();
194 void _SaveSpellCooldowns();
195 void _LoadAuras(uint32 timediff);
196 void _SaveAuras();
197 void _LoadSpells();
198 void _SaveSpells();
200 bool addSpell(uint32 spell_id,ActiveStates active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, PetSpellType type = PETSPELL_NORMAL);
201 bool learnSpell(uint32 spell_id);
202 void learnSpellHighRank(uint32 spellid);
203 void InitLevelupSpellsForLevel();
204 bool unlearnSpell(uint32 spell_id, bool learn_prev, bool clear_ab = true);
205 bool removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab = true);
206 void CleanupActionBar();
208 PetSpellMap m_spells;
209 AutoSpellList m_autospells;
211 void InitPetCreateSpells();
213 bool resetTalents(bool no_cost = false);
214 static void resetTalentsForAllPetsOf(Player* owner, Pet* online_pet = NULL);
215 uint32 resetTalentsCost() const;
216 void InitTalentForLevel();
218 uint8 GetMaxTalentPointsForLevel(uint32 level);
219 uint8 GetFreeTalentPoints() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); }
220 void SetFreeTalentPoints(uint8 points) { SetByteValue(UNIT_FIELD_BYTES_1, 1, points); }
222 uint32 m_resetTalentsCost;
223 time_t m_resetTalentsTime;
224 uint32 m_usedTalentCount;
226 const uint64& GetAuraUpdateMask() const { return m_auraUpdateMask; }
227 void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); }
228 void ResetAuraUpdateMask() { m_auraUpdateMask = 0; }
230 // overwrite Creature function for name localization back to WorldObject version without localization
231 const char* GetNameForLocaleIdx(int32 locale_idx) const { return WorldObject::GetNameForLocaleIdx(locale_idx); }
233 DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
235 bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
236 protected:
237 uint32 m_happinessTimer;
238 PetType m_petType;
239 int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
240 int32 m_bonusdamage;
241 uint64 m_auraUpdateMask;
242 bool m_loading;
244 DeclinedName *m_declinedname;
246 private:
247 void SaveToDB(uint32, uint8) // overwrited of Creature::SaveToDB - don't must be called
249 assert(false);
251 void DeleteFromDB() // overwrited of Creature::DeleteFromDB - don't must be called
253 assert(false);
256 #endif