2 * Copyright (C) 2005-2010 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 "ObjectGuid.h"
35 extern char const* petTypeSuffix
[MAX_PET_TYPE
];
37 #define MAX_PET_STABLES 4
39 // stored in character_pet.slot
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 // There might be a lot more
52 PET_MODE_UNKNOWN_0
= 0x0000001,
53 PET_MODE_UNKNOWN_2
= 0x0000100,
54 PET_MODE_DISABLE_ACTIONS
= 0x8000000,
56 // autoset in client at summon
57 PET_MODE_DEFAULT
= PET_MODE_UNKNOWN_0
| PET_MODE_UNKNOWN_2
,
69 PETSPELL_UNCHANGED
= 0,
83 uint8 active
; // use instead enum (not good use *uint8* limited enum in case when value in enum not possitive in *int8*)
85 PetSpellState state
: 8;
86 PetSpellType type
: 8;
92 FEEDBACK_PET_DEAD
= 1,
93 FEEDBACK_NOTHING_TO_ATT
= 2,
94 FEEDBACK_CANT_ATT_TARGET
= 3
99 PET_TALK_SPECIAL_SPELL
= 0,
103 enum PetNameInvalidReason
106 PET_NAME_SUCCESS
= 0,
108 PET_NAME_INVALID
= 1,
109 PET_NAME_NO_NAME
= 2,
110 PET_NAME_TOO_SHORT
= 3,
111 PET_NAME_TOO_LONG
= 4,
112 PET_NAME_MIXED_LANGUAGES
= 6,
113 PET_NAME_PROFANE
= 7,
114 PET_NAME_RESERVED
= 8,
115 PET_NAME_THREE_CONSECUTIVE
= 11,
116 PET_NAME_INVALID_SPACE
= 12,
117 PET_NAME_CONSECUTIVE_SPACES
= 13,
118 PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS
= 14,
119 PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END
= 15,
120 PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME
= 16
123 typedef UNORDERED_MAP
<uint32
, PetSpell
> PetSpellMap
;
124 typedef std::vector
<uint32
> AutoSpellList
;
126 #define HAPPINESS_LEVEL_SIZE 333000
128 #define ACTIVE_SPELLS_MAX 4
130 #define PET_FOLLOW_DIST 1.0f
131 #define PET_FOLLOW_ANGLE M_PI_F/2
135 class Pet
: public Creature
138 explicit Pet(PetType type
= MAX_PET_TYPE
);
142 void RemoveFromWorld();
144 PetType
getPetType() const { return m_petType
; }
145 void setPetType(PetType type
) { m_petType
= type
; }
146 bool isControlled() const { return getPetType()==SUMMON_PET
|| getPetType()==HUNTER_PET
; }
147 bool isTemporarySummoned() const { return m_duration
> 0; }
149 bool IsPermanentPetFor(Player
* owner
); // pet have tab in character windows and set UNIT_FIELD_PETNUMBER
151 bool Create (uint32 guidlow
, Map
*map
, uint32 phaseMask
, uint32 Entry
, uint32 pet_number
);
152 bool CreateBaseAtCreature(Creature
* creature
);
153 bool LoadPetFromDB( Player
* owner
,uint32 petentry
= 0,uint32 petnumber
= 0, bool current
= false );
154 void SavePetToDB(PetSaveMode mode
);
155 void Remove(PetSaveMode mode
, bool returnreagent
= false);
156 static void DeleteFromDB(uint32 guidlow
);
158 void setDeathState(DeathState s
); // overwrite virtual Creature::setDeathState and Unit::setDeathState
159 void Update(uint32 diff
); // overwrite virtual Creature::Update and Unit::Update
161 uint8
GetPetAutoSpellSize() const { return m_autospells
.size(); }
162 uint32
GetPetAutoSpellOnPos(uint8 pos
) const
164 if (pos
>= m_autospells
.size())
167 return m_autospells
[pos
];
170 void Regenerate(Powers power
);
171 void LooseHappiness();
172 HappinessState
GetHappinessState();
173 void GivePetXP(uint32 xp
);
174 void GivePetLevel(uint32 level
);
175 void SynchronizeLevelWithOwner();
176 bool InitStatsForLevel(uint32 level
, Unit
* owner
= NULL
);
177 bool HaveInDiet(ItemPrototype
const* item
) const;
178 uint32
GetCurrentFoodBenefitLevel(uint32 itemlevel
);
179 void SetDuration(int32 dur
) { m_duration
= dur
; }
181 int32
GetBonusDamage() { return m_bonusdamage
; }
182 void SetBonusDamage(int32 damage
) { m_bonusdamage
= damage
; }
184 bool UpdateStats(Stats stat
);
185 bool UpdateAllStats();
186 void UpdateResistances(uint32 school
);
188 void UpdateMaxHealth();
189 void UpdateMaxPower(Powers power
);
190 void UpdateAttackPowerAndDamage(bool ranged
= false);
191 void UpdateDamagePhysical(WeaponAttackType attType
);
193 bool CanTakeMoreActiveSpells(uint32 SpellIconID
);
194 void ToggleAutocast(uint32 spellid
, bool apply
);
196 void ApplyModeFlags(PetModeFlags mode
, bool apply
);
197 PetModeFlags
GetModeFlags() const { return m_petModeFlags
; }
199 bool HasSpell(uint32 spell
) const;
201 void LearnPetPassives();
202 void CastPetAuras(bool current
);
203 void CastPetAura(PetAura
const* aura
);
205 void _LoadSpellCooldowns();
206 void _SaveSpellCooldowns();
207 void _LoadAuras(uint32 timediff
);
212 bool addSpell(uint32 spell_id
,ActiveStates active
= ACT_DECIDE
, PetSpellState state
= PETSPELL_NEW
, PetSpellType type
= PETSPELL_NORMAL
);
213 bool learnSpell(uint32 spell_id
);
214 void learnSpellHighRank(uint32 spellid
);
215 void InitLevelupSpellsForLevel();
216 bool unlearnSpell(uint32 spell_id
, bool learn_prev
, bool clear_ab
= true);
217 bool removeSpell(uint32 spell_id
, bool learn_prev
, bool clear_ab
= true);
218 void CleanupActionBar();
220 PetSpellMap m_spells
;
221 AutoSpellList m_autospells
;
223 void InitPetCreateSpells();
225 bool resetTalents(bool no_cost
= false);
226 static void resetTalentsForAllPetsOf(Player
* owner
, Pet
* online_pet
= NULL
);
227 uint32
resetTalentsCost() const;
228 void InitTalentForLevel();
230 uint8
GetMaxTalentPointsForLevel(uint32 level
);
231 uint8
GetFreeTalentPoints() { return GetByteValue(UNIT_FIELD_BYTES_1
, 1); }
232 void SetFreeTalentPoints(uint8 points
) { SetByteValue(UNIT_FIELD_BYTES_1
, 1, points
); }
234 uint32 m_resetTalentsCost
;
235 time_t m_resetTalentsTime
;
236 uint32 m_usedTalentCount
;
238 const uint64
& GetAuraUpdateMask() const { return m_auraUpdateMask
; }
239 void SetAuraUpdateMask(uint8 slot
) { m_auraUpdateMask
|= (uint64(1) << slot
); }
240 void ResetAuraUpdateMask() { m_auraUpdateMask
= 0; }
242 // overwrite Creature function for name localization back to WorldObject version without localization
243 const char* GetNameForLocaleIdx(int32 locale_idx
) const { return WorldObject::GetNameForLocaleIdx(locale_idx
); }
245 DeclinedName
const* GetDeclinedNames() const { return m_declinedname
; }
247 bool m_removed
; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
249 uint32 m_happinessTimer
;
251 int32 m_duration
; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
253 uint64 m_auraUpdateMask
;
256 DeclinedName
*m_declinedname
;
259 PetModeFlags m_petModeFlags
;
261 void SaveToDB(uint32
, uint8
) // overwrited of Creature::SaveToDB - don't must be called
265 void DeleteFromDB() // overwrited of Creature::DeleteFromDB - don't must be called