root/trunk/src/game/Pet.h @ 252

Revision 250, 8.8 kB (checked in by yumileroy, 17 years ago)

*Update aura stacking check. By QAston.
*Update pet autocast check. By qubix.

Original author: megamage
Date: 2008-11-17 17:59:33-06:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
4 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef TRINITYCORE_PET_H
22#define TRINITYCORE_PET_H
23
24#include "ObjectDefines.h"
25#include "Creature.h"
26#include "Unit.h"
27
28enum PetType
29{
30    SUMMON_PET              = 0,
31    HUNTER_PET              = 1,
32    GUARDIAN_PET            = 2,
33    MINI_PET                = 3,
34    MAX_PET_TYPE            = 4
35};
36
37extern char const* petTypeSuffix[MAX_PET_TYPE];
38
39enum PetSaveMode
40{
41    PET_SAVE_AS_DELETED       =-1,
42    PET_SAVE_AS_CURRENT       = 0,
43    PET_SAVE_IN_STABLE_SLOT_1 = 1,
44    PET_SAVE_IN_STABLE_SLOT_2 = 2,
45    PET_SAVE_NOT_IN_SLOT      = 3
46};
47
48enum HappinessState
49{
50    UNHAPPY = 1,
51    CONTENT = 2,
52    HAPPY   = 3
53};
54
55enum LoyaltyLevel
56{
57    REBELLIOUS  = 1,
58    UNRULY      = 2,
59    SUBMISSIVE  = 3,
60    DEPENDABLE  = 4,
61    FAITHFUL    = 5,
62    BEST_FRIEND = 6
63};
64
65enum PetSpellState
66{
67    PETSPELL_UNCHANGED = 0,
68    PETSPELL_CHANGED   = 1,
69    PETSPELL_NEW       = 2,
70    PETSPELL_REMOVED   = 3
71};
72
73enum PetSpellType
74{
75    PETSPELL_NORMAL = 0,
76    PETSPELL_FAMILY = 1,
77};
78
79struct PetSpell
80{
81    uint16 slotId;
82    uint16 active;
83    PetSpellState state : 16;
84    PetSpellType type   : 16;
85};
86
87enum ActionFeedback
88{
89    FEEDBACK_NONE            = 0,
90    FEEDBACK_PET_DEAD        = 1,
91    FEEDBACK_NOTHING_TO_ATT  = 2,
92    FEEDBACK_CANT_ATT_TARGET = 3
93};
94
95enum PetTalk
96{
97    PET_TALK_SPECIAL_SPELL  = 0,
98    PET_TALK_ATTACK         = 1
99};
100
101enum PetNameInvalidReason
102{
103    PET_NAME_INVALID                                        = 1,
104    PET_NAME_NO_NAME                                        = 2,
105    PET_NAME_TOO_SHORT                                      = 3,
106    PET_NAME_TOO_LONG                                       = 4,
107    PET_NAME_MIXED_LANGUAGES                                = 6,
108    PET_NAME_PROFANE                                        = 7,
109    PET_NAME_RESERVED                                       = 8,
110    PET_NAME_THREE_CONSECUTIVE                              = 11,
111    PET_NAME_INVALID_SPACE                                  = 12,
112    PET_NAME_CONSECUTIVE_SPACES                             = 13,
113    PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS          = 14,
114    PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END   = 15,
115    PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME              = 16
116};
117
118typedef UNORDERED_MAP<uint16, PetSpell*> PetSpellMap;
119typedef std::map<uint32,uint32> TeachSpellMap;
120typedef std::vector<uint32> AutoSpellList;
121
122#define HAPPINESS_LEVEL_SIZE        333000
123
124extern const uint32 LevelUpLoyalty[6];
125extern const uint32 LevelStartLoyalty[6];
126
127#define ACTIVE_SPELLS_MAX           4
128
129#define OWNER_MAX_DISTANCE 100
130
131#define PET_FOLLOW_DIST  1
132#define PET_FOLLOW_ANGLE (M_PI/2)
133
134class Pet : public Creature
135{
136    public:
137        explicit Pet(PetType type = MAX_PET_TYPE);
138        virtual ~Pet();
139
140        void AddToWorld();
141        void RemoveFromWorld();
142
143        PetType getPetType() const { return m_petType; }
144        void setPetType(PetType type) { m_petType = type; }
145        bool isControlled() const { return getPetType()==SUMMON_PET || getPetType()==HUNTER_PET; }
146        bool isTemporarySummoned() const { return m_duration > 0; }
147
148        bool Create (uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number);
149        bool CreateBaseAtCreature( Creature* creature );
150        bool LoadPetFromDB( Unit* owner,uint32 petentry = 0,uint32 petnumber = 0, bool current = false );
151        void SavePetToDB(PetSaveMode mode);
152        void Remove(PetSaveMode mode, bool returnreagent = false);
153        static void DeleteFromDB(uint32 guidlow);
154
155        void setDeathState(DeathState s);                   // overwrite virtual Creature::setDeathState and Unit::setDeathState
156        void Update(uint32 diff);                           // overwrite virtual Creature::Update and Unit::Update
157
158        uint8 GetPetAutoSpellSize() const { return m_autospells.size(); }
159        uint32 GetPetAutoSpellOnPos(uint8 pos) const
160        {
161            if (pos >= m_autospells.size())
162                return 0;
163            else
164                return m_autospells[pos];
165        }
166
167        void RegenerateFocus();
168        void LooseHappiness();
169        void TickLoyaltyChange();
170        void ModifyLoyalty(int32 addvalue);
171        HappinessState GetHappinessState();
172        uint32 GetMaxLoyaltyPoints(uint32 level);
173        uint32 GetStartLoyaltyPoints(uint32 level);
174        void KillLoyaltyBonus(uint32 level);
175        uint32 GetLoyaltyLevel() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); }
176        void SetLoyaltyLevel(LoyaltyLevel level);
177        void GivePetXP(uint32 xp);
178        void GivePetLevel(uint32 level);
179        bool InitStatsForLevel(uint32 level);
180        bool HaveInDiet(ItemPrototype const* item) const;
181        uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel);
182        void SetDuration(int32 dur) { m_duration = dur; }
183
184        int32 GetBonusDamage() { return m_bonusdamage; }
185        void SetBonusDamage(int32 damage) { m_bonusdamage = damage; }
186
187        bool UpdateStats(Stats stat);
188        bool UpdateAllStats();
189        void UpdateResistances(uint32 school);
190        void UpdateArmor();
191        void UpdateMaxHealth();
192        void UpdateMaxPower(Powers power);
193        void UpdateAttackPowerAndDamage(bool ranged = false);
194        void UpdateDamagePhysical(WeaponAttackType attType);
195
196        bool   CanTakeMoreActiveSpells(uint32 SpellIconID);
197        void   ToggleAutocast(uint32 spellid, bool apply);
198        bool   HasTPForSpell(uint32 spellid);
199        int32  GetTPForSpell(uint32 spellid);
200
201        bool HasSpell(uint32 spell) const;
202        void AddTeachSpell(uint32 learned_id, uint32 source_id) { m_teachspells[learned_id] = source_id; }
203
204        void LearnPetPassives();
205        void CastPetAuras(bool current);
206        void CastPetAura(PetAura const* aura);
207
208        void _LoadSpellCooldowns();
209        void _SaveSpellCooldowns();
210        void _LoadAuras(uint32 timediff);
211        void _SaveAuras();
212        void _LoadSpells();
213        void _SaveSpells();
214
215        bool addSpell(uint16 spell_id, ActiveStates active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, uint16 slot_id=0xffff, PetSpellType type = PETSPELL_NORMAL);
216        bool learnSpell(uint16 spell_id);
217        void removeSpell(uint16 spell_id);
218        bool _removeSpell(uint16 spell_id);
219
220        PetSpellMap     m_spells;
221        TeachSpellMap   m_teachspells;
222        AutoSpellList   m_autospells;
223
224        void InitPetCreateSpells();
225        void CheckLearning(uint32 spellid);
226        uint32 resetTalentsCost() const;
227
228        void  SetTP(int32 TP);
229        int32 GetDispTP();
230
231        int32   m_TrainingPoints;
232        uint32  m_resetTalentsCost;
233        time_t  m_resetTalentsTime;
234
235        uint64 GetAuraUpdateMask() { return m_auraUpdateMask; }
236        void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); }
237        void ResetAuraUpdateMask() { m_auraUpdateMask = 0; }
238
239        DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
240
241        bool    m_removed;                                  // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
242    protected:
243        uint32  m_regenTimer;
244        uint32  m_happinessTimer;
245        uint32  m_loyaltyTimer;
246        PetType m_petType;
247        int32   m_duration;                                 // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
248        int32   m_loyaltyPoints;
249        int32   m_bonusdamage;
250        uint64  m_auraUpdateMask;
251
252        DeclinedName *m_declinedname;
253
254    private:
255        void SaveToDB(uint32, uint8)                        // overwrited of Creature::SaveToDB     - don't must be called
256        {
257            assert(false);
258        }
259        void DeleteFromDB()                                 // overwrited of Creature::DeleteFromDB - don't must be called
260        {
261            assert(false);
262        }
263};
264#endif
Note: See TracBrowser for help on using the browser.