[7664] Implement work of rogue talent 58426.
[AHbot.git] / src / game / SpellMgr.cpp
blob0b4647d98f917f53fc8513db8c1ba19f401353ca
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 // Dragonmaw Illusion, Blood Elf Illusion, Human Illusion, Illidari Agent Illusion, Scarlet Crusade Disguise
1232 if(spellInfo_1->SpellIconID == 1691 && spellInfo_2->SpellIconID == 1691)
1233 return false;
1234 break;
1235 case SPELLFAMILY_MAGE:
1236 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_MAGE )
1238 // Blizzard & Chilled (and some other stacked with blizzard spells
1239 if( (spellInfo_1->SpellFamilyFlags & 0x80) && (spellInfo_2->SpellFamilyFlags & 0x100000) ||
1240 (spellInfo_2->SpellFamilyFlags & 0x80) && (spellInfo_1->SpellFamilyFlags & 0x100000) )
1241 return false;
1243 // Blink & Improved Blink
1244 if( (spellInfo_1->SpellFamilyFlags & 0x0000000000010000LL) && (spellInfo_2->SpellVisual[0] == 72 && spellInfo_2->SpellIconID == 1499) ||
1245 (spellInfo_2->SpellFamilyFlags & 0x0000000000010000LL) && (spellInfo_1->SpellVisual[0] == 72 && spellInfo_1->SpellIconID == 1499) )
1246 return false;
1248 // Detect Invisibility and Mana Shield (multi-family check)
1249 if( spellInfo_2->Id == 132 && spellInfo_1->SpellIconID == 209 && spellInfo_1->SpellVisual[0] == 968 )
1250 return false;
1252 // Combustion and Fire Protection Aura (multi-family check)
1253 if( spellInfo_1->Id == 11129 && spellInfo_2->SpellIconID == 33 && spellInfo_2->SpellVisual[0] == 321 )
1254 return false;
1256 break;
1257 case SPELLFAMILY_WARLOCK:
1258 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_WARLOCK )
1260 // Siphon Life and Drain Life
1261 if( spellInfo_1->SpellIconID == 152 && spellInfo_2->SpellIconID == 546 ||
1262 spellInfo_2->SpellIconID == 152 && spellInfo_1->SpellIconID == 546 )
1263 return false;
1265 //Corruption & Seed of corruption
1266 if( spellInfo_1->SpellIconID == 313 && spellInfo_2->SpellIconID == 1932 ||
1267 spellInfo_2->SpellIconID == 313 && spellInfo_1->SpellIconID == 1932 )
1268 if(spellInfo_1->SpellVisual[0] != 0 && spellInfo_2->SpellVisual[0] != 0)
1269 return true; // can't be stacked
1271 // Corruption and Unstable Affliction
1272 if( spellInfo_1->SpellIconID == 313 && spellInfo_2->SpellIconID == 2039 ||
1273 spellInfo_2->SpellIconID == 313 && spellInfo_1->SpellIconID == 2039 )
1274 return false;
1276 // (Corruption or Unstable Affliction) and (Curse of Agony or Curse of Doom)
1277 if( (spellInfo_1->SpellIconID == 313 || spellInfo_1->SpellIconID == 2039) && (spellInfo_2->SpellIconID == 544 || spellInfo_2->SpellIconID == 91) ||
1278 (spellInfo_2->SpellIconID == 313 || spellInfo_2->SpellIconID == 2039) && (spellInfo_1->SpellIconID == 544 || spellInfo_1->SpellIconID == 91) )
1279 return false;
1281 // Detect Invisibility and Mana Shield (multi-family check)
1282 if( spellInfo_1->Id == 132 && spellInfo_2->SpellIconID == 209 && spellInfo_2->SpellVisual[0] == 968 )
1283 return false;
1284 break;
1285 case SPELLFAMILY_WARRIOR:
1286 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_WARRIOR )
1288 // Rend and Deep Wound
1289 if( (spellInfo_1->SpellFamilyFlags & 0x20) && (spellInfo_2->SpellFamilyFlags & 0x1000000000LL) ||
1290 (spellInfo_2->SpellFamilyFlags & 0x20) && (spellInfo_1->SpellFamilyFlags & 0x1000000000LL) )
1291 return false;
1293 // Battle Shout and Rampage
1294 if( (spellInfo_1->SpellIconID == 456 && spellInfo_2->SpellIconID == 2006) ||
1295 (spellInfo_2->SpellIconID == 456 && spellInfo_1->SpellIconID == 2006) )
1296 return false;
1299 // Hamstring -> Improved Hamstring (multi-family check)
1300 if( (spellInfo_1->SpellFamilyFlags & 2) && spellInfo_2->Id == 23694 )
1301 return false;
1303 // Defensive Stance and Scroll of Protection (multi-family check)
1304 if( spellInfo_1->Id == 71 && spellInfo_2->SpellIconID == 276 && spellInfo_2->SpellVisual[0] == 196 )
1305 return false;
1307 // Bloodlust and Bloodthirst (multi-family check)
1308 if( spellInfo_2->Id == 2825 && spellInfo_1->SpellIconID == 38 && spellInfo_1->SpellVisual[0] == 0 )
1309 return false;
1311 break;
1312 case SPELLFAMILY_PRIEST:
1313 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_PRIEST )
1315 //Devouring Plague and Shadow Vulnerability
1316 if( (spellInfo_1->SpellFamilyFlags & 0x2000000) && (spellInfo_2->SpellFamilyFlags & 0x800000000LL) ||
1317 (spellInfo_2->SpellFamilyFlags & 0x2000000) && (spellInfo_1->SpellFamilyFlags & 0x800000000LL) )
1318 return false;
1320 //StarShards and Shadow Word: Pain
1321 if( (spellInfo_1->SpellFamilyFlags & 0x200000) && (spellInfo_2->SpellFamilyFlags & 0x8000) ||
1322 (spellInfo_2->SpellFamilyFlags & 0x200000) && (spellInfo_1->SpellFamilyFlags & 0x8000) )
1323 return false;
1324 // Dispersion
1325 if( (spellInfo_1->Id == 47585 && spellInfo_2->Id == 60069) ||
1326 (spellInfo_2->Id == 47585 && spellInfo_1->Id == 60069) )
1327 return false;
1329 break;
1330 case SPELLFAMILY_DRUID:
1331 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_DRUID )
1333 //Omen of Clarity and Blood Frenzy
1334 if( (spellInfo_1->SpellFamilyFlags == 0x0 && spellInfo_1->SpellIconID == 108) && (spellInfo_2->SpellFamilyFlags & 0x20000000000000LL) ||
1335 (spellInfo_2->SpellFamilyFlags == 0x0 && spellInfo_2->SpellIconID == 108) && (spellInfo_1->SpellFamilyFlags & 0x20000000000000LL) )
1336 return false;
1338 // Tree of Life (Shapeshift) and 34123 Tree of Life (Passive)
1339 if ((spellId_1 == 33891 && spellId_2 == 34123) ||
1340 (spellId_2 == 33891 && spellId_1 == 34123))
1341 return false;
1343 // Wrath of Elune and Nature's Grace
1344 if( spellInfo_1->Id == 16886 && spellInfo_2->Id == 46833 || spellInfo_2->Id == 16886 && spellInfo_1->Id == 46833 )
1345 return false;
1347 // Bear Rage (Feral T4 (2)) and Omen of Clarity
1348 if( spellInfo_1->Id == 16864 && spellInfo_2->Id == 37306 || spellInfo_2->Id == 16864 && spellInfo_1->Id == 37306 )
1349 return false;
1351 // Cat Energy (Feral T4 (2)) and Omen of Clarity
1352 if( spellInfo_1->Id == 16864 && spellInfo_2->Id == 37311 || spellInfo_2->Id == 16864 && spellInfo_1->Id == 37311 )
1353 return false;
1355 // Survival Instincts and Survival Instincts
1356 if( spellInfo_1->Id == 61336 && spellInfo_2->Id == 50322 || spellInfo_2->Id == 61336 && spellInfo_1->Id == 50322 )
1357 return false;
1360 // Leader of the Pack and Scroll of Stamina (multi-family check)
1361 if( spellInfo_1->Id == 24932 && spellInfo_2->SpellIconID == 312 && spellInfo_2->SpellVisual[0] == 216 )
1362 return false;
1364 // Dragonmaw Illusion (multi-family check)
1365 if (spellId_1 == 42016 && spellId_2 == 40216 )
1366 return false;
1368 break;
1369 case SPELLFAMILY_ROGUE:
1370 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_ROGUE )
1372 // Master of Subtlety
1373 if (spellId_1 == 31665 && spellId_2 == 31666 || spellId_1 == 31666 && spellId_2 == 31665 )
1374 return false;
1377 //Overkill
1378 if( spellInfo_1->SpellIconID == 2285 && spellInfo_2->SpellIconID == 2285 )
1379 return false;
1381 // Garrote -> Garrote-Silence (multi-family check)
1382 if( spellInfo_1->SpellIconID == 498 && spellInfo_2->SpellIconID == 498 && spellInfo_2->SpellVisual[0] == 0 )
1383 return false;
1384 break;
1385 case SPELLFAMILY_HUNTER:
1386 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_HUNTER )
1388 // Rapid Fire & Quick Shots
1389 if( (spellInfo_1->SpellFamilyFlags & 0x20) && (spellInfo_2->SpellFamilyFlags & 0x20000000000LL) ||
1390 (spellInfo_2->SpellFamilyFlags & 0x20) && (spellInfo_1->SpellFamilyFlags & 0x20000000000LL) )
1391 return false;
1393 // Serpent Sting & (Immolation/Explosive Trap Effect)
1394 if( (spellInfo_1->SpellFamilyFlags & 0x4) && (spellInfo_2->SpellFamilyFlags & 0x00000004000LL) ||
1395 (spellInfo_2->SpellFamilyFlags & 0x4) && (spellInfo_1->SpellFamilyFlags & 0x00000004000LL) )
1396 return false;
1398 // Bestial Wrath
1399 if( spellInfo_1->SpellIconID == 1680 && spellInfo_2->SpellIconID == 1680 )
1400 return false;
1403 // Wing Clip -> Improved Wing Clip (multi-family check)
1404 if( (spellInfo_1->SpellFamilyFlags & 0x40) && spellInfo_2->Id == 19229 )
1405 return false;
1407 // Concussive Shot and Imp. Concussive Shot (multi-family check)
1408 if( spellInfo_2->Id == 19410 && spellInfo_1->Id == 5116 )
1409 return false;
1410 break;
1411 case SPELLFAMILY_PALADIN:
1412 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_PALADIN )
1414 // Paladin Seals
1415 if( IsSealSpell(spellInfo_1) && IsSealSpell(spellInfo_2) )
1416 return true;
1418 // Combustion and Fire Protection Aura (multi-family check)
1419 if( spellInfo_2->Id == 11129 && spellInfo_1->SpellIconID == 33 && spellInfo_1->SpellVisual[0] == 321 )
1420 return false;
1422 // *Sanctity Aura -> Unstable Currents and other (multi-family check)
1423 if( spellInfo_1->SpellIconID==502 && spellInfo_2->SpellFamilyName == SPELLFAMILY_GENERIC && spellInfo_2->SpellIconID==502 && spellInfo_2->SpellVisual[0]==969 )
1424 return false;
1426 // *Seal of Command and Band of Eternal Champion (multi-family check)
1427 if( spellInfo_1->SpellIconID==561 && spellInfo_1->SpellVisual[0]==7992 && spellId_2 == 35081)
1428 return false;
1429 break;
1430 case SPELLFAMILY_SHAMAN:
1431 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_SHAMAN )
1433 // shaman shields
1434 if( IsElementalShield(spellInfo_1) && IsElementalShield(spellInfo_2) )
1435 return true;
1437 // Windfury weapon
1438 if( spellInfo_1->SpellIconID==220 && spellInfo_2->SpellIconID==220 &&
1439 spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags )
1440 return false;
1442 // Bloodlust and Bloodthirst (multi-family check)
1443 if( spellInfo_1->Id == 2825 && spellInfo_2->SpellIconID == 38 && spellInfo_2->SpellVisual[0] == 0 )
1444 return false;
1445 break;
1446 default:
1447 break;
1450 // more generic checks
1451 if (spellInfo_1->SpellIconID == spellInfo_2->SpellIconID &&
1452 spellInfo_1->SpellIconID != 0 && spellInfo_2->SpellIconID != 0)
1454 bool isModifier = false;
1455 for (int i = 0; i < 3; i++)
1457 if (spellInfo_1->EffectApplyAuraName[i] == SPELL_AURA_ADD_FLAT_MODIFIER ||
1458 spellInfo_1->EffectApplyAuraName[i] == SPELL_AURA_ADD_PCT_MODIFIER ||
1459 spellInfo_2->EffectApplyAuraName[i] == SPELL_AURA_ADD_FLAT_MODIFIER ||
1460 spellInfo_2->EffectApplyAuraName[i] == SPELL_AURA_ADD_PCT_MODIFIER )
1461 isModifier = true;
1464 if (!isModifier)
1465 return true;
1468 if (IsRankSpellDueToSpell(spellInfo_1, spellId_2))
1469 return true;
1471 if (spellInfo_1->SpellFamilyName == 0 || spellInfo_2->SpellFamilyName == 0)
1472 return false;
1474 if (spellInfo_1->SpellFamilyName != spellInfo_2->SpellFamilyName)
1475 return false;
1477 for (int i = 0; i < 3; ++i)
1478 if (spellInfo_1->Effect[i] != spellInfo_2->Effect[i] ||
1479 spellInfo_1->EffectItemType[i] != spellInfo_2->EffectItemType[i] ||
1480 spellInfo_1->EffectMiscValue[i] != spellInfo_2->EffectMiscValue[i] ||
1481 spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i])
1482 return false;
1484 return true;
1487 bool SpellMgr::IsProfessionOrRidingSpell(uint32 spellId)
1489 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1490 if(!spellInfo)
1491 return false;
1493 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1494 return false;
1496 uint32 skill = spellInfo->EffectMiscValue[1];
1498 return IsProfessionOrRidingSkill(skill);
1501 bool SpellMgr::IsProfessionSpell(uint32 spellId)
1503 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1504 if(!spellInfo)
1505 return false;
1507 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1508 return false;
1510 uint32 skill = spellInfo->EffectMiscValue[1];
1512 return IsProfessionSkill(skill);
1515 bool SpellMgr::IsPrimaryProfessionSpell(uint32 spellId)
1517 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1518 if(!spellInfo)
1519 return false;
1521 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1522 return false;
1524 uint32 skill = spellInfo->EffectMiscValue[1];
1526 return IsPrimaryProfessionSkill(skill);
1529 bool SpellMgr::IsPrimaryProfessionFirstRankSpell(uint32 spellId) const
1531 return IsPrimaryProfessionSpell(spellId) && GetSpellRank(spellId)==1;
1534 bool SpellMgr::IsSkillBonusSpell(uint32 spellId) const
1536 SkillLineAbilityMap::const_iterator lower = GetBeginSkillLineAbilityMap(spellId);
1537 SkillLineAbilityMap::const_iterator upper = GetEndSkillLineAbilityMap(spellId);
1539 for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx)
1541 SkillLineAbilityEntry const *pAbility = _spell_idx->second;
1542 if (!pAbility || pAbility->learnOnGetSkill != ABILITY_LEARNED_ON_GET_PROFESSION_SKILL)
1543 continue;
1545 if(pAbility->req_skill_value > 0)
1546 return true;
1549 return false;
1552 SpellEntry const* SpellMgr::SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const
1554 // ignore passive spells
1555 if(IsPassiveSpell(spellInfo->Id))
1556 return spellInfo;
1558 bool needRankSelection = false;
1559 for(int i=0;i<3;i++)
1561 if( IsPositiveEffect(spellInfo->Id, i) && (
1562 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA ||
1563 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
1564 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_RAID
1567 needRankSelection = true;
1568 break;
1572 // not required
1573 if(!needRankSelection)
1574 return spellInfo;
1576 for(uint32 nextSpellId = spellInfo->Id; nextSpellId != 0; nextSpellId = GetPrevSpellInChain(nextSpellId))
1578 SpellEntry const *nextSpellInfo = sSpellStore.LookupEntry(nextSpellId);
1579 if(!nextSpellInfo)
1580 break;
1582 // if found appropriate level
1583 if(playerLevel + 10 >= nextSpellInfo->spellLevel)
1584 return nextSpellInfo;
1586 // one rank less then
1589 // not found
1590 return NULL;
1593 void SpellMgr::LoadSpellChains()
1595 mSpellChains.clear(); // need for reload case
1596 mSpellChainsNext.clear(); // need for reload case
1598 QueryResult *result = WorldDatabase.Query("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain");
1599 if(result == NULL)
1601 barGoLink bar( 1 );
1602 bar.step();
1604 sLog.outString();
1605 sLog.outString( ">> Loaded 0 spell chain records" );
1606 sLog.outErrorDb("`spell_chains` table is empty!");
1607 return;
1610 uint32 count = 0;
1612 barGoLink bar( result->GetRowCount() );
1615 bar.step();
1616 Field *fields = result->Fetch();
1618 uint32 spell_id = fields[0].GetUInt32();
1620 SpellChainNode node;
1621 node.prev = fields[1].GetUInt32();
1622 node.first = fields[2].GetUInt32();
1623 node.rank = fields[3].GetUInt8();
1624 node.req = fields[4].GetUInt32();
1626 if(!sSpellStore.LookupEntry(spell_id))
1628 sLog.outErrorDb("Spell %u listed in `spell_chain` does not exist",spell_id);
1629 continue;
1632 if(node.prev!=0 && !sSpellStore.LookupEntry(node.prev))
1634 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existed previous rank spell.",
1635 spell_id,node.prev,node.first,node.rank,node.req);
1636 continue;
1639 if(!sSpellStore.LookupEntry(node.first))
1641 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing first rank spell.",
1642 spell_id,node.prev,node.first,node.rank,node.req);
1643 continue;
1646 // check basic spell chain data integrity (note: rank can be equal 0 or 1 for first/single spell)
1647 if( (spell_id == node.first) != (node.rank <= 1) ||
1648 (spell_id == node.first) != (node.prev == 0) ||
1649 (node.rank <= 1) != (node.prev == 0) )
1651 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not compatible chain data.",
1652 spell_id,node.prev,node.first,node.rank,node.req);
1653 continue;
1656 if(node.req!=0 && !sSpellStore.LookupEntry(node.req))
1658 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing required spell.",
1659 spell_id,node.prev,node.first,node.rank,node.req);
1660 continue;
1663 // talents not required data in spell chain for work, but must be checked if present for intergrity
1664 if(TalentSpellPos const* pos = GetTalentSpellPos(spell_id))
1666 if(node.rank!=pos->rank+1)
1668 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong rank.",
1669 spell_id,node.prev,node.first,node.rank,node.req);
1670 continue;
1673 if(TalentEntry const* talentEntry = sTalentStore.LookupEntry(pos->talent_id))
1675 if(node.first!=talentEntry->RankID[0])
1677 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong first rank spell.",
1678 spell_id,node.prev,node.first,node.rank,node.req);
1679 continue;
1682 if(node.rank > 1 && node.prev != talentEntry->RankID[node.rank-1-1])
1684 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong prev rank spell.",
1685 spell_id,node.prev,node.first,node.rank,node.req);
1686 continue;
1689 /*if(node.req!=talentEntry->DependsOnSpell)
1691 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong required spell.",
1692 spell_id,node.prev,node.first,node.rank,node.req);
1693 continue;
1698 mSpellChains[spell_id] = node;
1700 if(node.prev)
1701 mSpellChainsNext.insert(SpellChainMapNext::value_type(node.prev,spell_id));
1703 if(node.req)
1704 mSpellChainsNext.insert(SpellChainMapNext::value_type(node.req,spell_id));
1706 ++count;
1707 } while( result->NextRow() );
1709 delete result;
1711 // additional integrity checks
1712 for(SpellChainMap::iterator i = mSpellChains.begin(); i != mSpellChains.end(); ++i)
1714 if(i->second.prev)
1716 SpellChainMap::iterator i_prev = mSpellChains.find(i->second.prev);
1717 if(i_prev == mSpellChains.end())
1719 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found previous rank spell in table.",
1720 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req);
1722 else if( i_prev->second.first != i->second.first )
1724 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).",
1725 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1726 i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req);
1728 else if( i_prev->second.rank+1 != i->second.rank )
1730 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).",
1731 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1732 i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req);
1736 if(i->second.req)
1738 SpellChainMap::iterator i_req = mSpellChains.find(i->second.req);
1739 if(i_req == mSpellChains.end())
1741 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found required rank spell in table.",
1742 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req);
1744 else if( i_req->second.first == i->second.first )
1746 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).",
1747 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1748 i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req);
1750 else if( i_req->second.req )
1752 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).",
1753 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1754 i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req);
1759 sLog.outString();
1760 sLog.outString( ">> Loaded %u spell chain records", count );
1763 void SpellMgr::LoadSpellLearnSkills()
1765 mSpellLearnSkills.clear(); // need for reload case
1767 // search auto-learned skills and add its to map also for use in unlearn spells/talents
1768 uint32 dbc_count = 0;
1769 barGoLink bar( sSpellStore.GetNumRows() );
1770 for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
1772 bar.step();
1773 SpellEntry const* entry = sSpellStore.LookupEntry(spell);
1775 if(!entry)
1776 continue;
1778 for(int i = 0; i < 3; ++i)
1780 if(entry->Effect[i]==SPELL_EFFECT_SKILL)
1782 SpellLearnSkillNode dbc_node;
1783 dbc_node.skill = entry->EffectMiscValue[i];
1784 if ( dbc_node.skill != SKILL_RIDING )
1785 dbc_node.value = 1;
1786 else
1787 dbc_node.value = entry->CalculateSimpleValue(i)*75;
1788 dbc_node.maxvalue = entry->CalculateSimpleValue(i)*75;
1790 mSpellLearnSkills[spell] = dbc_node;
1791 ++dbc_count;
1792 break;
1797 sLog.outString();
1798 sLog.outString( ">> Loaded %u Spell Learn Skills from DBC", dbc_count );
1801 void SpellMgr::LoadSpellLearnSpells()
1803 mSpellLearnSpells.clear(); // need for reload case
1805 // 0 1 2
1806 QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell");
1807 if(!result)
1809 barGoLink bar( 1 );
1810 bar.step();
1812 sLog.outString();
1813 sLog.outString( ">> Loaded 0 spell learn spells" );
1814 sLog.outErrorDb("`spell_learn_spell` table is empty!");
1815 return;
1818 uint32 count = 0;
1820 barGoLink bar( result->GetRowCount() );
1823 bar.step();
1824 Field *fields = result->Fetch();
1826 uint32 spell_id = fields[0].GetUInt32();
1828 SpellLearnSpellNode node;
1829 node.spell = fields[1].GetUInt32();
1830 node.active = fields[2].GetBool();
1831 node.autoLearned= false;
1833 if(!sSpellStore.LookupEntry(spell_id))
1835 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id);
1836 continue;
1839 if(!sSpellStore.LookupEntry(node.spell))
1841 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",node.spell);
1842 continue;
1845 mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell_id,node));
1847 ++count;
1848 } while( result->NextRow() );
1850 delete result;
1852 // search auto-learned spells and add its to map also for use in unlearn spells/talents
1853 uint32 dbc_count = 0;
1854 for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
1856 SpellEntry const* entry = sSpellStore.LookupEntry(spell);
1858 if(!entry)
1859 continue;
1861 for(int i = 0; i < 3; ++i)
1863 if(entry->Effect[i]==SPELL_EFFECT_LEARN_SPELL)
1865 SpellLearnSpellNode dbc_node;
1866 dbc_node.spell = entry->EffectTriggerSpell[i];
1867 dbc_node.active = true; // all dbc based learned spells is active (show in spell book or hide by client itself)
1869 // ignore learning not existed spells (broken/outdated/or generic learnig spell 483
1870 if(!sSpellStore.LookupEntry(dbc_node.spell))
1871 continue;
1873 // talent or passive spells or skill-step spells auto-casted and not need dependent learning,
1874 // pet teaching spells don't must be dependent learning (casted)
1875 // other required explicit dependent learning
1876 dbc_node.autoLearned = entry->EffectImplicitTargetA[i]==TARGET_PET || GetTalentSpellCost(spell) > 0 || IsPassiveSpell(spell) || IsSpellHaveEffect(entry,SPELL_EFFECT_SKILL_STEP);
1878 SpellLearnSpellMap::const_iterator db_node_begin = GetBeginSpellLearnSpell(spell);
1879 SpellLearnSpellMap::const_iterator db_node_end = GetEndSpellLearnSpell(spell);
1881 bool found = false;
1882 for(SpellLearnSpellMap::const_iterator itr = db_node_begin; itr != db_node_end; ++itr)
1884 if(itr->second.spell == dbc_node.spell)
1886 sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.",
1887 spell,dbc_node.spell);
1888 found = true;
1889 break;
1893 if(!found) // add new spell-spell pair if not found
1895 mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node));
1896 ++dbc_count;
1902 sLog.outString();
1903 sLog.outString( ">> Loaded %u spell learn spells + %u found in DBC", count, dbc_count );
1906 void SpellMgr::LoadSpellScriptTarget()
1908 mSpellScriptTarget.clear(); // need for reload case
1910 uint32 count = 0;
1912 QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target");
1914 if(!result)
1916 barGoLink bar(1);
1918 bar.step();
1920 sLog.outString();
1921 sLog.outErrorDb(">> Loaded 0 SpellScriptTarget. DB table `spell_script_target` is empty.");
1922 return;
1925 barGoLink bar(result->GetRowCount());
1929 Field *fields = result->Fetch();
1930 bar.step();
1932 uint32 spellId = fields[0].GetUInt32();
1933 uint32 type = fields[1].GetUInt32();
1934 uint32 targetEntry = fields[2].GetUInt32();
1936 SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId);
1938 if(!spellProto)
1940 sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist.",spellId,targetEntry);
1941 continue;
1944 bool targetfound = false;
1945 for(int i = 0; i <3; ++i)
1947 if( spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT ||
1948 spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT ||
1949 spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT_COORDINATES ||
1950 spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT_COORDINATES )
1952 targetfound = true;
1953 break;
1956 if(!targetfound)
1958 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);
1959 continue;
1962 if( type >= MAX_SPELL_TARGET_TYPE )
1964 sLog.outErrorDb("Table `spell_script_target`: target type %u for TargetEntry %u is incorrect.",type,targetEntry);
1965 continue;
1968 switch(type)
1970 case SPELL_TARGET_TYPE_GAMEOBJECT:
1972 if( targetEntry==0 )
1973 break;
1975 if(!sGOStorage.LookupEntry<GameObjectInfo>(targetEntry))
1977 sLog.outErrorDb("Table `spell_script_target`: gameobject template entry %u does not exist.",targetEntry);
1978 continue;
1980 break;
1982 default:
1984 if( targetEntry==0 )
1986 sLog.outErrorDb("Table `spell_script_target`: target entry == 0 for not GO target type (%u).",type);
1987 continue;
1989 if(!sCreatureStorage.LookupEntry<CreatureInfo>(targetEntry))
1991 sLog.outErrorDb("Table `spell_script_target`: creature template entry %u does not exist.",targetEntry);
1992 continue;
1994 const CreatureInfo* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(targetEntry);
1996 if(spellId == 30427 && !cInfo->SkinLootId)
1998 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);
1999 continue;
2001 break;
2005 mSpellScriptTarget.insert(SpellScriptTarget::value_type(spellId,SpellTargetEntry(SpellTargetType(type),targetEntry)));
2007 ++count;
2008 } while (result->NextRow());
2010 delete result;
2012 // Check all spells
2013 /* Disabled (lot errors at this moment)
2014 for(uint32 i = 1; i < sSpellStore.nCount; ++i)
2016 SpellEntry const * spellInfo = sSpellStore.LookupEntry(i);
2017 if(!spellInfo)
2018 continue;
2020 bool found = false;
2021 for(int j=0; j<3; ++j)
2023 if( spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT || spellInfo->EffectImplicitTargetA[j] != TARGET_SELF && spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT )
2025 SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(spellInfo->Id);
2026 SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(spellInfo->Id);
2027 if(lower==upper)
2029 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);
2030 break; // effects of spell
2037 sLog.outString();
2038 sLog.outString(">> Loaded %u Spell Script Targets", count);
2041 void SpellMgr::LoadSpellPetAuras()
2043 mSpellPetAuraMap.clear(); // need for reload case
2045 uint32 count = 0;
2047 // 0 1 2
2048 QueryResult *result = WorldDatabase.Query("SELECT spell, pet, aura FROM spell_pet_auras");
2049 if( !result )
2052 barGoLink bar( 1 );
2054 bar.step();
2056 sLog.outString();
2057 sLog.outString( ">> Loaded %u spell pet auras", count );
2058 return;
2061 barGoLink bar( result->GetRowCount() );
2065 Field *fields = result->Fetch();
2067 bar.step();
2069 uint16 spell = fields[0].GetUInt16();
2070 uint16 pet = fields[1].GetUInt16();
2071 uint16 aura = fields[2].GetUInt16();
2073 SpellPetAuraMap::iterator itr = mSpellPetAuraMap.find(spell);
2074 if(itr != mSpellPetAuraMap.end())
2076 itr->second.AddAura(pet, aura);
2078 else
2080 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2081 if (!spellInfo)
2083 sLog.outErrorDb("Spell %u listed in `spell_pet_auras` does not exist", spell);
2084 continue;
2086 int i = 0;
2087 for(; i < 3; ++i)
2088 if((spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA &&
2089 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_DUMMY) ||
2090 spellInfo->Effect[i] == SPELL_EFFECT_DUMMY)
2091 break;
2093 if(i == 3)
2095 sLog.outError("Spell %u listed in `spell_pet_auras` does not have dummy aura or dummy effect", spell);
2096 continue;
2099 SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(aura);
2100 if (!spellInfo2)
2102 sLog.outErrorDb("Aura %u listed in `spell_pet_auras` does not exist", aura);
2103 continue;
2106 PetAura pa(pet, aura, spellInfo->EffectImplicitTargetA[i] == TARGET_PET, spellInfo->CalculateSimpleValue(i));
2107 mSpellPetAuraMap[spell] = pa;
2110 ++count;
2111 } while( result->NextRow() );
2113 delete result;
2115 sLog.outString();
2116 sLog.outString( ">> Loaded %u spell pet auras", count );
2119 void SpellMgr::LoadPetLevelupSpellMap()
2121 CreatureFamilyEntry const *creatureFamily;
2122 SpellEntry const *spell;
2123 uint32 count = 0;
2125 for (uint32 i = 0; i < sCreatureFamilyStore.GetNumRows(); ++i)
2127 creatureFamily = sCreatureFamilyStore.LookupEntry(i);
2129 if(!creatureFamily) // not exist
2130 continue;
2132 if(creatureFamily->petTalentType < 0) // not hunter pet family
2133 continue;
2135 for(uint32 j = 0; j < sSpellStore.GetNumRows(); ++j)
2137 spell = sSpellStore.LookupEntry(j);
2139 // not exist
2140 if(!spell)
2141 continue;
2143 // not hunter spell
2144 if(spell->SpellFamilyName != SPELLFAMILY_HUNTER)
2145 continue;
2147 // not pet spell
2148 if(!(spell->SpellFamilyFlags & 0x1000000000000000LL))
2149 continue;
2151 // not Growl or Cower (generics)
2152 if(spell->SpellIconID != 201 && spell->SpellIconID != 958)
2154 switch(creatureFamily->ID)
2156 case CREATURE_FAMILY_BAT: // Bite and Sonic Blast
2157 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1577)
2158 continue;
2159 break;
2160 case CREATURE_FAMILY_BEAR: // Claw and Swipe
2161 if(spell->SpellIconID != 262 && spell->SpellIconID != 1562)
2162 continue;
2163 break;
2164 case CREATURE_FAMILY_BIRD_OF_PREY: // Claw and Snatch
2165 if(spell->SpellIconID != 262 && spell->SpellIconID != 168)
2166 continue;
2167 break;
2168 case CREATURE_FAMILY_BOAR: // Bite and Gore
2169 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1578)
2170 continue;
2171 break;
2172 case CREATURE_FAMILY_CARRION_BIRD: // Bite and Demoralizing Screech
2173 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1579)
2174 continue;
2175 break;
2176 case CREATURE_FAMILY_CAT: // Claw and Prowl and Rake
2177 if(spell->SpellIconID != 262 && spell->SpellIconID != 495 && spell->SpellIconID != 494)
2178 continue;
2179 break;
2180 case CREATURE_FAMILY_CHIMAERA: // Bite and Froststorm Breath
2181 if(spell->SpellIconID != 1680 && spell->SpellIconID != 62)
2182 continue;
2183 break;
2184 case CREATURE_FAMILY_CORE_HOUND: // Bite and Lava Breath
2185 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1197)
2186 continue;
2187 break;
2188 case CREATURE_FAMILY_CRAB: // Claw and Pin
2189 if(spell->SpellIconID != 262 && spell->SpellIconID != 2679)
2190 continue;
2191 break;
2192 case CREATURE_FAMILY_CROCOLISK: // Bite and Bad Attitude
2193 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1581)
2194 continue;
2195 break;
2196 case CREATURE_FAMILY_DEVILSAUR: // Bite and Monstrous Bite
2197 if(spell->SpellIconID != 1680 && spell->SpellIconID != 599)
2198 continue;
2199 break;
2200 case CREATURE_FAMILY_DRAGONHAWK: // Bite and Fire Breath
2201 if(spell->SpellIconID != 1680 && spell->SpellIconID != 2128)
2202 continue;
2203 break;
2204 case CREATURE_FAMILY_GORILLA: // Smack and Thunderstomp
2205 if(spell->SpellIconID != 473 && spell->SpellIconID != 148)
2206 continue;
2207 break;
2208 case CREATURE_FAMILY_HYENA: // Bite and Tendon Rip
2209 if(spell->SpellIconID != 1680 && spell->SpellIconID != 138)
2210 continue;
2211 break;
2212 case CREATURE_FAMILY_MOTH: // Serenity Dust and Smack
2213 if(spell->SpellIconID != 1714 && spell->SpellIconID != 473)
2214 continue;
2215 break;
2216 case CREATURE_FAMILY_NETHER_RAY: // Bite and Nether Shock
2217 if(spell->SpellIconID != 1680 && spell->SpellIconID != 2027)
2218 continue;
2219 break;
2220 case CREATURE_FAMILY_RAPTOR: // Claw and Savage Rend
2221 if(spell->SpellIconID != 262 && spell->SpellIconID != 245)
2222 continue;
2223 break;
2224 case CREATURE_FAMILY_RAVAGER: // Bite and Ravage
2225 if(spell->SpellIconID != 1680 && spell->SpellIconID != 2253)
2226 continue;
2227 break;
2228 case CREATURE_FAMILY_RHINO: // Smack and Stampede
2229 if(spell->SpellIconID != 473 && spell->SpellIconID != 3066)
2230 continue;
2231 break;
2232 case CREATURE_FAMILY_SCORPID: // Claw and Scorpid Poison
2233 if(spell->SpellIconID != 262 && spell->SpellIconID != 163)
2234 continue;
2235 break;
2236 case CREATURE_FAMILY_SERPENT: // Bite and Poison Spit
2237 if(spell->SpellIconID != 1680 && spell->SpellIconID != 68)
2238 continue;
2239 break;
2240 case CREATURE_FAMILY_SILITHID: // Claw and Venom Web Spray
2241 if(spell->SpellIconID != 262 && (spell->SpellIconID != 272 && spell->SpellVisual[0] != 12013))
2242 continue;
2243 break;
2244 case CREATURE_FAMILY_SPIDER: // Bite and Web
2245 if(spell->SpellIconID != 1680 && (spell->SpellIconID != 272 && spell->SpellVisual[0] != 684))
2246 continue;
2247 break;
2248 case CREATURE_FAMILY_SPIRIT_BEAST: // Claw and Prowl and Spirit Strike
2249 if(spell->SpellIconID != 262 && spell->SpellIconID != 495 && spell->SpellIconID != 255)
2250 continue;
2251 break;
2252 case CREATURE_FAMILY_SPOREBAT: // Smack and Spore Cloud
2253 if(spell->SpellIconID != 473 && spell->SpellIconID != 2681)
2254 continue;
2255 break;
2256 case CREATURE_FAMILY_TALLSTRIDER: // Claw and Dust Cloud
2257 if(spell->SpellIconID != 262 && (spell->SpellIconID != 157 && !(spell->Attributes & 0x4000000)))
2258 continue;
2259 break;
2260 case CREATURE_FAMILY_TURTLE: // Bite and Shell Shield
2261 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1588)
2262 continue;
2263 break;
2264 case CREATURE_FAMILY_WARP_STALKER: // Bite and Warp
2265 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1952)
2266 continue;
2267 break;
2268 case CREATURE_FAMILY_WASP: // Smack and Sting
2269 if(spell->SpellIconID != 473 && spell->SpellIconID != 110)
2270 continue;
2271 break;
2272 case CREATURE_FAMILY_WIND_SERPENT: // Bite and Lightning Breath
2273 if(spell->SpellIconID != 1680 && spell->SpellIconID != 62)
2274 continue;
2275 break;
2276 case CREATURE_FAMILY_WOLF: // Bite and Furious Howl
2277 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1573)
2278 continue;
2279 break;
2280 case CREATURE_FAMILY_WORM: // Acid Spit and Bite
2281 if(spell->SpellIconID != 636 && spell->SpellIconID != 1680)
2282 continue;
2283 break;
2284 default:
2285 sLog.outError("LoadPetLevelupSpellMap: Unhandled creature family %u", creatureFamily->ID);
2286 continue;
2290 mPetLevelupSpellMap[creatureFamily->ID][spell->spellLevel] = spell->Id;
2291 count++;
2295 sLog.outString();
2296 sLog.outString( ">> Loaded %u pet levelup spells", count );
2299 /// Some checks for spells, to prevent adding deprecated/broken spells for trainers, spell book, etc
2300 bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg)
2302 // not exist
2303 if(!spellInfo)
2304 return false;
2306 bool need_check_reagents = false;
2308 // check effects
2309 for(int i=0; i<3; ++i)
2311 switch(spellInfo->Effect[i])
2313 case 0:
2314 continue;
2316 // craft spell for crafting non-existed item (break client recipes list show)
2317 case SPELL_EFFECT_CREATE_ITEM:
2319 if(!ObjectMgr::GetItemPrototype( spellInfo->EffectItemType[i] ))
2321 if(msg)
2323 if(pl)
2324 ChatHandler(pl).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]);
2325 else
2326 sLog.outErrorDb("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]);
2328 return false;
2331 need_check_reagents = true;
2332 break;
2334 case SPELL_EFFECT_LEARN_SPELL:
2336 SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[i]);
2337 if( !IsSpellValid(spellInfo2,pl,msg) )
2339 if(msg)
2341 if(pl)
2342 ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
2343 else
2344 sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
2346 return false;
2348 break;
2353 if(need_check_reagents)
2355 for(int j = 0; j < 8; ++j)
2357 if(spellInfo->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype( spellInfo->Reagent[j] ))
2359 if(msg)
2361 if(pl)
2362 ChatHandler(pl).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]);
2363 else
2364 sLog.outErrorDb("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]);
2366 return false;
2371 return true;
2374 void SpellMgr::LoadSpellAreas()
2376 mSpellAreaMap.clear(); // need for reload case
2377 mSpellAreaForQuestMap.clear();
2378 mSpellAreaForActiveQuestMap.clear();
2379 mSpellAreaForQuestEndMap.clear();
2380 mSpellAreaForAuraMap.clear();
2382 uint32 count = 0;
2384 // 0 1 2 3 4 5 6 7 8
2385 QueryResult *result = WorldDatabase.Query("SELECT spell, area, quest_start, quest_start_active, quest_end, aura_spell, racemask, gender, autocast FROM spell_area");
2387 if( !result )
2389 barGoLink bar( 1 );
2391 bar.step();
2393 sLog.outString();
2394 sLog.outString( ">> Loaded %u spell area requirements", count );
2395 return;
2398 barGoLink bar( result->GetRowCount() );
2402 Field *fields = result->Fetch();
2404 bar.step();
2406 uint32 spell = fields[0].GetUInt32();
2407 SpellArea spellArea;
2408 spellArea.spellId = spell;
2409 spellArea.areaId = fields[1].GetUInt32();
2410 spellArea.questStart = fields[2].GetUInt32();
2411 spellArea.questStartCanActive = fields[3].GetBool();
2412 spellArea.questEnd = fields[4].GetUInt32();
2413 spellArea.auraSpell = fields[5].GetInt32();
2414 spellArea.raceMask = fields[6].GetUInt32();
2415 spellArea.gender = Gender(fields[7].GetUInt8());
2416 spellArea.autocast = fields[8].GetBool();
2418 if(!sSpellStore.LookupEntry(spell))
2420 sLog.outErrorDb("Spell %u listed in `spell_area` does not exist", spell);
2421 continue;
2425 bool ok = true;
2426 SpellAreaMapBounds sa_bounds = GetSpellAreaMapBounds(spellArea.spellId);
2427 for(SpellAreaMap::const_iterator itr = sa_bounds.first; itr != sa_bounds.second; ++itr)
2429 if(spellArea.spellId && itr->second.spellId && spellArea.spellId != itr->second.spellId)
2430 continue;
2431 if(spellArea.areaId && itr->second.areaId && spellArea.areaId!= itr->second.areaId)
2432 continue;
2433 if(spellArea.questStart && itr->second.questStart && spellArea.questStart!= itr->second.questStart)
2434 continue;
2435 if(spellArea.auraSpell && itr->second.auraSpell && spellArea.auraSpell!= itr->second.auraSpell)
2436 continue;
2437 if(spellArea.raceMask && itr->second.raceMask && (spellArea.raceMask & itr->second.raceMask)==0)
2438 continue;
2439 if(spellArea.gender != GENDER_NONE && itr->second.gender != GENDER_NONE && spellArea.gender!= itr->second.gender)
2440 continue;
2442 // duplicate by requirements
2443 ok =false;
2444 break;
2447 if(!ok)
2449 sLog.outErrorDb("Spell %u listed in `spell_area` already listed with similar requirements.", spell);
2450 continue;
2455 if(spellArea.areaId && !GetAreaEntryByAreaID(spellArea.areaId))
2457 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong area (%u) requirement", spell,spellArea.areaId);
2458 continue;
2461 if(spellArea.questStart && !objmgr.GetQuestTemplate(spellArea.questStart))
2463 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong start quest (%u) requirement", spell,spellArea.questStart);
2464 continue;
2467 if(spellArea.questEnd)
2469 if(!objmgr.GetQuestTemplate(spellArea.questEnd))
2471 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong end quest (%u) requirement", spell,spellArea.questEnd);
2472 continue;
2475 if(spellArea.questEnd==spellArea.questStart && !spellArea.questStartCanActive)
2477 sLog.outErrorDb("Spell %u listed in `spell_area` have quest (%u) requirement for start and end in same time", spell,spellArea.questEnd);
2478 continue;
2482 if(spellArea.auraSpell)
2484 SpellEntry const* spellInfo = sSpellStore.LookupEntry(abs(spellArea.auraSpell));
2485 if(!spellInfo)
2487 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong aura spell (%u) requirement", spell,abs(spellArea.auraSpell));
2488 continue;
2491 if(spellInfo->EffectApplyAuraName[0]!=SPELL_AURA_DUMMY && spellInfo->EffectApplyAuraName[0]!=SPELL_AURA_PHASE)
2493 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell requirement (%u) without dummy/phase aura in effect 0", spell,abs(spellArea.auraSpell));
2494 continue;
2497 if(abs(spellArea.auraSpell)==spellArea.spellId)
2499 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement for itself", spell,abs(spellArea.auraSpell));
2500 continue;
2503 // not allow autocast chains by auraSpell field (but allow use as alternative if not present)
2504 if(spellArea.autocast && spellArea.auraSpell > 0)
2506 bool chain = false;
2507 SpellAreaForAuraMapBounds saBound = GetSpellAreaForAuraMapBounds(spellArea.spellId);
2508 for(SpellAreaForAuraMap::const_iterator itr = saBound.first; itr != saBound.second; ++itr)
2510 if(itr->second->autocast && itr->second->auraSpell > 0)
2512 chain = true;
2513 break;
2517 if(chain)
2519 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura", spell,spellArea.auraSpell);
2520 continue;
2523 SpellAreaMapBounds saBound2 = GetSpellAreaMapBounds(spellArea.auraSpell);
2524 for(SpellAreaMap::const_iterator itr2 = saBound2.first; itr2 != saBound2.second; ++itr2)
2526 if(itr2->second.autocast && itr2->second.auraSpell > 0)
2528 chain = true;
2529 break;
2533 if(chain)
2535 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura", spell,spellArea.auraSpell);
2536 continue;
2541 if(spellArea.raceMask && (spellArea.raceMask & RACEMASK_ALL_PLAYABLE)==0)
2543 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong race mask (%u) requirement", spell,spellArea.raceMask);
2544 continue;
2547 if(spellArea.gender!=GENDER_NONE && spellArea.gender!=GENDER_FEMALE && spellArea.gender!=GENDER_MALE)
2549 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong gender (%u) requirement", spell,spellArea.gender);
2550 continue;
2553 SpellArea const* sa = &mSpellAreaMap.insert(SpellAreaMap::value_type(spell,spellArea))->second;
2555 // for search by current zone/subzone at zone/subzone change
2556 if(spellArea.areaId)
2557 mSpellAreaForAreaMap.insert(SpellAreaForAreaMap::value_type(spellArea.areaId,sa));
2559 // for search at quest start/reward
2560 if(spellArea.questStart)
2562 if(spellArea.questStartCanActive)
2563 mSpellAreaForActiveQuestMap.insert(SpellAreaForQuestMap::value_type(spellArea.questStart,sa));
2564 else
2565 mSpellAreaForQuestMap.insert(SpellAreaForQuestMap::value_type(spellArea.questStart,sa));
2568 // for search at quest start/reward
2569 if(spellArea.questEnd)
2570 mSpellAreaForQuestEndMap.insert(SpellAreaForQuestMap::value_type(spellArea.questEnd,sa));
2572 // for search at aura apply
2573 if(spellArea.auraSpell)
2574 mSpellAreaForAuraMap.insert(SpellAreaForAuraMap::value_type(abs(spellArea.auraSpell),sa));
2576 ++count;
2577 } while( result->NextRow() );
2579 delete result;
2581 sLog.outString();
2582 sLog.outString( ">> Loaded %u spell area requirements", count );
2585 SpellCastResult SpellMgr::GetSpellAllowedInLocationError(SpellEntry const *spellInfo, uint32 map_id, uint32 zone_id, uint32 area_id, Player const* player)
2587 // normal case
2588 if( spellInfo->AreaGroupId > 0)
2590 bool found = false;
2592 AreaGroupEntry const* groupEntry = sAreaGroupStore.LookupEntry(spellInfo->AreaGroupId);
2593 if(groupEntry)
2595 for (uint8 i=0; i<7; i++)
2596 if( groupEntry->AreaId[i] == zone_id || groupEntry->AreaId[i] == area_id )
2597 found = true;
2600 if(!found)
2601 return SPELL_FAILED_INCORRECT_AREA;
2604 // DB base check (if non empty then must fit at least single for allow)
2605 SpellAreaMapBounds saBounds = spellmgr.GetSpellAreaMapBounds(spellInfo->Id);
2606 if(saBounds.first != saBounds.second)
2608 for(SpellAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
2610 if(itr->second.IsFitToRequirements(player,zone_id,area_id))
2611 return SPELL_CAST_OK;
2613 return SPELL_FAILED_INCORRECT_AREA;
2616 // bg spell checks
2617 switch(spellInfo->Id)
2619 case 23333: // Warsong Flag
2620 case 23335: // Silverwing Flag
2621 return map_id == 489 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2622 case 34976: // Netherstorm Flag
2623 return map_id == 566 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2624 case 2584: // Waiting to Resurrect
2625 case 22011: // Spirit Heal Channel
2626 case 22012: // Spirit Heal
2627 case 24171: // Resurrection Impact Visual
2628 case 42792: // Recently Dropped Flag
2629 case 43681: // Inactive
2630 case 44535: // Spirit Heal (mana)
2632 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2633 if(!mapEntry)
2634 return SPELL_FAILED_INCORRECT_AREA;
2636 return mapEntry->IsBattleGround() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2638 case 44521: // Preparation
2640 if(!player)
2641 return SPELL_FAILED_REQUIRES_AREA;
2643 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2644 if(!mapEntry)
2645 return SPELL_FAILED_INCORRECT_AREA;
2647 if(!mapEntry->IsBattleGround())
2648 return SPELL_FAILED_REQUIRES_AREA;
2650 BattleGround* bg = player->GetBattleGround();
2651 return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2653 case 32724: // Gold Team (Alliance)
2654 case 32725: // Green Team (Alliance)
2655 case 35774: // Gold Team (Horde)
2656 case 35775: // Green Team (Horde)
2658 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2659 if(!mapEntry)
2660 return SPELL_FAILED_INCORRECT_AREA;
2662 return mapEntry->IsBattleArena() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2664 case 32727: // Arena Preparation
2666 if(!player)
2667 return SPELL_FAILED_REQUIRES_AREA;
2669 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2670 if(!mapEntry)
2671 return SPELL_FAILED_INCORRECT_AREA;
2673 if(!mapEntry->IsBattleArena())
2674 return SPELL_FAILED_REQUIRES_AREA;
2676 BattleGround* bg = player->GetBattleGround();
2677 return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2681 return SPELL_CAST_OK;
2684 void SpellMgr::LoadSkillLineAbilityMap()
2686 mSkillLineAbilityMap.clear();
2688 barGoLink bar( sSkillLineAbilityStore.GetNumRows() );
2689 uint32 count = 0;
2691 for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); i++)
2693 bar.step();
2694 SkillLineAbilityEntry const *SkillInfo = sSkillLineAbilityStore.LookupEntry(i);
2695 if(!SkillInfo)
2696 continue;
2698 mSkillLineAbilityMap.insert(SkillLineAbilityMap::value_type(SkillInfo->spellId,SkillInfo));
2699 ++count;
2702 sLog.outString();
2703 sLog.outString(">> Loaded %u SkillLineAbility MultiMap Data", count);
2706 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered)
2708 // Explicit Diminishing Groups
2709 switch(spellproto->SpellFamilyName)
2711 case SPELLFAMILY_ROGUE:
2713 // Kidney Shot
2714 if (spellproto->SpellFamilyFlags & 0x00000200000LL)
2715 return DIMINISHING_KIDNEYSHOT;
2716 // Blind
2717 else if (spellproto->SpellFamilyFlags & 0x00001000000LL)
2718 return DIMINISHING_BLIND_CYCLONE;
2719 break;
2721 case SPELLFAMILY_WARLOCK:
2723 // Fear
2724 if (spellproto->SpellFamilyFlags & 0x40840000000LL)
2725 return DIMINISHING_WARLOCK_FEAR;
2726 // Curses/etc
2727 else if (spellproto->SpellFamilyFlags & 0x00080000000LL)
2728 return DIMINISHING_LIMITONLY;
2729 break;
2731 case SPELLFAMILY_DRUID:
2733 // Cyclone
2734 if (spellproto->SpellFamilyFlags & 0x02000000000LL)
2735 return DIMINISHING_BLIND_CYCLONE;
2736 break;
2738 case SPELLFAMILY_WARRIOR:
2740 // Hamstring - limit duration to 10s in PvP
2741 if (spellproto->SpellFamilyFlags & 0x00000000002LL)
2742 return DIMINISHING_LIMITONLY;
2743 break;
2745 default:
2746 break;
2749 // Get by mechanic
2750 uint32 mechanic = GetAllSpellMechanicMask(spellproto);
2751 if (mechanic == MECHANIC_NONE) return DIMINISHING_NONE;
2752 if (mechanic & (1<<MECHANIC_STUN)) return triggered ? DIMINISHING_TRIGGER_STUN : DIMINISHING_CONTROL_STUN;
2753 if (mechanic & (1<<MECHANIC_SLEEP)) return DIMINISHING_SLEEP;
2754 if (mechanic & (1<<MECHANIC_POLYMORPH)) return DIMINISHING_POLYMORPH;
2755 if (mechanic & (1<<MECHANIC_ROOT)) return triggered ? DIMINISHING_TRIGGER_ROOT : DIMINISHING_CONTROL_ROOT;
2756 if (mechanic & (1<<MECHANIC_FEAR)) return DIMINISHING_FEAR;
2757 if (mechanic & (1<<MECHANIC_CHARM)) return DIMINISHING_CHARM;
2758 if (mechanic & (1<<MECHANIC_SILENCE)) return DIMINISHING_SILENCE;
2759 if (mechanic & (1<<DIMINISHING_DISARM)) return DIMINISHING_DISARM;
2760 if (mechanic & (1<<MECHANIC_FREEZE)) return DIMINISHING_FREEZE;
2761 if (mechanic & ((1<<MECHANIC_KNOCKOUT) | (1<<MECHANIC_SAPPED))) return DIMINISHING_KNOCKOUT;
2762 if (mechanic & (1<<MECHANIC_BANISH)) return DIMINISHING_BANISH;
2763 if (mechanic & (1<<MECHANIC_HORROR)) return DIMINISHING_DEATHCOIL;
2766 return DIMINISHING_NONE;
2769 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group)
2771 switch(group)
2773 case DIMINISHING_CONTROL_STUN:
2774 case DIMINISHING_TRIGGER_STUN:
2775 case DIMINISHING_KIDNEYSHOT:
2776 case DIMINISHING_SLEEP:
2777 case DIMINISHING_CONTROL_ROOT:
2778 case DIMINISHING_TRIGGER_ROOT:
2779 case DIMINISHING_FEAR:
2780 case DIMINISHING_WARLOCK_FEAR:
2781 case DIMINISHING_CHARM:
2782 case DIMINISHING_POLYMORPH:
2783 case DIMINISHING_FREEZE:
2784 case DIMINISHING_KNOCKOUT:
2785 case DIMINISHING_BLIND_CYCLONE:
2786 case DIMINISHING_BANISH:
2787 case DIMINISHING_LIMITONLY:
2788 return true;
2790 return false;
2793 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group)
2795 switch(group)
2797 case DIMINISHING_BLIND_CYCLONE:
2798 case DIMINISHING_CONTROL_STUN:
2799 case DIMINISHING_TRIGGER_STUN:
2800 case DIMINISHING_KIDNEYSHOT:
2801 return DRTYPE_ALL;
2802 case DIMINISHING_SLEEP:
2803 case DIMINISHING_CONTROL_ROOT:
2804 case DIMINISHING_TRIGGER_ROOT:
2805 case DIMINISHING_FEAR:
2806 case DIMINISHING_CHARM:
2807 case DIMINISHING_POLYMORPH:
2808 case DIMINISHING_SILENCE:
2809 case DIMINISHING_DISARM:
2810 case DIMINISHING_DEATHCOIL:
2811 case DIMINISHING_FREEZE:
2812 case DIMINISHING_BANISH:
2813 case DIMINISHING_WARLOCK_FEAR:
2814 case DIMINISHING_KNOCKOUT:
2815 return DRTYPE_PLAYER;
2818 return DRTYPE_NONE;
2821 bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32 newArea) const
2823 if(gender!=GENDER_NONE)
2825 // not in expected gender
2826 if(!player || gender != player->getGender())
2827 return false;
2830 if(raceMask)
2832 // not in expected race
2833 if(!player || !(raceMask & player->getRaceMask()))
2834 return false;
2837 if(areaId)
2839 // not in expected zone
2840 if(newZone!=areaId && newArea!=areaId)
2841 return false;
2844 if(questStart)
2846 // not in expected required quest state
2847 if(!player || (!questStartCanActive || !player->IsActiveQuest(questStart)) && !player->GetQuestRewardStatus(questStart))
2848 return false;
2851 if(questEnd)
2853 // not in expected forbidden quest state
2854 if(!player || player->GetQuestRewardStatus(questEnd))
2855 return false;
2858 if(auraSpell)
2860 // not have expected aura
2861 if(!player)
2862 return false;
2863 if(auraSpell > 0)
2864 // have expected aura
2865 return player->HasAura(auraSpell,0);
2866 else
2867 // not have expected aura
2868 return !player->HasAura(-auraSpell,0);
2871 return true;