[6982] Implemented gmlevel-based command security
[getmangos.git] / src / game / SpellMgr.h
blobc5d005b98193e6063f5509d99a362a5a646ecefc
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _SPELLMGR_H
20 #define _SPELLMGR_H
22 // For static or at-server-startup loaded spell data
23 // For more high level function for sSpellStore data
25 #include "SharedDefines.h"
26 #include "Database/DBCStructure.h"
27 #include "Database/SQLStorage.h"
29 #include "Utilities/UnorderedMap.h"
31 #include "Player.h"
33 #include <map>
35 class Player;
36 class Spell;
38 extern SQLStorage sSpellThreatStore;
40 enum SpellFailedReason
42 SPELL_FAILED_AFFECTING_COMBAT = 0,
43 SPELL_FAILED_ALREADY_AT_FULL_HEALTH = 1,
44 SPELL_FAILED_ALREADY_AT_FULL_MANA = 2,
45 SPELL_FAILED_ALREADY_AT_FULL_POWER = 3,
46 SPELL_FAILED_ALREADY_BEING_TAMED = 4,
47 SPELL_FAILED_ALREADY_HAVE_CHARM = 5,
48 SPELL_FAILED_ALREADY_HAVE_SUMMON = 6,
49 SPELL_FAILED_ALREADY_OPEN = 7,
50 SPELL_FAILED_AURA_BOUNCED = 8,
51 SPELL_FAILED_AUTOTRACK_INTERRUPTED = 9,
52 SPELL_FAILED_BAD_IMPLICIT_TARGETS = 10,
53 SPELL_FAILED_BAD_TARGETS = 11,
54 SPELL_FAILED_CANT_BE_CHARMED = 12,
55 SPELL_FAILED_CANT_BE_DISENCHANTED = 13,
56 SPELL_FAILED_CANT_BE_DISENCHANTED_SKILL = 14,
57 SPELL_FAILED_CANT_BE_MILLED = 15,
58 SPELL_FAILED_CANT_BE_PROSPECTED = 16,
59 SPELL_FAILED_CANT_CAST_ON_TAPPED = 17,
60 SPELL_FAILED_CANT_DUEL_WHILE_INVISIBLE = 18,
61 SPELL_FAILED_CANT_DUEL_WHILE_STEALTHED = 19,
62 SPELL_FAILED_CANT_STEALTH = 20,
63 SPELL_FAILED_CASTER_AURASTATE = 21,
64 SPELL_FAILED_CASTER_DEAD = 22,
65 SPELL_FAILED_CHARMED = 23,
66 SPELL_FAILED_CHEST_IN_USE = 24,
67 SPELL_FAILED_CONFUSED = 25,
68 SPELL_FAILED_DONT_REPORT = 26,
69 SPELL_FAILED_EQUIPPED_ITEM = 27,
70 SPELL_FAILED_EQUIPPED_ITEM_CLASS = 28,
71 SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND = 29,
72 SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND = 30,
73 SPELL_FAILED_ERROR = 31,
74 SPELL_FAILED_FIZZLE = 32,
75 SPELL_FAILED_FLEEING = 33,
76 SPELL_FAILED_FOOD_LOWLEVEL = 34,
77 SPELL_FAILED_HIGHLEVEL = 35,
78 SPELL_FAILED_HUNGER_SATIATED = 36,
79 SPELL_FAILED_IMMUNE = 37,
80 SPELL_FAILED_INCORRECT_AREA = 38,
81 SPELL_FAILED_INTERRUPTED = 39,
82 SPELL_FAILED_INTERRUPTED_COMBAT = 40,
83 SPELL_FAILED_ITEM_ALREADY_ENCHANTED = 41,
84 SPELL_FAILED_ITEM_GONE = 42,
85 SPELL_FAILED_ITEM_NOT_FOUND = 43,
86 SPELL_FAILED_ITEM_NOT_READY = 44,
87 SPELL_FAILED_LEVEL_REQUIREMENT = 45,
88 SPELL_FAILED_LINE_OF_SIGHT = 46,
89 SPELL_FAILED_LOWLEVEL = 47,
90 SPELL_FAILED_LOW_CASTLEVEL = 48,
91 SPELL_FAILED_MAINHAND_EMPTY = 49,
92 SPELL_FAILED_MOVING = 50,
93 SPELL_FAILED_NEED_AMMO = 51,
94 SPELL_FAILED_NEED_AMMO_POUCH = 52,
95 SPELL_FAILED_NEED_EXOTIC_AMMO = 53,
96 SPELL_FAILED_NEED_MORE_ITEMS = 54,
97 SPELL_FAILED_NOPATH = 55,
98 SPELL_FAILED_NOT_BEHIND = 56,
99 SPELL_FAILED_NOT_FISHABLE = 57,
100 SPELL_FAILED_NOT_FLYING = 58,
101 SPELL_FAILED_NOT_HERE = 59,
102 SPELL_FAILED_NOT_INFRONT = 60,
103 SPELL_FAILED_NOT_IN_CONTROL = 61,
104 SPELL_FAILED_NOT_KNOWN = 62,
105 SPELL_FAILED_NOT_MOUNTED = 63,
106 SPELL_FAILED_NOT_ON_TAXI = 64,
107 SPELL_FAILED_NOT_ON_TRANSPORT = 65,
108 SPELL_FAILED_NOT_READY = 66,
109 SPELL_FAILED_NOT_SHAPESHIFT = 67,
110 SPELL_FAILED_NOT_STANDING = 68,
111 SPELL_FAILED_NOT_TRADEABLE = 69,
112 SPELL_FAILED_NOT_TRADING = 70,
113 SPELL_FAILED_NOT_UNSHEATHED = 71,
114 SPELL_FAILED_NOT_WHILE_GHOST = 72,
115 SPELL_FAILED_NOT_WHILE_LOOTING = 73,
116 SPELL_FAILED_NO_AMMO = 74,
117 SPELL_FAILED_NO_CHARGES_REMAIN = 75,
118 SPELL_FAILED_NO_CHAMPION = 76,
119 SPELL_FAILED_NO_COMBO_POINTS = 77,
120 SPELL_FAILED_NO_DUELING = 78,
121 SPELL_FAILED_NO_ENDURANCE = 79,
122 SPELL_FAILED_NO_FISH = 80,
123 SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED = 81,
124 SPELL_FAILED_NO_MOUNTS_ALLOWED = 82,
125 SPELL_FAILED_NO_PET = 83,
126 SPELL_FAILED_NO_POWER = 84,
127 SPELL_FAILED_NOTHING_TO_DISPEL = 85,
128 SPELL_FAILED_NOTHING_TO_STEAL = 86,
129 SPELL_FAILED_ONLY_ABOVEWATER = 87,
130 SPELL_FAILED_ONLY_DAYTIME = 88,
131 SPELL_FAILED_ONLY_INDOORS = 89,
132 SPELL_FAILED_ONLY_MOUNTED = 90,
133 SPELL_FAILED_ONLY_NIGHTTIME = 91,
134 SPELL_FAILED_ONLY_OUTDOORS = 92,
135 SPELL_FAILED_ONLY_SHAPESHIFT = 93,
136 SPELL_FAILED_ONLY_STEALTHED = 94,
137 SPELL_FAILED_ONLY_UNDERWATER = 95,
138 SPELL_FAILED_OUT_OF_RANGE = 96,
139 SPELL_FAILED_PACIFIED = 97,
140 SPELL_FAILED_POSSESSED = 98,
141 SPELL_FAILED_REAGENTS = 99,
142 SPELL_FAILED_REQUIRES_AREA = 100,
143 SPELL_FAILED_REQUIRES_SPELL_FOCUS = 101,
144 SPELL_FAILED_ROOTED = 102,
145 SPELL_FAILED_SILENCED = 103,
146 SPELL_FAILED_SPELL_IN_PROGRESS = 104,
147 SPELL_FAILED_SPELL_LEARNED = 105,
148 SPELL_FAILED_SPELL_UNAVAILABLE = 106,
149 SPELL_FAILED_STUNNED = 107,
150 SPELL_FAILED_TARGETS_DEAD = 108,
151 SPELL_FAILED_TARGET_AFFECTING_COMBAT = 109,
152 SPELL_FAILED_TARGET_AURASTATE = 110,
153 SPELL_FAILED_TARGET_DUELING = 111,
154 SPELL_FAILED_TARGET_ENEMY = 112,
155 SPELL_FAILED_TARGET_ENRAGED = 113,
156 SPELL_FAILED_TARGET_FRIENDLY = 114,
157 SPELL_FAILED_TARGET_IN_COMBAT = 115,
158 SPELL_FAILED_TARGET_IS_PLAYER = 116,
159 SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED = 117,
160 SPELL_FAILED_TARGET_NOT_DEAD = 118,
161 SPELL_FAILED_TARGET_NOT_IN_PARTY = 119,
162 SPELL_FAILED_TARGET_NOT_LOOTED = 120,
163 SPELL_FAILED_TARGET_NOT_PLAYER = 121,
164 SPELL_FAILED_TARGET_NO_POCKETS = 122,
165 SPELL_FAILED_TARGET_NO_WEAPONS = 123,
166 SPELL_FAILED_TARGET_NO_RANGED_WEAPONS = 124,
167 SPELL_FAILED_TARGET_UNSKINNABLE = 125,
168 SPELL_FAILED_THIRST_SATIATED = 126,
169 SPELL_FAILED_TOO_CLOSE = 127,
170 SPELL_FAILED_TOO_MANY_OF_ITEM = 128,
171 SPELL_FAILED_TOTEM_CATEGORY = 129,
172 SPELL_FAILED_TOTEMS = 130,
173 SPELL_FAILED_TRY_AGAIN = 131,
174 SPELL_FAILED_UNIT_NOT_BEHIND = 132,
175 SPELL_FAILED_UNIT_NOT_INFRONT = 133,
176 SPELL_FAILED_WRONG_PET_FOOD = 134,
177 SPELL_FAILED_NOT_WHILE_FATIGUED = 135,
178 SPELL_FAILED_TARGET_NOT_IN_INSTANCE = 136,
179 SPELL_FAILED_NOT_WHILE_TRADING = 137,
180 SPELL_FAILED_TARGET_NOT_IN_RAID = 138,
181 SPELL_FAILED_TARGET_FREEFORALL = 139,
182 SPELL_FAILED_NO_EDIBLE_CORPSES = 140,
183 SPELL_FAILED_ONLY_BATTLEGROUNDS = 141,
184 SPELL_FAILED_TARGET_NOT_GHOST = 142,
185 SPELL_FAILED_TRANSFORM_UNUSABLE = 143,
186 SPELL_FAILED_WRONG_WEATHER = 144,
187 SPELL_FAILED_DAMAGE_IMMUNE = 145,
188 SPELL_FAILED_PREVENTED_BY_MECHANIC = 146,
189 SPELL_FAILED_PLAY_TIME = 147,
190 SPELL_FAILED_REPUTATION = 148,
191 SPELL_FAILED_MIN_SKILL = 149,
192 SPELL_FAILED_NOT_IN_ARENA = 150,
193 SPELL_FAILED_NOT_ON_SHAPESHIFT = 151,
194 SPELL_FAILED_NOT_ON_STEALTHED = 152,
195 SPELL_FAILED_NOT_ON_DAMAGE_IMMUNE = 153,
196 SPELL_FAILED_NOT_ON_MOUNTED = 154,
197 SPELL_FAILED_TOO_SHALLOW = 155,
198 SPELL_FAILED_TARGET_NOT_IN_SANCTUARY = 156,
199 SPELL_FAILED_TARGET_IS_TRIVIAL = 157,
200 SPELL_FAILED_BM_OR_INVISGOD = 158,
201 SPELL_FAILED_EXPERT_RIDING_REQUIREMENT = 159,
202 SPELL_FAILED_ARTISAN_RIDING_REQUIREMENT = 160,
203 SPELL_FAILED_NOT_IDLE = 161,
204 SPELL_FAILED_NOT_INACTIVE = 162,
205 SPELL_FAILED_PARTIAL_PLAYTIME = 163,
206 SPELL_FAILED_NO_PLAYTIME = 164,
207 SPELL_FAILED_NOT_IN_BATTLEGROUND = 165,
208 SPELL_FAILED_NOT_IN_RAID_INSTANCE = 166,
209 SPELL_FAILED_ONLY_IN_ARENA = 167,
210 SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE = 168,
211 SPELL_FAILED_ON_USE_ENCHANT = 169,
212 SPELL_FAILED_NOT_ON_GROUND = 170,
213 SPELL_FAILED_CUSTOM_ERROR = 171,
214 SPELL_FAILED_CANT_DO_THAT_RIGHT_NOW = 172,
215 SPELL_FAILED_TOO_MANY_SOCKETS = 173,
216 SPELL_FAILED_INVALID_GLYPH = 174,
217 SPELL_FAILED_UNIQUE_GLYPH = 175,
218 SPELL_FAILED_GLYPH_SOCKET_LOCKED = 176,
219 SPELL_FAILED_NO_VALID_TARGETS = 177,
220 SPELL_FAILED_ITEM_AT_MAX_CHARGES = 178,
221 SPELL_FAILED_NOT_IN_BARBERSHOP = 179,
222 SPELL_FAILED_FISHING_TOO_LOW = 180,
223 SPELL_FAILED_UNKNOWN = 181
226 enum SpellFamilyNames
228 SPELLFAMILY_GENERIC = 0,
229 SPELLFAMILY_UNK1 = 1, // events, holidays
230 // 2 - unused
231 SPELLFAMILY_MAGE = 3,
232 SPELLFAMILY_WARRIOR = 4,
233 SPELLFAMILY_WARLOCK = 5,
234 SPELLFAMILY_PRIEST = 6,
235 SPELLFAMILY_DRUID = 7,
236 SPELLFAMILY_ROGUE = 8,
237 SPELLFAMILY_HUNTER = 9,
238 SPELLFAMILY_PALADIN = 10,
239 SPELLFAMILY_SHAMAN = 11,
240 SPELLFAMILY_UNK2 = 12, // 2 spells (silence resistance)
241 SPELLFAMILY_POTION = 13,
242 // 14 - unused
243 SPELLFAMILY_DEATHKNIGHT = 15,
244 // 16 - unused
245 SPELLFAMILY_PET = 17
248 //Some SpellFamilyFlags
249 #define SPELLFAMILYFLAG_ROGUE_VANISH 0x000000800LL
250 #define SPELLFAMILYFLAG_ROGUE_STEALTH 0x000400000LL
251 #define SPELLFAMILYFLAG_ROGUE_BACKSTAB 0x000800004LL
252 #define SPELLFAMILYFLAG_ROGUE_SAP 0x000000080LL
253 #define SPELLFAMILYFLAG_ROGUE_FEINT 0x008000000LL
254 #define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT 0x000200000LL
255 #define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE 0x9003E0000LL
257 // Spell clasification
258 enum SpellSpecific
260 SPELL_NORMAL = 0,
261 SPELL_SEAL = 1,
262 SPELL_BLESSING = 2,
263 SPELL_AURA = 3,
264 SPELL_STING = 4,
265 SPELL_CURSE = 5,
266 SPELL_ASPECT = 6,
267 SPELL_TRACKER = 7,
268 SPELL_WARLOCK_ARMOR = 8,
269 SPELL_MAGE_ARMOR = 9,
270 SPELL_ELEMENTAL_SHIELD = 10,
271 SPELL_MAGE_POLYMORPH = 11,
272 SPELL_POSITIVE_SHOUT = 12,
273 SPELL_JUDGEMENT = 13,
274 SPELL_BATTLE_ELIXIR = 14,
275 SPELL_GUARDIAN_ELIXIR = 15,
276 SPELL_FLASK_ELIXIR = 16,
277 SPELL_PRESENCE = 17
280 SpellSpecific GetSpellSpecific(uint32 spellId);
282 // Different spell properties
283 inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); }
284 uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL);
285 inline float GetSpellMinRange(SpellRangeEntry const *range) { return (range ? range->minRange : 0); }
286 inline float GetSpellMaxRange(SpellRangeEntry const *range) { return (range ? range->maxRange : 0); }
287 inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; }
288 int32 GetSpellDuration(SpellEntry const *spellInfo);
289 int32 GetSpellMaxDuration(SpellEntry const *spellInfo);
291 inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
293 for(int i= 0; i < 3; ++i)
294 if(spellInfo->Effect[i]==effect)
295 return true;
296 return false;
299 bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
301 inline bool IsSealSpell(SpellEntry const *spellInfo)
303 //Collection of all the seal family flags. No other paladin spell has any of those.
304 return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN &&
305 ( spellInfo->SpellFamilyFlags & 0x26000C000A000000LL );
308 inline bool IsElementalShield(SpellEntry const *spellInfo)
310 // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus
311 return (spellInfo->SpellFamilyFlags & 0x42000000400LL) || spellInfo->Id == 23552;
314 int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
315 bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2);
316 bool IsPassiveSpell(uint32 spellId);
318 inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo)
320 switch(spellInfo->Id)
322 case 40214: // Dragonmaw Illusion
323 case 35480: case 35481: case 35482: // Human Illusion
324 case 35483: case 39824: // Human Illusion
325 return true;
328 return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT;
331 inline bool IsNonCombatSpell(SpellEntry const *spellInfo)
333 return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0;
336 bool IsPositiveSpell(uint32 spellId);
337 bool IsPositiveEffect(uint32 spellId, uint32 effIndex);
338 bool IsPositiveTarget(uint32 targetA, uint32 targetB);
340 bool IsSingleTargetSpell(SpellEntry const *spellInfo);
341 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);
343 bool IsAuraAddedBySpell(uint32 auraType, uint32 spellId);
345 bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id);
347 inline bool IsAreaEffectTarget( Targets target )
349 switch (target )
351 case TARGET_AREAEFFECT_CUSTOM:
352 case TARGET_ALL_ENEMY_IN_AREA:
353 case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
354 case TARGET_ALL_PARTY_AROUND_CASTER:
355 case TARGET_ALL_AROUND_CASTER:
356 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
357 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
358 case TARGET_ALL_PARTY:
359 case TARGET_ALL_PARTY_AROUND_CASTER_2:
360 case TARGET_AREAEFFECT_PARTY:
361 case TARGET_AREAEFFECT_CUSTOM_2:
362 case TARGET_AREAEFFECT_PARTY_AND_CLASS:
363 case TARGET_IN_FRONT_OF_CASTER:
364 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
365 return true;
366 default:
367 break;
369 return false;
372 inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo)
374 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0])))
375 return true;
376 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1])))
377 return true;
378 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2])))
379 return true;
380 return false;
383 inline bool IsAreaAuraEffect(uint32 effect)
385 if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
386 effect == SPELL_EFFECT_APPLY_AREA_AURA_RAID ||
387 effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND ||
388 effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY ||
389 effect == SPELL_EFFECT_APPLY_AREA_AURA_PET ||
390 effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER)
391 return true;
392 return false;
395 inline bool IsDispelSpell(SpellEntry const *spellInfo)
397 if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL ||
398 spellInfo->Effect[1] == SPELL_EFFECT_DISPEL ||
399 spellInfo->Effect[2] == SPELL_EFFECT_DISPEL )
400 return true;
401 return false;
403 inline bool isSpellBreakStealth(SpellEntry const* spellInfo)
405 return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH);
408 uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form);
410 inline bool IsChanneledSpell(SpellEntry const* spellInfo)
412 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2));
415 inline bool NeedsComboPoints(SpellEntry const* spellInfo)
417 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2));
420 inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo)
422 return SpellSchoolMask(spellInfo->SchoolMask);
425 inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect)
427 uint32 mask = 0;
428 if (spellInfo->Mechanic)
429 mask |= 1<<spellInfo->Mechanic;
430 if (spellInfo->EffectMechanic[effect])
431 mask |= 1<<spellInfo->EffectMechanic[effect];
432 return mask;
435 inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect)
437 if (spellInfo->EffectMechanic[effect])
438 return Mechanics(spellInfo->EffectMechanic[effect]);
439 if (spellInfo->Mechanic)
440 return Mechanics(spellInfo->Mechanic);
441 return MECHANIC_NONE;
444 inline uint32 GetDispellMask(DispelType dispel)
446 // If dispell all
447 if (dispel == DISPEL_ALL)
448 return DISPEL_ALL_MASK;
449 else
450 return (1 << dispel);
453 // Diminishing Returns interaction with spells
454 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered);
455 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
456 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group);
458 // Spell affects related declarations (accessed using SpellMgr functions)
459 struct SpellAffectEntry
461 uint32 SpellClassMask[3];
463 typedef UNORDERED_MAP<uint32, SpellAffectEntry> SpellAffectMap;
465 // Spell proc event related declarations (accessed using SpellMgr functions)
466 enum ProcFlags
468 PROC_FLAG_NONE = 0x00000000,
470 PROC_FLAG_KILLED = 0x00000001, // 00 Killed by agressor
471 PROC_FLAG_KILL = 0x00000002, // 01 Kill target (in most cases need XP/Honor reward)
473 PROC_FLAG_SUCCESSFUL_MILEE_HIT = 0x00000004, // 02 Successful melee auto attack
474 PROC_FLAG_TAKEN_MELEE_HIT = 0x00000008, // 03 Taken damage from melee auto attack hit
476 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT = 0x00000010, // 04 Successful attack by Spell that use melee weapon
477 PROC_FLAG_TAKEN_MELEE_SPELL_HIT = 0x00000020, // 05 Taken damage by Spell that use melee weapon
479 PROC_FLAG_SUCCESSFUL_RANGED_HIT = 0x00000040, // 06 Successful Ranged auto attack
480 PROC_FLAG_TAKEN_RANGED_HIT = 0x00000080, // 07 Taken damage from ranged auto attack
482 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT = 0x00000100, // 08 Successful Ranged attack by Spell that use ranged weapon
483 PROC_FLAG_TAKEN_RANGED_SPELL_HIT = 0x00000200, // 09 Taken damage by Spell that use ranged weapon
485 PROC_FLAG_SUCCESSFUL_POSITIVE_AOE_HIT = 0x00000400, // 10 Successful AoE (not 100% shure unused)
486 PROC_FLAG_TAKEN_POSITIVE_AOE = 0x00000800, // 11 Taken AoE (not 100% shure unused)
488 PROC_FLAG_SUCCESSFUL_AOE_SPELL_HIT = 0x00001000, // 12 Successful AoE damage spell hit (not 100% shure unused)
489 PROC_FLAG_TAKEN_AOE_SPELL_HIT = 0x00002000, // 13 Taken AoE damage spell hit (not 100% shure unused)
491 PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL = 0x00004000, // 14 Successful cast positive spell (by default only on healing)
492 PROC_FLAG_TAKEN_POSITIVE_SPELL = 0x00008000, // 15 Taken positive spell hit (by default only on healing)
494 PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT = 0x00010000, // 16 Successful negative spell cast (by default only on damage)
495 PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT = 0x00020000, // 17 Taken negative spell (by default only on damage)
497 PROC_FLAG_ON_DO_PERIODIC = 0x00040000, // 18 Successful do periodic (damage / healing, determined from 14-17 flags)
498 PROC_FLAG_ON_TAKE_PERIODIC = 0x00080000, // 19 Taken spell periodic (damage / healing, determined from 14-17 flags)
500 PROC_FLAG_TAKEN_ANY_DAMAGE = 0x00100000, // 20 Taken any damage
501 PROC_FLAG_ON_TRAP_ACTIVATION = 0x00200000, // 21 On trap activation
503 PROC_FLAG_TAKEN_OFFHAND_HIT = 0x00400000, // 22 Taken off-hand melee attacks(not used)
504 PROC_FLAG_SUCCESSFUL_OFFHAND_HIT = 0x00800000 // 23 Successful off-hand melee attacks
507 #define MELEE_BASED_TRIGGER_MASK (PROC_FLAG_SUCCESSFUL_MILEE_HIT | \
508 PROC_FLAG_TAKEN_MELEE_HIT | \
509 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT | \
510 PROC_FLAG_TAKEN_MELEE_SPELL_HIT | \
511 PROC_FLAG_SUCCESSFUL_RANGED_HIT | \
512 PROC_FLAG_TAKEN_RANGED_HIT | \
513 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT | \
514 PROC_FLAG_TAKEN_RANGED_SPELL_HIT)
516 enum ProcFlagsEx
518 PROC_EX_NONE = 0x0000000, // If none can tigger on Hit/Crit only (passive spells MUST defined by SpellFamily flag)
519 PROC_EX_NORMAL_HIT = 0x0000001, // If set only from normal hit (only damage spells)
520 PROC_EX_CRITICAL_HIT = 0x0000002,
521 PROC_EX_MISS = 0x0000004,
522 PROC_EX_RESIST = 0x0000008,
523 PROC_EX_DODGE = 0x0000010,
524 PROC_EX_PARRY = 0x0000020,
525 PROC_EX_BLOCK = 0x0000040,
526 PROC_EX_EVADE = 0x0000080,
527 PROC_EX_IMMUNE = 0x0000100,
528 PROC_EX_DEFLECT = 0x0000200,
529 PROC_EX_ABSORB = 0x0000400,
530 PROC_EX_REFLECT = 0x0000800,
531 PROC_EX_INTERRUPT = 0x0001000, // Melee hit result can be Interrupt (not used)
532 PROC_EX_RESERVED1 = 0x0002000,
533 PROC_EX_RESERVED2 = 0x0004000,
534 PROC_EX_RESERVED3 = 0x0008000,
535 PROC_EX_EX_TRIGGER_ALWAYS = 0x0010000, // If set trigger always ( no matter another flags) used for drop charges
536 PROC_EX_EX_ONE_TIME_TRIGGER = 0x0020000 // If set trigger always but only one time (not used)
539 struct SpellProcEventEntry
541 uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2
542 uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value
543 uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do)
544 uint32 procFlags; // bitmask for matching proc event
545 uint32 procEx; // proc Extend info (see ProcFlagsEx)
546 float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc
547 float customChance; // Owerride chance (in most cases for debug only)
548 uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_
551 typedef UNORDERED_MAP<uint32, SpellProcEventEntry> SpellProcEventMap;
553 #define ELIXIR_BATTLE_MASK 0x1
554 #define ELIXIR_GUARDIAN_MASK 0x2
555 #define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK)
556 #define ELIXIR_UNSTABLE_MASK 0x4
557 #define ELIXIR_SHATTRATH_MASK 0x8
559 typedef std::map<uint32, uint8> SpellElixirMap;
561 // Spell script target related declarations (accessed using SpellMgr functions)
562 enum SpellTargetType
564 SPELL_TARGET_TYPE_GAMEOBJECT = 0,
565 SPELL_TARGET_TYPE_CREATURE = 1,
566 SPELL_TARGET_TYPE_DEAD = 2
569 #define MAX_SPELL_TARGET_TYPE 3
571 struct SpellTargetEntry
573 SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {}
574 SpellTargetType type;
575 uint32 targetEntry;
578 typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
580 // coordinates for spells (accessed using SpellMgr functions)
581 struct SpellTargetPosition
583 uint32 target_mapId;
584 float target_X;
585 float target_Y;
586 float target_Z;
587 float target_Orientation;
590 typedef UNORDERED_MAP<uint32, SpellTargetPosition> SpellTargetPositionMap;
592 // Spell pet auras
593 class PetAura
595 public:
596 PetAura()
598 auras.clear();
601 PetAura(uint16 petEntry, uint16 aura, bool _removeOnChangePet, int _damage) :
602 removeOnChangePet(_removeOnChangePet), damage(_damage)
604 auras[petEntry] = aura;
607 uint16 GetAura(uint16 petEntry) const
609 std::map<uint16, uint16>::const_iterator itr = auras.find(petEntry);
610 if(itr != auras.end())
611 return itr->second;
612 else
614 std::map<uint16, uint16>::const_iterator itr = auras.find(0);
615 if(itr != auras.end())
616 return itr->second;
617 else
618 return 0;
622 void AddAura(uint16 petEntry, uint16 aura)
624 auras[petEntry] = aura;
627 bool IsRemovedOnChangePet() const
629 return removeOnChangePet;
632 int32 GetDamage() const
634 return damage;
637 private:
638 std::map<uint16, uint16> auras;
639 bool removeOnChangePet;
640 int32 damage;
642 typedef std::map<uint16, PetAura> SpellPetAuraMap;
644 // Spell rank chain (accessed using SpellMgr functions)
645 struct SpellChainNode
647 uint32 prev;
648 uint32 first;
649 uint32 req;
650 uint8 rank;
653 typedef UNORDERED_MAP<uint32, SpellChainNode> SpellChainMap;
654 typedef std::multimap<uint32, uint32> SpellChainMapNext;
656 // Spell learning properties (accessed using SpellMgr functions)
657 struct SpellLearnSkillNode
659 uint32 skill;
660 uint32 value; // 0 - max skill value for player level
661 uint32 maxvalue; // 0 - max skill value for player level
664 typedef std::map<uint32, SpellLearnSkillNode> SpellLearnSkillMap;
666 struct SpellLearnSpellNode
668 uint32 spell;
669 bool autoLearned;
672 typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
674 typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
676 typedef std::map<uint32, uint32> PetLevelupSpellSet;
677 typedef std::map<uint32, PetLevelupSpellSet> PetLevelupSpellMap;
679 inline bool IsPrimaryProfessionSkill(uint32 skill)
681 SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill);
682 if(!pSkill)
683 return false;
685 if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
686 return false;
688 return true;
691 inline bool IsProfessionSkill(uint32 skill)
693 return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
696 class SpellMgr
698 // Constructors
699 public:
700 SpellMgr();
701 ~SpellMgr();
703 // Accessors (const or static functions)
704 public:
705 // Spell affects
706 SpellAffectEntry const*GetSpellAffect(uint16 spellId, uint8 effectId) const
708 SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId);
709 if( itr != mSpellAffectMap.end( ) )
710 return &itr->second;
711 return 0;
714 bool IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const;
716 SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }
718 uint32 GetSpellElixirMask(uint32 spellid) const
720 SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid);
721 if(itr==mSpellElixirs.end())
722 return 0x0;
724 return itr->second;
727 SpellSpecific GetSpellElixirSpecific(uint32 spellid) const
729 uint32 mask = GetSpellElixirMask(spellid);
730 if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK)
731 return SPELL_FLASK_ELIXIR;
732 else if(mask & ELIXIR_BATTLE_MASK)
733 return SPELL_BATTLE_ELIXIR;
734 else if(mask & ELIXIR_GUARDIAN_MASK)
735 return SPELL_GUARDIAN_ELIXIR;
736 else
737 return SPELL_NORMAL;
740 // Spell proc events
741 SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
743 SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
744 if( itr != mSpellProcEventMap.end( ) )
745 return &itr->second;
746 return NULL;
749 static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active);
751 // Spell target coordinates
752 SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const
754 SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id );
755 if( itr != mSpellTargetPositions.end( ) )
756 return &itr->second;
757 return NULL;
760 // Spell ranks chains
761 SpellChainNode const* GetSpellChainNode(uint32 spell_id) const
763 SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
764 if(itr == mSpellChains.end())
765 return NULL;
767 return &itr->second;
770 uint32 GetFirstSpellInChain(uint32 spell_id) const
772 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
773 return node->first;
775 return spell_id;
778 uint32 GetPrevSpellInChain(uint32 spell_id) const
780 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
781 return node->prev;
783 return 0;
786 SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; }
788 // Note: not use rank for compare to spell ranks: spell chains isn't linear order
789 // Use IsHighRankOfSpell instead
790 uint8 GetSpellRank(uint32 spell_id) const
792 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
793 return node->rank;
795 return 0;
798 uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const
800 SpellChainMap::const_iterator itr = mSpellChains.find(spell1);
802 uint32 rank2 = GetSpellRank(spell2);
804 // not ordered correctly by rank value
805 if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2)
806 return false;
808 // check present in same rank chain
809 for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev))
810 if(itr->second.prev==spell2)
811 return true;
813 return false;
816 bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const;
817 static bool canStackSpellRanks(SpellEntry const *spellInfo);
818 bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const;
820 SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const;
822 // Spell learning
823 SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const
825 SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id);
826 if(itr != mSpellLearnSkills.end())
827 return &itr->second;
828 else
829 return NULL;
832 bool IsSpellLearnSpell(uint32 spell_id) const
834 return mSpellLearnSpells.count(spell_id)!=0;
837 SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const
839 return mSpellLearnSpells.lower_bound(spell_id);
842 SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const
844 return mSpellLearnSpells.upper_bound(spell_id);
847 bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const
849 SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1);
850 SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1);
851 for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i)
852 if(i->second.spell==spell_id2)
853 return true;
854 return false;
857 static bool IsProfessionSpell(uint32 spellId);
858 static bool IsPrimaryProfessionSpell(uint32 spellId);
859 bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const;
861 // Spell script targets
862 SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const
864 return mSpellScriptTarget.lower_bound(spell_id);
867 SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const
869 return mSpellScriptTarget.upper_bound(spell_id);
872 // Spell correctess for client using
873 static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true);
875 SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const
877 return mSkillLineAbilityMap.lower_bound(spell_id);
880 SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const
882 return mSkillLineAbilityMap.upper_bound(spell_id);
885 PetAura const* GetPetAura(uint16 spell_id)
887 SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find(spell_id);
888 if(itr != mSpellPetAuraMap.end())
889 return &itr->second;
890 else
891 return NULL;
894 PetLevelupSpellSet const* GetPetLevelupSpellList(uint32 petFamily) const
896 PetLevelupSpellMap::const_iterator itr = mPetLevelupSpellMap.find(petFamily);
897 if(itr != mPetLevelupSpellMap.end())
898 return &itr->second;
899 else
900 return NULL;
903 // Modifiers
904 public:
905 static SpellMgr& Instance();
907 // Loading data at server startup
908 void LoadSpellChains();
909 void LoadSpellLearnSkills();
910 void LoadSpellLearnSpells();
911 void LoadSpellScriptTarget();
912 void LoadSpellAffects();
913 void LoadSpellElixirs();
914 void LoadSpellProcEvents();
915 void LoadSpellTargetPositions();
916 void LoadSpellThreats();
917 void LoadSkillLineAbilityMap();
918 void LoadSpellPetAuras();
919 void LoadPetLevelupSpellMap();
921 private:
922 SpellScriptTarget mSpellScriptTarget;
923 SpellChainMap mSpellChains;
924 SpellChainMapNext mSpellChainsNext;
925 SpellLearnSkillMap mSpellLearnSkills;
926 SpellLearnSpellMap mSpellLearnSpells;
927 SpellTargetPositionMap mSpellTargetPositions;
928 SpellAffectMap mSpellAffectMap;
929 SpellElixirMap mSpellElixirs;
930 SpellProcEventMap mSpellProcEventMap;
931 SkillLineAbilityMap mSkillLineAbilityMap;
932 SpellPetAuraMap mSpellPetAuraMap;
933 PetLevelupSpellMap mPetLevelupSpellMap;
936 #define spellmgr SpellMgr::Instance()
937 #endif