[7716] Fixed some typos and possible crashes.
[AHbot.git] / src / game / SpellMgr.h
blob8061dbee314a7d94803b6cbc2061e45753456ab0
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 "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 // only used in code
41 enum SpellCategories
43 SPELLCATEGORY_HEALTH_MANA_POTIONS = 4,
44 SPELLCATEGORY_DEVOUR_MAGIC = 12
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 0x000000800LL
71 #define SPELLFAMILYFLAG_ROGUE_STEALTH 0x000400000LL
72 #define SPELLFAMILYFLAG_ROGUE_BACKSTAB 0x000800004LL
73 #define SPELLFAMILYFLAG_ROGUE_SAP 0x000000080LL
74 #define SPELLFAMILYFLAG_ROGUE_FEINT 0x008000000LL
75 #define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT 0x000200000LL
76 #define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE 0x9003E0000LL
78 #define SPELLFAMILYFLAG_PALADIN_SEALS 0x26000C000A000000LL
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) { return (range ? range->minRange : 0); }
108 inline float GetSpellMaxRange(SpellRangeEntry const *range) { return (range ? range->maxRange : 0); }
109 inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; }
110 int32 GetSpellDuration(SpellEntry const *spellInfo);
111 int32 GetSpellMaxDuration(SpellEntry const *spellInfo);
113 inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
115 for(int i= 0; i < 3; ++i)
116 if(SpellEffects(spellInfo->Effect[i])==effect)
117 return true;
118 return false;
121 bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
123 inline bool IsSealSpell(SpellEntry const *spellInfo)
125 //Collection of all the seal family flags. No other paladin spell has any of those.
126 return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN &&
127 ( spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_PALADIN_SEALS );
130 inline bool IsElementalShield(SpellEntry const *spellInfo)
132 // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus
133 return (spellInfo->SpellFamilyFlags & 0x42000000400LL) || spellInfo->Id == 23552;
136 inline bool IsExplicitDiscoverySpell(SpellEntry const *spellInfo)
138 return spellInfo->Effect[0]==SPELL_EFFECT_CREATE_ITEM_2 && spellInfo->Effect[1]==SPELL_EFFECT_SCRIPT_EFFECT;
141 inline bool IsLootCraftingSpell(SpellEntry const *spellInfo)
143 return spellInfo->Effect[0]==SPELL_EFFECT_CREATE_ITEM_2 &&
144 (spellInfo->Effect[1]==SPELL_EFFECT_SCRIPT_EFFECT || !spellInfo->EffectItemType[0]);
147 int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
148 bool IsSingleFromSpellSpecificPerCaster(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
149 bool IsSingleFromSpellSpecificRanksPerTarget(SpellSpecific spellId_spec, SpellSpecific i_spellId_spec);
150 bool IsPassiveSpell(uint32 spellId);
152 inline bool IsPassiveSpellStackableWithRanks(SpellEntry const* spellProto)
154 if(!IsPassiveSpell(spellProto->Id))
155 return false;
157 return !IsSpellHaveEffect(spellProto,SPELL_EFFECT_APPLY_AURA);
161 inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo)
163 return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT;
166 inline bool IsNonCombatSpell(SpellEntry const *spellInfo)
168 return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0;
171 bool IsPositiveSpell(uint32 spellId);
172 bool IsPositiveEffect(uint32 spellId, uint32 effIndex);
173 bool IsPositiveTarget(uint32 targetA, uint32 targetB);
175 bool IsSingleTargetSpell(SpellEntry const *spellInfo);
176 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);
178 bool IsAuraAddedBySpell(uint32 auraType, uint32 spellId);
180 inline bool IsAreaEffectTarget( Targets target )
182 switch (target )
184 case TARGET_AREAEFFECT_INSTANT:
185 case TARGET_AREAEFFECT_CUSTOM:
186 case TARGET_ALL_ENEMY_IN_AREA:
187 case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
188 case TARGET_ALL_PARTY_AROUND_CASTER:
189 case TARGET_IN_FRONT_OF_CASTER:
190 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
191 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
192 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
193 case TARGET_ALL_PARTY:
194 case TARGET_ALL_PARTY_AROUND_CASTER_2:
195 case TARGET_AREAEFFECT_PARTY:
196 case TARGET_AREAEFFECT_CUSTOM_2:
197 case TARGET_ALL_RAID_AROUND_CASTER:
198 case TARGET_AREAEFFECT_PARTY_AND_CLASS:
199 return true;
200 default:
201 break;
203 return false;
206 inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo)
208 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0])))
209 return true;
210 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1])))
211 return true;
212 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2])))
213 return true;
214 return false;
217 inline bool IsAreaAuraEffect(uint32 effect)
219 if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
220 effect == SPELL_EFFECT_APPLY_AREA_AURA_RAID ||
221 effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND ||
222 effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY ||
223 effect == SPELL_EFFECT_APPLY_AREA_AURA_PET ||
224 effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER)
225 return true;
226 return false;
229 inline bool IsDispelSpell(SpellEntry const *spellInfo)
231 if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL ||
232 spellInfo->Effect[1] == SPELL_EFFECT_DISPEL ||
233 spellInfo->Effect[2] == SPELL_EFFECT_DISPEL )
234 return true;
235 return false;
237 inline bool isSpellBreakStealth(SpellEntry const* spellInfo)
239 return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH);
242 inline bool IsAutoRepeatRangedSpell(SpellEntry const* spellInfo)
244 return (spellInfo->Attributes & SPELL_ATTR_RANGED) && (spellInfo->AttributesEx2 & SPELL_ATTR_EX2_AUTOREPEAT_FLAG);
247 SpellCastResult GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form);
249 inline bool IsChanneledSpell(SpellEntry const* spellInfo)
251 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2));
254 inline bool NeedsComboPoints(SpellEntry const* spellInfo)
256 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2));
259 inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo)
261 return SpellSchoolMask(spellInfo->SchoolMask);
264 inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect)
266 uint32 mask = 0;
267 if (spellInfo->Mechanic)
268 mask |= 1<<spellInfo->Mechanic;
269 if (spellInfo->EffectMechanic[effect])
270 mask |= 1<<spellInfo->EffectMechanic[effect];
271 return mask;
274 inline uint32 GetAllSpellMechanicMask(SpellEntry const* spellInfo)
276 uint32 mask = 0;
277 if (spellInfo->Mechanic)
278 mask |= 1<<spellInfo->Mechanic;
279 for (int i=0; i< 3; ++i)
280 if (spellInfo->EffectMechanic[i])
281 mask |= 1<<spellInfo->EffectMechanic[i];
282 return mask;
285 inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect)
287 if (spellInfo->EffectMechanic[effect])
288 return Mechanics(spellInfo->EffectMechanic[effect]);
289 if (spellInfo->Mechanic)
290 return Mechanics(spellInfo->Mechanic);
291 return MECHANIC_NONE;
294 inline uint32 GetDispellMask(DispelType dispel)
296 // If dispell all
297 if (dispel == DISPEL_ALL)
298 return DISPEL_ALL_MASK;
299 else
300 return (1 << dispel);
303 // Diminishing Returns interaction with spells
304 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered);
305 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
306 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group);
308 // Spell affects related declarations (accessed using SpellMgr functions)
309 struct SpellAffectEntry
311 uint32 SpellClassMask[3];
313 typedef UNORDERED_MAP<uint32, SpellAffectEntry> SpellAffectMap;
315 // Spell proc event related declarations (accessed using SpellMgr functions)
316 enum ProcFlags
318 PROC_FLAG_NONE = 0x00000000,
320 PROC_FLAG_KILLED = 0x00000001, // 00 Killed by agressor
321 PROC_FLAG_KILL = 0x00000002, // 01 Kill target (in most cases need XP/Honor reward)
323 PROC_FLAG_SUCCESSFUL_MILEE_HIT = 0x00000004, // 02 Successful melee auto attack
324 PROC_FLAG_TAKEN_MELEE_HIT = 0x00000008, // 03 Taken damage from melee auto attack hit
326 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT = 0x00000010, // 04 Successful attack by Spell that use melee weapon
327 PROC_FLAG_TAKEN_MELEE_SPELL_HIT = 0x00000020, // 05 Taken damage by Spell that use melee weapon
329 PROC_FLAG_SUCCESSFUL_RANGED_HIT = 0x00000040, // 06 Successful Ranged auto attack
330 PROC_FLAG_TAKEN_RANGED_HIT = 0x00000080, // 07 Taken damage from ranged auto attack
332 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT = 0x00000100, // 08 Successful Ranged attack by Spell that use ranged weapon
333 PROC_FLAG_TAKEN_RANGED_SPELL_HIT = 0x00000200, // 09 Taken damage by Spell that use ranged weapon
335 PROC_FLAG_SUCCESSFUL_POSITIVE_AOE_HIT = 0x00000400, // 10 Successful AoE (not 100% shure unused)
336 PROC_FLAG_TAKEN_POSITIVE_AOE = 0x00000800, // 11 Taken AoE (not 100% shure unused)
338 PROC_FLAG_SUCCESSFUL_AOE_SPELL_HIT = 0x00001000, // 12 Successful AoE damage spell hit (not 100% shure unused)
339 PROC_FLAG_TAKEN_AOE_SPELL_HIT = 0x00002000, // 13 Taken AoE damage spell hit (not 100% shure unused)
341 PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL = 0x00004000, // 14 Successful cast positive spell (by default only on healing)
342 PROC_FLAG_TAKEN_POSITIVE_SPELL = 0x00008000, // 15 Taken positive spell hit (by default only on healing)
344 PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT = 0x00010000, // 16 Successful negative spell cast (by default only on damage)
345 PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT = 0x00020000, // 17 Taken negative spell (by default only on damage)
347 PROC_FLAG_ON_DO_PERIODIC = 0x00040000, // 18 Successful do periodic (damage / healing, determined from 14-17 flags)
348 PROC_FLAG_ON_TAKE_PERIODIC = 0x00080000, // 19 Taken spell periodic (damage / healing, determined from 14-17 flags)
350 PROC_FLAG_TAKEN_ANY_DAMAGE = 0x00100000, // 20 Taken any damage
351 PROC_FLAG_ON_TRAP_ACTIVATION = 0x00200000, // 21 On trap activation
353 PROC_FLAG_TAKEN_OFFHAND_HIT = 0x00400000, // 22 Taken off-hand melee attacks(not used)
354 PROC_FLAG_SUCCESSFUL_OFFHAND_HIT = 0x00800000 // 23 Successful off-hand melee attacks
357 #define MELEE_BASED_TRIGGER_MASK (PROC_FLAG_SUCCESSFUL_MILEE_HIT | \
358 PROC_FLAG_TAKEN_MELEE_HIT | \
359 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT | \
360 PROC_FLAG_TAKEN_MELEE_SPELL_HIT | \
361 PROC_FLAG_SUCCESSFUL_RANGED_HIT | \
362 PROC_FLAG_TAKEN_RANGED_HIT | \
363 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT | \
364 PROC_FLAG_TAKEN_RANGED_SPELL_HIT)
366 enum ProcFlagsEx
368 PROC_EX_NONE = 0x0000000, // If none can tigger on Hit/Crit only (passive spells MUST defined by SpellFamily flag)
369 PROC_EX_NORMAL_HIT = 0x0000001, // If set only from normal hit (only damage spells)
370 PROC_EX_CRITICAL_HIT = 0x0000002,
371 PROC_EX_MISS = 0x0000004,
372 PROC_EX_RESIST = 0x0000008,
373 PROC_EX_DODGE = 0x0000010,
374 PROC_EX_PARRY = 0x0000020,
375 PROC_EX_BLOCK = 0x0000040,
376 PROC_EX_EVADE = 0x0000080,
377 PROC_EX_IMMUNE = 0x0000100,
378 PROC_EX_DEFLECT = 0x0000200,
379 PROC_EX_ABSORB = 0x0000400,
380 PROC_EX_REFLECT = 0x0000800,
381 PROC_EX_INTERRUPT = 0x0001000, // Melee hit result can be Interrupt (not used)
382 PROC_EX_RESERVED1 = 0x0002000,
383 PROC_EX_RESERVED2 = 0x0004000,
384 PROC_EX_RESERVED3 = 0x0008000,
385 PROC_EX_EX_TRIGGER_ALWAYS = 0x0010000, // If set trigger always ( no matter another flags) used for drop charges
386 PROC_EX_EX_ONE_TIME_TRIGGER = 0x0020000 // If set trigger always but only one time (not used)
389 struct SpellProcEventEntry
391 uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2
392 uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value
393 uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do)
394 uint32 spellFamilyMask2; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags2 (like auras 107 and 108 do)
395 uint32 procFlags; // bitmask for matching proc event
396 uint32 procEx; // proc Extend info (see ProcFlagsEx)
397 float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc
398 float customChance; // Owerride chance (in most cases for debug only)
399 uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_
402 struct SpellBonusEntry
404 float direct_damage;
405 float dot_damage;
406 float ap_bonus;
409 typedef UNORDERED_MAP<uint32, SpellProcEventEntry> SpellProcEventMap;
410 typedef UNORDERED_MAP<uint32, SpellBonusEntry> SpellBonusMap;
412 #define ELIXIR_BATTLE_MASK 0x1
413 #define ELIXIR_GUARDIAN_MASK 0x2
414 #define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK)
415 #define ELIXIR_UNSTABLE_MASK 0x4
416 #define ELIXIR_SHATTRATH_MASK 0x8
418 typedef std::map<uint32, uint8> SpellElixirMap;
420 // Spell script target related declarations (accessed using SpellMgr functions)
421 enum SpellTargetType
423 SPELL_TARGET_TYPE_GAMEOBJECT = 0,
424 SPELL_TARGET_TYPE_CREATURE = 1,
425 SPELL_TARGET_TYPE_DEAD = 2
428 #define MAX_SPELL_TARGET_TYPE 3
430 struct SpellTargetEntry
432 SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {}
433 SpellTargetType type;
434 uint32 targetEntry;
437 typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
439 // coordinates for spells (accessed using SpellMgr functions)
440 struct SpellTargetPosition
442 uint32 target_mapId;
443 float target_X;
444 float target_Y;
445 float target_Z;
446 float target_Orientation;
449 typedef UNORDERED_MAP<uint32, SpellTargetPosition> SpellTargetPositionMap;
451 // Spell pet auras
452 class PetAura
454 public:
455 PetAura()
457 auras.clear();
460 PetAura(uint16 petEntry, uint16 aura, bool _removeOnChangePet, int _damage) :
461 removeOnChangePet(_removeOnChangePet), damage(_damage)
463 auras[petEntry] = aura;
466 uint16 GetAura(uint16 petEntry) const
468 std::map<uint16, uint16>::const_iterator itr = auras.find(petEntry);
469 if(itr != auras.end())
470 return itr->second;
471 else
473 std::map<uint16, uint16>::const_iterator itr2 = auras.find(0);
474 if(itr2 != auras.end())
475 return itr2->second;
476 else
477 return 0;
481 void AddAura(uint16 petEntry, uint16 aura)
483 auras[petEntry] = aura;
486 bool IsRemovedOnChangePet() const
488 return removeOnChangePet;
491 int32 GetDamage() const
493 return damage;
496 private:
497 std::map<uint16, uint16> auras;
498 bool removeOnChangePet;
499 int32 damage;
501 typedef std::map<uint16, PetAura> SpellPetAuraMap;
503 struct SpellArea
505 uint32 spellId;
506 uint32 areaId; // zone/subzone/or 0 is not limited to zone
507 uint32 questStart; // quest start (quest must be active or rewarded for spell apply)
508 uint32 questEnd; // quest end (quest don't must be rewarded for spell apply)
509 int32 auraSpell; // spell aura must be applied for spell apply )if possitive) and it don't must be applied in other case
510 uint32 raceMask; // can be applied only to races
511 Gender gender; // can be applied only to gender
512 bool questStartCanActive; // if true then quest start can be active (not only rewarded)
513 bool autocast; // if true then auto applied at area enter, in other case just allowed to cast
515 // helpers
516 bool IsFitToRequirements(Player const* player, uint32 newZone, uint32 newArea) const;
519 typedef std::multimap<uint32,SpellArea> SpellAreaMap;
520 typedef std::multimap<uint32,SpellArea const*> SpellAreaForQuestMap;
521 typedef std::multimap<uint32,SpellArea const*> SpellAreaForAuraMap;
522 typedef std::multimap<uint32,SpellArea const*> SpellAreaForAreaMap;
523 typedef std::pair<SpellAreaMap::const_iterator,SpellAreaMap::const_iterator> SpellAreaMapBounds;
524 typedef std::pair<SpellAreaForQuestMap::const_iterator,SpellAreaForQuestMap::const_iterator> SpellAreaForQuestMapBounds;
525 typedef std::pair<SpellAreaForAuraMap::const_iterator, SpellAreaForAuraMap::const_iterator> SpellAreaForAuraMapBounds;
526 typedef std::pair<SpellAreaForAreaMap::const_iterator, SpellAreaForAreaMap::const_iterator> SpellAreaForAreaMapBounds;
529 // Spell rank chain (accessed using SpellMgr functions)
530 struct SpellChainNode
532 uint32 prev;
533 uint32 first;
534 uint32 req;
535 uint8 rank;
538 typedef UNORDERED_MAP<uint32, SpellChainNode> SpellChainMap;
539 typedef std::multimap<uint32, uint32> SpellChainMapNext;
541 // Spell learning properties (accessed using SpellMgr functions)
542 struct SpellLearnSkillNode
544 uint32 skill;
545 uint32 value; // 0 - max skill value for player level
546 uint32 maxvalue; // 0 - max skill value for player level
549 typedef std::map<uint32, SpellLearnSkillNode> SpellLearnSkillMap;
551 struct SpellLearnSpellNode
553 uint32 spell;
554 bool active; // show in spellbook or not
555 bool autoLearned;
558 typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
560 typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
562 typedef std::map<uint32, uint32> PetLevelupSpellSet;
563 typedef std::map<uint32, PetLevelupSpellSet> PetLevelupSpellMap;
565 inline bool IsPrimaryProfessionSkill(uint32 skill)
567 SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill);
568 if(!pSkill)
569 return false;
571 if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
572 return false;
574 return true;
577 inline bool IsProfessionSkill(uint32 skill)
579 return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
582 inline bool IsProfessionOrRidingSkill(uint32 skill)
584 return IsProfessionSkill(skill) || skill == SKILL_RIDING;
587 class SpellMgr
589 // Constructors
590 public:
591 SpellMgr();
592 ~SpellMgr();
594 // Accessors (const or static functions)
595 public:
596 // Spell affects
597 SpellAffectEntry const*GetSpellAffect(uint16 spellId, uint8 effectId) const
599 SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId);
600 if( itr != mSpellAffectMap.end( ) )
601 return &itr->second;
602 return 0;
605 bool IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const;
607 SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }
609 uint32 GetSpellElixirMask(uint32 spellid) const
611 SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid);
612 if(itr==mSpellElixirs.end())
613 return 0x0;
615 return itr->second;
618 SpellSpecific GetSpellElixirSpecific(uint32 spellid) const
620 uint32 mask = GetSpellElixirMask(spellid);
621 if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK)
622 return SPELL_FLASK_ELIXIR;
623 else if(mask & ELIXIR_BATTLE_MASK)
624 return SPELL_BATTLE_ELIXIR;
625 else if(mask & ELIXIR_GUARDIAN_MASK)
626 return SPELL_GUARDIAN_ELIXIR;
627 else
628 return SPELL_NORMAL;
631 // Spell proc events
632 SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
634 SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
635 if( itr != mSpellProcEventMap.end( ) )
636 return &itr->second;
637 return NULL;
640 static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active);
642 // Spell bonus data
643 SpellBonusEntry const* GetSpellBonusData(uint32 spellId) const
645 // Lookup data
646 SpellBonusMap::const_iterator itr = mSpellBonusMap.find(spellId);
647 if( itr != mSpellBonusMap.end( ) )
648 return &itr->second;
649 // Not found, try lookup for 1 spell rank if exist
650 if (uint32 rank_1 = GetFirstSpellInChain(spellId))
652 SpellBonusMap::const_iterator itr2 = mSpellBonusMap.find(rank_1);
653 if( itr2 != mSpellBonusMap.end( ) )
654 return &itr2->second;
656 return NULL;
659 // Spell target coordinates
660 SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const
662 SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id );
663 if( itr != mSpellTargetPositions.end( ) )
664 return &itr->second;
665 return NULL;
668 // Spell ranks chains
669 SpellChainNode const* GetSpellChainNode(uint32 spell_id) const
671 SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
672 if(itr == mSpellChains.end())
673 return NULL;
675 return &itr->second;
678 uint32 GetFirstSpellInChain(uint32 spell_id) const
680 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
681 return node->first;
683 return spell_id;
686 uint32 GetPrevSpellInChain(uint32 spell_id) const
688 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
689 return node->prev;
691 return 0;
694 SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; }
696 // Note: not use rank for compare to spell ranks: spell chains isn't linear order
697 // Use IsHighRankOfSpell instead
698 uint8 GetSpellRank(uint32 spell_id) const
700 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
701 return node->rank;
703 return 0;
706 uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const
708 SpellChainMap::const_iterator itr = mSpellChains.find(spell1);
710 uint32 rank2 = GetSpellRank(spell2);
712 // not ordered correctly by rank value
713 if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2)
714 return false;
716 // check present in same rank chain
717 for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev))
718 if(itr->second.prev==spell2)
719 return true;
721 return false;
724 bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const;
725 static bool canStackSpellRanks(SpellEntry const *spellInfo);
726 bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const;
728 SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const;
730 // Spell learning
731 SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const
733 SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id);
734 if(itr != mSpellLearnSkills.end())
735 return &itr->second;
736 else
737 return NULL;
740 bool IsSpellLearnSpell(uint32 spell_id) const
742 return mSpellLearnSpells.find(spell_id) != mSpellLearnSpells.end();
745 SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const
747 return mSpellLearnSpells.lower_bound(spell_id);
750 SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const
752 return mSpellLearnSpells.upper_bound(spell_id);
755 bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const
757 SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1);
758 SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1);
759 for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i)
760 if(i->second.spell==spell_id2)
761 return true;
762 return false;
765 static bool IsProfessionOrRidingSpell(uint32 spellId);
766 static bool IsProfessionSpell(uint32 spellId);
767 static bool IsPrimaryProfessionSpell(uint32 spellId);
768 bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const;
770 bool IsSkillBonusSpell(uint32 spellId) const;
773 // Spell script targets
774 SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const
776 return mSpellScriptTarget.lower_bound(spell_id);
779 SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const
781 return mSpellScriptTarget.upper_bound(spell_id);
784 // Spell correctess for client using
785 static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true);
787 SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const
789 return mSkillLineAbilityMap.lower_bound(spell_id);
792 SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const
794 return mSkillLineAbilityMap.upper_bound(spell_id);
797 PetAura const* GetPetAura(uint16 spell_id)
799 SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find(spell_id);
800 if(itr != mSpellPetAuraMap.end())
801 return &itr->second;
802 else
803 return NULL;
806 PetLevelupSpellSet const* GetPetLevelupSpellList(uint32 petFamily) const
808 PetLevelupSpellMap::const_iterator itr = mPetLevelupSpellMap.find(petFamily);
809 if(itr != mPetLevelupSpellMap.end())
810 return &itr->second;
811 else
812 return NULL;
815 SpellCastResult GetSpellAllowedInLocationError(SpellEntry const *spellInfo, uint32 map_id, uint32 zone_id, uint32 area_id, Player const* player = NULL);
817 SpellAreaMapBounds GetSpellAreaMapBounds(uint32 spell_id) const
819 return SpellAreaMapBounds(mSpellAreaMap.lower_bound(spell_id),mSpellAreaMap.upper_bound(spell_id));
822 SpellAreaForQuestMapBounds GetSpellAreaForQuestMapBounds(uint32 quest_id, bool active) const
824 if(active)
825 return SpellAreaForQuestMapBounds(mSpellAreaForActiveQuestMap.lower_bound(quest_id),mSpellAreaForActiveQuestMap.upper_bound(quest_id));
826 else
827 return SpellAreaForQuestMapBounds(mSpellAreaForQuestMap.lower_bound(quest_id),mSpellAreaForQuestMap.upper_bound(quest_id));
830 SpellAreaForQuestMapBounds GetSpellAreaForQuestEndMapBounds(uint32 quest_id) const
832 return SpellAreaForQuestMapBounds(mSpellAreaForQuestEndMap.lower_bound(quest_id),mSpellAreaForQuestEndMap.upper_bound(quest_id));
835 SpellAreaForAuraMapBounds GetSpellAreaForAuraMapBounds(uint32 spell_id) const
837 return SpellAreaForAuraMapBounds(mSpellAreaForAuraMap.lower_bound(spell_id),mSpellAreaForAuraMap.upper_bound(spell_id));
840 SpellAreaForAreaMapBounds GetSpellAreaForAreaMapBounds(uint32 area_id) const
842 return SpellAreaForAreaMapBounds(mSpellAreaForAreaMap.lower_bound(area_id),mSpellAreaForAreaMap.upper_bound(area_id));
845 // Modifiers
846 public:
847 static SpellMgr& Instance();
849 // Loading data at server startup
850 void LoadSpellChains();
851 void LoadSpellLearnSkills();
852 void LoadSpellLearnSpells();
853 void LoadSpellScriptTarget();
854 void LoadSpellAffects();
855 void LoadSpellElixirs();
856 void LoadSpellProcEvents();
857 void LoadSpellBonusess();
858 void LoadSpellTargetPositions();
859 void LoadSpellThreats();
860 void LoadSkillLineAbilityMap();
861 void LoadSpellPetAuras();
862 void LoadPetLevelupSpellMap();
863 void LoadSpellAreas();
865 private:
866 SpellScriptTarget mSpellScriptTarget;
867 SpellChainMap mSpellChains;
868 SpellChainMapNext mSpellChainsNext;
869 SpellLearnSkillMap mSpellLearnSkills;
870 SpellLearnSpellMap mSpellLearnSpells;
871 SpellTargetPositionMap mSpellTargetPositions;
872 SpellAffectMap mSpellAffectMap;
873 SpellElixirMap mSpellElixirs;
874 SpellProcEventMap mSpellProcEventMap;
875 SpellBonusMap mSpellBonusMap;
876 SkillLineAbilityMap mSkillLineAbilityMap;
877 SpellPetAuraMap mSpellPetAuraMap;
878 PetLevelupSpellMap mPetLevelupSpellMap;
879 SpellAreaMap mSpellAreaMap;
880 SpellAreaForQuestMap mSpellAreaForQuestMap;
881 SpellAreaForQuestMap mSpellAreaForActiveQuestMap;
882 SpellAreaForQuestMap mSpellAreaForQuestEndMap;
883 SpellAreaForAuraMap mSpellAreaForAuraMap;
884 SpellAreaForAreaMap mSpellAreaForAreaMap;
887 #define spellmgr SpellMgr::Instance()
888 #endif