[7297] Fixed profession spells sorting in trainer spell list at client.
[getmangos.git] / src / game / Pet.h
blob47e0a65bf37641bd6d0c4dfcf19ebc9935b543be
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 enum PetSaveMode
39 PET_SAVE_AS_DELETED =-1,
40 PET_SAVE_AS_CURRENT = 0,
41 PET_SAVE_IN_STABLE_SLOT_1 = 1,
42 PET_SAVE_IN_STABLE_SLOT_2 = 2,
43 PET_SAVE_NOT_IN_SLOT = 3
46 enum HappinessState
48 UNHAPPY = 1,
49 CONTENT = 2,
50 HAPPY = 3
53 enum PetSpellState
55 PETSPELL_UNCHANGED = 0,
56 PETSPELL_CHANGED = 1,
57 PETSPELL_NEW = 2,
58 PETSPELL_REMOVED = 3
61 enum PetSpellType
63 PETSPELL_NORMAL = 0,
64 PETSPELL_FAMILY = 1,
67 struct PetSpell
69 uint16 active;
71 PetSpellState state : 16;
72 PetSpellType type : 16;
75 enum ActionFeedback
77 FEEDBACK_NONE = 0,
78 FEEDBACK_PET_DEAD = 1,
79 FEEDBACK_NOTHING_TO_ATT = 2,
80 FEEDBACK_CANT_ATT_TARGET = 3
83 enum PetTalk
85 PET_TALK_SPECIAL_SPELL = 0,
86 PET_TALK_ATTACK = 1
89 enum PetNameInvalidReason
91 PET_NAME_INVALID = 1,
92 PET_NAME_NO_NAME = 2,
93 PET_NAME_TOO_SHORT = 3,
94 PET_NAME_TOO_LONG = 4,
95 PET_NAME_MIXED_LANGUAGES = 6,
96 PET_NAME_PROFANE = 7,
97 PET_NAME_RESERVED = 8,
98 PET_NAME_THREE_CONSECUTIVE = 11,
99 PET_NAME_INVALID_SPACE = 12,
100 PET_NAME_CONSECUTIVE_SPACES = 13,
101 PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS = 14,
102 PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END = 15,
103 PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16
106 typedef UNORDERED_MAP<uint32, PetSpell*> PetSpellMap;
107 typedef std::map<uint32,uint32> TeachSpellMap;
108 typedef std::vector<uint32> AutoSpellList;
110 #define HAPPINESS_LEVEL_SIZE 333000
112 #define ACTIVE_SPELLS_MAX 4
114 #define OWNER_MAX_DISTANCE 100
116 #define PET_FOLLOW_DIST 1
117 #define PET_FOLLOW_ANGLE (M_PI/2)
119 class Pet : public Creature
121 public:
122 explicit Pet(PetType type = MAX_PET_TYPE);
123 virtual ~Pet();
125 void AddToWorld();
126 void RemoveFromWorld();
128 PetType getPetType() const { return m_petType; }
129 void setPetType(PetType type) { m_petType = type; }
130 bool isControlled() const { return getPetType()==SUMMON_PET || getPetType()==HUNTER_PET; }
131 bool isTemporarySummoned() const { return m_duration > 0; }
133 bool Create (uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 pet_number);
134 bool CreateBaseAtCreature(Creature* creature);
135 bool LoadPetFromDB( Player* owner,uint32 petentry = 0,uint32 petnumber = 0, bool current = false );
136 void SavePetToDB(PetSaveMode mode);
137 void Remove(PetSaveMode mode, bool returnreagent = false);
138 static void DeleteFromDB(uint32 guidlow);
140 void setDeathState(DeathState s); // overwrite virtual Creature::setDeathState and Unit::setDeathState
141 void Update(uint32 diff); // overwrite virtual Creature::Update and Unit::Update
143 uint8 GetPetAutoSpellSize() const { return m_autospells.size(); }
144 uint32 GetPetAutoSpellOnPos(uint8 pos) const
146 if (pos >= m_autospells.size())
147 return 0;
148 else
149 return m_autospells[pos];
152 void RegenerateFocus();
153 void LooseHappiness();
154 HappinessState GetHappinessState();
155 void GivePetXP(uint32 xp);
156 void GivePetLevel(uint32 level);
157 bool InitStatsForLevel(uint32 level);
158 bool HaveInDiet(ItemPrototype const* item) const;
159 uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel);
160 void SetDuration(int32 dur) { m_duration = dur; }
162 int32 GetBonusDamage() { return m_bonusdamage; }
163 void SetBonusDamage(int32 damage) { m_bonusdamage = damage; }
165 bool UpdateStats(Stats stat);
166 bool UpdateAllStats();
167 void UpdateResistances(uint32 school);
168 void UpdateArmor();
169 void UpdateMaxHealth();
170 void UpdateMaxPower(Powers power);
171 void UpdateAttackPowerAndDamage(bool ranged = false);
172 void UpdateDamagePhysical(WeaponAttackType attType);
174 bool CanTakeMoreActiveSpells(uint32 SpellIconID);
175 void ToggleAutocast(uint32 spellid, bool apply);
177 bool HasSpell(uint32 spell) const;
178 void AddTeachSpell(uint32 learned_id, uint32 source_id) { m_teachspells[learned_id] = source_id; }
180 void LearnPetPassives();
181 void CastPetAuras(bool current);
182 void CastPetAura(PetAura const* aura);
184 void _LoadSpellCooldowns();
185 void _SaveSpellCooldowns();
186 void _LoadAuras(uint32 timediff);
187 void _SaveAuras();
188 void _LoadSpells();
189 void _SaveSpells();
191 bool addSpell(uint32 spell_id,uint16 active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, PetSpellType type = PETSPELL_NORMAL);
192 bool learnSpell(uint32 spell_id);
193 void learnLevelupSpells();
194 bool unlearnSpell(uint32 spell_id);
195 bool removeSpell(uint32 spell_id);
196 bool _removeSpell(uint32 spell_id);
198 PetSpellMap m_spells;
199 TeachSpellMap m_teachspells;
200 AutoSpellList m_autospells;
202 void InitPetCreateSpells();
203 void CheckLearning(uint32 spellid);
205 bool resetTalents(bool no_cost = false);
206 uint32 resetTalentsCost() const;
207 void InitTalentForLevel();
209 uint8 GetMaxTalentPointsForLevel(uint32 level);
210 uint8 GetFreeTalentPoints() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); }
211 void SetFreeTalentPoints(uint8 points) { SetByteValue(UNIT_FIELD_BYTES_1, 1, points); }
213 uint32 m_resetTalentsCost;
214 time_t m_resetTalentsTime;
215 uint32 m_usedTalentCount;
217 const uint64& GetAuraUpdateMask() const { return m_auraUpdateMask; }
218 void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); }
219 void ResetAuraUpdateMask() { m_auraUpdateMask = 0; }
221 // overwrite Creature function for name localization back to WorldObject version without localization
222 const char* GetNameForLocaleIdx(int32 locale_idx) const { return WorldObject::GetNameForLocaleIdx(locale_idx); }
224 DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
226 bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
227 protected:
228 uint32 m_happinessTimer;
229 PetType m_petType;
230 int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
231 int32 m_bonusdamage;
232 uint64 m_auraUpdateMask;
233 bool m_loading;
235 DeclinedName *m_declinedname;
237 private:
238 void SaveToDB(uint32, uint8) // overwrited of Creature::SaveToDB - don't must be called
240 assert(false);
242 void DeleteFromDB() // overwrited of Creature::DeleteFromDB - don't must be called
244 assert(false);
247 #endif