[7924] Not teleport player to non-player caster at ressurection.
[getmangos.git] / src / game / SpellMgr.cpp
blobf06073ee60355316b496f7f024b65e5ef1930b04
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_UNK5)) )
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_MAGE:
140 // family flags 18(Molten), 25(Frost/Ice), 28(Mage)
141 if (spellInfo->SpellFamilyFlags & UI64LIT(0x12040000))
142 return SPELL_MAGE_ARMOR;
144 if ((spellInfo->SpellFamilyFlags & UI64LIT(0x1000000)) && spellInfo->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE)
145 return SPELL_MAGE_POLYMORPH;
147 break;
149 case SPELLFAMILY_WARRIOR:
151 if (spellInfo->SpellFamilyFlags & UI64LIT(0x00008000010000))
152 return SPELL_POSITIVE_SHOUT;
154 break;
156 case SPELLFAMILY_WARLOCK:
158 // only warlock curses have this
159 if (spellInfo->Dispel == DISPEL_CURSE)
160 return SPELL_CURSE;
162 // Warlock (Demon Armor | Demon Skin | Fel Armor)
163 if (spellInfo->SpellFamilyFlags & UI64LIT(0x2000002000000000) || spellInfo->SpellFamilyFlags2 & 0x00000010)
164 return SPELL_WARLOCK_ARMOR;
166 break;
168 case SPELLFAMILY_HUNTER:
170 // only hunter stings have this
171 if (spellInfo->Dispel == DISPEL_POISON)
172 return SPELL_STING;
174 // only hunter aspects have this (but not all aspects in hunter family)
175 if( spellInfo->SpellFamilyFlags & UI64LIT(0x0044000000380000) || spellInfo->SpellFamilyFlags2 & 0x00003010)
176 return SPELL_ASPECT;
178 if( spellInfo->SpellFamilyFlags2 & 0x00000002 )
179 return SPELL_TRACKER;
181 break;
183 case SPELLFAMILY_PALADIN:
185 if (IsSealSpell(spellInfo))
186 return SPELL_SEAL;
188 if (spellInfo->SpellFamilyFlags & UI64LIT(0x0000000011010002))
189 return SPELL_BLESSING;
191 if ((spellInfo->SpellFamilyFlags & UI64LIT(0x00000820180400)) && (spellInfo->AttributesEx3 & 0x200))
192 return SPELL_JUDGEMENT;
194 for (int i = 0; i < 3; ++i)
196 // only paladin auras have this (for palaldin class family)
197 if (spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_RAID)
198 return SPELL_AURA;
200 break;
202 case SPELLFAMILY_SHAMAN:
204 if (IsElementalShield(spellInfo))
205 return SPELL_ELEMENTAL_SHIELD;
207 break;
210 case SPELLFAMILY_POTION:
211 return spellmgr.GetSpellElixirSpecific(spellInfo->Id);
213 case SPELLFAMILY_DEATHKNIGHT:
214 if ((spellInfo->Attributes & 0x10) && (spellInfo->AttributesEx2 & 0x10) && (spellInfo->AttributesEx4 & 0x200000))
215 return SPELL_PRESENCE;
216 break;
219 // elixirs can have different families, but potion most ofc.
220 if(SpellSpecific sp = spellmgr.GetSpellElixirSpecific(spellInfo->Id))
221 return sp;
223 return SPELL_NORMAL;
226 bool IsSingleFromSpellSpecificPerCaster(SpellSpecific spellSpec1,SpellSpecific spellSpec2)
228 switch(spellSpec1)
230 case SPELL_SEAL:
231 case SPELL_BLESSING:
232 case SPELL_AURA:
233 case SPELL_STING:
234 case SPELL_CURSE:
235 case SPELL_ASPECT:
236 case SPELL_TRACKER:
237 case SPELL_WARLOCK_ARMOR:
238 case SPELL_MAGE_ARMOR:
239 case SPELL_MAGE_POLYMORPH:
240 case SPELL_POSITIVE_SHOUT:
241 case SPELL_JUDGEMENT:
242 case SPELL_PRESENCE:
243 return spellSpec1==spellSpec2;
244 case SPELL_BATTLE_ELIXIR:
245 return spellSpec2==SPELL_BATTLE_ELIXIR
246 || spellSpec2==SPELL_FLASK_ELIXIR;
247 case SPELL_GUARDIAN_ELIXIR:
248 return spellSpec2==SPELL_GUARDIAN_ELIXIR
249 || spellSpec2==SPELL_FLASK_ELIXIR;
250 case SPELL_FLASK_ELIXIR:
251 return spellSpec2==SPELL_BATTLE_ELIXIR
252 || spellSpec2==SPELL_GUARDIAN_ELIXIR
253 || spellSpec2==SPELL_FLASK_ELIXIR;
254 default:
255 return false;
259 bool IsSingleFromSpellSpecificRanksPerTarget(SpellSpecific spellId_spec, SpellSpecific i_spellId_spec)
261 switch(spellId_spec)
263 case SPELL_BLESSING:
264 case SPELL_AURA:
265 case SPELL_CURSE:
266 return spellId_spec==i_spellId_spec;
267 default:
268 return false;
272 bool IsPositiveTarget(uint32 targetA, uint32 targetB)
274 // non-positive targets
275 switch(targetA)
277 case TARGET_CHAIN_DAMAGE:
278 case TARGET_ALL_ENEMY_IN_AREA:
279 case TARGET_ALL_ENEMY_IN_AREA_INSTANT:
280 case TARGET_IN_FRONT_OF_CASTER:
281 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED:
282 case TARGET_CURRENT_ENEMY_COORDINATES:
283 case TARGET_SINGLE_ENEMY:
284 return false;
285 case TARGET_CASTER_COORDINATES:
286 return (targetB == TARGET_ALL_PARTY || targetB == TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER);
287 default:
288 break;
290 if (targetB)
291 return IsPositiveTarget(targetB, 0);
292 return true;
295 bool IsPositiveEffect(uint32 spellId, uint32 effIndex)
297 SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId);
298 if (!spellproto) return false;
300 switch(spellId)
302 case 28441: // not positive dummy spell
303 case 37675: // Chaos Blast
304 return false;
307 switch(spellproto->Effect[effIndex])
309 // always positive effects (check before target checks that provided non-positive result in some case for positive effects)
310 case SPELL_EFFECT_HEAL:
311 case SPELL_EFFECT_LEARN_SPELL:
312 case SPELL_EFFECT_SKILL_STEP:
313 case SPELL_EFFECT_HEAL_PCT:
314 case SPELL_EFFECT_ENERGIZE_PCT:
315 return true;
317 // non-positive aura use
318 case SPELL_EFFECT_APPLY_AURA:
319 case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND:
321 switch(spellproto->EffectApplyAuraName[effIndex])
323 case SPELL_AURA_DUMMY:
325 // dummy aura can be positive or negative dependent from casted spell
326 switch(spellproto->Id)
328 case 13139: // net-o-matic special effect
329 case 23445: // evil twin
330 case 35679: // Protectorate Demolitionist
331 case 38637: // Nether Exhaustion (red)
332 case 38638: // Nether Exhaustion (green)
333 case 38639: // Nether Exhaustion (blue)
334 return false;
335 default:
336 break;
338 } break;
339 case SPELL_AURA_MOD_STAT:
340 case SPELL_AURA_MOD_DAMAGE_DONE: // dependent from bas point sign (negative -> negative)
341 case SPELL_AURA_MOD_HEALING_DONE:
342 if(spellproto->CalculateSimpleValue(effIndex) < 0)
343 return false;
344 break;
345 case SPELL_AURA_MOD_SPELL_CRIT_CHANCE:
346 if(spellproto->CalculateSimpleValue(effIndex) > 0)
347 return true; // some expected possitive spells have SPELL_ATTR_EX_NEGATIVE
348 break;
349 case SPELL_AURA_ADD_TARGET_TRIGGER:
350 return true;
351 case SPELL_AURA_PERIODIC_TRIGGER_SPELL:
352 if(spellId != spellproto->EffectTriggerSpell[effIndex])
354 uint32 spellTriggeredId = spellproto->EffectTriggerSpell[effIndex];
355 SpellEntry const *spellTriggeredProto = sSpellStore.LookupEntry(spellTriggeredId);
357 if(spellTriggeredProto)
359 // non-positive targets of main spell return early
360 for(int i = 0; i < 3; ++i)
362 // if non-positive trigger cast targeted to positive target this main cast is non-positive
363 // this will place this spell auras as debuffs
364 if(IsPositiveTarget(spellTriggeredProto->EffectImplicitTargetA[effIndex],spellTriggeredProto->EffectImplicitTargetB[effIndex]) && !IsPositiveEffect(spellTriggeredId,i))
365 return false;
369 break;
370 case SPELL_AURA_PROC_TRIGGER_SPELL:
371 // many positive auras have negative triggered spells at damage for example and this not make it negative (it can be canceled for example)
372 break;
373 case SPELL_AURA_MOD_STUN: //have positive and negative spells, we can't sort its correctly at this moment.
374 if(effIndex==0 && spellproto->Effect[1]==0 && spellproto->Effect[2]==0)
375 return false; // but all single stun aura spells is negative
377 // Petrification
378 if(spellproto->Id == 17624)
379 return false;
380 break;
381 case SPELL_AURA_MOD_ROOT:
382 case SPELL_AURA_MOD_SILENCE:
383 case SPELL_AURA_GHOST:
384 case SPELL_AURA_PERIODIC_LEECH:
385 case SPELL_AURA_MOD_PACIFY_SILENCE:
386 case SPELL_AURA_MOD_STALKED:
387 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
388 return false;
389 case SPELL_AURA_PERIODIC_DAMAGE: // used in positive spells also.
390 // part of negative spell if casted at self (prevent cancel)
391 if(spellproto->EffectImplicitTargetA[effIndex] == TARGET_SELF)
392 return false;
393 break;
394 case SPELL_AURA_MOD_DECREASE_SPEED: // used in positive spells also
395 // part of positive spell if casted at self
396 if(spellproto->EffectImplicitTargetA[effIndex] != TARGET_SELF)
397 return false;
398 // but not this if this first effect (don't found batter check)
399 if(spellproto->Attributes & 0x4000000 && effIndex==0)
400 return false;
401 break;
402 case SPELL_AURA_TRANSFORM:
403 // some spells negative
404 switch(spellproto->Id)
406 case 36897: // Transporter Malfunction (race mutation to horde)
407 case 36899: // Transporter Malfunction (race mutation to alliance)
408 return false;
410 break;
411 case SPELL_AURA_MOD_SCALE:
412 // some spells negative
413 switch(spellproto->Id)
415 case 36900: // Soul Split: Evil!
416 case 36901: // Soul Split: Good
417 case 36893: // Transporter Malfunction (decrease size case)
418 case 36895: // Transporter Malfunction (increase size case)
419 return false;
421 break;
422 case SPELL_AURA_MECHANIC_IMMUNITY:
424 // non-positive immunities
425 switch(spellproto->EffectMiscValue[effIndex])
427 case MECHANIC_BANDAGE:
428 case MECHANIC_SHIELD:
429 case MECHANIC_MOUNT:
430 case MECHANIC_INVULNERABILITY:
431 return false;
432 default:
433 break;
435 } break;
436 case SPELL_AURA_ADD_FLAT_MODIFIER: // mods
437 case SPELL_AURA_ADD_PCT_MODIFIER:
439 // non-positive mods
440 switch(spellproto->EffectMiscValue[effIndex])
442 case SPELLMOD_COST: // dependent from bas point sign (negative -> positive)
443 if(spellproto->CalculateSimpleValue(effIndex) > 0)
444 return false;
445 break;
446 default:
447 break;
449 } break;
450 case SPELL_AURA_MOD_HEALING_PCT:
451 if(spellproto->CalculateSimpleValue(effIndex) < 0)
452 return false;
453 break;
454 case SPELL_AURA_MOD_SKILL:
455 if(spellproto->CalculateSimpleValue(effIndex) < 0)
456 return false;
457 break;
458 case SPELL_AURA_FORCE_REACTION:
459 if(spellproto->Id==42792) // Recently Dropped Flag (prevent cancel)
460 return false;
461 break;
462 default:
463 break;
465 break;
467 default:
468 break;
471 // non-positive targets
472 if(!IsPositiveTarget(spellproto->EffectImplicitTargetA[effIndex],spellproto->EffectImplicitTargetB[effIndex]))
473 return false;
475 // AttributesEx check
476 if(spellproto->AttributesEx & SPELL_ATTR_EX_NEGATIVE)
477 return false;
479 // ok, positive
480 return true;
483 bool IsPositiveSpell(uint32 spellId)
485 SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId);
486 if (!spellproto) return false;
488 // spells with atleast one negative effect are considered negative
489 // some self-applied spells have negative effects but in self casting case negative check ignored.
490 for (int i = 0; i < 3; ++i)
491 if (!IsPositiveEffect(spellId, i))
492 return false;
493 return true;
496 bool IsSingleTargetSpell(SpellEntry const *spellInfo)
498 // all other single target spells have if it has AttributesEx5
499 if ( spellInfo->AttributesEx5 & SPELL_ATTR_EX5_SINGLE_TARGET_SPELL )
500 return true;
502 // TODO - need found Judgements rule
503 switch(GetSpellSpecific(spellInfo->Id))
505 case SPELL_JUDGEMENT:
506 return true;
507 default:
508 break;
511 // single target triggered spell.
512 // Not real client side single target spell, but it' not triggered until prev. aura expired.
513 // This is allow store it in single target spells list for caster for spell proc checking
514 if(spellInfo->Id==38324) // Regeneration (triggered by 38299 (HoTs on Heals))
515 return true;
517 return false;
520 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2)
522 // TODO - need better check
523 // Equal icon and spellfamily
524 if( spellInfo1->SpellFamilyName == spellInfo2->SpellFamilyName &&
525 spellInfo1->SpellIconID == spellInfo2->SpellIconID )
526 return true;
528 // TODO - need found Judgements rule
529 SpellSpecific spec1 = GetSpellSpecific(spellInfo1->Id);
530 // spell with single target specific types
531 switch(spec1)
533 case SPELL_JUDGEMENT:
534 case SPELL_MAGE_POLYMORPH:
535 if(GetSpellSpecific(spellInfo2->Id) == spec1)
536 return true;
537 break;
538 default:
539 break;
542 return false;
545 bool IsAuraAddedBySpell(uint32 auraType, uint32 spellId)
547 SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId);
548 if (!spellproto) return false;
550 for (int i = 0; i < 3; ++i)
551 if (spellproto->EffectApplyAuraName[i] == auraType)
552 return true;
553 return false;
556 SpellCastResult GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form)
558 // talents that learn spells can have stance requirements that need ignore
559 // (this requirement only for client-side stance show in talent description)
560 if( GetTalentSpellCost(spellInfo->Id) > 0 &&
561 (spellInfo->Effect[0]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[1]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[2]==SPELL_EFFECT_LEARN_SPELL) )
562 return SPELL_CAST_OK;
564 uint32 stanceMask = (form ? 1 << (form - 1) : 0);
566 if (stanceMask & spellInfo->StancesNot) // can explicitly not be casted in this stance
567 return SPELL_FAILED_NOT_SHAPESHIFT;
569 if (stanceMask & spellInfo->Stances) // can explicitly be casted in this stance
570 return SPELL_CAST_OK;
572 bool actAsShifted = false;
573 if (form > 0)
575 SpellShapeshiftEntry const *shapeInfo = sSpellShapeshiftStore.LookupEntry(form);
576 if (!shapeInfo)
578 sLog.outError("GetErrorAtShapeshiftedCast: unknown shapeshift %u", form);
579 return SPELL_CAST_OK;
581 actAsShifted = !(shapeInfo->flags1 & 1); // shapeshift acts as normal form for spells
584 if(actAsShifted)
586 if (spellInfo->Attributes & SPELL_ATTR_NOT_SHAPESHIFT) // not while shapeshifted
587 return SPELL_FAILED_NOT_SHAPESHIFT;
588 else if (spellInfo->Stances != 0) // needs other shapeshift
589 return SPELL_FAILED_ONLY_SHAPESHIFT;
591 else
593 // needs shapeshift
594 if(!(spellInfo->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) && spellInfo->Stances != 0)
595 return SPELL_FAILED_ONLY_SHAPESHIFT;
598 return SPELL_CAST_OK;
601 void SpellMgr::LoadSpellTargetPositions()
603 mSpellTargetPositions.clear(); // need for reload case
605 uint32 count = 0;
607 // 0 1 2 3 4 5
608 QueryResult *result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position");
609 if( !result )
612 barGoLink bar( 1 );
614 bar.step();
616 sLog.outString();
617 sLog.outString( ">> Loaded %u spell target coordinates", count );
618 return;
621 barGoLink bar( result->GetRowCount() );
625 Field *fields = result->Fetch();
627 bar.step();
629 ++count;
631 uint32 Spell_ID = fields[0].GetUInt32();
633 SpellTargetPosition st;
635 st.target_mapId = fields[1].GetUInt32();
636 st.target_X = fields[2].GetFloat();
637 st.target_Y = fields[3].GetFloat();
638 st.target_Z = fields[4].GetFloat();
639 st.target_Orientation = fields[5].GetFloat();
641 SpellEntry const* spellInfo = sSpellStore.LookupEntry(Spell_ID);
642 if(!spellInfo)
644 sLog.outErrorDb("Spell (ID:%u) listed in `spell_target_position` does not exist.",Spell_ID);
645 continue;
648 bool found = false;
649 for(int i = 0; i < 3; ++i)
651 if( spellInfo->EffectImplicitTargetA[i]==TARGET_TABLE_X_Y_Z_COORDINATES || spellInfo->EffectImplicitTargetB[i]==TARGET_TABLE_X_Y_Z_COORDINATES )
653 found = true;
654 break;
657 if(!found)
659 sLog.outErrorDb("Spell (Id: %u) listed in `spell_target_position` does not have target TARGET_TABLE_X_Y_Z_COORDINATES (17).",Spell_ID);
660 continue;
663 MapEntry const* mapEntry = sMapStore.LookupEntry(st.target_mapId);
664 if(!mapEntry)
666 sLog.outErrorDb("Spell (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Spell_ID,st.target_mapId);
667 continue;
670 if(st.target_X==0 && st.target_Y==0 && st.target_Z==0)
672 sLog.outErrorDb("Spell (ID:%u) target coordinates not provided.",Spell_ID);
673 continue;
676 mSpellTargetPositions[Spell_ID] = st;
678 } while( result->NextRow() );
680 delete result;
682 sLog.outString();
683 sLog.outString( ">> Loaded %u spell teleport coordinates", count );
686 void SpellMgr::LoadSpellAffects()
688 mSpellAffectMap.clear(); // need for reload case
690 uint32 count = 0;
692 // 0 1 2 3 4
693 QueryResult *result = WorldDatabase.Query("SELECT entry, effectId, SpellClassMask0, SpellClassMask1, SpellClassMask2 FROM spell_affect");
694 if( !result )
697 barGoLink bar( 1 );
699 bar.step();
701 sLog.outString();
702 sLog.outString( ">> Loaded %u spell affect definitions", count );
703 return;
706 barGoLink bar( result->GetRowCount() );
710 Field *fields = result->Fetch();
712 bar.step();
714 uint16 entry = fields[0].GetUInt16();
715 uint8 effectId = fields[1].GetUInt8();
717 SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry);
719 if (!spellInfo)
721 sLog.outErrorDb("Spell %u listed in `spell_affect` does not exist", entry);
722 continue;
725 if (effectId >= 3)
727 sLog.outErrorDb("Spell %u listed in `spell_affect` have invalid effect index (%u)", entry,effectId);
728 continue;
731 if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA ||
732 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER &&
733 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER &&
734 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER )
736 sLog.outErrorDb("Spell %u listed in `spell_affect` have not SPELL_AURA_ADD_FLAT_MODIFIER (%u) or SPELL_AURA_ADD_PCT_MODIFIER (%u) or SPELL_AURA_ADD_TARGET_TRIGGER (%u) for effect index (%u)", entry,SPELL_AURA_ADD_FLAT_MODIFIER,SPELL_AURA_ADD_PCT_MODIFIER,SPELL_AURA_ADD_TARGET_TRIGGER,effectId);
737 continue;
740 SpellAffectEntry affect;
741 affect.SpellClassMask[0] = fields[2].GetUInt32();
742 affect.SpellClassMask[1] = fields[3].GetUInt32();
743 affect.SpellClassMask[2] = fields[4].GetUInt32();
745 // Spell.dbc have own data
746 uint32 const *ptr = 0;
747 switch (effectId)
749 case 0: ptr = &spellInfo->EffectSpellClassMaskA[0]; break;
750 case 1: ptr = &spellInfo->EffectSpellClassMaskB[0]; break;
751 case 2: ptr = &spellInfo->EffectSpellClassMaskC[0]; break;
752 default:
753 continue;
755 if(ptr[0] == affect.SpellClassMask[0] || ptr[1] == affect.SpellClassMask[1] || ptr[2] == affect.SpellClassMask[2])
757 char text[]="ABC";
758 sLog.outErrorDb("Spell %u listed in `spell_affect` have redundant (same with EffectSpellClassMask%c) data for effect index (%u) and not needed, skipped.", entry, text[effectId], effectId);
759 continue;
762 mSpellAffectMap[(entry<<8) + effectId] = affect;
764 ++count;
765 } while( result->NextRow() );
767 delete result;
769 sLog.outString();
770 sLog.outString( ">> Loaded %u custom spell affect definitions", count );
772 for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id)
774 SpellEntry const* spellInfo = sSpellStore.LookupEntry(id);
775 if (!spellInfo)
776 continue;
778 for (int effectId = 0; effectId < 3; ++effectId)
780 if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA ||
781 (spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER &&
782 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER &&
783 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER) )
784 continue;
786 uint32 const *ptr = 0;
787 switch (effectId)
789 case 0: ptr = &spellInfo->EffectSpellClassMaskA[0]; break;
790 case 1: ptr = &spellInfo->EffectSpellClassMaskB[0]; break;
791 case 2: ptr = &spellInfo->EffectSpellClassMaskC[0]; break;
792 default:
793 continue;
795 if(ptr[0] || ptr[1] || ptr[2])
796 continue;
798 if(mSpellAffectMap.find((id<<8) + effectId) != mSpellAffectMap.end())
799 continue;
801 sLog.outErrorDb("Spell %u (%s) misses spell_affect for effect %u",id,spellInfo->SpellName[sWorld.GetDefaultDbcLocale()], effectId);
806 bool SpellMgr::IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const
808 // false for spellInfo == NULL
809 if (!spellInfo || !mod)
810 return false;
812 SpellEntry const *affect_spell = sSpellStore.LookupEntry(mod->spellId);
813 // False if affect_spell == NULL or spellFamily not equal
814 if (!affect_spell || affect_spell->SpellFamilyName != spellInfo->SpellFamilyName)
815 return false;
817 // true
818 if (mod->mask & spellInfo->SpellFamilyFlags ||
819 mod->mask2 & spellInfo->SpellFamilyFlags2)
820 return true;
822 return false;
825 void SpellMgr::LoadSpellProcEvents()
827 mSpellProcEventMap.clear(); // need for reload case
829 uint32 count = 0;
831 // 0 1 2 3 4 5 6 7 8 9 10
832 QueryResult *result = WorldDatabase.Query("SELECT entry, SchoolMask, SpellFamilyName, SpellFamilyMask0, SpellFamilyMask1, SpellFamilyMask2, procFlags, procEx, ppmRate, CustomChance, Cooldown FROM spell_proc_event");
833 if( !result )
835 barGoLink bar( 1 );
836 bar.step();
837 sLog.outString();
838 sLog.outString( ">> Loaded %u spell proc event conditions", count );
839 return;
842 barGoLink bar( result->GetRowCount() );
843 uint32 customProc = 0;
846 Field *fields = result->Fetch();
848 bar.step();
850 uint32 entry = fields[0].GetUInt32();
852 const SpellEntry *spell = sSpellStore.LookupEntry(entry);
853 if (!spell)
855 sLog.outErrorDb("Spell %u listed in `spell_proc_event` does not exist", entry);
856 continue;
859 SpellProcEventEntry spe;
861 spe.schoolMask = fields[1].GetUInt32();
862 spe.spellFamilyName = fields[2].GetUInt32();
863 spe.spellFamilyMask = (uint64)fields[3].GetUInt32()|((uint64)fields[4].GetUInt32()<<32);
864 spe.spellFamilyMask2= fields[5].GetUInt32();
865 spe.procFlags = fields[6].GetUInt32();
866 spe.procEx = fields[7].GetUInt32();
867 spe.ppmRate = fields[8].GetFloat();
868 spe.customChance = fields[9].GetFloat();
869 spe.cooldown = fields[10].GetUInt32();
871 mSpellProcEventMap[entry] = spe;
873 if (spell->procFlags==0)
875 if (spe.procFlags == 0)
877 sLog.outErrorDb("Spell %u listed in `spell_proc_event` probally not triggered spell", entry);
878 continue;
880 customProc++;
882 ++count;
883 } while( result->NextRow() );
885 delete result;
887 sLog.outString();
888 if (customProc)
889 sLog.outString( ">> Loaded %u extra spell proc event conditions +%u custom", count, customProc );
890 else
891 sLog.outString( ">> Loaded %u extra spell proc event conditions", count );
894 void SpellMgr::LoadSpellBonusess()
896 mSpellBonusMap.clear(); // need for reload case
897 uint32 count = 0;
898 // 0 1 2 3
899 QueryResult *result = WorldDatabase.Query("SELECT entry, direct_bonus, dot_bonus, ap_bonus FROM spell_bonus_data");
900 if( !result )
902 barGoLink bar( 1 );
903 bar.step();
904 sLog.outString();
905 sLog.outString( ">> Loaded %u spell bonus data", count);
906 return;
909 barGoLink bar( result->GetRowCount() );
912 Field *fields = result->Fetch();
913 bar.step();
914 uint32 entry = fields[0].GetUInt32();
916 const SpellEntry *spell = sSpellStore.LookupEntry(entry);
917 if (!spell)
919 sLog.outErrorDb("Spell %u listed in `spell_bonus_data` does not exist", entry);
920 continue;
923 SpellBonusEntry sbe;
925 sbe.direct_damage = fields[1].GetFloat();
926 sbe.dot_damage = fields[2].GetFloat();
927 sbe.ap_bonus = fields[3].GetFloat();
929 mSpellBonusMap[entry] = sbe;
930 } while( result->NextRow() );
932 delete result;
934 sLog.outString();
935 sLog.outString( ">> Loaded %u extra spell bonus data", count);
938 bool SpellMgr::IsSpellProcEventCanTriggeredBy(SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active)
940 // No extra req need
941 uint32 procEvent_procEx = PROC_EX_NONE;
943 // check prockFlags for condition
944 if((procFlags & EventProcFlag) == 0)
945 return false;
947 // Always trigger for this
948 if (EventProcFlag & (PROC_FLAG_KILLED | PROC_FLAG_KILL | PROC_FLAG_ON_TRAP_ACTIVATION))
949 return true;
951 if (spellProcEvent) // Exist event data
953 // Store extra req
954 procEvent_procEx = spellProcEvent->procEx;
956 // For melee triggers
957 if (procSpell == NULL)
959 // Check (if set) for school (melee attack have Normal school)
960 if(spellProcEvent->schoolMask && (spellProcEvent->schoolMask & SPELL_SCHOOL_MASK_NORMAL) == 0)
961 return false;
963 else // For spells need check school/spell family/family mask
965 // Check (if set) for school
966 if(spellProcEvent->schoolMask && (spellProcEvent->schoolMask & procSpell->SchoolMask) == 0)
967 return false;
969 // Check (if set) for spellFamilyName
970 if(spellProcEvent->spellFamilyName && (spellProcEvent->spellFamilyName != procSpell->SpellFamilyName))
971 return false;
973 // spellFamilyName is Ok need check for spellFamilyMask if present
974 if(spellProcEvent->spellFamilyMask || spellProcEvent->spellFamilyMask2)
976 if ((spellProcEvent->spellFamilyMask & procSpell->SpellFamilyFlags ) == 0 &&
977 (spellProcEvent->spellFamilyMask2 & procSpell->SpellFamilyFlags2) == 0)
978 return false;
979 active = true; // Spell added manualy -> so its active spell
983 // Check for extra req (if none) and hit/crit
984 if (procEvent_procEx == PROC_EX_NONE)
986 // No extra req, so can trigger only for active (damage/healing present) and hit/crit
987 if((procExtra & (PROC_EX_NORMAL_HIT|PROC_EX_CRITICAL_HIT)) && active)
988 return true;
990 else // Passive spells hits here only if resist/reflect/immune/evade
992 // Exist req for PROC_EX_EX_TRIGGER_ALWAYS
993 if (procEvent_procEx & PROC_EX_EX_TRIGGER_ALWAYS)
994 return true;
995 // Passive spells can`t trigger if need hit
996 if ((procEvent_procEx & PROC_EX_NORMAL_HIT) && !active)
997 return false;
998 // Check Extra Requirement like (hit/crit/miss/resist/parry/dodge/block/immune/reflect/absorb and other)
999 if (procEvent_procEx & procExtra)
1000 return true;
1002 return false;
1005 void SpellMgr::LoadSpellElixirs()
1007 mSpellElixirs.clear(); // need for reload case
1009 uint32 count = 0;
1011 // 0 1
1012 QueryResult *result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir");
1013 if( !result )
1016 barGoLink bar( 1 );
1018 bar.step();
1020 sLog.outString();
1021 sLog.outString( ">> Loaded %u spell elixir definitions", count );
1022 return;
1025 barGoLink bar( result->GetRowCount() );
1029 Field *fields = result->Fetch();
1031 bar.step();
1033 uint16 entry = fields[0].GetUInt16();
1034 uint8 mask = fields[1].GetUInt8();
1036 SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry);
1038 if (!spellInfo)
1040 sLog.outErrorDb("Spell %u listed in `spell_elixir` does not exist", entry);
1041 continue;
1044 mSpellElixirs[entry] = mask;
1046 ++count;
1047 } while( result->NextRow() );
1049 delete result;
1051 sLog.outString();
1052 sLog.outString( ">> Loaded %u spell elixir definitions", count );
1055 void SpellMgr::LoadSpellThreats()
1057 sSpellThreatStore.Free(); // for reload
1059 sSpellThreatStore.Load();
1061 sLog.outString( ">> Loaded %u aggro generating spells", sSpellThreatStore.RecordCount );
1062 sLog.outString();
1065 bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const
1067 SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
1068 if(!spellInfo_1 || !spellInfo_2) return false;
1069 if(spellInfo_1->Id == spellId_2) return false;
1071 return GetFirstSpellInChain(spellInfo_1->Id)==GetFirstSpellInChain(spellId_2);
1074 bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo)
1076 if(IsPassiveSpell(spellInfo->Id)) // ranked passive spell
1077 return false;
1078 if(spellInfo->powerType != POWER_MANA && spellInfo->powerType != POWER_HEALTH)
1079 return false;
1080 if(IsProfessionOrRidingSpell(spellInfo->Id))
1081 return false;
1083 if(spellmgr.IsSkillBonusSpell(spellInfo->Id))
1084 return false;
1086 // All stance spells. if any better way, change it.
1087 for (int i = 0; i < 3; ++i)
1089 switch(spellInfo->SpellFamilyName)
1091 case SPELLFAMILY_PALADIN:
1092 // Paladin aura Spell
1093 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AREA_AURA_RAID)
1094 return false;
1095 break;
1096 case SPELLFAMILY_DRUID:
1097 // Druid form Spell
1098 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA &&
1099 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT)
1100 return false;
1101 break;
1102 case SPELLFAMILY_ROGUE:
1103 // Rogue Stealth
1104 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA &&
1105 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT)
1106 return false;
1109 return true;
1112 bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const
1114 SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1);
1115 SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
1117 if(!spellInfo_1 || !spellInfo_2)
1118 return false;
1120 if(spellInfo_1->Id == spellId_2)
1121 return false;
1123 //I think we don't check this correctly because i need a exception for spell:
1124 //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.
1125 if(spellInfo_2->SpellFamilyFlags == 2048)
1126 return false;
1128 // Resurrection sickness
1129 if((spellInfo_1->Id == SPELL_ID_PASSIVE_RESURRECTION_SICKNESS) != (spellInfo_2->Id==SPELL_ID_PASSIVE_RESURRECTION_SICKNESS))
1130 return false;
1132 // Allow stack passive and not passive spells
1133 if ((spellInfo_1->Attributes & SPELL_ATTR_PASSIVE)!=(spellInfo_2->Attributes & SPELL_ATTR_PASSIVE))
1134 return false;
1136 // Specific spell family spells
1137 switch(spellInfo_1->SpellFamilyName)
1139 case SPELLFAMILY_GENERIC:
1140 switch(spellInfo_2->SpellFamilyName)
1142 case SPELLFAMILY_GENERIC: // same family case
1144 // Thunderfury
1145 if ((spellInfo_1->Id == 21992 && spellInfo_2->Id == 27648) ||
1146 (spellInfo_2->Id == 21992 && spellInfo_1->Id == 27648))
1147 return false;
1149 // Lightning Speed (Mongoose) and Fury of the Crashing Waves (Tsunami Talisman)
1150 if ((spellInfo_1->Id == 28093 && spellInfo_2->Id == 42084) ||
1151 (spellInfo_2->Id == 28093 && spellInfo_1->Id == 42084))
1152 return false;
1154 // Soulstone Resurrection and Twisting Nether (resurrector)
1155 if( spellInfo_1->SpellIconID == 92 && spellInfo_2->SpellIconID == 92 && (
1156 spellInfo_1->SpellVisual[0] == 99 && spellInfo_2->SpellVisual[0] == 0 ||
1157 spellInfo_2->SpellVisual[0] == 99 && spellInfo_1->SpellVisual[0] == 0 ) )
1158 return false;
1160 // Heart of the Wild and (Primal Instinct (Idol of Terror) triggering spell or Agility)
1161 if( spellInfo_1->SpellIconID == 240 && spellInfo_2->SpellIconID == 240 && (
1162 spellInfo_1->SpellVisual[0] == 0 && spellInfo_2->SpellVisual[0] == 78 ||
1163 spellInfo_2->SpellVisual[0] == 0 && spellInfo_1->SpellVisual[0] == 78 ) )
1164 return false;
1166 // Personalized Weather (thunder effect should overwrite rainy aura)
1167 if(spellInfo_1->SpellIconID == 2606 && spellInfo_2->SpellIconID == 2606)
1168 return false;
1170 // Brood Affliction: Bronze
1171 if( (spellInfo_1->Id == 23170 && spellInfo_2->Id == 23171) ||
1172 (spellInfo_2->Id == 23170 && spellInfo_1->Id == 23171) )
1173 return false;
1175 // See Chapel Invisibility and See Noth Invisibility
1176 if( (spellInfo_1->Id == 52950 && spellInfo_2->Id == 52707) ||
1177 (spellInfo_2->Id == 52950 && spellInfo_1->Id == 52707) )
1178 return false;
1180 // Regular and Night Elf Ghost
1181 if( (spellInfo_1->Id == 8326 && spellInfo_2->Id == 20584) ||
1182 (spellInfo_2->Id == 8326 && spellInfo_1->Id == 20584) )
1183 return false;
1185 break;
1187 case SPELLFAMILY_WARRIOR:
1189 // Scroll of Protection and Defensive Stance (multi-family check)
1190 if( spellInfo_1->SpellIconID == 276 && spellInfo_1->SpellVisual[0] == 196 && spellInfo_2->Id == 71)
1191 return false;
1193 // Improved Hamstring -> Hamstring (multi-family check)
1194 if( (spellInfo_2->SpellFamilyFlags & UI64LIT(0x2)) && spellInfo_1->Id == 23694 )
1195 return false;
1197 break;
1199 case SPELLFAMILY_DRUID:
1201 // Scroll of Stamina and Leader of the Pack (multi-family check)
1202 if( spellInfo_1->SpellIconID == 312 && spellInfo_1->SpellVisual[0] == 216 && spellInfo_2->Id == 24932 )
1203 return false;
1205 // Dragonmaw Illusion (multi-family check)
1206 if (spellId_1 == 40216 && spellId_2 == 42016 )
1207 return false;
1209 break;
1211 case SPELLFAMILY_ROGUE:
1213 // Garrote-Silence -> Garrote (multi-family check)
1214 if( spellInfo_1->SpellIconID == 498 && spellInfo_1->SpellVisual[0] == 0 && spellInfo_2->SpellIconID == 498 )
1215 return false;
1217 break;
1219 case SPELLFAMILY_HUNTER:
1221 // Concussive Shot and Imp. Concussive Shot (multi-family check)
1222 if( spellInfo_1->Id == 19410 && spellInfo_2->Id == 5116 )
1223 return false;
1225 // Improved Wing Clip -> Wing Clip (multi-family check)
1226 if( (spellInfo_2->SpellFamilyFlags & UI64LIT(0x40)) && spellInfo_1->Id == 19229 )
1227 return false;
1228 break;
1230 case SPELLFAMILY_PALADIN:
1232 // Unstable Currents and other -> *Sanctity Aura (multi-family check)
1233 if( spellInfo_2->SpellIconID==502 && spellInfo_1->SpellIconID==502 && spellInfo_1->SpellVisual[0]==969 )
1234 return false;
1236 // *Band of Eternal Champion and Seal of Command(multi-family check)
1237 if( spellId_1 == 35081 && spellInfo_2->SpellIconID==561 && spellInfo_2->SpellVisual[0]==7992)
1238 return false;
1240 break;
1243 // Dragonmaw Illusion, Blood Elf Illusion, Human Illusion, Illidari Agent Illusion, Scarlet Crusade Disguise
1244 if(spellInfo_1->SpellIconID == 1691 && spellInfo_2->SpellIconID == 1691)
1245 return false;
1246 break;
1247 case SPELLFAMILY_MAGE:
1248 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_MAGE )
1250 // Blizzard & Chilled (and some other stacked with blizzard spells
1251 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x80)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x100000)) ||
1252 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x80)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x100000)) )
1253 return false;
1255 // Blink & Improved Blink
1256 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x0000000000010000)) && (spellInfo_2->SpellVisual[0] == 72 && spellInfo_2->SpellIconID == 1499) ||
1257 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x0000000000010000)) && (spellInfo_1->SpellVisual[0] == 72 && spellInfo_1->SpellIconID == 1499) )
1258 return false;
1260 // Detect Invisibility and Mana Shield (multi-family check)
1261 if( spellInfo_2->Id == 132 && spellInfo_1->SpellIconID == 209 && spellInfo_1->SpellVisual[0] == 968 )
1262 return false;
1264 // Combustion and Fire Protection Aura (multi-family check)
1265 if( spellInfo_1->Id == 11129 && spellInfo_2->SpellIconID == 33 && spellInfo_2->SpellVisual[0] == 321 )
1266 return false;
1268 break;
1269 case SPELLFAMILY_WARLOCK:
1270 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_WARLOCK )
1272 // Siphon Life and Drain Life
1273 if( spellInfo_1->SpellIconID == 152 && spellInfo_2->SpellIconID == 546 ||
1274 spellInfo_2->SpellIconID == 152 && spellInfo_1->SpellIconID == 546 )
1275 return false;
1277 //Corruption & Seed of corruption
1278 if( spellInfo_1->SpellIconID == 313 && spellInfo_2->SpellIconID == 1932 ||
1279 spellInfo_2->SpellIconID == 313 && spellInfo_1->SpellIconID == 1932 )
1280 if(spellInfo_1->SpellVisual[0] != 0 && spellInfo_2->SpellVisual[0] != 0)
1281 return true; // can't be stacked
1283 // Corruption and Unstable Affliction
1284 if( spellInfo_1->SpellIconID == 313 && spellInfo_2->SpellIconID == 2039 ||
1285 spellInfo_2->SpellIconID == 313 && spellInfo_1->SpellIconID == 2039 )
1286 return false;
1288 // (Corruption or Unstable Affliction) and (Curse of Agony or Curse of Doom)
1289 if( (spellInfo_1->SpellIconID == 313 || spellInfo_1->SpellIconID == 2039) && (spellInfo_2->SpellIconID == 544 || spellInfo_2->SpellIconID == 91) ||
1290 (spellInfo_2->SpellIconID == 313 || spellInfo_2->SpellIconID == 2039) && (spellInfo_1->SpellIconID == 544 || spellInfo_1->SpellIconID == 91) )
1291 return false;
1293 // Detect Invisibility and Mana Shield (multi-family check)
1294 if( spellInfo_1->Id == 132 && spellInfo_2->SpellIconID == 209 && spellInfo_2->SpellVisual[0] == 968 )
1295 return false;
1296 break;
1297 case SPELLFAMILY_WARRIOR:
1298 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_WARRIOR )
1300 // Rend and Deep Wound
1301 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x20)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x1000000000)) ||
1302 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x20)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x1000000000)) )
1303 return false;
1305 // Battle Shout and Rampage
1306 if( (spellInfo_1->SpellIconID == 456 && spellInfo_2->SpellIconID == 2006) ||
1307 (spellInfo_2->SpellIconID == 456 && spellInfo_1->SpellIconID == 2006) )
1308 return false;
1311 // Hamstring -> Improved Hamstring (multi-family check)
1312 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x2)) && spellInfo_2->Id == 23694 )
1313 return false;
1315 // Defensive Stance and Scroll of Protection (multi-family check)
1316 if( spellInfo_1->Id == 71 && spellInfo_2->SpellIconID == 276 && spellInfo_2->SpellVisual[0] == 196 )
1317 return false;
1319 // Bloodlust and Bloodthirst (multi-family check)
1320 if( spellInfo_2->Id == 2825 && spellInfo_1->SpellIconID == 38 && spellInfo_1->SpellVisual[0] == 0 )
1321 return false;
1323 break;
1324 case SPELLFAMILY_PRIEST:
1325 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_PRIEST )
1327 //Devouring Plague and Shadow Vulnerability
1328 if ((spellInfo_1->SpellFamilyFlags & UI64LIT(0x2000000)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x800000000)) ||
1329 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x2000000)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x800000000)))
1330 return false;
1332 //StarShards and Shadow Word: Pain
1333 if ((spellInfo_1->SpellFamilyFlags & UI64LIT(0x200000)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x8000)) ||
1334 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x200000)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x8000)))
1335 return false;
1336 // Dispersion
1337 if ((spellInfo_1->Id == 47585 && spellInfo_2->Id == 60069) ||
1338 (spellInfo_2->Id == 47585 && spellInfo_1->Id == 60069))
1339 return false;
1341 break;
1342 case SPELLFAMILY_DRUID:
1343 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_DRUID )
1345 //Omen of Clarity and Blood Frenzy
1346 if( (spellInfo_1->SpellFamilyFlags == UI64LIT(0x0) && spellInfo_1->SpellIconID == 108) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x20000000000000)) ||
1347 (spellInfo_2->SpellFamilyFlags == UI64LIT(0x0) && spellInfo_2->SpellIconID == 108) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x20000000000000)) )
1348 return false;
1350 // Tree of Life (Shapeshift) and 34123 Tree of Life (Passive)
1351 if ((spellId_1 == 33891 && spellId_2 == 34123) ||
1352 (spellId_2 == 33891 && spellId_1 == 34123))
1353 return false;
1355 // Wrath of Elune and Nature's Grace
1356 if( spellInfo_1->Id == 16886 && spellInfo_2->Id == 46833 || spellInfo_2->Id == 16886 && spellInfo_1->Id == 46833 )
1357 return false;
1359 // Bear Rage (Feral T4 (2)) and Omen of Clarity
1360 if( spellInfo_1->Id == 16864 && spellInfo_2->Id == 37306 || spellInfo_2->Id == 16864 && spellInfo_1->Id == 37306 )
1361 return false;
1363 // Cat Energy (Feral T4 (2)) and Omen of Clarity
1364 if( spellInfo_1->Id == 16864 && spellInfo_2->Id == 37311 || spellInfo_2->Id == 16864 && spellInfo_1->Id == 37311 )
1365 return false;
1367 // Survival Instincts and Survival Instincts
1368 if( spellInfo_1->Id == 61336 && spellInfo_2->Id == 50322 || spellInfo_2->Id == 61336 && spellInfo_1->Id == 50322 )
1369 return false;
1372 // Leader of the Pack and Scroll of Stamina (multi-family check)
1373 if( spellInfo_1->Id == 24932 && spellInfo_2->SpellIconID == 312 && spellInfo_2->SpellVisual[0] == 216 )
1374 return false;
1376 // Dragonmaw Illusion (multi-family check)
1377 if (spellId_1 == 42016 && spellId_2 == 40216 )
1378 return false;
1380 break;
1381 case SPELLFAMILY_ROGUE:
1382 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_ROGUE )
1384 // Master of Subtlety
1385 if (spellId_1 == 31665 && spellId_2 == 31666 || spellId_1 == 31666 && spellId_2 == 31665 )
1386 return false;
1389 //Overkill
1390 if( spellInfo_1->SpellIconID == 2285 && spellInfo_2->SpellIconID == 2285 )
1391 return false;
1393 // Garrote -> Garrote-Silence (multi-family check)
1394 if( spellInfo_1->SpellIconID == 498 && spellInfo_2->SpellIconID == 498 && spellInfo_2->SpellVisual[0] == 0 )
1395 return false;
1396 break;
1397 case SPELLFAMILY_HUNTER:
1398 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_HUNTER )
1400 // Rapid Fire & Quick Shots
1401 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x20)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x20000000000)) ||
1402 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x20)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x20000000000)) )
1403 return false;
1405 // Serpent Sting & (Immolation/Explosive Trap Effect)
1406 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x4)) && (spellInfo_2->SpellFamilyFlags & UI64LIT(0x00000004000)) ||
1407 (spellInfo_2->SpellFamilyFlags & UI64LIT(0x4)) && (spellInfo_1->SpellFamilyFlags & UI64LIT(0x00000004000)) )
1408 return false;
1410 // Bestial Wrath
1411 if( spellInfo_1->SpellIconID == 1680 && spellInfo_2->SpellIconID == 1680 )
1412 return false;
1415 // Wing Clip -> Improved Wing Clip (multi-family check)
1416 if( (spellInfo_1->SpellFamilyFlags & UI64LIT(0x40)) && spellInfo_2->Id == 19229 )
1417 return false;
1419 // Concussive Shot and Imp. Concussive Shot (multi-family check)
1420 if( spellInfo_2->Id == 19410 && spellInfo_1->Id == 5116 )
1421 return false;
1422 break;
1423 case SPELLFAMILY_PALADIN:
1424 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_PALADIN )
1426 // Paladin Seals
1427 if( IsSealSpell(spellInfo_1) && IsSealSpell(spellInfo_2) )
1428 return true;
1430 // Combustion and Fire Protection Aura (multi-family check)
1431 if( spellInfo_2->Id == 11129 && spellInfo_1->SpellIconID == 33 && spellInfo_1->SpellVisual[0] == 321 )
1432 return false;
1434 // *Sanctity Aura -> Unstable Currents and other (multi-family check)
1435 if( spellInfo_1->SpellIconID==502 && spellInfo_2->SpellFamilyName == SPELLFAMILY_GENERIC && spellInfo_2->SpellIconID==502 && spellInfo_2->SpellVisual[0]==969 )
1436 return false;
1438 // *Seal of Command and Band of Eternal Champion (multi-family check)
1439 if( spellInfo_1->SpellIconID==561 && spellInfo_1->SpellVisual[0]==7992 && spellId_2 == 35081)
1440 return false;
1441 break;
1442 case SPELLFAMILY_SHAMAN:
1443 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_SHAMAN )
1445 // shaman shields
1446 if( IsElementalShield(spellInfo_1) && IsElementalShield(spellInfo_2) )
1447 return true;
1449 // Windfury weapon
1450 if( spellInfo_1->SpellIconID==220 && spellInfo_2->SpellIconID==220 &&
1451 spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags )
1452 return false;
1454 // Bloodlust and Bloodthirst (multi-family check)
1455 if( spellInfo_1->Id == 2825 && spellInfo_2->SpellIconID == 38 && spellInfo_2->SpellVisual[0] == 0 )
1456 return false;
1457 break;
1458 default:
1459 break;
1462 // more generic checks
1463 if (spellInfo_1->SpellIconID == spellInfo_2->SpellIconID &&
1464 spellInfo_1->SpellIconID != 0 && spellInfo_2->SpellIconID != 0)
1466 bool isModifier = false;
1467 for (int i = 0; i < 3; ++i)
1469 if (spellInfo_1->EffectApplyAuraName[i] == SPELL_AURA_ADD_FLAT_MODIFIER ||
1470 spellInfo_1->EffectApplyAuraName[i] == SPELL_AURA_ADD_PCT_MODIFIER ||
1471 spellInfo_2->EffectApplyAuraName[i] == SPELL_AURA_ADD_FLAT_MODIFIER ||
1472 spellInfo_2->EffectApplyAuraName[i] == SPELL_AURA_ADD_PCT_MODIFIER )
1473 isModifier = true;
1476 if (!isModifier)
1477 return true;
1480 if (IsRankSpellDueToSpell(spellInfo_1, spellId_2))
1481 return true;
1483 if (spellInfo_1->SpellFamilyName == 0 || spellInfo_2->SpellFamilyName == 0)
1484 return false;
1486 if (spellInfo_1->SpellFamilyName != spellInfo_2->SpellFamilyName)
1487 return false;
1489 for (int i = 0; i < 3; ++i)
1490 if (spellInfo_1->Effect[i] != spellInfo_2->Effect[i] ||
1491 spellInfo_1->EffectItemType[i] != spellInfo_2->EffectItemType[i] ||
1492 spellInfo_1->EffectMiscValue[i] != spellInfo_2->EffectMiscValue[i] ||
1493 spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i])
1494 return false;
1496 return true;
1499 bool SpellMgr::IsProfessionOrRidingSpell(uint32 spellId)
1501 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1502 if(!spellInfo)
1503 return false;
1505 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1506 return false;
1508 uint32 skill = spellInfo->EffectMiscValue[1];
1510 return IsProfessionOrRidingSkill(skill);
1513 bool SpellMgr::IsProfessionSpell(uint32 spellId)
1515 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1516 if(!spellInfo)
1517 return false;
1519 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1520 return false;
1522 uint32 skill = spellInfo->EffectMiscValue[1];
1524 return IsProfessionSkill(skill);
1527 bool SpellMgr::IsPrimaryProfessionSpell(uint32 spellId)
1529 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1530 if(!spellInfo)
1531 return false;
1533 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1534 return false;
1536 uint32 skill = spellInfo->EffectMiscValue[1];
1538 return IsPrimaryProfessionSkill(skill);
1541 bool SpellMgr::IsPrimaryProfessionFirstRankSpell(uint32 spellId) const
1543 return IsPrimaryProfessionSpell(spellId) && GetSpellRank(spellId)==1;
1546 bool SpellMgr::IsSkillBonusSpell(uint32 spellId) const
1548 SkillLineAbilityMap::const_iterator lower = GetBeginSkillLineAbilityMap(spellId);
1549 SkillLineAbilityMap::const_iterator upper = GetEndSkillLineAbilityMap(spellId);
1551 for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx)
1553 SkillLineAbilityEntry const *pAbility = _spell_idx->second;
1554 if (!pAbility || pAbility->learnOnGetSkill != ABILITY_LEARNED_ON_GET_PROFESSION_SKILL)
1555 continue;
1557 if(pAbility->req_skill_value > 0)
1558 return true;
1561 return false;
1564 SpellEntry const* SpellMgr::SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const
1566 // ignore passive spells
1567 if(IsPassiveSpell(spellInfo->Id))
1568 return spellInfo;
1570 bool needRankSelection = false;
1571 for(int i=0;i<3;++i)
1573 if( IsPositiveEffect(spellInfo->Id, i) && (
1574 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA ||
1575 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
1576 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_RAID
1579 needRankSelection = true;
1580 break;
1584 // not required
1585 if(!needRankSelection)
1586 return spellInfo;
1588 for(uint32 nextSpellId = spellInfo->Id; nextSpellId != 0; nextSpellId = GetPrevSpellInChain(nextSpellId))
1590 SpellEntry const *nextSpellInfo = sSpellStore.LookupEntry(nextSpellId);
1591 if(!nextSpellInfo)
1592 break;
1594 // if found appropriate level
1595 if(playerLevel + 10 >= nextSpellInfo->spellLevel)
1596 return nextSpellInfo;
1598 // one rank less then
1601 // not found
1602 return NULL;
1605 void SpellMgr::LoadSpellChains()
1607 mSpellChains.clear(); // need for reload case
1608 mSpellChainsNext.clear(); // need for reload case
1610 QueryResult *result = WorldDatabase.Query("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain");
1611 if(result == NULL)
1613 barGoLink bar( 1 );
1614 bar.step();
1616 sLog.outString();
1617 sLog.outString( ">> Loaded 0 spell chain records" );
1618 sLog.outErrorDb("`spell_chains` table is empty!");
1619 return;
1622 uint32 count = 0;
1624 barGoLink bar( result->GetRowCount() );
1627 bar.step();
1628 Field *fields = result->Fetch();
1630 uint32 spell_id = fields[0].GetUInt32();
1632 SpellChainNode node;
1633 node.prev = fields[1].GetUInt32();
1634 node.first = fields[2].GetUInt32();
1635 node.rank = fields[3].GetUInt8();
1636 node.req = fields[4].GetUInt32();
1638 if(!sSpellStore.LookupEntry(spell_id))
1640 sLog.outErrorDb("Spell %u listed in `spell_chain` does not exist",spell_id);
1641 continue;
1644 if(node.prev!=0 && !sSpellStore.LookupEntry(node.prev))
1646 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existed previous rank spell.",
1647 spell_id,node.prev,node.first,node.rank,node.req);
1648 continue;
1651 if(!sSpellStore.LookupEntry(node.first))
1653 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing first rank spell.",
1654 spell_id,node.prev,node.first,node.rank,node.req);
1655 continue;
1658 // check basic spell chain data integrity (note: rank can be equal 0 or 1 for first/single spell)
1659 if( (spell_id == node.first) != (node.rank <= 1) ||
1660 (spell_id == node.first) != (node.prev == 0) ||
1661 (node.rank <= 1) != (node.prev == 0) )
1663 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not compatible chain data.",
1664 spell_id,node.prev,node.first,node.rank,node.req);
1665 continue;
1668 if(node.req!=0 && !sSpellStore.LookupEntry(node.req))
1670 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing required spell.",
1671 spell_id,node.prev,node.first,node.rank,node.req);
1672 continue;
1675 // talents not required data in spell chain for work, but must be checked if present for intergrity
1676 if(TalentSpellPos const* pos = GetTalentSpellPos(spell_id))
1678 if(node.rank!=pos->rank+1)
1680 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong rank.",
1681 spell_id,node.prev,node.first,node.rank,node.req);
1682 continue;
1685 if(TalentEntry const* talentEntry = sTalentStore.LookupEntry(pos->talent_id))
1687 if(node.first!=talentEntry->RankID[0])
1689 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong first rank spell.",
1690 spell_id,node.prev,node.first,node.rank,node.req);
1691 continue;
1694 if(node.rank > 1 && node.prev != talentEntry->RankID[node.rank-1-1])
1696 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong prev rank spell.",
1697 spell_id,node.prev,node.first,node.rank,node.req);
1698 continue;
1701 /*if(node.req!=talentEntry->DependsOnSpell)
1703 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong required spell.",
1704 spell_id,node.prev,node.first,node.rank,node.req);
1705 continue;
1710 mSpellChains[spell_id] = node;
1712 if(node.prev)
1713 mSpellChainsNext.insert(SpellChainMapNext::value_type(node.prev,spell_id));
1715 if(node.req)
1716 mSpellChainsNext.insert(SpellChainMapNext::value_type(node.req,spell_id));
1718 ++count;
1719 } while( result->NextRow() );
1721 delete result;
1723 // additional integrity checks
1724 for(SpellChainMap::const_iterator i = mSpellChains.begin(); i != mSpellChains.end(); ++i)
1726 if(i->second.prev)
1728 SpellChainMap::const_iterator i_prev = mSpellChains.find(i->second.prev);
1729 if(i_prev == mSpellChains.end())
1731 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found previous rank spell in table.",
1732 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req);
1734 else if( i_prev->second.first != i->second.first )
1736 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).",
1737 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1738 i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req);
1740 else if( i_prev->second.rank+1 != i->second.rank )
1742 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).",
1743 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1744 i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req);
1748 if(i->second.req)
1750 SpellChainMap::const_iterator i_req = mSpellChains.find(i->second.req);
1751 if(i_req == mSpellChains.end())
1753 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found required rank spell in table.",
1754 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req);
1756 else if( i_req->second.first == i->second.first )
1758 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).",
1759 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1760 i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req);
1762 else if( i_req->second.req )
1764 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).",
1765 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1766 i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req);
1771 sLog.outString();
1772 sLog.outString( ">> Loaded %u spell chain records", count );
1775 void SpellMgr::LoadSpellLearnSkills()
1777 mSpellLearnSkills.clear(); // need for reload case
1779 // search auto-learned skills and add its to map also for use in unlearn spells/talents
1780 uint32 dbc_count = 0;
1781 barGoLink bar( sSpellStore.GetNumRows() );
1782 for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
1784 bar.step();
1785 SpellEntry const* entry = sSpellStore.LookupEntry(spell);
1787 if(!entry)
1788 continue;
1790 for(int i = 0; i < 3; ++i)
1792 if(entry->Effect[i]==SPELL_EFFECT_SKILL)
1794 SpellLearnSkillNode dbc_node;
1795 dbc_node.skill = entry->EffectMiscValue[i];
1796 if ( dbc_node.skill != SKILL_RIDING )
1797 dbc_node.value = 1;
1798 else
1799 dbc_node.value = entry->CalculateSimpleValue(i)*75;
1800 dbc_node.maxvalue = entry->CalculateSimpleValue(i)*75;
1802 mSpellLearnSkills[spell] = dbc_node;
1803 ++dbc_count;
1804 break;
1809 sLog.outString();
1810 sLog.outString( ">> Loaded %u Spell Learn Skills from DBC", dbc_count );
1813 void SpellMgr::LoadSpellLearnSpells()
1815 mSpellLearnSpells.clear(); // need for reload case
1817 // 0 1 2
1818 QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell");
1819 if(!result)
1821 barGoLink bar( 1 );
1822 bar.step();
1824 sLog.outString();
1825 sLog.outString( ">> Loaded 0 spell learn spells" );
1826 sLog.outErrorDb("`spell_learn_spell` table is empty!");
1827 return;
1830 uint32 count = 0;
1832 barGoLink bar( result->GetRowCount() );
1835 bar.step();
1836 Field *fields = result->Fetch();
1838 uint32 spell_id = fields[0].GetUInt32();
1840 SpellLearnSpellNode node;
1841 node.spell = fields[1].GetUInt32();
1842 node.active = fields[2].GetBool();
1843 node.autoLearned= false;
1845 if(!sSpellStore.LookupEntry(spell_id))
1847 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id);
1848 continue;
1851 if(!sSpellStore.LookupEntry(node.spell))
1853 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",node.spell);
1854 continue;
1857 mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell_id,node));
1859 ++count;
1860 } while( result->NextRow() );
1862 delete result;
1864 // search auto-learned spells and add its to map also for use in unlearn spells/talents
1865 uint32 dbc_count = 0;
1866 for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
1868 SpellEntry const* entry = sSpellStore.LookupEntry(spell);
1870 if(!entry)
1871 continue;
1873 for(int i = 0; i < 3; ++i)
1875 if(entry->Effect[i]==SPELL_EFFECT_LEARN_SPELL)
1877 SpellLearnSpellNode dbc_node;
1878 dbc_node.spell = entry->EffectTriggerSpell[i];
1879 dbc_node.active = true; // all dbc based learned spells is active (show in spell book or hide by client itself)
1881 // ignore learning not existed spells (broken/outdated/or generic learnig spell 483
1882 if(!sSpellStore.LookupEntry(dbc_node.spell))
1883 continue;
1885 // talent or passive spells or skill-step spells auto-casted and not need dependent learning,
1886 // pet teaching spells don't must be dependent learning (casted)
1887 // other required explicit dependent learning
1888 dbc_node.autoLearned = entry->EffectImplicitTargetA[i]==TARGET_PET || GetTalentSpellCost(spell) > 0 || IsPassiveSpell(spell) || IsSpellHaveEffect(entry,SPELL_EFFECT_SKILL_STEP);
1890 SpellLearnSpellMap::const_iterator db_node_begin = GetBeginSpellLearnSpell(spell);
1891 SpellLearnSpellMap::const_iterator db_node_end = GetEndSpellLearnSpell(spell);
1893 bool found = false;
1894 for(SpellLearnSpellMap::const_iterator itr = db_node_begin; itr != db_node_end; ++itr)
1896 if(itr->second.spell == dbc_node.spell)
1898 sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.",
1899 spell,dbc_node.spell);
1900 found = true;
1901 break;
1905 if(!found) // add new spell-spell pair if not found
1907 mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node));
1908 ++dbc_count;
1914 sLog.outString();
1915 sLog.outString( ">> Loaded %u spell learn spells + %u found in DBC", count, dbc_count );
1918 void SpellMgr::LoadSpellScriptTarget()
1920 mSpellScriptTarget.clear(); // need for reload case
1922 uint32 count = 0;
1924 QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target");
1926 if(!result)
1928 barGoLink bar(1);
1930 bar.step();
1932 sLog.outString();
1933 sLog.outErrorDb(">> Loaded 0 SpellScriptTarget. DB table `spell_script_target` is empty.");
1934 return;
1937 barGoLink bar(result->GetRowCount());
1941 Field *fields = result->Fetch();
1942 bar.step();
1944 uint32 spellId = fields[0].GetUInt32();
1945 uint32 type = fields[1].GetUInt32();
1946 uint32 targetEntry = fields[2].GetUInt32();
1948 SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId);
1950 if(!spellProto)
1952 sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist.",spellId,targetEntry);
1953 continue;
1956 bool targetfound = false;
1957 for(int i = 0; i <3; ++i)
1959 if( spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT ||
1960 spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT ||
1961 spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT_COORDINATES ||
1962 spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT_COORDINATES )
1964 targetfound = true;
1965 break;
1968 if(!targetfound)
1970 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);
1971 continue;
1974 if( type >= MAX_SPELL_TARGET_TYPE )
1976 sLog.outErrorDb("Table `spell_script_target`: target type %u for TargetEntry %u is incorrect.",type,targetEntry);
1977 continue;
1980 switch(type)
1982 case SPELL_TARGET_TYPE_GAMEOBJECT:
1984 if( targetEntry==0 )
1985 break;
1987 if(!sGOStorage.LookupEntry<GameObjectInfo>(targetEntry))
1989 sLog.outErrorDb("Table `spell_script_target`: gameobject template entry %u does not exist.",targetEntry);
1990 continue;
1992 break;
1994 default:
1996 if( targetEntry==0 )
1998 sLog.outErrorDb("Table `spell_script_target`: target entry == 0 for not GO target type (%u).",type);
1999 continue;
2001 if(!sCreatureStorage.LookupEntry<CreatureInfo>(targetEntry))
2003 sLog.outErrorDb("Table `spell_script_target`: creature template entry %u does not exist.",targetEntry);
2004 continue;
2006 const CreatureInfo* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(targetEntry);
2008 if(spellId == 30427 && !cInfo->SkinLootId)
2010 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);
2011 continue;
2013 break;
2017 mSpellScriptTarget.insert(SpellScriptTarget::value_type(spellId,SpellTargetEntry(SpellTargetType(type),targetEntry)));
2019 ++count;
2020 } while (result->NextRow());
2022 delete result;
2024 // Check all spells
2025 /* Disabled (lot errors at this moment)
2026 for(uint32 i = 1; i < sSpellStore.nCount; ++i)
2028 SpellEntry const * spellInfo = sSpellStore.LookupEntry(i);
2029 if(!spellInfo)
2030 continue;
2032 bool found = false;
2033 for(int j=0; j<3; ++j)
2035 if( spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT || spellInfo->EffectImplicitTargetA[j] != TARGET_SELF && spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT )
2037 SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(spellInfo->Id);
2038 SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(spellInfo->Id);
2039 if(lower==upper)
2041 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);
2042 break; // effects of spell
2049 sLog.outString();
2050 sLog.outString(">> Loaded %u Spell Script Targets", count);
2053 void SpellMgr::LoadSpellPetAuras()
2055 mSpellPetAuraMap.clear(); // need for reload case
2057 uint32 count = 0;
2059 // 0 1 2
2060 QueryResult *result = WorldDatabase.Query("SELECT spell, pet, aura FROM spell_pet_auras");
2061 if( !result )
2064 barGoLink bar( 1 );
2066 bar.step();
2068 sLog.outString();
2069 sLog.outString( ">> Loaded %u spell pet auras", count );
2070 return;
2073 barGoLink bar( result->GetRowCount() );
2077 Field *fields = result->Fetch();
2079 bar.step();
2081 uint16 spell = fields[0].GetUInt16();
2082 uint16 pet = fields[1].GetUInt16();
2083 uint16 aura = fields[2].GetUInt16();
2085 SpellPetAuraMap::iterator itr = mSpellPetAuraMap.find(spell);
2086 if(itr != mSpellPetAuraMap.end())
2088 itr->second.AddAura(pet, aura);
2090 else
2092 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2093 if (!spellInfo)
2095 sLog.outErrorDb("Spell %u listed in `spell_pet_auras` does not exist", spell);
2096 continue;
2098 int i = 0;
2099 for(; i < 3; ++i)
2100 if((spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA &&
2101 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_DUMMY) ||
2102 spellInfo->Effect[i] == SPELL_EFFECT_DUMMY)
2103 break;
2105 if(i == 3)
2107 sLog.outError("Spell %u listed in `spell_pet_auras` does not have dummy aura or dummy effect", spell);
2108 continue;
2111 SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(aura);
2112 if (!spellInfo2)
2114 sLog.outErrorDb("Aura %u listed in `spell_pet_auras` does not exist", aura);
2115 continue;
2118 PetAura pa(pet, aura, spellInfo->EffectImplicitTargetA[i] == TARGET_PET, spellInfo->CalculateSimpleValue(i));
2119 mSpellPetAuraMap[spell] = pa;
2122 ++count;
2123 } while( result->NextRow() );
2125 delete result;
2127 sLog.outString();
2128 sLog.outString( ">> Loaded %u spell pet auras", count );
2131 void SpellMgr::LoadPetLevelupSpellMap()
2133 uint32 count = 0;
2134 uint32 family_count = 0;
2136 for (uint32 i = 0; i < sCreatureFamilyStore.GetNumRows(); ++i)
2138 CreatureFamilyEntry const *creatureFamily = sCreatureFamilyStore.LookupEntry(i);
2139 if(!creatureFamily) // not exist
2140 continue;
2142 for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j)
2144 SkillLineAbilityEntry const *skillLine = sSkillLineAbilityStore.LookupEntry(j);
2145 if( !skillLine )
2146 continue;
2148 if (skillLine->skillId!=creatureFamily->skillLine[0] &&
2149 (!creatureFamily->skillLine[1] || skillLine->skillId!=creatureFamily->skillLine[1]))
2150 continue;
2152 if(skillLine->learnOnGetSkill != ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL)
2153 continue;
2155 SpellEntry const *spell = sSpellStore.LookupEntry(skillLine->spellId);
2156 if(!spell) // not exist
2157 continue;
2159 PetLevelupSpellSet& spellSet = mPetLevelupSpellMap[creatureFamily->ID];
2160 if(spellSet.empty())
2161 ++family_count;
2163 spellSet.insert(PetLevelupSpellSet::value_type(spell->spellLevel,spell->Id));
2164 count++;
2168 sLog.outString();
2169 sLog.outString( ">> Loaded %u pet levelup and default spells for %u families", count, family_count );
2172 bool LoadPetDefaultSpells_helper(CreatureInfo const* cInfo, PetDefaultSpellsEntry& petDefSpells)
2174 // skip empty list;
2175 bool have_spell = false;
2176 for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
2178 if(petDefSpells.spellid[j])
2180 have_spell = true;
2181 break;
2184 if(!have_spell)
2185 return false;
2187 // remove duplicates with levelupSpells if any
2188 if(PetLevelupSpellSet const *levelupSpells = cInfo->family ? spellmgr.GetPetLevelupSpellList(cInfo->family) : NULL)
2190 for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
2192 if(!petDefSpells.spellid[j])
2193 continue;
2195 for(PetLevelupSpellSet::const_iterator itr = levelupSpells->begin(); itr != levelupSpells->end(); ++itr)
2197 if (itr->second == petDefSpells.spellid[j])
2199 petDefSpells.spellid[j] = 0;
2200 break;
2206 // skip empty list;
2207 have_spell = false;
2208 for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
2210 if(petDefSpells.spellid[j])
2212 have_spell = true;
2213 break;
2217 return have_spell;
2220 void SpellMgr::LoadPetDefaultSpells()
2222 assert(MAX_CREATURE_SPELL_DATA_SLOT==CREATURE_MAX_SPELLS);
2224 mPetDefaultSpellsMap.clear();
2226 uint32 countCreature = 0;
2227 uint32 countData = 0;
2229 for(uint32 i = 0; i < sCreatureStorage.MaxEntry; ++i )
2231 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(i);
2232 if(!cInfo)
2233 continue;
2235 if(!cInfo->PetSpellDataId)
2236 continue;
2238 // for creature with PetSpellDataId get default pet spells from dbc
2239 CreatureSpellDataEntry const* spellDataEntry = sCreatureSpellDataStore.LookupEntry(cInfo->PetSpellDataId);
2240 if(!spellDataEntry)
2241 continue;
2243 int32 petSpellsId = -(int32)cInfo->PetSpellDataId;
2244 PetDefaultSpellsEntry petDefSpells;
2245 for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
2246 petDefSpells.spellid[j] = spellDataEntry->spellId[j];
2248 if(LoadPetDefaultSpells_helper(cInfo, petDefSpells))
2250 mPetDefaultSpellsMap[petSpellsId] = petDefSpells;
2251 ++countData;
2255 // different summon spells
2256 for(uint32 i = 0; i < sSpellStore.GetNumRows(); ++i )
2258 SpellEntry const* spellEntry = sSpellStore.LookupEntry(i);
2259 if(!spellEntry)
2260 continue;
2262 for(int k = 0; k < 3; ++k)
2264 if(spellEntry->Effect[k]==SPELL_EFFECT_SUMMON || spellEntry->Effect[k]==SPELL_EFFECT_SUMMON_PET)
2266 uint32 creature_id = spellEntry->EffectMiscValue[k];
2267 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(creature_id);
2268 if(!cInfo)
2269 continue;
2271 // already loaded
2272 if(cInfo->PetSpellDataId)
2273 continue;
2275 // for creature without PetSpellDataId get default pet spells from creature_template
2276 int32 petSpellsId = cInfo->Entry;
2277 if(mPetDefaultSpellsMap.find(cInfo->Entry) != mPetDefaultSpellsMap.end())
2278 continue;
2280 PetDefaultSpellsEntry petDefSpells;
2281 for(int j = 0; j < MAX_CREATURE_SPELL_DATA_SLOT; ++j)
2282 petDefSpells.spellid[j] = cInfo->spells[j];
2284 if(LoadPetDefaultSpells_helper(cInfo, petDefSpells))
2286 mPetDefaultSpellsMap[petSpellsId] = petDefSpells;
2287 ++countCreature;
2293 sLog.outString();
2294 sLog.outString( ">> Loaded addition spells for %u pet spell data entries and %u summonable creature templates", countData, countCreature );
2297 /// Some checks for spells, to prevent adding deprecated/broken spells for trainers, spell book, etc
2298 bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg)
2300 // not exist
2301 if(!spellInfo)
2302 return false;
2304 bool need_check_reagents = false;
2306 // check effects
2307 for(int i=0; i<3; ++i)
2309 switch(spellInfo->Effect[i])
2311 case 0:
2312 continue;
2314 // craft spell for crafting non-existed item (break client recipes list show)
2315 case SPELL_EFFECT_CREATE_ITEM:
2317 if(!ObjectMgr::GetItemPrototype( spellInfo->EffectItemType[i] ))
2319 if(msg)
2321 if(pl)
2322 ChatHandler(pl).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]);
2323 else
2324 sLog.outErrorDb("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]);
2326 return false;
2329 need_check_reagents = true;
2330 break;
2332 case SPELL_EFFECT_LEARN_SPELL:
2334 SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[i]);
2335 if( !IsSpellValid(spellInfo2,pl,msg) )
2337 if(msg)
2339 if(pl)
2340 ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
2341 else
2342 sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
2344 return false;
2346 break;
2351 if(need_check_reagents)
2353 for(int j = 0; j < 8; ++j)
2355 if(spellInfo->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype( spellInfo->Reagent[j] ))
2357 if(msg)
2359 if(pl)
2360 ChatHandler(pl).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]);
2361 else
2362 sLog.outErrorDb("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]);
2364 return false;
2369 return true;
2372 void SpellMgr::LoadSpellAreas()
2374 mSpellAreaMap.clear(); // need for reload case
2375 mSpellAreaForQuestMap.clear();
2376 mSpellAreaForActiveQuestMap.clear();
2377 mSpellAreaForQuestEndMap.clear();
2378 mSpellAreaForAuraMap.clear();
2380 uint32 count = 0;
2382 // 0 1 2 3 4 5 6 7 8
2383 QueryResult *result = WorldDatabase.Query("SELECT spell, area, quest_start, quest_start_active, quest_end, aura_spell, racemask, gender, autocast FROM spell_area");
2385 if( !result )
2387 barGoLink bar( 1 );
2389 bar.step();
2391 sLog.outString();
2392 sLog.outString( ">> Loaded %u spell area requirements", count );
2393 return;
2396 barGoLink bar( result->GetRowCount() );
2400 Field *fields = result->Fetch();
2402 bar.step();
2404 uint32 spell = fields[0].GetUInt32();
2405 SpellArea spellArea;
2406 spellArea.spellId = spell;
2407 spellArea.areaId = fields[1].GetUInt32();
2408 spellArea.questStart = fields[2].GetUInt32();
2409 spellArea.questStartCanActive = fields[3].GetBool();
2410 spellArea.questEnd = fields[4].GetUInt32();
2411 spellArea.auraSpell = fields[5].GetInt32();
2412 spellArea.raceMask = fields[6].GetUInt32();
2413 spellArea.gender = Gender(fields[7].GetUInt8());
2414 spellArea.autocast = fields[8].GetBool();
2416 if(!sSpellStore.LookupEntry(spell))
2418 sLog.outErrorDb("Spell %u listed in `spell_area` does not exist", spell);
2419 continue;
2423 bool ok = true;
2424 SpellAreaMapBounds sa_bounds = GetSpellAreaMapBounds(spellArea.spellId);
2425 for(SpellAreaMap::const_iterator itr = sa_bounds.first; itr != sa_bounds.second; ++itr)
2427 if(spellArea.spellId && itr->second.spellId && spellArea.spellId != itr->second.spellId)
2428 continue;
2429 if(spellArea.areaId && itr->second.areaId && spellArea.areaId!= itr->second.areaId)
2430 continue;
2431 if(spellArea.questStart && itr->second.questStart && spellArea.questStart!= itr->second.questStart)
2432 continue;
2433 if(spellArea.auraSpell && itr->second.auraSpell && spellArea.auraSpell!= itr->second.auraSpell)
2434 continue;
2435 if(spellArea.raceMask && itr->second.raceMask && (spellArea.raceMask & itr->second.raceMask)==0)
2436 continue;
2437 if(spellArea.gender != GENDER_NONE && itr->second.gender != GENDER_NONE && spellArea.gender!= itr->second.gender)
2438 continue;
2440 // duplicate by requirements
2441 ok =false;
2442 break;
2445 if(!ok)
2447 sLog.outErrorDb("Spell %u listed in `spell_area` already listed with similar requirements.", spell);
2448 continue;
2453 if(spellArea.areaId && !GetAreaEntryByAreaID(spellArea.areaId))
2455 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong area (%u) requirement", spell,spellArea.areaId);
2456 continue;
2459 if(spellArea.questStart && !objmgr.GetQuestTemplate(spellArea.questStart))
2461 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong start quest (%u) requirement", spell,spellArea.questStart);
2462 continue;
2465 if(spellArea.questEnd)
2467 if(!objmgr.GetQuestTemplate(spellArea.questEnd))
2469 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong end quest (%u) requirement", spell,spellArea.questEnd);
2470 continue;
2473 if(spellArea.questEnd==spellArea.questStart && !spellArea.questStartCanActive)
2475 sLog.outErrorDb("Spell %u listed in `spell_area` have quest (%u) requirement for start and end in same time", spell,spellArea.questEnd);
2476 continue;
2480 if(spellArea.auraSpell)
2482 SpellEntry const* spellInfo = sSpellStore.LookupEntry(abs(spellArea.auraSpell));
2483 if(!spellInfo)
2485 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong aura spell (%u) requirement", spell,abs(spellArea.auraSpell));
2486 continue;
2489 if(spellInfo->EffectApplyAuraName[0]!=SPELL_AURA_DUMMY && spellInfo->EffectApplyAuraName[0]!=SPELL_AURA_PHASE)
2491 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell requirement (%u) without dummy/phase aura in effect 0", spell,abs(spellArea.auraSpell));
2492 continue;
2495 if(abs(spellArea.auraSpell)==spellArea.spellId)
2497 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement for itself", spell,abs(spellArea.auraSpell));
2498 continue;
2501 // not allow autocast chains by auraSpell field (but allow use as alternative if not present)
2502 if(spellArea.autocast && spellArea.auraSpell > 0)
2504 bool chain = false;
2505 SpellAreaForAuraMapBounds saBound = GetSpellAreaForAuraMapBounds(spellArea.spellId);
2506 for(SpellAreaForAuraMap::const_iterator itr = saBound.first; itr != saBound.second; ++itr)
2508 if(itr->second->autocast && itr->second->auraSpell > 0)
2510 chain = true;
2511 break;
2515 if(chain)
2517 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura", spell,spellArea.auraSpell);
2518 continue;
2521 SpellAreaMapBounds saBound2 = GetSpellAreaMapBounds(spellArea.auraSpell);
2522 for(SpellAreaMap::const_iterator itr2 = saBound2.first; itr2 != saBound2.second; ++itr2)
2524 if(itr2->second.autocast && itr2->second.auraSpell > 0)
2526 chain = true;
2527 break;
2531 if(chain)
2533 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura", spell,spellArea.auraSpell);
2534 continue;
2539 if(spellArea.raceMask && (spellArea.raceMask & RACEMASK_ALL_PLAYABLE)==0)
2541 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong race mask (%u) requirement", spell,spellArea.raceMask);
2542 continue;
2545 if(spellArea.gender!=GENDER_NONE && spellArea.gender!=GENDER_FEMALE && spellArea.gender!=GENDER_MALE)
2547 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong gender (%u) requirement", spell,spellArea.gender);
2548 continue;
2551 SpellArea const* sa = &mSpellAreaMap.insert(SpellAreaMap::value_type(spell,spellArea))->second;
2553 // for search by current zone/subzone at zone/subzone change
2554 if(spellArea.areaId)
2555 mSpellAreaForAreaMap.insert(SpellAreaForAreaMap::value_type(spellArea.areaId,sa));
2557 // for search at quest start/reward
2558 if(spellArea.questStart)
2560 if(spellArea.questStartCanActive)
2561 mSpellAreaForActiveQuestMap.insert(SpellAreaForQuestMap::value_type(spellArea.questStart,sa));
2562 else
2563 mSpellAreaForQuestMap.insert(SpellAreaForQuestMap::value_type(spellArea.questStart,sa));
2566 // for search at quest start/reward
2567 if(spellArea.questEnd)
2568 mSpellAreaForQuestEndMap.insert(SpellAreaForQuestMap::value_type(spellArea.questEnd,sa));
2570 // for search at aura apply
2571 if(spellArea.auraSpell)
2572 mSpellAreaForAuraMap.insert(SpellAreaForAuraMap::value_type(abs(spellArea.auraSpell),sa));
2574 ++count;
2575 } while( result->NextRow() );
2577 delete result;
2579 sLog.outString();
2580 sLog.outString( ">> Loaded %u spell area requirements", count );
2583 SpellCastResult SpellMgr::GetSpellAllowedInLocationError(SpellEntry const *spellInfo, uint32 map_id, uint32 zone_id, uint32 area_id, Player const* player)
2585 // normal case
2586 if( spellInfo->AreaGroupId > 0)
2588 bool found = false;
2589 AreaGroupEntry const* groupEntry = sAreaGroupStore.LookupEntry(spellInfo->AreaGroupId);
2590 while (groupEntry)
2592 for (uint32 i=0; i<6; ++i)
2593 if( groupEntry->AreaId[i] == zone_id || groupEntry->AreaId[i] == area_id )
2594 found = true;
2595 if (found || !groupEntry->nextGroup)
2596 break;
2597 // Try search in next group
2598 groupEntry = sAreaGroupStore.LookupEntry(groupEntry->nextGroup);
2601 if(!found)
2602 return SPELL_FAILED_INCORRECT_AREA;
2605 // DB base check (if non empty then must fit at least single for allow)
2606 SpellAreaMapBounds saBounds = spellmgr.GetSpellAreaMapBounds(spellInfo->Id);
2607 if(saBounds.first != saBounds.second)
2609 for(SpellAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
2611 if(itr->second.IsFitToRequirements(player,zone_id,area_id))
2612 return SPELL_CAST_OK;
2614 return SPELL_FAILED_INCORRECT_AREA;
2617 // bg spell checks
2618 switch(spellInfo->Id)
2620 case 23333: // Warsong Flag
2621 case 23335: // Silverwing Flag
2622 return map_id == 489 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2623 case 34976: // Netherstorm Flag
2624 return map_id == 566 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2625 case 2584: // Waiting to Resurrect
2626 case 22011: // Spirit Heal Channel
2627 case 22012: // Spirit Heal
2628 case 24171: // Resurrection Impact Visual
2629 case 42792: // Recently Dropped Flag
2630 case 43681: // Inactive
2631 case 44535: // Spirit Heal (mana)
2633 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2634 if(!mapEntry)
2635 return SPELL_FAILED_INCORRECT_AREA;
2637 return mapEntry->IsBattleGround() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2639 case 44521: // Preparation
2641 if(!player)
2642 return SPELL_FAILED_REQUIRES_AREA;
2644 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2645 if(!mapEntry)
2646 return SPELL_FAILED_INCORRECT_AREA;
2648 if(!mapEntry->IsBattleGround())
2649 return SPELL_FAILED_REQUIRES_AREA;
2651 BattleGround* bg = player->GetBattleGround();
2652 return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2654 case 32724: // Gold Team (Alliance)
2655 case 32725: // Green Team (Alliance)
2656 case 35774: // Gold Team (Horde)
2657 case 35775: // Green Team (Horde)
2659 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2660 if(!mapEntry)
2661 return SPELL_FAILED_INCORRECT_AREA;
2663 return mapEntry->IsBattleArena() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2665 case 32727: // Arena Preparation
2667 if(!player)
2668 return SPELL_FAILED_REQUIRES_AREA;
2670 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2671 if(!mapEntry)
2672 return SPELL_FAILED_INCORRECT_AREA;
2674 if(!mapEntry->IsBattleArena())
2675 return SPELL_FAILED_REQUIRES_AREA;
2677 BattleGround* bg = player->GetBattleGround();
2678 return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2682 return SPELL_CAST_OK;
2685 void SpellMgr::LoadSkillLineAbilityMap()
2687 mSkillLineAbilityMap.clear();
2689 barGoLink bar( sSkillLineAbilityStore.GetNumRows() );
2690 uint32 count = 0;
2692 for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); ++i)
2694 bar.step();
2695 SkillLineAbilityEntry const *SkillInfo = sSkillLineAbilityStore.LookupEntry(i);
2696 if(!SkillInfo)
2697 continue;
2699 mSkillLineAbilityMap.insert(SkillLineAbilityMap::value_type(SkillInfo->spellId,SkillInfo));
2700 ++count;
2703 sLog.outString();
2704 sLog.outString(">> Loaded %u SkillLineAbility MultiMap Data", count);
2707 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered)
2709 // Explicit Diminishing Groups
2710 switch(spellproto->SpellFamilyName)
2712 case SPELLFAMILY_ROGUE:
2714 // Kidney Shot
2715 if (spellproto->SpellFamilyFlags & UI64LIT(0x00000200000))
2716 return DIMINISHING_KIDNEYSHOT;
2717 // Blind
2718 else if (spellproto->SpellFamilyFlags & UI64LIT(0x00001000000))
2719 return DIMINISHING_BLIND_CYCLONE;
2720 break;
2722 case SPELLFAMILY_WARLOCK:
2724 // Fear
2725 if (spellproto->SpellFamilyFlags & UI64LIT(0x40840000000))
2726 return DIMINISHING_WARLOCK_FEAR;
2727 // Curses/etc
2728 else if (spellproto->SpellFamilyFlags & UI64LIT(0x00080000000))
2729 return DIMINISHING_LIMITONLY;
2730 break;
2732 case SPELLFAMILY_DRUID:
2734 // Cyclone
2735 if (spellproto->SpellFamilyFlags & UI64LIT(0x02000000000))
2736 return DIMINISHING_BLIND_CYCLONE;
2737 break;
2739 case SPELLFAMILY_WARRIOR:
2741 // Hamstring - limit duration to 10s in PvP
2742 if (spellproto->SpellFamilyFlags & UI64LIT(0x00000000002))
2743 return DIMINISHING_LIMITONLY;
2744 break;
2746 default:
2747 break;
2750 // Get by mechanic
2751 uint32 mechanic = GetAllSpellMechanicMask(spellproto);
2752 if (mechanic == MECHANIC_NONE) return DIMINISHING_NONE;
2753 if (mechanic & (1<<MECHANIC_STUN)) return triggered ? DIMINISHING_TRIGGER_STUN : DIMINISHING_CONTROL_STUN;
2754 if (mechanic & (1<<MECHANIC_SLEEP)) return DIMINISHING_SLEEP;
2755 if (mechanic & (1<<MECHANIC_POLYMORPH)) return DIMINISHING_POLYMORPH;
2756 if (mechanic & (1<<MECHANIC_ROOT)) return triggered ? DIMINISHING_TRIGGER_ROOT : DIMINISHING_CONTROL_ROOT;
2757 if (mechanic & (1<<MECHANIC_FEAR)) return DIMINISHING_FEAR;
2758 if (mechanic & (1<<MECHANIC_CHARM)) return DIMINISHING_CHARM;
2759 if (mechanic & (1<<MECHANIC_SILENCE)) return DIMINISHING_SILENCE;
2760 if (mechanic & (1<<DIMINISHING_DISARM)) return DIMINISHING_DISARM;
2761 if (mechanic & (1<<MECHANIC_FREEZE)) return DIMINISHING_FREEZE;
2762 if (mechanic & ((1<<MECHANIC_KNOCKOUT) | (1<<MECHANIC_SAPPED))) return DIMINISHING_KNOCKOUT;
2763 if (mechanic & (1<<MECHANIC_BANISH)) return DIMINISHING_BANISH;
2764 if (mechanic & (1<<MECHANIC_HORROR)) return DIMINISHING_DEATHCOIL;
2767 return DIMINISHING_NONE;
2770 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group)
2772 switch(group)
2774 case DIMINISHING_CONTROL_STUN:
2775 case DIMINISHING_TRIGGER_STUN:
2776 case DIMINISHING_KIDNEYSHOT:
2777 case DIMINISHING_SLEEP:
2778 case DIMINISHING_CONTROL_ROOT:
2779 case DIMINISHING_TRIGGER_ROOT:
2780 case DIMINISHING_FEAR:
2781 case DIMINISHING_WARLOCK_FEAR:
2782 case DIMINISHING_CHARM:
2783 case DIMINISHING_POLYMORPH:
2784 case DIMINISHING_FREEZE:
2785 case DIMINISHING_KNOCKOUT:
2786 case DIMINISHING_BLIND_CYCLONE:
2787 case DIMINISHING_BANISH:
2788 case DIMINISHING_LIMITONLY:
2789 return true;
2790 default:
2791 return false;
2793 return false;
2796 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group)
2798 switch(group)
2800 case DIMINISHING_BLIND_CYCLONE:
2801 case DIMINISHING_CONTROL_STUN:
2802 case DIMINISHING_TRIGGER_STUN:
2803 case DIMINISHING_KIDNEYSHOT:
2804 return DRTYPE_ALL;
2805 case DIMINISHING_SLEEP:
2806 case DIMINISHING_CONTROL_ROOT:
2807 case DIMINISHING_TRIGGER_ROOT:
2808 case DIMINISHING_FEAR:
2809 case DIMINISHING_CHARM:
2810 case DIMINISHING_POLYMORPH:
2811 case DIMINISHING_SILENCE:
2812 case DIMINISHING_DISARM:
2813 case DIMINISHING_DEATHCOIL:
2814 case DIMINISHING_FREEZE:
2815 case DIMINISHING_BANISH:
2816 case DIMINISHING_WARLOCK_FEAR:
2817 case DIMINISHING_KNOCKOUT:
2818 return DRTYPE_PLAYER;
2819 default:
2820 break;
2823 return DRTYPE_NONE;
2826 bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32 newArea) const
2828 if(gender!=GENDER_NONE)
2830 // not in expected gender
2831 if(!player || gender != player->getGender())
2832 return false;
2835 if(raceMask)
2837 // not in expected race
2838 if(!player || !(raceMask & player->getRaceMask()))
2839 return false;
2842 if(areaId)
2844 // not in expected zone
2845 if(newZone!=areaId && newArea!=areaId)
2846 return false;
2849 if(questStart)
2851 // not in expected required quest state
2852 if(!player || (!questStartCanActive || !player->IsActiveQuest(questStart)) && !player->GetQuestRewardStatus(questStart))
2853 return false;
2856 if(questEnd)
2858 // not in expected forbidden quest state
2859 if(!player || player->GetQuestRewardStatus(questEnd))
2860 return false;
2863 if(auraSpell)
2865 // not have expected aura
2866 if(!player)
2867 return false;
2868 if(auraSpell > 0)
2869 // have expected aura
2870 return player->HasAura(auraSpell,0);
2871 else
2872 // not have expected aura
2873 return !player->HasAura(-auraSpell,0);
2876 return true;