2010-10-07 15:35:36 +02:00
/*
2017-01-01 16:21:30 +01:00
* Copyright (C) 2008-2017 TrinityCore <http://www.trinitycore.org/>
2010-10-07 15:35:36 +02:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* 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, see <http://www.gnu.org/licenses/>.
2010-02-20 23:59:05 +01:00
*/
#include "Common.h"
2010-06-08 17:01:03 -06:00
#include "DatabaseEnv.h"
2010-02-20 23:59:05 +01:00
#include "WorldPacket.h"
#include "WorldSession.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "Opcodes.h"
#include "Log.h"
#include "World.h"
#include "ObjectMgr.h"
#include "SpellMgr.h"
#include "Player.h"
#include "Pet.h"
#include "Unit.h"
#include "Spell.h"
#include "DynamicObject.h"
2013-07-06 15:28:12 +02:00
#include "Guild.h"
2010-02-20 23:59:05 +01:00
#include "UpdateData.h"
#include "ObjectAccessor.h"
#include "CellImpl.h"
#include "SharedDefines.h"
#include "LootMgr.h"
#include "VMapFactory.h"
2010-08-08 04:37:24 +02:00
#include "Battleground.h"
2010-02-20 23:59:05 +01:00
#include "Util.h"
#include "TemporarySummon.h"
#include "Vehicle.h"
#include "SpellAuraEffects.h"
#include "ScriptMgr.h"
2010-06-04 23:24:48 +02:00
#include "ConditionMgr.h"
2010-07-21 12:14:23 +02:00
#include "DisableMgr.h"
2010-07-24 22:41:42 +02:00
#include "SpellScript.h"
2011-02-03 22:20:40 +01:00
#include "InstanceScript.h"
2011-07-26 23:09:28 +02:00
#include "SpellInfo.h"
2011-11-20 18:28:18 +01:00
#include "DB2Stores.h"
2012-08-20 16:23:24 -04:00
#include "Battlefield.h"
#include "BattlefieldMgr.h"
2014-11-30 15:37:11 +01:00
#include "SpellPackets.h"
2015-04-18 17:02:33 +02:00
#include "CombatLogPackets.h"
2015-02-17 01:01:44 +01:00
#include "SpellHistory.h"
2015-11-13 02:39:45 +01:00
#include "TradeData.h"
2010-02-20 23:59:05 +01:00
extern pEffect SpellEffects [ TOTAL_SPELL_EFFECTS ];
2012-05-30 08:01:02 +02:00
SpellDestination :: SpellDestination ()
{
_position . Relocate ( 0 , 0 , 0 , 0 );
2014-09-14 16:14:12 +02:00
_transportGUID . Clear ();
2012-05-30 08:01:02 +02:00
_transportOffset . Relocate ( 0 , 0 , 0 , 0 );
}
SpellDestination :: SpellDestination ( float x , float y , float z , float orientation , uint32 mapId )
{
_position . Relocate ( x , y , z , orientation );
2014-09-14 16:14:12 +02:00
_transportGUID . Clear ();
2012-05-30 08:01:02 +02:00
_position . m_mapId = mapId ;
2013-12-14 18:41:26 +01:00
_transportOffset . Relocate ( 0 , 0 , 0 , 0 );
2012-05-30 08:01:02 +02:00
}
SpellDestination :: SpellDestination ( Position const & pos )
{
_position . Relocate ( pos );
2014-09-14 16:14:12 +02:00
_transportGUID . Clear ();
2013-12-14 18:41:26 +01:00
_transportOffset . Relocate ( 0 , 0 , 0 , 0 );
2012-05-30 08:01:02 +02:00
}
SpellDestination :: SpellDestination ( WorldObject const & wObj )
{
_transportGUID = wObj . GetTransGUID ();
_transportOffset . Relocate ( wObj . GetTransOffsetX (), wObj . GetTransOffsetY (), wObj . GetTransOffsetZ (), wObj . GetTransOffsetO ());
_position . Relocate ( wObj );
}
2014-01-23 18:15:59 +01:00
void SpellDestination :: Relocate ( Position const & pos )
{
2014-10-21 20:27:00 +02:00
if ( ! _transportGUID . IsEmpty ())
2014-01-23 18:15:59 +01:00
{
Position offset ;
_position . GetPositionOffsetTo ( pos , offset );
_transportOffset . RelocateOffset ( offset );
}
_position . Relocate ( pos );
}
void SpellDestination :: RelocateOffset ( Position const & offset )
{
2014-10-21 20:27:00 +02:00
if ( ! _transportGUID . IsEmpty ())
2014-01-23 18:15:59 +01:00
_transportOffset . RelocateOffset ( offset );
_position . RelocateOffset ( offset );
}
2012-05-30 08:01:02 +02:00
2015-01-30 23:58:16 +01:00
SpellCastTargets :: SpellCastTargets () : m_targetMask ( 0 ), m_objectTarget ( nullptr ), m_itemTarget ( nullptr ),
2015-02-12 02:37:42 +00:00
m_itemTargetEntry ( 0 ), m_pitch ( 0.0f ), m_speed ( 0.0f )
2010-02-20 23:59:05 +01:00
{
}
2015-02-12 02:37:42 +00:00
SpellCastTargets :: SpellCastTargets ( Unit * caster , WorldPackets :: Spells :: SpellCastRequest const & spellCastRequest ) :
m_targetMask ( spellCastRequest . Target . Flags ), m_objectTarget ( nullptr ), m_itemTarget ( nullptr ),
m_objectTargetGUID ( spellCastRequest . Target . Unit ), m_itemTargetGUID ( spellCastRequest . Target . Item ),
m_itemTargetEntry ( 0 ), m_pitch ( 0.0f ), m_speed ( 0.0f ), m_strTarget ( spellCastRequest . Target . Name )
2014-11-30 15:37:11 +01:00
{
2015-04-26 23:45:52 +02:00
if ( spellCastRequest . Target . SrcLocation )
2015-01-30 23:58:16 +01:00
{
2015-04-26 23:45:52 +02:00
m_src . _transportGUID = spellCastRequest . Target . SrcLocation -> Transport ;
2015-01-30 23:58:16 +01:00
Position * pos ;
if ( ! m_src . _transportGUID . IsEmpty ())
pos = & m_src . _transportOffset ;
else
pos = & m_src . _position ;
2014-11-30 15:37:11 +01:00
2015-04-26 23:45:52 +02:00
pos -> Relocate ( spellCastRequest . Target . SrcLocation -> Location );
if ( spellCastRequest . Target . Orientation )
pos -> SetOrientation ( * spellCastRequest . Target . Orientation );
2015-01-30 23:58:16 +01:00
}
2014-11-30 15:37:11 +01:00
2015-04-26 23:45:52 +02:00
if ( spellCastRequest . Target . DstLocation )
2015-01-30 23:58:16 +01:00
{
2015-04-26 23:45:52 +02:00
m_dst . _transportGUID = spellCastRequest . Target . DstLocation -> Transport ;
2015-01-30 23:58:16 +01:00
Position * pos ;
if ( ! m_dst . _transportGUID . IsEmpty ())
pos = & m_dst . _transportOffset ;
else
pos = & m_dst . _position ;
2015-04-26 23:45:52 +02:00
pos -> Relocate ( spellCastRequest . Target . DstLocation -> Location );
if ( spellCastRequest . Target . Orientation )
pos -> SetOrientation ( * spellCastRequest . Target . Orientation );
2015-01-30 23:58:16 +01:00
}
2014-11-30 15:37:11 +01:00
2015-02-12 02:37:42 +00:00
SetPitch ( spellCastRequest . MissileTrajectory . Pitch );
SetSpeed ( spellCastRequest . MissileTrajectory . Speed );
2014-11-30 15:37:11 +01:00
Update ( caster );
}
2013-10-28 14:36:07 -04:00
SpellCastTargets ::~ SpellCastTargets () { }
2010-02-20 23:59:05 +01:00
2014-12-02 00:07:36 +02:00
void SpellCastTargets :: Write ( WorldPackets :: Spells :: SpellTargetData & data )
2011-06-23 13:28:52 +02:00
{
2014-12-02 00:07:36 +02:00
data . Flags = m_targetMask ;
if ( m_targetMask & ( TARGET_FLAG_UNIT | TARGET_FLAG_CORPSE_ALLY | TARGET_FLAG_GAMEOBJECT | TARGET_FLAG_CORPSE_ENEMY | TARGET_FLAG_UNIT_MINIPET ))
data . Unit = m_objectTargetGUID ;
if ( m_targetMask & ( TARGET_FLAG_ITEM | TARGET_FLAG_TRADE_ITEM ) && m_itemTarget )
data . Item = m_itemTarget -> GetGUID ();
if ( m_targetMask & TARGET_FLAG_SOURCE_LOCATION )
{
2015-04-27 17:01:30 +02:00
data . SrcLocation = boost :: in_place ();
2015-04-26 23:45:52 +02:00
data . SrcLocation -> Transport = m_src . _transportGUID ; // relative position guid here - transport for example
2014-12-02 00:07:36 +02:00
if ( ! m_src . _transportGUID . IsEmpty ())
2015-04-26 23:45:52 +02:00
data . SrcLocation -> Location = m_src . _transportOffset ;
2014-12-02 00:07:36 +02:00
else
2015-04-26 23:45:52 +02:00
data . SrcLocation -> Location = m_src . _position ;
2014-12-02 00:07:36 +02:00
}
if ( m_targetMask & TARGET_FLAG_DEST_LOCATION )
{
2015-04-27 17:01:30 +02:00
data . DstLocation = boost :: in_place ();
2015-04-26 23:45:52 +02:00
data . DstLocation -> Transport = m_dst . _transportGUID ; // relative position guid here - transport for example
2014-12-02 00:07:36 +02:00
if ( ! m_dst . _transportGUID . IsEmpty ())
2015-04-26 23:45:52 +02:00
data . DstLocation -> Location = m_dst . _transportOffset ;
2014-12-02 00:07:36 +02:00
else
2015-04-26 23:45:52 +02:00
data . DstLocation -> Location = m_dst . _position ;
2014-12-02 00:07:36 +02:00
}
if ( m_targetMask & TARGET_FLAG_STRING )
data . Name = m_strTarget ;
2011-06-23 13:28:52 +02:00
}
2014-10-18 20:51:00 +01:00
ObjectGuid SpellCastTargets :: GetOrigUnitTargetGUID () const
{
switch ( m_origObjectTargetGUID . GetHigh ())
{
2014-10-27 12:03:35 +01:00
case HighGuid :: Player :
case HighGuid :: Vehicle :
case HighGuid :: Creature :
case HighGuid :: Pet :
2014-10-18 20:51:00 +01:00
return m_origObjectTargetGUID ;
default :
return ObjectGuid ();
}
}
void SpellCastTargets :: SetOrigUnitTarget ( Unit * target )
{
if ( ! target )
return ;
m_origObjectTargetGUID = target -> GetGUID ();
}
2014-09-14 16:14:12 +02:00
ObjectGuid SpellCastTargets :: GetUnitTargetGUID () const
2011-08-26 12:05:47 +02:00
{
2014-09-14 16:14:12 +02:00
if ( m_objectTargetGUID . IsUnit ())
return m_objectTargetGUID ;
return ObjectGuid :: Empty ;
2011-08-26 12:05:47 +02:00
}
Unit * SpellCastTargets :: GetUnitTarget () const
{
if ( m_objectTarget )
return m_objectTarget -> ToUnit ();
2014-09-14 16:14:12 +02:00
2011-08-26 12:05:47 +02:00
return NULL ;
}
2011-06-23 13:28:52 +02:00
void SpellCastTargets :: SetUnitTarget ( Unit * target )
2010-02-20 23:59:05 +01:00
{
if ( ! target )
return ;
2011-08-26 12:05:47 +02:00
m_objectTarget = target ;
m_objectTargetGUID = target -> GetGUID ();
2010-08-02 20:05:22 +02:00
m_targetMask |= TARGET_FLAG_UNIT ;
2010-02-20 23:59:05 +01:00
}
2014-09-14 16:14:12 +02:00
ObjectGuid SpellCastTargets :: GetGOTargetGUID () const
2011-08-26 12:05:47 +02:00
{
2014-09-14 16:14:12 +02:00
if ( m_objectTargetGUID . IsAnyTypeGameObject ())
return m_objectTargetGUID ;
return ObjectGuid :: Empty ;
2011-08-26 12:05:47 +02:00
}
GameObject * SpellCastTargets :: GetGOTarget () const
2011-08-24 08:07:59 +02:00
{
2011-08-26 12:05:47 +02:00
if ( m_objectTarget )
return m_objectTarget -> ToGameObject ();
2014-09-14 16:14:12 +02:00
2011-08-26 12:05:47 +02:00
return NULL ;
2011-08-24 08:07:59 +02:00
}
void SpellCastTargets :: SetGOTarget ( GameObject * target )
{
if ( ! target )
return ;
2011-08-26 12:05:47 +02:00
m_objectTarget = target ;
m_objectTargetGUID = target -> GetGUID ();
2011-08-24 08:07:59 +02:00
m_targetMask |= TARGET_FLAG_GAMEOBJECT ;
}
2014-09-14 16:14:12 +02:00
ObjectGuid SpellCastTargets :: GetCorpseTargetGUID () const
2011-08-26 12:05:47 +02:00
{
2014-09-14 16:14:12 +02:00
if ( m_objectTargetGUID . IsCorpse ())
return m_objectTargetGUID ;
return ObjectGuid :: Empty ;
2011-08-26 12:05:47 +02:00
}
Corpse * SpellCastTargets :: GetCorpseTarget () const
{
if ( m_objectTarget )
return m_objectTarget -> ToCorpse ();
2014-09-14 16:14:12 +02:00
2011-08-26 12:05:47 +02:00
return NULL ;
}
WorldObject * SpellCastTargets :: GetObjectTarget () const
{
return m_objectTarget ;
}
2014-09-14 16:14:12 +02:00
ObjectGuid SpellCastTargets :: GetObjectTargetGUID () const
2011-08-24 08:07:59 +02:00
{
2011-08-26 12:05:47 +02:00
return m_objectTargetGUID ;
2011-08-24 08:07:59 +02:00
}
2011-08-26 12:05:47 +02:00
void SpellCastTargets :: RemoveObjectTarget ()
2011-08-24 08:07:59 +02:00
{
2011-08-26 12:05:47 +02:00
m_objectTarget = NULL ;
2014-09-14 16:14:12 +02:00
m_objectTargetGUID . Clear ();
2011-08-26 12:05:47 +02:00
m_targetMask &= ~ ( TARGET_FLAG_UNIT_MASK | TARGET_FLAG_CORPSE_MASK | TARGET_FLAG_GAMEOBJECT_MASK );
2011-08-24 08:07:59 +02:00
}
void SpellCastTargets :: SetItemTarget ( Item * item )
{
if ( ! item )
return ;
m_itemTarget = item ;
m_itemTargetGUID = item -> GetGUID ();
m_itemTargetEntry = item -> GetEntry ();
m_targetMask |= TARGET_FLAG_ITEM ;
}
void SpellCastTargets :: SetTradeItemTarget ( Player * caster )
{
2015-04-04 00:07:16 +02:00
m_itemTargetGUID = ObjectGuid :: TradeItem ;
2011-08-24 08:07:59 +02:00
m_itemTargetEntry = 0 ;
m_targetMask |= TARGET_FLAG_TRADE_ITEM ;
Update ( caster );
}
void SpellCastTargets :: UpdateTradeSlotItem ()
{
if ( m_itemTarget && ( m_targetMask & TARGET_FLAG_TRADE_ITEM ))
{
m_itemTargetGUID = m_itemTarget -> GetGUID ();
m_itemTargetEntry = m_itemTarget -> GetEntry ();
}
}
2012-05-30 08:01:02 +02:00
SpellDestination const * SpellCastTargets :: GetSrc () const
2011-06-23 13:28:52 +02:00
{
2012-05-30 08:01:02 +02:00
return & m_src ;
}
Position const * SpellCastTargets :: GetSrcPos () const
{
return & m_src . _position ;
2011-06-23 13:28:52 +02:00
}
void SpellCastTargets :: SetSrc ( float x , float y , float z )
2010-02-20 23:59:05 +01:00
{
2012-05-30 08:01:02 +02:00
m_src = SpellDestination ( x , y , z );
2010-08-02 20:05:22 +02:00
m_targetMask |= TARGET_FLAG_SOURCE_LOCATION ;
2010-02-20 23:59:05 +01:00
}
2011-06-23 13:28:52 +02:00
void SpellCastTargets :: SetSrc ( Position const & pos )
2010-02-20 23:59:05 +01:00
{
2012-05-30 08:01:02 +02:00
m_src = SpellDestination ( pos );
2010-08-08 20:32:14 +02:00
m_targetMask |= TARGET_FLAG_SOURCE_LOCATION ;
}
2011-06-23 13:28:52 +02:00
void SpellCastTargets :: SetSrc ( WorldObject const & wObj )
2010-08-08 20:32:14 +02:00
{
2012-05-30 08:01:02 +02:00
m_src = SpellDestination ( wObj );
2010-08-08 20:32:14 +02:00
m_targetMask |= TARGET_FLAG_SOURCE_LOCATION ;
}
2011-06-23 13:28:52 +02:00
void SpellCastTargets :: ModSrc ( Position const & pos )
2010-08-08 20:32:14 +02:00
{
ASSERT ( m_targetMask & TARGET_FLAG_SOURCE_LOCATION );
2014-01-23 18:15:59 +01:00
m_src . Relocate ( pos );
2010-02-20 23:59:05 +01:00
}
2011-08-24 08:07:59 +02:00
void SpellCastTargets :: RemoveSrc ()
{
m_targetMask &= ~ ( TARGET_FLAG_SOURCE_LOCATION );
}
2012-05-30 08:01:02 +02:00
SpellDestination const * SpellCastTargets :: GetDst () const
{
return & m_dst ;
}
WorldLocation const * SpellCastTargets :: GetDstPos () const
2011-06-23 13:28:52 +02:00
{
2012-05-30 08:01:02 +02:00
return & m_dst . _position ;
2011-06-23 13:28:52 +02:00
}
void SpellCastTargets :: SetDst ( float x , float y , float z , float orientation , uint32 mapId )
2010-02-20 23:59:05 +01:00
{
2012-05-30 08:01:02 +02:00
m_dst = SpellDestination ( x , y , z , orientation , mapId );
2010-08-02 20:05:22 +02:00
m_targetMask |= TARGET_FLAG_DEST_LOCATION ;
2010-02-20 23:59:05 +01:00
}
2011-06-23 13:28:52 +02:00
void SpellCastTargets :: SetDst ( Position const & pos )
2010-08-08 20:32:14 +02:00
{
2012-05-30 08:01:02 +02:00
m_dst = SpellDestination ( pos );
2010-08-08 20:32:14 +02:00
m_targetMask |= TARGET_FLAG_DEST_LOCATION ;
}
2011-06-23 13:28:52 +02:00
void SpellCastTargets :: SetDst ( WorldObject const & wObj )
2010-08-08 20:32:14 +02:00
{
2012-05-30 08:01:02 +02:00
m_dst = SpellDestination ( wObj );
2010-08-08 20:32:14 +02:00
m_targetMask |= TARGET_FLAG_DEST_LOCATION ;
}
2014-01-23 18:15:59 +01:00
void SpellCastTargets :: SetDst ( SpellDestination const & spellDest )
{
m_dst = spellDest ;
m_targetMask |= TARGET_FLAG_DEST_LOCATION ;
}
2011-06-23 13:28:52 +02:00
void SpellCastTargets :: SetDst ( SpellCastTargets const & spellTargets )
2010-08-18 15:04:00 +02:00
{
2012-05-30 08:01:02 +02:00
m_dst = spellTargets . m_dst ;
2011-09-05 14:01:50 +02:00
m_targetMask |= TARGET_FLAG_DEST_LOCATION ;
2010-08-18 15:04:00 +02:00
}
2011-06-23 13:28:52 +02:00
void SpellCastTargets :: ModDst ( Position const & pos )
2010-02-20 23:59:05 +01:00
{
2010-08-08 20:32:14 +02:00
ASSERT ( m_targetMask & TARGET_FLAG_DEST_LOCATION );
2014-01-23 18:15:59 +01:00
m_dst . Relocate ( pos );
}
2010-08-08 20:32:14 +02:00
2014-01-23 18:15:59 +01:00
void SpellCastTargets :: ModDst ( SpellDestination const & spellDest )
{
ASSERT ( m_targetMask & TARGET_FLAG_DEST_LOCATION );
m_dst = spellDest ;
2010-02-20 23:59:05 +01:00
}
2011-08-24 08:07:59 +02:00
void SpellCastTargets :: RemoveDst ()
2011-07-28 23:44:39 +02:00
{
2011-08-24 08:07:59 +02:00
m_targetMask &= ~ ( TARGET_FLAG_DEST_LOCATION );
2011-07-28 23:44:39 +02:00
}
2010-02-20 23:59:05 +01:00
void SpellCastTargets :: Update ( Unit * caster )
{
2014-10-21 19:23:32 +02:00
m_objectTarget = ! m_objectTargetGUID . IsEmpty () ? (( m_objectTargetGUID == caster -> GetGUID ()) ? caster : ObjectAccessor :: GetWorldObject ( * caster , m_objectTargetGUID )) : NULL ;
2010-02-20 23:59:05 +01:00
m_itemTarget = NULL ;
2010-03-09 21:11:54 +01:00
if ( caster -> GetTypeId () == TYPEID_PLAYER )
2010-02-20 23:59:05 +01:00
{
2011-06-12 01:47:45 +02:00
Player * player = caster -> ToPlayer ();
2010-04-07 19:14:10 +02:00
if ( m_targetMask & TARGET_FLAG_ITEM )
2010-06-25 13:15:51 +02:00
m_itemTarget = player -> GetItemByGuid ( m_itemTargetGUID );
2010-03-09 21:11:54 +01:00
else if ( m_targetMask & TARGET_FLAG_TRADE_ITEM )
2014-10-25 17:11:35 +02:00
{
2015-04-04 00:07:16 +02:00
if ( m_itemTargetGUID == ObjectGuid :: TradeItem )
2010-06-25 13:15:51 +02:00
if ( TradeData * pTrade = player -> GetTradeData ())
m_itemTarget = pTrade -> GetTraderData () -> GetItem ( TRADE_SLOT_NONTRADED );
2014-10-25 17:11:35 +02:00
}
2010-03-09 21:11:54 +01:00
if ( m_itemTarget )
2010-02-20 23:59:05 +01:00
m_itemTargetEntry = m_itemTarget -> GetEntry ();
}
2011-05-22 16:01:53 -07:00
2010-08-08 20:32:14 +02:00
// update positions by transport move
2014-10-21 19:23:32 +02:00
if ( HasSrc () && ! m_src . _transportGUID . IsEmpty ())
2010-08-08 20:32:14 +02:00
{
2012-05-30 08:01:02 +02:00
if ( WorldObject * transport = ObjectAccessor :: GetWorldObject ( * caster , m_src . _transportGUID ))
2010-08-08 20:32:14 +02:00
{
2012-05-30 08:01:02 +02:00
m_src . _position . Relocate ( transport );
m_src . _position . RelocateOffset ( m_src . _transportOffset );
2010-08-08 20:32:14 +02:00
}
}
2011-05-22 16:01:53 -07:00
2014-10-21 19:23:32 +02:00
if ( HasDst () && ! m_dst . _transportGUID . IsEmpty ())
2010-08-08 20:32:14 +02:00
{
2012-05-30 08:01:02 +02:00
if ( WorldObject * transport = ObjectAccessor :: GetWorldObject ( * caster , m_dst . _transportGUID ))
2010-08-08 20:32:14 +02:00
{
2012-05-30 08:01:02 +02:00
m_dst . _position . Relocate ( transport );
m_dst . _position . RelocateOffset ( m_dst . _transportOffset );
2010-08-08 20:32:14 +02:00
}
}
2010-02-20 23:59:05 +01:00
}
2011-06-23 13:28:52 +02:00
void SpellCastTargets :: OutDebug () const
2010-02-20 23:59:05 +01:00
{
2010-08-08 20:32:14 +02:00
if ( ! m_targetMask )
2015-03-08 05:18:51 +01:00
TC_LOG_DEBUG ( "spells" , "No targets" );
2011-08-26 12:05:47 +02:00
2015-03-08 05:18:51 +01:00
TC_LOG_DEBUG ( "spells" , "target mask: %u" , m_targetMask );
2011-08-26 12:05:47 +02:00
if ( m_targetMask & ( TARGET_FLAG_UNIT_MASK | TARGET_FLAG_CORPSE_MASK | TARGET_FLAG_GAMEOBJECT_MASK ))
2015-03-08 05:18:51 +01:00
TC_LOG_DEBUG ( "spells" , "Object target: %s" , m_objectTargetGUID . ToString (). c_str ());
2010-08-08 20:32:14 +02:00
if ( m_targetMask & TARGET_FLAG_ITEM )
2015-03-08 05:18:51 +01:00
TC_LOG_DEBUG ( "spells" , "Item target: %s" , m_itemTargetGUID . ToString (). c_str ());
2010-08-08 20:32:14 +02:00
if ( m_targetMask & TARGET_FLAG_TRADE_ITEM )
2015-03-08 05:18:51 +01:00
TC_LOG_DEBUG ( "spells" , "Trade item target: %s" , m_itemTargetGUID . ToString (). c_str ());
2010-08-08 20:32:14 +02:00
if ( m_targetMask & TARGET_FLAG_SOURCE_LOCATION )
2015-03-08 05:18:51 +01:00
TC_LOG_DEBUG ( "spells" , "Source location: transport guid:%s trans offset: %s position: %s" , m_src . _transportGUID . ToString (). c_str (), m_src . _transportOffset . ToString (). c_str (), m_src . _position . ToString (). c_str ());
2010-08-08 20:32:14 +02:00
if ( m_targetMask & TARGET_FLAG_DEST_LOCATION )
2015-03-08 05:18:51 +01:00
TC_LOG_DEBUG ( "spells" , "Destination location: transport guid:%s trans offset: %s position: %s" , m_dst . _transportGUID . ToString (). c_str (), m_dst . _transportOffset . ToString (). c_str (), m_dst . _position . ToString (). c_str ());
2010-08-08 20:32:14 +02:00
if ( m_targetMask & TARGET_FLAG_STRING )
2015-03-08 05:18:51 +01:00
TC_LOG_DEBUG ( "spells" , "String: %s" , m_strTarget . c_str ());
TC_LOG_DEBUG ( "spells" , "speed: %f" , m_speed );
TC_LOG_DEBUG ( "spells" , "pitch: %f" , m_pitch );
2010-08-08 20:32:14 +02:00
}
2014-12-07 10:11:47 +01:00
SpellValue :: SpellValue ( Difficulty diff , SpellInfo const * proto )
2011-07-26 23:09:28 +02:00
{
2014-11-16 14:20:01 +01:00
// todo 6.x
2014-12-07 10:11:47 +01:00
SpellEffectInfoVector effects = proto -> GetEffectsForDifficulty ( diff );
ASSERT ( effects . size () <= MAX_SPELL_EFFECTS );
2015-02-08 16:23:31 +01:00
memset ( EffectBasePoints , 0 , sizeof ( EffectBasePoints ));
2014-12-07 10:11:47 +01:00
for ( SpellEffectInfo const * effect : effects )
if ( effect )
EffectBasePoints [ effect -> EffectIndex ] = effect -> BasePoints ;
2011-07-26 23:09:28 +02:00
MaxAffectedTargets = proto -> MaxAffectedTargets ;
RadiusMod = 1.0f ;
AuraStackAmount = 1 ;
}
2014-09-14 16:14:12 +02:00
Spell :: Spell ( Unit * caster , SpellInfo const * info , TriggerCastFlags triggerFlags , ObjectGuid originalCasterGUID , bool skipCheck ) :
2015-01-05 23:49:43 +02:00
m_spellInfo ( info ), m_caster (( info -> HasAttribute ( SPELL_ATTR6_CAST_BY_CHARMER ) && caster -> GetCharmerOrOwner ()) ? caster -> GetCharmerOrOwner () : caster ),
2015-01-10 01:35:47 +01:00
m_spellValue ( new SpellValue ( caster -> GetMap () -> GetDifficultyID (), m_spellInfo )), m_preGeneratedPath ( PathGenerator ( m_caster ))
2010-02-20 23:59:05 +01:00
{
2015-01-10 01:35:47 +01:00
_effects = info -> GetEffectsForDifficulty ( caster -> GetMap () -> GetDifficultyID ());
2014-11-16 14:20:01 +01:00
2011-03-04 21:18:38 +01:00
m_customError = SPELL_CUSTOM_ERROR_NONE ;
2010-02-20 23:59:05 +01:00
m_skipCheck = skipCheck ;
2017-01-13 18:54:15 +01:00
m_fromClient = false ;
2010-02-20 23:59:05 +01:00
m_selfContainer = NULL ;
m_referencedFromCurrentSpell = false ;
m_executedCurrently = false ;
2011-07-26 23:09:28 +02:00
m_needComboPoints = m_spellInfo -> NeedsComboPoints ();
2010-02-20 23:59:05 +01:00
m_comboPointGain = 0 ;
m_delayStart = 0 ;
m_delayAtDamageCount = 0 ;
2010-12-04 10:31:14 +01:00
m_applyMultiplierMask = 0 ;
2010-02-20 23:59:05 +01:00
m_auraScaleMask = 0 ;
2013-12-14 19:36:43 +01:00
memset ( m_damageMultipliers , 0 , sizeof ( m_damageMultipliers ));
2010-02-20 23:59:05 +01:00
// Get data for type of attack
switch ( m_spellInfo -> DmgClass )
{
case SPELL_DAMAGE_CLASS_MELEE :
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR3_REQ_OFFHAND ))
2010-02-20 23:59:05 +01:00
m_attackType = OFF_ATTACK ;
else
m_attackType = BASE_ATTACK ;
break ;
case SPELL_DAMAGE_CLASS_RANGED :
2011-07-26 23:09:28 +02:00
m_attackType = m_spellInfo -> IsRangedWeaponSpell () ? RANGED_ATTACK : BASE_ATTACK ;
2010-02-20 23:59:05 +01:00
break ;
default :
// Wands
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR2_AUTOREPEAT_FLAG ))
2010-02-20 23:59:05 +01:00
m_attackType = RANGED_ATTACK ;
else
m_attackType = BASE_ATTACK ;
break ;
}
2011-07-26 23:09:28 +02:00
m_spellSchoolMask = info -> GetSchoolMask (); // Can be override for some spell (wand shoot for example)
2010-02-20 23:59:05 +01:00
2010-04-07 19:14:10 +02:00
if ( m_attackType == RANGED_ATTACK )
2010-02-20 23:59:05 +01:00
// wand case
2010-04-07 19:14:10 +02:00
if (( m_caster -> getClassMask () & CLASSMASK_WAND_USERS ) != 0 && m_caster -> GetTypeId () == TYPEID_PLAYER )
if ( Item * pItem = m_caster -> ToPlayer () -> GetWeaponForAttack ( RANGED_ATTACK ))
2014-12-21 13:35:43 +01:00
m_spellSchoolMask = SpellSchoolMask ( 1 << pItem -> GetTemplate () -> GetDamageType ());
2010-02-20 23:59:05 +01:00
2014-10-21 20:27:00 +02:00
if ( ! originalCasterGUID . IsEmpty ())
2010-02-20 23:59:05 +01:00
m_originalCasterGUID = originalCasterGUID ;
else
m_originalCasterGUID = m_caster -> GetGUID ();
2010-04-07 19:14:10 +02:00
if ( m_originalCasterGUID == m_caster -> GetGUID ())
2010-02-20 23:59:05 +01:00
m_originalCaster = m_caster ;
else
{
m_originalCaster = ObjectAccessor :: GetUnit ( * m_caster , m_originalCasterGUID );
2011-08-18 20:24:46 +02:00
if ( m_originalCaster && ! m_originalCaster -> IsInWorld ())
m_originalCaster = NULL ;
2010-02-20 23:59:05 +01:00
}
m_spellState = SPELL_STATE_NULL ;
2011-07-31 19:03:06 +02:00
_triggeredCastFlags = triggerFlags ;
2015-01-31 19:52:36 +01:00
if ( info -> HasAttribute ( SPELL_ATTR4_CAN_CAST_WHILE_CASTING ))
_triggeredCastFlags = TriggerCastFlags ( uint32 ( _triggeredCastFlags ) | TRIGGERED_IGNORE_CAST_IN_PROGRESS | TRIGGERED_CAST_DIRECTLY );
2011-07-31 19:03:06 +02:00
2010-02-20 23:59:05 +01:00
m_CastItem = NULL ;
2014-09-14 16:14:12 +02:00
m_castItemGUID . Clear ();
2014-05-05 20:05:33 +02:00
m_castItemEntry = 0 ;
2015-11-24 00:16:42 +01:00
m_castItemLevel = - 1 ;
2015-08-26 11:12:35 +02:00
m_castFlagsEx = 0 ;
2010-02-20 23:59:05 +01:00
unitTarget = NULL ;
itemTarget = NULL ;
gameObjTarget = NULL ;
2013-12-14 19:36:43 +01:00
destTarget = NULL ;
damage = 0 ;
2014-12-19 18:55:09 +01:00
variance = 0.0f ;
2013-12-14 19:36:43 +01:00
effectHandleMode = SPELL_EFFECT_HANDLE_LAUNCH ;
2014-12-19 23:52:29 +01:00
effectInfo = nullptr ;
2013-12-14 19:36:43 +01:00
m_diminishLevel = DIMINISHING_LEVEL_1 ;
m_diminishGroup = DIMINISHING_NONE ;
m_damage = 0 ;
m_healing = 0 ;
m_procAttacker = 0 ;
m_procVictim = 0 ;
m_procEx = 0 ;
2010-02-20 23:59:05 +01:00
focusObject = NULL ;
2016-06-05 14:08:53 +02:00
m_castId = ObjectGuid :: Create < HighGuid :: Cast > ( SPELL_CAST_SOURCE_NORMAL , m_caster -> GetMapId (), m_spellInfo -> Id , m_caster -> GetMap () -> GenerateLowGuid < HighGuid :: Cast > ());
2015-07-18 00:45:21 +02:00
memset ( m_misc . Raw . Data , 0 , sizeof ( m_misc . Raw . Data ));
2016-06-29 19:49:23 +02:00
m_SpellVisual = caster -> GetCastSpellXSpellVisualId ( m_spellInfo );
2010-02-20 23:59:05 +01:00
m_preCastSpell = 0 ;
m_triggeredByAuraSpell = NULL ;
m_spellAura = NULL ;
//Auto Shot & Shoot (wand)
2011-07-26 23:09:28 +02:00
m_autoRepeat = m_spellInfo -> IsAutoRepeatRangedSpell ();
2016-03-16 21:38:01 +01:00
2010-02-20 23:59:05 +01:00
m_runesState = 0 ;
2011-08-30 13:46:36 +02:00
m_casttime = 0 ; // setup to correct value in Spell::prepare, must not be used before.
2010-02-20 23:59:05 +01:00
m_timer = 0 ; // will set to castime in prepare
2014-08-18 09:37:30 +02:00
m_channeledDuration = 0 ; // will be setup in Spell::handle_immediate
2013-12-14 19:36:43 +01:00
m_immediateHandled = false ;
2010-08-30 17:32:51 +02:00
m_channelTargetEffectMask = 0 ;
2010-02-20 23:59:05 +01:00
2011-07-13 20:14:55 +02:00
// Determine if spell can be reflected back to the caster
2011-07-12 06:34:57 +02:00
// Patch 1.2 notes: Spell Reflection no longer reflects abilities
2015-01-05 23:49:43 +02:00
m_canReflect = m_spellInfo -> DmgClass == SPELL_DAMAGE_CLASS_MAGIC && ! m_spellInfo -> HasAttribute ( SPELL_ATTR0_ABILITY )
&& ! m_spellInfo -> HasAttribute ( SPELL_ATTR1_CANT_BE_REFLECTED ) && ! m_spellInfo -> HasAttribute ( SPELL_ATTR0_UNAFFECTED_BY_INVULNERABILITY )
2011-07-26 23:09:28 +02:00
&& ! m_spellInfo -> IsPassive () && ! m_spellInfo -> IsPositive ();
2010-02-20 23:59:05 +01:00
CleanupTargetList ();
2012-05-30 08:01:02 +02:00
for ( uint8 i = 0 ; i < MAX_SPELL_EFFECTS ; ++ i )
m_destTargets [ i ] = SpellDestination ( * m_caster );
2010-02-20 23:59:05 +01:00
}
Spell ::~ Spell ()
{
2010-07-24 22:41:42 +02:00
// unload scripts
2016-11-13 21:44:04 -03:00
for ( auto itr = m_loadedScripts . begin (); itr != m_loadedScripts . end (); ++ itr )
2010-07-24 22:41:42 +02:00
{
2010-10-04 17:44:49 +02:00
( * itr ) -> _Unload ();
2010-07-24 22:41:42 +02:00
delete ( * itr );
}
2010-10-04 17:44:49 +02:00
2010-05-31 19:19:30 +02:00
if ( m_referencedFromCurrentSpell && m_selfContainer && * m_selfContainer == this )
{
// Clean the reference to avoid later crash.
2010-07-30 20:04:28 +02:00
// If this error is repeating, we may have to add an ASSERT to better track down how we get into this case.
2013-11-08 10:50:51 +01:00
TC_LOG_ERROR ( "spells" , "SPELL: deleting spell for spell ID %u. However, spell still referenced." , m_spellInfo -> Id );
2010-05-31 19:19:30 +02:00
* m_selfContainer = NULL ;
}
2010-04-07 19:14:10 +02:00
if ( m_caster && m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-07-30 20:04:28 +02:00
ASSERT ( m_caster -> ToPlayer () -> m_spellModTakingSpell != this );
2012-09-03 20:30:30 +02:00
2010-02-20 23:59:05 +01:00
delete m_spellValue ;
}
2011-08-24 08:07:59 +02:00
void Spell :: InitExplicitTargets ( SpellCastTargets const & targets )
{
m_targets = targets ;
2014-10-18 20:51:00 +01:00
m_targets . SetOrigUnitTarget ( m_targets . GetUnitTarget ());
2011-08-24 08:07:59 +02:00
// this function tries to correct spell explicit targets for spell
// client doesn't send explicit targets correctly sometimes - we need to fix such spells serverside
// this also makes sure that we correctly send explicit targets to client (removes redundant data)
uint32 neededTargets = m_spellInfo -> GetExplicitTargetMask ();
2011-08-26 12:05:47 +02:00
if ( WorldObject * target = m_targets . GetObjectTarget ())
2011-08-24 08:07:59 +02:00
{
2011-08-26 12:05:47 +02:00
// check if object target is valid with needed target flags
// for unit case allow corpse target mask because player with not released corpse is a unit target
if (( target -> ToUnit () && ! ( neededTargets & ( TARGET_FLAG_UNIT_MASK | TARGET_FLAG_CORPSE_MASK )))
|| ( target -> ToGameObject () && ! ( neededTargets & TARGET_FLAG_GAMEOBJECT_MASK ))
|| ( target -> ToCorpse () && ! ( neededTargets & TARGET_FLAG_CORPSE_MASK )))
m_targets . RemoveObjectTarget ();
}
else
{
// try to select correct unit target if not provided by client or by serverside cast
if ( neededTargets & ( TARGET_FLAG_UNIT_MASK ))
2011-08-24 08:07:59 +02:00
{
2011-11-23 19:17:33 +01:00
Unit * unit = NULL ;
2011-08-24 08:07:59 +02:00
// try to use player selection as a target
if ( Player * playerCaster = m_caster -> ToPlayer ())
{
// selection has to be found and to be valid target for the spell
2013-10-03 17:07:25 +02:00
if ( Unit * selectedUnit = ObjectAccessor :: GetUnit ( * m_caster , playerCaster -> GetTarget ()))
2011-08-26 12:05:47 +02:00
if ( m_spellInfo -> CheckExplicitTarget ( m_caster , selectedUnit ) == SPELL_CAST_OK )
2011-11-23 19:17:33 +01:00
unit = selectedUnit ;
2011-08-24 08:07:59 +02:00
}
// try to use attacked unit as a target
else if (( m_caster -> GetTypeId () == TYPEID_UNIT ) && neededTargets & ( TARGET_FLAG_UNIT_ENEMY | TARGET_FLAG_UNIT ))
2013-06-11 19:54:27 -02:30
unit = m_caster -> GetVictim ();
2011-11-23 19:17:33 +01:00
2011-08-24 08:07:59 +02:00
// didn't find anything - let's use self as target
2011-11-23 19:17:33 +01:00
if ( ! unit && neededTargets & ( TARGET_FLAG_UNIT_RAID | TARGET_FLAG_UNIT_PARTY | TARGET_FLAG_UNIT_ALLY ))
unit = m_caster ;
2011-08-26 12:05:47 +02:00
2011-11-23 19:17:33 +01:00
m_targets . SetUnitTarget ( unit );
2011-08-24 08:07:59 +02:00
}
}
// check if spell needs dst target
if ( neededTargets & TARGET_FLAG_DEST_LOCATION )
{
// and target isn't set
2011-08-26 16:30:56 +02:00
if ( ! m_targets . HasDst ())
2011-08-24 08:07:59 +02:00
{
// try to use unit target if provided
2011-08-26 16:30:56 +02:00
if ( WorldObject * target = targets . GetObjectTarget ())
2011-08-24 08:07:59 +02:00
m_targets . SetDst ( * target );
// or use self if not available
else
m_targets . SetDst ( * m_caster );
}
}
else
m_targets . RemoveDst ();
if ( neededTargets & TARGET_FLAG_SOURCE_LOCATION )
{
2011-08-26 16:30:56 +02:00
if ( ! targets . HasSrc ())
2011-08-24 08:07:59 +02:00
m_targets . SetSrc ( * m_caster );
}
else
m_targets . RemoveSrc ();
}
2012-02-19 00:40:22 +01:00
void Spell :: SelectExplicitTargets ()
{
// here go all explicit target changes made to explicit targets after spell prepare phase is finished
if ( Unit * target = m_targets . GetUnitTarget ())
{
// check for explicit target redirection, for Grounding Totem for example
if ( m_spellInfo -> GetExplicitTargetMask () & TARGET_FLAG_UNIT_ENEMY
2015-08-08 21:11:55 +02:00
|| ( m_spellInfo -> GetExplicitTargetMask () & TARGET_FLAG_UNIT && ! m_caster -> IsFriendlyTo ( target )))
2012-02-19 00:40:22 +01:00
{
Unit * redirect ;
switch ( m_spellInfo -> DmgClass )
{
case SPELL_DAMAGE_CLASS_MAGIC :
redirect = m_caster -> GetMagicHitRedirectTarget ( target , m_spellInfo );
break ;
case SPELL_DAMAGE_CLASS_MELEE :
case SPELL_DAMAGE_CLASS_RANGED :
redirect = m_caster -> GetMeleeHitRedirectTarget ( target , m_spellInfo );
break ;
default :
redirect = NULL ;
break ;
}
if ( redirect && ( redirect != target ))
m_targets . SetUnitTarget ( redirect );
}
}
}
2010-02-20 23:59:05 +01:00
void Spell :: SelectSpellTargets ()
{
2012-02-19 00:40:22 +01:00
// select targets for cast phase
SelectExplicitTargets ();
2012-02-21 20:03:27 +01:00
uint32 processedAreaEffectsMask = 0 ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2014-11-27 15:11:43 +01:00
if ( ! effect )
continue ;
2010-02-20 23:59:05 +01:00
// not call for empty effect.
// Also some spells use not used effect targets for store targets for dummy effect in triggered spells
2014-11-16 14:20:01 +01:00
if ( ! effect -> IsEffect ())
2011-09-16 11:40:53 +02:00
continue ;
2011-08-27 12:59:05 +02:00
// set expected type of implicit targets to be sent to client
2014-11-16 14:20:01 +01:00
uint32 implicitTargetMask = GetTargetFlagMask ( effect -> TargetA . GetObjectType ()) | GetTargetFlagMask ( effect -> TargetB . GetObjectType ());
2011-08-27 12:59:05 +02:00
if ( implicitTargetMask & TARGET_FLAG_UNIT )
m_targets . SetTargetFlag ( TARGET_FLAG_UNIT );
if ( implicitTargetMask & ( TARGET_FLAG_GAMEOBJECT | TARGET_FLAG_GAMEOBJECT_ITEM ))
m_targets . SetTargetFlag ( TARGET_FLAG_GAMEOBJECT );
2014-11-16 14:20:01 +01:00
SelectEffectImplicitTargets ( SpellEffIndex ( effect -> EffectIndex ), effect -> TargetA , processedAreaEffectsMask );
SelectEffectImplicitTargets ( SpellEffIndex ( effect -> EffectIndex ), effect -> TargetB , processedAreaEffectsMask );
2010-02-20 23:59:05 +01:00
2011-09-23 11:58:01 +02:00
// Select targets of effect based on effect type
// those are used when no valid target could be added for spell effect based on spell target type
// some spell effects use explicit target as a default target added to target map (like SPELL_EFFECT_LEARN_SPELL)
// some spell effects add target to target map only when target type specified (like SPELL_EFFECT_WEAPON)
// some spell effects don't add anything to target map (confirmed with sniffs) (like SPELL_EFFECT_DESTROY_ALL_TOTEMS)
2014-11-16 14:20:01 +01:00
SelectEffectTypeImplicitTargets ( effect -> EffectIndex );
2011-07-28 23:44:39 +02:00
2012-05-30 08:01:02 +02:00
if ( m_targets . HasDst ())
2014-11-16 14:20:01 +01:00
AddDestTarget ( * m_targets . GetDst (), effect -> EffectIndex );
2012-05-30 08:01:02 +02:00
2011-07-26 23:09:28 +02:00
if ( m_spellInfo -> IsChanneled ())
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
uint32 mask = ( 1 << effect -> EffectIndex );
2015-02-12 22:08:17 +00:00
for ( std :: vector < TargetInfo >:: iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
{
2010-04-07 19:14:10 +02:00
if ( ihit -> effectMask & mask )
2010-02-20 23:59:05 +01:00
{
2010-08-30 17:32:51 +02:00
m_channelTargetEffectMask |= mask ;
2010-02-20 23:59:05 +01:00
break ;
}
}
}
else if ( m_auraScaleMask )
{
bool checkLvl = ! m_UniqueTargetInfo . empty ();
2015-02-12 22:08:17 +00:00
for ( std :: vector < TargetInfo >:: iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end ();)
2010-02-20 23:59:05 +01:00
{
// remove targets which did not pass min level check
2010-04-07 19:14:10 +02:00
if ( m_auraScaleMask && ihit -> effectMask == m_auraScaleMask )
2010-02-20 23:59:05 +01:00
{
// Do not check for selfcast
if ( ! ihit -> scaleAura && ihit -> targetGUID != m_caster -> GetGUID ())
{
2015-06-01 00:26:49 +01:00
ihit = m_UniqueTargetInfo . erase ( ihit );
continue ;
2010-02-20 23:59:05 +01:00
}
}
2015-06-01 00:26:49 +01:00
2010-02-20 23:59:05 +01:00
++ ihit ;
}
2015-06-01 00:26:49 +01:00
2010-02-20 23:59:05 +01:00
if ( checkLvl && m_UniqueTargetInfo . empty ())
{
SendCastResult ( SPELL_FAILED_LOWLEVEL );
finish ( false );
}
}
}
2010-04-07 19:14:10 +02:00
if ( m_targets . HasDst ())
2010-02-20 23:59:05 +01:00
{
2010-04-07 19:14:10 +02:00
if ( m_targets . HasTraj ())
2010-02-20 23:59:05 +01:00
{
float speed = m_targets . GetSpeedXY ();
2010-04-07 19:14:10 +02:00
if ( speed > 0.0f )
2014-08-24 02:11:33 +02:00
m_delayMoment = uint64 ( std :: floor ( m_targets . GetDist2d () / speed * 1000.0f ));
2010-02-20 23:59:05 +01:00
}
2011-07-26 23:09:28 +02:00
else if ( m_spellInfo -> Speed > 0.0f )
2010-02-20 23:59:05 +01:00
{
2012-05-30 08:01:02 +02:00
float dist = m_caster -> GetDistance ( * m_targets . GetDstPos ());
2015-01-05 23:49:43 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR9_SPECIAL_DELAY_CALCULATION ))
2014-08-24 02:11:33 +02:00
m_delayMoment = uint64 ( std :: floor ( dist / m_spellInfo -> Speed * 1000.0f ));
2012-12-28 22:18:19 +01:00
else
m_delayMoment = uint64 ( m_spellInfo -> Speed * 1000.0f );
2010-02-20 23:59:05 +01:00
}
}
}
2012-02-21 20:03:27 +01:00
void Spell :: SelectEffectImplicitTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType , uint32 & processedEffectMask )
2011-09-23 11:58:01 +02:00
{
2012-02-21 20:03:27 +01:00
if ( ! targetType . GetTarget ())
return ;
uint32 effectMask = 1 << effIndex ;
// set the same target list for all effects
// some spells appear to need this, however this requires more research
switch ( targetType . GetSelectionCategory ())
2011-09-23 11:58:01 +02:00
{
2012-02-21 20:03:27 +01:00
case TARGET_SELECT_CATEGORY_NEARBY :
case TARGET_SELECT_CATEGORY_CONE :
case TARGET_SELECT_CATEGORY_AREA :
// targets for effect already selected
if ( effectMask & processedEffectMask )
return ;
2014-12-19 20:47:01 +01:00
if ( SpellEffectInfo const * _effect = GetEffect ( effIndex ))
2013-01-02 11:00:16 +01:00
{
2014-12-19 20:47:01 +01:00
// choose which targets we can select at once
for ( SpellEffectInfo const * effect : GetEffects ())
2013-01-02 11:00:16 +01:00
{
2014-12-19 20:47:01 +01:00
//for (uint32 j = effIndex + 1; j < MAX_SPELL_EFFECTS; ++j)
if ( ! effect || effect -> EffectIndex <= uint32 ( effIndex ))
continue ;
if ( effect -> IsEffect () &&
_effect -> TargetA . GetTarget () == effect -> TargetA . GetTarget () &&
_effect -> TargetB . GetTarget () == effect -> TargetB . GetTarget () &&
_effect -> ImplicitTargetConditions == effect -> ImplicitTargetConditions &&
_effect -> CalcRadius ( m_caster ) == effect -> CalcRadius ( m_caster ) &&
CheckScriptEffectImplicitTargets ( effIndex , effect -> EffectIndex ))
{
effectMask |= 1 << effect -> EffectIndex ;
}
2013-01-02 11:00:16 +01:00
}
}
2012-02-21 20:03:27 +01:00
processedEffectMask |= effectMask ;
2012-02-22 09:15:57 +01:00
break ;
2011-09-23 11:58:01 +02:00
default :
break ;
}
2012-06-30 16:07:09 +02:00
switch ( targetType . GetSelectionCategory ())
2011-09-23 11:58:01 +02:00
{
2012-02-21 20:03:27 +01:00
case TARGET_SELECT_CATEGORY_CHANNEL :
SelectImplicitChannelTargets ( effIndex , targetType );
break ;
case TARGET_SELECT_CATEGORY_NEARBY :
SelectImplicitNearbyTargets ( effIndex , targetType , effectMask );
break ;
case TARGET_SELECT_CATEGORY_CONE :
SelectImplicitConeTargets ( effIndex , targetType , effectMask );
break ;
case TARGET_SELECT_CATEGORY_AREA :
SelectImplicitAreaTargets ( effIndex , targetType , effectMask );
break ;
case TARGET_SELECT_CATEGORY_DEFAULT :
switch ( targetType . GetObjectType ())
2011-09-23 11:58:01 +02:00
{
2012-02-21 20:03:27 +01:00
case TARGET_OBJECT_TYPE_SRC :
2012-06-30 16:07:09 +02:00
switch ( targetType . GetReferenceType ())
2011-09-23 11:58:01 +02:00
{
2012-02-21 20:03:27 +01:00
case TARGET_REFERENCE_TYPE_CASTER :
m_targets . SetSrc ( * m_caster );
break ;
default :
2012-05-30 08:01:02 +02:00
ASSERT ( false && "Spell::SelectEffectImplicitTargets: received not implemented select target reference type for TARGET_TYPE_OBJECT_SRC" );
2012-02-21 20:03:27 +01:00
break ;
2011-09-23 11:58:01 +02:00
}
2012-02-21 20:03:27 +01:00
break ;
case TARGET_OBJECT_TYPE_DEST :
2012-06-30 16:07:09 +02:00
switch ( targetType . GetReferenceType ())
2012-02-21 20:03:27 +01:00
{
case TARGET_REFERENCE_TYPE_CASTER :
SelectImplicitCasterDestTargets ( effIndex , targetType );
break ;
case TARGET_REFERENCE_TYPE_TARGET :
2012-02-22 10:21:02 +01:00
SelectImplicitTargetDestTargets ( effIndex , targetType );
2012-02-21 20:03:27 +01:00
break ;
case TARGET_REFERENCE_TYPE_DEST :
SelectImplicitDestDestTargets ( effIndex , targetType );
break ;
default :
2012-05-30 08:01:02 +02:00
ASSERT ( false && "Spell::SelectEffectImplicitTargets: received not implemented select target reference type for TARGET_TYPE_OBJECT_DEST" );
2012-02-21 20:03:27 +01:00
break ;
}
break ;
default :
2012-06-30 16:07:09 +02:00
switch ( targetType . GetReferenceType ())
2012-02-21 20:03:27 +01:00
{
case TARGET_REFERENCE_TYPE_CASTER :
SelectImplicitCasterObjectTargets ( effIndex , targetType );
break ;
case TARGET_REFERENCE_TYPE_TARGET :
SelectImplicitTargetObjectTargets ( effIndex , targetType );
break ;
default :
2012-05-30 08:01:02 +02:00
ASSERT ( false && "Spell::SelectEffectImplicitTargets: received not implemented select target reference type for TARGET_TYPE_OBJECT" );
2012-02-21 20:03:27 +01:00
break ;
}
break ;
2011-09-23 11:58:01 +02:00
}
break ;
2012-02-21 20:03:27 +01:00
case TARGET_SELECT_CATEGORY_NYI :
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "SPELL: target type %u, found in spellID %u, effect %u is not implemented yet!" , m_spellInfo -> Id , effIndex , targetType . GetTarget ());
2011-09-23 11:58:01 +02:00
break ;
2011-09-28 11:11:38 +02:00
default :
2012-02-21 20:03:27 +01:00
ASSERT ( false && "Spell::SelectEffectImplicitTargets: received not implemented select target category" );
2011-09-28 11:11:38 +02:00
break ;
2011-09-23 11:58:01 +02:00
}
}
2012-02-21 20:03:27 +01:00
void Spell :: SelectImplicitChannelTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( targetType . GetReferenceType () != TARGET_REFERENCE_TYPE_CASTER )
{
ASSERT ( false && "Spell::SelectImplicitChannelTargets: received not implemented target reference type" );
2011-09-23 11:58:01 +02:00
return ;
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
Spell * channeledSpell = m_originalCaster -> GetCurrentSpell ( CURRENT_CHANNELED_SPELL );
if ( ! channeledSpell )
2010-02-20 23:59:05 +01:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "Spell::SelectImplicitChannelTargets: cannot find channel spell for spell ID %u, effect %u" , m_spellInfo -> Id , effIndex );
2011-09-23 11:58:01 +02:00
return ;
2012-02-21 20:03:27 +01:00
}
2012-02-22 10:34:08 +01:00
switch ( targetType . GetTarget ())
2011-09-23 11:58:01 +02:00
{
2012-02-21 20:03:27 +01:00
case TARGET_UNIT_CHANNEL_TARGET :
2012-07-03 12:35:06 +02:00
{
2014-09-14 16:14:12 +02:00
WorldObject * target = ObjectAccessor :: GetUnit ( * m_caster , m_originalCaster -> GetChannelObjectGuid ());
2014-03-22 21:39:38 +01:00
CallScriptObjectTargetSelectHandlers ( target , effIndex , targetType );
2012-02-21 20:03:27 +01:00
// unit target may be no longer avalible - teleported out of map for example
2012-07-03 12:35:06 +02:00
if ( target && target -> ToUnit ())
AddUnitTarget ( target -> ToUnit (), 1 << effIndex );
2010-10-08 19:17:49 +02:00
else
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "SPELL: cannot find channel spell target for spell ID %u, effect %u" , m_spellInfo -> Id , effIndex );
2010-02-20 23:59:05 +01:00
break ;
2012-07-03 12:35:06 +02:00
}
2012-02-21 20:03:27 +01:00
case TARGET_DEST_CHANNEL_TARGET :
if ( channeledSpell -> m_targets . HasDst ())
m_targets . SetDst ( channeledSpell -> m_targets );
2014-09-14 16:14:12 +02:00
else if ( WorldObject * target = ObjectAccessor :: GetWorldObject ( * m_caster , m_originalCaster -> GetChannelObjectGuid ()))
2012-07-03 12:35:06 +02:00
{
2014-03-22 21:39:38 +01:00
CallScriptObjectTargetSelectHandlers ( target , effIndex , targetType );
2012-07-03 12:35:06 +02:00
if ( target )
2016-04-23 16:13:12 +02:00
{
SpellDestination dest ( * target );
CallScriptDestinationTargetSelectHandlers ( dest , effIndex , targetType );
m_targets . SetDst ( dest );
}
2012-07-03 12:35:06 +02:00
}
2012-02-21 20:03:27 +01:00
else
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "SPELL: cannot find channel spell destination for spell ID %u, effect %u" , m_spellInfo -> Id , effIndex );
2012-02-21 20:03:27 +01:00
break ;
case TARGET_DEST_CHANNEL_CASTER :
2016-04-23 16:13:12 +02:00
{
SpellDestination dest ( * channeledSpell -> GetCaster ());
CallScriptDestinationTargetSelectHandlers ( dest , effIndex , targetType );
m_targets . SetDst ( dest );
2010-02-20 23:59:05 +01:00
break ;
2016-04-23 16:13:12 +02:00
}
2010-02-20 23:59:05 +01:00
default :
2012-02-21 20:03:27 +01:00
ASSERT ( false && "Spell::SelectImplicitChannelTargets: received not implemented target type" );
2011-09-28 11:11:38 +02:00
break ;
2010-02-20 23:59:05 +01:00
}
2011-09-23 11:58:01 +02:00
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
void Spell :: SelectImplicitNearbyTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType , uint32 effMask )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( targetType . GetReferenceType () != TARGET_REFERENCE_TYPE_CASTER )
{
ASSERT ( false && "Spell::SelectImplicitNearbyTargets: received not implemented target reference type" );
return ;
}
2010-04-07 18:09:10 +02:00
2014-11-16 14:20:01 +01:00
SpellEffectInfo const * effect = GetEffect ( effIndex );
if ( ! effect )
return ;
2012-02-22 09:15:57 +01:00
float range = 0.0f ;
2012-02-21 20:03:27 +01:00
switch ( targetType . GetCheckType ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
case TARGET_CHECK_ENEMY :
range = m_spellInfo -> GetMaxRange ( false , m_caster , this );
2010-02-20 23:59:05 +01:00
break ;
2012-02-21 20:03:27 +01:00
case TARGET_CHECK_ALLY :
case TARGET_CHECK_PARTY :
case TARGET_CHECK_RAID :
case TARGET_CHECK_RAID_CLASS :
range = m_spellInfo -> GetMaxRange ( true , m_caster , this );
break ;
case TARGET_CHECK_ENTRY :
case TARGET_CHECK_DEFAULT :
range = m_spellInfo -> GetMaxRange ( m_spellInfo -> IsPositive (), m_caster , this );
2010-02-20 23:59:05 +01:00
break ;
default :
2012-02-21 20:03:27 +01:00
ASSERT ( false && "Spell::SelectImplicitNearbyTargets: received not implemented selection check type" );
break ;
2010-02-20 23:59:05 +01:00
}
2015-10-25 10:59:58 +01:00
ConditionContainer * condList = effect -> ImplicitTargetConditions ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// handle emergency case - try to use other provided targets if no conditions provided
2012-02-22 09:15:57 +01:00
if ( targetType . GetCheckType () == TARGET_CHECK_ENTRY && ( ! condList || condList -> empty ()))
2010-07-21 01:15:27 +02:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "Spell::SelectImplicitNearbyTargets: no conditions entry for target with TARGET_CHECK_ENTRY of spell ID %u, effect %u - selecting default targets" , m_spellInfo -> Id , effIndex );
2012-02-21 20:03:27 +01:00
switch ( targetType . GetObjectType ())
{
case TARGET_OBJECT_TYPE_GOBJ :
if ( m_spellInfo -> RequiresSpellFocus )
{
if ( focusObject )
AddGOTarget ( focusObject , effMask );
return ;
}
break ;
case TARGET_OBJECT_TYPE_DEST :
if ( m_spellInfo -> RequiresSpellFocus )
{
if ( focusObject )
2016-04-23 16:13:12 +02:00
{
SpellDestination dest ( * focusObject );
CallScriptDestinationTargetSelectHandlers ( dest , effIndex , targetType );
m_targets . SetDst ( dest );
}
2012-02-21 20:03:27 +01:00
return ;
}
break ;
default :
break ;
}
2010-07-21 01:15:27 +02:00
}
2012-02-21 20:03:27 +01:00
WorldObject * target = SearchNearbyTarget ( range , targetType . GetObjectType (), targetType . GetCheckType (), condList );
if ( ! target )
2010-02-20 23:59:05 +01:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "Spell::SelectImplicitNearbyTargets: cannot find nearby target for spell ID %u, effect %u" , m_spellInfo -> Id , effIndex );
2012-02-21 20:03:27 +01:00
return ;
2010-02-20 23:59:05 +01:00
}
2014-03-22 21:39:38 +01:00
CallScriptObjectTargetSelectHandlers ( target , effIndex , targetType );
2014-03-22 16:35:11 +01:00
if ( ! target )
{
TC_LOG_DEBUG ( "spells" , "Spell::SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id %u set NULL target, effect %u" , m_spellInfo -> Id , effIndex );
return ;
}
2012-07-03 12:35:06 +02:00
2012-02-21 20:03:27 +01:00
switch ( targetType . GetObjectType ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
case TARGET_OBJECT_TYPE_UNIT :
2015-07-21 00:33:36 +02:00
if ( Unit * unit = target -> ToUnit ())
AddUnitTarget ( unit , effMask , true , false );
2014-03-22 16:35:11 +01:00
else
{
2014-09-14 16:14:12 +02:00
TC_LOG_DEBUG ( "spells" , "Spell::SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id %u set object of wrong type, expected unit, got %s, effect %u" , m_spellInfo -> Id , target -> GetGUID (). GetTypeName (), effMask );
2014-03-22 16:35:11 +01:00
return ;
}
2012-02-21 20:03:27 +01:00
break ;
case TARGET_OBJECT_TYPE_GOBJ :
if ( GameObject * gobjTarget = target -> ToGameObject ())
AddGOTarget ( gobjTarget , effMask );
2014-03-22 16:35:11 +01:00
else
{
2014-09-14 16:14:12 +02:00
TC_LOG_DEBUG ( "spells" , "Spell::SelectImplicitNearbyTargets: OnObjectTargetSelect script hook for spell Id %u set object of wrong type, expected gameobject, got %s, effect %u" , m_spellInfo -> Id , target -> GetGUID (). GetTypeName (), effMask );
2014-03-22 16:35:11 +01:00
return ;
}
2012-02-21 20:03:27 +01:00
break ;
case TARGET_OBJECT_TYPE_DEST :
2016-04-23 16:13:12 +02:00
{
SpellDestination dest ( * target );
CallScriptDestinationTargetSelectHandlers ( dest , effIndex , targetType );
m_targets . SetDst ( dest );
2012-02-21 20:03:27 +01:00
break ;
2016-04-23 16:13:12 +02:00
}
2012-02-21 20:03:27 +01:00
default :
ASSERT ( false && "Spell::SelectImplicitNearbyTargets: received not implemented target object type" );
break ;
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
SelectImplicitChainTargets ( effIndex , targetType , target , effMask );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
void Spell :: SelectImplicitConeTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType , uint32 effMask )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( targetType . GetReferenceType () != TARGET_REFERENCE_TYPE_CASTER )
{
ASSERT ( false && "Spell::SelectImplicitConeTargets: received not implemented target reference type" );
2010-02-20 23:59:05 +01:00
return ;
2012-02-21 20:03:27 +01:00
}
std :: list < WorldObject *> targets ;
SpellTargetObjectTypes objectType = targetType . GetObjectType ();
SpellTargetCheckTypes selectionType = targetType . GetCheckType ();
2014-11-16 14:20:01 +01:00
SpellEffectInfo const * effect = GetEffect ( effIndex );
if ( ! effect )
return ;
2015-10-25 10:59:58 +01:00
ConditionContainer * condList = effect -> ImplicitTargetConditions ;
2014-08-21 16:56:11 +02:00
float coneAngle = float ( M_PI ) / 2 ;
2014-11-16 14:20:01 +01:00
float radius = effect -> CalcRadius ( m_caster ) * m_spellValue -> RadiusMod ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( uint32 containerTypeMask = GetSearcherTypeMask ( objectType , condList ))
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
Trinity :: WorldObjectSpellConeTargetCheck check ( coneAngle , radius , m_caster , m_spellInfo , selectionType , condList );
Trinity :: WorldObjectListSearcher < Trinity :: WorldObjectSpellConeTargetCheck > searcher ( m_caster , targets , check , containerTypeMask );
2012-06-29 21:53:35 +02:00
SearchTargets < Trinity :: WorldObjectListSearcher < Trinity :: WorldObjectSpellConeTargetCheck > > ( searcher , containerTypeMask , m_caster , m_caster , radius );
2014-03-22 21:39:38 +01:00
CallScriptObjectAreaTargetSelectHandlers ( targets , effIndex , targetType );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( ! targets . empty ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// Other special target selection goes here
if ( uint32 maxTargets = m_spellValue -> MaxAffectedTargets )
2017-03-23 00:11:58 +01:00
Trinity :: Containers :: RandomResize ( targets , maxTargets );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
for ( std :: list < WorldObject *>:: iterator itr = targets . begin (); itr != targets . end (); ++ itr )
{
2015-07-21 00:33:36 +02:00
if ( Unit * unit = ( * itr ) -> ToUnit ())
AddUnitTarget ( unit , effMask , false );
2012-02-21 20:03:27 +01:00
else if ( GameObject * gObjTarget = ( * itr ) -> ToGameObject ())
2014-01-23 18:15:59 +01:00
AddGOTarget ( gObjTarget , effMask );
2012-02-21 20:03:27 +01:00
}
}
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
void Spell :: SelectImplicitAreaTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType , uint32 effMask )
{
Unit * referer = NULL ;
switch ( targetType . GetReferenceType ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
case TARGET_REFERENCE_TYPE_SRC :
case TARGET_REFERENCE_TYPE_DEST :
case TARGET_REFERENCE_TYPE_CASTER :
referer = m_caster ;
break ;
case TARGET_REFERENCE_TYPE_TARGET :
referer = m_targets . GetUnitTarget ();
break ;
case TARGET_REFERENCE_TYPE_LAST :
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// find last added target for this effect
2015-02-12 22:08:17 +00:00
for ( std :: vector < TargetInfo >:: reverse_iterator ihit = m_UniqueTargetInfo . rbegin (); ihit != m_UniqueTargetInfo . rend (); ++ ihit )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( ihit -> effectMask & ( 1 << effIndex ))
{
referer = ObjectAccessor :: GetUnit ( * m_caster , ihit -> targetGUID );
break ;
}
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
break ;
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
default :
ASSERT ( false && "Spell::SelectImplicitAreaTargets: received not implemented target reference type" );
return ;
2010-02-20 23:59:05 +01:00
}
2014-01-26 18:22:06 +01:00
2012-02-21 20:03:27 +01:00
if ( ! referer )
return ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
Position const * center = NULL ;
switch ( targetType . GetReferenceType ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
case TARGET_REFERENCE_TYPE_SRC :
2012-05-30 08:01:02 +02:00
center = m_targets . GetSrcPos ();
2012-02-21 20:03:27 +01:00
break ;
case TARGET_REFERENCE_TYPE_DEST :
2012-05-30 08:01:02 +02:00
center = m_targets . GetDstPos ();
2012-02-21 20:03:27 +01:00
break ;
case TARGET_REFERENCE_TYPE_CASTER :
case TARGET_REFERENCE_TYPE_TARGET :
case TARGET_REFERENCE_TYPE_LAST :
center = referer ;
break ;
default :
ASSERT ( false && "Spell::SelectImplicitAreaTargets: received not implemented target reference type" );
return ;
2010-02-20 23:59:05 +01:00
}
2014-01-26 18:22:06 +01:00
2012-02-21 20:03:27 +01:00
std :: list < WorldObject *> targets ;
2014-11-16 14:20:01 +01:00
SpellEffectInfo const * effect = GetEffect ( effIndex );
if ( ! effect )
return ;
float radius = effect -> CalcRadius ( m_caster ) * m_spellValue -> RadiusMod ;
SearchAreaTargets ( targets , radius , center , referer , targetType . GetObjectType (), targetType . GetCheckType (), effect -> ImplicitTargetConditions );
2010-02-20 23:59:05 +01:00
2014-03-22 21:39:38 +01:00
CallScriptObjectAreaTargetSelectHandlers ( targets , effIndex , targetType );
2012-07-01 21:05:53 +02:00
2014-01-26 02:24:57 +01:00
if ( ! targets . empty ())
2011-07-22 21:22:05 +02:00
{
2012-02-21 20:03:27 +01:00
// Other special target selection goes here
if ( uint32 maxTargets = m_spellValue -> MaxAffectedTargets )
2017-03-23 00:11:58 +01:00
Trinity :: Containers :: RandomResize ( targets , maxTargets );
2010-02-20 23:59:05 +01:00
2014-01-26 02:24:57 +01:00
for ( std :: list < WorldObject *>:: iterator itr = targets . begin (); itr != targets . end (); ++ itr )
2012-02-21 20:03:27 +01:00
{
2015-07-21 00:33:36 +02:00
if ( Unit * unit = ( * itr ) -> ToUnit ())
AddUnitTarget ( unit , effMask , false , true , center );
2014-01-26 02:24:57 +01:00
else if ( GameObject * gObjTarget = ( * itr ) -> ToGameObject ())
AddGOTarget ( gObjTarget , effMask );
2012-02-21 20:03:27 +01:00
}
}
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
void Spell :: SelectImplicitCasterDestTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType )
2010-02-20 23:59:05 +01:00
{
2014-01-23 18:15:59 +01:00
SpellDestination dest ( * m_caster );
2012-06-30 16:07:09 +02:00
switch ( targetType . GetTarget ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
case TARGET_DEST_CASTER :
2014-01-23 18:15:59 +01:00
break ;
2012-02-21 20:03:27 +01:00
case TARGET_DEST_HOME :
if ( Player * playerCaster = m_caster -> ToPlayer ())
2014-01-23 18:15:59 +01:00
dest = SpellDestination ( playerCaster -> m_homebindX , playerCaster -> m_homebindY , playerCaster -> m_homebindZ , playerCaster -> GetOrientation (), playerCaster -> m_homebindMapId );
break ;
2012-02-21 20:03:27 +01:00
case TARGET_DEST_DB :
2013-05-13 11:30:48 +03:00
if ( SpellTargetPosition const * st = sSpellMgr -> GetSpellTargetPosition ( m_spellInfo -> Id , effIndex ))
2011-09-16 11:40:53 +02:00
{
2013-03-08 21:41:30 +01:00
/// @todo fix this check
2014-11-16 14:20:01 +01:00
if ( HasEffect ( SPELL_EFFECT_TELEPORT_UNITS ) || HasEffect ( SPELL_EFFECT_BIND ))
2014-01-23 18:15:59 +01:00
dest = SpellDestination ( st -> target_X , st -> target_Y , st -> target_Z , st -> target_Orientation , ( int32 ) st -> target_mapId );
2012-02-21 20:03:27 +01:00
else if ( st -> target_mapId == m_caster -> GetMapId ())
2014-01-23 18:15:59 +01:00
dest = SpellDestination ( st -> target_X , st -> target_Y , st -> target_Z , st -> target_Orientation );
2012-02-21 20:03:27 +01:00
}
else
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "SPELL: unknown target coordinates for spell ID %u" , m_spellInfo -> Id );
2014-01-23 18:15:59 +01:00
if ( WorldObject * target = m_targets . GetObjectTarget ())
dest = SpellDestination ( * target );
2011-09-16 11:40:53 +02:00
}
2014-01-23 18:15:59 +01:00
break ;
2012-02-21 20:03:27 +01:00
case TARGET_DEST_CASTER_FISHING :
{
2014-01-26 01:02:20 +01:00
float minDist = m_spellInfo -> GetMinRange ( true );
float maxDist = m_spellInfo -> GetMaxRange ( true );
float dist = frand ( minDist , maxDist );
2014-01-26 02:24:57 +01:00
float x , y , z ;
2014-01-26 01:02:20 +01:00
float angle = float ( rand_norm ()) * static_cast < float > ( M_PI * 35.0f / 180.0f ) - static_cast < float > ( M_PI * 17.5f / 180.0f );
2014-01-26 02:24:57 +01:00
m_caster -> GetClosePoint ( x , y , z , DEFAULT_WORLD_OBJECT_SIZE , dist , angle );
2014-01-26 01:02:20 +01:00
2014-05-11 14:43:12 +01:00
float ground = m_caster -> GetMap () -> GetHeight ( m_caster -> GetPhaseMask (), x , y , z , true , 50.0f );
float liquidLevel = VMAP_INVALID_HEIGHT_VALUE ;
LiquidData liquidData ;
if ( m_caster -> GetMap () -> getLiquidStatus ( x , y , z , MAP_ALL_LIQUIDS , & liquidData ))
liquidLevel = liquidData . level ;
2014-01-26 01:02:20 +01:00
if ( liquidLevel <= ground ) // When there is no liquid Map::GetWaterOrGroundLevel returns ground level
{
SendCastResult ( SPELL_FAILED_NOT_HERE );
SendChannelUpdate ( 0 );
finish ( false );
return ;
}
if ( ground + 0.75 > liquidLevel )
{
SendCastResult ( SPELL_FAILED_TOO_SHALLOW );
SendChannelUpdate ( 0 );
finish ( false );
return ;
}
dest = SpellDestination ( x , y , liquidLevel , m_caster -> GetOrientation ());
break ;
2011-09-16 11:40:53 +02:00
}
2012-02-22 09:15:57 +01:00
default :
2014-01-23 18:15:59 +01:00
{
2014-11-16 14:20:01 +01:00
if ( SpellEffectInfo const * effect = GetEffect ( effIndex ))
{
2016-02-05 14:36:08 +01:00
float dist = effect -> CalcRadius ( m_caster );
2014-11-16 14:20:01 +01:00
float angle = targetType . CalcDirectionAngle ();
float objSize = m_caster -> GetObjectSize ();
2016-02-05 14:36:08 +01:00
switch ( targetType . GetTarget ())
{
case TARGET_DEST_CASTER_SUMMON :
dist = PET_FOLLOW_DIST ;
break ;
case TARGET_DEST_CASTER_RANDOM :
if ( dist > objSize )
dist = objSize + ( dist - objSize ) * float ( rand_norm ());
break ;
case TARGET_DEST_CASTER_FRONT_LEFT :
case TARGET_DEST_CASTER_BACK_LEFT :
case TARGET_DEST_CASTER_FRONT_RIGHT :
case TARGET_DEST_CASTER_BACK_RIGHT :
{
static float const DefaultTotemDistance = 3.0f ;
if ( ! effect -> HasRadius () && ! effect -> HasMaxRadius ())
dist = DefaultTotemDistance ;
break ;
}
default :
break ;
}
2011-07-22 21:22:05 +02:00
2014-11-16 14:20:01 +01:00
if ( dist < objSize )
dist = objSize ;
2010-02-20 23:59:05 +01:00
2014-11-16 14:20:01 +01:00
Position pos = dest . _position ;
m_caster -> MovePositionToFirstCollision ( pos , dist , angle );
2010-02-20 23:59:05 +01:00
2014-11-16 14:20:01 +01:00
dest . Relocate ( pos );
}
2014-01-23 18:15:59 +01:00
break ;
}
}
2014-03-22 21:39:38 +01:00
CallScriptDestinationTargetSelectHandlers ( dest , effIndex , targetType );
2014-01-23 18:15:59 +01:00
m_targets . SetDst ( dest );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
void Spell :: SelectImplicitTargetDestTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType )
2010-02-20 23:59:05 +01:00
{
2014-01-27 20:26:34 +01:00
ASSERT ( m_targets . GetObjectTarget () && "Spell::SelectImplicitTargetDestTargets - no explicit object target available!" );
2012-02-21 20:03:27 +01:00
WorldObject * target = m_targets . GetObjectTarget ();
2014-01-23 18:15:59 +01:00
SpellDestination dest ( * target );
2012-06-30 16:07:09 +02:00
switch ( targetType . GetTarget ())
2011-09-16 11:40:53 +02:00
{
2012-02-21 20:03:27 +01:00
case TARGET_DEST_TARGET_ENEMY :
case TARGET_DEST_TARGET_ANY :
2014-01-23 18:15:59 +01:00
break ;
2012-02-22 09:15:57 +01:00
default :
2014-01-23 18:15:59 +01:00
{
2014-11-16 14:20:01 +01:00
if ( SpellEffectInfo const * effect = GetEffect ( effIndex ))
{
float angle = targetType . CalcDirectionAngle ();
float objSize = target -> GetObjectSize ();
float dist = effect -> CalcRadius ( m_caster );
if ( dist < objSize )
dist = objSize ;
else if ( targetType . GetTarget () == TARGET_DEST_TARGET_RANDOM )
dist = objSize + ( dist - objSize ) * float ( rand_norm ());
Position pos = dest . _position ;
target -> MovePositionToFirstCollision ( pos , dist , angle );
dest . Relocate ( pos );
}
2012-02-22 09:15:57 +01:00
break ;
2014-01-23 18:15:59 +01:00
}
2011-09-16 11:40:53 +02:00
}
2010-02-20 23:59:05 +01:00
2014-03-22 21:39:38 +01:00
CallScriptDestinationTargetSelectHandlers ( dest , effIndex , targetType );
2014-01-23 18:15:59 +01:00
m_targets . SetDst ( dest );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
void Spell :: SelectImplicitDestDestTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType )
2010-02-20 23:59:05 +01:00
{
2012-02-22 21:06:29 +01:00
// set destination to caster if no dest provided
// can only happen if previous destination target could not be set for some reason
// (not found nearby target, or channel target for example
// maybe we should abort the spell in such case?
2014-01-23 18:15:59 +01:00
CheckDst ();
SpellDestination dest ( * m_targets . GetDst ());
2010-03-29 21:47:07 +02:00
2012-06-30 16:07:09 +02:00
switch ( targetType . GetTarget ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
case TARGET_DEST_DYNOBJ_ENEMY :
case TARGET_DEST_DYNOBJ_ALLY :
case TARGET_DEST_DYNOBJ_NONE :
case TARGET_DEST_DEST :
return ;
case TARGET_DEST_TRAJ :
2014-01-23 18:15:59 +01:00
SelectImplicitTrajTargets ( effIndex );
2012-02-21 20:03:27 +01:00
return ;
2012-02-22 09:15:57 +01:00
default :
2014-01-23 18:15:59 +01:00
{
2014-11-16 14:20:01 +01:00
if ( SpellEffectInfo const * effect = GetEffect ( effIndex ))
{
float angle = targetType . CalcDirectionAngle ();
float dist = effect -> CalcRadius ( m_caster );
if ( targetType . GetTarget () == TARGET_DEST_DEST_RANDOM )
dist *= float ( rand_norm ());
2014-01-23 18:15:59 +01:00
2014-11-16 14:20:01 +01:00
Position pos = dest . _position ;
m_caster -> MovePositionToFirstCollision ( pos , dist , angle );
2014-01-23 18:15:59 +01:00
2014-11-16 14:20:01 +01:00
dest . Relocate ( pos );
}
2012-02-22 09:15:57 +01:00
break ;
2014-01-23 18:15:59 +01:00
}
2010-02-20 23:59:05 +01:00
}
2014-03-22 21:39:38 +01:00
CallScriptDestinationTargetSelectHandlers ( dest , effIndex , targetType );
2014-01-23 18:15:59 +01:00
m_targets . ModDst ( dest );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
void Spell :: SelectImplicitCasterObjectTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType )
2010-02-20 23:59:05 +01:00
{
2012-07-03 12:35:06 +02:00
WorldObject * target = NULL ;
bool checkIfValid = true ;
2012-06-30 16:07:09 +02:00
switch ( targetType . GetTarget ())
2010-07-29 19:48:40 +02:00
{
2012-02-21 20:03:27 +01:00
case TARGET_UNIT_CASTER :
2012-07-03 12:35:06 +02:00
target = m_caster ;
checkIfValid = false ;
2012-02-21 20:03:27 +01:00
break ;
case TARGET_UNIT_MASTER :
2012-07-03 12:35:06 +02:00
target = m_caster -> GetCharmerOrOwner ();
2012-02-21 20:03:27 +01:00
break ;
case TARGET_UNIT_PET :
2012-07-03 12:35:06 +02:00
target = m_caster -> GetGuardianPet ();
2012-02-21 20:03:27 +01:00
break ;
case TARGET_UNIT_SUMMONER :
2013-06-11 19:54:27 -02:30
if ( m_caster -> IsSummon ())
2012-07-03 12:35:06 +02:00
target = m_caster -> ToTempSummon () -> GetSummoner ();
2012-02-21 20:03:27 +01:00
break ;
case TARGET_UNIT_VEHICLE :
2012-07-03 12:35:06 +02:00
target = m_caster -> GetVehicleBase ();
2012-02-21 20:03:27 +01:00
break ;
case TARGET_UNIT_PASSENGER_0 :
case TARGET_UNIT_PASSENGER_1 :
case TARGET_UNIT_PASSENGER_2 :
case TARGET_UNIT_PASSENGER_3 :
case TARGET_UNIT_PASSENGER_4 :
case TARGET_UNIT_PASSENGER_5 :
case TARGET_UNIT_PASSENGER_6 :
case TARGET_UNIT_PASSENGER_7 :
2015-08-12 14:05:14 +02:00
if ( m_caster -> GetTypeId () == TYPEID_UNIT && m_caster -> IsVehicle ())
2012-07-03 12:35:06 +02:00
target = m_caster -> GetVehicleKit () -> GetPassenger ( targetType . GetTarget () - TARGET_UNIT_PASSENGER_0 );
2012-02-21 20:03:27 +01:00
break ;
2012-02-22 09:15:57 +01:00
default :
break ;
2012-02-21 20:03:27 +01:00
}
2012-07-03 12:35:06 +02:00
2014-03-22 21:39:38 +01:00
CallScriptObjectTargetSelectHandlers ( target , effIndex , targetType );
2012-07-03 12:35:06 +02:00
if ( target && target -> ToUnit ())
AddUnitTarget ( target -> ToUnit (), 1 << effIndex , checkIfValid );
2010-02-20 23:59:05 +01:00
}
2011-05-22 16:01:53 -07:00
2012-02-21 20:03:27 +01:00
void Spell :: SelectImplicitTargetObjectTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType )
2010-02-20 23:59:05 +01:00
{
2012-02-22 19:15:52 +01:00
ASSERT (( m_targets . GetObjectTarget () || m_targets . GetItemTarget ()) && "Spell::SelectImplicitTargetObjectTargets - no explicit object or item target available!" );
2011-05-22 16:01:53 -07:00
2012-07-03 12:35:06 +02:00
WorldObject * target = m_targets . GetObjectTarget ();
2014-03-22 21:39:38 +01:00
CallScriptObjectTargetSelectHandlers ( target , effIndex , targetType );
2012-07-03 12:35:06 +02:00
if ( target )
{
if ( Unit * unit = target -> ToUnit ())
AddUnitTarget ( unit , 1 << effIndex , true , false );
else if ( GameObject * gobj = target -> ToGameObject ())
AddGOTarget ( gobj , 1 << effIndex );
2012-02-21 20:03:27 +01:00
SelectImplicitChainTargets ( effIndex , targetType , target , 1 << effIndex );
2012-07-03 12:35:06 +02:00
}
// Script hook can remove object target and we would wrongly land here
else if ( Item * item = m_targets . GetItemTarget ())
AddItemTarget ( item , 1 << effIndex );
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
void Spell :: SelectImplicitChainTargets ( SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType , WorldObject * target , uint32 effMask )
{
2014-11-16 14:20:01 +01:00
SpellEffectInfo const * effect = GetEffect ( effIndex );
if ( ! effect )
return ;
uint32 maxTargets = effect -> ChainTargets ;
2012-02-21 20:03:27 +01:00
if ( Player * modOwner = m_caster -> GetSpellModOwner ())
modOwner -> ApplySpellMod ( m_spellInfo -> Id , SPELLMOD_JUMP_TARGETS , maxTargets , this );
if ( maxTargets > 1 )
2011-09-16 11:40:53 +02:00
{
2012-02-21 20:03:27 +01:00
// mark damage multipliers as used
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * eff : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( eff && ( effMask & ( 1 << eff -> EffectIndex )))
2014-11-16 14:20:01 +01:00
m_damageMultipliers [ eff -> EffectIndex ] = 1.0f ;
2012-02-21 20:03:27 +01:00
m_applyMultiplierMask |= effMask ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
std :: list < WorldObject *> targets ;
SearchChainTargets ( targets , maxTargets - 1 , target , targetType . GetObjectType (), targetType . GetCheckType ()
2014-11-16 14:20:01 +01:00
, effect -> ImplicitTargetConditions , targetType . GetTarget () == TARGET_UNIT_TARGET_CHAINHEAL_ALLY );
2010-02-20 23:59:05 +01:00
2012-07-01 21:05:53 +02:00
// Chain primary target is added earlier
2014-03-22 21:39:38 +01:00
CallScriptObjectAreaTargetSelectHandlers ( targets , effIndex , targetType );
2012-07-01 21:05:53 +02:00
2012-02-21 20:03:27 +01:00
for ( std :: list < WorldObject *>:: iterator itr = targets . begin (); itr != targets . end (); ++ itr )
2015-07-21 00:33:36 +02:00
if ( Unit * unit = ( * itr ) -> ToUnit ())
AddUnitTarget ( unit , effMask , false );
2010-07-29 19:48:40 +02:00
}
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
float tangent ( float x )
2010-02-20 23:59:05 +01:00
{
2014-08-21 16:56:11 +02:00
x = std :: tan ( x );
2012-02-21 20:03:27 +01:00
//if (x < std::numeric_limits<float>::max() && x > -std::numeric_limits<float>::max()) return x;
//if (x >= std::numeric_limits<float>::max()) return std::numeric_limits<float>::max();
//if (x <= -std::numeric_limits<float>::max()) return -std::numeric_limits<float>::max();
if ( x < 100000.0f && x > - 100000.0f ) return x ;
if ( x >= 100000.0f ) return 100000.0f ;
if ( x <= 100000.0f ) return - 100000.0f ;
return 0.0f ;
}
2011-05-22 16:01:53 -07:00
2012-02-21 20:03:27 +01:00
#define DEBUG_TRAJ(a) //a
2011-05-22 16:01:53 -07:00
2014-01-23 18:15:59 +01:00
void Spell :: SelectImplicitTrajTargets ( SpellEffIndex effIndex )
2012-02-21 20:03:27 +01:00
{
if ( ! m_targets . HasTraj ())
2010-02-20 23:59:05 +01:00
return ;
2012-02-21 20:03:27 +01:00
float dist2d = m_targets . GetDist2d ();
if ( ! dist2d )
2010-02-20 23:59:05 +01:00
return ;
2010-11-13 18:04:56 +01:00
2012-05-30 08:01:02 +02:00
float srcToDestDelta = m_targets . GetDstPos () -> m_positionZ - m_targets . GetSrcPos () -> m_positionZ ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
std :: list < WorldObject *> targets ;
2012-05-30 08:01:02 +02:00
Trinity :: WorldObjectSpellTrajTargetCheck check ( dist2d , m_targets . GetSrcPos (), m_caster , m_spellInfo );
2012-02-21 20:03:27 +01:00
Trinity :: WorldObjectListSearcher < Trinity :: WorldObjectSpellTrajTargetCheck > searcher ( m_caster , targets , check , GRID_MAP_TYPE_MASK_ALL );
2012-05-30 08:01:02 +02:00
SearchTargets < Trinity :: WorldObjectListSearcher < Trinity :: WorldObjectSpellTrajTargetCheck > > ( searcher , GRID_MAP_TYPE_MASK_ALL , m_caster , m_targets . GetSrcPos (), dist2d );
2012-02-21 20:03:27 +01:00
if ( targets . empty ())
2010-02-20 23:59:05 +01:00
return ;
2012-02-21 20:03:27 +01:00
targets . sort ( Trinity :: ObjectDistanceOrderPred ( m_caster ));
2010-02-20 23:59:05 +01:00
2015-02-12 02:37:42 +00:00
float b = tangent ( m_targets . GetPitch ());
2012-02-21 20:03:27 +01:00
float a = ( srcToDestDelta - dist2d * b ) / ( dist2d * dist2d );
if ( a > - 0.0001f )
a = 0 ;
2013-11-08 10:50:51 +01:00
DEBUG_TRAJ ( TC_LOG_ERROR ( "spells" , "Spell::SelectTrajTargets: a %f b %f" , a , b );)
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
float bestDist = m_spellInfo -> GetMaxRange ( false );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
std :: list < WorldObject *>:: const_iterator itr = targets . begin ();
for (; itr != targets . end (); ++ itr )
2010-02-20 23:59:05 +01:00
{
2014-06-27 16:58:46 +01:00
if ( ! m_caster -> HasInLine ( * itr , 5.0f ))
continue ;
if ( m_spellInfo -> CheckTarget ( m_caster , * itr , true ) != SPELL_CAST_OK )
continue ;
2015-07-21 00:33:36 +02:00
if ( Unit * unit = ( * itr ) -> ToUnit ())
2014-06-27 16:58:46 +01:00
{
2015-07-21 00:33:36 +02:00
if ( m_caster == * itr || m_caster -> IsOnVehicle ( unit ) || unit -> GetVehicle ())
2012-02-21 20:03:27 +01:00
continue ;
2010-02-20 23:59:05 +01:00
2015-07-21 00:33:36 +02:00
if ( Creature * creatureTarget = unit -> ToCreature ())
2014-06-27 16:58:46 +01:00
{
2016-05-26 12:56:50 +04:00
if ( ! ( creatureTarget -> GetCreatureTemplate () -> type_flags & CREATURE_TYPE_FLAG_CAN_COLLIDE_WITH_MISSILES ))
2014-06-27 16:58:46 +01:00
continue ;
}
}
2012-02-21 20:03:27 +01:00
const float size = std :: max (( * itr ) -> GetObjectSize () * 0.7f , 1.0f ); // 1/sqrt(3)
2013-03-08 21:41:30 +01:00
/// @todo all calculation should be based on src instead of m_caster
2012-10-02 15:06:19 +02:00
const float objDist2d = m_targets . GetSrcPos () -> GetExactDist2d ( * itr ) * std :: cos ( m_targets . GetSrcPos () -> GetRelativeAngle ( * itr ));
2012-05-30 08:01:02 +02:00
const float dz = ( * itr ) -> GetPositionZ () - m_targets . GetSrcPos () -> m_positionZ ;
2010-02-20 23:59:05 +01:00
2013-11-08 10:50:51 +01:00
DEBUG_TRAJ ( TC_LOG_ERROR ( "spells" , "Spell::SelectTrajTargets: check %u, dist between %f %f, height between %f %f." , ( * itr ) -> GetEntry (), objDist2d - size , objDist2d + size , dz - size , dz + size );)
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
float dist = objDist2d - size ;
float height = dist * ( a * dist + b );
2013-11-08 10:50:51 +01:00
DEBUG_TRAJ ( TC_LOG_ERROR ( "spells" , "Spell::SelectTrajTargets: dist %f, height %f." , dist , height );)
2012-02-21 20:03:27 +01:00
if ( dist < bestDist && height < dz + size && height > dz - size )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
bestDist = dist > 0 ? dist : 0 ;
2010-02-20 23:59:05 +01:00
break ;
}
2012-02-21 20:03:27 +01:00
#define CHECK_DIST {\
2013-11-08 10:50:51 +01:00
DEBUG_TRAJ(TC_LOG_ERROR("spells", "Spell::SelectTrajTargets: dist %f, height %f.", dist, height);)\
2012-02-21 20:03:27 +01:00
if (dist > bestDist)\
continue;\
if (dist < objDist2d + size && dist > objDist2d - size)\
{\
bestDist = dist;\
break;\
}\
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
if ( ! a )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
height = dz - size ;
dist = height / b ;
CHECK_DIST ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
height = dz + size ;
dist = height / b ;
CHECK_DIST ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
continue ;
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
height = dz - size ;
float sqrt1 = b * b + 4 * a * height ;
if ( sqrt1 > 0 )
2010-02-20 23:59:05 +01:00
{
2014-08-21 16:56:11 +02:00
sqrt1 = std :: sqrt ( sqrt1 );
2012-02-21 20:03:27 +01:00
dist = ( sqrt1 - b ) / ( 2 * a );
CHECK_DIST ;
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
height = dz + size ;
float sqrt2 = b * b + 4 * a * height ;
if ( sqrt2 > 0 )
2010-02-20 23:59:05 +01:00
{
2014-08-21 16:56:11 +02:00
sqrt2 = std :: sqrt ( sqrt2 );
2012-02-21 20:03:27 +01:00
dist = ( sqrt2 - b ) / ( 2 * a );
CHECK_DIST ;
dist = ( - sqrt2 - b ) / ( 2 * a );
CHECK_DIST ;
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
if ( sqrt1 > 0 )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
dist = ( - sqrt1 - b ) / ( 2 * a );
CHECK_DIST ;
2010-02-20 23:59:05 +01:00
}
}
2010-08-21 20:18:54 +02:00
2012-05-30 08:01:02 +02:00
if ( m_targets . GetSrcPos () -> GetExactDist2d ( m_targets . GetDstPos ()) > bestDist )
2010-02-20 23:59:05 +01:00
{
2012-10-02 15:06:19 +02:00
float x = m_targets . GetSrcPos () -> m_positionX + std :: cos ( m_caster -> GetOrientation ()) * bestDist ;
float y = m_targets . GetSrcPos () -> m_positionY + std :: sin ( m_caster -> GetOrientation ()) * bestDist ;
2012-05-30 08:01:02 +02:00
float z = m_targets . GetSrcPos () -> m_positionZ + bestDist * ( a * bestDist + b );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( itr != targets . end ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
float distSq = ( * itr ) -> GetExactDistSq ( x , y , z );
float sizeSq = ( * itr ) -> GetObjectSize ();
sizeSq *= sizeSq ;
2013-11-08 10:50:51 +01:00
DEBUG_TRAJ ( TC_LOG_ERROR ( "spells" , "Initial %f %f %f %f %f" , x , y , z , distSq , sizeSq );)
2012-02-21 20:03:27 +01:00
if ( distSq > sizeSq )
{
2014-08-21 16:56:11 +02:00
float factor = 1 - std :: sqrt ( sizeSq / distSq );
2012-02-21 20:03:27 +01:00
x += factor * (( * itr ) -> GetPositionX () - x );
y += factor * (( * itr ) -> GetPositionY () - y );
z += factor * (( * itr ) -> GetPositionZ () - z );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
distSq = ( * itr ) -> GetExactDistSq ( x , y , z );
2013-11-08 10:50:51 +01:00
DEBUG_TRAJ ( TC_LOG_ERROR ( "spells" , "Initial %f %f %f %f %f" , x , y , z , distSq , sizeSq );)
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
Position trajDst ;
trajDst . Relocate ( x , y , z , m_caster -> GetOrientation ());
2014-01-23 18:15:59 +01:00
SpellDestination dest ( * m_targets . GetDst ());
dest . Relocate ( trajDst );
2014-03-22 21:39:38 +01:00
CallScriptDestinationTargetSelectHandlers ( dest , effIndex , SpellImplicitTargetInfo ( TARGET_DEST_TRAJ ));
2014-01-23 18:15:59 +01:00
m_targets . ModDst ( dest );
2010-02-20 23:59:05 +01:00
}
2012-11-16 09:51:44 +01:00
2013-01-14 11:12:58 +01:00
if ( Vehicle * veh = m_caster -> GetVehicleKit ())
2012-11-16 09:51:44 +01:00
veh -> SetLastShootPos ( * m_targets . GetDstPos ());
2010-02-20 23:59:05 +01:00
}
2014-11-16 14:20:01 +01:00
void Spell :: SelectEffectTypeImplicitTargets ( uint32 effIndex )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// special case for SPELL_EFFECT_SUMMON_RAF_FRIEND and SPELL_EFFECT_SUMMON_PLAYER
2013-03-08 21:41:30 +01:00
/// @todo this is a workaround - target shouldn't be stored in target map for those spells
2014-11-16 14:20:01 +01:00
SpellEffectInfo const * effect = GetEffect ( effIndex );
if ( ! effect )
return ;
switch ( effect -> Effect )
2012-02-21 20:03:27 +01:00
{
case SPELL_EFFECT_SUMMON_RAF_FRIEND :
case SPELL_EFFECT_SUMMON_PLAYER :
2014-10-21 19:23:32 +02:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER && ! m_caster -> GetTarget (). IsEmpty ())
2012-02-21 20:03:27 +01:00
{
2013-10-03 17:07:25 +02:00
WorldObject * target = ObjectAccessor :: FindPlayer ( m_caster -> GetTarget ());
2012-07-03 12:35:06 +02:00
2014-03-22 21:39:38 +01:00
CallScriptObjectTargetSelectHandlers ( target , SpellEffIndex ( effIndex ), SpellImplicitTargetInfo ());
2012-07-03 12:35:06 +02:00
if ( target && target -> ToPlayer ())
AddUnitTarget ( target -> ToUnit (), 1 << effIndex , false );
2012-02-21 20:03:27 +01:00
}
return ;
default :
break ;
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// select spell implicit targets based on effect type
2014-11-16 14:20:01 +01:00
if ( ! effect -> GetImplicitTargetType ())
2012-02-21 20:03:27 +01:00
return ;
2010-02-20 23:59:05 +01:00
2014-11-16 14:20:01 +01:00
uint32 targetMask = effect -> GetMissingTargetMask ();
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( ! targetMask )
return ;
2010-02-20 23:59:05 +01:00
2012-07-03 12:35:06 +02:00
WorldObject * target = NULL ;
2014-11-16 14:20:01 +01:00
switch ( effect -> GetImplicitTargetType ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// add explicit object target or self to the target map
case EFFECT_IMPLICIT_TARGET_EXPLICIT :
// player which not released his spirit is Unit, but target flag for it is TARGET_FLAG_CORPSE_MASK
if ( targetMask & ( TARGET_FLAG_UNIT_MASK | TARGET_FLAG_CORPSE_MASK ))
{
2015-07-21 00:33:36 +02:00
if ( Unit * unit = m_targets . GetUnitTarget ())
target = unit ;
2012-02-21 20:03:27 +01:00
else if ( targetMask & TARGET_FLAG_CORPSE_MASK )
{
if ( Corpse * corpseTarget = m_targets . GetCorpseTarget ())
{
2013-03-08 21:41:30 +01:00
/// @todo this is a workaround - corpses should be added to spell target map too, but we can't do that so we add owner instead
2012-02-21 20:03:27 +01:00
if ( Player * owner = ObjectAccessor :: FindPlayer ( corpseTarget -> GetOwnerGUID ()))
2012-07-03 12:35:06 +02:00
target = owner ;
2012-02-21 20:03:27 +01:00
}
}
else //if (targetMask & TARGET_FLAG_UNIT_MASK)
2012-07-03 12:35:06 +02:00
target = m_caster ;
2012-02-21 20:03:27 +01:00
}
if ( targetMask & TARGET_FLAG_ITEM_MASK )
{
2015-07-21 00:33:36 +02:00
if ( Item * item = m_targets . GetItemTarget ())
AddItemTarget ( item , 1 << effIndex );
2012-07-03 12:35:06 +02:00
return ;
2012-02-21 20:03:27 +01:00
}
if ( targetMask & TARGET_FLAG_GAMEOBJECT_MASK )
2012-07-03 12:35:06 +02:00
target = m_targets . GetGOTarget ();
2012-02-21 20:03:27 +01:00
break ;
// add self to the target map
case EFFECT_IMPLICIT_TARGET_CASTER :
if ( targetMask & TARGET_FLAG_UNIT_MASK )
2012-07-03 12:35:06 +02:00
target = m_caster ;
2012-02-21 20:03:27 +01:00
break ;
default :
break ;
2010-02-20 23:59:05 +01:00
}
2012-07-03 12:35:06 +02:00
2014-03-22 21:39:38 +01:00
CallScriptObjectTargetSelectHandlers ( target , SpellEffIndex ( effIndex ), SpellImplicitTargetInfo ());
2012-07-03 12:35:06 +02:00
if ( target )
{
if ( target -> ToUnit ())
AddUnitTarget ( target -> ToUnit (), 1 << effIndex , false );
else if ( target -> ToGameObject ())
AddGOTarget ( target -> ToGameObject (), 1 << effIndex );
}
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2015-10-25 10:59:58 +01:00
uint32 Spell :: GetSearcherTypeMask ( SpellTargetObjectTypes objType , ConditionContainer * condList )
2012-02-21 20:03:27 +01:00
{
// this function selects which containers need to be searched for spell target
uint32 retMask = GRID_MAP_TYPE_MASK_ALL ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// filter searchers based on searched object type
switch ( objType )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
case TARGET_OBJECT_TYPE_UNIT :
case TARGET_OBJECT_TYPE_UNIT_AND_DEST :
case TARGET_OBJECT_TYPE_CORPSE :
case TARGET_OBJECT_TYPE_CORPSE_ENEMY :
case TARGET_OBJECT_TYPE_CORPSE_ALLY :
retMask &= GRID_MAP_TYPE_MASK_PLAYER | GRID_MAP_TYPE_MASK_CORPSE | GRID_MAP_TYPE_MASK_CREATURE ;
break ;
case TARGET_OBJECT_TYPE_GOBJ :
case TARGET_OBJECT_TYPE_GOBJ_ITEM :
retMask &= GRID_MAP_TYPE_MASK_GAMEOBJECT ;
break ;
2012-02-22 09:15:57 +01:00
default :
break ;
2010-02-20 23:59:05 +01:00
}
2015-01-05 23:49:43 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR2_CAN_TARGET_DEAD ))
2012-02-21 20:03:27 +01:00
retMask &= ~ GRID_MAP_TYPE_MASK_CORPSE ;
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR3_ONLY_TARGET_PLAYERS ))
2012-02-21 20:03:27 +01:00
retMask &= GRID_MAP_TYPE_MASK_CORPSE | GRID_MAP_TYPE_MASK_PLAYER ;
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR3_ONLY_TARGET_GHOSTS ))
2012-02-21 20:03:27 +01:00
retMask &= GRID_MAP_TYPE_MASK_PLAYER ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( condList )
retMask &= sConditionMgr -> GetSearcherTypeMaskForConditionList ( * condList );
return retMask ;
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
template < class SEARCHER >
void Spell :: SearchTargets ( SEARCHER & searcher , uint32 containerMask , Unit * referer , Position const * pos , float radius )
{
if ( ! containerMask )
return ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// search world and grid for possible targets
2014-07-17 15:42:57 +02:00
bool searchInGrid = ( containerMask & ( GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_GAMEOBJECT )) != 0 ;
bool searchInWorld = ( containerMask & ( GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER | GRID_MAP_TYPE_MASK_CORPSE )) != 0 ;
2012-02-21 20:03:27 +01:00
if ( searchInGrid || searchInWorld )
2010-02-20 23:59:05 +01:00
{
2013-01-14 09:50:59 +01:00
float x , y ;
2012-02-21 20:03:27 +01:00
x = pos -> GetPositionX ();
y = pos -> GetPositionY ();
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
CellCoord p ( Trinity :: ComputeCellCoord ( x , y ));
Cell cell ( p );
cell . SetNoCreate ();
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
Map & map = * ( referer -> GetMap ());
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( searchInWorld )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
TypeContainerVisitor < SEARCHER , WorldTypeMapContainer > world_object_notifier ( searcher );
cell . Visit ( p , world_object_notifier , map , radius , x , y );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
if ( searchInGrid )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
TypeContainerVisitor < SEARCHER , GridTypeMapContainer > grid_object_notifier ( searcher );
2013-01-14 09:50:59 +01:00
cell . Visit ( p , grid_object_notifier , map , radius , x , y );
2010-02-20 23:59:05 +01:00
}
}
}
2015-10-25 10:59:58 +01:00
WorldObject * Spell :: SearchNearbyTarget ( float range , SpellTargetObjectTypes objectType , SpellTargetCheckTypes selectionType , ConditionContainer * condList )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
WorldObject * target = NULL ;
uint32 containerTypeMask = GetSearcherTypeMask ( objectType , condList );
if ( ! containerTypeMask )
return NULL ;
Trinity :: WorldObjectSpellNearbyTargetCheck check ( range , m_caster , m_spellInfo , selectionType , condList );
Trinity :: WorldObjectLastSearcher < Trinity :: WorldObjectSpellNearbyTargetCheck > searcher ( m_caster , target , check , containerTypeMask );
SearchTargets < Trinity :: WorldObjectLastSearcher < Trinity :: WorldObjectSpellNearbyTargetCheck > > ( searcher , containerTypeMask , m_caster , m_caster , range );
return target ;
}
2010-08-19 14:31:31 +02:00
2015-10-25 10:59:58 +01:00
void Spell :: SearchAreaTargets ( std :: list < WorldObject *>& targets , float range , Position const * position , Unit * referer , SpellTargetObjectTypes objectType , SpellTargetCheckTypes selectionType , ConditionContainer * condList )
2012-02-21 20:03:27 +01:00
{
uint32 containerTypeMask = GetSearcherTypeMask ( objectType , condList );
if ( ! containerTypeMask )
return ;
Trinity :: WorldObjectSpellAreaTargetCheck check ( range , position , m_caster , referer , m_spellInfo , selectionType , condList );
Trinity :: WorldObjectListSearcher < Trinity :: WorldObjectSpellAreaTargetCheck > searcher ( m_caster , targets , check , containerTypeMask );
2012-05-30 08:01:02 +02:00
SearchTargets < Trinity :: WorldObjectListSearcher < Trinity :: WorldObjectSpellAreaTargetCheck > > ( searcher , containerTypeMask , m_caster , position , range );
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2015-10-25 10:59:58 +01:00
void Spell :: SearchChainTargets ( std :: list < WorldObject *>& targets , uint32 chainTargets , WorldObject * target , SpellTargetObjectTypes objectType , SpellTargetCheckTypes selectType , ConditionContainer * condList , bool isChainHeal )
2012-02-21 20:03:27 +01:00
{
// max dist for jump target selection
float jumpRadius = 0.0f ;
switch ( m_spellInfo -> DmgClass )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
case SPELL_DAMAGE_CLASS_RANGED :
// 7.5y for multi shot
jumpRadius = 7.5f ;
break ;
case SPELL_DAMAGE_CLASS_MELEE :
// 5y for swipe, cleave and similar
jumpRadius = 5.0f ;
break ;
case SPELL_DAMAGE_CLASS_NONE :
case SPELL_DAMAGE_CLASS_MAGIC :
// 12.5y for chain heal spell since 3.2 patch
if ( isChainHeal )
jumpRadius = 12.5f ;
// 10y as default for magic chain spells
else
jumpRadius = 10.0f ;
break ;
2010-02-20 23:59:05 +01:00
}
2015-03-08 17:39:20 +01:00
if ( Player * modOwner = m_caster -> GetSpellModOwner ())
modOwner -> ApplySpellMod ( m_spellInfo -> Id , SPELLMOD_JUMP_DISTANCE , jumpRadius , this );
2012-02-21 20:03:27 +01:00
// chain lightning/heal spells and similar - allow to jump at larger distance and go out of los
2015-01-05 23:49:43 +02:00
bool isBouncingFar = ( m_spellInfo -> HasAttribute ( SPELL_ATTR4_AREA_TARGET_CHAIN )
2012-02-21 20:03:27 +01:00
|| m_spellInfo -> DmgClass == SPELL_DAMAGE_CLASS_NONE
|| m_spellInfo -> DmgClass == SPELL_DAMAGE_CLASS_MAGIC );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// max dist which spell can reach
float searchRadius = jumpRadius ;
if ( isBouncingFar )
searchRadius *= chainTargets ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
std :: list < WorldObject *> tempTargets ;
SearchAreaTargets ( tempTargets , searchRadius , target , m_caster , objectType , selectType , condList );
tempTargets . remove ( target );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// remove targets which are always invalid for chain spells
// for some spells allow only chain targets in front of caster (swipe for example)
if ( ! isBouncingFar )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
for ( std :: list < WorldObject *>:: iterator itr = tempTargets . begin (); itr != tempTargets . end ();)
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
std :: list < WorldObject *>:: iterator checkItr = itr ++ ;
if ( ! m_caster -> HasInArc ( static_cast < float > ( M_PI ), * checkItr ))
tempTargets . erase ( checkItr );
}
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
while ( chainTargets )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// try to get unit for next chain jump
std :: list < WorldObject *>:: iterator foundItr = tempTargets . end ();
// get unit with highest hp deficit in dist
if ( isChainHeal )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
uint32 maxHPDeficit = 0 ;
for ( std :: list < WorldObject *>:: iterator itr = tempTargets . begin (); itr != tempTargets . end (); ++ itr )
2010-02-20 23:59:05 +01:00
{
2015-07-21 00:33:36 +02:00
if ( Unit * unit = ( * itr ) -> ToUnit ())
2010-02-20 23:59:05 +01:00
{
2015-07-21 00:33:36 +02:00
uint32 deficit = unit -> GetMaxHealth () - unit -> GetHealth ();
if (( deficit > maxHPDeficit || foundItr == tempTargets . end ()) && target -> IsWithinDist ( unit , jumpRadius ) && target -> IsWithinLOSInMap ( unit ))
2012-02-21 20:03:27 +01:00
{
foundItr = itr ;
maxHPDeficit = deficit ;
}
2010-02-20 23:59:05 +01:00
}
}
}
2012-02-21 20:03:27 +01:00
// get closest object
else
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
for ( std :: list < WorldObject *>:: iterator itr = tempTargets . begin (); itr != tempTargets . end (); ++ itr )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( foundItr == tempTargets . end ())
2011-08-01 12:05:30 +02:00
{
2012-02-21 20:03:27 +01:00
if (( ! isBouncingFar || target -> IsWithinDist ( * itr , jumpRadius )) && target -> IsWithinLOSInMap ( * itr ))
foundItr = itr ;
2011-08-01 12:05:30 +02:00
}
2012-02-21 20:03:27 +01:00
else if ( target -> GetDistanceOrder ( * itr , * foundItr ) && target -> IsWithinLOSInMap ( * itr ))
foundItr = itr ;
}
}
// not found any valid target - chain ends
if ( foundItr == tempTargets . end ())
break ;
target = * foundItr ;
tempTargets . erase ( foundItr );
targets . push_back ( target );
-- chainTargets ;
}
}
2011-05-21 21:36:37 +02:00
2013-08-14 15:45:36 +02:00
GameObject * Spell :: SearchSpellFocus ()
{
GameObject * focus = NULL ;
Trinity :: GameObjectFocusCheck check ( m_caster , m_spellInfo -> RequiresSpellFocus );
Trinity :: GameObjectSearcher < Trinity :: GameObjectFocusCheck > searcher ( m_caster , focus , check );
SearchTargets < Trinity :: GameObjectSearcher < Trinity :: GameObjectFocusCheck > > ( searcher , GRID_MAP_TYPE_MASK_GAMEOBJECT , m_caster , m_caster , m_caster -> GetVisibilityRange ());
return focus ;
}
2012-02-21 20:03:27 +01:00
void Spell :: prepareDataForTriggerSystem ( AuraEffect const * /*triggeredByAura*/ )
{
//==========================================================================================
// Now fill data for trigger system, need know:
// can spell trigger another or not (m_canTrigger)
// Create base triggers flags for Attacker and Victim (m_procAttacker, m_procVictim and m_procEx)
//==========================================================================================
2010-07-16 14:23:03 +02:00
2012-02-21 20:03:27 +01:00
m_procVictim = m_procAttacker = 0 ;
// Get data for type of attack and fill base info for trigger
switch ( m_spellInfo -> DmgClass )
{
case SPELL_DAMAGE_CLASS_MELEE :
m_procAttacker = PROC_FLAG_DONE_SPELL_MELEE_DMG_CLASS ;
if ( m_attackType == OFF_ATTACK )
m_procAttacker |= PROC_FLAG_DONE_OFFHAND_ATTACK ;
else
m_procAttacker |= PROC_FLAG_DONE_MAINHAND_ATTACK ;
m_procVictim = PROC_FLAG_TAKEN_SPELL_MELEE_DMG_CLASS ;
break ;
case SPELL_DAMAGE_CLASS_RANGED :
// Auto attack
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR2_AUTOREPEAT_FLAG ))
2012-02-21 20:03:27 +01:00
{
m_procAttacker = PROC_FLAG_DONE_RANGED_AUTO_ATTACK ;
m_procVictim = PROC_FLAG_TAKEN_RANGED_AUTO_ATTACK ;
}
else // Ranged spell attack
{
m_procAttacker = PROC_FLAG_DONE_SPELL_RANGED_DMG_CLASS ;
m_procVictim = PROC_FLAG_TAKEN_SPELL_RANGED_DMG_CLASS ;
}
break ;
default :
if ( m_spellInfo -> EquippedItemClass == ITEM_CLASS_WEAPON &&
m_spellInfo -> EquippedItemSubClassMask & ( 1 << ITEM_SUBCLASS_WEAPON_WAND )
2015-01-05 23:49:43 +02:00
&& m_spellInfo -> HasAttribute ( SPELL_ATTR2_AUTOREPEAT_FLAG )) // Wands auto attack
2012-02-21 20:03:27 +01:00
{
m_procAttacker = PROC_FLAG_DONE_RANGED_AUTO_ATTACK ;
m_procVictim = PROC_FLAG_TAKEN_RANGED_AUTO_ATTACK ;
}
// For other spells trigger procflags are set in Spell::DoAllEffectOnTarget
// Because spell positivity is dependant on target
}
m_procEx = PROC_EX_NONE ;
2010-07-16 14:23:03 +02:00
2012-02-21 20:03:27 +01:00
// Hunter trap spells - activation proc for Lock and Load, Entrapment and Misdirection
if ( m_spellInfo -> SpellFamilyName == SPELLFAMILY_HUNTER &&
( m_spellInfo -> SpellFamilyFlags [ 0 ] & 0x18 || // Freezing and Frost Trap, Freezing Arrow
m_spellInfo -> Id == 57879 || // Snake Trap - done this way to avoid double proc
m_spellInfo -> SpellFamilyFlags [ 2 ] & 0x00024000 )) // Explosive and Immolation Trap
2013-07-20 14:54:50 +02:00
{
2012-02-21 20:03:27 +01:00
m_procAttacker |= PROC_FLAG_DONE_TRAP_ACTIVATION ;
2013-07-20 14:54:50 +02:00
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
/* Effects which are result of aura proc from triggered spell cannot proc
to prevent chain proc of these spells */
2010-08-01 01:22:13 +02:00
2012-02-21 20:03:27 +01:00
// Hellfire Effect - trigger as DOT
if ( m_spellInfo -> SpellFamilyName == SPELLFAMILY_WARLOCK && m_spellInfo -> SpellFamilyFlags [ 0 ] & 0x00000040 )
{
m_procAttacker = PROC_FLAG_DONE_PERIODIC ;
m_procVictim = PROC_FLAG_TAKEN_PERIODIC ;
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
// Ranged autorepeat attack is set as triggered spell - ignore it
if ( ! ( m_procAttacker & PROC_FLAG_DONE_RANGED_AUTO_ATTACK ))
{
if ( _triggeredCastFlags & TRIGGERED_DISALLOW_PROC_EVENTS &&
2015-01-05 23:49:43 +02:00
( m_spellInfo -> HasAttribute ( SPELL_ATTR2_TRIGGERED_CAN_TRIGGER_PROC ) ||
m_spellInfo -> HasAttribute ( SPELL_ATTR3_TRIGGERED_CAN_TRIGGER_PROC_2 )))
2012-02-21 20:03:27 +01:00
m_procEx |= PROC_EX_INTERNAL_CANT_PROC ;
else if ( _triggeredCastFlags & TRIGGERED_DISALLOW_PROC_EVENTS )
m_procEx |= PROC_EX_INTERNAL_TRIGGERED ;
}
// Totem casts require spellfamilymask defined in spell_proc_event to proc
2015-08-12 14:05:14 +02:00
if ( m_originalCaster && m_caster != m_originalCaster && m_caster -> GetTypeId () == TYPEID_UNIT && m_caster -> IsTotem () && m_caster -> IsControlledByPlayer ())
2012-02-21 20:03:27 +01:00
m_procEx |= PROC_EX_INTERNAL_REQ_FAMILY ;
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
void Spell :: CleanupTargetList ()
{
m_UniqueTargetInfo . clear ();
m_UniqueGOTargetInfo . clear ();
m_UniqueItemInfo . clear ();
m_delayMoment = 0 ;
2010-02-20 23:59:05 +01:00
}
2014-08-04 18:56:17 +02:00
void Spell :: AddUnitTarget ( Unit * target , uint32 effectMask , bool checkIfValid /*= true*/ , bool implicit /*= true*/ , Position const * losPosition /*= nullptr*/ )
2010-02-20 23:59:05 +01:00
{
2014-12-29 01:00:16 +01:00
uint32 validEffectMask = 0 ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-12-29 04:00:29 +01:00
if ( effect && ( effectMask & ( 1 << effect -> EffectIndex )) != 0 && CheckEffectTarget ( target , effect , losPosition ))
2014-12-29 01:00:16 +01:00
validEffectMask |= 1 << effect -> EffectIndex ;
effectMask &= validEffectMask ;
2010-03-26 22:21:33 +01:00
2012-02-21 20:03:27 +01:00
// no effects left
if ( ! effectMask )
return ;
2010-03-26 22:21:33 +01:00
2012-02-21 20:03:27 +01:00
if ( checkIfValid )
2012-05-30 08:01:02 +02:00
if ( m_spellInfo -> CheckTarget ( m_caster , target , implicit ) != SPELL_CAST_OK )
2012-02-21 20:03:27 +01:00
return ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Check for effect immune skip if immuned
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && target -> IsImmunedToSpellEffect ( m_spellInfo , effect -> EffectIndex ))
2014-11-16 14:20:01 +01:00
effectMask &= ~ ( 1 << effect -> EffectIndex );
2012-02-21 20:03:27 +01:00
2014-09-14 16:14:12 +02:00
ObjectGuid targetGUID = target -> GetGUID ();
2012-02-21 20:03:27 +01:00
// Lookup target in already in list
2015-02-12 22:08:17 +00:00
for ( std :: vector < TargetInfo >:: iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( targetGUID == ihit -> targetGUID ) // Found in list
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
ihit -> effectMask |= effectMask ; // Immune effects removed from mask
ihit -> scaleAura = false ;
if ( m_auraScaleMask && ihit -> effectMask == m_auraScaleMask && m_caster != target )
2010-02-20 23:59:05 +01:00
{
2013-07-21 13:37:34 +02:00
SpellInfo const * auraSpell = m_spellInfo -> GetFirstRankSpell ();
2012-02-21 20:03:27 +01:00
if ( uint32 ( target -> getLevel () + 10 ) >= auraSpell -> SpellLevel )
ihit -> scaleAura = true ;
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
return ;
2010-02-20 23:59:05 +01:00
}
}
2010-03-26 22:21:33 +01:00
2012-02-21 20:03:27 +01:00
// This is new target calculate data for him
2010-03-26 22:21:33 +01:00
2012-02-21 20:03:27 +01:00
// Get spell hit result on target
TargetInfo targetInfo ;
targetInfo . targetGUID = targetGUID ; // Store target GUID
targetInfo . effectMask = effectMask ; // Store all effects not immune
targetInfo . processed = false ; // Effects not apply on target
2013-06-11 19:54:27 -02:30
targetInfo . alive = target -> IsAlive ();
2012-02-21 20:03:27 +01:00
targetInfo . damage = 0 ;
targetInfo . crit = false ;
targetInfo . scaleAura = false ;
if ( m_auraScaleMask && targetInfo . effectMask == m_auraScaleMask && m_caster != target )
{
2013-07-21 13:37:34 +02:00
SpellInfo const * auraSpell = m_spellInfo -> GetFirstRankSpell ();
2012-02-21 20:03:27 +01:00
if ( uint32 ( target -> getLevel () + 10 ) >= auraSpell -> SpellLevel )
targetInfo . scaleAura = true ;
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
// Calculate hit result
if ( m_originalCaster )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
targetInfo . missCondition = m_originalCaster -> SpellHitResult ( target , m_spellInfo , m_canReflect );
if ( m_skipCheck && targetInfo . missCondition != SPELL_MISS_IMMUNE )
targetInfo . missCondition = SPELL_MISS_NONE ;
}
else
targetInfo . missCondition = SPELL_MISS_EVADE ; //SPELL_MISS_NONE;
2011-06-26 00:29:12 +02:00
2012-02-21 20:03:27 +01:00
// Spell have speed - need calculate incoming time
// Incoming time is zero for self casts. At least I think so.
if ( m_spellInfo -> Speed > 0.0f && m_caster != target )
{
// calculate spell incoming interval
2013-03-08 21:41:30 +01:00
/// @todo this is a hack
2012-02-21 20:03:27 +01:00
float dist = m_caster -> GetDistance ( target -> GetPositionX (), target -> GetPositionY (), target -> GetPositionZ ());
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( dist < 5.0f )
dist = 5.0f ;
2012-12-28 22:18:19 +01:00
2015-01-05 23:49:43 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR9_SPECIAL_DELAY_CALCULATION ))
2014-08-24 02:11:33 +02:00
targetInfo . timeDelay = uint64 ( std :: floor ( dist / m_spellInfo -> Speed * 1000.0f ));
2012-12-28 22:18:19 +01:00
else
targetInfo . timeDelay = uint64 ( m_spellInfo -> Speed * 1000.0f );
2010-08-19 14:31:31 +02:00
2012-02-21 20:03:27 +01:00
// Calculate minimum incoming time
if ( m_delayMoment == 0 || m_delayMoment > targetInfo . timeDelay )
m_delayMoment = targetInfo . timeDelay ;
}
else
targetInfo . timeDelay = 0LL ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// If target reflect spell back to caster
if ( targetInfo . missCondition == SPELL_MISS_REFLECT )
{
// Calculate reflected spell result on caster
2012-05-30 08:01:02 +02:00
targetInfo . reflectResult = m_caster -> SpellHitResult ( m_caster , m_spellInfo , m_canReflect );
2010-08-21 20:18:54 +02:00
2012-02-21 20:03:27 +01:00
if ( targetInfo . reflectResult == SPELL_MISS_REFLECT ) // Impossible reflect again, so simply deflect spell
targetInfo . reflectResult = SPELL_MISS_PARRY ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Increase time interval for reflected spells by 1.5
targetInfo . timeDelay += targetInfo . timeDelay >> 1 ;
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
else
targetInfo . reflectResult = SPELL_MISS_NONE ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Add target to list
m_UniqueTargetInfo . push_back ( targetInfo );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
void Spell :: AddGOTarget ( GameObject * go , uint32 effectMask )
2010-02-20 23:59:05 +01:00
{
2014-12-29 01:00:16 +01:00
uint32 validEffectMask = 0 ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-12-29 04:00:29 +01:00
if ( effect && ( effectMask & ( 1 << effect -> EffectIndex )) != 0 && CheckEffectTarget ( go , effect ))
2014-12-29 01:00:16 +01:00
validEffectMask |= 1 << effect -> EffectIndex ;
2014-11-27 15:11:43 +01:00
2014-12-29 01:00:16 +01:00
effectMask &= validEffectMask ;
2010-02-20 23:59:05 +01:00
2014-12-29 01:00:16 +01:00
// no effects left
2010-04-07 19:14:10 +02:00
if ( ! effectMask )
2010-02-20 23:59:05 +01:00
return ;
2014-09-14 16:14:12 +02:00
ObjectGuid targetGUID = go -> GetGUID ();
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Lookup target in already in list
2015-02-12 22:08:17 +00:00
for ( std :: vector < GOTargetInfo >:: iterator ihit = m_UniqueGOTargetInfo . begin (); ihit != m_UniqueGOTargetInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( targetGUID == ihit -> targetGUID ) // Found in list
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
ihit -> effectMask |= effectMask ; // Add only effect mask
return ;
2010-02-20 23:59:05 +01:00
}
}
2010-08-19 14:31:31 +02:00
2012-02-21 20:03:27 +01:00
// This is new target calculate data for him
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
GOTargetInfo target ;
target . targetGUID = targetGUID ;
target . effectMask = effectMask ;
target . processed = false ; // Effects not apply on target
2010-08-21 20:18:54 +02:00
2012-02-21 20:03:27 +01:00
// Spell have speed - need calculate incoming time
if ( m_spellInfo -> Speed > 0.0f )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// calculate spell incoming interval
float dist = m_caster -> GetDistance ( go -> GetPositionX (), go -> GetPositionY (), go -> GetPositionZ ());
if ( dist < 5.0f )
dist = 5.0f ;
2012-12-28 22:18:19 +01:00
2015-01-05 23:49:43 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR9_SPECIAL_DELAY_CALCULATION ))
2012-12-28 22:18:19 +01:00
target . timeDelay = uint64 ( floor ( dist / m_spellInfo -> Speed * 1000.0f ));
else
target . timeDelay = uint64 ( m_spellInfo -> Speed * 1000.0f );
2012-02-21 20:03:27 +01:00
if ( m_delayMoment == 0 || m_delayMoment > target . timeDelay )
m_delayMoment = target . timeDelay ;
2010-02-20 23:59:05 +01:00
}
else
2012-02-21 20:03:27 +01:00
target . timeDelay = 0LL ;
2011-01-15 19:40:06 +01:00
2012-02-21 20:03:27 +01:00
// Add target to list
m_UniqueGOTargetInfo . push_back ( target );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
void Spell :: AddItemTarget ( Item * item , uint32 effectMask )
2010-02-20 23:59:05 +01:00
{
2014-12-29 01:00:16 +01:00
uint32 validEffectMask = 0 ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-12-29 04:00:29 +01:00
if ( effect && ( effectMask & ( 1 << effect -> EffectIndex )) != 0 && CheckEffectTarget ( item , effect ))
2014-12-29 01:00:16 +01:00
validEffectMask |= 1 << effect -> EffectIndex ;
effectMask &= validEffectMask ;
2012-02-21 20:03:27 +01:00
// no effects left
if ( ! effectMask )
2010-02-20 23:59:05 +01:00
return ;
2012-02-21 20:03:27 +01:00
// Lookup target in already in list
2015-02-12 22:08:17 +00:00
for ( std :: vector < ItemTargetInfo >:: iterator ihit = m_UniqueItemInfo . begin (); ihit != m_UniqueItemInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( item == ihit -> item ) // Found in list
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
ihit -> effectMask |= effectMask ; // Add only effect mask
return ;
2010-02-20 23:59:05 +01:00
}
}
2010-08-19 14:31:31 +02:00
2012-02-21 20:03:27 +01:00
// This is new target add data
2010-08-21 20:18:54 +02:00
2012-02-21 20:03:27 +01:00
ItemTargetInfo target ;
target . item = item ;
target . effectMask = effectMask ;
2010-08-21 20:18:54 +02:00
2012-02-21 20:03:27 +01:00
m_UniqueItemInfo . push_back ( target );
2010-02-20 23:59:05 +01:00
}
2012-05-30 08:01:02 +02:00
void Spell :: AddDestTarget ( SpellDestination const & dest , uint32 effIndex )
{
m_destTargets [ effIndex ] = dest ;
}
2012-02-21 20:03:27 +01:00
void Spell :: DoAllEffectOnTarget ( TargetInfo * target )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( ! target || target -> processed )
2010-07-30 01:51:33 +02:00
return ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
target -> processed = true ; // Target checked in apply effects procedure
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Get mask of effects for target
2015-05-10 00:07:48 +02:00
uint32 mask = target -> effectMask ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
Unit * unit = m_caster -> GetGUID () == target -> targetGUID ? m_caster : ObjectAccessor :: GetUnit ( * m_caster , target -> targetGUID );
2015-02-25 00:13:14 +01:00
if ( ! unit && target -> targetGUID . IsPlayer ()) // only players may be targeted across maps
2010-02-20 23:59:05 +01:00
{
2017-01-06 17:20:04 +01:00
uint32 farMask = 0 ;
2012-02-21 20:03:27 +01:00
// create far target mask
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && effect -> IsFarUnitTargetEffect ())
if (( 1 << effect -> EffectIndex ) & mask )
farMask |= ( 1 << effect -> EffectIndex );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( ! farMask )
return ;
2015-02-25 00:13:14 +01:00
2012-02-21 20:03:27 +01:00
// find unit in world
2015-02-25 00:13:14 +01:00
unit = ObjectAccessor :: FindPlayer ( target -> targetGUID );
2012-02-21 20:03:27 +01:00
if ( ! unit )
return ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// do far effects on the unit
// can't use default call because of threading, do stuff as fast as possible
2015-02-25 00:13:14 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && ( farMask & ( 1 << effect -> EffectIndex )))
2014-11-16 14:20:01 +01:00
HandleEffects ( unit , NULL , NULL , effect -> EffectIndex , SPELL_EFFECT_HANDLE_HIT_TARGET );
2012-02-21 20:03:27 +01:00
return ;
2010-02-20 23:59:05 +01:00
}
2015-06-01 03:03:05 +01:00
if ( ! unit )
return ;
2013-06-11 19:54:27 -02:30
if ( unit -> IsAlive () != target -> alive )
2012-02-21 20:03:27 +01:00
return ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( getState () == SPELL_STATE_DELAYED && ! m_spellInfo -> IsPositive () && ( getMSTime () - target -> timeDelay ) <= unit -> m_lastSanctuaryTime )
return ; // No missinfo in that case
2010-08-30 17:32:51 +02:00
2012-02-21 20:03:27 +01:00
// Get original caster (if exist) and calculate damage/healing from him data
Unit * caster = m_originalCaster ? m_originalCaster : m_caster ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Skip if m_originalCaster not avaiable
if ( ! caster )
return ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
SpellMissInfo missInfo = target -> missCondition ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Need init unitTarget by default unit (can changed in code on reflect)
// Or on missInfo != SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem)
unitTarget = unit ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Reset damage/healing counter
m_damage = target -> damage ;
m_healing = - target -> damage ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Fill base trigger info
uint32 procAttacker = m_procAttacker ;
uint32 procVictim = m_procVictim ;
uint32 procEx = m_procEx ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
m_spellAura = NULL ; // Set aura to null for every target-make sure that pointer is not used for unit without aura applied
2010-02-20 23:59:05 +01:00
2013-12-25 14:16:55 -03:30
//Spells with this flag cannot trigger if effect is cast on self
2015-01-05 23:49:43 +02:00
bool canEffectTrigger = ! m_spellInfo -> HasAttribute ( SPELL_ATTR3_CANT_TRIGGER_PROC ) && unitTarget -> CanProc () && ( CanExecuteTriggersOnHit ( mask ) || missInfo == SPELL_MISS_IMMUNE || missInfo == SPELL_MISS_IMMUNE2 );
2012-02-21 20:03:27 +01:00
Unit * spellHitTarget = NULL ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( missInfo == SPELL_MISS_NONE ) // In case spell hit target, do all effect on that target
spellHitTarget = unit ;
else if ( missInfo == SPELL_MISS_REFLECT ) // In case spell reflect from target, do all effect on caster (if hit)
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( target -> reflectResult == SPELL_MISS_NONE ) // If reflected spell hit caster -> do all effect on him
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
spellHitTarget = m_caster ;
if ( m_caster -> GetTypeId () == TYPEID_UNIT )
m_caster -> ToCreature () -> LowerPlayerDamageReq ( target -> damage );
2010-02-20 23:59:05 +01:00
}
}
2016-07-20 09:08:58 +02:00
PrepareScriptHitHandlers ();
CallScriptBeforeHitHandlers ( missInfo );
2016-05-18 02:06:24 -07:00
bool enablePvP = false ; // need to check PvP state before spell effects, but act on it afterwards
2012-02-21 20:03:27 +01:00
if ( spellHitTarget )
2010-02-20 23:59:05 +01:00
{
2016-05-18 02:06:24 -07:00
// if target is flagged for pvp also flag caster if a player
if ( unit -> IsPvP () && m_caster -> GetTypeId () == TYPEID_PLAYER )
enablePvP = true ; // Decide on PvP flagging now, but act on it later.
2016-06-14 20:06:00 +01:00
2012-02-21 20:03:27 +01:00
SpellMissInfo missInfo2 = DoSpellHitOnUnit ( spellHitTarget , mask , target -> scaleAura );
2016-07-20 09:08:58 +02:00
2012-02-21 20:03:27 +01:00
if ( missInfo2 != SPELL_MISS_NONE )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( missInfo2 != SPELL_MISS_MISS )
m_caster -> SendSpellMiss ( unit , m_spellInfo -> Id , missInfo2 );
m_damage = 0 ;
spellHitTarget = NULL ;
2010-02-20 23:59:05 +01:00
}
}
2012-02-21 20:03:27 +01:00
// Do not take combo points on dodge and miss
if ( missInfo != SPELL_MISS_NONE && m_needComboPoints &&
m_targets . GetUnitTargetGUID () == target -> targetGUID )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
m_needComboPoints = false ;
// Restore spell mods for a miss/dodge/parry Cold Blood
2013-03-08 21:41:30 +01:00
/// @todo check how broad this rule should be
2012-02-21 20:03:27 +01:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER && ( missInfo == SPELL_MISS_MISS ||
missInfo == SPELL_MISS_DODGE || missInfo == SPELL_MISS_PARRY ))
m_caster -> ToPlayer () -> RestoreSpellMods ( this , 14177 );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
// Trigger info was not filled in spell::preparedatafortriggersystem - we do it now
if ( canEffectTrigger && ! procAttacker && ! procVictim )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
bool positive = true ;
if ( m_damage > 0 )
positive = false ;
else if ( ! m_healing )
2014-07-03 22:32:41 +02:00
positive = m_spellInfo -> IsPositive ();
2012-02-21 20:03:27 +01:00
switch ( m_spellInfo -> DmgClass )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
case SPELL_DAMAGE_CLASS_MAGIC :
if ( positive )
{
procAttacker |= PROC_FLAG_DONE_SPELL_MAGIC_DMG_CLASS_POS ;
procVictim |= PROC_FLAG_TAKEN_SPELL_MAGIC_DMG_CLASS_POS ;
}
else
{
procAttacker |= PROC_FLAG_DONE_SPELL_MAGIC_DMG_CLASS_NEG ;
procVictim |= PROC_FLAG_TAKEN_SPELL_MAGIC_DMG_CLASS_NEG ;
}
2010-02-20 23:59:05 +01:00
break ;
2012-02-21 20:03:27 +01:00
case SPELL_DAMAGE_CLASS_NONE :
if ( positive )
{
procAttacker |= PROC_FLAG_DONE_SPELL_NONE_DMG_CLASS_POS ;
procVictim |= PROC_FLAG_TAKEN_SPELL_NONE_DMG_CLASS_POS ;
}
else
{
procAttacker |= PROC_FLAG_DONE_SPELL_NONE_DMG_CLASS_NEG ;
procVictim |= PROC_FLAG_TAKEN_SPELL_NONE_DMG_CLASS_NEG ;
}
2010-02-20 23:59:05 +01:00
break ;
}
}
2012-02-21 20:03:27 +01:00
CallScriptOnHitHandlers ();
2010-08-08 19:45:53 +02:00
2012-02-21 20:03:27 +01:00
// All calculated do it!
// Do healing and triggers
if ( m_healing > 0 )
2010-02-20 23:59:05 +01:00
{
2016-01-09 16:51:39 +01:00
bool crit = target -> crit ;
2012-02-21 20:03:27 +01:00
uint32 addhealth = m_healing ;
if ( crit )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
procEx |= PROC_EX_CRITICAL_HIT ;
addhealth = caster -> SpellCriticalHealingBonus ( m_spellInfo , addhealth , NULL );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
else
procEx |= PROC_EX_NORMAL_HIT ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
int32 gain = caster -> HealBySpell ( unitTarget , m_spellInfo , addhealth , crit );
unitTarget -> getHostileRefManager (). threatAssist ( caster , float ( gain ) * 0.5f , m_spellInfo );
m_healing = gain ;
2012-05-30 08:01:02 +02:00
// Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
if ( canEffectTrigger && missInfo != SPELL_MISS_REFLECT )
caster -> ProcDamageAndSpell ( unitTarget , procAttacker , procVictim , procEx , addhealth , m_attackType , m_spellInfo , m_triggeredByAuraSpell );
2010-07-30 01:51:33 +02:00
}
2012-02-21 20:03:27 +01:00
// Do damage and triggers
else if ( m_damage > 0 )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// Fill base damage struct (unitTarget - is real spell target)
2016-06-16 20:50:27 +02:00
SpellNonMeleeDamage damageInfo ( caster , unitTarget , m_spellInfo -> Id , m_spellSchoolMask , m_castId );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Add bonuses and fill damageInfo struct
2016-01-09 16:51:39 +01:00
caster -> CalculateSpellDamageTaken ( & damageInfo , m_damage , m_spellInfo , m_attackType , target -> crit );
2012-02-21 20:03:27 +01:00
caster -> DealDamageMods ( damageInfo . target , damageInfo . damage , & damageInfo . absorb );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
procEx |= createProcExtendMask ( & damageInfo , missInfo );
procVictim |= PROC_FLAG_TAKEN_DAMAGE ;
2011-01-21 23:42:51 +01:00
2012-02-21 20:03:27 +01:00
// Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
if ( canEffectTrigger && missInfo != SPELL_MISS_REFLECT )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
caster -> ProcDamageAndSpell ( unitTarget , procAttacker , procVictim , procEx , damageInfo . damage , m_attackType , m_spellInfo , m_triggeredByAuraSpell );
2015-01-05 23:49:43 +02:00
if ( caster -> GetTypeId () == TYPEID_PLAYER && ( m_spellInfo -> HasAttribute ( SPELL_ATTR0_STOP_ATTACK_TARGET )) == 0 &&
2012-02-21 20:03:27 +01:00
( m_spellInfo -> DmgClass == SPELL_DAMAGE_CLASS_MELEE || m_spellInfo -> DmgClass == SPELL_DAMAGE_CLASS_RANGED ))
caster -> ToPlayer () -> CastItemCombatSpell ( unitTarget , m_attackType , procVictim , procEx );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
m_damage = damageInfo . damage ;
2012-05-30 08:01:02 +02:00
2015-08-10 17:46:31 +02:00
caster -> DealSpellDamage ( & damageInfo , true );
2015-08-08 15:15:14 +02:00
// Send log damage message to client
caster -> SendSpellNonMeleeDamageLog ( & damageInfo );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
// Passive spell hits/misses or active spells only misses (only triggers)
else
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// Fill base damage struct (unitTarget - is real spell target)
SpellNonMeleeDamage damageInfo ( caster , unitTarget , m_spellInfo -> Id , m_spellSchoolMask );
procEx |= createProcExtendMask ( & damageInfo , missInfo );
// Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
if ( canEffectTrigger && missInfo != SPELL_MISS_REFLECT )
caster -> ProcDamageAndSpell ( unit , procAttacker , procVictim , procEx , 0 , m_attackType , m_spellInfo , m_triggeredByAuraSpell );
// Failed Pickpocket, reveal rogue
2015-01-05 23:49:43 +02:00
if ( missInfo == SPELL_MISS_RESIST && m_spellInfo -> HasAttribute ( SPELL_ATTR0_CU_PICKPOCKET ) && unitTarget -> GetTypeId () == TYPEID_UNIT )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
m_caster -> RemoveAurasWithInterruptFlags ( AURA_INTERRUPT_FLAG_TALK );
if ( unitTarget -> ToCreature () -> IsAIEnabled )
unitTarget -> ToCreature () -> AI () -> AttackStart ( m_caster );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2014-11-16 14:20:01 +01:00
if ( missInfo != SPELL_MISS_EVADE && ! m_caster -> IsFriendlyTo ( unit ) && ( ! m_spellInfo -> IsPositive () || HasEffect ( SPELL_EFFECT_DISPEL )))
2012-02-21 20:03:27 +01:00
{
2016-02-10 22:35:23 +01:00
m_caster -> CombatStart ( unit , m_spellInfo -> HasInitialAggro ());
2010-02-20 23:59:05 +01:00
2015-11-22 15:37:32 +01:00
if ( ! unit -> IsStandState ())
unit -> SetStandState ( UNIT_STAND_STATE_STAND );
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2016-06-14 20:06:00 +01:00
// Check for SPELL_ATTR7_INTERRUPT_ONLY_NONPLAYER
2016-09-12 12:41:02 -03:00
if ( missInfo == SPELL_MISS_NONE && m_spellInfo -> HasAttribute ( SPELL_ATTR7_INTERRUPT_ONLY_NONPLAYER ) && unit -> GetTypeId () != TYPEID_PLAYER )
2016-06-14 20:06:00 +01:00
caster -> CastSpell ( unit , SPELL_INTERRUPT_NONPLAYER , true );
2012-02-21 20:03:27 +01:00
if ( spellHitTarget )
{
//AI functions
if ( spellHitTarget -> GetTypeId () == TYPEID_UNIT )
if ( spellHitTarget -> ToCreature () -> IsAIEnabled )
spellHitTarget -> ToCreature () -> AI () -> SpellHit ( m_caster , m_spellInfo );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( m_caster -> GetTypeId () == TYPEID_UNIT && m_caster -> ToCreature () -> IsAIEnabled )
m_caster -> ToCreature () -> AI () -> SpellHitTarget ( spellHitTarget , m_spellInfo );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// Needs to be called after dealing damage/healing to not remove breaking on damage auras
DoTriggersOnSpellHit ( spellHitTarget , mask );
2010-02-20 23:59:05 +01:00
2016-05-18 02:06:24 -07:00
if ( enablePvP )
2012-02-21 20:03:27 +01:00
m_caster -> ToPlayer () -> UpdatePvP ( true );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
CallScriptAfterHitHandlers ();
}
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
SpellMissInfo Spell :: DoSpellHitOnUnit ( Unit * unit , uint32 effectMask , bool scaleAura )
{
if ( ! unit || ! effectMask )
return SPELL_MISS_EVADE ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
// For delayed spells immunity may be applied between missile launch and hit - check immunity for that case
2012-06-13 12:34:59 -04:00
if ( m_spellInfo -> Speed && ( unit -> IsImmunedToDamage ( m_spellInfo ) || unit -> IsImmunedToSpell ( m_spellInfo )))
return SPELL_MISS_IMMUNE ;
2012-02-21 20:03:27 +01:00
// disable effects to which unit is immune
2012-06-13 12:34:59 -04:00
SpellMissInfo returnVal = SPELL_MISS_IMMUNE ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && ( effectMask & ( 1 << effect -> EffectIndex )))
2014-11-16 14:20:01 +01:00
if ( unit -> IsImmunedToSpellEffect ( m_spellInfo , effect -> EffectIndex ))
effectMask &= ~ ( 1 << effect -> EffectIndex );
2012-07-30 10:07:26 +02:00
2012-06-13 12:34:59 -04:00
if ( ! effectMask )
return returnVal ;
2010-02-20 23:59:05 +01:00
2012-09-18 14:29:53 +02:00
if ( Player * player = unit -> ToPlayer ())
2012-02-21 20:03:27 +01:00
{
2016-05-07 01:16:29 +02:00
player -> StartCriteriaTimer ( CRITERIA_TIMED_TYPE_SPELL_TARGET , m_spellInfo -> Id );
player -> UpdateCriteria ( CRITERIA_TYPE_BE_SPELL_TARGET , m_spellInfo -> Id , 0 , 0 , m_caster );
player -> UpdateCriteria ( CRITERIA_TYPE_BE_SPELL_TARGET2 , m_spellInfo -> Id );
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2012-09-18 14:29:53 +02:00
if ( Player * player = m_caster -> ToPlayer ())
2012-02-21 20:03:27 +01:00
{
2016-05-07 01:16:29 +02:00
player -> StartCriteriaTimer ( CRITERIA_TIMED_TYPE_SPELL_CASTER , m_spellInfo -> Id );
player -> UpdateCriteria ( CRITERIA_TYPE_CAST_SPELL2 , m_spellInfo -> Id , 0 , 0 , unit );
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( m_caster != unit )
{
// Recheck UNIT_FLAG_NON_ATTACKABLE for delayed spells
if ( m_spellInfo -> Speed > 0.0f && unit -> HasFlag ( UNIT_FIELD_FLAGS , UNIT_FLAG_NON_ATTACKABLE ) && unit -> GetCharmerOrOwnerGUID () != m_caster -> GetGUID ())
return SPELL_MISS_EVADE ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( m_caster -> _IsValidAttackTarget ( unit , m_spellInfo ))
{
unit -> RemoveAurasWithInterruptFlags ( AURA_INTERRUPT_FLAG_HITBYSPELL );
2015-11-22 15:37:32 +01:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR0_CU_DONT_BREAK_STEALTH ))
2012-02-21 20:03:27 +01:00
unit -> RemoveAurasByType ( SPELL_AURA_MOD_STEALTH );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
else if ( m_caster -> IsFriendlyTo ( unit ))
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// for delayed spells ignore negative spells (after duel end) for friendly targets
2013-03-08 21:41:30 +01:00
/// @todo this cause soul transfer bugged
2013-03-03 22:19:57 +01:00
// 63881 - Malady of the Mind jump spell (Yogg-Saron)
if ( m_spellInfo -> Speed > 0.0f && unit -> GetTypeId () == TYPEID_PLAYER && ! m_spellInfo -> IsPositive () && m_spellInfo -> Id != 63881 )
2012-02-21 20:03:27 +01:00
return SPELL_MISS_EVADE ;
// assisting case, healing and resurrection
if ( unit -> HasUnitState ( UNIT_STATE_ATTACK_PLAYER ))
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
m_caster -> SetContestedPvP ();
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
m_caster -> ToPlayer () -> UpdatePvP ( true );
2010-02-20 23:59:05 +01:00
}
2016-02-10 22:35:23 +01:00
if ( unit -> IsInCombat () && m_spellInfo -> HasInitialAggro ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
m_caster -> SetInCombatState ( unit -> GetCombatTimer () > 0 , unit );
unit -> getHostileRefManager (). threatAssist ( m_caster , 0.0f );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
}
}
2010-02-20 23:59:05 +01:00
2017-01-06 17:20:04 +01:00
uint32 aura_effmask = 0 ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && ( effectMask & ( 1 << effect -> EffectIndex ) && effect -> IsUnitOwnedAuraEffect ()))
2014-11-16 14:20:01 +01:00
aura_effmask |= 1 << effect -> EffectIndex ;
2014-07-03 00:42:55 +01:00
2012-02-21 20:03:27 +01:00
// Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
2015-01-17 15:04:31 -06:00
m_diminishGroup = GetDiminishingReturnsGroupForSpell ( m_spellInfo );
2014-07-03 00:42:55 +01:00
if ( m_diminishGroup && aura_effmask )
2012-02-21 20:03:27 +01:00
{
m_diminishLevel = unit -> GetDiminishing ( m_diminishGroup );
DiminishingReturnsType type = GetDiminishingReturnsGroupType ( m_diminishGroup );
// Increase Diminishing on unit, current informations for actually casts will use values above
2013-10-20 12:47:54 +02:00
if (( type == DRTYPE_PLAYER &&
( unit -> GetCharmerOrOwnerPlayerOrPlayerItself () || ( unit -> GetTypeId () == TYPEID_UNIT && unit -> ToCreature () -> GetCreatureTemplate () -> flags_extra & CREATURE_FLAG_EXTRA_ALL_DIMINISH ))) ||
type == DRTYPE_ALL )
2012-02-21 20:03:27 +01:00
unit -> IncrDiminishing ( m_diminishGroup );
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
if ( aura_effmask )
{
// Select rank for aura with level requirements only in specific cases
// Unit has to be target only of aura effect, both caster and target have to be players, target has to be other than unit target
SpellInfo const * aurSpellInfo = m_spellInfo ;
2014-11-16 14:20:01 +01:00
int32 basePoints [ MAX_SPELL_EFFECTS ];
2012-02-21 20:03:27 +01:00
if ( scaleAura )
{
aurSpellInfo = m_spellInfo -> GetAuraRankForLevel ( unitTarget -> getLevel ());
ASSERT ( aurSpellInfo );
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : aurSpellInfo -> GetEffectsForDifficulty ( 0 ))
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
basePoints [ effect -> EffectIndex ] = effect -> BasePoints ;
if ( SpellEffectInfo const * myEffect = GetEffect ( effect -> EffectIndex ))
2012-02-21 20:03:27 +01:00
{
2014-11-16 14:20:01 +01:00
if ( myEffect -> Effect != effect -> Effect )
{
aurSpellInfo = m_spellInfo ;
break ;
}
2010-02-20 23:59:05 +01:00
}
}
}
2012-02-21 20:03:27 +01:00
if ( m_originalCaster )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
bool refresh = false ;
2016-06-05 14:08:53 +02:00
m_spellAura = Aura :: TryRefreshStackOrCreate ( aurSpellInfo , m_castId , effectMask , unit ,
2015-11-24 00:16:42 +01:00
m_originalCaster , ( aurSpellInfo == m_spellInfo ) ? m_spellValue -> EffectBasePoints : basePoints ,
m_CastItem , ObjectGuid :: Empty , & refresh , m_castItemLevel );
2012-02-21 20:03:27 +01:00
if ( m_spellAura )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// Set aura stack amount to desired value
if ( m_spellValue -> AuraStackAmount > 1 )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
if ( ! refresh )
m_spellAura -> SetStackAmount ( m_spellValue -> AuraStackAmount );
else
m_spellAura -> ModStackAmount ( m_spellValue -> AuraStackAmount );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
// Now Reduce spell duration using data received at spell hit
int32 duration = m_spellAura -> GetMaxDuration ();
2015-01-17 15:04:31 -06:00
int32 limitduration = m_diminishGroup ? GetDiminishingReturnsLimitDuration ( aurSpellInfo ) : 0 ;
2012-02-21 20:03:27 +01:00
float diminishMod = unit -> ApplyDiminishingToDuration ( m_diminishGroup , duration , m_originalCaster , m_diminishLevel , limitduration );
// unit is immune to aura if it was diminished to 0 duration
if ( diminishMod == 0.0f )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
m_spellAura -> Remove ();
bool found = false ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && ( effectMask & ( 1 << effect -> EffectIndex ) && effect -> Effect != SPELL_EFFECT_APPLY_AURA ))
2012-02-21 20:03:27 +01:00
found = true ;
if ( ! found )
return SPELL_MISS_IMMUNE ;
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
else
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
(( UnitAura * ) m_spellAura ) -> SetDiminishGroup ( m_diminishGroup );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
bool positive = m_spellAura -> GetSpellInfo () -> IsPositive ();
if ( AuraApplication * aurApp = m_spellAura -> GetApplicationOfTarget ( m_originalCaster -> GetGUID ()))
positive = aurApp -> IsPositive ();
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
duration = m_originalCaster -> ModSpellDuration ( aurSpellInfo , unit , duration , positive , effectMask );
2010-02-20 23:59:05 +01:00
2012-08-18 21:02:39 +02:00
if ( duration > 0 )
2010-02-20 23:59:05 +01:00
{
2012-08-18 21:02:39 +02:00
// Haste modifies duration of channeled spells
if ( m_spellInfo -> IsChanneled ())
2015-10-25 10:10:57 +01:00
m_originalCaster -> ModSpellDurationTime ( aurSpellInfo , duration , this );
2015-01-05 23:49:43 +02:00
else if ( m_spellInfo -> HasAttribute ( SPELL_ATTR5_HASTE_AFFECT_DURATION ))
2012-08-18 21:02:39 +02:00
{
int32 origDuration = duration ;
duration = 0 ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect )
if ( AuraEffect const * eff = m_spellAura -> GetEffect ( effect -> EffectIndex ))
if ( int32 period = eff -> GetPeriod ()) // period is hastened by UNIT_MOD_CAST_SPEED
duration = std :: max ( std :: max ( origDuration / period , 1 ) * period , duration );
2012-08-18 21:02:39 +02:00
// if there is no periodic effect
if ( ! duration )
duration = int32 ( origDuration * m_originalCaster -> GetFloatValue ( UNIT_MOD_CAST_SPEED ));
}
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
if ( duration != m_spellAura -> GetMaxDuration ())
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
m_spellAura -> SetMaxDuration ( duration );
m_spellAura -> SetDuration ( duration );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
m_spellAura -> _RegisterForTargets ();
2010-02-20 23:59:05 +01:00
}
}
}
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && ( effectMask & ( 1 << effect -> EffectIndex )))
2014-11-16 14:20:01 +01:00
HandleEffects ( unit , NULL , NULL , effect -> EffectIndex , SPELL_EFFECT_HANDLE_HIT_TARGET );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
return SPELL_MISS_NONE ;
}
2017-01-06 17:20:04 +01:00
void Spell :: DoTriggersOnSpellHit ( Unit * unit , uint32 effMask )
2012-02-21 20:03:27 +01:00
{
// Apply additional spell effects to target
2013-03-08 21:41:30 +01:00
/// @todo move this code to scripts
2012-02-21 20:03:27 +01:00
if ( m_preCastSpell )
{
// Paladin immunity shields
if ( m_preCastSpell == 61988 )
2010-02-20 23:59:05 +01:00
{
2012-02-21 20:03:27 +01:00
// Cast Forbearance
m_caster -> CastSpell ( unit , 25771 , true );
// Cast Avenging Wrath Marker
unit -> CastSpell ( unit , 61987 , true );
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
// Avenging Wrath
if ( m_preCastSpell == 61987 )
// Cast the serverside immunity shield marker
m_caster -> CastSpell ( unit , 61988 , true );
2010-06-18 04:17:21 +02:00
2012-02-21 20:03:27 +01:00
if ( sSpellMgr -> GetSpellInfo ( m_preCastSpell ))
// Blizz seems to just apply aura without bothering to cast
m_caster -> AddAura ( m_preCastSpell , unit );
}
2010-06-18 04:17:21 +02:00
2012-02-21 20:03:27 +01:00
// handle SPELL_AURA_ADD_TARGET_TRIGGER auras
// this is executed after spell proc spells on target hit
// spells are triggered for each hit spell target
// info confirmed with retail sniffs of permafrost and shadow weaving
if ( ! m_hitTriggerSpells . empty ())
{
int _duration = 0 ;
2012-05-30 08:01:02 +02:00
for ( HitTriggerSpellList :: const_iterator i = m_hitTriggerSpells . begin (); i != m_hitTriggerSpells . end (); ++ i )
2010-02-20 23:59:05 +01:00
{
2012-05-30 08:01:02 +02:00
if ( CanExecuteTriggersOnHit ( effMask , i -> triggeredByAura ) && roll_chance_i ( i -> chance ))
2010-02-20 23:59:05 +01:00
{
2013-10-20 00:40:20 +02:00
m_caster -> CastSpell ( unit , i -> triggeredSpell , TriggerCastFlags ( TRIGGERED_FULL_MASK & ~ TRIGGERED_IGNORE_TARGET_CHECK ));
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "Spell %d triggered spell %d by SPELL_AURA_ADD_TARGET_TRIGGER aura" , m_spellInfo -> Id , i -> triggeredSpell -> Id );
2011-05-22 16:01:53 -07:00
2012-02-21 20:03:27 +01:00
// SPELL_AURA_ADD_TARGET_TRIGGER auras shouldn't trigger auras without duration
// set duration of current aura to the triggered spell
2012-05-30 08:01:02 +02:00
if ( i -> triggeredSpell -> GetDuration () == - 1 )
2012-02-21 20:03:27 +01:00
{
2012-05-30 08:01:02 +02:00
if ( Aura * triggeredAur = unit -> GetAura ( i -> triggeredSpell -> Id , m_caster -> GetGUID ()))
2010-06-18 04:17:21 +02:00
{
2012-02-21 20:03:27 +01:00
// get duration from aura-only once
if ( ! _duration )
{
Aura * aur = unit -> GetAura ( m_spellInfo -> Id , m_caster -> GetGUID ());
_duration = aur ? aur -> GetDuration () : - 1 ;
}
triggeredAur -> SetDuration ( _duration );
2010-06-18 04:17:21 +02:00
}
}
2010-02-20 23:59:05 +01:00
}
}
}
2012-02-21 20:03:27 +01:00
// trigger linked auras remove/apply
2013-03-08 21:41:30 +01:00
/// @todo remove/cleanup this, as this table is not documented and people are doing stupid things with it
2012-02-21 20:03:27 +01:00
if ( std :: vector < int32 > const * spellTriggered = sSpellMgr -> GetSpellLinked ( m_spellInfo -> Id + SPELL_LINK_HIT ))
2012-11-16 09:51:44 +01:00
{
2012-02-21 20:03:27 +01:00
for ( std :: vector < int32 >:: const_iterator i = spellTriggered -> begin (); i != spellTriggered -> end (); ++ i )
2012-11-16 09:51:44 +01:00
{
2012-02-21 20:03:27 +01:00
if ( * i < 0 )
unit -> RemoveAurasDueToSpell ( - ( * i ));
else
2014-08-09 21:32:26 +01:00
unit -> CastSpell ( unit , * i , true , nullptr , nullptr , m_caster -> GetGUID ());
2012-11-16 09:51:44 +01:00
}
}
2012-02-21 20:03:27 +01:00
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
void Spell :: DoAllEffectOnTarget ( GOTargetInfo * target )
{
if ( target -> processed ) // Check target
return ;
target -> processed = true ; // Target checked in apply effects procedure
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
uint32 effectMask = target -> effectMask ;
if ( ! effectMask )
return ;
2010-12-04 10:31:14 +01:00
2012-02-21 20:03:27 +01:00
GameObject * go = m_caster -> GetMap () -> GetGameObject ( target -> targetGUID );
if ( ! go )
return ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
PrepareScriptHitHandlers ();
2016-07-20 09:08:58 +02:00
CallScriptBeforeHitHandlers ( SPELL_MISS_NONE );
2010-02-20 23:59:05 +01:00
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && ( effectMask & ( 1 << effect -> EffectIndex )))
2014-11-16 14:20:01 +01:00
HandleEffects ( NULL , NULL , go , effect -> EffectIndex , SPELL_EFFECT_HANDLE_HIT_TARGET );
2011-01-21 23:42:51 +01:00
2012-02-21 20:03:27 +01:00
CallScriptOnHitHandlers ();
CallScriptAfterHitHandlers ();
}
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
void Spell :: DoAllEffectOnTarget ( ItemTargetInfo * target )
{
uint32 effectMask = target -> effectMask ;
if ( ! target -> item || ! effectMask )
return ;
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
PrepareScriptHitHandlers ();
2016-07-20 09:08:58 +02:00
CallScriptBeforeHitHandlers ( SPELL_MISS_NONE );
2010-02-20 23:59:05 +01:00
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && ( effectMask & ( 1 << effect -> EffectIndex )))
2014-11-16 14:20:01 +01:00
HandleEffects ( NULL , target -> item , NULL , effect -> EffectIndex , SPELL_EFFECT_HANDLE_HIT_TARGET );
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
CallScriptOnHitHandlers ();
2010-02-20 23:59:05 +01:00
2012-02-21 20:03:27 +01:00
CallScriptAfterHitHandlers ();
}
2010-06-18 04:17:21 +02:00
2012-02-21 20:03:27 +01:00
bool Spell :: UpdateChanneledTargetList ()
{
// Not need check return true
if ( m_channelTargetEffectMask == 0 )
return true ;
2010-06-18 04:17:21 +02:00
2015-05-10 00:07:48 +02:00
uint32 channelTargetEffectMask = m_channelTargetEffectMask ;
uint32 channelAuraMask = 0 ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && effect -> Effect == SPELL_EFFECT_APPLY_AURA )
2014-11-16 14:20:01 +01:00
channelAuraMask |= 1 << effect -> EffectIndex ;
2012-02-21 20:03:27 +01:00
channelAuraMask &= channelTargetEffectMask ;
float range = 0 ;
if ( channelAuraMask )
{
range = m_spellInfo -> GetMaxRange ( m_spellInfo -> IsPositive ());
if ( Player * modOwner = m_caster -> GetSpellModOwner ())
modOwner -> ApplySpellMod ( m_spellInfo -> Id , SPELLMOD_RANGE , range , this );
}
2015-06-01 00:26:49 +01:00
for ( std :: vector < TargetInfo >:: iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2012-02-21 20:03:27 +01:00
{
if ( ihit -> missCondition == SPELL_MISS_NONE && ( channelTargetEffectMask & ihit -> effectMask ))
{
Unit * unit = m_caster -> GetGUID () == ihit -> targetGUID ? m_caster : ObjectAccessor :: GetUnit ( * m_caster , ihit -> targetGUID );
if ( ! unit )
continue ;
2010-06-18 04:17:21 +02:00
2012-02-21 20:03:27 +01:00
if ( IsValidDeadOrAliveTarget ( unit ))
2010-06-18 04:17:21 +02:00
{
2012-02-21 20:03:27 +01:00
if ( channelAuraMask & ihit -> effectMask )
2010-06-18 04:17:21 +02:00
{
2012-02-21 20:03:27 +01:00
if ( AuraApplication * aurApp = unit -> GetAuraApplication ( m_spellInfo -> Id , m_originalCasterGUID ))
2010-06-18 04:17:21 +02:00
{
2012-02-21 20:03:27 +01:00
if ( m_caster != unit && ! m_caster -> IsWithinDistInMap ( unit , range ))
{
ihit -> effectMask &= ~ aurApp -> GetEffectMask ();
unit -> RemoveAura ( aurApp );
continue ;
}
2010-06-18 04:17:21 +02:00
}
2012-02-21 20:03:27 +01:00
else // aura is dispelled
continue ;
2010-06-18 04:17:21 +02:00
}
2010-08-08 19:45:53 +02:00
2012-02-21 20:03:27 +01:00
channelTargetEffectMask &= ~ ihit -> effectMask ; // remove from need alive mask effect that have alive target
2010-02-20 23:59:05 +01:00
}
2012-02-21 20:03:27 +01:00
}
}
2011-01-21 23:42:51 +01:00
2012-02-21 20:03:27 +01:00
// is all effects from m_needAliveTargetMask have alive targets
return channelTargetEffectMask == 0 ;
}
2011-01-21 23:42:51 +01:00
2011-06-11 22:35:29 +02:00
void Spell :: prepare ( SpellCastTargets const * targets , AuraEffect const * triggeredByAura )
2010-02-20 23:59:05 +01:00
{
if ( m_CastItem )
2014-05-05 20:05:33 +02:00
{
2010-02-20 23:59:05 +01:00
m_castItemGUID = m_CastItem -> GetGUID ();
2014-05-05 20:05:33 +02:00
m_castItemEntry = m_CastItem -> GetEntry ();
2016-02-21 16:26:24 +01:00
if ( Player * owner = m_CastItem -> GetOwner ())
m_castItemLevel = int32 ( m_CastItem -> GetItemLevel ( owner ));
else if ( m_CastItem -> GetOwnerGUID () == m_caster -> GetGUID ())
m_castItemLevel = int32 ( m_CastItem -> GetItemLevel ( m_caster -> ToPlayer ()));
else
{
SendCastResult ( SPELL_FAILED_EQUIPPED_ITEM );
finish ( false );
return ;
}
2014-05-05 20:05:33 +02:00
}
2010-02-20 23:59:05 +01:00
2011-08-24 08:07:59 +02:00
InitExplicitTargets ( * targets );
2010-02-20 23:59:05 +01:00
// Fill aura scaling information
2011-07-31 19:03:06 +02:00
if ( m_caster -> IsControlledByPlayer () && ! m_spellInfo -> IsPassive () && m_spellInfo -> SpellLevel && ! m_spellInfo -> IsChanneled () && ! ( _triggeredCastFlags & TRIGGERED_IGNORE_AURA_SCALING ))
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2014-11-27 15:11:43 +01:00
if ( effect && effect -> Effect == SPELL_EFFECT_APPLY_AURA )
2010-02-20 23:59:05 +01:00
{
// Change aura with ranks only if basepoints are taken from spellInfo and aura is positive
2014-11-16 14:20:01 +01:00
if ( m_spellInfo -> IsPositiveEffect ( effect -> EffectIndex ))
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
m_auraScaleMask |= ( 1 << effect -> EffectIndex );
if ( m_spellValue -> EffectBasePoints [ effect -> EffectIndex ] != effect -> BasePoints )
2010-02-20 23:59:05 +01:00
{
m_auraScaleMask = 0 ;
break ;
}
}
}
}
}
m_spellState = SPELL_STATE_PREPARING ;
2010-04-07 19:14:10 +02:00
if ( triggeredByAura )
2015-11-24 00:16:42 +01:00
{
m_triggeredByAuraSpell = triggeredByAura -> GetSpellInfo ();
m_castItemLevel = triggeredByAura -> GetBase () -> GetCastItemLevel ();
}
2010-02-20 23:59:05 +01:00
// create and add update event for this spell
SpellEvent * Event = new SpellEvent ( this );
m_caster -> m_Events . AddEvent ( Event , m_caster -> m_Events . CalculateTime ( 1 ));
//Prevent casting at cast another spell (ServerSide check)
2016-06-05 14:08:53 +02:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_CAST_IN_PROGRESS ) && m_caster -> IsNonMeleeSpellCast ( false , true , true ) && ! m_castId . IsEmpty ())
2010-02-20 23:59:05 +01:00
{
SendCastResult ( SPELL_FAILED_SPELL_IN_PROGRESS );
finish ( false );
return ;
}
2010-07-21 12:14:23 +02:00
2011-09-09 14:27:23 +02:00
if ( DisableMgr :: IsDisabledFor ( DISABLE_TYPE_SPELL , m_spellInfo -> Id , m_caster ))
2010-02-20 23:59:05 +01:00
{
2010-07-21 12:14:23 +02:00
SendCastResult ( SPELL_FAILED_SPELL_UNAVAILABLE );
finish ( false );
return ;
2010-02-20 23:59:05 +01:00
}
2010-07-24 22:41:42 +02:00
LoadScripts ();
2010-02-20 23:59:05 +01:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> SetSpellModTakingSpell ( this , true );
2016-03-26 18:41:03 +01:00
// Fill cost data (do not use power for item casts)
2015-03-08 13:31:57 +01:00
if ( ! m_CastItem )
m_powerCost = m_spellInfo -> CalcPowerCost ( m_caster , m_spellSchoolMask );
2010-02-20 23:59:05 +01:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> SetSpellModTakingSpell ( this , false );
2010-02-20 23:59:05 +01:00
2010-09-14 13:28:25 +03:00
// Set combo point requirement
2016-08-20 12:43:04 +02:00
if (( _triggeredCastFlags & TRIGGERED_IGNORE_COMBO_POINTS ) || m_CastItem || ! m_caster -> m_playerMovingMe )
2010-09-14 13:28:25 +03:00
m_needComboPoints = false ;
2010-02-20 23:59:05 +01:00
SpellCastResult result = CheckCast ( true );
2013-04-16 02:18:43 +03:00
// target is checked in too many locations and with different results to handle each of them
// handle just the general SPELL_FAILED_BAD_TARGETS result which is the default result for most DBC target checks
if ( _triggeredCastFlags & TRIGGERED_IGNORE_TARGET_CHECK && result == SPELL_FAILED_BAD_TARGETS )
result = SPELL_CAST_OK ;
2010-04-07 19:14:10 +02:00
if ( result != SPELL_CAST_OK && ! IsAutoRepeat ()) //always cast autorepeat dummy for triggering
2010-02-20 23:59:05 +01:00
{
2011-08-26 14:23:23 +02:00
// Periodic auras should be interrupted when aura triggers a spell which can't be cast
// for example bladestorm aura should be removed on disarm as of patch 3.3.5
// channeled periodic spells should be affected by this (arcane missiles, penance, etc)
// a possible alternative sollution for those would be validating aura target on unit state change
2011-08-26 15:40:11 +02:00
if ( triggeredByAura && triggeredByAura -> IsPeriodic () && ! triggeredByAura -> GetBase () -> IsPassive ())
2010-02-20 23:59:05 +01:00
{
SendChannelUpdate ( 0 );
triggeredByAura -> GetBase () -> SetDuration ( 0 );
}
2011-08-12 13:22:53 +02:00
2015-07-15 18:21:43 +02:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
{
m_caster -> ToPlayer () -> RestoreSpellMods ( this );
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
m_caster -> ToPlayer () -> SetSpellModTakingSpell ( this , false );
}
2010-02-20 23:59:05 +01:00
SendCastResult ( result );
finish ( false );
return ;
}
// Prepare data for triggers
prepareDataForTriggerSystem ( triggeredByAura );
2013-08-15 16:37:18 +02:00
if ( Player * player = m_caster -> ToPlayer ())
2012-08-31 01:26:21 +01:00
{
2013-08-18 13:54:20 +02:00
if ( ! player -> GetCommandStatus ( CHEAT_CASTTIME ))
2013-08-15 16:37:18 +02:00
{
2013-08-18 13:54:20 +02:00
player -> SetSpellModTakingSpell ( this , true );
2013-08-15 16:37:18 +02:00
// calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
2013-08-18 18:13:14 +02:00
m_casttime = m_spellInfo -> CalcCastTime ( player -> getLevel (), this );
2013-08-18 13:54:20 +02:00
player -> SetSpellModTakingSpell ( this , false );
2013-08-15 16:37:18 +02:00
}
else
m_casttime = 0 ; // Set cast time to 0 if .cheat casttime is enabled.
2012-08-31 01:26:21 +01:00
}
2013-08-15 16:37:18 +02:00
else
2013-08-15 19:04:09 +02:00
m_casttime = m_spellInfo -> CalcCastTime ( m_caster -> getLevel (), this );
2010-02-20 23:59:05 +01:00
2016-01-13 18:38:54 +01:00
if ( m_caster -> GetTypeId () == TYPEID_UNIT && ! m_caster -> HasFlag ( UNIT_FIELD_FLAGS , UNIT_FLAG_PLAYER_CONTROLLED )) // _UNIT actually means creature. for some reason.
if ( ! ( IsNextMeleeSwingSpell () || IsAutoRepeat () || _triggeredCastFlags & TRIGGERED_IGNORE_SET_FACING ))
{
if ( m_targets . GetObjectTarget () && m_caster != m_targets . GetObjectTarget ())
2016-08-21 11:07:38 +02:00
m_caster -> ToCreature () -> FocusTarget ( this , m_targets . GetObjectTarget ());
2016-01-13 18:38:54 +01:00
else if ( m_spellInfo -> HasAttribute ( SPELL_ATTR5_DONT_TURN_DURING_CAST ))
2016-08-21 11:07:38 +02:00
m_caster -> ToCreature () -> FocusTarget ( this , nullptr );
2016-01-13 18:38:54 +01:00
}
2013-12-25 14:16:55 -03:30
// don't allow channeled spells / spells with cast time to be cast while moving
2016-04-25 11:46:35 -03:00
// exception are only channeled spells that have no casttime and SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING
2010-09-10 15:51:31 +03:00
// (even if they are interrupted on moving, spells with almost immediate effect get to have their effect processed before movement interrupter kicks in)
2012-09-10 18:20:26 -05:00
// don't cancel spells which are affected by a SPELL_AURA_CAST_WHILE_WALKING effect
2016-07-20 15:23:14 +02:00
if ((( m_spellInfo -> IsChanneled () || m_casttime ) && m_caster -> GetTypeId () == TYPEID_PLAYER && ! ( m_caster -> IsCharmed () && m_caster -> GetCharmerGUID (). IsCreature ()) && m_caster -> isMoving () &&
2012-09-11 01:31:55 +01:00
m_spellInfo -> InterruptFlags & SPELL_INTERRUPT_FLAG_MOVEMENT ) && ! m_caster -> HasAuraTypeWithAffectMask ( SPELL_AURA_CAST_WHILE_WALKING , m_spellInfo ))
2010-09-10 15:51:31 +03:00
{
2016-04-25 11:46:35 -03:00
// 1. Is a channel spell, 2. Has no casttime, 3. And has flag to allow movement during channel
if ( ! ( m_spellInfo -> IsChanneled () && ! m_casttime && m_spellInfo -> HasAttribute ( SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING )))
{
SendCastResult ( SPELL_FAILED_MOVING );
finish ( false );
return ;
}
2010-09-10 15:51:31 +03:00
}
2010-02-20 23:59:05 +01:00
// set timer base at cast time
ReSetTimer ();
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "Spell::prepare: spell id %u source %u caster %d customCastFlags %u mask %u" , m_spellInfo -> Id , m_caster -> GetEntry (), m_originalCaster ? m_originalCaster -> GetEntry () : - 1 , _triggeredCastFlags , m_targets . GetTargetMask ());
2010-02-20 23:59:05 +01:00
//Containers for channeled spells have to be set
2013-12-25 14:16:55 -03:30
/// @todoApply this to all cast spells if needed
2010-02-20 23:59:05 +01:00
// Why check duration? 29350: channelled triggers channelled
2011-07-31 19:03:06 +02:00
if (( _triggeredCastFlags & TRIGGERED_CAST_DIRECTLY ) && ( ! m_spellInfo -> IsChanneled () || ! m_spellInfo -> GetMaxDuration ()))
2010-02-20 23:59:05 +01:00
cast ( true );
else
{
// stealth must be removed at cast starting (at show channel bar)
// skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
2011-07-31 19:03:06 +02:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_AURA_INTERRUPT_FLAGS ) && m_spellInfo -> IsBreakingStealth ())
2010-02-20 23:59:05 +01:00
{
m_caster -> RemoveAurasWithInterruptFlags ( AURA_INTERRUPT_FLAG_CAST );
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && effect -> GetUsedTargetObjectType () == TARGET_OBJECT_TYPE_UNIT )
2010-02-20 23:59:05 +01:00
{
m_caster -> RemoveAurasWithInterruptFlags ( AURA_INTERRUPT_FLAG_SPELL_ATTACK );
break ;
}
}
2013-12-25 14:16:55 -03:30
m_caster -> SetCurrentCastSpell ( this );
2016-08-21 11:07:38 +02:00
SendSpellStart ();
2011-07-15 12:33:03 +02:00
2011-07-31 19:03:06 +02:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_GCD ))
TriggerGlobalCooldown ();
2011-02-22 17:02:47 +06:00
2011-05-30 19:48:22 +02:00
//item: first cast may destroy item and second cast causes crash
2016-08-21 11:07:38 +02:00
if ( ! m_casttime && ! m_spellInfo -> StartRecoveryTime && ! m_castItemGUID && GetCurrentContainer () == CURRENT_GENERIC_SPELL )
2010-02-20 23:59:05 +01:00
cast ( true );
}
}
void Spell :: cancel ()
{
2010-04-07 19:14:10 +02:00
if ( m_spellState == SPELL_STATE_FINISHED )
2010-02-20 23:59:05 +01:00
return ;
uint32 oldState = m_spellState ;
m_spellState = SPELL_STATE_FINISHED ;
m_autoRepeat = false ;
switch ( oldState )
{
case SPELL_STATE_PREPARING :
2011-02-22 17:02:47 +06:00
CancelGlobalCooldown ();
2011-05-17 13:33:24 +02:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
m_caster -> ToPlayer () -> RestoreSpellMods ( this );
2013-08-01 21:31:11 +02:00
// no break
2010-02-20 23:59:05 +01:00
case SPELL_STATE_DELAYED :
SendInterrupted ( 0 );
SendCastResult ( SPELL_FAILED_INTERRUPTED );
2010-04-11 11:19:22 +02:00
break ;
2010-02-20 23:59:05 +01:00
case SPELL_STATE_CASTING :
2015-02-12 22:08:17 +00:00
for ( std :: vector < TargetInfo >:: const_iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
if (( * ihit ). missCondition == SPELL_MISS_NONE )
if ( Unit * unit = m_caster -> GetGUID () == ihit -> targetGUID ? m_caster : ObjectAccessor :: GetUnit ( * m_caster , ihit -> targetGUID ))
unit -> RemoveOwnedAura ( m_spellInfo -> Id , m_originalCasterGUID , 0 , AURA_REMOVE_BY_CANCEL );
SendChannelUpdate ( 0 );
SendInterrupted ( 0 );
SendCastResult ( SPELL_FAILED_INTERRUPTED );
// spell is canceled-take mods and clear list
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> RemoveSpellMods ( this );
2010-02-20 23:59:05 +01:00
m_appliedMods . clear ();
2010-04-11 11:19:22 +02:00
break ;
2010-02-20 23:59:05 +01:00
default :
2010-04-11 11:19:22 +02:00
break ;
2010-02-20 23:59:05 +01:00
}
2011-04-11 16:35:31 +06:00
SetReferencedFromCurrent ( false );
if ( m_selfContainer && * m_selfContainer == this )
* m_selfContainer = NULL ;
2010-02-20 23:59:05 +01:00
m_caster -> RemoveDynObject ( m_spellInfo -> Id );
2012-05-30 08:01:02 +02:00
if ( m_spellInfo -> IsChanneled ()) // if not channeled then the object for the current cast wasn't summoned yet
m_caster -> RemoveGameObject ( m_spellInfo -> Id , true );
2010-02-20 23:59:05 +01:00
//set state back so finish will be processed
m_spellState = oldState ;
finish ( false );
}
void Spell :: cast ( bool skipCheck )
{
// update pointers base at GUIDs to prevent access to non-existed already object
2014-05-03 21:22:12 +02:00
if ( ! UpdatePointers ())
{
// cancel the spell if UpdatePointers() returned false, something wrong happened there
cancel ();
return ;
}
2010-02-20 23:59:05 +01:00
2011-09-11 22:40:48 +02:00
// cancel at lost explicit target during cast
2014-10-21 19:23:32 +02:00
if ( ! m_targets . GetObjectTargetGUID (). IsEmpty () && ! m_targets . GetObjectTarget ())
2010-02-20 23:59:05 +01:00
{
2011-09-11 22:40:48 +02:00
cancel ();
return ;
2010-02-20 23:59:05 +01:00
}
2011-06-12 01:47:45 +02:00
if ( Player * playerCaster = m_caster -> ToPlayer ())
2012-05-30 08:01:02 +02:00
{
// now that we've done the basic check, now run the scripts
// should be done before the spell is actually executed
2010-12-22 21:25:23 +01:00
sScriptMgr -> OnPlayerSpellCast ( playerCaster , this , skipCheck );
2010-09-03 19:58:16 -07:00
2012-05-30 08:01:02 +02:00
// As of 3.0.2 pets begin attacking their owner's target immediately
// Let any pets know we've attacked something. Check DmgClass for harmful spells only
// This prevents spells such as Hunter's Mark from triggering pet attack
if ( this -> GetSpellInfo () -> DmgClass != SPELL_DAMAGE_CLASS_NONE )
if ( Pet * playerPet = playerCaster -> GetPet ())
2013-06-11 19:54:27 -02:30
if ( playerPet -> IsAlive () && playerPet -> isControlled () && ( m_targets . GetTargetMask () & TARGET_FLAG_UNIT ))
2014-02-06 22:11:06 +01:00
playerPet -> AI () -> OwnerAttacked ( m_targets . GetUnitTarget ());
2012-05-30 08:01:02 +02:00
}
2013-03-03 23:15:54 +01:00
2010-02-20 23:59:05 +01:00
SetExecutedCurrently ( true );
2013-03-03 23:15:54 +01:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_SET_FACING ))
if ( m_caster -> GetTypeId () == TYPEID_UNIT && m_targets . GetObjectTarget () && m_caster != m_targets . GetObjectTarget ())
m_caster -> SetInFront ( m_targets . GetObjectTarget ());
2010-02-20 23:59:05 +01:00
// Should this be done for original caster?
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
{
// Set spell which will drop charges for triggered cast spells
2013-12-25 14:16:55 -03:30
// if not successfully cast, will be remove in finish(false)
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> SetSpellModTakingSpell ( this , true );
2010-02-20 23:59:05 +01:00
}
2011-12-31 13:10:13 +01:00
CallScriptBeforeCastHandlers ();
2011-09-11 22:24:53 +02:00
// skip check if done already (for instant cast spells for example)
if ( ! skipCheck )
2010-02-20 23:59:05 +01:00
{
SpellCastResult castResult = CheckCast ( false );
2010-04-07 19:14:10 +02:00
if ( castResult != SPELL_CAST_OK )
2010-02-20 23:59:05 +01:00
{
SendCastResult ( castResult );
SendInterrupted ( 0 );
//restore spell mods
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
{
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> RestoreSpellMods ( this );
2010-02-20 23:59:05 +01:00
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> SetSpellModTakingSpell ( this , false );
2010-02-20 23:59:05 +01:00
}
finish ( false );
SetExecutedCurrently ( false );
return ;
}
2010-06-25 13:15:51 +02:00
// additional check after cast bar completes (must not be in CheckCast)
// if trade not complete then remember it in trade data
2011-06-23 13:28:52 +02:00
if ( m_targets . GetTargetMask () & TARGET_FLAG_TRADE_ITEM )
2010-06-25 13:15:51 +02:00
{
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
{
if ( TradeData * my_trade = m_caster -> ToPlayer () -> GetTradeData ())
{
if ( ! my_trade -> IsInAcceptProcess ())
{
2013-12-25 14:16:55 -03:30
// Spell will be cast after completing the trade. Silently ignore at this place
2010-06-25 13:15:51 +02:00
my_trade -> SetSpell ( m_spellInfo -> Id , m_CastItem );
SendCastResult ( SPELL_FAILED_DONT_REPORT );
SendInterrupted ( 0 );
m_caster -> ToPlayer () -> RestoreSpellMods ( this );
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
m_caster -> ToPlayer () -> SetSpellModTakingSpell ( this , false );
finish ( false );
SetExecutedCurrently ( false );
return ;
}
}
}
}
2010-02-20 23:59:05 +01:00
}
2016-01-13 18:38:54 +01:00
// if the spell allows the creature to turn while casting, then adjust server-side orientation to face the target now
// client-side orientation is handled by the client itself, as the cast target is targeted due to Creature::FocusTarget
if ( m_caster -> GetTypeId () == TYPEID_UNIT && ! m_caster -> HasFlag ( UNIT_FIELD_FLAGS , UNIT_FLAG_PLAYER_CONTROLLED ))
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR5_DONT_TURN_DURING_CAST ))
if ( WorldObject * objTarget = m_targets . GetObjectTarget ())
m_caster -> SetInFront ( objTarget );
2010-02-20 23:59:05 +01:00
SelectSpellTargets ();
// Spell may be finished after target map check
2010-04-07 19:14:10 +02:00
if ( m_spellState == SPELL_STATE_FINISHED )
2010-02-20 23:59:05 +01:00
{
SendInterrupted ( 0 );
//restore spell mods
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
{
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> RestoreSpellMods ( this );
2010-02-20 23:59:05 +01:00
// cleanup after mod system
// triggered spell pointer can be not removed in some cases
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> SetSpellModTakingSpell ( this , false );
2010-02-20 23:59:05 +01:00
}
finish ( false );
SetExecutedCurrently ( false );
return ;
}
2016-05-26 16:04:16 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR1_DISMISS_PET ))
if ( Creature * pet = ObjectAccessor :: GetCreature ( * m_caster , m_caster -> GetPetGUID ()))
pet -> DespawnOrUnsummon ();
2011-06-26 00:29:12 +02:00
PrepareTriggersExecutedOnHit ();
2010-09-03 20:30:29 -07:00
2011-12-31 13:10:13 +01:00
CallScriptOnCastHandlers ();
2010-02-20 23:59:05 +01:00
// traded items have trade slot instead of guid in m_itemTargetGUID
// set to real guid to be sent later to the client
2011-06-23 13:28:52 +02:00
m_targets . UpdateTradeSlotItem ();
2010-02-20 23:59:05 +01:00
2012-09-18 14:29:53 +02:00
if ( Player * player = m_caster -> ToPlayer ())
2010-02-20 23:59:05 +01:00
{
2011-07-31 19:03:06 +02:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_CAST_ITEM ) && m_CastItem )
2010-04-27 22:22:13 +02:00
{
2016-05-07 01:16:29 +02:00
player -> StartCriteriaTimer ( CRITERIA_TIMED_TYPE_ITEM , m_CastItem -> GetEntry ());
player -> UpdateCriteria ( CRITERIA_TYPE_USE_ITEM , m_CastItem -> GetEntry ());
2010-04-27 22:22:13 +02:00
}
2010-02-20 23:59:05 +01:00
2016-05-07 01:16:29 +02:00
player -> UpdateCriteria ( CRITERIA_TYPE_CAST_SPELL , m_spellInfo -> Id );
2010-02-20 23:59:05 +01:00
}
2011-07-31 19:03:06 +02:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_POWER_AND_REAGENT_COST ))
2010-02-20 23:59:05 +01:00
{
// Powers have to be taken before SendSpellGo
TakePower ();
TakeReagents (); // we must remove reagents before HandleEffects to allow place crafted item in same slot
}
2011-06-23 13:28:52 +02:00
else if ( Item * targetItem = m_targets . GetItemTarget ())
2010-06-25 13:15:51 +02:00
{
/// Not own traded item (in trader trade slot) req. reagents including triggered spell case
if ( targetItem -> GetOwnerGUID () != m_caster -> GetGUID ())
TakeReagents ();
}
2010-02-20 23:59:05 +01:00
// CAST SPELL
SendSpellCooldown ();
2010-08-21 20:18:54 +02:00
PrepareScriptHitHandlers ();
2010-08-19 14:31:31 +02:00
2011-09-25 13:29:17 +02:00
HandleLaunchPhase ();
2010-02-20 23:59:05 +01:00
// we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2010-04-07 18:09:10 +02:00
SendSpellGo ();
2010-02-20 23:59:05 +01:00
// Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2015-01-05 23:49:43 +02:00
if (( m_spellInfo -> Speed > 0.0f && ! m_spellInfo -> IsChanneled ()) || m_spellInfo -> HasAttribute ( SPELL_ATTR4_UNK4 ))
2010-02-20 23:59:05 +01:00
{
// Remove used for cast item if need (it can be already NULL after TakeReagents call
// in case delayed spell remove item at cast delay start
TakeCastItem ();
// Okay, maps created, now prepare flags
m_immediateHandled = false ;
m_spellState = SPELL_STATE_DELAYED ;
SetDelayStart ( 0 );
2013-12-25 14:16:55 -03:30
if ( m_caster -> HasUnitState ( UNIT_STATE_CASTING ) && ! m_caster -> IsNonMeleeSpellCast ( false , false , true ))
2012-02-03 19:12:41 +02:00
m_caster -> ClearUnitState ( UNIT_STATE_CASTING );
2010-02-20 23:59:05 +01:00
}
else
{
// Immediate spell, no big deal
handle_immediate ();
}
2011-12-31 13:10:13 +01:00
CallScriptAfterCastHandlers ();
2011-07-26 23:09:28 +02:00
if ( const std :: vector < int32 > * spell_triggered = sSpellMgr -> GetSpellLinked ( m_spellInfo -> Id ))
2010-02-20 23:59:05 +01:00
{
2011-07-26 23:09:28 +02:00
for ( std :: vector < int32 >:: const_iterator i = spell_triggered -> begin (); i != spell_triggered -> end (); ++ i )
if ( * i < 0 )
m_caster -> RemoveAurasDueToSpell ( - ( * i ));
else
m_caster -> CastSpell ( m_targets . GetUnitTarget () ? m_targets . GetUnitTarget () : m_caster , * i , true );
2010-09-05 13:39:10 +02:00
}
2010-02-20 23:59:05 +01:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2012-08-31 01:26:21 +01:00
{
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> SetSpellModTakingSpell ( this , false );
2012-09-04 16:14:15 +01:00
2012-08-31 01:26:21 +01:00
//Clear spell cooldowns after every spell is cast if .cheat cooldown is enabled.
if ( m_caster -> ToPlayer () -> GetCommandStatus ( CHEAT_COOLDOWN ))
2015-12-03 00:08:44 +01:00
{
2015-02-17 01:01:44 +01:00
m_caster -> GetSpellHistory () -> ResetCooldown ( m_spellInfo -> Id , true );
2016-01-24 15:56:10 +01:00
m_caster -> GetSpellHistory () -> RestoreCharge ( m_spellInfo -> ChargeCategoryId );
2015-12-03 00:08:44 +01:00
}
2012-08-31 01:26:21 +01:00
}
2010-02-20 23:59:05 +01:00
SetExecutedCurrently ( false );
2016-01-13 18:38:54 +01:00
if ( Creature * creatureCaster = m_caster -> ToCreature ())
creatureCaster -> ReleaseFocus ( this );
2010-02-20 23:59:05 +01:00
}
void Spell :: handle_immediate ()
{
// start channeling if applicable
2011-07-26 23:09:28 +02:00
if ( m_spellInfo -> IsChanneled ())
2010-02-20 23:59:05 +01:00
{
2011-07-26 23:09:28 +02:00
int32 duration = m_spellInfo -> GetDuration ();
2013-05-19 10:55:29 +02:00
if ( duration > 0 )
2010-02-20 23:59:05 +01:00
{
2010-04-25 22:20:59 +02:00
// First mod_duration then haste - see Missile Barrage
2010-02-20 23:59:05 +01:00
// Apply duration mod
2010-04-07 19:14:10 +02:00
if ( Player * modOwner = m_caster -> GetSpellModOwner ())
2010-02-20 23:59:05 +01:00
modOwner -> ApplySpellMod ( m_spellInfo -> Id , SPELLMOD_DURATION , duration );
2014-06-15 14:49:03 +01:00
2010-04-25 22:20:59 +02:00
// Apply haste mods
2015-10-25 10:10:57 +01:00
m_caster -> ModSpellDurationTime ( m_spellInfo , duration , this );
2010-04-25 22:20:59 +02:00
2010-02-20 23:59:05 +01:00
m_spellState = SPELL_STATE_CASTING ;
m_caster -> AddInterruptMask ( m_spellInfo -> ChannelInterruptFlags );
2014-08-18 09:37:30 +02:00
m_channeledDuration = duration ;
2010-02-20 23:59:05 +01:00
SendChannelStart ( duration );
}
2011-12-22 00:38:01 +01:00
else if ( duration == - 1 )
{
m_spellState = SPELL_STATE_CASTING ;
m_caster -> AddInterruptMask ( m_spellInfo -> ChannelInterruptFlags );
SendChannelStart ( duration );
}
2010-02-20 23:59:05 +01:00
}
2010-08-27 17:49:32 +02:00
PrepareTargetProcessing ();
2010-02-20 23:59:05 +01:00
// process immediate effects (items, ground, etc.) also initialize some variables
_handle_immediate_phase ();
2015-06-01 00:26:49 +01:00
for ( std :: vector < TargetInfo >:: iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
DoAllEffectOnTarget ( & ( * ihit ));
2015-06-01 00:26:49 +01:00
for ( std :: vector < GOTargetInfo >:: iterator ihit = m_UniqueGOTargetInfo . begin (); ihit != m_UniqueGOTargetInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
DoAllEffectOnTarget ( & ( * ihit ));
2010-08-27 17:49:32 +02:00
FinishTargetProcessing ();
2010-02-20 23:59:05 +01:00
// spell is finished, perform some last features of the spell here
_handle_finish_phase ();
// Remove used for cast item if need (it can be already NULL after TakeReagents call
TakeCastItem ();
2010-04-07 19:14:10 +02:00
if ( m_spellState != SPELL_STATE_CASTING )
2010-02-20 23:59:05 +01:00
finish ( true ); // successfully finish spell cast (not last in case autorepeat or channel spell)
}
uint64 Spell :: handle_delayed ( uint64 t_offset )
{
2014-05-03 21:22:12 +02:00
if ( ! UpdatePointers ())
{
// finish the spell if UpdatePointers() returned false, something wrong happened there
finish ( false );
return 0 ;
}
2010-02-20 23:59:05 +01:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> SetSpellModTakingSpell ( this , true );
2010-02-20 23:59:05 +01:00
uint64 next_time = 0 ;
2010-08-27 17:49:32 +02:00
PrepareTargetProcessing ();
2010-02-20 23:59:05 +01:00
if ( ! m_immediateHandled )
{
_handle_immediate_phase ();
m_immediateHandled = true ;
}
2010-08-02 20:05:22 +02:00
bool single_missile = ( m_targets . HasDst ());
2010-02-20 23:59:05 +01:00
// now recheck units targeting correctness (need before any effects apply to prevent adding immunity at first effect not allow apply second spell effect and similar cases)
2015-06-01 00:26:49 +01:00
for ( std :: vector < TargetInfo >:: iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
{
if ( ihit -> processed == false )
{
2010-04-07 22:59:46 +02:00
if ( single_missile || ihit -> timeDelay <= t_offset )
2010-11-13 18:04:56 +01:00
{
ihit -> timeDelay = t_offset ;
2010-02-20 23:59:05 +01:00
DoAllEffectOnTarget ( & ( * ihit ));
2010-11-13 18:04:56 +01:00
}
2010-04-07 22:59:46 +02:00
else if ( next_time == 0 || ihit -> timeDelay < next_time )
2010-02-20 23:59:05 +01:00
next_time = ihit -> timeDelay ;
}
}
// now recheck gameobject targeting correctness
2015-06-01 00:26:49 +01:00
for ( std :: vector < GOTargetInfo >:: iterator ighit = m_UniqueGOTargetInfo . begin (); ighit != m_UniqueGOTargetInfo . end (); ++ ighit )
2010-02-20 23:59:05 +01:00
{
if ( ighit -> processed == false )
{
2010-04-07 22:59:46 +02:00
if ( single_missile || ighit -> timeDelay <= t_offset )
2010-02-20 23:59:05 +01:00
DoAllEffectOnTarget ( & ( * ighit ));
2010-04-07 22:59:46 +02:00
else if ( next_time == 0 || ighit -> timeDelay < next_time )
2010-02-20 23:59:05 +01:00
next_time = ighit -> timeDelay ;
}
}
2010-08-27 17:49:32 +02:00
FinishTargetProcessing ();
2010-02-20 23:59:05 +01:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> SetSpellModTakingSpell ( this , false );
2010-02-20 23:59:05 +01:00
// All targets passed - need finish phase
if ( next_time == 0 )
{
// spell is finished, perform some last features of the spell here
_handle_finish_phase ();
finish ( true ); // successfully finish spell cast
// return zero, spell is finished now
return 0 ;
}
else
{
// spell is unfinished, return next execution time
return next_time ;
}
}
void Spell :: _handle_immediate_phase ()
{
m_spellAura = NULL ;
2011-09-25 13:29:17 +02:00
// initialize Diminishing Returns Data
m_diminishLevel = DIMINISHING_LEVEL_1 ;
m_diminishGroup = DIMINISHING_NONE ;
2010-02-20 23:59:05 +01:00
// handle some immediate features of the spell here
2011-07-26 23:09:28 +02:00
HandleThreatSpells ();
2010-02-20 23:59:05 +01:00
2010-08-21 20:18:54 +02:00
PrepareScriptHitHandlers ();
2010-08-19 14:31:31 +02:00
2011-09-25 13:29:17 +02:00
// handle effects with SPELL_EFFECT_HANDLE_HIT mode
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2011-09-25 13:29:17 +02:00
// don't do anything for empty effect
2014-11-27 15:11:43 +01:00
if ( ! effect || ! effect -> IsEffect ())
2010-02-20 23:59:05 +01:00
continue ;
2011-09-25 13:29:17 +02:00
// call effect handlers to handle destination hit
2014-11-16 14:20:01 +01:00
HandleEffects ( NULL , NULL , NULL , effect -> EffectIndex , SPELL_EFFECT_HANDLE_HIT );
2010-02-20 23:59:05 +01:00
}
// process items
2015-06-01 00:26:49 +01:00
for ( std :: vector < ItemTargetInfo >:: iterator ihit = m_UniqueItemInfo . begin (); ihit != m_UniqueItemInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
DoAllEffectOnTarget ( & ( * ihit ));
2010-04-07 19:14:10 +02:00
if ( ! m_originalCaster )
2010-02-20 23:59:05 +01:00
return ;
2011-09-25 13:29:17 +02:00
// Handle procs on cast
2013-03-08 21:41:30 +01:00
/// @todo finish new proc system:P
2012-05-30 08:01:02 +02:00
if ( m_UniqueTargetInfo . empty () && m_targets . HasDst ())
2010-02-20 23:59:05 +01:00
{
uint32 procAttacker = m_procAttacker ;
if ( ! procAttacker )
2012-05-30 08:01:02 +02:00
procAttacker |= PROC_FLAG_DONE_SPELL_MAGIC_DMG_CLASS_POS ;
// Proc the spells that have DEST target
2011-10-02 16:23:52 +02:00
m_originalCaster -> ProcDamageAndSpell ( NULL , procAttacker , 0 , m_procEx | PROC_EX_NORMAL_HIT , 0 , BASE_ATTACK , m_spellInfo , m_triggeredByAuraSpell );
2010-02-20 23:59:05 +01:00
}
}
void Spell :: _handle_finish_phase ()
{
2016-08-20 12:43:04 +02:00
if ( m_caster -> m_playerMovingMe )
2010-02-20 23:59:05 +01:00
{
// Take for real after all targets are processed
if ( m_needComboPoints )
2016-08-20 12:43:04 +02:00
m_caster -> m_playerMovingMe -> ClearComboPoints ();
2010-02-20 23:59:05 +01:00
// Real add combo points from effects
if ( m_comboPointGain )
2016-08-20 12:43:04 +02:00
m_caster -> m_playerMovingMe -> GainSpellComboPoints ( m_comboPointGain );
2010-02-20 23:59:05 +01:00
}
2011-09-25 16:42:12 +03:00
2014-11-16 14:20:01 +01:00
if ( m_caster -> m_extraAttacks && HasEffect ( SPELL_EFFECT_ADD_EXTRA_ATTACKS ))
2014-10-18 20:51:00 +01:00
{
2015-02-25 00:13:14 +01:00
if ( Unit * victim = ObjectAccessor :: GetUnit ( * m_caster , m_targets . GetOrigUnitTargetGUID ()))
2014-10-18 20:51:00 +01:00
m_caster -> HandleProcExtraAttackFor ( victim );
else
m_caster -> m_extraAttacks = 0 ;
}
2011-09-25 16:42:12 +03:00
2013-03-08 21:41:30 +01:00
/// @todo trigger proc phase finish here
2010-02-20 23:59:05 +01:00
}
void Spell :: SendSpellCooldown ()
{
2015-08-26 11:12:35 +02:00
if ( m_CastItem )
m_caster -> GetSpellHistory () -> HandleCooldowns ( m_spellInfo , m_CastItem , this );
else
m_caster -> GetSpellHistory () -> HandleCooldowns ( m_spellInfo , m_castItemEntry , this );
2010-02-20 23:59:05 +01:00
}
void Spell :: update ( uint32 difftime )
{
// update pointers based at it's GUIDs
2014-05-03 21:22:12 +02:00
if ( ! UpdatePointers ())
{
// cancel the spell if UpdatePointers() returned false, something wrong happened there
cancel ();
return ;
}
2010-02-20 23:59:05 +01:00
2014-10-21 19:23:32 +02:00
if ( ! m_targets . GetUnitTargetGUID (). IsEmpty () && ! m_targets . GetUnitTarget ())
2010-02-20 23:59:05 +01:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "Spell %u is cancelled due to removal of target." , m_spellInfo -> Id );
2010-02-20 23:59:05 +01:00
cancel ();
return ;
}
// check if the player caster has moved before the spell finished
2012-09-10 18:20:26 -05:00
// with the exception of spells affected with SPELL_AURA_CAST_WHILE_WALKING effect
2014-11-16 14:20:01 +01:00
SpellEffectInfo const * effect = GetEffect ( EFFECT_0 );
2010-02-20 23:59:05 +01:00
if (( m_caster -> GetTypeId () == TYPEID_PLAYER && m_timer != 0 ) &&
m_caster -> isMoving () && ( m_spellInfo -> InterruptFlags & SPELL_INTERRUPT_FLAG_MOVEMENT ) &&
2014-11-16 14:20:01 +01:00
(( effect && effect -> Effect != SPELL_EFFECT_STUCK ) || ! m_caster -> HasUnitMovementFlag ( MOVEMENTFLAG_FALLING_FAR )) &&
2012-09-11 01:31:55 +01:00
! m_caster -> HasAuraTypeWithAffectMask ( SPELL_AURA_CAST_WHILE_WALKING , m_spellInfo ))
2010-02-20 23:59:05 +01:00
{
// don't cancel for melee, autorepeat, triggered and instant spells
2016-04-25 11:46:35 -03:00
if ( ! IsNextMeleeSwingSpell () && ! IsAutoRepeat () && ! IsTriggered () && ! ( IsChannelActive () && m_spellInfo -> HasAttribute ( SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING )))
2016-03-26 18:41:03 +01:00
{
// if charmed by creature, trust the AI not to cheat and allow the cast to proceed
// @todo this is a hack, "creature" movesplines don't differentiate turning/moving right now
// however, checking what type of movement the spline is for every single spline would be really expensive
if ( ! m_caster -> GetCharmerGUID (). IsCreature ())
cancel ();
}
2010-02-20 23:59:05 +01:00
}
2011-09-05 14:01:50 +02:00
switch ( m_spellState )
2010-02-20 23:59:05 +01:00
{
case SPELL_STATE_PREPARING :
{
2011-12-22 18:48:06 +01:00
if ( m_timer > 0 )
2010-02-20 23:59:05 +01:00
{
2011-12-22 13:22:18 +01:00
if ( difftime >= ( uint32 ) m_timer )
2010-02-20 23:59:05 +01:00
m_timer = 0 ;
else
m_timer -= difftime ;
}
2010-04-07 19:14:10 +02:00
if ( m_timer == 0 && ! IsNextMeleeSwingSpell () && ! IsAutoRepeat ())
2011-07-26 23:09:28 +02:00
// don't CheckCast for instant spells - done in spell::prepare, skip duplicate checks, needed for range checks for example
cast ( ! m_casttime );
2011-12-22 13:22:18 +01:00
break ;
}
2010-02-20 23:59:05 +01:00
case SPELL_STATE_CASTING :
{
2011-12-22 18:48:06 +01:00
if ( m_timer )
2010-02-20 23:59:05 +01:00
{
// check if there are alive targets left
if ( ! UpdateChanneledTargetList ())
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "Channeled spell %d is removed due to lack of targets" , m_spellInfo -> Id );
2010-02-20 23:59:05 +01:00
SendChannelUpdate ( 0 );
finish ();
}
2011-12-22 18:48:06 +01:00
if ( m_timer > 0 )
{
if ( difftime >= ( uint32 ) m_timer )
m_timer = 0 ;
else
m_timer -= difftime ;
}
2010-02-20 23:59:05 +01:00
}
2010-04-07 19:14:10 +02:00
if ( m_timer == 0 )
2010-02-20 23:59:05 +01:00
{
SendChannelUpdate ( 0 );
finish ();
}
2011-12-22 13:22:18 +01:00
break ;
}
2010-02-20 23:59:05 +01:00
default :
2011-12-22 13:22:18 +01:00
break ;
2010-02-20 23:59:05 +01:00
}
}
void Spell :: finish ( bool ok )
{
2010-04-07 19:14:10 +02:00
if ( ! m_caster )
2010-02-20 23:59:05 +01:00
return ;
2010-04-07 19:14:10 +02:00
if ( m_spellState == SPELL_STATE_FINISHED )
2010-02-20 23:59:05 +01:00
return ;
m_spellState = SPELL_STATE_FINISHED ;
2011-07-26 23:09:28 +02:00
if ( m_spellInfo -> IsChanneled ())
2010-02-20 23:59:05 +01:00
m_caster -> UpdateInterruptMask ();
2013-12-25 14:16:55 -03:30
if ( m_caster -> HasUnitState ( UNIT_STATE_CASTING ) && ! m_caster -> IsNonMeleeSpellCast ( false , false , true ))
2012-02-03 19:12:41 +02:00
m_caster -> ClearUnitState ( UNIT_STATE_CASTING );
2010-02-20 23:59:05 +01:00
// Unsummon summon as possessed creatures on spell cancel
2011-07-26 23:09:28 +02:00
if ( m_spellInfo -> IsChanneled () && m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-02-20 23:59:05 +01:00
{
2011-09-15 14:08:17 +02:00
if ( Unit * charm = m_caster -> GetCharm ())
2010-04-07 19:14:10 +02:00
if ( charm -> GetTypeId () == TYPEID_UNIT
2010-03-07 18:30:53 +01:00
&& charm -> ToCreature () -> HasUnitTypeMask ( UNIT_MASK_PUPPET )
2010-02-20 23:59:05 +01:00
&& charm -> GetUInt32Value ( UNIT_CREATED_BY_SPELL ) == m_spellInfo -> Id )
(( Puppet * ) charm ) -> UnSummon ();
}
2013-10-03 17:07:25 +02:00
if ( Creature * creatureCaster = m_caster -> ToCreature ())
creatureCaster -> ReleaseFocus ( this );
2011-07-15 12:33:03 +02:00
2010-04-07 19:14:10 +02:00
if ( ! ok )
2010-02-20 23:59:05 +01:00
return ;
2015-08-12 14:05:14 +02:00
if ( m_caster -> GetTypeId () == TYPEID_UNIT && m_caster -> IsSummon ())
2010-02-20 23:59:05 +01:00
{
// Unsummon statue
uint32 spell = m_caster -> GetUInt32Value ( UNIT_CREATED_BY_SPELL );
2011-09-15 14:08:17 +02:00
SpellInfo const * spellInfo = sSpellMgr -> GetSpellInfo ( spell );
2017-04-06 23:39:34 +02:00
if ( spellInfo && spellInfo -> IconFileDataId == 134230 )
2010-02-20 23:59:05 +01:00
{
2014-10-22 21:22:04 +02:00
TC_LOG_DEBUG ( "spells" , "Statue %s is unsummoned in spell %d finish" , m_caster -> GetGUID (). ToString (). c_str (), m_spellInfo -> Id );
2010-02-20 23:59:05 +01:00
m_caster -> setDeathState ( JUST_DIED );
return ;
}
}
2010-09-12 23:52:37 +03:00
if ( IsAutoActionResetSpell ())
2010-02-20 23:59:05 +01:00
{
bool found = false ;
Unit :: AuraEffectList const & vIgnoreReset = m_caster -> GetAuraEffectsByType ( SPELL_AURA_IGNORE_MELEE_RESET );
for ( Unit :: AuraEffectList :: const_iterator i = vIgnoreReset . begin (); i != vIgnoreReset . end (); ++ i )
{
2011-11-26 23:38:06 +02:00
if (( * i ) -> IsAffectingSpell ( m_spellInfo ))
2010-02-20 23:59:05 +01:00
{
found = true ;
break ;
}
}
2016-10-02 00:24:47 -03:00
2015-01-05 23:49:43 +02:00
if ( ! found && ! m_spellInfo -> HasAttribute ( SPELL_ATTR2_NOT_RESET_AUTO_ACTIONS ))
2010-02-20 23:59:05 +01:00
{
m_caster -> resetAttackTimer ( BASE_ATTACK );
2010-04-07 19:14:10 +02:00
if ( m_caster -> haveOffhandWeapon ())
2010-02-20 23:59:05 +01:00
m_caster -> resetAttackTimer ( OFF_ATTACK );
2010-09-12 23:52:37 +03:00
m_caster -> resetAttackTimer ( RANGED_ATTACK );
2010-02-20 23:59:05 +01:00
}
}
// potions disabled by client, send event "not in combat" if need
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
{
if ( ! m_triggeredByAuraSpell )
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> UpdatePotionCooldown ( this );
2016-09-01 01:09:23 -03:00
}
2010-02-20 23:59:05 +01:00
2016-09-01 01:09:23 -03:00
if ( Player * modOwner = m_caster -> GetSpellModOwner ())
{
2010-02-20 23:59:05 +01:00
// triggered spell pointer can be not set in some cases
// this is needed for proper apply of triggered spell mods
2016-09-01 01:09:23 -03:00
modOwner -> SetSpellModTakingSpell ( this , true );
2010-02-20 23:59:05 +01:00
2011-02-03 22:20:40 +01:00
// Take mods after trigger spell (needed for 14177 to affect 48664)
// mods are taken only on succesfull cast and independantly from targets of the spell
2016-09-01 01:09:23 -03:00
modOwner -> RemoveSpellMods ( this );
modOwner -> SetSpellModTakingSpell ( this , false );
2010-02-20 23:59:05 +01:00
}
// Stop Attack for some spells
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR0_STOP_ATTACK_TARGET ))
2010-02-20 23:59:05 +01:00
m_caster -> AttackStop ();
}
2016-06-05 14:08:53 +02:00
template < class T >
inline void FillSpellCastFailedArgs ( T & packet , ObjectGuid castId , SpellInfo const * spellInfo , SpellCastResult result , SpellCustomErrors customError , uint32 * misc , Player * caster )
2013-08-14 16:52:13 +02:00
{
2016-06-05 14:08:53 +02:00
packet . CastID = castId ;
2014-12-05 00:33:21 +02:00
packet . SpellID = spellInfo -> Id ;
packet . Reason = result ;
2010-02-20 23:59:05 +01:00
switch ( result )
{
2011-12-21 03:29:25 +01:00
case SPELL_FAILED_NOT_READY :
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = 0 ; // unknown (value 1 update cooldowns on client flag)
2011-12-21 03:29:25 +01:00
break ;
2010-02-20 23:59:05 +01:00
case SPELL_FAILED_REQUIRES_SPELL_FOCUS :
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = spellInfo -> RequiresSpellFocus ; // SpellFocusObject.dbc id
2010-02-20 23:59:05 +01:00
break ;
2011-12-21 03:29:25 +01:00
case SPELL_FAILED_REQUIRES_AREA : // AreaTable.dbc id
2010-02-20 23:59:05 +01:00
// hardcode areas limitation case
2011-09-05 14:01:50 +02:00
switch ( spellInfo -> Id )
2010-02-20 23:59:05 +01:00
{
case 41617 : // Cenarion Mana Salve
case 41619 : // Cenarion Healing Salve
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = 3905 ;
2010-02-20 23:59:05 +01:00
break ;
case 41618 : // Bottled Nethergon Energy
case 41620 : // Bottled Nethergon Vapor
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = 3842 ;
2010-02-20 23:59:05 +01:00
break ;
case 45373 : // Bloodberry Elixir
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = 4075 ;
2010-02-20 23:59:05 +01:00
break ;
default : // default case (don't must be)
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = 0 ;
2010-02-20 23:59:05 +01:00
break ;
}
break ;
case SPELL_FAILED_TOTEMS :
2010-04-07 19:14:10 +02:00
if ( spellInfo -> Totem [ 0 ])
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = spellInfo -> Totem [ 0 ];
2010-04-07 19:14:10 +02:00
if ( spellInfo -> Totem [ 1 ])
2014-12-05 00:33:21 +02:00
packet . FailedArg2 = spellInfo -> Totem [ 1 ];
2010-02-20 23:59:05 +01:00
break ;
case SPELL_FAILED_TOTEM_CATEGORY :
2010-04-07 19:14:10 +02:00
if ( spellInfo -> TotemCategory [ 0 ])
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = spellInfo -> TotemCategory [ 0 ];
2010-04-07 19:14:10 +02:00
if ( spellInfo -> TotemCategory [ 1 ])
2014-12-05 00:33:21 +02:00
packet . FailedArg2 = spellInfo -> TotemCategory [ 1 ];
2010-02-20 23:59:05 +01:00
break ;
case SPELL_FAILED_EQUIPPED_ITEM_CLASS :
2011-12-21 03:29:25 +01:00
case SPELL_FAILED_EQUIPPED_ITEM_CLASS_MAINHAND :
case SPELL_FAILED_EQUIPPED_ITEM_CLASS_OFFHAND :
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = spellInfo -> EquippedItemClass ;
packet . FailedArg2 = spellInfo -> EquippedItemSubClassMask ;
2010-02-20 23:59:05 +01:00
break ;
case SPELL_FAILED_TOO_MANY_OF_ITEM :
{
2014-12-05 00:33:21 +02:00
uint32 item = 0 ;
2015-01-10 01:35:47 +01:00
for ( SpellEffectInfo const * effect : spellInfo -> GetEffectsForDifficulty ( caster -> GetMap () -> GetDifficultyID ()))
2014-12-05 00:33:21 +02:00
if ( effect -> ItemType )
item = effect -> ItemType ;
ItemTemplate const * proto = sObjectMgr -> GetItemTemplate ( item );
2014-12-21 13:35:43 +01:00
if ( proto && proto -> GetItemLimitCategory ())
packet . FailedArg1 = proto -> GetItemLimitCategory ();
2014-12-05 00:33:21 +02:00
break ;
2010-02-20 23:59:05 +01:00
}
2011-12-21 03:29:25 +01:00
case SPELL_FAILED_PREVENTED_BY_MECHANIC :
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = spellInfo -> GetAllEffectsMechanicMask (); // SpellMechanic.dbc id
2011-12-21 03:29:25 +01:00
break ;
case SPELL_FAILED_NEED_EXOTIC_AMMO :
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = spellInfo -> EquippedItemSubClassMask ; // seems correct...
2011-12-21 03:29:25 +01:00
break ;
case SPELL_FAILED_NEED_MORE_ITEMS :
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = 0 ; // Item id
packet . FailedArg2 = 0 ; // Item count?
2011-12-21 03:29:25 +01:00
break ;
case SPELL_FAILED_MIN_SKILL :
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = 0 ; // SkillLine.dbc id
packet . FailedArg2 = 0 ; // required skill value
2011-12-21 03:29:25 +01:00
break ;
case SPELL_FAILED_FISHING_TOO_LOW :
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = 0 ; // required fishing skill
2011-12-21 03:29:25 +01:00
break ;
2011-03-04 21:18:38 +01:00
case SPELL_FAILED_CUSTOM_ERROR :
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = customError ;
2011-03-04 21:18:38 +01:00
break ;
2011-12-21 03:29:25 +01:00
case SPELL_FAILED_SILENCED :
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = 0 ; // Unknown
2011-12-21 03:29:25 +01:00
break ;
2012-02-15 00:46:08 +01:00
case SPELL_FAILED_REAGENTS :
{
uint32 missingItem = 0 ;
for ( uint32 i = 0 ; i < MAX_SPELL_REAGENTS ; i ++ )
{
if ( spellInfo -> Reagent [ i ] <= 0 )
continue ;
uint32 itemid = spellInfo -> Reagent [ i ];
uint32 itemcount = spellInfo -> ReagentCount [ i ];
if ( ! caster -> HasItemCount ( itemid , itemcount ))
{
missingItem = itemid ;
break ;
}
}
2014-12-05 00:33:21 +02:00
packet . FailedArg1 = missingItem ; // first missing item
2012-02-15 00:46:08 +01:00
break ;
}
2015-07-18 00:45:21 +02:00
case SPELL_FAILED_CANT_UNTALENT :
2015-01-30 23:58:16 +01:00
{
2015-07-18 00:45:21 +02:00
if ( misc )
if ( TalentEntry const * talent = sTalentStore . LookupEntry ( misc [ 0 ]))
packet . FailedArg1 = talent -> SpellID ;
2015-01-30 23:58:16 +01:00
break ;
}
2012-08-07 17:10:13 +01:00
// TODO: SPELL_FAILED_NOT_STANDING
2010-02-20 23:59:05 +01:00
default :
break ;
}
2016-06-05 14:08:53 +02:00
}
void Spell :: SendCastResult ( SpellCastResult result )
{
if ( result == SPELL_CAST_OK )
return ;
2014-12-05 00:33:21 +02:00
2016-06-05 14:08:53 +02:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return ;
if ( m_caster -> ToPlayer () -> GetSession () -> PlayerLoading ()) // don't send cast results at loading time
return ;
2016-05-11 18:29:02 +02:00
if ( _triggeredCastFlags & TRIGGERED_DONT_REPORT_CAST_ERROR )
result = SPELL_FAILED_DONT_REPORT ;
2016-06-05 14:08:53 +02:00
WorldPackets :: Spells :: CastFailed castFailed ;
castFailed . SpellXSpellVisualID = m_SpellVisual ;
FillSpellCastFailedArgs ( castFailed , m_castId , m_spellInfo , result , m_customError , m_misc . Raw . Data , m_caster -> ToPlayer ());
m_caster -> ToPlayer () -> SendDirectMessage ( castFailed . Write ());
}
void Spell :: SendPetCastResult ( SpellCastResult result )
{
if ( result == SPELL_CAST_OK )
return ;
Unit * owner = m_caster -> GetCharmerOrOwner ();
if ( ! owner || owner -> GetTypeId () != TYPEID_PLAYER )
return ;
2016-05-11 18:29:02 +02:00
if ( _triggeredCastFlags & TRIGGERED_DONT_REPORT_CAST_ERROR )
result = SPELL_FAILED_DONT_REPORT ;
2016-06-05 14:08:53 +02:00
WorldPackets :: Spells :: PetCastFailed petCastFailed ;
FillSpellCastFailedArgs ( petCastFailed , m_castId , m_spellInfo , result , SPELL_CUSTOM_ERROR_NONE , m_misc . Raw . Data , owner -> ToPlayer ());
owner -> ToPlayer () -> SendDirectMessage ( petCastFailed . Write ());
}
void Spell :: SendCastResult ( Player * caster , SpellInfo const * spellInfo , uint32 spellVisual , ObjectGuid cast_count , SpellCastResult result , SpellCustomErrors customError /*= SPELL_CUSTOM_ERROR_NONE*/ , uint32 * misc /*= nullptr*/ )
{
if ( result == SPELL_CAST_OK )
return ;
WorldPackets :: Spells :: CastFailed packet ;
packet . SpellXSpellVisualID = spellVisual ;
FillSpellCastFailedArgs ( packet , cast_count , spellInfo , result , customError , misc , caster );
2014-12-05 00:33:21 +02:00
caster -> GetSession () -> SendPacket ( packet . Write ());
2010-02-20 23:59:05 +01:00
}
void Spell :: SendSpellStart ()
{
2010-04-07 19:14:10 +02:00
if ( ! IsNeedSendToClient ())
2010-02-20 23:59:05 +01:00
return ;
2014-12-02 00:07:36 +02:00
TC_LOG_DEBUG ( "spells" , "Sending SMSG_SPELL_START id=%u" , m_spellInfo -> Id );
2010-02-20 23:59:05 +01:00
2012-08-06 09:32:35 -04:00
uint32 castFlags = CAST_FLAG_HAS_TRAJECTORY ;
2015-06-30 11:44:11 +02:00
uint32 schoolImmunityMask = m_caster -> GetSchoolImmunityMask ();
uint32 mechanicImmunityMask = m_caster -> GetMechanicImmunityMask ();
if ( schoolImmunityMask || mechanicImmunityMask )
castFlags |= CAST_FLAG_IMMUNITY ;
2011-07-30 19:15:06 +02:00
2017-01-13 18:54:15 +01:00
if ((( IsTriggered () && ! m_spellInfo -> IsAutoRepeatRangedSpell ()) || m_triggeredByAuraSpell ) && ! m_fromClient )
2011-07-30 19:15:06 +02:00
castFlags |= CAST_FLAG_PENDING ;
2016-03-23 20:17:17 +01:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR0_REQ_AMMO ) || m_spellInfo -> HasAttribute ( SPELL_ATTR0_CU_NEEDS_AMMO_DATA ))
castFlags |= CAST_FLAG_PROJECTILE ;
2010-02-20 23:59:05 +01:00
if (( m_caster -> GetTypeId () == TYPEID_PLAYER ||
2015-08-12 12:48:33 +02:00
( m_caster -> GetTypeId () == TYPEID_UNIT && m_caster -> IsPet ()))
2015-03-08 13:31:57 +01:00
&& std :: find_if ( m_powerCost . begin (), m_powerCost . end (), []( SpellInfo :: CostData const & cost ) { return cost . Power != POWER_HEALTH ; }) != m_powerCost . end ())
2010-02-20 23:59:05 +01:00
castFlags |= CAST_FLAG_POWER_LEFT_SELF ;
2016-01-24 15:56:10 +01:00
if ( std :: find_if ( m_powerCost . begin (), m_powerCost . end (), []( SpellInfo :: CostData const & cost ) { return cost . Power == POWER_RUNES ; }) != m_powerCost . end ())
2014-06-15 14:49:03 +01:00
castFlags |= CAST_FLAG_NO_GCD ; // not needed, but Blizzard sends it
2010-02-20 23:59:05 +01:00
2014-12-02 00:07:36 +02:00
WorldPackets :: Spells :: SpellStart packet ;
WorldPackets :: Spells :: SpellCastData & castData = packet . Cast ;
if ( m_CastItem )
castData . CasterGUID = m_CastItem -> GetGUID ();
else
castData . CasterGUID = m_caster -> GetGUID ();
castData . CasterUnit = m_caster -> GetGUID ();
2016-06-05 14:08:53 +02:00
castData . CastID = m_castId ;
castData . OriginalCastID = m_originalCastId ;
2014-12-02 00:07:36 +02:00
castData . SpellID = m_spellInfo -> Id ;
2015-07-18 00:45:21 +02:00
castData . SpellXSpellVisualID = m_SpellVisual ;
2014-12-02 00:07:36 +02:00
castData . CastFlags = castFlags ;
2015-08-26 11:12:35 +02:00
castData . CastFlagsEx = m_castFlagsEx ;
2014-12-02 00:07:36 +02:00
castData . CastTime = m_casttime ;
m_targets . Write ( castData . Target );
if ( castFlags & CAST_FLAG_POWER_LEFT_SELF )
{
2015-03-08 13:31:57 +01:00
for ( SpellInfo :: CostData const & cost : m_powerCost )
{
WorldPackets :: Spells :: SpellPowerData powerData ;
powerData . Type = cost . Power ;
powerData . Cost = m_caster -> GetPower ( cost . Power );
castData . RemainingPower . push_back ( powerData );
}
2014-12-02 00:07:36 +02:00
}
if ( castFlags & CAST_FLAG_RUNE_LIST ) // rune cooldowns list
{
2015-04-27 17:01:30 +02:00
castData . RemainingRunes = boost :: in_place ();
2015-04-26 23:45:52 +02:00
2014-12-02 00:07:36 +02:00
//TODO: There is a crash caused by a spell with CAST_FLAG_RUNE_LIST casted by a creature
//The creature is the mover of a player, so HandleCastSpellOpcode uses it as the caster
if ( Player * player = m_caster -> ToPlayer ())
{
2015-04-26 23:45:52 +02:00
castData . RemainingRunes -> Start = m_runesState ; // runes state before
castData . RemainingRunes -> Count = player -> GetRunesState (); // runes state after
2014-12-02 00:07:36 +02:00
for ( uint8 i = 0 ; i < MAX_RUNES ; ++ i )
{
// float casts ensure the division is performed on floats as we need float result
2016-01-24 15:56:10 +01:00
float baseCd = float ( player -> GetRuneBaseCooldown ());
2015-04-26 23:45:52 +02:00
castData . RemainingRunes -> Cooldowns . push_back (( baseCd - float ( player -> GetRuneCooldown ( i ))) / baseCd * 255 ); // rune cooldown passed
2014-12-02 00:07:36 +02:00
}
}
else
{
2015-04-26 23:45:52 +02:00
castData . RemainingRunes -> Start = 0 ;
castData . RemainingRunes -> Count = 0 ;
2014-12-02 00:07:36 +02:00
for ( uint8 i = 0 ; i < MAX_RUNES ; ++ i )
2015-04-26 23:45:52 +02:00
castData . RemainingRunes -> Cooldowns . push_back ( 0 );
2014-12-02 00:07:36 +02:00
}
}
if ( castFlags & CAST_FLAG_PROJECTILE )
2016-03-23 20:17:17 +01:00
UpdateSpellCastDataAmmo ( castData . Ammo );
2014-12-02 00:07:36 +02:00
if ( castFlags & CAST_FLAG_IMMUNITY )
{
2015-06-30 11:44:11 +02:00
castData . Immunities . School = schoolImmunityMask ;
castData . Immunities . Value = mechanicImmunityMask ;
}
2014-11-30 15:37:11 +01:00
2014-12-02 00:07:36 +02:00
/** @todo implement heal prediction packet data
if (castFlags & CAST_FLAG_HEAL_PREDICTION)
{
castData.Predict.BeconGUID = ??
castData.Predict.Points = 0;
castData.Predict.Type = 0;
}**/
2014-12-19 18:55:09 +01:00
2014-12-02 00:07:36 +02:00
m_caster -> SendMessageToSet ( packet . Write (), true );
2010-02-20 23:59:05 +01:00
}
void Spell :: SendSpellGo ()
{
// not send invisible spell casting
2010-04-07 19:14:10 +02:00
if ( ! IsNeedSendToClient ())
2010-02-20 23:59:05 +01:00
return ;
2014-12-02 00:07:36 +02:00
TC_LOG_DEBUG ( "spells" , "Sending SMSG_SPELL_GO id=%u" , m_spellInfo -> Id );
2010-02-20 23:59:05 +01:00
uint32 castFlags = CAST_FLAG_UNKNOWN_9 ;
// triggered spells with spell visual != 0
2017-01-13 18:54:15 +01:00
if ((( IsTriggered () && ! m_spellInfo -> IsAutoRepeatRangedSpell ()) || m_triggeredByAuraSpell ) && ! m_fromClient )
2010-02-20 23:59:05 +01:00
castFlags |= CAST_FLAG_PENDING ;
2016-03-23 20:17:17 +01:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR0_REQ_AMMO ) || m_spellInfo -> HasAttribute ( SPELL_ATTR0_CU_NEEDS_AMMO_DATA ))
castFlags |= CAST_FLAG_PROJECTILE ; // arrows/bullets visual
2010-02-20 23:59:05 +01:00
if (( m_caster -> GetTypeId () == TYPEID_PLAYER ||
2015-08-12 12:48:33 +02:00
( m_caster -> GetTypeId () == TYPEID_UNIT && m_caster -> IsPet ()))
2015-03-08 13:31:57 +01:00
&& std :: find_if ( m_powerCost . begin (), m_powerCost . end (), []( SpellInfo :: CostData const & cost ) { return cost . Power != POWER_HEALTH ; }) != m_powerCost . end ())
2010-02-20 23:59:05 +01:00
castFlags |= CAST_FLAG_POWER_LEFT_SELF ; // should only be sent to self, but the current messaging doesn't make that possible
2010-04-07 19:14:10 +02:00
if (( m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-04-07 18:09:10 +02:00
&& ( m_caster -> getClass () == CLASS_DEATH_KNIGHT )
2015-03-08 13:31:57 +01:00
&& std :: find_if ( m_powerCost . begin (), m_powerCost . end (), []( SpellInfo :: CostData const & cost ) { return cost . Power == POWER_RUNES ; }) != m_powerCost . end ()
2014-06-15 15:00:56 +01:00
&& ! ( _triggeredCastFlags & TRIGGERED_IGNORE_POWER_AND_REAGENT_COST ))
2010-02-20 23:59:05 +01:00
{
2014-06-15 14:49:03 +01:00
castFlags |= CAST_FLAG_NO_GCD ; // not needed, but Blizzard sends it
2010-02-20 23:59:05 +01:00
castFlags |= CAST_FLAG_RUNE_LIST ; // rune cooldowns list
}
2014-11-16 14:20:01 +01:00
if ( HasEffect ( SPELL_EFFECT_ACTIVATE_RUNE ))
2010-02-20 23:59:05 +01:00
castFlags |= CAST_FLAG_RUNE_LIST ; // rune cooldowns list
2012-01-08 18:50:25 +03:00
if ( m_targets . HasTraj ())
castFlags |= CAST_FLAG_ADJUST_MISSILE ;
2014-06-15 14:49:03 +01:00
if ( ! m_spellInfo -> StartRecoveryTime )
castFlags |= CAST_FLAG_NO_GCD ;
2014-12-02 00:07:36 +02:00
WorldPackets :: Spells :: SpellGo packet ;
WorldPackets :: Spells :: SpellCastData & castData = packet . Cast ;
if ( m_CastItem )
castData . CasterGUID = m_CastItem -> GetGUID ();
else
castData . CasterGUID = m_caster -> GetGUID ();
castData . CasterUnit = m_caster -> GetGUID ();
2016-06-05 14:08:53 +02:00
castData . CastID = m_castId ;
castData . OriginalCastID = m_originalCastId ;
2014-12-02 00:07:36 +02:00
castData . SpellID = m_spellInfo -> Id ;
2015-07-18 00:45:21 +02:00
castData . SpellXSpellVisualID = m_SpellVisual ;
2014-12-02 00:07:36 +02:00
castData . CastFlags = castFlags ;
2015-08-26 11:12:35 +02:00
castData . CastFlagsEx = m_castFlagsEx ;
2014-12-02 00:07:36 +02:00
castData . CastTime = getMSTime ();
2015-02-12 22:08:17 +00:00
UpdateSpellCastDataTargets ( castData );
2014-12-02 00:07:36 +02:00
m_targets . Write ( castData . Target );
if ( castFlags & CAST_FLAG_POWER_LEFT_SELF )
{
2015-03-08 13:31:57 +01:00
for ( SpellInfo :: CostData const & cost : m_powerCost )
{
WorldPackets :: Spells :: SpellPowerData powerData ;
powerData . Type = cost . Power ;
powerData . Cost = m_caster -> GetPower ( cost . Power );
castData . RemainingPower . push_back ( powerData );
}
2014-12-02 00:07:36 +02:00
}
if ( castFlags & CAST_FLAG_RUNE_LIST ) // rune cooldowns list
{
2015-04-27 17:01:30 +02:00
castData . RemainingRunes = boost :: in_place ();
2015-04-26 23:45:52 +02:00
2014-12-02 00:07:36 +02:00
//TODO: There is a crash caused by a spell with CAST_FLAG_RUNE_LIST casted by a creature
//The creature is the mover of a player, so HandleCastSpellOpcode uses it as the caster
if ( Player * player = m_caster -> ToPlayer ())
{
2015-04-26 23:45:52 +02:00
castData . RemainingRunes -> Start = m_runesState ; // runes state before
castData . RemainingRunes -> Count = player -> GetRunesState (); // runes state after
2014-12-02 00:07:36 +02:00
for ( uint8 i = 0 ; i < MAX_RUNES ; ++ i )
{
// float casts ensure the division is performed on floats as we need float result
2016-01-24 15:56:10 +01:00
float baseCd = float ( player -> GetRuneBaseCooldown ());
2015-04-26 23:45:52 +02:00
castData . RemainingRunes -> Cooldowns . push_back (( baseCd - float ( player -> GetRuneCooldown ( i ))) / baseCd * 255 ); // rune cooldown passed
2014-12-02 00:07:36 +02:00
}
}
else
{
2015-04-26 23:45:52 +02:00
castData . RemainingRunes -> Start = 0 ;
castData . RemainingRunes -> Count = 0 ;
2014-12-02 00:07:36 +02:00
for ( uint8 i = 0 ; i < MAX_RUNES ; ++ i )
2015-04-26 23:45:52 +02:00
castData . RemainingRunes -> Cooldowns . push_back ( 0 );
2014-12-02 00:07:36 +02:00
}
}
if ( castFlags & CAST_FLAG_ADJUST_MISSILE )
{
castData . MissileTrajectory . TravelTime = m_delayMoment ;
2015-02-12 02:37:42 +00:00
castData . MissileTrajectory . Pitch = m_targets . GetPitch ();
2014-12-02 00:07:36 +02:00
}
2011-11-27 23:31:46 +01:00
2016-07-07 22:56:07 +02:00
packet . LogData . Initialize ( this );
m_caster -> SendCombatLogMessage ( & packet );
2010-02-20 23:59:05 +01:00
}
2012-09-03 02:45:27 +01:00
/// Writes miss and hit targets for a SMSG_SPELL_GO packet
2015-02-12 22:08:17 +00:00
void Spell :: UpdateSpellCastDataTargets ( WorldPackets :: Spells :: SpellCastData & data )
2010-02-20 23:59:05 +01:00
{
// This function also fill data for channeled spells:
2015-02-12 22:08:17 +00:00
// m_needAliveTargetMask req for stop channeling if one target die
for ( TargetInfo & targetInfo : m_UniqueTargetInfo )
2010-02-20 23:59:05 +01:00
{
2015-02-12 22:08:17 +00:00
if ( targetInfo . effectMask == 0 ) // No effect apply - all immune add state
2010-02-20 23:59:05 +01:00
// possibly SPELL_MISS_IMMUNE2 for this??
2015-02-12 22:08:17 +00:00
targetInfo . missCondition = SPELL_MISS_IMMUNE2 ;
2015-02-12 19:56:39 +00:00
2015-02-12 22:08:17 +00:00
if ( targetInfo . missCondition == SPELL_MISS_NONE ) // hits
2010-02-20 23:59:05 +01:00
{
2015-02-12 22:08:17 +00:00
data . HitTargets . push_back ( targetInfo . targetGUID );
2010-02-20 23:59:05 +01:00
2015-02-12 22:08:17 +00:00
m_channelTargetEffectMask |= targetInfo . effectMask ;
}
else // misses
2010-02-20 23:59:05 +01:00
{
2015-02-12 22:08:17 +00:00
data . MissTargets . push_back ( targetInfo . targetGUID );
2015-02-12 19:56:39 +00:00
WorldPackets :: Spells :: SpellMissStatus missStatus ;
2015-02-12 22:08:17 +00:00
missStatus . Reason = targetInfo . missCondition ;
if ( targetInfo . missCondition == SPELL_MISS_REFLECT )
missStatus . ReflectStatus = targetInfo . reflectResult ;
2015-02-12 19:56:39 +00:00
data . MissStatus . push_back ( missStatus );
2010-02-20 23:59:05 +01:00
}
}
2015-02-12 19:56:39 +00:00
2015-02-12 22:08:17 +00:00
for ( GOTargetInfo const & targetInfo : m_UniqueGOTargetInfo )
data . HitTargets . push_back ( targetInfo . targetGUID ); // Always hits
2010-02-20 23:59:05 +01:00
// Reset m_needAliveTargetMask for non channeled spell
2011-07-26 23:09:28 +02:00
if ( ! m_spellInfo -> IsChanneled ())
2010-08-30 17:32:51 +02:00
m_channelTargetEffectMask = 0 ;
2010-02-20 23:59:05 +01:00
}
2016-03-23 20:17:17 +01:00
void Spell :: UpdateSpellCastDataAmmo ( WorldPackets :: Spells :: SpellAmmo & ammo )
{
uint32 ammoInventoryType = 0 ;
uint32 ammoDisplayID = 0 ;
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
{
Item * pItem = m_caster -> ToPlayer () -> GetWeaponForAttack ( RANGED_ATTACK );
if ( pItem )
{
ammoInventoryType = pItem -> GetTemplate () -> GetInventoryType ();
if ( ammoInventoryType == INVTYPE_THROWN )
2016-07-05 22:07:35 +02:00
ammoDisplayID = pItem -> GetDisplayId ( m_caster -> ToPlayer ());
2016-03-23 20:17:17 +01:00
else if ( m_caster -> HasAura ( 46699 )) // Requires No Ammo
{
ammoDisplayID = 5996 ; // normal arrow
ammoInventoryType = INVTYPE_AMMO ;
}
}
}
else
{
for ( uint8 i = 0 ; i < 3 ; ++ i )
{
if ( uint32 item_id = m_caster -> GetVirtualItemId ( i ))
{
if ( ItemEntry const * itemEntry = sItemStore . LookupEntry ( item_id ))
{
if ( itemEntry -> Class == ITEM_CLASS_WEAPON )
{
switch ( itemEntry -> SubClass )
{
case ITEM_SUBCLASS_WEAPON_THROWN :
ammoDisplayID = sDB2Manager . GetItemDisplayId ( item_id , m_caster -> GetVirtualItemAppearanceMod ( i ));
ammoInventoryType = itemEntry -> InventoryType ;
break ;
case ITEM_SUBCLASS_WEAPON_BOW :
case ITEM_SUBCLASS_WEAPON_CROSSBOW :
ammoDisplayID = 5996 ; // is this need fixing?
ammoInventoryType = INVTYPE_AMMO ;
break ;
case ITEM_SUBCLASS_WEAPON_GUN :
ammoDisplayID = 5998 ; // is this need fixing?
ammoInventoryType = INVTYPE_AMMO ;
break ;
}
if ( ammoDisplayID )
break ;
}
}
}
}
}
ammo . DisplayID = ammoDisplayID ;
ammo . InventoryType = ammoInventoryType ;
}
2015-04-18 17:02:33 +02:00
void Spell :: SendSpellExecuteLog ()
2010-02-20 23:59:05 +01:00
{
2015-04-18 17:02:33 +02:00
WorldPackets :: CombatLog :: SpellExecuteLog spellExecuteLog ;
spellExecuteLog . Caster = m_caster -> GetGUID ();
spellExecuteLog . SpellID = m_spellInfo -> Id ;
2010-08-27 17:49:32 +02:00
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-08-27 17:49:32 +02:00
{
2015-04-18 17:02:33 +02:00
if ( ! effect )
2010-08-27 17:49:32 +02:00
continue ;
2016-06-05 14:08:53 +02:00
if ( _powerDrainTargets [ effect -> EffectIndex ]. empty () && _extraAttacksTargets [ effect -> EffectIndex ]. empty () &&
_durabilityDamageTargets [ effect -> EffectIndex ]. empty () && _genericVictimTargets [ effect -> EffectIndex ]. empty () &&
_tradeSkillTargets [ effect -> EffectIndex ]. empty () && _feedPetTargets [ effect -> EffectIndex ]. empty ())
continue ;
2015-04-18 17:02:33 +02:00
2016-06-05 01:19:25 +02:00
spellExecuteLog . Effects . emplace_back ();
2015-04-18 17:02:33 +02:00
2016-06-05 01:19:25 +02:00
WorldPackets :: CombatLog :: SpellExecuteLog :: SpellLogEffect & spellLogEffect = spellExecuteLog . Effects . back ();
2016-06-05 14:08:53 +02:00
spellLogEffect . Effect = effect -> Effect ;
spellLogEffect . PowerDrainTargets = std :: move ( _powerDrainTargets [ effect -> EffectIndex ]);
spellLogEffect . ExtraAttacksTargets = std :: move ( _extraAttacksTargets [ effect -> EffectIndex ]);
spellLogEffect . DurabilityDamageTargets = std :: move ( _durabilityDamageTargets [ effect -> EffectIndex ]);
spellLogEffect . GenericVictimTargets = std :: move ( _genericVictimTargets [ effect -> EffectIndex ]);
spellLogEffect . TradeSkillTargets = std :: move ( _tradeSkillTargets [ effect -> EffectIndex ]);
spellLogEffect . FeedPetTargets = std :: move ( _feedPetTargets [ effect -> EffectIndex ]);
2010-08-27 17:49:32 +02:00
}
2015-04-18 17:02:33 +02:00
2016-06-05 14:08:53 +02:00
if ( ! spellExecuteLog . Effects . empty ())
m_caster -> SendCombatLogMessage ( & spellExecuteLog );
2010-02-20 23:59:05 +01:00
}
2015-04-18 18:09:13 +02:00
void Spell :: ExecuteLogEffectTakeTargetPower ( uint8 effIndex , Unit * target , uint32 powerType , uint32 points , float amplitude )
2010-08-27 17:49:32 +02:00
{
2015-04-18 17:02:33 +02:00
SpellLogEffectPowerDrainParams spellLogEffectPowerDrainParams ;
spellLogEffectPowerDrainParams . Victim = target -> GetGUID ();
spellLogEffectPowerDrainParams . Points = points ;
spellLogEffectPowerDrainParams . PowerType = powerType ;
spellLogEffectPowerDrainParams . Amplitude = amplitude ;
2015-04-18 18:09:13 +02:00
_powerDrainTargets [ effIndex ]. push_back ( spellLogEffectPowerDrainParams );
2010-08-27 17:49:32 +02:00
}
2015-04-18 18:09:13 +02:00
void Spell :: ExecuteLogEffectExtraAttacks ( uint8 effIndex , Unit * victim , uint32 numAttacks )
2010-08-27 17:49:32 +02:00
{
2015-04-18 17:02:33 +02:00
SpellLogEffectExtraAttacksParams spellLogEffectExtraAttacksParams ;
spellLogEffectExtraAttacksParams . Victim = victim -> GetGUID ();
spellLogEffectExtraAttacksParams . NumAttacks = numAttacks ;
2015-04-18 18:09:13 +02:00
_extraAttacksTargets [ effIndex ]. push_back ( spellLogEffectExtraAttacksParams );
2010-08-27 17:49:32 +02:00
}
2015-04-18 18:09:13 +02:00
void Spell :: ExecuteLogEffectInterruptCast ( uint8 /*effIndex*/ , Unit * victim , uint32 spellId )
2010-08-27 17:49:32 +02:00
{
2015-06-03 15:02:38 +02:00
WorldPackets :: CombatLog :: SpellInterruptLog data ;
data . Caster = m_caster -> GetGUID ();
data . Victim = victim -> GetGUID ();
data . InterruptedSpellID = m_spellInfo -> Id ;
data . SpellID = spellId ;
m_caster -> SendMessageToSet ( data . Write (), true );
2010-08-27 17:49:32 +02:00
}
2015-04-18 18:09:13 +02:00
void Spell :: ExecuteLogEffectDurabilityDamage ( uint8 effIndex , Unit * victim , int32 itemId , int32 amount )
2010-08-27 17:49:32 +02:00
{
2015-04-18 17:02:33 +02:00
SpellLogEffectDurabilityDamageParams spellLogEffectDurabilityDamageParams ;
spellLogEffectDurabilityDamageParams . Victim = victim -> GetGUID ();
spellLogEffectDurabilityDamageParams . ItemID = itemId ;
spellLogEffectDurabilityDamageParams . Amount = amount ;
2015-04-18 18:09:13 +02:00
_durabilityDamageTargets [ effIndex ]. push_back ( spellLogEffectDurabilityDamageParams );
2010-08-27 17:49:32 +02:00
}
2015-04-18 18:09:13 +02:00
void Spell :: ExecuteLogEffectOpenLock ( uint8 effIndex , Object * obj )
2010-08-27 17:49:32 +02:00
{
2015-04-18 17:02:33 +02:00
SpellLogEffectGenericVictimParams spellLogEffectGenericVictimParams ;
spellLogEffectGenericVictimParams . Victim = obj -> GetGUID ();
2015-04-18 18:09:13 +02:00
_genericVictimTargets [ effIndex ]. push_back ( spellLogEffectGenericVictimParams );
2010-08-27 17:49:32 +02:00
}
2015-04-18 18:09:13 +02:00
void Spell :: ExecuteLogEffectCreateItem ( uint8 effIndex , uint32 entry )
2010-08-27 17:49:32 +02:00
{
2015-04-18 17:02:33 +02:00
SpellLogEffectTradeSkillItemParams spellLogEffectTradeSkillItemParams ;
spellLogEffectTradeSkillItemParams . ItemID = entry ;
2015-04-18 18:09:13 +02:00
_tradeSkillTargets [ effIndex ]. push_back ( spellLogEffectTradeSkillItemParams );
2015-04-18 17:02:33 +02:00
}
2015-04-18 18:09:13 +02:00
void Spell :: ExecuteLogEffectDestroyItem ( uint8 effIndex , uint32 entry )
2015-04-18 17:02:33 +02:00
{
SpellLogEffectFeedPetParams spellLogEffectFeedPetParams ;
spellLogEffectFeedPetParams . ItemID = entry ;
2015-04-18 18:09:13 +02:00
_feedPetTargets [ effIndex ]. push_back ( spellLogEffectFeedPetParams );
2010-08-27 17:49:32 +02:00
}
2015-04-18 18:09:13 +02:00
void Spell :: ExecuteLogEffectSummonObject ( uint8 effIndex , WorldObject * obj )
2010-08-27 17:49:32 +02:00
{
2015-04-18 17:02:33 +02:00
SpellLogEffectGenericVictimParams spellLogEffectGenericVictimParams ;
spellLogEffectGenericVictimParams . Victim = obj -> GetGUID ();
2015-04-18 18:09:13 +02:00
_genericVictimTargets [ effIndex ]. push_back ( spellLogEffectGenericVictimParams );
2010-08-27 17:49:32 +02:00
}
2015-04-18 18:09:13 +02:00
void Spell :: ExecuteLogEffectUnsummonObject ( uint8 effIndex , WorldObject * obj )
2010-08-27 17:49:32 +02:00
{
2015-04-18 17:02:33 +02:00
SpellLogEffectGenericVictimParams spellLogEffectGenericVictimParams ;
spellLogEffectGenericVictimParams . Victim = obj -> GetGUID ();
2015-04-18 18:09:13 +02:00
_genericVictimTargets [ effIndex ]. push_back ( spellLogEffectGenericVictimParams );
2010-08-27 17:49:32 +02:00
}
2015-04-18 17:02:33 +02:00
void Spell :: ExecuteLogEffectResurrect ( uint8 effect , Unit * target )
2010-08-27 17:49:32 +02:00
{
2015-04-18 17:02:33 +02:00
SpellLogEffectGenericVictimParams spellLogEffectGenericVictimParams ;
spellLogEffectGenericVictimParams . Victim = target -> GetGUID ();
_genericVictimTargets [ effect ]. push_back ( spellLogEffectGenericVictimParams );
2010-08-27 17:49:32 +02:00
}
2010-02-20 23:59:05 +01:00
void Spell :: SendInterrupted ( uint8 result )
{
2014-11-30 20:13:23 +02:00
WorldPackets :: Spells :: SpellFailure failurePacket ;
failurePacket . CasterUnit = m_caster -> GetGUID ();
2016-06-05 14:08:53 +02:00
failurePacket . CastID = m_castId ;
2014-11-30 20:13:23 +02:00
failurePacket . SpellID = m_spellInfo -> Id ;
2015-07-19 00:31:11 +02:00
failurePacket . SpelXSpellVisualID = m_SpellVisual ;
2014-11-30 20:13:23 +02:00
failurePacket . Reason = result ;
m_caster -> SendMessageToSet ( failurePacket . Write (), true );
WorldPackets :: Spells :: SpellFailedOther failedPacket ;
failedPacket . CasterUnit = m_caster -> GetGUID ();
2016-06-05 14:08:53 +02:00
failedPacket . CastID = m_castId ;
2014-11-30 20:13:23 +02:00
failedPacket . SpellID = m_spellInfo -> Id ;
failedPacket . Reason = result ;
m_caster -> SendMessageToSet ( failedPacket . Write (), true );
2010-02-20 23:59:05 +01:00
}
void Spell :: SendChannelUpdate ( uint32 time )
{
2010-04-07 19:14:10 +02:00
if ( time == 0 )
2010-02-20 23:59:05 +01:00
{
2014-09-14 16:14:12 +02:00
m_caster -> SetChannelObjectGuid ( ObjectGuid :: Empty );
2010-02-20 23:59:05 +01:00
m_caster -> SetUInt32Value ( UNIT_CHANNEL_SPELL , 0 );
}
2015-04-04 16:04:40 +02:00
WorldPackets :: Spells :: SpellChannelUpdate spellChannelUpdate ;
spellChannelUpdate . CasterGUID = m_caster -> GetGUID ();
spellChannelUpdate . TimeRemaining = time ;
m_caster -> SendMessageToSet ( spellChannelUpdate . Write (), true );
2010-02-20 23:59:05 +01:00
}
void Spell :: SendChannelStart ( uint32 duration )
{
2014-09-14 16:14:12 +02:00
ObjectGuid channelTarget = m_targets . GetObjectTargetGUID ();
2012-09-09 17:52:27 +02:00
if ( ! channelTarget && ! m_spellInfo -> NeedsExplicitUnitTarget ())
if ( m_UniqueTargetInfo . size () + m_UniqueGOTargetInfo . size () == 1 ) // this is for TARGET_SELECT_CATEGORY_NEARBY
2012-09-09 19:22:30 +02:00
channelTarget = ! m_UniqueTargetInfo . empty () ? m_UniqueTargetInfo . front (). targetGUID : m_UniqueGOTargetInfo . front (). targetGUID ;
2010-02-20 23:59:05 +01:00
2015-04-04 16:04:40 +02:00
WorldPackets :: Spells :: SpellChannelStart spellChannelStart ;
spellChannelStart . CasterGUID = m_caster -> GetGUID ();
spellChannelStart . SpellID = m_spellInfo -> Id ;
spellChannelStart . ChannelDuration = duration ;
m_caster -> SendMessageToSet ( spellChannelStart . Write (), true );
2010-02-20 23:59:05 +01:00
2015-07-19 00:31:11 +02:00
uint32 schoolImmunityMask = m_caster -> GetSchoolImmunityMask ();
uint32 mechanicImmunityMask = m_caster -> GetMechanicImmunityMask ();
if ( schoolImmunityMask || mechanicImmunityMask )
{
spellChannelStart . InterruptImmunities = boost :: in_place ();
spellChannelStart . InterruptImmunities -> SchoolImmunities = schoolImmunityMask ;
spellChannelStart . InterruptImmunities -> Immunities = mechanicImmunityMask ;
}
2010-02-20 23:59:05 +01:00
m_timer = duration ;
2014-10-21 20:27:00 +02:00
if ( ! channelTarget . IsEmpty ())
2014-09-14 16:14:12 +02:00
m_caster -> SetChannelObjectGuid ( channelTarget );
2011-08-12 13:22:53 +02:00
2010-02-20 23:59:05 +01:00
m_caster -> SetUInt32Value ( UNIT_CHANNEL_SPELL , m_spellInfo -> Id );
2016-06-29 19:49:23 +02:00
m_caster -> SetUInt32Value ( UNIT_CHANNEL_SPELL_X_SPELL_VISUAL , m_SpellVisual );
2010-02-20 23:59:05 +01:00
}
void Spell :: SendResurrectRequest ( Player * target )
{
2014-05-24 18:25:53 +02:00
// get resurrector name for creature resurrections, otherwise packet will be not accepted
2011-07-12 10:43:58 +02:00
// for player resurrections the name is looked up by guid
2012-10-24 13:29:34 +02:00
std :: string const sentName ( m_caster -> GetTypeId () == TYPEID_PLAYER
2015-04-19 13:45:43 +02:00
? "" : m_caster -> GetNameForLocaleIdx ( target -> GetSession () -> GetSessionDbLocaleIndex ()));
2015-05-02 00:05:01 +02:00
2015-04-19 13:45:43 +02:00
WorldPackets :: Spells :: ResurrectRequest resurrectRequest ;
resurrectRequest . ResurrectOffererGUID = m_caster -> GetGUID ();
resurrectRequest . ResurrectOffererVirtualRealmAddress = GetVirtualRealmAddress ();
2010-02-20 23:59:05 +01:00
2015-04-19 13:45:43 +02:00
if ( Pet * pet = target -> GetPet ())
{
if ( CharmInfo * charmInfo = pet -> GetCharmInfo ())
resurrectRequest . PetNumber = charmInfo -> GetPetNumber ();
}
2010-02-20 23:59:05 +01:00
2015-04-19 13:45:43 +02:00
resurrectRequest . SpellID = m_spellInfo -> Id ;
2010-02-20 23:59:05 +01:00
2015-04-19 13:45:43 +02:00
//packet.ReadBit("UseTimer"); /// @todo: 6.x Has to be implemented
resurrectRequest . Sickness = m_caster -> GetTypeId () != TYPEID_PLAYER ; // "you'll be afflicted with resurrection sickness"
resurrectRequest . Name = sentName ;
target -> GetSession () -> SendPacket ( resurrectRequest . Write ());
2010-02-20 23:59:05 +01:00
}
void Spell :: TakeCastItem ()
{
2013-07-20 21:52:05 +02:00
if ( ! m_CastItem )
return ;
Player * player = m_caster -> ToPlayer ();
if ( ! player )
2010-02-20 23:59:05 +01:00
return ;
// not remove cast item at triggered spell (equipping, weapon damage, etc)
2011-07-31 19:03:06 +02:00
if ( _triggeredCastFlags & TRIGGERED_IGNORE_CAST_ITEM )
2010-02-20 23:59:05 +01:00
return ;
2011-09-15 14:08:17 +02:00
ItemTemplate const * proto = m_CastItem -> GetTemplate ();
2010-02-20 23:59:05 +01:00
2010-04-07 19:14:10 +02:00
if ( ! proto )
2010-02-20 23:59:05 +01:00
{
// This code is to avoid a crash
// I'm not sure, if this is really an error, but I guess every item needs a prototype
2014-10-22 21:22:04 +02:00
TC_LOG_ERROR ( "spells" , "Cast item has no item prototype %s" , m_CastItem -> GetGUID (). ToString (). c_str ());
2010-02-20 23:59:05 +01:00
return ;
}
bool expendable = false ;
bool withoutCharges = false ;
2015-02-21 13:08:33 +01:00
for ( uint8 i = 0 ; i < proto -> Effects . size () && i < 5 ; ++ i )
2010-02-20 23:59:05 +01:00
{
2014-11-14 14:47:20 +02:00
// item has limited charges
2015-02-21 13:08:33 +01:00
if ( proto -> Effects [ i ] -> Charges )
2010-02-20 23:59:05 +01:00
{
2015-02-21 13:08:33 +01:00
if ( proto -> Effects [ i ] -> Charges < 0 )
2014-11-14 14:47:20 +02:00
expendable = true ;
2010-02-20 23:59:05 +01:00
2014-11-14 14:47:20 +02:00
int32 charges = m_CastItem -> GetSpellCharges ( i );
2010-02-20 23:59:05 +01:00
2014-11-14 14:47:20 +02:00
// item has charges left
if ( charges )
{
( charges > 0 ) ? -- charges : ++ charges ; // abs(charges) less at 1 after use
2014-12-21 13:35:43 +01:00
if ( proto -> GetMaxStackSize () == 1 )
2014-11-14 14:47:20 +02:00
m_CastItem -> SetSpellCharges ( i , charges );
m_CastItem -> SetState ( ITEM_CHANGED , player );
2010-02-20 23:59:05 +01:00
}
2014-11-14 14:47:20 +02:00
// all charges used
withoutCharges = ( charges == 0 );
2010-02-20 23:59:05 +01:00
}
}
if ( expendable && withoutCharges )
{
uint32 count = 1 ;
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> DestroyItemCount ( m_CastItem , count , true );
2010-02-20 23:59:05 +01:00
2011-06-23 13:28:52 +02:00
// prevent crash at access to deleted m_targets.GetItemTarget
if ( m_CastItem == m_targets . GetItemTarget ())
m_targets . SetItemTarget ( NULL );
2010-02-20 23:59:05 +01:00
m_CastItem = NULL ;
2014-09-14 16:14:12 +02:00
m_castItemGUID . Clear ();
2014-05-05 20:05:33 +02:00
m_castItemEntry = 0 ;
2010-02-20 23:59:05 +01:00
}
}
void Spell :: TakePower ()
{
2010-04-07 19:14:10 +02:00
if ( m_CastItem || m_triggeredByAuraSpell )
2010-02-20 23:59:05 +01:00
return ;
2012-08-31 01:26:21 +01:00
//Don't take power if the spell is cast while .cheat power is enabled.
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
{
if ( m_caster -> ToPlayer () -> GetCommandStatus ( CHEAT_POWER ))
return ;
}
2015-03-08 13:31:57 +01:00
for ( SpellInfo :: CostData & cost : m_powerCost )
2010-02-20 23:59:05 +01:00
{
2015-03-08 13:31:57 +01:00
Powers powerType = Powers ( cost . Power );
bool hit = true ;
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2014-10-21 20:27:00 +02:00
{
2015-03-08 13:31:57 +01:00
if ( powerType == POWER_RAGE || powerType == POWER_ENERGY || powerType == POWER_RUNES )
2014-10-21 20:27:00 +02:00
{
2015-03-08 13:31:57 +01:00
ObjectGuid targetGUID = m_targets . GetUnitTargetGUID ();
if ( ! targetGUID . IsEmpty ())
2014-10-21 20:27:00 +02:00
{
2015-03-08 13:31:57 +01:00
for ( std :: vector < TargetInfo >:: iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
{
2015-03-08 13:31:57 +01:00
if ( ihit -> targetGUID == targetGUID )
2010-02-20 23:59:05 +01:00
{
2015-03-08 13:31:57 +01:00
if ( ihit -> missCondition != SPELL_MISS_NONE )
{
hit = false ;
//lower spell cost on fail (by talent aura)
if ( Player * modOwner = m_caster -> ToPlayer () -> GetSpellModOwner ())
modOwner -> ApplySpellMod ( m_spellInfo -> Id , SPELLMOD_SPELL_COST_REFUND_ON_FAIL , cost . Amount );
}
break ;
2010-02-20 23:59:05 +01:00
}
}
2014-10-21 20:27:00 +02:00
}
}
}
2010-02-20 23:59:05 +01:00
2015-03-08 13:31:57 +01:00
if ( powerType == POWER_RUNES )
{
TakeRunePower ( hit );
continue ;
}
2010-02-20 23:59:05 +01:00
2015-03-08 13:31:57 +01:00
if ( ! cost . Amount )
continue ;
2010-02-20 23:59:05 +01:00
2015-03-08 13:31:57 +01:00
// health as power used
if ( powerType == POWER_HEALTH )
{
m_caster -> ModifyHealth ( - cost . Amount );
continue ;
}
2010-02-20 23:59:05 +01:00
2015-03-08 13:31:57 +01:00
if ( powerType >= MAX_POWERS )
{
TC_LOG_ERROR ( "spells" , "Spell::TakePower: Unknown power type '%d'" , powerType );
continue ;
}
2010-02-20 23:59:05 +01:00
2015-03-08 13:31:57 +01:00
if ( hit )
m_caster -> ModifyPower ( powerType , - cost . Amount );
else
m_caster -> ModifyPower ( powerType , - irand ( 0 , cost . Amount / 4 ));
}
2010-02-20 23:59:05 +01:00
}
2016-01-24 15:56:10 +01:00
SpellCastResult Spell :: CheckRuneCost ()
2010-02-20 23:59:05 +01:00
{
2016-01-24 15:56:10 +01:00
auto runeCost = std :: find_if ( m_powerCost . begin (), m_powerCost . end (), []( SpellInfo :: CostData const & cost ) { return cost . Power == POWER_RUNES ; });
if ( runeCost == m_powerCost . end ())
2010-02-20 23:59:05 +01:00
return SPELL_CAST_OK ;
2013-07-20 21:52:05 +02:00
Player * player = m_caster -> ToPlayer ();
if ( ! player )
2010-02-20 23:59:05 +01:00
return SPELL_CAST_OK ;
2011-11-07 11:06:39 -06:00
if ( player -> getClass () != CLASS_DEATH_KNIGHT )
2010-02-20 23:59:05 +01:00
return SPELL_CAST_OK ;
2016-01-24 15:56:10 +01:00
int32 readyRunes = 0 ;
2016-01-31 19:25:51 +01:00
for ( int32 i = 0 ; i < player -> GetMaxPower ( POWER_RUNES ); ++ i )
2016-01-24 15:56:10 +01:00
if ( player -> GetRuneCooldown ( i ) == 0 )
++ readyRunes ;
2010-02-20 23:59:05 +01:00
2016-01-24 15:56:10 +01:00
if ( readyRunes < runeCost -> Amount )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NO_POWER ; // not sure if result code is correct
return SPELL_CAST_OK ;
}
2011-04-07 23:13:35 +02:00
void Spell :: TakeRunePower ( bool didHit )
2010-02-20 23:59:05 +01:00
{
2011-07-27 11:00:39 +02:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER || m_caster -> getClass () != CLASS_DEATH_KNIGHT )
2010-02-20 23:59:05 +01:00
return ;
2011-09-15 14:08:17 +02:00
Player * player = m_caster -> ToPlayer ();
2011-07-27 11:00:39 +02:00
m_runesState = player -> GetRunesState (); // store previous state
2010-02-20 23:59:05 +01:00
2016-01-24 15:56:10 +01:00
int32 runeCost = std :: find_if ( m_powerCost . begin (), m_powerCost . end (), []( SpellInfo :: CostData const & cost )
2010-02-20 23:59:05 +01:00
{
2016-01-24 15:56:10 +01:00
return cost . Power == POWER_RUNES ;
}) -> Amount ;
2010-02-20 23:59:05 +01:00
2016-01-31 19:25:51 +01:00
for ( int32 i = 0 ; i < player -> GetMaxPower ( POWER_RUNES ); ++ i )
2010-02-20 23:59:05 +01:00
{
2016-01-24 15:56:10 +01:00
if ( ! player -> GetRuneCooldown ( i ) && runeCost > 0 )
2010-02-20 23:59:05 +01:00
{
2016-01-24 15:56:10 +01:00
player -> SetRuneCooldown ( i , didHit ? player -> GetRuneBaseCooldown () : uint32 ( RUNE_MISS_COOLDOWN ), true );
-- runeCost ;
2010-02-20 23:59:05 +01:00
}
}
}
void Spell :: TakeReagents ()
{
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return ;
2012-05-30 08:01:02 +02:00
ItemTemplate const * castItemTemplate = m_CastItem ? m_CastItem -> GetTemplate () : NULL ;
2011-09-05 14:01:50 +02:00
2010-02-20 23:59:05 +01:00
// do not take reagents for these item casts
2016-09-09 10:22:57 +02:00
if ( castItemTemplate && castItemTemplate -> GetFlags () & ITEM_FLAG_NO_REAGENT_COST )
2010-02-20 23:59:05 +01:00
return ;
2011-09-05 14:01:50 +02:00
Player * p_caster = m_caster -> ToPlayer ();
2010-02-20 23:59:05 +01:00
if ( p_caster -> CanNoReagentCast ( m_spellInfo ))
return ;
2010-09-28 08:41:24 +03:00
for ( uint32 x = 0 ; x < MAX_SPELL_REAGENTS ; ++ x )
2010-02-20 23:59:05 +01:00
{
2010-04-07 19:14:10 +02:00
if ( m_spellInfo -> Reagent [ x ] <= 0 )
2010-02-20 23:59:05 +01:00
continue ;
uint32 itemid = m_spellInfo -> Reagent [ x ];
uint32 itemcount = m_spellInfo -> ReagentCount [ x ];
// if CastItem is also spell reagent
2014-12-21 13:35:43 +01:00
if ( castItemTemplate && castItemTemplate -> GetId () == itemid )
2010-02-20 23:59:05 +01:00
{
2015-02-21 13:08:33 +01:00
for ( uint8 s = 0 ; s < castItemTemplate -> Effects . size () && s < 5 ; ++ s )
2010-02-20 23:59:05 +01:00
{
2011-09-05 14:01:50 +02:00
// CastItem will be used up and does not count as reagent
int32 charges = m_CastItem -> GetSpellCharges ( s );
2015-02-21 13:08:33 +01:00
if ( castItemTemplate -> Effects [ s ] -> Charges < 0 && abs ( charges ) < 2 )
2010-02-20 23:59:05 +01:00
{
2011-09-05 14:01:50 +02:00
++ itemcount ;
break ;
2010-02-20 23:59:05 +01:00
}
}
2011-09-05 14:01:50 +02:00
m_CastItem = NULL ;
2014-09-14 16:14:12 +02:00
m_castItemGUID . Clear ();
2014-05-05 20:05:33 +02:00
m_castItemEntry = 0 ;
2010-02-20 23:59:05 +01:00
}
2011-06-23 13:28:52 +02:00
// if GetItemTarget is also spell reagent
if ( m_targets . GetItemTargetEntry () == itemid )
m_targets . SetItemTarget ( NULL );
2010-02-20 23:59:05 +01:00
p_caster -> DestroyItemCount ( itemid , itemcount , true );
}
}
2011-07-26 23:09:28 +02:00
void Spell :: HandleThreatSpells ()
2010-02-20 23:59:05 +01:00
{
2011-08-21 12:00:36 +02:00
if ( m_UniqueTargetInfo . empty ())
2010-02-20 23:59:05 +01:00
return ;
2016-02-10 22:35:23 +01:00
if ( ! m_spellInfo -> HasInitialAggro ())
2010-02-20 23:59:05 +01:00
return ;
2011-08-21 12:00:36 +02:00
float threat = 0.0f ;
if ( SpellThreatEntry const * threatEntry = sSpellMgr -> GetSpellThreatEntry ( m_spellInfo -> Id ))
{
if ( threatEntry -> apPctMod != 0.0f )
threat += threatEntry -> apPctMod * m_caster -> GetTotalAttackPowerValue ( BASE_ATTACK );
threat += threatEntry -> flatMod ;
}
2016-02-10 22:35:23 +01:00
else if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR0_CU_NO_INITIAL_THREAT ))
2011-08-21 12:00:36 +02:00
threat += m_spellInfo -> SpellLevel ;
2010-02-20 23:59:05 +01:00
2011-08-21 12:00:36 +02:00
// past this point only multiplicative effects occur
if ( threat == 0.0f )
2010-02-20 23:59:05 +01:00
return ;
2011-08-21 12:00:36 +02:00
// since 2.0.1 threat from positive effects also is distributed among all targets, so the overall caused threat is at most the defined bonus
threat /= m_UniqueTargetInfo . size ();
2015-02-12 22:08:17 +00:00
for ( std :: vector < TargetInfo >:: iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2011-08-21 12:00:36 +02:00
{
2014-09-26 22:26:51 +02:00
float threatToAdd = threat ;
2011-08-21 12:00:36 +02:00
if ( ihit -> missCondition != SPELL_MISS_NONE )
2014-09-26 22:26:51 +02:00
threatToAdd = 0.0f ;
2011-08-21 12:00:36 +02:00
Unit * target = ObjectAccessor :: GetUnit ( * m_caster , ihit -> targetGUID );
if ( ! target )
continue ;
// positive spells distribute threat among all units that are in combat with target, like healing
if ( m_spellInfo -> _IsPositiveSpell ())
2014-09-26 22:26:51 +02:00
target -> getHostileRefManager (). threatAssist ( m_caster , threatToAdd , m_spellInfo );
2011-08-21 12:00:36 +02:00
// for negative spells threat gets distributed among affected targets
else
{
if ( ! target -> CanHaveThreatList ())
continue ;
2010-02-20 23:59:05 +01:00
2014-09-26 22:26:51 +02:00
target -> AddThreat ( m_caster , threatToAdd , m_spellInfo -> GetSchoolMask (), m_spellInfo );
2011-08-21 12:00:36 +02:00
}
}
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "Spell %u, added an additional %f threat for %s %u target(s)" , m_spellInfo -> Id , threat , m_spellInfo -> _IsPositiveSpell () ? "assisting" : "harming" , uint32 ( m_UniqueTargetInfo . size ()));
2010-02-20 23:59:05 +01:00
}
2011-09-25 13:29:17 +02:00
void Spell :: HandleEffects ( Unit * pUnitTarget , Item * pItemTarget , GameObject * pGOTarget , uint32 i , SpellEffectHandleMode mode )
2010-02-20 23:59:05 +01:00
{
2011-09-25 13:29:17 +02:00
effectHandleMode = mode ;
2010-02-20 23:59:05 +01:00
unitTarget = pUnitTarget ;
itemTarget = pItemTarget ;
gameObjTarget = pGOTarget ;
2012-05-30 08:01:02 +02:00
destTarget = & m_destTargets [ i ]. _position ;
2010-02-20 23:59:05 +01:00
2014-12-19 23:52:29 +01:00
effectInfo = GetEffect ( i );
if ( ! effectInfo )
2014-11-16 14:20:01 +01:00
{
TC_LOG_ERROR ( "spells" , "Spell: %u HandleEffects at EffectIndex: %u missing effect" , m_spellInfo -> Id , i );
return ;
}
2014-12-19 23:52:29 +01:00
uint32 eff = effectInfo -> Effect ;
2010-02-20 23:59:05 +01:00
2014-11-16 14:20:01 +01:00
TC_LOG_DEBUG ( "spells" , "Spell: %u Effect: %u" , m_spellInfo -> Id , eff );
2010-02-20 23:59:05 +01:00
2014-12-19 18:55:09 +01:00
damage = CalculateDamage ( i , unitTarget , & variance );
2010-07-25 16:23:57 +02:00
2011-09-25 13:29:17 +02:00
bool preventDefault = CallScriptEffectHandlers (( SpellEffIndex ) i , mode );
2010-07-24 22:41:42 +02:00
2010-08-19 14:31:31 +02:00
if ( ! preventDefault && eff < TOTAL_SPELL_EFFECTS )
2010-02-20 23:59:05 +01:00
{
2010-08-27 19:36:27 +02:00
( this ->* SpellEffects [ eff ])(( SpellEffIndex ) i );
2010-02-20 23:59:05 +01:00
}
}
SpellCastResult Spell :: CheckCast ( bool strict )
{
2010-09-08 07:01:55 +03:00
// check death state
2016-10-01 17:51:05 +02:00
if ( ! m_caster -> IsAlive () && ! m_spellInfo -> IsPassive () && ! ( m_spellInfo -> HasAttribute ( SPELL_ATTR0_CASTABLE_WHILE_DEAD ) || ( IsTriggered () && ! m_triggeredByAuraSpell )))
2010-09-08 07:01:55 +03:00
return SPELL_FAILED_CASTER_DEAD ;
2010-02-20 23:59:05 +01:00
// check cooldowns to prevent cheating
2015-02-17 01:01:44 +01:00
if ( ! m_spellInfo -> IsPassive ())
2010-02-20 23:59:05 +01:00
{
2015-02-17 01:01:44 +01:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
{
//can cast triggered (by aura only?) spells while have this flag
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_CASTER_AURASTATE ) && m_caster -> ToPlayer () -> HasFlag ( PLAYER_FLAGS , PLAYER_ALLOW_ONLY_ABILITY ))
return SPELL_FAILED_SPELL_IN_PROGRESS ;
2010-02-20 23:59:05 +01:00
2015-02-17 01:01:44 +01:00
// check if we are using a potion in combat for the 2nd+ time. Cooldown is added only after caster gets out of combat
if ( m_caster -> ToPlayer () -> GetLastPotionId () && m_CastItem && ( m_CastItem -> IsPotion () || m_spellInfo -> IsCooldownStartedOnEvent ()))
return SPELL_FAILED_NOT_READY ;
}
2016-01-22 22:11:11 +01:00
if ( ! m_caster -> GetSpellHistory () -> IsReady ( m_spellInfo , m_castItemEntry , IsIgnoringCooldowns ()))
2010-02-20 23:59:05 +01:00
{
2010-04-07 19:14:10 +02:00
if ( m_triggeredByAuraSpell )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_DONT_REPORT ;
else
return SPELL_FAILED_NOT_READY ;
}
}
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR7_IS_CHEAT_SPELL ) && ! m_caster -> HasFlag ( UNIT_FIELD_FLAGS_2 , UNIT_FLAG2_ALLOW_CHEAT_SPELLS ))
2011-10-02 16:23:52 +02:00
{
m_customError = SPELL_CUSTOM_ERROR_GM_ONLY ;
return SPELL_FAILED_CUSTOM_ERROR ;
}
2011-06-11 13:02:54 +02:00
2011-02-22 17:02:47 +06:00
// Check global cooldown
2011-07-31 19:03:06 +02:00
if ( strict && ! ( _triggeredCastFlags & TRIGGERED_IGNORE_GCD ) && HasGlobalCooldown ())
2016-08-21 11:32:42 +02:00
return ! m_spellInfo -> HasAttribute ( SPELL_ATTR0_DISABLED_WHILE_ACTIVE ) ? SPELL_FAILED_NOT_READY : SPELL_FAILED_DONT_REPORT ;
2011-02-22 17:02:47 +06:00
2011-07-31 19:03:06 +02:00
// only triggered spells can be processed an ended battleground
if ( ! IsTriggered () && m_caster -> GetTypeId () == TYPEID_PLAYER )
2011-06-11 22:35:29 +02:00
if ( Battleground * bg = m_caster -> ToPlayer () -> GetBattleground ())
2010-04-07 19:14:10 +02:00
if ( bg -> GetStatus () == STATUS_WAIT_LEAVE )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_DONT_REPORT ;
2011-06-12 02:30:32 +02:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER && VMAP :: VMapFactory :: createOrGetVMapManager () -> isLineOfSightCalcEnabled ())
2010-06-05 00:59:25 +02:00
{
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR0_OUTDOORS_ONLY ) &&
2010-06-05 00:59:25 +02:00
! m_caster -> GetMap () -> IsOutdoors ( m_caster -> GetPositionX (), m_caster -> GetPositionY (), m_caster -> GetPositionZ ()))
return SPELL_FAILED_ONLY_OUTDOORS ;
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR0_INDOORS_ONLY ) &&
2010-06-05 00:59:25 +02:00
m_caster -> GetMap () -> IsOutdoors ( m_caster -> GetPositionX (), m_caster -> GetPositionY (), m_caster -> GetPositionZ ()))
return SPELL_FAILED_ONLY_INDOORS ;
}
2010-02-20 23:59:05 +01:00
// only check at first call, Stealth auras are already removed at second call
// for now, ignore triggered spells
2011-07-31 19:03:06 +02:00
if ( strict && ! ( _triggeredCastFlags & TRIGGERED_IGNORE_SHAPESHIFT ))
2010-02-20 23:59:05 +01:00
{
bool checkForm = true ;
// Ignore form req aura
Unit :: AuraEffectList const & ignore = m_caster -> GetAuraEffectsByType ( SPELL_AURA_MOD_IGNORE_SHAPESHIFT );
for ( Unit :: AuraEffectList :: const_iterator i = ignore . begin (); i != ignore . end (); ++ i )
{
2011-11-26 23:38:06 +02:00
if ( ! ( * i ) -> IsAffectingSpell ( m_spellInfo ))
2010-02-20 23:59:05 +01:00
continue ;
checkForm = false ;
break ;
}
if ( checkForm )
{
// Cannot be used in this stance/form
2011-07-26 23:09:28 +02:00
SpellCastResult shapeError = m_spellInfo -> CheckShapeshift ( m_caster -> GetShapeshiftForm ());
2010-04-07 19:14:10 +02:00
if ( shapeError != SPELL_CAST_OK )
2010-02-20 23:59:05 +01:00
return shapeError ;
2015-01-05 23:49:43 +02:00
if (( m_spellInfo -> HasAttribute ( SPELL_ATTR0_ONLY_STEALTHED )) && ! ( m_caster -> HasStealthAura ()))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ONLY_STEALTHED ;
}
}
2011-10-02 16:23:52 +02:00
Unit :: AuraEffectList const & blockSpells = m_caster -> GetAuraEffectsByType ( SPELL_AURA_BLOCK_SPELL_FAMILY );
for ( Unit :: AuraEffectList :: const_iterator blockItr = blockSpells . begin (); blockItr != blockSpells . end (); ++ blockItr )
2012-02-16 13:56:08 +01:00
if ( uint32 (( * blockItr ) -> GetMiscValue ()) == m_spellInfo -> SpellFamilyName )
2011-10-02 16:23:52 +02:00
return SPELL_FAILED_SPELL_UNAVAILABLE ;
bool reqCombat = true ;
2010-02-20 23:59:05 +01:00
Unit :: AuraEffectList const & stateAuras = m_caster -> GetAuraEffectsByType ( SPELL_AURA_ABILITY_IGNORE_AURASTATE );
for ( Unit :: AuraEffectList :: const_iterator j = stateAuras . begin (); j != stateAuras . end (); ++ j )
{
2011-11-26 23:38:06 +02:00
if (( * j ) -> IsAffectingSpell ( m_spellInfo ))
2010-02-20 23:59:05 +01:00
{
2010-09-08 10:59:10 +02:00
m_needComboPoints = false ;
2010-04-07 23:25:02 +02:00
if (( * j ) -> GetMiscValue () == 1 )
2010-02-20 23:59:05 +01:00
{
reqCombat = false ;
break ;
}
}
}
// caster state requirements
// not for triggered spells (needed by execute)
2011-07-31 19:03:06 +02:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_CASTER_AURASTATE ))
2010-02-20 23:59:05 +01:00
{
2011-07-26 23:09:28 +02:00
if ( m_spellInfo -> CasterAuraState && ! m_caster -> HasAuraState ( AuraStateType ( m_spellInfo -> CasterAuraState ), m_spellInfo , m_caster ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CASTER_AURASTATE ;
2014-11-09 23:53:48 +02:00
if ( m_spellInfo -> ExcludeCasterAuraState && m_caster -> HasAuraState ( AuraStateType ( m_spellInfo -> ExcludeCasterAuraState ), m_spellInfo , m_caster ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CASTER_AURASTATE ;
// Note: spell 62473 requres casterAuraSpell = triggering spell
2014-11-16 14:20:01 +01:00
if ( m_spellInfo -> CasterAuraSpell && ! m_caster -> HasAura ( m_spellInfo -> CasterAuraSpell ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CASTER_AURASTATE ;
2014-11-16 14:20:01 +01:00
if ( m_spellInfo -> ExcludeCasterAuraSpell && m_caster -> HasAura ( m_spellInfo -> ExcludeCasterAuraSpell ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CASTER_AURASTATE ;
2013-06-11 19:54:27 -02:30
if ( reqCombat && m_caster -> IsInCombat () && ! m_spellInfo -> CanBeUsedInCombat ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_AFFECTING_COMBAT ;
}
// cancel autorepeat spells if cast start when moving
// (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
2012-09-10 18:20:26 -05:00
// Do not cancel spells which are affected by a SPELL_AURA_CAST_WHILE_WALKING effect
2016-03-26 18:41:03 +01:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER && m_caster -> ToPlayer () -> isMoving () && ( ! m_caster -> IsCharmed () || ! m_caster -> GetCharmerGUID (). IsCreature ()) && ! m_caster -> HasAuraTypeWithAffectMask ( SPELL_AURA_CAST_WHILE_WALKING , m_spellInfo ))
2010-02-20 23:59:05 +01:00
{
// skip stuck spell to allow use it in falling case and apply spell limitations at movement
2014-11-16 14:20:01 +01:00
SpellEffectInfo const * effect = GetEffect ( EFFECT_0 );
if (( ! m_caster -> HasUnitMovementFlag ( MOVEMENTFLAG_FALLING_FAR ) || ( effect && effect -> Effect != SPELL_EFFECT_STUCK )) &&
2010-04-07 22:59:46 +02:00
( IsAutoRepeat () || ( m_spellInfo -> AuraInterruptFlags & AURA_INTERRUPT_FLAG_NOT_SEATED ) != 0 ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_MOVING ;
}
2013-02-27 13:17:20 +01:00
// Check vehicle flags
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_CASTER_MOUNTED_OR_ON_VEHICLE ))
2011-07-30 20:36:19 +02:00
{
2013-02-27 13:17:20 +01:00
SpellCastResult vehicleCheck = m_spellInfo -> CheckVehicle ( m_caster );
if ( vehicleCheck != SPELL_CAST_OK )
return vehicleCheck ;
2011-07-30 20:36:19 +02:00
}
2012-02-10 23:40:38 +01:00
// check spell cast conditions from database
2012-02-09 18:35:52 +01:00
{
2015-10-25 13:20:28 +01:00
ConditionSourceInfo condInfo = ConditionSourceInfo ( m_caster , m_targets . GetObjectTarget ());
if ( ! sConditionMgr -> IsObjectMeetingNotGroupedConditions ( CONDITION_SOURCE_TYPE_SPELL , m_spellInfo -> Id , condInfo ))
2012-02-10 23:40:38 +01:00
{
2012-11-24 02:45:48 +01:00
// mLastFailedCondition can be NULL if there was an error processing the condition in Condition::Meets (i.e. wrong data for ConditionTarget or others)
if ( condInfo . mLastFailedCondition && condInfo . mLastFailedCondition -> ErrorType )
2012-02-10 23:40:38 +01:00
{
2012-11-24 02:45:48 +01:00
if ( condInfo . mLastFailedCondition -> ErrorType == SPELL_FAILED_CUSTOM_ERROR )
m_customError = SpellCustomErrors ( condInfo . mLastFailedCondition -> ErrorTextId );
return SpellCastResult ( condInfo . mLastFailedCondition -> ErrorType );
2012-02-10 23:40:38 +01:00
}
2016-04-09 15:31:26 +02:00
2012-05-30 08:01:02 +02:00
if ( ! condInfo . mLastFailedCondition || ! condInfo . mLastFailedCondition -> ConditionTarget )
return SPELL_FAILED_CASTER_AURASTATE ;
return SPELL_FAILED_BAD_TARGETS ;
2012-02-10 23:40:38 +01:00
}
2012-02-09 18:35:52 +01:00
}
2011-09-06 11:21:40 +02:00
// Don't check explicit target for passive spells (workaround) (check should be skipped only for learn case)
// those spells may have incorrect target entries or not filled at all (for example 15332)
// such spells when learned are not targeting anyone using targeting system, they should apply directly to caster instead
// also, such casts shouldn't be sent to client
2016-10-01 17:51:05 +02:00
if ( ! ( m_spellInfo -> IsPassive () && ( ! m_targets . GetUnitTarget () || m_targets . GetUnitTarget () == m_caster )))
2011-08-26 12:05:47 +02:00
{
2011-09-03 20:38:23 +02:00
// Check explicit target for m_originalCaster - todo: get rid of such workarounds
SpellCastResult castResult = m_spellInfo -> CheckExplicitTarget ( m_originalCaster ? m_originalCaster : m_caster , m_targets . GetObjectTarget (), m_targets . GetItemTarget ());
2011-08-26 12:05:47 +02:00
if ( castResult != SPELL_CAST_OK )
return castResult ;
}
2011-08-24 08:07:59 +02:00
if ( Unit * target = m_targets . GetUnitTarget ())
2010-02-20 23:59:05 +01:00
{
2011-08-24 08:07:59 +02:00
SpellCastResult castResult = m_spellInfo -> CheckTarget ( m_caster , target , false );
if ( castResult != SPELL_CAST_OK )
return castResult ;
2010-02-20 23:59:05 +01:00
2016-10-15 16:32:18 +02:00
// If it's not a melee spell, check if vision is obscured by SPELL_AURA_INTERFERE_TARGETTING
if ( m_spellInfo -> DmgClass != SPELL_DAMAGE_CLASS_MELEE )
{
for ( auto const & itr : m_caster -> GetAuraEffectsByType ( SPELL_AURA_INTERFERE_TARGETTING ))
if ( ! m_caster -> IsFriendlyTo ( itr -> GetCaster ()) && ! target -> HasAura ( itr -> GetId (), itr -> GetCasterGUID ()))
return SPELL_FAILED_VISION_OBSCURED ;
for ( auto const & itr : target -> GetAuraEffectsByType ( SPELL_AURA_INTERFERE_TARGETTING ))
if ( ! m_caster -> IsFriendlyTo ( itr -> GetCaster ()) && ( ! target -> HasAura ( itr -> GetId (), itr -> GetCasterGUID ()) || ! m_caster -> HasAura ( itr -> GetId (), itr -> GetCasterGUID ())))
return SPELL_FAILED_VISION_OBSCURED ;
}
2011-08-19 14:53:40 +02:00
if ( target != m_caster )
{
// Must be behind the target
2015-01-05 23:49:43 +02:00
if (( m_spellInfo -> HasAttribute ( SPELL_ATTR0_CU_REQ_CASTER_BEHIND_TARGET )) && target -> HasInArc ( static_cast < float > ( M_PI ), m_caster ))
2011-08-19 14:53:40 +02:00
return SPELL_FAILED_NOT_BEHIND ;
2010-02-20 23:59:05 +01:00
2011-08-19 14:53:40 +02:00
// Target must be facing you
2015-01-05 23:49:43 +02:00
if (( m_spellInfo -> HasAttribute ( SPELL_ATTR0_CU_REQ_TARGET_FACING_CASTER )) && ! target -> HasInArc ( static_cast < float > ( M_PI ), m_caster ))
2011-08-19 14:53:40 +02:00
return SPELL_FAILED_NOT_INFRONT ;
2010-02-20 23:59:05 +01:00
2013-12-25 14:16:55 -03:30
if ( m_caster -> GetEntry () != WORLD_TRIGGER ) // Ignore LOS for gameobjects casts (wrongly cast by a trigger)
2014-07-25 14:47:07 +02:00
{
2014-07-25 14:04:12 +01:00
WorldObject * losTarget = m_caster ;
2014-07-25 14:47:07 +02:00
if ( IsTriggered () && m_triggeredByAuraSpell )
2014-07-25 14:04:12 +01:00
if ( DynamicObject * dynObj = m_caster -> GetDynObject ( m_triggeredByAuraSpell -> Id ))
2014-07-25 14:47:07 +02:00
losTarget = dynObj ;
2014-08-04 18:56:17 +02:00
2015-01-05 23:49:43 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR2_CAN_TARGET_NOT_IN_LOS ) && ! DisableMgr :: IsDisabledFor ( DISABLE_TYPE_SPELL , m_spellInfo -> Id , NULL , SPELL_DISABLE_LOS ) && ! target -> IsWithinLOSInMap ( losTarget ))
2012-05-30 08:01:02 +02:00
return SPELL_FAILED_LINE_OF_SIGHT ;
2014-07-25 14:47:07 +02:00
}
2010-02-20 23:59:05 +01:00
}
2011-09-16 22:17:20 +02:00
}
2010-02-20 23:59:05 +01:00
2012-05-28 04:07:51 +02:00
// Check for line of sight for spells with dest
2012-02-02 19:06:28 +01:00
if ( m_targets . HasDst ())
{
float x , y , z ;
2012-05-30 08:01:02 +02:00
m_targets . GetDstPos () -> GetPosition ( x , y , z );
2012-02-02 19:06:28 +01:00
2015-01-05 23:49:43 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR2_CAN_TARGET_NOT_IN_LOS ) && ! DisableMgr :: IsDisabledFor ( DISABLE_TYPE_SPELL , m_spellInfo -> Id , NULL , SPELL_DISABLE_LOS ) && ! m_caster -> IsWithinLOS ( x , y , z ))
2012-02-02 19:06:28 +01:00
return SPELL_FAILED_LINE_OF_SIGHT ;
}
2011-09-16 22:17:20 +02:00
// check pet presence
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2011-09-16 22:17:20 +02:00
{
2014-11-27 15:11:43 +01:00
if ( effect && effect -> TargetA . GetTarget () == TARGET_UNIT_PET )
2010-02-20 23:59:05 +01:00
{
2011-09-16 22:17:20 +02:00
if ( ! m_caster -> GetGuardianPet ())
2010-02-20 23:59:05 +01:00
{
2011-09-16 22:17:20 +02:00
if ( m_triggeredByAuraSpell ) // not report pet not existence for triggered spells
return SPELL_FAILED_DONT_REPORT ;
else
return SPELL_FAILED_NO_PET ;
2010-02-20 23:59:05 +01:00
}
2011-09-16 22:17:20 +02:00
break ;
2010-02-20 23:59:05 +01:00
}
}
2013-12-25 14:16:55 -03:30
// Spell cast only in battleground
2015-01-05 23:49:43 +02:00
if (( m_spellInfo -> HasAttribute ( SPELL_ATTR3_BATTLEGROUND )) && m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-08-08 04:37:24 +02:00
if ( ! m_caster -> ToPlayer () -> InBattleground ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ONLY_BATTLEGROUNDS ;
2012-08-22 20:33:45 +03:00
// do not allow spells to be cast in arenas or rated battlegrounds
2013-01-14 11:12:58 +01:00
if ( Player * player = m_caster -> ToPlayer ())
2012-08-22 20:33:45 +03:00
if ( player -> InArena () /* || player->InRatedBattleGround() NYI*/ )
{
SpellCastResult castResult = CheckArenaAndRatedBattlegroundCastRules ();
if ( castResult != SPELL_CAST_OK )
return castResult ;
}
2010-02-20 23:59:05 +01:00
// zone check
2013-06-11 21:25:12 -02:30
if ( m_caster -> GetTypeId () == TYPEID_UNIT || ! m_caster -> ToPlayer () -> IsGameMaster ())
2010-02-20 23:59:05 +01:00
{
uint32 zone , area ;
2011-04-29 20:47:02 +02:00
m_caster -> GetZoneAndAreaId ( zone , area );
2010-02-20 23:59:05 +01:00
2014-01-30 02:40:12 +01:00
SpellCastResult locRes = m_spellInfo -> CheckLocation ( m_caster -> GetMapId (), zone , area , m_caster -> ToPlayer ());
2010-04-07 19:14:10 +02:00
if ( locRes != SPELL_CAST_OK )
2010-02-20 23:59:05 +01:00
return locRes ;
}
// not let players cast spells at mount (and let do it to creatures)
2011-07-31 19:03:06 +02:00
if ( m_caster -> IsMounted () && m_caster -> GetTypeId () == TYPEID_PLAYER && ! ( _triggeredCastFlags & TRIGGERED_IGNORE_CASTER_MOUNTED_OR_ON_VEHICLE ) &&
2015-01-05 23:49:43 +02:00
! m_spellInfo -> IsPassive () && ! m_spellInfo -> HasAttribute ( SPELL_ATTR0_CASTABLE_WHILE_MOUNTED ))
2010-02-20 23:59:05 +01:00
{
2013-06-11 19:54:27 -02:30
if ( m_caster -> IsInFlight ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NOT_ON_TAXI ;
else
return SPELL_FAILED_NOT_MOUNTED ;
}
2013-08-14 15:45:36 +02:00
// check spell focus object
if ( m_spellInfo -> RequiresSpellFocus )
{
focusObject = SearchSpellFocus ();
if ( ! focusObject )
return SPELL_FAILED_REQUIRES_SPELL_FOCUS ;
}
2010-10-22 17:22:38 -03:00
SpellCastResult castResult = SPELL_CAST_OK ;
2013-08-14 15:45:36 +02:00
// always (except passive spells) check items (only player related checks)
2011-07-26 23:09:28 +02:00
if ( ! m_spellInfo -> IsPassive ())
2010-02-20 23:59:05 +01:00
{
2010-10-22 17:22:38 -03:00
castResult = CheckItems ();
2010-04-07 19:14:10 +02:00
if ( castResult != SPELL_CAST_OK )
2010-02-20 23:59:05 +01:00
return castResult ;
}
2010-10-22 17:22:38 -03:00
// Triggered spells also have range check
2013-03-08 21:41:30 +01:00
/// @todo determine if there is some flag to enable/disable the check
2010-10-22 17:22:38 -03:00
castResult = CheckRange ( strict );
if ( castResult != SPELL_CAST_OK )
return castResult ;
2011-07-31 19:03:06 +02:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_POWER_AND_REAGENT_COST ))
2010-02-20 23:59:05 +01:00
{
castResult = CheckPower ();
2010-04-07 19:14:10 +02:00
if ( castResult != SPELL_CAST_OK )
2010-02-20 23:59:05 +01:00
return castResult ;
2011-07-31 19:03:06 +02:00
}
2011-08-01 11:17:34 +02:00
2011-07-31 19:03:06 +02:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_CASTER_AURAS ))
{
2010-02-20 23:59:05 +01:00
castResult = CheckCasterAuras ();
2010-04-07 19:14:10 +02:00
if ( castResult != SPELL_CAST_OK )
2010-02-20 23:59:05 +01:00
return castResult ;
}
2011-03-04 21:18:38 +01:00
// script hook
castResult = CallScriptCheckCastHandlers ();
if ( castResult != SPELL_CAST_OK )
return castResult ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2014-11-27 15:11:43 +01:00
if ( ! effect )
continue ;
2010-02-20 23:59:05 +01:00
// for effects of spells that have only one target
2014-11-16 14:20:01 +01:00
switch ( effect -> Effect )
2010-02-20 23:59:05 +01:00
{
case SPELL_EFFECT_DUMMY :
{
2012-05-30 08:01:02 +02:00
if ( m_spellInfo -> Id == 19938 ) // Awaken Peon
2010-02-20 23:59:05 +01:00
{
2011-09-15 14:08:17 +02:00
Unit * unit = m_targets . GetUnitTarget ();
2010-04-07 19:14:10 +02:00
if ( ! unit || ! unit -> HasAura ( 17743 ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
}
else if ( m_spellInfo -> Id == 31789 ) // Righteous Defense
{
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return SPELL_FAILED_DONT_REPORT ;
2011-06-23 13:28:52 +02:00
Unit * target = m_targets . GetUnitTarget ();
2010-02-20 23:59:05 +01:00
if ( ! target || ! target -> IsFriendlyTo ( m_caster ) || target -> getAttackers (). empty ())
return SPELL_FAILED_BAD_TARGETS ;
}
break ;
}
case SPELL_EFFECT_LEARN_SPELL :
{
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return SPELL_FAILED_BAD_TARGETS ;
2014-11-16 14:20:01 +01:00
if ( effect -> TargetA . GetTarget () != TARGET_UNIT_PET )
2010-02-20 23:59:05 +01:00
break ;
2010-03-07 15:20:19 +01:00
Pet * pet = m_caster -> ToPlayer () -> GetPet ();
2010-02-20 23:59:05 +01:00
2010-04-07 19:14:10 +02:00
if ( ! pet )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NO_PET ;
2014-11-16 14:20:01 +01:00
SpellInfo const * learn_spellproto = sSpellMgr -> GetSpellInfo ( effect -> TriggerSpell );
2010-02-20 23:59:05 +01:00
2010-04-07 19:14:10 +02:00
if ( ! learn_spellproto )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NOT_KNOWN ;
2011-07-26 23:09:28 +02:00
if ( m_spellInfo -> SpellLevel > pet -> getLevel ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_LOWLEVEL ;
break ;
}
2013-07-06 15:03:23 +02:00
case SPELL_EFFECT_UNLOCK_GUILD_VAULT_TAB :
{
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return SPELL_FAILED_BAD_TARGETS ;
if ( Guild * guild = m_caster -> ToPlayer () -> GetGuild ())
if ( guild -> GetLeaderGUID () != m_caster -> ToPlayer () -> GetGUID ())
return SPELL_FAILED_CANT_DO_THAT_RIGHT_NOW ;
break ;
}
2010-02-20 23:59:05 +01:00
case SPELL_EFFECT_LEARN_PET_SPELL :
{
2011-09-24 02:01:18 +02:00
// check target only for unit target case
2015-07-21 00:33:36 +02:00
if ( Unit * unit = m_targets . GetUnitTarget ())
2011-09-24 02:01:18 +02:00
{
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return SPELL_FAILED_BAD_TARGETS ;
2010-02-20 23:59:05 +01:00
2015-07-21 00:33:36 +02:00
Pet * pet = unit -> ToPet ();
2011-09-24 02:01:18 +02:00
if ( ! pet || pet -> GetOwner () != m_caster )
return SPELL_FAILED_BAD_TARGETS ;
2010-02-20 23:59:05 +01:00
2014-11-16 14:20:01 +01:00
SpellInfo const * learn_spellproto = sSpellMgr -> GetSpellInfo ( effect -> TriggerSpell );
2010-02-20 23:59:05 +01:00
2011-09-24 02:01:18 +02:00
if ( ! learn_spellproto )
return SPELL_FAILED_NOT_KNOWN ;
2010-02-20 23:59:05 +01:00
2011-09-24 02:01:18 +02:00
if ( m_spellInfo -> SpellLevel > pet -> getLevel ())
return SPELL_FAILED_LOWLEVEL ;
}
2010-02-20 23:59:05 +01:00
break ;
}
case SPELL_EFFECT_APPLY_GLYPH :
{
2016-08-25 19:12:00 +02:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return SPELL_FAILED_GLYPH_NO_SPEC ;
Player * caster = m_caster -> ToPlayer ();
if ( ! caster -> HasSpell ( m_misc . SpellId ))
return SPELL_FAILED_NOT_KNOWN ;
if ( uint32 glyphId = effect -> MiscValue )
{
GlyphPropertiesEntry const * glyphProperties = sGlyphPropertiesStore . LookupEntry ( glyphId );
if ( ! glyphProperties )
return SPELL_FAILED_INVALID_GLYPH ;
std :: vector < uint32 > const * glyphBindableSpells = sDB2Manager . GetGlyphBindableSpells ( glyphId );
if ( ! glyphBindableSpells )
return SPELL_FAILED_INVALID_GLYPH ;
if ( std :: find ( glyphBindableSpells -> begin (), glyphBindableSpells -> end (), m_misc . SpellId ) == glyphBindableSpells -> end ())
return SPELL_FAILED_INVALID_GLYPH ;
if ( std :: vector < uint32 > const * glyphRequiredSpecs = sDB2Manager . GetGlyphRequiredSpecs ( glyphId ))
{
if ( ! caster -> GetUInt32Value ( PLAYER_FIELD_CURRENT_SPEC_ID ))
return SPELL_FAILED_GLYPH_NO_SPEC ;
if ( std :: find ( glyphRequiredSpecs -> begin (), glyphRequiredSpecs -> end (), caster -> GetUInt32Value ( PLAYER_FIELD_CURRENT_SPEC_ID )) == glyphRequiredSpecs -> end ())
return SPELL_FAILED_GLYPH_INVALID_SPEC ;
}
uint32 replacedGlyph = 0 ;
for ( uint32 activeGlyphId : caster -> GetGlyphs ( caster -> GetActiveTalentGroup ()))
{
if ( std :: vector < uint32 > const * activeGlyphBindableSpells = sDB2Manager . GetGlyphBindableSpells ( activeGlyphId ))
{
if ( std :: find ( activeGlyphBindableSpells -> begin (), activeGlyphBindableSpells -> end (), m_misc . SpellId ) != activeGlyphBindableSpells -> end ())
{
replacedGlyph = activeGlyphId ;
break ;
}
}
}
for ( uint32 activeGlyphId : caster -> GetGlyphs ( caster -> GetActiveTalentGroup ()))
{
if ( activeGlyphId == replacedGlyph )
continue ;
if ( activeGlyphId == glyphId )
return SPELL_FAILED_UNIQUE_GLYPH ;
if ( sGlyphPropertiesStore . AssertEntry ( activeGlyphId ) -> GlyphExclusiveCategoryID == glyphProperties -> GlyphExclusiveCategoryID )
return SPELL_FAILED_GLYPH_EXCLUSIVE_CATEGORY ;
}
}
2010-02-20 23:59:05 +01:00
break ;
}
case SPELL_EFFECT_FEED_PET :
{
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return SPELL_FAILED_BAD_TARGETS ;
2011-06-23 13:28:52 +02:00
Item * foodItem = m_targets . GetItemTarget ();
2010-04-07 19:14:10 +02:00
if ( ! foodItem )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
2010-03-07 15:20:19 +01:00
Pet * pet = m_caster -> ToPlayer () -> GetPet ();
2010-02-20 23:59:05 +01:00
2010-04-07 19:14:10 +02:00
if ( ! pet )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NO_PET ;
2011-04-28 22:42:33 +02:00
if ( ! pet -> HaveInDiet ( foodItem -> GetTemplate ()))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_WRONG_PET_FOOD ;
2014-12-21 13:35:43 +01:00
if ( ! pet -> GetCurrentFoodBenefitLevel ( foodItem -> GetTemplate () -> GetBaseItemLevel ()))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_FOOD_LOWLEVEL ;
2013-06-11 19:54:27 -02:30
if ( m_caster -> IsInCombat () || pet -> IsInCombat ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_AFFECTING_COMBAT ;
break ;
}
case SPELL_EFFECT_POWER_BURN :
case SPELL_EFFECT_POWER_DRAIN :
{
// Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
2010-04-07 19:14:10 +02:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2011-06-23 13:28:52 +02:00
if ( Unit * target = m_targets . GetUnitTarget ())
2014-11-16 14:20:01 +01:00
if ( target != m_caster && target -> getPowerType () != Powers ( effect -> MiscValue ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
break ;
}
case SPELL_EFFECT_CHARGE :
{
2012-02-03 19:12:41 +02:00
if ( m_caster -> HasUnitState ( UNIT_STATE_ROOT ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ROOTED ;
2012-09-03 20:30:30 +02:00
2013-02-13 20:21:26 +01:00
if ( GetSpellInfo () -> NeedsExplicitUnitTarget ())
{
Unit * target = m_targets . GetUnitTarget ();
if ( ! target )
return SPELL_FAILED_DONT_REPORT ;
2012-09-03 20:30:30 +02:00
2014-07-04 22:22:28 +01:00
float objSize = target -> GetObjectSize ();
float range = m_spellInfo -> GetMaxRange ( true , m_caster , this ) * 1.5f + objSize ; // can't be overly strict
2012-09-03 20:30:30 +02:00
2014-07-04 22:22:28 +01:00
m_preGeneratedPath . SetPathLengthLimit ( range );
// first try with raycast, if it fails fall back to normal path
2015-07-28 21:11:55 +02:00
float targetObjectSize = std :: min ( target -> GetObjectSize (), 4.0f );
bool result = m_preGeneratedPath . CalculatePath ( target -> GetPositionX (), target -> GetPositionY (), target -> GetPositionZ () + targetObjectSize , false , true );
2013-02-13 20:21:26 +01:00
if ( m_preGeneratedPath . GetPathType () & PATHFIND_SHORT )
return SPELL_FAILED_OUT_OF_RANGE ;
2015-06-15 22:38:42 +02:00
else if ( ! result || m_preGeneratedPath . GetPathType () & ( PATHFIND_NOPATH | PATHFIND_INCOMPLETE ))
2014-07-04 22:00:46 +02:00
{
2015-07-28 21:11:55 +02:00
result = m_preGeneratedPath . CalculatePath ( target -> GetPositionX (), target -> GetPositionY (), target -> GetPositionZ () + targetObjectSize , false , false );
2014-07-04 22:00:46 +02:00
if ( m_preGeneratedPath . GetPathType () & PATHFIND_SHORT )
return SPELL_FAILED_OUT_OF_RANGE ;
2015-06-15 22:38:42 +02:00
else if ( ! result || m_preGeneratedPath . GetPathType () & ( PATHFIND_NOPATH | PATHFIND_INCOMPLETE ))
2014-07-04 22:00:46 +02:00
return SPELL_FAILED_NOPATH ;
2016-07-06 10:23:12 +02:00
else if ( m_preGeneratedPath . IsInvalidDestinationZ ( target )) // Check position z, if not in a straight line
return SPELL_FAILED_NOPATH ;
2014-07-04 22:00:46 +02:00
}
2016-07-06 10:23:12 +02:00
else if ( m_preGeneratedPath . IsInvalidDestinationZ ( target )) // Check position z, if in a straight line
return SPELL_FAILED_NOPATH ;
2014-07-04 22:22:28 +01:00
m_preGeneratedPath . ReducePathLenghtByDist ( objSize ); // move back
2013-02-13 20:21:26 +01:00
}
2010-02-20 23:59:05 +01:00
break ;
}
case SPELL_EFFECT_SKINNING :
{
2011-06-23 13:28:52 +02:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER || ! m_targets . GetUnitTarget () || m_targets . GetUnitTarget () -> GetTypeId () != TYPEID_UNIT )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
2011-06-23 13:28:52 +02:00
if ( ! ( m_targets . GetUnitTarget () -> GetUInt32Value ( UNIT_FIELD_FLAGS ) & UNIT_FLAG_SKINNABLE ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_TARGET_UNSKINNABLE ;
2011-06-23 13:28:52 +02:00
Creature * creature = m_targets . GetUnitTarget () -> ToCreature ();
2014-08-14 16:09:14 +02:00
if ( ! creature -> IsCritter () && ! creature -> loot . isLooted ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_TARGET_NOT_LOOTED ;
2012-05-30 08:01:02 +02:00
uint32 skill = creature -> GetCreatureTemplate () -> GetRequiredLootSkill ();
2010-02-20 23:59:05 +01:00
2010-03-07 15:20:19 +01:00
int32 skillValue = m_caster -> ToPlayer () -> GetSkillValue ( skill );
2011-06-23 13:28:52 +02:00
int32 TargetLevel = m_targets . GetUnitTarget () -> getLevel ();
2010-02-20 23:59:05 +01:00
int32 ReqValue = ( skillValue < 100 ? ( TargetLevel - 10 ) * 10 : TargetLevel * 5 );
if ( ReqValue > skillValue )
return SPELL_FAILED_LOW_CASTLEVEL ;
// chance for fail at orange skinning attempt
2010-04-07 22:59:46 +02:00
if (( m_selfContainer && ( * m_selfContainer ) == this ) &&
2010-12-23 23:25:44 +01:00
skillValue < sWorld -> GetConfigMaxSkillValue () &&
2014-06-26 22:01:55 +02:00
( ReqValue < 0 ? 0 : ReqValue ) > irand ( skillValue - 25 , skillValue + 37 ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_TRY_AGAIN ;
break ;
}
case SPELL_EFFECT_OPEN_LOCK :
{
2014-11-16 14:20:01 +01:00
if ( effect -> TargetA . GetTarget () != TARGET_GAMEOBJECT_TARGET &&
effect -> TargetA . GetTarget () != TARGET_GAMEOBJECT_ITEM_TARGET )
2010-02-20 23:59:05 +01:00
break ;
2010-04-07 22:59:46 +02:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER // only players can open locks, gather etc.
2011-08-16 19:44:18 +02:00
// we need a go target in case of TARGET_GAMEOBJECT_TARGET
2014-11-16 14:20:01 +01:00
|| ( effect -> TargetA . GetTarget () == TARGET_GAMEOBJECT_TARGET && ! m_targets . GetGOTarget ()))
2010-08-04 10:34:30 +02:00
return SPELL_FAILED_BAD_TARGETS ;
2011-09-15 14:08:17 +02:00
Item * pTempItem = NULL ;
2011-06-23 13:28:52 +02:00
if ( m_targets . GetTargetMask () & TARGET_FLAG_TRADE_ITEM )
2010-08-04 10:34:30 +02:00
{
if ( TradeData * pTrade = m_caster -> ToPlayer () -> GetTradeData ())
2014-10-23 17:01:26 +02:00
pTempItem = pTrade -> GetTraderData () -> GetItem ( TradeSlots ( m_targets . GetItemTargetGUID (). GetRawValue (). at ( 0 ))); // at this point item target guid contains the trade slot
2010-08-04 10:34:30 +02:00
}
2011-06-23 13:28:52 +02:00
else if ( m_targets . GetTargetMask () & TARGET_FLAG_ITEM )
pTempItem = m_caster -> ToPlayer () -> GetItemByGuid ( m_targets . GetItemTargetGUID ());
2010-08-04 10:34:30 +02:00
2011-08-16 19:44:18 +02:00
// we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM_TARGET
2014-11-16 14:20:01 +01:00
if ( effect -> TargetA . GetTarget () == TARGET_GAMEOBJECT_ITEM_TARGET &&
2011-06-23 13:28:52 +02:00
! m_targets . GetGOTarget () &&
2014-12-21 13:35:43 +01:00
( ! pTempItem || ! pTempItem -> GetTemplate () -> GetLockID () || ! pTempItem -> IsLocked ()))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
2011-06-23 13:28:52 +02:00
if ( m_spellInfo -> Id != 1842 || ( m_targets . GetGOTarget () &&
m_targets . GetGOTarget () -> GetGOInfo () -> type != GAMEOBJECT_TYPE_TRAP ))
2010-08-08 04:37:24 +02:00
if ( m_caster -> ToPlayer () -> InBattleground () && // In Battleground players can use only flags and banners
2012-10-17 16:56:35 +02:00
! m_caster -> ToPlayer () -> CanUseBattlegroundObject ( m_targets . GetGOTarget ()))
2010-05-23 18:20:10 -03:00
return SPELL_FAILED_TRY_AGAIN ;
2010-02-20 23:59:05 +01:00
// get the lock entry
uint32 lockId = 0 ;
2011-06-23 13:28:52 +02:00
if ( GameObject * go = m_targets . GetGOTarget ())
2010-02-20 23:59:05 +01:00
{
lockId = go -> GetGOInfo () -> GetLockId ();
if ( ! lockId )
return SPELL_FAILED_BAD_TARGETS ;
}
2011-06-23 13:28:52 +02:00
else if ( Item * itm = m_targets . GetItemTarget ())
2014-12-21 13:35:43 +01:00
lockId = itm -> GetTemplate () -> GetLockID ();
2010-02-20 23:59:05 +01:00
SkillType skillId = SKILL_NONE ;
int32 reqSkillValue = 0 ;
int32 skillValue = 0 ;
// check lock compatibility
2014-11-16 14:20:01 +01:00
SpellCastResult res = CanOpenLock ( effect -> EffectIndex , lockId , skillId , reqSkillValue , skillValue );
2010-04-07 19:14:10 +02:00
if ( res != SPELL_CAST_OK )
2010-02-20 23:59:05 +01:00
return res ;
break ;
}
2013-01-02 11:00:16 +01:00
case SPELL_EFFECT_RESURRECT_PET :
2010-02-20 23:59:05 +01:00
{
2011-09-15 14:08:17 +02:00
Creature * pet = m_caster -> GetGuardianPet ();
2010-02-20 23:59:05 +01:00
2013-06-11 19:54:27 -02:30
if ( pet && pet -> IsAlive ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ALREADY_HAVE_SUMMON ;
break ;
}
// This is generic summon effect
case SPELL_EFFECT_SUMMON :
{
2014-11-16 14:20:01 +01:00
SummonPropertiesEntry const * SummonProperties = sSummonPropertiesStore . LookupEntry ( effect -> MiscValueB );
2010-04-07 19:14:10 +02:00
if ( ! SummonProperties )
2010-02-20 23:59:05 +01:00
break ;
2011-09-05 14:01:50 +02:00
switch ( SummonProperties -> Category )
2010-02-20 23:59:05 +01:00
{
case SUMMON_CATEGORY_PET :
2016-05-26 16:04:16 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR1_DISMISS_PET ) && ! m_caster -> GetPetGUID (). IsEmpty ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ALREADY_HAVE_SUMMON ;
2014-03-22 14:54:32 +01:00
// intentional missing break, check both GetPetGUID() and GetCharmGUID for SUMMON_CATEGORY_PET
2010-02-20 23:59:05 +01:00
case SUMMON_CATEGORY_PUPPET :
2014-10-21 20:27:00 +02:00
if ( ! m_caster -> GetCharmGUID (). IsEmpty ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ALREADY_HAVE_CHARM ;
break ;
}
break ;
}
2010-07-20 22:55:28 +02:00
case SPELL_EFFECT_CREATE_TAMED_PET :
{
2011-06-23 13:28:52 +02:00
if ( m_targets . GetUnitTarget ())
2010-07-20 22:55:28 +02:00
{
2011-06-23 13:28:52 +02:00
if ( m_targets . GetUnitTarget () -> GetTypeId () != TYPEID_PLAYER )
2010-07-20 22:55:28 +02:00
return SPELL_FAILED_BAD_TARGETS ;
2016-05-26 16:04:16 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR1_DISMISS_PET ) && ! m_targets . GetUnitTarget () -> GetPetGUID (). IsEmpty ())
2010-07-20 22:55:28 +02:00
return SPELL_FAILED_ALREADY_HAVE_SUMMON ;
}
break ;
}
2010-02-20 23:59:05 +01:00
case SPELL_EFFECT_SUMMON_PET :
{
2014-10-21 20:27:00 +02:00
if ( ! m_caster -> GetPetGUID (). IsEmpty ()) //let warlock do a replacement summon
2010-02-20 23:59:05 +01:00
{
2016-05-26 16:04:16 +02:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-02-20 23:59:05 +01:00
{
if ( strict ) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
2010-04-07 19:14:10 +02:00
if ( Pet * pet = m_caster -> ToPlayer () -> GetPet ())
2010-02-20 23:59:05 +01:00
pet -> CastSpell ( pet , 32752 , true , NULL , NULL , pet -> GetGUID ());
}
2016-05-26 16:04:16 +02:00
else if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR1_DISMISS_PET ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ALREADY_HAVE_SUMMON ;
}
2014-10-21 20:27:00 +02:00
if ( ! m_caster -> GetCharmGUID (). IsEmpty ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ALREADY_HAVE_CHARM ;
break ;
}
case SPELL_EFFECT_SUMMON_PLAYER :
{
2010-04-07 19:14:10 +02:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
2013-10-03 17:07:25 +02:00
if ( ! m_caster -> GetTarget ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
2013-10-05 23:59:52 +02:00
Player * target = ObjectAccessor :: FindPlayer ( m_caster -> ToPlayer () -> GetTarget ());
2011-08-03 09:28:12 -07:00
if ( ! target || m_caster -> ToPlayer () == target || ( ! target -> IsInSameRaidWith ( m_caster -> ToPlayer ()) && m_spellInfo -> Id != 48955 )) // refer-a-friend spell
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
2016-05-01 12:31:55 +02:00
if ( target -> HasSummonPending ())
return SPELL_FAILED_SUMMON_PENDING ;
2010-02-20 23:59:05 +01:00
// check if our map is dungeon
2011-03-09 23:07:50 +01:00
MapEntry const * map = sMapStore . LookupEntry ( m_caster -> GetMapId ());
if ( map -> IsDungeon ())
2010-02-20 23:59:05 +01:00
{
2011-03-09 23:07:50 +01:00
uint32 mapId = m_caster -> GetMap () -> GetId ();
2015-01-10 01:35:47 +01:00
Difficulty difficulty = m_caster -> GetMap () -> GetDifficultyID ();
2011-03-09 23:07:50 +01:00
if ( map -> IsRaid ())
if ( InstancePlayerBind * targetBind = target -> GetBoundInstance ( mapId , difficulty ))
2011-09-15 00:02:45 +02:00
if ( InstancePlayerBind * casterBind = m_caster -> ToPlayer () -> GetBoundInstance ( mapId , difficulty ))
if ( targetBind -> perm && targetBind -> save != casterBind -> save )
return SPELL_FAILED_TARGET_LOCKED_TO_RAID_INSTANCE ;
2011-03-09 23:07:50 +01:00
2011-04-28 22:16:13 +02:00
InstanceTemplate const * instance = sObjectMgr -> GetInstanceTemplate ( mapId );
2010-04-07 19:14:10 +02:00
if ( ! instance )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_TARGET_NOT_IN_INSTANCE ;
2011-03-09 23:07:50 +01:00
if ( ! target -> Satisfy ( sObjectMgr -> GetAccessRequirement ( mapId , difficulty ), mapId ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
}
break ;
}
2011-08-03 09:28:12 -07:00
// RETURN HERE
case SPELL_EFFECT_SUMMON_RAF_FRIEND :
{
2011-09-29 12:43:05 +02:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
2011-08-03 09:28:12 -07:00
return SPELL_FAILED_BAD_TARGETS ;
Player * playerCaster = m_caster -> ToPlayer ();
2011-08-12 13:22:53 +02:00
//
2013-10-03 17:07:25 +02:00
if ( ! ( playerCaster -> GetTarget ()))
2011-08-03 09:28:12 -07:00
return SPELL_FAILED_BAD_TARGETS ;
2013-10-03 17:07:25 +02:00
Player * target = playerCaster -> GetSelectedPlayer ();
2011-08-03 09:28:12 -07:00
if ( ! target ||
! ( target -> GetSession () -> GetRecruiterId () == playerCaster -> GetSession () -> GetAccountId () || target -> GetSession () -> GetAccountId () == playerCaster -> GetSession () -> GetRecruiterId ()))
return SPELL_FAILED_BAD_TARGETS ;
break ;
}
2010-02-20 23:59:05 +01:00
case SPELL_EFFECT_LEAP :
case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER :
{
//Do not allow to cast it before BG starts.
2010-04-07 19:14:10 +02:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2011-09-15 14:08:17 +02:00
if ( Battleground const * bg = m_caster -> ToPlayer () -> GetBattleground ())
2010-04-07 19:14:10 +02:00
if ( bg -> GetStatus () != STATUS_IN_PROGRESS )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_TRY_AGAIN ;
break ;
}
case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF :
{
2011-06-23 13:28:52 +02:00
if ( m_targets . GetUnitTarget () == m_caster )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
break ;
}
2010-05-09 08:39:25 +02:00
case SPELL_EFFECT_LEAP_BACK :
{
2012-05-30 08:01:02 +02:00
if ( m_caster -> HasUnitState ( UNIT_STATE_ROOT ))
2010-05-21 10:24:51 +02:00
{
2010-05-21 12:25:03 +02:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
2010-05-21 10:24:51 +02:00
return SPELL_FAILED_ROOTED ;
else
return SPELL_FAILED_DONT_REPORT ;
}
2010-05-09 08:39:25 +02:00
break ;
}
2010-10-16 17:53:33 +03:00
case SPELL_EFFECT_TALENT_SPEC_SELECT :
2015-01-30 23:58:16 +01:00
{
2016-06-09 21:33:18 +02:00
ChrSpecializationEntry const * spec = sChrSpecializationStore . LookupEntry ( m_misc . SpecializationId );
2017-03-21 17:36:44 +01:00
Player * player = m_caster -> ToPlayer ();
if ( ! player )
return SPELL_FAILED_TARGET_NOT_PLAYER ;
if ( ! spec || ( spec -> ClassID != m_caster -> getClass () && ! spec -> IsPetSpecialization ()))
2016-06-09 21:33:18 +02:00
return SPELL_FAILED_NO_SPEC ;
2017-03-21 17:36:44 +01:00
if ( spec -> IsPetSpecialization ())
{
Pet * pet = player -> GetPet ();
if ( ! pet || pet -> getPetType () != HUNTER_PET || ! pet -> GetCharmInfo ())
return SPELL_FAILED_NO_PET ;
}
2010-10-16 17:53:33 +03:00
// can't change during already started arena/battleground
2017-03-21 17:36:44 +01:00
if ( Battleground const * bg = player -> GetBattleground ())
if ( bg -> GetStatus () == STATUS_IN_PROGRESS )
return SPELL_FAILED_NOT_IN_BATTLEGROUND ;
2010-10-16 17:53:33 +03:00
break ;
2015-01-30 23:58:16 +01:00
}
case SPELL_EFFECT_REMOVE_TALENT :
{
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return SPELL_FAILED_BAD_TARGETS ;
TalentEntry const * talent = sTalentStore . LookupEntry ( m_misc . TalentId );
if ( ! talent )
return SPELL_FAILED_DONT_REPORT ;
2015-02-17 01:01:44 +01:00
if ( m_caster -> GetSpellHistory () -> HasCooldown ( talent -> SpellID ))
2015-01-30 23:58:16 +01:00
return SPELL_FAILED_CANT_UNTALENT ;
break ;
}
2016-08-15 00:03:38 +02:00
case SPELL_EFFECT_GIVE_ARTIFACT_POWER :
case SPELL_EFFECT_GIVE_ARTIFACT_POWER_NO_BONUS :
{
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return SPELL_FAILED_BAD_TARGETS ;
Aura * artifactAura = m_caster -> GetAura ( ARTIFACTS_ALL_WEAPONS_GENERAL_WEAPON_EQUIPPED_PASSIVE );
if ( ! artifactAura )
return SPELL_FAILED_NO_ARTIFACT_EQUIPPED ;
Item * artifact = m_caster -> ToPlayer () -> GetItemByGuid ( artifactAura -> GetCastItemGUID ());
if ( ! artifact )
return SPELL_FAILED_NO_ARTIFACT_EQUIPPED ;
if ( effect -> Effect == SPELL_EFFECT_GIVE_ARTIFACT_POWER )
{
ArtifactEntry const * artifactEntry = sArtifactStore . LookupEntry ( artifact -> GetTemplate () -> GetArtifactID ());
if ( ! artifactEntry || artifactEntry -> ArtifactCategoryID != effect -> MiscValue )
return SPELL_FAILED_WRONG_ARTIFACT_EQUIPPED ;
}
break ;
}
2010-05-21 10:24:51 +02:00
default :
break ;
2010-02-20 23:59:05 +01:00
}
}
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2014-11-27 15:11:43 +01:00
if ( ! effect )
continue ;
2014-11-16 14:20:01 +01:00
switch ( effect -> ApplyAuraName )
2010-02-20 23:59:05 +01:00
{
case SPELL_AURA_MOD_POSSESS_PET :
{
2010-04-07 19:14:10 +02:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NO_PET ;
2011-09-15 14:08:17 +02:00
Pet * pet = m_caster -> ToPlayer () -> GetPet ();
2010-04-07 19:14:10 +02:00
if ( ! pet )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NO_PET ;
2014-10-21 20:27:00 +02:00
if ( ! pet -> GetCharmerGUID (). IsEmpty ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CHARMED ;
break ;
}
case SPELL_AURA_MOD_POSSESS :
case SPELL_AURA_MOD_CHARM :
case SPELL_AURA_AOE_CHARM :
{
2014-10-21 20:27:00 +02:00
if ( ! m_caster -> GetCharmerGUID (). IsEmpty ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CHARMED ;
2014-11-16 14:20:01 +01:00
if ( effect -> ApplyAuraName == SPELL_AURA_MOD_CHARM
|| effect -> ApplyAuraName == SPELL_AURA_MOD_POSSESS )
2010-02-20 23:59:05 +01:00
{
2016-05-26 16:04:16 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR1_DISMISS_PET ) && ! m_caster -> GetPetGUID (). IsEmpty ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ALREADY_HAVE_SUMMON ;
2014-10-21 20:27:00 +02:00
if ( ! m_caster -> GetCharmGUID (). IsEmpty ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ALREADY_HAVE_CHARM ;
}
2011-06-23 13:28:52 +02:00
if ( Unit * target = m_targets . GetUnitTarget ())
2010-02-20 23:59:05 +01:00
{
2015-08-12 14:05:14 +02:00
if ( target -> GetTypeId () == TYPEID_UNIT && target -> IsVehicle ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_IMPLICIT_TARGETS ;
2010-07-20 01:42:14 +02:00
if ( target -> IsMounted ())
return SPELL_FAILED_CANT_BE_CHARMED ;
2014-10-21 20:27:00 +02:00
if ( ! target -> GetCharmerGUID (). IsEmpty ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CHARMED ;
2012-11-19 01:00:47 +00:00
2012-11-14 10:33:56 -05:00
if ( target -> GetOwner () && target -> GetOwner () -> GetTypeId () == TYPEID_PLAYER )
return SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED ;
2010-02-20 23:59:05 +01:00
2015-07-21 00:33:36 +02:00
int32 value = CalculateDamage ( effect -> EffectIndex , target );
if ( value && int32 ( target -> getLevel ()) > value )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_HIGHLEVEL ;
}
break ;
}
case SPELL_AURA_MOUNTED :
{
2017-02-05 00:16:58 +01:00
if ( m_caster -> IsInWater () && m_spellInfo -> HasAura ( m_caster -> GetMap () -> GetDifficultyID (), SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ONLY_ABOVEWATER ;
// Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
2011-07-31 19:03:06 +02:00
bool allowMount = ! m_caster -> GetMap () -> IsDungeon () || m_caster -> GetMap () -> IsBattlegroundOrArena ();
2011-09-15 14:08:17 +02:00
InstanceTemplate const * it = sObjectMgr -> GetInstanceTemplate ( m_caster -> GetMapId ());
2010-03-21 18:17:20 +01:00
if ( it )
2011-07-31 19:03:06 +02:00
allowMount = it -> AllowMount ;
2014-11-09 23:53:48 +02:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER && ! allowMount && ! m_spellInfo -> RequiredAreasID )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NO_MOUNTS_ALLOWED ;
2010-12-09 17:03:42 +06:00
if ( m_caster -> IsInDisallowedMountForm ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NOT_SHAPESHIFT ;
break ;
}
case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS :
{
2011-06-23 13:28:52 +02:00
if ( ! m_targets . GetUnitTarget ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_IMPLICIT_TARGETS ;
2013-12-25 14:16:55 -03:30
// can be cast at non-friendly unit or own pet/charm
2011-06-23 13:28:52 +02:00
if ( m_caster -> IsFriendlyTo ( m_targets . GetUnitTarget ()))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_TARGET_FRIENDLY ;
break ;
}
case SPELL_AURA_FLY :
case SPELL_AURA_MOD_INCREASE_MOUNTED_FLIGHT_SPEED :
{
// not allow cast fly spells if not have req. skills (all spells is self target)
// allow always ghost flight spells
2013-06-11 19:54:27 -02:30
if ( m_originalCaster && m_originalCaster -> GetTypeId () == TYPEID_PLAYER && m_originalCaster -> IsAlive ())
2010-02-20 23:59:05 +01:00
{
2012-03-02 22:00:26 -03:00
Battlefield * Bf = sBattlefieldMgr -> GetBattlefieldToZoneId ( m_originalCaster -> GetZoneId ());
2016-02-02 19:13:04 +01:00
if ( AreaTableEntry const * area = sAreaTableStore . LookupEntry ( m_originalCaster -> GetAreaId ()))
2014-11-13 02:30:19 +02:00
if ( area -> Flags [ 0 ] & AREA_FLAG_NO_FLY_ZONE || ( Bf && ! Bf -> CanFlyIn ()))
2016-05-11 18:29:02 +02:00
return SPELL_FAILED_NOT_HERE ;
2010-02-20 23:59:05 +01:00
}
break ;
}
case SPELL_AURA_PERIODIC_MANA_LEECH :
{
2014-11-16 14:20:01 +01:00
if ( effect -> IsTargetingArea ())
2012-01-31 20:27:22 -05:00
break ;
2011-06-23 13:28:52 +02:00
if ( ! m_targets . GetUnitTarget ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_IMPLICIT_TARGETS ;
if ( m_caster -> GetTypeId () != TYPEID_PLAYER || m_CastItem )
break ;
2011-06-23 13:28:52 +02:00
if ( m_targets . GetUnitTarget () -> getPowerType () != POWER_MANA )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
break ;
}
default :
break ;
}
}
2010-06-25 13:15:51 +02:00
// check trade slot case (last, for allow catch any another cast problems)
2011-06-23 13:28:52 +02:00
if ( m_targets . GetTargetMask () & TARGET_FLAG_TRADE_ITEM )
2010-06-25 13:15:51 +02:00
{
2010-11-04 21:59:27 +01:00
if ( m_CastItem )
return SPELL_FAILED_ITEM_ENCHANT_TRADE_WINDOW ;
2010-06-25 13:15:51 +02:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
return SPELL_FAILED_NOT_TRADING ;
TradeData * my_trade = m_caster -> ToPlayer () -> GetTradeData ();
if ( ! my_trade )
return SPELL_FAILED_NOT_TRADING ;
2015-04-04 00:07:16 +02:00
if ( m_targets . GetItemTargetGUID () != ObjectGuid :: TradeItem )
2010-08-04 10:34:30 +02:00
return SPELL_FAILED_BAD_TARGETS ;
2010-06-25 13:15:51 +02:00
2011-07-31 19:03:06 +02:00
if ( ! IsTriggered ())
2010-06-25 13:15:51 +02:00
if ( my_trade -> GetSpell ())
return SPELL_FAILED_ITEM_ALREADY_ENCHANTED ;
}
2010-09-08 01:35:36 +03:00
// check if caster has at least 1 combo point for spells that require combo points
2010-09-14 13:28:25 +03:00
if ( m_needComboPoints )
2010-09-08 10:59:10 +02:00
if ( Player * plrCaster = m_caster -> ToPlayer ())
2010-09-08 11:22:51 +02:00
if ( ! plrCaster -> GetComboPoints ())
2010-09-08 10:59:10 +02:00
return SPELL_FAILED_NO_COMBO_POINTS ;
2010-09-08 01:35:36 +03:00
2010-02-20 23:59:05 +01:00
// all ok
return SPELL_CAST_OK ;
}
SpellCastResult Spell :: CheckPetCast ( Unit * target )
{
2012-02-03 19:12:41 +02:00
if ( m_caster -> HasUnitState ( UNIT_STATE_CASTING ) && ! ( _triggeredCastFlags & TRIGGERED_IGNORE_CAST_IN_PROGRESS )) //prevent spellcast interruption by another spellcast
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_SPELL_IN_PROGRESS ;
2011-08-20 09:49:18 +02:00
// dead owner (pets still alive when owners ressed?)
2011-09-15 14:08:17 +02:00
if ( Unit * owner = m_caster -> GetCharmerOrOwner ())
2013-06-11 19:54:27 -02:30
if ( ! owner -> IsAlive ())
2011-08-20 09:49:18 +02:00
return SPELL_FAILED_CASTER_DEAD ;
2010-02-20 23:59:05 +01:00
2011-08-20 09:49:18 +02:00
if ( ! target && m_targets . GetUnitTarget ())
target = m_targets . GetUnitTarget ();
2010-02-20 23:59:05 +01:00
2012-05-30 08:01:02 +02:00
if ( m_spellInfo -> NeedsExplicitUnitTarget ())
2011-08-20 09:49:18 +02:00
{
2012-05-30 08:01:02 +02:00
if ( ! target )
return SPELL_FAILED_BAD_IMPLICIT_TARGETS ;
m_targets . SetUnitTarget ( target );
2011-08-20 09:49:18 +02:00
}
2010-02-20 23:59:05 +01:00
2016-03-26 18:41:03 +01:00
// check cooldown
2015-02-17 01:01:44 +01:00
if ( Creature * creatureCaster = m_caster -> ToCreature ())
if ( ! creatureCaster -> GetSpellHistory () -> IsReady ( m_spellInfo ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NOT_READY ;
2013-08-14 15:45:36 +02:00
// Check if spell is affected by GCD
if ( m_spellInfo -> StartRecoveryCategory > 0 )
2015-02-17 01:01:44 +01:00
if ( m_caster -> GetCharmInfo () && m_caster -> GetSpellHistory () -> HasGlobalCooldown ( m_spellInfo ))
2013-08-14 15:45:36 +02:00
return SPELL_FAILED_NOT_READY ;
2010-02-20 23:59:05 +01:00
return CheckCast ( true );
}
SpellCastResult Spell :: CheckCasterAuras () const
{
2010-04-07 22:59:46 +02:00
// spells totally immuned to caster auras (wsg flag drop, give marks etc)
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR6_IGNORE_CASTER_AURAS ))
2010-02-20 23:59:05 +01:00
return SPELL_CAST_OK ;
uint8 school_immune = 0 ;
uint32 mechanic_immune = 0 ;
uint32 dispel_immune = 0 ;
// Check if the spell grants school or mechanic immunity.
// We use bitmasks so the loop is done only once and not on every aura check below.
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR1_DISPEL_AURAS_ON_IMMUNITY ))
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2014-11-27 15:11:43 +01:00
if ( ! effect )
continue ;
2014-11-16 14:20:01 +01:00
if ( effect -> ApplyAuraName == SPELL_AURA_SCHOOL_IMMUNITY )
school_immune |= uint32 ( effect -> MiscValue );
else if ( effect -> ApplyAuraName == SPELL_AURA_MECHANIC_IMMUNITY )
mechanic_immune |= 1 << uint32 ( effect -> MiscValue );
else if ( effect -> ApplyAuraName == SPELL_AURA_DISPEL_IMMUNITY )
dispel_immune |= SpellInfo :: GetDispelMask ( DispelType ( effect -> MiscValue ));
2010-02-20 23:59:05 +01:00
}
2010-07-26 22:57:25 +02:00
// immune movement impairment and loss of control
2016-08-31 23:12:57 -03:00
if ( m_spellInfo -> Id == 42292 || m_spellInfo -> Id == 59752 || m_spellInfo -> Id == 19574 || m_spellInfo -> Id == 53490 )
2010-02-20 23:59:05 +01:00
mechanic_immune = IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK ;
}
2015-01-05 23:49:43 +02:00
bool usableInStun = m_spellInfo -> HasAttribute ( SPELL_ATTR5_USABLE_WHILE_STUNNED );
2011-06-30 08:05:03 +07:00
2011-01-14 20:24:39 +01:00
// Glyph of Pain Suppression
2012-08-17 09:01:48 -05:00
// Allow Pain Suppression and Guardian Spirit to be cast while stunned
2011-06-30 08:05:03 +07:00
// there is no other way to handle it
2012-08-17 09:01:48 -05:00
if (( m_spellInfo -> Id == 33206 || m_spellInfo -> Id == 47788 ) && ! m_caster -> HasAura ( 63248 ))
2011-06-30 08:05:03 +07:00
usableInStun = false ;
2011-01-14 20:24:39 +01:00
2010-02-20 23:59:05 +01:00
// Check whether the cast should be prevented by any state you might have.
SpellCastResult prevented_reason = SPELL_CAST_OK ;
// Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
uint32 unitflag = m_caster -> GetUInt32Value ( UNIT_FIELD_FLAGS ); // Get unit state
2011-06-30 08:05:03 +07:00
if ( unitflag & UNIT_FLAG_STUNNED )
{
2016-10-02 23:32:14 +02:00
// spell is usable while stunned, check if caster has allowed stun auras, another stun types must prevent cast spell
2011-06-30 08:05:03 +07:00
if ( usableInStun )
{
2016-10-02 23:32:14 +02:00
static uint32 const allowedStunMask =
1 << MECHANIC_STUN
| 1 << MECHANIC_FREEZE
| 1 << MECHANIC_SAPPED
| 1 << MECHANIC_SLEEP ;
2011-06-30 08:05:03 +07:00
bool foundNotStun = false ;
Unit :: AuraEffectList const & stunAuras = m_caster -> GetAuraEffectsByType ( SPELL_AURA_MOD_STUN );
for ( Unit :: AuraEffectList :: const_iterator i = stunAuras . begin (); i != stunAuras . end (); ++ i )
{
2016-10-02 23:32:14 +02:00
uint32 mechanicMask = ( * i ) -> GetSpellInfo () -> GetAllEffectsMechanicMask ();
if ( mechanicMask && ! ( mechanicMask & allowedStunMask ))
2011-06-30 08:05:03 +07:00
{
foundNotStun = true ;
break ;
}
}
2016-10-02 23:32:14 +02:00
if ( foundNotStun )
2011-06-30 08:05:03 +07:00
prevented_reason = SPELL_FAILED_STUNNED ;
}
else
prevented_reason = SPELL_FAILED_STUNNED ;
}
2015-01-05 23:49:43 +02:00
else if ( unitflag & UNIT_FLAG_CONFUSED && ! m_spellInfo -> HasAttribute ( SPELL_ATTR5_USABLE_WHILE_CONFUSED ))
2010-02-20 23:59:05 +01:00
prevented_reason = SPELL_FAILED_CONFUSED ;
2015-01-05 23:49:43 +02:00
else if ( unitflag & UNIT_FLAG_FLEEING && ! m_spellInfo -> HasAttribute ( SPELL_ATTR5_USABLE_WHILE_FEARED ))
2010-02-20 23:59:05 +01:00
prevented_reason = SPELL_FAILED_FLEEING ;
2016-06-23 22:19:52 +02:00
else if ( unitflag & UNIT_FLAG_SILENCED && m_spellInfo -> PreventionType & SPELL_PREVENTION_TYPE_SILENCE )
2010-02-20 23:59:05 +01:00
prevented_reason = SPELL_FAILED_SILENCED ;
2016-06-23 22:19:52 +02:00
else if ( unitflag & UNIT_FLAG_PACIFIED && m_spellInfo -> PreventionType & SPELL_PREVENTION_TYPE_PACIFY )
2010-02-20 23:59:05 +01:00
prevented_reason = SPELL_FAILED_PACIFIED ;
2016-06-25 10:50:28 +02:00
else if ( m_caster -> HasFlag ( UNIT_FIELD_FLAGS_2 , UNIT_FLAG2_NO_ACTIONS ) && m_spellInfo -> PreventionType & SPELL_PREVENTION_TYPE_NO_ACTIONS )
prevented_reason = SPELL_FAILED_NO_ACTIONS ;
2010-02-20 23:59:05 +01:00
// Attr must make flag drop spell totally immune from all effects
2010-04-07 19:14:10 +02:00
if ( prevented_reason != SPELL_CAST_OK )
2010-02-20 23:59:05 +01:00
{
2010-04-07 19:14:10 +02:00
if ( school_immune || mechanic_immune || dispel_immune )
2010-02-20 23:59:05 +01:00
{
//Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
Unit :: AuraApplicationMap const & auras = m_caster -> GetAppliedAuras ();
for ( Unit :: AuraApplicationMap :: const_iterator itr = auras . begin (); itr != auras . end (); ++ itr )
{
2011-06-11 22:35:29 +02:00
Aura const * aura = itr -> second -> GetBase ();
2011-07-26 23:09:28 +02:00
SpellInfo const * auraInfo = aura -> GetSpellInfo ();
if ( auraInfo -> GetAllEffectsMechanicMask () & mechanic_immune )
2010-02-20 23:59:05 +01:00
continue ;
2015-01-05 23:49:43 +02:00
if ( auraInfo -> GetSchoolMask () & school_immune && ! auraInfo -> HasAttribute ( SPELL_ATTR1_UNAFFECTED_BY_SCHOOL_IMMUNE ))
2010-02-20 23:59:05 +01:00
continue ;
2011-07-26 23:09:28 +02:00
if ( auraInfo -> GetDispelMask () & dispel_immune )
2010-02-20 23:59:05 +01:00
continue ;
//Make a second check for spell failed so the right SPELL_FAILED message is returned.
//That is needed when your casting is prevented by multiple states and you are only immune to some of them.
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2014-11-27 15:11:43 +01:00
if ( ! effect )
continue ;
2014-11-16 14:20:01 +01:00
if ( AuraEffect * part = aura -> GetEffect ( effect -> EffectIndex ))
2010-02-20 23:59:05 +01:00
{
2011-06-30 08:05:03 +07:00
switch ( part -> GetAuraType ())
2010-02-20 23:59:05 +01:00
{
case SPELL_AURA_MOD_STUN :
2011-07-26 23:09:28 +02:00
if ( ! usableInStun || ! ( auraInfo -> GetAllEffectsMechanicMask () & ( 1 << MECHANIC_STUN )))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_STUNNED ;
break ;
case SPELL_AURA_MOD_CONFUSE :
2015-01-05 23:49:43 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR5_USABLE_WHILE_CONFUSED ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CONFUSED ;
break ;
case SPELL_AURA_MOD_FEAR :
2015-01-05 23:49:43 +02:00
if ( ! m_spellInfo -> HasAttribute ( SPELL_ATTR5_USABLE_WHILE_FEARED ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_FLEEING ;
break ;
case SPELL_AURA_MOD_SILENCE :
case SPELL_AURA_MOD_PACIFY :
case SPELL_AURA_MOD_PACIFY_SILENCE :
2016-06-23 22:19:52 +02:00
if ( m_spellInfo -> PreventionType & SPELL_PREVENTION_TYPE_PACIFY )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_PACIFIED ;
2016-06-23 22:19:52 +02:00
else if ( m_spellInfo -> PreventionType & SPELL_PREVENTION_TYPE_SILENCE )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_SILENCED ;
break ;
default : break ;
}
}
}
}
}
2013-12-25 14:16:55 -03:30
// You are prevented from casting and the spell cast does not grant immunity. Return a failed error.
2010-02-20 23:59:05 +01:00
else
return prevented_reason ;
}
return SPELL_CAST_OK ;
}
2012-08-22 20:33:45 +03:00
SpellCastResult Spell :: CheckArenaAndRatedBattlegroundCastRules ()
{
bool isRatedBattleground = false ; // NYI
bool isArena = ! isRatedBattleground ;
// check USABLE attributes
// USABLE takes precedence over NOT_USABLE
2015-01-05 23:49:43 +02:00
if ( isRatedBattleground && m_spellInfo -> HasAttribute ( SPELL_ATTR9_USABLE_IN_RATED_BATTLEGROUNDS ))
2012-08-22 20:33:45 +03:00
return SPELL_CAST_OK ;
2015-01-05 23:49:43 +02:00
if ( isArena && m_spellInfo -> HasAttribute ( SPELL_ATTR4_USABLE_IN_ARENA ))
2012-08-22 20:33:45 +03:00
return SPELL_CAST_OK ;
// check NOT_USABLE attributes
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR4_NOT_USABLE_IN_ARENA_OR_RATED_BG ))
2012-08-22 20:33:45 +03:00
return isArena ? SPELL_FAILED_NOT_IN_ARENA : SPELL_FAILED_NOT_IN_RATED_BATTLEGROUND ;
2015-01-05 23:49:43 +02:00
if ( isArena && m_spellInfo -> HasAttribute ( SPELL_ATTR9_NOT_USABLE_IN_ARENA ))
2012-08-22 20:33:45 +03:00
return SPELL_FAILED_NOT_IN_ARENA ;
// check cooldowns
uint32 spellCooldown = m_spellInfo -> GetRecoveryTime ();
if ( isArena && spellCooldown > 10 * MINUTE * IN_MILLISECONDS ) // not sure if still needed
return SPELL_FAILED_NOT_IN_ARENA ;
if ( isRatedBattleground && spellCooldown > 15 * MINUTE * IN_MILLISECONDS )
return SPELL_FAILED_NOT_IN_RATED_BATTLEGROUND ;
return SPELL_CAST_OK ;
}
2010-02-20 23:59:05 +01:00
bool Spell :: CanAutoCast ( Unit * target )
{
2016-03-26 18:41:03 +01:00
if ( ! target )
return ( CheckPetCast ( target ) == SPELL_CAST_OK );
2014-09-14 16:14:12 +02:00
ObjectGuid targetguid = target -> GetGUID ();
2010-02-20 23:59:05 +01:00
2016-03-23 18:09:15 +01:00
// check if target already has the same or a more powerful aura
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2014-11-27 15:11:43 +01:00
if ( ! effect )
continue ;
2016-03-23 18:09:15 +01:00
if ( ! effect -> IsAura ())
continue ;
AuraType const & auraType = AuraType ( effect -> ApplyAuraName );
Unit :: AuraEffectList const & auras = target -> GetAuraEffectsByType ( auraType );
for ( Unit :: AuraEffectList :: const_iterator auraIt = auras . begin (); auraIt != auras . end (); ++ auraIt )
2010-02-20 23:59:05 +01:00
{
2016-03-23 18:09:15 +01:00
if ( GetSpellInfo () -> Id == ( * auraIt ) -> GetSpellInfo () -> Id )
return false ;
switch ( sSpellMgr -> CheckSpellGroupStackRules ( GetSpellInfo (), ( * auraIt ) -> GetSpellInfo ()))
2010-02-20 23:59:05 +01:00
{
2016-03-23 18:09:15 +01:00
case SPELL_GROUP_STACK_RULE_EXCLUSIVE :
2010-02-20 23:59:05 +01:00
return false ;
2016-03-23 18:09:15 +01:00
case SPELL_GROUP_STACK_RULE_EXCLUSIVE_FROM_SAME_CASTER :
if ( GetCaster () == ( * auraIt ) -> GetCaster ())
return false ;
break ;
case SPELL_GROUP_STACK_RULE_EXCLUSIVE_SAME_EFFECT : // this one has further checks, but i don't think they're necessary for autocast logic
case SPELL_GROUP_STACK_RULE_EXCLUSIVE_HIGHEST :
if ( abs ( effect -> BasePoints ) <= abs (( * auraIt ) -> GetAmount ()))
2010-02-20 23:59:05 +01:00
return false ;
2016-03-23 18:09:15 +01:00
break ;
2016-03-23 18:13:02 +01:00
case SPELL_GROUP_STACK_RULE_DEFAULT :
default :
break ;
2010-02-20 23:59:05 +01:00
}
}
}
SpellCastResult result = CheckPetCast ( target );
2010-04-07 19:14:10 +02:00
if ( result == SPELL_CAST_OK || result == SPELL_FAILED_UNIT_NOT_INFRONT )
2010-02-20 23:59:05 +01:00
{
2016-03-26 18:41:03 +01:00
// do not check targets for ground-targeted spells (we target them on top of the intended target anyway)
if ( GetSpellInfo () -> ExplicitTargetMask & TARGET_FLAG_DEST_LOCATION )
return true ;
2010-02-20 23:59:05 +01:00
SelectSpellTargets ();
//check if among target units, our WANTED target is as well (->only self cast spells return false)
2015-06-01 00:26:49 +01:00
for ( std :: vector < TargetInfo >:: iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2010-04-07 22:59:46 +02:00
if ( ihit -> targetGUID == targetguid )
2010-02-20 23:59:05 +01:00
return true ;
}
2016-03-26 18:41:03 +01:00
// either the cast failed or the intended target wouldn't be hit
return false ;
2010-02-20 23:59:05 +01:00
}
2011-08-06 20:42:00 +07:00
SpellCastResult Spell :: CheckRange ( bool strict )
2010-02-20 23:59:05 +01:00
{
2011-08-06 20:42:00 +07:00
// Don't check for instant cast spells
if ( ! strict && m_casttime == 0 )
return SPELL_CAST_OK ;
2016-08-15 18:17:07 +02:00
float minRange , maxRange ;
std :: tie ( minRange , maxRange ) = GetMinMaxRange ( strict );
// get square values for sqr distance checks
minRange *= minRange ;
maxRange *= maxRange ;
2016-07-01 20:26:49 +02:00
Unit * target = m_targets . GetUnitTarget ();
2016-08-15 18:17:07 +02:00
if ( target && target != m_caster )
{
if ( m_caster -> GetExactDistSq ( target ) > maxRange )
return SPELL_FAILED_OUT_OF_RANGE ;
if ( minRange > 0.0f && m_caster -> GetExactDistSq ( target ) < minRange )
return SPELL_FAILED_OUT_OF_RANGE ;
if ( m_caster -> GetTypeId () == TYPEID_PLAYER &&
((( m_spellInfo -> FacingCasterFlags & SPELL_FACING_FLAG_INFRONT ) && ! m_caster -> HasInArc ( static_cast < float > ( M_PI ), target ))
&& ! m_caster -> IsWithinBoundaryRadius ( target )))
return SPELL_FAILED_UNIT_NOT_INFRONT ;
}
if ( m_targets . HasDst () && ! m_targets . HasTraj ())
{
if ( m_caster -> GetExactDistSq ( m_targets . GetDstPos ()) > maxRange )
return SPELL_FAILED_OUT_OF_RANGE ;
if ( minRange > 0.0f && m_caster -> GetExactDistSq ( m_targets . GetDstPos ()) < minRange )
return SPELL_FAILED_OUT_OF_RANGE ;
}
return SPELL_CAST_OK ;
}
std :: pair < float , float > Spell :: GetMinMaxRange ( bool strict )
{
float rangeMod = 0.0f ;
2016-07-01 20:26:49 +02:00
float minRange = 0.0f ;
float maxRange = 0.0f ;
if ( strict && IsNextMeleeSwingSpell ())
2016-08-15 18:17:07 +02:00
{
2016-07-01 20:26:49 +02:00
maxRange = 100.0f ;
2016-08-15 18:17:07 +02:00
return std :: pair < float , float > ( minRange , maxRange );
}
if ( m_spellInfo -> RangeEntry )
2016-07-01 20:26:49 +02:00
{
2016-08-15 18:17:07 +02:00
Unit * target = m_targets . GetUnitTarget ();
2016-07-01 20:26:49 +02:00
if ( m_spellInfo -> RangeEntry -> Flags & SPELL_RANGE_MELEE )
{
2016-08-15 18:17:07 +02:00
rangeMod = m_caster -> GetMeleeRange ( target ? target : m_caster ); // when the target is not a unit, take the caster's combat reach as the target's combat reach.
2016-07-01 20:26:49 +02:00
}
else
{
float meleeRange = 0.0f ;
if ( m_spellInfo -> RangeEntry -> Flags & SPELL_RANGE_RANGED )
2016-08-15 18:17:07 +02:00
meleeRange = m_caster -> GetMeleeRange ( target ? target : m_caster ); // when the target is not a unit, take the caster's combat reach as the target's combat reach.
2016-07-01 20:26:49 +02:00
minRange = m_caster -> GetSpellMinRangeForTarget ( target , m_spellInfo ) + meleeRange ;
maxRange = m_caster -> GetSpellMaxRangeForTarget ( target , m_spellInfo );
2011-10-19 00:24:43 +02:00
2016-07-01 20:26:49 +02:00
if ( target || m_targets . GetCorpseTarget ())
{
2016-08-15 18:17:07 +02:00
rangeMod = m_caster -> GetCombatReach () + ( target ? target -> GetCombatReach () : m_caster -> GetCombatReach ());
2016-07-01 20:26:49 +02:00
if ( minRange > 0.0f && ! ( m_spellInfo -> RangeEntry -> Flags & SPELL_RANGE_RANGED ))
minRange += rangeMod ;
}
}
2011-10-19 00:24:43 +02:00
2016-07-01 20:26:49 +02:00
if ( target && m_caster -> isMoving () && target -> isMoving () && ! m_caster -> IsWalking () && ! target -> IsWalking () &&
( m_spellInfo -> RangeEntry -> Flags & SPELL_RANGE_MELEE || target -> GetTypeId () == TYPEID_PLAYER ))
2016-08-20 00:28:55 +02:00
rangeMod += 8.0f / 3.0f ;
2011-10-19 00:24:43 +02:00
}
2011-08-06 20:42:00 +07:00
2016-07-01 20:26:49 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR0_REQ_AMMO ) && m_caster -> GetTypeId () == TYPEID_PLAYER )
if ( Item * ranged = m_caster -> ToPlayer () -> GetWeaponForAttack ( RANGED_ATTACK , true ))
maxRange *= ranged -> GetTemplate () -> GetRangedModRange () * 0.01f ;
2010-02-20 23:59:05 +01:00
2010-04-07 19:14:10 +02:00
if ( Player * modOwner = m_caster -> GetSpellModOwner ())
2016-07-01 20:26:49 +02:00
modOwner -> ApplySpellMod ( m_spellInfo -> Id , SPELLMOD_RANGE , maxRange , this );
maxRange += rangeMod ;
2010-02-20 23:59:05 +01:00
2016-08-15 18:17:07 +02:00
return std :: pair < float , float > ( minRange , maxRange );
2010-02-20 23:59:05 +01:00
}
SpellCastResult Spell :: CheckPower ()
{
// item cast not used power
2010-04-07 19:14:10 +02:00
if ( m_CastItem )
2010-02-20 23:59:05 +01:00
return SPELL_CAST_OK ;
2015-03-08 13:31:57 +01:00
for ( SpellInfo :: CostData const & cost : m_powerCost )
2010-02-20 23:59:05 +01:00
{
2015-03-08 13:31:57 +01:00
// health as power used - need check health amount
if ( cost . Power == POWER_HEALTH )
{
if ( int32 ( m_caster -> GetHealth ()) <= cost . Amount )
return SPELL_FAILED_CASTER_AURASTATE ;
continue ;
}
// Check valid power type
if ( cost . Power >= MAX_POWERS )
{
TC_LOG_ERROR ( "spells" , "Spell::CheckPower: Unknown power type '%d'" , cost . Power );
return SPELL_FAILED_UNKNOWN ;
}
2010-02-20 23:59:05 +01:00
2015-03-08 13:31:57 +01:00
//check rune cost only if a spell has PowerType == POWER_RUNES
if ( cost . Power == POWER_RUNES )
{
2016-01-24 15:56:10 +01:00
SpellCastResult failReason = CheckRuneCost ();
2015-03-08 13:31:57 +01:00
if ( failReason != SPELL_CAST_OK )
return failReason ;
}
// Check power amount
if ( int32 ( m_caster -> GetPower ( cost . Power )) < cost . Amount )
return SPELL_FAILED_NO_POWER ;
2010-02-20 23:59:05 +01:00
}
2015-03-08 13:31:57 +01:00
return SPELL_CAST_OK ;
2010-02-20 23:59:05 +01:00
}
SpellCastResult Spell :: CheckItems ()
{
2013-07-20 21:52:05 +02:00
Player * player = m_caster -> ToPlayer ();
if ( ! player )
2010-02-20 23:59:05 +01:00
return SPELL_CAST_OK ;
2010-04-07 19:14:10 +02:00
if ( ! m_CastItem )
2010-02-20 23:59:05 +01:00
{
2014-10-21 20:27:00 +02:00
if ( ! m_castItemGUID . IsEmpty ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ITEM_NOT_READY ;
}
else
{
uint32 itemid = m_CastItem -> GetEntry ();
2013-07-20 21:52:05 +02:00
if ( ! player -> HasItemCount ( itemid ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ITEM_NOT_READY ;
2011-09-15 14:08:17 +02:00
ItemTemplate const * proto = m_CastItem -> GetTemplate ();
2010-04-07 19:14:10 +02:00
if ( ! proto )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ITEM_NOT_READY ;
2015-02-21 13:08:33 +01:00
for ( uint8 i = 0 ; i < proto -> Effects . size () && i < 5 ; ++ i )
if ( proto -> Effects [ i ] -> Charges )
2010-04-07 19:14:10 +02:00
if ( m_CastItem -> GetSpellCharges ( i ) == 0 )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NO_CHARGES_REMAIN ;
// consumable cast item checks
2014-12-21 13:35:43 +01:00
if ( proto -> GetClass () == ITEM_CLASS_CONSUMABLE && m_targets . GetUnitTarget ())
2010-02-20 23:59:05 +01:00
{
// such items should only fail if there is no suitable effect at all - see Rejuvenation Potions for example
SpellCastResult failReason = SPELL_CAST_OK ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2013-07-20 21:52:05 +02:00
// skip check, pet not required like checks, and for TARGET_UNIT_PET m_targets.GetUnitTarget() is not the real target but the caster
2014-11-27 15:11:43 +01:00
if ( ! effect || effect -> TargetA . GetTarget () == TARGET_UNIT_PET )
2010-02-20 23:59:05 +01:00
continue ;
2014-11-16 14:20:01 +01:00
if ( effect -> Effect == SPELL_EFFECT_HEAL )
2010-02-20 23:59:05 +01:00
{
2011-06-23 13:28:52 +02:00
if ( m_targets . GetUnitTarget () -> IsFullHealth ())
2010-02-20 23:59:05 +01:00
{
failReason = SPELL_FAILED_ALREADY_AT_FULL_HEALTH ;
continue ;
}
else
{
failReason = SPELL_CAST_OK ;
break ;
}
}
// Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
2014-11-16 14:20:01 +01:00
if ( effect -> Effect == SPELL_EFFECT_ENERGIZE )
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
if ( effect -> MiscValue < 0 || effect -> MiscValue >= int8 ( MAX_POWERS ))
2010-02-20 23:59:05 +01:00
{
failReason = SPELL_FAILED_ALREADY_AT_FULL_POWER ;
continue ;
}
2014-11-16 14:20:01 +01:00
Powers power = Powers ( effect -> MiscValue );
2012-08-17 14:30:10 +02:00
if ( m_targets . GetUnitTarget () -> GetPower ( power ) == m_targets . GetUnitTarget () -> GetMaxPower ( power ))
2010-02-20 23:59:05 +01:00
{
failReason = SPELL_FAILED_ALREADY_AT_FULL_POWER ;
continue ;
}
else
{
failReason = SPELL_CAST_OK ;
break ;
}
}
}
if ( failReason != SPELL_CAST_OK )
return failReason ;
}
}
// check target item
2014-10-21 20:27:00 +02:00
if ( ! m_targets . GetItemTargetGUID (). IsEmpty ())
2010-02-20 23:59:05 +01:00
{
2011-06-23 13:28:52 +02:00
if ( ! m_targets . GetItemTarget ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ITEM_GONE ;
2011-06-23 13:28:52 +02:00
if ( ! m_targets . GetItemTarget () -> IsFitToSpellRequirements ( m_spellInfo ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_EQUIPPED_ITEM_CLASS ;
}
// if not item target then required item must be equipped
else
{
2013-02-25 05:38:34 +02:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_EQUIPPED_ITEM_REQUIREMENT ))
2013-07-20 21:52:05 +02:00
if ( ! player -> HasItemFitToSpellRequirements ( m_spellInfo ))
2013-02-25 05:38:34 +02:00
return SPELL_FAILED_EQUIPPED_ITEM_CLASS ;
2010-02-20 23:59:05 +01:00
}
// do not take reagents for these item casts
2016-09-09 10:22:57 +02:00
if ( ! ( m_CastItem && m_CastItem -> GetTemplate () -> GetFlags () & ITEM_FLAG_NO_REAGENT_COST ))
2010-02-20 23:59:05 +01:00
{
2013-07-20 21:52:05 +02:00
bool checkReagents = ! ( _triggeredCastFlags & TRIGGERED_IGNORE_POWER_AND_REAGENT_COST ) && ! player -> CanNoReagentCast ( m_spellInfo );
2011-03-22 16:09:55 +01:00
// Not own traded item (in trader trade slot) requires reagents even if triggered spell
if ( ! checkReagents )
2011-06-23 13:28:52 +02:00
if ( Item * targetItem = m_targets . GetItemTarget ())
2011-03-22 16:09:55 +01:00
if ( targetItem -> GetOwnerGUID () != m_caster -> GetGUID ())
checkReagents = true ;
2010-02-20 23:59:05 +01:00
// check reagents (ignore triggered spells with reagents processed by original spell) and special reagent ignore case.
2011-03-22 16:09:55 +01:00
if ( checkReagents )
2010-02-20 23:59:05 +01:00
{
2010-09-28 08:41:24 +03:00
for ( uint32 i = 0 ; i < MAX_SPELL_REAGENTS ; i ++ )
2010-02-20 23:59:05 +01:00
{
2010-04-07 19:14:10 +02:00
if ( m_spellInfo -> Reagent [ i ] <= 0 )
2010-02-20 23:59:05 +01:00
continue ;
uint32 itemid = m_spellInfo -> Reagent [ i ];
uint32 itemcount = m_spellInfo -> ReagentCount [ i ];
// if CastItem is also spell reagent
2010-04-07 22:59:46 +02:00
if ( m_CastItem && m_CastItem -> GetEntry () == itemid )
2010-02-20 23:59:05 +01:00
{
2011-09-15 14:08:17 +02:00
ItemTemplate const * proto = m_CastItem -> GetTemplate ();
2010-04-07 19:14:10 +02:00
if ( ! proto )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ITEM_NOT_READY ;
2015-02-21 13:08:33 +01:00
for ( uint8 s = 0 ; s < proto -> Effects . size () && s < 5 ; ++ s )
2010-02-20 23:59:05 +01:00
{
// CastItem will be used up and does not count as reagent
int32 charges = m_CastItem -> GetSpellCharges ( s );
2015-02-21 13:08:33 +01:00
if ( proto -> Effects [ s ] -> Charges < 0 && abs ( charges ) < 2 )
2010-02-20 23:59:05 +01:00
{
++ itemcount ;
break ;
}
}
}
2013-07-20 21:52:05 +02:00
if ( ! player -> HasItemCount ( itemid , itemcount ))
2012-02-15 00:46:08 +01:00
return SPELL_FAILED_REAGENTS ;
2010-02-20 23:59:05 +01:00
}
}
// check totem-item requirements (items presence in inventory)
uint32 totems = 2 ;
2013-07-20 21:52:05 +02:00
for ( uint8 i = 0 ; i < 2 ; ++ i )
2010-02-20 23:59:05 +01:00
{
2010-04-07 19:14:10 +02:00
if ( m_spellInfo -> Totem [ i ] != 0 )
2010-02-20 23:59:05 +01:00
{
2013-07-20 21:52:05 +02:00
if ( player -> HasItemCount ( m_spellInfo -> Totem [ i ]))
2010-02-20 23:59:05 +01:00
{
totems -= 1 ;
continue ;
}
2013-07-20 21:52:05 +02:00
}
else
totems -= 1 ;
2010-02-20 23:59:05 +01:00
}
2015-02-21 16:58:09 +01:00
2010-04-07 19:14:10 +02:00
if ( totems != 0 )
2012-08-14 00:17:06 +02:00
return SPELL_FAILED_TOTEMS ;
2015-02-21 16:58:09 +01:00
// Check items for TotemCategory (items presence in inventory)
uint32 totemCategory = 2 ;
for ( uint8 i = 0 ; i < 2 ; ++ i )
{
if ( m_spellInfo -> TotemCategory [ i ] != 0 )
{
if ( player -> HasItemTotemCategory ( m_spellInfo -> TotemCategory [ i ]))
{
totemCategory -= 1 ;
continue ;
}
}
else
totemCategory -= 1 ;
}
if ( totemCategory != 0 )
return SPELL_FAILED_TOTEM_CATEGORY ;
2010-02-20 23:59:05 +01:00
}
// special checks for spell effects
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2014-11-27 15:11:43 +01:00
if ( ! effect )
continue ;
2014-11-16 14:20:01 +01:00
switch ( effect -> Effect )
2010-02-20 23:59:05 +01:00
{
case SPELL_EFFECT_CREATE_ITEM :
2017-04-06 23:39:34 +02:00
case SPELL_EFFECT_CREATE_LOOT :
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
if ( ! IsTriggered () && effect -> ItemType )
2010-02-20 23:59:05 +01:00
{
ItemPosCountVec dest ;
2014-11-16 14:20:01 +01:00
InventoryResult msg = player -> CanStoreNewItem ( NULL_BAG , NULL_SLOT , dest , effect -> ItemType , 1 );
2010-04-07 22:59:46 +02:00
if ( msg != EQUIP_ERR_OK )
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
ItemTemplate const * pProto = sObjectMgr -> GetItemTemplate ( effect -> ItemType );
2013-03-08 21:41:30 +01:00
/// @todo Needs review
2014-12-21 13:35:43 +01:00
if ( pProto && ! ( pProto -> GetItemLimitCategory ()))
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
player -> SendEquipError ( msg , NULL , NULL , effect -> ItemType );
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_DONT_REPORT ;
}
else
{
if ( ! ( m_spellInfo -> SpellFamilyName == SPELLFAMILY_MAGE && ( m_spellInfo -> SpellFamilyFlags [ 0 ] & 0x40000000 )))
return SPELL_FAILED_TOO_MANY_OF_ITEM ;
2014-11-16 14:20:01 +01:00
else if ( ! ( player -> HasItemCount ( effect -> ItemType )))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_TOO_MANY_OF_ITEM ;
2014-11-16 14:20:01 +01:00
else if ( SpellEffectInfo const * efi = GetEffect ( EFFECT_1 ))
player -> CastSpell ( m_caster , efi -> CalcValue (), false ); // move this to anywhere
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_DONT_REPORT ;
}
}
}
break ;
}
case SPELL_EFFECT_ENCHANT_ITEM :
2014-11-16 14:20:01 +01:00
if ( effect -> ItemType && m_targets . GetItemTarget ()
2012-08-15 16:30:49 +01:00
&& ( m_targets . GetItemTarget () -> IsVellum ()))
2010-02-20 23:59:05 +01:00
{
// cannot enchant vellum for other player
2011-06-23 13:28:52 +02:00
if ( m_targets . GetItemTarget () -> GetOwner () != m_caster )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NOT_TRADEABLE ;
// do not allow to enchant vellum from scroll made by vellum-prevent exploit
2016-09-09 10:22:57 +02:00
if ( m_CastItem && m_CastItem -> GetTemplate () -> GetFlags () & ITEM_FLAG_NO_REAGENT_COST )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_TOTEM_CATEGORY ;
ItemPosCountVec dest ;
2014-11-16 14:20:01 +01:00
InventoryResult msg = player -> CanStoreNewItem ( NULL_BAG , NULL_SLOT , dest , effect -> ItemType , 1 );
2010-04-07 22:59:46 +02:00
if ( msg != EQUIP_ERR_OK )
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
player -> SendEquipError ( msg , NULL , NULL , effect -> ItemType );
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_DONT_REPORT ;
}
}
2013-08-24 22:56:29 +01:00
// no break
2010-02-20 23:59:05 +01:00
case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC :
{
2011-06-23 13:28:52 +02:00
Item * targetItem = m_targets . GetItemTarget ();
2010-04-07 19:14:10 +02:00
if ( ! targetItem )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ITEM_NOT_FOUND ;
2014-12-21 13:35:43 +01:00
if ( targetItem -> GetTemplate () -> GetBaseItemLevel () < m_spellInfo -> BaseLevel )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_LOWLEVEL ;
2010-09-28 18:50:38 +02:00
bool isItemUsable = false ;
2014-11-14 14:47:20 +02:00
ItemTemplate const * proto = targetItem -> GetTemplate ();
for ( uint8 e = 0 ; e < proto -> Effects . size (); ++ e )
2010-09-28 18:50:38 +02:00
{
2016-08-22 18:15:33 +02:00
if ( proto -> Effects [ e ] -> SpellID && proto -> Effects [ e ] -> Trigger == ITEM_SPELLTRIGGER_ON_USE )
2010-09-28 18:50:38 +02:00
{
isItemUsable = true ;
break ;
}
}
2014-11-16 14:20:01 +01:00
SpellItemEnchantmentEntry const * enchantEntry = sSpellItemEnchantmentStore . LookupEntry ( effect -> MiscValue );
2010-09-28 18:50:38 +02:00
// do not allow adding usable enchantments to items that have use effect already
2013-12-23 14:25:34 +01:00
if ( enchantEntry )
{
2010-09-28 18:50:38 +02:00
for ( uint8 s = 0 ; s < MAX_ITEM_ENCHANTMENT_EFFECTS ; ++ s )
2013-12-23 14:25:34 +01:00
{
2014-11-10 02:51:55 +02:00
switch ( enchantEntry -> Effect [ s ])
2013-12-23 14:25:34 +01:00
{
case ITEM_ENCHANTMENT_TYPE_USE_SPELL :
if ( isItemUsable )
return SPELL_FAILED_ON_USE_ENCHANT ;
break ;
case ITEM_ENCHANTMENT_TYPE_PRISMATIC_SOCKET :
{
uint32 numSockets = 0 ;
for ( uint32 socket = 0 ; socket < MAX_ITEM_PROTO_SOCKETS ; ++ socket )
2014-12-23 00:25:43 +01:00
if ( targetItem -> GetSocketColor ( socket ))
2013-12-23 14:25:34 +01:00
++ numSockets ;
if ( numSockets == MAX_ITEM_PROTO_SOCKETS || targetItem -> GetEnchantmentId ( PRISMATIC_ENCHANTMENT_SLOT ))
return SPELL_FAILED_MAX_SOCKETS ;
break ;
}
}
}
}
2010-09-28 18:50:38 +02:00
2010-02-20 23:59:05 +01:00
// Not allow enchant in trade slot for some enchant type
2010-04-07 22:59:46 +02:00
if ( targetItem -> GetOwner () != m_caster )
2010-02-20 23:59:05 +01:00
{
2013-12-23 14:25:34 +01:00
if ( ! enchantEntry )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ERROR ;
2014-11-10 02:51:55 +02:00
if ( enchantEntry -> Flags & ENCHANTMENT_CAN_SOULBOUND )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NOT_TRADEABLE ;
}
break ;
}
case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY :
{
2011-09-15 14:08:17 +02:00
Item * item = m_targets . GetItemTarget ();
2010-04-07 19:14:10 +02:00
if ( ! item )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ITEM_NOT_FOUND ;
// Not allow enchant in trade slot for some enchant type
2010-04-07 22:59:46 +02:00
if ( item -> GetOwner () != m_caster )
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
uint32 enchant_id = effect -> MiscValue ;
2011-09-15 14:08:17 +02:00
SpellItemEnchantmentEntry const * pEnchant = sSpellItemEnchantmentStore . LookupEntry ( enchant_id );
2010-04-07 19:14:10 +02:00
if ( ! pEnchant )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ERROR ;
2014-11-10 02:51:55 +02:00
if ( pEnchant -> Flags & ENCHANTMENT_CAN_SOULBOUND )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NOT_TRADEABLE ;
}
break ;
}
case SPELL_EFFECT_ENCHANT_HELD_ITEM :
// check item existence in effect code (not output errors at offhand hold item effect to main hand for example
break ;
case SPELL_EFFECT_DISENCHANT :
{
2011-06-23 13:28:52 +02:00
if ( ! m_targets . GetItemTarget ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_DISENCHANTED ;
// prevent disenchanting in trade slot
2011-06-23 13:28:52 +02:00
if ( m_targets . GetItemTarget () -> GetOwnerGUID () != m_caster -> GetGUID ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_DISENCHANTED ;
2011-06-23 13:28:52 +02:00
ItemTemplate const * itemProto = m_targets . GetItemTarget () -> GetTemplate ();
2010-04-07 19:14:10 +02:00
if ( ! itemProto )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_DISENCHANTED ;
2014-12-21 13:35:43 +01:00
uint32 item_quality = itemProto -> GetQuality ();
2010-02-20 23:59:05 +01:00
// 2.0.x addon: Check player enchanting level against the item disenchanting requirements
uint32 item_disenchantskilllevel = itemProto -> RequiredDisenchantSkill ;
if ( item_disenchantskilllevel == uint32 ( - 1 ))
return SPELL_FAILED_CANT_BE_DISENCHANTED ;
2013-07-20 21:52:05 +02:00
if ( item_disenchantskilllevel > player -> GetSkillValue ( SKILL_ENCHANTING ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_LOW_CASTLEVEL ;
2010-04-07 19:14:10 +02:00
if ( item_quality > 4 || item_quality < 2 )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_DISENCHANTED ;
2014-12-21 13:35:43 +01:00
if ( itemProto -> GetClass () != ITEM_CLASS_WEAPON && itemProto -> GetClass () != ITEM_CLASS_ARMOR )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_DISENCHANTED ;
if ( ! itemProto -> DisenchantID )
return SPELL_FAILED_CANT_BE_DISENCHANTED ;
break ;
}
case SPELL_EFFECT_PROSPECTING :
{
2011-06-23 13:28:52 +02:00
if ( ! m_targets . GetItemTarget ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_PROSPECTED ;
//ensure item is a prospectable ore
2016-09-09 10:22:57 +02:00
if ( ! ( m_targets . GetItemTarget () -> GetTemplate () -> GetFlags () & ITEM_FLAG_IS_PROSPECTABLE ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_PROSPECTED ;
//prevent prospecting in trade slot
2011-06-23 13:28:52 +02:00
if ( m_targets . GetItemTarget () -> GetOwnerGUID () != m_caster -> GetGUID ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_PROSPECTED ;
//Check for enough skill in jewelcrafting
2014-12-21 13:35:43 +01:00
uint32 item_prospectingskilllevel = m_targets . GetItemTarget () -> GetTemplate () -> GetRequiredSkillRank ();
2013-07-20 21:52:05 +02:00
if ( item_prospectingskilllevel > player -> GetSkillValue ( SKILL_JEWELCRAFTING ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_LOW_CASTLEVEL ;
//make sure the player has the required ores in inventory
2011-06-23 13:28:52 +02:00
if ( m_targets . GetItemTarget () -> GetCount () < 5 )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NEED_MORE_ITEMS ;
2011-06-23 13:28:52 +02:00
if ( ! LootTemplates_Prospecting . HaveLootFor ( m_targets . GetItemTargetEntry ()))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_PROSPECTED ;
break ;
}
case SPELL_EFFECT_MILLING :
{
2011-06-23 13:28:52 +02:00
if ( ! m_targets . GetItemTarget ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_MILLED ;
//ensure item is a millable herb
2016-09-09 10:22:57 +02:00
if ( ! ( m_targets . GetItemTarget () -> GetTemplate () -> GetFlags () & ITEM_FLAG_IS_MILLABLE ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_MILLED ;
//prevent milling in trade slot
2011-06-23 13:28:52 +02:00
if ( m_targets . GetItemTarget () -> GetOwnerGUID () != m_caster -> GetGUID ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_MILLED ;
//Check for enough skill in inscription
2014-12-21 13:35:43 +01:00
uint32 item_millingskilllevel = m_targets . GetItemTarget () -> GetTemplate () -> GetRequiredSkillRank ();
2013-07-20 21:52:05 +02:00
if ( item_millingskilllevel > player -> GetSkillValue ( SKILL_INSCRIPTION ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_LOW_CASTLEVEL ;
//make sure the player has the required herbs in inventory
2011-06-23 13:28:52 +02:00
if ( m_targets . GetItemTarget () -> GetCount () < 5 )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NEED_MORE_ITEMS ;
2011-06-23 13:28:52 +02:00
if ( ! LootTemplates_Milling . HaveLootFor ( m_targets . GetItemTargetEntry ()))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_CANT_BE_MILLED ;
break ;
}
case SPELL_EFFECT_WEAPON_DAMAGE :
case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL :
{
2010-04-07 22:59:46 +02:00
if ( m_attackType != RANGED_ATTACK )
2010-02-20 23:59:05 +01:00
break ;
2012-05-30 08:01:02 +02:00
2013-07-20 21:52:05 +02:00
Item * pItem = player -> GetWeaponForAttack ( m_attackType );
2010-04-07 19:14:10 +02:00
if ( ! pItem || pItem -> IsBroken ())
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_EQUIPPED_ITEM ;
2014-12-21 13:35:43 +01:00
switch ( pItem -> GetTemplate () -> GetSubClass ())
2010-02-20 23:59:05 +01:00
{
case ITEM_SUBCLASS_WEAPON_THROWN :
{
uint32 ammo = pItem -> GetEntry ();
2013-07-20 21:52:05 +02:00
if ( ! player -> HasItemCount ( ammo ))
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_NO_AMMO ;
2013-07-20 21:52:05 +02:00
break ;
}
2010-02-20 23:59:05 +01:00
case ITEM_SUBCLASS_WEAPON_GUN :
case ITEM_SUBCLASS_WEAPON_BOW :
case ITEM_SUBCLASS_WEAPON_CROSSBOW :
case ITEM_SUBCLASS_WEAPON_WAND :
break ;
default :
break ;
}
break ;
}
case SPELL_EFFECT_CREATE_MANA_GEM :
{
2014-11-16 14:20:01 +01:00
uint32 item_id = effect -> ItemType ;
2014-12-02 00:07:36 +02:00
ItemTemplate const * pProto = sObjectMgr -> GetItemTemplate ( item_id );
2010-02-20 23:59:05 +01:00
2014-12-02 00:07:36 +02:00
if ( ! pProto )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ITEM_AT_MAX_CHARGES ;
2014-12-02 00:07:36 +02:00
if ( Item * pitem = player -> GetItemByEntry ( item_id ))
2010-02-20 23:59:05 +01:00
{
2015-02-21 13:08:33 +01:00
for ( uint8 x = 0 ; x < pProto -> Effects . size () && x < 5 ; ++ x )
if ( pProto -> Effects [ x ] -> Charges != 0 && pitem -> GetSpellCharges ( x ) == pProto -> Effects [ x ] -> Charges )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_ITEM_AT_MAX_CHARGES ;
}
2010-04-07 18:09:10 +02:00
break ;
2010-02-20 23:59:05 +01:00
}
default :
break ;
}
}
// check weapon presence in slots for main/offhand weapons
2013-02-25 05:38:34 +02:00
if ( ! ( _triggeredCastFlags & TRIGGERED_IGNORE_EQUIPPED_ITEM_REQUIREMENT ) && m_spellInfo -> EquippedItemClass >= 0 )
2010-02-20 23:59:05 +01:00
{
// main hand weapon required
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR3_MAIN_HAND ))
2010-02-20 23:59:05 +01:00
{
2010-03-07 15:20:19 +01:00
Item * item = m_caster -> ToPlayer () -> GetWeaponForAttack ( BASE_ATTACK );
2010-02-20 23:59:05 +01:00
// skip spell if no weapon in slot or broken
2010-04-07 22:59:46 +02:00
if ( ! item || item -> IsBroken ())
2016-05-11 18:29:02 +02:00
return SPELL_FAILED_EQUIPPED_ITEM_CLASS ;
2010-02-20 23:59:05 +01:00
// skip spell if weapon not fit to triggered spell
2010-04-07 19:14:10 +02:00
if ( ! item -> IsFitToSpellRequirements ( m_spellInfo ))
2016-05-11 18:29:02 +02:00
return SPELL_FAILED_EQUIPPED_ITEM_CLASS ;
2010-02-20 23:59:05 +01:00
}
// offhand hand weapon required
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR3_REQ_OFFHAND ))
2010-02-20 23:59:05 +01:00
{
2010-03-07 15:20:19 +01:00
Item * item = m_caster -> ToPlayer () -> GetWeaponForAttack ( OFF_ATTACK );
2010-02-20 23:59:05 +01:00
// skip spell if no weapon in slot or broken
2010-04-07 22:59:46 +02:00
if ( ! item || item -> IsBroken ())
2016-05-11 18:29:02 +02:00
return SPELL_FAILED_EQUIPPED_ITEM_CLASS ;
2010-02-20 23:59:05 +01:00
// skip spell if weapon not fit to triggered spell
2010-04-07 19:14:10 +02:00
if ( ! item -> IsFitToSpellRequirements ( m_spellInfo ))
2016-05-11 18:29:02 +02:00
return SPELL_FAILED_EQUIPPED_ITEM_CLASS ;
2010-02-20 23:59:05 +01:00
}
}
return SPELL_CAST_OK ;
}
void Spell :: Delayed () // only called in DealDamage()
{
2010-04-07 19:14:10 +02:00
if ( ! m_caster ) // || m_caster->GetTypeId() != TYPEID_PLAYER)
2010-02-20 23:59:05 +01:00
return ;
//if (m_spellState == SPELL_STATE_DELAYED)
// return; // spell is active and can't be time-backed
2010-04-07 19:14:10 +02:00
if ( isDelayableNoMore ()) // Spells may only be delayed twice
2010-02-20 23:59:05 +01:00
return ;
2010-04-07 22:59:46 +02:00
// spells not loosing casting time (slam, dynamites, bombs..)
2010-04-07 19:14:10 +02:00
//if (!(m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_DAMAGE))
2010-02-20 23:59:05 +01:00
// return;
//check pushback reduce
int32 delaytime = 500 ; // spellcasting delay is normally 500ms
int32 delayReduce = 100 ; // must be initialized to 100 for percent modifiers
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> ApplySpellMod ( m_spellInfo -> Id , SPELLMOD_NOT_LOSE_CASTING_TIME , delayReduce , this );
2010-02-20 23:59:05 +01:00
delayReduce += m_caster -> GetTotalAuraModifier ( SPELL_AURA_REDUCE_PUSHBACK ) - 100 ;
2010-04-07 19:14:10 +02:00
if ( delayReduce >= 100 )
2010-02-20 23:59:05 +01:00
return ;
2012-10-02 12:17:42 +02:00
AddPct ( delaytime , - delayReduce );
2010-02-20 23:59:05 +01:00
2011-12-22 00:38:01 +01:00
if ( m_timer + delaytime > m_casttime )
2010-02-20 23:59:05 +01:00
{
delaytime = m_casttime - m_timer ;
m_timer = m_casttime ;
}
else
m_timer += delaytime ;
2015-03-08 05:18:51 +01:00
TC_LOG_DEBUG ( "spells" , "Spell %u partially interrupted for (%d) ms at damage" , m_spellInfo -> Id , delaytime );
2010-02-20 23:59:05 +01:00
2016-02-29 00:23:23 +00:00
WorldPackets :: Spells :: SpellDelayed spellDelayed ;
spellDelayed . Caster = m_caster -> GetGUID ();
spellDelayed . ActualDelay = delaytime ;
2010-02-20 23:59:05 +01:00
2016-02-29 00:23:23 +00:00
m_caster -> SendMessageToSet ( spellDelayed . Write (), true );
2010-02-20 23:59:05 +01:00
}
void Spell :: DelayedChannel ()
{
if ( ! m_caster || m_caster -> GetTypeId () != TYPEID_PLAYER || getState () != SPELL_STATE_CASTING )
return ;
if ( isDelayableNoMore ()) // Spells may only be delayed twice
return ;
//check pushback reduce
2014-08-18 09:37:30 +02:00
// should be affected by modifiers, not take the dbc duration.
int32 duration = (( m_channeledDuration > 0 ) ? m_channeledDuration : m_spellInfo -> GetDuration ());
int32 delaytime = CalculatePct ( duration , 25 ); // channeling delay is normally 25% of its time per hit
2010-02-20 23:59:05 +01:00
int32 delayReduce = 100 ; // must be initialized to 100 for percent modifiers
2010-03-07 15:20:19 +01:00
m_caster -> ToPlayer () -> ApplySpellMod ( m_spellInfo -> Id , SPELLMOD_NOT_LOSE_CASTING_TIME , delayReduce , this );
2010-02-20 23:59:05 +01:00
delayReduce += m_caster -> GetTotalAuraModifier ( SPELL_AURA_REDUCE_PUSHBACK ) - 100 ;
2010-04-07 19:14:10 +02:00
if ( delayReduce >= 100 )
2010-02-20 23:59:05 +01:00
return ;
2012-10-02 12:17:42 +02:00
AddPct ( delaytime , - delayReduce );
2010-02-20 23:59:05 +01:00
2011-12-22 00:38:01 +01:00
if ( m_timer <= delaytime )
2010-02-20 23:59:05 +01:00
{
delaytime = m_timer ;
m_timer = 0 ;
}
else
m_timer -= delaytime ;
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "Spell %u partially interrupted for %i ms, new duration: %u ms" , m_spellInfo -> Id , delaytime , m_timer );
2010-02-20 23:59:05 +01:00
2015-02-12 22:08:17 +00:00
for ( std :: vector < TargetInfo >:: const_iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
if (( * ihit ). missCondition == SPELL_MISS_NONE )
if ( Unit * unit = ( m_caster -> GetGUID () == ihit -> targetGUID ) ? m_caster : ObjectAccessor :: GetUnit ( * m_caster , ihit -> targetGUID ))
unit -> DelayOwnedAuras ( m_spellInfo -> Id , m_originalCasterGUID , delaytime );
// partially interrupt persistent area auras
2010-04-07 19:14:10 +02:00
if ( DynamicObject * dynObj = m_caster -> GetDynObject ( m_spellInfo -> Id ))
2010-02-20 23:59:05 +01:00
dynObj -> Delay ( delaytime );
SendChannelUpdate ( m_timer );
}
2014-05-03 21:22:12 +02:00
bool Spell :: UpdatePointers ()
2010-02-20 23:59:05 +01:00
{
2010-04-07 19:14:10 +02:00
if ( m_originalCasterGUID == m_caster -> GetGUID ())
2010-02-20 23:59:05 +01:00
m_originalCaster = m_caster ;
else
{
2011-04-29 20:47:02 +02:00
m_originalCaster = ObjectAccessor :: GetUnit ( * m_caster , m_originalCasterGUID );
2010-02-20 23:59:05 +01:00
if ( m_originalCaster && ! m_originalCaster -> IsInWorld ())
m_originalCaster = NULL ;
}
2014-10-21 19:23:32 +02:00
if ( ! m_castItemGUID . IsEmpty () && m_caster -> GetTypeId () == TYPEID_PLAYER )
2014-05-03 21:22:12 +02:00
{
2010-03-07 15:20:19 +01:00
m_CastItem = m_caster -> ToPlayer () -> GetItemByGuid ( m_castItemGUID );
2015-11-24 00:16:42 +01:00
m_castItemLevel = - 1 ;
2014-05-03 21:22:12 +02:00
// cast item not found, somehow the item is no longer where we expected
if ( ! m_CastItem )
return false ;
2014-05-04 13:41:07 +02:00
2014-05-05 20:05:33 +02:00
// check if the item is really the same, in case it has been wrapped for example
if ( m_castItemEntry != m_CastItem -> GetEntry ())
2014-05-04 13:41:07 +02:00
return false ;
2015-11-24 00:16:42 +01:00
m_castItemLevel = int32 ( m_CastItem -> GetItemLevel ( m_caster -> ToPlayer ()));
2014-05-03 21:22:12 +02:00
}
2010-02-20 23:59:05 +01:00
m_targets . Update ( m_caster );
2012-05-30 08:01:02 +02:00
// further actions done only for dest targets
if ( ! m_targets . HasDst ())
2014-05-03 21:22:12 +02:00
return true ;
2012-05-30 08:01:02 +02:00
// cache last transport
WorldObject * transport = NULL ;
// update effect destinations (in case of moved transport dest target)
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2012-05-30 08:01:02 +02:00
{
2014-11-27 15:11:43 +01:00
if ( ! effect )
continue ;
2014-11-16 14:20:01 +01:00
SpellDestination & dest = m_destTargets [ effect -> EffectIndex ];
2012-05-30 08:01:02 +02:00
if ( ! dest . _transportGUID )
continue ;
if ( ! transport || transport -> GetGUID () != dest . _transportGUID )
transport = ObjectAccessor :: GetWorldObject ( * m_caster , dest . _transportGUID );
if ( transport )
{
dest . _position . Relocate ( transport );
dest . _position . RelocateOffset ( dest . _transportOffset );
}
}
2014-05-03 21:22:12 +02:00
return true ;
2010-02-20 23:59:05 +01:00
}
2011-08-21 13:57:15 +02:00
CurrentSpellTypes Spell :: GetCurrentContainer () const
2010-02-20 23:59:05 +01:00
{
if ( IsNextMeleeSwingSpell ())
return ( CURRENT_MELEE_SPELL );
else if ( IsAutoRepeat ())
return ( CURRENT_AUTOREPEAT_SPELL );
2011-07-26 23:09:28 +02:00
else if ( m_spellInfo -> IsChanneled ())
2010-02-20 23:59:05 +01:00
return ( CURRENT_CHANNELED_SPELL );
else
return ( CURRENT_GENERIC_SPELL );
}
2014-12-29 01:00:16 +01:00
bool Spell :: CheckEffectTarget ( Unit const * target , SpellEffectInfo const * effect , Position const * losPosition ) const
2010-02-20 23:59:05 +01:00
{
2014-12-29 01:00:16 +01:00
if ( ! effect -> IsEffect ())
2014-11-16 14:20:01 +01:00
return false ;
switch ( effect -> ApplyAuraName )
2010-02-20 23:59:05 +01:00
{
case SPELL_AURA_MOD_POSSESS :
case SPELL_AURA_MOD_CHARM :
case SPELL_AURA_MOD_POSSESS_PET :
case SPELL_AURA_AOE_CHARM :
2010-04-07 19:14:10 +02:00
if ( target -> GetTypeId () == TYPEID_UNIT && target -> IsVehicle ())
2010-02-20 23:59:05 +01:00
return false ;
2010-07-20 01:42:14 +02:00
if ( target -> IsMounted ())
return false ;
2014-10-21 20:27:00 +02:00
if ( ! target -> GetCharmerGUID (). IsEmpty ())
2010-02-20 23:59:05 +01:00
return false ;
2015-07-21 00:33:36 +02:00
if ( int32 value = CalculateDamage ( effect -> EffectIndex , target ))
if (( int32 ) target -> getLevel () > value )
2010-02-20 23:59:05 +01:00
return false ;
break ;
2011-08-19 14:53:40 +02:00
default :
break ;
2010-02-20 23:59:05 +01:00
}
2014-08-26 09:40:34 +02:00
// check for ignore LOS on the effect itself
2015-01-05 23:49:43 +02:00
if ( m_spellInfo -> HasAttribute ( SPELL_ATTR2_CAN_TARGET_NOT_IN_LOS ) || DisableMgr :: IsDisabledFor ( DISABLE_TYPE_SPELL , m_spellInfo -> Id , NULL , SPELL_DISABLE_LOS ))
2014-08-25 17:16:02 +02:00
return true ;
2014-09-07 04:06:50 +02:00
2014-08-26 09:40:34 +02:00
// if spell is triggered, need to check for LOS disable on the aura triggering it and inherit that behaviour
2015-01-05 23:49:43 +02:00
if ( IsTriggered () && m_triggeredByAuraSpell && ( m_triggeredByAuraSpell -> HasAttribute ( SPELL_ATTR2_CAN_TARGET_NOT_IN_LOS ) || DisableMgr :: IsDisabledFor ( DISABLE_TYPE_SPELL , m_triggeredByAuraSpell -> Id , NULL , SPELL_DISABLE_LOS )))
2010-02-20 23:59:05 +01:00
return true ;
2013-03-08 21:41:30 +01:00
/// @todo shit below shouldn't be here, but it's temporary
2016-08-09 17:21:19 +02:00
//Check targets for LOS visibility
if ( losPosition )
return target -> IsWithinLOS ( losPosition -> GetPositionX (), losPosition -> GetPositionY (), losPosition -> GetPositionZ ());
else
2010-02-20 23:59:05 +01:00
{
2016-08-09 17:21:19 +02:00
// Get GO cast coordinates if original caster -> GO
WorldObject * caster = NULL ;
if ( m_originalCasterGUID . IsGameObject ())
caster = m_caster -> GetMap () -> GetGameObject ( m_originalCasterGUID );
if ( ! caster )
caster = m_caster ;
if ( target != m_caster && ! target -> IsWithinLOSInMap ( caster ))
return false ;
2010-02-20 23:59:05 +01:00
}
return true ;
}
2014-12-29 01:00:16 +01:00
bool Spell :: CheckEffectTarget ( GameObject const * target , SpellEffectInfo const * effect ) const
{
if ( ! effect -> IsEffect ())
return false ;
switch ( effect -> Effect )
{
case SPELL_EFFECT_GAMEOBJECT_DAMAGE :
case SPELL_EFFECT_GAMEOBJECT_REPAIR :
case SPELL_EFFECT_GAMEOBJECT_SET_DESTRUCTION_STATE :
if ( target -> GetGoType () != GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING )
return false ;
break ;
default :
break ;
}
return true ;
}
2014-12-29 01:32:55 +01:00
bool Spell :: CheckEffectTarget ( Item const * /*target*/ , SpellEffectInfo const * effect ) const
2014-12-29 01:00:16 +01:00
{
if ( ! effect -> IsEffect ())
return false ;
return true ;
}
2011-07-26 23:09:28 +02:00
bool Spell :: IsNextMeleeSwingSpell () const
{
2015-01-05 23:49:43 +02:00
return m_spellInfo -> HasAttribute ( SPELL_ATTR0_ON_NEXT_SWING );
2011-07-26 23:09:28 +02:00
}
2011-07-27 12:35:59 +02:00
bool Spell :: IsAutoActionResetSpell () const
2011-07-26 23:09:28 +02:00
{
2013-03-08 21:41:30 +01:00
/// @todo changed SPELL_INTERRUPT_FLAG_AUTOATTACK -> SPELL_INTERRUPT_FLAG_INTERRUPT to fix compile - is this check correct at all?
2016-10-02 00:24:47 -03:00
if ( IsTriggered () || ! ( m_spellInfo -> InterruptFlags & SPELL_INTERRUPT_FLAG_INTERRUPT ))
return false ;
if ( ! m_casttime && m_spellInfo -> HasAttribute ( SPELL_ATTR6_NOT_RESET_SWING_IF_INSTANT ))
return false ;
return true ;
2011-07-26 23:09:28 +02:00
}
2010-02-20 23:59:05 +01:00
bool Spell :: IsNeedSendToClient () const
{
2016-06-29 19:49:23 +02:00
return m_SpellVisual || m_spellInfo -> IsChanneled () ||
2015-01-05 23:49:43 +02:00
( m_spellInfo -> HasAttribute ( SPELL_ATTR8_AURA_SEND_AMOUNT )) || m_spellInfo -> Speed > 0.0f || ( ! m_triggeredByAuraSpell && ! IsTriggered ());
2010-02-20 23:59:05 +01:00
}
2010-04-07 22:59:46 +02:00
bool Spell :: HaveTargetsForEffect ( uint8 effect ) const
2010-02-20 23:59:05 +01:00
{
2015-02-12 22:08:17 +00:00
for ( std :: vector < TargetInfo >:: const_iterator itr = m_UniqueTargetInfo . begin (); itr != m_UniqueTargetInfo . end (); ++ itr )
2010-04-07 19:14:10 +02:00
if ( itr -> effectMask & ( 1 << effect ))
2010-02-20 23:59:05 +01:00
return true ;
2015-02-12 22:08:17 +00:00
for ( std :: vector < GOTargetInfo >:: const_iterator itr = m_UniqueGOTargetInfo . begin (); itr != m_UniqueGOTargetInfo . end (); ++ itr )
2010-04-07 19:14:10 +02:00
if ( itr -> effectMask & ( 1 << effect ))
2010-02-20 23:59:05 +01:00
return true ;
2015-02-12 22:08:17 +00:00
for ( std :: vector < ItemTargetInfo >:: const_iterator itr = m_UniqueItemInfo . begin (); itr != m_UniqueItemInfo . end (); ++ itr )
2010-04-07 19:14:10 +02:00
if ( itr -> effectMask & ( 1 << effect ))
2010-02-20 23:59:05 +01:00
return true ;
return false ;
}
SpellEvent :: SpellEvent ( Spell * spell ) : BasicEvent ()
{
m_Spell = spell ;
}
SpellEvent ::~ SpellEvent ()
{
if ( m_Spell -> getState () != SPELL_STATE_FINISHED )
m_Spell -> cancel ();
if ( m_Spell -> IsDeletable ())
{
delete m_Spell ;
}
else
{
2014-10-22 21:22:04 +02:00
TC_LOG_ERROR ( "spells" , "~SpellEvent: %s %s tried to delete non-deletable spell %u. Was not deleted, causes memory leak." ,
( m_Spell -> GetCaster () -> GetTypeId () == TYPEID_PLAYER ? "Player" : "Creature" ), m_Spell -> GetCaster () -> GetGUID (). ToString (). c_str (), m_Spell -> m_spellInfo -> Id );
2015-09-21 15:17:05 +02:00
ABORT ();
2010-02-20 23:59:05 +01:00
}
}
bool SpellEvent :: Execute ( uint64 e_time , uint32 p_time )
{
// update spell if it is not finished
if ( m_Spell -> getState () != SPELL_STATE_FINISHED )
m_Spell -> update ( p_time );
// check spell state to process
switch ( m_Spell -> getState ())
{
case SPELL_STATE_FINISHED :
{
// spell was finished, check deletable state
if ( m_Spell -> IsDeletable ())
{
// check, if we do have unfinished triggered spells
return true ; // spell is deletable, finish event
}
// event will be re-added automatically at the end of routine)
2016-06-28 17:38:19 +02:00
break ;
}
2010-02-20 23:59:05 +01:00
case SPELL_STATE_DELAYED :
{
// first, check, if we have just started
if ( m_Spell -> GetDelayStart () != 0 )
{
// no, we aren't, do the typical update
// check, if we have channeled spell on our hands
/*
2012-05-30 08:01:02 +02:00
if (m_Spell->m_spellInfo->IsChanneled())
2010-02-20 23:59:05 +01:00
{
2013-12-25 14:16:55 -03:30
// evented channeled spell is processed separately, cast once after delay, and not destroyed till finish
2010-02-20 23:59:05 +01:00
// check, if we have casting anything else except this channeled spell and autorepeat
2013-12-25 14:16:55 -03:30
if (m_Spell->GetCaster()->IsNonMeleeSpellCast(false, true, true))
2010-02-20 23:59:05 +01:00
{
2013-12-25 14:16:55 -03:30
// another non-melee non-delayed spell is cast now, abort
2010-02-20 23:59:05 +01:00
m_Spell->cancel();
}
else
{
// Set last not triggered spell for apply spellmods
((Player*)m_Spell->GetCaster())->SetSpellModTakingSpell(m_Spell, true);
// do the action (pass spell to channeling state)
m_Spell->handle_immediate();
// And remove after effect handling
((Player*)m_Spell->GetCaster())->SetSpellModTakingSpell(m_Spell, false);
}
// event will be re-added automatically at the end of routine)
}
else
*/
{
// run the spell handler and think about what we can do next
uint64 t_offset = e_time - m_Spell -> GetDelayStart ();
uint64 n_offset = m_Spell -> handle_delayed ( t_offset );
if ( n_offset )
{
// re-add us to the queue
m_Spell -> GetCaster () -> m_Events . AddEvent ( this , m_Spell -> GetDelayStart () + n_offset , false );
return false ; // event not complete
}
// event complete
// finish update event will be re-added automatically at the end of routine)
}
}
else
{
// delaying had just started, record the moment
m_Spell -> SetDelayStart ( e_time );
2016-06-28 17:38:19 +02:00
// handle effects on caster if the spell has travel time but also affects the caster in some way
2016-07-05 00:02:04 +02:00
if ( ! m_Spell -> m_targets . HasDst ())
{
uint64 n_offset = m_Spell -> handle_delayed ( 0 );
ASSERT ( n_offset == m_Spell -> GetDelayMoment ());
}
2010-02-20 23:59:05 +01:00
// re-plan the event for the delay moment
m_Spell -> GetCaster () -> m_Events . AddEvent ( this , e_time + m_Spell -> GetDelayMoment (), false );
return false ; // event not complete
}
2016-06-28 17:38:19 +02:00
break ;
}
2010-02-20 23:59:05 +01:00
default :
{
// all other states
// event will be re-added automatically at the end of routine)
2016-06-28 17:38:19 +02:00
break ;
}
2010-02-20 23:59:05 +01:00
}
// spell processing not complete, plan event on the next update interval
m_Spell -> GetCaster () -> m_Events . AddEvent ( this , e_time + 1 , false );
return false ; // event not complete
}
void SpellEvent :: Abort ( uint64 /*e_time*/ )
{
// oops, the spell we try to do is aborted
if ( m_Spell -> getState () != SPELL_STATE_FINISHED )
m_Spell -> cancel ();
}
bool SpellEvent :: IsDeletable () const
{
return m_Spell -> IsDeletable ();
}
2010-08-30 17:32:51 +02:00
bool Spell :: IsValidDeadOrAliveTarget ( Unit const * target ) const
{
2013-06-11 19:54:27 -02:30
if ( target -> IsAlive ())
2011-07-26 23:09:28 +02:00
return ! m_spellInfo -> IsRequiringDeadTarget ();
if ( m_spellInfo -> IsAllowingDeadTarget ())
2010-08-30 17:32:51 +02:00
return true ;
return false ;
}
2011-09-25 13:29:17 +02:00
void Spell :: HandleLaunchPhase ()
2010-02-20 23:59:05 +01:00
{
2011-09-25 13:29:17 +02:00
// handle effects with SPELL_EFFECT_HANDLE_LAUNCH mode
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2011-09-25 13:29:17 +02:00
{
// don't do anything for empty effect
2014-11-27 15:11:43 +01:00
if ( ! effect || ! effect -> IsEffect ())
2011-09-25 13:29:17 +02:00
continue ;
2014-11-16 14:20:01 +01:00
HandleEffects ( NULL , NULL , NULL , effect -> EffectIndex , SPELL_EFFECT_HANDLE_LAUNCH );
2011-09-25 13:29:17 +02:00
}
2010-08-26 19:07:55 +02:00
float multiplier [ MAX_SPELL_EFFECTS ];
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2014-11-27 15:11:43 +01:00
if ( effect && ( m_applyMultiplierMask & ( 1 << effect -> EffectIndex )))
2014-11-16 14:20:01 +01:00
multiplier [ effect -> EffectIndex ] = effect -> CalcDamageMultiplier ( m_originalCaster , this );
2010-02-20 23:59:05 +01:00
2015-06-01 00:26:49 +01:00
for ( std :: vector < TargetInfo >:: iterator ihit = m_UniqueTargetInfo . begin (); ihit != m_UniqueTargetInfo . end (); ++ ihit )
2010-02-20 23:59:05 +01:00
{
2011-09-25 13:29:17 +02:00
TargetInfo & target = * ihit ;
2010-02-20 23:59:05 +01:00
uint32 mask = target . effectMask ;
if ( ! mask )
continue ;
2011-09-25 13:29:17 +02:00
DoAllEffectOnLaunchTarget ( target , multiplier );
2010-02-20 23:59:05 +01:00
}
}
2011-09-25 13:29:17 +02:00
void Spell :: DoAllEffectOnLaunchTarget ( TargetInfo & targetInfo , float * multiplier )
2010-02-20 23:59:05 +01:00
{
2011-09-25 13:29:17 +02:00
Unit * unit = NULL ;
// In case spell hit target, do all effect on that target
if ( targetInfo . missCondition == SPELL_MISS_NONE )
unit = m_caster -> GetGUID () == targetInfo . targetGUID ? m_caster : ObjectAccessor :: GetUnit ( * m_caster , targetInfo . targetGUID );
// In case spell reflect from target, do all effect on caster (if hit)
else if ( targetInfo . missCondition == SPELL_MISS_REFLECT && targetInfo . reflectResult == SPELL_MISS_NONE )
unit = m_caster ;
if ( ! unit )
return ;
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2010-02-20 23:59:05 +01:00
{
2014-11-27 15:11:43 +01:00
if ( effect && ( targetInfo . effectMask & ( 1 << effect -> EffectIndex )))
2010-02-20 23:59:05 +01:00
{
m_damage = 0 ;
2011-09-25 13:29:17 +02:00
m_healing = 0 ;
2010-02-20 23:59:05 +01:00
2014-11-16 14:20:01 +01:00
HandleEffects ( unit , NULL , NULL , effect -> EffectIndex , SPELL_EFFECT_HANDLE_LAUNCH_TARGET );
2010-02-20 23:59:05 +01:00
2010-04-07 19:14:10 +02:00
if ( m_damage > 0 )
2010-02-20 23:59:05 +01:00
{
2014-11-16 14:20:01 +01:00
if ( effect -> IsTargetingArea () || effect -> IsAreaAuraEffect () || effect -> IsEffect ( SPELL_EFFECT_PERSISTENT_AREA_AURA ))
2010-02-20 23:59:05 +01:00
{
2010-08-22 12:39:39 -07:00
m_damage = int32 ( float ( m_damage ) * unit -> GetTotalAuraMultiplierByMiscMask ( SPELL_AURA_MOD_AOE_DAMAGE_AVOIDANCE , m_spellInfo -> SchoolMask ));
2014-02-04 11:31:13 +01:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER )
2010-08-22 12:39:39 -07:00
m_damage = int32 ( float ( m_damage ) * unit -> GetTotalAuraMultiplierByMiscMask ( SPELL_AURA_MOD_CREATURE_AOE_DAMAGE_AVOIDANCE , m_spellInfo -> SchoolMask ));
2010-07-16 13:20:50 +02:00
2010-02-20 23:59:05 +01:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
{
uint32 targetAmount = m_UniqueTargetInfo . size ();
if ( targetAmount > 10 )
m_damage = m_damage * 10 / targetAmount ;
}
}
}
2014-11-16 14:20:01 +01:00
if ( m_applyMultiplierMask & ( 1 << effect -> EffectIndex ))
2010-12-04 10:31:14 +01:00
{
2014-11-16 14:20:01 +01:00
m_damage = int32 ( m_damage * m_damageMultipliers [ effect -> EffectIndex ]);
m_damageMultipliers [ effect -> EffectIndex ] *= multiplier [ effect -> EffectIndex ];
2010-12-04 10:31:14 +01:00
}
2011-09-25 13:29:17 +02:00
targetInfo . damage += m_damage ;
2010-02-20 23:59:05 +01:00
}
}
2016-09-02 08:59:14 +02:00
if ( Player * modOwner = m_caster -> GetSpellModOwner ())
modOwner -> SetSpellModTakingSpell ( this , true );
targetInfo . crit = m_caster -> IsSpellCrit ( unit , m_spellInfo , m_spellSchoolMask , m_attackType );
if ( Player * modOwner = m_caster -> GetSpellModOwner ())
modOwner -> SetSpellModTakingSpell ( this , false );
2010-02-20 23:59:05 +01:00
}
SpellCastResult Spell :: CanOpenLock ( uint32 effIndex , uint32 lockId , SkillType & skillId , int32 & reqSkillValue , int32 & skillValue )
{
2010-04-07 19:14:10 +02:00
if ( ! lockId ) // possible case for GO and maybe for items.
2010-02-20 23:59:05 +01:00
return SPELL_CAST_OK ;
// Get LockInfo
2011-09-15 14:08:17 +02:00
LockEntry const * lockInfo = sLockStore . LookupEntry ( lockId );
2010-02-20 23:59:05 +01:00
if ( ! lockInfo )
return SPELL_FAILED_BAD_TARGETS ;
2014-11-16 14:20:01 +01:00
SpellEffectInfo const * effect = GetEffect ( effIndex );
if ( ! effect )
return SPELL_FAILED_BAD_TARGETS ; // no idea about correct error
2010-02-20 23:59:05 +01:00
bool reqKey = false ; // some locks not have reqs
2010-09-28 08:41:24 +03:00
for ( int j = 0 ; j < MAX_LOCK_CASE ; ++ j )
2010-02-20 23:59:05 +01:00
{
2011-09-05 14:01:50 +02:00
switch ( lockInfo -> Type [ j ])
2010-02-20 23:59:05 +01:00
{
// check key item (many fit cases can be)
case LOCK_KEY_ITEM :
2010-04-07 23:25:02 +02:00
if ( lockInfo -> Index [ j ] && m_CastItem && m_CastItem -> GetEntry () == lockInfo -> Index [ j ])
2010-02-20 23:59:05 +01:00
return SPELL_CAST_OK ;
reqKey = true ;
break ;
// check key skill (only single first fit case can be)
case LOCK_KEY_SKILL :
{
reqKey = true ;
// wrong locktype, skip
2014-11-16 14:20:01 +01:00
if ( uint32 ( effect -> MiscValue ) != lockInfo -> Index [ j ])
2010-02-20 23:59:05 +01:00
continue ;
skillId = SkillByLockType ( LockType ( lockInfo -> Index [ j ]));
2016-06-18 17:38:44 +02:00
if ( skillId != SKILL_NONE || lockInfo -> Index [ j ] == LOCKTYPE_PICKLOCK )
2010-02-20 23:59:05 +01:00
{
reqSkillValue = lockInfo -> Skill [ j ];
// castitem check: rogue using skeleton keys. the skill values should not be added in this case.
2016-06-18 17:38:44 +02:00
skillValue = 0 ;
if ( ! m_CastItem && m_caster -> GetTypeId () == TYPEID_PLAYER )
skillValue = m_caster -> ToPlayer () -> GetSkillValue ( skillId );
else if ( lockInfo -> Index [ j ] == LOCKTYPE_PICKLOCK )
skillValue = m_caster -> getLevel () * 5 ;
2010-02-20 23:59:05 +01:00
2011-03-01 17:47:53 +02:00
// skill bonus provided by casting spell (mostly item spells)
2013-12-25 14:16:55 -03:30
// add the effect base points modifier from the spell cast (cheat lock / skeleton key etc.)
2014-11-16 14:20:01 +01:00
if ( effect -> TargetA . GetTarget () == TARGET_GAMEOBJECT_ITEM_TARGET || effect -> TargetB . GetTarget () == TARGET_GAMEOBJECT_ITEM_TARGET )
skillValue += effect -> CalcValue ();
2010-02-20 23:59:05 +01:00
if ( skillValue < reqSkillValue )
return SPELL_FAILED_LOW_CASTLEVEL ;
}
return SPELL_CAST_OK ;
}
}
}
2010-04-07 19:14:10 +02:00
if ( reqKey )
2010-02-20 23:59:05 +01:00
return SPELL_FAILED_BAD_TARGETS ;
return SPELL_CAST_OK ;
}
void Spell :: SetSpellValue ( SpellValueMod mod , int32 value )
{
2014-11-16 14:20:01 +01:00
if ( mod < SPELLVALUE_BASE_POINT_END )
{
if ( SpellEffectInfo const * effect = GetEffect ( mod ))
m_spellValue -> EffectBasePoints [ mod ] = effect -> CalcBaseValue ( value );
return ;
}
2011-05-21 21:36:37 +02:00
switch ( mod )
2010-02-20 23:59:05 +01:00
{
case SPELLVALUE_RADIUS_MOD :
m_spellValue -> RadiusMod = ( float ) value / 10000 ;
break ;
case SPELLVALUE_MAX_TARGETS :
m_spellValue -> MaxAffectedTargets = ( uint32 ) value ;
break ;
2011-05-21 21:36:37 +02:00
case SPELLVALUE_AURA_STACK :
m_spellValue -> AuraStackAmount = uint8 ( value );
break ;
2014-12-29 01:32:55 +01:00
default :
break ;
2010-02-20 23:59:05 +01:00
}
}
2010-08-27 17:49:32 +02:00
void Spell :: PrepareTargetProcessing ()
{
}
void Spell :: FinishTargetProcessing ()
{
2015-04-18 17:02:33 +02:00
SendSpellExecuteLog ();
2010-08-27 17:49:32 +02:00
}
2010-07-24 22:41:42 +02:00
void Spell :: LoadScripts ()
{
2016-11-13 21:44:04 -03:00
sScriptMgr -> CreateSpellScripts ( m_spellInfo -> Id , m_loadedScripts , this );
for ( auto itr = m_loadedScripts . begin (); itr != m_loadedScripts . end (); ++ itr )
2010-07-24 22:41:42 +02:00
{
2013-11-08 10:50:51 +01:00
TC_LOG_DEBUG ( "spells" , "Spell::LoadScripts: Script `%s` for spell `%u` is loaded now" , ( * itr ) -> _GetScriptName () -> c_str (), m_spellInfo -> Id );
2010-07-24 22:41:42 +02:00
( * itr ) -> Register ();
}
}
2010-08-19 14:31:31 +02:00
2011-12-31 13:10:13 +01:00
void Spell :: CallScriptBeforeCastHandlers ()
2010-08-19 14:31:31 +02:00
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2011-12-31 13:10:13 +01:00
{
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_BEFORE_CAST );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> BeforeCast . end (), hookItr = ( * scritr ) -> BeforeCast . begin ();
2012-05-30 08:01:02 +02:00
for (; hookItr != hookItrEnd ; ++ hookItr )
2011-12-31 13:10:13 +01:00
( * hookItr ). Call ( * scritr );
( * scritr ) -> _FinishScriptCall ();
}
}
void Spell :: CallScriptOnCastHandlers ()
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2011-12-31 13:10:13 +01:00
{
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_ON_CAST );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> OnCast . end (), hookItr = ( * scritr ) -> OnCast . begin ();
2012-05-30 08:01:02 +02:00
for (; hookItr != hookItrEnd ; ++ hookItr )
2011-12-31 13:10:13 +01:00
( * hookItr ). Call ( * scritr );
( * scritr ) -> _FinishScriptCall ();
}
}
void Spell :: CallScriptAfterCastHandlers ()
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2011-12-31 13:10:13 +01:00
{
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_AFTER_CAST );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> AfterCast . end (), hookItr = ( * scritr ) -> AfterCast . begin ();
2012-05-30 08:01:02 +02:00
for (; hookItr != hookItrEnd ; ++ hookItr )
2011-12-31 13:10:13 +01:00
( * hookItr ). Call ( * scritr );
( * scritr ) -> _FinishScriptCall ();
}
2010-08-19 14:31:31 +02:00
}
2010-08-21 20:18:54 +02:00
2011-03-04 21:18:38 +01:00
SpellCastResult Spell :: CallScriptCheckCastHandlers ()
{
SpellCastResult retVal = SPELL_CAST_OK ;
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2011-03-04 21:18:38 +01:00
{
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_CHECK_CAST );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> OnCheckCast . end (), hookItr = ( * scritr ) -> OnCheckCast . begin ();
2011-03-04 21:18:38 +01:00
for (; hookItr != hookItrEnd ; ++ hookItr )
{
SpellCastResult tempResult = ( * hookItr ). Call ( * scritr );
if ( retVal == SPELL_CAST_OK )
retVal = tempResult ;
}
( * scritr ) -> _FinishScriptCall ();
}
return retVal ;
}
2011-12-31 13:10:13 +01:00
void Spell :: PrepareScriptHitHandlers ()
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2011-12-31 13:10:13 +01:00
( * scritr ) -> _InitHit ();
}
2011-09-25 13:29:17 +02:00
bool Spell :: CallScriptEffectHandlers ( SpellEffIndex effIndex , SpellEffectHandleMode mode )
2010-08-21 20:18:54 +02:00
{
// execute script effect handler hooks and check if effects was prevented
bool preventDefault = false ;
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2010-08-21 20:18:54 +02:00
{
2016-11-13 21:44:04 -03:00
HookList < SpellScript :: EffectHandler >:: iterator effItr , effEndItr ;
2011-09-25 13:29:17 +02:00
SpellScriptHookType hookType ;
switch ( mode )
{
case SPELL_EFFECT_HANDLE_LAUNCH :
effItr = ( * scritr ) -> OnEffectLaunch . begin ();
effEndItr = ( * scritr ) -> OnEffectLaunch . end ();
hookType = SPELL_SCRIPT_HOOK_EFFECT_LAUNCH ;
break ;
case SPELL_EFFECT_HANDLE_LAUNCH_TARGET :
effItr = ( * scritr ) -> OnEffectLaunchTarget . begin ();
effEndItr = ( * scritr ) -> OnEffectLaunchTarget . end ();
hookType = SPELL_SCRIPT_HOOK_EFFECT_LAUNCH_TARGET ;
break ;
case SPELL_EFFECT_HANDLE_HIT :
effItr = ( * scritr ) -> OnEffectHit . begin ();
effEndItr = ( * scritr ) -> OnEffectHit . end ();
hookType = SPELL_SCRIPT_HOOK_EFFECT_HIT ;
break ;
case SPELL_EFFECT_HANDLE_HIT_TARGET :
effItr = ( * scritr ) -> OnEffectHitTarget . begin ();
effEndItr = ( * scritr ) -> OnEffectHitTarget . end ();
hookType = SPELL_SCRIPT_HOOK_EFFECT_HIT_TARGET ;
break ;
default :
2015-09-21 15:17:05 +02:00
ABORT ();
2011-11-23 12:42:11 -05:00
return false ;
2011-09-25 13:29:17 +02:00
}
( * scritr ) -> _PrepareScriptCall ( hookType );
2012-05-30 08:01:02 +02:00
for (; effItr != effEndItr ; ++ effItr )
2010-08-21 20:18:54 +02:00
// effect execution can be prevented
if ( ! ( * scritr ) -> _IsEffectPrevented ( effIndex ) && ( * effItr ). IsEffectAffected ( m_spellInfo , effIndex ))
( * effItr ). Call ( * scritr , effIndex );
2011-01-22 17:21:24 +01:00
2010-08-21 20:18:54 +02:00
if ( ! preventDefault )
preventDefault = ( * scritr ) -> _IsDefaultEffectPrevented ( effIndex );
2011-01-22 17:21:24 +01:00
2010-10-05 08:17:10 +02:00
( * scritr ) -> _FinishScriptCall ();
2010-08-21 20:18:54 +02:00
}
return preventDefault ;
}
2014-12-24 16:40:51 +01:00
void Spell :: CallScriptSuccessfulDispel ( SpellEffIndex effIndex )
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2014-12-24 16:40:51 +01:00
{
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_EFFECT_SUCCESSFUL_DISPEL );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> OnEffectSuccessfulDispel . end (), hookItr = ( * scritr ) -> OnEffectSuccessfulDispel . begin ();
2014-12-24 16:40:51 +01:00
for (; hookItr != hookItrEnd ; ++ hookItr )
hookItr -> Call ( * scritr , effIndex );
( * scritr ) -> _FinishScriptCall ();
}
}
2016-07-20 09:08:58 +02:00
void Spell :: CallScriptBeforeHitHandlers ( SpellMissInfo missInfo )
2010-08-21 20:18:54 +02:00
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2010-08-21 20:18:54 +02:00
{
2010-10-05 08:17:10 +02:00
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_BEFORE_HIT );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> BeforeHit . end (), hookItr = ( * scritr ) -> BeforeHit . begin ();
2012-05-30 08:01:02 +02:00
for (; hookItr != hookItrEnd ; ++ hookItr )
2016-07-20 09:08:58 +02:00
( * hookItr ). Call ( * scritr , missInfo );
2011-01-22 17:21:24 +01:00
2010-10-05 08:17:10 +02:00
( * scritr ) -> _FinishScriptCall ();
2010-08-21 20:18:54 +02:00
}
}
void Spell :: CallScriptOnHitHandlers ()
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2010-08-21 20:18:54 +02:00
{
2010-10-05 08:17:10 +02:00
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_HIT );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> OnHit . end (), hookItr = ( * scritr ) -> OnHit . begin ();
2012-05-30 08:01:02 +02:00
for (; hookItr != hookItrEnd ; ++ hookItr )
2010-10-08 21:33:44 +02:00
( * hookItr ). Call ( * scritr );
2011-01-22 17:21:24 +01:00
2010-10-05 08:17:10 +02:00
( * scritr ) -> _FinishScriptCall ();
2010-08-21 20:18:54 +02:00
}
}
void Spell :: CallScriptAfterHitHandlers ()
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2010-08-21 20:18:54 +02:00
{
2010-10-05 08:17:10 +02:00
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_AFTER_HIT );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> AfterHit . end (), hookItr = ( * scritr ) -> AfterHit . begin ();
2012-05-30 08:01:02 +02:00
for (; hookItr != hookItrEnd ; ++ hookItr )
2010-10-08 21:33:44 +02:00
( * hookItr ). Call ( * scritr );
2011-01-22 17:21:24 +01:00
2010-10-05 08:17:10 +02:00
( * scritr ) -> _FinishScriptCall ();
2010-08-21 20:18:54 +02:00
}
}
2011-01-21 23:42:51 +01:00
2014-03-22 21:39:38 +01:00
void Spell :: CallScriptObjectAreaTargetSelectHandlers ( std :: list < WorldObject *>& targets , SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType )
2011-01-21 23:42:51 +01:00
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2011-01-21 23:42:51 +01:00
{
2012-06-30 00:06:17 +02:00
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_OBJECT_AREA_TARGET_SELECT );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> OnObjectAreaTargetSelect . end (), hookItr = ( * scritr ) -> OnObjectAreaTargetSelect . begin ();
2012-05-30 08:01:02 +02:00
for (; hookItr != hookItrEnd ; ++ hookItr )
2014-03-22 21:39:38 +01:00
if ( hookItr -> IsEffectAffected ( m_spellInfo , effIndex ) && targetType . GetTarget () == hookItr -> GetTarget ())
hookItr -> Call ( * scritr , targets );
2011-01-21 23:42:51 +01:00
( * scritr ) -> _FinishScriptCall ();
}
}
2011-02-22 17:02:47 +06:00
2014-03-22 21:39:38 +01:00
void Spell :: CallScriptObjectTargetSelectHandlers ( WorldObject *& target , SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType )
2012-07-03 12:35:06 +02:00
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2012-07-03 12:35:06 +02:00
{
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_OBJECT_TARGET_SELECT );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> OnObjectTargetSelect . end (), hookItr = ( * scritr ) -> OnObjectTargetSelect . begin ();
2012-07-03 12:35:06 +02:00
for (; hookItr != hookItrEnd ; ++ hookItr )
2014-03-22 21:39:38 +01:00
if ( hookItr -> IsEffectAffected ( m_spellInfo , effIndex ) && targetType . GetTarget () == hookItr -> GetTarget ())
hookItr -> Call ( * scritr , target );
2011-01-21 23:42:51 +01:00
( * scritr ) -> _FinishScriptCall ();
}
}
2011-02-22 17:02:47 +06:00
2014-03-22 21:39:38 +01:00
void Spell :: CallScriptDestinationTargetSelectHandlers ( SpellDestination & target , SpellEffIndex effIndex , SpellImplicitTargetInfo const & targetType )
2014-01-23 18:15:59 +01:00
{
2016-11-13 21:44:04 -03:00
for ( auto scritr = m_loadedScripts . begin (); scritr != m_loadedScripts . end (); ++ scritr )
2014-01-23 18:15:59 +01:00
{
( * scritr ) -> _PrepareScriptCall ( SPELL_SCRIPT_HOOK_DESTINATION_TARGET_SELECT );
2016-11-13 21:44:04 -03:00
auto hookItrEnd = ( * scritr ) -> OnDestinationTargetSelect . end (), hookItr = ( * scritr ) -> OnDestinationTargetSelect . begin ();
2014-01-23 18:15:59 +01:00
for (; hookItr != hookItrEnd ; ++ hookItr )
2014-03-22 21:39:38 +01:00
if ( hookItr -> IsEffectAffected ( m_spellInfo , effIndex ) && targetType . GetTarget () == hookItr -> GetTarget ())
2014-01-23 18:15:59 +01:00
hookItr -> Call ( * scritr , target );
( * scritr ) -> _FinishScriptCall ();
}
}
2013-02-07 15:31:01 +01:00
bool Spell :: CheckScriptEffectImplicitTargets ( uint32 effIndex , uint32 effIndexToCheck )
{
// Skip if there are not any script
2015-03-11 08:53:13 +01:00
if ( m_loadedScripts . empty ())
2013-02-07 15:31:01 +01:00
return true ;
2016-11-13 21:44:04 -03:00
for ( auto itr = m_loadedScripts . begin (); itr != m_loadedScripts . end (); ++ itr )
2013-02-07 15:31:01 +01:00
{
2016-11-13 21:44:04 -03:00
auto targetSelectHookEnd = ( * itr ) -> OnObjectTargetSelect . end (), targetSelectHookItr = ( * itr ) -> OnObjectTargetSelect . begin ();
2013-02-07 15:31:01 +01:00
for (; targetSelectHookItr != targetSelectHookEnd ; ++ targetSelectHookItr )
if ((( * targetSelectHookItr ). IsEffectAffected ( m_spellInfo , effIndex ) && ! ( * targetSelectHookItr ). IsEffectAffected ( m_spellInfo , effIndexToCheck )) ||
( ! ( * targetSelectHookItr ). IsEffectAffected ( m_spellInfo , effIndex ) && ( * targetSelectHookItr ). IsEffectAffected ( m_spellInfo , effIndexToCheck )))
return false ;
2013-02-27 13:17:20 +01:00
2016-11-13 21:44:04 -03:00
auto areaTargetSelectHookEnd = ( * itr ) -> OnObjectAreaTargetSelect . end (), areaTargetSelectHookItr = ( * itr ) -> OnObjectAreaTargetSelect . begin ();
2013-02-07 15:31:01 +01:00
for (; areaTargetSelectHookItr != areaTargetSelectHookEnd ; ++ areaTargetSelectHookItr )
if ((( * areaTargetSelectHookItr ). IsEffectAffected ( m_spellInfo , effIndex ) && ! ( * areaTargetSelectHookItr ). IsEffectAffected ( m_spellInfo , effIndexToCheck )) ||
( ! ( * areaTargetSelectHookItr ). IsEffectAffected ( m_spellInfo , effIndex ) && ( * areaTargetSelectHookItr ). IsEffectAffected ( m_spellInfo , effIndexToCheck )))
return false ;
}
return true ;
}
2017-01-06 17:20:04 +01:00
bool Spell :: CanExecuteTriggersOnHit ( uint32 effMask , SpellInfo const * triggeredByAura /*= nullptr*/ ) const
2011-06-26 00:29:12 +02:00
{
2015-01-05 23:49:43 +02:00
bool only_on_caster = ( triggeredByAura && ( triggeredByAura -> HasAttribute ( SPELL_ATTR4_PROC_ONLY_ON_CASTER )));
2013-12-25 14:16:55 -03:30
// If triggeredByAura has SPELL_ATTR4_PROC_ONLY_ON_CASTER then it can only proc on a cast spell with TARGET_UNIT_CASTER
2014-11-16 14:20:01 +01:00
for ( SpellEffectInfo const * effect : GetEffects ())
2011-06-26 00:29:12 +02:00
{
2014-11-27 15:11:43 +01:00
if ( effect && (( effMask & ( 1 << effect -> EffectIndex )) && ( ! only_on_caster || ( effect -> TargetA . GetTarget () == TARGET_UNIT_CASTER ))))
2011-10-19 22:08:54 +02:00
return true ;
2011-06-26 00:29:12 +02:00
}
2011-10-19 22:08:54 +02:00
return false ;
2011-06-26 00:29:12 +02:00
}
void Spell :: PrepareTriggersExecutedOnHit ()
{
2013-03-08 21:41:30 +01:00
/// @todo move this to scripts
2011-06-26 00:29:12 +02:00
if ( m_spellInfo -> SpellFamilyName )
{
2011-07-26 23:09:28 +02:00
SpellInfo const * excludeCasterSpellInfo = sSpellMgr -> GetSpellInfo ( m_spellInfo -> ExcludeCasterAuraSpell );
if ( excludeCasterSpellInfo && ! excludeCasterSpellInfo -> IsPositive ())
m_preCastSpell = m_spellInfo -> ExcludeCasterAuraSpell ;
SpellInfo const * excludeTargetSpellInfo = sSpellMgr -> GetSpellInfo ( m_spellInfo -> ExcludeTargetAuraSpell );
if ( excludeTargetSpellInfo && ! excludeTargetSpellInfo -> IsPositive ())
m_preCastSpell = m_spellInfo -> ExcludeTargetAuraSpell ;
2011-06-26 00:29:12 +02:00
}
2013-03-08 21:41:30 +01:00
/// @todo move this to scripts
2011-06-26 00:29:12 +02:00
switch ( m_spellInfo -> SpellFamilyName )
{
case SPELLFAMILY_MAGE :
{
// Permafrost
if ( m_spellInfo -> SpellFamilyFlags [ 1 ] & 0x00001000 || m_spellInfo -> SpellFamilyFlags [ 0 ] & 0x00100220 )
m_preCastSpell = 68391 ;
break ;
}
}
// handle SPELL_AURA_ADD_TARGET_TRIGGER auras:
// save auras which were present on spell caster on cast, to prevent triggered auras from affecting caster
// and to correctly calculate proc chance when combopoints are present
Unit :: AuraEffectList const & targetTriggers = m_caster -> GetAuraEffectsByType ( SPELL_AURA_ADD_TARGET_TRIGGER );
for ( Unit :: AuraEffectList :: const_iterator i = targetTriggers . begin (); i != targetTriggers . end (); ++ i )
{
2011-11-26 23:38:06 +02:00
if ( ! ( * i ) -> IsAffectingSpell ( m_spellInfo ))
2011-06-26 00:29:12 +02:00
continue ;
2011-09-15 14:08:17 +02:00
SpellInfo const * auraSpellInfo = ( * i ) -> GetSpellInfo ();
2011-06-26 00:29:12 +02:00
uint32 auraSpellIdx = ( * i ) -> GetEffIndex ();
2014-11-16 14:20:01 +01:00
// todo 6.x
2015-01-10 01:35:47 +01:00
if ( SpellEffectInfo const * auraEffect = auraSpellInfo -> GetEffect ( m_caster -> GetMap () -> GetDifficultyID (), auraSpellIdx ))
2011-06-26 00:29:12 +02:00
{
2014-11-16 14:20:01 +01:00
if ( SpellInfo const * spellInfo = sSpellMgr -> GetSpellInfo ( auraEffect -> TriggerSpell ))
{
// calculate the chance using spell base amount, because aura amount is not updated on combo-points change
// this possibly needs fixing
int32 auraBaseAmount = ( * i ) -> GetBaseAmount ();
// proc chance is stored in effect amount
int32 chance = m_caster -> CalculateSpellDamage ( NULL , auraSpellInfo , auraSpellIdx , & auraBaseAmount );
// build trigger and add to the list
HitTriggerSpell spellTriggerInfo ;
spellTriggerInfo . triggeredSpell = spellInfo ;
spellTriggerInfo . triggeredByAura = auraSpellInfo ;
spellTriggerInfo . chance = chance * ( * i ) -> GetBase () -> GetStackAmount ();
m_hitTriggerSpells . push_back ( spellTriggerInfo );
}
2011-06-26 00:29:12 +02:00
}
}
}
2011-02-22 23:20:21 +06:00
// Global cooldowns management
enum GCDLimits
{
2016-06-13 19:54:06 +02:00
MIN_GCD = 750 ,
2011-02-22 17:02:47 +06:00
MAX_GCD = 1500
};
2011-08-21 13:57:15 +02:00
bool Spell :: HasGlobalCooldown () const
2011-02-22 17:02:47 +06:00
{
2015-02-17 01:01:44 +01:00
// Only players or controlled units have global cooldown
if ( m_caster -> GetTypeId () != TYPEID_PLAYER && ! m_caster -> GetCharmInfo ())
2011-02-22 17:02:47 +06:00
return false ;
2015-02-17 01:01:44 +01:00
return m_caster -> GetSpellHistory () -> HasGlobalCooldown ( m_spellInfo );
2011-02-22 17:02:47 +06:00
}
void Spell :: TriggerGlobalCooldown ()
{
int32 gcd = m_spellInfo -> StartRecoveryTime ;
2016-05-26 14:47:36 +02:00
if ( ! gcd || ! m_spellInfo -> StartRecoveryCategory )
2011-02-22 17:02:47 +06:00
return ;
2015-02-17 01:01:44 +01:00
// Only players or controlled units have global cooldown
if ( m_caster -> GetTypeId () != TYPEID_PLAYER && ! m_caster -> GetCharmInfo ())
return ;
2012-08-31 01:26:21 +01:00
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
if ( m_caster -> ToPlayer () -> GetCommandStatus ( CHEAT_COOLDOWN ))
return ;
2011-02-22 17:02:47 +06:00
// Global cooldown can't leave range 1..1.5 secs
2013-12-25 14:16:55 -03:30
// There are some spells (mostly not cast directly by player) that have < 1 sec and > 1.5 sec global cooldowns
2011-02-22 17:02:47 +06:00
// but as tests show are not affected by any spell mods.
if ( m_spellInfo -> StartRecoveryTime >= MIN_GCD && m_spellInfo -> StartRecoveryTime <= MAX_GCD )
{
// gcd modifier auras are applied only to own spells and only players have such mods
if ( m_caster -> GetTypeId () == TYPEID_PLAYER )
m_caster -> ToPlayer () -> ApplySpellMod ( m_spellInfo -> Id , SPELLMOD_GLOBAL_COOLDOWN , gcd , this );
2016-05-26 14:47:36 +02:00
bool isMeleeOrRangedSpell = m_spellInfo -> DmgClass == SPELL_DAMAGE_CLASS_MELEE ||
m_spellInfo -> DmgClass == SPELL_DAMAGE_CLASS_RANGED ||
m_spellInfo -> HasAttribute ( SPELL_ATTR0_REQ_AMMO ) ||
m_spellInfo -> HasAttribute ( SPELL_ATTR0_ABILITY );
2011-02-22 17:02:47 +06:00
// Apply haste rating
2016-05-26 14:47:36 +02:00
if ( gcd > MIN_GCD && (( m_spellInfo -> StartRecoveryCategory == 133 && ! isMeleeOrRangedSpell ) || m_caster -> HasAuraTypeWithAffectMask ( SPELL_AURA_MOD_GLOBAL_COOLDOWN_BY_HASTE , m_spellInfo )))
gcd = std :: min < int32 > ( std :: max < int32 > ( int32 ( float ( gcd ) * m_caster -> GetFloatValue ( UNIT_MOD_CAST_HASTE )), MIN_GCD ), MAX_GCD );
if ( gcd > MIN_GCD && m_caster -> HasAuraTypeWithAffectMask ( SPELL_AURA_MOD_GLOBAL_COOLDOWN_BY_HASTE_REGEN , m_spellInfo ))
gcd = std :: min < int32 > ( std :: max < int32 > ( int32 ( float ( gcd ) * m_caster -> GetFloatValue ( UNIT_FIELD_MOD_HASTE_REGEN )), MIN_GCD ), MAX_GCD );
2011-02-22 17:02:47 +06:00
}
2015-02-17 01:01:44 +01:00
m_caster -> GetSpellHistory () -> AddGlobalCooldown ( m_spellInfo , gcd );
2011-02-22 17:02:47 +06:00
}
void Spell :: CancelGlobalCooldown ()
{
if ( ! m_spellInfo -> StartRecoveryTime )
return ;
// Cancel global cooldown when interrupting current cast
if ( m_caster -> GetCurrentSpell ( CURRENT_GENERIC_SPELL ) != this )
return ;
// Only players or controlled units have global cooldown
2015-02-17 01:01:44 +01:00
if ( m_caster -> GetTypeId () != TYPEID_PLAYER && ! m_caster -> GetCharmInfo ())
return ;
m_caster -> GetSpellHistory () -> CancelGlobalCooldown ( m_spellInfo );
2011-02-22 17:02:47 +06:00
}
2012-02-21 20:03:27 +01:00
2014-11-16 14:20:01 +01:00
bool Spell :: HasEffect ( SpellEffectName effect ) const
{
for ( SpellEffectInfo const * eff : GetEffects ())
{
2014-11-27 15:11:43 +01:00
if ( eff && eff -> IsEffect ( effect ))
2014-11-16 14:20:01 +01:00
return true ;
}
return false ;
}
2012-02-21 20:03:27 +01:00
namespace Trinity
{
WorldObjectSpellTargetCheck :: WorldObjectSpellTargetCheck ( Unit * caster , Unit * referer , SpellInfo const * spellInfo ,
2015-10-25 10:59:58 +01:00
SpellTargetCheckTypes selectionType , ConditionContainer * condList ) : _caster ( caster ), _referer ( referer ), _spellInfo ( spellInfo ),
2012-02-22 09:15:57 +01:00
_targetSelectionType ( selectionType ), _condList ( condList )
2012-02-21 20:03:27 +01:00
{
if ( condList )
_condSrcInfo = new ConditionSourceInfo ( NULL , caster );
else
_condSrcInfo = NULL ;
}
WorldObjectSpellTargetCheck ::~ WorldObjectSpellTargetCheck ()
{
2014-09-19 03:30:02 +01:00
delete _condSrcInfo ;
2012-02-21 20:03:27 +01:00
}
bool WorldObjectSpellTargetCheck :: operator ()( WorldObject * target )
{
if ( _spellInfo -> CheckTarget ( _caster , target , true ) != SPELL_CAST_OK )
return false ;
Unit * unitTarget = target -> ToUnit ();
if ( Corpse * corpseTarget = target -> ToCorpse ())
{
// use ofter for party/assistance checks
if ( Player * owner = ObjectAccessor :: FindPlayer ( corpseTarget -> GetOwnerGUID ()))
unitTarget = owner ;
else
return false ;
}
if ( unitTarget )
{
switch ( _targetSelectionType )
{
case TARGET_CHECK_ENEMY :
2013-06-11 19:54:27 -02:30
if ( unitTarget -> IsTotem ())
2012-02-21 20:03:27 +01:00
return false ;
if ( ! _caster -> _IsValidAttackTarget ( unitTarget , _spellInfo ))
return false ;
break ;
case TARGET_CHECK_ALLY :
2013-06-11 19:54:27 -02:30
if ( unitTarget -> IsTotem ())
2012-02-21 20:03:27 +01:00
return false ;
if ( ! _caster -> _IsValidAssistTarget ( unitTarget , _spellInfo ))
return false ;
break ;
case TARGET_CHECK_PARTY :
2013-06-11 19:54:27 -02:30
if ( unitTarget -> IsTotem ())
2012-02-21 20:03:27 +01:00
return false ;
if ( ! _caster -> _IsValidAssistTarget ( unitTarget , _spellInfo ))
return false ;
if ( ! _referer -> IsInPartyWith ( unitTarget ))
return false ;
break ;
case TARGET_CHECK_RAID_CLASS :
if ( _referer -> getClass () != unitTarget -> getClass ())
return false ;
// nobreak;
case TARGET_CHECK_RAID :
2013-06-11 19:54:27 -02:30
if ( unitTarget -> IsTotem ())
2012-02-21 20:03:27 +01:00
return false ;
if ( ! _caster -> _IsValidAssistTarget ( unitTarget , _spellInfo ))
return false ;
if ( ! _referer -> IsInRaidWith ( unitTarget ))
return false ;
break ;
default :
break ;
}
}
if ( ! _condSrcInfo )
return true ;
_condSrcInfo -> mConditionTargets [ 0 ] = target ;
return sConditionMgr -> IsObjectMeetToConditions ( * _condSrcInfo , * _condList );
}
2012-05-30 08:01:02 +02:00
WorldObjectSpellNearbyTargetCheck :: WorldObjectSpellNearbyTargetCheck ( float range , Unit * caster , SpellInfo const * spellInfo ,
2015-10-25 10:59:58 +01:00
SpellTargetCheckTypes selectionType , ConditionContainer * condList )
2013-10-28 14:36:07 -04:00
: WorldObjectSpellTargetCheck ( caster , caster , spellInfo , selectionType , condList ), _range ( range ), _position ( caster ) { }
2012-02-21 20:03:27 +01:00
bool WorldObjectSpellNearbyTargetCheck :: operator ()( WorldObject * target )
{
float dist = target -> GetDistance ( * _position );
if ( dist < _range && WorldObjectSpellTargetCheck :: operator ()( target ))
{
_range = dist ;
return true ;
}
return false ;
}
WorldObjectSpellAreaTargetCheck :: WorldObjectSpellAreaTargetCheck ( float range , Position const * position , Unit * caster ,
2015-10-25 10:59:58 +01:00
Unit * referer , SpellInfo const * spellInfo , SpellTargetCheckTypes selectionType , ConditionContainer * condList )
2013-10-28 14:36:07 -04:00
: WorldObjectSpellTargetCheck ( caster , referer , spellInfo , selectionType , condList ), _range ( range ), _position ( position ) { }
2012-02-21 20:03:27 +01:00
bool WorldObjectSpellAreaTargetCheck :: operator ()( WorldObject * target )
{
2013-04-03 02:12:26 -04:00
if ( ! target -> IsWithinDist3d ( _position , _range ) && ! ( target -> ToGameObject () && target -> ToGameObject () -> IsInRange ( _position -> GetPositionX (), _position -> GetPositionY (), _position -> GetPositionZ (), _range )))
2012-02-21 20:03:27 +01:00
return false ;
return WorldObjectSpellTargetCheck :: operator ()( target );
}
WorldObjectSpellConeTargetCheck :: WorldObjectSpellConeTargetCheck ( float coneAngle , float range , Unit * caster ,
2015-10-25 10:59:58 +01:00
SpellInfo const * spellInfo , SpellTargetCheckTypes selectionType , ConditionContainer * condList )
2013-10-28 14:36:07 -04:00
: WorldObjectSpellAreaTargetCheck ( range , caster , caster , caster , spellInfo , selectionType , condList ), _coneAngle ( coneAngle ) { }
2012-02-21 20:03:27 +01:00
bool WorldObjectSpellConeTargetCheck :: operator ()( WorldObject * target )
{
2015-01-05 23:49:43 +02:00
if ( _spellInfo -> HasAttribute ( SPELL_ATTR0_CU_CONE_BACK ))
2012-02-21 20:03:27 +01:00
{
if ( ! _caster -> isInBack ( target , _coneAngle ))
return false ;
}
2015-01-05 23:49:43 +02:00
else if ( _spellInfo -> HasAttribute ( SPELL_ATTR0_CU_CONE_LINE ))
2012-02-21 20:03:27 +01:00
{
2015-05-02 00:05:01 +02:00
if ( ! _caster -> HasInLine ( target , _caster -> GetObjectSize () + target -> GetObjectSize ()))
2012-02-21 20:03:27 +01:00
return false ;
}
else
{
2016-03-31 16:21:50 +02:00
if ( ! _caster -> IsWithinBoundaryRadius ( target -> ToUnit ()))
if ( ! _caster -> isInFront ( target , _coneAngle ))
return false ;
2012-02-21 20:03:27 +01:00
}
return WorldObjectSpellAreaTargetCheck :: operator ()( target );
}
WorldObjectSpellTrajTargetCheck :: WorldObjectSpellTrajTargetCheck ( float range , Position const * position , Unit * caster , SpellInfo const * spellInfo )
2013-10-28 14:36:07 -04:00
: WorldObjectSpellAreaTargetCheck ( range , position , caster , caster , spellInfo , TARGET_CHECK_DEFAULT , NULL ) { }
2012-02-21 20:03:27 +01:00
bool WorldObjectSpellTrajTargetCheck :: operator ()( WorldObject * target )
{
// return all targets on missile trajectory (0 - size of a missile)
2015-05-02 00:05:01 +02:00
if ( ! _caster -> HasInLine ( target , target -> GetObjectSize ()))
2012-02-21 20:03:27 +01:00
return false ;
return WorldObjectSpellAreaTargetCheck :: operator ()( target );
}
} //namespace Trinity