[9529] Make Player::IsValidPos const
[getmangos.git] / src / game / SpellMgr.h
blobc50a35cf8af09bc245b2fe793e2fd5e41f52ba3a
1 /*
2 * Copyright (C) 2005-2010 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 "SpellAuraDefines.h"
27 #include "DBCStructure.h"
28 #include "DBCStores.h"
29 #include "Database/SQLStorage.h"
31 #include "Utilities/UnorderedMap.h"
33 #include <map>
35 class Player;
36 class Spell;
37 struct SpellModifier;
39 // only used in code
40 enum SpellCategories
42 SPELLCATEGORY_HEALTH_MANA_POTIONS = 4,
43 SPELLCATEGORY_DEVOUR_MAGIC = 12,
44 SPELLCATEGORY_JUDGEMENT = 1210, // Judgement (seal trigger)
47 enum SpellFamilyNames
49 SPELLFAMILY_GENERIC = 0,
50 SPELLFAMILY_UNK1 = 1, // events, holidays
51 // 2 - unused
52 SPELLFAMILY_MAGE = 3,
53 SPELLFAMILY_WARRIOR = 4,
54 SPELLFAMILY_WARLOCK = 5,
55 SPELLFAMILY_PRIEST = 6,
56 SPELLFAMILY_DRUID = 7,
57 SPELLFAMILY_ROGUE = 8,
58 SPELLFAMILY_HUNTER = 9,
59 SPELLFAMILY_PALADIN = 10,
60 SPELLFAMILY_SHAMAN = 11,
61 SPELLFAMILY_UNK2 = 12, // 2 spells (silence resistance)
62 SPELLFAMILY_POTION = 13,
63 // 14 - unused
64 SPELLFAMILY_DEATHKNIGHT = 15,
65 // 16 - unused
66 SPELLFAMILY_PET = 17
69 //Some SpellFamilyFlags
70 #define SPELLFAMILYFLAG_ROGUE_VANISH UI64LIT(0x0000000000000800)
71 #define SPELLFAMILYFLAG_ROGUE_STEALTH UI64LIT(0x0000000000400000)
72 #define SPELLFAMILYFLAG_ROGUE_BACKSTAB UI64LIT(0x0000000000800004)
73 #define SPELLFAMILYFLAG_ROGUE_SAP UI64LIT(0x0000000000000080)
74 #define SPELLFAMILYFLAG_ROGUE_FEINT UI64LIT(0x0000000008000000)
75 #define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT UI64LIT(0x0000000000200000)
76 #define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE UI64LIT(0x00000009003E0000)
78 #define SPELLFAMILYFLAG_PALADIN_SEALS UI64LIT(0x26000C000A000000)
80 // Spell clasification
81 enum SpellSpecific
83 SPELL_NORMAL = 0,
84 SPELL_SEAL = 1,
85 SPELL_BLESSING = 2,
86 SPELL_AURA = 3,
87 SPELL_STING = 4,
88 SPELL_CURSE = 5,
89 SPELL_ASPECT = 6,
90 SPELL_TRACKER = 7,
91 SPELL_WARLOCK_ARMOR = 8,
92 SPELL_MAGE_ARMOR = 9,
93 SPELL_ELEMENTAL_SHIELD = 10,
94 SPELL_MAGE_POLYMORPH = 11,
95 SPELL_POSITIVE_SHOUT = 12,
96 SPELL_JUDGEMENT = 13,
97 SPELL_BATTLE_ELIXIR = 14,
98 SPELL_GUARDIAN_ELIXIR = 15,
99 SPELL_FLASK_ELIXIR = 16,
100 SPELL_PRESENCE = 17,
101 SPELL_HAND = 18,
102 SPELL_WELL_FED = 19,
103 SPELL_FOOD = 20,
104 SPELL_DRINK = 21,
105 SPELL_FOOD_AND_DRINK = 22,
108 SpellSpecific GetSpellSpecific(uint32 spellId);
110 // Different spell properties
111 inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); }
112 uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL);
113 inline float GetSpellMinRange(SpellRangeEntry const *range, bool friendly = false)
115 if(!range)
116 return 0;
117 return (friendly ? range->minRangeFriendly : range->minRange);
119 inline float GetSpellMaxRange(SpellRangeEntry const *range, bool friendly = false)
121 if(!range)
122 return 0;
123 return (friendly ? range->maxRangeFriendly : range->maxRange);
125 inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; }
126 int32 GetSpellDuration(SpellEntry const *spellInfo);
127 int32 GetSpellMaxDuration(SpellEntry const *spellInfo);
128 uint16 GetSpellAuraMaxTicks(SpellEntry const* spellInfo);
129 WeaponAttackType GetWeaponAttackType(SpellEntry const *spellInfo);
131 inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
133 for(int i = 0; i < MAX_EFFECT_INDEX; ++i)
134 if(SpellEffects(spellInfo->Effect[i])==effect)
135 return true;
136 return false;
139 inline bool IsSpellHaveAura(SpellEntry const *spellInfo, AuraType aura)
141 for(int i = 0; i < MAX_EFFECT_INDEX; ++i)
142 if(AuraType(spellInfo->EffectApplyAuraName[i])==aura)
143 return true;
144 return false;
147 inline bool IsSpellLastAuraEffect(SpellEntry const *spellInfo, SpellEffectIndex effecIdx)
149 for(int i = effecIdx+1; i < MAX_EFFECT_INDEX; ++i)
150 if(spellInfo->EffectApplyAuraName[i])
151 return false;
152 return true;
155 bool IsNoStackAuraDueToAura(uint32 spellId_1, SpellEffectIndex effIndex_1, uint32 spellId_2, SpellEffectIndex effIndex_2);
157 inline bool IsSealSpell(SpellEntry const *spellInfo)
159 //Collection of all the seal family flags. No other paladin spell has any of those.
160 return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN &&
161 ( spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_PALADIN_SEALS ) &&
162 // avoid counting target triggered effect as seal for avoid remove it or seal by it.
163 spellInfo->EffectImplicitTargetA[EFFECT_INDEX_0] == TARGET_SELF;
166 inline bool IsElementalShield(SpellEntry const *spellInfo)
168 // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus
169 return (spellInfo->SpellFamilyFlags & UI64LIT(0x42000000400)) || spellInfo->Id == 23552;
172 inline bool IsExplicitDiscoverySpell(SpellEntry const *spellInfo)
174 return ((spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_CREATE_RANDOM_ITEM
175 && spellInfo->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_SCRIPT_EFFECT)
176 || spellInfo->Id == 64323); // Book of Glyph Mastery (Effect0==SPELL_EFFECT_SCRIPT_EFFECT without any other data)
179 inline bool IsLootCraftingSpell(SpellEntry const *spellInfo)
181 return (spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_CREATE_RANDOM_ITEM ||
182 // different random cards from Inscription (121==Virtuoso Inking Set category)
183 // also Abyssal Shatter (63), any !=0 infact
184 (spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_CREATE_ITEM_2 && spellInfo->TotemCategory[0] != 0));
187 int32 CompareAuraRanks(uint32 spellId_1, SpellEffectIndex effIndex_1, uint32 spellId_2, SpellEffectIndex effIndex_2);
189 // order from less to more strict
190 bool IsSingleFromSpellSpecificPerTargetPerCaster(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
191 bool IsSingleFromSpellSpecificSpellRanksPerTarget(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
192 bool IsSingleFromSpellSpecificPerTarget(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
194 bool IsPassiveSpell(uint32 spellId);
196 inline bool IsPassiveSpellStackableWithRanks(SpellEntry const* spellProto)
198 if(!IsPassiveSpell(spellProto->Id))
199 return false;
201 return !IsSpellHaveEffect(spellProto,SPELL_EFFECT_APPLY_AURA);
204 inline bool IsDeathOnlySpell(SpellEntry const *spellInfo)
206 return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_CAST_ON_DEAD
207 || spellInfo->Id == 2584;
210 inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo)
212 return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT;
215 inline bool IsNonCombatSpell(SpellEntry const *spellInfo)
217 return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0;
220 bool IsPositiveSpell(uint32 spellId);
221 bool IsPositiveEffect(uint32 spellId, SpellEffectIndex effIndex);
222 bool IsPositiveTarget(uint32 targetA, uint32 targetB);
224 bool IsExplicitPositiveTarget(uint32 targetA);
225 bool IsExplicitNegativeTarget(uint32 targetA);
227 bool IsSingleTargetSpell(SpellEntry const *spellInfo);
228 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);
230 inline bool IsCasterSourceTarget(uint32 target)
232 switch (target )
234 case TARGET_SELF:
235 case TARGET_PET:
236 case TARGET_ALL_PARTY_AROUND_CASTER:
237 case TARGET_IN_FRONT_OF_CASTER:
238 case TARGET_MASTER:
239 case TARGET_MINION:
240 case TARGET_ALL_PARTY:
241 case TARGET_ALL_PARTY_AROUND_CASTER_2:
242 case TARGET_SELF_FISHING:
243 case TARGET_TOTEM_EARTH:
244 case TARGET_TOTEM_WATER:
245 case TARGET_TOTEM_AIR:
246 case TARGET_TOTEM_FIRE:
247 case TARGET_AREAEFFECT_CUSTOM_2:
248 case TARGET_ALL_RAID_AROUND_CASTER:
249 case TARGET_SELF2:
250 case TARGET_DIRECTLY_FORWARD:
251 case TARGET_NONCOMBAT_PET:
252 case TARGET_IN_FRONT_OF_CASTER_30:
253 return true;
254 default:
255 break;
257 return false;
260 inline bool IsSpellWithCasterSourceTargetsOnly(SpellEntry const* spellInfo)
262 for(int i = 0; i < MAX_EFFECT_INDEX; ++i)
264 uint32 targetA = spellInfo->EffectImplicitTargetA[i];
265 if(targetA && !IsCasterSourceTarget(targetA))
266 return false;
268 uint32 targetB = spellInfo->EffectImplicitTargetB[i];
269 if(targetB && !IsCasterSourceTarget(targetB))
270 return false;
272 if(!targetA && !targetB)
273 return false;
275 return true;
278 inline bool IsPointEffectTarget( Targets target )
280 switch (target )
282 case TARGET_INNKEEPER_COORDINATES:
283 case TARGET_TABLE_X_Y_Z_COORDINATES:
284 case TARGET_CASTER_COORDINATES:
285 case TARGET_SCRIPT_COORDINATES:
286 case TARGET_CURRENT_ENEMY_COORDINATES:
287 case TARGET_DUELVSPLAYER_COORDINATES:
288 case TARGET_DYNAMIC_OBJECT_COORDINATES:
289 case TARGET_POINT_AT_NORTH:
290 case TARGET_POINT_AT_SOUTH:
291 case TARGET_POINT_AT_EAST:
292 case TARGET_POINT_AT_WEST:
293 case TARGET_POINT_AT_NE:
294 case TARGET_POINT_AT_NW:
295 case TARGET_POINT_AT_SE:
296 case TARGET_POINT_AT_SW:
297 return true;
298 default:
299 break;
301 return false;
304 inline bool IsAreaEffectTarget( Targets target )
306 switch (target )
308 case TARGET_AREAEFFECT_INSTANT:
309 case TARGET_AREAEFFECT_CUSTOM:
310 case TARGET_ALL_ENEMY_IN_AREA:
311 case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
312 case TARGET_ALL_PARTY_AROUND_CASTER:
313 case TARGET_IN_FRONT_OF_CASTER:
314 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
315 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
316 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
317 case TARGET_ALL_PARTY:
318 case TARGET_ALL_PARTY_AROUND_CASTER_2:
319 case TARGET_AREAEFFECT_PARTY:
320 case TARGET_AREAEFFECT_CUSTOM_2:
321 case TARGET_ALL_RAID_AROUND_CASTER:
322 case TARGET_AREAEFFECT_PARTY_AND_CLASS:
323 case TARGET_IN_FRONT_OF_CASTER_30:
324 return true;
325 default:
326 break;
328 return false;
331 inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo)
333 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[EFFECT_INDEX_0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[EFFECT_INDEX_0])))
334 return true;
335 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[EFFECT_INDEX_1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[EFFECT_INDEX_1])))
336 return true;
337 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[EFFECT_INDEX_2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[EFFECT_INDEX_2])))
338 return true;
339 return false;
342 inline bool IsAreaAuraEffect(uint32 effect)
344 if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
345 effect == SPELL_EFFECT_APPLY_AREA_AURA_RAID ||
346 effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND ||
347 effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY ||
348 effect == SPELL_EFFECT_APPLY_AREA_AURA_PET ||
349 effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER)
350 return true;
351 return false;
354 inline bool IsDispelSpell(SpellEntry const *spellInfo)
356 if (spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_DISPEL ||
357 spellInfo->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_DISPEL ||
358 spellInfo->Effect[EFFECT_INDEX_2] == SPELL_EFFECT_DISPEL )
359 return true;
360 return false;
362 inline bool isSpellBreakStealth(SpellEntry const* spellInfo)
364 return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH);
367 inline bool IsAutoRepeatRangedSpell(SpellEntry const* spellInfo)
369 return (spellInfo->Attributes & SPELL_ATTR_RANGED) && (spellInfo->AttributesEx2 & SPELL_ATTR_EX2_AUTOREPEAT_FLAG);
372 SpellCastResult GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form);
374 inline bool IsChanneledSpell(SpellEntry const* spellInfo)
376 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2));
379 inline bool NeedsComboPoints(SpellEntry const* spellInfo)
381 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2));
384 inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo)
386 return SpellSchoolMask(spellInfo->SchoolMask);
389 inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect)
391 uint32 mask = 0;
392 if (spellInfo->Mechanic)
393 mask |= 1 << (spellInfo->Mechanic - 1);
394 if (spellInfo->EffectMechanic[effect])
395 mask |= 1 << (spellInfo->EffectMechanic[effect] - 1);
396 return mask;
399 inline uint32 GetAllSpellMechanicMask(SpellEntry const* spellInfo)
401 uint32 mask = 0;
402 if (spellInfo->Mechanic)
403 mask |= 1 << (spellInfo->Mechanic - 1);
404 for (int i=0; i< MAX_EFFECT_INDEX; ++i)
405 if (spellInfo->EffectMechanic[i])
406 mask |= 1 << (spellInfo->EffectMechanic[i]-1);
407 return mask;
410 inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, SpellEffectIndex effect)
412 if (spellInfo->EffectMechanic[effect])
413 return Mechanics(spellInfo->EffectMechanic[effect]);
414 if (spellInfo->Mechanic)
415 return Mechanics(spellInfo->Mechanic);
416 return MECHANIC_NONE;
419 inline uint32 GetDispellMask(DispelType dispel)
421 // If dispell all
422 if (dispel == DISPEL_ALL)
423 return DISPEL_ALL_MASK;
424 else
425 return (1 << dispel);
428 // Diminishing Returns interaction with spells
429 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered);
430 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
431 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group);
432 int32 GetDiminishingReturnsLimitDuration(DiminishingGroup group, SpellEntry const* spellproto);
434 // Spell proc event related declarations (accessed using SpellMgr functions)
435 enum ProcFlags
437 PROC_FLAG_NONE = 0x00000000,
439 PROC_FLAG_KILLED = 0x00000001, // 00 Killed by agressor
440 PROC_FLAG_KILL = 0x00000002, // 01 Kill target (in most cases need XP/Honor reward)
442 PROC_FLAG_SUCCESSFUL_MELEE_HIT = 0x00000004, // 02 Successful melee auto attack
443 PROC_FLAG_TAKEN_MELEE_HIT = 0x00000008, // 03 Taken damage from melee auto attack hit
445 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT = 0x00000010, // 04 Successful attack by Spell that use melee weapon
446 PROC_FLAG_TAKEN_MELEE_SPELL_HIT = 0x00000020, // 05 Taken damage by Spell that use melee weapon
448 PROC_FLAG_SUCCESSFUL_RANGED_HIT = 0x00000040, // 06 Successful Ranged auto attack
449 PROC_FLAG_TAKEN_RANGED_HIT = 0x00000080, // 07 Taken damage from ranged auto attack
451 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT = 0x00000100, // 08 Successful Ranged attack by Spell that use ranged weapon
452 PROC_FLAG_TAKEN_RANGED_SPELL_HIT = 0x00000200, // 09 Taken damage by Spell that use ranged weapon
454 PROC_FLAG_SUCCESSFUL_POSITIVE_AOE_HIT = 0x00000400, // 10 Successful AoE (not 100% shure unused)
455 PROC_FLAG_TAKEN_POSITIVE_AOE = 0x00000800, // 11 Taken AoE (not 100% shure unused)
457 PROC_FLAG_SUCCESSFUL_AOE_SPELL_HIT = 0x00001000, // 12 Successful AoE damage spell hit (not 100% shure unused)
458 PROC_FLAG_TAKEN_AOE_SPELL_HIT = 0x00002000, // 13 Taken AoE damage spell hit (not 100% shure unused)
460 PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL = 0x00004000, // 14 Successful cast positive spell (by default only on healing)
461 PROC_FLAG_TAKEN_POSITIVE_SPELL = 0x00008000, // 15 Taken positive spell hit (by default only on healing)
463 PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT = 0x00010000, // 16 Successful negative spell cast (by default only on damage)
464 PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT = 0x00020000, // 17 Taken negative spell (by default only on damage)
466 PROC_FLAG_ON_DO_PERIODIC = 0x00040000, // 18 Successful do periodic (damage / healing, determined from 14-17 flags)
467 PROC_FLAG_ON_TAKE_PERIODIC = 0x00080000, // 19 Taken spell periodic (damage / healing, determined from 14-17 flags)
469 PROC_FLAG_TAKEN_ANY_DAMAGE = 0x00100000, // 20 Taken any damage
470 PROC_FLAG_ON_TRAP_ACTIVATION = 0x00200000, // 21 On trap activation
472 PROC_FLAG_TAKEN_OFFHAND_HIT = 0x00400000, // 22 Taken off-hand melee attacks(not used)
473 PROC_FLAG_SUCCESSFUL_OFFHAND_HIT = 0x00800000 // 23 Successful off-hand melee attacks
476 #define MELEE_BASED_TRIGGER_MASK (PROC_FLAG_SUCCESSFUL_MELEE_HIT | \
477 PROC_FLAG_TAKEN_MELEE_HIT | \
478 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT | \
479 PROC_FLAG_TAKEN_MELEE_SPELL_HIT | \
480 PROC_FLAG_SUCCESSFUL_RANGED_HIT | \
481 PROC_FLAG_TAKEN_RANGED_HIT | \
482 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT | \
483 PROC_FLAG_TAKEN_RANGED_SPELL_HIT)
485 enum ProcFlagsEx
487 PROC_EX_NONE = 0x0000000, // If none can tigger on Hit/Crit only (passive spells MUST defined by SpellFamily flag)
488 PROC_EX_NORMAL_HIT = 0x0000001, // If set only from normal hit (only damage spells)
489 PROC_EX_CRITICAL_HIT = 0x0000002,
490 PROC_EX_MISS = 0x0000004,
491 PROC_EX_RESIST = 0x0000008,
492 PROC_EX_DODGE = 0x0000010,
493 PROC_EX_PARRY = 0x0000020,
494 PROC_EX_BLOCK = 0x0000040,
495 PROC_EX_EVADE = 0x0000080,
496 PROC_EX_IMMUNE = 0x0000100,
497 PROC_EX_DEFLECT = 0x0000200,
498 PROC_EX_ABSORB = 0x0000400,
499 PROC_EX_REFLECT = 0x0000800,
500 PROC_EX_INTERRUPT = 0x0001000, // Melee hit result can be Interrupt (not used)
501 PROC_EX_FULL_BLOCK = 0x0002000, // block al attack damage
502 PROC_EX_RESERVED2 = 0x0004000,
503 PROC_EX_RESERVED3 = 0x0008000,
504 PROC_EX_EX_TRIGGER_ALWAYS = 0x0010000, // If set trigger always ( no matter another flags) used for drop charges
505 PROC_EX_EX_ONE_TIME_TRIGGER = 0x0020000 // If set trigger always but only one time (not used)
508 struct SpellProcEventEntry
510 uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2
511 uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value
512 uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do)
513 uint32 spellFamilyMask2; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags2 (like auras 107 and 108 do)
514 uint32 procFlags; // bitmask for matching proc event
515 uint32 procEx; // proc Extend info (see ProcFlagsEx)
516 float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc
517 float customChance; // Owerride chance (in most cases for debug only)
518 uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_
521 struct SpellBonusEntry
523 float direct_damage;
524 float dot_damage;
525 float ap_bonus;
528 typedef UNORDERED_MAP<uint32, SpellProcEventEntry> SpellProcEventMap;
529 typedef UNORDERED_MAP<uint32, SpellBonusEntry> SpellBonusMap;
531 #define ELIXIR_BATTLE_MASK 0x01
532 #define ELIXIR_GUARDIAN_MASK 0x02
533 #define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK)
534 #define ELIXIR_UNSTABLE_MASK 0x04
535 #define ELIXIR_SHATTRATH_MASK 0x08
536 #define ELIXIR_WELL_FED 0x10 // Some foods have SPELLFAMILY_POTION
538 typedef std::map<uint32, uint8> SpellElixirMap;
539 typedef std::map<uint32, float> SpellProcItemEnchantMap;
540 typedef std::map<uint32, uint16> SpellThreatMap;
542 // Spell script target related declarations (accessed using SpellMgr functions)
543 enum SpellTargetType
545 SPELL_TARGET_TYPE_GAMEOBJECT = 0,
546 SPELL_TARGET_TYPE_CREATURE = 1,
547 SPELL_TARGET_TYPE_DEAD = 2
550 #define MAX_SPELL_TARGET_TYPE 3
552 struct SpellTargetEntry
554 SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {}
555 SpellTargetType type;
556 uint32 targetEntry;
559 typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
560 typedef std::pair<SpellScriptTarget::const_iterator,SpellScriptTarget::const_iterator> SpellScriptTargetBounds;
562 // coordinates for spells (accessed using SpellMgr functions)
563 struct SpellTargetPosition
565 uint32 target_mapId;
566 float target_X;
567 float target_Y;
568 float target_Z;
569 float target_Orientation;
572 typedef UNORDERED_MAP<uint32, SpellTargetPosition> SpellTargetPositionMap;
574 // Spell pet auras
575 class PetAura
577 public:
578 PetAura()
580 auras.clear();
583 PetAura(uint32 petEntry, uint32 aura, bool _removeOnChangePet, int _damage) :
584 removeOnChangePet(_removeOnChangePet), damage(_damage)
586 auras[petEntry] = aura;
589 uint32 GetAura(uint32 petEntry) const
591 std::map<uint32, uint32>::const_iterator itr = auras.find(petEntry);
592 if(itr != auras.end())
593 return itr->second;
594 else
596 std::map<uint32, uint32>::const_iterator itr2 = auras.find(0);
597 if(itr2 != auras.end())
598 return itr2->second;
599 else
600 return 0;
604 void AddAura(uint32 petEntry, uint32 aura)
606 auras[petEntry] = aura;
609 bool IsRemovedOnChangePet() const
611 return removeOnChangePet;
614 int32 GetDamage() const
616 return damage;
619 private:
620 std::map<uint32, uint32> auras;
621 bool removeOnChangePet;
622 int32 damage;
624 typedef std::map<uint32, PetAura> SpellPetAuraMap;
626 struct SpellArea
628 uint32 spellId;
629 uint32 areaId; // zone/subzone/or 0 is not limited to zone
630 uint32 questStart; // quest start (quest must be active or rewarded for spell apply)
631 uint32 questEnd; // quest end (quest don't must be rewarded for spell apply)
632 int32 auraSpell; // spell aura must be applied for spell apply )if possitive) and it don't must be applied in other case
633 uint32 raceMask; // can be applied only to races
634 Gender gender; // can be applied only to gender
635 bool questStartCanActive; // if true then quest start can be active (not only rewarded)
636 bool autocast; // if true then auto applied at area enter, in other case just allowed to cast
638 // helpers
639 bool IsFitToRequirements(Player const* player, uint32 newZone, uint32 newArea) const;
642 typedef std::multimap<uint32,SpellArea> SpellAreaMap;
643 typedef std::multimap<uint32,SpellArea const*> SpellAreaForQuestMap;
644 typedef std::multimap<uint32,SpellArea const*> SpellAreaForAuraMap;
645 typedef std::multimap<uint32,SpellArea const*> SpellAreaForAreaMap;
646 typedef std::pair<SpellAreaMap::const_iterator,SpellAreaMap::const_iterator> SpellAreaMapBounds;
647 typedef std::pair<SpellAreaForQuestMap::const_iterator,SpellAreaForQuestMap::const_iterator> SpellAreaForQuestMapBounds;
648 typedef std::pair<SpellAreaForAuraMap::const_iterator, SpellAreaForAuraMap::const_iterator> SpellAreaForAuraMapBounds;
649 typedef std::pair<SpellAreaForAreaMap::const_iterator, SpellAreaForAreaMap::const_iterator> SpellAreaForAreaMapBounds;
652 // Spell rank chain (accessed using SpellMgr functions)
653 struct SpellChainNode
655 uint32 prev;
656 uint32 first;
657 uint32 req;
658 uint8 rank;
661 typedef UNORDERED_MAP<uint32, SpellChainNode> SpellChainMap;
662 typedef std::multimap<uint32, uint32> SpellChainMapNext;
664 // Spell learning properties (accessed using SpellMgr functions)
665 struct SpellLearnSkillNode
667 uint32 skill;
668 uint32 value; // 0 - max skill value for player level
669 uint32 maxvalue; // 0 - max skill value for player level
672 typedef std::map<uint32, SpellLearnSkillNode> SpellLearnSkillMap;
674 struct SpellLearnSpellNode
676 uint32 spell;
677 bool active; // show in spellbook or not
678 bool autoLearned;
681 typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
682 typedef std::pair<SpellLearnSpellMap::const_iterator,SpellLearnSpellMap::const_iterator> SpellLearnSpellMapBounds;
684 typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
685 typedef std::pair<SkillLineAbilityMap::const_iterator,SkillLineAbilityMap::const_iterator> SkillLineAbilityMapBounds;
687 typedef std::multimap<uint32, uint32> PetLevelupSpellSet;
688 typedef std::map<uint32, PetLevelupSpellSet> PetLevelupSpellMap;
690 struct PetDefaultSpellsEntry
692 uint32 spellid[MAX_CREATURE_SPELL_DATA_SLOT];
695 // < 0 for petspelldata id, > 0 for creature_id
696 typedef std::map<int32, PetDefaultSpellsEntry> PetDefaultSpellsMap;
699 inline bool IsPrimaryProfessionSkill(uint32 skill)
701 SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill);
702 if(!pSkill)
703 return false;
705 if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
706 return false;
708 return true;
711 inline bool IsProfessionSkill(uint32 skill)
713 return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
716 inline bool IsProfessionOrRidingSkill(uint32 skill)
718 return IsProfessionSkill(skill) || skill == SKILL_RIDING;
721 class SpellMgr
723 friend struct DoSpellBonusess;
724 friend struct DoSpellProcEvent;
725 friend struct DoSpellProcItemEnchant;
727 // Constructors
728 public:
729 SpellMgr();
730 ~SpellMgr();
732 // Accessors (const or static functions)
733 public:
735 SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }
737 uint32 GetSpellElixirMask(uint32 spellid) const
739 SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid);
740 if(itr==mSpellElixirs.end())
741 return 0x0;
743 return itr->second;
746 SpellSpecific GetSpellElixirSpecific(uint32 spellid) const
748 uint32 mask = GetSpellElixirMask(spellid);
749 if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK)
750 return SPELL_FLASK_ELIXIR;
751 else if(mask & ELIXIR_BATTLE_MASK)
752 return SPELL_BATTLE_ELIXIR;
753 else if(mask & ELIXIR_GUARDIAN_MASK)
754 return SPELL_GUARDIAN_ELIXIR;
755 else if(mask & ELIXIR_WELL_FED)
756 return SPELL_WELL_FED;
757 else
758 return SPELL_NORMAL;
761 uint16 GetSpellThreat(uint32 spellid) const
763 SpellThreatMap::const_iterator itr = mSpellThreatMap.find(spellid);
764 if(itr==mSpellThreatMap.end())
765 return 0;
767 return itr->second;
770 // Spell proc events
771 SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
773 SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
774 if( itr != mSpellProcEventMap.end( ) )
775 return &itr->second;
776 return NULL;
779 // Spell procs from item enchants
780 float GetItemEnchantProcChance(uint32 spellid) const
782 SpellProcItemEnchantMap::const_iterator itr = mSpellProcItemEnchantMap.find(spellid);
783 if(itr==mSpellProcItemEnchantMap.end())
784 return 0.0f;
786 return itr->second;
789 static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active);
791 // Spell bonus data
792 SpellBonusEntry const* GetSpellBonusData(uint32 spellId) const
794 // Lookup data
795 SpellBonusMap::const_iterator itr = mSpellBonusMap.find(spellId);
796 if( itr != mSpellBonusMap.end( ) )
797 return &itr->second;
799 return NULL;
802 // Spell target coordinates
803 SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const
805 SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id );
806 if( itr != mSpellTargetPositions.end( ) )
807 return &itr->second;
808 return NULL;
811 // Spell ranks chains
812 SpellChainNode const* GetSpellChainNode(uint32 spell_id) const
814 SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
815 if(itr == mSpellChains.end())
816 return NULL;
818 return &itr->second;
821 uint32 GetFirstSpellInChain(uint32 spell_id) const
823 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
824 return node->first;
826 return spell_id;
829 uint32 GetPrevSpellInChain(uint32 spell_id) const
831 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
832 return node->prev;
834 return 0;
837 SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; }
839 template<typename Worker>
840 void doForHighRanks(uint32 spellid, Worker& worker)
842 SpellChainMapNext const& nextMap = GetSpellChainNext();
843 for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
845 worker(itr->second);
846 doForHighRanks(itr->second,worker);
850 // Note: not use rank for compare to spell ranks: spell chains isn't linear order
851 // Use IsHighRankOfSpell instead
852 uint8 GetSpellRank(uint32 spell_id) const
854 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
855 return node->rank;
857 return 0;
860 uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const
862 SpellChainMap::const_iterator itr = mSpellChains.find(spell1);
864 uint32 rank2 = GetSpellRank(spell2);
866 // not ordered correctly by rank value
867 if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2)
868 return false;
870 // check present in same rank chain
871 for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev))
872 if(itr->second.prev==spell2)
873 return true;
875 return false;
878 bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const;
879 static bool canStackSpellRanks(SpellEntry const *spellInfo);
880 bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const;
882 SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const;
884 // Spell learning
885 SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const
887 SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id);
888 if(itr != mSpellLearnSkills.end())
889 return &itr->second;
890 else
891 return NULL;
894 bool IsSpellLearnSpell(uint32 spell_id) const
896 return mSpellLearnSpells.find(spell_id) != mSpellLearnSpells.end();
899 SpellLearnSpellMapBounds GetSpellLearnSpellMapBounds(uint32 spell_id) const
901 return SpellLearnSpellMapBounds(mSpellLearnSpells.lower_bound(spell_id),mSpellLearnSpells.upper_bound(spell_id));
904 bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const
906 SpellLearnSpellMapBounds bounds = GetSpellLearnSpellMapBounds(spell_id1);
907 for(SpellLearnSpellMap::const_iterator i = bounds.first; i != bounds.second; ++i)
908 if (i->second.spell==spell_id2)
909 return true;
910 return false;
913 static bool IsProfessionOrRidingSpell(uint32 spellId);
914 static bool IsProfessionSpell(uint32 spellId);
915 static bool IsPrimaryProfessionSpell(uint32 spellId);
916 bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const;
918 bool IsSkillBonusSpell(uint32 spellId) const;
921 // Spell script targets
922 SpellScriptTargetBounds GetSpellScriptTargetBounds(uint32 spell_id) const
924 return SpellScriptTargetBounds(mSpellScriptTarget.lower_bound(spell_id),mSpellScriptTarget.upper_bound(spell_id));
927 // Spell correctess for client using
928 static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true);
930 SkillLineAbilityMapBounds GetSkillLineAbilityMapBounds(uint32 spell_id) const
932 return SkillLineAbilityMapBounds(mSkillLineAbilityMap.lower_bound(spell_id),mSkillLineAbilityMap.upper_bound(spell_id));
935 PetAura const* GetPetAura(uint32 spell_id, SpellEffectIndex eff)
937 SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find((spell_id<<8) + eff);
938 if(itr != mSpellPetAuraMap.end())
939 return &itr->second;
940 else
941 return NULL;
944 PetLevelupSpellSet const* GetPetLevelupSpellList(uint32 petFamily) const
946 PetLevelupSpellMap::const_iterator itr = mPetLevelupSpellMap.find(petFamily);
947 if(itr != mPetLevelupSpellMap.end())
948 return &itr->second;
949 else
950 return NULL;
953 // < 0 for petspelldata id, > 0 for creature_id
954 PetDefaultSpellsEntry const* GetPetDefaultSpellsEntry(int32 id) const
956 PetDefaultSpellsMap::const_iterator itr = mPetDefaultSpellsMap.find(id);
957 if(itr != mPetDefaultSpellsMap.end())
958 return &itr->second;
959 return NULL;
962 SpellCastResult GetSpellAllowedInLocationError(SpellEntry const *spellInfo, uint32 map_id, uint32 zone_id, uint32 area_id, Player const* player = NULL);
964 SpellAreaMapBounds GetSpellAreaMapBounds(uint32 spell_id) const
966 return SpellAreaMapBounds(mSpellAreaMap.lower_bound(spell_id),mSpellAreaMap.upper_bound(spell_id));
969 SpellAreaForQuestMapBounds GetSpellAreaForQuestMapBounds(uint32 quest_id, bool active) const
971 if(active)
972 return SpellAreaForQuestMapBounds(mSpellAreaForActiveQuestMap.lower_bound(quest_id),mSpellAreaForActiveQuestMap.upper_bound(quest_id));
973 else
974 return SpellAreaForQuestMapBounds(mSpellAreaForQuestMap.lower_bound(quest_id),mSpellAreaForQuestMap.upper_bound(quest_id));
977 SpellAreaForQuestMapBounds GetSpellAreaForQuestEndMapBounds(uint32 quest_id) const
979 return SpellAreaForQuestMapBounds(mSpellAreaForQuestEndMap.lower_bound(quest_id),mSpellAreaForQuestEndMap.upper_bound(quest_id));
982 SpellAreaForAuraMapBounds GetSpellAreaForAuraMapBounds(uint32 spell_id) const
984 return SpellAreaForAuraMapBounds(mSpellAreaForAuraMap.lower_bound(spell_id),mSpellAreaForAuraMap.upper_bound(spell_id));
987 SpellAreaForAreaMapBounds GetSpellAreaForAreaMapBounds(uint32 area_id) const
989 return SpellAreaForAreaMapBounds(mSpellAreaForAreaMap.lower_bound(area_id),mSpellAreaForAreaMap.upper_bound(area_id));
992 // Modifiers
993 public:
994 static SpellMgr& Instance();
996 void CheckUsedSpells(char const* table);
998 // Loading data at server startup
999 void LoadSpellChains();
1000 void LoadSpellLearnSkills();
1001 void LoadSpellLearnSpells();
1002 void LoadSpellScriptTarget();
1003 void LoadSpellElixirs();
1004 void LoadSpellProcEvents();
1005 void LoadSpellProcItemEnchant();
1006 void LoadSpellBonusess();
1007 void LoadSpellTargetPositions();
1008 void LoadSpellThreats();
1009 void LoadSkillLineAbilityMap();
1010 void LoadSpellPetAuras();
1011 void LoadPetLevelupSpellMap();
1012 void LoadPetDefaultSpells();
1013 void LoadSpellAreas();
1015 private:
1016 SpellScriptTarget mSpellScriptTarget;
1017 SpellChainMap mSpellChains;
1018 SpellChainMapNext mSpellChainsNext;
1019 SpellLearnSkillMap mSpellLearnSkills;
1020 SpellLearnSpellMap mSpellLearnSpells;
1021 SpellTargetPositionMap mSpellTargetPositions;
1022 SpellElixirMap mSpellElixirs;
1023 SpellThreatMap mSpellThreatMap;
1024 SpellProcEventMap mSpellProcEventMap;
1025 SpellProcItemEnchantMap mSpellProcItemEnchantMap;
1026 SpellBonusMap mSpellBonusMap;
1027 SkillLineAbilityMap mSkillLineAbilityMap;
1028 SpellPetAuraMap mSpellPetAuraMap;
1029 PetLevelupSpellMap mPetLevelupSpellMap;
1030 PetDefaultSpellsMap mPetDefaultSpellsMap; // only spells not listed in related mPetLevelupSpellMap entry
1031 SpellAreaMap mSpellAreaMap;
1032 SpellAreaForQuestMap mSpellAreaForQuestMap;
1033 SpellAreaForQuestMap mSpellAreaForActiveQuestMap;
1034 SpellAreaForQuestMap mSpellAreaForQuestEndMap;
1035 SpellAreaForAuraMap mSpellAreaForAuraMap;
1036 SpellAreaForAreaMap mSpellAreaForAreaMap;
1039 #define sSpellMgr SpellMgr::Instance()
1040 #endif