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

Revision 2, 7.6 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/*
2 * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3 *
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.
8 *
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.
13 *
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
17 */
18
19#ifndef MANGOSSERVER_PET_H
20#define MANGOSSERVER_PET_H
21
22#include "ObjectDefines.h"
23#include "Creature.h"
24#include "Unit.h"
25
26enum PetType
27{
28    SUMMON_PET              = 0,
29    HUNTER_PET              = 1,
30    GUARDIAN_PET            = 2,
31    MINI_PET                = 3,
32    MAX_PET_TYPE            = 4
33};
34
35extern char const* petTypeSuffix[MAX_PET_TYPE];
36
37enum PetSaveMode
38{
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
44};
45
46enum HappinessState
47{
48    UNHAPPY = 1,
49    CONTENT = 2,
50    HAPPY   = 3
51};
52
53enum LoyaltyLevel
54{
55    REBELLIOUS  = 1,
56    UNRULY      = 2,
57    SUBMISSIVE  = 3,
58    DEPENDABLE  = 4,
59    FAITHFUL    = 5,
60    BEST_FRIEND = 6
61};
62
63enum PetSpellState
64{
65    PETSPELL_UNCHANGED = 0,
66    PETSPELL_CHANGED   = 1,
67    PETSPELL_NEW       = 2,
68    PETSPELL_REMOVED   = 3
69};
70
71enum PetSpellType
72{
73    PETSPELL_NORMAL = 0,
74    PETSPELL_FAMILY = 1,
75};
76
77struct PetSpell
78{
79    uint16 slotId;
80    uint16 active;
81    PetSpellState state : 16;
82    PetSpellType type   : 16;
83};
84
85enum ActionFeedback
86{
87    FEEDBACK_NONE            = 0,
88    FEEDBACK_PET_DEAD        = 1,
89    FEEDBACK_NOTHING_TO_ATT  = 2,
90    FEEDBACK_CANT_ATT_TARGET = 3
91};
92
93enum PetTalk
94{
95    PET_TALK_SPECIAL_SPELL  = 0,
96    PET_TALK_ATTACK         = 1
97};
98
99typedef HM_NAMESPACE::hash_map<uint16, PetSpell*> PetSpellMap;
100typedef std::map<uint32,uint32> TeachSpellMap;
101typedef std::vector<uint32> AutoSpellList;
102
103#define HAPPINESS_LEVEL_SIZE        333000
104
105extern const uint32 LevelUpLoyalty[6];
106extern const uint32 LevelStartLoyalty[6];
107
108#define ACTIVE_SPELLS_MAX           4
109
110#define OWNER_MAX_DISTANCE 100
111
112#define PET_FOLLOW_DIST  1
113#define PET_FOLLOW_ANGLE (M_PI/2)
114
115class Pet : public Creature
116{
117    public:
118        explicit Pet(PetType type = MAX_PET_TYPE);
119        virtual ~Pet();
120
121        void AddToWorld();
122        void RemoveFromWorld();
123
124        PetType getPetType() const { return m_petType; }
125        void setPetType(PetType type) { m_petType = type; }
126        bool isControlled() const { return getPetType()==SUMMON_PET || getPetType()==HUNTER_PET; }
127        bool isTemporarySummoned() const { return m_duration > 0; }
128
129        bool Create (uint32 guidlow, Map *map, uint32 Entry, uint32 pet_number);
130        bool CreateBaseAtCreature( Creature* creature );
131        bool LoadPetFromDB( Unit* owner,uint32 petentry = 0,uint32 petnumber = 0, bool current = false );
132        void SavePetToDB(PetSaveMode mode);
133        void Remove(PetSaveMode mode, bool returnreagent = false);
134        static void DeleteFromDB(uint32 guidlow);
135
136        void setDeathState(DeathState s);                   // overwrite virtual Creature::setDeathState and Unit::setDeathState
137        void Update(uint32 diff);                           // overwrite virtual Creature::Update and Unit::Update
138
139        uint8 GetPetAutoSpellSize() const { return m_autospells.size(); }
140        uint32 GetPetAutoSpellOnPos(uint8 pos) const
141        {
142            if (pos >= m_autospells.size())
143                return 0;
144            else
145                return m_autospells[pos];
146        }
147
148        void RegenerateFocus();
149        void LooseHappiness();
150        void TickLoyaltyChange();
151        void ModifyLoyalty(int32 addvalue);
152        HappinessState GetHappinessState();
153        uint32 GetMaxLoyaltyPoints(uint32 level);
154        uint32 GetStartLoyaltyPoints(uint32 level);
155        void KillLoyaltyBonus(uint32 level);
156        uint32 GetLoyaltyLevel() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); }
157        void SetLoyaltyLevel(LoyaltyLevel level);
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; }
164
165        int32 GetBonusDamage() { return m_bonusdamage; }
166        void SetBonusDamage(int32 damage) { m_bonusdamage = damage; }
167
168        bool UpdateStats(Stats stat);
169        bool UpdateAllStats();
170        void UpdateResistances(uint32 school);
171        void UpdateArmor();
172        void UpdateMaxHealth();
173        void UpdateMaxPower(Powers power);
174        void UpdateAttackPowerAndDamage(bool ranged = false);
175        void UpdateDamagePhysical(WeaponAttackType attType);
176
177        bool   CanTakeMoreActiveSpells(uint32 SpellIconID);
178        void   ToggleAutocast(uint32 spellid, bool apply);
179        bool   HasTPForSpell(uint32 spellid);
180        int32  GetTPForSpell(uint32 spellid);
181
182        bool HasSpell(uint32 spell) const;
183        void AddTeachSpell(uint32 learned_id, uint32 source_id) { m_teachspells[learned_id] = source_id; }
184
185        void LearnPetPassives();
186        void CastPetAuras(bool current);
187        void CastPetAura(PetAura const* aura);
188
189        void _LoadSpellCooldowns();
190        void _SaveSpellCooldowns();
191        void _LoadAuras(uint32 timediff);
192        void _SaveAuras();
193        void _LoadSpells();
194        void _SaveSpells();
195
196        bool addSpell(uint16 spell_id,uint16 active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, uint16 slot_id=0xffff, PetSpellType type = PETSPELL_NORMAL);
197        bool learnSpell(uint16 spell_id);
198        void removeSpell(uint16 spell_id);
199        bool _removeSpell(uint16 spell_id);
200
201        PetSpellMap     m_spells;
202        TeachSpellMap   m_teachspells;
203        AutoSpellList   m_autospells;
204
205        void InitPetCreateSpells();
206        void CheckLearning(uint32 spellid);
207        uint32 resetTalentsCost() const;
208
209        void  SetTP(int32 TP);
210        int32 GetDispTP();
211
212        int32   m_TrainingPoints;
213        uint32  m_resetTalentsCost;
214        time_t  m_resetTalentsTime;
215
216        uint64 GetAuraUpdateMask() { return m_auraUpdateMask; }
217        void SetAuraUpdateMask(uint8 slot) { m_auraUpdateMask |= (uint64(1) << slot); }
218        void ResetAuraUpdateMask() { m_auraUpdateMask = 0; }
219
220        DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
221
222        bool    m_removed;                                  // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
223    protected:
224        uint32  m_regenTimer;
225        uint32  m_happinessTimer;
226        uint32  m_loyaltyTimer;
227        PetType m_petType;
228        int32   m_duration;                                 // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
229        int32   m_loyaltyPoints;
230        int32   m_bonusdamage;
231        uint64  m_auraUpdateMask;
232
233        DeclinedName *m_declinedname;
234
235    private:
236        void SaveToDB(uint32, uint8)                        // overwrited of Creature::SaveToDB     - don't must be called
237        {
238            assert(false);
239        }
240        void DeleteFromDB()                                 // overwrited of Creature::DeleteFromDB - don't must be called
241        {
242            assert(false);
243        }
244};
245#endif
Note: See TracBrowser for help on using the browser.