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

Revision 219, 35.2 kB (checked in by yumileroy, 17 years ago)

[svn] Update IsNoStackSpellDueToSpell?. This should fix the bug that some talent spell auras cannot stack. Patch provided by QAston.

Original author: megamage
Date: 2008-11-12 10:22:56-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
287bool 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 IsPassiveSpell(uint32 spellId);
305
306inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo)
307{
308    switch(spellInfo->Id)
309    {
310        case 40214:                                     // Dragonmaw Illusion
311        case 35480: case 35481: case 35482:             // Human Illusion
312        case 35483: case 39824:                         // Human Illusion
313            return true;
314    }
315
316    return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT;
317}
318
319inline bool IsNonCombatSpell(SpellEntry const *spellInfo)
320{
321    return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0;
322}
323
324bool IsPositiveSpell(uint32 spellId);
325bool IsPositiveEffect(uint32 spellId, uint32 effIndex);
326bool IsPositiveTarget(uint32 targetA, uint32 targetB);
327
328bool IsSingleTargetSpell(SpellEntry const *spellInfo);
329bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);
330
331bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id);
332
333inline bool IsAreaEffectTarget( Targets target )
334{
335    switch (target )
336    {
337        case TARGET_AREAEFFECT_CUSTOM:
338        case TARGET_ALL_ENEMY_IN_AREA:
339        case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
340        case TARGET_ALL_PARTY_AROUND_CASTER:
341        case TARGET_ALL_AROUND_CASTER:
342        case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
343        case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
344        case TARGET_ALL_PARTY:
345        case TARGET_ALL_PARTY_AROUND_CASTER_2:
346        case TARGET_AREAEFFECT_PARTY:
347        case TARGET_AREAEFFECT_CUSTOM_2:
348        case TARGET_AREAEFFECT_PARTY_AND_CLASS:
349        case TARGET_IN_FRONT_OF_CASTER:
350        case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
351            return true;
352        default:
353            break;
354    }
355    return false;
356}
357
358inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo)
359{
360    if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0])))
361        return true;
362    if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1])))
363        return true;
364    if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2])))
365        return true;
366    return false;
367}
368
369inline bool IsAreaAuraEffect(uint32 effect)
370{
371    if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY    ||
372        effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND   ||
373        effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY    ||
374        effect == SPELL_EFFECT_APPLY_AREA_AURA_PET      ||
375        effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER)
376        return true;
377    return false;
378}
379
380inline bool IsDispelSpell(SpellEntry const *spellInfo)
381{
382    if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL ||
383        spellInfo->Effect[1] == SPELL_EFFECT_DISPEL ||
384        spellInfo->Effect[2] == SPELL_EFFECT_DISPEL )
385        return true;
386    return false;
387}
388inline bool isSpellBreakStealth(SpellEntry const* spellInfo)
389{
390    return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH);
391}
392
393uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form);
394
395inline bool IsChanneledSpell(SpellEntry const* spellInfo)
396{
397    return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2));
398}
399
400inline bool NeedsComboPoints(SpellEntry const* spellInfo)
401{
402    return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2));
403}
404
405inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo)
406{
407    return SpellSchoolMask(spellInfo->SchoolMask);
408}
409
410inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect)
411{
412    uint32 mask = 0;
413    if (spellInfo->Mechanic)
414        mask |= 1<<spellInfo->Mechanic;
415    if (spellInfo->EffectMechanic[effect])
416        mask |= 1<<spellInfo->EffectMechanic[effect];
417    return mask;
418}
419
420inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect)
421{
422    if (spellInfo->EffectMechanic[effect])
423        return Mechanics(spellInfo->EffectMechanic[effect]);
424    if (spellInfo->Mechanic)
425        return Mechanics(spellInfo->Mechanic);
426    return MECHANIC_NONE;
427}
428
429inline uint32 GetDispellMask(DispelType dispel)
430{
431    // If dispell all
432    if (dispel == DISPEL_ALL)
433        return DISPEL_ALL_MASK;
434    else
435        return (1 << dispel);
436}
437
438// Diminishing Returns interaction with spells
439DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered);
440bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
441DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group);
442
443// Spell affects related declarations (accessed using SpellMgr functions)
444typedef std::map<uint32, uint64> SpellAffectMap;
445
446// Spell proc event related declarations (accessed using SpellMgr functions)
447enum ProcFlags
448{
449    PROC_FLAG_NONE                  = 0x00000000,           // None
450    PROC_FLAG_HIT_MELEE             = 0x00000001,           // On melee hit
451    PROC_FLAG_STRUCK_MELEE          = 0x00000002,           // On being struck melee
452    PROC_FLAG_KILL_XP_GIVER         = 0x00000004,           // On kill target giving XP or honor
453    PROC_FLAG_SPECIAL_DROP          = 0x00000008,           //
454    PROC_FLAG_DODGE                 = 0x00000010,           // On dodge melee attack
455    PROC_FLAG_PARRY                 = 0x00000020,           // On parry melee attack
456    PROC_FLAG_BLOCK                 = 0x00000040,           // On block attack
457    PROC_FLAG_TOUCH                 = 0x00000080,           // On being touched (for bombs, probably?)
458    PROC_FLAG_TARGET_LOW_HEALTH     = 0x00000100,           // On deal damage to enemy with 20% or less health
459    PROC_FLAG_LOW_HEALTH            = 0x00000200,           // On health dropped below 20%
460    PROC_FLAG_STRUCK_RANGED         = 0x00000400,           // On being struck ranged
461    PROC_FLAG_HIT_SPECIAL           = 0x00000800,           // (!)Removed, may be reassigned in future
462    PROC_FLAG_CRIT_MELEE            = 0x00001000,           // On crit melee
463    PROC_FLAG_STRUCK_CRIT_MELEE     = 0x00002000,           // On being critically struck in melee
464    PROC_FLAG_CAST_SPELL            = 0x00004000,           // On cast spell
465    PROC_FLAG_TAKE_DAMAGE           = 0x00008000,           // On take damage
466    PROC_FLAG_CRIT_SPELL            = 0x00010000,           // On crit spell
467    PROC_FLAG_HIT_SPELL             = 0x00020000,           // On hit spell
468    PROC_FLAG_STRUCK_CRIT_SPELL     = 0x00040000,           // On being critically struck by a spell
469    PROC_FLAG_HIT_RANGED            = 0x00080000,           // On getting ranged hit
470    PROC_FLAG_STRUCK_SPELL          = 0x00100000,           // On being struck by a spell
471    PROC_FLAG_TRAP                  = 0x00200000,           // On trap activation (?)
472    PROC_FLAG_CRIT_RANGED           = 0x00400000,           // On getting ranged crit
473    PROC_FLAG_STRUCK_CRIT_RANGED    = 0x00800000,           // On being critically struck by a ranged attack
474    PROC_FLAG_RESIST_SPELL          = 0x01000000,           // On resist enemy spell
475    PROC_FLAG_TARGET_RESISTS        = 0x02000000,           // On enemy resisted spell
476    PROC_FLAG_TARGET_DODGE_OR_PARRY = 0x04000000,           // On enemy dodges/parries
477    PROC_FLAG_HEAL                  = 0x08000000,           // On heal
478    PROC_FLAG_CRIT_HEAL             = 0x10000000,           // On critical healing effect
479    PROC_FLAG_HEALED                = 0x20000000,           // On healing
480    PROC_FLAG_TARGET_BLOCK          = 0x40000000,           // On enemy blocks
481    PROC_FLAG_MISS                  = 0x80000000            // On miss melee attack
482};
483
484struct SpellProcEventEntry
485{
486    uint32      schoolMask;                                 // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2
487    uint32      category;                                   // if nonzero - match proc condition based on candidate spell's category
488    uint32      skillId;                                    // if nonzero - for matching proc condition based on candidate spell's skillId from SkillLineAbility.dbc (Shadow Bolt = Destruction)
489    uint32      spellFamilyName;                            // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value
490    uint64      spellFamilyMask;                            // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do)
491    uint32      procFlags;                                  // bitmask for matching proc event
492    float       ppmRate;                                    // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc
493    uint32      cooldown;                                   // hidden cooldown used for some spell proc events, applied to _triggered_spell_
494};
495
496typedef UNORDERED_MAP<uint32, SpellProcEventEntry> SpellProcEventMap;
497
498#define ELIXIR_BATTLE_MASK    0x1
499#define ELIXIR_GUARDIAN_MASK  0x2
500#define ELIXIR_FLASK_MASK     (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK)
501#define ELIXIR_UNSTABLE_MASK  0x4
502#define ELIXIR_SHATTRATH_MASK 0x8
503
504typedef std::map<uint32, uint8> SpellElixirMap;
505
506// Spell script target related declarations (accessed using SpellMgr functions)
507enum SpellTargetType
508{
509    SPELL_TARGET_TYPE_GAMEOBJECT = 0,
510    SPELL_TARGET_TYPE_CREATURE   = 1,
511    SPELL_TARGET_TYPE_DEAD       = 2
512};
513
514#define MAX_SPELL_TARGET_TYPE 3
515
516struct SpellTargetEntry
517{
518    SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {}
519    SpellTargetType type;
520    uint32 targetEntry;
521};
522
523typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
524
525// coordinates for spells (accessed using SpellMgr functions)
526struct SpellTargetPosition
527{
528    uint32 target_mapId;
529    float  target_X;
530    float  target_Y;
531    float  target_Z;
532    float  target_Orientation;
533};
534
535typedef UNORDERED_MAP<uint32, SpellTargetPosition> SpellTargetPositionMap;
536
537// Spell pet auras
538class PetAura
539{
540    public:
541        PetAura()
542        {
543            auras.clear();
544        }
545
546        PetAura(uint16 petEntry, uint16 aura, bool _removeOnChangePet, int _damage) :
547        removeOnChangePet(_removeOnChangePet), damage(_damage)
548        {
549            auras[petEntry] = aura;
550        }
551
552        uint16 GetAura(uint16 petEntry) const
553        {
554            std::map<uint16, uint16>::const_iterator itr = auras.find(petEntry);
555            if(itr != auras.end())
556                return itr->second;
557            else
558            {
559                std::map<uint16, uint16>::const_iterator itr = auras.find(0);
560                if(itr != auras.end())
561                    return itr->second;
562                else
563                    return 0;
564            }
565        }
566
567        void AddAura(uint16 petEntry, uint16 aura)
568        {
569            auras[petEntry] = aura;
570        }
571
572        bool IsRemovedOnChangePet() const
573        {
574            return removeOnChangePet;
575        }
576
577        int32 GetDamage() const
578        {
579            return damage;
580        }
581
582    private:
583        std::map<uint16, uint16> auras;
584        bool removeOnChangePet;
585        int32 damage;
586};
587typedef std::map<uint16, PetAura> SpellPetAuraMap;
588
589// Spell rank chain  (accessed using SpellMgr functions)
590struct SpellChainNode
591{
592    uint32 prev;
593    uint32 first;
594    uint32 req;
595    uint8  rank;
596};
597
598typedef UNORDERED_MAP<uint32, SpellChainNode> SpellChainMap;
599typedef std::multimap<uint32, uint32> SpellChainMapNext;
600
601// Spell learning properties (accessed using SpellMgr functions)
602struct SpellLearnSkillNode
603{
604    uint32 skill;
605    uint32 value;                                           // 0  - max skill value for player level
606    uint32 maxvalue;                                        // 0  - max skill value for player level
607};
608
609typedef std::map<uint32, SpellLearnSkillNode> SpellLearnSkillMap;
610
611struct SpellLearnSpellNode
612{
613    uint32 spell;
614    bool autoLearned;
615};
616
617typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
618
619typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
620
621inline bool IsPrimaryProfessionSkill(uint32 skill)
622{
623    SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill);
624    if(!pSkill)
625        return false;
626
627    if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
628        return false;
629
630    return true;
631}
632
633inline bool IsProfessionSkill(uint32 skill)
634{
635    return  IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
636}
637
638#define SPELL_ATTR_CU_PLAYERS_ONLY      0x00000001
639#define SPELL_ATTR_CU_CONE_BACK         0x00000002
640#define SPELL_ATTR_CU_CONE_LINE         0x00000004
641#define SPELL_ATTR_CU_SHARE_DAMAGE      0x00000008
642#define SPELL_ATTR_CU_EFFECT_HEAL       0x00000010
643#define SPELL_ATTR_CU_EFFECT_DAMAGE     0x00000020
644
645typedef std::map<uint32, uint32> SpellCustomAttrMap;
646
647typedef std::map<int32, std::vector<int32> > SpellLinkedMap;
648
649class SpellMgr
650{
651    // Constructors
652    public:
653        SpellMgr();
654        ~SpellMgr();
655
656        // Accessors (const or static functions)
657    public:
658        // Spell affects
659        uint64 GetSpellAffectMask(uint16 spellId, uint8 effectId) const
660        {
661            SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId);
662            if( itr != mSpellAffectMap.end( ) )
663                return itr->second;
664            return 0;
665        }
666
667        bool IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const;
668
669        SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }
670
671        uint32 GetSpellElixirMask(uint32 spellid) const
672        {
673            SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid);
674            if(itr==mSpellElixirs.end())
675                return 0x0;
676
677            return itr->second;
678        }
679
680        SpellSpecific GetSpellElixirSpecific(uint32 spellid) const
681        {
682            uint32 mask = GetSpellElixirMask(spellid);
683            if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK)
684                return SPELL_FLASK_ELIXIR;
685            else if(mask & ELIXIR_BATTLE_MASK)
686                return SPELL_BATTLE_ELIXIR;
687            else if(mask & ELIXIR_GUARDIAN_MASK)
688                return SPELL_GUARDIAN_ELIXIR;
689            else
690                return SPELL_NORMAL;
691        }
692
693        // Spell proc events
694        SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
695        {
696            SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
697            if( itr != mSpellProcEventMap.end( ) )
698                return &itr->second;
699            return NULL;
700        }
701
702        static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags );
703
704        // Spell target coordinates
705        SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const
706        {
707            SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id );
708            if( itr != mSpellTargetPositions.end( ) )
709                return &itr->second;
710            return NULL;
711        }
712
713        // Spell ranks chains
714        SpellChainNode const* GetSpellChainNode(uint32 spell_id) const
715        {
716            SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
717            if(itr == mSpellChains.end())
718                return NULL;
719
720            return &itr->second;
721        }
722
723        uint32 GetFirstSpellInChain(uint32 spell_id) const
724        {
725            if(SpellChainNode const* node = GetSpellChainNode(spell_id))
726                return node->first;
727
728            return spell_id;
729        }
730
731        uint32 GetPrevSpellInChain(uint32 spell_id) const
732        {
733            if(SpellChainNode const* node = GetSpellChainNode(spell_id))
734                return node->prev;
735
736            return 0;
737        }
738
739        SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; }
740
741        // Note: not use rank for compare to spell ranks: spell chains isn't linear order
742        // Use IsHighRankOfSpell instead
743        uint8 GetSpellRank(uint32 spell_id) const
744        {
745            if(SpellChainNode const* node = GetSpellChainNode(spell_id))
746                return node->rank;
747
748            return 0;
749        }
750
751        uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const
752        {
753            SpellChainMap::const_iterator itr = mSpellChains.find(spell1);
754
755            uint32 rank2 = GetSpellRank(spell2);
756
757            // not ordered correctly by rank value
758            if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2)
759                return false;
760
761            // check present in same rank chain
762            for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev))
763                if(itr->second.prev==spell2)
764                    return true;
765
766            return false;
767        }
768
769        bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const;
770        static bool canStackSpellRanks(SpellEntry const *spellInfo);
771        bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const;
772
773        SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const;
774
775        // Spell learning
776        SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const
777        {
778            SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id);
779            if(itr != mSpellLearnSkills.end())
780                return &itr->second;
781            else
782                return NULL;
783        }
784
785        bool IsSpellLearnSpell(uint32 spell_id) const
786        {
787            return mSpellLearnSpells.count(spell_id)!=0;
788        }
789
790        SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const
791        {
792            return mSpellLearnSpells.lower_bound(spell_id);
793        }
794
795        SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const
796        {
797            return mSpellLearnSpells.upper_bound(spell_id);
798        }
799
800        bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const
801        {
802            SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1);
803            SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1);
804            for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i)
805                if(i->second.spell==spell_id2)
806                    return true;
807            return false;
808        }
809
810        static bool IsProfessionSpell(uint32 spellId);
811        static bool IsPrimaryProfessionSpell(uint32 spellId);
812        bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const;
813
814        // Spell script targets
815        SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const
816        {
817            return mSpellScriptTarget.lower_bound(spell_id);
818        }
819
820        SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const
821        {
822            return mSpellScriptTarget.upper_bound(spell_id);
823        }
824
825        // Spell correctess for client using
826        static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true);
827
828        SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const
829        {
830            return mSkillLineAbilityMap.lower_bound(spell_id);
831        }
832
833        SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const
834        {
835            return mSkillLineAbilityMap.upper_bound(spell_id);
836        }
837
838        PetAura const* GetPetAura(uint16 spell_id)
839        {
840            SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find(spell_id);
841            if(itr != mSpellPetAuraMap.end())
842                return &itr->second;
843            else
844                return NULL;
845        }
846
847        uint32 GetSpellCustomAttr(uint32 spell_id) const
848        {
849            SpellCustomAttrMap::const_iterator itr = mSpellCustomAttrMap.find(spell_id);
850            if(itr != mSpellCustomAttrMap.end())
851                return itr->second;
852            else
853                return 0;
854        }
855
856        const std::vector<int32> *GetSpellLinked(int32 spell_id) const
857        {
858            SpellLinkedMap::const_iterator itr = mSpellLinkedMap.find(spell_id);
859            return itr != mSpellLinkedMap.end() ? &(itr->second) : NULL;
860        }
861
862        // Modifiers
863    public:
864        static SpellMgr& Instance();
865
866        // Loading data at server startup
867        void LoadSpellChains();
868        void LoadSpellLearnSkills();
869        void LoadSpellLearnSpells();
870        void LoadSpellScriptTarget();
871        void LoadSpellAffects();
872        void LoadSpellElixirs();
873        void LoadSpellProcEvents();
874        void LoadSpellTargetPositions();
875        void LoadSpellThreats();
876        void LoadSkillLineAbilityMap();
877        void LoadSpellPetAuras();
878        void LoadSpellCustomAttr();
879        void LoadSpellLinked();
880
881    private:
882        SpellScriptTarget  mSpellScriptTarget;
883        SpellChainMap      mSpellChains;
884        SpellChainMapNext  mSpellChainsNext;
885        SpellLearnSkillMap mSpellLearnSkills;
886        SpellLearnSpellMap mSpellLearnSpells;
887        SpellTargetPositionMap mSpellTargetPositions;
888        SpellAffectMap     mSpellAffectMap;
889        SpellElixirMap     mSpellElixirs;
890        SpellProcEventMap  mSpellProcEventMap;
891        SkillLineAbilityMap mSkillLineAbilityMap;
892        SpellPetAuraMap     mSpellPetAuraMap;
893        SpellCustomAttrMap  mSpellCustomAttrMap;
894        SpellLinkedMap      mSpellLinkedMap;
895};
896
897#define spellmgr SpellMgr::Instance()
898#endif
Note: See TracBrowser for help on using the browser.