2 * Copyright (C) 2005-2008 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
];
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
55 PETSPELL_UNCHANGED
= 0,
72 PetSpellState state
: 16;
73 PetSpellType type
: 16;
79 FEEDBACK_PET_DEAD
= 1,
80 FEEDBACK_NOTHING_TO_ATT
= 2,
81 FEEDBACK_CANT_ATT_TARGET
= 3
86 PET_TALK_SPECIAL_SPELL
= 0,
90 enum PetNameInvalidReason
94 PET_NAME_TOO_SHORT
= 3,
95 PET_NAME_TOO_LONG
= 4,
96 PET_NAME_MIXED_LANGUAGES
= 6,
98 PET_NAME_RESERVED
= 8,
99 PET_NAME_THREE_CONSECUTIVE
= 11,
100 PET_NAME_INVALID_SPACE
= 12,
101 PET_NAME_CONSECUTIVE_SPACES
= 13,
102 PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS
= 14,
103 PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END
= 15,
104 PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME
= 16
107 typedef UNORDERED_MAP
<uint16
, PetSpell
*> PetSpellMap
;
108 typedef std::map
<uint32
,uint32
> TeachSpellMap
;
109 typedef std::vector
<uint32
> AutoSpellList
;
111 #define HAPPINESS_LEVEL_SIZE 333000
113 #define ACTIVE_SPELLS_MAX 4
115 #define OWNER_MAX_DISTANCE 100
117 #define PET_FOLLOW_DIST 1
118 #define PET_FOLLOW_ANGLE (M_PI/2)
120 class Pet
: public Creature
123 explicit Pet(PetType type
= MAX_PET_TYPE
);
127 void RemoveFromWorld();
129 PetType
getPetType() const { return m_petType
; }
130 void setPetType(PetType type
) { m_petType
= type
; }
131 bool isControlled() const { return getPetType()==SUMMON_PET
|| getPetType()==HUNTER_PET
; }
132 bool isTemporarySummoned() const { return m_duration
> 0; }
134 bool Create (uint32 guidlow
, Map
*map
, uint32 Entry
, uint32 pet_number
);
135 bool CreateBaseAtCreature(Creature
* creature
);
136 bool LoadPetFromDB( Unit
* owner
,uint32 petentry
= 0,uint32 petnumber
= 0, bool current
= false );
137 void SavePetToDB(PetSaveMode mode
);
138 void Remove(PetSaveMode mode
, bool returnreagent
= false);
139 static void DeleteFromDB(uint32 guidlow
);
141 void setDeathState(DeathState s
); // overwrite virtual Creature::setDeathState and Unit::setDeathState
142 void Update(uint32 diff
); // overwrite virtual Creature::Update and Unit::Update
144 uint8
GetPetAutoSpellSize() const { return m_autospells
.size(); }
145 uint32
GetPetAutoSpellOnPos(uint8 pos
) const
147 if (pos
>= m_autospells
.size())
150 return m_autospells
[pos
];
153 void RegenerateFocus();
154 void LooseHappiness();
155 HappinessState
GetHappinessState();
156 void GivePetXP(uint32 xp
);
157 void GivePetLevel(uint32 level
);
158 bool InitStatsForLevel(uint32 level
);
159 bool HaveInDiet(ItemPrototype
const* item
) const;
160 uint32
GetCurrentFoodBenefitLevel(uint32 itemlevel
);
161 void SetDuration(int32 dur
) { m_duration
= dur
; }
163 int32
GetBonusDamage() { return m_bonusdamage
; }
164 void SetBonusDamage(int32 damage
) { m_bonusdamage
= damage
; }
166 bool UpdateStats(Stats stat
);
167 bool UpdateAllStats();
168 void UpdateResistances(uint32 school
);
170 void UpdateMaxHealth();
171 void UpdateMaxPower(Powers power
);
172 void UpdateAttackPowerAndDamage(bool ranged
= false);
173 void UpdateDamagePhysical(WeaponAttackType attType
);
175 bool CanTakeMoreActiveSpells(uint32 SpellIconID
);
176 void ToggleAutocast(uint32 spellid
, bool apply
);
178 bool HasSpell(uint32 spell
) const;
179 void AddTeachSpell(uint32 learned_id
, uint32 source_id
) { m_teachspells
[learned_id
] = source_id
; }
181 void LearnPetPassives();
182 void CastPetAuras(bool current
);
183 void CastPetAura(PetAura
const* aura
);
185 void _LoadSpellCooldowns();
186 void _SaveSpellCooldowns();
187 void _LoadAuras(uint32 timediff
);
192 bool addSpell(uint16 spell_id
,uint16 active
= ACT_DECIDE
, PetSpellState state
= PETSPELL_NEW
, uint16 slot_id
=0xffff, PetSpellType type
= PETSPELL_NORMAL
);
193 bool learnSpell(uint16 spell_id
);
194 void learnLevelupSpells();
195 bool unlearnSpell(uint16 spell_id
);
196 bool removeSpell(uint16 spell_id
);
197 bool _removeSpell(uint16 spell_id
);
199 PetSpellMap m_spells
;
200 TeachSpellMap m_teachspells
;
201 AutoSpellList m_autospells
;
203 void InitPetCreateSpells();
204 void CheckLearning(uint32 spellid
);
205 uint32
resetTalentsCost() const;
206 uint8
GetMaxTalentPointsForLevel(uint32 level
) { return (level
>= 20) ? ((level
- 16) / 4) : 0; }
207 uint8
GetFreeTalentPoints() { return GetByteValue(UNIT_FIELD_BYTES_1
, 1); }
208 void SetFreeTalentPoints(uint8 points
) { SetByteValue(UNIT_FIELD_BYTES_1
, 1, points
); }
210 uint32 m_resetTalentsCost
;
211 time_t m_resetTalentsTime
;
213 uint64
GetAuraUpdateMask() { return m_auraUpdateMask
; }
214 void SetAuraUpdateMask(uint8 slot
) { m_auraUpdateMask
|= (uint64(1) << slot
); }
215 void ResetAuraUpdateMask() { m_auraUpdateMask
= 0; }
217 // overwrite Creature function for name localization back to WorldObject version without localization
218 const char* GetNameForLocaleIdx(int32 locale_idx
) const { return WorldObject::GetNameForLocaleIdx(locale_idx
); }
220 DeclinedName
const* GetDeclinedNames() const { return m_declinedname
; }
222 bool m_removed
; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
224 uint32 m_happinessTimer
;
226 int32 m_duration
; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
228 uint64 m_auraUpdateMask
;
231 DeclinedName
*m_declinedname
;
234 void SaveToDB(uint32
, uint8
) // overwrited of Creature::SaveToDB - don't must be called
238 void DeleteFromDB() // overwrited of Creature::DeleteFromDB - don't must be called