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

Revision 44, 34.0 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge Temp dev SVN with Assembla.
* Changes include:

  • Implementation of w12x's Outdoor PvP and Game Event Systems.
  • Temporary removal of IRC Chat Bot (until infinite loop when disabled is fixed).
  • All mangos -> trinity (to convert your mangos_string table, please run mangos_string_to_trinity_string.sql).
  • Improved Config cleanup.
  • And many more changes.

Original author: Seline
Date: 2008-10-14 11:57:03-05:00

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