Updated spells stuff
[getmangos.git] / src / game / SpellMgr.h
blob222833a63d80da0032a982f62727bf29788af27e
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef _SPELLMGR_H
20 #define _SPELLMGR_H
22 // For static or at-server-startup loaded spell data
23 // For more high level function for sSpellStore data
25 #include "SharedDefines.h"
26 #include "Database/DBCStructure.h"
27 #include "Database/SQLStorage.h"
29 #include "Utilities/HashMap.h"
30 #include <map>
32 class Player;
33 class Spell;
35 extern SQLStorage sSpellThreatStore;
37 enum SpellFailedReason
39 SPELL_FAILED_AFFECTING_COMBAT = 0,
40 SPELL_FAILED_ALREADY_AT_FULL_HEALTH = 1,
41 SPELL_FAILED_ALREADY_AT_FULL_MANA = 2,
42 SPELL_FAILED_ALREADY_AT_FULL_POWER = 3,
43 SPELL_FAILED_ALREADY_BEING_TAMED = 4,
44 SPELL_FAILED_ALREADY_HAVE_CHARM = 5,
45 SPELL_FAILED_ALREADY_HAVE_SUMMON = 6,
46 SPELL_FAILED_ALREADY_OPEN = 7,
47 SPELL_FAILED_AURA_BOUNCED = 8,
48 SPELL_FAILED_AUTOTRACK_INTERRUPTED = 9,
49 SPELL_FAILED_BAD_IMPLICIT_TARGETS = 10,
50 SPELL_FAILED_BAD_TARGETS = 11,
51 SPELL_FAILED_CANT_BE_CHARMED = 12,
52 SPELL_FAILED_CANT_BE_DISENCHANTED = 13,
53 SPELL_FAILED_CANT_BE_DISENCHANTED_SKILL = 14,
54 SPELL_FAILED_CANT_BE_MILLED = 15,
55 SPELL_FAILED_CANT_BE_PROSPECTED = 16,
56 SPELL_FAILED_CANT_CAST_ON_TAPPED = 17,
57 SPELL_FAILED_CANT_DUEL_WHILE_INVISIBLE = 18,
58 SPELL_FAILED_CANT_DUEL_WHILE_STEALTHED = 19,
59 SPELL_FAILED_CANT_STEALTH = 20,
60 SPELL_FAILED_CASTER_AURASTATE = 21,
61 SPELL_FAILED_CASTER_DEAD = 22,
62 SPELL_FAILED_CHARMED = 23,
63 SPELL_FAILED_CHEST_IN_USE = 24,
64 SPELL_FAILED_CONFUSED = 25,
65 SPELL_FAILED_DONT_REPORT = 26,
66 SPELL_FAILED_EQUIPPED_ITEM = 27,
67 SPELL_FAILED_EQUIPPED_ITEM_CLASS = 28,
68 SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND = 29,
69 SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND = 30,
70 SPELL_FAILED_ERROR = 31,
71 SPELL_FAILED_FIZZLE = 32,
72 SPELL_FAILED_FLEEING = 33,
73 SPELL_FAILED_FOOD_LOWLEVEL = 34,
74 SPELL_FAILED_HIGHLEVEL = 35,
75 SPELL_FAILED_HUNGER_SATIATED = 36,
76 SPELL_FAILED_IMMUNE = 37,
77 SPELL_FAILED_INCORRECT_AREA = 38,
78 SPELL_FAILED_INTERRUPTED = 39,
79 SPELL_FAILED_INTERRUPTED_COMBAT = 40,
80 SPELL_FAILED_ITEM_ALREADY_ENCHANTED = 41,
81 SPELL_FAILED_ITEM_GONE = 42,
82 SPELL_FAILED_ITEM_NOT_FOUND = 43,
83 SPELL_FAILED_ITEM_NOT_READY = 44,
84 SPELL_FAILED_LEVEL_REQUIREMENT = 45,
85 SPELL_FAILED_LINE_OF_SIGHT = 46,
86 SPELL_FAILED_LOWLEVEL = 47,
87 SPELL_FAILED_LOW_CASTLEVEL = 48,
88 SPELL_FAILED_MAINHAND_EMPTY = 49,
89 SPELL_FAILED_MOVING = 50,
90 SPELL_FAILED_NEED_AMMO = 51,
91 SPELL_FAILED_NEED_AMMO_POUCH = 52,
92 SPELL_FAILED_NEED_EXOTIC_AMMO = 53,
93 SPELL_FAILED_NEED_MORE_ITEMS = 54,
94 SPELL_FAILED_NOPATH = 55,
95 SPELL_FAILED_NOT_BEHIND = 56,
96 SPELL_FAILED_NOT_FISHABLE = 57,
97 SPELL_FAILED_NOT_FLYING = 58,
98 SPELL_FAILED_NOT_HERE = 59,
99 SPELL_FAILED_NOT_INFRONT = 60,
100 SPELL_FAILED_NOT_IN_CONTROL = 61,
101 SPELL_FAILED_NOT_KNOWN = 62,
102 SPELL_FAILED_NOT_MOUNTED = 63,
103 SPELL_FAILED_NOT_ON_TAXI = 64,
104 SPELL_FAILED_NOT_ON_TRANSPORT = 65,
105 SPELL_FAILED_NOT_READY = 66,
106 SPELL_FAILED_NOT_SHAPESHIFT = 67,
107 SPELL_FAILED_NOT_STANDING = 68,
108 SPELL_FAILED_NOT_TRADEABLE = 69,
109 SPELL_FAILED_NOT_TRADING = 70,
110 SPELL_FAILED_NOT_UNSHEATHED = 71,
111 SPELL_FAILED_NOT_WHILE_GHOST = 72,
112 SPELL_FAILED_NOT_WHILE_LOOTING = 73,
113 SPELL_FAILED_NO_AMMO = 74,
114 SPELL_FAILED_NO_CHARGES_REMAIN = 75,
115 SPELL_FAILED_NO_CHAMPION = 76,
116 SPELL_FAILED_NO_COMBO_POINTS = 77,
117 SPELL_FAILED_NO_DUELING = 78,
118 SPELL_FAILED_NO_ENDURANCE = 79,
119 SPELL_FAILED_NO_FISH = 80,
120 SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED = 81,
121 SPELL_FAILED_NO_MOUNTS_ALLOWED = 82,
122 SPELL_FAILED_NO_PET = 83,
123 SPELL_FAILED_NO_POWER = 84,
124 SPELL_FAILED_NOTHING_TO_DISPEL = 85,
125 SPELL_FAILED_NOTHING_TO_STEAL = 86,
126 SPELL_FAILED_ONLY_ABOVEWATER = 87,
127 SPELL_FAILED_ONLY_DAYTIME = 88,
128 SPELL_FAILED_ONLY_INDOORS = 89,
129 SPELL_FAILED_ONLY_MOUNTED = 90,
130 SPELL_FAILED_ONLY_NIGHTTIME = 91,
131 SPELL_FAILED_ONLY_OUTDOORS = 92,
132 SPELL_FAILED_ONLY_SHAPESHIFT = 93,
133 SPELL_FAILED_ONLY_STEALTHED = 94,
134 SPELL_FAILED_ONLY_UNDERWATER = 95,
135 SPELL_FAILED_OUT_OF_RANGE = 96,
136 SPELL_FAILED_PACIFIED = 97,
137 SPELL_FAILED_POSSESSED = 98,
138 SPELL_FAILED_REAGENTS = 99,
139 SPELL_FAILED_REQUIRES_AREA = 100,
140 SPELL_FAILED_REQUIRES_SPELL_FOCUS = 101,
141 SPELL_FAILED_ROOTED = 102,
142 SPELL_FAILED_SILENCED = 103,
143 SPELL_FAILED_SPELL_IN_PROGRESS = 104,
144 SPELL_FAILED_SPELL_LEARNED = 105,
145 SPELL_FAILED_SPELL_UNAVAILABLE = 106,
146 SPELL_FAILED_STUNNED = 107,
147 SPELL_FAILED_TARGETS_DEAD = 108,
148 SPELL_FAILED_TARGET_AFFECTING_COMBAT = 109,
149 SPELL_FAILED_TARGET_AURASTATE = 110,
150 SPELL_FAILED_TARGET_DUELING = 111,
151 SPELL_FAILED_TARGET_ENEMY = 112,
152 SPELL_FAILED_TARGET_ENRAGED = 113,
153 SPELL_FAILED_TARGET_FRIENDLY = 114,
154 SPELL_FAILED_TARGET_IN_COMBAT = 115,
155 SPELL_FAILED_TARGET_IS_PLAYER = 116,
156 SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED = 117,
157 SPELL_FAILED_TARGET_NOT_DEAD = 118,
158 SPELL_FAILED_TARGET_NOT_IN_PARTY = 119,
159 SPELL_FAILED_TARGET_NOT_LOOTED = 120,
160 SPELL_FAILED_TARGET_NOT_PLAYER = 121,
161 SPELL_FAILED_TARGET_NO_POCKETS = 122,
162 SPELL_FAILED_TARGET_NO_WEAPONS = 123,
163 SPELL_FAILED_TARGET_NO_RANGED_WEAPONS = 124,
164 SPELL_FAILED_TARGET_UNSKINNABLE = 125,
165 SPELL_FAILED_THIRST_SATIATED = 126,
166 SPELL_FAILED_TOO_CLOSE = 127,
167 SPELL_FAILED_TOO_MANY_OF_ITEM = 128,
168 SPELL_FAILED_TOTEM_CATEGORY = 129,
169 SPELL_FAILED_TOTEMS = 130,
170 SPELL_FAILED_TRY_AGAIN = 131,
171 SPELL_FAILED_UNIT_NOT_BEHIND = 132,
172 SPELL_FAILED_UNIT_NOT_INFRONT = 133,
173 SPELL_FAILED_WRONG_PET_FOOD = 134,
174 SPELL_FAILED_NOT_WHILE_FATIGUED = 135,
175 SPELL_FAILED_TARGET_NOT_IN_INSTANCE = 136,
176 SPELL_FAILED_NOT_WHILE_TRADING = 137,
177 SPELL_FAILED_TARGET_NOT_IN_RAID = 138,
178 SPELL_FAILED_TARGET_FREEFORALL = 139,
179 SPELL_FAILED_NO_EDIBLE_CORPSES = 140,
180 SPELL_FAILED_ONLY_BATTLEGROUNDS = 141,
181 SPELL_FAILED_TARGET_NOT_GHOST = 142,
182 SPELL_FAILED_TRANSFORM_UNUSABLE = 143,
183 SPELL_FAILED_WRONG_WEATHER = 144,
184 SPELL_FAILED_DAMAGE_IMMUNE = 145,
185 SPELL_FAILED_PREVENTED_BY_MECHANIC = 146,
186 SPELL_FAILED_PLAY_TIME = 147,
187 SPELL_FAILED_REPUTATION = 148,
188 SPELL_FAILED_MIN_SKILL = 149,
189 SPELL_FAILED_NOT_IN_ARENA = 150,
190 SPELL_FAILED_NOT_ON_SHAPESHIFT = 151,
191 SPELL_FAILED_NOT_ON_STEALTHED = 152,
192 SPELL_FAILED_NOT_ON_DAMAGE_IMMUNE = 153,
193 SPELL_FAILED_NOT_ON_MOUNTED = 154,
194 SPELL_FAILED_TOO_SHALLOW = 155,
195 SPELL_FAILED_TARGET_NOT_IN_SANCTUARY = 156,
196 SPELL_FAILED_TARGET_IS_TRIVIAL = 157,
197 SPELL_FAILED_BM_OR_INVISGOD = 158,
198 SPELL_FAILED_EXPERT_RIDING_REQUIREMENT = 159,
199 SPELL_FAILED_ARTISAN_RIDING_REQUIREMENT = 160,
200 SPELL_FAILED_NOT_IDLE = 161,
201 SPELL_FAILED_NOT_INACTIVE = 162,
202 SPELL_FAILED_PARTIAL_PLAYTIME = 163,
203 SPELL_FAILED_NO_PLAYTIME = 164,
204 SPELL_FAILED_NOT_IN_BATTLEGROUND = 165,
205 SPELL_FAILED_NOT_IN_RAID_INSTANCE = 166,
206 SPELL_FAILED_ONLY_IN_ARENA = 167,
207 SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE = 168,
208 SPELL_FAILED_ON_USE_ENCHANT = 169,
209 SPELL_FAILED_NOT_ON_GROUND = 170,
210 SPELL_FAILED_CUSTOM_ERROR = 171,
211 SPELL_FAILED_CANT_DO_THAT_RIGHT_NOW = 172,
212 SPELL_FAILED_TOO_MANY_SOCKETS = 173,
213 SPELL_FAILED_INVALID_GLYPH = 174,
214 SPELL_FAILED_UNIQUE_GLYPH = 175,
215 SPELL_FAILED_GLYPH_SOCKET_LOCKED = 176,
216 SPELL_FAILED_NO_VALID_TARGETS = 177,
217 SPELL_FAILED_ITEM_AT_MAX_CHARGES = 178,
218 SPELL_FAILED_NOT_IN_BARBERSHOP = 179,
219 SPELL_FAILED_FISHING_TOO_LOW = 180,
220 SPELL_FAILED_UNKNOWN = 181
223 enum SpellFamilyNames
225 SPELLFAMILY_GENERIC = 0,
226 SPELLFAMILY_UNK1 = 1, // events, holidays
227 // 2 - unused
228 SPELLFAMILY_MAGE = 3,
229 SPELLFAMILY_WARRIOR = 4,
230 SPELLFAMILY_WARLOCK = 5,
231 SPELLFAMILY_PRIEST = 6,
232 SPELLFAMILY_DRUID = 7,
233 SPELLFAMILY_ROGUE = 8,
234 SPELLFAMILY_HUNTER = 9,
235 SPELLFAMILY_PALADIN = 10,
236 SPELLFAMILY_SHAMAN = 11,
237 SPELLFAMILY_UNK2 = 12,
238 SPELLFAMILY_POTION = 13,
239 // 14 - unused
240 SPELLFAMILY_DEATHKNIGHT = 15,
241 // 16 - unused
242 SPELLFAMILY_UNK3 = 17
245 //Some SpellFamilyFlags
246 #define SPELLFAMILYFLAG_ROGUE_VANISH 0x000000800LL
247 #define SPELLFAMILYFLAG_ROGUE_STEALTH 0x000400000LL
248 #define SPELLFAMILYFLAG_ROGUE_BACKSTAB 0x000800004LL
249 #define SPELLFAMILYFLAG_ROGUE_SAP 0x000000080LL
250 #define SPELLFAMILYFLAG_ROGUE_FEINT 0x008000000LL
251 #define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT 0x000200000LL
252 #define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE 0x9003E0000LL
254 // Spell clasification
255 enum SpellSpecific
257 SPELL_NORMAL = 0,
258 SPELL_SEAL = 1,
259 SPELL_BLESSING = 2,
260 SPELL_AURA = 3,
261 SPELL_STING = 4,
262 SPELL_CURSE = 5,
263 SPELL_ASPECT = 6,
264 SPELL_TRACKER = 7,
265 SPELL_WARLOCK_ARMOR = 8,
266 SPELL_MAGE_ARMOR = 9,
267 SPELL_ELEMENTAL_SHIELD = 10,
268 SPELL_MAGE_POLYMORPH = 11,
269 SPELL_POSITIVE_SHOUT = 12,
270 SPELL_JUDGEMENT = 13,
271 SPELL_BATTLE_ELIXIR = 14,
272 SPELL_GUARDIAN_ELIXIR = 15,
273 SPELL_FLASK_ELIXIR = 16
276 SpellSpecific GetSpellSpecific(uint32 spellId);
278 // Different spell properties
279 inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); }
280 uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL);
281 inline float GetSpellMinRange(SpellRangeEntry const *range) { return (range ? range->minRange : 0); }
282 inline float GetSpellMaxRange(SpellRangeEntry const *range) { return (range ? range->maxRange : 0); }
283 inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; }
284 int32 GetSpellDuration(SpellEntry const *spellInfo);
285 int32 GetSpellMaxDuration(SpellEntry const *spellInfo);
287 inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
289 for(int i= 0; i < 3; ++i)
290 if(spellInfo->Effect[i]==effect)
291 return true;
292 return false;
295 bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
297 inline bool IsSealSpell(SpellEntry const *spellInfo)
299 //Collection of all the seal family flags. No other paladin spell has any of those.
300 return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN &&
301 ( spellInfo->SpellFamilyFlags & 0x4000A000200LL );
304 inline bool IsElementalShield(SpellEntry const *spellInfo)
306 // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus
307 return (spellInfo->SpellFamilyFlags & 0x42000000400LL) || spellInfo->Id == 23552;
310 int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
311 bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2);
312 bool IsPassiveSpell(uint32 spellId);
314 inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo)
316 switch(spellInfo->Id)
318 case 40214: // Dragonmaw Illusion
319 case 35480: case 35481: case 35482: // Human Illusion
320 case 35483: case 39824: // Human Illusion
321 return true;
324 return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT;
327 inline bool IsNonCombatSpell(SpellEntry const *spellInfo)
329 return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0;
332 bool IsPositiveSpell(uint32 spellId);
333 bool IsPositiveEffect(uint32 spellId, uint32 effIndex);
334 bool IsPositiveTarget(uint32 targetA, uint32 targetB);
336 bool IsSingleTargetSpell(SpellEntry const *spellInfo);
337 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);
339 bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id);
341 inline bool IsAreaEffectTarget( Targets target )
343 switch (target )
345 case TARGET_AREAEFFECT_CUSTOM:
346 case TARGET_ALL_ENEMY_IN_AREA:
347 case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
348 case TARGET_ALL_PARTY_AROUND_CASTER:
349 case TARGET_ALL_AROUND_CASTER:
350 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
351 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
352 case TARGET_ALL_PARTY:
353 case TARGET_ALL_PARTY_AROUND_CASTER_2:
354 case TARGET_AREAEFFECT_PARTY:
355 case TARGET_AREAEFFECT_CUSTOM_2:
356 case TARGET_AREAEFFECT_PARTY_AND_CLASS:
357 case TARGET_IN_FRONT_OF_CASTER:
358 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
359 return true;
360 default:
361 break;
363 return false;
366 inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo)
368 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0])))
369 return true;
370 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1])))
371 return true;
372 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2])))
373 return true;
374 return false;
377 inline bool IsAreaAuraEffect(uint32 effect)
379 if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
380 effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND ||
381 effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY ||
382 effect == SPELL_EFFECT_APPLY_AREA_AURA_PET ||
383 effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER)
384 return true;
385 return false;
388 inline bool IsDispelSpell(SpellEntry const *spellInfo)
390 if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL ||
391 spellInfo->Effect[1] == SPELL_EFFECT_DISPEL ||
392 spellInfo->Effect[2] == SPELL_EFFECT_DISPEL )
393 return true;
394 return false;
396 inline bool isSpellBreakStealth(SpellEntry const* spellInfo)
398 return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH);
401 uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form);
403 inline bool IsChanneledSpell(SpellEntry const* spellInfo)
405 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2));
408 inline bool NeedsComboPoints(SpellEntry const* spellInfo)
410 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2));
413 inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo)
415 return SpellSchoolMask(spellInfo->SchoolMask);
418 inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect)
420 uint32 mask = 0;
421 if (spellInfo->Mechanic)
422 mask |= 1<<spellInfo->Mechanic;
423 if (spellInfo->EffectMechanic[effect])
424 mask |= 1<<spellInfo->EffectMechanic[effect];
425 return mask;
428 inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect)
430 if (spellInfo->EffectMechanic[effect])
431 return Mechanics(spellInfo->EffectMechanic[effect]);
432 if (spellInfo->Mechanic)
433 return Mechanics(spellInfo->Mechanic);
434 return MECHANIC_NONE;
437 inline uint32 GetDispellMask(DispelType dispel)
439 // If dispell all
440 if (dispel == DISPEL_ALL)
441 return DISPEL_ALL_MASK;
442 else
443 return (1 << dispel);
446 // Diminishing Returns interaction with spells
447 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered);
448 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
449 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group);
451 // Spell affects related declarations (accessed using SpellMgr functions)
452 typedef std::map<uint32, uint64> SpellAffectMap;
454 // Spell proc event related declarations (accessed using SpellMgr functions)
455 enum ProcFlags
457 PROC_FLAG_NONE = 0x00000000, // None
458 PROC_FLAG_HIT_MELEE = 0x00000001, // On melee hit
459 PROC_FLAG_STRUCK_MELEE = 0x00000002, // On being struck melee
460 PROC_FLAG_KILL_XP_GIVER = 0x00000004, // On kill target giving XP or honor
461 PROC_FLAG_SPECIAL_DROP = 0x00000008, //
462 PROC_FLAG_DODGE = 0x00000010, // On dodge melee attack
463 PROC_FLAG_PARRY = 0x00000020, // On parry melee attack
464 PROC_FLAG_BLOCK = 0x00000040, // On block attack
465 PROC_FLAG_TOUCH = 0x00000080, // On being touched (for bombs, probably?)
466 PROC_FLAG_TARGET_LOW_HEALTH = 0x00000100, // On deal damage to enemy with 20% or less health
467 PROC_FLAG_LOW_HEALTH = 0x00000200, // On health dropped below 20%
468 PROC_FLAG_STRUCK_RANGED = 0x00000400, // On being struck ranged
469 PROC_FLAG_HIT_SPECIAL = 0x00000800, // (!)Removed, may be reassigned in future
470 PROC_FLAG_CRIT_MELEE = 0x00001000, // On crit melee
471 PROC_FLAG_STRUCK_CRIT_MELEE = 0x00002000, // On being critically struck in melee
472 PROC_FLAG_CAST_SPELL = 0x00004000, // On cast spell
473 PROC_FLAG_TAKE_DAMAGE = 0x00008000, // On take damage
474 PROC_FLAG_CRIT_SPELL = 0x00010000, // On crit spell
475 PROC_FLAG_HIT_SPELL = 0x00020000, // On hit spell
476 PROC_FLAG_STRUCK_CRIT_SPELL = 0x00040000, // On being critically struck by a spell
477 PROC_FLAG_HIT_RANGED = 0x00080000, // On getting ranged hit
478 PROC_FLAG_STRUCK_SPELL = 0x00100000, // On being struck by a spell
479 PROC_FLAG_TRAP = 0x00200000, // On trap activation (?)
480 PROC_FLAG_CRIT_RANGED = 0x00400000, // On getting ranged crit
481 PROC_FLAG_STRUCK_CRIT_RANGED = 0x00800000, // On being critically struck by a ranged attack
482 PROC_FLAG_RESIST_SPELL = 0x01000000, // On resist enemy spell
483 PROC_FLAG_TARGET_RESISTS = 0x02000000, // On enemy resisted spell
484 PROC_FLAG_TARGET_DODGE_OR_PARRY = 0x04000000, // On enemy dodges/parries
485 PROC_FLAG_HEAL = 0x08000000, // On heal
486 PROC_FLAG_CRIT_HEAL = 0x10000000, // On critical healing effect
487 PROC_FLAG_HEALED = 0x20000000, // On healing
488 PROC_FLAG_TARGET_BLOCK = 0x40000000, // On enemy blocks
489 PROC_FLAG_MISS = 0x80000000 // On miss melee attack
492 struct SpellProcEventEntry
494 uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2
495 uint32 category; // if nonzero - match proc condition based on candidate spell's category
496 uint32 skillId; // if nonzero - for matching proc condition based on candidate spell's skillId from SkillLineAbility.dbc (Shadow Bolt = Destruction)
497 uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value
498 uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do)
499 uint32 procFlags; // bitmask for matching proc event
500 float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc
501 uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_
504 typedef HM_NAMESPACE::hash_map<uint32, SpellProcEventEntry> SpellProcEventMap;
506 #define ELIXIR_BATTLE_MASK 0x1
507 #define ELIXIR_GUARDIAN_MASK 0x2
508 #define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK)
509 #define ELIXIR_UNSTABLE_MASK 0x4
510 #define ELIXIR_SHATTRATH_MASK 0x8
512 typedef std::map<uint32, uint8> SpellElixirMap;
514 // Spell script target related declarations (accessed using SpellMgr functions)
515 enum SpellTargetType
517 SPELL_TARGET_TYPE_GAMEOBJECT = 0,
518 SPELL_TARGET_TYPE_CREATURE = 1,
519 SPELL_TARGET_TYPE_DEAD = 2
522 #define MAX_SPELL_TARGET_TYPE 3
524 struct SpellTargetEntry
526 SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {}
527 SpellTargetType type;
528 uint32 targetEntry;
531 typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
533 // coordinates for spells (accessed using SpellMgr functions)
534 struct SpellTargetPosition
536 uint32 target_mapId;
537 float target_X;
538 float target_Y;
539 float target_Z;
540 float target_Orientation;
543 typedef HM_NAMESPACE::hash_map<uint32, SpellTargetPosition> SpellTargetPositionMap;
545 // Spell pet auras
546 class PetAura
548 public:
549 PetAura()
551 auras.clear();
554 PetAura(uint16 petEntry, uint16 aura, bool _removeOnChangePet, int _damage) :
555 removeOnChangePet(_removeOnChangePet), damage(_damage)
557 auras[petEntry] = aura;
560 uint16 GetAura(uint16 petEntry) const
562 std::map<uint16, uint16>::const_iterator itr = auras.find(petEntry);
563 if(itr != auras.end())
564 return itr->second;
565 else
567 std::map<uint16, uint16>::const_iterator itr = auras.find(0);
568 if(itr != auras.end())
569 return itr->second;
570 else
571 return 0;
575 void AddAura(uint16 petEntry, uint16 aura)
577 auras[petEntry] = aura;
580 bool IsRemovedOnChangePet() const
582 return removeOnChangePet;
585 int32 GetDamage() const
587 return damage;
590 private:
591 std::map<uint16, uint16> auras;
592 bool removeOnChangePet;
593 int32 damage;
595 typedef std::map<uint16, PetAura> SpellPetAuraMap;
597 // Spell rank chain (accessed using SpellMgr functions)
598 struct SpellChainNode
600 uint32 prev;
601 uint32 first;
602 uint32 req;
603 uint8 rank;
606 typedef HM_NAMESPACE::hash_map<uint32, SpellChainNode> SpellChainMap;
607 typedef std::multimap<uint32, uint32> SpellChainMapNext;
609 // Spell learning properties (accessed using SpellMgr functions)
610 struct SpellLearnSkillNode
612 uint32 skill;
613 uint32 value; // 0 - max skill value for player level
614 uint32 maxvalue; // 0 - max skill value for player level
617 typedef std::map<uint32, SpellLearnSkillNode> SpellLearnSkillMap;
619 struct SpellLearnSpellNode
621 uint32 spell;
622 bool autoLearned;
625 typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
627 typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
629 inline bool IsPrimaryProfessionSkill(uint32 skill)
631 SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill);
632 if(!pSkill)
633 return false;
635 if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
636 return false;
638 return true;
641 inline bool IsProfessionSkill(uint32 skill)
643 return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
646 class SpellMgr
648 // Constructors
649 public:
650 SpellMgr();
651 ~SpellMgr();
653 // Accessors (const or static functions)
654 public:
655 // Spell affects
656 uint64 GetSpellAffectMask(uint16 spellId, uint8 effectId) const
658 SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId);
659 if( itr != mSpellAffectMap.end( ) )
660 return itr->second;
661 return 0;
664 bool IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const;
666 SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }
668 uint32 GetSpellElixirMask(uint32 spellid) const
670 SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid);
671 if(itr==mSpellElixirs.end())
672 return 0x0;
674 return itr->second;
677 SpellSpecific GetSpellElixirSpecific(uint32 spellid) const
679 uint32 mask = GetSpellElixirMask(spellid);
680 if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK)
681 return SPELL_FLASK_ELIXIR;
682 else if(mask & ELIXIR_BATTLE_MASK)
683 return SPELL_BATTLE_ELIXIR;
684 else if(mask & ELIXIR_GUARDIAN_MASK)
685 return SPELL_GUARDIAN_ELIXIR;
686 else
687 return SPELL_NORMAL;
690 // Spell proc events
691 SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
693 SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
694 if( itr != mSpellProcEventMap.end( ) )
695 return &itr->second;
696 return NULL;
699 static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, SpellEntry const * procSpell, uint32 procFlags );
701 // Spell target coordinates
702 SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const
704 SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id );
705 if( itr != mSpellTargetPositions.end( ) )
706 return &itr->second;
707 return NULL;
710 // Spell ranks chains
711 SpellChainNode const* GetSpellChainNode(uint32 spell_id) const
713 SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
714 if(itr == mSpellChains.end())
715 return NULL;
717 return &itr->second;
720 uint32 GetFirstSpellInChain(uint32 spell_id) const
722 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
723 return node->first;
725 return spell_id;
728 uint32 GetPrevSpellInChain(uint32 spell_id) const
730 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
731 return node->prev;
733 return 0;
736 SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; }
738 // Note: not use rank for compare to spell ranks: spell chains isn't linear order
739 // Use IsHighRankOfSpell instead
740 uint8 GetSpellRank(uint32 spell_id) const
742 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
743 return node->rank;
745 return 0;
748 uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const
750 SpellChainMap::const_iterator itr = mSpellChains.find(spell1);
752 uint32 rank2 = GetSpellRank(spell2);
754 // not ordered correctly by rank value
755 if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2)
756 return false;
758 // check present in same rank chain
759 for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev))
760 if(itr->second.prev==spell2)
761 return true;
763 return false;
766 bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const;
767 static bool canStackSpellRanks(SpellEntry const *spellInfo);
768 bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const;
770 SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const;
772 // Spell learning
773 SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const
775 SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id);
776 if(itr != mSpellLearnSkills.end())
777 return &itr->second;
778 else
779 return NULL;
782 bool IsSpellLearnSpell(uint32 spell_id) const
784 return mSpellLearnSpells.count(spell_id)!=0;
787 SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const
789 return mSpellLearnSpells.lower_bound(spell_id);
792 SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const
794 return mSpellLearnSpells.upper_bound(spell_id);
797 bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const
799 SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1);
800 SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1);
801 for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i)
802 if(i->second.spell==spell_id2)
803 return true;
804 return false;
807 static bool IsProfessionSpell(uint32 spellId);
808 static bool IsPrimaryProfessionSpell(uint32 spellId);
809 bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const;
811 // Spell script targets
812 SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const
814 return mSpellScriptTarget.lower_bound(spell_id);
817 SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const
819 return mSpellScriptTarget.upper_bound(spell_id);
822 // Spell correctess for client using
823 static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true);
825 SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const
827 return mSkillLineAbilityMap.lower_bound(spell_id);
830 SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const
832 return mSkillLineAbilityMap.upper_bound(spell_id);
835 PetAura const* GetPetAura(uint16 spell_id)
837 SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find(spell_id);
838 if(itr != mSpellPetAuraMap.end())
839 return &itr->second;
840 else
841 return NULL;
844 // Modifiers
845 public:
846 static SpellMgr& Instance();
848 // Loading data at server startup
849 void LoadSpellChains();
850 void LoadSpellLearnSkills();
851 void LoadSpellLearnSpells();
852 void LoadSpellScriptTarget();
853 void LoadSpellAffects();
854 void LoadSpellElixirs();
855 void LoadSpellProcEvents();
856 void LoadSpellTargetPositions();
857 void LoadSpellThreats();
858 void LoadSkillLineAbilityMap();
859 void LoadSpellPetAuras();
861 private:
862 SpellScriptTarget mSpellScriptTarget;
863 SpellChainMap mSpellChains;
864 SpellChainMapNext mSpellChainsNext;
865 SpellLearnSkillMap mSpellLearnSkills;
866 SpellLearnSpellMap mSpellLearnSpells;
867 SpellTargetPositionMap mSpellTargetPositions;
868 SpellAffectMap mSpellAffectMap;
869 SpellElixirMap mSpellElixirs;
870 SpellProcEventMap mSpellProcEventMap;
871 SkillLineAbilityMap mSkillLineAbilityMap;
872 SpellPetAuraMap mSpellPetAuraMap;
875 #define spellmgr SpellMgr::Instance()
876 #endif