[8298] Use new Aura::HandleSpellSpecificBoosts for apply/remove dependent auras.
[getmangos.git] / src / game / SpellMgr.h
blob05ec8dae9097bcd8a4a8ae7b7ad8a0f371aa247e
1 /*
2 * Copyright (C) 2005-2009 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
46 enum SpellFamilyNames
48 SPELLFAMILY_GENERIC = 0,
49 SPELLFAMILY_UNK1 = 1, // events, holidays
50 // 2 - unused
51 SPELLFAMILY_MAGE = 3,
52 SPELLFAMILY_WARRIOR = 4,
53 SPELLFAMILY_WARLOCK = 5,
54 SPELLFAMILY_PRIEST = 6,
55 SPELLFAMILY_DRUID = 7,
56 SPELLFAMILY_ROGUE = 8,
57 SPELLFAMILY_HUNTER = 9,
58 SPELLFAMILY_PALADIN = 10,
59 SPELLFAMILY_SHAMAN = 11,
60 SPELLFAMILY_UNK2 = 12, // 2 spells (silence resistance)
61 SPELLFAMILY_POTION = 13,
62 // 14 - unused
63 SPELLFAMILY_DEATHKNIGHT = 15,
64 // 16 - unused
65 SPELLFAMILY_PET = 17
68 //Some SpellFamilyFlags
69 #define SPELLFAMILYFLAG_ROGUE_VANISH UI64LIT(0x0000000000000800)
70 #define SPELLFAMILYFLAG_ROGUE_STEALTH UI64LIT(0x0000000000400000)
71 #define SPELLFAMILYFLAG_ROGUE_BACKSTAB UI64LIT(0x0000000000800004)
72 #define SPELLFAMILYFLAG_ROGUE_SAP UI64LIT(0x0000000000000080)
73 #define SPELLFAMILYFLAG_ROGUE_FEINT UI64LIT(0x0000000008000000)
74 #define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT UI64LIT(0x0000000000200000)
75 #define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE UI64LIT(0x00000009003E0000)
77 #define SPELLFAMILYFLAG_PALADIN_SEALS UI64LIT(0x26000C000A000000)
79 // Spell clasification
80 enum SpellSpecific
82 SPELL_NORMAL = 0,
83 SPELL_SEAL = 1,
84 SPELL_BLESSING = 2,
85 SPELL_AURA = 3,
86 SPELL_STING = 4,
87 SPELL_CURSE = 5,
88 SPELL_ASPECT = 6,
89 SPELL_TRACKER = 7,
90 SPELL_WARLOCK_ARMOR = 8,
91 SPELL_MAGE_ARMOR = 9,
92 SPELL_ELEMENTAL_SHIELD = 10,
93 SPELL_MAGE_POLYMORPH = 11,
94 SPELL_POSITIVE_SHOUT = 12,
95 SPELL_JUDGEMENT = 13,
96 SPELL_BATTLE_ELIXIR = 14,
97 SPELL_GUARDIAN_ELIXIR = 15,
98 SPELL_FLASK_ELIXIR = 16,
99 SPELL_PRESENCE = 17
102 SpellSpecific GetSpellSpecific(uint32 spellId);
104 // Different spell properties
105 inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); }
106 uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL);
107 inline float GetSpellMinRange(SpellRangeEntry const *range, bool friendly = false)
109 if(!range)
110 return 0;
111 return (friendly ? range->minRangeFriendly : range->minRange);
113 inline float GetSpellMaxRange(SpellRangeEntry const *range, bool friendly = false)
115 if(!range)
116 return 0;
117 return (friendly ? range->maxRangeFriendly : range->maxRange);
119 inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; }
120 int32 GetSpellDuration(SpellEntry const *spellInfo);
121 int32 GetSpellMaxDuration(SpellEntry const *spellInfo);
123 inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
125 for(int i = 0; i < 3; ++i)
126 if(SpellEffects(spellInfo->Effect[i])==effect)
127 return true;
128 return false;
131 inline bool IsSpellHaveAura(SpellEntry const *spellInfo, AuraType aura)
133 for(int i = 0; i < 3; ++i)
134 if(AuraType(spellInfo->EffectApplyAuraName[i])==aura)
135 return true;
136 return false;
139 inline bool IsSpellLastAuraEffect(SpellEntry const *spellInfo, int effecIdx)
141 for(int i = effecIdx+1; i < 3; ++i)
142 if(spellInfo->EffectApplyAuraName[i])
143 return false;
144 return true;
147 bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
149 inline bool IsSealSpell(SpellEntry const *spellInfo)
151 //Collection of all the seal family flags. No other paladin spell has any of those.
152 return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN &&
153 ( spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_PALADIN_SEALS );
156 inline bool IsElementalShield(SpellEntry const *spellInfo)
158 // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus
159 return (spellInfo->SpellFamilyFlags & UI64LIT(0x42000000400)) || spellInfo->Id == 23552;
162 inline bool IsExplicitDiscoverySpell(SpellEntry const *spellInfo)
164 return spellInfo->Effect[0] == SPELL_EFFECT_CREATE_RANDOM_ITEM
165 && spellInfo->Effect[1] == SPELL_EFFECT_SCRIPT_EFFECT
166 || spellInfo->Id == 64323; // Book of Glyph Mastery (Effect0==SPELL_EFFECT_SCRIPT_EFFECT without any other data)
169 inline bool IsLootCraftingSpell(SpellEntry const *spellInfo)
171 return spellInfo->Effect[0]==SPELL_EFFECT_CREATE_RANDOM_ITEM ||
172 // different random cards from Inscription (121==Virtuoso Inking Set category)
173 spellInfo->Effect[0]==SPELL_EFFECT_CREATE_ITEM_2 && spellInfo->TotemCategory[0] == 121;
176 int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
177 bool IsSingleFromSpellSpecificPerCaster(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
178 bool IsSingleFromSpellSpecificRanksPerTarget(SpellSpecific spellId_spec, SpellSpecific i_spellId_spec);
179 bool IsPassiveSpell(uint32 spellId);
181 inline bool IsPassiveSpellStackableWithRanks(SpellEntry const* spellProto)
183 if(!IsPassiveSpell(spellProto->Id))
184 return false;
186 return !IsSpellHaveEffect(spellProto,SPELL_EFFECT_APPLY_AURA);
190 inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo)
192 return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT;
195 inline bool IsNonCombatSpell(SpellEntry const *spellInfo)
197 return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0;
200 bool IsPositiveSpell(uint32 spellId);
201 bool IsPositiveEffect(uint32 spellId, uint32 effIndex);
202 bool IsPositiveTarget(uint32 targetA, uint32 targetB);
204 bool IsSingleTargetSpell(SpellEntry const *spellInfo);
205 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);
207 inline bool IsCasterSourceTarget(uint32 target)
209 switch (target )
211 case TARGET_SELF:
212 case TARGET_PET:
213 case TARGET_ALL_PARTY_AROUND_CASTER:
214 case TARGET_IN_FRONT_OF_CASTER:
215 case TARGET_MASTER:
216 case TARGET_MINION:
217 case TARGET_ALL_PARTY:
218 case TARGET_ALL_PARTY_AROUND_CASTER_2:
219 case TARGET_SELF_FISHING:
220 case TARGET_TOTEM_EARTH:
221 case TARGET_TOTEM_WATER:
222 case TARGET_TOTEM_AIR:
223 case TARGET_TOTEM_FIRE:
224 case TARGET_SUMMON:
225 case TARGET_AREAEFFECT_CUSTOM_2:
226 case TARGET_ALL_RAID_AROUND_CASTER:
227 case TARGET_SELF2:
228 case TARGET_DIRECTLY_FORWARD:
229 case TARGET_NONCOMBAT_PET:
230 case TARGET_IN_FRONT_OF_CASTER_30:
231 return true;
232 default:
233 break;
235 return false;
238 inline bool IsSpellWithCasterSourceTargetsOnly(SpellEntry const* spellInfo)
240 for(int i = 0; i < 3; ++i)
241 if(uint32 target = spellInfo->EffectImplicitTargetA[i])
242 if(!IsCasterSourceTarget(target))
243 return false;
244 return true;
247 inline bool IsPointEffectTarget( Targets target )
249 switch (target )
251 case TARGET_INNKEEPER_COORDINATES:
252 case TARGET_TABLE_X_Y_Z_COORDINATES:
253 case TARGET_CASTER_COORDINATES:
254 case TARGET_SCRIPT_COORDINATES:
255 case TARGET_CURRENT_ENEMY_COORDINATES:
256 case TARGET_DUELVSPLAYER_COORDINATES:
257 case TARGET_DYNAMIC_OBJECT_COORDINATES:
258 return true;
259 default:
260 break;
262 return false;
265 inline bool IsAreaEffectTarget( Targets target )
267 switch (target )
269 case TARGET_AREAEFFECT_INSTANT:
270 case TARGET_AREAEFFECT_CUSTOM:
271 case TARGET_ALL_ENEMY_IN_AREA:
272 case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
273 case TARGET_ALL_PARTY_AROUND_CASTER:
274 case TARGET_IN_FRONT_OF_CASTER:
275 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
276 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
277 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
278 case TARGET_ALL_PARTY:
279 case TARGET_ALL_PARTY_AROUND_CASTER_2:
280 case TARGET_AREAEFFECT_PARTY:
281 case TARGET_AREAEFFECT_CUSTOM_2:
282 case TARGET_ALL_RAID_AROUND_CASTER:
283 case TARGET_AREAEFFECT_PARTY_AND_CLASS:
284 case TARGET_IN_FRONT_OF_CASTER_30:
285 return true;
286 default:
287 break;
289 return false;
292 inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo)
294 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0])))
295 return true;
296 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1])))
297 return true;
298 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2])))
299 return true;
300 return false;
303 inline bool IsAreaAuraEffect(uint32 effect)
305 if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
306 effect == SPELL_EFFECT_APPLY_AREA_AURA_RAID ||
307 effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND ||
308 effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY ||
309 effect == SPELL_EFFECT_APPLY_AREA_AURA_PET ||
310 effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER)
311 return true;
312 return false;
315 inline bool IsDispelSpell(SpellEntry const *spellInfo)
317 if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL ||
318 spellInfo->Effect[1] == SPELL_EFFECT_DISPEL ||
319 spellInfo->Effect[2] == SPELL_EFFECT_DISPEL )
320 return true;
321 return false;
323 inline bool isSpellBreakStealth(SpellEntry const* spellInfo)
325 return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH);
328 inline bool IsAutoRepeatRangedSpell(SpellEntry const* spellInfo)
330 return (spellInfo->Attributes & SPELL_ATTR_RANGED) && (spellInfo->AttributesEx2 & SPELL_ATTR_EX2_AUTOREPEAT_FLAG);
333 SpellCastResult GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form);
335 inline bool IsChanneledSpell(SpellEntry const* spellInfo)
337 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2));
340 inline bool NeedsComboPoints(SpellEntry const* spellInfo)
342 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2));
345 inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo)
347 return SpellSchoolMask(spellInfo->SchoolMask);
350 inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect)
352 uint32 mask = 0;
353 if (spellInfo->Mechanic)
354 mask |= 1<<spellInfo->Mechanic;
355 if (spellInfo->EffectMechanic[effect])
356 mask |= 1<<spellInfo->EffectMechanic[effect];
357 return mask;
360 inline uint32 GetAllSpellMechanicMask(SpellEntry const* spellInfo)
362 uint32 mask = 0;
363 if (spellInfo->Mechanic)
364 mask |= 1<<spellInfo->Mechanic;
365 for (int i=0; i< 3; ++i)
366 if (spellInfo->EffectMechanic[i])
367 mask |= 1<<spellInfo->EffectMechanic[i];
368 return mask;
371 inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect)
373 if (spellInfo->EffectMechanic[effect])
374 return Mechanics(spellInfo->EffectMechanic[effect]);
375 if (spellInfo->Mechanic)
376 return Mechanics(spellInfo->Mechanic);
377 return MECHANIC_NONE;
380 inline uint32 GetDispellMask(DispelType dispel)
382 // If dispell all
383 if (dispel == DISPEL_ALL)
384 return DISPEL_ALL_MASK;
385 else
386 return (1 << dispel);
389 // Diminishing Returns interaction with spells
390 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered);
391 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
392 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group);
393 int32 GetDiminishingReturnsLimitDuration(DiminishingGroup group, SpellEntry const* spellproto);
395 // Spell proc event related declarations (accessed using SpellMgr functions)
396 enum ProcFlags
398 PROC_FLAG_NONE = 0x00000000,
400 PROC_FLAG_KILLED = 0x00000001, // 00 Killed by agressor
401 PROC_FLAG_KILL = 0x00000002, // 01 Kill target (in most cases need XP/Honor reward)
403 PROC_FLAG_SUCCESSFUL_MILEE_HIT = 0x00000004, // 02 Successful melee auto attack
404 PROC_FLAG_TAKEN_MELEE_HIT = 0x00000008, // 03 Taken damage from melee auto attack hit
406 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT = 0x00000010, // 04 Successful attack by Spell that use melee weapon
407 PROC_FLAG_TAKEN_MELEE_SPELL_HIT = 0x00000020, // 05 Taken damage by Spell that use melee weapon
409 PROC_FLAG_SUCCESSFUL_RANGED_HIT = 0x00000040, // 06 Successful Ranged auto attack
410 PROC_FLAG_TAKEN_RANGED_HIT = 0x00000080, // 07 Taken damage from ranged auto attack
412 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT = 0x00000100, // 08 Successful Ranged attack by Spell that use ranged weapon
413 PROC_FLAG_TAKEN_RANGED_SPELL_HIT = 0x00000200, // 09 Taken damage by Spell that use ranged weapon
415 PROC_FLAG_SUCCESSFUL_POSITIVE_AOE_HIT = 0x00000400, // 10 Successful AoE (not 100% shure unused)
416 PROC_FLAG_TAKEN_POSITIVE_AOE = 0x00000800, // 11 Taken AoE (not 100% shure unused)
418 PROC_FLAG_SUCCESSFUL_AOE_SPELL_HIT = 0x00001000, // 12 Successful AoE damage spell hit (not 100% shure unused)
419 PROC_FLAG_TAKEN_AOE_SPELL_HIT = 0x00002000, // 13 Taken AoE damage spell hit (not 100% shure unused)
421 PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL = 0x00004000, // 14 Successful cast positive spell (by default only on healing)
422 PROC_FLAG_TAKEN_POSITIVE_SPELL = 0x00008000, // 15 Taken positive spell hit (by default only on healing)
424 PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT = 0x00010000, // 16 Successful negative spell cast (by default only on damage)
425 PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT = 0x00020000, // 17 Taken negative spell (by default only on damage)
427 PROC_FLAG_ON_DO_PERIODIC = 0x00040000, // 18 Successful do periodic (damage / healing, determined from 14-17 flags)
428 PROC_FLAG_ON_TAKE_PERIODIC = 0x00080000, // 19 Taken spell periodic (damage / healing, determined from 14-17 flags)
430 PROC_FLAG_TAKEN_ANY_DAMAGE = 0x00100000, // 20 Taken any damage
431 PROC_FLAG_ON_TRAP_ACTIVATION = 0x00200000, // 21 On trap activation
433 PROC_FLAG_TAKEN_OFFHAND_HIT = 0x00400000, // 22 Taken off-hand melee attacks(not used)
434 PROC_FLAG_SUCCESSFUL_OFFHAND_HIT = 0x00800000 // 23 Successful off-hand melee attacks
437 #define MELEE_BASED_TRIGGER_MASK (PROC_FLAG_SUCCESSFUL_MILEE_HIT | \
438 PROC_FLAG_TAKEN_MELEE_HIT | \
439 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT | \
440 PROC_FLAG_TAKEN_MELEE_SPELL_HIT | \
441 PROC_FLAG_SUCCESSFUL_RANGED_HIT | \
442 PROC_FLAG_TAKEN_RANGED_HIT | \
443 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT | \
444 PROC_FLAG_TAKEN_RANGED_SPELL_HIT)
446 enum ProcFlagsEx
448 PROC_EX_NONE = 0x0000000, // If none can tigger on Hit/Crit only (passive spells MUST defined by SpellFamily flag)
449 PROC_EX_NORMAL_HIT = 0x0000001, // If set only from normal hit (only damage spells)
450 PROC_EX_CRITICAL_HIT = 0x0000002,
451 PROC_EX_MISS = 0x0000004,
452 PROC_EX_RESIST = 0x0000008,
453 PROC_EX_DODGE = 0x0000010,
454 PROC_EX_PARRY = 0x0000020,
455 PROC_EX_BLOCK = 0x0000040,
456 PROC_EX_EVADE = 0x0000080,
457 PROC_EX_IMMUNE = 0x0000100,
458 PROC_EX_DEFLECT = 0x0000200,
459 PROC_EX_ABSORB = 0x0000400,
460 PROC_EX_REFLECT = 0x0000800,
461 PROC_EX_INTERRUPT = 0x0001000, // Melee hit result can be Interrupt (not used)
462 PROC_EX_RESERVED1 = 0x0002000,
463 PROC_EX_RESERVED2 = 0x0004000,
464 PROC_EX_RESERVED3 = 0x0008000,
465 PROC_EX_EX_TRIGGER_ALWAYS = 0x0010000, // If set trigger always ( no matter another flags) used for drop charges
466 PROC_EX_EX_ONE_TIME_TRIGGER = 0x0020000 // If set trigger always but only one time (not used)
469 struct SpellProcEventEntry
471 uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2
472 uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value
473 uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do)
474 uint32 spellFamilyMask2; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags2 (like auras 107 and 108 do)
475 uint32 procFlags; // bitmask for matching proc event
476 uint32 procEx; // proc Extend info (see ProcFlagsEx)
477 float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc
478 float customChance; // Owerride chance (in most cases for debug only)
479 uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_
482 struct SpellBonusEntry
484 float direct_damage;
485 float dot_damage;
486 float ap_bonus;
489 typedef UNORDERED_MAP<uint32, SpellProcEventEntry> SpellProcEventMap;
490 typedef UNORDERED_MAP<uint32, SpellBonusEntry> SpellBonusMap;
492 #define ELIXIR_BATTLE_MASK 0x1
493 #define ELIXIR_GUARDIAN_MASK 0x2
494 #define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK)
495 #define ELIXIR_UNSTABLE_MASK 0x4
496 #define ELIXIR_SHATTRATH_MASK 0x8
498 typedef std::map<uint32, uint8> SpellElixirMap;
499 typedef std::map<uint32, float> SpellProcItemEnchantMap;
500 typedef std::map<uint32, uint16> SpellThreatMap;
502 // Spell script target related declarations (accessed using SpellMgr functions)
503 enum SpellTargetType
505 SPELL_TARGET_TYPE_GAMEOBJECT = 0,
506 SPELL_TARGET_TYPE_CREATURE = 1,
507 SPELL_TARGET_TYPE_DEAD = 2
510 #define MAX_SPELL_TARGET_TYPE 3
512 struct SpellTargetEntry
514 SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {}
515 SpellTargetType type;
516 uint32 targetEntry;
519 typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
521 // coordinates for spells (accessed using SpellMgr functions)
522 struct SpellTargetPosition
524 uint32 target_mapId;
525 float target_X;
526 float target_Y;
527 float target_Z;
528 float target_Orientation;
531 typedef UNORDERED_MAP<uint32, SpellTargetPosition> SpellTargetPositionMap;
533 // Spell pet auras
534 class PetAura
536 public:
537 PetAura()
539 auras.clear();
542 PetAura(uint32 petEntry, uint32 aura, bool _removeOnChangePet, int _damage) :
543 removeOnChangePet(_removeOnChangePet), damage(_damage)
545 auras[petEntry] = aura;
548 uint32 GetAura(uint32 petEntry) const
550 std::map<uint32, uint32>::const_iterator itr = auras.find(petEntry);
551 if(itr != auras.end())
552 return itr->second;
553 else
555 std::map<uint32, uint32>::const_iterator itr2 = auras.find(0);
556 if(itr2 != auras.end())
557 return itr2->second;
558 else
559 return 0;
563 void AddAura(uint32 petEntry, uint32 aura)
565 auras[petEntry] = aura;
568 bool IsRemovedOnChangePet() const
570 return removeOnChangePet;
573 int32 GetDamage() const
575 return damage;
578 private:
579 std::map<uint32, uint32> auras;
580 bool removeOnChangePet;
581 int32 damage;
583 typedef std::map<uint32, PetAura> SpellPetAuraMap;
585 struct SpellArea
587 uint32 spellId;
588 uint32 areaId; // zone/subzone/or 0 is not limited to zone
589 uint32 questStart; // quest start (quest must be active or rewarded for spell apply)
590 uint32 questEnd; // quest end (quest don't must be rewarded for spell apply)
591 int32 auraSpell; // spell aura must be applied for spell apply )if possitive) and it don't must be applied in other case
592 uint32 raceMask; // can be applied only to races
593 Gender gender; // can be applied only to gender
594 bool questStartCanActive; // if true then quest start can be active (not only rewarded)
595 bool autocast; // if true then auto applied at area enter, in other case just allowed to cast
597 // helpers
598 bool IsFitToRequirements(Player const* player, uint32 newZone, uint32 newArea) const;
601 typedef std::multimap<uint32,SpellArea> SpellAreaMap;
602 typedef std::multimap<uint32,SpellArea const*> SpellAreaForQuestMap;
603 typedef std::multimap<uint32,SpellArea const*> SpellAreaForAuraMap;
604 typedef std::multimap<uint32,SpellArea const*> SpellAreaForAreaMap;
605 typedef std::pair<SpellAreaMap::const_iterator,SpellAreaMap::const_iterator> SpellAreaMapBounds;
606 typedef std::pair<SpellAreaForQuestMap::const_iterator,SpellAreaForQuestMap::const_iterator> SpellAreaForQuestMapBounds;
607 typedef std::pair<SpellAreaForAuraMap::const_iterator, SpellAreaForAuraMap::const_iterator> SpellAreaForAuraMapBounds;
608 typedef std::pair<SpellAreaForAreaMap::const_iterator, SpellAreaForAreaMap::const_iterator> SpellAreaForAreaMapBounds;
611 // Spell rank chain (accessed using SpellMgr functions)
612 struct SpellChainNode
614 uint32 prev;
615 uint32 first;
616 uint32 req;
617 uint8 rank;
620 typedef UNORDERED_MAP<uint32, SpellChainNode> SpellChainMap;
621 typedef std::multimap<uint32, uint32> SpellChainMapNext;
623 // Spell learning properties (accessed using SpellMgr functions)
624 struct SpellLearnSkillNode
626 uint32 skill;
627 uint32 value; // 0 - max skill value for player level
628 uint32 maxvalue; // 0 - max skill value for player level
631 typedef std::map<uint32, SpellLearnSkillNode> SpellLearnSkillMap;
633 struct SpellLearnSpellNode
635 uint32 spell;
636 bool active; // show in spellbook or not
637 bool autoLearned;
640 typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
642 typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
644 typedef std::multimap<uint32, uint32> PetLevelupSpellSet;
645 typedef std::map<uint32, PetLevelupSpellSet> PetLevelupSpellMap;
647 struct PetDefaultSpellsEntry
649 uint32 spellid[MAX_CREATURE_SPELL_DATA_SLOT];
652 // < 0 for petspelldata id, > 0 for creature_id
653 typedef std::map<int32, PetDefaultSpellsEntry> PetDefaultSpellsMap;
656 inline bool IsPrimaryProfessionSkill(uint32 skill)
658 SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill);
659 if(!pSkill)
660 return false;
662 if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
663 return false;
665 return true;
668 inline bool IsProfessionSkill(uint32 skill)
670 return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
673 inline bool IsProfessionOrRidingSkill(uint32 skill)
675 return IsProfessionSkill(skill) || skill == SKILL_RIDING;
678 class SpellMgr
680 friend struct DoSpellBonusess;
681 friend struct DoSpellProcEvent;
682 friend struct DoSpellProcItemEnchant;
684 // Constructors
685 public:
686 SpellMgr();
687 ~SpellMgr();
689 // Accessors (const or static functions)
690 public:
692 bool IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const;
694 SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }
696 uint32 GetSpellElixirMask(uint32 spellid) const
698 SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid);
699 if(itr==mSpellElixirs.end())
700 return 0x0;
702 return itr->second;
705 SpellSpecific GetSpellElixirSpecific(uint32 spellid) const
707 uint32 mask = GetSpellElixirMask(spellid);
708 if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK)
709 return SPELL_FLASK_ELIXIR;
710 else if(mask & ELIXIR_BATTLE_MASK)
711 return SPELL_BATTLE_ELIXIR;
712 else if(mask & ELIXIR_GUARDIAN_MASK)
713 return SPELL_GUARDIAN_ELIXIR;
714 else
715 return SPELL_NORMAL;
718 uint16 GetSpellThreat(uint32 spellid) const
720 SpellThreatMap::const_iterator itr = mSpellThreatMap.find(spellid);
721 if(itr==mSpellThreatMap.end())
722 return 0;
724 return itr->second;
727 // Spell proc events
728 SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
730 SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
731 if( itr != mSpellProcEventMap.end( ) )
732 return &itr->second;
733 return NULL;
736 // Spell procs from item enchants
737 float GetItemEnchantProcChance(uint32 spellid) const
739 SpellProcItemEnchantMap::const_iterator itr = mSpellProcItemEnchantMap.find(spellid);
740 if(itr==mSpellProcItemEnchantMap.end())
741 return 0.0f;
743 return itr->second;
746 static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active);
748 // Spell bonus data
749 SpellBonusEntry const* GetSpellBonusData(uint32 spellId) const
751 // Lookup data
752 SpellBonusMap::const_iterator itr = mSpellBonusMap.find(spellId);
753 if( itr != mSpellBonusMap.end( ) )
754 return &itr->second;
756 return NULL;
759 // Spell target coordinates
760 SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const
762 SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id );
763 if( itr != mSpellTargetPositions.end( ) )
764 return &itr->second;
765 return NULL;
768 // Spell ranks chains
769 SpellChainNode const* GetSpellChainNode(uint32 spell_id) const
771 SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
772 if(itr == mSpellChains.end())
773 return NULL;
775 return &itr->second;
778 uint32 GetFirstSpellInChain(uint32 spell_id) const
780 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
781 return node->first;
783 return spell_id;
786 uint32 GetPrevSpellInChain(uint32 spell_id) const
788 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
789 return node->prev;
791 return 0;
794 SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; }
796 template<typename Worker>
797 void doForHighRanks(uint32 spellid, Worker& worker)
799 SpellChainMapNext const& nextMap = GetSpellChainNext();
800 for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
802 worker(itr->second);
803 doForHighRanks(itr->second,worker);
807 // Note: not use rank for compare to spell ranks: spell chains isn't linear order
808 // Use IsHighRankOfSpell instead
809 uint8 GetSpellRank(uint32 spell_id) const
811 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
812 return node->rank;
814 return 0;
817 uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const
819 SpellChainMap::const_iterator itr = mSpellChains.find(spell1);
821 uint32 rank2 = GetSpellRank(spell2);
823 // not ordered correctly by rank value
824 if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2)
825 return false;
827 // check present in same rank chain
828 for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev))
829 if(itr->second.prev==spell2)
830 return true;
832 return false;
835 bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const;
836 static bool canStackSpellRanks(SpellEntry const *spellInfo);
837 bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const;
839 SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const;
841 // Spell learning
842 SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const
844 SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id);
845 if(itr != mSpellLearnSkills.end())
846 return &itr->second;
847 else
848 return NULL;
851 bool IsSpellLearnSpell(uint32 spell_id) const
853 return mSpellLearnSpells.find(spell_id) != mSpellLearnSpells.end();
856 SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const
858 return mSpellLearnSpells.lower_bound(spell_id);
861 SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const
863 return mSpellLearnSpells.upper_bound(spell_id);
866 bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const
868 SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1);
869 SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1);
870 for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i)
871 if(i->second.spell==spell_id2)
872 return true;
873 return false;
876 static bool IsProfessionOrRidingSpell(uint32 spellId);
877 static bool IsProfessionSpell(uint32 spellId);
878 static bool IsPrimaryProfessionSpell(uint32 spellId);
879 bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const;
881 bool IsSkillBonusSpell(uint32 spellId) const;
884 // Spell script targets
885 SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const
887 return mSpellScriptTarget.lower_bound(spell_id);
890 SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const
892 return mSpellScriptTarget.upper_bound(spell_id);
895 // Spell correctess for client using
896 static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true);
898 SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const
900 return mSkillLineAbilityMap.lower_bound(spell_id);
903 SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const
905 return mSkillLineAbilityMap.upper_bound(spell_id);
908 PetAura const* GetPetAura(uint32 spell_id, uint8 eff)
910 SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find((spell_id<<8) + eff);
911 if(itr != mSpellPetAuraMap.end())
912 return &itr->second;
913 else
914 return NULL;
917 PetLevelupSpellSet const* GetPetLevelupSpellList(uint32 petFamily) const
919 PetLevelupSpellMap::const_iterator itr = mPetLevelupSpellMap.find(petFamily);
920 if(itr != mPetLevelupSpellMap.end())
921 return &itr->second;
922 else
923 return NULL;
926 // < 0 for petspelldata id, > 0 for creature_id
927 PetDefaultSpellsEntry const* GetPetDefaultSpellsEntry(int32 id) const
929 PetDefaultSpellsMap::const_iterator itr = mPetDefaultSpellsMap.find(id);
930 if(itr != mPetDefaultSpellsMap.end())
931 return &itr->second;
932 return NULL;
935 SpellCastResult GetSpellAllowedInLocationError(SpellEntry const *spellInfo, uint32 map_id, uint32 zone_id, uint32 area_id, Player const* player = NULL);
937 SpellAreaMapBounds GetSpellAreaMapBounds(uint32 spell_id) const
939 return SpellAreaMapBounds(mSpellAreaMap.lower_bound(spell_id),mSpellAreaMap.upper_bound(spell_id));
942 SpellAreaForQuestMapBounds GetSpellAreaForQuestMapBounds(uint32 quest_id, bool active) const
944 if(active)
945 return SpellAreaForQuestMapBounds(mSpellAreaForActiveQuestMap.lower_bound(quest_id),mSpellAreaForActiveQuestMap.upper_bound(quest_id));
946 else
947 return SpellAreaForQuestMapBounds(mSpellAreaForQuestMap.lower_bound(quest_id),mSpellAreaForQuestMap.upper_bound(quest_id));
950 SpellAreaForQuestMapBounds GetSpellAreaForQuestEndMapBounds(uint32 quest_id) const
952 return SpellAreaForQuestMapBounds(mSpellAreaForQuestEndMap.lower_bound(quest_id),mSpellAreaForQuestEndMap.upper_bound(quest_id));
955 SpellAreaForAuraMapBounds GetSpellAreaForAuraMapBounds(uint32 spell_id) const
957 return SpellAreaForAuraMapBounds(mSpellAreaForAuraMap.lower_bound(spell_id),mSpellAreaForAuraMap.upper_bound(spell_id));
960 SpellAreaForAreaMapBounds GetSpellAreaForAreaMapBounds(uint32 area_id) const
962 return SpellAreaForAreaMapBounds(mSpellAreaForAreaMap.lower_bound(area_id),mSpellAreaForAreaMap.upper_bound(area_id));
965 // Modifiers
966 public:
967 static SpellMgr& Instance();
969 void CheckUsedSpells(char const* table);
971 // Loading data at server startup
972 void LoadSpellChains();
973 void LoadSpellLearnSkills();
974 void LoadSpellLearnSpells();
975 void LoadSpellScriptTarget();
976 void LoadSpellElixirs();
977 void LoadSpellProcEvents();
978 void LoadSpellProcItemEnchant();
979 void LoadSpellBonusess();
980 void LoadSpellTargetPositions();
981 void LoadSpellThreats();
982 void LoadSkillLineAbilityMap();
983 void LoadSpellPetAuras();
984 void LoadPetLevelupSpellMap();
985 void LoadPetDefaultSpells();
986 void LoadSpellAreas();
988 private:
989 SpellScriptTarget mSpellScriptTarget;
990 SpellChainMap mSpellChains;
991 SpellChainMapNext mSpellChainsNext;
992 SpellLearnSkillMap mSpellLearnSkills;
993 SpellLearnSpellMap mSpellLearnSpells;
994 SpellTargetPositionMap mSpellTargetPositions;
995 SpellElixirMap mSpellElixirs;
996 SpellThreatMap mSpellThreatMap;
997 SpellProcEventMap mSpellProcEventMap;
998 SpellProcItemEnchantMap mSpellProcItemEnchantMap;
999 SpellBonusMap mSpellBonusMap;
1000 SkillLineAbilityMap mSkillLineAbilityMap;
1001 SpellPetAuraMap mSpellPetAuraMap;
1002 PetLevelupSpellMap mPetLevelupSpellMap;
1003 PetDefaultSpellsMap mPetDefaultSpellsMap; // only spells not listed in related mPetLevelupSpellMap entry
1004 SpellAreaMap mSpellAreaMap;
1005 SpellAreaForQuestMap mSpellAreaForQuestMap;
1006 SpellAreaForQuestMap mSpellAreaForActiveQuestMap;
1007 SpellAreaForQuestMap mSpellAreaForQuestEndMap;
1008 SpellAreaForAuraMap mSpellAreaForAuraMap;
1009 SpellAreaForAreaMap mSpellAreaForAreaMap;
1012 #define spellmgr SpellMgr::Instance()
1013 #endif