port over some changes from Trinity version including one possible memory leak fix
[AHbot.git] / src / game / SpellMgr.cpp
blob7c72d2ec2900f329e025b66b41d93a9ffc8a3cdf
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;
505 default:
506 break;
509 // single target triggered spell.
510 // Not real client side single target spell, but it' not triggered until prev. aura expired.
511 // This is allow store it in single target spells list for caster for spell proc checking
512 if(spellInfo->Id==38324) // Regeneration (triggered by 38299 (HoTs on Heals))
513 return true;
515 return false;
518 bool IsSingleTargetSpells(SpellEntry const *spellInfo1, SpellEntry const *spellInfo2)
520 // TODO - need better check
521 // Equal icon and spellfamily
522 if( spellInfo1->SpellFamilyName == spellInfo2->SpellFamilyName &&
523 spellInfo1->SpellIconID == spellInfo2->SpellIconID )
524 return true;
526 // TODO - need found Judgements rule
527 SpellSpecific spec1 = GetSpellSpecific(spellInfo1->Id);
528 // spell with single target specific types
529 switch(spec1)
531 case SPELL_JUDGEMENT:
532 case SPELL_MAGE_POLYMORPH:
533 if(GetSpellSpecific(spellInfo2->Id) == spec1)
534 return true;
535 break;
536 default:
537 break;
540 return false;
543 bool IsAuraAddedBySpell(uint32 auraType, uint32 spellId)
545 SpellEntry const *spellproto = sSpellStore.LookupEntry(spellId);
546 if (!spellproto) return false;
548 for (int i = 0; i < 3; ++i)
549 if (spellproto->EffectApplyAuraName[i] == auraType)
550 return true;
551 return false;
554 SpellCastResult GetErrorAtShapeshiftedCast (SpellEntry const *spellInfo, uint32 form)
556 // talents that learn spells can have stance requirements that need ignore
557 // (this requirement only for client-side stance show in talent description)
558 if( GetTalentSpellCost(spellInfo->Id) > 0 &&
559 (spellInfo->Effect[0]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[1]==SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[2]==SPELL_EFFECT_LEARN_SPELL) )
560 return SPELL_CAST_OK;
562 uint32 stanceMask = (form ? 1 << (form - 1) : 0);
564 if (stanceMask & spellInfo->StancesNot) // can explicitly not be casted in this stance
565 return SPELL_FAILED_NOT_SHAPESHIFT;
567 if (stanceMask & spellInfo->Stances) // can explicitly be casted in this stance
568 return SPELL_CAST_OK;
570 bool actAsShifted = false;
571 if (form > 0)
573 SpellShapeshiftEntry const *shapeInfo = sSpellShapeshiftStore.LookupEntry(form);
574 if (!shapeInfo)
576 sLog.outError("GetErrorAtShapeshiftedCast: unknown shapeshift %u", form);
577 return SPELL_CAST_OK;
579 actAsShifted = !(shapeInfo->flags1 & 1); // shapeshift acts as normal form for spells
582 if(actAsShifted)
584 if (spellInfo->Attributes & SPELL_ATTR_NOT_SHAPESHIFT) // not while shapeshifted
585 return SPELL_FAILED_NOT_SHAPESHIFT;
586 else if (spellInfo->Stances != 0) // needs other shapeshift
587 return SPELL_FAILED_ONLY_SHAPESHIFT;
589 else
591 // needs shapeshift
592 if(!(spellInfo->AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT) && spellInfo->Stances != 0)
593 return SPELL_FAILED_ONLY_SHAPESHIFT;
596 return SPELL_CAST_OK;
599 void SpellMgr::LoadSpellTargetPositions()
601 mSpellTargetPositions.clear(); // need for reload case
603 uint32 count = 0;
605 // 0 1 2 3 4 5
606 QueryResult *result = WorldDatabase.Query("SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position");
607 if( !result )
610 barGoLink bar( 1 );
612 bar.step();
614 sLog.outString();
615 sLog.outString( ">> Loaded %u spell target coordinates", count );
616 return;
619 barGoLink bar( result->GetRowCount() );
623 Field *fields = result->Fetch();
625 bar.step();
627 ++count;
629 uint32 Spell_ID = fields[0].GetUInt32();
631 SpellTargetPosition st;
633 st.target_mapId = fields[1].GetUInt32();
634 st.target_X = fields[2].GetFloat();
635 st.target_Y = fields[3].GetFloat();
636 st.target_Z = fields[4].GetFloat();
637 st.target_Orientation = fields[5].GetFloat();
639 SpellEntry const* spellInfo = sSpellStore.LookupEntry(Spell_ID);
640 if(!spellInfo)
642 sLog.outErrorDb("Spell (ID:%u) listed in `spell_target_position` does not exist.",Spell_ID);
643 continue;
646 bool found = false;
647 for(int i = 0; i < 3; ++i)
649 if( spellInfo->EffectImplicitTargetA[i]==TARGET_TABLE_X_Y_Z_COORDINATES || spellInfo->EffectImplicitTargetB[i]==TARGET_TABLE_X_Y_Z_COORDINATES )
651 found = true;
652 break;
655 if(!found)
657 sLog.outErrorDb("Spell (Id: %u) listed in `spell_target_position` does not have target TARGET_TABLE_X_Y_Z_COORDINATES (17).",Spell_ID);
658 continue;
661 MapEntry const* mapEntry = sMapStore.LookupEntry(st.target_mapId);
662 if(!mapEntry)
664 sLog.outErrorDb("Spell (ID:%u) target map (ID: %u) does not exist in `Map.dbc`.",Spell_ID,st.target_mapId);
665 continue;
668 if(st.target_X==0 && st.target_Y==0 && st.target_Z==0)
670 sLog.outErrorDb("Spell (ID:%u) target coordinates not provided.",Spell_ID);
671 continue;
674 mSpellTargetPositions[Spell_ID] = st;
676 } while( result->NextRow() );
678 delete result;
680 sLog.outString();
681 sLog.outString( ">> Loaded %u spell teleport coordinates", count );
684 void SpellMgr::LoadSpellAffects()
686 mSpellAffectMap.clear(); // need for reload case
688 uint32 count = 0;
690 // 0 1 2 3 4
691 QueryResult *result = WorldDatabase.Query("SELECT entry, effectId, SpellClassMask0, SpellClassMask1, SpellClassMask2 FROM spell_affect");
692 if( !result )
695 barGoLink bar( 1 );
697 bar.step();
699 sLog.outString();
700 sLog.outString( ">> Loaded %u spell affect definitions", count );
701 return;
704 barGoLink bar( result->GetRowCount() );
708 Field *fields = result->Fetch();
710 bar.step();
712 uint16 entry = fields[0].GetUInt16();
713 uint8 effectId = fields[1].GetUInt8();
715 SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry);
717 if (!spellInfo)
719 sLog.outErrorDb("Spell %u listed in `spell_affect` does not exist", entry);
720 continue;
723 if (effectId >= 3)
725 sLog.outErrorDb("Spell %u listed in `spell_affect` have invalid effect index (%u)", entry,effectId);
726 continue;
729 if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA ||
730 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER &&
731 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER &&
732 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER )
734 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);
735 continue;
738 SpellAffectEntry affect;
739 affect.SpellClassMask[0] = fields[2].GetUInt32();
740 affect.SpellClassMask[1] = fields[3].GetUInt32();
741 affect.SpellClassMask[2] = fields[4].GetUInt32();
743 // Spell.dbc have own data
744 uint32 const *ptr = 0;
745 switch (effectId)
747 case 0: ptr = &spellInfo->EffectSpellClassMaskA[0]; break;
748 case 1: ptr = &spellInfo->EffectSpellClassMaskB[0]; break;
749 case 2: ptr = &spellInfo->EffectSpellClassMaskC[0]; break;
750 default:
751 continue;
753 if(ptr[0] == affect.SpellClassMask[0] || ptr[1] == affect.SpellClassMask[1] || ptr[2] == affect.SpellClassMask[2])
755 char text[]="ABC";
756 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);
757 continue;
760 mSpellAffectMap[(entry<<8) + effectId] = affect;
762 ++count;
763 } while( result->NextRow() );
765 delete result;
767 sLog.outString();
768 sLog.outString( ">> Loaded %u custom spell affect definitions", count );
770 for (uint32 id = 0; id < sSpellStore.GetNumRows(); ++id)
772 SpellEntry const* spellInfo = sSpellStore.LookupEntry(id);
773 if (!spellInfo)
774 continue;
776 for (int effectId = 0; effectId < 3; ++effectId)
778 if( spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA ||
779 (spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_FLAT_MODIFIER &&
780 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_PCT_MODIFIER &&
781 spellInfo->EffectApplyAuraName[effectId] != SPELL_AURA_ADD_TARGET_TRIGGER) )
782 continue;
784 uint32 const *ptr = 0;
785 switch (effectId)
787 case 0: ptr = &spellInfo->EffectSpellClassMaskA[0]; break;
788 case 1: ptr = &spellInfo->EffectSpellClassMaskB[0]; break;
789 case 2: ptr = &spellInfo->EffectSpellClassMaskC[0]; break;
790 default:
791 continue;
793 if(ptr[0] || ptr[1] || ptr[2])
794 continue;
796 if(mSpellAffectMap.find((id<<8) + effectId) != mSpellAffectMap.end())
797 continue;
799 sLog.outErrorDb("Spell %u (%s) misses spell_affect for effect %u",id,spellInfo->SpellName[sWorld.GetDefaultDbcLocale()], effectId);
804 bool SpellMgr::IsAffectedByMod(SpellEntry const *spellInfo, SpellModifier *mod) const
806 // false for spellInfo == NULL
807 if (!spellInfo || !mod)
808 return false;
810 SpellEntry const *affect_spell = sSpellStore.LookupEntry(mod->spellId);
811 // False if affect_spell == NULL or spellFamily not equal
812 if (!affect_spell || affect_spell->SpellFamilyName != spellInfo->SpellFamilyName)
813 return false;
815 // true
816 if (mod->mask & spellInfo->SpellFamilyFlags ||
817 mod->mask2 & spellInfo->SpellFamilyFlags2)
818 return true;
820 return false;
823 void SpellMgr::LoadSpellProcEvents()
825 mSpellProcEventMap.clear(); // need for reload case
827 uint32 count = 0;
829 // 0 1 2 3 4 5 6 7 8 9 10
830 QueryResult *result = WorldDatabase.Query("SELECT entry, SchoolMask, SpellFamilyName, SpellFamilyMask0, SpellFamilyMask1, SpellFamilyMask2, procFlags, procEx, ppmRate, CustomChance, Cooldown FROM spell_proc_event");
831 if( !result )
833 barGoLink bar( 1 );
834 bar.step();
835 sLog.outString();
836 sLog.outString( ">> Loaded %u spell proc event conditions", count );
837 return;
840 barGoLink bar( result->GetRowCount() );
841 uint32 customProc = 0;
844 Field *fields = result->Fetch();
846 bar.step();
848 uint32 entry = fields[0].GetUInt32();
850 const SpellEntry *spell = sSpellStore.LookupEntry(entry);
851 if (!spell)
853 sLog.outErrorDb("Spell %u listed in `spell_proc_event` does not exist", entry);
854 continue;
857 SpellProcEventEntry spe;
859 spe.schoolMask = fields[1].GetUInt32();
860 spe.spellFamilyName = fields[2].GetUInt32();
861 spe.spellFamilyMask = (uint64)fields[3].GetUInt32()|((uint64)fields[4].GetUInt32()<<32);
862 spe.spellFamilyMask2= fields[5].GetUInt32();
863 spe.procFlags = fields[6].GetUInt32();
864 spe.procEx = fields[7].GetUInt32();
865 spe.ppmRate = fields[8].GetFloat();
866 spe.customChance = fields[9].GetFloat();
867 spe.cooldown = fields[10].GetUInt32();
869 mSpellProcEventMap[entry] = spe;
871 if (spell->procFlags==0)
873 if (spe.procFlags == 0)
875 sLog.outErrorDb("Spell %u listed in `spell_proc_event` probally not triggered spell", entry);
876 continue;
878 customProc++;
880 ++count;
881 } while( result->NextRow() );
883 delete result;
885 sLog.outString();
886 if (customProc)
887 sLog.outString( ">> Loaded %u extra spell proc event conditions +%u custom", count, customProc );
888 else
889 sLog.outString( ">> Loaded %u extra spell proc event conditions", count );
892 void SpellMgr::LoadSpellBonusess()
894 mSpellBonusMap.clear(); // need for reload case
895 uint32 count = 0;
896 // 0 1 2 3
897 QueryResult *result = WorldDatabase.Query("SELECT entry, direct_bonus, dot_bonus, ap_bonus FROM spell_bonus_data");
898 if( !result )
900 barGoLink bar( 1 );
901 bar.step();
902 sLog.outString();
903 sLog.outString( ">> Loaded %u spell bonus data", count);
904 return;
907 barGoLink bar( result->GetRowCount() );
910 Field *fields = result->Fetch();
911 bar.step();
912 uint32 entry = fields[0].GetUInt32();
914 const SpellEntry *spell = sSpellStore.LookupEntry(entry);
915 if (!spell)
917 sLog.outErrorDb("Spell %u listed in `spell_bonus_data` does not exist", entry);
918 continue;
921 SpellBonusEntry sbe;
923 sbe.direct_damage = fields[1].GetFloat();
924 sbe.dot_damage = fields[2].GetFloat();
925 sbe.ap_bonus = fields[3].GetFloat();
927 mSpellBonusMap[entry] = sbe;
928 } while( result->NextRow() );
930 delete result;
932 sLog.outString();
933 sLog.outString( ">> Loaded %u extra spell bonus data", count);
936 bool SpellMgr::IsSpellProcEventCanTriggeredBy(SpellProcEventEntry const * spellProcEvent, uint32 EventProcFlag, SpellEntry const * procSpell, uint32 procFlags, uint32 procExtra, bool active)
938 // No extra req need
939 uint32 procEvent_procEx = PROC_EX_NONE;
941 // check prockFlags for condition
942 if((procFlags & EventProcFlag) == 0)
943 return false;
945 // Always trigger for this
946 if (EventProcFlag & (PROC_FLAG_KILLED | PROC_FLAG_KILL | PROC_FLAG_ON_TRAP_ACTIVATION))
947 return true;
949 if (spellProcEvent) // Exist event data
951 // Store extra req
952 procEvent_procEx = spellProcEvent->procEx;
954 // For melee triggers
955 if (procSpell == NULL)
957 // Check (if set) for school (melee attack have Normal school)
958 if(spellProcEvent->schoolMask && (spellProcEvent->schoolMask & SPELL_SCHOOL_MASK_NORMAL) == 0)
959 return false;
961 else // For spells need check school/spell family/family mask
963 // Check (if set) for school
964 if(spellProcEvent->schoolMask && (spellProcEvent->schoolMask & procSpell->SchoolMask) == 0)
965 return false;
967 // Check (if set) for spellFamilyName
968 if(spellProcEvent->spellFamilyName && (spellProcEvent->spellFamilyName != procSpell->SpellFamilyName))
969 return false;
971 // spellFamilyName is Ok need check for spellFamilyMask if present
972 if(spellProcEvent->spellFamilyMask || spellProcEvent->spellFamilyMask2)
974 if ((spellProcEvent->spellFamilyMask & procSpell->SpellFamilyFlags ) == 0 &&
975 (spellProcEvent->spellFamilyMask2 & procSpell->SpellFamilyFlags2) == 0)
976 return false;
977 active = true; // Spell added manualy -> so its active spell
981 // Check for extra req (if none) and hit/crit
982 if (procEvent_procEx == PROC_EX_NONE)
984 // No extra req, so can trigger only for active (damage/healing present) and hit/crit
985 if((procExtra & (PROC_EX_NORMAL_HIT|PROC_EX_CRITICAL_HIT)) && active)
986 return true;
988 else // Passive spells hits here only if resist/reflect/immune/evade
990 // Exist req for PROC_EX_EX_TRIGGER_ALWAYS
991 if (procEvent_procEx & PROC_EX_EX_TRIGGER_ALWAYS)
992 return true;
993 // Passive spells can`t trigger if need hit
994 if ((procEvent_procEx & PROC_EX_NORMAL_HIT) && !active)
995 return false;
996 // Check Extra Requirement like (hit/crit/miss/resist/parry/dodge/block/immune/reflect/absorb and other)
997 if (procEvent_procEx & procExtra)
998 return true;
1000 return false;
1003 void SpellMgr::LoadSpellElixirs()
1005 mSpellElixirs.clear(); // need for reload case
1007 uint32 count = 0;
1009 // 0 1
1010 QueryResult *result = WorldDatabase.Query("SELECT entry, mask FROM spell_elixir");
1011 if( !result )
1014 barGoLink bar( 1 );
1016 bar.step();
1018 sLog.outString();
1019 sLog.outString( ">> Loaded %u spell elixir definitions", count );
1020 return;
1023 barGoLink bar( result->GetRowCount() );
1027 Field *fields = result->Fetch();
1029 bar.step();
1031 uint16 entry = fields[0].GetUInt16();
1032 uint8 mask = fields[1].GetUInt8();
1034 SpellEntry const* spellInfo = sSpellStore.LookupEntry(entry);
1036 if (!spellInfo)
1038 sLog.outErrorDb("Spell %u listed in `spell_elixir` does not exist", entry);
1039 continue;
1042 mSpellElixirs[entry] = mask;
1044 ++count;
1045 } while( result->NextRow() );
1047 delete result;
1049 sLog.outString();
1050 sLog.outString( ">> Loaded %u spell elixir definitions", count );
1053 void SpellMgr::LoadSpellThreats()
1055 sSpellThreatStore.Free(); // for reload
1057 sSpellThreatStore.Load();
1059 sLog.outString( ">> Loaded %u aggro generating spells", sSpellThreatStore.RecordCount );
1060 sLog.outString();
1063 bool SpellMgr::IsRankSpellDueToSpell(SpellEntry const *spellInfo_1,uint32 spellId_2) const
1065 SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
1066 if(!spellInfo_1 || !spellInfo_2) return false;
1067 if(spellInfo_1->Id == spellId_2) return false;
1069 return GetFirstSpellInChain(spellInfo_1->Id)==GetFirstSpellInChain(spellId_2);
1072 bool SpellMgr::canStackSpellRanks(SpellEntry const *spellInfo)
1074 if(IsPassiveSpell(spellInfo->Id)) // ranked passive spell
1075 return false;
1076 if(spellInfo->powerType != POWER_MANA && spellInfo->powerType != POWER_HEALTH)
1077 return false;
1078 if(IsProfessionOrRidingSpell(spellInfo->Id))
1079 return false;
1081 if(spellmgr.IsSkillBonusSpell(spellInfo->Id))
1082 return false;
1084 // All stance spells. if any better way, change it.
1085 for (int i = 0; i < 3; ++i)
1087 switch(spellInfo->SpellFamilyName)
1089 case SPELLFAMILY_PALADIN:
1090 // Paladin aura Spell
1091 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AREA_AURA_RAID)
1092 return false;
1093 break;
1094 case SPELLFAMILY_DRUID:
1095 // Druid form Spell
1096 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA &&
1097 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT)
1098 return false;
1099 break;
1100 case SPELLFAMILY_ROGUE:
1101 // Rogue Stealth
1102 if (spellInfo->Effect[i]==SPELL_EFFECT_APPLY_AURA &&
1103 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_SHAPESHIFT)
1104 return false;
1107 return true;
1110 bool SpellMgr::IsNoStackSpellDueToSpell(uint32 spellId_1, uint32 spellId_2) const
1112 SpellEntry const *spellInfo_1 = sSpellStore.LookupEntry(spellId_1);
1113 SpellEntry const *spellInfo_2 = sSpellStore.LookupEntry(spellId_2);
1115 if(!spellInfo_1 || !spellInfo_2)
1116 return false;
1118 if(spellInfo_1->Id == spellId_2)
1119 return false;
1121 //I think we don't check this correctly because i need a exception for spell:
1122 //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.
1123 if(spellInfo_2->SpellFamilyFlags == 2048)
1124 return false;
1126 // Resurrection sickness
1127 if((spellInfo_1->Id == SPELL_ID_PASSIVE_RESURRECTION_SICKNESS) != (spellInfo_2->Id==SPELL_ID_PASSIVE_RESURRECTION_SICKNESS))
1128 return false;
1130 // Allow stack passive and not passive spells
1131 if ((spellInfo_1->Attributes & SPELL_ATTR_PASSIVE)!=(spellInfo_2->Attributes & SPELL_ATTR_PASSIVE))
1132 return false;
1134 // Specific spell family spells
1135 switch(spellInfo_1->SpellFamilyName)
1137 case SPELLFAMILY_GENERIC:
1138 switch(spellInfo_2->SpellFamilyName)
1140 case SPELLFAMILY_GENERIC: // same family case
1142 // Thunderfury
1143 if ((spellInfo_1->Id == 21992 && spellInfo_2->Id == 27648) ||
1144 (spellInfo_2->Id == 21992 && spellInfo_1->Id == 27648))
1145 return false;
1147 // Lightning Speed (Mongoose) and Fury of the Crashing Waves (Tsunami Talisman)
1148 if ((spellInfo_1->Id == 28093 && spellInfo_2->Id == 42084) ||
1149 (spellInfo_2->Id == 28093 && spellInfo_1->Id == 42084))
1150 return false;
1152 // Soulstone Resurrection and Twisting Nether (resurrector)
1153 if( spellInfo_1->SpellIconID == 92 && spellInfo_2->SpellIconID == 92 && (
1154 spellInfo_1->SpellVisual[0] == 99 && spellInfo_2->SpellVisual[0] == 0 ||
1155 spellInfo_2->SpellVisual[0] == 99 && spellInfo_1->SpellVisual[0] == 0 ) )
1156 return false;
1158 // Heart of the Wild and (Primal Instinct (Idol of Terror) triggering spell or Agility)
1159 if( spellInfo_1->SpellIconID == 240 && spellInfo_2->SpellIconID == 240 && (
1160 spellInfo_1->SpellVisual[0] == 0 && spellInfo_2->SpellVisual[0] == 78 ||
1161 spellInfo_2->SpellVisual[0] == 0 && spellInfo_1->SpellVisual[0] == 78 ) )
1162 return false;
1164 // Personalized Weather (thunder effect should overwrite rainy aura)
1165 if(spellInfo_1->SpellIconID == 2606 && spellInfo_2->SpellIconID == 2606)
1166 return false;
1168 // Brood Affliction: Bronze
1169 if( (spellInfo_1->Id == 23170 && spellInfo_2->Id == 23171) ||
1170 (spellInfo_2->Id == 23170 && spellInfo_1->Id == 23171) )
1171 return false;
1173 // See Chapel Invisibility and See Noth Invisibility
1174 if( (spellInfo_1->Id == 52950 && spellInfo_2->Id == 52707) ||
1175 (spellInfo_2->Id == 52950 && spellInfo_1->Id == 52707) )
1176 return false;
1178 // Regular and Night Elf Ghost
1179 if( (spellInfo_1->Id == 8326 && spellInfo_2->Id == 20584) ||
1180 (spellInfo_2->Id == 8326 && spellInfo_1->Id == 20584) )
1181 return false;
1183 break;
1185 case SPELLFAMILY_WARRIOR:
1187 // Scroll of Protection and Defensive Stance (multi-family check)
1188 if( spellInfo_1->SpellIconID == 276 && spellInfo_1->SpellVisual[0] == 196 && spellInfo_2->Id == 71)
1189 return false;
1191 // Improved Hamstring -> Hamstring (multi-family check)
1192 if( (spellInfo_2->SpellFamilyFlags & 2) && spellInfo_1->Id == 23694 )
1193 return false;
1195 break;
1197 case SPELLFAMILY_DRUID:
1199 // Scroll of Stamina and Leader of the Pack (multi-family check)
1200 if( spellInfo_1->SpellIconID == 312 && spellInfo_1->SpellVisual[0] == 216 && spellInfo_2->Id == 24932 )
1201 return false;
1203 // Dragonmaw Illusion (multi-family check)
1204 if (spellId_1 == 40216 && spellId_2 == 42016 )
1205 return false;
1207 break;
1209 case SPELLFAMILY_ROGUE:
1211 // Garrote-Silence -> Garrote (multi-family check)
1212 if( spellInfo_1->SpellIconID == 498 && spellInfo_1->SpellVisual[0] == 0 && spellInfo_2->SpellIconID == 498 )
1213 return false;
1215 break;
1217 case SPELLFAMILY_HUNTER:
1219 // Concussive Shot and Imp. Concussive Shot (multi-family check)
1220 if( spellInfo_1->Id == 19410 && spellInfo_2->Id == 5116 )
1221 return false;
1223 // Improved Wing Clip -> Wing Clip (multi-family check)
1224 if( (spellInfo_2->SpellFamilyFlags & 0x40) && spellInfo_1->Id == 19229 )
1225 return false;
1226 break;
1228 case SPELLFAMILY_PALADIN:
1230 // Unstable Currents and other -> *Sanctity Aura (multi-family check)
1231 if( spellInfo_2->SpellIconID==502 && spellInfo_1->SpellIconID==502 && spellInfo_1->SpellVisual[0]==969 )
1232 return false;
1234 // *Band of Eternal Champion and Seal of Command(multi-family check)
1235 if( spellId_1 == 35081 && spellInfo_2->SpellIconID==561 && spellInfo_2->SpellVisual[0]==7992)
1236 return false;
1238 break;
1241 // Dragonmaw Illusion, Blood Elf Illusion, Human Illusion, Illidari Agent Illusion, Scarlet Crusade Disguise
1242 if(spellInfo_1->SpellIconID == 1691 && spellInfo_2->SpellIconID == 1691)
1243 return false;
1244 break;
1245 case SPELLFAMILY_MAGE:
1246 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_MAGE )
1248 // Blizzard & Chilled (and some other stacked with blizzard spells
1249 if( (spellInfo_1->SpellFamilyFlags & 0x80) && (spellInfo_2->SpellFamilyFlags & 0x100000) ||
1250 (spellInfo_2->SpellFamilyFlags & 0x80) && (spellInfo_1->SpellFamilyFlags & 0x100000) )
1251 return false;
1253 // Blink & Improved Blink
1254 if( (spellInfo_1->SpellFamilyFlags & 0x0000000000010000LL) && (spellInfo_2->SpellVisual[0] == 72 && spellInfo_2->SpellIconID == 1499) ||
1255 (spellInfo_2->SpellFamilyFlags & 0x0000000000010000LL) && (spellInfo_1->SpellVisual[0] == 72 && spellInfo_1->SpellIconID == 1499) )
1256 return false;
1258 // Detect Invisibility and Mana Shield (multi-family check)
1259 if( spellInfo_2->Id == 132 && spellInfo_1->SpellIconID == 209 && spellInfo_1->SpellVisual[0] == 968 )
1260 return false;
1262 // Combustion and Fire Protection Aura (multi-family check)
1263 if( spellInfo_1->Id == 11129 && spellInfo_2->SpellIconID == 33 && spellInfo_2->SpellVisual[0] == 321 )
1264 return false;
1266 break;
1267 case SPELLFAMILY_WARLOCK:
1268 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_WARLOCK )
1270 // Siphon Life and Drain Life
1271 if( spellInfo_1->SpellIconID == 152 && spellInfo_2->SpellIconID == 546 ||
1272 spellInfo_2->SpellIconID == 152 && spellInfo_1->SpellIconID == 546 )
1273 return false;
1275 //Corruption & Seed of corruption
1276 if( spellInfo_1->SpellIconID == 313 && spellInfo_2->SpellIconID == 1932 ||
1277 spellInfo_2->SpellIconID == 313 && spellInfo_1->SpellIconID == 1932 )
1278 if(spellInfo_1->SpellVisual[0] != 0 && spellInfo_2->SpellVisual[0] != 0)
1279 return true; // can't be stacked
1281 // Corruption and Unstable Affliction
1282 if( spellInfo_1->SpellIconID == 313 && spellInfo_2->SpellIconID == 2039 ||
1283 spellInfo_2->SpellIconID == 313 && spellInfo_1->SpellIconID == 2039 )
1284 return false;
1286 // (Corruption or Unstable Affliction) and (Curse of Agony or Curse of Doom)
1287 if( (spellInfo_1->SpellIconID == 313 || spellInfo_1->SpellIconID == 2039) && (spellInfo_2->SpellIconID == 544 || spellInfo_2->SpellIconID == 91) ||
1288 (spellInfo_2->SpellIconID == 313 || spellInfo_2->SpellIconID == 2039) && (spellInfo_1->SpellIconID == 544 || spellInfo_1->SpellIconID == 91) )
1289 return false;
1291 // Detect Invisibility and Mana Shield (multi-family check)
1292 if( spellInfo_1->Id == 132 && spellInfo_2->SpellIconID == 209 && spellInfo_2->SpellVisual[0] == 968 )
1293 return false;
1294 break;
1295 case SPELLFAMILY_WARRIOR:
1296 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_WARRIOR )
1298 // Rend and Deep Wound
1299 if( (spellInfo_1->SpellFamilyFlags & 0x20) && (spellInfo_2->SpellFamilyFlags & 0x1000000000LL) ||
1300 (spellInfo_2->SpellFamilyFlags & 0x20) && (spellInfo_1->SpellFamilyFlags & 0x1000000000LL) )
1301 return false;
1303 // Battle Shout and Rampage
1304 if( (spellInfo_1->SpellIconID == 456 && spellInfo_2->SpellIconID == 2006) ||
1305 (spellInfo_2->SpellIconID == 456 && spellInfo_1->SpellIconID == 2006) )
1306 return false;
1309 // Hamstring -> Improved Hamstring (multi-family check)
1310 if( (spellInfo_1->SpellFamilyFlags & 2) && spellInfo_2->Id == 23694 )
1311 return false;
1313 // Defensive Stance and Scroll of Protection (multi-family check)
1314 if( spellInfo_1->Id == 71 && spellInfo_2->SpellIconID == 276 && spellInfo_2->SpellVisual[0] == 196 )
1315 return false;
1317 // Bloodlust and Bloodthirst (multi-family check)
1318 if( spellInfo_2->Id == 2825 && spellInfo_1->SpellIconID == 38 && spellInfo_1->SpellVisual[0] == 0 )
1319 return false;
1321 break;
1322 case SPELLFAMILY_PRIEST:
1323 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_PRIEST )
1325 //Devouring Plague and Shadow Vulnerability
1326 if( (spellInfo_1->SpellFamilyFlags & 0x2000000) && (spellInfo_2->SpellFamilyFlags & 0x800000000LL) ||
1327 (spellInfo_2->SpellFamilyFlags & 0x2000000) && (spellInfo_1->SpellFamilyFlags & 0x800000000LL) )
1328 return false;
1330 //StarShards and Shadow Word: Pain
1331 if( (spellInfo_1->SpellFamilyFlags & 0x200000) && (spellInfo_2->SpellFamilyFlags & 0x8000) ||
1332 (spellInfo_2->SpellFamilyFlags & 0x200000) && (spellInfo_1->SpellFamilyFlags & 0x8000) )
1333 return false;
1334 // Dispersion
1335 if( (spellInfo_1->Id == 47585 && spellInfo_2->Id == 60069) ||
1336 (spellInfo_2->Id == 47585 && spellInfo_1->Id == 60069) )
1337 return false;
1339 break;
1340 case SPELLFAMILY_DRUID:
1341 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_DRUID )
1343 //Omen of Clarity and Blood Frenzy
1344 if( (spellInfo_1->SpellFamilyFlags == 0x0 && spellInfo_1->SpellIconID == 108) && (spellInfo_2->SpellFamilyFlags & 0x20000000000000LL) ||
1345 (spellInfo_2->SpellFamilyFlags == 0x0 && spellInfo_2->SpellIconID == 108) && (spellInfo_1->SpellFamilyFlags & 0x20000000000000LL) )
1346 return false;
1348 // Tree of Life (Shapeshift) and 34123 Tree of Life (Passive)
1349 if ((spellId_1 == 33891 && spellId_2 == 34123) ||
1350 (spellId_2 == 33891 && spellId_1 == 34123))
1351 return false;
1353 // Wrath of Elune and Nature's Grace
1354 if( spellInfo_1->Id == 16886 && spellInfo_2->Id == 46833 || spellInfo_2->Id == 16886 && spellInfo_1->Id == 46833 )
1355 return false;
1357 // Bear Rage (Feral T4 (2)) and Omen of Clarity
1358 if( spellInfo_1->Id == 16864 && spellInfo_2->Id == 37306 || spellInfo_2->Id == 16864 && spellInfo_1->Id == 37306 )
1359 return false;
1361 // Cat Energy (Feral T4 (2)) and Omen of Clarity
1362 if( spellInfo_1->Id == 16864 && spellInfo_2->Id == 37311 || spellInfo_2->Id == 16864 && spellInfo_1->Id == 37311 )
1363 return false;
1365 // Survival Instincts and Survival Instincts
1366 if( spellInfo_1->Id == 61336 && spellInfo_2->Id == 50322 || spellInfo_2->Id == 61336 && spellInfo_1->Id == 50322 )
1367 return false;
1370 // Leader of the Pack and Scroll of Stamina (multi-family check)
1371 if( spellInfo_1->Id == 24932 && spellInfo_2->SpellIconID == 312 && spellInfo_2->SpellVisual[0] == 216 )
1372 return false;
1374 // Dragonmaw Illusion (multi-family check)
1375 if (spellId_1 == 42016 && spellId_2 == 40216 )
1376 return false;
1378 break;
1379 case SPELLFAMILY_ROGUE:
1380 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_ROGUE )
1382 // Master of Subtlety
1383 if (spellId_1 == 31665 && spellId_2 == 31666 || spellId_1 == 31666 && spellId_2 == 31665 )
1384 return false;
1387 //Overkill
1388 if( spellInfo_1->SpellIconID == 2285 && spellInfo_2->SpellIconID == 2285 )
1389 return false;
1391 // Garrote -> Garrote-Silence (multi-family check)
1392 if( spellInfo_1->SpellIconID == 498 && spellInfo_2->SpellIconID == 498 && spellInfo_2->SpellVisual[0] == 0 )
1393 return false;
1394 break;
1395 case SPELLFAMILY_HUNTER:
1396 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_HUNTER )
1398 // Rapid Fire & Quick Shots
1399 if( (spellInfo_1->SpellFamilyFlags & 0x20) && (spellInfo_2->SpellFamilyFlags & 0x20000000000LL) ||
1400 (spellInfo_2->SpellFamilyFlags & 0x20) && (spellInfo_1->SpellFamilyFlags & 0x20000000000LL) )
1401 return false;
1403 // Serpent Sting & (Immolation/Explosive Trap Effect)
1404 if( (spellInfo_1->SpellFamilyFlags & 0x4) && (spellInfo_2->SpellFamilyFlags & 0x00000004000LL) ||
1405 (spellInfo_2->SpellFamilyFlags & 0x4) && (spellInfo_1->SpellFamilyFlags & 0x00000004000LL) )
1406 return false;
1408 // Bestial Wrath
1409 if( spellInfo_1->SpellIconID == 1680 && spellInfo_2->SpellIconID == 1680 )
1410 return false;
1413 // Wing Clip -> Improved Wing Clip (multi-family check)
1414 if( (spellInfo_1->SpellFamilyFlags & 0x40) && spellInfo_2->Id == 19229 )
1415 return false;
1417 // Concussive Shot and Imp. Concussive Shot (multi-family check)
1418 if( spellInfo_2->Id == 19410 && spellInfo_1->Id == 5116 )
1419 return false;
1420 break;
1421 case SPELLFAMILY_PALADIN:
1422 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_PALADIN )
1424 // Paladin Seals
1425 if( IsSealSpell(spellInfo_1) && IsSealSpell(spellInfo_2) )
1426 return true;
1428 // Combustion and Fire Protection Aura (multi-family check)
1429 if( spellInfo_2->Id == 11129 && spellInfo_1->SpellIconID == 33 && spellInfo_1->SpellVisual[0] == 321 )
1430 return false;
1432 // *Sanctity Aura -> Unstable Currents and other (multi-family check)
1433 if( spellInfo_1->SpellIconID==502 && spellInfo_2->SpellFamilyName == SPELLFAMILY_GENERIC && spellInfo_2->SpellIconID==502 && spellInfo_2->SpellVisual[0]==969 )
1434 return false;
1436 // *Seal of Command and Band of Eternal Champion (multi-family check)
1437 if( spellInfo_1->SpellIconID==561 && spellInfo_1->SpellVisual[0]==7992 && spellId_2 == 35081)
1438 return false;
1439 break;
1440 case SPELLFAMILY_SHAMAN:
1441 if( spellInfo_2->SpellFamilyName == SPELLFAMILY_SHAMAN )
1443 // shaman shields
1444 if( IsElementalShield(spellInfo_1) && IsElementalShield(spellInfo_2) )
1445 return true;
1447 // Windfury weapon
1448 if( spellInfo_1->SpellIconID==220 && spellInfo_2->SpellIconID==220 &&
1449 spellInfo_1->SpellFamilyFlags != spellInfo_2->SpellFamilyFlags )
1450 return false;
1452 // Bloodlust and Bloodthirst (multi-family check)
1453 if( spellInfo_1->Id == 2825 && spellInfo_2->SpellIconID == 38 && spellInfo_2->SpellVisual[0] == 0 )
1454 return false;
1455 break;
1456 default:
1457 break;
1460 // more generic checks
1461 if (spellInfo_1->SpellIconID == spellInfo_2->SpellIconID &&
1462 spellInfo_1->SpellIconID != 0 && spellInfo_2->SpellIconID != 0)
1464 bool isModifier = false;
1465 for (int i = 0; i < 3; ++i)
1467 if (spellInfo_1->EffectApplyAuraName[i] == SPELL_AURA_ADD_FLAT_MODIFIER ||
1468 spellInfo_1->EffectApplyAuraName[i] == SPELL_AURA_ADD_PCT_MODIFIER ||
1469 spellInfo_2->EffectApplyAuraName[i] == SPELL_AURA_ADD_FLAT_MODIFIER ||
1470 spellInfo_2->EffectApplyAuraName[i] == SPELL_AURA_ADD_PCT_MODIFIER )
1471 isModifier = true;
1474 if (!isModifier)
1475 return true;
1478 if (IsRankSpellDueToSpell(spellInfo_1, spellId_2))
1479 return true;
1481 if (spellInfo_1->SpellFamilyName == 0 || spellInfo_2->SpellFamilyName == 0)
1482 return false;
1484 if (spellInfo_1->SpellFamilyName != spellInfo_2->SpellFamilyName)
1485 return false;
1487 for (int i = 0; i < 3; ++i)
1488 if (spellInfo_1->Effect[i] != spellInfo_2->Effect[i] ||
1489 spellInfo_1->EffectItemType[i] != spellInfo_2->EffectItemType[i] ||
1490 spellInfo_1->EffectMiscValue[i] != spellInfo_2->EffectMiscValue[i] ||
1491 spellInfo_1->EffectApplyAuraName[i] != spellInfo_2->EffectApplyAuraName[i])
1492 return false;
1494 return true;
1497 bool SpellMgr::IsProfessionOrRidingSpell(uint32 spellId)
1499 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1500 if(!spellInfo)
1501 return false;
1503 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1504 return false;
1506 uint32 skill = spellInfo->EffectMiscValue[1];
1508 return IsProfessionOrRidingSkill(skill);
1511 bool SpellMgr::IsProfessionSpell(uint32 spellId)
1513 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1514 if(!spellInfo)
1515 return false;
1517 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1518 return false;
1520 uint32 skill = spellInfo->EffectMiscValue[1];
1522 return IsProfessionSkill(skill);
1525 bool SpellMgr::IsPrimaryProfessionSpell(uint32 spellId)
1527 SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
1528 if(!spellInfo)
1529 return false;
1531 if(spellInfo->Effect[1] != SPELL_EFFECT_SKILL)
1532 return false;
1534 uint32 skill = spellInfo->EffectMiscValue[1];
1536 return IsPrimaryProfessionSkill(skill);
1539 bool SpellMgr::IsPrimaryProfessionFirstRankSpell(uint32 spellId) const
1541 return IsPrimaryProfessionSpell(spellId) && GetSpellRank(spellId)==1;
1544 bool SpellMgr::IsSkillBonusSpell(uint32 spellId) const
1546 SkillLineAbilityMap::const_iterator lower = GetBeginSkillLineAbilityMap(spellId);
1547 SkillLineAbilityMap::const_iterator upper = GetEndSkillLineAbilityMap(spellId);
1549 for(SkillLineAbilityMap::const_iterator _spell_idx = lower; _spell_idx != upper; ++_spell_idx)
1551 SkillLineAbilityEntry const *pAbility = _spell_idx->second;
1552 if (!pAbility || pAbility->learnOnGetSkill != ABILITY_LEARNED_ON_GET_PROFESSION_SKILL)
1553 continue;
1555 if(pAbility->req_skill_value > 0)
1556 return true;
1559 return false;
1562 SpellEntry const* SpellMgr::SelectAuraRankForPlayerLevel(SpellEntry const* spellInfo, uint32 playerLevel) const
1564 // ignore passive spells
1565 if(IsPassiveSpell(spellInfo->Id))
1566 return spellInfo;
1568 bool needRankSelection = false;
1569 for(int i=0;i<3;++i)
1571 if( IsPositiveEffect(spellInfo->Id, i) && (
1572 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA ||
1573 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
1574 spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AREA_AURA_RAID
1577 needRankSelection = true;
1578 break;
1582 // not required
1583 if(!needRankSelection)
1584 return spellInfo;
1586 for(uint32 nextSpellId = spellInfo->Id; nextSpellId != 0; nextSpellId = GetPrevSpellInChain(nextSpellId))
1588 SpellEntry const *nextSpellInfo = sSpellStore.LookupEntry(nextSpellId);
1589 if(!nextSpellInfo)
1590 break;
1592 // if found appropriate level
1593 if(playerLevel + 10 >= nextSpellInfo->spellLevel)
1594 return nextSpellInfo;
1596 // one rank less then
1599 // not found
1600 return NULL;
1603 void SpellMgr::LoadSpellChains()
1605 mSpellChains.clear(); // need for reload case
1606 mSpellChainsNext.clear(); // need for reload case
1608 QueryResult *result = WorldDatabase.Query("SELECT spell_id, prev_spell, first_spell, rank, req_spell FROM spell_chain");
1609 if(result == NULL)
1611 barGoLink bar( 1 );
1612 bar.step();
1614 sLog.outString();
1615 sLog.outString( ">> Loaded 0 spell chain records" );
1616 sLog.outErrorDb("`spell_chains` table is empty!");
1617 return;
1620 uint32 count = 0;
1622 barGoLink bar( result->GetRowCount() );
1625 bar.step();
1626 Field *fields = result->Fetch();
1628 uint32 spell_id = fields[0].GetUInt32();
1630 SpellChainNode node;
1631 node.prev = fields[1].GetUInt32();
1632 node.first = fields[2].GetUInt32();
1633 node.rank = fields[3].GetUInt8();
1634 node.req = fields[4].GetUInt32();
1636 if(!sSpellStore.LookupEntry(spell_id))
1638 sLog.outErrorDb("Spell %u listed in `spell_chain` does not exist",spell_id);
1639 continue;
1642 if(node.prev!=0 && !sSpellStore.LookupEntry(node.prev))
1644 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existed previous rank spell.",
1645 spell_id,node.prev,node.first,node.rank,node.req);
1646 continue;
1649 if(!sSpellStore.LookupEntry(node.first))
1651 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing first rank spell.",
1652 spell_id,node.prev,node.first,node.rank,node.req);
1653 continue;
1656 // check basic spell chain data integrity (note: rank can be equal 0 or 1 for first/single spell)
1657 if( (spell_id == node.first) != (node.rank <= 1) ||
1658 (spell_id == node.first) != (node.prev == 0) ||
1659 (node.rank <= 1) != (node.prev == 0) )
1661 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not compatible chain data.",
1662 spell_id,node.prev,node.first,node.rank,node.req);
1663 continue;
1666 if(node.req!=0 && !sSpellStore.LookupEntry(node.req))
1668 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing required spell.",
1669 spell_id,node.prev,node.first,node.rank,node.req);
1670 continue;
1673 // talents not required data in spell chain for work, but must be checked if present for intergrity
1674 if(TalentSpellPos const* pos = GetTalentSpellPos(spell_id))
1676 if(node.rank!=pos->rank+1)
1678 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong rank.",
1679 spell_id,node.prev,node.first,node.rank,node.req);
1680 continue;
1683 if(TalentEntry const* talentEntry = sTalentStore.LookupEntry(pos->talent_id))
1685 if(node.first!=talentEntry->RankID[0])
1687 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong first rank spell.",
1688 spell_id,node.prev,node.first,node.rank,node.req);
1689 continue;
1692 if(node.rank > 1 && node.prev != talentEntry->RankID[node.rank-1-1])
1694 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong prev rank spell.",
1695 spell_id,node.prev,node.first,node.rank,node.req);
1696 continue;
1699 /*if(node.req!=talentEntry->DependsOnSpell)
1701 sLog.outErrorDb("Talent %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has wrong required spell.",
1702 spell_id,node.prev,node.first,node.rank,node.req);
1703 continue;
1708 mSpellChains[spell_id] = node;
1710 if(node.prev)
1711 mSpellChainsNext.insert(SpellChainMapNext::value_type(node.prev,spell_id));
1713 if(node.req)
1714 mSpellChainsNext.insert(SpellChainMapNext::value_type(node.req,spell_id));
1716 ++count;
1717 } while( result->NextRow() );
1719 delete result;
1721 // additional integrity checks
1722 for(SpellChainMap::const_iterator i = mSpellChains.begin(); i != mSpellChains.end(); ++i)
1724 if(i->second.prev)
1726 SpellChainMap::const_iterator i_prev = mSpellChains.find(i->second.prev);
1727 if(i_prev == mSpellChains.end())
1729 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found previous rank spell in table.",
1730 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req);
1732 else if( i_prev->second.first != i->second.first )
1734 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).",
1735 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1736 i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req);
1738 else if( i_prev->second.rank+1 != i->second.rank )
1740 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).",
1741 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1742 i_prev->second.prev,i_prev->second.first,i_prev->second.rank,i_prev->second.req);
1746 if(i->second.req)
1748 SpellChainMap::const_iterator i_req = mSpellChains.find(i->second.req);
1749 if(i_req == mSpellChains.end())
1751 sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not found required rank spell in table.",
1752 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req);
1754 else if( i_req->second.first == i->second.first )
1756 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).",
1757 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1758 i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req);
1760 else if( i_req->second.req )
1762 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).",
1763 i->first,i->second.prev,i->second.first,i->second.rank,i->second.req,
1764 i_req->second.prev,i_req->second.first,i_req->second.rank,i_req->second.req);
1769 sLog.outString();
1770 sLog.outString( ">> Loaded %u spell chain records", count );
1773 void SpellMgr::LoadSpellLearnSkills()
1775 mSpellLearnSkills.clear(); // need for reload case
1777 // search auto-learned skills and add its to map also for use in unlearn spells/talents
1778 uint32 dbc_count = 0;
1779 barGoLink bar( sSpellStore.GetNumRows() );
1780 for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
1782 bar.step();
1783 SpellEntry const* entry = sSpellStore.LookupEntry(spell);
1785 if(!entry)
1786 continue;
1788 for(int i = 0; i < 3; ++i)
1790 if(entry->Effect[i]==SPELL_EFFECT_SKILL)
1792 SpellLearnSkillNode dbc_node;
1793 dbc_node.skill = entry->EffectMiscValue[i];
1794 if ( dbc_node.skill != SKILL_RIDING )
1795 dbc_node.value = 1;
1796 else
1797 dbc_node.value = entry->CalculateSimpleValue(i)*75;
1798 dbc_node.maxvalue = entry->CalculateSimpleValue(i)*75;
1800 mSpellLearnSkills[spell] = dbc_node;
1801 ++dbc_count;
1802 break;
1807 sLog.outString();
1808 sLog.outString( ">> Loaded %u Spell Learn Skills from DBC", dbc_count );
1811 void SpellMgr::LoadSpellLearnSpells()
1813 mSpellLearnSpells.clear(); // need for reload case
1815 // 0 1 2
1816 QueryResult *result = WorldDatabase.Query("SELECT entry, SpellID, Active FROM spell_learn_spell");
1817 if(!result)
1819 barGoLink bar( 1 );
1820 bar.step();
1822 sLog.outString();
1823 sLog.outString( ">> Loaded 0 spell learn spells" );
1824 sLog.outErrorDb("`spell_learn_spell` table is empty!");
1825 return;
1828 uint32 count = 0;
1830 barGoLink bar( result->GetRowCount() );
1833 bar.step();
1834 Field *fields = result->Fetch();
1836 uint32 spell_id = fields[0].GetUInt32();
1838 SpellLearnSpellNode node;
1839 node.spell = fields[1].GetUInt32();
1840 node.active = fields[2].GetBool();
1841 node.autoLearned= false;
1843 if(!sSpellStore.LookupEntry(spell_id))
1845 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",spell_id);
1846 continue;
1849 if(!sSpellStore.LookupEntry(node.spell))
1851 sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist",node.spell);
1852 continue;
1855 mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell_id,node));
1857 ++count;
1858 } while( result->NextRow() );
1860 delete result;
1862 // search auto-learned spells and add its to map also for use in unlearn spells/talents
1863 uint32 dbc_count = 0;
1864 for(uint32 spell = 0; spell < sSpellStore.GetNumRows(); ++spell)
1866 SpellEntry const* entry = sSpellStore.LookupEntry(spell);
1868 if(!entry)
1869 continue;
1871 for(int i = 0; i < 3; ++i)
1873 if(entry->Effect[i]==SPELL_EFFECT_LEARN_SPELL)
1875 SpellLearnSpellNode dbc_node;
1876 dbc_node.spell = entry->EffectTriggerSpell[i];
1877 dbc_node.active = true; // all dbc based learned spells is active (show in spell book or hide by client itself)
1879 // ignore learning not existed spells (broken/outdated/or generic learnig spell 483
1880 if(!sSpellStore.LookupEntry(dbc_node.spell))
1881 continue;
1883 // talent or passive spells or skill-step spells auto-casted and not need dependent learning,
1884 // pet teaching spells don't must be dependent learning (casted)
1885 // other required explicit dependent learning
1886 dbc_node.autoLearned = entry->EffectImplicitTargetA[i]==TARGET_PET || GetTalentSpellCost(spell) > 0 || IsPassiveSpell(spell) || IsSpellHaveEffect(entry,SPELL_EFFECT_SKILL_STEP);
1888 SpellLearnSpellMap::const_iterator db_node_begin = GetBeginSpellLearnSpell(spell);
1889 SpellLearnSpellMap::const_iterator db_node_end = GetEndSpellLearnSpell(spell);
1891 bool found = false;
1892 for(SpellLearnSpellMap::const_iterator itr = db_node_begin; itr != db_node_end; ++itr)
1894 if(itr->second.spell == dbc_node.spell)
1896 sLog.outErrorDb("Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB.",
1897 spell,dbc_node.spell);
1898 found = true;
1899 break;
1903 if(!found) // add new spell-spell pair if not found
1905 mSpellLearnSpells.insert(SpellLearnSpellMap::value_type(spell,dbc_node));
1906 ++dbc_count;
1912 sLog.outString();
1913 sLog.outString( ">> Loaded %u spell learn spells + %u found in DBC", count, dbc_count );
1916 void SpellMgr::LoadSpellScriptTarget()
1918 mSpellScriptTarget.clear(); // need for reload case
1920 uint32 count = 0;
1922 QueryResult *result = WorldDatabase.Query("SELECT entry,type,targetEntry FROM spell_script_target");
1924 if(!result)
1926 barGoLink bar(1);
1928 bar.step();
1930 sLog.outString();
1931 sLog.outErrorDb(">> Loaded 0 SpellScriptTarget. DB table `spell_script_target` is empty.");
1932 return;
1935 barGoLink bar(result->GetRowCount());
1939 Field *fields = result->Fetch();
1940 bar.step();
1942 uint32 spellId = fields[0].GetUInt32();
1943 uint32 type = fields[1].GetUInt32();
1944 uint32 targetEntry = fields[2].GetUInt32();
1946 SpellEntry const* spellProto = sSpellStore.LookupEntry(spellId);
1948 if(!spellProto)
1950 sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist.",spellId,targetEntry);
1951 continue;
1954 bool targetfound = false;
1955 for(int i = 0; i <3; ++i)
1957 if( spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT ||
1958 spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT ||
1959 spellProto->EffectImplicitTargetA[i]==TARGET_SCRIPT_COORDINATES ||
1960 spellProto->EffectImplicitTargetB[i]==TARGET_SCRIPT_COORDINATES )
1962 targetfound = true;
1963 break;
1966 if(!targetfound)
1968 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);
1969 continue;
1972 if( type >= MAX_SPELL_TARGET_TYPE )
1974 sLog.outErrorDb("Table `spell_script_target`: target type %u for TargetEntry %u is incorrect.",type,targetEntry);
1975 continue;
1978 switch(type)
1980 case SPELL_TARGET_TYPE_GAMEOBJECT:
1982 if( targetEntry==0 )
1983 break;
1985 if(!sGOStorage.LookupEntry<GameObjectInfo>(targetEntry))
1987 sLog.outErrorDb("Table `spell_script_target`: gameobject template entry %u does not exist.",targetEntry);
1988 continue;
1990 break;
1992 default:
1994 if( targetEntry==0 )
1996 sLog.outErrorDb("Table `spell_script_target`: target entry == 0 for not GO target type (%u).",type);
1997 continue;
1999 if(!sCreatureStorage.LookupEntry<CreatureInfo>(targetEntry))
2001 sLog.outErrorDb("Table `spell_script_target`: creature template entry %u does not exist.",targetEntry);
2002 continue;
2004 const CreatureInfo* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(targetEntry);
2006 if(spellId == 30427 && !cInfo->SkinLootId)
2008 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);
2009 continue;
2011 break;
2015 mSpellScriptTarget.insert(SpellScriptTarget::value_type(spellId,SpellTargetEntry(SpellTargetType(type),targetEntry)));
2017 ++count;
2018 } while (result->NextRow());
2020 delete result;
2022 // Check all spells
2023 /* Disabled (lot errors at this moment)
2024 for(uint32 i = 1; i < sSpellStore.nCount; ++i)
2026 SpellEntry const * spellInfo = sSpellStore.LookupEntry(i);
2027 if(!spellInfo)
2028 continue;
2030 bool found = false;
2031 for(int j=0; j<3; ++j)
2033 if( spellInfo->EffectImplicitTargetA[j] == TARGET_SCRIPT || spellInfo->EffectImplicitTargetA[j] != TARGET_SELF && spellInfo->EffectImplicitTargetB[j] == TARGET_SCRIPT )
2035 SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(spellInfo->Id);
2036 SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(spellInfo->Id);
2037 if(lower==upper)
2039 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);
2040 break; // effects of spell
2047 sLog.outString();
2048 sLog.outString(">> Loaded %u Spell Script Targets", count);
2051 void SpellMgr::LoadSpellPetAuras()
2053 mSpellPetAuraMap.clear(); // need for reload case
2055 uint32 count = 0;
2057 // 0 1 2
2058 QueryResult *result = WorldDatabase.Query("SELECT spell, pet, aura FROM spell_pet_auras");
2059 if( !result )
2062 barGoLink bar( 1 );
2064 bar.step();
2066 sLog.outString();
2067 sLog.outString( ">> Loaded %u spell pet auras", count );
2068 return;
2071 barGoLink bar( result->GetRowCount() );
2075 Field *fields = result->Fetch();
2077 bar.step();
2079 uint16 spell = fields[0].GetUInt16();
2080 uint16 pet = fields[1].GetUInt16();
2081 uint16 aura = fields[2].GetUInt16();
2083 SpellPetAuraMap::iterator itr = mSpellPetAuraMap.find(spell);
2084 if(itr != mSpellPetAuraMap.end())
2086 itr->second.AddAura(pet, aura);
2088 else
2090 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
2091 if (!spellInfo)
2093 sLog.outErrorDb("Spell %u listed in `spell_pet_auras` does not exist", spell);
2094 continue;
2096 int i = 0;
2097 for(; i < 3; ++i)
2098 if((spellInfo->Effect[i] == SPELL_EFFECT_APPLY_AURA &&
2099 spellInfo->EffectApplyAuraName[i] == SPELL_AURA_DUMMY) ||
2100 spellInfo->Effect[i] == SPELL_EFFECT_DUMMY)
2101 break;
2103 if(i == 3)
2105 sLog.outError("Spell %u listed in `spell_pet_auras` does not have dummy aura or dummy effect", spell);
2106 continue;
2109 SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(aura);
2110 if (!spellInfo2)
2112 sLog.outErrorDb("Aura %u listed in `spell_pet_auras` does not exist", aura);
2113 continue;
2116 PetAura pa(pet, aura, spellInfo->EffectImplicitTargetA[i] == TARGET_PET, spellInfo->CalculateSimpleValue(i));
2117 mSpellPetAuraMap[spell] = pa;
2120 ++count;
2121 } while( result->NextRow() );
2123 delete result;
2125 sLog.outString();
2126 sLog.outString( ">> Loaded %u spell pet auras", count );
2129 void SpellMgr::LoadPetLevelupSpellMap()
2131 CreatureFamilyEntry const *creatureFamily;
2132 SpellEntry const *spell;
2133 uint32 count = 0;
2135 for (uint32 i = 0; i < sCreatureFamilyStore.GetNumRows(); ++i)
2137 creatureFamily = sCreatureFamilyStore.LookupEntry(i);
2139 if(!creatureFamily) // not exist
2140 continue;
2142 if(creatureFamily->petTalentType < 0) // not hunter pet family
2143 continue;
2145 for(uint32 j = 0; j < sSpellStore.GetNumRows(); ++j)
2147 spell = sSpellStore.LookupEntry(j);
2149 // not exist
2150 if(!spell)
2151 continue;
2153 // not hunter spell
2154 if(spell->SpellFamilyName != SPELLFAMILY_HUNTER)
2155 continue;
2157 // not pet spell
2158 if(!(spell->SpellFamilyFlags & 0x1000000000000000LL))
2159 continue;
2161 // not Growl or Cower (generics)
2162 if(spell->SpellIconID != 201 && spell->SpellIconID != 958)
2164 switch(creatureFamily->ID)
2166 case CREATURE_FAMILY_BAT: // Bite and Sonic Blast
2167 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1577)
2168 continue;
2169 break;
2170 case CREATURE_FAMILY_BEAR: // Claw and Swipe
2171 if(spell->SpellIconID != 262 && spell->SpellIconID != 1562)
2172 continue;
2173 break;
2174 case CREATURE_FAMILY_BIRD_OF_PREY: // Claw and Snatch
2175 if(spell->SpellIconID != 262 && spell->SpellIconID != 168)
2176 continue;
2177 break;
2178 case CREATURE_FAMILY_BOAR: // Bite and Gore
2179 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1578)
2180 continue;
2181 break;
2182 case CREATURE_FAMILY_CARRION_BIRD: // Bite and Demoralizing Screech
2183 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1579)
2184 continue;
2185 break;
2186 case CREATURE_FAMILY_CAT: // Claw and Prowl and Rake
2187 if(spell->SpellIconID != 262 && spell->SpellIconID != 495 && spell->SpellIconID != 494)
2188 continue;
2189 break;
2190 case CREATURE_FAMILY_CHIMAERA: // Bite and Froststorm Breath
2191 if(spell->SpellIconID != 1680 && spell->SpellIconID != 62)
2192 continue;
2193 break;
2194 case CREATURE_FAMILY_CORE_HOUND: // Bite and Lava Breath
2195 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1197)
2196 continue;
2197 break;
2198 case CREATURE_FAMILY_CRAB: // Claw and Pin
2199 if(spell->SpellIconID != 262 && spell->SpellIconID != 2679)
2200 continue;
2201 break;
2202 case CREATURE_FAMILY_CROCOLISK: // Bite and Bad Attitude
2203 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1581)
2204 continue;
2205 break;
2206 case CREATURE_FAMILY_DEVILSAUR: // Bite and Monstrous Bite
2207 if(spell->SpellIconID != 1680 && spell->SpellIconID != 599)
2208 continue;
2209 break;
2210 case CREATURE_FAMILY_DRAGONHAWK: // Bite and Fire Breath
2211 if(spell->SpellIconID != 1680 && spell->SpellIconID != 2128)
2212 continue;
2213 break;
2214 case CREATURE_FAMILY_GORILLA: // Smack and Thunderstomp
2215 if(spell->SpellIconID != 473 && spell->SpellIconID != 148)
2216 continue;
2217 break;
2218 case CREATURE_FAMILY_HYENA: // Bite and Tendon Rip
2219 if(spell->SpellIconID != 1680 && spell->SpellIconID != 138)
2220 continue;
2221 break;
2222 case CREATURE_FAMILY_MOTH: // Serenity Dust and Smack
2223 if(spell->SpellIconID != 1714 && spell->SpellIconID != 473)
2224 continue;
2225 break;
2226 case CREATURE_FAMILY_NETHER_RAY: // Bite and Nether Shock
2227 if(spell->SpellIconID != 1680 && spell->SpellIconID != 2027)
2228 continue;
2229 break;
2230 case CREATURE_FAMILY_RAPTOR: // Claw and Savage Rend
2231 if(spell->SpellIconID != 262 && spell->SpellIconID != 245)
2232 continue;
2233 break;
2234 case CREATURE_FAMILY_RAVAGER: // Bite and Ravage
2235 if(spell->SpellIconID != 1680 && spell->SpellIconID != 2253)
2236 continue;
2237 break;
2238 case CREATURE_FAMILY_RHINO: // Smack and Stampede
2239 if(spell->SpellIconID != 473 && spell->SpellIconID != 3066)
2240 continue;
2241 break;
2242 case CREATURE_FAMILY_SCORPID: // Claw and Scorpid Poison
2243 if(spell->SpellIconID != 262 && spell->SpellIconID != 163)
2244 continue;
2245 break;
2246 case CREATURE_FAMILY_SERPENT: // Bite and Poison Spit
2247 if(spell->SpellIconID != 1680 && spell->SpellIconID != 68)
2248 continue;
2249 break;
2250 case CREATURE_FAMILY_SILITHID: // Claw and Venom Web Spray
2251 if(spell->SpellIconID != 262 && (spell->SpellIconID != 272 && spell->SpellVisual[0] != 12013))
2252 continue;
2253 break;
2254 case CREATURE_FAMILY_SPIDER: // Bite and Web
2255 if(spell->SpellIconID != 1680 && (spell->SpellIconID != 272 && spell->SpellVisual[0] != 684))
2256 continue;
2257 break;
2258 case CREATURE_FAMILY_SPIRIT_BEAST: // Claw and Prowl and Spirit Strike
2259 if(spell->SpellIconID != 262 && spell->SpellIconID != 495 && spell->SpellIconID != 255)
2260 continue;
2261 break;
2262 case CREATURE_FAMILY_SPOREBAT: // Smack and Spore Cloud
2263 if(spell->SpellIconID != 473 && spell->SpellIconID != 2681)
2264 continue;
2265 break;
2266 case CREATURE_FAMILY_TALLSTRIDER: // Claw and Dust Cloud
2267 if(spell->SpellIconID != 262 && (spell->SpellIconID != 157 && !(spell->Attributes & 0x4000000)))
2268 continue;
2269 break;
2270 case CREATURE_FAMILY_TURTLE: // Bite and Shell Shield
2271 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1588)
2272 continue;
2273 break;
2274 case CREATURE_FAMILY_WARP_STALKER: // Bite and Warp
2275 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1952)
2276 continue;
2277 break;
2278 case CREATURE_FAMILY_WASP: // Smack and Sting
2279 if(spell->SpellIconID != 473 && spell->SpellIconID != 110)
2280 continue;
2281 break;
2282 case CREATURE_FAMILY_WIND_SERPENT: // Bite and Lightning Breath
2283 if(spell->SpellIconID != 1680 && spell->SpellIconID != 62)
2284 continue;
2285 break;
2286 case CREATURE_FAMILY_WOLF: // Bite and Furious Howl
2287 if(spell->SpellIconID != 1680 && spell->SpellIconID != 1573)
2288 continue;
2289 break;
2290 case CREATURE_FAMILY_WORM: // Acid Spit and Bite
2291 if(spell->SpellIconID != 636 && spell->SpellIconID != 1680)
2292 continue;
2293 break;
2294 default:
2295 sLog.outError("LoadPetLevelupSpellMap: Unhandled creature family %u", creatureFamily->ID);
2296 continue;
2300 mPetLevelupSpellMap[creatureFamily->ID][spell->spellLevel] = spell->Id;
2301 count++;
2305 sLog.outString();
2306 sLog.outString( ">> Loaded %u pet levelup spells", count );
2309 /// Some checks for spells, to prevent adding deprecated/broken spells for trainers, spell book, etc
2310 bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg)
2312 // not exist
2313 if(!spellInfo)
2314 return false;
2316 bool need_check_reagents = false;
2318 // check effects
2319 for(int i=0; i<3; ++i)
2321 switch(spellInfo->Effect[i])
2323 case 0:
2324 continue;
2326 // craft spell for crafting non-existed item (break client recipes list show)
2327 case SPELL_EFFECT_CREATE_ITEM:
2329 if(!ObjectMgr::GetItemPrototype( spellInfo->EffectItemType[i] ))
2331 if(msg)
2333 if(pl)
2334 ChatHandler(pl).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]);
2335 else
2336 sLog.outErrorDb("Craft spell %u create not-exist in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->EffectItemType[i]);
2338 return false;
2341 need_check_reagents = true;
2342 break;
2344 case SPELL_EFFECT_LEARN_SPELL:
2346 SpellEntry const* spellInfo2 = sSpellStore.LookupEntry(spellInfo->EffectTriggerSpell[i]);
2347 if( !IsSpellValid(spellInfo2,pl,msg) )
2349 if(msg)
2351 if(pl)
2352 ChatHandler(pl).PSendSysMessage("Spell %u learn to broken spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
2353 else
2354 sLog.outErrorDb("Spell %u learn to invalid spell %u, and then...",spellInfo->Id,spellInfo->EffectTriggerSpell[i]);
2356 return false;
2358 break;
2363 if(need_check_reagents)
2365 for(int j = 0; j < 8; ++j)
2367 if(spellInfo->Reagent[j] > 0 && !ObjectMgr::GetItemPrototype( spellInfo->Reagent[j] ))
2369 if(msg)
2371 if(pl)
2372 ChatHandler(pl).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]);
2373 else
2374 sLog.outErrorDb("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...",spellInfo->Id,spellInfo->Reagent[j]);
2376 return false;
2381 return true;
2384 void SpellMgr::LoadSpellAreas()
2386 mSpellAreaMap.clear(); // need for reload case
2387 mSpellAreaForQuestMap.clear();
2388 mSpellAreaForActiveQuestMap.clear();
2389 mSpellAreaForQuestEndMap.clear();
2390 mSpellAreaForAuraMap.clear();
2392 uint32 count = 0;
2394 // 0 1 2 3 4 5 6 7 8
2395 QueryResult *result = WorldDatabase.Query("SELECT spell, area, quest_start, quest_start_active, quest_end, aura_spell, racemask, gender, autocast FROM spell_area");
2397 if( !result )
2399 barGoLink bar( 1 );
2401 bar.step();
2403 sLog.outString();
2404 sLog.outString( ">> Loaded %u spell area requirements", count );
2405 return;
2408 barGoLink bar( result->GetRowCount() );
2412 Field *fields = result->Fetch();
2414 bar.step();
2416 uint32 spell = fields[0].GetUInt32();
2417 SpellArea spellArea;
2418 spellArea.spellId = spell;
2419 spellArea.areaId = fields[1].GetUInt32();
2420 spellArea.questStart = fields[2].GetUInt32();
2421 spellArea.questStartCanActive = fields[3].GetBool();
2422 spellArea.questEnd = fields[4].GetUInt32();
2423 spellArea.auraSpell = fields[5].GetInt32();
2424 spellArea.raceMask = fields[6].GetUInt32();
2425 spellArea.gender = Gender(fields[7].GetUInt8());
2426 spellArea.autocast = fields[8].GetBool();
2428 if(!sSpellStore.LookupEntry(spell))
2430 sLog.outErrorDb("Spell %u listed in `spell_area` does not exist", spell);
2431 continue;
2435 bool ok = true;
2436 SpellAreaMapBounds sa_bounds = GetSpellAreaMapBounds(spellArea.spellId);
2437 for(SpellAreaMap::const_iterator itr = sa_bounds.first; itr != sa_bounds.second; ++itr)
2439 if(spellArea.spellId && itr->second.spellId && spellArea.spellId != itr->second.spellId)
2440 continue;
2441 if(spellArea.areaId && itr->second.areaId && spellArea.areaId!= itr->second.areaId)
2442 continue;
2443 if(spellArea.questStart && itr->second.questStart && spellArea.questStart!= itr->second.questStart)
2444 continue;
2445 if(spellArea.auraSpell && itr->second.auraSpell && spellArea.auraSpell!= itr->second.auraSpell)
2446 continue;
2447 if(spellArea.raceMask && itr->second.raceMask && (spellArea.raceMask & itr->second.raceMask)==0)
2448 continue;
2449 if(spellArea.gender != GENDER_NONE && itr->second.gender != GENDER_NONE && spellArea.gender!= itr->second.gender)
2450 continue;
2452 // duplicate by requirements
2453 ok =false;
2454 break;
2457 if(!ok)
2459 sLog.outErrorDb("Spell %u listed in `spell_area` already listed with similar requirements.", spell);
2460 continue;
2465 if(spellArea.areaId && !GetAreaEntryByAreaID(spellArea.areaId))
2467 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong area (%u) requirement", spell,spellArea.areaId);
2468 continue;
2471 if(spellArea.questStart && !objmgr.GetQuestTemplate(spellArea.questStart))
2473 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong start quest (%u) requirement", spell,spellArea.questStart);
2474 continue;
2477 if(spellArea.questEnd)
2479 if(!objmgr.GetQuestTemplate(spellArea.questEnd))
2481 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong end quest (%u) requirement", spell,spellArea.questEnd);
2482 continue;
2485 if(spellArea.questEnd==spellArea.questStart && !spellArea.questStartCanActive)
2487 sLog.outErrorDb("Spell %u listed in `spell_area` have quest (%u) requirement for start and end in same time", spell,spellArea.questEnd);
2488 continue;
2492 if(spellArea.auraSpell)
2494 SpellEntry const* spellInfo = sSpellStore.LookupEntry(abs(spellArea.auraSpell));
2495 if(!spellInfo)
2497 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong aura spell (%u) requirement", spell,abs(spellArea.auraSpell));
2498 continue;
2501 if(spellInfo->EffectApplyAuraName[0]!=SPELL_AURA_DUMMY && spellInfo->EffectApplyAuraName[0]!=SPELL_AURA_PHASE)
2503 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell requirement (%u) without dummy/phase aura in effect 0", spell,abs(spellArea.auraSpell));
2504 continue;
2507 if(abs(spellArea.auraSpell)==spellArea.spellId)
2509 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement for itself", spell,abs(spellArea.auraSpell));
2510 continue;
2513 // not allow autocast chains by auraSpell field (but allow use as alternative if not present)
2514 if(spellArea.autocast && spellArea.auraSpell > 0)
2516 bool chain = false;
2517 SpellAreaForAuraMapBounds saBound = GetSpellAreaForAuraMapBounds(spellArea.spellId);
2518 for(SpellAreaForAuraMap::const_iterator itr = saBound.first; itr != saBound.second; ++itr)
2520 if(itr->second->autocast && itr->second->auraSpell > 0)
2522 chain = true;
2523 break;
2527 if(chain)
2529 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura", spell,spellArea.auraSpell);
2530 continue;
2533 SpellAreaMapBounds saBound2 = GetSpellAreaMapBounds(spellArea.auraSpell);
2534 for(SpellAreaMap::const_iterator itr2 = saBound2.first; itr2 != saBound2.second; ++itr2)
2536 if(itr2->second.autocast && itr2->second.auraSpell > 0)
2538 chain = true;
2539 break;
2543 if(chain)
2545 sLog.outErrorDb("Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura", spell,spellArea.auraSpell);
2546 continue;
2551 if(spellArea.raceMask && (spellArea.raceMask & RACEMASK_ALL_PLAYABLE)==0)
2553 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong race mask (%u) requirement", spell,spellArea.raceMask);
2554 continue;
2557 if(spellArea.gender!=GENDER_NONE && spellArea.gender!=GENDER_FEMALE && spellArea.gender!=GENDER_MALE)
2559 sLog.outErrorDb("Spell %u listed in `spell_area` have wrong gender (%u) requirement", spell,spellArea.gender);
2560 continue;
2563 SpellArea const* sa = &mSpellAreaMap.insert(SpellAreaMap::value_type(spell,spellArea))->second;
2565 // for search by current zone/subzone at zone/subzone change
2566 if(spellArea.areaId)
2567 mSpellAreaForAreaMap.insert(SpellAreaForAreaMap::value_type(spellArea.areaId,sa));
2569 // for search at quest start/reward
2570 if(spellArea.questStart)
2572 if(spellArea.questStartCanActive)
2573 mSpellAreaForActiveQuestMap.insert(SpellAreaForQuestMap::value_type(spellArea.questStart,sa));
2574 else
2575 mSpellAreaForQuestMap.insert(SpellAreaForQuestMap::value_type(spellArea.questStart,sa));
2578 // for search at quest start/reward
2579 if(spellArea.questEnd)
2580 mSpellAreaForQuestEndMap.insert(SpellAreaForQuestMap::value_type(spellArea.questEnd,sa));
2582 // for search at aura apply
2583 if(spellArea.auraSpell)
2584 mSpellAreaForAuraMap.insert(SpellAreaForAuraMap::value_type(abs(spellArea.auraSpell),sa));
2586 ++count;
2587 } while( result->NextRow() );
2589 delete result;
2591 sLog.outString();
2592 sLog.outString( ">> Loaded %u spell area requirements", count );
2595 SpellCastResult SpellMgr::GetSpellAllowedInLocationError(SpellEntry const *spellInfo, uint32 map_id, uint32 zone_id, uint32 area_id, Player const* player)
2597 // normal case
2598 if( spellInfo->AreaGroupId > 0)
2600 bool found = false;
2601 AreaGroupEntry const* groupEntry = sAreaGroupStore.LookupEntry(spellInfo->AreaGroupId);
2602 while (groupEntry)
2604 for (uint32 i=0; i<6; ++i)
2605 if( groupEntry->AreaId[i] == zone_id || groupEntry->AreaId[i] == area_id )
2606 found = true;
2607 if (found || !groupEntry->nextGroup)
2608 break;
2609 // Try search in next group
2610 groupEntry = sAreaGroupStore.LookupEntry(groupEntry->nextGroup);
2613 if(!found)
2614 return SPELL_FAILED_INCORRECT_AREA;
2617 // DB base check (if non empty then must fit at least single for allow)
2618 SpellAreaMapBounds saBounds = spellmgr.GetSpellAreaMapBounds(spellInfo->Id);
2619 if(saBounds.first != saBounds.second)
2621 for(SpellAreaMap::const_iterator itr = saBounds.first; itr != saBounds.second; ++itr)
2623 if(itr->second.IsFitToRequirements(player,zone_id,area_id))
2624 return SPELL_CAST_OK;
2626 return SPELL_FAILED_INCORRECT_AREA;
2629 // bg spell checks
2630 switch(spellInfo->Id)
2632 case 23333: // Warsong Flag
2633 case 23335: // Silverwing Flag
2634 return map_id == 489 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2635 case 34976: // Netherstorm Flag
2636 return map_id == 566 && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2637 case 2584: // Waiting to Resurrect
2638 case 22011: // Spirit Heal Channel
2639 case 22012: // Spirit Heal
2640 case 24171: // Resurrection Impact Visual
2641 case 42792: // Recently Dropped Flag
2642 case 43681: // Inactive
2643 case 44535: // Spirit Heal (mana)
2645 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2646 if(!mapEntry)
2647 return SPELL_FAILED_INCORRECT_AREA;
2649 return mapEntry->IsBattleGround() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2651 case 44521: // Preparation
2653 if(!player)
2654 return SPELL_FAILED_REQUIRES_AREA;
2656 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2657 if(!mapEntry)
2658 return SPELL_FAILED_INCORRECT_AREA;
2660 if(!mapEntry->IsBattleGround())
2661 return SPELL_FAILED_REQUIRES_AREA;
2663 BattleGround* bg = player->GetBattleGround();
2664 return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2666 case 32724: // Gold Team (Alliance)
2667 case 32725: // Green Team (Alliance)
2668 case 35774: // Gold Team (Horde)
2669 case 35775: // Green Team (Horde)
2671 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2672 if(!mapEntry)
2673 return SPELL_FAILED_INCORRECT_AREA;
2675 return mapEntry->IsBattleArena() && player && player->InBattleGround() ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2677 case 32727: // Arena Preparation
2679 if(!player)
2680 return SPELL_FAILED_REQUIRES_AREA;
2682 MapEntry const* mapEntry = sMapStore.LookupEntry(map_id);
2683 if(!mapEntry)
2684 return SPELL_FAILED_INCORRECT_AREA;
2686 if(!mapEntry->IsBattleArena())
2687 return SPELL_FAILED_REQUIRES_AREA;
2689 BattleGround* bg = player->GetBattleGround();
2690 return bg && bg->GetStatus()==STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA;
2694 return SPELL_CAST_OK;
2697 void SpellMgr::LoadSkillLineAbilityMap()
2699 mSkillLineAbilityMap.clear();
2701 barGoLink bar( sSkillLineAbilityStore.GetNumRows() );
2702 uint32 count = 0;
2704 for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); ++i)
2706 bar.step();
2707 SkillLineAbilityEntry const *SkillInfo = sSkillLineAbilityStore.LookupEntry(i);
2708 if(!SkillInfo)
2709 continue;
2711 mSkillLineAbilityMap.insert(SkillLineAbilityMap::value_type(SkillInfo->spellId,SkillInfo));
2712 ++count;
2715 sLog.outString();
2716 sLog.outString(">> Loaded %u SkillLineAbility MultiMap Data", count);
2719 DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellEntry const* spellproto, bool triggered)
2721 // Explicit Diminishing Groups
2722 switch(spellproto->SpellFamilyName)
2724 case SPELLFAMILY_ROGUE:
2726 // Kidney Shot
2727 if (spellproto->SpellFamilyFlags & 0x00000200000LL)
2728 return DIMINISHING_KIDNEYSHOT;
2729 // Blind
2730 else if (spellproto->SpellFamilyFlags & 0x00001000000LL)
2731 return DIMINISHING_BLIND_CYCLONE;
2732 break;
2734 case SPELLFAMILY_WARLOCK:
2736 // Fear
2737 if (spellproto->SpellFamilyFlags & 0x40840000000LL)
2738 return DIMINISHING_WARLOCK_FEAR;
2739 // Curses/etc
2740 else if (spellproto->SpellFamilyFlags & 0x00080000000LL)
2741 return DIMINISHING_LIMITONLY;
2742 break;
2744 case SPELLFAMILY_DRUID:
2746 // Cyclone
2747 if (spellproto->SpellFamilyFlags & 0x02000000000LL)
2748 return DIMINISHING_BLIND_CYCLONE;
2749 break;
2751 case SPELLFAMILY_WARRIOR:
2753 // Hamstring - limit duration to 10s in PvP
2754 if (spellproto->SpellFamilyFlags & 0x00000000002LL)
2755 return DIMINISHING_LIMITONLY;
2756 break;
2758 default:
2759 break;
2762 // Get by mechanic
2763 uint32 mechanic = GetAllSpellMechanicMask(spellproto);
2764 if (mechanic == MECHANIC_NONE) return DIMINISHING_NONE;
2765 if (mechanic & (1<<MECHANIC_STUN)) return triggered ? DIMINISHING_TRIGGER_STUN : DIMINISHING_CONTROL_STUN;
2766 if (mechanic & (1<<MECHANIC_SLEEP)) return DIMINISHING_SLEEP;
2767 if (mechanic & (1<<MECHANIC_POLYMORPH)) return DIMINISHING_POLYMORPH;
2768 if (mechanic & (1<<MECHANIC_ROOT)) return triggered ? DIMINISHING_TRIGGER_ROOT : DIMINISHING_CONTROL_ROOT;
2769 if (mechanic & (1<<MECHANIC_FEAR)) return DIMINISHING_FEAR;
2770 if (mechanic & (1<<MECHANIC_CHARM)) return DIMINISHING_CHARM;
2771 if (mechanic & (1<<MECHANIC_SILENCE)) return DIMINISHING_SILENCE;
2772 if (mechanic & (1<<DIMINISHING_DISARM)) return DIMINISHING_DISARM;
2773 if (mechanic & (1<<MECHANIC_FREEZE)) return DIMINISHING_FREEZE;
2774 if (mechanic & ((1<<MECHANIC_KNOCKOUT) | (1<<MECHANIC_SAPPED))) return DIMINISHING_KNOCKOUT;
2775 if (mechanic & (1<<MECHANIC_BANISH)) return DIMINISHING_BANISH;
2776 if (mechanic & (1<<MECHANIC_HORROR)) return DIMINISHING_DEATHCOIL;
2779 return DIMINISHING_NONE;
2782 bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group)
2784 switch(group)
2786 case DIMINISHING_CONTROL_STUN:
2787 case DIMINISHING_TRIGGER_STUN:
2788 case DIMINISHING_KIDNEYSHOT:
2789 case DIMINISHING_SLEEP:
2790 case DIMINISHING_CONTROL_ROOT:
2791 case DIMINISHING_TRIGGER_ROOT:
2792 case DIMINISHING_FEAR:
2793 case DIMINISHING_WARLOCK_FEAR:
2794 case DIMINISHING_CHARM:
2795 case DIMINISHING_POLYMORPH:
2796 case DIMINISHING_FREEZE:
2797 case DIMINISHING_KNOCKOUT:
2798 case DIMINISHING_BLIND_CYCLONE:
2799 case DIMINISHING_BANISH:
2800 case DIMINISHING_LIMITONLY:
2801 return true;
2802 default:
2803 return false;
2805 return false;
2808 DiminishingReturnsType GetDiminishingReturnsGroupType(DiminishingGroup group)
2810 switch(group)
2812 case DIMINISHING_BLIND_CYCLONE:
2813 case DIMINISHING_CONTROL_STUN:
2814 case DIMINISHING_TRIGGER_STUN:
2815 case DIMINISHING_KIDNEYSHOT:
2816 return DRTYPE_ALL;
2817 case DIMINISHING_SLEEP:
2818 case DIMINISHING_CONTROL_ROOT:
2819 case DIMINISHING_TRIGGER_ROOT:
2820 case DIMINISHING_FEAR:
2821 case DIMINISHING_CHARM:
2822 case DIMINISHING_POLYMORPH:
2823 case DIMINISHING_SILENCE:
2824 case DIMINISHING_DISARM:
2825 case DIMINISHING_DEATHCOIL:
2826 case DIMINISHING_FREEZE:
2827 case DIMINISHING_BANISH:
2828 case DIMINISHING_WARLOCK_FEAR:
2829 case DIMINISHING_KNOCKOUT:
2830 return DRTYPE_PLAYER;
2831 default:
2832 break;
2835 return DRTYPE_NONE;
2838 bool SpellArea::IsFitToRequirements(Player const* player, uint32 newZone, uint32 newArea) const
2840 if(gender!=GENDER_NONE)
2842 // not in expected gender
2843 if(!player || gender != player->getGender())
2844 return false;
2847 if(raceMask)
2849 // not in expected race
2850 if(!player || !(raceMask & player->getRaceMask()))
2851 return false;
2854 if(areaId)
2856 // not in expected zone
2857 if(newZone!=areaId && newArea!=areaId)
2858 return false;
2861 if(questStart)
2863 // not in expected required quest state
2864 if(!player || (!questStartCanActive || !player->IsActiveQuest(questStart)) && !player->GetQuestRewardStatus(questStart))
2865 return false;
2868 if(questEnd)
2870 // not in expected forbidden quest state
2871 if(!player || player->GetQuestRewardStatus(questEnd))
2872 return false;
2875 if(auraSpell)
2877 // not have expected aura
2878 if(!player)
2879 return false;
2880 if(auraSpell > 0)
2881 // have expected aura
2882 return player->HasAura(auraSpell,0);
2883 else
2884 // not have expected aura
2885 return !player->HasAura(-auraSpell,0);
2888 return true;