[8490] Fix typo in constant name.
[getmangos.git] / src / game / SpellMgr.h
blob86388e2af627db62969996c46df73b3435afc1fa
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,
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);
129 inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
131 for(int i = 0; i < 3; ++i)
132 if(SpellEffects(spellInfo->Effect[i])==effect)
133 return true;
134 return false;
137 inline bool IsSpellHaveAura(SpellEntry const *spellInfo, AuraType aura)
139 for(int i = 0; i < 3; ++i)
140 if(AuraType(spellInfo->EffectApplyAuraName[i])==aura)
141 return true;
142 return false;
145 inline bool IsSpellLastAuraEffect(SpellEntry const *spellInfo, int effecIdx)
147 for(int i = effecIdx+1; i < 3; ++i)
148 if(spellInfo->EffectApplyAuraName[i])
149 return false;
150 return true;
153 bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
155 inline bool IsSealSpell(SpellEntry const *spellInfo)
157 //Collection of all the seal family flags. No other paladin spell has any of those.
158 return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN &&
159 ( spellInfo->SpellFamilyFlags & SPELLFAMILYFLAG_PALADIN_SEALS );
162 inline bool IsElementalShield(SpellEntry const *spellInfo)
164 // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus
165 return (spellInfo->SpellFamilyFlags & UI64LIT(0x42000000400)) || spellInfo->Id == 23552;
168 inline bool IsExplicitDiscoverySpell(SpellEntry const *spellInfo)
170 return ((spellInfo->Effect[0] == SPELL_EFFECT_CREATE_RANDOM_ITEM
171 && spellInfo->Effect[1] == SPELL_EFFECT_SCRIPT_EFFECT)
172 || spellInfo->Id == 64323); // Book of Glyph Mastery (Effect0==SPELL_EFFECT_SCRIPT_EFFECT without any other data)
175 inline bool IsLootCraftingSpell(SpellEntry const *spellInfo)
177 return (spellInfo->Effect[0]==SPELL_EFFECT_CREATE_RANDOM_ITEM ||
178 // different random cards from Inscription (121==Virtuoso Inking Set category)
179 (spellInfo->Effect[0]==SPELL_EFFECT_CREATE_ITEM_2 && spellInfo->TotemCategory[0] == 121));
182 int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
184 // order from less to more strict
185 bool IsSingleFromSpellSpecificPerTargetPerCaster(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
186 bool IsSingleFromSpellSpecificSpellRanksPerTarget(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
187 bool IsSingleFromSpellSpecificPerTarget(SpellSpecific spellSpec1,SpellSpecific spellSpec2);
189 bool IsPassiveSpell(uint32 spellId);
191 inline bool IsPassiveSpellStackableWithRanks(SpellEntry const* spellProto)
193 if(!IsPassiveSpell(spellProto->Id))
194 return false;
196 return !IsSpellHaveEffect(spellProto,SPELL_EFFECT_APPLY_AURA);
200 inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo)
202 return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT;
205 inline bool IsNonCombatSpell(SpellEntry const *spellInfo)
207 return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0;
210 bool IsPositiveSpell(uint32 spellId);
211 bool IsPositiveEffect(uint32 spellId, uint32 effIndex);
212 bool IsPositiveTarget(uint32 targetA, uint32 targetB);
214 bool IsSingleTargetSpell(SpellEntry const *spellInfo);
215 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);
217 inline bool IsCasterSourceTarget(uint32 target)
219 switch (target )
221 case TARGET_SELF:
222 case TARGET_PET:
223 case TARGET_ALL_PARTY_AROUND_CASTER:
224 case TARGET_IN_FRONT_OF_CASTER:
225 case TARGET_MASTER:
226 case TARGET_MINION:
227 case TARGET_ALL_PARTY:
228 case TARGET_ALL_PARTY_AROUND_CASTER_2:
229 case TARGET_SELF_FISHING:
230 case TARGET_TOTEM_EARTH:
231 case TARGET_TOTEM_WATER:
232 case TARGET_TOTEM_AIR:
233 case TARGET_TOTEM_FIRE:
234 case TARGET_SUMMON:
235 case TARGET_AREAEFFECT_CUSTOM_2:
236 case TARGET_ALL_RAID_AROUND_CASTER:
237 case TARGET_SELF2:
238 case TARGET_DIRECTLY_FORWARD:
239 case TARGET_NONCOMBAT_PET:
240 case TARGET_IN_FRONT_OF_CASTER_30:
241 return true;
242 default:
243 break;
245 return false;
248 inline bool IsSpellWithCasterSourceTargetsOnly(SpellEntry const* spellInfo)
250 for(int i = 0; i < 3; ++i)
252 uint32 targetA = spellInfo->EffectImplicitTargetA[i];
253 if(targetA && !IsCasterSourceTarget(targetA))
254 return false;
256 uint32 targetB = spellInfo->EffectImplicitTargetB[i];
257 if(targetB && !IsCasterSourceTarget(targetB))
258 return false;
260 if(!targetA && !targetB)
261 return false;
263 return true;
266 inline bool IsPointEffectTarget( Targets target )
268 switch (target )
270 case TARGET_INNKEEPER_COORDINATES:
271 case TARGET_TABLE_X_Y_Z_COORDINATES:
272 case TARGET_CASTER_COORDINATES:
273 case TARGET_SCRIPT_COORDINATES:
274 case TARGET_CURRENT_ENEMY_COORDINATES:
275 case TARGET_DUELVSPLAYER_COORDINATES:
276 case TARGET_DYNAMIC_OBJECT_COORDINATES:
277 case TARGET_POINT_AT_NORTH:
278 case TARGET_POINT_AT_SOUTH:
279 case TARGET_POINT_AT_EAST:
280 case TARGET_POINT_AT_WEST:
281 case TARGET_POINT_AT_NE:
282 case TARGET_POINT_AT_NW:
283 case TARGET_POINT_AT_SE:
284 case TARGET_POINT_AT_SW:
285 return true;
286 default:
287 break;
289 return false;
292 inline bool IsAreaEffectTarget( Targets target )
294 switch (target )
296 case TARGET_AREAEFFECT_INSTANT:
297 case TARGET_AREAEFFECT_CUSTOM:
298 case TARGET_ALL_ENEMY_IN_AREA:
299 case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
300 case TARGET_ALL_PARTY_AROUND_CASTER:
301 case TARGET_IN_FRONT_OF_CASTER:
302 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
303 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
304 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
305 case TARGET_ALL_PARTY:
306 case TARGET_ALL_PARTY_AROUND_CASTER_2:
307 case TARGET_AREAEFFECT_PARTY:
308 case TARGET_AREAEFFECT_CUSTOM_2:
309 case TARGET_ALL_RAID_AROUND_CASTER:
310 case TARGET_AREAEFFECT_PARTY_AND_CLASS:
311 case TARGET_IN_FRONT_OF_CASTER_30:
312 return true;
313 default:
314 break;
316 return false;
319 inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo)
321 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0])))
322 return true;
323 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1])))
324 return true;
325 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2])))
326 return true;
327 return false;
330 inline bool IsAreaAuraEffect(uint32 effect)
332 if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
333 effect == SPELL_EFFECT_APPLY_AREA_AURA_RAID ||
334 effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND ||
335 effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY ||
336 effect == SPELL_EFFECT_APPLY_AREA_AURA_PET ||
337 effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER)
338 return true;
339 return false;
342 inline bool IsDispelSpell(SpellEntry const *spellInfo)
344 if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL ||
345 spellInfo->Effect[1] == SPELL_EFFECT_DISPEL ||
346 spellInfo->Effect[2] == SPELL_EFFECT_DISPEL )
347 return true;
348 return false;
350 inline bool isSpellBreakStealth(SpellEntry const* spellInfo)
352 return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH);
355 inline bool IsAutoRepeatRangedSpell(SpellEntry const* spellInfo)
357 return (spellInfo->Attributes & SPELL_ATTR_RANGED) && (spellInfo->AttributesEx2 & SPELL_ATTR_EX2_AUTOREPEAT_FLAG);
360 SpellCastResult GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form);
362 inline bool IsChanneledSpell(SpellEntry const* spellInfo)
364 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2));
367 inline bool NeedsComboPoints(SpellEntry const* spellInfo)
369 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2));
372 inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo)
374 return SpellSchoolMask(spellInfo->SchoolMask);
377 inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect)
379 uint32 mask = 0;
380 if (spellInfo->Mechanic)
381 mask |= 1<<spellInfo->Mechanic;
382 if (spellInfo->EffectMechanic[effect])
383 mask |= 1<<spellInfo->EffectMechanic[effect];
384 return mask;
387 inline uint32 GetAllSpellMechanicMask(SpellEntry const* spellInfo)
389 uint32 mask = 0;
390 if (spellInfo->Mechanic)
391 mask |= 1<<spellInfo->Mechanic;
392 for (int i=0; i< 3; ++i)
393 if (spellInfo->EffectMechanic[i])
394 mask |= 1<<spellInfo->EffectMechanic[i];
395 return mask;
398 inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect)
400 if (spellInfo->EffectMechanic[effect])
401 return Mechanics(spellInfo->EffectMechanic[effect]);
402 if (spellInfo->Mechanic)
403 return Mechanics(spellInfo->Mechanic);
404 return MECHANIC_NONE;
407 inline uint32 GetDispellMask(DispelType dispel)
409 // If dispell all
410 if (dispel == DISPEL_ALL)
411 return DISPEL_ALL_MASK;
412 else
413 return (1 << dispel);
416 // Diminishing Returns interaction with spells
417 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered);
418 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
419 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group);
420 int32 GetDiminishingReturnsLimitDuration(DiminishingGroup group, SpellEntry const* spellproto);
422 // Spell proc event related declarations (accessed using SpellMgr functions)
423 enum ProcFlags
425 PROC_FLAG_NONE = 0x00000000,
427 PROC_FLAG_KILLED = 0x00000001, // 00 Killed by agressor
428 PROC_FLAG_KILL = 0x00000002, // 01 Kill target (in most cases need XP/Honor reward)
430 PROC_FLAG_SUCCESSFUL_MELEE_HIT = 0x00000004, // 02 Successful melee auto attack
431 PROC_FLAG_TAKEN_MELEE_HIT = 0x00000008, // 03 Taken damage from melee auto attack hit
433 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT = 0x00000010, // 04 Successful attack by Spell that use melee weapon
434 PROC_FLAG_TAKEN_MELEE_SPELL_HIT = 0x00000020, // 05 Taken damage by Spell that use melee weapon
436 PROC_FLAG_SUCCESSFUL_RANGED_HIT = 0x00000040, // 06 Successful Ranged auto attack
437 PROC_FLAG_TAKEN_RANGED_HIT = 0x00000080, // 07 Taken damage from ranged auto attack
439 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT = 0x00000100, // 08 Successful Ranged attack by Spell that use ranged weapon
440 PROC_FLAG_TAKEN_RANGED_SPELL_HIT = 0x00000200, // 09 Taken damage by Spell that use ranged weapon
442 PROC_FLAG_SUCCESSFUL_POSITIVE_AOE_HIT = 0x00000400, // 10 Successful AoE (not 100% shure unused)
443 PROC_FLAG_TAKEN_POSITIVE_AOE = 0x00000800, // 11 Taken AoE (not 100% shure unused)
445 PROC_FLAG_SUCCESSFUL_AOE_SPELL_HIT = 0x00001000, // 12 Successful AoE damage spell hit (not 100% shure unused)
446 PROC_FLAG_TAKEN_AOE_SPELL_HIT = 0x00002000, // 13 Taken AoE damage spell hit (not 100% shure unused)
448 PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL = 0x00004000, // 14 Successful cast positive spell (by default only on healing)
449 PROC_FLAG_TAKEN_POSITIVE_SPELL = 0x00008000, // 15 Taken positive spell hit (by default only on healing)
451 PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT = 0x00010000, // 16 Successful negative spell cast (by default only on damage)
452 PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT = 0x00020000, // 17 Taken negative spell (by default only on damage)
454 PROC_FLAG_ON_DO_PERIODIC = 0x00040000, // 18 Successful do periodic (damage / healing, determined from 14-17 flags)
455 PROC_FLAG_ON_TAKE_PERIODIC = 0x00080000, // 19 Taken spell periodic (damage / healing, determined from 14-17 flags)
457 PROC_FLAG_TAKEN_ANY_DAMAGE = 0x00100000, // 20 Taken any damage
458 PROC_FLAG_ON_TRAP_ACTIVATION = 0x00200000, // 21 On trap activation
460 PROC_FLAG_TAKEN_OFFHAND_HIT = 0x00400000, // 22 Taken off-hand melee attacks(not used)
461 PROC_FLAG_SUCCESSFUL_OFFHAND_HIT = 0x00800000 // 23 Successful off-hand melee attacks
464 #define MELEE_BASED_TRIGGER_MASK (PROC_FLAG_SUCCESSFUL_MELEE_HIT | \
465 PROC_FLAG_TAKEN_MELEE_HIT | \
466 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT | \
467 PROC_FLAG_TAKEN_MELEE_SPELL_HIT | \
468 PROC_FLAG_SUCCESSFUL_RANGED_HIT | \
469 PROC_FLAG_TAKEN_RANGED_HIT | \
470 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT | \
471 PROC_FLAG_TAKEN_RANGED_SPELL_HIT)
473 enum ProcFlagsEx
475 PROC_EX_NONE = 0x0000000, // If none can tigger on Hit/Crit only (passive spells MUST defined by SpellFamily flag)
476 PROC_EX_NORMAL_HIT = 0x0000001, // If set only from normal hit (only damage spells)
477 PROC_EX_CRITICAL_HIT = 0x0000002,
478 PROC_EX_MISS = 0x0000004,
479 PROC_EX_RESIST = 0x0000008,
480 PROC_EX_DODGE = 0x0000010,
481 PROC_EX_PARRY = 0x0000020,
482 PROC_EX_BLOCK = 0x0000040,
483 PROC_EX_EVADE = 0x0000080,
484 PROC_EX_IMMUNE = 0x0000100,
485 PROC_EX_DEFLECT = 0x0000200,
486 PROC_EX_ABSORB = 0x0000400,
487 PROC_EX_REFLECT = 0x0000800,
488 PROC_EX_INTERRUPT = 0x0001000, // Melee hit result can be Interrupt (not used)
489 PROC_EX_RESERVED1 = 0x0002000,
490 PROC_EX_RESERVED2 = 0x0004000,
491 PROC_EX_RESERVED3 = 0x0008000,
492 PROC_EX_EX_TRIGGER_ALWAYS = 0x0010000, // If set trigger always ( no matter another flags) used for drop charges
493 PROC_EX_EX_ONE_TIME_TRIGGER = 0x0020000 // If set trigger always but only one time (not used)
496 struct SpellProcEventEntry
498 uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2
499 uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value
500 uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do)
501 uint32 spellFamilyMask2; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags2 (like auras 107 and 108 do)
502 uint32 procFlags; // bitmask for matching proc event
503 uint32 procEx; // proc Extend info (see ProcFlagsEx)
504 float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc
505 float customChance; // Owerride chance (in most cases for debug only)
506 uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_
509 struct SpellBonusEntry
511 float direct_damage;
512 float dot_damage;
513 float ap_bonus;
516 typedef UNORDERED_MAP<uint32, SpellProcEventEntry> SpellProcEventMap;
517 typedef UNORDERED_MAP<uint32, SpellBonusEntry> SpellBonusMap;
519 #define ELIXIR_BATTLE_MASK 0x01
520 #define ELIXIR_GUARDIAN_MASK 0x02
521 #define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK)
522 #define ELIXIR_UNSTABLE_MASK 0x04
523 #define ELIXIR_SHATTRATH_MASK 0x08
524 #define ELIXIR_WELL_FED 0x10 // Some foods have SPELLFAMILY_POTION
526 typedef std::map<uint32, uint8> SpellElixirMap;
527 typedef std::map<uint32, float> SpellProcItemEnchantMap;
528 typedef std::map<uint32, uint16> SpellThreatMap;
530 // Spell script target related declarations (accessed using SpellMgr functions)
531 enum SpellTargetType
533 SPELL_TARGET_TYPE_GAMEOBJECT = 0,
534 SPELL_TARGET_TYPE_CREATURE = 1,
535 SPELL_TARGET_TYPE_DEAD = 2
538 #define MAX_SPELL_TARGET_TYPE 3
540 struct SpellTargetEntry
542 SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {}
543 SpellTargetType type;
544 uint32 targetEntry;
547 typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
548 typedef std::pair<SpellScriptTarget::const_iterator,SpellScriptTarget::const_iterator> SpellScriptTargetBounds;
550 // coordinates for spells (accessed using SpellMgr functions)
551 struct SpellTargetPosition
553 uint32 target_mapId;
554 float target_X;
555 float target_Y;
556 float target_Z;
557 float target_Orientation;
560 typedef UNORDERED_MAP<uint32, SpellTargetPosition> SpellTargetPositionMap;
562 // Spell pet auras
563 class PetAura
565 public:
566 PetAura()
568 auras.clear();
571 PetAura(uint32 petEntry, uint32 aura, bool _removeOnChangePet, int _damage) :
572 removeOnChangePet(_removeOnChangePet), damage(_damage)
574 auras[petEntry] = aura;
577 uint32 GetAura(uint32 petEntry) const
579 std::map<uint32, uint32>::const_iterator itr = auras.find(petEntry);
580 if(itr != auras.end())
581 return itr->second;
582 else
584 std::map<uint32, uint32>::const_iterator itr2 = auras.find(0);
585 if(itr2 != auras.end())
586 return itr2->second;
587 else
588 return 0;
592 void AddAura(uint32 petEntry, uint32 aura)
594 auras[petEntry] = aura;
597 bool IsRemovedOnChangePet() const
599 return removeOnChangePet;
602 int32 GetDamage() const
604 return damage;
607 private:
608 std::map<uint32, uint32> auras;
609 bool removeOnChangePet;
610 int32 damage;
612 typedef std::map<uint32, PetAura> SpellPetAuraMap;
614 struct SpellArea
616 uint32 spellId;
617 uint32 areaId; // zone/subzone/or 0 is not limited to zone
618 uint32 questStart; // quest start (quest must be active or rewarded for spell apply)
619 uint32 questEnd; // quest end (quest don't must be rewarded for spell apply)
620 int32 auraSpell; // spell aura must be applied for spell apply )if possitive) and it don't must be applied in other case
621 uint32 raceMask; // can be applied only to races
622 Gender gender; // can be applied only to gender
623 bool questStartCanActive; // if true then quest start can be active (not only rewarded)
624 bool autocast; // if true then auto applied at area enter, in other case just allowed to cast
626 // helpers
627 bool IsFitToRequirements(Player const* player, uint32 newZone, uint32 newArea) const;
630 typedef std::multimap<uint32,SpellArea> SpellAreaMap;
631 typedef std::multimap<uint32,SpellArea const*> SpellAreaForQuestMap;
632 typedef std::multimap<uint32,SpellArea const*> SpellAreaForAuraMap;
633 typedef std::multimap<uint32,SpellArea const*> SpellAreaForAreaMap;
634 typedef std::pair<SpellAreaMap::const_iterator,SpellAreaMap::const_iterator> SpellAreaMapBounds;
635 typedef std::pair<SpellAreaForQuestMap::const_iterator,SpellAreaForQuestMap::const_iterator> SpellAreaForQuestMapBounds;
636 typedef std::pair<SpellAreaForAuraMap::const_iterator, SpellAreaForAuraMap::const_iterator> SpellAreaForAuraMapBounds;
637 typedef std::pair<SpellAreaForAreaMap::const_iterator, SpellAreaForAreaMap::const_iterator> SpellAreaForAreaMapBounds;
640 // Spell rank chain (accessed using SpellMgr functions)
641 struct SpellChainNode
643 uint32 prev;
644 uint32 first;
645 uint32 req;
646 uint8 rank;
649 typedef UNORDERED_MAP<uint32, SpellChainNode> SpellChainMap;
650 typedef std::multimap<uint32, uint32> SpellChainMapNext;
652 // Spell learning properties (accessed using SpellMgr functions)
653 struct SpellLearnSkillNode
655 uint32 skill;
656 uint32 value; // 0 - max skill value for player level
657 uint32 maxvalue; // 0 - max skill value for player level
660 typedef std::map<uint32, SpellLearnSkillNode> SpellLearnSkillMap;
662 struct SpellLearnSpellNode
664 uint32 spell;
665 bool active; // show in spellbook or not
666 bool autoLearned;
669 typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
670 typedef std::pair<SpellLearnSpellMap::const_iterator,SpellLearnSpellMap::const_iterator> SpellLearnSpellMapBounds;
672 typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
673 typedef std::pair<SkillLineAbilityMap::const_iterator,SkillLineAbilityMap::const_iterator> SkillLineAbilityMapBounds;
675 typedef std::multimap<uint32, uint32> PetLevelupSpellSet;
676 typedef std::map<uint32, PetLevelupSpellSet> PetLevelupSpellMap;
678 struct PetDefaultSpellsEntry
680 uint32 spellid[MAX_CREATURE_SPELL_DATA_SLOT];
683 // < 0 for petspelldata id, > 0 for creature_id
684 typedef std::map<int32, PetDefaultSpellsEntry> PetDefaultSpellsMap;
687 inline bool IsPrimaryProfessionSkill(uint32 skill)
689 SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill);
690 if(!pSkill)
691 return false;
693 if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
694 return false;
696 return true;
699 inline bool IsProfessionSkill(uint32 skill)
701 return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
704 inline bool IsProfessionOrRidingSkill(uint32 skill)
706 return IsProfessionSkill(skill) || skill == SKILL_RIDING;
709 class SpellMgr
711 friend struct DoSpellBonusess;
712 friend struct DoSpellProcEvent;
713 friend struct DoSpellProcItemEnchant;
715 // Constructors
716 public:
717 SpellMgr();
718 ~SpellMgr();
720 // Accessors (const or static functions)
721 public:
723 bool IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const;
725 SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }
727 uint32 GetSpellElixirMask(uint32 spellid) const
729 SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid);
730 if(itr==mSpellElixirs.end())
731 return 0x0;
733 return itr->second;
736 SpellSpecific GetSpellElixirSpecific(uint32 spellid) const
738 uint32 mask = GetSpellElixirMask(spellid);
739 if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK)
740 return SPELL_FLASK_ELIXIR;
741 else if(mask & ELIXIR_BATTLE_MASK)
742 return SPELL_BATTLE_ELIXIR;
743 else if(mask & ELIXIR_GUARDIAN_MASK)
744 return SPELL_GUARDIAN_ELIXIR;
745 else if(mask & ELIXIR_WELL_FED)
746 return SPELL_WELL_FED;
747 else
748 return SPELL_NORMAL;
751 uint16 GetSpellThreat(uint32 spellid) const
753 SpellThreatMap::const_iterator itr = mSpellThreatMap.find(spellid);
754 if(itr==mSpellThreatMap.end())
755 return 0;
757 return itr->second;
760 // Spell proc events
761 SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
763 SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
764 if( itr != mSpellProcEventMap.end( ) )
765 return &itr->second;
766 return NULL;
769 // Spell procs from item enchants
770 float GetItemEnchantProcChance(uint32 spellid) const
772 SpellProcItemEnchantMap::const_iterator itr = mSpellProcItemEnchantMap.find(spellid);
773 if(itr==mSpellProcItemEnchantMap.end())
774 return 0.0f;
776 return itr->second;
779 static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active);
781 // Spell bonus data
782 SpellBonusEntry const* GetSpellBonusData(uint32 spellId) const
784 // Lookup data
785 SpellBonusMap::const_iterator itr = mSpellBonusMap.find(spellId);
786 if( itr != mSpellBonusMap.end( ) )
787 return &itr->second;
789 return NULL;
792 // Spell target coordinates
793 SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const
795 SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id );
796 if( itr != mSpellTargetPositions.end( ) )
797 return &itr->second;
798 return NULL;
801 // Spell ranks chains
802 SpellChainNode const* GetSpellChainNode(uint32 spell_id) const
804 SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
805 if(itr == mSpellChains.end())
806 return NULL;
808 return &itr->second;
811 uint32 GetFirstSpellInChain(uint32 spell_id) const
813 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
814 return node->first;
816 return spell_id;
819 uint32 GetPrevSpellInChain(uint32 spell_id) const
821 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
822 return node->prev;
824 return 0;
827 SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; }
829 template<typename Worker>
830 void doForHighRanks(uint32 spellid, Worker& worker)
832 SpellChainMapNext const& nextMap = GetSpellChainNext();
833 for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
835 worker(itr->second);
836 doForHighRanks(itr->second,worker);
840 // Note: not use rank for compare to spell ranks: spell chains isn't linear order
841 // Use IsHighRankOfSpell instead
842 uint8 GetSpellRank(uint32 spell_id) const
844 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
845 return node->rank;
847 return 0;
850 uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const
852 SpellChainMap::const_iterator itr = mSpellChains.find(spell1);
854 uint32 rank2 = GetSpellRank(spell2);
856 // not ordered correctly by rank value
857 if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2)
858 return false;
860 // check present in same rank chain
861 for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev))
862 if(itr->second.prev==spell2)
863 return true;
865 return false;
868 bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const;
869 static bool canStackSpellRanks(SpellEntry const *spellInfo);
870 bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const;
872 SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const;
874 // Spell learning
875 SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const
877 SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id);
878 if(itr != mSpellLearnSkills.end())
879 return &itr->second;
880 else
881 return NULL;
884 bool IsSpellLearnSpell(uint32 spell_id) const
886 return mSpellLearnSpells.find(spell_id) != mSpellLearnSpells.end();
889 SpellLearnSpellMapBounds GetSpellLearnSpellMapBounds(uint32 spell_id) const
891 return SpellLearnSpellMapBounds(mSpellLearnSpells.lower_bound(spell_id),mSpellLearnSpells.upper_bound(spell_id));
894 bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const
896 SpellLearnSpellMapBounds bounds = GetSpellLearnSpellMapBounds(spell_id1);
897 for(SpellLearnSpellMap::const_iterator i = bounds.first; i != bounds.second; ++i)
898 if (i->second.spell==spell_id2)
899 return true;
900 return false;
903 static bool IsProfessionOrRidingSpell(uint32 spellId);
904 static bool IsProfessionSpell(uint32 spellId);
905 static bool IsPrimaryProfessionSpell(uint32 spellId);
906 bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const;
908 bool IsSkillBonusSpell(uint32 spellId) const;
911 // Spell script targets
912 SpellScriptTargetBounds GetSpellScriptTargetBounds(uint32 spell_id) const
914 return SpellScriptTargetBounds(mSpellScriptTarget.lower_bound(spell_id),mSpellScriptTarget.upper_bound(spell_id));
917 // Spell correctess for client using
918 static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true);
920 SkillLineAbilityMapBounds GetSkillLineAbilityMapBounds(uint32 spell_id) const
922 return SkillLineAbilityMapBounds(mSkillLineAbilityMap.lower_bound(spell_id),mSkillLineAbilityMap.upper_bound(spell_id));
925 PetAura const* GetPetAura(uint32 spell_id, uint8 eff)
927 SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find((spell_id<<8) + eff);
928 if(itr != mSpellPetAuraMap.end())
929 return &itr->second;
930 else
931 return NULL;
934 PetLevelupSpellSet const* GetPetLevelupSpellList(uint32 petFamily) const
936 PetLevelupSpellMap::const_iterator itr = mPetLevelupSpellMap.find(petFamily);
937 if(itr != mPetLevelupSpellMap.end())
938 return &itr->second;
939 else
940 return NULL;
943 // < 0 for petspelldata id, > 0 for creature_id
944 PetDefaultSpellsEntry const* GetPetDefaultSpellsEntry(int32 id) const
946 PetDefaultSpellsMap::const_iterator itr = mPetDefaultSpellsMap.find(id);
947 if(itr != mPetDefaultSpellsMap.end())
948 return &itr->second;
949 return NULL;
952 SpellCastResult GetSpellAllowedInLocationError(SpellEntry const *spellInfo, uint32 map_id, uint32 zone_id, uint32 area_id, Player const* player = NULL);
954 SpellAreaMapBounds GetSpellAreaMapBounds(uint32 spell_id) const
956 return SpellAreaMapBounds(mSpellAreaMap.lower_bound(spell_id),mSpellAreaMap.upper_bound(spell_id));
959 SpellAreaForQuestMapBounds GetSpellAreaForQuestMapBounds(uint32 quest_id, bool active) const
961 if(active)
962 return SpellAreaForQuestMapBounds(mSpellAreaForActiveQuestMap.lower_bound(quest_id),mSpellAreaForActiveQuestMap.upper_bound(quest_id));
963 else
964 return SpellAreaForQuestMapBounds(mSpellAreaForQuestMap.lower_bound(quest_id),mSpellAreaForQuestMap.upper_bound(quest_id));
967 SpellAreaForQuestMapBounds GetSpellAreaForQuestEndMapBounds(uint32 quest_id) const
969 return SpellAreaForQuestMapBounds(mSpellAreaForQuestEndMap.lower_bound(quest_id),mSpellAreaForQuestEndMap.upper_bound(quest_id));
972 SpellAreaForAuraMapBounds GetSpellAreaForAuraMapBounds(uint32 spell_id) const
974 return SpellAreaForAuraMapBounds(mSpellAreaForAuraMap.lower_bound(spell_id),mSpellAreaForAuraMap.upper_bound(spell_id));
977 SpellAreaForAreaMapBounds GetSpellAreaForAreaMapBounds(uint32 area_id) const
979 return SpellAreaForAreaMapBounds(mSpellAreaForAreaMap.lower_bound(area_id),mSpellAreaForAreaMap.upper_bound(area_id));
982 // Modifiers
983 public:
984 static SpellMgr& Instance();
986 void CheckUsedSpells(char const* table);
988 // Loading data at server startup
989 void LoadSpellChains();
990 void LoadSpellLearnSkills();
991 void LoadSpellLearnSpells();
992 void LoadSpellScriptTarget();
993 void LoadSpellElixirs();
994 void LoadSpellProcEvents();
995 void LoadSpellProcItemEnchant();
996 void LoadSpellBonusess();
997 void LoadSpellTargetPositions();
998 void LoadSpellThreats();
999 void LoadSkillLineAbilityMap();
1000 void LoadSpellPetAuras();
1001 void LoadPetLevelupSpellMap();
1002 void LoadPetDefaultSpells();
1003 void LoadSpellAreas();
1005 private:
1006 SpellScriptTarget mSpellScriptTarget;
1007 SpellChainMap mSpellChains;
1008 SpellChainMapNext mSpellChainsNext;
1009 SpellLearnSkillMap mSpellLearnSkills;
1010 SpellLearnSpellMap mSpellLearnSpells;
1011 SpellTargetPositionMap mSpellTargetPositions;
1012 SpellElixirMap mSpellElixirs;
1013 SpellThreatMap mSpellThreatMap;
1014 SpellProcEventMap mSpellProcEventMap;
1015 SpellProcItemEnchantMap mSpellProcItemEnchantMap;
1016 SpellBonusMap mSpellBonusMap;
1017 SkillLineAbilityMap mSkillLineAbilityMap;
1018 SpellPetAuraMap mSpellPetAuraMap;
1019 PetLevelupSpellMap mPetLevelupSpellMap;
1020 PetDefaultSpellsMap mPetDefaultSpellsMap; // only spells not listed in related mPetLevelupSpellMap entry
1021 SpellAreaMap mSpellAreaMap;
1022 SpellAreaForQuestMap mSpellAreaForQuestMap;
1023 SpellAreaForQuestMap mSpellAreaForActiveQuestMap;
1024 SpellAreaForQuestMap mSpellAreaForQuestEndMap;
1025 SpellAreaForAuraMap mSpellAreaForAuraMap;
1026 SpellAreaForAreaMap mSpellAreaForAreaMap;
1029 #define spellmgr SpellMgr::Instance()
1030 #endif