root/trunk/src/game/SpellMgr.h @ 250

Revision 250, 36.2 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 _SPELLMGR_H
22#define _SPELLMGR_H
23
24// For static or at-server-startup loaded spell data
25// For more high level function for sSpellStore data
26
27#include "SharedDefines.h"
28#include "Database/DBCStructure.h"
29#include "Database/SQLStorage.h"
30
31#include "Utilities/UnorderedMap.h"
32#include <map>
33
34class Player;
35class Spell;
36
37extern SQLStorage sSpellThreatStore;
38
39enum SpellFailedReason
40{
41    SPELL_FAILED_AFFECTING_COMBAT               = 0x00,
42    SPELL_FAILED_ALREADY_AT_FULL_HEALTH         = 0x01,
43    SPELL_FAILED_ALREADY_AT_FULL_MANA           = 0x02,
44    SPELL_FAILED_ALREADY_AT_FULL_POWER          = 0x03,
45    SPELL_FAILED_ALREADY_BEING_TAMED            = 0x04,
46    SPELL_FAILED_ALREADY_HAVE_CHARM             = 0x05,
47    SPELL_FAILED_ALREADY_HAVE_SUMMON            = 0x06,
48    SPELL_FAILED_ALREADY_OPEN                   = 0x07,
49    SPELL_FAILED_AURA_BOUNCED                   = 0x08,
50    SPELL_FAILED_AUTOTRACK_INTERRUPTED          = 0x09,
51    SPELL_FAILED_BAD_IMPLICIT_TARGETS           = 0x0A,
52    SPELL_FAILED_BAD_TARGETS                    = 0x0B,
53    SPELL_FAILED_CANT_BE_CHARMED                = 0x0C,
54    SPELL_FAILED_CANT_BE_DISENCHANTED           = 0x0D,
55    SPELL_FAILED_CANT_BE_DISENCHANTED_SKILL     = 0x0E,
56    SPELL_FAILED_CANT_BE_PROSPECTED             = 0x0F,
57    SPELL_FAILED_CANT_CAST_ON_TAPPED            = 0x10,
58    SPELL_FAILED_CANT_DUEL_WHILE_INVISIBLE      = 0x11,
59    SPELL_FAILED_CANT_DUEL_WHILE_STEALTHED      = 0x12,
60    SPELL_FAILED_CANT_STEALTH                   = 0x13,
61    SPELL_FAILED_CASTER_AURASTATE               = 0x14,
62    SPELL_FAILED_CASTER_DEAD                    = 0x15,
63    SPELL_FAILED_CHARMED                        = 0x16,
64    SPELL_FAILED_CHEST_IN_USE                   = 0x17,
65    SPELL_FAILED_CONFUSED                       = 0x18,
66    SPELL_FAILED_DONT_REPORT                    = 0x19,
67    SPELL_FAILED_EQUIPPED_ITEM                  = 0x1A,
68    SPELL_FAILED_EQUIPPED_ITEM_CLASS            = 0x1B,
69    SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND   = 0x1C,
70    SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND    = 0x1D,
71    SPELL_FAILED_ERROR                          = 0x1E,
72    SPELL_FAILED_FIZZLE                         = 0x1F,
73    SPELL_FAILED_FLEEING                        = 0x20,
74    SPELL_FAILED_FOOD_LOWLEVEL                  = 0x21,
75    SPELL_FAILED_HIGHLEVEL                      = 0x22,
76    SPELL_FAILED_HUNGER_SATIATED                = 0x23,
77    SPELL_FAILED_IMMUNE                         = 0x24,
78    SPELL_FAILED_INTERRUPTED                    = 0x25,
79    SPELL_FAILED_INTERRUPTED_COMBAT             = 0x26,
80    SPELL_FAILED_ITEM_ALREADY_ENCHANTED         = 0x27,
81    SPELL_FAILED_ITEM_GONE                      = 0x28,
82    SPELL_FAILED_ITEM_NOT_FOUND                 = 0x29,
83    SPELL_FAILED_ITEM_NOT_READY                 = 0x2A,
84    SPELL_FAILED_LEVEL_REQUIREMENT              = 0x2B,
85    SPELL_FAILED_LINE_OF_SIGHT                  = 0x2C,
86    SPELL_FAILED_LOWLEVEL                       = 0x2D,
87    SPELL_FAILED_LOW_CASTLEVEL                  = 0x2E,
88    SPELL_FAILED_MAINHAND_EMPTY                 = 0x2F,
89    SPELL_FAILED_MOVING                         = 0x30,
90    SPELL_FAILED_NEED_AMMO                      = 0x31,
91    SPELL_FAILED_NEED_AMMO_POUCH                = 0x32,
92    SPELL_FAILED_NEED_EXOTIC_AMMO               = 0x33,
93    SPELL_FAILED_NOPATH                         = 0x34,
94    SPELL_FAILED_NOT_BEHIND                     = 0x35,
95    SPELL_FAILED_NOT_FISHABLE                   = 0x36,
96    SPELL_FAILED_NOT_FLYING                     = 0x37,
97    SPELL_FAILED_NOT_HERE                       = 0x38,
98    SPELL_FAILED_NOT_INFRONT                    = 0x39,
99    SPELL_FAILED_NOT_IN_CONTROL                 = 0x3A,
100    SPELL_FAILED_NOT_KNOWN                      = 0x3B,
101    SPELL_FAILED_NOT_MOUNTED                    = 0x3C,
102    SPELL_FAILED_NOT_ON_TAXI                    = 0x3D,
103    SPELL_FAILED_NOT_ON_TRANSPORT               = 0x3E,
104    SPELL_FAILED_NOT_READY                      = 0x3F,
105    SPELL_FAILED_NOT_SHAPESHIFT                 = 0x40,
106    SPELL_FAILED_NOT_STANDING                   = 0x41,
107    SPELL_FAILED_NOT_TRADEABLE                  = 0x42,
108    SPELL_FAILED_NOT_TRADING                    = 0x43,
109    SPELL_FAILED_NOT_UNSHEATHED                 = 0x44,
110    SPELL_FAILED_NOT_WHILE_GHOST                = 0x45,
111    SPELL_FAILED_NO_AMMO                        = 0x46,
112    SPELL_FAILED_NO_CHARGES_REMAIN              = 0x47,
113    SPELL_FAILED_NO_CHAMPION                    = 0x48,
114    SPELL_FAILED_NO_COMBO_POINTS                = 0x49,
115    SPELL_FAILED_NO_DUELING                     = 0x4A,
116    SPELL_FAILED_NO_ENDURANCE                   = 0x4B,
117    SPELL_FAILED_NO_FISH                        = 0x4C,
118    SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED    = 0x4D,
119    SPELL_FAILED_NO_MOUNTS_ALLOWED              = 0x4E,
120    SPELL_FAILED_NO_PET                         = 0x4F,
121    SPELL_FAILED_NO_POWER                       = 0x50,
122    SPELL_FAILED_NOTHING_TO_DISPEL              = 0x51,
123    SPELL_FAILED_NOTHING_TO_STEAL               = 0x52,
124    SPELL_FAILED_ONLY_ABOVEWATER                = 0x53,
125    SPELL_FAILED_ONLY_DAYTIME                   = 0x54,
126    SPELL_FAILED_ONLY_INDOORS                   = 0x55,
127    SPELL_FAILED_ONLY_MOUNTED                   = 0x56,
128    SPELL_FAILED_ONLY_NIGHTTIME                 = 0x57,
129    SPELL_FAILED_ONLY_OUTDOORS                  = 0x58,
130    SPELL_FAILED_ONLY_SHAPESHIFT                = 0x59,
131    SPELL_FAILED_ONLY_STEALTHED                 = 0x5A,
132    SPELL_FAILED_ONLY_UNDERWATER                = 0x5B,
133    SPELL_FAILED_OUT_OF_RANGE                   = 0x5C,
134    SPELL_FAILED_PACIFIED                       = 0x5D,
135    SPELL_FAILED_POSSESSED                      = 0x5E,
136    SPELL_FAILED_REAGENTS                       = 0x5F,
137    SPELL_FAILED_REQUIRES_AREA                  = 0x60,
138    SPELL_FAILED_REQUIRES_SPELL_FOCUS           = 0x61,
139    SPELL_FAILED_ROOTED                         = 0x62,
140    SPELL_FAILED_SILENCED                       = 0x63,
141    SPELL_FAILED_SPELL_IN_PROGRESS              = 0x64,
142    SPELL_FAILED_SPELL_LEARNED                  = 0x65,
143    SPELL_FAILED_SPELL_UNAVAILABLE              = 0x66,
144    SPELL_FAILED_STUNNED                        = 0x67,
145    SPELL_FAILED_TARGETS_DEAD                   = 0x68,
146    SPELL_FAILED_TARGET_AFFECTING_COMBAT        = 0x69,
147    SPELL_FAILED_TARGET_AURASTATE               = 0x6A,
148    SPELL_FAILED_TARGET_DUELING                 = 0x6B,
149    SPELL_FAILED_TARGET_ENEMY                   = 0x6C,
150    SPELL_FAILED_TARGET_ENRAGED                 = 0x6D,
151    SPELL_FAILED_TARGET_FRIENDLY                = 0x6E,
152    SPELL_FAILED_TARGET_IN_COMBAT               = 0x6F,
153    SPELL_FAILED_TARGET_IS_PLAYER               = 0x70,
154    SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED    = 0x71,
155    SPELL_FAILED_TARGET_NOT_DEAD                = 0x72,
156    SPELL_FAILED_TARGET_NOT_IN_PARTY            = 0x73,
157    SPELL_FAILED_TARGET_NOT_LOOTED              = 0x74,
158    SPELL_FAILED_TARGET_NOT_PLAYER              = 0x75,
159    SPELL_FAILED_TARGET_NO_POCKETS              = 0x76,
160    SPELL_FAILED_TARGET_NO_WEAPONS              = 0x77,
161    SPELL_FAILED_TARGET_UNSKINNABLE             = 0x78,
162    SPELL_FAILED_THIRST_SATIATED                = 0x79,
163    SPELL_FAILED_TOO_CLOSE                      = 0x7A,
164    SPELL_FAILED_TOO_MANY_OF_ITEM               = 0x7B,
165    SPELL_FAILED_TOTEM_CATEGORY                 = 0x7C,
166    SPELL_FAILED_TOTEMS                         = 0x7D,
167    SPELL_FAILED_TRAINING_POINTS                = 0x7E,
168    SPELL_FAILED_TRY_AGAIN                      = 0x7F,
169    SPELL_FAILED_UNIT_NOT_BEHIND                = 0x80,
170    SPELL_FAILED_UNIT_NOT_INFRONT               = 0x81,
171    SPELL_FAILED_WRONG_PET_FOOD                 = 0x82,
172    SPELL_FAILED_NOT_WHILE_FATIGUED             = 0x83,
173    SPELL_FAILED_TARGET_NOT_IN_INSTANCE         = 0x84,
174    SPELL_FAILED_NOT_WHILE_TRADING              = 0x85,
175    SPELL_FAILED_TARGET_NOT_IN_RAID             = 0x86,
176    SPELL_FAILED_DISENCHANT_WHILE_LOOTING       = 0x87,
177    SPELL_FAILED_PROSPECT_WHILE_LOOTING         = 0x88,
178    SPELL_FAILED_PROSPECT_NEED_MORE             = 0x89,
179    SPELL_FAILED_TARGET_FREEFORALL              = 0x8A,
180    SPELL_FAILED_NO_EDIBLE_CORPSES              = 0x8B,
181    SPELL_FAILED_ONLY_BATTLEGROUNDS             = 0x8C,
182    SPELL_FAILED_TARGET_NOT_GHOST               = 0x8D,
183    SPELL_FAILED_TOO_MANY_SKILLS                = 0x8E,
184    SPELL_FAILED_TRANSFORM_UNUSABLE             = 0x8F,
185    SPELL_FAILED_WRONG_WEATHER                  = 0x90,
186    SPELL_FAILED_DAMAGE_IMMUNE                  = 0x91,
187    SPELL_FAILED_PREVENTED_BY_MECHANIC          = 0x92,
188    SPELL_FAILED_PLAY_TIME                      = 0x93,
189    SPELL_FAILED_REPUTATION                     = 0x94,
190    SPELL_FAILED_MIN_SKILL                      = 0x95,
191    SPELL_FAILED_NOT_IN_ARENA                   = 0x96,
192    SPELL_FAILED_NOT_ON_SHAPESHIFT              = 0x97,
193    SPELL_FAILED_NOT_ON_STEALTHED               = 0x98,
194    SPELL_FAILED_NOT_ON_DAMAGE_IMMUNE           = 0x99,
195    SPELL_FAILED_NOT_ON_MOUNTED                 = 0x9A,
196    SPELL_FAILED_TOO_SHALLOW                    = 0x9B,
197    SPELL_FAILED_TARGET_NOT_IN_SANCTUARY        = 0x9C,
198    SPELL_FAILED_TARGET_IS_TRIVIAL              = 0x9D,
199    SPELL_FAILED_BM_OR_INVISGOD                 = 0x9E,
200    SPELL_FAILED_EXPERT_RIDING_REQUIREMENT      = 0x9F,
201    SPELL_FAILED_ARTISAN_RIDING_REQUIREMENT     = 0xA0,
202    SPELL_FAILED_NOT_IDLE                       = 0xA1,
203    SPELL_FAILED_NOT_INACTIVE                   = 0xA2,
204    SPELL_FAILED_PARTIAL_PLAYTIME               = 0xA3,
205    SPELL_FAILED_NO_PLAYTIME                    = 0xA4,
206    SPELL_FAILED_NOT_IN_BATTLEGROUND            = 0xA5,
207    SPELL_FAILED_ONLY_IN_ARENA                  = 0xA6,
208    SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE = 0xA7,
209    SPELL_FAILED_UNKNOWN                        = 0xA8,
210};
211
212enum SpellFamilyNames
213{
214    SPELLFAMILY_GENERIC     = 0,
215    SPELLFAMILY_UNK1        = 1,                            // events, holidays
216    // 2 - unused
217    SPELLFAMILY_MAGE        = 3,
218    SPELLFAMILY_WARRIOR     = 4,
219    SPELLFAMILY_WARLOCK     = 5,
220    SPELLFAMILY_PRIEST      = 6,
221    SPELLFAMILY_DRUID       = 7,
222    SPELLFAMILY_ROGUE       = 8,
223    SPELLFAMILY_HUNTER      = 9,
224    SPELLFAMILY_PALADIN     = 10,
225    SPELLFAMILY_SHAMAN      = 11,
226    SPELLFAMILY_UNK2        = 12,
227    SPELLFAMILY_POTION      = 13
228};
229
230enum SpellDisableTypes
231{
232    SPELL_DISABLE_PLAYER = 1,
233    SPELL_DISABLE_CREATURE = 2
234};
235
236//Some SpellFamilyFlags
237#define SPELLFAMILYFLAG_ROGUE_VANISH            0x000000800LL
238#define SPELLFAMILYFLAG_ROGUE_STEALTH           0x000400000LL
239#define SPELLFAMILYFLAG_ROGUE_BACKSTAB          0x000800004LL
240#define SPELLFAMILYFLAG_ROGUE_SAP               0x000000080LL
241#define SPELLFAMILYFLAG_ROGUE_FEINT             0x008000000LL
242#define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT        0x000200000LL
243#define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE   0x9003E0000LL
244
245// Spell clasification
246enum SpellSpecific
247{
248    SPELL_NORMAL            = 0,
249    SPELL_SEAL              = 1,
250    SPELL_BLESSING          = 2,
251    SPELL_AURA              = 3,
252    SPELL_STING             = 4,
253    SPELL_CURSE             = 5,
254    SPELL_ASPECT            = 6,
255    SPELL_TRACKER           = 7,
256    SPELL_WARLOCK_ARMOR     = 8,
257    SPELL_MAGE_ARMOR        = 9,
258    SPELL_ELEMENTAL_SHIELD  = 10,
259    SPELL_MAGE_POLYMORPH    = 11,
260    SPELL_POSITIVE_SHOUT    = 12,
261    SPELL_JUDGEMENT         = 13,
262    SPELL_BATTLE_ELIXIR     = 14,
263    SPELL_GUARDIAN_ELIXIR   = 15,
264    SPELL_FLASK_ELIXIR      = 16,
265    SPELL_WARLOCK_CORRUPTION= 17
266};
267
268SpellSpecific GetSpellSpecific(uint32 spellId);
269
270// Different spell properties
271inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); }
272uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL);
273inline float GetSpellMinRange(SpellRangeEntry const *range) { return (range ? range->minRange : 0); }
274inline float GetSpellMaxRange(SpellRangeEntry const *range) { return (range ? range->maxRange : 0); }
275inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; }
276int32 GetSpellDuration(SpellEntry const *spellInfo);
277int32 GetSpellMaxDuration(SpellEntry const *spellInfo);
278
279inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
280{
281    for(int i= 0; i < 3; ++i)
282        if(spellInfo->Effect[i]==effect)
283            return true;
284    return false;
285}
286
287//bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
288
289inline bool IsSealSpell(SpellEntry const *spellInfo)
290{
291    //Collection of all the seal family flags. No other paladin spell has any of those.
292    return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN &&
293        ( spellInfo->SpellFamilyFlags & 0x4000A000200LL );
294}
295
296inline bool IsElementalShield(SpellEntry const *spellInfo)
297{
298    // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus
299    return (spellInfo->SpellFamilyFlags & 0x42000000400LL) || spellInfo->Id == 23552;
300}
301
302int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
303bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2);
304bool IsSingleFromSpellSpecificPerTarget(uint32 spellSpec1,uint32 spellSpec2);
305bool IsPassiveSpell(uint32 spellId);
306
307inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo)
308{
309    switch(spellInfo->Id)
310    {
311        case 40214:                                     // Dragonmaw Illusion
312        case 35480: case 35481: case 35482:             // Human Illusion
313        case 35483: case 39824:                         // Human Illusion
314            return true;
315    }
316
317    return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT;
318}
319
320inline bool IsNonCombatSpell(SpellEntry const *spellInfo)
321{
322    return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0;
323}
324
325bool IsPositiveSpell(uint32 spellId);
326bool IsPositiveEffect(uint32 spellId, uint32 effIndex);
327bool IsPositiveTarget(uint32 targetA, uint32 targetB);
328
329bool IsSingleTargetSpell(SpellEntry const *spellInfo);
330bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);
331
332bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id);
333
334inline bool IsAreaEffectTarget( Targets target )
335{
336    switch (target )
337    {
338        case TARGET_AREAEFFECT_CUSTOM:
339        case TARGET_ALL_ENEMY_IN_AREA:
340        case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
341        case TARGET_ALL_PARTY_AROUND_CASTER:
342        case TARGET_ALL_AROUND_CASTER:
343        case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
344        case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
345        case TARGET_ALL_PARTY:
346        case TARGET_ALL_PARTY_AROUND_CASTER_2:
347        case TARGET_AREAEFFECT_PARTY:
348        case TARGET_AREAEFFECT_CUSTOM_2:
349        case TARGET_AREAEFFECT_PARTY_AND_CLASS:
350        case TARGET_IN_FRONT_OF_CASTER:
351        case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
352            return true;
353        default:
354            break;
355    }
356    return false;
357}
358
359inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo)
360{
361    if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0])))
362        return true;
363    if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1])))
364        return true;
365    if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2])))
366        return true;
367    return false;
368}
369
370inline bool IsAreaAuraEffect(uint32 effect)
371{
372    if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY    ||
373        effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND   ||
374        effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY    ||
375        effect == SPELL_EFFECT_APPLY_AREA_AURA_PET      ||
376        effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER)
377        return true;
378    return false;
379}
380
381inline bool IsDispelSpell(SpellEntry const *spellInfo)
382{
383    if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL ||
384        spellInfo->Effect[1] == SPELL_EFFECT_DISPEL ||
385        spellInfo->Effect[2] == SPELL_EFFECT_DISPEL )
386        return true;
387    return false;
388}
389inline bool isSpellBreakStealth(SpellEntry const* spellInfo)
390{
391    return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH);
392}
393
394uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form);
395
396inline bool IsChanneledSpell(SpellEntry const* spellInfo)
397{
398    return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2));
399}
400
401inline bool NeedsComboPoints(SpellEntry const* spellInfo)
402{
403    return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2));
404}
405
406inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo)
407{
408    return SpellSchoolMask(spellInfo->SchoolMask);
409}
410
411inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect)
412{
413    uint32 mask = 0;
414    if (spellInfo->Mechanic)
415        mask |= 1<<spellInfo->Mechanic;
416    if (spellInfo->EffectMechanic[effect])
417        mask |= 1<<spellInfo->EffectMechanic[effect];
418    return mask;
419}
420
421inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect)
422{
423    if (spellInfo->EffectMechanic[effect])
424        return Mechanics(spellInfo->EffectMechanic[effect]);
425    if (spellInfo->Mechanic)
426        return Mechanics(spellInfo->Mechanic);
427    return MECHANIC_NONE;
428}
429
430inline uint32 GetDispellMask(DispelType dispel)
431{
432    // If dispel all
433    if (dispel == DISPEL_ALL)
434        return DISPEL_ALL_MASK;
435    else
436        return (1 << dispel);
437}
438
439// Diminishing Returns interaction with spells
440DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered);
441bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
442DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group);
443
444// Spell affects related declarations (accessed using SpellMgr functions)
445typedef std::map<uint32, uint64> SpellAffectMap;
446
447// Spell proc event related declarations (accessed using SpellMgr functions)
448enum ProcFlags
449{
450    PROC_FLAG_NONE                  = 0x00000000,           // None
451    PROC_FLAG_HIT_MELEE             = 0x00000001,           // On melee hit
452    PROC_FLAG_STRUCK_MELEE          = 0x00000002,           // On being struck melee
453    PROC_FLAG_KILL_XP_GIVER         = 0x00000004,           // On kill target giving XP or honor
454    PROC_FLAG_SPECIAL_DROP          = 0x00000008,           //
455    PROC_FLAG_DODGE                 = 0x00000010,           // On dodge melee attack
456    PROC_FLAG_PARRY                 = 0x00000020,           // On parry melee attack
457    PROC_FLAG_BLOCK                 = 0x00000040,           // On block attack
458    PROC_FLAG_TOUCH                 = 0x00000080,           // On being touched (for bombs, probably?)
459    PROC_FLAG_TARGET_LOW_HEALTH     = 0x00000100,           // On deal damage to enemy with 20% or less health
460    PROC_FLAG_LOW_HEALTH            = 0x00000200,           // On health dropped below 20%
461    PROC_FLAG_STRUCK_RANGED         = 0x00000400,           // On being struck ranged
462    PROC_FLAG_HIT_SPECIAL           = 0x00000800,           // (!)Removed, may be reassigned in future
463    PROC_FLAG_CRIT_MELEE            = 0x00001000,           // On crit melee
464    PROC_FLAG_STRUCK_CRIT_MELEE     = 0x00002000,           // On being critically struck in melee
465    PROC_FLAG_CAST_SPELL            = 0x00004000,           // On cast spell
466    PROC_FLAG_TAKE_DAMAGE           = 0x00008000,           // On take damage
467    PROC_FLAG_CRIT_SPELL            = 0x00010000,           // On crit spell
468    PROC_FLAG_HIT_SPELL             = 0x00020000,           // On hit spell
469    PROC_FLAG_STRUCK_CRIT_SPELL     = 0x00040000,           // On being critically struck by a spell
470    PROC_FLAG_HIT_RANGED            = 0x00080000,           // On getting ranged hit
471    PROC_FLAG_STRUCK_SPELL          = 0x00100000,           // On being struck by a spell
472    PROC_FLAG_TRAP                  = 0x00200000,           // On trap activation (?)
473    PROC_FLAG_CRIT_RANGED           = 0x00400000,           // On getting ranged crit
474    PROC_FLAG_STRUCK_CRIT_RANGED    = 0x00800000,           // On being critically struck by a ranged attack
475    PROC_FLAG_RESIST_SPELL          = 0x01000000,           // On resist enemy spell
476    PROC_FLAG_TARGET_RESISTS        = 0x02000000,           // On enemy resisted spell
477    PROC_FLAG_TARGET_DODGE_OR_PARRY = 0x04000000,           // On enemy dodges/parries
478    PROC_FLAG_HEAL                  = 0x08000000,           // On heal
479    PROC_FLAG_CRIT_HEAL             = 0x10000000,           // On critical healing effect
480    PROC_FLAG_HEALED                = 0x20000000,           // On healing
481    PROC_FLAG_TARGET_BLOCK          = 0x40000000,           // On enemy blocks
482    PROC_FLAG_MISS                  = 0x80000000            // On miss melee attack
483};
484
485struct SpellProcEventEntry
486{
487    uint32      schoolMask;                                 // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2
488    uint32      category;                                   // if nonzero - match proc condition based on candidate spell's category
489    uint32      skillId;                                    // if nonzero - for matching proc condition based on candidate spell's skillId from SkillLineAbility.dbc (Shadow Bolt = Destruction)
490    uint32      spellFamilyName;                            // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value
491    uint64      spellFamilyMask;                            // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do)
492    uint32      procFlags;                                  // bitmask for matching proc event
493    float       ppmRate;                                    // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc
494    uint32      cooldown;                                   // hidden cooldown used for some spell proc events, applied to _triggered_spell_
495};
496
497typedef UNORDERED_MAP<uint32, SpellProcEventEntry> SpellProcEventMap;
498
499#define ELIXIR_BATTLE_MASK    0x1
500#define ELIXIR_GUARDIAN_MASK  0x2
501#define ELIXIR_FLASK_MASK     (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK)
502#define ELIXIR_UNSTABLE_MASK  0x4
503#define ELIXIR_SHATTRATH_MASK 0x8
504
505typedef std::map<uint32, uint8> SpellElixirMap;
506
507// Spell script target related declarations (accessed using SpellMgr functions)
508enum SpellTargetType
509{
510    SPELL_TARGET_TYPE_GAMEOBJECT = 0,
511    SPELL_TARGET_TYPE_CREATURE   = 1,
512    SPELL_TARGET_TYPE_DEAD       = 2
513};
514
515#define MAX_SPELL_TARGET_TYPE 3
516
517struct SpellTargetEntry
518{
519    SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {}
520    SpellTargetType type;
521    uint32 targetEntry;
522};
523
524typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
525
526// coordinates for spells (accessed using SpellMgr functions)
527struct SpellTargetPosition
528{
529    uint32 target_mapId;
530    float  target_X;
531    float  target_Y;
532    float  target_Z;
533    float  target_Orientation;
534};
535
536typedef UNORDERED_MAP<uint32, SpellTargetPosition> SpellTargetPositionMap;
537
538// Spell pet auras
539class PetAura
540{
541    public:
542        PetAura()
543        {
544            auras.clear();
545        }
546
547        PetAura(uint16 petEntry, uint16 aura, bool _removeOnChangePet, int _damage) :
548        removeOnChangePet(_removeOnChangePet), damage(_damage)
549        {
550            auras[petEntry] = aura;
551        }
552
553        uint16 GetAura(uint16 petEntry) const
554        {
555            std::map<uint16, uint16>::const_iterator itr = auras.find(petEntry);
556            if(itr != auras.end())
557                return itr->second;
558            else
559            {
560                std::map<uint16, uint16>::const_iterator itr = auras.find(0);
561                if(itr != auras.end())
562                    return itr->second;
563                else
564                    return 0;
565            }
566        }
567
568        void AddAura(uint16 petEntry, uint16 aura)
569        {
570            auras[petEntry] = aura;
571        }
572
573        bool IsRemovedOnChangePet() const
574        {
575            return removeOnChangePet;
576        }
577
578        int32 GetDamage() const
579        {
580            return damage;
581        }
582
583    private:
584        std::map<uint16, uint16> auras;
585        bool removeOnChangePet;
586        int32 damage;
587};
588typedef std::map<uint16, PetAura> SpellPetAuraMap;
589
590// Spell rank chain  (accessed using SpellMgr functions)
591struct SpellChainNode
592{
593    uint32 prev;
594    uint32 first;
595    uint32 req;
596    uint8  rank;
597};
598
599typedef UNORDERED_MAP<uint32, SpellChainNode> SpellChainMap;
600typedef std::multimap<uint32, uint32> SpellChainMapNext;
601
602// Spell learning properties (accessed using SpellMgr functions)
603struct SpellLearnSkillNode
604{
605    uint32 skill;
606    uint32 value;                                           // 0  - max skill value for player level
607    uint32 maxvalue;                                        // 0  - max skill value for player level
608};
609
610typedef std::map<uint32, SpellLearnSkillNode> SpellLearnSkillMap;
611
612struct SpellLearnSpellNode
613{
614    uint32 spell;
615    bool autoLearned;
616};
617
618typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
619
620typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
621
622inline bool IsPrimaryProfessionSkill(uint32 skill)
623{
624    SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill);
625    if(!pSkill)
626        return false;
627
628    if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
629        return false;
630
631    return true;
632}
633
634inline bool IsProfessionSkill(uint32 skill)
635{
636    return  IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
637}
638
639#define SPELL_ATTR_CU_PLAYERS_ONLY      0x00000001
640#define SPELL_ATTR_CU_CONE_BACK         0x00000002
641#define SPELL_ATTR_CU_CONE_LINE         0x00000004
642#define SPELL_ATTR_CU_SHARE_DAMAGE      0x00000008
643#define SPELL_ATTR_CU_EFFECT_HEAL       0x00000010
644#define SPELL_ATTR_CU_EFFECT_DAMAGE     0x00000020
645
646typedef std::map<uint32, uint32> SpellCustomAttrMap;
647
648typedef std::map<int32, std::vector<int32> > SpellLinkedMap;
649
650class SpellMgr
651{
652    // Constructors
653    public:
654        SpellMgr();
655        ~SpellMgr();
656
657        // Accessors (const or static functions)
658    public:
659        // Spell affects
660        uint64 GetSpellAffectMask(uint16 spellId, uint8 effectId) const
661        {
662            SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId);
663            if( itr != mSpellAffectMap.end( ) )
664                return itr->second;
665            return 0;
666        }
667
668        bool IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const;
669
670        SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }
671
672        uint32 GetSpellElixirMask(uint32 spellid) const
673        {
674            SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid);
675            if(itr==mSpellElixirs.end())
676                return 0x0;
677
678            return itr->second;
679        }
680
681        SpellSpecific GetSpellElixirSpecific(uint32 spellid) const
682        {
683            uint32 mask = GetSpellElixirMask(spellid);
684            if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK)
685                return SPELL_FLASK_ELIXIR;
686            else if(mask & ELIXIR_BATTLE_MASK)
687                return SPELL_BATTLE_ELIXIR;
688            else if(mask & ELIXIR_GUARDIAN_MASK)
689                return SPELL_GUARDIAN_ELIXIR;
690            else
691                return SPELL_NORMAL;
692        }
693
694        // Spell proc events
695        SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
696        {
697            SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
698            if( itr != mSpellProcEventMap.end( ) )
699                return &itr->second;
700            return NULL;
701        }
702
703        static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags );
704
705        // Spell target coordinates
706        SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const
707        {
708            SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id );
709            if( itr != mSpellTargetPositions.end( ) )
710                return &itr->second;
711            return NULL;
712        }
713
714        // Spell ranks chains
715        SpellChainNode const* GetSpellChainNode(uint32 spell_id) const
716        {
717            SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
718            if(itr == mSpellChains.end())
719                return NULL;
720
721            return &itr->second;
722        }
723
724        uint32 GetFirstSpellInChain(uint32 spell_id) const
725        {
726            if(SpellChainNode const* node = GetSpellChainNode(spell_id))
727                return node->first;
728
729            return spell_id;
730        }
731
732        uint32 GetPrevSpellInChain(uint32 spell_id) const
733        {
734            if(SpellChainNode const* node = GetSpellChainNode(spell_id))
735                return node->prev;
736
737            return 0;
738        }
739
740        SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; }
741
742        // Note: not use rank for compare to spell ranks: spell chains isn't linear order
743        // Use IsHighRankOfSpell instead
744        uint8 GetSpellRank(uint32 spell_id) const
745        {
746            if(SpellChainNode const* node = GetSpellChainNode(spell_id))
747                return node->rank;
748
749            return 0;
750        }
751
752        uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const
753        {
754            SpellChainMap::const_iterator itr = mSpellChains.find(spell1);
755
756            uint32 rank2 = GetSpellRank(spell2);
757
758            // not ordered correctly by rank value
759            if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2)
760                return false;
761
762            // check present in same rank chain
763            for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev))
764                if(itr->second.prev==spell2)
765                    return true;
766
767            return false;
768        }
769
770        bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const;
771        static bool canStackSpellRanks(SpellEntry const *spellInfo);
772        bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2, bool isFromTheSameCaster ) const;
773
774        SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const;
775
776        // Spell learning
777        SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const
778        {
779            SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id);
780            if(itr != mSpellLearnSkills.end())
781                return &itr->second;
782            else
783                return NULL;
784        }
785
786        bool IsSpellLearnSpell(uint32 spell_id) const
787        {
788            return mSpellLearnSpells.count(spell_id)!=0;
789        }
790
791        SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const
792        {
793            return mSpellLearnSpells.lower_bound(spell_id);
794        }
795
796        SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const
797        {
798            return mSpellLearnSpells.upper_bound(spell_id);
799        }
800
801        bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const
802        {
803            SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1);
804            SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1);
805            for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i)
806                if(i->second.spell==spell_id2)
807                    return true;
808            return false;
809        }
810
811        static bool IsProfessionSpell(uint32 spellId);
812        static bool IsPrimaryProfessionSpell(uint32 spellId);
813        bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const;
814
815        // Spell script targets
816        SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const
817        {
818            return mSpellScriptTarget.lower_bound(spell_id);
819        }
820
821        SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const
822        {
823            return mSpellScriptTarget.upper_bound(spell_id);
824        }
825
826        // Spell correctess for client using
827        static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true);
828
829        SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const
830        {
831            return mSkillLineAbilityMap.lower_bound(spell_id);
832        }
833
834        SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const
835        {
836            return mSkillLineAbilityMap.upper_bound(spell_id);
837        }
838
839        PetAura const* GetPetAura(uint16 spell_id)
840        {
841            SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find(spell_id);
842            if(itr != mSpellPetAuraMap.end())
843                return &itr->second;
844            else
845                return NULL;
846        }
847
848        uint32 GetSpellCustomAttr(uint32 spell_id) const
849        {
850            SpellCustomAttrMap::const_iterator itr = mSpellCustomAttrMap.find(spell_id);
851            if(itr != mSpellCustomAttrMap.end())
852                return itr->second;
853            else
854                return 0;
855        }
856
857        const std::vector<int32> *GetSpellLinked(int32 spell_id) const
858        {
859            SpellLinkedMap::const_iterator itr = mSpellLinkedMap.find(spell_id);
860            return itr != mSpellLinkedMap.end() ? &(itr->second) : NULL;
861        }
862
863        // Modifiers
864    public:
865        static SpellMgr& Instance();
866
867        // Loading data at server startup
868        void LoadSpellChains();
869        void LoadSpellLearnSkills();
870        void LoadSpellLearnSpells();
871        void LoadSpellScriptTarget();
872        void LoadSpellAffects();
873        void LoadSpellElixirs();
874        void LoadSpellProcEvents();
875        void LoadSpellTargetPositions();
876        void LoadSpellThreats();
877        void LoadSkillLineAbilityMap();
878        void LoadSpellPetAuras();
879        void LoadSpellCustomAttr();
880        void LoadSpellLinked();
881
882    private:
883        SpellScriptTarget  mSpellScriptTarget;
884        SpellChainMap      mSpellChains;
885        SpellChainMapNext  mSpellChainsNext;
886        SpellLearnSkillMap mSpellLearnSkills;
887        SpellLearnSpellMap mSpellLearnSpells;
888        SpellTargetPositionMap mSpellTargetPositions;
889        SpellAffectMap     mSpellAffectMap;
890        SpellElixirMap     mSpellElixirs;
891        SpellProcEventMap  mSpellProcEventMap;
892        SkillLineAbilityMap mSkillLineAbilityMap;
893        SpellPetAuraMap     mSpellPetAuraMap;
894        SpellCustomAttrMap  mSpellCustomAttrMap;
895        SpellLinkedMap      mSpellLinkedMap;
896};
897
898#define spellmgr SpellMgr::Instance()
899#endif
Note: See TracBrowser for help on using the browser.