[7592] Correct delay loading for creature waypoints.
[getmangos.git] / src / game / SpellMgr.cpp
blob7fd3d1a8d43ba3a721ba33a7d52d9ebea36dfa5a
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 & 0x12040000)
142 return SPELL_MAGE_ARMOR;
144 if ((spellInfo->SpellFamilyFlags & 0x1000000) && spellInfo->EffectApplyAuraName[0]==SPELL_AURA_MOD_CONFUSE)
145 return SPELL_MAGE_POLYMORPH;
147 break;
149 case SPELLFAMILY_WARRIOR:
151 if (spellInfo->SpellFamilyFlags & 0x00008000010000LL)
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 & 0x2000002000000000LL || 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 & 0x0044000000380000LL || 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 & 0x0000000011010002LL)
189 return SPELL_BLESSING;
191 if ((spellInfo->SpellFamilyFlags & 0x00000820180400LL) && (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:
343 if(spellproto->CalculateSimpleValue(effIndex) < 0)
344 return false;
345 break;
347 case SPELL_AURA_ADD_TARGET_TRIGGER:
348 return true;
349 case SPELL_AURA_PERIODIC_TRIGGER_SPELL:
350 if(spellId != spellproto->EffectTriggerSpell[effIndex])
352 uint32 spellTriggeredId = spellproto->EffectTriggerSpell[effIndex];
353 SpellEntry const *spellTriggeredProto = sSpellStore.LookupEntry(spellTriggeredId);
355 if(spellTriggeredProto)
357 // non-positive targets of main spell return early
358 for(int i = 0; i < 3; ++i)
360 // if non-positive trigger cast targeted to positive target this main cast is non-positive
361 // this will place this spell auras as debuffs
362 if(IsPositiveTarget(spellTriggeredProto->EffectImplicitTargetA[effIndex],spellTriggeredProto->EffectImplicitTargetB[effIndex]) && !IsPositiveEffect(spellTriggeredId,i))
363 return false;
367 break;
368 case SPELL_AURA_PROC_TRIGGER_SPELL:
369 // many positive auras have negative triggered spells at damage for example and this not make it negative (it can be canceled for example)
370 break;
371 case SPELL_AURA_MOD_STUN: //have positive and negative spells, we can't sort its correctly at this moment.
372 if(effIndex==0 && spellproto->Effect[1]==0 && spellproto->Effect[2]==0)
373 return false; // but all single stun aura spells is negative
375 // Petrification
376 if(spellproto->Id == 17624)
377 return false;
378 break;
379 case SPELL_AURA_MOD_ROOT:
380 case SPELL_AURA_MOD_SILENCE:
381 case SPELL_AURA_GHOST:
382 case SPELL_AURA_PERIODIC_LEECH:
383 case SPELL_AURA_MOD_PACIFY_SILENCE:
384 case SPELL_AURA_MOD_STALKED:
385 case SPELL_AURA_PERIODIC_DAMAGE_PERCENT:
386 return false;
387 case SPELL_AURA_PERIODIC_DAMAGE: // used in positive spells also.
388 // part of negative spell if casted at self (prevent cancel)
389 if(spellproto->EffectImplicitTargetA[effIndex] == TARGET_SELF)
390 return false;
391 break;
392 case SPELL_AURA_MOD_DECREASE_SPEED: // used in positive spells also
393 // part of positive spell if casted at self
394 if(spellproto->EffectImplicitTargetA[effIndex] != TARGET_SELF)
395 return false;
396 // but not this if this first effect (don't found batter check)
397 if(spellproto->Attributes & 0x4000000 && effIndex==0)
398 return false;
399 break;
400 case SPELL_AURA_TRANSFORM:
401 // some spells negative
402 switch(spellproto->Id)
404 case 36897: // Transporter Malfunction (race mutation to horde)
405 case 36899: // Transporter Malfunction (race mutation to alliance)
406 return false;
408 break;
409 case SPELL_AURA_MOD_SCALE:
410 // some spells negative
411 switch(spellproto->Id)
413 case 36900: // Soul Split: Evil!
414 case 36901: // Soul Split: Good
415 case 36893: // Transporter Malfunction (decrease size case)
416 case 36895: // Transporter Malfunction (increase size case)
417 return false;
419 break;
420 case SPELL_AURA_MECHANIC_IMMUNITY:
422 // non-positive immunities
423 switch(spellproto->EffectMiscValue[effIndex])
425 case MECHANIC_BANDAGE:
426 case MECHANIC_SHIELD:
427 case MECHANIC_MOUNT:
428 case MECHANIC_INVULNERABILITY:
429 return false;
430 default:
431 break;
433 } break;
434 case SPELL_AURA_ADD_FLAT_MODIFIER: // mods
435 case SPELL_AURA_ADD_PCT_MODIFIER:
437 // non-positive mods
438 switch(spellproto->EffectMiscValue[effIndex])
440 case SPELLMOD_COST: // dependent from bas point sign (negative -> positive)
441 if(spellproto->CalculateSimpleValue(effIndex) > 0)
442 return false;
443 break;
444 default:
445 break;
447 } break;
448 case SPELL_AURA_MOD_HEALING_PCT:
449 if(spellproto->CalculateSimpleValue(effIndex) < 0)
450 return false;
451 break;
452 case SPELL_AURA_MOD_SKILL:
453 if(spellproto->CalculateSimpleValue(effIndex) < 0)
454 return false;
455 break;
456 case SPELL_AURA_FORCE_REACTION:
457 if(spellproto->Id==42792) // Recently Dropped Flag (prevent cancel)
458 return false;
459 break;
460 default:
461 break;
463 break;
465 default:
466 break;
469 // non-positive targets
470 if(!IsPositiveTarget(spellproto->EffectImplicitTargetA[effIndex],spellproto->EffectImplicitTargetB[effIndex]))
471 return false;
473 // AttributesEx check
474 if(spellproto->AttributesEx & SPELL_ATTR_EX_NEGATIVE)
475 return false;
477 // ok, positive
478 return true;
481 bool IsPositiveSpell(uint32 spellId)
483 SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId);
484 if (!spellproto) return false;
486 // spells with atleast one negative effect are considered negative
487 // some self-applied spells have negative effects but in self casting case negative check ignored.
488 for (int i = 0; i < 3; i++)
489 if (!IsPositiveEffect(spellId, i))
490 return false;
491 return true;
494 bool IsSingleTargetSpell(SpellEntry const *spellInfo)
496 // all other single target spells have if it has AttributesEx5
497 if ( spellInfo->AttributesEx5 & SPELL_ATTR_EX5_SINGLE_TARGET_SPELL )
498 return true;
500 // TODO - need found Judgements rule
501 switch(GetSpellSpecific(spellInfo->Id))
503 case SPELL_JUDGEMENT:
504 return true;
507 // single target triggered spell.
508 // Not real client side single target spell, but it' not triggered until prev. aura expired.
509 // This is allow store it in single target spells list for caster for spell proc checking
510 if(spellInfo->Id==38324) // Regeneration (triggered by 38299 (HoTs on Heals))
511 return true;
513 return false;
516 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2)
518 // TODO - need better check
519 // Equal icon and spellfamily
520 if( spellInfo1->SpellFamilyName == spellInfo2->SpellFamilyName &&
521 spellInfo1->SpellIconID == spellInfo2->SpellIconID )
522 return true;
524 // TODO - need found Judgements rule
525 SpellSpecific spec1 = GetSpellSpecific(spellInfo1->Id);
526 // spell with single target specific types
527 switch(spec1)
529 case SPELL_JUDGEMENT:
530 case SPELL_MAGE_POLYMORPH:
531 if(GetSpellSpecific(spellInfo2->Id) == spec1)
532 return true;
533 break;
536 return false;
539 bool IsAuraAddedBySpell(uint32 auraType, uint32 spellId)
541 SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId);
542 if (!spellproto) return false;
544 for (int i = 0; i < 3; i++)
545 if (spellproto->EffectApplyAuraName[i] == auraType)
546 return true;
547 return false;
550 SpellCastResult GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form)
552 // talents that learn spells can have stance requirements that need ignore
553 // (this requirement only for client-side stance show in talent description)
554 if( GetTalentSpellCost(spellInfo->Id) > 0 &&
555 (spellInfo->Effect[0]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[1]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[2]==SPELL_EFFECT_LEARN_SPELL) )
556 return SPELL_CAST_OK;
558 uint32 stanceMask = (form ? 1 << (form - 1) : 0);
560 if (stanceMask & spellInfo->StancesNot) // can explicitly not be casted in this stance
561 return SPELL_FAILED_NOT_SHAPESHIFT;
563 if (stanceMask & spellInfo->Stances) // can explicitly be casted in this stance
564 return SPELL_CAST_OK;
566 bool actAsShifted = false;
567 if (form > 0)
569 SpellShapeshiftEntry const *shapeInfo = sSpellShapeshiftStore.LookupEntry(form);
570 if (!shapeInfo)
572 sLog.outError("GetErrorAtShapeshiftedCast: unknown shapeshift %u", form);
573 return SPELL_CAST_OK;
575 actAsShifted = !(shapeInfo->flags1 & 1); // shapeshift acts as normal form for spells
578 if(actAsShifted)
580 if (spellInfo->Attributes & SPELL_ATTR_NOT_SHAPESHIFT) // not while shapeshifted
581 return SPELL_FAILED_NOT_SHAPESHIFT;
582 else if (spellInfo->Stances != 0) // needs other shapeshift
583 return SPELL_FAILED_ONLY_SHAPESHIFT;
585 else
587 // needs shapeshift
588 if(!(spellInfo->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) && spellInfo->Stances != 0)
589 return SPELL_FAILED_ONLY_SHAPESHIFT;
592 return SPELL_CAST_OK;
595 void SpellMgr::LoadSpellTargetPositions()
597 mSpellTargetPositions.clear(); // need for reload case
599 uint32 count = 0;
601 // 0 1 2 3 4 5
602 QueryResult *result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position");
603 if( !result )
606 barGoLink bar( 1 );
608 bar.step();
610 sLog.outString();
611 sLog.outString( ">> Loaded %u spell target coordinates", count );
612 return;
615 barGoLink bar( result->GetRowCount() );
619 Field *fields = result->Fetch();
621 bar.step();
623 ++count;
625 uint32 Spell_ID = fields[0].GetUInt32();
627 SpellTargetPosition st;
629 st.target_mapId = fields[1].GetUInt32();
630 st.target_X = fields[2].GetFloat();
631 st.target_Y = fields[3].GetFloat();
632 st.target_Z = fields[4].GetFloat();
633 st.target_Orientation = fields[5].GetFloat();
635 SpellEntry const* spellInfo = sSpellStore.LookupEntry(Spell_ID);
636 if(!spellInfo)
638 sLog.outErrorDb("Spell (ID:%u) listed in `spell_target_position` does not exist.",Spell_ID);
639 continue;
642 bool found = false;
643 for(int i = 0; i < 3; ++i)
645 if( spellInfo->EffectImplicitTargetA[i]==TARGET_TABLE_X_Y_Z_COORDINATES || spellInfo->EffectImplicitTargetB[i]==TARGET_TABLE_X_Y_Z_COORDINATES )
647 found = true;
648 break;
651 if(!found)
653 sLog.outErrorDb("Spell (Id: %u) listed in `spell_target_position` does not have target TARGET_TABLE_X_Y_Z_COORDINATES (17).",Spell_ID);
654 continue;
657 MapEntry const* mapEntry = sMapStore.LookupEntry(st.target_mapId);
658 if(!mapEntry)
660 sLog.outErrorDb("Spell (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Spell_ID,st.target_mapId);
661 continue;
664 if(st.target_X==0 && st.target_Y==0 && st.target_Z==0)
666 sLog.outErrorDb("Spell (ID:%u) target coordinates not provided.",Spell_ID);
667 continue;
670 mSpellTargetPositions[Spell_ID] = st;
672 } while( result->NextRow() );
674 delete result;
676 sLog.outString();
677 sLog.outString( ">> Loaded %u spell teleport coordinates", count );
680 void SpellMgr::LoadSpellAffects()
682 mSpellAffectMap.clear(); // need for reload case
684 uint32 count = 0;
686 // 0 1 2 3 4
687 QueryResult *result = WorldDatabase.Query("SELECT entry, effectId, SpellClassMask0, SpellClassMask1, SpellClassMask2 FROM spell_affect");
688 if( !result )
691 barGoLink bar( 1 );
693 bar.step();
695 sLog.outString();
696 sLog.outString( ">> Loaded %u spell affect definitions", count );
697 return;
700 barGoLink bar( result->GetRowCount() );
704 Field *fields = result->Fetch();
706 bar.step();
708 uint16 entry = fields[0].GetUInt16();
709 uint8 effectId = fields[1].GetUInt8();
711 SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry);
713 if (!spellInfo)
715 sLog.outErrorDb("Spell %u listed in `spell_affect` does not exist", entry);
716 continue;
719 if (effectId >= 3)
721 sLog.outErrorDb("Spell %u listed in `spell_affect` have invalid effect index (%u)", entry,effectId);
722 continue;
725 if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA ||
726 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER &&
727 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER &&
728 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER )
730 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);
731 continue;
734 SpellAffectEntry affect;
735 affect.SpellClassMask[0] = fields[2].GetUInt32();
736 affect.SpellClassMask[1] = fields[3].GetUInt32();
737 affect.SpellClassMask[2] = fields[4].GetUInt32();
739 // Spell.dbc have own data
740 uint32 const *ptr = 0;
741 switch (effectId)
743 case 0: ptr = &spellInfo->EffectSpellClassMaskA[0]; break;
744 case 1: ptr = &spellInfo->EffectSpellClassMaskB[0]; break;
745 case 2: ptr = &spellInfo->EffectSpellClassMaskC[0]; break;
746 default:
747 continue;
749 if(ptr[0] == affect.SpellClassMask[0] || ptr[1] == affect.SpellClassMask[1] || ptr[2] == affect.SpellClassMask[2])
751 char text[]="ABC";
752 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);
753 continue;
756 mSpellAffectMap[(entry<<8) + effectId] = affect;
758 ++count;
759 } while( result->NextRow() );
761 delete result;
763 sLog.outString();
764 sLog.outString( ">> Loaded %u custom spell affect definitions", count );
766 for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id)
768 SpellEntry const* spellInfo = sSpellStore.LookupEntry(id);
769 if (!spellInfo)
770 continue;
772 for (int effectId = 0; effectId < 3; ++effectId)
774 if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA ||
775 (spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER &&
776 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER &&
777 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER) )
778 continue;
780 uint32 const *ptr = 0;
781 switch (effectId)
783 case 0: ptr = &spellInfo->EffectSpellClassMaskA[0]; break;
784 case 1: ptr = &spellInfo->EffectSpellClassMaskB[0]; break;
785 case 2: ptr = &spellInfo->EffectSpellClassMaskC[0]; break;
786 default:
787 continue;
789 if(ptr[0] || ptr[1] || ptr[2])
790 continue;
792 if(mSpellAffectMap.find((id<<8) + effectId) != mSpellAffectMap.end())
793 continue;
795 sLog.outErrorDb("Spell %u (%s) misses spell_affect for effect %u",id,spellInfo->SpellName[sWorld.GetDefaultDbcLocale()], effectId);
800 bool SpellMgr::IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const
802 // false for spellInfo == NULL
803 if (!spellInfo || !mod)
804 return false;
806 SpellEntry const *affect_spell = sSpellStore.LookupEntry(mod->spellId);
807 // False if affect_spell == NULL or spellFamily not equal
808 if (!affect_spell || affect_spell->SpellFamilyName != spellInfo->SpellFamilyName)
809 return false;
811 // true
812 if (mod->mask & spellInfo->SpellFamilyFlags ||
813 mod->mask2 & spellInfo->SpellFamilyFlags2)
814 return true;
816 return false;
819 void SpellMgr::LoadSpellProcEvents()
821 mSpellProcEventMap.clear(); // need for reload case
823 uint32 count = 0;
825 // 0 1 2 3 4 5 6 7 8 9 10
826 QueryResult *result = WorldDatabase.Query("SELECT entry, SchoolMask, SpellFamilyName, SpellFamilyMask0, SpellFamilyMask1, SpellFamilyMask2, procFlags, procEx, ppmRate, CustomChance, Cooldown FROM spell_proc_event");
827 if( !result )
829 barGoLink bar( 1 );
830 bar.step();
831 sLog.outString();
832 sLog.outString( ">> Loaded %u spell proc event conditions", count );
833 return;
836 barGoLink bar( result->GetRowCount() );
837 uint32 customProc = 0;
840 Field *fields = result->Fetch();
842 bar.step();
844 uint32 entry = fields[0].GetUInt32();
846 const SpellEntry *spell = sSpellStore.LookupEntry(entry);
847 if (!spell)
849 sLog.outErrorDb("Spell %u listed in `spell_proc_event` does not exist", entry);
850 continue;
853 SpellProcEventEntry spe;
855 spe.schoolMask = fields[1].GetUInt32();
856 spe.spellFamilyName = fields[2].GetUInt32();
857 spe.spellFamilyMask = (uint64)fields[3].GetUInt32()|((uint64)fields[4].GetUInt32()<<32);
858 spe.spellFamilyMask2= fields[5].GetUInt32();
859 spe.procFlags = fields[6].GetUInt32();
860 spe.procEx = fields[7].GetUInt32();
861 spe.ppmRate = fields[8].GetFloat();
862 spe.customChance = fields[9].GetFloat();
863 spe.cooldown = fields[10].GetUInt32();
865 mSpellProcEventMap[entry] = spe;
867 if (spell->procFlags==0)
869 if (spe.procFlags == 0)
871 sLog.outErrorDb("Spell %u listed in `spell_proc_event` probally not triggered spell", entry);
872 continue;
874 customProc++;
876 ++count;
877 } while( result->NextRow() );
879 delete result;
881 sLog.outString();
882 if (customProc)
883 sLog.outString( ">> Loaded %u extra spell proc event conditions +%u custom", count, customProc );
884 else
885 sLog.outString( ">> Loaded %u extra spell proc event conditions", count );
888 void SpellMgr::LoadSpellBonusess()
890 mSpellBonusMap.clear(); // need for reload case
891 uint32 count = 0;
892 // 0 1 2 3
893 QueryResult *result = WorldDatabase.Query("SELECT entry, direct_bonus, dot_bonus, ap_bonus FROM spell_bonus_data");
894 if( !result )
896 barGoLink bar( 1 );
897 bar.step();
898 sLog.outString();
899 sLog.outString( ">> Loaded %u spell bonus data", count);
900 return;
903 barGoLink bar( result->GetRowCount() );
906 Field *fields = result->Fetch();
907 bar.step();
908 uint32 entry = fields[0].GetUInt32();
910 const SpellEntry *spell = sSpellStore.LookupEntry(entry);
911 if (!spell)
913 sLog.outErrorDb("Spell %u listed in `spell_bonus_data` does not exist", entry);
914 continue;
917 SpellBonusEntry sbe;
919 sbe.direct_damage = fields[1].GetFloat();
920 sbe.dot_damage = fields[2].GetFloat();
921 sbe.ap_bonus = fields[3].GetFloat();
923 mSpellBonusMap[entry] = sbe;
924 } while( result->NextRow() );
926 delete result;
928 sLog.outString();
929 sLog.outString( ">> Loaded %u extra spell bonus data", count);
932 bool SpellMgr::IsSpellProcEventCanTriggeredBy(SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active)
934 // No extra req need
935 uint32 procEvent_procEx = PROC_EX_NONE;
937 // check prockFlags for condition
938 if((procFlags & EventProcFlag) == 0)
939 return false;
941 // Always trigger for this
942 if (EventProcFlag & (PROC_FLAG_KILLED | PROC_FLAG_KILL | PROC_FLAG_ON_TRAP_ACTIVATION))
943 return true;
945 if (spellProcEvent) // Exist event data
947 // Store extra req
948 procEvent_procEx = spellProcEvent->procEx;
950 // For melee triggers
951 if (procSpell == NULL)
953 // Check (if set) for school (melee attack have Normal school)
954 if(spellProcEvent->schoolMask && (spellProcEvent->schoolMask & SPELL_SCHOOL_MASK_NORMAL) == 0)
955 return false;
957 else // For spells need check school/spell family/family mask
959 // Check (if set) for school
960 if(spellProcEvent->schoolMask && (spellProcEvent->schoolMask & procSpell->SchoolMask) == 0)
961 return false;
963 // Check (if set) for spellFamilyName
964 if(spellProcEvent->spellFamilyName && (spellProcEvent->spellFamilyName != procSpell->SpellFamilyName))
965 return false;
967 // spellFamilyName is Ok need check for spellFamilyMask if present
968 if(spellProcEvent->spellFamilyMask || spellProcEvent->spellFamilyMask2)
970 if ((spellProcEvent->spellFamilyMask & procSpell->SpellFamilyFlags ) == 0 &&
971 (spellProcEvent->spellFamilyMask2 & procSpell->SpellFamilyFlags2) == 0)
972 return false;
973 active = true; // Spell added manualy -> so its active spell
977 // Check for extra req (if none) and hit/crit
978 if (procEvent_procEx == PROC_EX_NONE)
980 // No extra req, so can trigger only for active (damage/healing present) and hit/crit
981 if((procExtra & (PROC_EX_NORMAL_HIT|PROC_EX_CRITICAL_HIT)) && active)
982 return true;
984 else // Passive spells hits here only if resist/reflect/immune/evade
986 // Exist req for PROC_EX_EX_TRIGGER_ALWAYS
987 if (procEvent_procEx & PROC_EX_EX_TRIGGER_ALWAYS)
988 return true;
989 // Passive spells can`t trigger if need hit
990 if ((procEvent_procEx & PROC_EX_NORMAL_HIT) && !active)
991 return false;
992 // Check Extra Requirement like (hit/crit/miss/resist/parry/dodge/block/immune/reflect/absorb and other)
993 if (procEvent_procEx & procExtra)
994 return true;
996 return false;
999 void SpellMgr::LoadSpellElixirs()
1001 mSpellElixirs.clear(); // need for reload case
1003 uint32 count = 0;
1005 // 0 1
1006 QueryResult *result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir");
1007 if( !result )
1010 barGoLink bar( 1 );
1012 bar.step();
1014 sLog.outString();
1015 sLog.outString( ">> Loaded %u spell elixir definitions", count );
1016 return;
1019 barGoLink bar( result->GetRowCount() );
1023 Field *fields = result->Fetch();
1025 bar.step();
1027 uint16 entry = fields[0].GetUInt16();
1028 uint8 mask = fields[1].GetUInt8();
1030 SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry);
1032 if (!spellInfo)
1034 sLog.outErrorDb("Spell %u listed in `spell_elixir` does not exist", entry);
1035 continue;
1038 mSpellElixirs[entry] = mask;
1040 ++count;
1041 } while( result->NextRow() );
1043 delete result;
1045 sLog.outString();
1046 sLog.outString( ">> Loaded %u spell elixir definitions", count );
1049 void SpellMgr::LoadSpellThreats()
1051 sSpellThreatStore.Free(); // for reload
1053 sSpellThreatStore.Load();
1055 sLog.outString( ">> Loaded %u aggro generating spells", sSpellThreatStore.RecordCount );
1056 sLog.outString();
1059 bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const
1061 SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
1062 if(!spellInfo_1 || !spellInfo_2) return false;
1063 if(spellInfo_1->Id == spellId_2) return false;
1065 return GetFirstSpellInChain(spellInfo_1->Id)==GetFirstSpellInChain(spellId_2);
1068 bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo)
1070 if(IsPassiveSpell(spellInfo->Id)) // ranked passive spell
1071 return false;
1072 if(spellInfo->powerType != POWER_MANA && spellInfo->powerType != POWER_HEALTH)
1073 return false;
1074 if(IsProfessionOrRidingSpell(spellInfo->Id))
1075 return false;
1077 if(spellmgr.IsSkillBonusSpell(spellInfo->Id))
1078 return false;
1080 // All stance spells. if any better way, change it.
1081 for (int i = 0; i < 3; i++)
1083 switch(spellInfo->SpellFamilyName)
1085 case SPELLFAMILY_PALADIN:
1086 // Paladin aura Spell
1087 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AREA_AURA_RAID)
1088 return false;
1089 break;
1090 case SPELLFAMILY_DRUID:
1091 // Druid form Spell
1092 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA &&
1093 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT)
1094 return false;
1095 break;
1096 case SPELLFAMILY_ROGUE:
1097 // Rogue Stealth
1098 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA &&
1099 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT)
1100 return false;
1103 return true;
1106 bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const
1108 SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1);
1109 SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
1111 if(!spellInfo_1 || !spellInfo_2)
1112 return false;
1114 if(spellInfo_1->Id == spellId_2)
1115 return false;
1117 //I think we don't check this correctly because i need a exception for spell:
1118 //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.
1119 if(spellInfo_2->SpellFamilyFlags == 2048)
1120 return false;
1122 // Resurrection sickness
1123 if((spellInfo_1->Id == SPELL_ID_PASSIVE_RESURRECTION_SICKNESS) != (spellInfo_2->Id==SPELL_ID_PASSIVE_RESURRECTION_SICKNESS))
1124 return false;
1126 // Allow stack passive and not passive spells
1127 if ((spellInfo_1->Attributes & SPELL_ATTR_PASSIVE)!=(spellInfo_2->Attributes & SPELL_ATTR_PASSIVE))
1128 return false;
1130 // Specific spell family spells
1131 switch(spellInfo_1->SpellFamilyName)
1133 case SPELLFAMILY_GENERIC:
1134 switch(spellInfo_2->SpellFamilyName)
1136 case SPELLFAMILY_GENERIC: // same family case
1138 // Thunderfury
1139 if( spellInfo_1->Id == 21992 && spellInfo_2->Id == 27648 || spellInfo_2->Id == 21992 && spellInfo_1->Id == 27648 )
1140 return false;
1142 // Lightning Speed (Mongoose) and Fury of the Crashing Waves (Tsunami Talisman)
1143 if( spellInfo_1->Id == 28093 && spellInfo_2->Id == 42084 ||
1144 spellInfo_2->Id == 28093 && spellInfo_1->Id == 42084 )
1145 return false;
1147 // Soulstone Resurrection and Twisting Nether (resurrector)
1148 if( spellInfo_1->SpellIconID == 92 && spellInfo_2->SpellIconID == 92 && (
1149 spellInfo_1->SpellVisual[0] == 99 && spellInfo_2->SpellVisual[0] == 0 ||
1150 spellInfo_2->SpellVisual[0] == 99 && spellInfo_1->SpellVisual[0] == 0 ) )
1151 return false;
1153 // Heart of the Wild and (Primal Instinct (Idol of Terror) triggering spell or Agility)
1154 if( spellInfo_1->SpellIconID == 240 && spellInfo_2->SpellIconID == 240 && (
1155 spellInfo_1->SpellVisual[0] == 0 && spellInfo_2->SpellVisual[0] == 78 ||
1156 spellInfo_2->SpellVisual[0] == 0 && spellInfo_1->SpellVisual[0] == 78 ) )
1157 return false;
1159 // Personalized Weather (thunder effect should overwrite rainy aura)
1160 if(spellInfo_1->SpellIconID == 2606 && spellInfo_2->SpellIconID == 2606)
1161 return false;
1163 // Brood Affliction: Bronze
1164 if( (spellInfo_1->Id == 23170 && spellInfo_2->Id == 23171) ||
1165 (spellInfo_2->Id == 23170 && spellInfo_1->Id == 23171) )
1166 return false;
1168 // See Chapel Invisibility and See Noth Invisibility
1169 if( (spellInfo_1->Id == 52950 && spellInfo_2->Id == 52707) ||
1170 (spellInfo_2->Id == 52950 && spellInfo_1->Id == 52707) )
1171 return false;
1173 break;
1175 case SPELLFAMILY_WARRIOR:
1177 // Scroll of Protection and Defensive Stance (multi-family check)
1178 if( spellInfo_1->SpellIconID == 276 && spellInfo_1->SpellVisual[0] == 196 && spellInfo_2->Id == 71)
1179 return false;
1181 // Improved Hamstring -> Hamstring (multi-family check)
1182 if( (spellInfo_2->SpellFamilyFlags & 2) && spellInfo_1->Id == 23694 )
1183 return false;
1185 break;
1187 case SPELLFAMILY_DRUID:
1189 // Scroll of Stamina and Leader of the Pack (multi-family check)
1190 if( spellInfo_1->SpellIconID == 312 && spellInfo_1->SpellVisual[0] == 216 && spellInfo_2->Id == 24932 )
1191 return false;
1193 // Dragonmaw Illusion (multi-family check)
1194 if (spellId_1 == 40216 && spellId_2 == 42016 )
1195 return false;
1197 break;
1199 case SPELLFAMILY_ROGUE:
1201 // Garrote-Silence -> Garrote (multi-family check)
1202 if( spellInfo_1->SpellIconID == 498 && spellInfo_1->SpellVisual[0] == 0 && spellInfo_2->SpellIconID == 498 )
1203 return false;
1205 break;
1207 case SPELLFAMILY_HUNTER:
1209 // Concussive Shot and Imp. Concussive Shot (multi-family check)
1210 if( spellInfo_1->Id == 19410 && spellInfo_2->Id == 5116 )
1211 return false;
1213 // Improved Wing Clip -> Wing Clip (multi-family check)
1214 if( (spellInfo_2->SpellFamilyFlags & 0x40) && spellInfo_1->Id == 19229 )
1215 return false;
1216 break;
1218 case SPELLFAMILY_PALADIN:
1220 // Unstable Currents and other -> *Sanctity Aura (multi-family check)
1221 if( spellInfo_2->SpellIconID==502 && spellInfo_1->SpellIconID==502 && spellInfo_1->SpellVisual[0]==969 )
1222 return false;
1224 // *Band of Eternal Champion and Seal of Command(multi-family check)
1225 if( spellId_1 == 35081 && spellInfo_2->SpellIconID==561 && spellInfo_2->SpellVisual[0]==7992)
1226 return false;
1228 break;
1231 break;
1232 case SPELLFAMILY_MAGE:
1233 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_MAGE )
1235 // Blizzard & Chilled (and some other stacked with blizzard spells
1236 if( (spellInfo_1->SpellFamilyFlags & 0x80) && (spellInfo_2->SpellFamilyFlags & 0x100000) ||
1237 (spellInfo_2->SpellFamilyFlags & 0x80) && (spellInfo_1->SpellFamilyFlags & 0x100000) )
1238 return false;
1240 // Blink & Improved Blink
1241 if( (spellInfo_1->SpellFamilyFlags & 0x0000000000010000LL) && (spellInfo_2->SpellVisual[0] == 72 && spellInfo_2->SpellIconID == 1499) ||
1242 (spellInfo_2->SpellFamilyFlags & 0x0000000000010000LL) && (spellInfo_1->SpellVisual[0] == 72 && spellInfo_1->SpellIconID == 1499) )
1243 return false;
1245 // Detect Invisibility and Mana Shield (multi-family check)
1246 if( spellInfo_2->Id == 132 && spellInfo_1->SpellIconID == 209 && spellInfo_1->SpellVisual[0] == 968 )
1247 return false;
1249 // Combustion and Fire Protection Aura (multi-family check)
1250 if( spellInfo_1->Id == 11129 && spellInfo_2->SpellIconID == 33 && spellInfo_2->SpellVisual[0] == 321 )
1251 return false;
1253 break;
1254 case SPELLFAMILY_WARLOCK:
1255 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_WARLOCK )
1257 // Siphon Life and Drain Life
1258 if( spellInfo_1->SpellIconID == 152 && spellInfo_2->SpellIconID == 546 ||
1259 spellInfo_2->SpellIconID == 152 && spellInfo_1->SpellIconID == 546 )
1260 return false;
1262 //Corruption & Seed of corruption
1263 if( spellInfo_1->SpellIconID == 313 && spellInfo_2->SpellIconID == 1932 ||
1264 spellInfo_2->SpellIconID == 313 && spellInfo_1->SpellIconID == 1932 )
1265 if(spellInfo_1->SpellVisual[0] != 0 && spellInfo_2->SpellVisual[0] != 0)
1266 return true; // can't be stacked
1268 // Corruption and Unstable Affliction
1269 if( spellInfo_1->SpellIconID == 313 && spellInfo_2->SpellIconID == 2039 ||
1270 spellInfo_2->SpellIconID == 313 && spellInfo_1->SpellIconID == 2039 )
1271 return false;
1273 // (Corruption or Unstable Affliction) and (Curse of Agony or Curse of Doom)
1274 if( (spellInfo_1->SpellIconID == 313 || spellInfo_1->SpellIconID == 2039) && (spellInfo_2->SpellIconID == 544 || spellInfo_2->SpellIconID == 91) ||
1275 (spellInfo_2->SpellIconID == 313 || spellInfo_2->SpellIconID == 2039) && (spellInfo_1->SpellIconID == 544 || spellInfo_1->SpellIconID == 91) )
1276 return false;
1278 // Detect Invisibility and Mana Shield (multi-family check)
1279 if( spellInfo_1->Id == 132 && spellInfo_2->SpellIconID == 209 && spellInfo_2->SpellVisual[0] == 968 )
1280 return false;
1281 break;
1282 case SPELLFAMILY_WARRIOR:
1283 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_WARRIOR )
1285 // Rend and Deep Wound
1286 if( (spellInfo_1->SpellFamilyFlags & 0x20) && (spellInfo_2->SpellFamilyFlags & 0x1000000000LL) ||
1287 (spellInfo_2->SpellFamilyFlags & 0x20) && (spellInfo_1->SpellFamilyFlags & 0x1000000000LL) )
1288 return false;
1290 // Battle Shout and Rampage
1291 if( (spellInfo_1->SpellIconID == 456 && spellInfo_2->SpellIconID == 2006) ||
1292 (spellInfo_2->SpellIconID == 456 && spellInfo_1->SpellIconID == 2006) )
1293 return false;
1296 // Hamstring -> Improved Hamstring (multi-family check)
1297 if( (spellInfo_1->SpellFamilyFlags & 2) && spellInfo_2->Id == 23694 )
1298 return false;
1300 // Defensive Stance and Scroll of Protection (multi-family check)
1301 if( spellInfo_1->Id == 71 && spellInfo_2->SpellIconID == 276 && spellInfo_2->SpellVisual[0] == 196 )
1302 return false;
1304 // Bloodlust and Bloodthirst (multi-family check)
1305 if( spellInfo_2->Id == 2825 && spellInfo_1->SpellIconID == 38 && spellInfo_1->SpellVisual[0] == 0 )
1306 return false;
1308 break;
1309 case SPELLFAMILY_PRIEST:
1310 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_PRIEST )
1312 //Devouring Plague and Shadow Vulnerability
1313 if( (spellInfo_1->SpellFamilyFlags & 0x2000000) && (spellInfo_2->SpellFamilyFlags & 0x800000000LL) ||
1314 (spellInfo_2->SpellFamilyFlags & 0x2000000) && (spellInfo_1->SpellFamilyFlags & 0x800000000LL) )
1315 return false;
1317 //StarShards and Shadow Word: Pain
1318 if( (spellInfo_1->SpellFamilyFlags & 0x200000) && (spellInfo_2->SpellFamilyFlags & 0x8000) ||
1319 (spellInfo_2->SpellFamilyFlags & 0x200000) && (spellInfo_1->SpellFamilyFlags & 0x8000) )
1320 return false;
1321 // Dispersion
1322 if( (spellInfo_1->Id == 47585 && spellInfo_2->Id == 60069) ||
1323 (spellInfo_2->Id == 47585 && spellInfo_1->Id == 60069) )
1324 return false;
1326 break;
1327 case SPELLFAMILY_DRUID:
1328 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_DRUID )
1330 //Omen of Clarity and Blood Frenzy
1331 if( (spellInfo_1->SpellFamilyFlags == 0x0 && spellInfo_1->SpellIconID == 108) && (spellInfo_2->SpellFamilyFlags & 0x20000000000000LL) ||
1332 (spellInfo_2->SpellFamilyFlags == 0x0 && spellInfo_2->SpellIconID == 108) && (spellInfo_1->SpellFamilyFlags & 0x20000000000000LL) )
1333 return false;
1335 // Tree of Life (Shapeshift) and 34123 Tree of Life (Passive)
1336 if ((spellId_1 == 33891 && spellId_2 == 34123) ||
1337 (spellId_2 == 33891 && spellId_1 == 34123))
1338 return false;
1340 // Wrath of Elune and Nature's Grace
1341 if( spellInfo_1->Id == 16886 && spellInfo_2->Id == 46833 || spellInfo_2->Id == 16886 && spellInfo_1->Id == 46833 )
1342 return false;
1344 // Bear Rage (Feral T4 (2)) and Omen of Clarity
1345 if( spellInfo_1->Id == 16864 && spellInfo_2->Id == 37306 || spellInfo_2->Id == 16864 && spellInfo_1->Id == 37306 )
1346 return false;
1348 // Cat Energy (Feral T4 (2)) and Omen of Clarity
1349 if( spellInfo_1->Id == 16864 && spellInfo_2->Id == 37311 || spellInfo_2->Id == 16864 && spellInfo_1->Id == 37311 )
1350 return false;
1352 // Survival Instincts and Survival Instincts
1353 if( spellInfo_1->Id == 61336 && spellInfo_2->Id == 50322 || spellInfo_2->Id == 61336 && spellInfo_1->Id == 50322 )
1354 return false;
1357 // Leader of the Pack and Scroll of Stamina (multi-family check)
1358 if( spellInfo_1->Id == 24932 && spellInfo_2->SpellIconID == 312 && spellInfo_2->SpellVisual[0] == 216 )
1359 return false;
1361 // Dragonmaw Illusion (multi-family check)
1362 if (spellId_1 == 42016 && spellId_2 == 40216 )
1363 return false;
1365 break;
1366 case SPELLFAMILY_ROGUE:
1367 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_ROGUE )
1369 // Master of Subtlety
1370 if (spellId_1 == 31665 && spellId_2 == 31666 || spellId_1 == 31666 && spellId_2 == 31665 )
1371 return false;
1374 // Garrote -> Garrote-Silence (multi-family check)
1375 if( spellInfo_1->SpellIconID == 498 && spellInfo_2->SpellIconID == 498 && spellInfo_2->SpellVisual[0] == 0 )
1376 return false;
1377 break;
1378 case SPELLFAMILY_HUNTER:
1379 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_HUNTER )
1381 // Rapid Fire & Quick Shots
1382 if( (spellInfo_1->SpellFamilyFlags & 0x20) && (spellInfo_2->SpellFamilyFlags & 0x20000000000LL) ||
1383 (spellInfo_2->SpellFamilyFlags & 0x20) && (spellInfo_1->SpellFamilyFlags & 0x20000000000LL) )
1384 return false;
1386 // Serpent Sting & (Immolation/Explosive Trap Effect)
1387 if( (spellInfo_1->SpellFamilyFlags & 0x4) && (spellInfo_2->SpellFamilyFlags & 0x00000004000LL) ||
1388 (spellInfo_2->SpellFamilyFlags & 0x4) && (spellInfo_1->SpellFamilyFlags & 0x00000004000LL) )
1389 return false;
1391 // Bestial Wrath
1392 if( spellInfo_1->SpellIconID == 1680 && spellInfo_2->SpellIconID == 1680 )
1393 return false;
1396 // Wing Clip -> Improved Wing Clip (multi-family check)
1397 if( (spellInfo_1->SpellFamilyFlags & 0x40) && spellInfo_2->Id == 19229 )
1398 return false;
1400 // Concussive Shot and Imp. Concussive Shot (multi-family check)
1401 if( spellInfo_2->Id == 19410 && spellInfo_1->Id == 5116 )
1402 return false;
1403 break;
1404 case SPELLFAMILY_PALADIN:
1405 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_PALADIN )
1407 // Paladin Seals
1408 if( IsSealSpell(spellInfo_1) && IsSealSpell(spellInfo_2) )
1409 return true;
1411 // Combustion and Fire Protection Aura (multi-family check)
1412 if( spellInfo_2->Id == 11129 && spellInfo_1->SpellIconID == 33 && spellInfo_1->SpellVisual[0] == 321 )
1413 return false;
1415 // *Sanctity Aura -> Unstable Currents and other (multi-family check)
1416 if( spellInfo_1->SpellIconID==502 && spellInfo_2->SpellFamilyName == SPELLFAMILY_GENERIC && spellInfo_2->SpellIconID==502 && spellInfo_2->SpellVisual[0]==969 )
1417 return false;
1419 // *Seal of Command and Band of Eternal Champion (multi-family check)
1420 if( spellInfo_1->SpellIconID==561 && spellInfo_1->SpellVisual[0]==7992 && spellId_2 == 35081)
1421 return false;
1422 break;
1423 case SPELLFAMILY_SHAMAN:
1424 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_SHAMAN )
1426 // shaman shields
1427 if( IsElementalShield(spellInfo_1) && IsElementalShield(spellInfo_2) )
1428 return true;
1430 // Windfury weapon
1431 if( spellInfo_1->SpellIconID==220 && spellInfo_2->SpellIconID==220 &&
1432 spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags )
1433 return false;
1435 // Bloodlust and Bloodthirst (multi-family check)
1436 if( spellInfo_1->Id == 2825 && spellInfo_2->SpellIconID == 38 && spellInfo_2->SpellVisual[0] == 0 )
1437 return false;
1438 break;
1439 default:
1440 break;
1443 // more generic checks
1444 if (spellInfo_1->SpellIconID == spellInfo_2->SpellIconID &&
1445 spellInfo_1->SpellIconID != 0 && spellInfo_2->SpellIconID != 0)
1447 bool isModifier = false;
1448 for (int i = 0; i < 3; i++)
1450 if (spellInfo_1->EffectApplyAuraName[i] == SPELL_AURA_ADD_FLAT_MODIFIER ||
1451 spellInfo_1->EffectApplyAuraName[i] == SPELL_AURA_ADD_PCT_MODIFIER ||
1452 spellInfo_2->EffectApplyAuraName[i] == SPELL_AURA_ADD_FLAT_MODIFIER ||
1453 spellInfo_2->EffectApplyAuraName[i] == SPELL_AURA_ADD_PCT_MODIFIER )
1454 isModifier = true;
1457 if (!isModifier)
1458 return true;
1461 if (IsRankSpellDueToSpell(spellInfo_1, spellId_2))
1462 return true;
1464 if (spellInfo_1->SpellFamilyName == 0 || spellInfo_2->SpellFamilyName == 0)
1465 return false;
1467 if (spellInfo_1->SpellFamilyName != spellInfo_2->SpellFamilyName)
1468 return false;
1470 for (int i = 0; i < 3; ++i)
1471 if (spellInfo_1->Effect[i] != spellInfo_2->Effect[i] ||
1472 spellInfo_1->EffectItemType[i] != spellInfo_2->EffectItemType[i] ||
1473 spellInfo_1->EffectMiscValue[i] != spellInfo_2->EffectMiscValue[i] ||
1474 spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i])
1475 return false;
1477 return true;
1480 bool SpellMgr::IsProfessionOrRidingSpell(uint32 spellId)
1482 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1483 if(!spellInfo)
1484 return false;
1486 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1487 return false;
1489 uint32 skill = spellInfo->EffectMiscValue[1];
1491 return IsProfessionOrRidingSkill(skill);
1494 bool SpellMgr::IsProfessionSpell(uint32 spellId)
1496 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1497 if(!spellInfo)
1498 return false;
1500 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1501 return false;
1503 uint32 skill = spellInfo->EffectMiscValue[1];
1505 return IsProfessionSkill(skill);
1508 bool SpellMgr::IsPrimaryProfessionSpell(uint32 spellId)
1510 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1511 if(!spellInfo)
1512 return false;
1514 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1515 return false;
1517 uint32 skill = spellInfo->EffectMiscValue[1];
1519 return IsPrimaryProfessionSkill(skill);
1522 bool SpellMgr::IsPrimaryProfessionFirstRankSpell(uint32 spellId) const
1524 return IsPrimaryProfessionSpell(spellId) && GetSpellRank(spellId)==1;
1527 bool SpellMgr::IsSkillBonusSpell(uint32 spellId) const
1529 SkillLineAbilityMap::const_iterator lower = GetBeginSkillLineAbilityMap(spellId);
1530 SkillLineAbilityMap::const_iterator upper = GetEndSkillLineAbilityMap(spellId);
1532 for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx)
1534 SkillLineAbilityEntry const *pAbility = _spell_idx->second;
1535 if (!pAbility || pAbility->learnOnGetSkill != ABILITY_LEARNED_ON_GET_PROFESSION_SKILL)
1536 continue;
1538 if(pAbility->req_skill_value > 0)
1539 return true;
1542 return false;
1545 SpellEntry const* SpellMgr::SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const
1547 // ignore passive spells
1548 if(IsPassiveSpell(spellInfo->Id))
1549 return spellInfo;
1551 bool needRankSelection = false;
1552 for(int i=0;i<3;i++)
1554 if( IsPositiveEffect(spellInfo->Id, i) && (
1555 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA ||
1556 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
1557 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_RAID
1560 needRankSelection = true;
1561 break;
1565 // not required
1566 if(!needRankSelection)
1567 return spellInfo;
1569 for(uint32 nextSpellId = spellInfo->Id; nextSpellId != 0; nextSpellId = GetPrevSpellInChain(nextSpellId))
1571 SpellEntry const *nextSpellInfo = sSpellStore.LookupEntry(nextSpellId);
1572 if(!nextSpellInfo)
1573 break;
1575 // if found appropriate level
1576 if(playerLevel + 10 >= nextSpellInfo->spellLevel)
1577 return nextSpellInfo;
1579 // one rank less then
1582 // not found
1583 return NULL;
1586 void SpellMgr::LoadSpellChains()
1588 mSpellChains.clear(); // need for reload case
1589 mSpellChainsNext.clear(); // need for reload case
1591 QueryResult *result = WorldDatabase.Query("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain");
1592 if(result == NULL)
1594 barGoLink bar( 1 );
1595 bar.step();
1597 sLog.outString();
1598 sLog.outString( ">> Loaded 0 spell chain records" );
1599 sLog.outErrorDb("`spell_chains` table is empty!");
1600 return;
1603 uint32 count = 0;
1605 barGoLink bar( result->GetRowCount() );
1608 bar.step();
1609 Field *fields = result->Fetch();
1611 uint32 spell_id = fields[0].GetUInt32();
1613 SpellChainNode node;
1614 node.prev = fields[1].GetUInt32();
1615 node.first = fields[2].GetUInt32();
1616 node.rank = fields[3].GetUInt8();
1617 node.req = fields[4].GetUInt32();
1619 if(!sSpellStore.LookupEntry(spell_id))
1621 sLog.outErrorDb("Spell %u listed in `spell_chain` does not exist",spell_id);
1622 continue;
1625 if(node.prev!=0 && !sSpellStore.LookupEntry(node.prev))
1627 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existed previous rank spell.",
1628 spell_id,node.prev,node.first,node.rank,node.req);
1629 continue;
1632 if(!sSpellStore.LookupEntry(node.first))
1634 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing first rank spell.",
1635 spell_id,node.prev,node.first,node.rank,node.req);
1636 continue;
1639 // check basic spell chain data integrity (note: rank can be equal 0 or 1 for first/single spell)
1640 if( (spell_id == node.first) != (node.rank <= 1) ||
1641 (spell_id == node.first) != (node.prev == 0) ||
1642 (node.rank <= 1) != (node.prev == 0) )
1644 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not compatible chain data.",
1645 spell_id,node.prev,node.first,node.rank,node.req);
1646 continue;
1649 if(node.req!=0 && !sSpellStore.LookupEntry(node.req))
1651 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing required spell.",
1652 spell_id,node.prev,node.first,node.rank,node.req);
1653 continue;
1656 // talents not required data in spell chain for work, but must be checked if present for intergrity
1657 if(TalentSpellPos const* pos = GetTalentSpellPos(spell_id))
1659 if(node.rank!=pos->rank+1)
1661 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong rank.",
1662 spell_id,node.prev,node.first,node.rank,node.req);
1663 continue;
1666 if(TalentEntry const* talentEntry = sTalentStore.LookupEntry(pos->talent_id))
1668 if(node.first!=talentEntry->RankID[0])
1670 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong first rank spell.",
1671 spell_id,node.prev,node.first,node.rank,node.req);
1672 continue;
1675 if(node.rank > 1 && node.prev != talentEntry->RankID[node.rank-1-1])
1677 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong prev rank spell.",
1678 spell_id,node.prev,node.first,node.rank,node.req);
1679 continue;
1682 /*if(node.req!=talentEntry->DependsOnSpell)
1684 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong required spell.",
1685 spell_id,node.prev,node.first,node.rank,node.req);
1686 continue;
1691 mSpellChains[spell_id] = node;
1693 if(node.prev)
1694 mSpellChainsNext.insert(SpellChainMapNext::value_type(node.prev,spell_id));
1696 if(node.req)
1697 mSpellChainsNext.insert(SpellChainMapNext::value_type(node.req,spell_id));
1699 ++count;
1700 } while( result->NextRow() );
1702 delete result;
1704 // additional integrity checks
1705 for(SpellChainMap::iterator i = mSpellChains.begin(); i != mSpellChains.end(); ++i)
1707 if(i->second.prev)
1709 SpellChainMap::iterator i_prev = mSpellChains.find(i->second.prev);
1710 if(i_prev == mSpellChains.end())
1712 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found previous rank spell in table.",
1713 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req);
1715 else if( i_prev->second.first != i->second.first )
1717 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).",
1718 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1719 i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req);
1721 else if( i_prev->second.rank+1 != i->second.rank )
1723 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).",
1724 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1725 i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req);
1729 if(i->second.req)
1731 SpellChainMap::iterator i_req = mSpellChains.find(i->second.req);
1732 if(i_req == mSpellChains.end())
1734 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found required rank spell in table.",
1735 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req);
1737 else if( i_req->second.first == i->second.first )
1739 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).",
1740 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1741 i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req);
1743 else if( i_req->second.req )
1745 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).",
1746 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1747 i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req);
1752 sLog.outString();
1753 sLog.outString( ">> Loaded %u spell chain records", count );
1756 void SpellMgr::LoadSpellLearnSkills()
1758 mSpellLearnSkills.clear(); // need for reload case
1760 // search auto-learned skills and add its to map also for use in unlearn spells/talents
1761 uint32 dbc_count = 0;
1762 barGoLink bar( sSpellStore.GetNumRows() );
1763 for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
1765 bar.step();
1766 SpellEntry const* entry = sSpellStore.LookupEntry(spell);
1768 if(!entry)
1769 continue;
1771 for(int i = 0; i < 3; ++i)
1773 if(entry->Effect[i]==SPELL_EFFECT_SKILL)
1775 SpellLearnSkillNode dbc_node;
1776 dbc_node.skill = entry->EffectMiscValue[i];
1777 if ( dbc_node.skill != SKILL_RIDING )
1778 dbc_node.value = 1;
1779 else
1780 dbc_node.value = entry->CalculateSimpleValue(i)*75;
1781 dbc_node.maxvalue = entry->CalculateSimpleValue(i)*75;
1783 mSpellLearnSkills[spell] = dbc_node;
1784 ++dbc_count;
1785 break;
1790 sLog.outString();
1791 sLog.outString( ">> Loaded %u Spell Learn Skills from DBC", dbc_count );
1794 void SpellMgr::LoadSpellLearnSpells()
1796 mSpellLearnSpells.clear(); // need for reload case
1798 // 0 1 2
1799 QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell");
1800 if(!result)
1802 barGoLink bar( 1 );
1803 bar.step();
1805 sLog.outString();
1806 sLog.outString( ">> Loaded 0 spell learn spells" );
1807 sLog.outErrorDb("`spell_learn_spell` table is empty!");
1808 return;
1811 uint32 count = 0;
1813 barGoLink bar( result->GetRowCount() );
1816 bar.step();
1817 Field *fields = result->Fetch();
1819 uint32 spell_id = fields[0].GetUInt32();
1821 SpellLearnSpellNode node;
1822 node.spell = fields[1].GetUInt32();
1823 node.active = fields[2].GetBool();
1824 node.autoLearned= false;
1826 if(!sSpellStore.LookupEntry(spell_id))
1828 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id);
1829 continue;
1832 if(!sSpellStore.LookupEntry(node.spell))
1834 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",node.spell);
1835 continue;
1838 mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell_id,node));
1840 ++count;
1841 } while( result->NextRow() );
1843 delete result;
1845 // search auto-learned spells and add its to map also for use in unlearn spells/talents
1846 uint32 dbc_count = 0;
1847 for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
1849 SpellEntry const* entry = sSpellStore.LookupEntry(spell);
1851 if(!entry)
1852 continue;
1854 for(int i = 0; i < 3; ++i)
1856 if(entry->Effect[i]==SPELL_EFFECT_LEARN_SPELL)
1858 SpellLearnSpellNode dbc_node;
1859 dbc_node.spell = entry->EffectTriggerSpell[i];
1860 dbc_node.active = true; // all dbc based learned spells is active (show in spell book or hide by client itself)
1862 // ignore learning not existed spells (broken/outdated/or generic learnig spell 483
1863 if(!sSpellStore.LookupEntry(dbc_node.spell))
1864 continue;
1866 // talent or passive spells or skill-step spells auto-casted and not need dependent learning,
1867 // pet teaching spells don't must be dependent learning (casted)
1868 // other required explicit dependent learning
1869 dbc_node.autoLearned = entry->EffectImplicitTargetA[i]==TARGET_PET || GetTalentSpellCost(spell) > 0 || IsPassiveSpell(spell) || IsSpellHaveEffect(entry,SPELL_EFFECT_SKILL_STEP);
1871 SpellLearnSpellMap::const_iterator db_node_begin = GetBeginSpellLearnSpell(spell);
1872 SpellLearnSpellMap::const_iterator db_node_end = GetEndSpellLearnSpell(spell);
1874 bool found = false;
1875 for(SpellLearnSpellMap::const_iterator itr = db_node_begin; itr != db_node_end; ++itr)
1877 if(itr->second.spell == dbc_node.spell)
1879 sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.",
1880 spell,dbc_node.spell);
1881 found = true;
1882 break;
1886 if(!found) // add new spell-spell pair if not found
1888 mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node));
1889 ++dbc_count;
1895 sLog.outString();
1896 sLog.outString( ">> Loaded %u spell learn spells + %u found in DBC", count, dbc_count );
1899 void SpellMgr::LoadSpellScriptTarget()
1901 mSpellScriptTarget.clear(); // need for reload case
1903 uint32 count = 0;
1905 QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target");
1907 if(!result)
1909 barGoLink bar(1);
1911 bar.step();
1913 sLog.outString();
1914 sLog.outErrorDb(">> Loaded 0 SpellScriptTarget. DB table `spell_script_target` is empty.");
1915 return;
1918 barGoLink bar(result->GetRowCount());
1922 Field *fields = result->Fetch();
1923 bar.step();
1925 uint32 spellId = fields[0].GetUInt32();
1926 uint32 type = fields[1].GetUInt32();
1927 uint32 targetEntry = fields[2].GetUInt32();
1929 SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId);
1931 if(!spellProto)
1933 sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist.",spellId,targetEntry);
1934 continue;
1937 bool targetfound = false;
1938 for(int i = 0; i <3; ++i)
1940 if( spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT ||
1941 spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT ||
1942 spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT_COORDINATES ||
1943 spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT_COORDINATES )
1945 targetfound = true;
1946 break;
1949 if(!targetfound)
1951 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);
1952 continue;
1955 if( type >= MAX_SPELL_TARGET_TYPE )
1957 sLog.outErrorDb("Table `spell_script_target`: target type %u for TargetEntry %u is incorrect.",type,targetEntry);
1958 continue;
1961 switch(type)
1963 case SPELL_TARGET_TYPE_GAMEOBJECT:
1965 if( targetEntry==0 )
1966 break;
1968 if(!sGOStorage.LookupEntry<GameObjectInfo>(targetEntry))
1970 sLog.outErrorDb("Table `spell_script_target`: gameobject template entry %u does not exist.",targetEntry);
1971 continue;
1973 break;
1975 default:
1977 if( targetEntry==0 )
1979 sLog.outErrorDb("Table `spell_script_target`: target entry == 0 for not GO target type (%u).",type);
1980 continue;
1982 if(!sCreatureStorage.LookupEntry<CreatureInfo>(targetEntry))
1984 sLog.outErrorDb("Table `spell_script_target`: creature template entry %u does not exist.",targetEntry);
1985 continue;
1987 const CreatureInfo* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(targetEntry);
1989 if(spellId == 30427 && !cInfo->SkinLootId)
1991 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);
1992 continue;
1994 break;
1998 mSpellScriptTarget.insert(SpellScriptTarget::value_type(spellId,SpellTargetEntry(SpellTargetType(type),targetEntry)));
2000 ++count;
2001 } while (result->NextRow());
2003 delete result;
2005 // Check all spells
2006 /* Disabled (lot errors at this moment)
2007 for(uint32 i = 1; i < sSpellStore.nCount; ++i)
2009 SpellEntry const * spellInfo = sSpellStore.LookupEntry(i);
2010 if(!spellInfo)
2011 continue;
2013 bool found = false;
2014 for(int j=0; j<3; ++j)
2016 if( spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT || spellInfo->EffectImplicitTargetA[j] != TARGET_SELF && spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT )
2018 SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(spellInfo->Id);
2019 SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(spellInfo->Id);
2020 if(lower==upper)
2022 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);
2023 break; // effects of spell
2030 sLog.outString();
2031 sLog.outString(">> Loaded %u Spell Script Targets", count);
2034 void SpellMgr::LoadSpellPetAuras()
2036 mSpellPetAuraMap.clear(); // need for reload case
2038 uint32 count = 0;
2040 // 0 1 2
2041 QueryResult *result = WorldDatabase.Query("SELECT spell, pet, aura FROM spell_pet_auras");
2042 if( !result )
2045 barGoLink bar( 1 );
2047 bar.step();
2049 sLog.outString();
2050 sLog.outString( ">> Loaded %u spell pet auras", count );
2051 return;
2054 barGoLink bar( result->GetRowCount() );
2058 Field *fields = result->Fetch();
2060 bar.step();
2062 uint16 spell = fields[0].GetUInt16();
2063 uint16 pet = fields[1].GetUInt16();
2064 uint16 aura = fields[2].GetUInt16();
2066 SpellPetAuraMap::iterator itr = mSpellPetAuraMap.find(spell);
2067 if(itr != mSpellPetAuraMap.end())
2069 itr->second.AddAura(pet, aura);
2071 else
2073 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2074 if (!spellInfo)
2076 sLog.outErrorDb("Spell %u listed in `spell_pet_auras` does not exist", spell);
2077 continue;
2079 int i = 0;
2080 for(; i < 3; ++i)
2081 if((spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA &&
2082 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_DUMMY) ||
2083 spellInfo->Effect[i] == SPELL_EFFECT_DUMMY)
2084 break;
2086 if(i == 3)
2088 sLog.outError("Spell %u listed in `spell_pet_auras` does not have dummy aura or dummy effect", spell);
2089 continue;
2092 SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(aura);
2093 if (!spellInfo2)
2095 sLog.outErrorDb("Aura %u listed in `spell_pet_auras` does not exist", aura);
2096 continue;
2099 PetAura pa(pet, aura, spellInfo->EffectImplicitTargetA[i] == TARGET_PET, spellInfo->CalculateSimpleValue(i));
2100 mSpellPetAuraMap[spell] = pa;
2103 ++count;
2104 } while( result->NextRow() );
2106 delete result;
2108 sLog.outString();
2109 sLog.outString( ">> Loaded %u spell pet auras", count );
2112 void SpellMgr::LoadPetLevelupSpellMap()
2114 CreatureFamilyEntry const *creatureFamily;
2115 SpellEntry const *spell;
2116 uint32 count = 0;
2118 for (uint32 i = 0; i < sCreatureFamilyStore.GetNumRows(); ++i)
2120 creatureFamily = sCreatureFamilyStore.LookupEntry(i);
2122 if(!creatureFamily) // not exist
2123 continue;
2125 if(creatureFamily->petTalentType < 0) // not hunter pet family
2126 continue;
2128 for(uint32 j = 0; j < sSpellStore.GetNumRows(); ++j)
2130 spell = sSpellStore.LookupEntry(j);
2132 // not exist
2133 if(!spell)
2134 continue;
2136 // not hunter spell
2137 if(spell->SpellFamilyName != SPELLFAMILY_HUNTER)
2138 continue;
2140 // not pet spell
2141 if(!(spell->SpellFamilyFlags & 0x1000000000000000LL))
2142 continue;
2144 // not Growl or Cower (generics)
2145 if(spell->SpellIconID != 201 && spell->SpellIconID != 958)
2147 switch(creatureFamily->ID)
2149 case CREATURE_FAMILY_BAT: // Bite and Sonic Blast
2150 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1577)
2151 continue;
2152 break;
2153 case CREATURE_FAMILY_BEAR: // Claw and Swipe
2154 if(spell->SpellIconID != 262 && spell->SpellIconID != 1562)
2155 continue;
2156 break;
2157 case CREATURE_FAMILY_BIRD_OF_PREY: // Claw and Snatch
2158 if(spell->SpellIconID != 262 && spell->SpellIconID != 168)
2159 continue;
2160 break;
2161 case CREATURE_FAMILY_BOAR: // Bite and Gore
2162 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1578)
2163 continue;
2164 break;
2165 case CREATURE_FAMILY_CARRION_BIRD: // Bite and Demoralizing Screech
2166 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1579)
2167 continue;
2168 break;
2169 case CREATURE_FAMILY_CAT: // Claw and Prowl and Rake
2170 if(spell->SpellIconID != 262 && spell->SpellIconID != 495 && spell->SpellIconID != 494)
2171 continue;
2172 break;
2173 case CREATURE_FAMILY_CHIMAERA: // Bite and Froststorm Breath
2174 if(spell->SpellIconID != 1680 && spell->SpellIconID != 62)
2175 continue;
2176 break;
2177 case CREATURE_FAMILY_CORE_HOUND: // Bite and Lava Breath
2178 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1197)
2179 continue;
2180 break;
2181 case CREATURE_FAMILY_CRAB: // Claw and Pin
2182 if(spell->SpellIconID != 262 && spell->SpellIconID != 2679)
2183 continue;
2184 break;
2185 case CREATURE_FAMILY_CROCOLISK: // Bite and Bad Attitude
2186 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1581)
2187 continue;
2188 break;
2189 case CREATURE_FAMILY_DEVILSAUR: // Bite and Monstrous Bite
2190 if(spell->SpellIconID != 1680 && spell->SpellIconID != 599)
2191 continue;
2192 break;
2193 case CREATURE_FAMILY_DRAGONHAWK: // Bite and Fire Breath
2194 if(spell->SpellIconID != 1680 && spell->SpellIconID != 2128)
2195 continue;
2196 break;
2197 case CREATURE_FAMILY_GORILLA: // Smack and Thunderstomp
2198 if(spell->SpellIconID != 473 && spell->SpellIconID != 148)
2199 continue;
2200 break;
2201 case CREATURE_FAMILY_HYENA: // Bite and Tendon Rip
2202 if(spell->SpellIconID != 1680 && spell->SpellIconID != 138)
2203 continue;
2204 break;
2205 case CREATURE_FAMILY_MOTH: // Serenity Dust and Smack
2206 if(spell->SpellIconID != 1714 && spell->SpellIconID != 473)
2207 continue;
2208 break;
2209 case CREATURE_FAMILY_NETHER_RAY: // Bite and Nether Shock
2210 if(spell->SpellIconID != 1680 && spell->SpellIconID != 2027)
2211 continue;
2212 break;
2213 case CREATURE_FAMILY_RAPTOR: // Claw and Savage Rend
2214 if(spell->SpellIconID != 262 && spell->SpellIconID != 245)
2215 continue;
2216 break;
2217 case CREATURE_FAMILY_RAVAGER: // Bite and Ravage
2218 if(spell->SpellIconID != 1680 && spell->SpellIconID != 2253)
2219 continue;
2220 break;
2221 case CREATURE_FAMILY_RHINO: // Smack and Stampede
2222 if(spell->SpellIconID != 473 && spell->SpellIconID != 3066)
2223 continue;
2224 break;
2225 case CREATURE_FAMILY_SCORPID: // Claw and Scorpid Poison
2226 if(spell->SpellIconID != 262 && spell->SpellIconID != 163)
2227 continue;
2228 break;
2229 case CREATURE_FAMILY_SERPENT: // Bite and Poison Spit
2230 if(spell->SpellIconID != 1680 && spell->SpellIconID != 68)
2231 continue;
2232 break;
2233 case CREATURE_FAMILY_SILITHID: // Claw and Venom Web Spray
2234 if(spell->SpellIconID != 262 && (spell->SpellIconID != 272 && spell->SpellVisual[0] != 12013))
2235 continue;
2236 break;
2237 case CREATURE_FAMILY_SPIDER: // Bite and Web
2238 if(spell->SpellIconID != 1680 && (spell->SpellIconID != 272 && spell->SpellVisual[0] != 684))
2239 continue;
2240 break;
2241 case CREATURE_FAMILY_SPIRIT_BEAST: // Claw and Prowl and Spirit Strike
2242 if(spell->SpellIconID != 262 && spell->SpellIconID != 495 && spell->SpellIconID != 255)
2243 continue;
2244 break;
2245 case CREATURE_FAMILY_SPOREBAT: // Smack and Spore Cloud
2246 if(spell->SpellIconID != 473 && spell->SpellIconID != 2681)
2247 continue;
2248 break;
2249 case CREATURE_FAMILY_TALLSTRIDER: // Claw and Dust Cloud
2250 if(spell->SpellIconID != 262 && (spell->SpellIconID != 157 && !(spell->Attributes & 0x4000000)))
2251 continue;
2252 break;
2253 case CREATURE_FAMILY_TURTLE: // Bite and Shell Shield
2254 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1588)
2255 continue;
2256 break;
2257 case CREATURE_FAMILY_WARP_STALKER: // Bite and Warp
2258 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1952)
2259 continue;
2260 break;
2261 case CREATURE_FAMILY_WASP: // Smack and Sting
2262 if(spell->SpellIconID != 473 && spell->SpellIconID != 110)
2263 continue;
2264 break;
2265 case CREATURE_FAMILY_WIND_SERPENT: // Bite and Lightning Breath
2266 if(spell->SpellIconID != 1680 && spell->SpellIconID != 62)
2267 continue;
2268 break;
2269 case CREATURE_FAMILY_WOLF: // Bite and Furious Howl
2270 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1573)
2271 continue;
2272 break;
2273 case CREATURE_FAMILY_WORM: // Acid Spit and Bite
2274 if(spell->SpellIconID != 636 && spell->SpellIconID != 1680)
2275 continue;
2276 break;
2277 default:
2278 sLog.outError("LoadPetLevelupSpellMap: Unhandled creature family %u", creatureFamily->ID);
2279 continue;
2283 mPetLevelupSpellMap[creatureFamily->ID][spell->spellLevel] = spell->Id;
2284 count++;
2288 sLog.outString();
2289 sLog.outString( ">> Loaded %u pet levelup spells", count );
2292 /// Some checks for spells, to prevent adding deprecated/broken spells for trainers, spell book, etc
2293 bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg)
2295 // not exist
2296 if(!spellInfo)
2297 return false;
2299 bool need_check_reagents = false;
2301 // check effects
2302 for(int i=0; i<3; ++i)
2304 switch(spellInfo->Effect[i])
2306 case 0:
2307 continue;
2309 // craft spell for crafting non-existed item (break client recipes list show)
2310 case SPELL_EFFECT_CREATE_ITEM:
2312 if(!ObjectMgr::GetItemPrototype( spellInfo->EffectItemType[i] ))
2314 if(msg)
2316 if(pl)
2317 ChatHandler(pl).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]);
2318 else
2319 sLog.outErrorDb("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]);
2321 return false;
2324 need_check_reagents = true;
2325 break;
2327 case SPELL_EFFECT_LEARN_SPELL:
2329 SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[i]);
2330 if( !IsSpellValid(spellInfo2,pl,msg) )
2332 if(msg)
2334 if(pl)
2335 ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
2336 else
2337 sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
2339 return false;
2341 break;
2346 if(need_check_reagents)
2348 for(int j = 0; j < 8; ++j)
2350 if(spellInfo->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype( spellInfo->Reagent[j] ))
2352 if(msg)
2354 if(pl)
2355 ChatHandler(pl).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]);
2356 else
2357 sLog.outErrorDb("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]);
2359 return false;
2364 return true;
2367 void SpellMgr::LoadSpellAreas()
2369 mSpellAreaMap.clear(); // need for reload case
2370 mSpellAreaForQuestMap.clear();
2371 mSpellAreaForActiveQuestMap.clear();
2372 mSpellAreaForQuestEndMap.clear();
2373 mSpellAreaForAuraMap.clear();
2375 uint32 count = 0;
2377 // 0 1 2 3 4 5 6 7 8
2378 QueryResult *result = WorldDatabase.Query("SELECT spell, area, quest_start, quest_start_active, quest_end, aura_spell, racemask, gender, autocast FROM spell_area");
2380 if( !result )
2382 barGoLink bar( 1 );
2384 bar.step();
2386 sLog.outString();
2387 sLog.outString( ">> Loaded %u spell area requirements", count );
2388 return;
2391 barGoLink bar( result->GetRowCount() );
2395 Field *fields = result->Fetch();
2397 bar.step();
2399 uint32 spell = fields[0].GetUInt32();
2400 SpellArea spellArea;
2401 spellArea.spellId = spell;
2402 spellArea.areaId = fields[1].GetUInt32();
2403 spellArea.questStart = fields[2].GetUInt32();
2404 spellArea.questStartCanActive = fields[3].GetBool();
2405 spellArea.questEnd = fields[4].GetUInt32();
2406 spellArea.auraSpell = fields[5].GetInt32();
2407 spellArea.raceMask = fields[6].GetUInt32();
2408 spellArea.gender = Gender(fields[7].GetUInt8());
2409 spellArea.autocast = fields[8].GetBool();
2411 if(!sSpellStore.LookupEntry(spell))
2413 sLog.outErrorDb("Spell %u listed in `spell_area` does not exist", spell);
2414 continue;
2418 bool ok = true;
2419 SpellAreaMapBounds sa_bounds = GetSpellAreaMapBounds(spellArea.spellId);
2420 for(SpellAreaMap::const_iterator itr = sa_bounds.first; itr != sa_bounds.second; ++itr)
2422 if(spellArea.spellId && itr->second.spellId && spellArea.spellId != itr->second.spellId)
2423 continue;
2424 if(spellArea.areaId && itr->second.areaId && spellArea.areaId!= itr->second.areaId)
2425 continue;
2426 if(spellArea.questStart && itr->second.questStart && spellArea.questStart!= itr->second.questStart)
2427 continue;
2428 if(spellArea.auraSpell && itr->second.auraSpell && spellArea.auraSpell!= itr->second.auraSpell)
2429 continue;
2430 if(spellArea.raceMask && itr->second.raceMask && (spellArea.raceMask & itr->second.raceMask)==0)
2431 continue;
2432 if(spellArea.gender != GENDER_NONE && itr->second.gender != GENDER_NONE && spellArea.gender!= itr->second.gender)
2433 continue;
2435 // duplicate by requirements
2436 ok =false;
2437 break;
2440 if(!ok)
2442 sLog.outErrorDb("Spell %u listed in `spell_area` already listed with similar requirements.", spell);
2443 continue;
2448 if(spellArea.areaId && !GetAreaEntryByAreaID(spellArea.areaId))
2450 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong area (%u) requirement", spell,spellArea.areaId);
2451 continue;
2454 if(spellArea.questStart && !objmgr.GetQuestTemplate(spellArea.questStart))
2456 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong start quest (%u) requirement", spell,spellArea.questStart);
2457 continue;
2460 if(spellArea.questEnd)
2462 if(!objmgr.GetQuestTemplate(spellArea.questEnd))
2464 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong end quest (%u) requirement", spell,spellArea.questEnd);
2465 continue;
2468 if(spellArea.questEnd==spellArea.questStart && !spellArea.questStartCanActive)
2470 sLog.outErrorDb("Spell %u listed in `spell_area` have quest (%u) requirement for start and end in same time", spell,spellArea.questEnd);
2471 continue;
2475 if(spellArea.auraSpell)
2477 SpellEntry const* spellInfo = sSpellStore.LookupEntry(abs(spellArea.auraSpell));
2478 if(!spellInfo)
2480 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong aura spell (%u) requirement", spell,abs(spellArea.auraSpell));
2481 continue;
2484 if(spellInfo->EffectApplyAuraName[0]!=SPELL_AURA_DUMMY && spellInfo->EffectApplyAuraName[0]!=SPELL_AURA_PHASE)
2486 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell requirement (%u) without dummy/phase aura in effect 0", spell,abs(spellArea.auraSpell));
2487 continue;
2490 if(abs(spellArea.auraSpell)==spellArea.spellId)
2492 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement for itself", spell,abs(spellArea.auraSpell));
2493 continue;
2496 // not allow autocast chains by auraSpell field (but allow use as alternative if not present)
2497 if(spellArea.autocast && spellArea.auraSpell > 0)
2499 bool chain = false;
2500 SpellAreaForAuraMapBounds saBound = GetSpellAreaForAuraMapBounds(spellArea.spellId);
2501 for(SpellAreaForAuraMap::const_iterator itr = saBound.first; itr != saBound.second; ++itr)
2503 if(itr->second->autocast && itr->second->auraSpell > 0)
2505 chain = true;
2506 break;
2510 if(chain)
2512 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura", spell,spellArea.auraSpell);
2513 continue;
2516 SpellAreaMapBounds saBound2 = GetSpellAreaMapBounds(spellArea.auraSpell);
2517 for(SpellAreaMap::const_iterator itr2 = saBound2.first; itr2 != saBound2.second; ++itr2)
2519 if(itr2->second.autocast && itr2->second.auraSpell > 0)
2521 chain = true;
2522 break;
2526 if(chain)
2528 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura", spell,spellArea.auraSpell);
2529 continue;
2534 if(spellArea.raceMask && (spellArea.raceMask & RACEMASK_ALL_PLAYABLE)==0)
2536 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong race mask (%u) requirement", spell,spellArea.raceMask);
2537 continue;
2540 if(spellArea.gender!=GENDER_NONE && spellArea.gender!=GENDER_FEMALE && spellArea.gender!=GENDER_MALE)
2542 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong gender (%u) requirement", spell,spellArea.gender);
2543 continue;
2546 SpellArea const* sa = &mSpellAreaMap.insert(SpellAreaMap::value_type(spell,spellArea))->second;
2548 // for search by current zone/subzone at zone/subzone change
2549 if(spellArea.areaId)
2550 mSpellAreaForAreaMap.insert(SpellAreaForAreaMap::value_type(spellArea.areaId,sa));
2552 // for search at quest start/reward
2553 if(spellArea.questStart)
2555 if(spellArea.questStartCanActive)
2556 mSpellAreaForActiveQuestMap.insert(SpellAreaForQuestMap::value_type(spellArea.questStart,sa));
2557 else
2558 mSpellAreaForQuestMap.insert(SpellAreaForQuestMap::value_type(spellArea.questStart,sa));
2561 // for search at quest start/reward
2562 if(spellArea.questEnd)
2563 mSpellAreaForQuestEndMap.insert(SpellAreaForQuestMap::value_type(spellArea.questEnd,sa));
2565 // for search at aura apply
2566 if(spellArea.auraSpell)
2567 mSpellAreaForAuraMap.insert(SpellAreaForAuraMap::value_type(abs(spellArea.auraSpell),sa));
2569 ++count;
2570 } while( result->NextRow() );
2572 delete result;
2574 sLog.outString();
2575 sLog.outString( ">> Loaded %u spell area requirements", count );
2578 SpellCastResult SpellMgr::GetSpellAllowedInLocationError(SpellEntry const *spellInfo, uint32 map_id, uint32 zone_id, uint32 area_id, Player const* player)
2580 // normal case
2581 if( spellInfo->AreaGroupId > 0)
2583 bool found = false;
2585 AreaGroupEntry const* groupEntry = sAreaGroupStore.LookupEntry(spellInfo->AreaGroupId);
2586 if(groupEntry)
2588 for (uint8 i=0; i<7; i++)
2589 if( groupEntry->AreaId[i] == zone_id || groupEntry->AreaId[i] == area_id )
2590 found = true;
2593 if(!found)
2594 return SPELL_FAILED_INCORRECT_AREA;
2597 // DB base check (if non empty then must fit at least single for allow)
2598 SpellAreaMapBounds saBounds = spellmgr.GetSpellAreaMapBounds(spellInfo->Id);
2599 if(saBounds.first != saBounds.second)
2601 for(SpellAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
2603 if(itr->second.IsFitToRequirements(player,zone_id,area_id))
2604 return SPELL_CAST_OK;
2606 return SPELL_FAILED_INCORRECT_AREA;
2609 // bg spell checks
2610 switch(spellInfo->Id)
2612 case 23333: // Warsong Flag
2613 case 23335: // Silverwing Flag
2614 return map_id == 489 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2615 case 34976: // Netherstorm Flag
2616 return map_id == 566 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2617 case 2584: // Waiting to Resurrect
2618 case 22011: // Spirit Heal Channel
2619 case 22012: // Spirit Heal
2620 case 24171: // Resurrection Impact Visual
2621 case 42792: // Recently Dropped Flag
2622 case 43681: // Inactive
2623 case 44535: // Spirit Heal (mana)
2625 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2626 if(!mapEntry)
2627 return SPELL_FAILED_INCORRECT_AREA;
2629 return mapEntry->IsBattleGround() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2631 case 44521: // Preparation
2633 if(!player)
2634 return SPELL_FAILED_REQUIRES_AREA;
2636 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2637 if(!mapEntry)
2638 return SPELL_FAILED_INCORRECT_AREA;
2640 if(!mapEntry->IsBattleGround())
2641 return SPELL_FAILED_REQUIRES_AREA;
2643 BattleGround* bg = player->GetBattleGround();
2644 return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2646 case 32724: // Gold Team (Alliance)
2647 case 32725: // Green Team (Alliance)
2648 case 35774: // Gold Team (Horde)
2649 case 35775: // Green Team (Horde)
2651 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2652 if(!mapEntry)
2653 return SPELL_FAILED_INCORRECT_AREA;
2655 return mapEntry->IsBattleArena() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2657 case 32727: // Arena Preparation
2659 if(!player)
2660 return SPELL_FAILED_REQUIRES_AREA;
2662 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2663 if(!mapEntry)
2664 return SPELL_FAILED_INCORRECT_AREA;
2666 if(!mapEntry->IsBattleArena())
2667 return SPELL_FAILED_REQUIRES_AREA;
2669 BattleGround* bg = player->GetBattleGround();
2670 return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2674 return SPELL_CAST_OK;
2677 void SpellMgr::LoadSkillLineAbilityMap()
2679 mSkillLineAbilityMap.clear();
2681 barGoLink bar( sSkillLineAbilityStore.GetNumRows() );
2682 uint32 count = 0;
2684 for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); i++)
2686 bar.step();
2687 SkillLineAbilityEntry const *SkillInfo = sSkillLineAbilityStore.LookupEntry(i);
2688 if(!SkillInfo)
2689 continue;
2691 mSkillLineAbilityMap.insert(SkillLineAbilityMap::value_type(SkillInfo->spellId,SkillInfo));
2692 ++count;
2695 sLog.outString();
2696 sLog.outString(">> Loaded %u SkillLineAbility MultiMap Data", count);
2699 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered)
2701 // Explicit Diminishing Groups
2702 switch(spellproto->SpellFamilyName)
2704 case SPELLFAMILY_ROGUE:
2706 // Kidney Shot
2707 if (spellproto->SpellFamilyFlags & 0x00000200000LL)
2708 return DIMINISHING_KIDNEYSHOT;
2709 // Blind
2710 else if (spellproto->SpellFamilyFlags & 0x00001000000LL)
2711 return DIMINISHING_BLIND_CYCLONE;
2712 break;
2714 case SPELLFAMILY_WARLOCK:
2716 // Fear
2717 if (spellproto->SpellFamilyFlags & 0x40840000000LL)
2718 return DIMINISHING_WARLOCK_FEAR;
2719 // Curses/etc
2720 else if (spellproto->SpellFamilyFlags & 0x00080000000LL)
2721 return DIMINISHING_LIMITONLY;
2722 break;
2724 case SPELLFAMILY_DRUID:
2726 // Cyclone
2727 if (spellproto->SpellFamilyFlags & 0x02000000000LL)
2728 return DIMINISHING_BLIND_CYCLONE;
2729 break;
2731 case SPELLFAMILY_WARRIOR:
2733 // Hamstring - limit duration to 10s in PvP
2734 if (spellproto->SpellFamilyFlags & 0x00000000002LL)
2735 return DIMINISHING_LIMITONLY;
2736 break;
2738 default:
2739 break;
2742 // Get by mechanic
2743 uint32 mechanic = GetAllSpellMechanicMask(spellproto);
2744 if (mechanic == MECHANIC_NONE) return DIMINISHING_NONE;
2745 if (mechanic & (1<<MECHANIC_STUN)) return triggered ? DIMINISHING_TRIGGER_STUN : DIMINISHING_CONTROL_STUN;
2746 if (mechanic & (1<<MECHANIC_SLEEP)) return DIMINISHING_SLEEP;
2747 if (mechanic & (1<<MECHANIC_POLYMORPH)) return DIMINISHING_POLYMORPH;
2748 if (mechanic & (1<<MECHANIC_ROOT)) return triggered ? DIMINISHING_TRIGGER_ROOT : DIMINISHING_CONTROL_ROOT;
2749 if (mechanic & (1<<MECHANIC_FEAR)) return DIMINISHING_FEAR;
2750 if (mechanic & (1<<MECHANIC_CHARM)) return DIMINISHING_CHARM;
2751 if (mechanic & (1<<MECHANIC_SILENCE)) return DIMINISHING_SILENCE;
2752 if (mechanic & (1<<DIMINISHING_DISARM)) return DIMINISHING_DISARM;
2753 if (mechanic & (1<<MECHANIC_FREEZE)) return DIMINISHING_FREEZE;
2754 if (mechanic & ((1<<MECHANIC_KNOCKOUT) | (1<<MECHANIC_SAPPED))) return DIMINISHING_KNOCKOUT;
2755 if (mechanic & (1<<MECHANIC_BANISH)) return DIMINISHING_BANISH;
2756 if (mechanic & (1<<MECHANIC_HORROR)) return DIMINISHING_DEATHCOIL;
2759 return DIMINISHING_NONE;
2762 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group)
2764 switch(group)
2766 case DIMINISHING_CONTROL_STUN:
2767 case DIMINISHING_TRIGGER_STUN:
2768 case DIMINISHING_KIDNEYSHOT:
2769 case DIMINISHING_SLEEP:
2770 case DIMINISHING_CONTROL_ROOT:
2771 case DIMINISHING_TRIGGER_ROOT:
2772 case DIMINISHING_FEAR:
2773 case DIMINISHING_WARLOCK_FEAR:
2774 case DIMINISHING_CHARM:
2775 case DIMINISHING_POLYMORPH:
2776 case DIMINISHING_FREEZE:
2777 case DIMINISHING_KNOCKOUT:
2778 case DIMINISHING_BLIND_CYCLONE:
2779 case DIMINISHING_BANISH:
2780 case DIMINISHING_LIMITONLY:
2781 return true;
2783 return false;
2786 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group)
2788 switch(group)
2790 case DIMINISHING_BLIND_CYCLONE:
2791 case DIMINISHING_CONTROL_STUN:
2792 case DIMINISHING_TRIGGER_STUN:
2793 case DIMINISHING_KIDNEYSHOT:
2794 return DRTYPE_ALL;
2795 case DIMINISHING_SLEEP:
2796 case DIMINISHING_CONTROL_ROOT:
2797 case DIMINISHING_TRIGGER_ROOT:
2798 case DIMINISHING_FEAR:
2799 case DIMINISHING_CHARM:
2800 case DIMINISHING_POLYMORPH:
2801 case DIMINISHING_SILENCE:
2802 case DIMINISHING_DISARM:
2803 case DIMINISHING_DEATHCOIL:
2804 case DIMINISHING_FREEZE:
2805 case DIMINISHING_BANISH:
2806 case DIMINISHING_WARLOCK_FEAR:
2807 case DIMINISHING_KNOCKOUT:
2808 return DRTYPE_PLAYER;
2811 return DRTYPE_NONE;
2814 bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32 newArea) const
2816 if(gender!=GENDER_NONE)
2818 // not in expected gender
2819 if(!player || gender != player->getGender())
2820 return false;
2823 if(raceMask)
2825 // not in expected race
2826 if(!player || !(raceMask & player->getRaceMask()))
2827 return false;
2830 if(areaId)
2832 // not in expected zone
2833 if(newZone!=areaId && newArea!=areaId)
2834 return false;
2837 if(questStart)
2839 // not in expected required quest state
2840 if(!player || (!questStartCanActive || !player->IsActiveQuest(questStart)) && !player->GetQuestRewardStatus(questStart))
2841 return false;
2844 if(questEnd)
2846 // not in expected forbidden quest state
2847 if(!player || player->GetQuestRewardStatus(questEnd))
2848 return false;
2851 if(auraSpell)
2853 // not have expected aura
2854 if(!player)
2855 return false;
2856 if(auraSpell > 0)
2857 // have expected aura
2858 return player->HasAura(auraSpell,0);
2859 else
2860 // not have expected aura
2861 return !player->HasAura(-auraSpell,0);
2864 return true;