[8456] Implement area check for SPELL_ATTR_EX6_NOT_IN_RAID_INSTANCE
[getmangos.git] / src / game / SpellMgr.cpp
blob87c0849b753445e83cd123f899262c0d83864e3f
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 #include "SpellMgr.h"
20 #include "ObjectMgr.h"
21 #include "SpellAuraDefines.h"
22 #include "ProgressBar.h"
23 #include "DBCStores.h"
24 #include "World.h"
25 #include "Chat.h"
26 #include "Spell.h"
27 #include "BattleGroundMgr.h"
29 SpellMgr::SpellMgr()
33 SpellMgr::~SpellMgr()
37 SpellMgr& SpellMgr::Instance()
39 static SpellMgr spellMgr;
40 return spellMgr;
43 int32 GetSpellDuration(SpellEntry const *spellInfo)
45 if(!spellInfo)
46 return 0;
47 SpellDurationEntry const *du = sSpellDurationStore.LookupEntry(spellInfo->DurationIndex);
48 if(!du)
49 return 0;
50 return (du->Duration[0] == -1) ? -1 : abs(du->Duration[0]);
53 int32 GetSpellMaxDuration(SpellEntry const *spellInfo)
55 if(!spellInfo)
56 return 0;
57 SpellDurationEntry const *du = sSpellDurationStore.LookupEntry(spellInfo->DurationIndex);
58 if(!du)
59 return 0;
60 return (du->Duration[2] == -1) ? -1 : abs(du->Duration[2]);
63 uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell)
65 SpellCastTimesEntry const *spellCastTimeEntry = sSpellCastTimesStore.LookupEntry(spellInfo->CastingTimeIndex);
67 // not all spells have cast time index and this is all is pasiive abilities
68 if(!spellCastTimeEntry)
69 return 0;
71 int32 castTime = spellCastTimeEntry->CastTime;
73 if (spell)
75 if(Player* modOwner = spell->GetCaster()->GetSpellModOwner())
76 modOwner->ApplySpellMod(spellInfo->Id, SPELLMOD_CASTING_TIME, castTime, spell);
78 if( !(spellInfo->Attributes & (SPELL_ATTR_UNK4|SPELL_ATTR_TRADESPELL)) )
79 castTime = int32(castTime * spell->GetCaster()->GetFloatValue(UNIT_MOD_CAST_SPEED));
80 else
82 if (spell->IsRangedSpell() && !spell->IsAutoRepeat())
83 castTime = int32(castTime * spell->GetCaster()->m_modAttackSpeedPct[RANGED_ATTACK]);
87 if (spellInfo->Attributes & SPELL_ATTR_RANGED && (!spell || !(spell->IsAutoRepeat())))
88 castTime += 500;
90 return (castTime > 0) ? uint32(castTime) : 0;
93 bool IsPassiveSpell(uint32 spellId)
95 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
96 if (!spellInfo)
97 return false;
98 return (spellInfo->Attributes & SPELL_ATTR_PASSIVE) != 0;
101 bool IsNoStackAuraDueToAura(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2)
103 SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1);
104 SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
105 if(!spellInfo_1 || !spellInfo_2) return false;
106 if(spellInfo_1->Id == spellId_2) return false;
108 if (spellInfo_1->Effect[effIndex_1] != spellInfo_2->Effect[effIndex_2] ||
109 spellInfo_1->EffectItemType[effIndex_1] != spellInfo_2->EffectItemType[effIndex_2] ||
110 spellInfo_1->EffectMiscValue[effIndex_1] != spellInfo_2->EffectMiscValue[effIndex_2] ||
111 spellInfo_1->EffectApplyAuraName[effIndex_1] != spellInfo_2->EffectApplyAuraName[effIndex_2])
112 return false;
114 return true;
117 int32 CompareAuraRanks(uint32 spellId_1, uint32 effIndex_1, uint32 spellId_2, uint32 effIndex_2)
119 SpellEntry const*spellInfo_1 = sSpellStore.LookupEntry(spellId_1);
120 SpellEntry const*spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
121 if(!spellInfo_1 || !spellInfo_2) return 0;
122 if (spellId_1 == spellId_2) return 0;
124 int32 diff = spellInfo_1->EffectBasePoints[effIndex_1] - spellInfo_2->EffectBasePoints[effIndex_2];
125 if (spellInfo_1->CalculateSimpleValue(effIndex_1) < 0 && spellInfo_2->CalculateSimpleValue(effIndex_2) < 0)
126 return -diff;
127 else return diff;
130 SpellSpecific GetSpellSpecific(uint32 spellId)
132 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
133 if(!spellInfo)
134 return SPELL_NORMAL;
136 switch(spellInfo->SpellFamilyName)
138 case SPELLFAMILY_GENERIC:
140 // Food / Drinks (mostly)
141 if(spellInfo->AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED)
143 bool food = false;
144 bool drink = false;
145 for(int i = 0; i < 3; ++i)
147 switch(spellInfo->EffectApplyAuraName[i])
149 // Food
150 case SPELL_AURA_MOD_REGEN:
151 case SPELL_AURA_OBS_MOD_HEALTH:
152 food = true;
153 break;
154 // Drink
155 case SPELL_AURA_MOD_POWER_REGEN:
156 case SPELL_AURA_OBS_MOD_MANA:
157 drink = true;
158 break;
159 default:
160 break;
164 if(food && drink)
165 return SPELL_FOOD_AND_DRINK;
166 else if(food)
167 return SPELL_FOOD;
168 else if(drink)
169 return SPELL_DRINK;
171 else
173 // Well Fed buffs (must be exclusive with Food / Drink replenishment effects, or else Well Fed will cause them to be removed)
174 // SpellIcon 2560 is Spell 46687, does not have this flag
175 if ((spellInfo->AttributesEx2 & SPELL_ATTR_EX2_FOOD_BUFF) || spellInfo->SpellIconID == 2560)
176 return SPELL_WELL_FED;
178 break;
180 case SPELLFAMILY_MAGE:
182 // family flags 18(Molten), 25(Frost/Ice), 28(Mage)
183 if (spellInfo->SpellFamilyFlags & UI64LIT(0x12040000))
184 return SPELL_MAGE_ARMOR;
186 if ((spellInfo->SpellFamilyFlags & UI64LIT(0x1000000)) && spellInfo->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE)
187 return SPELL_MAGE_POLYMORPH;
189 break;
191 case SPELLFAMILY_WARRIOR:
193 if (spellInfo->SpellFamilyFlags & UI64LIT(0x00008000010000))
194 return SPELL_POSITIVE_SHOUT;
196 break;
198 case SPELLFAMILY_WARLOCK:
200 // only warlock curses have this
201 if (spellInfo->Dispel == DISPEL_CURSE)
202 return SPELL_CURSE;
204 // Warlock (Demon Armor | Demon Skin | Fel Armor)
205 if (spellInfo->SpellFamilyFlags & UI64LIT(0x2000002000000000) || spellInfo->SpellFamilyFlags2 & 0x00000010)
206 return SPELL_WARLOCK_ARMOR;
208 break;
210 case SPELLFAMILY_PRIEST:
212 // "Well Fed" buff from Blessed Sunfruit, Blessed Sunfruit Juice, Alterac Spring Water
213 if ((spellInfo->Attributes & SPELL_ATTR_CASTABLE_WHILE_SITTING) &&
214 (spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK) &&
215 (spellInfo->SpellIconID == 52 || spellInfo->SpellIconID == 79))
216 return SPELL_WELL_FED;
217 break;
219 case SPELLFAMILY_HUNTER:
221 // only hunter stings have this
222 if (spellInfo->Dispel == DISPEL_POISON)
223 return SPELL_STING;
225 // only hunter aspects have this (but not all aspects in hunter family)
226 if( spellInfo->SpellFamilyFlags & UI64LIT(0x0044000000380000) || spellInfo->SpellFamilyFlags2 & 0x00001010)
227 return SPELL_ASPECT;
229 if( spellInfo->SpellFamilyFlags2 & 0x00000002 )
230 return SPELL_TRACKER;
232 break;
234 case SPELLFAMILY_PALADIN:
236 if (IsSealSpell(spellInfo))
237 return SPELL_SEAL;
239 if (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000011010002))
240 return SPELL_BLESSING;
242 if (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000000002190))
243 return SPELL_HAND;
245 if ((spellInfo->SpellFamilyFlags & UI64LIT(0x00000820180400)) && (spellInfo->AttributesEx3 & 0x200))
246 return SPELL_JUDGEMENT;
248 // only paladin auras have this (for palaldin class family)
249 if( spellInfo->SpellFamilyFlags2 & 0x00000020 )
250 return SPELL_AURA;
252 break;
254 case SPELLFAMILY_SHAMAN:
256 if (IsElementalShield(spellInfo))
257 return SPELL_ELEMENTAL_SHIELD;
259 break;
262 case SPELLFAMILY_POTION:
263 return spellmgr.GetSpellElixirSpecific(spellInfo->Id);
265 case SPELLFAMILY_DEATHKNIGHT:
266 if (spellInfo->Category == 47)
267 return SPELL_PRESENCE;
268 break;
271 // elixirs can have different families, but potion most ofc.
272 if(SpellSpecific sp = spellmgr.GetSpellElixirSpecific(spellInfo->Id))
273 return sp;
275 return SPELL_NORMAL;
279 // target not allow have more one spell specific from same caster
280 bool IsSingleFromSpellSpecificPerTargetPerCaster(SpellSpecific spellSpec1,SpellSpecific spellSpec2)
282 switch(spellSpec1)
284 case SPELL_BLESSING:
285 case SPELL_AURA:
286 case SPELL_STING:
287 case SPELL_CURSE:
288 case SPELL_POSITIVE_SHOUT:
289 case SPELL_JUDGEMENT:
290 case SPELL_HAND:
291 return spellSpec1==spellSpec2;
292 default:
293 return false;
297 // target not allow have more one ranks from spell from spell specific per target
298 bool IsSingleFromSpellSpecificSpellRanksPerTarget(SpellSpecific spellSpec1,SpellSpecific spellSpec2)
300 switch(spellSpec1)
302 case SPELL_BLESSING:
303 case SPELL_AURA:
304 case SPELL_CURSE:
305 case SPELL_HAND:
306 return spellSpec1==spellSpec2;
307 default:
308 return false;
312 // target not allow have more one spell specific per target from any caster
313 bool IsSingleFromSpellSpecificPerTarget(SpellSpecific spellSpec1,SpellSpecific spellSpec2)
315 switch(spellSpec1)
317 case SPELL_SEAL:
318 case SPELL_ASPECT:
319 case SPELL_TRACKER:
320 case SPELL_WARLOCK_ARMOR:
321 case SPELL_MAGE_ARMOR:
322 case SPELL_ELEMENTAL_SHIELD:
323 case SPELL_MAGE_POLYMORPH:
324 case SPELL_PRESENCE:
325 case SPELL_WELL_FED:
326 return spellSpec1==spellSpec2;
327 case SPELL_BATTLE_ELIXIR:
328 return spellSpec2==SPELL_BATTLE_ELIXIR
329 || spellSpec2==SPELL_FLASK_ELIXIR;
330 case SPELL_GUARDIAN_ELIXIR:
331 return spellSpec2==SPELL_GUARDIAN_ELIXIR
332 || spellSpec2==SPELL_FLASK_ELIXIR;
333 case SPELL_FLASK_ELIXIR:
334 return spellSpec2==SPELL_BATTLE_ELIXIR
335 || spellSpec2==SPELL_GUARDIAN_ELIXIR
336 || spellSpec2==SPELL_FLASK_ELIXIR;
337 case SPELL_FOOD:
338 return spellSpec2==SPELL_FOOD
339 || spellSpec2==SPELL_FOOD_AND_DRINK;
340 case SPELL_DRINK:
341 return spellSpec2==SPELL_DRINK
342 || spellSpec2==SPELL_FOOD_AND_DRINK;
343 case SPELL_FOOD_AND_DRINK:
344 return spellSpec2==SPELL_FOOD
345 || spellSpec2==SPELL_DRINK
346 || spellSpec2==SPELL_FOOD_AND_DRINK;
347 default:
348 return false;
352 bool IsPositiveTarget(uint32 targetA, uint32 targetB)
354 // non-positive targets
355 switch(targetA)
357 case TARGET_CHAIN_DAMAGE:
358 case TARGET_ALL_ENEMY_IN_AREA:
359 case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
360 case TARGET_IN_FRONT_OF_CASTER:
361 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
362 case TARGET_CURRENT_ENEMY_COORDINATES:
363 case TARGET_SINGLE_ENEMY:
364 case TARGET_IN_FRONT_OF_CASTER_30:
365 return false;
366 case TARGET_CASTER_COORDINATES:
367 return (targetB == TARGET_ALL_PARTY || targetB == TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER);
368 default:
369 break;
371 if (targetB)
372 return IsPositiveTarget(targetB, 0);
373 return true;
376 bool IsPositiveEffect(uint32 spellId, uint32 effIndex)
378 SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId);
379 if (!spellproto) return false;
381 switch(spellproto->Effect[effIndex])
383 case SPELL_EFFECT_DUMMY:
384 // some explicitly required dummy effect sets
385 switch(spellId)
387 case 28441: return false; // AB Effect 000
388 default:
389 break;
391 break;
392 // always positive effects (check before target checks that provided non-positive result in some case for positive effects)
393 case SPELL_EFFECT_HEAL:
394 case SPELL_EFFECT_LEARN_SPELL:
395 case SPELL_EFFECT_SKILL_STEP:
396 case SPELL_EFFECT_HEAL_PCT:
397 case SPELL_EFFECT_ENERGIZE_PCT:
398 return true;
400 // non-positive aura use
401 case SPELL_EFFECT_APPLY_AURA:
402 case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND:
404 switch(spellproto->EffectApplyAuraName[effIndex])
406 case SPELL_AURA_DUMMY:
408 // dummy aura can be positive or negative dependent from casted spell
409 switch(spellproto->Id)
411 case 13139: // net-o-matic special effect
412 case 23445: // evil twin
413 case 35679: // Protectorate Demolitionist
414 case 38637: // Nether Exhaustion (red)
415 case 38638: // Nether Exhaustion (green)
416 case 38639: // Nether Exhaustion (blue)
417 case 11196: // Recently Bandaged
418 return false;
419 // some spells have unclear target modes for selection, so just make effect positive
420 case 27184:
421 case 27190:
422 case 27191:
423 case 27201:
424 case 27202:
425 case 27203:
426 return true;
427 default:
428 break;
430 } break;
431 case SPELL_AURA_MOD_DAMAGE_DONE: // dependent from bas point sign (negative -> negative)
432 case SPELL_AURA_MOD_STAT:
433 case SPELL_AURA_MOD_SKILL:
434 case SPELL_AURA_MOD_HEALING_PCT:
435 case SPELL_AURA_MOD_HEALING_DONE:
436 if(spellproto->CalculateSimpleValue(effIndex) < 0)
437 return false;
438 break;
439 case SPELL_AURA_MOD_DAMAGE_TAKEN: // dependent from bas point sign (positive -> negative)
440 if(spellproto->CalculateSimpleValue(effIndex) > 0)
441 return false;
442 break;
443 case SPELL_AURA_MOD_SPELL_CRIT_CHANCE:
444 if(spellproto->CalculateSimpleValue(effIndex) > 0)
445 return true; // some expected positive spells have SPELL_ATTR_EX_NEGATIVE
446 break;
447 case SPELL_AURA_ADD_TARGET_TRIGGER:
448 return true;
449 case SPELL_AURA_PERIODIC_TRIGGER_SPELL:
450 if(spellId != spellproto->EffectTriggerSpell[effIndex])
452 uint32 spellTriggeredId = spellproto->EffectTriggerSpell[effIndex];
453 SpellEntry const *spellTriggeredProto = sSpellStore.LookupEntry(spellTriggeredId);
455 if(spellTriggeredProto)
457 // non-positive targets of main spell return early
458 for(int i = 0; i < 3; ++i)
460 // if non-positive trigger cast targeted to positive target this main cast is non-positive
461 // this will place this spell auras as debuffs
462 if(IsPositiveTarget(spellTriggeredProto->EffectImplicitTargetA[effIndex],spellTriggeredProto->EffectImplicitTargetB[effIndex]) && !IsPositiveEffect(spellTriggeredId,i))
463 return false;
467 break;
468 case SPELL_AURA_PROC_TRIGGER_SPELL:
469 // many positive auras have negative triggered spells at damage for example and this not make it negative (it can be canceled for example)
470 break;
471 case SPELL_AURA_MOD_STUN: //have positive and negative spells, we can't sort its correctly at this moment.
472 if(effIndex==0 && spellproto->Effect[1]==0 && spellproto->Effect[2]==0)
473 return false; // but all single stun aura spells is negative
475 // Petrification
476 if(spellproto->Id == 17624)
477 return false;
478 break;
479 case SPELL_AURA_MOD_PACIFY_SILENCE:
480 if(spellproto->Id == 24740) // Wisp Costume
481 return true;
482 return false;
483 case SPELL_AURA_MOD_ROOT:
484 case SPELL_AURA_MOD_SILENCE:
485 case SPELL_AURA_GHOST:
486 case SPELL_AURA_PERIODIC_LEECH:
487 case SPELL_AURA_MOD_STALKED:
488 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
489 return false;
490 case SPELL_AURA_PERIODIC_DAMAGE: // used in positive spells also.
491 // part of negative spell if casted at self (prevent cancel)
492 if(spellproto->EffectImplicitTargetA[effIndex] == TARGET_SELF)
493 return false;
494 break;
495 case SPELL_AURA_MOD_DECREASE_SPEED: // used in positive spells also
496 // part of positive spell if casted at self
497 if(spellproto->EffectImplicitTargetA[effIndex] != TARGET_SELF)
498 return false;
499 // but not this if this first effect (don't found batter check)
500 if(spellproto->Attributes & 0x4000000 && effIndex==0)
501 return false;
502 break;
503 case SPELL_AURA_TRANSFORM:
504 // some spells negative
505 switch(spellproto->Id)
507 case 36897: // Transporter Malfunction (race mutation to horde)
508 case 36899: // Transporter Malfunction (race mutation to alliance)
509 return false;
511 break;
512 case SPELL_AURA_MOD_SCALE:
513 // some spells negative
514 switch(spellproto->Id)
516 case 36900: // Soul Split: Evil!
517 case 36901: // Soul Split: Good
518 case 36893: // Transporter Malfunction (decrease size case)
519 case 36895: // Transporter Malfunction (increase size case)
520 return false;
522 break;
523 case SPELL_AURA_MECHANIC_IMMUNITY:
525 // non-positive immunities
526 switch(spellproto->EffectMiscValue[effIndex])
528 case MECHANIC_BANDAGE:
529 case MECHANIC_SHIELD:
530 case MECHANIC_MOUNT:
531 case MECHANIC_INVULNERABILITY:
532 return false;
533 default:
534 break;
536 } break;
537 case SPELL_AURA_ADD_FLAT_MODIFIER: // mods
538 case SPELL_AURA_ADD_PCT_MODIFIER:
540 // non-positive mods
541 switch(spellproto->EffectMiscValue[effIndex])
543 case SPELLMOD_COST: // dependent from bas point sign (negative -> positive)
544 if(spellproto->CalculateSimpleValue(effIndex) > 0)
545 return false;
546 break;
547 default:
548 break;
550 } break;
551 case SPELL_AURA_FORCE_REACTION:
552 if(spellproto->Id==42792) // Recently Dropped Flag (prevent cancel)
553 return false;
554 break;
555 default:
556 break;
558 break;
560 default:
561 break;
564 // non-positive targets
565 if(!IsPositiveTarget(spellproto->EffectImplicitTargetA[effIndex],spellproto->EffectImplicitTargetB[effIndex]))
566 return false;
568 // AttributesEx check
569 if(spellproto->AttributesEx & SPELL_ATTR_EX_NEGATIVE)
570 return false;
572 // ok, positive
573 return true;
576 bool IsPositiveSpell(uint32 spellId)
578 SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId);
579 if (!spellproto) return false;
581 // spells with atleast one negative effect are considered negative
582 // some self-applied spells have negative effects but in self casting case negative check ignored.
583 for (int i = 0; i < 3; ++i)
584 if (!IsPositiveEffect(spellId, i))
585 return false;
586 return true;
589 bool IsSingleTargetSpell(SpellEntry const *spellInfo)
591 // all other single target spells have if it has AttributesEx5
592 if ( spellInfo->AttributesEx5 & SPELL_ATTR_EX5_SINGLE_TARGET_SPELL )
593 return true;
595 // TODO - need found Judgements rule
596 switch(GetSpellSpecific(spellInfo->Id))
598 case SPELL_JUDGEMENT:
599 return true;
600 default:
601 break;
604 // single target triggered spell.
605 // Not real client side single target spell, but it' not triggered until prev. aura expired.
606 // This is allow store it in single target spells list for caster for spell proc checking
607 if(spellInfo->Id==38324) // Regeneration (triggered by 38299 (HoTs on Heals))
608 return true;
610 return false;
613 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2)
615 // TODO - need better check
616 // Equal icon and spellfamily
617 if( spellInfo1->SpellFamilyName == spellInfo2->SpellFamilyName &&
618 spellInfo1->SpellIconID == spellInfo2->SpellIconID )
619 return true;
621 // TODO - need found Judgements rule
622 SpellSpecific spec1 = GetSpellSpecific(spellInfo1->Id);
623 // spell with single target specific types
624 switch(spec1)
626 case SPELL_JUDGEMENT:
627 case SPELL_MAGE_POLYMORPH:
628 if(GetSpellSpecific(spellInfo2->Id) == spec1)
629 return true;
630 break;
631 default:
632 break;
635 return false;
638 SpellCastResult GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form)
640 // talents that learn spells can have stance requirements that need ignore
641 // (this requirement only for client-side stance show in talent description)
642 if( GetTalentSpellCost(spellInfo->Id) > 0 &&
643 (spellInfo->Effect[0]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[1]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[2]==SPELL_EFFECT_LEARN_SPELL) )
644 return SPELL_CAST_OK;
646 uint32 stanceMask = (form ? 1 << (form - 1) : 0);
648 if (stanceMask & spellInfo->StancesNot) // can explicitly not be casted in this stance
649 return SPELL_FAILED_NOT_SHAPESHIFT;
651 if (stanceMask & spellInfo->Stances) // can explicitly be casted in this stance
652 return SPELL_CAST_OK;
654 bool actAsShifted = false;
655 if (form > 0)
657 SpellShapeshiftEntry const *shapeInfo = sSpellShapeshiftStore.LookupEntry(form);
658 if (!shapeInfo)
660 sLog.outError("GetErrorAtShapeshiftedCast: unknown shapeshift %u", form);
661 return SPELL_CAST_OK;
663 actAsShifted = !(shapeInfo->flags1 & 1); // shapeshift acts as normal form for spells
666 if(actAsShifted)
668 if (spellInfo->Attributes & SPELL_ATTR_NOT_SHAPESHIFT) // not while shapeshifted
669 return SPELL_FAILED_NOT_SHAPESHIFT;
670 else if (spellInfo->Stances != 0) // needs other shapeshift
671 return SPELL_FAILED_ONLY_SHAPESHIFT;
673 else
675 // needs shapeshift
676 if(!(spellInfo->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) && spellInfo->Stances != 0)
677 return SPELL_FAILED_ONLY_SHAPESHIFT;
680 return SPELL_CAST_OK;
683 void SpellMgr::LoadSpellTargetPositions()
685 mSpellTargetPositions.clear(); // need for reload case
687 uint32 count = 0;
689 // 0 1 2 3 4 5
690 QueryResult *result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position");
691 if( !result )
694 barGoLink bar( 1 );
696 bar.step();
698 sLog.outString();
699 sLog.outString( ">> Loaded %u spell target coordinates", count );
700 return;
703 barGoLink bar( result->GetRowCount() );
707 Field *fields = result->Fetch();
709 bar.step();
711 uint32 Spell_ID = fields[0].GetUInt32();
713 SpellTargetPosition st;
715 st.target_mapId = fields[1].GetUInt32();
716 st.target_X = fields[2].GetFloat();
717 st.target_Y = fields[3].GetFloat();
718 st.target_Z = fields[4].GetFloat();
719 st.target_Orientation = fields[5].GetFloat();
721 SpellEntry const* spellInfo = sSpellStore.LookupEntry(Spell_ID);
722 if(!spellInfo)
724 sLog.outErrorDb("Spell (ID:%u) listed in `spell_target_position` does not exist.",Spell_ID);
725 continue;
728 bool found = false;
729 for(int i = 0; i < 3; ++i)
731 if( spellInfo->EffectImplicitTargetA[i]==TARGET_TABLE_X_Y_Z_COORDINATES || spellInfo->EffectImplicitTargetB[i]==TARGET_TABLE_X_Y_Z_COORDINATES )
733 found = true;
734 break;
737 if(!found)
739 sLog.outErrorDb("Spell (Id: %u) listed in `spell_target_position` does not have target TARGET_TABLE_X_Y_Z_COORDINATES (17).",Spell_ID);
740 continue;
743 MapEntry const* mapEntry = sMapStore.LookupEntry(st.target_mapId);
744 if(!mapEntry)
746 sLog.outErrorDb("Spell (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Spell_ID,st.target_mapId);
747 continue;
750 if(st.target_X==0 && st.target_Y==0 && st.target_Z==0)
752 sLog.outErrorDb("Spell (ID:%u) target coordinates not provided.",Spell_ID);
753 continue;
756 mSpellTargetPositions[Spell_ID] = st;
757 ++count;
759 } while( result->NextRow() );
761 delete result;
763 sLog.outString();
764 sLog.outString( ">> Loaded %u spell teleport coordinates", count );
767 bool SpellMgr::IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const
769 // false for spellInfo == NULL
770 if (!spellInfo || !mod)
771 return false;
773 SpellEntry const *affect_spell = sSpellStore.LookupEntry(mod->spellId);
774 // False if affect_spell == NULL or spellFamily not equal
775 if (!affect_spell || affect_spell->SpellFamilyName != spellInfo->SpellFamilyName)
776 return false;
778 // true
779 if (mod->mask & spellInfo->SpellFamilyFlags ||
780 mod->mask2 & spellInfo->SpellFamilyFlags2)
781 return true;
783 return false;
786 struct DoSpellProcEvent
788 DoSpellProcEvent(SpellProcEventEntry const& _spe) : spe(_spe) {}
789 void operator() (uint32 spell_id) { spellmgr.mSpellProcEventMap[spell_id] = spe; }
790 SpellProcEventEntry const& spe;
793 void SpellMgr::LoadSpellProcEvents()
795 mSpellProcEventMap.clear(); // need for reload case
797 uint32 count = 0;
799 // 0 1 2 3 4 5 6 7 8 9 10
800 QueryResult *result = WorldDatabase.Query("SELECT entry, SchoolMask, SpellFamilyName, SpellFamilyMask0, SpellFamilyMask1, SpellFamilyMask2, procFlags, procEx, ppmRate, CustomChance, Cooldown FROM spell_proc_event");
801 if( !result )
803 barGoLink bar( 1 );
804 bar.step();
805 sLog.outString();
806 sLog.outString( ">> Loaded %u spell proc event conditions", count );
807 return;
810 barGoLink bar( result->GetRowCount() );
811 uint32 customProc = 0;
814 Field *fields = result->Fetch();
816 bar.step();
818 uint32 entry = fields[0].GetUInt32();
820 const SpellEntry *spell = sSpellStore.LookupEntry(entry);
821 if (!spell)
823 sLog.outErrorDb("Spell %u listed in `spell_proc_event` does not exist", entry);
824 continue;
827 uint32 first_id = GetFirstSpellInChain(entry);
829 if ( first_id != entry )
831 sLog.outErrorDb("Spell %u listed in `spell_proc_event` is not first rank (%u) in chain", entry, first_id);
832 // prevent loading since it won't have an effect anyway
833 continue;
836 SpellProcEventEntry spe;
838 spe.schoolMask = fields[1].GetUInt32();
839 spe.spellFamilyName = fields[2].GetUInt32();
840 spe.spellFamilyMask = (uint64)fields[3].GetUInt32()|((uint64)fields[4].GetUInt32()<<32);
841 spe.spellFamilyMask2= fields[5].GetUInt32();
842 spe.procFlags = fields[6].GetUInt32();
843 spe.procEx = fields[7].GetUInt32();
844 spe.ppmRate = fields[8].GetFloat();
845 spe.customChance = fields[9].GetFloat();
846 spe.cooldown = fields[10].GetUInt32();
848 mSpellProcEventMap[entry] = spe;
850 // also add to high ranks
851 DoSpellProcEvent worker(spe);
852 doForHighRanks(entry,worker);
854 if (spell->procFlags==0)
856 if (spe.procFlags == 0)
858 sLog.outErrorDb("Spell %u listed in `spell_proc_event` probally not triggered spell", entry);
859 continue;
861 customProc++;
863 ++count;
864 } while( result->NextRow() );
866 delete result;
868 sLog.outString();
869 if (customProc)
870 sLog.outString( ">> Loaded %u extra spell proc event conditions +%u custom", count, customProc );
871 else
872 sLog.outString( ">> Loaded %u extra spell proc event conditions", count );
875 struct DoSpellProcItemEnchant
877 DoSpellProcItemEnchant(float _ppm) : ppm(_ppm) {}
878 void operator() (uint32 spell_id) { spellmgr.mSpellProcItemEnchantMap[spell_id] = ppm; }
879 float ppm;
882 void SpellMgr::LoadSpellProcItemEnchant()
884 mSpellProcItemEnchantMap.clear(); // need for reload case
886 uint32 count = 0;
888 // 0 1
889 QueryResult *result = WorldDatabase.Query("SELECT entry, ppmRate FROM spell_proc_item_enchant");
890 if( !result )
893 barGoLink bar( 1 );
895 bar.step();
897 sLog.outString();
898 sLog.outString( ">> Loaded %u proc item enchant definitions", count );
899 return;
902 barGoLink bar( result->GetRowCount() );
906 Field *fields = result->Fetch();
908 bar.step();
910 uint32 entry = fields[0].GetUInt32();
911 float ppmRate = fields[1].GetFloat();
913 SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry);
915 if (!spellInfo)
917 sLog.outErrorDb("Spell %u listed in `spell_proc_item_enchant` does not exist", entry);
918 continue;
921 uint32 first_id = GetFirstSpellInChain(entry);
923 if ( first_id != entry )
925 sLog.outErrorDb("Spell %u listed in `spell_proc_item_enchant` is not first rank (%u) in chain", entry, first_id);
926 // prevent loading since it won't have an effect anyway
927 continue;
930 mSpellProcItemEnchantMap[entry] = ppmRate;
932 // also add to high ranks
933 DoSpellProcItemEnchant worker(ppmRate);
934 doForHighRanks(entry,worker);
936 ++count;
937 } while( result->NextRow() );
939 delete result;
941 sLog.outString();
942 sLog.outString( ">> Loaded %u proc item enchant definitions", count );
945 struct DoSpellBonusess
947 DoSpellBonusess(SpellBonusEntry const& _spellBonus) : spellBonus(_spellBonus) {}
948 void operator() (uint32 spell_id) { spellmgr.mSpellBonusMap[spell_id] = spellBonus; }
949 SpellBonusEntry const& spellBonus;
952 void SpellMgr::LoadSpellBonusess()
954 mSpellBonusMap.clear(); // need for reload case
955 uint32 count = 0;
956 // 0 1 2 3
957 QueryResult *result = WorldDatabase.Query("SELECT entry, direct_bonus, dot_bonus, ap_bonus FROM spell_bonus_data");
958 if( !result )
960 barGoLink bar( 1 );
961 bar.step();
962 sLog.outString();
963 sLog.outString( ">> Loaded %u spell bonus data", count);
964 return;
967 barGoLink bar( result->GetRowCount() );
970 Field *fields = result->Fetch();
971 bar.step();
972 uint32 entry = fields[0].GetUInt32();
974 SpellEntry const* spell = sSpellStore.LookupEntry(entry);
975 if (!spell)
977 sLog.outErrorDb("Spell %u listed in `spell_bonus_data` does not exist", entry);
978 continue;
981 uint32 first_id = GetFirstSpellInChain(entry);
983 if ( first_id != entry )
985 sLog.outErrorDb("Spell %u listed in `spell_bonus_data` is not first rank (%u) in chain", entry, first_id);
986 // prevent loading since it won't have an effect anyway
987 continue;
990 SpellBonusEntry sbe;
992 sbe.direct_damage = fields[1].GetFloat();
993 sbe.dot_damage = fields[2].GetFloat();
994 sbe.ap_bonus = fields[3].GetFloat();
996 mSpellBonusMap[entry] = sbe;
998 // also add to high ranks
999 DoSpellBonusess worker(sbe);
1000 doForHighRanks(entry,worker);
1002 ++count;
1004 } while( result->NextRow() );
1006 delete result;
1008 sLog.outString();
1009 sLog.outString( ">> Loaded %u extra spell bonus data", count);
1012 bool SpellMgr::IsSpellProcEventCanTriggeredBy(SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active)
1014 // No extra req need
1015 uint32 procEvent_procEx = PROC_EX_NONE;
1017 // check prockFlags for condition
1018 if((procFlags & EventProcFlag) == 0)
1019 return false;
1021 // Always trigger for this
1022 if (EventProcFlag & (PROC_FLAG_KILLED | PROC_FLAG_KILL | PROC_FLAG_ON_TRAP_ACTIVATION))
1023 return true;
1025 if (spellProcEvent) // Exist event data
1027 // Store extra req
1028 procEvent_procEx = spellProcEvent->procEx;
1030 // For melee triggers
1031 if (procSpell == NULL)
1033 // Check (if set) for school (melee attack have Normal school)
1034 if(spellProcEvent->schoolMask && (spellProcEvent->schoolMask & SPELL_SCHOOL_MASK_NORMAL) == 0)
1035 return false;
1037 else // For spells need check school/spell family/family mask
1039 // Check (if set) for school
1040 if(spellProcEvent->schoolMask && (spellProcEvent->schoolMask & procSpell->SchoolMask) == 0)
1041 return false;
1043 // Check (if set) for spellFamilyName
1044 if(spellProcEvent->spellFamilyName && (spellProcEvent->spellFamilyName != procSpell->SpellFamilyName))
1045 return false;
1047 // spellFamilyName is Ok need check for spellFamilyMask if present
1048 if(spellProcEvent->spellFamilyMask || spellProcEvent->spellFamilyMask2)
1050 if ((spellProcEvent->spellFamilyMask & procSpell->SpellFamilyFlags ) == 0 &&
1051 (spellProcEvent->spellFamilyMask2 & procSpell->SpellFamilyFlags2) == 0)
1052 return false;
1053 active = true; // Spell added manualy -> so its active spell
1057 // Check for extra req (if none) and hit/crit
1058 if (procEvent_procEx == PROC_EX_NONE)
1060 // No extra req, so can trigger only for active (damage/healing present) and hit/crit
1061 if((procExtra & (PROC_EX_NORMAL_HIT|PROC_EX_CRITICAL_HIT)) && active)
1062 return true;
1064 else // Passive spells hits here only if resist/reflect/immune/evade
1066 // Exist req for PROC_EX_EX_TRIGGER_ALWAYS
1067 if (procEvent_procEx & PROC_EX_EX_TRIGGER_ALWAYS)
1068 return true;
1069 // Passive spells can`t trigger if need hit
1070 if ((procEvent_procEx & PROC_EX_NORMAL_HIT) && !active)
1071 return false;
1072 // Check Extra Requirement like (hit/crit/miss/resist/parry/dodge/block/immune/reflect/absorb and other)
1073 if (procEvent_procEx & procExtra)
1074 return true;
1076 return false;
1079 void SpellMgr::LoadSpellElixirs()
1081 mSpellElixirs.clear(); // need for reload case
1083 uint32 count = 0;
1085 // 0 1
1086 QueryResult *result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir");
1087 if( !result )
1090 barGoLink bar( 1 );
1092 bar.step();
1094 sLog.outString();
1095 sLog.outString( ">> Loaded %u spell elixir definitions", count );
1096 return;
1099 barGoLink bar( result->GetRowCount() );
1103 Field *fields = result->Fetch();
1105 bar.step();
1107 uint32 entry = fields[0].GetUInt32();
1108 uint8 mask = fields[1].GetUInt8();
1110 SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry);
1112 if (!spellInfo)
1114 sLog.outErrorDb("Spell %u listed in `spell_elixir` does not exist", entry);
1115 continue;
1118 mSpellElixirs[entry] = mask;
1120 ++count;
1121 } while( result->NextRow() );
1123 delete result;
1125 sLog.outString();
1126 sLog.outString( ">> Loaded %u spell elixir definitions", count );
1129 void SpellMgr::LoadSpellThreats()
1131 mSpellThreatMap.clear(); // need for reload case
1133 uint32 count = 0;
1135 // 0 1
1136 QueryResult *result = WorldDatabase.Query("SELECT entry, Threat FROM spell_threat");
1137 if( !result )
1140 barGoLink bar( 1 );
1142 bar.step();
1144 sLog.outString();
1145 sLog.outString( ">> Loaded %u aggro generating spells", count );
1146 return;
1149 barGoLink bar( result->GetRowCount() );
1153 Field *fields = result->Fetch();
1155 bar.step();
1157 uint32 entry = fields[0].GetUInt32();
1158 uint16 Threat = fields[1].GetUInt16();
1160 if (!sSpellStore.LookupEntry(entry))
1162 sLog.outErrorDb("Spell %u listed in `spell_threat` does not exist", entry);
1163 continue;
1166 mSpellThreatMap[entry] = Threat;
1168 ++count;
1169 } while( result->NextRow() );
1171 delete result;
1173 sLog.outString();
1174 sLog.outString( ">> Loaded %u aggro generating spells", count );
1177 bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const
1179 SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
1180 if(!spellInfo_1 || !spellInfo_2) return false;
1181 if(spellInfo_1->Id == spellId_2) return false;
1183 return GetFirstSpellInChain(spellInfo_1->Id)==GetFirstSpellInChain(spellId_2);
1186 bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo)
1188 if(IsPassiveSpell(spellInfo->Id)) // ranked passive spell
1189 return false;
1190 if(spellInfo->powerType != POWER_MANA && spellInfo->powerType != POWER_HEALTH)
1191 return false;
1192 if(IsProfessionOrRidingSpell(spellInfo->Id))
1193 return false;
1195 if(spellmgr.IsSkillBonusSpell(spellInfo->Id))
1196 return false;
1198 // All stance spells. if any better way, change it.
1199 for (int i = 0; i < 3; ++i)
1201 switch(spellInfo->SpellFamilyName)
1203 case SPELLFAMILY_PALADIN:
1204 // Paladin aura Spell
1205 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AREA_AURA_RAID)
1206 return false;
1207 break;
1208 case SPELLFAMILY_DRUID:
1209 // Druid form Spell
1210 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA &&
1211 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT)
1212 return false;
1213 break;
1214 case SPELLFAMILY_ROGUE:
1215 // Rogue Stealth
1216 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA &&
1217 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT)
1218 return false;
1221 return true;
1224 bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const
1226 SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1);
1227 SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
1229 if(!spellInfo_1 || !spellInfo_2)
1230 return false;
1232 if(spellId_1 == spellId_2)
1233 return false;
1235 //I think we don't check this correctly because i need a exception for spell:
1236 //72,11327,18461...(called from 1856,1857...) Call Aura 16,31, after trigger another spell who call aura 77 and 77 remove 16 and 31, this should not happen.
1237 if(spellInfo_2->SpellFamilyFlags == 2048)
1238 return false;
1240 // Resurrection sickness
1241 if((spellInfo_1->Id == SPELL_ID_PASSIVE_RESURRECTION_SICKNESS) != (spellInfo_2->Id==SPELL_ID_PASSIVE_RESURRECTION_SICKNESS))
1242 return false;
1244 // Allow stack passive and not passive spells
1245 if ((spellInfo_1->Attributes & SPELL_ATTR_PASSIVE)!=(spellInfo_2->Attributes & SPELL_ATTR_PASSIVE))
1246 return false;
1248 // Specific spell family spells
1249 switch(spellInfo_1->SpellFamilyName)
1251 case SPELLFAMILY_GENERIC:
1252 switch(spellInfo_2->SpellFamilyName)
1254 case SPELLFAMILY_GENERIC: // same family case
1256 // Thunderfury
1257 if ((spellInfo_1->Id == 21992 && spellInfo_2->Id == 27648) ||
1258 (spellInfo_2->Id == 21992 && spellInfo_1->Id == 27648))
1259 return false;
1261 // Lightning Speed (Mongoose) and Fury of the Crashing Waves (Tsunami Talisman)
1262 if ((spellInfo_1->Id == 28093 && spellInfo_2->Id == 42084) ||
1263 (spellInfo_2->Id == 28093 && spellInfo_1->Id == 42084))
1264 return false;
1266 // Soulstone Resurrection and Twisting Nether (resurrector)
1267 if( spellInfo_1->SpellIconID == 92 && spellInfo_2->SpellIconID == 92 && (
1268 spellInfo_1->SpellVisual[0] == 99 && spellInfo_2->SpellVisual[0] == 0 ||
1269 spellInfo_2->SpellVisual[0] == 99 && spellInfo_1->SpellVisual[0] == 0 ) )
1270 return false;
1272 // Heart of the Wild and (Primal Instinct (Idol of Terror) triggering spell or Agility)
1273 if( spellInfo_1->SpellIconID == 240 && spellInfo_2->SpellIconID == 240 && (
1274 spellInfo_1->SpellVisual[0] == 0 && spellInfo_2->SpellVisual[0] == 78 ||
1275 spellInfo_2->SpellVisual[0] == 0 && spellInfo_1->SpellVisual[0] == 78 ) )
1276 return false;
1278 // Personalized Weather (thunder effect should overwrite rainy aura)
1279 if(spellInfo_1->SpellIconID == 2606 && spellInfo_2->SpellIconID == 2606)
1280 return false;
1282 // Brood Affliction: Bronze
1283 if( (spellInfo_1->Id == 23170 && spellInfo_2->Id == 23171) ||
1284 (spellInfo_2->Id == 23170 && spellInfo_1->Id == 23171) )
1285 return false;
1287 // See Chapel Invisibility and See Noth Invisibility
1288 if( (spellInfo_1->Id == 52950 && spellInfo_2->Id == 52707) ||
1289 (spellInfo_2->Id == 52950 && spellInfo_1->Id == 52707) )
1290 return false;
1292 // Regular and Night Elf Ghost
1293 if( (spellInfo_1->Id == 8326 && spellInfo_2->Id == 20584) ||
1294 (spellInfo_2->Id == 8326 && spellInfo_1->Id == 20584) )
1295 return false;
1297 break;
1299 case SPELLFAMILY_MAGE:
1300 // Arcane Intellect and Insight
1301 if( spellInfo_2->SpellIconID == 125 && spellInfo_1->Id == 18820 )
1302 return false;
1303 break;
1304 case SPELLFAMILY_WARRIOR:
1306 // Scroll of Protection and Defensive Stance (multi-family check)
1307 if( spellInfo_1->SpellIconID == 276 && spellInfo_1->SpellVisual[0] == 196 && spellInfo_2->Id == 71)
1308 return false;
1310 // Improved Hamstring -> Hamstring (multi-family check)
1311 if( (spellInfo_2->SpellFamilyFlags & UI64LIT(0x2)) && spellInfo_1->Id == 23694 )
1312 return false;
1314 break;
1316 case SPELLFAMILY_DRUID:
1318 // Scroll of Stamina and Leader of the Pack (multi-family check)
1319 if( spellInfo_1->SpellIconID == 312 && spellInfo_1->SpellVisual[0] == 216 && spellInfo_2->Id == 24932 )
1320 return false;
1322 // Dragonmaw Illusion (multi-family check)
1323 if (spellId_1 == 40216 && spellId_2 == 42016 )
1324 return false;
1326 break;
1328 case SPELLFAMILY_ROGUE:
1330 // Garrote-Silence -> Garrote (multi-family check)
1331 if( spellInfo_1->SpellIconID == 498 && spellInfo_1->SpellVisual[0] == 0 && spellInfo_2->SpellIconID == 498 )
1332 return false;
1334 break;
1336 case SPELLFAMILY_HUNTER:
1338 // Concussive Shot and Imp. Concussive Shot (multi-family check)
1339 if( spellInfo_1->Id == 19410 && spellInfo_2->Id == 5116 )
1340 return false;
1342 // Improved Wing Clip -> Wing Clip (multi-family check)
1343 if( (spellInfo_2->SpellFamilyFlags & UI64LIT(0x40)) && spellInfo_1->Id == 19229 )
1344 return false;
1345 break;
1347 case SPELLFAMILY_PALADIN:
1349 // Unstable Currents and other -> *Sanctity Aura (multi-family check)
1350 if( spellInfo_2->SpellIconID==502 && spellInfo_1->SpellIconID==502 && spellInfo_1->SpellVisual[0]==969 )
1351 return false;
1353 // *Band of Eternal Champion and Seal of Command(multi-family check)
1354 if( spellId_1 == 35081 && spellInfo_2->SpellIconID==561 && spellInfo_2->SpellVisual[0]==7992)
1355 return false;
1357 break;
1360 // Dragonmaw Illusion, Blood Elf Illusion, Human Illusion, Illidari Agent Illusion, Scarlet Crusade Disguise
1361 if(spellInfo_1->SpellIconID == 1691 && spellInfo_2->SpellIconID == 1691)
1362 return false;
1363 break;
1364 case SPELLFAMILY_MAGE:
1365 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_MAGE )
1367 // Blizzard & Chilled (and some other stacked with blizzard spells
1368 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x80)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x100000)) ||
1369 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x80)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x100000)) )
1370 return false;
1372 // Blink & Improved Blink
1373 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x0000000000010000)) && (spellInfo_2->SpellVisual[0] == 72 && spellInfo_2->SpellIconID == 1499) ||
1374 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x0000000000010000)) && (spellInfo_1->SpellVisual[0] == 72 && spellInfo_1->SpellIconID == 1499) )
1375 return false;
1377 // Detect Invisibility and Mana Shield (multi-family check)
1378 if( spellInfo_2->Id == 132 && spellInfo_1->SpellIconID == 209 && spellInfo_1->SpellVisual[0] == 968 )
1379 return false;
1381 // Combustion and Fire Protection Aura (multi-family check)
1382 if( spellInfo_1->Id == 11129 && spellInfo_2->SpellIconID == 33 && spellInfo_2->SpellVisual[0] == 321 )
1383 return false;
1385 // Arcane Intellect and Insight
1386 if( spellInfo_1->SpellIconID == 125 && spellInfo_2->Id == 18820 )
1387 return false;
1389 break;
1390 case SPELLFAMILY_WARLOCK:
1391 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_WARLOCK )
1393 // Siphon Life and Drain Life
1394 if( spellInfo_1->SpellIconID == 152 && spellInfo_2->SpellIconID == 546 ||
1395 spellInfo_2->SpellIconID == 152 && spellInfo_1->SpellIconID == 546 )
1396 return false;
1398 //Corruption & Seed of corruption
1399 if( spellInfo_1->SpellIconID == 313 && spellInfo_2->SpellIconID == 1932 ||
1400 spellInfo_2->SpellIconID == 313 && spellInfo_1->SpellIconID == 1932 )
1401 if(spellInfo_1->SpellVisual[0] != 0 && spellInfo_2->SpellVisual[0] != 0)
1402 return true; // can't be stacked
1404 // Corruption and Unstable Affliction
1405 if( spellInfo_1->SpellIconID == 313 && spellInfo_2->SpellIconID == 2039 ||
1406 spellInfo_2->SpellIconID == 313 && spellInfo_1->SpellIconID == 2039 )
1407 return false;
1409 // (Corruption or Unstable Affliction) and (Curse of Agony or Curse of Doom)
1410 if( (spellInfo_1->SpellIconID == 313 || spellInfo_1->SpellIconID == 2039) && (spellInfo_2->SpellIconID == 544 || spellInfo_2->SpellIconID == 91) ||
1411 (spellInfo_2->SpellIconID == 313 || spellInfo_2->SpellIconID == 2039) && (spellInfo_1->SpellIconID == 544 || spellInfo_1->SpellIconID == 91) )
1412 return false;
1414 // Metamorphosis, diff effects
1415 if (spellInfo_1->SpellIconID == 3314 && spellInfo_2->SpellIconID == 3314)
1416 return false;
1418 // Detect Invisibility and Mana Shield (multi-family check)
1419 if( spellInfo_1->Id == 132 && spellInfo_2->SpellIconID == 209 && spellInfo_2->SpellVisual[0] == 968 )
1420 return false;
1421 break;
1422 case SPELLFAMILY_WARRIOR:
1423 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_WARRIOR )
1425 // Rend and Deep Wound
1426 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x20)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x1000000000)) ||
1427 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x20)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x1000000000)) )
1428 return false;
1430 // Battle Shout and Rampage
1431 if( (spellInfo_1->SpellIconID == 456 && spellInfo_2->SpellIconID == 2006) ||
1432 (spellInfo_2->SpellIconID == 456 && spellInfo_1->SpellIconID == 2006) )
1433 return false;
1436 // Hamstring -> Improved Hamstring (multi-family check)
1437 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x2)) && spellInfo_2->Id == 23694 )
1438 return false;
1440 // Defensive Stance and Scroll of Protection (multi-family check)
1441 if( spellInfo_1->Id == 71 && spellInfo_2->SpellIconID == 276 && spellInfo_2->SpellVisual[0] == 196 )
1442 return false;
1444 // Bloodlust and Bloodthirst (multi-family check)
1445 if( spellInfo_2->Id == 2825 && spellInfo_1->SpellIconID == 38 && spellInfo_1->SpellVisual[0] == 0 )
1446 return false;
1448 break;
1449 case SPELLFAMILY_PRIEST:
1450 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_PRIEST )
1452 //Devouring Plague and Shadow Vulnerability
1453 if ((spellInfo_1->SpellFamilyFlags & UI64LIT(0x2000000)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x800000000)) ||
1454 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x2000000)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x800000000)))
1455 return false;
1457 //StarShards and Shadow Word: Pain
1458 if ((spellInfo_1->SpellFamilyFlags & UI64LIT(0x200000)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x8000)) ||
1459 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x200000)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x8000)))
1460 return false;
1461 // Dispersion
1462 if ((spellInfo_1->Id == 47585 && spellInfo_2->Id == 60069) ||
1463 (spellInfo_2->Id == 47585 && spellInfo_1->Id == 60069))
1464 return false;
1466 break;
1467 case SPELLFAMILY_DRUID:
1468 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_DRUID )
1470 //Omen of Clarity and Blood Frenzy
1471 if( (spellInfo_1->SpellFamilyFlags == UI64LIT(0x0) && spellInfo_1->SpellIconID == 108) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x20000000000000)) ||
1472 (spellInfo_2->SpellFamilyFlags == UI64LIT(0x0) && spellInfo_2->SpellIconID == 108) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x20000000000000)) )
1473 return false;
1475 // Tree of Life (Shapeshift) and 34123 Tree of Life (Passive)
1476 if ((spellId_1 == 33891 && spellId_2 == 34123) ||
1477 (spellId_2 == 33891 && spellId_1 == 34123))
1478 return false;
1480 // Wrath of Elune and Nature's Grace
1481 if( spellInfo_1->Id == 16886 && spellInfo_2->Id == 46833 || spellInfo_2->Id == 16886 && spellInfo_1->Id == 46833 )
1482 return false;
1484 // Bear Rage (Feral T4 (2)) and Omen of Clarity
1485 if( spellInfo_1->Id == 16864 && spellInfo_2->Id == 37306 || spellInfo_2->Id == 16864 && spellInfo_1->Id == 37306 )
1486 return false;
1488 // Cat Energy (Feral T4 (2)) and Omen of Clarity
1489 if( spellInfo_1->Id == 16864 && spellInfo_2->Id == 37311 || spellInfo_2->Id == 16864 && spellInfo_1->Id == 37311 )
1490 return false;
1492 // Survival Instincts and Survival Instincts
1493 if( spellInfo_1->Id == 61336 && spellInfo_2->Id == 50322 || spellInfo_2->Id == 61336 && spellInfo_1->Id == 50322 )
1494 return false;
1496 // Savage Roar and Savage Roar (triggered)
1497 if (spellInfo_1->SpellIconID == 2865 && spellInfo_2->SpellIconID == 2865)
1498 return false;
1501 // Leader of the Pack and Scroll of Stamina (multi-family check)
1502 if( spellInfo_1->Id == 24932 && spellInfo_2->SpellIconID == 312 && spellInfo_2->SpellVisual[0] == 216 )
1503 return false;
1505 // Dragonmaw Illusion (multi-family check)
1506 if (spellId_1 == 42016 && spellId_2 == 40216 )
1507 return false;
1509 break;
1510 case SPELLFAMILY_ROGUE:
1511 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_ROGUE )
1513 // Master of Subtlety
1514 if (spellId_1 == 31665 && spellId_2 == 31666 || spellId_1 == 31666 && spellId_2 == 31665 )
1515 return false;
1517 // Sprint & Sprint (waterwalk)
1518 if( spellInfo_1->SpellIconID == 516 && spellInfo_2->SpellIconID == 516 &&
1519 (spellInfo_1->Category == 44 && spellInfo_2->Category == 0 ||
1520 spellInfo_2->Category == 44 && spellInfo_1->Category == 0))
1521 return false;
1524 //Overkill
1525 if( spellInfo_1->SpellIconID == 2285 && spellInfo_2->SpellIconID == 2285 )
1526 return false;
1528 // Garrote -> Garrote-Silence (multi-family check)
1529 if( spellInfo_1->SpellIconID == 498 && spellInfo_2->SpellIconID == 498 && spellInfo_2->SpellVisual[0] == 0 )
1530 return false;
1531 break;
1532 case SPELLFAMILY_HUNTER:
1533 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_HUNTER )
1535 // Rapid Fire & Quick Shots
1536 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x20)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x20000000000)) ||
1537 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x20)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x20000000000)) )
1538 return false;
1540 // Serpent Sting & (Immolation/Explosive Trap Effect)
1541 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x4)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x00000004000)) ||
1542 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x4)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x00000004000)) )
1543 return false;
1545 // Bestial Wrath
1546 if( spellInfo_1->SpellIconID == 1680 && spellInfo_2->SpellIconID == 1680 )
1547 return false;
1550 // Wing Clip -> Improved Wing Clip (multi-family check)
1551 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x40)) && spellInfo_2->Id == 19229 )
1552 return false;
1554 // Concussive Shot and Imp. Concussive Shot (multi-family check)
1555 if( spellInfo_2->Id == 19410 && spellInfo_1->Id == 5116 )
1556 return false;
1557 break;
1558 case SPELLFAMILY_PALADIN:
1559 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_PALADIN )
1561 // Paladin Seals
1562 if (IsSealSpell(spellInfo_1) && IsSealSpell(spellInfo_2))
1563 return true;
1565 // Swift Retribution / Improved Devotion Aura (talents) and Paladin Auras
1566 if ((spellInfo_1->SpellFamilyFlags2 & 0x00000020) && (spellInfo_2->SpellIconID == 291 || spellInfo_2->SpellIconID == 3028) ||
1567 (spellInfo_2->SpellFamilyFlags2 & 0x00000020) && (spellInfo_1->SpellIconID == 291 || spellInfo_1->SpellIconID == 3028))
1568 return false;
1571 // Combustion and Fire Protection Aura (multi-family check)
1572 if( spellInfo_2->Id == 11129 && spellInfo_1->SpellIconID == 33 && spellInfo_1->SpellVisual[0] == 321 )
1573 return false;
1575 // *Sanctity Aura -> Unstable Currents and other (multi-family check)
1576 if( spellInfo_1->SpellIconID==502 && spellInfo_2->SpellFamilyName == SPELLFAMILY_GENERIC && spellInfo_2->SpellIconID==502 && spellInfo_2->SpellVisual[0]==969 )
1577 return false;
1579 // *Seal of Command and Band of Eternal Champion (multi-family check)
1580 if( spellInfo_1->SpellIconID==561 && spellInfo_1->SpellVisual[0]==7992 && spellId_2 == 35081)
1581 return false;
1582 break;
1583 case SPELLFAMILY_SHAMAN:
1584 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_SHAMAN )
1586 // Windfury weapon
1587 if( spellInfo_1->SpellIconID==220 && spellInfo_2->SpellIconID==220 &&
1588 spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags )
1589 return false;
1591 // Bloodlust and Bloodthirst (multi-family check)
1592 if( spellInfo_1->Id == 2825 && spellInfo_2->SpellIconID == 38 && spellInfo_2->SpellVisual[0] == 0 )
1593 return false;
1594 break;
1595 case SPELLFAMILY_DEATHKNIGHT:
1596 if (spellInfo_2->SpellFamilyName == SPELLFAMILY_DEATHKNIGHT)
1598 // Frost Presence and Frost Presence (triggered)
1599 if( spellInfo_1->SpellIconID == 2632 && spellInfo_2->SpellIconID == 2632 )
1600 return false;
1602 // Unholy Presence and Unholy Presence (triggered)
1603 if( spellInfo_1->SpellIconID == 2633 && spellInfo_2->SpellIconID == 2633 )
1604 return false;
1606 break;
1607 default:
1608 break;
1611 // more generic checks
1612 if (spellInfo_1->SpellIconID == spellInfo_2->SpellIconID &&
1613 spellInfo_1->SpellIconID != 0 && spellInfo_2->SpellIconID != 0)
1615 bool isModifier = false;
1616 for (int i = 0; i < 3; ++i)
1618 if (spellInfo_1->EffectApplyAuraName[i] == SPELL_AURA_ADD_FLAT_MODIFIER ||
1619 spellInfo_1->EffectApplyAuraName[i] == SPELL_AURA_ADD_PCT_MODIFIER ||
1620 spellInfo_2->EffectApplyAuraName[i] == SPELL_AURA_ADD_FLAT_MODIFIER ||
1621 spellInfo_2->EffectApplyAuraName[i] == SPELL_AURA_ADD_PCT_MODIFIER )
1622 isModifier = true;
1625 if (!isModifier)
1626 return true;
1629 if (IsRankSpellDueToSpell(spellInfo_1, spellId_2))
1630 return true;
1632 if (spellInfo_1->SpellFamilyName == 0 || spellInfo_2->SpellFamilyName == 0)
1633 return false;
1635 if (spellInfo_1->SpellFamilyName != spellInfo_2->SpellFamilyName)
1636 return false;
1638 for (int i = 0; i < 3; ++i)
1639 if (spellInfo_1->Effect[i] != spellInfo_2->Effect[i] ||
1640 spellInfo_1->EffectItemType[i] != spellInfo_2->EffectItemType[i] ||
1641 spellInfo_1->EffectMiscValue[i] != spellInfo_2->EffectMiscValue[i] ||
1642 spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i])
1643 return false;
1645 return true;
1648 bool SpellMgr::IsProfessionOrRidingSpell(uint32 spellId)
1650 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1651 if(!spellInfo)
1652 return false;
1654 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1655 return false;
1657 uint32 skill = spellInfo->EffectMiscValue[1];
1659 return IsProfessionOrRidingSkill(skill);
1662 bool SpellMgr::IsProfessionSpell(uint32 spellId)
1664 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1665 if(!spellInfo)
1666 return false;
1668 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1669 return false;
1671 uint32 skill = spellInfo->EffectMiscValue[1];
1673 return IsProfessionSkill(skill);
1676 bool SpellMgr::IsPrimaryProfessionSpell(uint32 spellId)
1678 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1679 if(!spellInfo)
1680 return false;
1682 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1683 return false;
1685 uint32 skill = spellInfo->EffectMiscValue[1];
1687 return IsPrimaryProfessionSkill(skill);
1690 bool SpellMgr::IsPrimaryProfessionFirstRankSpell(uint32 spellId) const
1692 return IsPrimaryProfessionSpell(spellId) && GetSpellRank(spellId)==1;
1695 bool SpellMgr::IsSkillBonusSpell(uint32 spellId) const
1697 SkillLineAbilityMapBounds bounds = GetSkillLineAbilityMapBounds(spellId);
1699 for(SkillLineAbilityMap::const_iterator _spell_idx = bounds.first; _spell_idx != bounds.second; ++_spell_idx)
1701 SkillLineAbilityEntry const *pAbility = _spell_idx->second;
1702 if (!pAbility || pAbility->learnOnGetSkill != ABILITY_LEARNED_ON_GET_PROFESSION_SKILL)
1703 continue;
1705 if (pAbility->req_skill_value > 0)
1706 return true;
1709 return false;
1712 SpellEntry const* SpellMgr::SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const
1714 // ignore passive spells
1715 if(IsPassiveSpell(spellInfo->Id))
1716 return spellInfo;
1718 bool needRankSelection = false;
1719 for(int i=0;i<3;++i)
1721 if( IsPositiveEffect(spellInfo->Id, i) && (
1722 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA ||
1723 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
1724 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_RAID
1727 needRankSelection = true;
1728 break;
1732 // not required
1733 if(!needRankSelection)
1734 return spellInfo;
1736 for(uint32 nextSpellId = spellInfo->Id; nextSpellId != 0; nextSpellId = GetPrevSpellInChain(nextSpellId))
1738 SpellEntry const *nextSpellInfo = sSpellStore.LookupEntry(nextSpellId);
1739 if(!nextSpellInfo)
1740 break;
1742 // if found appropriate level
1743 if(playerLevel + 10 >= nextSpellInfo->spellLevel)
1744 return nextSpellInfo;
1746 // one rank less then
1749 // not found
1750 return NULL;
1753 void SpellMgr::LoadSpellChains()
1755 mSpellChains.clear(); // need for reload case
1756 mSpellChainsNext.clear(); // need for reload case
1758 QueryResult *result = WorldDatabase.Query("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain");
1759 if(result == NULL)
1761 barGoLink bar( 1 );
1762 bar.step();
1764 sLog.outString();
1765 sLog.outString( ">> Loaded 0 spell chain records" );
1766 sLog.outErrorDb("`spell_chains` table is empty!");
1767 return;
1770 uint32 count = 0;
1772 barGoLink bar( result->GetRowCount() );
1775 bar.step();
1776 Field *fields = result->Fetch();
1778 uint32 spell_id = fields[0].GetUInt32();
1780 SpellChainNode node;
1781 node.prev = fields[1].GetUInt32();
1782 node.first = fields[2].GetUInt32();
1783 node.rank = fields[3].GetUInt8();
1784 node.req = fields[4].GetUInt32();
1786 if(!sSpellStore.LookupEntry(spell_id))
1788 sLog.outErrorDb("Spell %u listed in `spell_chain` does not exist",spell_id);
1789 continue;
1792 if(node.prev!=0 && !sSpellStore.LookupEntry(node.prev))
1794 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existed previous rank spell.",
1795 spell_id,node.prev,node.first,node.rank,node.req);
1796 continue;
1799 if(!sSpellStore.LookupEntry(node.first))
1801 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing first rank spell.",
1802 spell_id,node.prev,node.first,node.rank,node.req);
1803 continue;
1806 // check basic spell chain data integrity (note: rank can be equal 0 or 1 for first/single spell)
1807 if( (spell_id == node.first) != (node.rank <= 1) ||
1808 (spell_id == node.first) != (node.prev == 0) ||
1809 (node.rank <= 1) != (node.prev == 0) )
1811 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not compatible chain data.",
1812 spell_id,node.prev,node.first,node.rank,node.req);
1813 continue;
1816 if(node.req!=0 && !sSpellStore.LookupEntry(node.req))
1818 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing required spell.",
1819 spell_id,node.prev,node.first,node.rank,node.req);
1820 continue;
1823 // talents not required data in spell chain for work, but must be checked if present for intergrity
1824 if(TalentSpellPos const* pos = GetTalentSpellPos(spell_id))
1826 if(node.rank!=pos->rank+1)
1828 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong rank.",
1829 spell_id,node.prev,node.first,node.rank,node.req);
1830 continue;
1833 if(TalentEntry const* talentEntry = sTalentStore.LookupEntry(pos->talent_id))
1835 if(node.first!=talentEntry->RankID[0])
1837 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong first rank spell.",
1838 spell_id,node.prev,node.first,node.rank,node.req);
1839 continue;
1842 if(node.rank > 1 && node.prev != talentEntry->RankID[node.rank-1-1])
1844 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong prev rank spell.",
1845 spell_id,node.prev,node.first,node.rank,node.req);
1846 continue;
1849 /*if(node.req!=talentEntry->DependsOnSpell)
1851 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong required spell.",
1852 spell_id,node.prev,node.first,node.rank,node.req);
1853 continue;
1858 mSpellChains[spell_id] = node;
1860 if(node.prev)
1861 mSpellChainsNext.insert(SpellChainMapNext::value_type(node.prev,spell_id));
1863 if(node.req)
1864 mSpellChainsNext.insert(SpellChainMapNext::value_type(node.req,spell_id));
1866 ++count;
1867 } while( result->NextRow() );
1869 delete result;
1871 // additional integrity checks
1872 for(SpellChainMap::const_iterator i = mSpellChains.begin(); i != mSpellChains.end(); ++i)
1874 if(i->second.prev)
1876 SpellChainMap::const_iterator i_prev = mSpellChains.find(i->second.prev);
1877 if(i_prev == mSpellChains.end())
1879 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found previous rank spell in table.",
1880 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req);
1882 else if( i_prev->second.first != i->second.first )
1884 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has different first spell in chain compared to previous rank spell (prev: %u, first: %u, rank: %d, req: %u).",
1885 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1886 i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req);
1888 else if( i_prev->second.rank+1 != i->second.rank )
1890 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has different rank compared to previous rank spell (prev: %u, first: %u, rank: %d, req: %u).",
1891 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1892 i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req);
1896 if(i->second.req)
1898 SpellChainMap::const_iterator i_req = mSpellChains.find(i->second.req);
1899 if(i_req == mSpellChains.end())
1901 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found required rank spell in table.",
1902 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req);
1904 else if( i_req->second.first == i->second.first )
1906 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has required rank spell from same spell chain (prev: %u, first: %u, rank: %d, req: %u).",
1907 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1908 i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req);
1910 else if( i_req->second.req )
1912 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has required rank spell with required spell (prev: %u, first: %u, rank: %d, req: %u).",
1913 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1914 i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req);
1919 sLog.outString();
1920 sLog.outString( ">> Loaded %u spell chain records", count );
1923 void SpellMgr::LoadSpellLearnSkills()
1925 mSpellLearnSkills.clear(); // need for reload case
1927 // search auto-learned skills and add its to map also for use in unlearn spells/talents
1928 uint32 dbc_count = 0;
1929 barGoLink bar( sSpellStore.GetNumRows() );
1930 for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
1932 bar.step();
1933 SpellEntry const* entry = sSpellStore.LookupEntry(spell);
1935 if(!entry)
1936 continue;
1938 for(int i = 0; i < 3; ++i)
1940 if(entry->Effect[i]==SPELL_EFFECT_SKILL)
1942 SpellLearnSkillNode dbc_node;
1943 dbc_node.skill = entry->EffectMiscValue[i];
1944 if ( dbc_node.skill != SKILL_RIDING )
1945 dbc_node.value = 1;
1946 else
1947 dbc_node.value = entry->CalculateSimpleValue(i)*75;
1948 dbc_node.maxvalue = entry->CalculateSimpleValue(i)*75;
1950 mSpellLearnSkills[spell] = dbc_node;
1951 ++dbc_count;
1952 break;
1957 sLog.outString();
1958 sLog.outString( ">> Loaded %u Spell Learn Skills from DBC", dbc_count );
1961 void SpellMgr::LoadSpellLearnSpells()
1963 mSpellLearnSpells.clear(); // need for reload case
1965 // 0 1 2
1966 QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell");
1967 if (!result)
1969 barGoLink bar( 1 );
1970 bar.step();
1972 sLog.outString();
1973 sLog.outString( ">> Loaded 0 spell learn spells" );
1974 sLog.outErrorDb("`spell_learn_spell` table is empty!");
1975 return;
1978 uint32 count = 0;
1980 barGoLink bar( result->GetRowCount() );
1983 bar.step();
1984 Field *fields = result->Fetch();
1986 uint32 spell_id = fields[0].GetUInt32();
1988 SpellLearnSpellNode node;
1989 node.spell = fields[1].GetUInt32();
1990 node.active = fields[2].GetBool();
1991 node.autoLearned= false;
1993 if (!sSpellStore.LookupEntry(spell_id))
1995 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id);
1996 continue;
1999 if (!sSpellStore.LookupEntry(node.spell))
2001 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` learning not existed spell %u",spell_id,node.spell);
2002 continue;
2005 if (GetTalentSpellCost(node.spell))
2007 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` attempt learning talent spell %u, skipped",spell_id,node.spell);
2008 continue;
2011 mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell_id,node));
2013 ++count;
2014 } while( result->NextRow() );
2016 delete result;
2018 // search auto-learned spells and add its to map also for use in unlearn spells/talents
2019 uint32 dbc_count = 0;
2020 for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
2022 SpellEntry const* entry = sSpellStore.LookupEntry(spell);
2024 if (!entry)
2025 continue;
2027 for(int i = 0; i < 3; ++i)
2029 if(entry->Effect[i]==SPELL_EFFECT_LEARN_SPELL)
2031 SpellLearnSpellNode dbc_node;
2032 dbc_node.spell = entry->EffectTriggerSpell[i];
2033 dbc_node.active = true; // all dbc based learned spells is active (show in spell book or hide by client itself)
2035 // ignore learning not existed spells (broken/outdated/or generic learnig spell 483
2036 if (!sSpellStore.LookupEntry(dbc_node.spell))
2037 continue;
2039 // talent or passive spells or skill-step spells auto-casted and not need dependent learning,
2040 // pet teaching spells don't must be dependent learning (casted)
2041 // other required explicit dependent learning
2042 dbc_node.autoLearned = entry->EffectImplicitTargetA[i]==TARGET_PET || GetTalentSpellCost(spell) > 0 || IsPassiveSpell(spell) || IsSpellHaveEffect(entry,SPELL_EFFECT_SKILL_STEP);
2044 SpellLearnSpellMapBounds db_node_bounds = GetSpellLearnSpellMapBounds(spell);
2046 bool found = false;
2047 for(SpellLearnSpellMap::const_iterator itr = db_node_bounds.first; itr != db_node_bounds.second; ++itr)
2049 if (itr->second.spell == dbc_node.spell)
2051 sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.",
2052 spell,dbc_node.spell);
2053 found = true;
2054 break;
2058 if (!found) // add new spell-spell pair if not found
2060 mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node));
2061 ++dbc_count;
2067 sLog.outString();
2068 sLog.outString( ">> Loaded %u spell learn spells + %u found in DBC", count, dbc_count );
2071 void SpellMgr::LoadSpellScriptTarget()
2073 mSpellScriptTarget.clear(); // need for reload case
2075 uint32 count = 0;
2077 QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target");
2079 if(!result)
2081 barGoLink bar(1);
2083 bar.step();
2085 sLog.outString();
2086 sLog.outErrorDb(">> Loaded 0 SpellScriptTarget. DB table `spell_script_target` is empty.");
2087 return;
2090 barGoLink bar(result->GetRowCount());
2094 Field *fields = result->Fetch();
2095 bar.step();
2097 uint32 spellId = fields[0].GetUInt32();
2098 uint32 type = fields[1].GetUInt32();
2099 uint32 targetEntry = fields[2].GetUInt32();
2101 SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId);
2103 if(!spellProto)
2105 sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist.",spellId,targetEntry);
2106 continue;
2109 bool targetfound = false;
2110 for(int i = 0; i <3; ++i)
2112 if( spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT ||
2113 spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT ||
2114 spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT_COORDINATES ||
2115 spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT_COORDINATES )
2117 targetfound = true;
2118 break;
2121 if(!targetfound)
2123 sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not have any implicit target TARGET_SCRIPT(38) or TARGET_SCRIPT_COORDINATES (46).",spellId,targetEntry);
2124 continue;
2127 if( type >= MAX_SPELL_TARGET_TYPE )
2129 sLog.outErrorDb("Table `spell_script_target`: target type %u for TargetEntry %u is incorrect.",type,targetEntry);
2130 continue;
2133 switch(type)
2135 case SPELL_TARGET_TYPE_GAMEOBJECT:
2137 if( targetEntry==0 )
2138 break;
2140 if(!sGOStorage.LookupEntry<GameObjectInfo>(targetEntry))
2142 sLog.outErrorDb("Table `spell_script_target`: gameobject template entry %u does not exist.",targetEntry);
2143 continue;
2145 break;
2147 default:
2149 if( targetEntry==0 )
2151 sLog.outErrorDb("Table `spell_script_target`: target entry == 0 for not GO target type (%u).",type);
2152 continue;
2154 if(!sCreatureStorage.LookupEntry<CreatureInfo>(targetEntry))
2156 sLog.outErrorDb("Table `spell_script_target`: creature template entry %u does not exist.",targetEntry);
2157 continue;
2159 const CreatureInfo* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(targetEntry);
2161 if(spellId == 30427 && !cInfo->SkinLootId)
2163 sLog.outErrorDb("Table `spell_script_target` has creature %u as a target of spellid 30427, but this creature has no skinlootid. Gas extraction will not work!", cInfo->Entry);
2164 continue;
2166 break;
2170 mSpellScriptTarget.insert(SpellScriptTarget::value_type(spellId,SpellTargetEntry(SpellTargetType(type),targetEntry)));
2172 ++count;
2173 } while (result->NextRow());
2175 delete result;
2177 // Check all spells
2178 /* Disabled (lot errors at this moment)
2179 for(uint32 i = 1; i < sSpellStore.nCount; ++i)
2181 SpellEntry const * spellInfo = sSpellStore.LookupEntry(i);
2182 if(!spellInfo)
2183 continue;
2185 bool found = false;
2186 for(int j=0; j<3; ++j)
2188 if( spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT || spellInfo->EffectImplicitTargetA[j] != TARGET_SELF && spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT )
2190 SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(spellInfo->Id);
2191 SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(spellInfo->Id);
2192 if(lower==upper)
2194 sLog.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = %u (TARGET_SCRIPT), but does not have record in `spell_script_target`",spellInfo->Id,TARGET_SCRIPT);
2195 break; // effects of spell
2202 sLog.outString();
2203 sLog.outString(">> Loaded %u Spell Script Targets", count);
2206 void SpellMgr::LoadSpellPetAuras()
2208 mSpellPetAuraMap.clear(); // need for reload case
2210 uint32 count = 0;
2212 // 0 1 2 3
2213 QueryResult *result = WorldDatabase.Query("SELECT spell, effectId, pet, aura FROM spell_pet_auras");
2214 if( !result )
2217 barGoLink bar( 1 );
2219 bar.step();
2221 sLog.outString();
2222 sLog.outString( ">> Loaded %u spell pet auras", count );
2223 return;
2226 barGoLink bar( result->GetRowCount() );
2230 Field *fields = result->Fetch();
2232 bar.step();
2234 uint32 spell = fields[0].GetUInt32();
2235 uint8 eff = fields[1].GetUInt8();
2236 uint32 pet = fields[2].GetUInt32();
2237 uint32 aura = fields[3].GetUInt32();
2239 SpellPetAuraMap::iterator itr = mSpellPetAuraMap.find((spell<<8) + eff);
2240 if(itr != mSpellPetAuraMap.end())
2242 itr->second.AddAura(pet, aura);
2244 else
2246 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2247 if (!spellInfo)
2249 sLog.outErrorDb("Spell %u listed in `spell_pet_auras` does not exist", spell);
2250 continue;
2253 if (spellInfo->Effect[eff] != SPELL_EFFECT_DUMMY &&
2254 (spellInfo->Effect[eff] != SPELL_EFFECT_APPLY_AURA ||
2255 spellInfo->EffectApplyAuraName[eff] != SPELL_AURA_DUMMY))
2257 sLog.outError("Spell %u listed in `spell_pet_auras` does not have dummy aura or dummy effect", spell);
2258 continue;
2261 SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(aura);
2262 if (!spellInfo2)
2264 sLog.outErrorDb("Aura %u listed in `spell_pet_auras` does not exist", aura);
2265 continue;
2268 PetAura pa(pet, aura, spellInfo->EffectImplicitTargetA[eff] == TARGET_PET, spellInfo->CalculateSimpleValue(eff));
2269 mSpellPetAuraMap[(spell<<8) + eff] = pa;
2272 ++count;
2273 } while( result->NextRow() );
2275 delete result;
2277 sLog.outString();
2278 sLog.outString( ">> Loaded %u spell pet auras", count );
2281 void SpellMgr::LoadPetLevelupSpellMap()
2283 uint32 count = 0;
2284 uint32 family_count = 0;
2286 for (uint32 i = 0; i < sCreatureFamilyStore.GetNumRows(); ++i)
2288 CreatureFamilyEntry const *creatureFamily = sCreatureFamilyStore.LookupEntry(i);
2289 if(!creatureFamily) // not exist
2290 continue;
2292 for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
2294 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
2295 if( !skillLine )
2296 continue;
2298 if (skillLine->skillId!=creatureFamily->skillLine[0] &&
2299 (!creatureFamily->skillLine[1] || skillLine->skillId!=creatureFamily->skillLine[1]))
2300 continue;
2302 if(skillLine->learnOnGetSkill != ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL)
2303 continue;
2305 SpellEntry const *spell = sSpellStore.LookupEntry(skillLine->spellId);
2306 if(!spell) // not exist
2307 continue;
2309 PetLevelupSpellSet& spellSet = mPetLevelupSpellMap[creatureFamily->ID];
2310 if(spellSet.empty())
2311 ++family_count;
2313 spellSet.insert(PetLevelupSpellSet::value_type(spell->spellLevel,spell->Id));
2314 count++;
2318 sLog.outString();
2319 sLog.outString( ">> Loaded %u pet levelup and default spells for %u families", count, family_count );
2322 bool LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntry& petDefSpells)
2324 // skip empty list;
2325 bool have_spell = false;
2326 for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
2328 if(petDefSpells.spellid[j])
2330 have_spell = true;
2331 break;
2334 if(!have_spell)
2335 return false;
2337 // remove duplicates with levelupSpells if any
2338 if(PetLevelupSpellSet const *levelupSpells = cInfo->family ? spellmgr.GetPetLevelupSpellList(cInfo->family) : NULL)
2340 for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
2342 if(!petDefSpells.spellid[j])
2343 continue;
2345 for(PetLevelupSpellSet::const_iterator itr = levelupSpells->begin(); itr != levelupSpells->end(); ++itr)
2347 if (itr->second == petDefSpells.spellid[j])
2349 petDefSpells.spellid[j] = 0;
2350 break;
2356 // skip empty list;
2357 have_spell = false;
2358 for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
2360 if(petDefSpells.spellid[j])
2362 have_spell = true;
2363 break;
2367 return have_spell;
2370 void SpellMgr::LoadPetDefaultSpells()
2372 assert(MAX_CREATURE_SPELL_DATA_SLOT==CREATURE_MAX_SPELLS);
2374 mPetDefaultSpellsMap.clear();
2376 uint32 countCreature = 0;
2377 uint32 countData = 0;
2379 for(uint32 i = 0; i < sCreatureStorage.MaxEntry; ++i )
2381 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(i);
2382 if(!cInfo)
2383 continue;
2385 if(!cInfo->PetSpellDataId)
2386 continue;
2388 // for creature with PetSpellDataId get default pet spells from dbc
2389 CreatureSpellDataEntry const* spellDataEntry = sCreatureSpellDataStore.LookupEntry(cInfo->PetSpellDataId);
2390 if(!spellDataEntry)
2391 continue;
2393 int32 petSpellsId = -(int32)cInfo->PetSpellDataId;
2394 PetDefaultSpellsEntry petDefSpells;
2395 for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
2396 petDefSpells.spellid[j] = spellDataEntry->spellId[j];
2398 if(LoadPetDefaultSpells_helper(cInfo, petDefSpells))
2400 mPetDefaultSpellsMap[petSpellsId] = petDefSpells;
2401 ++countData;
2405 // different summon spells
2406 for(uint32 i = 0; i < sSpellStore.GetNumRows(); ++i )
2408 SpellEntry const* spellEntry = sSpellStore.LookupEntry(i);
2409 if(!spellEntry)
2410 continue;
2412 for(int k = 0; k < 3; ++k)
2414 if(spellEntry->Effect[k]==SPELL_EFFECT_SUMMON || spellEntry->Effect[k]==SPELL_EFFECT_SUMMON_PET)
2416 uint32 creature_id = spellEntry->EffectMiscValue[k];
2417 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(creature_id);
2418 if(!cInfo)
2419 continue;
2421 // already loaded
2422 if(cInfo->PetSpellDataId)
2423 continue;
2425 // for creature without PetSpellDataId get default pet spells from creature_template
2426 int32 petSpellsId = cInfo->Entry;
2427 if(mPetDefaultSpellsMap.find(cInfo->Entry) != mPetDefaultSpellsMap.end())
2428 continue;
2430 PetDefaultSpellsEntry petDefSpells;
2431 for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
2432 petDefSpells.spellid[j] = cInfo->spells[j];
2434 if(LoadPetDefaultSpells_helper(cInfo, petDefSpells))
2436 mPetDefaultSpellsMap[petSpellsId] = petDefSpells;
2437 ++countCreature;
2443 sLog.outString();
2444 sLog.outString( ">> Loaded addition spells for %u pet spell data entries and %u summonable creature templates", countData, countCreature );
2447 /// Some checks for spells, to prevent adding deprecated/broken spells for trainers, spell book, etc
2448 bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg)
2450 // not exist
2451 if(!spellInfo)
2452 return false;
2454 bool need_check_reagents = false;
2456 // check effects
2457 for(int i=0; i<3; ++i)
2459 switch(spellInfo->Effect[i])
2461 case 0:
2462 continue;
2464 // craft spell for crafting non-existed item (break client recipes list show)
2465 case SPELL_EFFECT_CREATE_ITEM:
2466 case SPELL_EFFECT_CREATE_ITEM_2:
2468 if(!ObjectMgr::GetItemPrototype( spellInfo->EffectItemType[i] ))
2470 if(msg)
2472 if(pl)
2473 ChatHandler(pl).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]);
2474 else
2475 sLog.outErrorDb("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]);
2477 return false;
2480 need_check_reagents = true;
2481 break;
2483 case SPELL_EFFECT_LEARN_SPELL:
2485 SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[i]);
2486 if( !IsSpellValid(spellInfo2,pl,msg) )
2488 if(msg)
2490 if(pl)
2491 ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
2492 else
2493 sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
2495 return false;
2497 break;
2502 if(need_check_reagents)
2504 for(int j = 0; j < 8; ++j)
2506 if(spellInfo->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype( spellInfo->Reagent[j] ))
2508 if(msg)
2510 if(pl)
2511 ChatHandler(pl).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]);
2512 else
2513 sLog.outErrorDb("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]);
2515 return false;
2520 return true;
2523 void SpellMgr::LoadSpellAreas()
2525 mSpellAreaMap.clear(); // need for reload case
2526 mSpellAreaForQuestMap.clear();
2527 mSpellAreaForActiveQuestMap.clear();
2528 mSpellAreaForQuestEndMap.clear();
2529 mSpellAreaForAuraMap.clear();
2531 uint32 count = 0;
2533 // 0 1 2 3 4 5 6 7 8
2534 QueryResult *result = WorldDatabase.Query("SELECT spell, area, quest_start, quest_start_active, quest_end, aura_spell, racemask, gender, autocast FROM spell_area");
2536 if( !result )
2538 barGoLink bar( 1 );
2540 bar.step();
2542 sLog.outString();
2543 sLog.outString( ">> Loaded %u spell area requirements", count );
2544 return;
2547 barGoLink bar( result->GetRowCount() );
2551 Field *fields = result->Fetch();
2553 bar.step();
2555 uint32 spell = fields[0].GetUInt32();
2556 SpellArea spellArea;
2557 spellArea.spellId = spell;
2558 spellArea.areaId = fields[1].GetUInt32();
2559 spellArea.questStart = fields[2].GetUInt32();
2560 spellArea.questStartCanActive = fields[3].GetBool();
2561 spellArea.questEnd = fields[4].GetUInt32();
2562 spellArea.auraSpell = fields[5].GetInt32();
2563 spellArea.raceMask = fields[6].GetUInt32();
2564 spellArea.gender = Gender(fields[7].GetUInt8());
2565 spellArea.autocast = fields[8].GetBool();
2567 if(!sSpellStore.LookupEntry(spell))
2569 sLog.outErrorDb("Spell %u listed in `spell_area` does not exist", spell);
2570 continue;
2574 bool ok = true;
2575 SpellAreaMapBounds sa_bounds = GetSpellAreaMapBounds(spellArea.spellId);
2576 for(SpellAreaMap::const_iterator itr = sa_bounds.first; itr != sa_bounds.second; ++itr)
2578 if (spellArea.spellId != itr->second.spellId)
2579 continue;
2580 if (spellArea.areaId != itr->second.areaId)
2581 continue;
2582 if (spellArea.questStart != itr->second.questStart)
2583 continue;
2584 if (spellArea.auraSpell != itr->second.auraSpell)
2585 continue;
2586 if ((spellArea.raceMask & itr->second.raceMask) == 0)
2587 continue;
2588 if (spellArea.gender != itr->second.gender)
2589 continue;
2591 // duplicate by requirements
2592 ok =false;
2593 break;
2596 if(!ok)
2598 sLog.outErrorDb("Spell %u listed in `spell_area` already listed with similar requirements.", spell);
2599 continue;
2604 if(spellArea.areaId && !GetAreaEntryByAreaID(spellArea.areaId))
2606 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong area (%u) requirement", spell,spellArea.areaId);
2607 continue;
2610 if(spellArea.questStart && !objmgr.GetQuestTemplate(spellArea.questStart))
2612 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong start quest (%u) requirement", spell,spellArea.questStart);
2613 continue;
2616 if(spellArea.questEnd)
2618 if(!objmgr.GetQuestTemplate(spellArea.questEnd))
2620 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong end quest (%u) requirement", spell,spellArea.questEnd);
2621 continue;
2624 if(spellArea.questEnd==spellArea.questStart && !spellArea.questStartCanActive)
2626 sLog.outErrorDb("Spell %u listed in `spell_area` have quest (%u) requirement for start and end in same time", spell,spellArea.questEnd);
2627 continue;
2631 if(spellArea.auraSpell)
2633 SpellEntry const* spellInfo = sSpellStore.LookupEntry(abs(spellArea.auraSpell));
2634 if(!spellInfo)
2636 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong aura spell (%u) requirement", spell,abs(spellArea.auraSpell));
2637 continue;
2640 switch(spellInfo->EffectApplyAuraName[0])
2642 case SPELL_AURA_DUMMY:
2643 case SPELL_AURA_PHASE:
2644 case SPELL_AURA_GHOST:
2645 break;
2646 default:
2647 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell requirement (%u) without dummy/phase/ghost aura in effect 0", spell,abs(spellArea.auraSpell));
2648 continue;
2651 if(abs(spellArea.auraSpell)==spellArea.spellId)
2653 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement for itself", spell,abs(spellArea.auraSpell));
2654 continue;
2657 // not allow autocast chains by auraSpell field (but allow use as alternative if not present)
2658 if(spellArea.autocast && spellArea.auraSpell > 0)
2660 bool chain = false;
2661 SpellAreaForAuraMapBounds saBound = GetSpellAreaForAuraMapBounds(spellArea.spellId);
2662 for(SpellAreaForAuraMap::const_iterator itr = saBound.first; itr != saBound.second; ++itr)
2664 if(itr->second->autocast && itr->second->auraSpell > 0)
2666 chain = true;
2667 break;
2671 if(chain)
2673 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura", spell,spellArea.auraSpell);
2674 continue;
2677 SpellAreaMapBounds saBound2 = GetSpellAreaMapBounds(spellArea.auraSpell);
2678 for(SpellAreaMap::const_iterator itr2 = saBound2.first; itr2 != saBound2.second; ++itr2)
2680 if(itr2->second.autocast && itr2->second.auraSpell > 0)
2682 chain = true;
2683 break;
2687 if(chain)
2689 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura", spell,spellArea.auraSpell);
2690 continue;
2695 if(spellArea.raceMask && (spellArea.raceMask & RACEMASK_ALL_PLAYABLE)==0)
2697 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong race mask (%u) requirement", spell,spellArea.raceMask);
2698 continue;
2701 if(spellArea.gender!=GENDER_NONE && spellArea.gender!=GENDER_FEMALE && spellArea.gender!=GENDER_MALE)
2703 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong gender (%u) requirement", spell,spellArea.gender);
2704 continue;
2707 SpellArea const* sa = &mSpellAreaMap.insert(SpellAreaMap::value_type(spell,spellArea))->second;
2709 // for search by current zone/subzone at zone/subzone change
2710 if(spellArea.areaId)
2711 mSpellAreaForAreaMap.insert(SpellAreaForAreaMap::value_type(spellArea.areaId,sa));
2713 // for search at quest start/reward
2714 if(spellArea.questStart)
2716 if(spellArea.questStartCanActive)
2717 mSpellAreaForActiveQuestMap.insert(SpellAreaForQuestMap::value_type(spellArea.questStart,sa));
2718 else
2719 mSpellAreaForQuestMap.insert(SpellAreaForQuestMap::value_type(spellArea.questStart,sa));
2722 // for search at quest start/reward
2723 if(spellArea.questEnd)
2724 mSpellAreaForQuestEndMap.insert(SpellAreaForQuestMap::value_type(spellArea.questEnd,sa));
2726 // for search at aura apply
2727 if(spellArea.auraSpell)
2728 mSpellAreaForAuraMap.insert(SpellAreaForAuraMap::value_type(abs(spellArea.auraSpell),sa));
2730 ++count;
2731 } while( result->NextRow() );
2733 delete result;
2735 sLog.outString();
2736 sLog.outString( ">> Loaded %u spell area requirements", count );
2739 SpellCastResult SpellMgr::GetSpellAllowedInLocationError(SpellEntry const *spellInfo, uint32 map_id, uint32 zone_id, uint32 area_id, Player const* player)
2741 // normal case
2742 if (spellInfo->AreaGroupId > 0)
2744 bool found = false;
2745 AreaGroupEntry const* groupEntry = sAreaGroupStore.LookupEntry(spellInfo->AreaGroupId);
2746 while (groupEntry)
2748 for (uint32 i=0; i<6; ++i)
2749 if (groupEntry->AreaId[i] == zone_id || groupEntry->AreaId[i] == area_id)
2750 found = true;
2751 if (found || !groupEntry->nextGroup)
2752 break;
2753 // Try search in next group
2754 groupEntry = sAreaGroupStore.LookupEntry(groupEntry->nextGroup);
2757 if (!found)
2758 return SPELL_FAILED_INCORRECT_AREA;
2761 // continent limitation (virtual continent)
2762 if (spellInfo->AttributesEx4 & SPELL_ATTR_EX4_CAST_ONLY_IN_OUTLAND)
2764 uint32 v_map = GetVirtualMapForMapAndZone(map_id, zone_id);
2765 MapEntry const* mapEntry = sMapStore.LookupEntry(v_map);
2766 if (!mapEntry || mapEntry->addon < 1 || !mapEntry->IsContinent())
2767 return SPELL_FAILED_INCORRECT_AREA;
2770 // raid instance limitation
2771 if (spellInfo->AttributesEx6 & SPELL_ATTR_EX6_NOT_IN_RAID_INSTANCE)
2773 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2774 if (!mapEntry || mapEntry->IsRaid())
2775 return SPELL_FAILED_NOT_IN_RAID_INSTANCE;
2778 // DB base check (if non empty then must fit at least single for allow)
2779 SpellAreaMapBounds saBounds = spellmgr.GetSpellAreaMapBounds(spellInfo->Id);
2780 if (saBounds.first != saBounds.second)
2782 for(SpellAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
2784 if(itr->second.IsFitToRequirements(player,zone_id,area_id))
2785 return SPELL_CAST_OK;
2787 return SPELL_FAILED_INCORRECT_AREA;
2790 // bg spell checks
2791 switch(spellInfo->Id)
2793 case 23333: // Warsong Flag
2794 case 23335: // Silverwing Flag
2795 return map_id == 489 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2796 case 34976: // Netherstorm Flag
2797 return map_id == 566 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2798 case 2584: // Waiting to Resurrect
2799 case 22011: // Spirit Heal Channel
2800 case 22012: // Spirit Heal
2801 case 24171: // Resurrection Impact Visual
2802 case 42792: // Recently Dropped Flag
2803 case 43681: // Inactive
2804 case 44535: // Spirit Heal (mana)
2806 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2807 if (!mapEntry)
2808 return SPELL_FAILED_INCORRECT_AREA;
2810 return mapEntry->IsBattleGround() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2812 case 44521: // Preparation
2814 if (!player)
2815 return SPELL_FAILED_REQUIRES_AREA;
2817 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2818 if (!mapEntry)
2819 return SPELL_FAILED_INCORRECT_AREA;
2821 if (!mapEntry->IsBattleGround())
2822 return SPELL_FAILED_REQUIRES_AREA;
2824 BattleGround* bg = player->GetBattleGround();
2825 return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2827 case 32724: // Gold Team (Alliance)
2828 case 32725: // Green Team (Alliance)
2829 case 35774: // Gold Team (Horde)
2830 case 35775: // Green Team (Horde)
2832 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2833 if (!mapEntry)
2834 return SPELL_FAILED_INCORRECT_AREA;
2836 return mapEntry->IsBattleArena() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2838 case 32727: // Arena Preparation
2840 if (!player)
2841 return SPELL_FAILED_REQUIRES_AREA;
2843 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2844 if (!mapEntry)
2845 return SPELL_FAILED_INCORRECT_AREA;
2847 if (!mapEntry->IsBattleArena())
2848 return SPELL_FAILED_REQUIRES_AREA;
2850 BattleGround* bg = player->GetBattleGround();
2851 return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2855 return SPELL_CAST_OK;
2858 void SpellMgr::LoadSkillLineAbilityMap()
2860 mSkillLineAbilityMap.clear();
2862 barGoLink bar( sSkillLineAbilityStore.GetNumRows() );
2863 uint32 count = 0;
2865 for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); ++i)
2867 bar.step();
2868 SkillLineAbilityEntry const *SkillInfo = sSkillLineAbilityStore.LookupEntry(i);
2869 if(!SkillInfo)
2870 continue;
2872 mSkillLineAbilityMap.insert(SkillLineAbilityMap::value_type(SkillInfo->spellId,SkillInfo));
2873 ++count;
2876 sLog.outString();
2877 sLog.outString(">> Loaded %u SkillLineAbility MultiMap Data", count);
2880 void SpellMgr::CheckUsedSpells(char const* table)
2882 uint32 countSpells = 0;
2883 uint32 countMasks = 0;
2885 // 0 1 2 3 4 5 6 7 8 9 10 11
2886 QueryResult *result = WorldDatabase.PQuery("SELECT spellid,SpellFamilyName,SpellFamilyMaskA,SpellFamilyMaskB,SpellIcon,SpellVisual,SpellCategory,EffectType,EffectAura,EffectIdx,Name,Code FROM %s",table);
2888 if( !result )
2890 barGoLink bar( 1 );
2892 bar.step();
2894 sLog.outString();
2895 sLog.outErrorDb("`%s` table is empty!",table);
2896 return;
2899 barGoLink bar( result->GetRowCount() );
2903 Field *fields = result->Fetch();
2905 bar.step();
2907 uint32 spell = fields[0].GetUInt32();
2908 int32 family = fields[1].GetInt32();
2909 uint64 familyMaskA = fields[2].GetUInt64();
2910 uint32 familyMaskB = fields[3].GetUInt32();
2911 int32 spellIcon = fields[4].GetInt32();
2912 int32 spellVisual = fields[5].GetInt32();
2913 int32 category = fields[6].GetInt32();
2914 int32 effectType = fields[7].GetInt32();
2915 int32 auraType = fields[8].GetInt32();
2916 int32 effectIdx = fields[9].GetInt32();
2917 std::string name = fields[10].GetCppString();
2918 std::string code = fields[11].GetCppString();
2920 // checks of correctness requirements itself
2922 if (family < -1 || family > SPELLFAMILY_PET)
2924 sLog.outError("Table '%s' for spell %u have wrong SpellFamily value(%u), skipped.",table,spell,family);
2925 continue;
2928 // TODO: spellIcon check need dbc loading
2929 if (spellIcon < -1)
2931 sLog.outError("Table '%s' for spell %u have wrong SpellIcon value(%u), skipped.",table,spell,spellIcon);
2932 continue;
2935 // TODO: spellVisual check need dbc loading
2936 if (spellVisual < -1)
2938 sLog.outError("Table '%s' for spell %u have wrong SpellVisual value(%u), skipped.",table,spell,spellVisual);
2939 continue;
2942 // TODO: for spellCategory better check need dbc loading
2943 if (category < -1 || category >=0 && sSpellCategoryStore.find(category) == sSpellCategoryStore.end())
2945 sLog.outError("Table '%s' for spell %u have wrong SpellCategory value(%u), skipped.",table,spell,category);
2946 continue;
2949 if (effectType < -1 || effectType >= TOTAL_SPELL_EFFECTS)
2951 sLog.outError("Table '%s' for spell %u have wrong SpellEffect type value(%u), skipped.",table,spell,effectType);
2952 continue;
2955 if (auraType < -1 || auraType >= TOTAL_AURAS)
2957 sLog.outError("Table '%s' for spell %u have wrong SpellAura type value(%u), skipped.",table,spell,auraType);
2958 continue;
2961 if (effectIdx < -1 || effectIdx >= 3)
2963 sLog.outError("Table '%s' for spell %u have wrong EffectIdx value(%u), skipped.",table,spell,effectIdx);
2964 continue;
2967 // now checks of requirements
2969 if(spell)
2971 ++countSpells;
2973 SpellEntry const* spellEntry = sSpellStore.LookupEntry(spell);
2974 if(!spellEntry)
2976 sLog.outError("Spell %u '%s' not exist but used in %s.",spell,name.c_str(),code.c_str());
2977 continue;
2980 if(family >= 0 && spellEntry->SpellFamilyName != family)
2982 sLog.outError("Spell %u '%s' family(%u) <> %u but used in %s.",spell,name.c_str(),spellEntry->SpellFamilyName,family,code.c_str());
2983 continue;
2986 if(familyMaskA != UI64LIT(0xFFFFFFFFFFFFFFFF) || familyMaskB != 0xFFFFFFFF)
2988 if(familyMaskA == UI64LIT(0x0000000000000000) && familyMaskB == 0x00000000)
2990 if(spellEntry->SpellFamilyFlags != 0 || spellEntry->SpellFamilyFlags2 != 0)
2992 sLog.outError("Spell %u '%s' not fit to (" I64FMT "," I32FMT ") but used in %s.",spell,name.c_str(),familyMaskA,familyMaskB,code.c_str());
2993 continue;
2997 else
2999 if((spellEntry->SpellFamilyFlags & familyMaskA)==0 && (spellEntry->SpellFamilyFlags2 & familyMaskB)==0)
3001 sLog.outError("Spell %u '%s' not fit to (" I64FMT "," I32FMT ") but used in %s.",spell,name.c_str(),familyMaskA,familyMaskB,code.c_str());
3002 continue;
3008 if(spellIcon >= 0 && spellEntry->SpellIconID != spellIcon)
3010 sLog.outError("Spell %u '%s' icon(%u) <> %u but used in %s.",spell,name.c_str(),spellEntry->SpellIconID,spellIcon,code.c_str());
3011 continue;
3014 if(spellVisual >= 0 && spellEntry->SpellVisual[0] != spellVisual)
3016 sLog.outError("Spell %u '%s' visual(%u) <> %u but used in %s.",spell,name.c_str(),spellEntry->SpellVisual[0],spellVisual,code.c_str());
3017 continue;
3020 if(category >= 0 && spellEntry->Category != category)
3022 sLog.outError("Spell %u '%s' category(%u) <> %u but used in %s.",spell,name.c_str(),spellEntry->Category,category,code.c_str());
3023 continue;
3026 if(effectIdx >= 0)
3028 if(effectType >= 0 && spellEntry->Effect[effectIdx] != effectType)
3030 sLog.outError("Spell %u '%s' effect%d <> %u but used in %s.",spell,name.c_str(),effectIdx+1,effectType,code.c_str());
3031 continue;
3034 if(auraType >= 0 && spellEntry->EffectApplyAuraName[effectIdx] != auraType)
3036 sLog.outError("Spell %u '%s' aura%d <> %u but used in %s.",spell,name.c_str(),effectIdx+1,auraType,code.c_str());
3037 continue;
3041 else
3043 if(effectType >= 0 && !IsSpellHaveEffect(spellEntry,SpellEffects(effectType)))
3045 sLog.outError("Spell %u '%s' not have effect %u but used in %s.",spell,name.c_str(),effectType,code.c_str());
3046 continue;
3049 if(auraType >= 0 && !IsSpellHaveAura(spellEntry,AuraType(auraType)))
3051 sLog.outError("Spell %u '%s' not have aura %u but used in %s.",spell,name.c_str(),auraType,code.c_str());
3052 continue;
3056 else
3058 ++countMasks;
3060 bool found = false;
3061 for(uint32 spellId = 1; spellId < sSpellStore.GetNumRows(); ++spellId)
3063 SpellEntry const* spellEntry = sSpellStore.LookupEntry(spellId);
3064 if(!spellEntry)
3065 continue;
3067 if(family >=0 && spellEntry->SpellFamilyName != family)
3068 continue;
3070 if(familyMaskA != UI64LIT(0xFFFFFFFFFFFFFFFF) || familyMaskB != 0xFFFFFFFF)
3072 if(familyMaskA == UI64LIT(0x0000000000000000) && familyMaskB == 0x00000000)
3074 if(spellEntry->SpellFamilyFlags != 0 || spellEntry->SpellFamilyFlags2 != 0)
3075 continue;
3077 else
3079 if((spellEntry->SpellFamilyFlags & familyMaskA)==0 && (spellEntry->SpellFamilyFlags2 & familyMaskB)==0)
3080 continue;
3084 if(spellIcon >= 0 && spellEntry->SpellIconID != spellIcon)
3085 continue;
3087 if(spellVisual >= 0 && spellEntry->SpellVisual[0] != spellVisual)
3088 continue;
3090 if(category >= 0 && spellEntry->Category != category)
3091 continue;
3093 if(effectIdx >= 0)
3095 if(effectType >=0 && spellEntry->Effect[effectIdx] != effectType)
3096 continue;
3098 if(auraType >=0 && spellEntry->EffectApplyAuraName[effectIdx] != auraType)
3099 continue;
3101 else
3103 if(effectType >=0 && !IsSpellHaveEffect(spellEntry,SpellEffects(effectType)))
3104 continue;
3106 if(auraType >=0 && !IsSpellHaveAura(spellEntry,AuraType(auraType)))
3107 continue;
3110 found = true;
3111 break;
3114 if(!found)
3116 if(effectIdx >= 0)
3117 sLog.outError("Spells '%s' not found for family %i (" I64FMT "," I32FMT ") icon(%i) visual(%i) category(%i) effect%d(%i) aura%d(%i) but used in %s",
3118 name.c_str(),family,familyMaskA,familyMaskB,spellIcon,spellVisual,category,effectIdx+1,effectType,effectIdx+1,auraType,code.c_str());
3119 else
3120 sLog.outError("Spells '%s' not found for family %i (" I64FMT "," I32FMT ") icon(%i) visual(%i) category(%i) effect(%i) aura(%i) but used in %s",
3121 name.c_str(),family,familyMaskA,familyMaskB,spellIcon,spellVisual,category,effectType,auraType,code.c_str());
3122 continue;
3126 } while( result->NextRow() );
3128 delete result;
3130 sLog.outString();
3131 sLog.outString( ">> Checked %u spells and %u spell masks", countSpells, countMasks );
3134 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered)
3136 // Explicit Diminishing Groups
3137 switch(spellproto->SpellFamilyName)
3139 case SPELLFAMILY_GENERIC:
3140 // some generic arena related spells have by some strange reason MECHANIC_TURN
3141 if (spellproto->Mechanic == MECHANIC_TURN)
3142 return DIMINISHING_NONE;
3143 break;
3144 case SPELLFAMILY_ROGUE:
3146 // Blind
3147 if (spellproto->SpellFamilyFlags & UI64LIT(0x00001000000))
3148 return DIMINISHING_FEAR_BLIND;
3149 // Cheap Shot
3150 else if (spellproto->SpellFamilyFlags & UI64LIT(0x00000000400))
3151 return DIMINISHING_CHEAPSHOT_POUNCE;
3152 // Crippling poison - Limit to 10 seconds in PvP (No SpellFamilyFlags)
3153 else if (spellproto->SpellIconID == 163)
3154 return DIMINISHING_LIMITONLY;
3155 break;
3157 case SPELLFAMILY_WARLOCK:
3159 // Curses/etc
3160 if (spellproto->SpellFamilyFlags & UI64LIT(0x00080000000))
3161 return DIMINISHING_LIMITONLY;
3162 // Seduction
3163 else if (spellproto->SpellFamilyFlags & UI64LIT(0x00040000000))
3164 return DIMINISHING_CHARM;
3165 break;
3167 case SPELLFAMILY_DRUID:
3169 // Cyclone
3170 if (spellproto->SpellFamilyFlags & UI64LIT(0x02000000000))
3171 return DIMINISHING_CYCLONE;
3172 // Pounce
3173 else if (spellproto->SpellFamilyFlags & UI64LIT(0x00000020000))
3174 return DIMINISHING_CHEAPSHOT_POUNCE;
3175 // Faerie Fire
3176 else if (spellproto->SpellFamilyFlags & UI64LIT(0x00000000400))
3177 return DIMINISHING_LIMITONLY;
3178 break;
3180 case SPELLFAMILY_WARRIOR:
3182 // Hamstring - limit duration to 10s in PvP
3183 if (spellproto->SpellFamilyFlags & UI64LIT(0x00000000002))
3184 return DIMINISHING_LIMITONLY;
3185 break;
3187 case SPELLFAMILY_PRIEST:
3189 // Vampiric Embrace
3190 if ((spellproto->SpellFamilyFlags & UI64LIT(0x00000000004)) && spellproto->SpellIconID == 150)
3191 return DIMINISHING_LIMITONLY;
3192 break;
3194 case SPELLFAMILY_DEATHKNIGHT:
3196 // Hungering Cold (no flags)
3197 if (spellproto->SpellIconID == 2797)
3198 return DIMINISHING_POLYMORPH_GOUGE_SAP;
3199 break;
3201 default:
3202 break;
3205 // Get by mechanic
3206 uint32 mechanic = GetAllSpellMechanicMask(spellproto);
3207 if (mechanic == MECHANIC_NONE) return DIMINISHING_NONE;
3208 if (mechanic & ((1<<MECHANIC_STUN) |
3209 (1<<MECHANIC_SHACKLE))) return triggered ? DIMINISHING_TRIGGER_STUN : DIMINISHING_CONTROL_STUN;
3210 if (mechanic & (1<<MECHANIC_SLEEP)) return DIMINISHING_FREEZE_SLEEP;
3211 if (mechanic & (1<<MECHANIC_POLYMORPH)) return DIMINISHING_POLYMORPH_GOUGE_SAP;
3212 if (mechanic & (1<<MECHANIC_ROOT)) return triggered ? DIMINISHING_TRIGGER_ROOT : DIMINISHING_CONTROL_ROOT;
3213 if (mechanic & ((1<<MECHANIC_FEAR) |
3214 (1<<MECHANIC_TURN))) return DIMINISHING_FEAR_BLIND;
3215 if (mechanic & (1<<MECHANIC_CHARM)) return DIMINISHING_CHARM;
3216 if (mechanic & (1<<MECHANIC_SILENCE)) return DIMINISHING_SILENCE;
3217 if (mechanic & (1<<MECHANIC_DISARM)) return DIMINISHING_DISARM;
3218 if (mechanic & (1<<MECHANIC_FREEZE)) return DIMINISHING_FREEZE_SLEEP;
3219 if (mechanic & ((1<<MECHANIC_KNOCKOUT) |
3220 (1<<MECHANIC_SAPPED))) return DIMINISHING_POLYMORPH_GOUGE_SAP;
3221 if (mechanic & (1<<MECHANIC_BANISH)) return DIMINISHING_BANISH;
3222 if (mechanic & (1<<MECHANIC_HORROR)) return DIMINISHING_DEATHCOIL;
3225 return DIMINISHING_NONE;
3228 int32 GetDiminishingReturnsLimitDuration(DiminishingGroup group, SpellEntry const* spellproto)
3230 if(!IsDiminishingReturnsGroupDurationLimited(group))
3231 return 0;
3233 // Explicit diminishing duration
3234 switch(spellproto->SpellFamilyName)
3236 case SPELLFAMILY_HUNTER:
3238 // Wyvern Sting
3239 if (spellproto->SpellFamilyFlags & UI64LIT(0x0000100000000000))
3240 return 6000;
3241 break;
3243 case SPELLFAMILY_PALADIN:
3245 // Repentance - limit to 6 seconds in PvP
3246 if (spellproto->SpellFamilyFlags & UI64LIT(0x00000000004))
3247 return 6000;
3248 break;
3250 case SPELLFAMILY_DRUID:
3252 // Faerie Fire - limit to 40 seconds in PvP (3.1)
3253 if (spellproto->SpellFamilyFlags & UI64LIT(0x00000000400))
3254 return 40000;
3255 break;
3257 case SPELLFAMILY_PRIEST:
3259 // Vampiric Embrace - limit to 60 seconds in PvP (3.1)
3260 if ((spellproto->SpellFamilyFlags & UI64LIT(0x00000000004)) && spellproto->SpellIconID == 150)
3261 return 60000;
3262 break;
3264 default:
3265 break;
3268 return 10000;
3271 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group)
3273 switch(group)
3275 case DIMINISHING_CONTROL_STUN:
3276 case DIMINISHING_TRIGGER_STUN:
3277 case DIMINISHING_CONTROL_ROOT:
3278 case DIMINISHING_TRIGGER_ROOT:
3279 case DIMINISHING_FEAR_BLIND:
3280 case DIMINISHING_CHARM:
3281 case DIMINISHING_POLYMORPH_GOUGE_SAP:
3282 case DIMINISHING_CHEAPSHOT_POUNCE:
3283 case DIMINISHING_FREEZE_SLEEP:
3284 case DIMINISHING_CYCLONE:
3285 case DIMINISHING_BANISH:
3286 case DIMINISHING_LIMITONLY:
3287 return true;
3288 default:
3289 return false;
3291 return false;
3294 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group)
3296 switch(group)
3298 case DIMINISHING_CYCLONE:
3299 case DIMINISHING_TRIGGER_STUN:
3300 case DIMINISHING_CONTROL_STUN:
3301 case DIMINISHING_CHEAPSHOT_POUNCE:
3302 return DRTYPE_ALL;
3303 case DIMINISHING_CONTROL_ROOT:
3304 case DIMINISHING_TRIGGER_ROOT:
3305 case DIMINISHING_FEAR_BLIND:
3306 case DIMINISHING_CHARM:
3307 case DIMINISHING_POLYMORPH_GOUGE_SAP:
3308 case DIMINISHING_SILENCE:
3309 case DIMINISHING_DISARM:
3310 case DIMINISHING_DEATHCOIL:
3311 case DIMINISHING_FREEZE_SLEEP:
3312 case DIMINISHING_BANISH:
3313 return DRTYPE_PLAYER;
3314 default:
3315 break;
3318 return DRTYPE_NONE;
3321 bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32 newArea) const
3323 if(gender!=GENDER_NONE)
3325 // not in expected gender
3326 if(!player || gender != player->getGender())
3327 return false;
3330 if(raceMask)
3332 // not in expected race
3333 if(!player || !(raceMask & player->getRaceMask()))
3334 return false;
3337 if(areaId)
3339 // not in expected zone
3340 if(newZone!=areaId && newArea!=areaId)
3341 return false;
3344 if(questStart)
3346 // not in expected required quest state
3347 if(!player || (!questStartCanActive || !player->IsActiveQuest(questStart)) && !player->GetQuestRewardStatus(questStart))
3348 return false;
3351 if(questEnd)
3353 // not in expected forbidden quest state
3354 if(!player || player->GetQuestRewardStatus(questEnd))
3355 return false;
3358 if(auraSpell)
3360 // not have expected aura
3361 if(!player)
3362 return false;
3363 if(auraSpell > 0)
3364 // have expected aura
3365 return player->HasAura(auraSpell,0);
3366 else
3367 // not have expected aura
3368 return !player->HasAura(-auraSpell,0);
3371 return true;