2008-11-17 22:07:21 -06:00
/*
2009-02-04 12:42:26 +01:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-11-17 22:07:21 -06:00
*
2009-02-04 12:04:12 +01:00
* Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/>
2008-11-17 22:07:21 -06:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "SpellMgr.h"
#include "ObjectMgr.h"
#include "SpellAuraDefines.h"
#include "ProgressBar.h"
2009-03-27 09:58:20 -06:00
#include "DBCStores.h"
2008-11-17 22:07:21 -06:00
#include "World.h"
#include "Chat.h"
#include "Spell.h"
2009-02-10 01:00:22 -06:00
#include "BattleGroundMgr.h"
2009-05-10 22:48:22 -05:00
#include "CreatureAI.h"
2008-11-17 22:07:21 -06:00
2009-01-30 01:11:51 -06:00
bool IsAreaEffectTarget [ TOTAL_SPELL_TARGETS ];
2008-11-17 22:07:21 -06:00
SpellMgr :: SpellMgr ()
{
2008-12-21 14:01:26 -06:00
for ( int i = 0 ; i < TOTAL_SPELL_EFFECTS ; ++ i )
{
switch ( i )
{
2008-12-23 14:58:55 -06:00
case SPELL_EFFECT_PERSISTENT_AREA_AURA : //27
case SPELL_EFFECT_SUMMON : //28
case SPELL_EFFECT_TRIGGER_MISSILE : //32
case SPELL_EFFECT_TRANS_DOOR : //50 summon object
case SPELL_EFFECT_SUMMON_PET : //56
case SPELL_EFFECT_ADD_FARSIGHT : //72
case SPELL_EFFECT_SUMMON_OBJECT_WILD : //76
2009-01-06 13:45:49 -06:00
//case SPELL_EFFECT_SUMMON_CRITTER: //97 not 303
2008-12-23 14:58:55 -06:00
case SPELL_EFFECT_SUMMON_OBJECT_SLOT1 : //104
case SPELL_EFFECT_SUMMON_OBJECT_SLOT2 : //105
case SPELL_EFFECT_SUMMON_OBJECT_SLOT3 : //106
case SPELL_EFFECT_SUMMON_OBJECT_SLOT4 : //107
case SPELL_EFFECT_SUMMON_DEAD_PET : //109
2009-01-06 13:45:49 -06:00
//case SPELL_EFFECT_SUMMON_DEMON: //112 not 303
2008-12-23 14:58:55 -06:00
case SPELL_EFFECT_TRIGGER_SPELL_2 : //151 ritual of summon
2008-12-21 14:01:26 -06:00
EffectTargetType [ i ] = SPELL_REQUIRE_DEST ;
break ;
case SPELL_EFFECT_PARRY : // 0
case SPELL_EFFECT_BLOCK : // 0
case SPELL_EFFECT_SKILL : // always with dummy 3 as A
2008-12-24 15:06:06 -06:00
//case SPELL_EFFECT_LEARN_SPELL: // 0 may be 5 pet
2008-12-21 14:01:26 -06:00
case SPELL_EFFECT_TRADE_SKILL : // 0 or 1
case SPELL_EFFECT_PROFICIENCY : // 0
EffectTargetType [ i ] = SPELL_REQUIRE_NONE ;
break ;
2008-12-24 18:45:06 -06:00
case SPELL_EFFECT_ENCHANT_ITEM :
case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY :
case SPELL_EFFECT_DISENCHANT :
2009-05-03 16:29:33 -05:00
//in 243 this is 0, in 309 it is 1
//so both item target and unit target is pushed, and cause crash
//case SPELL_EFFECT_FEED_PET:
2008-12-24 18:45:06 -06:00
case SPELL_EFFECT_PROSPECTING :
2009-03-18 21:04:46 +01:00
case SPELL_EFFECT_MILLING :
2009-04-10 15:18:41 +02:00
case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC :
2008-12-24 18:45:06 -06:00
EffectTargetType [ i ] = SPELL_REQUIRE_ITEM ;
break ;
2008-12-26 16:15:44 -06:00
//caster must be pushed otherwise no sound
case SPELL_EFFECT_APPLY_AREA_AURA_PARTY :
case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND :
case SPELL_EFFECT_APPLY_AREA_AURA_ENEMY :
case SPELL_EFFECT_APPLY_AREA_AURA_PET :
case SPELL_EFFECT_APPLY_AREA_AURA_OWNER :
2009-05-03 16:29:33 -05:00
case SPELL_EFFECT_CHARGE :
case SPELL_EFFECT_JUMP :
case SPELL_EFFECT_JUMP2 :
case SPELL_EFFECT_138 :
2008-12-26 16:15:44 -06:00
EffectTargetType [ i ] = SPELL_REQUIRE_CASTER ;
break ;
2008-12-21 14:01:26 -06:00
default :
EffectTargetType [ i ] = SPELL_REQUIRE_UNIT ;
break ;
}
}
for ( int i = 0 ; i < TOTAL_SPELL_TARGETS ; ++ i )
{
switch ( i )
{
case TARGET_UNIT_CASTER :
case TARGET_UNIT_CASTER_FISHING :
case TARGET_UNIT_MASTER :
case TARGET_UNIT_PET :
2008-12-23 20:19:40 -06:00
case TARGET_UNIT_PARTY_CASTER :
2009-05-02 11:28:11 -05:00
case TARGET_UNIT_RAID_CASTER :
2008-12-21 14:01:26 -06:00
SpellTargetType [ i ] = TARGET_TYPE_UNIT_CASTER ;
break ;
case TARGET_UNIT_MINIPET :
case TARGET_UNIT_TARGET_ALLY :
case TARGET_UNIT_TARGET_RAID :
case TARGET_UNIT_TARGET_ANY :
case TARGET_UNIT_TARGET_ENEMY :
2008-12-23 20:01:05 -06:00
case TARGET_UNIT_TARGET_PARTY :
case TARGET_UNIT_PARTY_TARGET :
2009-05-02 11:28:11 -05:00
case TARGET_UNIT_CLASS_TARGET :
2009-01-27 14:34:42 -06:00
case TARGET_UNIT_CHAINHEAL :
2008-12-21 14:01:26 -06:00
SpellTargetType [ i ] = TARGET_TYPE_UNIT_TARGET ;
break ;
2009-05-02 11:28:11 -05:00
case TARGET_UNIT_NEARBY_ENEMY :
case TARGET_UNIT_NEARBY_ALLY :
case TARGET_UNIT_NEARBY_ALLY_UNK :
case TARGET_UNIT_NEARBY_ENTRY :
case TARGET_UNIT_NEARBY_RAID :
SpellTargetType [ i ] = TARGET_TYPE_UNIT_NEARBY ;
2008-12-21 14:01:26 -06:00
break ;
2009-05-02 11:28:11 -05:00
case TARGET_UNIT_AREA_ENEMY_SRC :
case TARGET_UNIT_AREA_ALLY_SRC :
case TARGET_UNIT_AREA_ENTRY_SRC :
case TARGET_UNIT_AREA_PARTY_SRC :
case TARGET_OBJECT_AREA_SRC :
SpellTargetType [ i ] = TARGET_TYPE_AREA_SRC ;
2008-12-21 14:01:26 -06:00
break ;
2009-05-02 11:28:11 -05:00
case TARGET_UNIT_AREA_ENEMY_DST :
case TARGET_UNIT_AREA_ALLY_DST :
case TARGET_UNIT_AREA_ENTRY_DST :
case TARGET_UNIT_AREA_PARTY_DST :
case TARGET_OBJECT_AREA_DST :
SpellTargetType [ i ] = TARGET_TYPE_AREA_DST ;
break ;
case TARGET_UNIT_CONE_ENEMY :
case TARGET_UNIT_CONE_ALLY :
case TARGET_UNIT_CONE_ENTRY :
case TARGET_UNIT_CONE_ENEMY_UNKNOWN :
SpellTargetType [ i ] = TARGET_TYPE_AREA_CONE ;
break ;
case TARGET_DST_CASTER :
case TARGET_SRC_CASTER :
case TARGET_MINION :
case TARGET_DEST_CASTER_FRONT_LEAP :
case TARGET_DEST_CASTER_FRONT :
case TARGET_DEST_CASTER_BACK :
case TARGET_DEST_CASTER_RIGHT :
case TARGET_DEST_CASTER_LEFT :
case TARGET_DEST_CASTER_FRONT_LEFT :
case TARGET_DEST_CASTER_BACK_LEFT :
case TARGET_DEST_CASTER_BACK_RIGHT :
case TARGET_DEST_CASTER_FRONT_RIGHT :
case TARGET_DEST_CASTER_RANDOM :
case TARGET_DEST_CASTER_RADIUS :
SpellTargetType [ i ] = TARGET_TYPE_DEST_CASTER ;
break ;
case TARGET_DST_TARGET_ENEMY :
2009-03-12 09:15:30 -06:00
case TARGET_DEST_TARGET_ANY :
2008-12-21 14:01:26 -06:00
case TARGET_DEST_TARGET_FRONT :
case TARGET_DEST_TARGET_BACK :
case TARGET_DEST_TARGET_RIGHT :
case TARGET_DEST_TARGET_LEFT :
2009-01-08 14:22:15 -06:00
case TARGET_DEST_TARGET_FRONT_LEFT :
case TARGET_DEST_TARGET_BACK_LEFT :
case TARGET_DEST_TARGET_BACK_RIGHT :
case TARGET_DEST_TARGET_FRONT_RIGHT :
2008-12-21 14:01:26 -06:00
case TARGET_DEST_TARGET_RANDOM :
case TARGET_DEST_TARGET_RADIUS :
SpellTargetType [ i ] = TARGET_TYPE_DEST_TARGET ;
break ;
2009-04-30 22:04:15 -05:00
case TARGET_DEST_DYNOBJ_ENEMY :
case TARGET_DEST_DYNOBJ_ALLY :
2009-05-02 11:28:11 -05:00
case TARGET_DEST_DYNOBJ_NONE :
2008-12-21 14:01:26 -06:00
case TARGET_DEST_DEST :
2009-05-02 11:28:11 -05:00
case TARGET_DEST_TRAJ :
2009-01-08 14:22:15 -06:00
case TARGET_DEST_DEST_FRONT_LEFT :
case TARGET_DEST_DEST_BACK_LEFT :
case TARGET_DEST_DEST_BACK_RIGHT :
case TARGET_DEST_DEST_FRONT_RIGHT :
case TARGET_DEST_DEST_FRONT :
case TARGET_DEST_DEST_BACK :
case TARGET_DEST_DEST_RIGHT :
case TARGET_DEST_DEST_LEFT :
case TARGET_DEST_DEST_RANDOM :
2008-12-21 14:01:26 -06:00
SpellTargetType [ i ] = TARGET_TYPE_DEST_DEST ;
break ;
2009-05-02 11:28:11 -05:00
case TARGET_DST_DB :
case TARGET_DST_HOME :
case TARGET_DST_NEARBY_ENTRY :
SpellTargetType [ i ] = TARGET_TYPE_DEST_SPECIAL ;
break ;
case TARGET_UNIT_CHANNEL :
case TARGET_DEST_CHANNEL :
SpellTargetType [ i ] = TARGET_TYPE_CHANNEL ;
break ;
2008-12-21 14:01:26 -06:00
default :
SpellTargetType [ i ] = TARGET_TYPE_DEFAULT ;
}
}
2008-12-26 15:55:12 -06:00
for ( int i = 0 ; i < TOTAL_SPELL_TARGETS ; ++ i )
{
switch ( i )
{
2009-05-02 11:28:11 -05:00
case TARGET_UNIT_AREA_ENEMY_DST :
case TARGET_UNIT_AREA_ENEMY_SRC :
case TARGET_UNIT_AREA_ALLY_DST :
case TARGET_UNIT_AREA_ALLY_SRC :
case TARGET_UNIT_AREA_ENTRY_DST :
case TARGET_UNIT_AREA_ENTRY_SRC :
case TARGET_UNIT_AREA_PARTY_DST :
case TARGET_UNIT_AREA_PARTY_SRC :
2008-12-26 15:55:12 -06:00
case TARGET_UNIT_PARTY_TARGET :
case TARGET_UNIT_PARTY_CASTER :
case TARGET_UNIT_CONE_ENEMY :
case TARGET_UNIT_CONE_ALLY :
case TARGET_UNIT_CONE_ENEMY_UNKNOWN :
2009-05-02 11:28:11 -05:00
case TARGET_UNIT_RAID_CASTER :
2008-12-26 15:55:12 -06:00
IsAreaEffectTarget [ i ] = true ;
break ;
default :
IsAreaEffectTarget [ i ] = false ;
break ;
}
}
2008-11-17 22:07:21 -06:00
}
SpellMgr ::~ SpellMgr ()
{
}
SpellMgr & SpellMgr :: Instance ()
{
static SpellMgr spellMgr ;
return spellMgr ;
}
int32 GetSpellDuration ( SpellEntry const * spellInfo )
{
if ( ! spellInfo )
return 0 ;
SpellDurationEntry const * du = sSpellDurationStore . LookupEntry ( spellInfo -> DurationIndex );
if ( ! du )
return 0 ;
return ( du -> Duration [ 0 ] == - 1 ) ? - 1 : abs ( du -> Duration [ 0 ]);
}
int32 GetSpellMaxDuration ( SpellEntry const * spellInfo )
{
if ( ! spellInfo )
return 0 ;
SpellDurationEntry const * du = sSpellDurationStore . LookupEntry ( spellInfo -> DurationIndex );
if ( ! du )
return 0 ;
return ( du -> Duration [ 2 ] == - 1 ) ? - 1 : abs ( du -> Duration [ 2 ]);
}
2009-04-13 18:56:29 +02:00
bool GetDispelChance ( Unit * caster , uint32 spellId )
2009-03-23 01:54:50 +01:00
{
// we assume that aura dispel chance is 100% on start
// need formula for level difference based chance
2009-04-06 13:31:14 +02:00
int32 miss_chance = 0 ;
2009-03-23 01:54:50 +01:00
// Apply dispel mod from aura caster
if ( caster )
{
if ( Player * modOwner = caster -> GetSpellModOwner () )
2009-04-13 18:56:29 +02:00
modOwner -> ApplySpellMod ( spellId , SPELLMOD_RESIST_DISPEL_CHANCE , miss_chance );
2009-03-23 01:54:50 +01:00
}
// Try dispel
2009-04-06 13:31:14 +02:00
return ! roll_chance_i ( miss_chance );
2009-03-23 01:54:50 +01:00
}
2008-11-17 22:07:21 -06:00
uint32 GetSpellCastTime ( SpellEntry const * spellInfo , Spell const * spell )
{
SpellCastTimesEntry const * spellCastTimeEntry = sSpellCastTimesStore . LookupEntry ( spellInfo -> CastingTimeIndex );
// not all spells have cast time index and this is all is pasiive abilities
if ( ! spellCastTimeEntry )
return 0 ;
int32 castTime = spellCastTimeEntry -> CastTime ;
2009-02-11 20:10:00 +01:00
if ( spell && spell -> GetCaster ())
2009-03-02 23:37:24 +01:00
spell -> GetCaster () -> ModSpellCastTime ( spellInfo , castTime , spell );
2008-11-17 22:07:21 -06:00
2009-05-08 00:49:02 -05:00
if ( spellInfo -> Attributes & SPELL_ATTR_REQ_AMMO && ( ! spell || ! ( spell -> IsAutoRepeat ())))
2008-11-17 22:07:21 -06:00
castTime += 500 ;
return ( castTime > 0 ) ? uint32 ( castTime ) : 0 ;
}
bool IsPassiveSpell ( uint32 spellId )
{
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( spellId );
if ( ! spellInfo )
return false ;
return ( spellInfo -> Attributes & SPELL_ATTR_PASSIVE ) != 0 ;
}
2009-03-21 18:05:43 -06:00
bool IsAutocastableSpell ( uint32 spellId )
{
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( spellId );
if ( ! spellInfo )
return false ;
if ( spellInfo -> Attributes & SPELL_ATTR_PASSIVE )
return false ;
if ( spellInfo -> AttributesEx & SPELL_ATTR_EX_UNAUTOCASTABLE_BY_PET )
return false ;
return true ;
}
2009-04-06 13:31:14 +02:00
bool IsHigherHankOfSpell ( uint32 spellId_1 , uint32 spellId_2 )
2008-11-17 22:07:21 -06:00
{
2009-04-06 13:31:14 +02:00
return spellmgr . GetSpellRank ( spellId_1 ) < spellmgr . GetSpellRank ( spellId_2 );
2008-11-17 22:07:21 -06:00
}
SpellSpecific GetSpellSpecific ( uint32 spellId )
{
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( spellId );
if ( ! spellInfo )
return SPELL_NORMAL ;
switch ( spellInfo -> SpellFamilyName )
{
2008-11-28 20:19:37 +01:00
case SPELLFAMILY_GENERIC :
{
2008-12-13 16:08:39 +01:00
//food/drink
if ( spellInfo -> AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED )
2008-12-13 14:35:56 -06:00
{
for ( int i = 0 ; i < 3 ; i ++ )
2009-03-10 16:44:03 +01:00
if ( spellInfo -> EffectApplyAuraName [ i ] == SPELL_AURA_MOD_POWER_REGEN
|| spellInfo -> EffectApplyAuraName [ i ] == SPELL_AURA_OBS_MOD_ENERGY )
2008-12-13 14:35:56 -06:00
return SPELL_DRINK ;
2009-03-10 16:44:03 +01:00
else if ( spellInfo -> EffectApplyAuraName [ i ] == SPELL_AURA_MOD_REGEN
|| spellInfo -> EffectApplyAuraName [ i ] == SPELL_AURA_OBS_MOD_HEALTH )
2008-12-13 14:35:56 -06:00
return SPELL_FOOD ;
}
2008-11-28 15:12:23 -06:00
// this may be a hack
2008-12-13 14:35:56 -06:00
else if (( spellInfo -> AttributesEx2 & SPELL_ATTR_EX2_FOOD )
2008-11-28 15:12:23 -06:00
&& ! spellInfo -> Category )
return SPELL_WELL_FED ;
2009-03-10 16:44:03 +01:00
// scrolls effects
else
{
uint32 firstSpell = spellmgr . GetFirstSpellInChain ( spellInfo -> Id );
switch ( firstSpell )
{
// Strength
case 8118 :
// Stamina
case 8099 :
// Spirit
case 8112 :
//Intellect
case 8096 :
// Agility
case 8115 :
// Armor
case 8091 :
return SPELL_SCROLL ;
}
break ;
}
2008-11-28 20:19:37 +01:00
}
2008-11-17 22:07:21 -06:00
case SPELLFAMILY_MAGE :
{
// family flags 18(Molten), 25(Frost/Ice), 28(Mage)
2009-02-02 17:01:56 +01:00
if ( spellInfo -> SpellFamilyFlags [ 0 ] & 0x12040000 )
2008-11-17 22:07:21 -06:00
return SPELL_MAGE_ARMOR ;
2009-05-03 16:55:09 +02:00
// Arcane brillance and Arcane intelect (normal check fails because of flags difference)
if ( spellInfo -> SpellFamilyFlags [ 0 ] & 0x400 )
return SPELL_MAGE_ARCANE_BRILLANCE ;
2009-02-02 17:01:56 +01:00
if (( spellInfo -> SpellFamilyFlags [ 0 ] & 0x1000000 ) && spellInfo -> EffectApplyAuraName [ 0 ] == SPELL_AURA_MOD_CONFUSE )
2008-11-17 22:07:21 -06:00
return SPELL_MAGE_POLYMORPH ;
break ;
}
case SPELLFAMILY_WARRIOR :
{
2009-02-02 17:01:56 +01:00
if ( spellInfo -> SpellFamilyFlags [ 1 ] & 0x000080 || spellInfo -> SpellFamilyFlags [ 0 ] & 0x10000LL )
2008-11-17 22:07:21 -06:00
return SPELL_POSITIVE_SHOUT ;
break ;
}
case SPELLFAMILY_WARLOCK :
{
// only warlock curses have this
if ( spellInfo -> Dispel == DISPEL_CURSE )
return SPELL_CURSE ;
2009-01-30 19:26:53 -06:00
// Warlock (Demon Armor | Demon Skin | Fel Armor)
2009-02-02 17:01:56 +01:00
if ( spellInfo -> SpellFamilyFlags [ 1 ] & 0x20000020 || spellInfo -> SpellFamilyFlags [ 2 ] & 0x00000010 )
2008-11-17 22:07:21 -06:00
return SPELL_WARLOCK_ARMOR ;
//seed of corruption and corruption
2009-02-02 17:01:56 +01:00
if ( spellInfo -> SpellFamilyFlags [ 1 ] & 0x10 || spellInfo -> SpellFamilyFlags [ 0 ] & 0x2 )
2008-11-17 22:07:21 -06:00
return SPELL_WARLOCK_CORRUPTION ;
break ;
}
case SPELLFAMILY_HUNTER :
{
// only hunter stings have this
if ( spellInfo -> Dispel == DISPEL_POISON )
return SPELL_STING ;
2009-02-02 17:01:56 +01:00
// only hunter aspects have this
2009-03-14 16:20:04 +01:00
if ( spellInfo -> SpellFamilyFlags [ 1 ] & 0x00440000 || spellInfo -> SpellFamilyFlags [ 0 ] & 0x00380000 || spellInfo -> SpellFamilyFlags [ 2 ] & 0x00001010 )
2009-01-12 21:58:01 -06:00
return SPELL_ASPECT ;
2009-01-22 22:44:27 -06:00
2008-11-17 22:07:21 -06:00
break ;
}
case SPELLFAMILY_PALADIN :
{
if ( IsSealSpell ( spellInfo ))
return SPELL_SEAL ;
2009-02-02 17:01:56 +01:00
if ( spellInfo -> SpellFamilyFlags [ 0 ] & 0x11010002 )
2008-11-17 22:07:21 -06:00
return SPELL_BLESSING ;
2009-03-08 03:10:03 +01:00
if (( spellInfo -> SpellFamilyFlags [ 1 ] & 0x000008 || spellInfo -> SpellFamilyFlags [ 0 ] & 0x20180400 ) && ( spellInfo -> AttributesEx3 & 0x200 ))
2008-11-17 22:07:21 -06:00
return SPELL_JUDGEMENT ;
2009-04-29 00:26:07 -05:00
for ( int i = 0 ; i < 3 ; ++ i )
2008-11-17 22:07:21 -06:00
{
2008-12-29 12:22:49 -06:00
// only paladin auras have this (for palaldin class family)
2008-12-24 09:58:26 -06:00
if ( spellInfo -> Effect [ i ] == SPELL_EFFECT_APPLY_AREA_AURA_RAID )
2008-11-17 22:07:21 -06:00
return SPELL_AURA ;
}
break ;
}
case SPELLFAMILY_SHAMAN :
{
if ( IsElementalShield ( spellInfo ))
return SPELL_ELEMENTAL_SHIELD ;
break ;
}
case SPELLFAMILY_POTION :
return spellmgr . GetSpellElixirSpecific ( spellInfo -> Id );
2008-12-29 12:22:49 -06:00
case SPELLFAMILY_DEATHKNIGHT :
if (( spellInfo -> Attributes & 0x10 ) && ( spellInfo -> AttributesEx2 & 0x10 ) && ( spellInfo -> AttributesEx4 & 0x200000 ))
return SPELL_PRESENCE ;
break ;
2008-11-17 22:07:21 -06:00
}
2009-02-18 16:26:02 -06:00
for ( int i = 0 ; i < 3 ; ++ i )
{
if ( spellInfo -> Effect [ i ] == SPELL_EFFECT_APPLY_AURA )
{
switch ( spellInfo -> EffectApplyAuraName [ i ])
{
case SPELL_AURA_MOD_CHARM :
case SPELL_AURA_MOD_POSSESS_PET :
case SPELL_AURA_MOD_POSSESS :
return SPELL_CHARM ;
2009-04-06 13:31:14 +02:00
case SPELL_AURA_TRACK_CREATURES :
case SPELL_AURA_TRACK_RESOURCES :
case SPELL_AURA_TRACK_STEALTHED :
return SPELL_TRACKER ;
2009-02-18 16:26:02 -06:00
}
}
}
2008-11-17 22:07:21 -06:00
// elixirs can have different families, but potion most ofc.
if ( SpellSpecific sp = spellmgr . GetSpellElixirSpecific ( spellInfo -> Id ))
return sp ;
return SPELL_NORMAL ;
}
bool IsSingleFromSpellSpecificPerCaster ( uint32 spellSpec1 , uint32 spellSpec2 )
{
switch ( spellSpec1 )
{
case SPELL_SEAL :
case SPELL_BLESSING :
case SPELL_AURA :
case SPELL_STING :
case SPELL_CURSE :
case SPELL_ASPECT :
2008-11-20 18:13:10 -06:00
case SPELL_POSITIVE_SHOUT :
case SPELL_JUDGEMENT :
case SPELL_WARLOCK_CORRUPTION :
return spellSpec1 == spellSpec2 ;
default :
return false ;
}
}
bool IsSingleFromSpellSpecificPerTarget ( uint32 spellSpec1 , uint32 spellSpec2 )
{
switch ( spellSpec1 )
{
2008-11-17 22:07:21 -06:00
case SPELL_TRACKER :
case SPELL_WARLOCK_ARMOR :
case SPELL_MAGE_ARMOR :
case SPELL_ELEMENTAL_SHIELD :
case SPELL_MAGE_POLYMORPH :
2008-12-29 12:22:49 -06:00
case SPELL_PRESENCE :
2008-11-28 15:12:23 -06:00
case SPELL_WELL_FED :
2008-12-13 16:08:39 +01:00
case SPELL_DRINK :
case SPELL_FOOD :
2009-02-18 16:26:02 -06:00
case SPELL_CHARM :
2009-03-10 21:07:21 +01:00
case SPELL_SCROLL :
2009-05-03 16:55:09 +02:00
case SPELL_MAGE_ARCANE_BRILLANCE :
2008-11-17 22:07:21 -06:00
return spellSpec1 == spellSpec2 ;
case SPELL_BATTLE_ELIXIR :
return spellSpec2 == SPELL_BATTLE_ELIXIR
|| spellSpec2 == SPELL_FLASK_ELIXIR ;
case SPELL_GUARDIAN_ELIXIR :
return spellSpec2 == SPELL_GUARDIAN_ELIXIR
|| spellSpec2 == SPELL_FLASK_ELIXIR ;
case SPELL_FLASK_ELIXIR :
return spellSpec2 == SPELL_BATTLE_ELIXIR
|| spellSpec2 == SPELL_GUARDIAN_ELIXIR
|| spellSpec2 == SPELL_FLASK_ELIXIR ;
default :
return false ;
}
}
bool IsPositiveTarget ( uint32 targetA , uint32 targetB )
{
// non-positive targets
switch ( targetA )
{
2009-05-02 11:28:11 -05:00
case TARGET_UNIT_TARGET_ENEMY :
case TARGET_UNIT_AREA_ENEMY_SRC :
case TARGET_UNIT_AREA_ENEMY_DST :
case TARGET_UNIT_CONE_ENEMY :
2009-04-30 22:04:15 -05:00
case TARGET_DEST_DYNOBJ_ENEMY :
2009-05-02 11:28:11 -05:00
case TARGET_DST_TARGET_ENEMY :
2009-01-08 14:22:15 -06:00
case TARGET_UNIT_CHANNEL :
2008-11-17 22:07:21 -06:00
return false ;
default :
break ;
}
if ( targetB )
return IsPositiveTarget ( targetB , 0 );
return true ;
}
2009-03-11 22:27:07 +01:00
bool IsPositiveEffect ( uint32 spellId , uint32 effIndex , bool deep )
2008-11-17 22:07:21 -06:00
{
SpellEntry const * spellproto = sSpellStore . LookupEntry ( spellId );
if ( ! spellproto ) return false ;
switch ( spellId )
{
case 28441 : // not positive dummy spell
case 37675 : // Chaos Blast
2009-01-24 19:00:29 +01:00
case 41519 : // Mark of Stormrage
case 34877 : // Custodian of Time
2009-02-08 10:42:58 +01:00
case 34700 : // Allergic Reaction
case 31719 : // Suspension
2009-04-29 21:43:59 +02:00
case 61987 : // Avenging Wrath Marker
2008-11-17 22:07:21 -06:00
return false ;
2009-04-12 01:35:06 +02:00
case 12042 : // Arcane Power
return true ;
2009-03-18 21:04:46 +01:00
}
switch ( spellproto -> Mechanic )
{
2009-03-20 19:53:26 +01:00
case MECHANIC_IMMUNE_SHIELD :
2009-03-18 21:04:46 +01:00
return true ;
default :
break ;
}
2008-11-17 22:07:21 -06:00
switch ( spellproto -> Effect [ effIndex ])
{
// always positive effects (check before target checks that provided non-positive result in some case for positive effects)
case SPELL_EFFECT_HEAL :
case SPELL_EFFECT_LEARN_SPELL :
case SPELL_EFFECT_SKILL_STEP :
case SPELL_EFFECT_HEAL_PCT :
case SPELL_EFFECT_ENERGIZE_PCT :
return true ;
// non-positive aura use
case SPELL_EFFECT_APPLY_AURA :
case SPELL_EFFECT_APPLY_AREA_AURA_FRIEND :
{
switch ( spellproto -> EffectApplyAuraName [ effIndex ])
{
case SPELL_AURA_DUMMY :
{
// dummy aura can be positive or negative dependent from casted spell
switch ( spellproto -> Id )
{
case 13139 : // net-o-matic special effect
case 23445 : // evil twin
2009-03-18 20:37:56 -06:00
case 35679 : // Protectorate Demolitionist
2008-11-17 22:07:21 -06:00
case 38637 : // Nether Exhaustion (red)
case 38638 : // Nether Exhaustion (green)
case 38639 : // Nether Exhaustion (blue)
return false ;
default :
break ;
}
} break ;
case SPELL_AURA_MOD_STAT :
case SPELL_AURA_MOD_DAMAGE_DONE : // dependent from bas point sign (negative -> negative)
case SPELL_AURA_MOD_HEALING_DONE :
2009-03-13 22:48:04 +01:00
case SPELL_AURA_MOD_DAMAGE_PERCENT_DONE :
2008-11-17 22:07:21 -06:00
{
2009-03-29 17:21:06 -06:00
if ( spellproto -> CalculateSimpleValue ( effIndex ) < 0 )
2008-11-17 22:07:21 -06:00
return false ;
break ;
}
case SPELL_AURA_ADD_TARGET_TRIGGER :
return true ;
2009-04-23 20:57:17 +02:00
case SPELL_AURA_PERIODIC_TRIGGER_SPELL_WITH_VALUE :
2008-11-17 22:07:21 -06:00
case SPELL_AURA_PERIODIC_TRIGGER_SPELL :
2009-04-09 17:32:22 +02:00
if ( ! deep )
{
uint32 spellTriggeredId = spellproto -> EffectTriggerSpell [ effIndex ];
SpellEntry const * spellTriggeredProto = sSpellStore . LookupEntry ( spellTriggeredId );
if ( spellTriggeredProto )
{
// non-positive targets of main spell return early
for ( int i = 0 ; i < 3 ; ++ i )
{
2009-04-10 16:59:34 +02:00
if ( ! spellTriggeredProto -> Effect [ i ])
continue ;
2009-04-09 17:32:22 +02:00
// if non-positive trigger cast targeted to positive target this main cast is non-positive
// this will place this spell auras as debuffs
if ( IsPositiveTarget ( spellTriggeredProto -> EffectImplicitTargetA [ effIndex ], spellTriggeredProto -> EffectImplicitTargetB [ effIndex ]) && ! IsPositiveEffect ( spellTriggeredId , i , true ))
return false ;
}
}
}
2008-11-17 22:07:21 -06:00
case SPELL_AURA_PROC_TRIGGER_SPELL :
// many positive auras have negative triggered spells at damage for example and this not make it negative (it can be canceled for example)
break ;
case SPELL_AURA_MOD_STUN : //have positive and negative spells, we can't sort its correctly at this moment.
if ( effIndex == 0 && spellproto -> Effect [ 1 ] == 0 && spellproto -> Effect [ 2 ] == 0 )
return false ; // but all single stun aura spells is negative
// Petrification
if ( spellproto -> Id == 17624 )
return false ;
break ;
case SPELL_AURA_MOD_ROOT :
case SPELL_AURA_MOD_SILENCE :
case SPELL_AURA_GHOST :
case SPELL_AURA_PERIODIC_LEECH :
case SPELL_AURA_MOD_PACIFY_SILENCE :
case SPELL_AURA_MOD_STALKED :
case SPELL_AURA_PERIODIC_DAMAGE_PERCENT :
return false ;
case SPELL_AURA_PERIODIC_DAMAGE : // used in positive spells also.
// part of negative spell if casted at self (prevent cancel)
2009-05-02 11:28:11 -05:00
if ( spellproto -> EffectImplicitTargetA [ effIndex ] == TARGET_UNIT_CASTER )
2008-11-17 22:07:21 -06:00
return false ;
break ;
case SPELL_AURA_MOD_DECREASE_SPEED : // used in positive spells also
// part of positive spell if casted at self
2009-05-02 11:28:11 -05:00
if ( spellproto -> EffectImplicitTargetA [ effIndex ] != TARGET_UNIT_CASTER )
2008-11-17 22:07:21 -06:00
return false ;
// but not this if this first effect (don't found batter check)
if ( spellproto -> Attributes & 0x4000000 && effIndex == 0 )
return false ;
break ;
case SPELL_AURA_TRANSFORM :
// some spells negative
switch ( spellproto -> Id )
{
case 36897 : // Transporter Malfunction (race mutation to horde)
case 36899 : // Transporter Malfunction (race mutation to alliance)
return false ;
}
break ;
case SPELL_AURA_MOD_SCALE :
// some spells negative
switch ( spellproto -> Id )
{
case 36900 : // Soul Split: Evil!
case 36901 : // Soul Split: Good
case 36893 : // Transporter Malfunction (decrease size case)
case 36895 : // Transporter Malfunction (increase size case)
return false ;
}
break ;
case SPELL_AURA_MECHANIC_IMMUNITY :
{
// non-positive immunities
switch ( spellproto -> EffectMiscValue [ effIndex ])
{
case MECHANIC_BANDAGE :
case MECHANIC_SHIELD :
case MECHANIC_MOUNT :
case MECHANIC_INVULNERABILITY :
return false ;
default :
break ;
}
} break ;
case SPELL_AURA_ADD_FLAT_MODIFIER : // mods
case SPELL_AURA_ADD_PCT_MODIFIER :
{
// non-positive mods
switch ( spellproto -> EffectMiscValue [ effIndex ])
{
case SPELLMOD_COST : // dependent from bas point sign (negative -> positive)
2009-03-29 17:21:06 -06:00
if ( spellproto -> CalculateSimpleValue ( effIndex ) > 0 )
2009-04-14 19:09:08 +02:00
{
if ( ! deep )
{
bool negative = true ;
for ( uint8 i = 0 ; i < MAX_SPELL_EFFECTS ; ++ i )
{
if ( i != effIndex )
if ( IsPositiveEffect ( spellId , i , true ))
{
negative = false ;
break ;
}
}
if ( negative )
return false ;
}
}
2008-11-17 22:07:21 -06:00
break ;
default :
break ;
}
} break ;
case SPELL_AURA_MOD_HEALING_PCT :
2009-03-29 17:21:06 -06:00
if ( spellproto -> CalculateSimpleValue ( effIndex ) < 0 )
2008-11-17 22:07:21 -06:00
return false ;
break ;
case SPELL_AURA_MOD_SKILL :
2009-03-29 17:21:06 -06:00
if ( spellproto -> CalculateSimpleValue ( effIndex ) < 0 )
2008-11-17 22:07:21 -06:00
return false ;
break ;
case SPELL_AURA_FORCE_REACTION :
if ( spellproto -> Id == 42792 ) // Recently Dropped Flag (prevent cancel)
return false ;
break ;
default :
break ;
}
break ;
}
default :
break ;
}
// non-positive targets
if ( ! IsPositiveTarget ( spellproto -> EffectImplicitTargetA [ effIndex ], spellproto -> EffectImplicitTargetB [ effIndex ]))
return false ;
// AttributesEx check
2008-12-21 14:01:26 -06:00
if ( spellproto -> AttributesEx & SPELL_ATTR_EX_NEGATIVE )
2008-11-17 22:07:21 -06:00
return false ;
2009-03-14 13:34:05 +01:00
if ( ! deep && spellproto -> EffectTriggerSpell [ effIndex ]
2009-04-10 16:59:34 +02:00
&& ! spellproto -> EffectApplyAuraName [ effIndex ]
2009-03-14 13:34:05 +01:00
&& IsPositiveTarget ( spellproto -> EffectImplicitTargetA [ effIndex ], spellproto -> EffectImplicitTargetB [ effIndex ])
&& ! IsPositiveSpell ( spellproto -> EffectTriggerSpell [ effIndex ], true ))
2009-03-11 22:27:07 +01:00
return false ;
2008-11-17 22:07:21 -06:00
// ok, positive
return true ;
}
2009-03-11 22:27:07 +01:00
bool IsPositiveSpell ( uint32 spellId , bool deep )
2008-11-17 22:07:21 -06:00
{
SpellEntry const * spellproto = sSpellStore . LookupEntry ( spellId );
if ( ! spellproto ) return false ;
// spells with at least one negative effect are considered negative
// some self-applied spells have negative effects but in self casting case negative check ignored.
2009-04-29 00:26:07 -05:00
for ( int i = 0 ; i < 3 ; ++ i )
2009-03-11 22:27:07 +01:00
if ( ! IsPositiveEffect ( spellId , i , deep ))
2008-11-17 22:07:21 -06:00
return false ;
return true ;
}
bool IsSingleTargetSpell ( SpellEntry const * spellInfo )
{
// all other single target spells have if it has AttributesEx5
if ( spellInfo -> AttributesEx5 & SPELL_ATTR_EX5_SINGLE_TARGET_SPELL )
return true ;
// TODO - need found Judgements rule
switch ( GetSpellSpecific ( spellInfo -> Id ))
{
case SPELL_JUDGEMENT :
return true ;
2009-05-03 22:21:46 -05:00
default :
break ;
2008-11-17 22:07:21 -06:00
}
// single target triggered spell.
// Not real client side single target spell, but it' not triggered until prev. aura expired.
// This is allow store it in single target spells list for caster for spell proc checking
if ( spellInfo -> Id == 38324 ) // Regeneration (triggered by 38299 (HoTs on Heals))
return true ;
return false ;
}
bool IsSingleTargetSpells ( SpellEntry const * spellInfo1 , SpellEntry const * spellInfo2 )
{
// TODO - need better check
// Equal icon and spellfamily
if ( spellInfo1 -> SpellFamilyName == spellInfo2 -> SpellFamilyName &&
spellInfo1 -> SpellIconID == spellInfo2 -> SpellIconID )
return true ;
// TODO - need found Judgements rule
SpellSpecific spec1 = GetSpellSpecific ( spellInfo1 -> Id );
// spell with single target specific types
switch ( spec1 )
{
case SPELL_JUDGEMENT :
2009-03-05 15:16:13 -06:00
case SPELL_MAGE_POLYMORPH :
2008-11-17 22:07:21 -06:00
if ( GetSpellSpecific ( spellInfo2 -> Id ) == spec1 )
return true ;
break ;
2009-05-03 22:21:46 -05:00
default :
break ;
2008-11-17 22:07:21 -06:00
}
return false ;
}
2008-11-26 15:14:03 -06:00
bool IsAuraAddedBySpell ( uint32 auraType , uint32 spellId )
{
SpellEntry const * spellproto = sSpellStore . LookupEntry ( spellId );
if ( ! spellproto ) return false ;
2009-04-29 00:26:07 -05:00
for ( int i = 0 ; i < 3 ; ++ i )
2008-11-26 15:14:03 -06:00
if ( spellproto -> EffectApplyAuraName [ i ] == auraType )
return true ;
return false ;
}
2009-03-16 12:00:14 -06:00
SpellCastResult GetErrorAtShapeshiftedCast ( SpellEntry const * spellInfo , uint32 form )
2008-11-17 22:07:21 -06:00
{
// talents that learn spells can have stance requirements that need ignore
// (this requirement only for client-side stance show in talent description)
if ( GetTalentSpellCost ( spellInfo -> Id ) > 0 &&
( spellInfo -> Effect [ 0 ] == SPELL_EFFECT_LEARN_SPELL || spellInfo -> Effect [ 1 ] == SPELL_EFFECT_LEARN_SPELL || spellInfo -> Effect [ 2 ] == SPELL_EFFECT_LEARN_SPELL ) )
2009-03-16 12:00:14 -06:00
return SPELL_CAST_OK ;
2008-11-17 22:07:21 -06:00
uint32 stanceMask = ( form ? 1 << ( form - 1 ) : 0 );
if ( stanceMask & spellInfo -> StancesNot ) // can explicitly not be casted in this stance
return SPELL_FAILED_NOT_SHAPESHIFT ;
if ( stanceMask & spellInfo -> Stances ) // can explicitly be casted in this stance
2009-03-16 12:00:14 -06:00
return SPELL_CAST_OK ;
2008-11-17 22:07:21 -06:00
bool actAsShifted = false ;
if ( form > 0 )
{
SpellShapeshiftEntry const * shapeInfo = sSpellShapeshiftStore . LookupEntry ( form );
if ( ! shapeInfo )
{
sLog . outError ( "GetErrorAtShapeshiftedCast: unknown shapeshift %u" , form );
2009-03-16 12:00:14 -06:00
return SPELL_CAST_OK ;
2008-11-17 22:07:21 -06:00
}
actAsShifted = ! ( shapeInfo -> flags1 & 1 ); // shapeshift acts as normal form for spells
}
if ( actAsShifted )
{
if ( spellInfo -> Attributes & SPELL_ATTR_NOT_SHAPESHIFT ) // not while shapeshifted
return SPELL_FAILED_NOT_SHAPESHIFT ;
else if ( spellInfo -> Stances != 0 ) // needs other shapeshift
return SPELL_FAILED_ONLY_SHAPESHIFT ;
}
else
{
// needs shapeshift
if ( ! ( spellInfo -> AttributesEx2 & SPELL_ATTR_EX2_NOT_NEED_SHAPESHIFT ) && spellInfo -> Stances != 0 )
return SPELL_FAILED_ONLY_SHAPESHIFT ;
}
2009-03-16 12:00:14 -06:00
return SPELL_CAST_OK ;
2008-11-17 22:07:21 -06:00
}
void SpellMgr :: LoadSpellTargetPositions ()
{
mSpellTargetPositions . clear (); // need for reload case
uint32 count = 0 ;
// 0 1 2 3 4 5
QueryResult * result = WorldDatabase . Query ( "SELECT id, target_map, target_position_x, target_position_y, target_position_z, target_orientation FROM spell_target_position" );
if ( ! result )
{
barGoLink bar ( 1 );
bar . step ();
2009-04-03 16:36:20 -06:00
sLog . outString ();
2008-11-17 22:07:21 -06:00
sLog . outString ( ">> Loaded %u spell target coordinates" , count );
return ;
}
barGoLink bar ( result -> GetRowCount () );
do
{
Field * fields = result -> Fetch ();
bar . step ();
++ count ;
uint32 Spell_ID = fields [ 0 ]. GetUInt32 ();
SpellTargetPosition st ;
st . target_mapId = fields [ 1 ]. GetUInt32 ();
st . target_X = fields [ 2 ]. GetFloat ();
st . target_Y = fields [ 3 ]. GetFloat ();
st . target_Z = fields [ 4 ]. GetFloat ();
st . target_Orientation = fields [ 5 ]. GetFloat ();
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( Spell_ID );
if ( ! spellInfo )
{
sLog . outErrorDb ( "Spell (ID:%u) listed in `spell_target_position` does not exist." , Spell_ID );
continue ;
}
bool found = false ;
for ( int i = 0 ; i < 3 ; ++ i )
{
2009-05-02 11:28:11 -05:00
if ( spellInfo -> EffectImplicitTargetA [ i ] == TARGET_DST_DB || spellInfo -> EffectImplicitTargetB [ i ] == TARGET_DST_DB )
2008-11-17 22:07:21 -06:00
{
found = true ;
break ;
}
}
if ( ! found )
{
2009-05-02 11:28:11 -05:00
sLog . outErrorDb ( "Spell (Id: %u) listed in `spell_target_position` does not have target TARGET_DST_DB (17)." , Spell_ID );
2008-11-17 22:07:21 -06:00
continue ;
}
MapEntry const * mapEntry = sMapStore . LookupEntry ( st . target_mapId );
if ( ! mapEntry )
{
sLog . outErrorDb ( "Spell (ID:%u) target map (ID: %u) does not exist in `Map.dbc`." , Spell_ID , st . target_mapId );
continue ;
}
if ( st . target_X == 0 && st . target_Y == 0 && st . target_Z == 0 )
{
sLog . outErrorDb ( "Spell (ID:%u) target coordinates not provided." , Spell_ID );
continue ;
}
mSpellTargetPositions [ Spell_ID ] = st ;
} while ( result -> NextRow () );
delete result ;
2009-04-03 16:36:20 -06:00
sLog . outString ();
2008-11-17 22:07:21 -06:00
sLog . outString ( ">> Loaded %u spell teleport coordinates" , count );
}
void SpellMgr :: LoadSpellAffects ()
{
mSpellAffectMap . clear (); // need for reload case
uint32 count = 0 ;
2008-12-24 09:58:26 -06:00
// 0 1 2 3 4
QueryResult * result = WorldDatabase . Query ( "SELECT entry, effectId, SpellClassMask0, SpellClassMask1, SpellClassMask2 FROM spell_affect" );
2008-11-17 22:07:21 -06:00
if ( ! result )
{
barGoLink bar ( 1 );
bar . step ();
2009-04-03 16:36:20 -06:00
sLog . outString ();
2008-11-17 22:07:21 -06:00
sLog . outString ( ">> Loaded %u spell affect definitions" , count );
return ;
}
barGoLink bar ( result -> GetRowCount () );
do
{
Field * fields = result -> Fetch ();
bar . step ();
uint16 entry = fields [ 0 ]. GetUInt16 ();
uint8 effectId = fields [ 1 ]. GetUInt8 ();
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( entry );
if ( ! spellInfo )
{
sLog . outErrorDb ( "Spell %u listed in `spell_affect` does not exist" , entry );
continue ;
}
if ( effectId >= 3 )
{
sLog . outErrorDb ( "Spell %u listed in `spell_affect` have invalid effect index (%u)" , entry , effectId );
continue ;
}
if ( spellInfo -> Effect [ effectId ] != SPELL_EFFECT_APPLY_AURA ||
spellInfo -> EffectApplyAuraName [ effectId ] != SPELL_AURA_ADD_FLAT_MODIFIER &&
spellInfo -> EffectApplyAuraName [ effectId ] != SPELL_AURA_ADD_PCT_MODIFIER &&
spellInfo -> EffectApplyAuraName [ effectId ] != SPELL_AURA_ADD_TARGET_TRIGGER )
{
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 );
continue ;
}
2009-02-02 17:01:56 +01:00
flag96 affect ( fields [ 2 ]. GetUInt32 (), fields [ 3 ]. GetUInt32 (), fields [ 4 ]. GetUInt32 ());
2008-11-17 22:07:21 -06:00
2008-12-24 09:58:26 -06:00
// Spell.dbc have own data
2009-02-02 17:01:56 +01:00
if ( effectId > 3 )
continue ;
flag96 dbc_affect ;
dbc_affect = spellInfo -> EffectSpellClassMask [ effectId ];
if ( dbc_affect [ 0 ] == affect [ 0 ] || dbc_affect [ 1 ] == affect [ 1 ] || dbc_affect [ 2 ] == affect [ 2 ])
2008-12-24 09:58:26 -06:00
{
char text [] = "ABC" ;
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 );
continue ;
2008-11-17 22:07:21 -06:00
}
2008-12-24 09:58:26 -06:00
mSpellAffectMap [( entry << 8 ) + effectId ] = affect ;
2008-11-17 22:07:21 -06:00
++ count ;
} while ( result -> NextRow () );
delete result ;
2009-04-03 16:36:20 -06:00
sLog . outString ();
2008-12-24 09:58:26 -06:00
sLog . outString ( ">> Loaded %u custom spell affect definitions" , count );
2008-11-17 22:07:21 -06:00
for ( uint32 id = 0 ; id < sSpellStore . GetNumRows (); ++ id )
{
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( id );
if ( ! spellInfo )
continue ;
for ( int effectId = 0 ; effectId < 3 ; ++ effectId )
{
if ( spellInfo -> Effect [ effectId ] != SPELL_EFFECT_APPLY_AURA ||
( spellInfo -> EffectApplyAuraName [ effectId ] != SPELL_AURA_ADD_FLAT_MODIFIER &&
spellInfo -> EffectApplyAuraName [ effectId ] != SPELL_AURA_ADD_PCT_MODIFIER &&
spellInfo -> EffectApplyAuraName [ effectId ] != SPELL_AURA_ADD_TARGET_TRIGGER ) )
continue ;
2009-02-02 17:01:56 +01:00
flag96 dbc_affect ;
dbc_affect = spellInfo -> EffectSpellClassMask [ effectId ];
if ( dbc_affect )
2008-11-17 22:07:21 -06:00
continue ;
if ( mSpellAffectMap . find (( id << 8 ) + effectId ) != mSpellAffectMap . end ())
continue ;
sLog . outErrorDb ( "Spell %u (%s) misses spell_affect for effect %u" , id , spellInfo -> SpellName [ sWorld . GetDefaultDbcLocale ()], effectId );
}
}
}
2008-12-24 09:58:26 -06:00
bool SpellMgr :: IsAffectedByMod ( SpellEntry const * spellInfo , SpellModifier * mod ) const
2008-11-17 22:07:21 -06:00
{
// false for spellInfo == NULL
2008-12-24 09:58:26 -06:00
if ( ! spellInfo || ! mod )
2008-11-17 22:07:21 -06:00
return false ;
2008-12-24 09:58:26 -06:00
SpellEntry const * affect_spell = sSpellStore . LookupEntry ( mod -> spellId );
// False if affect_spell == NULL or spellFamily not equal
if ( ! affect_spell || affect_spell -> SpellFamilyName != spellInfo -> SpellFamilyName )
2008-11-17 22:07:21 -06:00
return false ;
// true
2009-02-02 17:01:56 +01:00
if ( mod -> mask & spellInfo -> SpellFamilyFlags )
2008-11-17 22:07:21 -06:00
return true ;
return false ;
}
void SpellMgr :: LoadSpellProcEvents ()
{
mSpellProcEventMap . clear (); // need for reload case
uint32 count = 0 ;
2009-01-06 13:45:49 -06:00
// 0 1 2 3 4 5 6 7 8 9 10
QueryResult * result = WorldDatabase . Query ( "SELECT entry, SchoolMask, SpellFamilyName, SpellFamilyMask0, SpellFamilyMask1, SpellFamilyMask2, procFlags, procEx, ppmRate, CustomChance, Cooldown FROM spell_proc_event" );
2008-11-17 22:07:21 -06:00
if ( ! result )
{
barGoLink bar ( 1 );
bar . step ();
2009-04-03 16:36:20 -06:00
sLog . outString ();
2008-11-17 22:07:21 -06:00
sLog . outString ( ">> Loaded %u spell proc event conditions" , count );
return ;
}
barGoLink bar ( result -> GetRowCount () );
2008-11-26 15:14:03 -06:00
uint32 customProc = 0 ;
2008-11-17 22:07:21 -06:00
do
{
Field * fields = result -> Fetch ();
bar . step ();
2009-01-29 19:33:39 -06:00
uint32 entry = fields [ 0 ]. GetUInt32 ();
2008-11-17 22:07:21 -06:00
2008-11-26 15:14:03 -06:00
const SpellEntry * spell = sSpellStore . LookupEntry ( entry );
if ( ! spell )
2008-11-17 22:07:21 -06:00
{
sLog . outErrorDb ( "Spell %u listed in `spell_proc_event` does not exist" , entry );
continue ;
}
SpellProcEventEntry spe ;
spe . schoolMask = fields [ 1 ]. GetUInt32 ();
2008-11-26 15:14:03 -06:00
spe . spellFamilyName = fields [ 2 ]. GetUInt32 ();
2009-02-25 21:15:38 +01:00
spe . spellFamilyMask [ 0 ] = fields [ 3 ]. GetUInt32 ();
spe . spellFamilyMask [ 1 ] = fields [ 4 ]. GetUInt32 ();
spe . spellFamilyMask [ 2 ] = fields [ 5 ]. GetUInt32 ();
2009-01-06 13:45:49 -06:00
spe . procFlags = fields [ 6 ]. GetUInt32 ();
spe . procEx = fields [ 7 ]. GetUInt32 ();
spe . ppmRate = fields [ 8 ]. GetFloat ();
spe . customChance = fields [ 9 ]. GetFloat ();
spe . cooldown = fields [ 10 ]. GetUInt32 ();
2008-11-17 22:07:21 -06:00
mSpellProcEventMap [ entry ] = spe ;
2008-11-26 15:14:03 -06:00
if ( spell -> procFlags == 0 )
{
if ( spe . procFlags == 0 )
{
sLog . outErrorDb ( "Spell %u listed in `spell_proc_event` probally not triggered spell" , entry );
continue ;
}
customProc ++ ;
}
2008-11-17 22:07:21 -06:00
++ count ;
} while ( result -> NextRow () );
delete result ;
2009-04-03 16:36:20 -06:00
sLog . outString ();
2008-11-26 15:14:03 -06:00
if ( customProc )
2008-12-28 12:10:31 -06:00
sLog . outString ( ">> Loaded %u extra spell proc event conditions +%u custom" , count , customProc );
2008-11-26 15:14:03 -06:00
else
2008-12-28 12:10:31 -06:00
sLog . outString ( ">> Loaded %u extra spell proc event conditions" , count );
2008-11-17 22:07:21 -06:00
}
2008-11-26 15:14:03 -06:00
2009-01-29 19:33:39 -06:00
void SpellMgr :: LoadSpellBonusess ()
{
mSpellBonusMap . clear (); // need for reload case
uint32 count = 0 ;
// 0 1 2 3
QueryResult * result = WorldDatabase . Query ( "SELECT entry, direct_bonus, dot_bonus, ap_bonus FROM spell_bonus_data" );
if ( ! result )
{
barGoLink bar ( 1 );
bar . step ();
2009-04-03 16:36:20 -06:00
sLog . outString ();
2009-01-29 19:33:39 -06:00
sLog . outString ( ">> Loaded %u spell bonus data" , count );
return ;
}
barGoLink bar ( result -> GetRowCount () );
do
{
Field * fields = result -> Fetch ();
bar . step ();
uint32 entry = fields [ 0 ]. GetUInt32 ();
const SpellEntry * spell = sSpellStore . LookupEntry ( entry );
if ( ! spell )
{
sLog . outErrorDb ( "Spell %u listed in `spell_bonus_data` does not exist" , entry );
continue ;
}
SpellBonusEntry sbe ;
sbe . direct_damage = fields [ 1 ]. GetFloat ();
sbe . dot_damage = fields [ 2 ]. GetFloat ();
sbe . ap_bonus = fields [ 3 ]. GetFloat ();
mSpellBonusMap [ entry ] = sbe ;
} while ( result -> NextRow () );
delete result ;
2009-04-03 16:36:20 -06:00
sLog . outString ();
2009-01-29 19:33:39 -06:00
sLog . outString ( ">> Loaded %u extra spell bonus data" , count );
}
2009-04-13 18:56:29 +02:00
bool SpellMgr :: IsSpellProcEventCanTriggeredBy ( SpellProcEventEntry const * spellProcEvent , uint32 EventProcFlag , SpellEntry const * procSpell , uint32 procFlags , uint32 procExtra , bool active )
2008-11-26 15:14:03 -06:00
{
// No extra req need
uint32 procEvent_procEx = PROC_EX_NONE ;
// check prockFlags for condition
if (( procFlags & EventProcFlag ) == 0 )
return false ;
2009-05-17 18:00:33 +02:00
bool hasFamilyMask = false ;
2009-05-15 16:59:27 +02:00
/* Check Periodic Auras
* Both hots and dots can trigger if spell has no PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
nor PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT
*Only Hots can trigger if spell has PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
*Only dots can trigger if spell has both positivity flags or PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT
*/
if ( procFlags & PROC_FLAG_ON_DO_PERIODIC )
{
if ( EventProcFlag & PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT )
{
if ( ! ( procExtra & PROC_EX_INTERNAL_DOT ))
return false ;
}
else if ( EventProcFlag & PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
&& ! ( procExtra & PROC_EX_INTERNAL_HOT ))
return false ;
}
if ( procFlags & PROC_FLAG_ON_TAKE_PERIODIC )
{
if ( EventProcFlag & PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT )
{
if ( ! ( procExtra & PROC_EX_INTERNAL_DOT ))
return false ;
}
else if ( EventProcFlag & PROC_FLAG_TAKEN_POSITIVE_SPELL
&& ! ( procExtra & PROC_EX_INTERNAL_HOT ))
return false ;
}
2008-11-26 15:14:03 -06:00
// Always trigger for this
2009-01-25 16:35:14 -06:00
if ( EventProcFlag & ( PROC_FLAG_KILLED | PROC_FLAG_KILL | PROC_FLAG_ON_TRAP_ACTIVATION ))
2008-11-26 15:14:03 -06:00
return true ;
if ( spellProcEvent ) // Exist event data
{
// Store extra req
procEvent_procEx = spellProcEvent -> procEx ;
// For melee triggers
if ( procSpell == NULL )
{
// Check (if set) for school (melee attack have Normal school)
if ( spellProcEvent -> schoolMask && ( spellProcEvent -> schoolMask & SPELL_SCHOOL_MASK_NORMAL ) == 0 )
return false ;
}
else // For spells need check school/spell family/family mask
{
// Check (if set) for school
if ( spellProcEvent -> schoolMask && ( spellProcEvent -> schoolMask & procSpell -> SchoolMask ) == 0 )
return false ;
// Check (if set) for spellFamilyName
if ( spellProcEvent -> spellFamilyName && ( spellProcEvent -> spellFamilyName != procSpell -> SpellFamilyName ))
return false ;
// spellFamilyName is Ok need check for spellFamilyMask if present
2009-02-25 21:15:38 +01:00
if ( spellProcEvent -> spellFamilyMask )
2008-11-26 15:14:03 -06:00
{
2009-04-12 18:31:22 +02:00
if (( spellProcEvent -> spellFamilyMask & procSpell -> SpellFamilyFlags ) == 0 )
2008-11-26 15:14:03 -06:00
return false ;
active = true ; // Spell added manualy -> so its active spell
2009-05-17 18:00:33 +02:00
hasFamilyMask = true ;
2008-11-26 15:14:03 -06:00
}
}
}
2009-04-18 21:25:48 +02:00
2009-05-17 18:00:33 +02:00
if ( procExtra & PROC_EX_INTERNAL_REQ_FAMILY )
{
if ( ! hasFamilyMask )
return false ;
}
2008-11-26 15:14:03 -06:00
// Check for extra req (if none) and hit/crit
if ( procEvent_procEx == PROC_EX_NONE )
{
// No extra req, so can trigger only for active (damage/healing present) and hit/crit
if (( procExtra & ( PROC_EX_NORMAL_HIT | PROC_EX_CRITICAL_HIT )) && active )
return true ;
}
else // Passive spells hits here only if resist/reflect/immune/evade
{
// Exist req for PROC_EX_EX_TRIGGER_ALWAYS
2009-04-18 21:25:48 +02:00
if (( procExtra & AURA_SPELL_PROC_EX_MASK ) && ( procEvent_procEx & PROC_EX_EX_TRIGGER_ALWAYS ))
2008-11-26 15:14:03 -06:00
return true ;
// Passive spells can`t trigger if need hit
if (( procEvent_procEx & PROC_EX_NORMAL_HIT ) && ! active )
return false ;
// Check Extra Requirement like (hit/crit/miss/resist/parry/dodge/block/immune/reflect/absorb and other)
if ( procEvent_procEx & procExtra )
return true ;
}
return false ;
}
2008-11-17 22:07:21 -06:00
void SpellMgr :: LoadSpellElixirs ()
{
mSpellElixirs . clear (); // need for reload case
uint32 count = 0 ;
// 0 1
QueryResult * result = WorldDatabase . Query ( "SELECT entry, mask FROM spell_elixir" );
if ( ! result )
{
barGoLink bar ( 1 );
bar . step ();
2009-04-03 16:36:20 -06:00
sLog . outString ();
2008-11-17 22:07:21 -06:00
sLog . outString ( ">> Loaded %u spell elixir definitions" , count );
return ;
}
barGoLink bar ( result -> GetRowCount () );
do
{
Field * fields = result -> Fetch ();
bar . step ();
uint16 entry = fields [ 0 ]. GetUInt16 ();
uint8 mask = fields [ 1 ]. GetUInt8 ();
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( entry );
if ( ! spellInfo )
{
sLog . outErrorDb ( "Spell %u listed in `spell_elixir` does not exist" , entry );
continue ;
}
mSpellElixirs [ entry ] = mask ;
++ count ;
} while ( result -> NextRow () );
delete result ;
2009-04-03 16:36:20 -06:00
sLog . outString ();
2008-11-17 22:07:21 -06:00
sLog . outString ( ">> Loaded %u spell elixir definitions" , count );
}
void SpellMgr :: LoadSpellThreats ()
{
sSpellThreatStore . Free (); // for reload
sSpellThreatStore . Load ();
sLog . outString ( ">> Loaded %u aggro generating spells" , sSpellThreatStore . RecordCount );
2009-04-03 16:36:20 -06:00
sLog . outString ();
2008-11-17 22:07:21 -06:00
}
bool SpellMgr :: IsRankSpellDueToSpell ( SpellEntry const * spellInfo_1 , uint32 spellId_2 ) const
{
SpellEntry const * spellInfo_2 = sSpellStore . LookupEntry ( spellId_2 );
if ( ! spellInfo_1 || ! spellInfo_2 ) return false ;
if ( spellInfo_1 -> Id == spellId_2 ) return false ;
return GetFirstSpellInChain ( spellInfo_1 -> Id ) == GetFirstSpellInChain ( spellId_2 );
}
bool SpellMgr :: canStackSpellRanks ( SpellEntry const * spellInfo )
{
2009-01-25 16:35:14 -06:00
if ( IsPassiveSpell ( spellInfo -> Id )) // ranked passive spell
return false ;
2008-11-17 22:07:21 -06:00
if ( spellInfo -> powerType != POWER_MANA && spellInfo -> powerType != POWER_HEALTH )
return false ;
2009-01-14 00:35:13 -06:00
if ( IsProfessionOrRidingSpell ( spellInfo -> Id ))
2008-11-17 22:07:21 -06:00
return false ;
2009-01-25 16:35:14 -06:00
if ( spellmgr . IsSkillBonusSpell ( spellInfo -> Id ))
return false ;
2008-11-17 22:07:21 -06:00
// All stance spells. if any better way, change it.
2009-04-29 00:26:07 -05:00
for ( int i = 0 ; i < 3 ; ++ i )
2008-11-17 22:07:21 -06:00
{
2009-01-25 16:35:14 -06:00
switch ( spellInfo -> SpellFamilyName )
{
case SPELLFAMILY_PALADIN :
// Paladin aura Spell
if ( spellInfo -> Effect [ i ] == SPELL_EFFECT_APPLY_AREA_AURA_RAID )
return false ;
break ;
case SPELLFAMILY_DRUID :
// Druid form Spell
if ( spellInfo -> Effect [ i ] == SPELL_EFFECT_APPLY_AURA &&
spellInfo -> EffectApplyAuraName [ i ] == SPELL_AURA_MOD_SHAPESHIFT )
return false ;
break ;
case SPELLFAMILY_ROGUE :
// Rogue Stealth
if ( spellInfo -> Effect [ i ] == SPELL_EFFECT_APPLY_AURA &&
spellInfo -> EffectApplyAuraName [ i ] == SPELL_AURA_MOD_SHAPESHIFT )
return false ;
}
2008-11-17 22:07:21 -06:00
}
return true ;
}
2009-01-14 00:35:13 -06:00
bool SpellMgr :: IsProfessionOrRidingSpell ( uint32 spellId )
2008-11-17 22:07:21 -06:00
{
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( spellId );
if ( ! spellInfo )
return false ;
if ( spellInfo -> Effect [ 1 ] != SPELL_EFFECT_SKILL )
return false ;
uint32 skill = spellInfo -> EffectMiscValue [ 1 ];
2009-01-14 00:35:13 -06:00
return IsProfessionOrRidingSkill ( skill );
2008-11-17 22:07:21 -06:00
}
2009-01-16 15:53:34 -06:00
bool SpellMgr :: IsProfessionSpell ( uint32 spellId )
{
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( spellId );
if ( ! spellInfo )
return false ;
if ( spellInfo -> Effect [ 1 ] != SPELL_EFFECT_SKILL )
return false ;
uint32 skill = spellInfo -> EffectMiscValue [ 1 ];
return IsProfessionSkill ( skill );
}
2008-11-17 22:07:21 -06:00
bool SpellMgr :: IsPrimaryProfessionSpell ( uint32 spellId )
{
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( spellId );
if ( ! spellInfo )
return false ;
if ( spellInfo -> Effect [ 1 ] != SPELL_EFFECT_SKILL )
return false ;
uint32 skill = spellInfo -> EffectMiscValue [ 1 ];
return IsPrimaryProfessionSkill ( skill );
}
bool SpellMgr :: IsPrimaryProfessionFirstRankSpell ( uint32 spellId ) const
{
return IsPrimaryProfessionSpell ( spellId ) && GetSpellRank ( spellId ) == 1 ;
}
2009-01-25 16:35:14 -06:00
bool SpellMgr :: IsSkillBonusSpell ( uint32 spellId ) const
{
SkillLineAbilityMap :: const_iterator lower = GetBeginSkillLineAbilityMap ( spellId );
SkillLineAbilityMap :: const_iterator upper = GetEndSkillLineAbilityMap ( spellId );
for ( SkillLineAbilityMap :: const_iterator _spell_idx = lower ; _spell_idx != upper ; ++ _spell_idx )
{
SkillLineAbilityEntry const * pAbility = _spell_idx -> second ;
if ( ! pAbility || pAbility -> learnOnGetSkill != ABILITY_LEARNED_ON_GET_PROFESSION_SKILL )
continue ;
if ( pAbility -> req_skill_value > 0 )
return true ;
}
return false ;
}
2008-11-17 22:07:21 -06:00
SpellEntry const * SpellMgr :: SelectAuraRankForPlayerLevel ( SpellEntry const * spellInfo , uint32 playerLevel ) const
{
// ignore passive spells
if ( IsPassiveSpell ( spellInfo -> Id ))
return spellInfo ;
bool needRankSelection = false ;
2009-04-29 00:26:07 -05:00
for ( int i = 0 ; i < 3 ; ++ i )
2008-11-17 22:07:21 -06:00
{
if ( IsPositiveEffect ( spellInfo -> Id , i ) && (
spellInfo -> Effect [ i ] == SPELL_EFFECT_APPLY_AURA ||
2008-12-24 09:58:26 -06:00
spellInfo -> Effect [ i ] == SPELL_EFFECT_APPLY_AREA_AURA_PARTY ||
spellInfo -> Effect [ i ] == SPELL_EFFECT_APPLY_AREA_AURA_RAID
2008-11-17 22:07:21 -06:00
) )
{
needRankSelection = true ;
break ;
}
}
// not required
if ( ! needRankSelection )
return spellInfo ;
for ( uint32 nextSpellId = spellInfo -> Id ; nextSpellId != 0 ; nextSpellId = GetPrevSpellInChain ( nextSpellId ))
{
SpellEntry const * nextSpellInfo = sSpellStore . LookupEntry ( nextSpellId );
if ( ! nextSpellInfo )
break ;
// if found appropriate level
if ( playerLevel + 10 >= nextSpellInfo -> spellLevel )
return nextSpellInfo ;
// one rank less then
}
// not found
return NULL ;
}
2009-05-15 16:26:00 -05:00
void SpellMgr :: LoadSpellLearnSkills ()
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
mSpellLearnSkills . clear (); // need for reload case
2008-12-14 23:01:02 +01:00
2009-05-15 16:26:00 -05:00
// search auto-learned skills and add its to map also for use in unlearn spells/talents
uint32 dbc_count = 0 ;
barGoLink bar ( sSpellStore . GetNumRows () );
for ( uint32 spell = 0 ; spell < sSpellStore . GetNumRows (); ++ spell )
{
bar . step ();
SpellEntry const * entry = sSpellStore . LookupEntry ( spell );
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( ! entry )
continue ;
for ( int i = 0 ; i < 3 ; ++ i )
{
if ( entry -> Effect [ i ] == SPELL_EFFECT_SKILL )
{
SpellLearnSkillNode dbc_node ;
dbc_node . skill = entry -> EffectMiscValue [ i ];
if ( dbc_node . skill != SKILL_RIDING )
dbc_node . value = 1 ;
else
dbc_node . value = entry -> CalculateSimpleValue ( i ) * 75 ;
dbc_node . maxvalue = entry -> CalculateSimpleValue ( i ) * 75 ;
SpellLearnSkillNode const * db_node = GetSpellLearnSkill ( spell );
mSpellLearnSkills [ spell ] = dbc_node ;
++ dbc_count ;
break ;
}
}
}
sLog . outString ();
sLog . outString ( ">> Loaded %u Spell Learn Skills from DBC" , dbc_count );
}
void SpellMgr :: LoadSpellLearnSpells ()
{
mSpellLearnSpells . clear (); // need for reload case
// 0 1 2
QueryResult * result = WorldDatabase . Query ( "SELECT entry, SpellID, Active FROM spell_learn_spell" );
if ( ! result )
2008-11-17 22:07:21 -06:00
{
barGoLink bar ( 1 );
bar . step ();
2009-04-03 16:36:20 -06:00
sLog . outString ();
2009-05-15 16:26:00 -05:00
sLog . outString ( ">> Loaded 0 spell learn spells" );
sLog . outErrorDb ( "`spell_learn_spell` table is empty!" );
2008-11-17 22:07:21 -06:00
return ;
}
2009-05-15 16:26:00 -05:00
uint32 count = 0 ;
2008-11-17 22:07:21 -06:00
barGoLink bar ( result -> GetRowCount () );
do
{
bar . step ();
Field * fields = result -> Fetch ();
2009-05-15 16:26:00 -05:00
uint32 spell_id = fields [ 0 ]. GetUInt32 ();
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
SpellLearnSpellNode node ;
node . spell = fields [ 1 ]. GetUInt32 ();
node . active = fields [ 2 ]. GetBool ();
node . autoLearned = false ;
if ( ! sSpellStore . LookupEntry ( spell_id ))
{
sLog . outErrorDb ( "Spell %u listed in `spell_learn_spell` does not exist" , spell_id );
continue ;
}
if ( ! sSpellStore . LookupEntry ( node . spell ))
{
sLog . outErrorDb ( "Spell %u listed in `spell_learn_spell` does not exist" , node . spell );
continue ;
}
mSpellLearnSpells . insert ( SpellLearnSpellMap :: value_type ( spell_id , node ));
++ count ;
2008-12-14 23:01:02 +01:00
} while ( result -> NextRow () );
2009-05-15 16:26:00 -05:00
2008-12-14 23:01:02 +01:00
delete result ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
// search auto-learned spells and add its to map also for use in unlearn spells/talents
uint32 dbc_count = 0 ;
for ( uint32 spell = 0 ; spell < sSpellStore . GetNumRows (); ++ spell )
{
SpellEntry const * entry = sSpellStore . LookupEntry ( spell );
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( ! entry )
continue ;
2008-12-22 02:11:11 +01:00
2009-05-15 16:26:00 -05:00
for ( int i = 0 ; i < 3 ; ++ i )
{
if ( entry -> Effect [ i ] == SPELL_EFFECT_LEARN_SPELL )
{
SpellLearnSpellNode dbc_node ;
dbc_node . spell = entry -> EffectTriggerSpell [ i ];
dbc_node . active = true ; // all dbc based learned spells is active (show in spell book or hide by client itself)
2009-02-02 18:55:03 +01:00
2009-05-15 16:26:00 -05:00
// ignore learning not existed spells (broken/outdated/or generic learnig spell 483
if ( ! sSpellStore . LookupEntry ( dbc_node . spell ))
continue ;
2009-02-02 18:55:03 +01:00
2009-05-15 16:26:00 -05:00
// talent or passive spells or skill-step spells auto-casted and not need dependent learning,
// pet teaching spells don't must be dependent learning (casted)
// other required explicit dependent learning
dbc_node . autoLearned = entry -> EffectImplicitTargetA [ i ] == TARGET_UNIT_PET || GetTalentSpellCost ( spell ) > 0 || IsPassiveSpell ( spell ) || IsSpellHaveEffect ( entry , SPELL_EFFECT_SKILL_STEP );
SpellLearnSpellMap :: const_iterator db_node_begin = GetBeginSpellLearnSpell ( spell );
SpellLearnSpellMap :: const_iterator db_node_end = GetEndSpellLearnSpell ( spell );
bool found = false ;
for ( SpellLearnSpellMap :: const_iterator itr = db_node_begin ; itr != db_node_end ; ++ itr )
{
if ( itr -> second . spell == dbc_node . spell )
{
sLog . outErrorDb ( "Spell %u auto-learn spell %u in spell.dbc then the record in `spell_learn_spell` is redundant, please fix DB." ,
spell , dbc_node . spell );
found = true ;
break ;
}
}
if ( ! found ) // add new spell-spell pair if not found
{
mSpellLearnSpells . insert ( SpellLearnSpellMap :: value_type ( spell , dbc_node ));
++ dbc_count ;
}
}
}
2008-12-22 02:11:11 +01:00
}
2008-12-21 23:14:42 -06:00
2009-05-15 16:26:00 -05:00
sLog . outString ();
sLog . outString ( ">> Loaded %u spell learn spells + %u found in DBC" , count , dbc_count );
}
2008-12-21 23:14:42 -06:00
2009-05-15 16:26:00 -05:00
void SpellMgr :: LoadSpellScriptTarget ()
2008-12-21 23:14:42 -06:00
{
2009-05-15 16:26:00 -05:00
mSpellScriptTarget . clear (); // need for reload case
2008-12-14 23:01:02 +01:00
2009-05-15 16:26:00 -05:00
uint32 count = 0 ;
QueryResult * result = WorldDatabase . Query ( "SELECT entry,type,targetEntry FROM spell_script_target" );
if ( ! result )
2008-12-31 20:06:25 +01:00
{
2009-05-15 16:26:00 -05:00
barGoLink bar ( 1 );
bar . step ();
sLog . outString ();
sLog . outErrorDb ( ">> Loaded 0 SpellScriptTarget. DB table `spell_script_target` is empty." );
return ;
2008-12-31 20:06:25 +01:00
}
2009-05-15 16:26:00 -05:00
barGoLink bar ( result -> GetRowCount ());
2008-12-22 02:11:11 +01:00
2009-05-15 16:26:00 -05:00
do
2008-12-22 02:11:11 +01:00
{
2009-05-15 16:26:00 -05:00
Field * fields = result -> Fetch ();
bar . step ();
uint32 spellId = fields [ 0 ]. GetUInt32 ();
uint32 type = fields [ 1 ]. GetUInt32 ();
uint32 targetEntry = fields [ 2 ]. GetUInt32 ();
SpellEntry const * spellProto = sSpellStore . LookupEntry ( spellId );
if ( ! spellProto )
{
sLog . outErrorDb ( "Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist." , spellId , targetEntry );
2008-11-17 22:07:21 -06:00
continue ;
2009-05-15 16:26:00 -05:00
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
/*bool targetfound = false;
for(int i = 0; i <3; ++i)
2008-12-31 20:06:25 +01:00
{
2009-05-15 16:26:00 -05:00
if( spellProto->EffectImplicitTargetA[i]==TARGET_UNIT_NEARBY_ENTRY ||
spellProto->EffectImplicitTargetB[i]==TARGET_UNIT_NEARBY_ENTRY ||
spellProto->EffectImplicitTargetA[i]==TARGET_DST_NEARBY_ENTRY ||
spellProto->EffectImplicitTargetB[i]==TARGET_DST_NEARBY_ENTRY )
{
targetfound = true;
break;
}
2008-12-31 20:06:25 +01:00
}
2009-05-15 16:26:00 -05:00
if(!targetfound)
{
sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not have any implicit target TARGET_UNIT_NEARBY_ENTRY(38) or TARGET_DST_NEARBY_ENTRY (46).",spellId,targetEntry);
2008-12-31 20:06:25 +01:00
continue;
2009-05-15 16:26:00 -05:00
}*/
2008-12-31 20:06:25 +01:00
2009-05-15 16:26:00 -05:00
if ( type >= MAX_SPELL_TARGET_TYPE )
{
sLog . outErrorDb ( "Table `spell_script_target`: target type %u for TargetEntry %u is incorrect." , type , targetEntry );
2008-12-31 20:06:25 +01:00
continue ;
2009-05-15 16:26:00 -05:00
}
2008-12-22 02:11:11 +01:00
2009-05-15 16:26:00 -05:00
switch ( type )
2008-12-31 20:06:25 +01:00
{
2009-05-15 16:26:00 -05:00
case SPELL_TARGET_TYPE_GAMEOBJECT :
{
if ( targetEntry == 0 )
break ;
if ( ! sGOStorage . LookupEntry < GameObjectInfo > ( targetEntry ))
{
sLog . outErrorDb ( "Table `spell_script_target`: gameobject template entry %u does not exist." , targetEntry );
continue ;
}
break ;
}
default :
{
//players
/*if( targetEntry==0 )
{
sLog.outErrorDb("Table `spell_script_target`: target entry == 0 for not GO target type (%u).",type);
continue;
}*/
if ( targetEntry && ! sCreatureStorage . LookupEntry < CreatureInfo > ( targetEntry ))
{
sLog . outErrorDb ( "Table `spell_script_target`: creature template entry %u does not exist." , targetEntry );
continue ;
}
const CreatureInfo * cInfo = sCreatureStorage . LookupEntry < CreatureInfo > ( targetEntry );
if ( spellId == 30427 && ! cInfo -> SkinLootId )
{
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 );
continue ;
}
2008-12-31 20:06:25 +01:00
break ;
2009-05-15 16:26:00 -05:00
}
2008-12-31 20:06:25 +01:00
}
2008-12-22 02:11:11 +01:00
2009-05-15 16:26:00 -05:00
mSpellScriptTarget . insert ( SpellScriptTarget :: value_type ( spellId , SpellTargetEntry ( SpellScriptTargetType ( type ), targetEntry )));
2008-12-22 02:11:11 +01:00
2009-05-15 16:26:00 -05:00
++ count ;
} while ( result -> NextRow ());
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
delete result ;
// Check all spells
/* Disabled (lot errors at this moment)
for(uint32 i = 1; i < sSpellStore.nCount; ++i)
2008-12-22 02:11:11 +01:00
{
2009-05-15 16:26:00 -05:00
SpellEntry const * spellInfo = sSpellStore.LookupEntry(i);
if(!spellInfo)
continue;
2009-04-06 21:14:51 +02:00
2009-05-15 16:26:00 -05:00
bool found = false;
for(int j=0; j<3; ++j)
{
if( spellInfo->EffectImplicitTargetA[j] == TARGET_UNIT_NEARBY_ENTRY || spellInfo->EffectImplicitTargetA[j] != TARGET_UNIT_CASTER && spellInfo->EffectImplicitTargetB[j] == TARGET_UNIT_NEARBY_ENTRY )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
SpellScriptTarget::const_iterator lower = spellmgr.GetBeginSpellScriptTarget(spellInfo->Id);
SpellScriptTarget::const_iterator upper = spellmgr.GetEndSpellScriptTarget(spellInfo->Id);
if(lower==upper)
2009-02-02 18:55:03 +01:00
{
2009-05-15 16:26:00 -05:00
sLog.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = %u (TARGET_UNIT_NEARBY_ENTRY), but does not have record in `spell_script_target`",spellInfo->Id,TARGET_UNIT_NEARBY_ENTRY);
break; // effects of spell
2009-02-02 18:55:03 +01:00
}
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
}
}
*/
2009-02-02 18:55:03 +01:00
2009-05-15 16:26:00 -05:00
sLog . outString ();
sLog . outString ( ">> Loaded %u Spell Script Targets" , count );
}
2009-02-02 18:55:03 +01:00
2009-05-15 16:26:00 -05:00
void SpellMgr :: LoadSpellPetAuras ()
{
mSpellPetAuraMap . clear (); // need for reload case
2009-02-02 18:55:03 +01:00
2009-05-15 16:26:00 -05:00
uint32 count = 0 ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
// 0 1 2
QueryResult * result = WorldDatabase . Query ( "SELECT spell, pet, aura FROM spell_pet_auras" );
if ( ! result )
{
2008-12-22 02:11:11 +01:00
2009-05-15 16:26:00 -05:00
barGoLink bar ( 1 );
bar . step ();
sLog . outString ();
sLog . outString ( ">> Loaded %u spell pet auras" , count );
return ;
}
barGoLink bar ( result -> GetRowCount () );
do
{
Field * fields = result -> Fetch ();
bar . step ();
uint16 spell = fields [ 0 ]. GetUInt16 ();
uint16 pet = fields [ 1 ]. GetUInt16 ();
uint16 aura = fields [ 2 ]. GetUInt16 ();
SpellPetAuraMap :: iterator itr = mSpellPetAuraMap . find ( spell );
if ( itr != mSpellPetAuraMap . end ())
2008-12-22 02:11:11 +01:00
{
2009-05-15 16:26:00 -05:00
itr -> second . AddAura ( pet , aura );
2008-12-22 02:11:11 +01:00
}
2009-05-15 16:26:00 -05:00
else
2008-12-22 02:11:11 +01:00
{
2009-05-15 16:26:00 -05:00
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( spell );
if ( ! spellInfo )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
sLog . outErrorDb ( "Spell %u listed in `spell_pet_auras` does not exist" , spell );
continue ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
int i = 0 ;
for (; i < 3 ; ++ i )
if (( spellInfo -> Effect [ i ] == SPELL_EFFECT_APPLY_AURA &&
spellInfo -> EffectApplyAuraName [ i ] == SPELL_AURA_DUMMY ) ||
spellInfo -> Effect [ i ] == SPELL_EFFECT_DUMMY )
break ;
2008-12-22 02:11:11 +01:00
2009-05-15 16:26:00 -05:00
if ( i == 3 )
{
sLog . outError ( "Spell %u listed in `spell_pet_auras` does not have dummy aura or dummy effect" , spell );
continue ;
}
2008-12-22 02:11:11 +01:00
2009-05-15 16:26:00 -05:00
SpellEntry const * spellInfo2 = sSpellStore . LookupEntry ( aura );
if ( ! spellInfo2 )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
sLog . outErrorDb ( "Aura %u listed in `spell_pet_auras` does not exist" , aura );
continue ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
PetAura pa ( pet , aura , spellInfo -> EffectImplicitTargetA [ i ] == TARGET_UNIT_PET , spellInfo -> CalculateSimpleValue ( i ));
mSpellPetAuraMap [ spell ] = pa ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
++ count ;
} while ( result -> NextRow () );
delete result ;
2008-12-31 20:06:25 +01:00
2009-04-03 16:36:20 -06:00
sLog . outString ();
2009-05-15 16:26:00 -05:00
sLog . outString ( ">> Loaded %u spell pet auras" , count );
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:36:59 -05:00
static uint32 family2skillline [ MAX_CREATURE_FAMILY ][ 2 ] = {
/* ----------------------------- = 0 */ { 0 , 0 },
/*CREATURE_FAMILY_WOLF = 1 */ { 208 , 270 },
/*CREATURE_FAMILY_CAT = 2 */ { 209 , 270 },
/*CREATURE_FAMILY_SPIDER = 3 */ { 203 , 270 },
/*CREATURE_FAMILY_BEAR = 4 */ { 210 , 270 },
/*CREATURE_FAMILY_BOAR = 5 */ { 211 , 270 },
/*CREATURE_FAMILY_CROCOLISK = 6 */ { 212 , 270 },
/*CREATURE_FAMILY_CARRION_BIRD = 7 */ { 213 , 270 },
/*CREATURE_FAMILY_CRAB = 8 */ { 214 , 270 },
/*CREATURE_FAMILY_GORILLA = 9 */ { 215 , 270 },
/*CREATURE_FAMILY_HORSE_CUSTOM = 10*/ { 0 , 0 },
/*CREATURE_FAMILY_RAPTOR = 11*/ { 217 , 270 },
/*CREATURE_FAMILY_TALLSTRIDER = 12*/ { 218 , 270 },
/* ----------------------------- = 13*/ { 0 , 0 },
/* ----------------------------- = 14*/ { 0 , 0 },
/*CREATURE_FAMILY_FELHUNTER = 15*/ { 189 , 0 },
/*CREATURE_FAMILY_VOIDWALKER = 16*/ { 204 , 0 },
/*CREATURE_FAMILY_SUCCUBUS = 17*/ { 205 , 0 },
/* ----------------------------- = 18*/ { 0 , 0 },
/*CREATURE_FAMILY_DOOMGUARD = 19*/ { 207 , 0 },
/*CREATURE_FAMILY_SCORPID = 20*/ { 236 , 270 },
/*CREATURE_FAMILY_TURTLE = 21*/ { 251 , 270 },
/* ----------------------------- = 22*/ { 0 , 0 },
/*CREATURE_FAMILY_IMP = 23*/ { 188 , 0 },
/*CREATURE_FAMILY_BAT = 24*/ { 653 , 270 },
/*CREATURE_FAMILY_HYENA = 25*/ { 654 , 270 },
/*CREATURE_FAMILY_BIRD_OF_PREY = 26*/ { 655 , 270 },
/*CREATURE_FAMILY_WIND_SERPENT = 27*/ { 656 , 270 },
/*CREATURE_FAMILY_REMOTE_CONTROL = 28*/ { 758 , 0 },
/*CREATURE_FAMILY_FELGUARD = 29*/ { 761 , 0 },
/*CREATURE_FAMILY_DRAGONHAWK = 30*/ { 763 , 270 },
/*CREATURE_FAMILY_RAVAGER = 31*/ { 767 , 270 },
/*CREATURE_FAMILY_WARP_STALKER = 32*/ { 766 , 270 },
/*CREATURE_FAMILY_SPOREBAT = 33*/ { 765 , 270 },
/*CREATURE_FAMILY_NETHER_RAY = 34*/ { 764 , 270 },
/*CREATURE_FAMILY_SERPENT = 35*/ { 768 , 270 },
/* ----------------------------- = 36*/ { 0 , 0 },
/*CREATURE_FAMILY_MOTH = 37*/ { 775 , 270 },
/*CREATURE_FAMILY_CHIMAERA = 38*/ { 780 , 270 },
/*CREATURE_FAMILY_DEVILSAUR = 39*/ { 781 , 270 },
/*CREATURE_FAMILY_GHOUL = 40*/ { 782 , 0 },
/*CREATURE_FAMILY_SILITHID = 41*/ { 783 , 270 },
/*CREATURE_FAMILY_WORM = 42*/ { 784 , 270 },
/*CREATURE_FAMILY_RHINO = 43*/ { 786 , 270 },
/*CREATURE_FAMILY_WASP = 44*/ { 785 , 270 },
/*CREATURE_FAMILY_CORE_HOUND = 45*/ { 787 , 270 },
/*CREATURE_FAMILY_SPIRIT_BEAST = 46*/ { 788 , 270 }
};
2009-05-15 16:26:00 -05:00
/// Some checks for spells, to prevent adding depricated/broken spells for trainers, spell book, etc
void SpellMgr :: LoadPetLevelupSpellMap ()
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
mPetLevelupSpellMap . clear (); // need for reload case
2008-11-17 22:07:21 -06:00
2009-05-15 16:36:59 -05:00
uint32 count = 0 ;
2009-05-17 10:57:55 -05:00
uint32 family_count = 0 ;
2009-05-15 16:26:00 -05:00
for ( uint32 i = 0 ; i < sCreatureFamilyStore . GetNumRows (); ++ i )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:36:59 -05:00
CreatureFamilyEntry const * creatureFamily = sCreatureFamilyStore . LookupEntry ( i );
2009-05-15 16:26:00 -05:00
if ( ! creatureFamily ) // not exist
2008-11-17 22:07:21 -06:00
continue ;
2009-05-15 16:26:00 -05:00
for ( uint8 j = 0 ; j < 2 ; ++ j )
2008-11-17 22:07:21 -06:00
{
2009-05-16 14:49:58 -05:00
if ( ! creatureFamily -> skillLine [ j ])
2009-05-15 16:26:00 -05:00
continue ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:36:59 -05:00
for ( uint32 k = 0 ; k < sSkillLineAbilityStore . GetNumRows (); ++ k )
2009-05-15 16:26:00 -05:00
{
SkillLineAbilityEntry const * skillLine = sSkillLineAbilityStore . LookupEntry ( k );
2009-05-15 16:36:59 -05:00
if ( ! skillLine )
2009-05-15 16:26:00 -05:00
continue ;
2009-05-15 16:36:59 -05:00
if ( skillLine -> skillId != creatureFamily -> skillLine [ j ])
2009-05-15 16:26:00 -05:00
continue ;
2009-05-15 16:36:59 -05:00
if ( skillLine -> learnOnGetSkill != ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL )
continue ;
2009-05-15 16:26:00 -05:00
SpellEntry const * spell = sSpellStore . LookupEntry ( skillLine -> spellId );
2009-05-17 10:57:55 -05:00
if ( ! spell ) // not exist or triggered or talent
continue ;
if ( ! spell -> spellLevel )
2009-05-15 16:26:00 -05:00
continue ;
2009-05-17 10:57:55 -05:00
PetLevelupSpellSet & spellSet = mPetLevelupSpellMap [ creatureFamily -> ID ];
if ( spellSet . empty ())
++ family_count ;
spellSet . insert ( PetLevelupSpellSet :: value_type ( spell -> spellLevel , spell -> Id ));
2009-05-15 16:26:00 -05:00
count ++ ;
2008-11-17 22:07:21 -06:00
}
}
}
2009-04-03 16:36:20 -06:00
sLog . outString ();
2009-05-17 10:57:55 -05:00
sLog . outString ( ">> Loaded %u pet levelup and default spells for %u families" , count , family_count );
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
/// Some checks for spells, to prevent adding deprecated/broken spells for trainers, spell book, etc
bool SpellMgr :: IsSpellValid ( SpellEntry const * spellInfo , Player * pl , bool msg )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
// not exist
if ( ! spellInfo )
return false ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
bool need_check_reagents = false ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
// check effects
for ( int i = 0 ; i < 3 ; ++ i )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
switch ( spellInfo -> Effect [ i ])
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
case 0 :
continue ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
// craft spell for crafting non-existed item (break client recipes list show)
case SPELL_EFFECT_CREATE_ITEM :
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( ! ObjectMgr :: GetItemPrototype ( spellInfo -> EffectItemType [ i ] ))
{
if ( msg )
{
if ( pl )
ChatHandler ( pl ). PSendSysMessage ( "Craft spell %u create not-exist in DB item (Entry: %u) and then..." , spellInfo -> Id , spellInfo -> EffectItemType [ i ]);
else
sLog . outErrorDb ( "Craft spell %u create not-exist in DB item (Entry: %u) and then..." , spellInfo -> Id , spellInfo -> EffectItemType [ i ]);
}
return false ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
need_check_reagents = true ;
break ;
}
case SPELL_EFFECT_LEARN_SPELL :
{
SpellEntry const * spellInfo2 = sSpellStore . LookupEntry ( spellInfo -> EffectTriggerSpell [ i ]);
if ( ! IsSpellValid ( spellInfo2 , pl , msg ) )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( msg )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( pl )
ChatHandler ( pl ). PSendSysMessage ( "Spell %u learn to broken spell %u, and then..." , spellInfo -> Id , spellInfo -> EffectTriggerSpell [ i ]);
else
sLog . outErrorDb ( "Spell %u learn to invalid spell %u, and then..." , spellInfo -> Id , spellInfo -> EffectTriggerSpell [ i ]);
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
return false ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
break ;
}
}
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( need_check_reagents )
{
for ( int j = 0 ; j < 8 ; ++ j )
{
if ( spellInfo -> Reagent [ j ] > 0 && ! ObjectMgr :: GetItemPrototype ( spellInfo -> Reagent [ j ] ))
{
if ( msg )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( pl )
ChatHandler ( pl ). PSendSysMessage ( "Craft spell %u have not-exist reagent in DB item (Entry: %u) and then..." , spellInfo -> Id , spellInfo -> Reagent [ j ]);
else
sLog . outErrorDb ( "Craft spell %u have not-exist reagent in DB item (Entry: %u) and then..." , spellInfo -> Id , spellInfo -> Reagent [ j ]);
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
return false ;
2008-11-17 22:07:21 -06:00
}
}
}
2009-05-15 16:26:00 -05:00
return true ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
void SpellMgr :: LoadSpellAreas ()
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
mSpellAreaMap . clear (); // need for reload case
mSpellAreaForQuestMap . clear ();
mSpellAreaForActiveQuestMap . clear ();
mSpellAreaForQuestEndMap . clear ();
mSpellAreaForAuraMap . clear ();
2008-11-17 22:07:21 -06:00
uint32 count = 0 ;
2009-05-15 16:26:00 -05:00
// 0 1 2 3 4 5 6 7 8
QueryResult * result = WorldDatabase . Query ( "SELECT spell, area, quest_start, quest_start_active, quest_end, aura_spell, racemask, gender, autocast FROM spell_area" );
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( ! result )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
barGoLink bar ( 1 );
2008-11-17 22:07:21 -06:00
bar . step ();
2009-04-03 16:36:20 -06:00
sLog . outString ();
2009-05-15 16:26:00 -05:00
sLog . outString ( ">> Loaded %u spell area requirements" , count );
2008-11-17 22:07:21 -06:00
return ;
}
2009-05-15 16:26:00 -05:00
barGoLink bar ( result -> GetRowCount () );
2008-11-17 22:07:21 -06:00
do
{
Field * fields = result -> Fetch ();
2009-05-15 16:26:00 -05:00
bar . step ();
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
uint32 spell = fields [ 0 ]. GetUInt32 ();
SpellArea spellArea ;
spellArea . spellId = spell ;
spellArea . areaId = fields [ 1 ]. GetUInt32 ();
spellArea . questStart = fields [ 2 ]. GetUInt32 ();
spellArea . questStartCanActive = fields [ 3 ]. GetBool ();
spellArea . questEnd = fields [ 4 ]. GetUInt32 ();
spellArea . auraSpell = fields [ 5 ]. GetInt32 ();
spellArea . raceMask = fields [ 6 ]. GetUInt32 ();
spellArea . gender = Gender ( fields [ 7 ]. GetUInt8 ());
spellArea . autocast = fields [ 8 ]. GetBool ();
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( ! sSpellStore . LookupEntry ( spell ))
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
sLog . outErrorDb ( "Spell %u listed in `spell_area` does not exist" , spell );
2008-11-17 22:07:21 -06:00
continue ;
}
{
2009-05-15 16:26:00 -05:00
bool ok = true ;
SpellAreaMapBounds sa_bounds = GetSpellAreaMapBounds ( spellArea . spellId );
for ( SpellAreaMap :: const_iterator itr = sa_bounds . first ; itr != sa_bounds . second ; ++ itr )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( spellArea . spellId && itr -> second . spellId && spellArea . spellId != itr -> second . spellId )
continue ;
if ( spellArea . areaId && itr -> second . areaId && spellArea . areaId != itr -> second . areaId )
continue ;
if ( spellArea . questStart && itr -> second . questStart && spellArea . questStart != itr -> second . questStart )
continue ;
if ( spellArea . auraSpell && itr -> second . auraSpell && spellArea . auraSpell != itr -> second . auraSpell )
continue ;
if ( spellArea . raceMask && itr -> second . raceMask && ( spellArea . raceMask & itr -> second . raceMask ) == 0 )
continue ;
if ( spellArea . gender != GENDER_NONE && itr -> second . gender != GENDER_NONE && spellArea . gender != itr -> second . gender )
continue ;
// duplicate by requirements
ok = false ;
2008-11-17 22:07:21 -06:00
break ;
}
2009-05-15 16:26:00 -05:00
if ( ! ok )
{
sLog . outErrorDb ( "Spell %u listed in `spell_area` already listed with similar requirements." , spell );
continue ;
}
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
if ( spellArea . areaId && ! GetAreaEntryByAreaID ( spellArea . areaId ))
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
sLog . outErrorDb ( "Spell %u listed in `spell_area` have wrong area (%u) requirement" , spell , spellArea . areaId );
2008-11-17 22:07:21 -06:00
continue ;
2009-05-15 16:26:00 -05:00
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( spellArea . questStart && ! objmgr . GetQuestTemplate ( spellArea . questStart ))
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
sLog . outErrorDb ( "Spell %u listed in `spell_area` have wrong start quest (%u) requirement" , spell , spellArea . questStart );
2008-11-17 22:07:21 -06:00
continue ;
}
2009-05-15 16:26:00 -05:00
if ( spellArea . questEnd )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( ! objmgr . GetQuestTemplate ( spellArea . questEnd ))
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
sLog . outErrorDb ( "Spell %u listed in `spell_area` have wrong end quest (%u) requirement" , spell , spellArea . questEnd );
continue ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
if ( spellArea . questEnd == spellArea . questStart && ! spellArea . questStartCanActive )
{
sLog . outErrorDb ( "Spell %u listed in `spell_area` have quest (%u) requirement for start and end in same time" , spell , spellArea . questEnd );
continue ;
2008-11-17 22:07:21 -06:00
}
}
2009-05-15 16:26:00 -05:00
if ( spellArea . auraSpell )
{
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( abs ( spellArea . auraSpell ));
if ( ! spellInfo )
{
sLog . outErrorDb ( "Spell %u listed in `spell_area` have wrong aura spell (%u) requirement" , spell , abs ( spellArea . auraSpell ));
continue ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( spellInfo -> EffectApplyAuraName [ 0 ] != SPELL_AURA_DUMMY && spellInfo -> EffectApplyAuraName [ 0 ] != SPELL_AURA_PHASE )
{
sLog . outErrorDb ( "Spell %u listed in `spell_area` have aura spell requirement (%u) without dummy/phase aura in effect 0" , spell , abs ( spellArea . auraSpell ));
continue ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( abs ( spellArea . auraSpell ) == spellArea . spellId )
{
sLog . outErrorDb ( "Spell %u listed in `spell_area` have aura spell (%u) requirement for itself" , spell , abs ( spellArea . auraSpell ));
continue ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
// not allow autocast chains by auraSpell field (but allow use as alternative if not present)
if ( spellArea . autocast && spellArea . auraSpell > 0 )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
bool chain = false ;
SpellAreaForAuraMapBounds saBound = GetSpellAreaForAuraMapBounds ( spellArea . spellId );
for ( SpellAreaForAuraMap :: const_iterator itr = saBound . first ; itr != saBound . second ; ++ itr )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( itr -> second -> autocast && itr -> second -> auraSpell > 0 )
{
chain = true ;
break ;
}
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
if ( chain )
{
sLog . outErrorDb ( "Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura" , spell , spellArea . auraSpell );
continue ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
SpellAreaMapBounds saBound2 = GetSpellAreaMapBounds ( spellArea . auraSpell );
for ( SpellAreaMap :: const_iterator itr2 = saBound2 . first ; itr2 != saBound2 . second ; ++ itr2 )
{
if ( itr2 -> second . autocast && itr2 -> second . auraSpell > 0 )
{
chain = true ;
break ;
}
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( chain )
{
sLog . outErrorDb ( "Spell %u listed in `spell_area` have aura spell (%u) requirement that itself autocast from aura" , spell , spellArea . auraSpell );
continue ;
}
}
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( spellArea . raceMask && ( spellArea . raceMask & RACEMASK_ALL_PLAYABLE ) == 0 )
{
sLog . outErrorDb ( "Spell %u listed in `spell_area` have wrong race mask (%u) requirement" , spell , spellArea . raceMask );
continue ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( spellArea . gender != GENDER_NONE && spellArea . gender != GENDER_FEMALE && spellArea . gender != GENDER_MALE )
{
sLog . outErrorDb ( "Spell %u listed in `spell_area` have wrong gender (%u) requirement" , spell , spellArea . gender );
continue ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
SpellArea const * sa = & mSpellAreaMap . insert ( SpellAreaMap :: value_type ( spell , spellArea )) -> second ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
// for search by current zone/subzone at zone/subzone change
if ( spellArea . areaId )
mSpellAreaForAreaMap . insert ( SpellAreaForAreaMap :: value_type ( spellArea . areaId , sa ));
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
// for search at quest start/reward
if ( spellArea . questStart )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( spellArea . questStartCanActive )
mSpellAreaForActiveQuestMap . insert ( SpellAreaForQuestMap :: value_type ( spellArea . questStart , sa ));
else
mSpellAreaForQuestMap . insert ( SpellAreaForQuestMap :: value_type ( spellArea . questStart , sa ));
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
// for search at quest start/reward
if ( spellArea . questEnd )
mSpellAreaForQuestEndMap . insert ( SpellAreaForQuestMap :: value_type ( spellArea . questEnd , sa ));
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
// for search at aura apply
if ( spellArea . auraSpell )
mSpellAreaForAuraMap . insert ( SpellAreaForAuraMap :: value_type ( abs ( spellArea . auraSpell ), sa ));
2008-11-17 22:07:21 -06:00
++ count ;
} while ( result -> NextRow () );
delete result ;
2009-04-03 16:36:20 -06:00
sLog . outString ();
2009-05-15 16:26:00 -05:00
sLog . outString ( ">> Loaded %u spell area requirements" , count );
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
SpellCastResult SpellMgr :: GetSpellAllowedInLocationError ( SpellEntry const * spellInfo , uint32 map_id , uint32 zone_id , uint32 area_id , Player const * player )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
// normal case
if ( spellInfo -> AreaGroupId > 0 )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
bool found = false ;
AreaGroupEntry const * groupEntry = sAreaGroupStore . LookupEntry ( spellInfo -> AreaGroupId );
while ( groupEntry )
{
for ( uint32 i = 0 ; i < 6 ; ++ i )
if ( groupEntry -> AreaId [ i ] == zone_id || groupEntry -> AreaId [ i ] == area_id )
found = true ;
if ( found || ! groupEntry -> nextGroup )
break ;
// Try search in next group
groupEntry = sAreaGroupStore . LookupEntry ( groupEntry -> nextGroup );
}
if ( ! found )
return SPELL_FAILED_INCORRECT_AREA ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
// DB base check (if non empty then must fit at least single for allow)
SpellAreaMapBounds saBounds = spellmgr . GetSpellAreaMapBounds ( spellInfo -> Id );
if ( saBounds . first != saBounds . second )
{
for ( SpellAreaMap :: const_iterator itr = saBounds . first ; itr != saBounds . second ; ++ itr )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( itr -> second . IsFitToRequirements ( player , zone_id , area_id ))
return SPELL_CAST_OK ;
2008-12-22 11:36:13 -06:00
}
2009-05-15 16:26:00 -05:00
return SPELL_FAILED_INCORRECT_AREA ;
}
2008-12-22 11:36:13 -06:00
2009-05-15 16:26:00 -05:00
// bg spell checks
switch ( spellInfo -> Id )
{
case 23333 : // Warsong Flag
case 23335 : // Silverwing Flag
return map_id == 489 && player && player -> InBattleGround () ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA ;
case 34976 : // Netherstorm Flag
return map_id == 566 && player && player -> InBattleGround () ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA ;
case 2584 : // Waiting to Resurrect
case 22011 : // Spirit Heal Channel
case 22012 : // Spirit Heal
case 24171 : // Resurrection Impact Visual
case 42792 : // Recently Dropped Flag
case 43681 : // Inactive
case 44535 : // Spirit Heal (mana)
2008-12-22 11:36:13 -06:00
{
2009-05-15 16:26:00 -05:00
MapEntry const * mapEntry = sMapStore . LookupEntry ( map_id );
if ( ! mapEntry )
return SPELL_FAILED_INCORRECT_AREA ;
2009-01-07 17:29:07 -06:00
2009-05-15 16:26:00 -05:00
return mapEntry -> IsBattleGround () && player && player -> InBattleGround () ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
case 44521 : // Preparation
2009-05-01 15:36:32 -05:00
{
2009-05-15 16:26:00 -05:00
if ( ! player )
return SPELL_FAILED_REQUIRES_AREA ;
2009-05-01 15:36:32 -05:00
2009-05-15 16:26:00 -05:00
MapEntry const * mapEntry = sMapStore . LookupEntry ( map_id );
if ( ! mapEntry )
return SPELL_FAILED_INCORRECT_AREA ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( ! mapEntry -> IsBattleGround ())
return SPELL_FAILED_REQUIRES_AREA ;
BattleGround * bg = player -> GetBattleGround ();
return bg && bg -> GetStatus () == STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
case 32724 : // Gold Team (Alliance)
case 32725 : // Green Team (Alliance)
case 35774 : // Gold Team (Horde)
case 35775 : // Green Team (Horde)
{
MapEntry const * mapEntry = sMapStore . LookupEntry ( map_id );
if ( ! mapEntry )
return SPELL_FAILED_INCORRECT_AREA ;
2009-03-21 23:01:36 -06:00
2009-05-15 16:26:00 -05:00
return mapEntry -> IsBattleArena () && player && player -> InBattleGround () ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA ;
}
case 32727 : // Arena Preparation
2009-03-21 23:01:36 -06:00
{
2009-05-15 16:26:00 -05:00
if ( ! player )
return SPELL_FAILED_REQUIRES_AREA ;
MapEntry const * mapEntry = sMapStore . LookupEntry ( map_id );
if ( ! mapEntry )
return SPELL_FAILED_INCORRECT_AREA ;
if ( ! mapEntry -> IsBattleArena ())
return SPELL_FAILED_REQUIRES_AREA ;
BattleGround * bg = player -> GetBattleGround ();
return bg && bg -> GetStatus () == STATUS_WAIT_JOIN ? SPELL_CAST_OK : SPELL_FAILED_REQUIRES_AREA ;
2009-03-21 23:01:36 -06:00
}
2008-11-17 22:07:21 -06:00
}
2009-03-23 22:36:14 -06:00
2009-05-15 16:26:00 -05:00
return SPELL_CAST_OK ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
void SpellMgr :: LoadSkillLineAbilityMap ()
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
mSkillLineAbilityMap . clear ();
barGoLink bar ( sSkillLineAbilityStore . GetNumRows () );
2008-11-17 22:07:21 -06:00
uint32 count = 0 ;
2009-05-15 16:26:00 -05:00
for ( uint32 i = 0 ; i < sSkillLineAbilityStore . GetNumRows (); ++ i )
2008-11-17 22:07:21 -06:00
{
bar . step ();
2009-05-15 16:26:00 -05:00
SkillLineAbilityEntry const * SkillInfo = sSkillLineAbilityStore . LookupEntry ( i );
if ( ! SkillInfo )
continue ;
mSkillLineAbilityMap . insert ( SkillLineAbilityMap :: value_type ( SkillInfo -> spellId , SkillInfo ));
++ count ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
sLog . outString ();
sLog . outString ( ">> Loaded %u SkillLineAbility MultiMap Data" , count );
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
DiminishingGroup GetDiminishingReturnsGroupForSpell ( SpellEntry const * spellproto , bool triggered )
{
// Explicit Diminishing Groups
switch ( spellproto -> SpellFamilyName )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
case SPELLFAMILY_ROGUE :
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
// Kidney Shot
if ( spellproto -> SpellFamilyFlags [ 0 ] & 0x200000 )
return DIMINISHING_KIDNEYSHOT ;
// Sap
else if ( spellproto -> SpellFamilyFlags [ 0 ] & 0x80 )
return DIMINISHING_POLYMORPH ;
// Gouge
else if ( spellproto -> SpellFamilyFlags [ 0 ] & 0x8 )
return DIMINISHING_POLYMORPH ;
// Blind
else if ( spellproto -> SpellFamilyFlags [ 0 ] & 0x00001000000 )
return DIMINISHING_BLIND_CYCLONE ;
break ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
case SPELLFAMILY_WARLOCK :
2009-02-05 22:49:07 -06:00
{
2009-05-15 16:26:00 -05:00
// Death Coil
if ( spellproto -> SpellFamilyFlags [ 0 ] & 0x00000080000 )
return DIMINISHING_DEATHCOIL ;
// Seduction
else if ( spellproto -> SpellFamilyFlags [ 0 ] & 0x00040000000 )
return DIMINISHING_FEAR ;
// Curses/etc
else if ( spellproto -> SpellFamilyFlags [ 0 ] & 0x80000000 )
return DIMINISHING_LIMITONLY ;
break ;
2009-02-05 22:49:07 -06:00
}
2009-05-15 16:26:00 -05:00
case SPELLFAMILY_DRUID :
2009-02-05 22:49:07 -06:00
{
2009-05-15 16:26:00 -05:00
// Cyclone
if ( spellproto -> SpellFamilyFlags [ 1 ] & 0x020 )
return DIMINISHING_BLIND_CYCLONE ;
break ;
2009-02-05 22:49:07 -06:00
}
2009-05-15 16:26:00 -05:00
case SPELLFAMILY_WARRIOR :
2009-02-06 15:07:56 -06:00
{
2009-05-15 16:26:00 -05:00
// Hamstring - limit duration to 10s in PvP
if ( spellproto -> SpellFamilyFlags [ 0 ] & 0x00000000002 )
return DIMINISHING_LIMITONLY ;
break ;
2009-02-06 15:07:56 -06:00
}
2009-05-15 16:26:00 -05:00
default :
break ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
// Get by mechanic
uint32 mechanic = GetAllSpellMechanicMask ( spellproto );
if ( mechanic == MECHANIC_NONE ) return DIMINISHING_NONE ;
if ( mechanic & ( 1 << MECHANIC_STUN )) return triggered ? DIMINISHING_TRIGGER_STUN : DIMINISHING_CONTROL_STUN ;
if ( mechanic & ( 1 << MECHANIC_SLEEP )) return DIMINISHING_SLEEP ;
if ( mechanic & ( 1 << MECHANIC_POLYMORPH )) return DIMINISHING_POLYMORPH ;
if ( mechanic & ( 1 << MECHANIC_ROOT )) return triggered ? DIMINISHING_TRIGGER_ROOT : DIMINISHING_CONTROL_ROOT ;
if ( mechanic & ( 1 << MECHANIC_FEAR )) return DIMINISHING_FEAR ;
if ( mechanic & ( 1 << MECHANIC_CHARM )) return DIMINISHING_CHARM ;
if ( mechanic & ( 1 << MECHANIC_SILENCE )) return DIMINISHING_SILENCE ;
if ( mechanic & ( 1 << MECHANIC_DISARM )) return DIMINISHING_DISARM ;
if ( mechanic & ( 1 << MECHANIC_FREEZE )) return DIMINISHING_FREEZE ;
if ( mechanic & (( 1 << MECHANIC_KNOCKOUT ) | ( 1 << MECHANIC_SAPPED ))) return DIMINISHING_KNOCKOUT ;
if ( mechanic & ( 1 << MECHANIC_BANISH )) return DIMINISHING_BANISH ;
if ( mechanic & ( 1 << MECHANIC_HORROR )) return DIMINISHING_DEATHCOIL ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
return DIMINISHING_NONE ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
bool IsDiminishingReturnsGroupDurationLimited ( DiminishingGroup group )
2008-12-24 09:58:26 -06:00
{
2009-05-15 16:26:00 -05:00
switch ( group )
2008-12-24 09:58:26 -06:00
{
2009-05-15 16:26:00 -05:00
case DIMINISHING_CONTROL_STUN :
case DIMINISHING_TRIGGER_STUN :
case DIMINISHING_KIDNEYSHOT :
case DIMINISHING_SLEEP :
case DIMINISHING_CONTROL_ROOT :
case DIMINISHING_TRIGGER_ROOT :
case DIMINISHING_FEAR :
case DIMINISHING_WARLOCK_FEAR :
case DIMINISHING_CHARM :
case DIMINISHING_POLYMORPH :
case DIMINISHING_FREEZE :
case DIMINISHING_KNOCKOUT :
case DIMINISHING_BLIND_CYCLONE :
case DIMINISHING_BANISH :
case DIMINISHING_LIMITONLY :
return true ;
default :
return false ;
}
return false ;
}
2008-12-24 09:58:26 -06:00
2009-05-15 16:26:00 -05:00
DiminishingReturnsType GetDiminishingReturnsGroupType ( DiminishingGroup group )
{
switch ( group )
{
case DIMINISHING_BLIND_CYCLONE :
case DIMINISHING_CONTROL_STUN :
case DIMINISHING_TRIGGER_STUN :
case DIMINISHING_KIDNEYSHOT :
return DRTYPE_ALL ;
case DIMINISHING_SLEEP :
case DIMINISHING_CONTROL_ROOT :
case DIMINISHING_TRIGGER_ROOT :
case DIMINISHING_FEAR :
case DIMINISHING_CHARM :
case DIMINISHING_POLYMORPH :
case DIMINISHING_SILENCE :
case DIMINISHING_DISARM :
case DIMINISHING_DEATHCOIL :
case DIMINISHING_FREEZE :
case DIMINISHING_BANISH :
case DIMINISHING_WARLOCK_FEAR :
case DIMINISHING_KNOCKOUT :
return DRTYPE_PLAYER ;
default :
break ;
2008-12-24 09:58:26 -06:00
}
2009-05-15 16:26:00 -05:00
return DRTYPE_NONE ;
2008-12-24 09:58:26 -06:00
}
2009-05-15 16:26:00 -05:00
bool SpellArea :: IsFitToRequirements ( Player const * player , uint32 newZone , uint32 newArea ) const
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( gender != GENDER_NONE )
{
// not in expected gender
if ( ! player || gender != player -> getGender ())
return false ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( raceMask )
{
// not in expected race
if ( ! player || ! ( raceMask & player -> getRaceMask ()))
return false ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( areaId )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
// not in expected zone
if ( newZone != areaId && newArea != areaId )
return false ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( questStart )
{
// not in expected required quest state
if ( ! player || ( ! questStartCanActive || ! player -> IsActiveQuest ( questStart )) && ! player -> GetQuestRewardStatus ( questStart ))
return false ;
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
if ( questEnd )
{
// not in expected forbidden quest state
if ( ! player || player -> GetQuestRewardStatus ( questEnd ))
return false ;
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
if ( auraSpell )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
// not have expected aura
if ( ! player )
return false ;
if ( auraSpell > 0 )
// have expected aura
return player -> HasAura ( auraSpell );
else
// not have expected aura
return ! player -> HasAura ( - auraSpell );
2008-11-17 22:07:21 -06:00
}
return true ;
}
2009-05-15 16:26:00 -05:00
//-----------TRINITY-------------
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
bool SpellMgr :: IsNoStackSpellDueToSpell ( uint32 spellId_1 , uint32 spellId_2 , bool sameCaster ) const
{
SpellEntry const * spellInfo_1 = sSpellStore . LookupEntry ( spellId_1 );
SpellEntry const * spellInfo_2 = sSpellStore . LookupEntry ( spellId_2 );
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
if ( ! spellInfo_1 || ! spellInfo_2 )
return false ;
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
SpellSpecific spellId_spec_1 = GetSpellSpecific ( spellId_1 );
SpellSpecific spellId_spec_2 = GetSpellSpecific ( spellId_2 );
if ( spellId_spec_1 && spellId_spec_2 )
if ( IsSingleFromSpellSpecificPerTarget ( spellId_spec_1 , spellId_spec_2 )
|| ( IsSingleFromSpellSpecificPerCaster ( spellId_spec_1 , spellId_spec_2 ) && sameCaster ))
return true ;
if ( spellInfo_1 -> SpellFamilyName != spellInfo_2 -> SpellFamilyName )
return false ;
if ( ! sameCaster )
{
for ( uint32 i = 0 ; i < 3 ; ++ i )
if ( spellInfo_1 -> Effect [ i ] == SPELL_EFFECT_APPLY_AURA
|| spellInfo_1 -> Effect [ i ] == SPELL_EFFECT_PERSISTENT_AREA_AURA )
// not area auras (shaman totem)
switch ( spellInfo_1 -> EffectApplyAuraName [ i ])
{
// DOT or HOT from different casters will stack
case SPELL_AURA_PERIODIC_DAMAGE :
case SPELL_AURA_PERIODIC_HEAL :
case SPELL_AURA_PERIODIC_TRIGGER_SPELL :
case SPELL_AURA_PERIODIC_ENERGIZE :
case SPELL_AURA_PERIODIC_MANA_LEECH :
case SPELL_AURA_PERIODIC_LEECH :
case SPELL_AURA_POWER_BURN_MANA :
case SPELL_AURA_OBS_MOD_ENERGY :
case SPELL_AURA_OBS_MOD_HEALTH :
return false ;
default :
break ;
}
}
// hack for Incanter's Absorption
if ( spellInfo_1 -> Id == 44413 && spellInfo_2 -> Id == 44413 )
return false ;
spellId_2 = GetLastSpellInChain ( spellId_2 );
spellId_1 = GetLastSpellInChain ( spellId_1 );
if ( spellId_1 == spellId_2 )
return true ;
// generic spells
if ( ! spellInfo_1 -> SpellFamilyName )
{
if ( ! spellInfo_1 -> SpellIconID
|| spellInfo_1 -> SpellIconID == 1
|| spellInfo_1 -> SpellIconID != spellInfo_2 -> SpellIconID )
return false ;
}
// check for class spells
else
{
if ( spellInfo_1 -> SpellFamilyFlags != spellInfo_2 -> SpellFamilyFlags )
return false ;
if ( ! spellInfo_1 -> SpellFamilyFlags )
return false ;
}
//use data of highest rank spell(needed for spells which ranks have different effects)
spellInfo_1 = sSpellStore . LookupEntry ( spellId_1 );
spellInfo_2 = sSpellStore . LookupEntry ( spellId_2 );
//if spells have exactly the same effect they cannot stack
for ( uint32 i = 0 ; i < 3 ; ++ i )
if ( spellInfo_1 -> Effect [ i ] != spellInfo_2 -> Effect [ i ]
|| spellInfo_1 -> EffectApplyAuraName [ i ] != spellInfo_2 -> EffectApplyAuraName [ i ]
|| spellInfo_1 -> EffectMiscValue [ i ] != spellInfo_2 -> EffectMiscValue [ i ]) // paladin resist aura
return false ; // need itemtype check? need an example to add that check
return true ;
}
bool IsDispelableBySpell ( SpellEntry const * dispelSpell , uint32 spellId , bool def )
{
if ( ! dispelSpell ) return false ;
SpellEntry const * spellproto = sSpellStore . LookupEntry ( spellId );
if ( ! spellproto ) return false ;
2009-05-16 20:23:56 +02:00
if ( spellproto -> Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY )
return false ;
2009-05-15 16:26:00 -05:00
if ( dispelSpell -> Attributes & SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY )
return true ;
return def ;
}
void SpellMgr :: LoadSpellEnchantProcData ()
{
mSpellEnchantProcEventMap . clear (); // need for reload case
uint32 count = 0 ;
// 0 1 2 3
QueryResult * result = WorldDatabase . Query ( "SELECT entry, customChance, PPMChance, procEx FROM spell_enchant_proc_data" );
if ( ! result )
2009-02-27 12:53:27 -06:00
{
2009-05-15 16:26:00 -05:00
2009-02-27 12:53:27 -06:00
barGoLink bar ( 1 );
bar . step ();
2009-04-03 16:36:20 -06:00
sLog . outString ();
2009-05-15 16:26:00 -05:00
sLog . outString ( ">> Loaded %u spell enchant proc event conditions" , count );
2009-02-27 12:53:27 -06:00
return ;
}
barGoLink bar ( result -> GetRowCount () );
do
{
Field * fields = result -> Fetch ();
bar . step ();
2009-05-15 16:26:00 -05:00
uint32 enchantId = fields [ 0 ]. GetUInt32 ();
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
SpellItemEnchantmentEntry const * ench = sSpellItemEnchantmentStore . LookupEntry ( enchantId );
if ( ! ench )
2009-02-27 12:53:27 -06:00
{
2009-05-15 16:26:00 -05:00
sLog . outErrorDb ( "Enchancment %u listed in `spell_enchant_proc_data` does not exist" , enchantId );
2009-02-27 12:53:27 -06:00
continue ;
}
2009-05-15 16:26:00 -05:00
SpellEnchantProcEntry spe ;
2009-03-03 18:41:11 -06:00
2009-05-15 16:26:00 -05:00
spe . customChance = fields [ 1 ]. GetUInt32 ();
spe . PPMChance = fields [ 2 ]. GetFloat ();
spe . procEx = fields [ 3 ]. GetUInt32 ();
2009-03-03 18:41:11 -06:00
2009-05-15 16:26:00 -05:00
mSpellEnchantProcEventMap [ enchantId ] = spe ;
2009-03-03 18:41:11 -06:00
2009-05-15 16:26:00 -05:00
++ count ;
} while ( result -> NextRow () );
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
delete result ;
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
sLog . outString ( ">> Loaded %u enchant proc data definitions" , count );
}
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
void SpellMgr :: LoadSpellRequired ()
{
mSpellsReqSpell . clear (); // need for reload case
mSpellReq . clear (); // need for reload case
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
QueryResult * result = WorldDatabase . Query ( "SELECT spell_id, req_spell from spell_required" );
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
if ( result == NULL )
{
barGoLink bar ( 1 );
bar . step ();
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
sLog . outString ();
sLog . outString ( ">> Loaded 0 spell required records" );
sLog . outErrorDb ( "`spell_required` table is empty!" );
return ;
}
uint32 rows = 0 ;
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
barGoLink bar ( result -> GetRowCount () );
do
{
bar . step ();
Field * fields = result -> Fetch ();
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
uint32 spell_id = fields [ 0 ]. GetUInt32 ();
uint32 spell_req = fields [ 1 ]. GetUInt32 ();
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
mSpellsReqSpell . insert ( std :: pair < uint32 , uint32 > ( spell_req , spell_id ));
mSpellReq [ spell_id ] = spell_req ;
++ rows ;
} while ( result -> NextRow () );
delete result ;
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
sLog . outString ();
sLog . outString ( ">> Loaded %u spell required records" , rows );
}
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
struct SpellRankEntry
{
uint32 SkillId ;
char const * SpellName ;
uint32 DurationIndex ;
uint32 RangeIndex ;
uint32 SpellVisual ;
uint32 ProcFlags ;
flag96 SpellFamilyFlags ;
uint32 TargetAuraState ;
uint32 ManaCost ;
uint32 CastingTimeIndex ;
flag96 Effect ;
flag96 Aura ;
uint16 TalentID ;
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
bool operator < ( const SpellRankEntry & _Right ) const
{
return ( SkillId != _Right . SkillId ? SkillId < _Right . SkillId
: SpellName != _Right . SpellName ? SpellName < _Right . SpellName
: ProcFlags != _Right . ProcFlags ? ProcFlags < _Right . ProcFlags
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
: Effect != _Right . Effect ? Effect < _Right . Effect
: Aura != _Right . Aura ? Aura < _Right . Aura
: TalentID != _Right . TalentID ? TalentID < _Right . TalentID
: ( CastingTimeIndex != _Right . CastingTimeIndex ) && ( ! CastingTimeIndex || ! _Right . CastingTimeIndex || CastingTimeIndex == 1 || ! _Right . CastingTimeIndex == 1 ) ? CastingTimeIndex < _Right . CastingTimeIndex
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
: SpellFamilyFlags != _Right . SpellFamilyFlags ? SpellFamilyFlags < _Right . SpellFamilyFlags
: ( SpellVisual != _Right . SpellVisual ) && ( ! SpellVisual || ! _Right . SpellVisual ) ? SpellVisual < _Right . SpellVisual
: ( ManaCost != _Right . ManaCost ) && ( ! ManaCost || ! _Right . ManaCost ) ? ManaCost < _Right . ManaCost
: ( DurationIndex != _Right . DurationIndex ) && ( ! DurationIndex || ! _Right . DurationIndex ) ? DurationIndex < _Right . DurationIndex
: ( RangeIndex != _Right . RangeIndex ) && ( ! RangeIndex || ! _Right . RangeIndex || RangeIndex == 1 || ! _Right . RangeIndex == 1 ) ? RangeIndex < _Right . RangeIndex
: TargetAuraState < _Right . TargetAuraState
);
}
};
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
struct SpellRankValue
{
uint32 Id ;
char const * Rank ;
bool strict ;
};
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
void SpellMgr :: LoadSpellChains ()
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
mSpellChains . clear (); // need for reload case
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
std :: vector < uint32 > ChainedSpells ;
for ( uint32 ability_id = 0 ; ability_id < sSkillLineAbilityStore . GetNumRows (); ability_id ++ )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
SkillLineAbilityEntry const * AbilityInfo = sSkillLineAbilityStore . LookupEntry ( ability_id );
if ( ! AbilityInfo )
continue ;
if ( ! AbilityInfo -> forward_spellid )
continue ;
ChainedSpells . push_back ( AbilityInfo -> forward_spellid );
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
std :: multimap < SpellRankEntry , SpellRankValue > RankMap ;
2009-02-10 01:00:22 -06:00
2009-05-15 16:26:00 -05:00
for ( uint32 ability_id = 0 ; ability_id < sSkillLineAbilityStore . GetNumRows (); ability_id ++ )
{
SkillLineAbilityEntry const * AbilityInfo = sSkillLineAbilityStore . LookupEntry ( ability_id );
if ( ! AbilityInfo )
continue ;
2009-02-10 01:00:22 -06:00
2009-05-15 16:26:00 -05:00
//get only spell with lowest ability_id to prevent doubles
uint32 spell_id = AbilityInfo -> spellId ;
bool found = false ;
for ( uint32 i = 0 ; i < ChainedSpells . size (); i ++ )
2009-02-05 22:55:43 -06:00
{
2009-05-15 16:26:00 -05:00
if ( ChainedSpells . at ( i ) == spell_id )
found = true ;
2009-02-10 01:00:22 -06:00
}
2009-05-15 16:26:00 -05:00
if ( found )
continue ;
2009-02-10 01:00:22 -06:00
2009-05-15 16:26:00 -05:00
if ( mSkillLineAbilityMap . lower_bound ( spell_id ) -> second -> id != ability_id )
continue ;
SpellEntry const * SpellInfo = sSpellStore . LookupEntry ( spell_id );
if ( ! SpellInfo )
continue ;
std :: string sRank = SpellInfo -> Rank [ sWorld . GetDefaultDbcLocale ()];
if ( sRank . empty ())
continue ;
//exception to polymorph spells-make pig and turtle other chain than sheep
if (( SpellInfo -> SpellFamilyName == SPELLFAMILY_MAGE ) && ( SpellInfo -> SpellFamilyFlags [ 0 ] & 0x1000000 ) && ( SpellInfo -> SpellIconID != 82 ))
continue ;
2009-02-10 01:00:22 -06:00
2009-05-15 16:26:00 -05:00
SpellRankEntry entry ;
SpellRankValue value ;
entry . SkillId = AbilityInfo -> skillId ;
entry . SpellName = SpellInfo -> SpellName [ sWorld . GetDefaultDbcLocale ()];
entry . DurationIndex = SpellInfo -> DurationIndex ;
entry . RangeIndex = SpellInfo -> rangeIndex ;
entry . ProcFlags = SpellInfo -> procFlags ;
entry . SpellFamilyFlags = SpellInfo -> SpellFamilyFlags ;
entry . TargetAuraState = SpellInfo -> TargetAuraState ;
entry . SpellVisual = SpellInfo -> SpellVisual [ 0 ];
entry . ManaCost = SpellInfo -> manaCost ;
entry . CastingTimeIndex = 0 ;
entry . TalentID = 0 ;
for (;;)
{
AbilityInfo = mSkillLineAbilityMap . lower_bound ( spell_id ) -> second ;
value . Id = spell_id ;
value . Rank = SpellInfo -> Rank [ sWorld . GetDefaultDbcLocale ()];
value . strict = false ;
RankMap . insert ( std :: pair < SpellRankEntry , SpellRankValue > ( entry , value ));
spell_id = AbilityInfo -> forward_spellid ;
SpellInfo = sSpellStore . LookupEntry ( spell_id );
if ( ! SpellInfo )
break ;
2009-02-05 22:55:43 -06:00
}
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
barGoLink bar ( RankMap . size ());
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
uint32 count = 0 ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
for ( std :: multimap < SpellRankEntry , SpellRankValue >:: iterator itr = RankMap . begin (); itr != RankMap . end ();)
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
SpellRankEntry entry = itr -> first ;
//trac errors in extracted data
std :: multimap < char const * , std :: multimap < SpellRankEntry , SpellRankValue >:: iterator > RankErrorMap ;
for ( std :: multimap < SpellRankEntry , SpellRankValue >:: iterator itr2 = RankMap . lower_bound ( entry ); itr2 != RankMap . upper_bound ( entry ); itr2 ++ )
{
bar . step ();
RankErrorMap . insert ( std :: pair < char const * , std :: multimap < SpellRankEntry , SpellRankValue >:: iterator > ( itr2 -> second . Rank , itr2 ));
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
bool error = false ;
//if strict == true strict check is not needed
if ( ! itr -> second . strict )
//check for rank duplicates, if there are any do strict check
for ( std :: multimap < char const * , std :: multimap < SpellRankEntry , SpellRankValue >:: iterator >:: iterator itr2 = RankErrorMap . begin (); itr2 != RankErrorMap . end ();)
{
char const * err_entry = itr2 -> first ;
uint32 rank_count = RankErrorMap . count ( itr2 -> first );
if ( rank_count > 1 )
{
error = true ;
break ;
}
else
itr2 ++ ;
}
bool allHaveTalents = true ;
if ( error )
{
std :: list < uint32 > ConflictedSpells ;
for ( std :: multimap < SpellRankEntry , SpellRankValue >:: iterator itr2 = RankMap . lower_bound ( entry ); itr2 != RankMap . upper_bound ( entry ); itr2 = RankMap . lower_bound ( entry ))
{
ConflictedSpells . push_back ( itr2 -> second . Id );
if ( ! GetTalentSpellPos ( itr2 -> second . Id ))
allHaveTalents = false ;
RankMap . erase ( itr2 );
}
SpellRankEntry nextEntry , currEntry ;
for (; ! ConflictedSpells . empty (); ConflictedSpells . pop_front ())
{
SpellEntry const * SpellInfo = sSpellStore . LookupEntry ( ConflictedSpells . front ());
currEntry . SkillId = entry . SkillId ;
currEntry . SpellName = SpellInfo -> SpellName [ sWorld . GetDefaultDbcLocale ()];
currEntry . DurationIndex = SpellInfo -> DurationIndex ;
currEntry . RangeIndex = SpellInfo -> rangeIndex ;
currEntry . ProcFlags = SpellInfo -> procFlags ;
currEntry . SpellFamilyFlags = SpellInfo -> SpellFamilyFlags ;
//compare talents only when all spells from chain have entry
//to prevent wrong results with spells which have first rank talented and other not
if ( allHaveTalents )
currEntry . TalentID = GetTalentSpellPos ( ConflictedSpells . front ()) -> talent_id ;
else
currEntry . TalentID = 0 ;
currEntry . TargetAuraState = SpellInfo -> TargetAuraState ;
currEntry . SpellVisual = SpellInfo -> SpellVisual [ 0 ];
currEntry . ManaCost = SpellInfo -> manaCost ;
//compare effects and casting time
currEntry . CastingTimeIndex = SpellInfo -> CastingTimeIndex ;
currEntry . Effect [ 0 ] = SpellInfo -> Effect [ 0 ];
currEntry . Effect [ 1 ] = SpellInfo -> Effect [ 1 ];
currEntry . Effect [ 2 ] = SpellInfo -> Effect [ 2 ];
currEntry . Aura [ 0 ] = SpellInfo -> EffectApplyAuraName [ 0 ];
currEntry . Aura [ 1 ] = SpellInfo -> EffectApplyAuraName [ 1 ];
currEntry . Aura [ 2 ] = SpellInfo -> EffectApplyAuraName [ 2 ];
SpellRankValue currValue ;
currValue . Id = ConflictedSpells . front ();
currValue . Rank = SpellInfo -> Rank [ sWorld . GetDefaultDbcLocale ()];
currValue . strict = true ;
RankMap . insert ( std :: pair < SpellRankEntry , SpellRankValue > ( currEntry , currValue ));
}
itr = RankMap . begin ();
continue ;
}
else
for ( std :: multimap < char const * , std :: multimap < SpellRankEntry , SpellRankValue >:: iterator >:: iterator itr2 = RankErrorMap . begin (); itr2 != RankErrorMap . end ();)
{
char const * err_entry = itr2 -> first ;
uint32 rank_count = RankErrorMap . count ( itr2 -> first );
if ( rank_count > 1 )
for ( itr2 = RankErrorMap . lower_bound ( err_entry ); itr2 != RankErrorMap . upper_bound ( err_entry ); itr2 ++ )
{
sLog . outDebug ( "There is a duplicate rank entry (%s) for spell: %u" , itr2 -> first , itr2 -> second -> second . Id );
if ( ! ( itr2 -> second -> second . Id == 52375 || itr2 -> second -> second . Id == 45902 ))
{
sLog . outDebug ( "Spell %u removed from chain data." , itr2 -> second -> second . Id );
RankMap . erase ( itr2 -> second );
}
}
else
itr2 ++ ;
}
//order spells by spellLevel
std :: list < uint32 > RankedSpells ;
uint32 min_spell_lvl = 0 ;
std :: multimap < SpellRankEntry , SpellRankValue >:: iterator min_itr ;
for (; RankMap . count ( entry );)
{
for ( std :: multimap < SpellRankEntry , SpellRankValue >:: iterator itr2 = RankMap . lower_bound ( entry ); itr2 != RankMap . upper_bound ( entry ); itr2 ++ )
{
SpellEntry const * SpellInfo = sSpellStore . LookupEntry ( itr2 -> second . Id );
if ( SpellInfo -> spellLevel < min_spell_lvl || itr2 == RankMap . lower_bound ( entry ))
{
min_spell_lvl = SpellInfo -> spellLevel ;
min_itr = itr2 ;
}
}
RankedSpells . push_back ( min_itr -> second . Id );
RankMap . erase ( min_itr );
}
//use data from talent.dbc
uint16 talent_id = 0 ;
for ( std :: list < uint32 >:: iterator itr2 = RankedSpells . begin (); itr2 != RankedSpells . end ();)
{
if ( TalentSpellPos const * TalentPos = GetTalentSpellPos ( * itr2 ))
{
talent_id = TalentPos -> talent_id ;
RankedSpells . erase ( itr2 );
itr2 = RankedSpells . begin ();
}
else
itr2 ++ ;
}
if ( talent_id )
{
TalentEntry const * TalentInfo = sTalentStore . LookupEntry ( talent_id );
for ( uint8 rank = 5 ; rank ; rank -- )
{
if ( TalentInfo -> RankID [ rank - 1 ])
RankedSpells . push_front ( TalentInfo -> RankID [ rank - 1 ]);
}
}
//do not proceed for spells with less than 2 ranks
itr = RankMap . begin ();
if ( RankedSpells . size () < 2 )
continue ;
count ++ ;
uint32 spell_rank = 1 ;
for ( std :: list < uint32 >:: iterator itr2 = RankedSpells . begin (); itr2 != RankedSpells . end (); spell_rank ++ )
{
uint32 spell_id =* itr2 ;
mSpellChains [ spell_id ]. rank = spell_rank ;
mSpellChains [ spell_id ]. first = RankedSpells . front ();
mSpellChains [ spell_id ]. last = RankedSpells . back ();
itr2 ++ ;
if ( spell_rank < 2 )
mSpellChains [ spell_id ]. prev = 0 ;
if ( spell_id == RankedSpells . back ())
mSpellChains [ spell_id ]. next = 0 ;
else
{
mSpellChains [ * itr2 ]. prev = spell_id ;
mSpellChains [ spell_id ]. next =* itr2 ;
}
}
}
//uncomment these two lines to print yourself list of spell_chains on startup
//for (UNORDERED_MAP<uint32, SpellChainNode>::iterator itr=mSpellChains.begin();itr!=mSpellChains.end();itr++)
//sLog.outString( "Id: %u, Rank: %d , %s, %u, %u, %u, %u",itr->first,itr->second.rank, sSpellStore.LookupEntry(itr->first)->Rank[sWorld.GetDefaultDbcLocale()], itr->second.first, itr->second.last,itr->second.next ,itr->second.prev);
2008-11-17 22:07:21 -06:00
2009-04-03 16:36:20 -06:00
sLog . outString ();
2009-05-15 16:26:00 -05:00
sLog . outString ( ">> Loaded %u spell chains" , count );
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
// set data in core for now
void SpellMgr :: LoadSpellCustomAttr ()
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
mSpellCustomAttr . resize ( GetSpellStore () -> GetNumRows ());
SpellEntry * spellInfo ;
for ( uint32 i = 0 ; i < GetSpellStore () -> GetNumRows (); ++ i )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
mSpellCustomAttr [ i ] = 0 ;
spellInfo = ( SpellEntry * ) GetSpellStore () -> LookupEntry ( i );
if ( ! spellInfo )
continue ;
bool auraSpell = true ;
for ( uint32 j = 0 ; j < 3 ; ++ j )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( spellInfo -> Effect [ j ])
if ( spellInfo -> Effect [ j ] != SPELL_EFFECT_APPLY_AURA
|| SpellTargetType [ spellInfo -> EffectImplicitTargetA [ j ]] != TARGET_TYPE_UNIT_TARGET )
//ignore target party for now
{
auraSpell = false ;
break ;
}
}
if ( auraSpell )
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_AURA_SPELL ;
for ( uint32 j = 0 ; j < 3 ; ++ j )
{
switch ( spellInfo -> EffectApplyAuraName [ j ])
{
case SPELL_AURA_PERIODIC_DAMAGE :
case SPELL_AURA_PERIODIC_DAMAGE_PERCENT :
case SPELL_AURA_PERIODIC_LEECH :
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_AURA_DOT ;
break ;
case SPELL_AURA_PERIODIC_HEAL :
case SPELL_AURA_OBS_MOD_HEALTH :
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_AURA_HOT ;
break ;
case SPELL_AURA_MOD_ROOT :
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_AURA_CC ;
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_MOVEMENT_IMPAIR ;
break ;
case SPELL_AURA_MOD_DECREASE_SPEED :
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_MOVEMENT_IMPAIR ;
break ;
default :
break ;
}
switch ( spellInfo -> Effect [ j ])
{
case SPELL_EFFECT_SCHOOL_DAMAGE :
case SPELL_EFFECT_WEAPON_DAMAGE :
case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL :
case SPELL_EFFECT_NORMALIZED_WEAPON_DMG :
case SPELL_EFFECT_WEAPON_PERCENT_DAMAGE :
case SPELL_EFFECT_HEAL :
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_DIRECT_DAMAGE ;
break ;
case SPELL_EFFECT_CHARGE :
case SPELL_EFFECT_JUMP :
case SPELL_EFFECT_JUMP2 :
case SPELL_EFFECT_138 :
if ( ! spellInfo -> speed && ! spellInfo -> SpellFamilyName )
spellInfo -> speed = SPEED_CHARGE ;
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_CHARGE ;
break ;
case SPELL_EFFECT_TRIGGER_SPELL :
if ( SpellTargetType [ spellInfo -> EffectImplicitTargetA [ j ]] == TARGET_TYPE_DEST_CASTER ||
SpellTargetType [ spellInfo -> EffectImplicitTargetA [ j ]] == TARGET_TYPE_DEST_TARGET ||
SpellTargetType [ spellInfo -> EffectImplicitTargetA [ j ]] == TARGET_TYPE_DEST_DEST ||
spellInfo -> Targets & ( TARGET_FLAG_SOURCE_LOCATION | TARGET_FLAG_DEST_LOCATION ))
spellInfo -> Effect [ j ] = SPELL_EFFECT_TRIGGER_MISSILE ;
break ;
}
switch ( SpellTargetType [ spellInfo -> EffectImplicitTargetA [ j ]])
{
case TARGET_TYPE_UNIT_TARGET :
case TARGET_TYPE_DEST_TARGET :
spellInfo -> Targets |= TARGET_FLAG_UNIT ;
break ;
}
}
for ( uint32 j = 0 ; j < 3 ; ++ j )
{
switch ( spellInfo -> EffectApplyAuraName [ j ])
{
case SPELL_AURA_MOD_POSSESS :
case SPELL_AURA_MOD_CONFUSE :
case SPELL_AURA_MOD_CHARM :
case SPELL_AURA_MOD_FEAR :
case SPELL_AURA_MOD_STUN :
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_AURA_CC ;
mSpellCustomAttr [ i ] &= ~ SPELL_ATTR_CU_MOVEMENT_IMPAIR ;
break ;
}
}
if ( spellInfo -> SpellVisual [ 0 ] == 3879 )
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_CONE_BACK ;
switch ( i )
{
case 26029 : // dark glare
case 37433 : // spout
case 43140 : case 43215 : // flame breath
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_CONE_LINE ;
break ;
case 24340 : case 26558 : case 28884 : // Meteor
case 36837 : case 38903 : case 41276 : // Meteor
2009-05-20 11:44:38 -05:00
case 57467 : // Meteor
2009-05-15 16:26:00 -05:00
case 26789 : // Shard of the Fallen Star
case 31436 : // Malevolent Cleave
case 35181 : // Dive Bomb
case 40810 : case 43267 : case 43268 : // Saber Lash
case 42384 : // Brutal Swipe
case 45150 : // Meteor Slash
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_SHARE_DAMAGE ;
break ;
2009-05-18 15:04:05 -05:00
case 27820 : // Mana Detonation
2009-05-20 11:44:38 -05:00
//case 28062: case 39090: // Positive/Negative Charge
//case 28085: case 39093:
2009-05-15 16:26:00 -05:00
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_EXCLUDE_SELF ;
break ;
case 44978 : case 45001 : case 45002 : // Wild Magic
case 45004 : case 45006 : case 45010 : // Wild Magic
case 31347 : // Doom
case 41635 : // Prayer of Mending
case 44869 : // Spectral Blast
case 45027 : // Revitalize
case 45976 : // Muru Portal Channel
case 39365 : // Thundering Storm
case 41071 : // Raise Dead (HACK)
spellInfo -> MaxAffectedTargets = 1 ;
break ;
case 41376 : // Spite
case 39992 : // Needle Spine
case 29576 : // Multi-Shot
case 40816 : // Saber Lash
case 37790 : // Spread Shot
case 46771 : // Flame Sear
case 45248 : // Shadow Blades
case 41303 : // Soul Drain
case 54172 : // Divine Storm (heal)
case 29213 : // Curse of the Plaguebringer - Noth
case 28542 : // Life Drain - Sapphiron
spellInfo -> MaxAffectedTargets = 3 ;
break ;
case 38310 : //Multi-Shot
spellInfo -> MaxAffectedTargets = 4 ;
break ;
case 42005 : // Bloodboil
case 38296 : // Spitfire Totem
case 37676 : // Insidious Whisper
case 46009 : // Negative Energy
case 45641 : // Fire Bloom
case 54937 : // Glyph of Holy Light
case 55665 : // Life Drain - Sapphiron (H)
case 28796 : // Poison Bolt Volly - Faerlina
spellInfo -> MaxAffectedTargets = 5 ;
2008-11-17 22:07:21 -06:00
break ;
2009-05-15 16:26:00 -05:00
case 40827 : // Sinful Beam
case 40859 : // Sinister Beam
case 40860 : // Vile Beam
case 40861 : // Wicked Beam
case 57669 : // Replenishment
case 54835 : // Curse of the Plaguebringer - Noth (H)
case 54098 : // Poison Bolt Volly - Faerlina (H)
spellInfo -> MaxAffectedTargets = 10 ;
2008-11-17 22:07:21 -06:00
break ;
2009-05-15 16:26:00 -05:00
case 8122 : case 8124 : case 10888 : case 10890 : // Psychic Scream
case 12494 : // Frostbite
spellInfo -> Attributes |= SPELL_ATTR_BREAKABLE_BY_DAMAGE ;
2008-11-17 22:07:21 -06:00
break ;
2009-05-15 16:26:00 -05:00
case 38794 : case 33711 : //Murmur's Touch
spellInfo -> MaxAffectedTargets = 1 ;
spellInfo -> EffectTriggerSpell [ 0 ] = 33760 ;
break ;
case 17941 : // Shadow Trance
case 22008 : // Netherwind Focus
case 31834 : // Light's Grace
case 34754 : // Clearcasting
case 34936 : // Backlash
case 48108 : // Hot Streak
case 51124 : // Killing Machine
case 54741 : // Firestarter
case 57761 : // Fireball!
case 39805 : // Lightning Overload
case 52437 : // Sudden Death
spellInfo -> procCharges = 1 ;
break ;
case 44544 : // Fingers of Frost
spellInfo -> procCharges = 2 ;
break ;
case 28200 : // Ascendance (Talisman of Ascendance trinket)
spellInfo -> procCharges = 6 ;
2008-11-17 22:07:21 -06:00
break ;
default :
break ;
2009-05-15 16:26:00 -05:00
}
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
switch ( spellInfo -> SpellFamilyName )
{
case SPELLFAMILY_DRUID :
2009-05-18 10:22:43 -05:00
// Starfall Target Selection
2009-05-15 16:26:00 -05:00
if ( spellInfo -> SpellFamilyFlags [ 2 ] & 0x100 )
spellInfo -> MaxAffectedTargets = 2 ;
2009-05-18 10:22:43 -05:00
// Starfall AOE Damage
else if ( spellInfo -> SpellFamilyFlags [ 2 ] & 0x800000 )
mSpellCustomAttr [ i ] |= SPELL_ATTR_CU_EXCLUDE_SELF ;
2009-05-15 16:26:00 -05:00
// Wild growth
else if ( spellInfo -> SpellFamilyFlags [ 1 ] & 0x4000000 )
spellInfo -> MaxAffectedTargets = 5 ;
break ;
// circle of healing
case SPELLFAMILY_PRIEST :
if ( spellInfo -> SpellFamilyFlags [ 0 ] & 0x10000000 )
spellInfo -> MaxAffectedTargets = 5 ;
break ;
}
}
2009-01-18 19:01:41 -06:00
2009-05-15 16:26:00 -05:00
SummonPropertiesEntry * properties = const_cast < SummonPropertiesEntry *> ( sSummonPropertiesStore . LookupEntry ( 121 ));
properties -> Type = SUMMON_TYPE_TOTEM ;
2008-11-17 22:07:21 -06:00
2009-05-15 16:26:00 -05:00
CreatureAI :: FillAISpellInfo ();
2008-11-17 22:07:21 -06:00
}
2009-05-15 16:26:00 -05:00
bool SpellMgr :: IsSkillTypeSpell ( uint32 spellId , SkillType type ) const
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
SkillLineAbilityMap :: const_iterator lower = GetBeginSkillLineAbilityMap ( spellId );
SkillLineAbilityMap :: const_iterator upper = GetEndSkillLineAbilityMap ( spellId );
for (; lower != upper ; ++ lower )
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
if ( lower -> second -> skillId == type )
2008-11-17 22:07:21 -06:00
return true ;
}
return false ;
}
2009-05-15 16:26:00 -05:00
void SpellMgr :: LoadSpellLinked ()
2008-11-17 22:07:21 -06:00
{
2009-05-15 16:26:00 -05:00
mSpellLinkedMap . clear (); // need for reload case
uint32 count = 0 ;
2009-02-17 20:07:49 -06:00
2009-05-15 16:26:00 -05:00
// 0 1 2
QueryResult * result = WorldDatabase . Query ( "SELECT spell_trigger, spell_effect, type FROM spell_linked_spell" );
if ( ! result )
2009-02-27 12:53:27 -06:00
{
2009-05-15 16:26:00 -05:00
barGoLink bar ( 1 );
bar . step ();
sLog . outString ();
sLog . outString ( ">> Loaded %u linked spells" , count );
return ;
2009-02-27 12:53:27 -06:00
}
2009-05-15 16:26:00 -05:00
barGoLink bar ( result -> GetRowCount () );
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
do
2009-02-27 12:53:27 -06:00
{
2009-05-15 16:26:00 -05:00
Field * fields = result -> Fetch ();
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
bar . step ();
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
int32 trigger = fields [ 0 ]. GetInt32 ();
int32 effect = fields [ 1 ]. GetInt32 ();
int32 type = fields [ 2 ]. GetInt32 ();
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
SpellEntry const * spellInfo = sSpellStore . LookupEntry ( abs ( trigger ));
if ( ! spellInfo )
{
sLog . outErrorDb ( "Spell %u listed in `spell_linked_spell` does not exist" , abs ( trigger ));
continue ;
}
spellInfo = sSpellStore . LookupEntry ( abs ( effect ));
if ( ! spellInfo )
{
sLog . outErrorDb ( "Spell %u listed in `spell_linked_spell` does not exist" , abs ( effect ));
continue ;
}
if ( trigger > 0 )
{
switch ( type )
{
case 0 : mSpellCustomAttr [ trigger ] |= SPELL_ATTR_CU_LINK_CAST ; break ;
case 1 : mSpellCustomAttr [ trigger ] |= SPELL_ATTR_CU_LINK_HIT ; break ;
case 2 : mSpellCustomAttr [ trigger ] |= SPELL_ATTR_CU_LINK_AURA ; break ;
}
}
2009-03-03 18:41:11 -06:00
else
2009-05-15 16:26:00 -05:00
{
mSpellCustomAttr [ - trigger ] |= SPELL_ATTR_CU_LINK_REMOVE ;
}
2009-02-27 12:53:27 -06:00
2009-05-15 16:26:00 -05:00
if ( type ) //we will find a better way when more types are needed
{
if ( trigger > 0 )
trigger += SPELL_LINKED_MAX_SPELLS * type ;
else
trigger -= SPELL_LINKED_MAX_SPELLS * type ;
}
mSpellLinkedMap [ trigger ]. push_back ( effect );
++ count ;
} while ( result -> NextRow () );
delete result ;
sLog . outString ();
sLog . outString ( ">> Loaded %u linked spells" , count );
2009-02-27 12:53:27 -06:00
}
2009-05-15 16:26:00 -05:00