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

Revision 120, 7.7 kB (checked in by yumileroy, 17 years ago)

[svn] * Allow WorldObjects? to keep the grid active, and prevent it from being unloaded. This can be done through calling WorldObject::setActive(bool) from the scripting library. Note that entire instances are still unloaded if no player is present on that map to save resources. This behavior can be changed if the need arises.

Original author: w12x
Date: 2008-10-27 08:41:55-05: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
101typedef HM_NAMESPACE::hash_map<uint16, PetSpell*> PetSpellMap;
102typedef std::map<uint32,uint32> TeachSpellMap;
103typedef std::vector<uint32> AutoSpellList;
104
105#define HAPPINESS_LEVEL_SIZE        333000
106
107extern const uint32 LevelUpLoyalty[6];
108extern const uint32 LevelStartLoyalty[6];
109
110#define ACTIVE_SPELLS_MAX           4
111
112#define OWNER_MAX_DISTANCE 100
113
114#define PET_FOLLOW_DIST  1
115#define PET_FOLLOW_ANGLE (M_PI/2)
116
117class Pet : public Creature
118{
119    public:
120        explicit Pet(PetType type = MAX_PET_TYPE);
121        virtual ~Pet();
122
123        void AddToWorld();
124        void RemoveFromWorld();
125        // always active
126        void setActive() {}
127
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; }
132
133        bool Create (uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number);
134        bool CreateBaseAtCreature( Creature* creature );
135        bool LoadPetFromDB( Unit* 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);
139
140        void setDeathState(DeathState s);                   // overwrite virtual Creature::setDeathState and Unit::setDeathState
141        void Update(uint32 diff);                           // overwrite virtual Creature::Update and Unit::Update
142
143        uint8 GetPetAutoSpellSize() const { return m_autospells.size(); }
144        uint32 GetPetAutoSpellOnPos(uint8 pos) const
145        {
146            if (pos >= m_autospells.size())
147                return 0;
148            else
149                return m_autospells[pos];
150        }
151
152        void RegenerateFocus();
153        void LooseHappiness();
154        void TickLoyaltyChange();
155        void ModifyLoyalty(int32 addvalue);
156        HappinessState GetHappinessState();
157        uint32 GetMaxLoyaltyPoints(uint32 level);
158        uint32 GetStartLoyaltyPoints(uint32 level);
159        void KillLoyaltyBonus(uint32 level);
160        uint32 GetLoyaltyLevel() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); }
161        void SetLoyaltyLevel(LoyaltyLevel level);
162        void GivePetXP(uint32 xp);
163        void GivePetLevel(uint32 level);
164        bool InitStatsForLevel(uint32 level);
165        bool HaveInDiet(ItemPrototype const* item) const;
166        uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel);
167        void SetDuration(int32 dur) { m_duration = dur; }
168
169        int32 GetBonusDamage() { return m_bonusdamage; }
170        void SetBonusDamage(int32 damage) { m_bonusdamage = damage; }
171
172        bool UpdateStats(Stats stat);
173        bool UpdateAllStats();
174        void UpdateResistances(uint32 school);
175        void UpdateArmor();
176        void UpdateMaxHealth();
177        void UpdateMaxPower(Powers power);
178        void UpdateAttackPowerAndDamage(bool ranged = false);
179        void UpdateDamagePhysical(WeaponAttackType attType);
180
181        bool   CanTakeMoreActiveSpells(uint32 SpellIconID);
182        void   ToggleAutocast(uint32 spellid, bool apply);
183        bool   HasTPForSpell(uint32 spellid);
184        int32  GetTPForSpell(uint32 spellid);
185
186        bool HasSpell(uint32 spell) const;
187        void AddTeachSpell(uint32 learned_id, uint32 source_id) { m_teachspells[learned_id] = source_id; }
188
189        void LearnPetPassives();
190        void CastPetAuras(bool current);
191        void CastPetAura(PetAura const* aura);
192
193        void _LoadSpellCooldowns();
194        void _SaveSpellCooldowns();
195        void _LoadAuras(uint32 timediff);
196        void _SaveAuras();
197        void _LoadSpells();
198        void _SaveSpells();
199
200        bool addSpell(uint16 spell_id,uint16 active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, uint16 slot_id=0xffff, PetSpellType type = PETSPELL_NORMAL);
201        bool learnSpell(uint16 spell_id);
202        void removeSpell(uint16 spell_id);
203        bool _removeSpell(uint16 spell_id);
204
205        PetSpellMap     m_spells;
206        TeachSpellMap   m_teachspells;
207        AutoSpellList   m_autospells;
208
209        void InitPetCreateSpells();
210        void CheckLearning(uint32 spellid);
211        uint32 resetTalentsCost() const;
212
213        void  SetTP(int32 TP);
214        int32 GetDispTP();
215
216        int32   m_TrainingPoints;
217        uint32  m_resetTalentsCost;
218        time_t  m_resetTalentsTime;
219
220        uint64 GetAuraUpdateMask() { return m_auraUpdateMask; }
221        void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); }
222        void ResetAuraUpdateMask() { m_auraUpdateMask = 0; }
223
224        DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
225
226        bool    m_removed;                                  // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
227    protected:
228        uint32  m_regenTimer;
229        uint32  m_happinessTimer;
230        uint32  m_loyaltyTimer;
231        PetType m_petType;
232        int32   m_duration;                                 // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
233        int32   m_loyaltyPoints;
234        int32   m_bonusdamage;
235        uint64  m_auraUpdateMask;
236
237        DeclinedName *m_declinedname;
238
239    private:
240        void SaveToDB(uint32, uint8)                        // overwrited of Creature::SaveToDB     - don't must be called
241        {
242            assert(false);
243        }
244        void DeleteFromDB()                                 // overwrited of Creature::DeleteFromDB - don't must be called
245        {
246            assert(false);
247        }
248};
249#endif
Note: See TracBrowser for help on using the browser.