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