* Fix some warlock talent work
[getmangos.git] / src / game / SpellMgr.h
blobc996ac4489cd27914eb0f55d24d45ca52e0bea6b
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/UnorderedMap.h"
30 #include <map>
32 class Player;
33 class Spell;
35 extern SQLStorage sSpellThreatStore;
37 enum SpellFailedReason
39 SPELL_FAILED_AFFECTING_COMBAT = 0x00,
40 SPELL_FAILED_ALREADY_AT_FULL_HEALTH = 0x01,
41 SPELL_FAILED_ALREADY_AT_FULL_MANA = 0x02,
42 SPELL_FAILED_ALREADY_AT_FULL_POWER = 0x03,
43 SPELL_FAILED_ALREADY_BEING_TAMED = 0x04,
44 SPELL_FAILED_ALREADY_HAVE_CHARM = 0x05,
45 SPELL_FAILED_ALREADY_HAVE_SUMMON = 0x06,
46 SPELL_FAILED_ALREADY_OPEN = 0x07,
47 SPELL_FAILED_AURA_BOUNCED = 0x08,
48 SPELL_FAILED_AUTOTRACK_INTERRUPTED = 0x09,
49 SPELL_FAILED_BAD_IMPLICIT_TARGETS = 0x0A,
50 SPELL_FAILED_BAD_TARGETS = 0x0B,
51 SPELL_FAILED_CANT_BE_CHARMED = 0x0C,
52 SPELL_FAILED_CANT_BE_DISENCHANTED = 0x0D,
53 SPELL_FAILED_CANT_BE_DISENCHANTED_SKILL = 0x0E,
54 SPELL_FAILED_CANT_BE_PROSPECTED = 0x0F,
55 SPELL_FAILED_CANT_CAST_ON_TAPPED = 0x10,
56 SPELL_FAILED_CANT_DUEL_WHILE_INVISIBLE = 0x11,
57 SPELL_FAILED_CANT_DUEL_WHILE_STEALTHED = 0x12,
58 SPELL_FAILED_CANT_STEALTH = 0x13,
59 SPELL_FAILED_CASTER_AURASTATE = 0x14,
60 SPELL_FAILED_CASTER_DEAD = 0x15,
61 SPELL_FAILED_CHARMED = 0x16,
62 SPELL_FAILED_CHEST_IN_USE = 0x17,
63 SPELL_FAILED_CONFUSED = 0x18,
64 SPELL_FAILED_DONT_REPORT = 0x19,
65 SPELL_FAILED_EQUIPPED_ITEM = 0x1A,
66 SPELL_FAILED_EQUIPPED_ITEM_CLASS = 0x1B,
67 SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND = 0x1C,
68 SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND = 0x1D,
69 SPELL_FAILED_ERROR = 0x1E,
70 SPELL_FAILED_FIZZLE = 0x1F,
71 SPELL_FAILED_FLEEING = 0x20,
72 SPELL_FAILED_FOOD_LOWLEVEL = 0x21,
73 SPELL_FAILED_HIGHLEVEL = 0x22,
74 SPELL_FAILED_HUNGER_SATIATED = 0x23,
75 SPELL_FAILED_IMMUNE = 0x24,
76 SPELL_FAILED_INTERRUPTED = 0x25,
77 SPELL_FAILED_INTERRUPTED_COMBAT = 0x26,
78 SPELL_FAILED_ITEM_ALREADY_ENCHANTED = 0x27,
79 SPELL_FAILED_ITEM_GONE = 0x28,
80 SPELL_FAILED_ITEM_NOT_FOUND = 0x29,
81 SPELL_FAILED_ITEM_NOT_READY = 0x2A,
82 SPELL_FAILED_LEVEL_REQUIREMENT = 0x2B,
83 SPELL_FAILED_LINE_OF_SIGHT = 0x2C,
84 SPELL_FAILED_LOWLEVEL = 0x2D,
85 SPELL_FAILED_LOW_CASTLEVEL = 0x2E,
86 SPELL_FAILED_MAINHAND_EMPTY = 0x2F,
87 SPELL_FAILED_MOVING = 0x30,
88 SPELL_FAILED_NEED_AMMO = 0x31,
89 SPELL_FAILED_NEED_AMMO_POUCH = 0x32,
90 SPELL_FAILED_NEED_EXOTIC_AMMO = 0x33,
91 SPELL_FAILED_NOPATH = 0x34,
92 SPELL_FAILED_NOT_BEHIND = 0x35,
93 SPELL_FAILED_NOT_FISHABLE = 0x36,
94 SPELL_FAILED_NOT_FLYING = 0x37,
95 SPELL_FAILED_NOT_HERE = 0x38,
96 SPELL_FAILED_NOT_INFRONT = 0x39,
97 SPELL_FAILED_NOT_IN_CONTROL = 0x3A,
98 SPELL_FAILED_NOT_KNOWN = 0x3B,
99 SPELL_FAILED_NOT_MOUNTED = 0x3C,
100 SPELL_FAILED_NOT_ON_TAXI = 0x3D,
101 SPELL_FAILED_NOT_ON_TRANSPORT = 0x3E,
102 SPELL_FAILED_NOT_READY = 0x3F,
103 SPELL_FAILED_NOT_SHAPESHIFT = 0x40,
104 SPELL_FAILED_NOT_STANDING = 0x41,
105 SPELL_FAILED_NOT_TRADEABLE = 0x42,
106 SPELL_FAILED_NOT_TRADING = 0x43,
107 SPELL_FAILED_NOT_UNSHEATHED = 0x44,
108 SPELL_FAILED_NOT_WHILE_GHOST = 0x45,
109 SPELL_FAILED_NO_AMMO = 0x46,
110 SPELL_FAILED_NO_CHARGES_REMAIN = 0x47,
111 SPELL_FAILED_NO_CHAMPION = 0x48,
112 SPELL_FAILED_NO_COMBO_POINTS = 0x49,
113 SPELL_FAILED_NO_DUELING = 0x4A,
114 SPELL_FAILED_NO_ENDURANCE = 0x4B,
115 SPELL_FAILED_NO_FISH = 0x4C,
116 SPELL_FAILED_NO_ITEMS_WHILE_SHAPESHIFTED = 0x4D,
117 SPELL_FAILED_NO_MOUNTS_ALLOWED = 0x4E,
118 SPELL_FAILED_NO_PET = 0x4F,
119 SPELL_FAILED_NO_POWER = 0x50,
120 SPELL_FAILED_NOTHING_TO_DISPEL = 0x51,
121 SPELL_FAILED_NOTHING_TO_STEAL = 0x52,
122 SPELL_FAILED_ONLY_ABOVEWATER = 0x53,
123 SPELL_FAILED_ONLY_DAYTIME = 0x54,
124 SPELL_FAILED_ONLY_INDOORS = 0x55,
125 SPELL_FAILED_ONLY_MOUNTED = 0x56,
126 SPELL_FAILED_ONLY_NIGHTTIME = 0x57,
127 SPELL_FAILED_ONLY_OUTDOORS = 0x58,
128 SPELL_FAILED_ONLY_SHAPESHIFT = 0x59,
129 SPELL_FAILED_ONLY_STEALTHED = 0x5A,
130 SPELL_FAILED_ONLY_UNDERWATER = 0x5B,
131 SPELL_FAILED_OUT_OF_RANGE = 0x5C,
132 SPELL_FAILED_PACIFIED = 0x5D,
133 SPELL_FAILED_POSSESSED = 0x5E,
134 SPELL_FAILED_REAGENTS = 0x5F,
135 SPELL_FAILED_REQUIRES_AREA = 0x60,
136 SPELL_FAILED_REQUIRES_SPELL_FOCUS = 0x61,
137 SPELL_FAILED_ROOTED = 0x62,
138 SPELL_FAILED_SILENCED = 0x63,
139 SPELL_FAILED_SPELL_IN_PROGRESS = 0x64,
140 SPELL_FAILED_SPELL_LEARNED = 0x65,
141 SPELL_FAILED_SPELL_UNAVAILABLE = 0x66,
142 SPELL_FAILED_STUNNED = 0x67,
143 SPELL_FAILED_TARGETS_DEAD = 0x68,
144 SPELL_FAILED_TARGET_AFFECTING_COMBAT = 0x69,
145 SPELL_FAILED_TARGET_AURASTATE = 0x6A,
146 SPELL_FAILED_TARGET_DUELING = 0x6B,
147 SPELL_FAILED_TARGET_ENEMY = 0x6C,
148 SPELL_FAILED_TARGET_ENRAGED = 0x6D,
149 SPELL_FAILED_TARGET_FRIENDLY = 0x6E,
150 SPELL_FAILED_TARGET_IN_COMBAT = 0x6F,
151 SPELL_FAILED_TARGET_IS_PLAYER = 0x70,
152 SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED = 0x71,
153 SPELL_FAILED_TARGET_NOT_DEAD = 0x72,
154 SPELL_FAILED_TARGET_NOT_IN_PARTY = 0x73,
155 SPELL_FAILED_TARGET_NOT_LOOTED = 0x74,
156 SPELL_FAILED_TARGET_NOT_PLAYER = 0x75,
157 SPELL_FAILED_TARGET_NO_POCKETS = 0x76,
158 SPELL_FAILED_TARGET_NO_WEAPONS = 0x77,
159 SPELL_FAILED_TARGET_UNSKINNABLE = 0x78,
160 SPELL_FAILED_THIRST_SATIATED = 0x79,
161 SPELL_FAILED_TOO_CLOSE = 0x7A,
162 SPELL_FAILED_TOO_MANY_OF_ITEM = 0x7B,
163 SPELL_FAILED_TOTEM_CATEGORY = 0x7C,
164 SPELL_FAILED_TOTEMS = 0x7D,
165 SPELL_FAILED_TRAINING_POINTS = 0x7E,
166 SPELL_FAILED_TRY_AGAIN = 0x7F,
167 SPELL_FAILED_UNIT_NOT_BEHIND = 0x80,
168 SPELL_FAILED_UNIT_NOT_INFRONT = 0x81,
169 SPELL_FAILED_WRONG_PET_FOOD = 0x82,
170 SPELL_FAILED_NOT_WHILE_FATIGUED = 0x83,
171 SPELL_FAILED_TARGET_NOT_IN_INSTANCE = 0x84,
172 SPELL_FAILED_NOT_WHILE_TRADING = 0x85,
173 SPELL_FAILED_TARGET_NOT_IN_RAID = 0x86,
174 SPELL_FAILED_DISENCHANT_WHILE_LOOTING = 0x87,
175 SPELL_FAILED_PROSPECT_WHILE_LOOTING = 0x88,
176 SPELL_FAILED_PROSPECT_NEED_MORE = 0x89,
177 SPELL_FAILED_TARGET_FREEFORALL = 0x8A,
178 SPELL_FAILED_NO_EDIBLE_CORPSES = 0x8B,
179 SPELL_FAILED_ONLY_BATTLEGROUNDS = 0x8C,
180 SPELL_FAILED_TARGET_NOT_GHOST = 0x8D,
181 SPELL_FAILED_TOO_MANY_SKILLS = 0x8E,
182 SPELL_FAILED_TRANSFORM_UNUSABLE = 0x8F,
183 SPELL_FAILED_WRONG_WEATHER = 0x90,
184 SPELL_FAILED_DAMAGE_IMMUNE = 0x91,
185 SPELL_FAILED_PREVENTED_BY_MECHANIC = 0x92,
186 SPELL_FAILED_PLAY_TIME = 0x93,
187 SPELL_FAILED_REPUTATION = 0x94,
188 SPELL_FAILED_MIN_SKILL = 0x95,
189 SPELL_FAILED_NOT_IN_ARENA = 0x96,
190 SPELL_FAILED_NOT_ON_SHAPESHIFT = 0x97,
191 SPELL_FAILED_NOT_ON_STEALTHED = 0x98,
192 SPELL_FAILED_NOT_ON_DAMAGE_IMMUNE = 0x99,
193 SPELL_FAILED_NOT_ON_MOUNTED = 0x9A,
194 SPELL_FAILED_TOO_SHALLOW = 0x9B,
195 SPELL_FAILED_TARGET_NOT_IN_SANCTUARY = 0x9C,
196 SPELL_FAILED_TARGET_IS_TRIVIAL = 0x9D,
197 SPELL_FAILED_BM_OR_INVISGOD = 0x9E,
198 SPELL_FAILED_EXPERT_RIDING_REQUIREMENT = 0x9F,
199 SPELL_FAILED_ARTISAN_RIDING_REQUIREMENT = 0xA0,
200 SPELL_FAILED_NOT_IDLE = 0xA1,
201 SPELL_FAILED_NOT_INACTIVE = 0xA2,
202 SPELL_FAILED_PARTIAL_PLAYTIME = 0xA3,
203 SPELL_FAILED_NO_PLAYTIME = 0xA4,
204 SPELL_FAILED_NOT_IN_BATTLEGROUND = 0xA5,
205 SPELL_FAILED_ONLY_IN_ARENA = 0xA6,
206 SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE = 0xA7,
207 SPELL_FAILED_UNKNOWN = 0xA8,
210 enum SpellFamilyNames
212 SPELLFAMILY_GENERIC = 0,
213 SPELLFAMILY_UNK1 = 1, // events, holidays
214 // 2 - unused
215 SPELLFAMILY_MAGE = 3,
216 SPELLFAMILY_WARRIOR = 4,
217 SPELLFAMILY_WARLOCK = 5,
218 SPELLFAMILY_PRIEST = 6,
219 SPELLFAMILY_DRUID = 7,
220 SPELLFAMILY_ROGUE = 8,
221 SPELLFAMILY_HUNTER = 9,
222 SPELLFAMILY_PALADIN = 10,
223 SPELLFAMILY_SHAMAN = 11,
224 SPELLFAMILY_UNK2 = 12,
225 SPELLFAMILY_POTION = 13,
226 // 14 - unused
227 SPELLFAMILY_DEATHKNIGHT = 15,
228 // 16 - unused
229 SPELLFAMILY_UNK3 = 17
232 //Some SpellFamilyFlags
233 #define SPELLFAMILYFLAG_ROGUE_VANISH 0x000000800LL
234 #define SPELLFAMILYFLAG_ROGUE_STEALTH 0x000400000LL
235 #define SPELLFAMILYFLAG_ROGUE_BACKSTAB 0x000800004LL
236 #define SPELLFAMILYFLAG_ROGUE_SAP 0x000000080LL
237 #define SPELLFAMILYFLAG_ROGUE_FEINT 0x008000000LL
238 #define SPELLFAMILYFLAG_ROGUE_KIDNEYSHOT 0x000200000LL
239 #define SPELLFAMILYFLAG_ROGUE__FINISHING_MOVE 0x9003E0000LL
241 // Spell clasification
242 enum SpellSpecific
244 SPELL_NORMAL = 0,
245 SPELL_SEAL = 1,
246 SPELL_BLESSING = 2,
247 SPELL_AURA = 3,
248 SPELL_STING = 4,
249 SPELL_CURSE = 5,
250 SPELL_ASPECT = 6,
251 SPELL_TRACKER = 7,
252 SPELL_WARLOCK_ARMOR = 8,
253 SPELL_MAGE_ARMOR = 9,
254 SPELL_ELEMENTAL_SHIELD = 10,
255 SPELL_MAGE_POLYMORPH = 11,
256 SPELL_POSITIVE_SHOUT = 12,
257 SPELL_JUDGEMENT = 13,
258 SPELL_BATTLE_ELIXIR = 14,
259 SPELL_GUARDIAN_ELIXIR = 15,
260 SPELL_FLASK_ELIXIR = 16
263 SpellSpecific GetSpellSpecific(uint32 spellId);
265 // Different spell properties
266 inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); }
267 uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL);
268 inline float GetSpellMinRange(SpellRangeEntry const *range) { return (range ? range->minRange : 0); }
269 inline float GetSpellMaxRange(SpellRangeEntry const *range) { return (range ? range->maxRange : 0); }
270 inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; }
271 int32 GetSpellDuration(SpellEntry const *spellInfo);
272 int32 GetSpellMaxDuration(SpellEntry const *spellInfo);
274 inline bool IsSpellHaveEffect(SpellEntry const *spellInfo, SpellEffects effect)
276 for(int i= 0; i < 3; ++i)
277 if(spellInfo->Effect[i]==effect)
278 return true;
279 return false;
282 bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
284 inline bool IsSealSpell(SpellEntry const *spellInfo)
286 //Collection of all the seal family flags. No other paladin spell has any of those.
287 return spellInfo->SpellFamilyName == SPELLFAMILY_PALADIN &&
288 ( spellInfo->SpellFamilyFlags & 0x4000A000200LL );
291 inline bool IsElementalShield(SpellEntry const *spellInfo)
293 // family flags 10 (Lightning), 42 (Earth), 37 (Water), proc shield from T2 8 pieces bonus
294 return (spellInfo->SpellFamilyFlags & 0x42000000400LL) || spellInfo->Id == 23552;
297 int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2);
298 bool IsSingleFromSpellSpecificPerCaster(uint32 spellSpec1,uint32 spellSpec2);
299 bool IsPassiveSpell(uint32 spellId);
301 inline bool IsDeathPersistentSpell(SpellEntry const *spellInfo)
303 switch(spellInfo->Id)
305 case 40214: // Dragonmaw Illusion
306 case 35480: case 35481: case 35482: // Human Illusion
307 case 35483: case 39824: // Human Illusion
308 return true;
311 return spellInfo->AttributesEx3 & SPELL_ATTR_EX3_DEATH_PERSISTENT;
314 inline bool IsNonCombatSpell(SpellEntry const *spellInfo)
316 return (spellInfo->Attributes & SPELL_ATTR_CANT_USED_IN_COMBAT) != 0;
319 bool IsPositiveSpell(uint32 spellId);
320 bool IsPositiveEffect(uint32 spellId, uint32 effIndex);
321 bool IsPositiveTarget(uint32 targetA, uint32 targetB);
323 bool IsSingleTargetSpell(SpellEntry const *spellInfo);
324 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2);
326 bool IsAuraAddedBySpell(uint32 auraType, uint32 spellId);
328 bool IsSpellAllowedInLocation(SpellEntry const *spellInfo,uint32 map_id,uint32 zone_id,uint32 area_id);
330 inline bool IsAreaEffectTarget( Targets target )
332 switch (target )
334 case TARGET_AREAEFFECT_CUSTOM:
335 case TARGET_ALL_ENEMY_IN_AREA:
336 case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
337 case TARGET_ALL_PARTY_AROUND_CASTER:
338 case TARGET_ALL_AROUND_CASTER:
339 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
340 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER:
341 case TARGET_ALL_PARTY:
342 case TARGET_ALL_PARTY_AROUND_CASTER_2:
343 case TARGET_AREAEFFECT_PARTY:
344 case TARGET_AREAEFFECT_CUSTOM_2:
345 case TARGET_AREAEFFECT_PARTY_AND_CLASS:
346 case TARGET_IN_FRONT_OF_CASTER:
347 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA:
348 return true;
349 default:
350 break;
352 return false;
355 inline bool IsAreaOfEffectSpell(SpellEntry const *spellInfo)
357 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[0])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[0])))
358 return true;
359 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[1])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[1])))
360 return true;
361 if(IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetA[2])) || IsAreaEffectTarget(Targets(spellInfo->EffectImplicitTargetB[2])))
362 return true;
363 return false;
366 inline bool IsAreaAuraEffect(uint32 effect)
368 if( effect == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
369 effect == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND ||
370 effect == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY ||
371 effect == SPELL_EFFECT_APPLY_AREA_AURA_PET ||
372 effect == SPELL_EFFECT_APPLY_AREA_AURA_OWNER)
373 return true;
374 return false;
377 inline bool IsDispelSpell(SpellEntry const *spellInfo)
379 if (spellInfo->Effect[0] == SPELL_EFFECT_DISPEL ||
380 spellInfo->Effect[1] == SPELL_EFFECT_DISPEL ||
381 spellInfo->Effect[2] == SPELL_EFFECT_DISPEL )
382 return true;
383 return false;
385 inline bool isSpellBreakStealth(SpellEntry const* spellInfo)
387 return !(spellInfo->AttributesEx & SPELL_ATTR_EX_NOT_BREAK_STEALTH);
390 uint8 GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form);
392 inline bool IsChanneledSpell(SpellEntry const* spellInfo)
394 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_CHANNELED_1 | SPELL_ATTR_EX_CHANNELED_2));
397 inline bool NeedsComboPoints(SpellEntry const* spellInfo)
399 return (spellInfo->AttributesEx & (SPELL_ATTR_EX_REQ_COMBO_POINTS1 | SPELL_ATTR_EX_REQ_COMBO_POINTS2));
402 inline SpellSchoolMask GetSpellSchoolMask(SpellEntry const* spellInfo)
404 return SpellSchoolMask(spellInfo->SchoolMask);
407 inline uint32 GetSpellMechanicMask(SpellEntry const* spellInfo, int32 effect)
409 uint32 mask = 0;
410 if (spellInfo->Mechanic)
411 mask |= 1<<spellInfo->Mechanic;
412 if (spellInfo->EffectMechanic[effect])
413 mask |= 1<<spellInfo->EffectMechanic[effect];
414 return mask;
417 inline Mechanics GetEffectMechanic(SpellEntry const* spellInfo, int32 effect)
419 if (spellInfo->EffectMechanic[effect])
420 return Mechanics(spellInfo->EffectMechanic[effect]);
421 if (spellInfo->Mechanic)
422 return Mechanics(spellInfo->Mechanic);
423 return MECHANIC_NONE;
426 inline uint32 GetDispellMask(DispelType dispel)
428 // If dispell all
429 if (dispel == DISPEL_ALL)
430 return DISPEL_ALL_MASK;
431 else
432 return (1 << dispel);
435 // Diminishing Returns interaction with spells
436 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered);
437 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
438 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group);
440 // Spell affects related declarations (accessed using SpellMgr functions)
441 typedef std::map<uint32, uint64> SpellAffectMap;
443 // Spell proc event related declarations (accessed using SpellMgr functions)
444 enum ProcFlags
446 PROC_FLAG_NONE = 0x00000000,
448 PROC_FLAG_KILLED = 0x00000001, // 00 Killed by agressor
449 PROC_FLAG_KILL_AND_GET_XP = 0x00000002, // 01 Kill that yields experience or honor
451 PROC_FLAG_SUCCESSFUL_MILEE_HIT = 0x00000004, // 02 Successful melee attack
452 PROC_FLAG_TAKEN_MELEE_HIT = 0x00000008, // 03 Taken damage from melee strike hit
454 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT = 0x00000010, // 04 Successful attack by Spell that use melee weapon
455 PROC_FLAG_TAKEN_MELEE_SPELL_HIT = 0x00000020, // 05 Taken damage by Spell that use melee weapon
457 PROC_FLAG_SUCCESSFUL_RANGED_HIT = 0x00000040, // 06 Successful Ranged attack (all ranged attack deal as spell so newer set :( )
458 PROC_FLAG_TAKEN_RANGED_HIT = 0x00000080, // 07 Taken damage from ranged attack (all ranged attack deal as spell so newer set :( )
460 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT = 0x00000100, // 08 Successful Ranged attack by Spell that use ranged weapon
461 PROC_FLAG_TAKEN_RANGED_SPELL_HIT = 0x00000200, // 09 Taken damage by Spell that use ranged weapon
463 PROC_FLAG_SUCCESSFUL_POSITIVE_AOE_HIT = 0x00000400, // 10 Successful AoE (not 100% shure unused)
464 PROC_FLAG_TAKEN_POSITIVE_AOE = 0x00000800, // 11 Taken AoE (not 100% shure unused)
466 PROC_FLAG_SUCCESSFUL_AOE_SPELL_HIT = 0x00001000, // 12 Successful AoE damage spell hit (not 100% shure unused)
467 PROC_FLAG_TAKEN_AOE_SPELL_HIT = 0x00002000, // 13 Taken AoE damage spell hit (not 100% shure unused)
469 PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL = 0x00004000, // 14 Successful cast positive spell (by default only on healing)
470 PROC_FLAG_TAKEN_POSITIVE_SPELL = 0x00008000, // 15 Taken positive spell hit (by default only on healing)
472 PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT = 0x00010000, // 16 Successful negative spell cast (by default only on damage)
473 PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT = 0x00020000, // 17 Taken negative spell (by default only on damage)
475 PROC_FLAG_ON_DO_PERIODIC = 0x00040000, // 18 Successful do periodic (damage / healing, determined from 14-17 flags)
476 PROC_FLAG_ON_TAKE_PERIODIC = 0x00080000, // 19 Taken spell periodic (damage / healing, determined from 14-17 flags)
478 PROC_FLAG_TAKEN_ANY_DAMAGE = 0x00100000, // 20 Taken any damage
479 PROC_FLAG_ON_TRAP_ACTIVATION = 0x00200000, // 21 On trap activation
481 PROC_FLAG_TAKEN_OFFHAND_HIT = 0x00400000, // 22 Taken off-hand melee attacks(not used)
482 PROC_FLAG_SUCCESSFUL_OFFHAND_HIT = 0x00800000 // 23 Successful off-hand melee attacks
485 #define MELEE_BASED_TRIGGER_MASK (PROC_FLAG_SUCCESSFUL_MILEE_HIT | \
486 PROC_FLAG_TAKEN_MELEE_HIT | \
487 PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT | \
488 PROC_FLAG_TAKEN_MELEE_SPELL_HIT | \
489 PROC_FLAG_SUCCESSFUL_RANGED_HIT | \
490 PROC_FLAG_TAKEN_RANGED_HIT | \
491 PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT | \
492 PROC_FLAG_TAKEN_RANGED_SPELL_HIT)
494 enum ProcFlagsEx
496 PROC_EX_NONE = 0x0000000, // If none can tigger on Hit/Crit only (passive spells MUST defined by SpellFamily flag)
497 PROC_EX_NORMAL_HIT = 0x0000001, // If set only from normal hit (only damage spells)
498 PROC_EX_CRITICAL_HIT = 0x0000002,
499 PROC_EX_MISS = 0x0000004,
500 PROC_EX_RESIST = 0x0000008,
501 PROC_EX_DODGE = 0x0000010,
502 PROC_EX_PARRY = 0x0000020,
503 PROC_EX_BLOCK = 0x0000040,
504 PROC_EX_EVADE = 0x0000080,
505 PROC_EX_IMMUNE = 0x0000100,
506 PROC_EX_DEFLECT = 0x0000200,
507 PROC_EX_ABSORB = 0x0000400,
508 PROC_EX_REFLECT = 0x0000800,
509 PROC_EX_INTERRUPT = 0x0001000, // Melle hit result can be Interrupt (not used)
510 PROC_EX_RESERVED1 = 0x0002000,
511 PROC_EX_RESERVED2 = 0x0004000,
512 PROC_EX_RESERVED3 = 0x0008000,
513 PROC_EX_EX_TRIGGER_ALWAYS = 0x0010000, // If set trigger always ( no matter another flags) used for drop charges
514 PROC_EX_EX_ONE_TIME_TRIGGER = 0x0020000 // If set trigger always but only one time
517 struct SpellProcEventEntry
519 uint32 schoolMask; // if nonzero - bit mask for matching proc condition based on spell candidate's school: Fire=2, Mask=1<<(2-1)=2
520 uint32 spellFamilyName; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyNamer value
521 uint64 spellFamilyMask; // if nonzero - for matching proc condition based on candidate spell's SpellFamilyFlags (like auras 107 and 108 do)
522 uint32 procFlags; // bitmask for matching proc event
523 uint32 procEx; // proc Extend info (see ProcFlagsEx)
524 float ppmRate; // for melee (ranged?) damage spells - proc rate per minute. if zero, falls back to flat chance from Spell.dbc
525 float customChance; // Owerride chance (in most cases for debug only)
526 uint32 cooldown; // hidden cooldown used for some spell proc events, applied to _triggered_spell_
529 typedef UNORDERED_MAP<uint32, SpellProcEventEntry> SpellProcEventMap;
531 #define ELIXIR_BATTLE_MASK 0x1
532 #define ELIXIR_GUARDIAN_MASK 0x2
533 #define ELIXIR_FLASK_MASK (ELIXIR_BATTLE_MASK|ELIXIR_GUARDIAN_MASK)
534 #define ELIXIR_UNSTABLE_MASK 0x4
535 #define ELIXIR_SHATTRATH_MASK 0x8
537 typedef std::map<uint32, uint8> SpellElixirMap;
539 // Spell script target related declarations (accessed using SpellMgr functions)
540 enum SpellTargetType
542 SPELL_TARGET_TYPE_GAMEOBJECT = 0,
543 SPELL_TARGET_TYPE_CREATURE = 1,
544 SPELL_TARGET_TYPE_DEAD = 2
547 #define MAX_SPELL_TARGET_TYPE 3
549 struct SpellTargetEntry
551 SpellTargetEntry(SpellTargetType type_,uint32 targetEntry_) : type(type_), targetEntry(targetEntry_) {}
552 SpellTargetType type;
553 uint32 targetEntry;
556 typedef std::multimap<uint32,SpellTargetEntry> SpellScriptTarget;
558 // coordinates for spells (accessed using SpellMgr functions)
559 struct SpellTargetPosition
561 uint32 target_mapId;
562 float target_X;
563 float target_Y;
564 float target_Z;
565 float target_Orientation;
568 typedef UNORDERED_MAP<uint32, SpellTargetPosition> SpellTargetPositionMap;
570 // Spell pet auras
571 class PetAura
573 public:
574 PetAura()
576 auras.clear();
579 PetAura(uint16 petEntry, uint16 aura, bool _removeOnChangePet, int _damage) :
580 removeOnChangePet(_removeOnChangePet), damage(_damage)
582 auras[petEntry] = aura;
585 uint16 GetAura(uint16 petEntry) const
587 std::map<uint16, uint16>::const_iterator itr = auras.find(petEntry);
588 if(itr != auras.end())
589 return itr->second;
590 else
592 std::map<uint16, uint16>::const_iterator itr = auras.find(0);
593 if(itr != auras.end())
594 return itr->second;
595 else
596 return 0;
600 void AddAura(uint16 petEntry, uint16 aura)
602 auras[petEntry] = aura;
605 bool IsRemovedOnChangePet() const
607 return removeOnChangePet;
610 int32 GetDamage() const
612 return damage;
615 private:
616 std::map<uint16, uint16> auras;
617 bool removeOnChangePet;
618 int32 damage;
620 typedef std::map<uint16, PetAura> SpellPetAuraMap;
622 // Spell rank chain (accessed using SpellMgr functions)
623 struct SpellChainNode
625 uint32 prev;
626 uint32 first;
627 uint32 req;
628 uint8 rank;
631 typedef UNORDERED_MAP<uint32, SpellChainNode> SpellChainMap;
632 typedef std::multimap<uint32, uint32> SpellChainMapNext;
634 // Spell learning properties (accessed using SpellMgr functions)
635 struct SpellLearnSkillNode
637 uint32 skill;
638 uint32 value; // 0 - max skill value for player level
639 uint32 maxvalue; // 0 - max skill value for player level
642 typedef std::map<uint32, SpellLearnSkillNode> SpellLearnSkillMap;
644 struct SpellLearnSpellNode
646 uint32 spell;
647 bool autoLearned;
650 typedef std::multimap<uint32, SpellLearnSpellNode> SpellLearnSpellMap;
652 typedef std::multimap<uint32, SkillLineAbilityEntry const*> SkillLineAbilityMap;
654 inline bool IsPrimaryProfessionSkill(uint32 skill)
656 SkillLineEntry const *pSkill = sSkillLineStore.LookupEntry(skill);
657 if(!pSkill)
658 return false;
660 if(pSkill->categoryId != SKILL_CATEGORY_PROFESSION)
661 return false;
663 return true;
666 inline bool IsProfessionSkill(uint32 skill)
668 return IsPrimaryProfessionSkill(skill) || skill == SKILL_FISHING || skill == SKILL_COOKING || skill == SKILL_FIRST_AID;
671 class SpellMgr
673 // Constructors
674 public:
675 SpellMgr();
676 ~SpellMgr();
678 // Accessors (const or static functions)
679 public:
680 // Spell affects
681 uint64 GetSpellAffectMask(uint16 spellId, uint8 effectId) const
683 SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId<<8) + effectId);
684 if( itr != mSpellAffectMap.end( ) )
685 return itr->second;
686 return 0;
689 bool IsAffectedBySpell(SpellEntry const *spellInfo, uint32 spellId, uint8 effectId, uint64 familyFlags) const;
691 SpellElixirMap const& GetSpellElixirMap() const { return mSpellElixirs; }
693 uint32 GetSpellElixirMask(uint32 spellid) const
695 SpellElixirMap::const_iterator itr = mSpellElixirs.find(spellid);
696 if(itr==mSpellElixirs.end())
697 return 0x0;
699 return itr->second;
702 SpellSpecific GetSpellElixirSpecific(uint32 spellid) const
704 uint32 mask = GetSpellElixirMask(spellid);
705 if((mask & ELIXIR_FLASK_MASK)==ELIXIR_FLASK_MASK)
706 return SPELL_FLASK_ELIXIR;
707 else if(mask & ELIXIR_BATTLE_MASK)
708 return SPELL_BATTLE_ELIXIR;
709 else if(mask & ELIXIR_GUARDIAN_MASK)
710 return SPELL_GUARDIAN_ELIXIR;
711 else
712 return SPELL_NORMAL;
715 // Spell proc events
716 SpellProcEventEntry const* GetSpellProcEvent(uint32 spellId) const
718 SpellProcEventMap::const_iterator itr = mSpellProcEventMap.find(spellId);
719 if( itr != mSpellProcEventMap.end( ) )
720 return &itr->second;
721 return NULL;
724 static bool IsSpellProcEventCanTriggeredBy( SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active);
726 // Spell target coordinates
727 SpellTargetPosition const* GetSpellTargetPosition(uint32 spell_id) const
729 SpellTargetPositionMap::const_iterator itr = mSpellTargetPositions.find( spell_id );
730 if( itr != mSpellTargetPositions.end( ) )
731 return &itr->second;
732 return NULL;
735 // Spell ranks chains
736 SpellChainNode const* GetSpellChainNode(uint32 spell_id) const
738 SpellChainMap::const_iterator itr = mSpellChains.find(spell_id);
739 if(itr == mSpellChains.end())
740 return NULL;
742 return &itr->second;
745 uint32 GetFirstSpellInChain(uint32 spell_id) const
747 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
748 return node->first;
750 return spell_id;
753 uint32 GetPrevSpellInChain(uint32 spell_id) const
755 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
756 return node->prev;
758 return 0;
761 SpellChainMapNext const& GetSpellChainNext() const { return mSpellChainsNext; }
763 // Note: not use rank for compare to spell ranks: spell chains isn't linear order
764 // Use IsHighRankOfSpell instead
765 uint8 GetSpellRank(uint32 spell_id) const
767 if(SpellChainNode const* node = GetSpellChainNode(spell_id))
768 return node->rank;
770 return 0;
773 uint8 IsHighRankOfSpell(uint32 spell1,uint32 spell2) const
775 SpellChainMap::const_iterator itr = mSpellChains.find(spell1);
777 uint32 rank2 = GetSpellRank(spell2);
779 // not ordered correctly by rank value
780 if(itr == mSpellChains.end() || !rank2 || itr->second.rank <= rank2)
781 return false;
783 // check present in same rank chain
784 for(; itr != mSpellChains.end(); itr = mSpellChains.find(itr->second.prev))
785 if(itr->second.prev==spell2)
786 return true;
788 return false;
791 bool IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const;
792 static bool canStackSpellRanks(SpellEntry const *spellInfo);
793 bool IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const;
795 SpellEntry const* SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const;
797 // Spell learning
798 SpellLearnSkillNode const* GetSpellLearnSkill(uint32 spell_id) const
800 SpellLearnSkillMap::const_iterator itr = mSpellLearnSkills.find(spell_id);
801 if(itr != mSpellLearnSkills.end())
802 return &itr->second;
803 else
804 return NULL;
807 bool IsSpellLearnSpell(uint32 spell_id) const
809 return mSpellLearnSpells.count(spell_id)!=0;
812 SpellLearnSpellMap::const_iterator GetBeginSpellLearnSpell(uint32 spell_id) const
814 return mSpellLearnSpells.lower_bound(spell_id);
817 SpellLearnSpellMap::const_iterator GetEndSpellLearnSpell(uint32 spell_id) const
819 return mSpellLearnSpells.upper_bound(spell_id);
822 bool IsSpellLearnToSpell(uint32 spell_id1,uint32 spell_id2) const
824 SpellLearnSpellMap::const_iterator b = GetBeginSpellLearnSpell(spell_id1);
825 SpellLearnSpellMap::const_iterator e = GetEndSpellLearnSpell(spell_id1);
826 for(SpellLearnSpellMap::const_iterator i = b; i != e; ++i)
827 if(i->second.spell==spell_id2)
828 return true;
829 return false;
832 static bool IsProfessionSpell(uint32 spellId);
833 static bool IsPrimaryProfessionSpell(uint32 spellId);
834 bool IsPrimaryProfessionFirstRankSpell(uint32 spellId) const;
836 // Spell script targets
837 SpellScriptTarget::const_iterator GetBeginSpellScriptTarget(uint32 spell_id) const
839 return mSpellScriptTarget.lower_bound(spell_id);
842 SpellScriptTarget::const_iterator GetEndSpellScriptTarget(uint32 spell_id) const
844 return mSpellScriptTarget.upper_bound(spell_id);
847 // Spell correctess for client using
848 static bool IsSpellValid(SpellEntry const * spellInfo, Player* pl = NULL, bool msg = true);
850 SkillLineAbilityMap::const_iterator GetBeginSkillLineAbilityMap(uint32 spell_id) const
852 return mSkillLineAbilityMap.lower_bound(spell_id);
855 SkillLineAbilityMap::const_iterator GetEndSkillLineAbilityMap(uint32 spell_id) const
857 return mSkillLineAbilityMap.upper_bound(spell_id);
860 PetAura const* GetPetAura(uint16 spell_id)
862 SpellPetAuraMap::const_iterator itr = mSpellPetAuraMap.find(spell_id);
863 if(itr != mSpellPetAuraMap.end())
864 return &itr->second;
865 else
866 return NULL;
869 // Modifiers
870 public:
871 static SpellMgr& Instance();
873 // Loading data at server startup
874 void LoadSpellChains();
875 void LoadSpellLearnSkills();
876 void LoadSpellLearnSpells();
877 void LoadSpellScriptTarget();
878 void LoadSpellAffects();
879 void LoadSpellElixirs();
880 void LoadSpellProcEvents();
881 void LoadSpellTargetPositions();
882 void LoadSpellThreats();
883 void LoadSkillLineAbilityMap();
884 void LoadSpellPetAuras();
886 private:
887 SpellScriptTarget mSpellScriptTarget;
888 SpellChainMap mSpellChains;
889 SpellChainMapNext mSpellChainsNext;
890 SpellLearnSkillMap mSpellLearnSkills;
891 SpellLearnSpellMap mSpellLearnSpells;
892 SpellTargetPositionMap mSpellTargetPositions;
893 SpellAffectMap mSpellAffectMap;
894 SpellElixirMap mSpellElixirs;
895 SpellProcEventMap mSpellProcEventMap;
896 SkillLineAbilityMap mSkillLineAbilityMap;
897 SpellPetAuraMap mSpellPetAuraMap;
900 #define spellmgr SpellMgr::Instance()
901 #endif