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"
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
58 PETSPELL_UNCHANGED
= 0,
74 PetSpellState state
: 16;
75 PetSpellType type
: 16;
81 FEEDBACK_PET_DEAD
= 1,
82 FEEDBACK_NOTHING_TO_ATT
= 2,
83 FEEDBACK_CANT_ATT_TARGET
= 3
88 PET_TALK_SPECIAL_SPELL
= 0,
92 enum PetNameInvalidReason
96 PET_NAME_TOO_SHORT
= 3,
97 PET_NAME_TOO_LONG
= 4,
98 PET_NAME_MIXED_LANGUAGES
= 6,
100 PET_NAME_RESERVED
= 8,
101 PET_NAME_THREE_CONSECUTIVE
= 11,
102 PET_NAME_INVALID_SPACE
= 12,
103 PET_NAME_CONSECUTIVE_SPACES
= 13,
104 PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS
= 14,
105 PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END
= 15,
106 PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME
= 16
109 typedef UNORDERED_MAP
<uint32
, PetSpell
*> PetSpellMap
;
110 typedef std::map
<uint32
,uint32
> TeachSpellMap
;
111 typedef std::vector
<uint32
> AutoSpellList
;
113 #define HAPPINESS_LEVEL_SIZE 333000
115 #define ACTIVE_SPELLS_MAX 4
117 #define OWNER_MAX_DISTANCE 100
119 #define PET_FOLLOW_DIST 1
120 #define PET_FOLLOW_ANGLE (M_PI/2)
122 class Pet
: public Creature
125 explicit Pet(PetType type
= MAX_PET_TYPE
);
129 void RemoveFromWorld();
131 PetType
getPetType() const { return m_petType
; }
132 void setPetType(PetType type
) { m_petType
= type
; }
133 bool isControlled() const { return getPetType()==SUMMON_PET
|| getPetType()==HUNTER_PET
; }
134 bool isTemporarySummoned() const { return m_duration
> 0; }
136 bool Create (uint32 guidlow
, Map
*map
, uint32 phaseMask
, uint32 Entry
, uint32 pet_number
);
137 bool CreateBaseAtCreature(Creature
* creature
);
138 bool LoadPetFromDB( Player
* owner
,uint32 petentry
= 0,uint32 petnumber
= 0, bool current
= false );
139 void SavePetToDB(PetSaveMode mode
);
140 void Remove(PetSaveMode mode
, bool returnreagent
= false);
141 static void DeleteFromDB(uint32 guidlow
);
143 void setDeathState(DeathState s
); // overwrite virtual Creature::setDeathState and Unit::setDeathState
144 void Update(uint32 diff
); // overwrite virtual Creature::Update and Unit::Update
146 uint8
GetPetAutoSpellSize() const { return m_autospells
.size(); }
147 uint32
GetPetAutoSpellOnPos(uint8 pos
) const
149 if (pos
>= m_autospells
.size())
152 return m_autospells
[pos
];
155 void RegenerateFocus();
156 void LooseHappiness();
157 HappinessState
GetHappinessState();
158 void GivePetXP(uint32 xp
);
159 void GivePetLevel(uint32 level
);
160 bool InitStatsForLevel(uint32 level
);
161 bool HaveInDiet(ItemPrototype
const* item
) const;
162 uint32
GetCurrentFoodBenefitLevel(uint32 itemlevel
);
163 void SetDuration(int32 dur
) { m_duration
= dur
; }
165 int32
GetBonusDamage() { return m_bonusdamage
; }
166 void SetBonusDamage(int32 damage
) { m_bonusdamage
= damage
; }
168 bool UpdateStats(Stats stat
);
169 bool UpdateAllStats();
170 void UpdateResistances(uint32 school
);
172 void UpdateMaxHealth();
173 void UpdateMaxPower(Powers power
);
174 void UpdateAttackPowerAndDamage(bool ranged
= false);
175 void UpdateDamagePhysical(WeaponAttackType attType
);
177 bool CanTakeMoreActiveSpells(uint32 SpellIconID
);
178 void ToggleAutocast(uint32 spellid
, bool apply
);
180 bool HasSpell(uint32 spell
) const;
181 void AddTeachSpell(uint32 learned_id
, uint32 source_id
) { m_teachspells
[learned_id
] = source_id
; }
183 void LearnPetPassives();
184 void CastPetAuras(bool current
);
185 void CastPetAura(PetAura
const* aura
);
187 void _LoadSpellCooldowns();
188 void _SaveSpellCooldowns();
189 void _LoadAuras(uint32 timediff
);
194 bool addSpell(uint32 spell_id
,uint16 active
= ACT_DECIDE
, PetSpellState state
= PETSPELL_NEW
, PetSpellType type
= PETSPELL_NORMAL
);
195 bool learnSpell(uint32 spell_id
);
196 void learnSpellHighRank(uint32 spellid
);
197 void learnLevelupSpells();
198 bool unlearnSpell(uint32 spell_id
);
199 bool removeSpell(uint32 spell_id
);
200 bool _removeSpell(uint32 spell_id
);
202 PetSpellMap m_spells
;
203 TeachSpellMap m_teachspells
;
204 AutoSpellList m_autospells
;
206 void InitPetCreateSpells();
207 void CheckLearning(uint32 spellid
);
209 bool resetTalents(bool no_cost
= false);
210 uint32
resetTalentsCost() const;
211 void InitTalentForLevel();
213 uint8
GetMaxTalentPointsForLevel(uint32 level
);
214 uint8
GetFreeTalentPoints() { return GetByteValue(UNIT_FIELD_BYTES_1
, 1); }
215 void SetFreeTalentPoints(uint8 points
) { SetByteValue(UNIT_FIELD_BYTES_1
, 1, points
); }
217 uint32 m_resetTalentsCost
;
218 time_t m_resetTalentsTime
;
219 uint32 m_usedTalentCount
;
221 const uint64
& GetAuraUpdateMask() const { return m_auraUpdateMask
; }
222 void SetAuraUpdateMask(uint8 slot
) { m_auraUpdateMask
|= (uint64(1) << slot
); }
223 void ResetAuraUpdateMask() { m_auraUpdateMask
= 0; }
225 // overwrite Creature function for name localization back to WorldObject version without localization
226 const char* GetNameForLocaleIdx(int32 locale_idx
) const { return WorldObject::GetNameForLocaleIdx(locale_idx
); }
228 DeclinedName
const* GetDeclinedNames() const { return m_declinedname
; }
230 bool m_removed
; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
232 uint32 m_happinessTimer
;
234 int32 m_duration
; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
236 uint64 m_auraUpdateMask
;
239 DeclinedName
*m_declinedname
;
242 void SaveToDB(uint32
, uint8
) // overwrited of Creature::SaveToDB - don't must be called
246 void DeleteFromDB() // overwrited of Creature::DeleteFromDB - don't must be called