2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "GridNotifiers.h"
24 #include "GridNotifiersImpl.h"
27 #include "UpdateMask.h"
29 #include "ObjectMgr.h"
35 #include "DynamicObject.h"
37 #include "UpdateData.h"
38 #include "MapManager.h"
39 #include "ObjectAccessor.h"
41 #include "Policies/SingletonImp.h"
42 #include "SharedDefines.h"
44 #include "VMapFactory.h"
45 #include "BattleGround.h"
48 #define SPELL_CHANNEL_UPDATE_INTERVAL (1*IN_MILISECONDS)
50 extern pEffect SpellEffects
[TOTAL_SPELL_EFFECTS
];
52 class PrioritizeManaPlayerWraper
54 friend struct PrioritizeMana
;
57 explicit PrioritizeManaPlayerWraper(Player
* player
) : player(player
)
59 uint32 maxmana
= player
->GetMaxPower(POWER_MANA
);
60 percentMana
= maxmana
? player
->GetPower(POWER_MANA
) * 100 / maxmana
: 101;
62 Player
* getPlayer() const { return player
; }
70 int operator()( PrioritizeManaPlayerWraper
const& x
, PrioritizeManaPlayerWraper
const& y
) const
72 return x
.percentMana
< y
.percentMana
;
77 bool IsQuestTameSpell(uint32 spellId
)
79 SpellEntry
const *spellproto
= sSpellStore
.LookupEntry(spellId
);
80 if (!spellproto
) return false;
82 return spellproto
->Effect
[0] == SPELL_EFFECT_THREAT
83 && spellproto
->Effect
[1] == SPELL_EFFECT_APPLY_AURA
&& spellproto
->EffectApplyAuraName
[1] == SPELL_AURA_DUMMY
;
86 SpellCastTargets::SpellCastTargets()
94 m_CorpseTargetGUID
= 0;
96 m_itemTargetEntry
= 0;
98 m_srcX
= m_srcY
= m_srcZ
= m_destX
= m_destY
= m_destZ
= 0;
103 SpellCastTargets::~SpellCastTargets()
107 void SpellCastTargets::setUnitTarget(Unit
*target
)
112 m_destX
= target
->GetPositionX();
113 m_destY
= target
->GetPositionY();
114 m_destZ
= target
->GetPositionZ();
115 m_unitTarget
= target
;
116 m_unitTargetGUID
= target
->GetGUID();
117 m_targetMask
|= TARGET_FLAG_UNIT
;
120 void SpellCastTargets::setDestination(float x
, float y
, float z
)
125 m_targetMask
|= TARGET_FLAG_DEST_LOCATION
;
128 void SpellCastTargets::setSource(float x
, float y
, float z
)
133 m_targetMask
|= TARGET_FLAG_SOURCE_LOCATION
;
136 void SpellCastTargets::setGOTarget(GameObject
*target
)
139 m_GOTargetGUID
= target
->GetGUID();
140 // m_targetMask |= TARGET_FLAG_OBJECT;
143 void SpellCastTargets::setItemTarget(Item
* item
)
149 m_itemTargetGUID
= item
->GetGUID();
150 m_itemTargetEntry
= item
->GetEntry();
151 m_targetMask
|= TARGET_FLAG_ITEM
;
154 void SpellCastTargets::setCorpseTarget(Corpse
* corpse
)
156 m_CorpseTargetGUID
= corpse
->GetGUID();
159 void SpellCastTargets::Update(Unit
* caster
)
161 m_GOTarget
= m_GOTargetGUID
? caster
->GetMap()->GetGameObject(m_GOTargetGUID
) : NULL
;
162 m_unitTarget
= m_unitTargetGUID
?
163 ( m_unitTargetGUID
==caster
->GetGUID() ? caster
: ObjectAccessor::GetUnit(*caster
, m_unitTargetGUID
) ) :
167 if(caster
->GetTypeId()==TYPEID_PLAYER
)
169 if(m_targetMask
& TARGET_FLAG_ITEM
)
170 m_itemTarget
= ((Player
*)caster
)->GetItemByGuid(m_itemTargetGUID
);
173 Player
* pTrader
= ((Player
*)caster
)->GetTrader();
174 if(pTrader
&& m_itemTargetGUID
< TRADE_SLOT_COUNT
)
175 m_itemTarget
= pTrader
->GetItemByPos(pTrader
->GetItemPosByTradeSlot(m_itemTargetGUID
));
178 m_itemTargetEntry
= m_itemTarget
->GetEntry();
182 bool SpellCastTargets::read ( WorldPacket
* data
, Unit
*caster
)
184 if(data
->rpos()+4 > data
->size())
187 *data
>> m_targetMask
;
189 if(m_targetMask
== TARGET_FLAG_SELF
)
191 m_destX
= caster
->GetPositionX();
192 m_destY
= caster
->GetPositionY();
193 m_destZ
= caster
->GetPositionZ();
194 m_unitTarget
= caster
;
195 m_unitTargetGUID
= caster
->GetGUID();
199 // TARGET_FLAG_UNK2 is used for non-combat pets, maybe other?
200 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_UNK2
))
201 if(!data
->readPackGUID(m_unitTargetGUID
))
204 if( m_targetMask
& ( TARGET_FLAG_OBJECT
))
205 if(!data
->readPackGUID(m_GOTargetGUID
))
208 if(( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
)) && caster
->GetTypeId() == TYPEID_PLAYER
)
209 if(!data
->readPackGUID(m_itemTargetGUID
))
212 if( m_targetMask
& (TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
213 if(!data
->readPackGUID(m_CorpseTargetGUID
))
216 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
218 if(data
->rpos()+4+4+4 > data
->size())
221 *data
>> m_srcX
>> m_srcY
>> m_srcZ
;
222 if(!MaNGOS::IsValidMapCoord(m_srcX
, m_srcY
, m_srcZ
))
226 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
228 if(data
->rpos()+1+4+4+4 > data
->size())
231 if(!data
->readPackGUID(m_unitTargetGUID
))
234 *data
>> m_destX
>> m_destY
>> m_destZ
;
235 if(!MaNGOS::IsValidMapCoord(m_destX
, m_destY
, m_destZ
))
239 if( m_targetMask
& TARGET_FLAG_STRING
)
241 if(data
->rpos()+1 > data
->size())
244 *data
>> m_strTarget
;
247 // find real units/GOs
252 void SpellCastTargets::write ( WorldPacket
* data
)
254 *data
<< uint32(m_targetMask
);
256 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_PVP_CORPSE
| TARGET_FLAG_OBJECT
| TARGET_FLAG_CORPSE
| TARGET_FLAG_UNK2
) )
258 if(m_targetMask
& TARGET_FLAG_UNIT
)
261 data
->append(m_unitTarget
->GetPackGUID());
265 else if( m_targetMask
& TARGET_FLAG_OBJECT
)
268 data
->append(m_GOTarget
->GetPackGUID());
272 else if( m_targetMask
& ( TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
273 data
->appendPackGUID(m_CorpseTargetGUID
);
278 if( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
) )
281 data
->append(m_itemTarget
->GetPackGUID());
286 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
287 *data
<< m_srcX
<< m_srcY
<< m_srcZ
;
289 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
292 data
->append(m_unitTarget
->GetPackGUID());
296 *data
<< m_destX
<< m_destY
<< m_destZ
;
299 if( m_targetMask
& TARGET_FLAG_STRING
)
300 *data
<< m_strTarget
;
303 Spell::Spell( Unit
* Caster
, SpellEntry
const *info
, bool triggered
, uint64 originalCasterGUID
, Spell
** triggeringContainer
)
305 ASSERT( Caster
!= NULL
&& info
!= NULL
);
306 ASSERT( info
== sSpellStore
.LookupEntry( info
->Id
) && "`info` must be pointer to sSpellStore element");
310 m_selfContainer
= NULL
;
311 m_triggeringContainer
= triggeringContainer
;
312 m_referencedFromCurrentSpell
= false;
313 m_executedCurrently
= false;
315 m_delayAtDamageCount
= 0;
317 m_applyMultiplierMask
= 0;
319 // Get data for type of attack
320 switch (m_spellInfo
->DmgClass
)
322 case SPELL_DAMAGE_CLASS_MELEE
:
323 if (m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_REQ_OFFHAND
)
324 m_attackType
= OFF_ATTACK
;
326 m_attackType
= BASE_ATTACK
;
328 case SPELL_DAMAGE_CLASS_RANGED
:
329 m_attackType
= RANGED_ATTACK
;
333 if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
)
334 m_attackType
= RANGED_ATTACK
;
336 m_attackType
= BASE_ATTACK
;
340 m_spellSchoolMask
= GetSpellSchoolMask(info
); // Can be override for some spell (wand shoot for example)
342 if(m_attackType
== RANGED_ATTACK
)
345 if((m_caster
->getClassMask() & CLASSMASK_WAND_USERS
) != 0 && m_caster
->GetTypeId()==TYPEID_PLAYER
)
347 if(Item
* pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(RANGED_ATTACK
))
348 m_spellSchoolMask
= SpellSchoolMask(1 << pItem
->GetProto()->Damage
[0].DamageType
);
351 // Set health leech amount to zero
354 if(originalCasterGUID
)
355 m_originalCasterGUID
= originalCasterGUID
;
357 m_originalCasterGUID
= m_caster
->GetGUID();
359 if(m_originalCasterGUID
==m_caster
->GetGUID())
360 m_originalCaster
= m_caster
;
363 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
,m_originalCasterGUID
);
364 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
367 for(int i
=0; i
<3; ++i
)
368 m_currentBasePoints
[i
] = m_spellInfo
->EffectBasePoints
[i
];
370 m_spellState
= SPELL_STATE_NULL
;
372 m_castPositionX
= m_castPositionY
= m_castPositionZ
= 0;
373 m_TriggerSpells
.clear();
374 m_IsTriggeredSpell
= triggered
;
375 //m_AreaAura = false;
380 gameObjTarget
= NULL
;
385 m_triggeredByAuraSpell
= NULL
;
387 //Auto Shot & Shoot (wand)
388 m_autoRepeat
= IsAutoRepeatRangedSpell(m_spellInfo
);
391 m_powerCost
= 0; // setup to correct value in Spell::prepare, don't must be used before.
392 m_casttime
= 0; // setup to correct value in Spell::prepare, don't must be used before.
393 m_timer
= 0; // will set to castime in prepare
395 m_needAliveTargetMask
= 0;
397 // determine reflection
398 m_canReflect
= false;
400 if(m_spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
&& !(m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
))
404 if (m_spellInfo
->Effect
[j
]==0)
407 if(!IsPositiveTarget(m_spellInfo
->EffectImplicitTargetA
[j
],m_spellInfo
->EffectImplicitTargetB
[j
]))
410 m_canReflect
= (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NEGATIVE
) ? true : false;
427 WorldObject
* Spell::FindCorpseUsing()
429 // non-standard target selection
430 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
431 float max_range
= GetSpellMaxRange(srange
);
433 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
435 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
438 WorldObject
* result
= NULL
;
440 T
u_check(m_caster
, max_range
);
441 MaNGOS::WorldObjectSearcher
<T
> searcher(m_caster
, result
, u_check
);
443 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<T
>, GridTypeMapContainer
> grid_searcher(searcher
);
444 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
445 cell_lock
->Visit(cell_lock
, grid_searcher
, *m_caster
->GetMap());
449 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<T
>, WorldTypeMapContainer
> world_searcher(searcher
);
450 cell_lock
->Visit(cell_lock
, world_searcher
, *m_caster
->GetMap());
456 void Spell::FillTargetMap()
458 // TODO: ADD the correct target FILLS!!!!!!
460 for(uint32 i
=0;i
<3;++i
)
462 // not call for empty effect.
463 // Also some spells use not used effect targets for store targets for dummy effect in triggered spells
464 if(m_spellInfo
->Effect
[i
]==0)
467 // targets for TARGET_SCRIPT_COORDINATES (A) and TARGET_SCRIPT filled in Spell::CheckCast call
468 if( m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT_COORDINATES
||
469 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT
||
470 m_spellInfo
->EffectImplicitTargetB
[i
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
)
473 // TODO: find a way so this is not needed?
474 // for area auras always add caster as target (needed for totems for example)
475 if(IsAreaAuraEffect(m_spellInfo
->Effect
[i
]))
476 AddUnitTarget(m_caster
, i
);
478 std::list
<Unit
*> tmpUnitMap
;
480 // TargetA/TargetB dependent from each other, we not switch to full support this dependences
481 // but need it support in some know cases
482 switch(m_spellInfo
->EffectImplicitTargetA
[i
])
485 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
488 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
490 case TARGET_AREAEFFECT_INSTANT
: // use B case that not dependent from from A in fact
491 if((m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)==0)
492 m_targets
.setDestination(m_caster
->GetPositionX(),m_caster
->GetPositionY(),m_caster
->GetPositionZ());
493 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
495 case TARGET_BEHIND_VICTIM
: // use B case that not dependent from from A in fact
496 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
499 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
500 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
504 case TARGET_CASTER_COORDINATES
:
505 // Note: this hack with search required until GO casting not implemented
506 // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support
507 // currently each enemy selected explicitly and self cast damage
508 if(m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_ALL_ENEMY_IN_AREA
&& m_spellInfo
->Effect
[i
]==SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
)
510 if(m_targets
.getUnitTarget())
511 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
515 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
516 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
519 case TARGET_TABLE_X_Y_Z_COORDINATES
:
520 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
523 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
525 // need some target for proccesing
526 if(m_targets
.getUnitTarget())
527 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
529 tmpUnitMap
.push_back(m_caster
);
531 case TARGET_AREAEFFECT_INSTANT
: // All 17/7 pairs used for dest teleportation, A processed in effect code
532 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
535 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
536 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
541 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
544 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
546 case TARGET_SCRIPT_COORDINATES
: // B case filled in CheckCast but we need fill unit list base at A case
547 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
550 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
551 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
557 if( (m_spellInfo
->EffectImplicitTargetA
[i
]==0 || m_spellInfo
->EffectImplicitTargetA
[i
]==TARGET_EFFECT_SELECT
) &&
558 (m_spellInfo
->EffectImplicitTargetB
[i
]==0 || m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_EFFECT_SELECT
) )
560 // add here custom effects that need default target.
561 // FOR EVERY TARGET TYPE THERE IS A DIFFERENT FILL!!
562 switch(m_spellInfo
->Effect
[i
])
564 case SPELL_EFFECT_DUMMY
:
566 switch(m_spellInfo
->Id
)
568 case 20577: // Cannibalize
570 WorldObject
* result
= FindCorpseUsing
<MaNGOS::CannibalizeObjectCheck
> ();
574 switch(result
->GetTypeId())
578 tmpUnitMap
.push_back((Unit
*)result
);
581 m_targets
.setCorpseTarget((Corpse
*)result
);
582 if(Player
* owner
= ObjectAccessor::FindPlayer(((Corpse
*)result
)->GetOwnerGUID()))
583 tmpUnitMap
.push_back(owner
);
589 // clear cooldown at fail
590 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
591 ((Player
*)m_caster
)->RemoveSpellCooldown(m_spellInfo
->Id
,true);
592 SendCastResult(SPELL_FAILED_NO_EDIBLE_CORPSES
);
598 if(m_targets
.getUnitTarget())
599 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
604 case SPELL_EFFECT_RESURRECT
:
605 case SPELL_EFFECT_PARRY
:
606 case SPELL_EFFECT_BLOCK
:
607 case SPELL_EFFECT_CREATE_ITEM
:
608 case SPELL_EFFECT_TRIGGER_SPELL
:
609 case SPELL_EFFECT_TRIGGER_MISSILE
:
610 case SPELL_EFFECT_LEARN_SPELL
:
611 case SPELL_EFFECT_SKILL_STEP
:
612 case SPELL_EFFECT_PROFICIENCY
:
613 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
614 case SPELL_EFFECT_SELF_RESURRECT
:
615 case SPELL_EFFECT_REPUTATION
:
616 case SPELL_EFFECT_SEND_TAXI
:
617 if(m_targets
.getUnitTarget())
618 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
619 // Triggered spells have additional spell targets - cast them even if no explicit unit target is given (required for spell 50516 for example)
620 else if(m_spellInfo
->Effect
[i
] == SPELL_EFFECT_TRIGGER_SPELL
)
621 tmpUnitMap
.push_back(m_caster
);
623 case SPELL_EFFECT_SUMMON_PLAYER
:
624 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetSelection())
626 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
628 tmpUnitMap
.push_back(target
);
631 case SPELL_EFFECT_RESURRECT_NEW
:
632 if(m_targets
.getUnitTarget())
633 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
634 if(m_targets
.getCorpseTargetGUID())
636 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
639 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
641 tmpUnitMap
.push_back(owner
);
645 case SPELL_EFFECT_SUMMON
:
646 if(m_spellInfo
->EffectMiscValueB
[i
] == SUMMON_TYPE_POSESSED
|| m_spellInfo
->EffectMiscValueB
[i
] == SUMMON_TYPE_POSESSED2
)
648 if(m_targets
.getUnitTarget())
649 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
652 tmpUnitMap
.push_back(m_caster
);
654 case SPELL_EFFECT_SUMMON_CHANGE_ITEM
:
655 case SPELL_EFFECT_TRANS_DOOR
:
656 case SPELL_EFFECT_ADD_FARSIGHT
:
657 case SPELL_EFFECT_APPLY_GLYPH
:
658 case SPELL_EFFECT_STUCK
:
659 case SPELL_EFFECT_FEED_PET
:
660 case SPELL_EFFECT_DESTROY_ALL_TOTEMS
:
661 case SPELL_EFFECT_SKILL
:
662 tmpUnitMap
.push_back(m_caster
);
664 case SPELL_EFFECT_LEARN_PET_SPELL
:
665 if(Pet
* pet
= m_caster
->GetPet())
666 tmpUnitMap
.push_back(pet
);
668 case SPELL_EFFECT_ENCHANT_ITEM
:
669 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
670 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
671 case SPELL_EFFECT_DISENCHANT
:
672 case SPELL_EFFECT_PROSPECTING
:
673 case SPELL_EFFECT_MILLING
:
674 if(m_targets
.getItemTarget())
675 AddItemTarget(m_targets
.getItemTarget(), i
);
677 case SPELL_EFFECT_APPLY_AURA
:
678 switch(m_spellInfo
->EffectApplyAuraName
[i
])
680 case SPELL_AURA_ADD_FLAT_MODIFIER
: // some spell mods auras have 0 target modes instead expected TARGET_SELF(1) (and present for other ranks for same spell for example)
681 case SPELL_AURA_ADD_PCT_MODIFIER
:
682 tmpUnitMap
.push_back(m_caster
);
684 default: // apply to target in other case
685 if(m_targets
.getUnitTarget())
686 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
690 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY
:
692 if(m_spellInfo
->Attributes
== 0x9050000 || m_spellInfo
->Attributes
== 0x10000)
693 SetTargetMap(i
,TARGET_AREAEFFECT_PARTY
,tmpUnitMap
);
695 case SPELL_EFFECT_SKIN_PLAYER_CORPSE
:
696 if(m_targets
.getUnitTarget())
698 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
700 else if (m_targets
.getCorpseTargetGUID())
702 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
705 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
707 tmpUnitMap
.push_back(owner
);
716 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
718 Player
*me
= (Player
*)m_caster
;
719 for (std::list
<Unit
*>::const_iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end(); ++itr
)
721 Unit
*owner
= (*itr
)->GetOwner();
722 Unit
*u
= owner
? owner
: (*itr
);
723 if(u
!=m_caster
&& u
->IsPvP() && (!me
->duel
|| me
->duel
->opponent
!= u
))
726 me
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
732 for (std::list
<Unit
*>::iterator itr
= tmpUnitMap
.begin() ; itr
!= tmpUnitMap
.end();)
734 if (!CheckTarget (*itr
, i
))
736 itr
= tmpUnitMap
.erase(itr
);
743 for(std::list
<Unit
*>::const_iterator iunit
= tmpUnitMap
.begin();iunit
!= tmpUnitMap
.end();++iunit
)
744 AddUnitTarget((*iunit
), i
);
748 void Spell::prepareDataForTriggerSystem()
750 //==========================================================================================
751 // Now fill data for trigger system, need know:
752 // an spell trigger another or not ( m_canTrigger )
753 // Create base triggers flags for Attacker and Victim ( m_procAttacker and m_procVictim)
754 //==========================================================================================
755 // Fill flag can spell trigger or not
756 // TODO: possible exist spell attribute for this
757 m_canTrigger
= false;
760 m_canTrigger
= false; // Do not trigger from item cast spell
761 else if (!m_IsTriggeredSpell
)
762 m_canTrigger
= true; // Normal cast - can trigger
763 else if (!m_triggeredByAuraSpell
)
764 m_canTrigger
= true; // Triggered from SPELL_EFFECT_TRIGGER_SPELL - can trigger
766 if (!m_canTrigger
) // Exceptions (some periodic triggers)
768 switch (m_spellInfo
->SpellFamilyName
)
770 case SPELLFAMILY_MAGE
: // Arcane Missles / Blizzard triggers need do it
771 if (m_spellInfo
->SpellFamilyFlags
& 0x0000000000200080LL
) m_canTrigger
= true;
773 case SPELLFAMILY_WARLOCK
: // For Hellfire Effect / Rain of Fire / Seed of Corruption triggers need do it
774 if (m_spellInfo
->SpellFamilyFlags
& 0x0000800000000060LL
) m_canTrigger
= true;
776 case SPELLFAMILY_PRIEST
: // For Penance heal/damage triggers need do it
777 if (m_spellInfo
->SpellFamilyFlags
& 0x0001800000000000LL
) m_canTrigger
= true;
779 case SPELLFAMILY_ROGUE
: // For poisons need do it
780 if (m_spellInfo
->SpellFamilyFlags
& 0x000000101001E000LL
) m_canTrigger
= true;
782 case SPELLFAMILY_HUNTER
: // Hunter Rapid Killing/Explosive Trap Effect/Immolation Trap Effect/Frost Trap Aura/Snake Trap Effect/Explosive Shot
783 if (m_spellInfo
->SpellFamilyFlags
& 0x0100200000000214LL
||
784 m_spellInfo
->SpellFamilyFlags2
& 0x200) m_canTrigger
= true;
786 case SPELLFAMILY_PALADIN
: // For Judgements (all) / Holy Shock triggers need do it
787 if (m_spellInfo
->SpellFamilyFlags
& 0x0001000900B80400LL
) m_canTrigger
= true;
792 // Get data for type of attack and fill base info for trigger
793 switch (m_spellInfo
->DmgClass
)
795 case SPELL_DAMAGE_CLASS_MELEE
:
796 m_procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT
;
797 m_procVictim
= PROC_FLAG_TAKEN_MELEE_SPELL_HIT
;
799 case SPELL_DAMAGE_CLASS_RANGED
:
801 if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
)
803 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
804 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
806 else // Ranged spell attack
808 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT
;
809 m_procVictim
= PROC_FLAG_TAKEN_RANGED_SPELL_HIT
;
813 if (IsPositiveSpell(m_spellInfo
->Id
)) // Check for positive spell
815 m_procAttacker
= PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
;
816 m_procVictim
= PROC_FLAG_TAKEN_POSITIVE_SPELL
;
818 else if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
) // Wands auto attack
820 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
821 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
823 else // Negative spell
825 m_procAttacker
= PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT
;
826 m_procVictim
= PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
;
830 // Hunter traps spells (for Entrapment trigger)
831 // Gives your Immolation Trap, Frost Trap, Explosive Trap, and Snake Trap ....
832 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_HUNTER
&& m_spellInfo
->SpellFamilyFlags
& 0x000020000000001CLL
)
833 m_procAttacker
|= PROC_FLAG_ON_TRAP_ACTIVATION
;
836 void Spell::CleanupTargetList()
838 m_UniqueTargetInfo
.clear();
839 m_UniqueGOTargetInfo
.clear();
840 m_UniqueItemInfo
.clear();
844 void Spell::AddUnitTarget(Unit
* pVictim
, uint32 effIndex
)
846 if( m_spellInfo
->Effect
[effIndex
]==0 )
849 // Check for effect immune skip if immuned
850 bool immuned
= pVictim
->IsImmunedToSpellEffect(m_spellInfo
, effIndex
);
852 uint64 targetGUID
= pVictim
->GetGUID();
854 // Lookup target in already in list
855 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
857 if (targetGUID
== ihit
->targetGUID
) // Found in list
860 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask if not immuned
865 // This is new target calculate data for him
867 // Get spell hit result on target
869 target
.targetGUID
= targetGUID
; // Store target GUID
870 target
.effectMask
= immuned
? 0 : 1<<effIndex
; // Store index of effect if not immuned
871 target
.processed
= false; // Effects not apply on target
873 // Calculate hit result
874 target
.missCondition
= m_caster
->SpellHitResult(pVictim
, m_spellInfo
, m_canReflect
);
876 // Spell have speed - need calculate incoming time
877 if (m_spellInfo
->speed
> 0.0f
)
879 // calculate spell incoming interval
880 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
881 if (dist
< 5.0f
) dist
= 5.0f
;
882 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
884 // Calculate minimum incoming time
885 if (m_delayMoment
==0 || m_delayMoment
>target
.timeDelay
)
886 m_delayMoment
= target
.timeDelay
;
889 target
.timeDelay
= 0LL;
891 // If target reflect spell back to caster
892 if (target
.missCondition
==SPELL_MISS_REFLECT
)
894 // Calculate reflected spell result on caster
895 target
.reflectResult
= m_caster
->SpellHitResult(m_caster
, m_spellInfo
, m_canReflect
);
897 if (target
.reflectResult
== SPELL_MISS_REFLECT
) // Impossible reflect again, so simply deflect spell
898 target
.reflectResult
= SPELL_MISS_PARRY
;
900 // Increase time interval for reflected spells by 1.5
901 target
.timeDelay
+=target
.timeDelay
>>1;
904 target
.reflectResult
= SPELL_MISS_NONE
;
906 // Add target to list
907 m_UniqueTargetInfo
.push_back(target
);
910 void Spell::AddUnitTarget(uint64 unitGUID
, uint32 effIndex
)
912 Unit
* unit
= m_caster
->GetGUID()==unitGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, unitGUID
);
914 AddUnitTarget(unit
, effIndex
);
917 void Spell::AddGOTarget(GameObject
* pVictim
, uint32 effIndex
)
919 if( m_spellInfo
->Effect
[effIndex
]==0 )
922 uint64 targetGUID
= pVictim
->GetGUID();
924 // Lookup target in already in list
925 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
927 if (targetGUID
== ihit
->targetGUID
) // Found in list
929 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask
934 // This is new target calculate data for him
937 target
.targetGUID
= targetGUID
;
938 target
.effectMask
= 1<<effIndex
;
939 target
.processed
= false; // Effects not apply on target
941 // Spell have speed - need calculate incoming time
942 if (m_spellInfo
->speed
> 0.0f
)
944 // calculate spell incoming interval
945 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
946 if (dist
< 5.0f
) dist
= 5.0f
;
947 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
948 if (m_delayMoment
==0 || m_delayMoment
>target
.timeDelay
)
949 m_delayMoment
= target
.timeDelay
;
952 target
.timeDelay
= 0LL;
954 // Add target to list
955 m_UniqueGOTargetInfo
.push_back(target
);
958 void Spell::AddGOTarget(uint64 goGUID
, uint32 effIndex
)
960 GameObject
* go
= m_caster
->GetMap()->GetGameObject(goGUID
);
962 AddGOTarget(go
, effIndex
);
965 void Spell::AddItemTarget(Item
* pitem
, uint32 effIndex
)
967 if( m_spellInfo
->Effect
[effIndex
]==0 )
970 // Lookup target in already in list
971 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
973 if (pitem
== ihit
->item
) // Found in list
975 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask
980 // This is new target add data
982 ItemTargetInfo target
;
984 target
.effectMask
= 1<<effIndex
;
985 m_UniqueItemInfo
.push_back(target
);
988 void Spell::DoAllEffectOnTarget(TargetInfo
*target
)
990 if (target
->processed
) // Check target
992 target
->processed
= true; // Target checked in apply effects procedure
994 // Get mask of effects for target
995 uint32 mask
= target
->effectMask
;
997 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
1001 // Get original caster (if exist) and calculate damage/healing from him data
1002 Unit
*caster
= m_originalCaster
? m_originalCaster
: m_caster
;
1004 // Skip if m_originalCaster not available
1008 SpellMissInfo missInfo
= target
->missCondition
;
1009 // Need init unitTarget by default unit (can changed in code on reflect)
1010 // Or on missInfo!=SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem)
1013 // Reset damage/healing counter
1017 // Fill base trigger info
1018 uint32 procAttacker
= m_procAttacker
;
1019 uint32 procVictim
= m_procVictim
;
1020 uint32 procEx
= PROC_EX_NONE
;
1022 if (missInfo
==SPELL_MISS_NONE
) // In case spell hit target, do all effect on that target
1023 DoSpellHitOnUnit(unit
, mask
);
1024 else if (missInfo
== SPELL_MISS_REFLECT
) // In case spell reflect from target, do all effect on caster (if hit)
1026 if (target
->reflectResult
== SPELL_MISS_NONE
) // If reflected spell hit caster -> do all effect on him
1027 DoSpellHitOnUnit(m_caster
, mask
);
1030 // All calculated do it!
1031 // Do healing and triggers
1034 bool crit
= caster
->isSpellCrit(NULL
, m_spellInfo
, m_spellSchoolMask
);
1035 uint32 addhealth
= m_healing
;
1038 procEx
|= PROC_EX_CRITICAL_HIT
;
1039 addhealth
= caster
->SpellCriticalHealingBonus(m_spellInfo
, addhealth
, NULL
);
1042 procEx
|= PROC_EX_NORMAL_HIT
;
1044 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1045 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1046 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, addhealth
, m_attackType
, m_spellInfo
);
1048 int32 gain
= caster
->DealHeal(unitTarget
, addhealth
, m_spellInfo
, crit
);
1049 unitTarget
->getHostilRefManager().threatAssist(caster
, float(gain
) * 0.5f
, m_spellInfo
);
1051 // Do damage and triggers
1054 // Fill base damage struct (unitTarget - is real spell target)
1055 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1057 // Add bonuses and fill damageInfo struct
1058 caster
->CalculateSpellDamage(&damageInfo
, m_damage
, m_spellInfo
);
1059 caster
->DealDamageMods(damageInfo
.target
,damageInfo
.damage
,&damageInfo
.absorb
);
1061 // Send log damage message to client
1062 caster
->SendSpellNonMeleeDamageLog(&damageInfo
);
1064 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1065 procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1067 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1068 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1069 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, damageInfo
.damage
, m_attackType
, m_spellInfo
);
1071 caster
->DealSpellDamage(&damageInfo
, true);
1073 // Judgement of Blood
1074 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& m_spellInfo
->SpellFamilyFlags
& 0x0000000800000000LL
&& m_spellInfo
->SpellIconID
==153)
1076 int32 damagePoint
= damageInfo
.damage
* 33 / 100;
1077 m_caster
->CastCustomSpell(m_caster
, 32220, &damagePoint
, NULL
, NULL
, true);
1080 // Passive spell hits/misses or active spells only misses (only triggers)
1083 // Fill base damage struct (unitTarget - is real spell target)
1084 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1085 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1086 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1087 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1088 caster
->ProcDamageAndSpell(unit
, procAttacker
, procVictim
, procEx
, 0, m_attackType
, m_spellInfo
);
1091 // Call scripted function for AI if this spell is casted upon a creature
1092 if(unit
->GetTypeId()==TYPEID_UNIT
)
1094 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1095 // ignore pets or autorepeat/melee casts for speed (not exist quest for spells (hm... )
1096 if( !((Creature
*)unit
)->isPet() && !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1098 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1099 p
->CastedCreatureOrGO(unit
->GetEntry(),unit
->GetGUID(),m_spellInfo
->Id
);
1102 if(((Creature
*)unit
)->AI())
1103 ((Creature
*)unit
)->AI()->SpellHit(m_caster
,m_spellInfo
);
1106 // Call scripted function for AI if this spell is casted by a creature
1107 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)m_caster
)->AI())
1108 ((Creature
*)m_caster
)->AI()->SpellHitTarget(unit
,m_spellInfo
);
1111 void Spell::DoSpellHitOnUnit(Unit
*unit
, const uint32 effectMask
)
1113 if(!unit
|| !effectMask
)
1116 // Recheck immune (only for delayed spells)
1117 if( m_spellInfo
->speed
&& (
1118 unit
->IsImmunedToDamage(GetSpellSchoolMask(m_spellInfo
)) ||
1119 unit
->IsImmunedToSpell(m_spellInfo
)))
1121 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_IMMUNE
);
1125 if (unit
->GetTypeId() == TYPEID_PLAYER
)
1127 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET
, m_spellInfo
->Id
);
1128 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2
, m_spellInfo
->Id
);
1131 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
1133 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2
, m_spellInfo
->Id
, 0, unit
);
1136 if( m_caster
!= unit
)
1138 // Recheck UNIT_FLAG_NON_ATTACKABLE for delayed spells
1139 if (m_spellInfo
->speed
> 0.0f
&&
1140 unit
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
) &&
1141 unit
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
1143 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1147 if( !m_caster
->IsFriendlyTo(unit
) )
1149 // for delayed spells ignore not visible explicit target
1150 if(m_spellInfo
->speed
> 0.0f
&& unit
==m_targets
.getUnitTarget() && !unit
->isVisibleForOrDetect(m_caster
,false))
1152 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1156 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1158 if( !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) )
1160 if(!unit
->IsStandState() && !unit
->hasUnitState(UNIT_STAT_STUNNED
))
1161 unit
->SetStandState(UNIT_STAND_STATE_STAND
);
1163 if(!unit
->isInCombat() && unit
->GetTypeId() != TYPEID_PLAYER
&& ((Creature
*)unit
)->AI())
1164 ((Creature
*)unit
)->AI()->AttackedBy(m_caster
);
1166 unit
->AddThreat(m_caster
, 0.0f
);
1167 unit
->SetInCombatWith(m_caster
);
1168 m_caster
->SetInCombatWith(unit
);
1170 if(Player
*attackedPlayer
= unit
->GetCharmerOrOwnerPlayerOrPlayerItself())
1172 m_caster
->SetContestedPvP(attackedPlayer
);
1178 // for delayed spells ignore negative spells (after duel end) for friendly targets
1179 if(m_spellInfo
->speed
> 0.0f
&& !IsPositiveSpell(m_spellInfo
->Id
))
1181 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1185 // assisting case, healing and resurrection
1186 if(unit
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
1187 m_caster
->SetContestedPvP();
1188 if( unit
->isInCombat() && !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) )
1190 m_caster
->SetInCombatState(unit
->GetCombatTimer() > 0);
1191 unit
->getHostilRefManager().threatAssist(m_caster
, 0.0f
);
1196 // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
1197 m_diminishGroup
= GetDiminishingReturnsGroupForSpell(m_spellInfo
,m_triggeredByAuraSpell
);
1198 m_diminishLevel
= unit
->GetDiminishing(m_diminishGroup
);
1199 // Increase Diminishing on unit, current informations for actually casts will use values above
1200 if((GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_PLAYER
&& unit
->GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_ALL
)
1201 unit
->IncrDiminishing(m_diminishGroup
);
1203 // Apply additional spell effects to target
1205 m_caster
->CastSpell(unit
,m_preCastSpell
, true, m_CastItem
);
1207 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1209 if (effectMask
& (1<<effectNumber
))
1211 HandleEffects(unit
,NULL
,NULL
,effectNumber
,m_damageMultipliers
[effectNumber
]);
1212 if ( m_applyMultiplierMask
& (1 << effectNumber
) )
1215 float multiplier
= m_spellInfo
->DmgMultiplier
[effectNumber
];
1216 // Apply multiplier mods
1217 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1218 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_EFFECT_PAST_FIRST
, multiplier
,this);
1219 m_damageMultipliers
[effectNumber
] *= multiplier
;
1225 void Spell::DoAllEffectOnTarget(GOTargetInfo
*target
)
1227 if (target
->processed
) // Check target
1229 target
->processed
= true; // Target checked in apply effects procedure
1231 uint32 effectMask
= target
->effectMask
;
1235 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
1239 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1240 if (effectMask
& (1<<effectNumber
))
1241 HandleEffects(NULL
,NULL
,go
,effectNumber
);
1243 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1244 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
1245 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1247 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1248 p
->CastedCreatureOrGO(go
->GetEntry(),go
->GetGUID(),m_spellInfo
->Id
);
1252 void Spell::DoAllEffectOnTarget(ItemTargetInfo
*target
)
1254 uint32 effectMask
= target
->effectMask
;
1255 if(!target
->item
|| !effectMask
)
1258 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1259 if (effectMask
& (1<<effectNumber
))
1260 HandleEffects(NULL
, target
->item
, NULL
, effectNumber
);
1263 bool Spell::IsAliveUnitPresentInTargetList()
1265 // Not need check return true
1266 if (m_needAliveTargetMask
== 0)
1269 uint8 needAliveTargetMask
= m_needAliveTargetMask
;
1271 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
1273 if( ihit
->missCondition
== SPELL_MISS_NONE
&& (needAliveTargetMask
& ihit
->effectMask
) )
1275 Unit
*unit
= m_caster
->GetGUID()==ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
1277 if (unit
&& unit
->isAlive())
1278 needAliveTargetMask
&= ~ihit
->effectMask
; // remove from need alive mask effect that have alive target
1282 // is all effects from m_needAliveTargetMask have alive targets
1283 return needAliveTargetMask
==0;
1286 // Helper for Chain Healing
1287 // Spell target first
1288 // Raidmates then descending by injury suffered (MaxHealth - Health)
1289 // Other players/mobs then descending by injury suffered (MaxHealth - Health)
1290 struct ChainHealingOrder
: public std::binary_function
<const Unit
*, const Unit
*, bool>
1292 const Unit
* MainTarget
;
1293 ChainHealingOrder(Unit
const* Target
) : MainTarget(Target
) {};
1294 // functor for operator ">"
1295 bool operator()(Unit
const* _Left
, Unit
const* _Right
) const
1297 return (ChainHealingHash(_Left
) < ChainHealingHash(_Right
));
1299 int32
ChainHealingHash(Unit
const* Target
) const
1301 if (Target
== MainTarget
)
1303 else if (Target
->GetTypeId() == TYPEID_PLAYER
&& MainTarget
->GetTypeId() == TYPEID_PLAYER
&&
1304 ((Player
const*)Target
)->IsInSameRaidWith((Player
const*)MainTarget
))
1306 if (Target
->GetHealth() == Target
->GetMaxHealth())
1309 return 20000 - Target
->GetMaxHealth() + Target
->GetHealth();
1312 return 40000 - Target
->GetMaxHealth() + Target
->GetHealth();
1316 class ChainHealingFullHealth
: std::unary_function
<const Unit
*, bool>
1319 const Unit
* MainTarget
;
1320 ChainHealingFullHealth(const Unit
* Target
) : MainTarget(Target
) {};
1322 bool operator()(const Unit
* Target
)
1324 return (Target
!= MainTarget
&& Target
->GetHealth() == Target
->GetMaxHealth());
1328 // Helper for targets nearest to the spell target
1329 // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
1330 struct TargetDistanceOrder
: public std::binary_function
<const Unit
, const Unit
, bool>
1332 const Unit
* MainTarget
;
1333 TargetDistanceOrder(const Unit
* Target
) : MainTarget(Target
) {};
1334 // functor for operator ">"
1335 bool operator()(const Unit
* _Left
, const Unit
* _Right
) const
1337 return MainTarget
->GetDistanceOrder(_Left
,_Right
);
1341 void Spell::SetTargetMap(uint32 i
,uint32 cur
,UnitList
& TagUnitMap
)
1344 if (m_spellInfo
->EffectRadiusIndex
[i
])
1345 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
1347 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
));
1349 if(m_originalCaster
)
1350 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1351 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RADIUS
, radius
,this);
1353 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[i
];
1354 if(m_originalCaster
)
1355 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1356 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
1358 // Get spell max affected targets
1359 uint32 unMaxTargets
= m_spellInfo
->MaxAffectedTargets
;
1361 // custom target amount cases
1362 switch(m_spellInfo
->SpellFamilyName
)
1364 case SPELLFAMILY_DRUID
:
1366 if (m_spellInfo
->SpellFamilyFlags2
& 0x00000100LL
)
1373 Unit::AuraList
const& mod
= m_caster
->GetAurasByType(SPELL_AURA_MOD_MAX_AFFECTED_TARGETS
);
1374 for(Unit::AuraList::const_iterator m
= mod
.begin(); m
!= mod
.end(); ++m
)
1376 if (!(*m
)->isAffectedOnSpell(m_spellInfo
))
1378 unMaxTargets
+=(*m
)->GetModifier()->m_amount
;
1383 case TARGET_TOTEM_EARTH
:
1384 case TARGET_TOTEM_WATER
:
1385 case TARGET_TOTEM_AIR
:
1386 case TARGET_TOTEM_FIRE
:
1389 case TARGET_DYNAMIC_OBJECT
:
1390 case TARGET_AREAEFFECT_CUSTOM
:
1391 case TARGET_AREAEFFECT_CUSTOM_2
:
1394 TagUnitMap
.push_back(m_caster
);
1397 case TARGET_RANDOM_ENEMY_CHAIN_IN_AREA
:
1399 m_targets
.m_targetMask
= 0;
1400 unMaxTargets
= EffectChainTarget
;
1401 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1403 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1405 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1408 std::list
<Unit
*> tempUnitMap
;
1411 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1412 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1414 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1415 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1417 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1418 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1419 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1422 if(tempUnitMap
.empty())
1425 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1427 //Now to get us a random target that's in the initial range of the spell
1429 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1430 while(itr
!= tempUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
,radius
))
1436 itr
= tempUnitMap
.begin();
1437 std::advance(itr
, rand()%t
);
1438 Unit
*pUnitTarget
= *itr
;
1439 TagUnitMap
.push_back(pUnitTarget
);
1441 tempUnitMap
.erase(itr
);
1443 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1445 t
= unMaxTargets
- 1;
1446 Unit
*prev
= pUnitTarget
;
1447 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1449 while(t
&& next
!= tempUnitMap
.end() )
1451 if(!prev
->IsWithinDist(*next
,CHAIN_SPELL_JUMP_RADIUS
))
1454 if(!prev
->IsWithinLOSInMap(*next
))
1461 TagUnitMap
.push_back(prev
);
1462 tempUnitMap
.erase(next
);
1463 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1464 next
= tempUnitMap
.begin();
1469 case TARGET_RANDOM_FRIEND_CHAIN_IN_AREA
:
1471 m_targets
.m_targetMask
= 0;
1472 unMaxTargets
= EffectChainTarget
;
1473 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1474 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1476 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1478 std::list
<Unit
*> tempUnitMap
;
1480 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1481 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1483 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1484 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1486 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1487 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1488 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1491 if(tempUnitMap
.empty())
1494 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1496 //Now to get us a random target that's in the initial range of the spell
1498 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1499 while(itr
!= tempUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
,radius
))
1505 itr
= tempUnitMap
.begin();
1506 std::advance(itr
, rand()%t
);
1507 Unit
*pUnitTarget
= *itr
;
1508 TagUnitMap
.push_back(pUnitTarget
);
1510 tempUnitMap
.erase(itr
);
1512 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1514 t
= unMaxTargets
- 1;
1515 Unit
*prev
= pUnitTarget
;
1516 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1518 while(t
&& next
!= tempUnitMap
.end() )
1520 if(!prev
->IsWithinDist(*next
,CHAIN_SPELL_JUMP_RADIUS
))
1523 if(!prev
->IsWithinLOSInMap(*next
))
1529 TagUnitMap
.push_back(prev
);
1530 tempUnitMap
.erase(next
);
1531 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1532 next
= tempUnitMap
.begin();
1538 Pet
* tmpUnit
= m_caster
->GetPet();
1539 if (!tmpUnit
) break;
1540 TagUnitMap
.push_back(tmpUnit
);
1543 case TARGET_CHAIN_DAMAGE
:
1545 if (EffectChainTarget
<= 1)
1547 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1549 m_targets
.setUnitTarget(pUnitTarget
);
1550 TagUnitMap
.push_back(pUnitTarget
);
1555 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1559 unMaxTargets
= EffectChainTarget
;
1562 if(m_spellInfo
->DmgClass
==SPELL_DAMAGE_CLASS_MELEE
)
1563 max_range
= radius
; //
1565 //FIXME: This very like horrible hack and wrong for most spells
1566 max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1568 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1570 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1573 Unit
* originalCaster
= GetOriginalCaster();
1576 std::list
<Unit
*> tempUnitMap
;
1579 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(pUnitTarget
, originalCaster
, max_range
);
1580 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1582 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1583 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1585 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1586 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1587 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1590 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1592 if(tempUnitMap
.empty())
1595 if(*tempUnitMap
.begin() == pUnitTarget
)
1596 tempUnitMap
.erase(tempUnitMap
.begin());
1598 TagUnitMap
.push_back(pUnitTarget
);
1599 uint32 t
= unMaxTargets
- 1;
1600 Unit
*prev
= pUnitTarget
;
1601 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1603 while(t
&& next
!= tempUnitMap
.end() )
1605 if(!prev
->IsWithinDist(*next
,CHAIN_SPELL_JUMP_RADIUS
))
1608 if(!prev
->IsWithinLOSInMap(*next
))
1615 TagUnitMap
.push_back(prev
);
1616 tempUnitMap
.erase(next
);
1617 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1618 next
= tempUnitMap
.begin();
1625 case TARGET_ALL_ENEMY_IN_AREA
:
1627 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1630 case TARGET_AREAEFFECT_INSTANT
:
1632 SpellTargets targetB
= SPELL_TARGETS_AOE_DAMAGE
;
1633 // Select friendly targets for positive effect
1634 if (IsPositiveEffect(m_spellInfo
->Id
, i
))
1635 targetB
= SPELL_TARGETS_FRIENDLY
;
1637 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),radius
, PUSH_DEST_CENTER
, targetB
);
1640 TagUnitMap
.remove(m_caster
);
1642 case TARGET_ALL_ENEMY_IN_AREA_INSTANT
:
1644 // targets the ground, not the units in the area
1645 if (m_spellInfo
->Effect
[i
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1647 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1649 // exclude caster (this can be important if this not original caster)
1650 TagUnitMap
.remove(m_caster
);
1653 case TARGET_DUELVSPLAYER_COORDINATES
:
1655 if(Unit
* currentTarget
= m_targets
.getUnitTarget())
1657 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1658 TagUnitMap
.push_back(currentTarget
);
1661 case TARGET_ALL_PARTY_AROUND_CASTER
:
1662 case TARGET_ALL_PARTY_AROUND_CASTER_2
:
1663 case TARGET_ALL_PARTY
:
1665 Player
*pTarget
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself();
1666 Group
*pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1670 uint8 subgroup
= pTarget
->GetSubGroup();
1672 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1674 Player
* Target
= itr
->getSource();
1676 // IsHostileTo check duel and controlled by enemy
1677 if( Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
) )
1679 if( m_caster
->IsWithinDistInMap(Target
, radius
) )
1680 TagUnitMap
.push_back(Target
);
1682 if(Pet
* pet
= Target
->GetPet())
1683 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1684 TagUnitMap
.push_back(pet
);
1690 Unit
* ownerOrSelf
= pTarget
? pTarget
: m_caster
->GetCharmerOrOwnerOrSelf();
1691 if(ownerOrSelf
==m_caster
|| m_caster
->IsWithinDistInMap(ownerOrSelf
, radius
))
1692 TagUnitMap
.push_back(ownerOrSelf
);
1693 if(Pet
* pet
= ownerOrSelf
->GetPet())
1694 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1695 TagUnitMap
.push_back(pet
);
1699 case TARGET_ALL_RAID_AROUND_CASTER
:
1701 Player
*pTarget
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself();
1702 Group
*pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1704 if(m_spellInfo
->Id
==57669) //Replenishment (special target selection)
1708 typedef std::priority_queue
<PrioritizeManaPlayerWraper
, std::vector
<PrioritizeManaPlayerWraper
>, PrioritizeMana
> Top10
;
1711 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
&& manaUsers
.size() < 10; itr
= itr
->next())
1713 Player
* Target
= itr
->getSource();
1714 if (m_caster
->GetGUID() != Target
->GetGUID() && Target
->getPowerType() == POWER_MANA
&&
1715 !Target
->isDead() && m_caster
->IsWithinDistInMap(Target
, radius
))
1717 PrioritizeManaPlayerWraper
WTarget(Target
);
1718 manaUsers
.push(WTarget
);
1722 while(!manaUsers
.empty())
1724 TagUnitMap
.push_back(manaUsers
.top().getPlayer());
1730 Unit
* ownerOrSelf
= pTarget
? pTarget
: m_caster
->GetCharmerOrOwnerOrSelf();
1731 if ((ownerOrSelf
==m_caster
|| m_caster
->IsWithinDistInMap(ownerOrSelf
, radius
)) &&
1732 ownerOrSelf
->getPowerType() == POWER_MANA
)
1733 TagUnitMap
.push_back(ownerOrSelf
);
1735 if(Pet
* pet
= ownerOrSelf
->GetPet())
1736 if( m_caster
->IsWithinDistInMap(pet
, radius
) && pet
->getPowerType() == POWER_MANA
)
1737 TagUnitMap
.push_back(pet
);
1744 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1746 Player
* Target
= itr
->getSource();
1748 // IsHostileTo check duel and controlled by enemy
1749 if( Target
&& !m_caster
->IsHostileTo(Target
) )
1751 if( m_caster
->IsWithinDistInMap(Target
, radius
) )
1752 TagUnitMap
.push_back(Target
);
1754 if(Pet
* pet
= Target
->GetPet())
1755 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1756 TagUnitMap
.push_back(pet
);
1762 Unit
* ownerOrSelf
= pTarget
? pTarget
: m_caster
->GetCharmerOrOwnerOrSelf();
1763 if(ownerOrSelf
==m_caster
|| m_caster
->IsWithinDistInMap(ownerOrSelf
, radius
))
1764 TagUnitMap
.push_back(ownerOrSelf
);
1765 if(Pet
* pet
= ownerOrSelf
->GetPet())
1766 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1767 TagUnitMap
.push_back(pet
);
1772 case TARGET_SINGLE_FRIEND
:
1773 case TARGET_SINGLE_FRIEND_2
:
1775 if(m_targets
.getUnitTarget())
1776 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1778 case TARGET_NONCOMBAT_PET
:
1780 if(Unit
* target
= m_targets
.getUnitTarget())
1781 if( target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet() && ((Pet
*)target
)->getPetType() == MINI_PET
)
1782 TagUnitMap
.push_back(target
);
1784 case TARGET_CASTER_COORDINATES
:
1786 // Check original caster is GO - set its coordinates as dst cast
1787 WorldObject
*caster
= NULL
;
1788 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
1789 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
1792 // Set dest for targets
1793 m_targets
.setDestination(caster
->GetPositionX(), caster
->GetPositionY(), caster
->GetPositionZ());
1795 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER
:
1796 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_SELF_CENTER
,SPELL_TARGETS_FRIENDLY
);
1798 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA
:
1799 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_FRIENDLY
);
1801 // TARGET_SINGLE_PARTY means that the spells can only be casted on a party member and not on the caster (some seals, fire shield from imp, etc..)
1802 case TARGET_SINGLE_PARTY
:
1804 Unit
*target
= m_targets
.getUnitTarget();
1805 // Thoses spells apparently can't be casted on the caster.
1806 if( target
&& target
!= m_caster
)
1808 // Can only be casted on group's members or its pets
1809 Group
*pGroup
= NULL
;
1811 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1812 Unit
*targetOwner
= target
->GetCharmerOrOwner();
1815 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1817 if( target
== owner
)
1819 TagUnitMap
.push_back(target
);
1822 pGroup
= ((Player
*)owner
)->GetGroup();
1825 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1827 if( targetOwner
== m_caster
&& target
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)target
)->isPet())
1829 TagUnitMap
.push_back(target
);
1832 pGroup
= ((Player
*)m_caster
)->GetGroup();
1837 // Our target can also be a player's pet who's grouped with us or our pet. But can't be controlled player
1840 if( targetOwner
->GetTypeId() == TYPEID_PLAYER
&&
1841 target
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)target
)->isPet()) &&
1842 target
->GetOwnerGUID()==targetOwner
->GetGUID() &&
1843 pGroup
->IsMember(((Player
*)targetOwner
)->GetGUID()))
1845 TagUnitMap
.push_back(target
);
1848 // 1Our target can be a player who is on our group
1849 else if (target
->GetTypeId() == TYPEID_PLAYER
&& pGroup
->IsMember(((Player
*)target
)->GetGUID()))
1851 TagUnitMap
.push_back(target
);
1856 case TARGET_GAMEOBJECT
:
1858 if(m_targets
.getGOTarget())
1859 AddGOTarget(m_targets
.getGOTarget(), i
);
1861 case TARGET_IN_FRONT_OF_CASTER
:
1863 bool inFront
= m_spellInfo
->SpellVisual
[0] != 3879;
1864 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),radius
,inFront
? PUSH_IN_FRONT
: PUSH_IN_BACK
,SPELL_TARGETS_AOE_DAMAGE
);
1867 case TARGET_DUELVSPLAYER
:
1869 Unit
*target
= m_targets
.getUnitTarget();
1872 if(m_caster
->IsFriendlyTo(target
))
1874 TagUnitMap
.push_back(target
);
1878 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1880 m_targets
.setUnitTarget(pUnitTarget
);
1881 TagUnitMap
.push_back(pUnitTarget
);
1886 case TARGET_GAMEOBJECT_ITEM
:
1888 if(m_targets
.getGOTargetGUID())
1889 AddGOTarget(m_targets
.getGOTarget(), i
);
1890 else if(m_targets
.getItemTarget())
1891 AddItemTarget(m_targets
.getItemTarget(), i
);
1896 if(Unit
* owner
= m_caster
->GetCharmerOrOwner())
1897 TagUnitMap
.push_back(owner
);
1900 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED
:
1902 // targets the ground, not the units in the area
1903 if (m_spellInfo
->Effect
[i
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1904 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1909 if(m_spellInfo
->Effect
[i
] != SPELL_EFFECT_DUEL
)
1910 TagUnitMap
.push_back(m_caster
);
1912 case TARGET_SINGLE_ENEMY
:
1914 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1916 m_targets
.setUnitTarget(pUnitTarget
);
1917 TagUnitMap
.push_back(pUnitTarget
);
1920 case TARGET_AREAEFFECT_PARTY
:
1922 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1923 Player
*pTarget
= NULL
;
1927 TagUnitMap
.push_back(m_caster
);
1928 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1929 pTarget
= (Player
*)owner
;
1931 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1933 if(Unit
* target
= m_targets
.getUnitTarget())
1935 if( target
->GetTypeId() != TYPEID_PLAYER
)
1937 if(((Creature
*)target
)->isPet())
1939 Unit
*targetOwner
= target
->GetOwner();
1940 if(targetOwner
->GetTypeId() == TYPEID_PLAYER
)
1941 pTarget
= (Player
*)targetOwner
;
1945 pTarget
= (Player
*)target
;
1949 Group
* pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1953 uint8 subgroup
= pTarget
->GetSubGroup();
1955 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1957 Player
* Target
= itr
->getSource();
1959 // IsHostileTo check duel and controlled by enemy
1960 if(Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
))
1962 if( pTarget
->IsWithinDistInMap(Target
, radius
) )
1963 TagUnitMap
.push_back(Target
);
1965 if(Pet
* pet
= Target
->GetPet())
1966 if( pTarget
->IsWithinDistInMap(pet
, radius
) )
1967 TagUnitMap
.push_back(pet
);
1973 if(m_caster
->IsWithinDistInMap(owner
, radius
))
1974 TagUnitMap
.push_back(owner
);
1978 TagUnitMap
.push_back(pTarget
);
1980 if(Pet
* pet
= pTarget
->GetPet())
1981 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1982 TagUnitMap
.push_back(pet
);
1988 if(m_targets
.getUnitTarget())
1989 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1990 if(m_targets
.getItemTarget())
1991 AddItemTarget(m_targets
.getItemTarget(), i
);
1993 case TARGET_SELF_FISHING
:
1995 TagUnitMap
.push_back(m_caster
);
1997 case TARGET_CHAIN_HEAL
:
1999 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
2003 if (EffectChainTarget
<= 1)
2004 TagUnitMap
.push_back(pUnitTarget
);
2007 unMaxTargets
= EffectChainTarget
;
2008 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
2010 UnitList tempUnitMap
;
2012 FillAreaTargets(tempUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),max_range
,PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
2014 if(m_caster
!= pUnitTarget
&& std::find(tempUnitMap
.begin(),tempUnitMap
.end(),m_caster
) == tempUnitMap
.end() )
2015 tempUnitMap
.push_front(m_caster
);
2017 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
2019 if(tempUnitMap
.empty())
2022 if(*tempUnitMap
.begin() == pUnitTarget
)
2023 tempUnitMap
.erase(tempUnitMap
.begin());
2025 TagUnitMap
.push_back(pUnitTarget
);
2026 uint32 t
= unMaxTargets
- 1;
2027 Unit
*prev
= pUnitTarget
;
2028 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
2030 while(t
&& next
!= tempUnitMap
.end() )
2032 if(!prev
->IsWithinDist(*next
,CHAIN_SPELL_JUMP_RADIUS
))
2035 if(!prev
->IsWithinLOSInMap(*next
))
2041 if((*next
)->GetHealth() == (*next
)->GetMaxHealth())
2043 next
= tempUnitMap
.erase(next
);
2048 TagUnitMap
.push_back(prev
);
2049 tempUnitMap
.erase(next
);
2050 tempUnitMap
.sort(TargetDistanceOrder(prev
));
2051 next
= tempUnitMap
.begin();
2057 case TARGET_CURRENT_ENEMY_COORDINATES
:
2059 Unit
* currentTarget
= m_targets
.getUnitTarget();
2062 TagUnitMap
.push_back(currentTarget
);
2063 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
2064 if(m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_ALL_ENEMY_IN_AREA_INSTANT
)
2065 FillAreaTargets(TagUnitMap
, currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), radius
, PUSH_TARGET_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
2069 case TARGET_AREAEFFECT_PARTY_AND_CLASS
:
2071 Player
* targetPlayer
= m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
2072 ? (Player
*)m_targets
.getUnitTarget() : NULL
;
2074 Group
* pGroup
= targetPlayer
? targetPlayer
->GetGroup() : NULL
;
2077 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2079 Player
* Target
= itr
->getSource();
2081 // IsHostileTo check duel and controlled by enemy
2082 if( Target
&& targetPlayer
->IsWithinDistInMap(Target
, radius
) &&
2083 targetPlayer
->getClass() == Target
->getClass() &&
2084 !m_caster
->IsHostileTo(Target
) )
2086 TagUnitMap
.push_back(Target
);
2090 else if(m_targets
.getUnitTarget())
2091 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2094 case TARGET_TABLE_X_Y_Z_COORDINATES
:
2096 SpellTargetPosition
const* st
= spellmgr
.GetSpellTargetPosition(m_spellInfo
->Id
);
2099 if (st
->target_mapId
== m_caster
->GetMapId())
2100 m_targets
.setDestination(st
->target_X
, st
->target_Y
, st
->target_Z
);
2102 sLog
.outError( "SPELL: wrong map (%u instead %u) target coordinates for spell ID %u", st
->target_mapId
, m_caster
->GetMapId(), m_spellInfo
->Id
);
2105 sLog
.outError( "SPELL: unknown target coordinates for spell ID %u", m_spellInfo
->Id
);
2107 case TARGET_BEHIND_VICTIM
:
2109 Unit
*pTarget
= NULL
;
2111 // explicit cast data from client or server-side cast
2112 // some spell at client send caster
2113 if(m_targets
.getUnitTarget() && m_targets
.getUnitTarget()!=m_caster
)
2114 pTarget
= m_targets
.getUnitTarget();
2115 else if(m_caster
->getVictim())
2116 pTarget
= m_caster
->getVictim();
2117 else if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
2118 pTarget
= ObjectAccessor::GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection());
2122 float _target_x
, _target_y
, _target_z
;
2123 pTarget
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), CONTACT_DISTANCE
, M_PI
);
2124 if(pTarget
->IsWithinLOS(_target_x
,_target_y
,_target_z
))
2126 TagUnitMap
.push_back(m_caster
);
2127 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2132 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
2134 // if parent spell create dynamic object extract area from it
2135 if(DynamicObject
* dynObj
= m_caster
->GetDynObject(m_triggeredByAuraSpell
? m_triggeredByAuraSpell
->Id
: m_spellInfo
->Id
))
2136 m_targets
.setDestination(dynObj
->GetPositionX(), dynObj
->GetPositionY(), dynObj
->GetPositionZ());
2139 case TARGET_DIRECTLY_FORWARD
:
2141 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2143 SpellRangeEntry
const* rEntry
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
2144 float minRange
= GetSpellMinRange(rEntry
);
2145 float maxRange
= GetSpellMaxRange(rEntry
);
2146 float dist
= minRange
+ rand_norm()*(maxRange
-minRange
);
2148 float _target_x
, _target_y
, _target_z
;
2149 m_caster
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), dist
);
2150 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2153 TagUnitMap
.push_back(m_caster
);
2160 if (unMaxTargets
&& TagUnitMap
.size() > unMaxTargets
)
2162 // make sure one unit is always removed per iteration
2163 uint32 removed_utarget
= 0;
2164 for (UnitList::iterator itr
= TagUnitMap
.begin(), next
; itr
!= TagUnitMap
.end(); itr
= next
)
2168 if (!*itr
) continue;
2169 if ((*itr
) == m_targets
.getUnitTarget())
2171 TagUnitMap
.erase(itr
);
2172 removed_utarget
= 1;
2176 // remove random units from the map
2177 while (TagUnitMap
.size() > unMaxTargets
- removed_utarget
)
2179 uint32 poz
= urand(0, TagUnitMap
.size()-1);
2180 for (UnitList::iterator itr
= TagUnitMap
.begin(); itr
!= TagUnitMap
.end(); ++itr
, --poz
)
2182 if (!*itr
) continue;
2186 TagUnitMap
.erase(itr
);
2191 // the player's target will always be added to the map
2192 if (removed_utarget
&& m_targets
.getUnitTarget())
2193 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2197 void Spell::prepare(SpellCastTargets
const* targets
, Aura
* triggeredByAura
)
2199 m_targets
= *targets
;
2201 m_spellState
= SPELL_STATE_PREPARING
;
2203 m_castPositionX
= m_caster
->GetPositionX();
2204 m_castPositionY
= m_caster
->GetPositionY();
2205 m_castPositionZ
= m_caster
->GetPositionZ();
2206 m_castOrientation
= m_caster
->GetOrientation();
2209 m_triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
2211 // create and add update event for this spell
2212 SpellEvent
* Event
= new SpellEvent(this);
2213 m_caster
->m_Events
.AddEvent(Event
, m_caster
->m_Events
.CalculateTime(1));
2215 //Prevent casting at cast another spell (ServerSide check)
2216 if(m_caster
->IsNonMeleeSpellCasted(false, true, true) && m_cast_count
)
2218 SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS
);
2224 m_powerCost
= CalculatePowerCost();
2226 SpellCastResult result
= CheckCast(true);
2227 if(result
!= SPELL_CAST_OK
&& !IsAutoRepeat()) //always cast autorepeat dummy for triggering
2231 SendChannelUpdate(0);
2232 triggeredByAura
->SetAuraDuration(0);
2234 SendCastResult(result
);
2239 // Prepare data for triggers
2240 prepareDataForTriggerSystem();
2242 // calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
2243 m_casttime
= GetSpellCastTime(m_spellInfo
, this);
2245 // set timer base at cast time
2248 // stealth must be removed at cast starting (at show channel bar)
2249 // skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
2250 if ( !m_IsTriggeredSpell
&& isSpellBreakStealth(m_spellInfo
) )
2252 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
2253 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
2256 if(m_IsTriggeredSpell
)
2260 m_caster
->SetCurrentCastedSpell( this );
2261 m_selfContainer
= &(m_caster
->m_currentSpells
[GetCurrentContainer()]);
2266 void Spell::cancel()
2268 if(m_spellState
== SPELL_STATE_FINISHED
)
2271 m_autoRepeat
= false;
2272 switch (m_spellState
)
2274 case SPELL_STATE_PREPARING
:
2275 case SPELL_STATE_DELAYED
:
2278 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2281 case SPELL_STATE_CASTING
:
2283 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2285 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2287 Unit
* unit
= m_caster
->GetGUID()==(*ihit
).targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2288 if( unit
&& unit
->isAlive() )
2289 unit
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2293 m_caster
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2294 SendChannelUpdate(0);
2296 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2305 m_caster
->RemoveDynObject(m_spellInfo
->Id
);
2306 m_caster
->RemoveGameObject(m_spellInfo
->Id
,true);
2309 void Spell::cast(bool skipCheck
)
2311 SetExecutedCurrently(true);
2313 // update pointers base at GUIDs to prevent access to non-existed already object
2316 // cancel at lost main target unit
2317 if(!m_targets
.getUnitTarget() && m_targets
.getUnitTargetGUID() && m_targets
.getUnitTargetGUID() != m_caster
->GetGUID())
2320 SetExecutedCurrently(false);
2324 if(m_caster
->GetTypeId() != TYPEID_PLAYER
&& m_targets
.getUnitTarget() && m_targets
.getUnitTarget() != m_caster
)
2325 m_caster
->SetInFront(m_targets
.getUnitTarget());
2327 SpellCastResult castResult
= CheckPower();
2328 if(castResult
!= SPELL_CAST_OK
)
2330 SendCastResult(castResult
);
2332 SetExecutedCurrently(false);
2336 // triggered cast called from Spell::prepare where it was already checked
2339 castResult
= CheckCast(false);
2340 if(castResult
!= SPELL_CAST_OK
)
2342 SendCastResult(castResult
);
2344 SetExecutedCurrently(false);
2349 switch(m_spellInfo
->SpellFamilyName
)
2351 case SPELLFAMILY_GENERIC
:
2353 if (m_spellInfo
->Mechanic
== MECHANIC_BANDAGE
) // Bandages
2354 m_preCastSpell
= 11196; // Recently Bandaged
2355 else if(m_spellInfo
->SpellIconID
== 1662 && m_spellInfo
->AttributesEx
& 0x20) // Blood Fury (Racial)
2356 m_preCastSpell
= 23230; // Blood Fury - Healing Reduction
2359 case SPELLFAMILY_MAGE
:
2361 if (m_spellInfo
->SpellFamilyFlags
&0x0000008000000000LL
) // Ice Block
2362 m_preCastSpell
= 41425; // Hypothermia
2365 case SPELLFAMILY_PRIEST
:
2367 if (m_spellInfo
->Mechanic
== MECHANIC_SHIELD
&&
2368 m_spellInfo
->SpellIconID
== 566) // Power Word: Shield
2369 m_preCastSpell
= 6788; // Weakened Soul
2370 if (m_spellInfo
->Id
== 47585) // Dispersion (transform)
2371 m_preCastSpell
= 60069; // Dispersion (mana regen)
2374 case SPELLFAMILY_PALADIN
:
2376 if (m_spellInfo
->SpellFamilyFlags
&0x0000000000400080LL
) // Divine Shield, Divine Protection or Hand of Protection
2377 m_preCastSpell
= 25771; // Forbearance
2380 case SPELLFAMILY_SHAMAN
:
2382 if (m_spellInfo
->Id
== 2825) // Bloodlust
2383 m_preCastSpell
= 57724; // Sated
2384 else if (m_spellInfo
->Id
== 32182) // Heroism
2385 m_preCastSpell
= 57723; // Exhaustion
2392 // Conflagrate - consumes immolate
2393 if ((m_spellInfo
->TargetAuraState
== AURA_STATE_IMMOLATE
) && m_targets
.getUnitTarget())
2395 // for caster applied auras only
2396 Unit::AuraList
const &mPeriodic
= m_targets
.getUnitTarget()->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
2397 for(Unit::AuraList::const_iterator i
= mPeriodic
.begin(); i
!= mPeriodic
.end(); ++i
)
2399 if( (*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& ((*i
)->GetSpellProto()->SpellFamilyFlags
& 4) &&
2400 (*i
)->GetCasterGUID()==m_caster
->GetGUID() )
2402 m_targets
.getUnitTarget()->RemoveAura((*i
)->GetId(), (*i
)->GetEffIndex());
2408 // traded items have trade slot instead of guid in m_itemTargetGUID
2409 // set to real guid to be sent later to the client
2410 m_targets
.updateTradeSlotItem();
2412 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2414 if (!m_IsTriggeredSpell
&& m_CastItem
)
2415 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM
, m_CastItem
->GetEntry());
2417 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL
, m_spellInfo
->Id
);
2422 if(m_spellState
== SPELL_STATE_FINISHED
) // stop cast if spell marked as finish somewhere in FillTargetMap
2424 SetExecutedCurrently(false);
2429 SendSpellCooldown();
2432 TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
2434 SendCastResult(castResult
);
2435 SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2437 // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2438 if (m_spellInfo
->speed
> 0.0f
)
2441 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2442 // in case delayed spell remove item at cast delay start
2445 // Okay, maps created, now prepare flags
2446 m_immediateHandled
= false;
2447 m_spellState
= SPELL_STATE_DELAYED
;
2452 // Immediate spell, no big deal
2456 SetExecutedCurrently(false);
2459 void Spell::handle_immediate()
2461 // start channeling if applicable
2462 if(IsChanneledSpell(m_spellInfo
))
2464 int32 duration
= GetSpellDuration(m_spellInfo
);
2467 // Apply duration mod
2468 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
2469 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_DURATION
, duration
);
2470 m_spellState
= SPELL_STATE_CASTING
;
2471 SendChannelStart(duration
);
2475 // process immediate effects (items, ground, etc.) also initialize some variables
2476 _handle_immediate_phase();
2478 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2479 DoAllEffectOnTarget(&(*ihit
));
2481 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2482 DoAllEffectOnTarget(&(*ihit
));
2484 // spell is finished, perform some last features of the spell here
2485 _handle_finish_phase();
2487 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2490 if(m_spellState
!= SPELL_STATE_CASTING
)
2491 finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell)
2494 uint64
Spell::handle_delayed(uint64 t_offset
)
2496 uint64 next_time
= 0;
2498 if (!m_immediateHandled
)
2500 _handle_immediate_phase();
2501 m_immediateHandled
= true;
2504 // 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)
2505 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2507 if (ihit
->processed
== false)
2509 if ( ihit
->timeDelay
<= t_offset
)
2510 DoAllEffectOnTarget(&(*ihit
));
2511 else if( next_time
== 0 || ihit
->timeDelay
< next_time
)
2512 next_time
= ihit
->timeDelay
;
2516 // now recheck gameobject targeting correctness
2517 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
2519 if (ighit
->processed
== false)
2521 if ( ighit
->timeDelay
<= t_offset
)
2522 DoAllEffectOnTarget(&(*ighit
));
2523 else if( next_time
== 0 || ighit
->timeDelay
< next_time
)
2524 next_time
= ighit
->timeDelay
;
2527 // All targets passed - need finish phase
2530 // spell is finished, perform some last features of the spell here
2531 _handle_finish_phase();
2533 finish(true); // successfully finish spell cast
2535 // return zero, spell is finished now
2540 // spell is unfinished, return next execution time
2545 void Spell::_handle_immediate_phase()
2547 // handle some immediate features of the spell here
2548 HandleThreatSpells(m_spellInfo
->Id
);
2550 m_needSpellLog
= IsNeedSendToClient();
2551 for(uint32 j
= 0;j
<3;j
++)
2553 if(m_spellInfo
->Effect
[j
]==0)
2556 // apply Send Event effect to ground in case empty target lists
2557 if( m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
&& !HaveTargetsForEffect(j
) )
2559 HandleEffects(NULL
,NULL
,NULL
, j
);
2563 // Don't do spell log, if is school damage spell
2564 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
|| m_spellInfo
->Effect
[j
] == 0)
2565 m_needSpellLog
= false;
2567 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[j
];
2568 if(m_originalCaster
)
2569 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
2570 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
2572 // initialize multipliers
2573 m_damageMultipliers
[j
] = 1.0f
;
2574 if( (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_HEAL
) &&
2575 (EffectChainTarget
> 1) )
2576 m_applyMultiplierMask
|= 1 << j
;
2579 // initialize Diminishing Returns Data
2580 m_diminishLevel
= DIMINISHING_LEVEL_1
;
2581 m_diminishGroup
= DIMINISHING_NONE
;
2584 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
2585 DoAllEffectOnTarget(&(*ihit
));
2588 for(uint32 j
= 0;j
<3;j
++)
2590 // persistent area auras target only the ground
2591 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2592 HandleEffects(NULL
,NULL
,NULL
, j
);
2596 void Spell::_handle_finish_phase()
2603 void Spell::SendSpellCooldown()
2605 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
2608 Player
* _player
= (Player
*)m_caster
;
2610 // mana/health/etc potions, disabled by client (until combat out as declarate)
2611 if (m_CastItem
&& m_CastItem
->IsPotion())
2613 // need in some way provided data for Spell::finish SendCooldownEvent
2614 _player
->SetLastPotionId(m_CastItem
->GetEntry());
2618 // have infinity cooldown but set at aura apply
2619 if(m_spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
2622 _player
->AddSpellAndCategoryCooldowns(m_spellInfo
,m_CastItem
? m_CastItem
->GetEntry() : 0, this);
2625 void Spell::update(uint32 difftime
)
2627 // update pointers based at it's GUIDs
2630 if(m_targets
.getUnitTargetGUID() && !m_targets
.getUnitTarget())
2636 // check if the player caster has moved before the spell finished
2637 if ((m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_timer
!= 0) &&
2638 (m_castPositionX
!= m_caster
->GetPositionX() || m_castPositionY
!= m_caster
->GetPositionY() || m_castPositionZ
!= m_caster
->GetPositionZ()) &&
2639 (m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
|| !m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_FALLING
)))
2641 // always cancel for channeled spells
2642 if( m_spellState
== SPELL_STATE_CASTING
)
2644 // don't cancel for melee, autorepeat, triggered and instant spells
2645 else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_MOVEMENT
))
2649 switch(m_spellState
)
2651 case SPELL_STATE_PREPARING
:
2655 if(difftime
>= m_timer
)
2658 m_timer
-= difftime
;
2661 if(m_timer
== 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat())
2664 case SPELL_STATE_CASTING
:
2668 if( m_caster
->GetTypeId() == TYPEID_PLAYER
)
2670 // check if player has jumped before the channeling finished
2671 if(m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_JUMPING
))
2674 // check for incapacitating player states
2675 if( m_caster
->hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_CONFUSED
))
2678 // check if player has turned if flag is set
2679 if( m_spellInfo
->ChannelInterruptFlags
& CHANNEL_FLAG_TURNING
&& m_castOrientation
!= m_caster
->GetOrientation() )
2683 // check if there are alive targets left
2684 if (!IsAliveUnitPresentInTargetList())
2686 SendChannelUpdate(0);
2690 if(difftime
>= m_timer
)
2693 m_timer
-= difftime
;
2698 SendChannelUpdate(0);
2700 // channeled spell processed independently for quest targeting
2701 // cast at creature (or GO) quest objectives update at successful cast channel finished
2702 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
2703 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() )
2705 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
2707 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2709 TargetInfo
* target
= &*ihit
;
2710 if(!IS_CREATURE_GUID(target
->targetGUID
))
2713 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
2717 p
->CastedCreatureOrGO(unit
->GetEntry(),unit
->GetGUID(),m_spellInfo
->Id
);
2720 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2722 GOTargetInfo
* target
= &*ihit
;
2724 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
2728 p
->CastedCreatureOrGO(go
->GetEntry(),go
->GetGUID(),m_spellInfo
->Id
);
2742 void Spell::finish(bool ok
)
2747 if(m_spellState
== SPELL_STATE_FINISHED
)
2750 m_spellState
= SPELL_STATE_FINISHED
;
2752 // other code related only to successfully finished spells
2757 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2758 ((Player
*)m_caster
)->RemoveSpellMods(this);
2760 // handle SPELL_AURA_ADD_TARGET_TRIGGER auras
2761 Unit::AuraList
const& targetTriggers
= m_caster
->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER
);
2762 for(Unit::AuraList::const_iterator i
= targetTriggers
.begin(); i
!= targetTriggers
.end(); ++i
)
2764 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
2766 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2767 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2769 // check m_caster->GetGUID() let load auras at login and speedup most often case
2770 Unit
*unit
= m_caster
->GetGUID()== ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2771 if (unit
&& unit
->isAlive())
2773 SpellEntry
const *auraSpellInfo
= (*i
)->GetSpellProto();
2774 uint32 auraSpellIdx
= (*i
)->GetEffIndex();
2775 // Calculate chance at that moment (can be depend for example from combo points)
2776 int32 chance
= m_caster
->CalculateSpellDamage(auraSpellInfo
, auraSpellIdx
, (*i
)->GetBasePoints(),unit
);
2777 if(roll_chance_i(chance
))
2778 m_caster
->CastSpell(unit
, auraSpellInfo
->EffectTriggerSpell
[auraSpellIdx
], true, NULL
, (*i
));
2783 // Heal caster for all health leech from all targets
2785 m_caster
->DealHeal(m_caster
, uint32(m_healthLeech
), m_spellInfo
);
2787 if (IsMeleeAttackResetSpell())
2789 m_caster
->resetAttackTimer(BASE_ATTACK
);
2790 if(m_caster
->haveOffhandWeapon())
2791 m_caster
->resetAttackTimer(OFF_ATTACK
);
2794 /*if (IsRangedAttackResetSpell())
2795 m_caster->resetAttackTimer(RANGED_ATTACK);*/
2797 // Clear combo at finish state
2798 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& NeedsComboPoints(m_spellInfo
))
2800 // Not drop combopoints if negative spell and if any miss on enemy exist
2801 bool needDrop
= true;
2802 if (!IsPositiveSpell(m_spellInfo
->Id
))
2803 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2804 if (ihit
->missCondition
!= SPELL_MISS_NONE
&& ihit
->targetGUID
!=m_caster
->GetGUID())
2810 ((Player
*)m_caster
)->ClearComboPoints();
2813 // potions disabled by client, send event "not in combat" if need
2814 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2815 ((Player
*)m_caster
)->UpdatePotionCooldown(this);
2817 // call triggered spell only at successful cast (after clear combo points -> for add some if need)
2818 if(!m_TriggerSpells
.empty())
2821 // Stop Attack for some spells
2822 if( m_spellInfo
->Attributes
& SPELL_ATTR_STOP_ATTACK_TARGET
)
2823 m_caster
->AttackStop();
2826 void Spell::SendCastResult(SpellCastResult result
)
2828 if(result
== SPELL_CAST_OK
)
2831 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
2834 if(((Player
*)m_caster
)->GetSession()->PlayerLoading()) // don't send cast results at loading time
2837 WorldPacket
data(SMSG_CAST_FAILED
, (4+1+1));
2838 data
<< uint8(m_cast_count
); // single cast or multi 2.3 (0/1)
2839 data
<< uint32(m_spellInfo
->Id
);
2840 data
<< uint8(result
); // problem
2843 case SPELL_FAILED_REQUIRES_SPELL_FOCUS
:
2844 data
<< uint32(m_spellInfo
->RequiresSpellFocus
);
2846 case SPELL_FAILED_REQUIRES_AREA
:
2847 // hardcode areas limitation case
2848 switch(m_spellInfo
->Id
)
2850 case 41617: // Cenarion Mana Salve
2851 case 41619: // Cenarion Healing Salve
2852 data
<< uint32(3905);
2854 case 41618: // Bottled Nethergon Energy
2855 case 41620: // Bottled Nethergon Vapor
2856 data
<< uint32(3842);
2858 case 45373: // Bloodberry Elixir
2859 data
<< uint32(4075);
2861 default: // default case (don't must be)
2866 case SPELL_FAILED_TOTEMS
:
2867 if(m_spellInfo
->Totem
[0])
2868 data
<< uint32(m_spellInfo
->Totem
[0]);
2869 if(m_spellInfo
->Totem
[1])
2870 data
<< uint32(m_spellInfo
->Totem
[1]);
2872 case SPELL_FAILED_TOTEM_CATEGORY
:
2873 if(m_spellInfo
->TotemCategory
[0])
2874 data
<< uint32(m_spellInfo
->TotemCategory
[0]);
2875 if(m_spellInfo
->TotemCategory
[1])
2876 data
<< uint32(m_spellInfo
->TotemCategory
[1]);
2878 case SPELL_FAILED_EQUIPPED_ITEM_CLASS
:
2879 data
<< uint32(m_spellInfo
->EquippedItemClass
);
2880 data
<< uint32(m_spellInfo
->EquippedItemSubClassMask
);
2881 //data << uint32(m_spellInfo->EquippedItemInventoryTypeMask);
2886 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
2889 void Spell::SendSpellStart()
2891 if(!IsNeedSendToClient())
2894 sLog
.outDebug("Sending SMSG_SPELL_START id=%u", m_spellInfo
->Id
);
2896 uint32 castFlags
= CAST_FLAG_UNKNOWN1
;
2898 castFlags
|= CAST_FLAG_AMMO
;
2900 if(m_spellInfo
->runeCostID
)
2901 castFlags
|= CAST_FLAG_UNKNOWN10
;
2903 WorldPacket
data(SMSG_SPELL_START
, (8+8+4+4+2));
2905 data
.append(m_CastItem
->GetPackGUID());
2907 data
.append(m_caster
->GetPackGUID());
2909 data
.append(m_caster
->GetPackGUID());
2910 data
<< uint8(m_cast_count
); // pending spell cast?
2911 data
<< uint32(m_spellInfo
->Id
); // spellId
2912 data
<< uint32(castFlags
); // cast flags
2913 data
<< uint32(m_timer
); // delay?
2915 m_targets
.write(&data
);
2917 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // predicted power?
2920 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
2922 uint8 v1
= 0;//m_runesState;
2923 uint8 v2
= 0;//((Player*)m_caster)->GetRunesState();
2924 data
<< uint8(v1
); // runes state before
2925 data
<< uint8(v2
); // runes state after
2926 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
2929 if(m
& v1
) // usable before...
2930 if(!(m
& v2
)) // ...but on cooldown now...
2931 data
<< uint8(0); // some unknown byte (time?)
2935 if ( castFlags
& CAST_FLAG_AMMO
)
2936 WriteAmmoToPacket(&data
);
2938 m_caster
->SendMessageToSet(&data
, true);
2941 void Spell::SendSpellGo()
2943 // not send invisible spell casting
2944 if(!IsNeedSendToClient())
2947 sLog
.outDebug("Sending SMSG_SPELL_GO id=%u", m_spellInfo
->Id
);
2949 uint32 castFlags
= CAST_FLAG_UNKNOWN3
;
2951 castFlags
|= CAST_FLAG_AMMO
; // arrows/bullets visual
2953 if((m_caster
->GetTypeId() == TYPEID_PLAYER
) && (m_caster
->getClass() == CLASS_DEATH_KNIGHT
) && m_spellInfo
->runeCostID
)
2955 castFlags
|= CAST_FLAG_UNKNOWN10
; // same as in SMSG_SPELL_START
2956 castFlags
|= CAST_FLAG_UNKNOWN6
; // makes cooldowns visible
2957 castFlags
|= CAST_FLAG_UNKNOWN7
; // rune cooldowns list
2960 WorldPacket
data(SMSG_SPELL_GO
, 50); // guess size
2963 data
.append(m_CastItem
->GetPackGUID());
2965 data
.append(m_caster
->GetPackGUID());
2967 data
.append(m_caster
->GetPackGUID());
2968 data
<< uint8(m_cast_count
); // pending spell cast?
2969 data
<< uint32(m_spellInfo
->Id
); // spellId
2970 data
<< uint32(castFlags
); // cast flags
2971 data
<< uint32(getMSTime()); // timestamp
2973 WriteSpellGoTargets(&data
);
2975 m_targets
.write(&data
);
2977 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // unknown wotlk, predicted power?
2980 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
2982 uint8 v1
= m_runesState
;
2983 uint8 v2
= ((Player
*)m_caster
)->GetRunesState();
2984 data
<< uint8(v1
); // runes state before
2985 data
<< uint8(v2
); // runes state after
2986 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
2989 if(m
& v1
) // usable before...
2990 if(!(m
& v2
)) // ...but on cooldown now...
2991 data
<< uint8(0); // some unknown byte (time?)
2995 if ( castFlags
& CAST_FLAG_UNKNOWN4
) // unknown wotlk
3001 if ( castFlags
& CAST_FLAG_AMMO
)
3002 WriteAmmoToPacket(&data
);
3004 if ( castFlags
& CAST_FLAG_UNKNOWN5
) // unknown wotlk
3010 if ( m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
3015 m_caster
->SendMessageToSet(&data
, true);
3018 void Spell::WriteAmmoToPacket( WorldPacket
* data
)
3020 uint32 ammoInventoryType
= 0;
3021 uint32 ammoDisplayID
= 0;
3023 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3025 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack( RANGED_ATTACK
);
3028 ammoInventoryType
= pItem
->GetProto()->InventoryType
;
3029 if( ammoInventoryType
== INVTYPE_THROWN
)
3030 ammoDisplayID
= pItem
->GetProto()->DisplayInfoID
;
3033 uint32 ammoID
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
3036 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( ammoID
);
3039 ammoDisplayID
= pProto
->DisplayInfoID
;
3040 ammoInventoryType
= pProto
->InventoryType
;
3043 else if(m_caster
->GetDummyAura(46699)) // Requires No Ammo
3045 ammoDisplayID
= 5996; // normal arrow
3046 ammoInventoryType
= INVTYPE_AMMO
;
3051 // TODO: implement selection ammo data based at ranged weapon stored in equipmodel/equipinfo/equipslot fields
3053 *data
<< uint32(ammoDisplayID
);
3054 *data
<< uint32(ammoInventoryType
);
3057 void Spell::WriteSpellGoTargets( WorldPacket
* data
)
3059 // This function also fill data for channeled spells:
3060 // m_needAliveTargetMask req for stop channelig if one target die
3061 uint32 hit
= m_UniqueGOTargetInfo
.size(); // Always hits on GO
3063 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3065 if ((*ihit
).effectMask
== 0) // No effect apply - all immuned add state
3067 // possibly SPELL_MISS_IMMUNE2 for this??
3068 ihit
->missCondition
= SPELL_MISS_IMMUNE2
;
3071 else if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
3077 *data
<< (uint8
)hit
;
3078 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3079 if ((*ihit
).missCondition
== SPELL_MISS_NONE
) // Add only hits
3081 *data
<< uint64(ihit
->targetGUID
);
3082 m_needAliveTargetMask
|=ihit
->effectMask
;
3085 for(std::list
<GOTargetInfo
>::const_iterator ighit
= m_UniqueGOTargetInfo
.begin();ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
3086 *data
<< uint64(ighit
->targetGUID
); // Always hits
3088 *data
<< (uint8
)miss
;
3089 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3091 if( ihit
->missCondition
!= SPELL_MISS_NONE
) // Add only miss
3093 *data
<< uint64(ihit
->targetGUID
);
3094 *data
<< uint8(ihit
->missCondition
);
3095 if( ihit
->missCondition
== SPELL_MISS_REFLECT
)
3096 *data
<< uint8(ihit
->reflectResult
);
3099 // Reset m_needAliveTargetMask for non channeled spell
3100 if(!IsChanneledSpell(m_spellInfo
))
3101 m_needAliveTargetMask
= 0;
3104 void Spell::SendLogExecute()
3106 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
3108 WorldPacket
data(SMSG_SPELLLOGEXECUTE
, (8+4+4+4+4+8));
3110 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
3111 data
.append(m_caster
->GetPackGUID());
3113 data
.append(target
->GetPackGUID());
3115 data
<< uint32(m_spellInfo
->Id
);
3117 data
<< uint32(count1
); // count1 (effect count?)
3118 for(uint32 i
= 0; i
< count1
; ++i
)
3120 data
<< uint32(m_spellInfo
->Effect
[0]); // spell effect
3122 data
<< uint32(count2
); // count2 (target count?)
3123 for(uint32 j
= 0; j
< count2
; ++j
)
3125 switch(m_spellInfo
->Effect
[0])
3127 case SPELL_EFFECT_POWER_DRAIN
:
3128 if(Unit
*unit
= m_targets
.getUnitTarget())
3129 data
.append(unit
->GetPackGUID());
3136 case SPELL_EFFECT_ADD_EXTRA_ATTACKS
:
3137 if(Unit
*unit
= m_targets
.getUnitTarget())
3138 data
.append(unit
->GetPackGUID());
3141 data
<< uint32(0); // count?
3143 case SPELL_EFFECT_INTERRUPT_CAST
:
3144 if(Unit
*unit
= m_targets
.getUnitTarget())
3145 data
.append(unit
->GetPackGUID());
3148 data
<< uint32(0); // spellid
3150 case SPELL_EFFECT_DURABILITY_DAMAGE
:
3151 if(Unit
*unit
= m_targets
.getUnitTarget())
3152 data
.append(unit
->GetPackGUID());
3158 case SPELL_EFFECT_OPEN_LOCK
:
3159 case SPELL_EFFECT_OPEN_LOCK_ITEM
:
3160 if(Item
*item
= m_targets
.getItemTarget())
3161 data
.append(item
->GetPackGUID());
3165 case SPELL_EFFECT_CREATE_ITEM
:
3166 case SPELL_EFFECT_CREATE_ITEM_2
:
3167 data
<< uint32(m_spellInfo
->EffectItemType
[0]);
3169 case SPELL_EFFECT_SUMMON
:
3170 case SPELL_EFFECT_TRANS_DOOR
:
3171 case SPELL_EFFECT_SUMMON_PET
:
3172 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
3173 case SPELL_EFFECT_CREATE_HOUSE
:
3174 case SPELL_EFFECT_DUEL
:
3175 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1
:
3176 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2
:
3177 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3
:
3178 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4
:
3179 if(Unit
*unit
= m_targets
.getUnitTarget())
3180 data
.append(unit
->GetPackGUID());
3181 else if(m_targets
.getItemTargetGUID())
3182 data
.appendPackGUID(m_targets
.getItemTargetGUID());
3183 else if(GameObject
*go
= m_targets
.getGOTarget())
3184 data
.append(go
->GetPackGUID());
3186 data
<< uint8(0); // guid
3188 case SPELL_EFFECT_FEED_PET
:
3189 data
<< uint32(m_targets
.getItemTargetEntry());
3191 case SPELL_EFFECT_DISMISS_PET
:
3192 if(Unit
*unit
= m_targets
.getUnitTarget())
3193 data
.append(unit
->GetPackGUID());
3197 case SPELL_EFFECT_RESURRECT
:
3198 case SPELL_EFFECT_RESURRECT_NEW
:
3199 if(Unit
*unit
= m_targets
.getUnitTarget())
3200 data
.append(unit
->GetPackGUID());
3210 m_caster
->SendMessageToSet(&data
, true);
3213 void Spell::SendInterrupted(uint8 result
)
3215 WorldPacket
data(SMSG_SPELL_FAILURE
, (8+4+1));
3216 data
.append(m_caster
->GetPackGUID());
3217 data
<< uint8(m_cast_count
);
3218 data
<< uint32(m_spellInfo
->Id
);
3219 data
<< uint8(result
);
3220 m_caster
->SendMessageToSet(&data
, true);
3222 data
.Initialize(SMSG_SPELL_FAILED_OTHER
, (8+4));
3223 data
.append(m_caster
->GetPackGUID());
3224 data
<< uint8(m_cast_count
);
3225 data
<< uint32(m_spellInfo
->Id
);
3226 data
<< uint8(result
);
3227 m_caster
->SendMessageToSet(&data
, true);
3230 void Spell::SendChannelUpdate(uint32 time
)
3234 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
,0);
3235 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
,0);
3238 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3241 WorldPacket
data( MSG_CHANNEL_UPDATE
, 8+4 );
3242 data
.append(m_caster
->GetPackGUID());
3243 data
<< uint32(time
);
3245 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3248 void Spell::SendChannelStart(uint32 duration
)
3250 WorldObject
* target
= NULL
;
3252 // select first not resisted target from target list for _0_ effect
3253 if(!m_UniqueTargetInfo
.empty())
3255 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin();itr
!= m_UniqueTargetInfo
.end();++itr
)
3257 if( (itr
->effectMask
& (1<<0)) && itr
->reflectResult
==SPELL_MISS_NONE
&& itr
->targetGUID
!= m_caster
->GetGUID())
3259 target
= ObjectAccessor::GetUnit(*m_caster
, itr
->targetGUID
);
3264 else if(!m_UniqueGOTargetInfo
.empty())
3266 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin();itr
!= m_UniqueGOTargetInfo
.end();++itr
)
3268 if(itr
->effectMask
& (1<<0) )
3270 target
= m_caster
->GetMap()->GetGameObject(itr
->targetGUID
);
3276 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3278 WorldPacket
data( MSG_CHANNEL_START
, (8+4+4) );
3279 data
.append(m_caster
->GetPackGUID());
3280 data
<< uint32(m_spellInfo
->Id
);
3281 data
<< uint32(duration
);
3283 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3288 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, target
->GetGUID());
3289 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, m_spellInfo
->Id
);
3292 void Spell::SendResurrectRequest(Player
* target
)
3294 // Both players and NPCs can resurrect using spells - have a look at creature 28487 for example
3295 // However, the packet structure differs slightly
3297 const char* sentName
= m_caster
->GetTypeId()==TYPEID_PLAYER
?"":m_caster
->GetNameForLocaleIdx(target
->GetSession()->GetSessionDbLocaleIndex());
3299 WorldPacket
data(SMSG_RESURRECT_REQUEST
, (8+4+strlen(sentName
)+1+1+1));
3300 data
<< uint64(m_caster
->GetGUID());
3301 data
<< uint32(strlen(sentName
)+1);
3306 data
<< uint8(m_caster
->GetTypeId()==TYPEID_PLAYER
?0:1);
3307 target
->GetSession()->SendPacket(&data
);
3310 void Spell::SendPlaySpellVisual(uint32 SpellID
)
3312 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3315 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 12);
3316 data
<< uint64(m_caster
->GetGUID());
3317 data
<< uint32(SpellID
); // spell visual id?
3318 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
3321 void Spell::TakeCastItem()
3323 if(!m_CastItem
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
3326 // not remove cast item at triggered spell (equipping, weapon damage, etc)
3327 if(m_IsTriggeredSpell
)
3330 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3334 // This code is to avoid a crash
3335 // I'm not sure, if this is really an error, but I guess every item needs a prototype
3336 sLog
.outError("Cast item has no item prototype highId=%d, lowId=%d",m_CastItem
->GetGUIDHigh(), m_CastItem
->GetGUIDLow());
3340 bool expendable
= false;
3341 bool withoutCharges
= false;
3343 for (int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
3345 if (proto
->Spells
[i
].SpellId
)
3347 // item has limited charges
3348 if (proto
->Spells
[i
].SpellCharges
)
3350 if (proto
->Spells
[i
].SpellCharges
< 0)
3353 int32 charges
= m_CastItem
->GetSpellCharges(i
);
3355 // item has charges left
3358 (charges
> 0) ? --charges
: ++charges
; // abs(charges) less at 1 after use
3359 if (proto
->Stackable
== 1)
3360 m_CastItem
->SetSpellCharges(i
, charges
);
3361 m_CastItem
->SetState(ITEM_CHANGED
, (Player
*)m_caster
);
3365 withoutCharges
= (charges
== 0);
3370 if (expendable
&& withoutCharges
)
3373 ((Player
*)m_caster
)->DestroyItemCount(m_CastItem
, count
, true);
3375 // prevent crash at access to deleted m_targets.getItemTarget
3376 if(m_CastItem
==m_targets
.getItemTarget())
3377 m_targets
.setItemTarget(NULL
);
3383 void Spell::TakePower()
3385 if(m_CastItem
|| m_triggeredByAuraSpell
)
3388 // health as power used
3389 if(m_spellInfo
->powerType
== POWER_HEALTH
)
3391 m_caster
->ModifyHealth( -(int32
)m_powerCost
);
3395 if(m_spellInfo
->powerType
>= MAX_POWERS
)
3397 sLog
.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo
->powerType
);
3401 Powers powerType
= Powers(m_spellInfo
->powerType
);
3403 if(powerType
== POWER_RUNE
)
3409 m_caster
->ModifyPower(powerType
, -(int32
)m_powerCost
);
3411 // Set the five second timer
3412 if (powerType
== POWER_MANA
&& m_powerCost
> 0)
3413 m_caster
->SetLastManaUse(getMSTime());
3416 SpellCastResult
Spell::CheckRuneCost(uint32 runeCostID
)
3418 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3419 return SPELL_CAST_OK
;
3421 Player
*plr
= (Player
*)m_caster
;
3423 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3424 return SPELL_CAST_OK
;
3426 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(runeCostID
);
3429 return SPELL_CAST_OK
;
3431 if(src
->NoRuneCost())
3432 return SPELL_CAST_OK
;
3434 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3436 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3437 runeCost
[i
] = src
->RuneCost
[i
];
3439 runeCost
[RUNE_DEATH
] = MAX_RUNES
; // calculated later
3441 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3443 uint8 rune
= plr
->GetCurrentRune(i
);
3444 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3448 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3450 runeCost
[RUNE_DEATH
] += runeCost
[i
];
3452 if(runeCost
[RUNE_DEATH
] > MAX_RUNES
)
3453 return SPELL_FAILED_NO_POWER
; // not sure if result code is correct
3455 return SPELL_CAST_OK
;
3458 void Spell::TakeRunePower()
3460 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3463 Player
*plr
= (Player
*)m_caster
;
3465 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3468 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(m_spellInfo
->runeCostID
);
3470 if(!src
|| (src
->NoRuneCost() && src
->NoRunicPowerGain()))
3473 m_runesState
= plr
->GetRunesState(); // store previous state
3475 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3477 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3479 runeCost
[i
] = src
->RuneCost
[i
];
3482 runeCost
[RUNE_DEATH
] = 0; // calculated later
3484 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3486 uint8 rune
= plr
->GetCurrentRune(i
);
3487 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3489 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3494 runeCost
[RUNE_DEATH
] = runeCost
[RUNE_BLOOD
] + runeCost
[RUNE_UNHOLY
] + runeCost
[RUNE_FROST
];
3496 if(runeCost
[RUNE_DEATH
] > 0)
3498 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3500 uint8 rune
= plr
->GetCurrentRune(i
);
3501 if((plr
->GetRuneCooldown(i
) == 0) && (rune
== RUNE_DEATH
))
3503 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3505 plr
->ConvertRune(i
, plr
->GetBaseRune(i
));
3506 if(runeCost
[RUNE_DEATH
] == 0)
3512 // you can gain some runic power when use runes
3513 float rp
= src
->runePowerGain
;;
3514 rp
*= sWorld
.getRate(RATE_POWER_RUNICPOWER_INCOME
);
3515 plr
->ModifyPower(POWER_RUNIC_POWER
, (int32
)rp
);
3518 void Spell::TakeReagents()
3520 if(m_IsTriggeredSpell
) // reagents used in triggered spell removed by original spell or don't must be removed.
3523 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3526 Player
* p_caster
= (Player
*)m_caster
;
3527 if (p_caster
->CanNoReagentCast(m_spellInfo
))
3530 for(uint32 x
=0;x
<8;x
++)
3532 if(m_spellInfo
->Reagent
[x
] <= 0)
3535 uint32 itemid
= m_spellInfo
->Reagent
[x
];
3536 uint32 itemcount
= m_spellInfo
->ReagentCount
[x
];
3538 // if CastItem is also spell reagent
3541 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3542 if( proto
&& proto
->ItemId
== itemid
)
3544 for(int s
=0;s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
3546 // CastItem will be used up and does not count as reagent
3547 int32 charges
= m_CastItem
->GetSpellCharges(s
);
3548 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
3559 // if getItemTarget is also spell reagent
3560 if (m_targets
.getItemTargetEntry()==itemid
)
3561 m_targets
.setItemTarget(NULL
);
3563 p_caster
->DestroyItemCount(itemid
, itemcount
, true);
3567 void Spell::HandleThreatSpells(uint32 spellId
)
3569 if(!m_targets
.getUnitTarget() || !spellId
)
3572 if(!m_targets
.getUnitTarget()->CanHaveThreatList())
3575 SpellThreatEntry
const *threatSpell
= sSpellThreatStore
.LookupEntry
<SpellThreatEntry
>(spellId
);
3579 m_targets
.getUnitTarget()->AddThreat(m_caster
, float(threatSpell
->threat
));
3581 DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId
, spellmgr
.GetSpellRank(spellId
), threatSpell
->threat
);
3584 void Spell::HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,uint32 i
, float DamageMultiplier
)
3586 unitTarget
= pUnitTarget
;
3587 itemTarget
= pItemTarget
;
3588 gameObjTarget
= pGOTarget
;
3590 uint8 eff
= m_spellInfo
->Effect
[i
];
3592 damage
= int32(CalculateDamage((uint8
)i
,unitTarget
)*DamageMultiplier
);
3594 sLog
.outDebug( "Spell: Effect : %u", eff
);
3596 if(eff
<TOTAL_SPELL_EFFECTS
)
3598 //sLog.outDebug( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff);
3599 (*this.*SpellEffects
[eff
])(i
);
3604 sLog.outDebug( "WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff);
3606 EffectEnchantItemTmp(i);
3609 sLog.outError("SPELL: unknown effect %u spell id %u",
3610 eff, m_spellInfo->Id);
3616 void Spell::TriggerSpell()
3618 for(TriggerSpells::const_iterator si
=m_TriggerSpells
.begin(); si
!=m_TriggerSpells
.end(); ++si
)
3620 Spell
* spell
= new Spell(m_caster
, (*si
), true, m_originalCasterGUID
, m_selfContainer
);
3621 spell
->prepare(&m_targets
); // use original spell original targets
3625 SpellCastResult
Spell::CheckCast(bool strict
)
3627 // check cooldowns to prevent cheating
3628 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
3630 if(m_triggeredByAuraSpell
)
3631 return SPELL_FAILED_DONT_REPORT
;
3633 return SPELL_FAILED_NOT_READY
;
3636 // only allow triggered spells if at an ended battleground
3637 if( !m_IsTriggeredSpell
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
3638 if(BattleGround
* bg
= ((Player
*)m_caster
)->GetBattleGround())
3639 if(bg
->GetStatus() == STATUS_WAIT_LEAVE
)
3640 return SPELL_FAILED_DONT_REPORT
;
3642 // only check at first call, Stealth auras are already removed at second call
3643 // for now, ignore triggered spells
3644 if( strict
&& !m_IsTriggeredSpell
)
3646 bool checkForm
= true;
3647 // Ignore form req aura
3648 Unit::AuraList
const& ignore
= m_caster
->GetAurasByType(SPELL_AURA_MOD_IGNORE_SHAPESHIFT
);
3649 for(Unit::AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
3651 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
3658 // Cannot be used in this stance/form
3659 SpellCastResult shapeError
= GetErrorAtShapeshiftedCast(m_spellInfo
, m_caster
->m_form
);
3660 if(shapeError
!= SPELL_CAST_OK
)
3663 if ((m_spellInfo
->Attributes
& SPELL_ATTR_ONLY_STEALTHED
) && !(m_caster
->HasStealthAura()))
3664 return SPELL_FAILED_ONLY_STEALTHED
;
3668 // caster state requirements
3669 if(m_spellInfo
->CasterAuraState
&& !m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraState
)))
3670 return SPELL_FAILED_CASTER_AURASTATE
;
3671 if(m_spellInfo
->CasterAuraStateNot
&& m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraStateNot
)))
3672 return SPELL_FAILED_CASTER_AURASTATE
;
3674 // Caster aura req check if need
3675 if(m_spellInfo
->casterAuraSpell
&& !m_caster
->HasAura(m_spellInfo
->casterAuraSpell
))
3676 return SPELL_FAILED_CASTER_AURASTATE
;
3677 if(m_spellInfo
->excludeCasterAuraSpell
&& m_caster
->HasAura(m_spellInfo
->excludeCasterAuraSpell
))
3678 return SPELL_FAILED_CASTER_AURASTATE
;
3680 // cancel autorepeat spells if cast start when moving
3681 // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
3682 if( m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->isMoving() )
3684 // skip stuck spell to allow use it in falling case and apply spell limitations at movement
3685 if( (!m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_FALLING
) || m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
) &&
3686 (IsAutoRepeat() || (m_spellInfo
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_NOT_SEATED
) != 0) )
3687 return SPELL_FAILED_MOVING
;
3690 if(Unit
*target
= m_targets
.getUnitTarget())
3692 // target state requirements (not allowed state), apply to self also
3693 if(m_spellInfo
->TargetAuraStateNot
&& target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraStateNot
)))
3694 return SPELL_FAILED_TARGET_AURASTATE
;
3696 // Target aura req check if need
3697 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
3698 return SPELL_FAILED_CASTER_AURASTATE
;
3699 if(m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
3700 return SPELL_FAILED_CASTER_AURASTATE
;
3702 if(target
!= m_caster
)
3704 // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds
3705 if(m_spellInfo
->TargetAuraState
&& !target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraState
)))
3706 return SPELL_FAILED_TARGET_AURASTATE
;
3708 // Not allow casting on flying player
3709 if (target
->isInFlight())
3710 return SPELL_FAILED_BAD_TARGETS
;
3712 if(!m_IsTriggeredSpell
&& VMAP::VMapFactory::checkSpellForLoS(m_spellInfo
->Id
) && !m_caster
->IsWithinLOSInMap(target
))
3713 return SPELL_FAILED_LINE_OF_SIGHT
;
3715 // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode
3716 // this case can be triggered if rank not found (too low-level target for first rank)
3717 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsPassiveSpell(m_spellInfo
->Id
) && !m_CastItem
)
3718 for(int i
=0;i
<3;++i
)
3719 if(IsPositiveEffect(m_spellInfo
->Id
, i
) && m_spellInfo
->Effect
[i
] == SPELL_EFFECT_APPLY_AURA
)
3720 if(target
->getLevel() + 10 < m_spellInfo
->spellLevel
)
3721 return SPELL_FAILED_LOWLEVEL
;
3723 else if (m_caster
->GetTypeId()==TYPEID_PLAYER
) // Target - is player caster
3725 // Additional check for some spells
3726 // If 0 spell effect empty - client not send target data (need use selection)
3727 // TODO: check it on next client version
3728 if (m_targets
.m_targetMask
== TARGET_FLAG_SELF
&&
3729 m_spellInfo
->EffectImplicitTargetA
[1] == TARGET_CHAIN_DAMAGE
)
3731 if (target
= m_caster
->GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection()))
3732 m_targets
.setUnitTarget(target
);
3734 return SPELL_FAILED_BAD_TARGETS
;
3738 // check pet presents
3739 for(int j
=0;j
<3;j
++)
3741 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_PET
)
3743 target
= m_caster
->GetPet();
3746 if(m_triggeredByAuraSpell
) // not report pet not existence for triggered spells
3747 return SPELL_FAILED_DONT_REPORT
;
3749 return SPELL_FAILED_NO_PET
;
3755 //check creature type
3756 //ignore self casts (including area casts when caster selected as target)
3757 if(target
!= m_caster
)
3759 if(!CheckTargetCreatureType(target
))
3761 if(target
->GetTypeId()==TYPEID_PLAYER
)
3762 return SPELL_FAILED_TARGET_IS_PLAYER
;
3764 return SPELL_FAILED_BAD_TARGETS
;
3768 // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
3769 // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
3770 if(m_caster
!= target
&& m_caster
->GetTypeId()==TYPEID_UNIT
&& m_caster
->GetCharmerOrOwnerGUID())
3772 // check correctness positive/negative cast target (pet cast real check and cheating check)
3773 if(IsPositiveSpell(m_spellInfo
->Id
))
3775 if(m_caster
->IsHostileTo(target
))
3776 return SPELL_FAILED_BAD_TARGETS
;
3780 if(m_caster
->IsFriendlyTo(target
))
3781 return SPELL_FAILED_BAD_TARGETS
;
3785 if(IsPositiveSpell(m_spellInfo
->Id
))
3786 if(target
->IsImmunedToSpell(m_spellInfo
))
3787 return SPELL_FAILED_TARGET_AURASTATE
;
3789 //Must be behind the target.
3790 if( m_spellInfo
->AttributesEx2
== 0x100000 && (m_spellInfo
->AttributesEx
& 0x200) == 0x200 && target
->HasInArc(M_PI
, m_caster
) )
3792 //Exclusion for Pounce: Facing Limitation was removed in 2.0.1, but it still uses the same, old Ex-Flags
3793 if( m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_DRUID
|| m_spellInfo
->SpellFamilyFlags
!= 0x0000000000020000LL
)
3796 return SPELL_FAILED_NOT_BEHIND
;
3800 //Target must be facing you.
3801 if((m_spellInfo
->Attributes
== 0x150010) && !target
->HasInArc(M_PI
, m_caster
) )
3804 return SPELL_FAILED_NOT_INFRONT
;
3807 // check if target is in combat
3808 if (target
!= m_caster
&& (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET
) && target
->isInCombat())
3809 return SPELL_FAILED_TARGET_AFFECTING_COMBAT
;
3812 // Spell casted only on battleground
3813 if((m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_BATTLEGROUND
) && m_caster
->GetTypeId()==TYPEID_PLAYER
)
3814 if(!((Player
*)m_caster
)->InBattleGround())
3815 return SPELL_FAILED_ONLY_BATTLEGROUNDS
;
3817 // do not allow spells to be cast in arenas
3818 // - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag
3819 // - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag
3820 if( (m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA
) ||
3821 GetSpellRecoveryTime(m_spellInfo
) > 15 * MINUTE
* IN_MILISECONDS
&& !(m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_USABLE_IN_ARENA
) )
3822 if(MapEntry
const* mapEntry
= sMapStore
.LookupEntry(m_caster
->GetMapId()))
3823 if(mapEntry
->IsBattleArena())
3824 return SPELL_FAILED_NOT_IN_ARENA
;
3828 m_caster
->GetZoneAndAreaId(zone
,area
);
3830 SpellCastResult locRes
= spellmgr
.GetSpellAllowedInLocationError(m_spellInfo
,m_caster
->GetMapId(),zone
,area
,
3831 m_caster
->GetTypeId()==TYPEID_PLAYER
? ((Player
*)m_caster
) : NULL
);
3832 if(locRes
!= SPELL_CAST_OK
)
3835 // not let players cast spells at mount (and let do it to creatures)
3836 if( m_caster
->IsMounted() && m_caster
->GetTypeId()==TYPEID_PLAYER
&& !m_IsTriggeredSpell
&&
3837 !IsPassiveSpell(m_spellInfo
->Id
) && !(m_spellInfo
->Attributes
& SPELL_ATTR_CASTABLE_WHILE_MOUNTED
) )
3839 if(m_caster
->isInFlight())
3840 return SPELL_FAILED_NOT_FLYING
;
3842 return SPELL_FAILED_NOT_MOUNTED
;
3845 // always (except passive spells) check items (focus object can be required for any type casts)
3846 if(!IsPassiveSpell(m_spellInfo
->Id
))
3848 SpellCastResult castResult
= CheckItems();
3849 if(castResult
!= SPELL_CAST_OK
)
3853 //ImpliciteTargetA-B = 38, If fact there is 0 Spell with ImpliciteTargetB=38
3854 if(m_UniqueTargetInfo
.empty()) // skip second CheckCast apply (for delayed spells for example)
3856 for(uint8 j
= 0; j
< 3; j
++)
3858 if( m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
3859 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_SELF
||
3860 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3861 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3863 SpellScriptTarget::const_iterator lower
= spellmgr
.GetBeginSpellScriptTarget(m_spellInfo
->Id
);
3864 SpellScriptTarget::const_iterator upper
= spellmgr
.GetEndSpellScriptTarget(m_spellInfo
->Id
);
3866 sLog
.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = TARGET_SCRIPT or TARGET_SCRIPT_COORDINATES, but does not have record in `spell_script_target`",m_spellInfo
->Id
);
3868 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
3869 float range
= GetSpellMaxRange(srange
);
3871 Creature
* creatureScriptTarget
= NULL
;
3872 GameObject
* goScriptTarget
= NULL
;
3874 for(SpellScriptTarget::const_iterator i_spellST
= lower
; i_spellST
!= upper
; ++i_spellST
)
3876 switch(i_spellST
->second
.type
)
3878 case SPELL_TARGET_TYPE_GAMEOBJECT
:
3880 GameObject
* p_GameObject
= NULL
;
3882 if(i_spellST
->second
.targetEntry
)
3884 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
3886 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3888 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*m_caster
,i_spellST
->second
.targetEntry
,range
);
3889 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(m_caster
, p_GameObject
,go_check
);
3891 TypeContainerVisitor
<MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
>, GridTypeMapContainer
> object_checker(checker
);
3892 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3893 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
3897 // remember found target and range, next attempt will find more near target with another entry
3898 creatureScriptTarget
= NULL
;
3899 goScriptTarget
= p_GameObject
;
3900 range
= go_check
.GetLastRange();
3903 else if( focusObject
) //Focus Object
3905 float frange
= m_caster
->GetDistance(focusObject
);
3908 creatureScriptTarget
= NULL
;
3909 goScriptTarget
= focusObject
;
3915 case SPELL_TARGET_TYPE_CREATURE
:
3916 case SPELL_TARGET_TYPE_DEAD
:
3919 Creature
*p_Creature
= NULL
;
3921 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
3923 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3924 cell
.SetNoCreate(); // Really don't know what is that???
3926 MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
u_check(*m_caster
,i_spellST
->second
.targetEntry
,i_spellST
->second
.type
!=SPELL_TARGET_TYPE_DEAD
,range
);
3927 MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
> searcher(m_caster
, p_Creature
, u_check
);
3929 TypeContainerVisitor
<MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
>, GridTypeMapContainer
> grid_creature_searcher(searcher
);
3931 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3932 cell_lock
->Visit(cell_lock
, grid_creature_searcher
, *m_caster
->GetMap());
3936 creatureScriptTarget
= p_Creature
;
3937 goScriptTarget
= NULL
;
3938 range
= u_check
.GetLastRange();
3945 if(creatureScriptTarget
)
3947 // store coordinates for TARGET_SCRIPT_COORDINATES
3948 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3949 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3951 m_targets
.setDestination(creatureScriptTarget
->GetPositionX(),creatureScriptTarget
->GetPositionY(),creatureScriptTarget
->GetPositionZ());
3953 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3954 AddUnitTarget(creatureScriptTarget
, j
);
3956 // store explicit target for TARGET_SCRIPT
3958 AddUnitTarget(creatureScriptTarget
, j
);
3960 else if(goScriptTarget
)
3962 // store coordinates for TARGET_SCRIPT_COORDINATES
3963 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3964 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3966 m_targets
.setDestination(goScriptTarget
->GetPositionX(),goScriptTarget
->GetPositionY(),goScriptTarget
->GetPositionZ());
3968 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3969 AddGOTarget(goScriptTarget
, j
);
3971 // store explicit target for TARGET_SCRIPT
3973 AddGOTarget(goScriptTarget
, j
);
3975 //Missing DB Entry or targets for this spellEffect.
3978 // not report target not existence for triggered spells
3979 if(m_triggeredByAuraSpell
|| m_IsTriggeredSpell
)
3980 return SPELL_FAILED_DONT_REPORT
;
3982 return SPELL_FAILED_BAD_TARGETS
;
3988 if(!m_IsTriggeredSpell
)
3990 SpellCastResult castResult
= CheckRange(strict
);
3991 if(castResult
!= SPELL_CAST_OK
)
3996 SpellCastResult castResult
= CheckPower();
3997 if(castResult
!= SPELL_CAST_OK
)
4001 if(!m_IsTriggeredSpell
) // triggered spell not affected by stun/etc
4003 SpellCastResult castResult
= CheckCasterAuras();
4004 if(castResult
!= SPELL_CAST_OK
)
4008 for (int i
= 0; i
< 3; ++i
)
4010 // for effects of spells that have only one target
4011 switch(m_spellInfo
->Effect
[i
])
4013 case SPELL_EFFECT_DUMMY
:
4015 if(m_spellInfo
->SpellIconID
== 1648) // Execute
4017 if(!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4018 return SPELL_FAILED_BAD_TARGETS
;
4020 else if (m_spellInfo
->Id
== 51582) // Rocket Boots Engaged
4022 if(m_caster
->IsInWater())
4023 return SPELL_FAILED_ONLY_ABOVEWATER
;
4025 else if(m_spellInfo
->SpellIconID
==156) // Holy Shock
4027 // spell different for friends and enemies
4028 // hart version required facing
4029 if(m_targets
.getUnitTarget() && !m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()) && !m_caster
->HasInArc( M_PI
, m_targets
.getUnitTarget() ))
4030 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4034 case SPELL_EFFECT_SCHOOL_DAMAGE
:
4037 if(m_spellInfo
->SpellVisual
[0] == 7250)
4039 if (!m_targets
.getUnitTarget())
4040 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4042 if(m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4043 return SPELL_FAILED_BAD_TARGETS
;
4047 case SPELL_EFFECT_TAMECREATURE
:
4049 if (!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
)
4050 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4052 if (m_targets
.getUnitTarget()->getLevel() > m_caster
->getLevel())
4053 return SPELL_FAILED_HIGHLEVEL
;
4055 // use SMSG_PET_TAME_FAILURE?
4056 if (!((Creature
*)m_targets
.getUnitTarget())->GetCreatureInfo()->isTameable ())
4057 return SPELL_FAILED_BAD_TARGETS
;
4059 if(m_caster
->GetPetGUID())
4060 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4062 if(m_caster
->GetCharmGUID())
4063 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4067 case SPELL_EFFECT_LEARN_SPELL
:
4069 if(m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_PET
)
4072 Pet
* pet
= m_caster
->GetPet();
4075 return SPELL_FAILED_NO_PET
;
4077 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4079 if(!learn_spellproto
)
4080 return SPELL_FAILED_NOT_KNOWN
;
4082 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4083 return SPELL_FAILED_LOWLEVEL
;
4087 case SPELL_EFFECT_LEARN_PET_SPELL
:
4089 Pet
* pet
= m_caster
->GetPet();
4092 return SPELL_FAILED_NO_PET
;
4094 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4096 if(!learn_spellproto
)
4097 return SPELL_FAILED_NOT_KNOWN
;
4099 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4100 return SPELL_FAILED_LOWLEVEL
;
4104 case SPELL_EFFECT_FEED_PET
:
4106 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4107 return SPELL_FAILED_BAD_TARGETS
;
4109 Item
* foodItem
= m_targets
.getItemTarget();
4111 return SPELL_FAILED_BAD_TARGETS
;
4113 Pet
* pet
= m_caster
->GetPet();
4116 return SPELL_FAILED_NO_PET
;
4118 if(!pet
->HaveInDiet(foodItem
->GetProto()))
4119 return SPELL_FAILED_WRONG_PET_FOOD
;
4121 if(!pet
->GetCurrentFoodBenefitLevel(foodItem
->GetProto()->ItemLevel
))
4122 return SPELL_FAILED_FOOD_LOWLEVEL
;
4124 if(m_caster
->isInCombat() || pet
->isInCombat())
4125 return SPELL_FAILED_AFFECTING_COMBAT
;
4129 case SPELL_EFFECT_POWER_BURN
:
4130 case SPELL_EFFECT_POWER_DRAIN
:
4132 // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
4133 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4134 if(Unit
* target
= m_targets
.getUnitTarget())
4135 if(target
!=m_caster
&& target
->getPowerType()!=m_spellInfo
->EffectMiscValue
[i
])
4136 return SPELL_FAILED_BAD_TARGETS
;
4139 case SPELL_EFFECT_CHARGE
:
4141 if (m_caster
->hasUnitState(UNIT_STAT_ROOT
))
4142 return SPELL_FAILED_ROOTED
;
4146 case SPELL_EFFECT_SKINNING
:
4148 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() != TYPEID_UNIT
)
4149 return SPELL_FAILED_BAD_TARGETS
;
4151 if( !(m_targets
.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS
) & UNIT_FLAG_SKINNABLE
) )
4152 return SPELL_FAILED_TARGET_UNSKINNABLE
;
4154 Creature
* creature
= (Creature
*)m_targets
.getUnitTarget();
4155 if ( creature
->GetCreatureType() != CREATURE_TYPE_CRITTER
&& ( !creature
->lootForBody
|| !creature
->loot
.empty() ) )
4157 return SPELL_FAILED_TARGET_NOT_LOOTED
;
4160 uint32 skill
= creature
->GetCreatureInfo()->GetRequiredLootSkill();
4162 int32 skillValue
= ((Player
*)m_caster
)->GetSkillValue(skill
);
4163 int32 TargetLevel
= m_targets
.getUnitTarget()->getLevel();
4164 int32 ReqValue
= (skillValue
< 100 ? (TargetLevel
-10)*10 : TargetLevel
*5);
4165 if (ReqValue
> skillValue
)
4166 return SPELL_FAILED_LOW_CASTLEVEL
;
4168 // chance for fail at orange skinning attempt
4169 if( (m_selfContainer
&& (*m_selfContainer
) == this) &&
4170 skillValue
< sWorld
.GetConfigMaxSkillValue() &&
4171 (ReqValue
< 0 ? 0 : ReqValue
) > irand(skillValue
-25, skillValue
+37) )
4172 return SPELL_FAILED_TRY_AGAIN
;
4176 case SPELL_EFFECT_OPEN_LOCK_ITEM
:
4177 case SPELL_EFFECT_OPEN_LOCK
:
4179 if( m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT
&&
4180 m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT_ITEM
)
4183 if( m_caster
->GetTypeId() != TYPEID_PLAYER
// only players can open locks, gather etc.
4184 // we need a go target in case of TARGET_GAMEOBJECT
4185 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT
&& !m_targets
.getGOTarget()
4186 // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM
4187 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT_ITEM
&& !m_targets
.getGOTarget() &&
4188 (!m_targets
.getItemTarget() || !m_targets
.getItemTarget()->GetProto()->LockID
|| m_targets
.getItemTarget()->GetOwner() != m_caster
) )
4189 return SPELL_FAILED_BAD_TARGETS
;
4191 // In BattleGround players can use only flags and banners
4192 if( ((Player
*)m_caster
)->InBattleGround() &&
4193 !((Player
*)m_caster
)->CanUseBattleGroundObject() )
4194 return SPELL_FAILED_TRY_AGAIN
;
4196 // get the lock entry
4198 if (GameObject
* go
=m_targets
.getGOTarget())
4199 lockId
= go
->GetLockId();
4200 else if(Item
* itm
=m_targets
.getItemTarget())
4201 lockId
= itm
->GetProto()->LockID
;
4203 SkillType skillId
=SKILL_NONE
;
4204 int32 reqSkillValue
= 0;
4205 int32 skillValue
= 0;
4207 // check lock compatibility
4208 SpellCastResult res
= CanOpenLock(i
,lockId
,skillId
,reqSkillValue
,skillValue
);
4209 if(res
!= SPELL_CAST_OK
)
4212 // chance for fail at orange mining/herb/LockPicking gathering attempt
4213 // second check prevent fail at rechecks
4214 if(skillId
!= SKILL_NONE
&& (!m_selfContainer
|| ((*m_selfContainer
) != this)))
4216 bool canFailAtMax
= skillId
!= SKILL_HERBALISM
&& skillId
!= SKILL_MINING
;
4218 // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill)
4219 if((canFailAtMax
|| skillValue
< sWorld
.GetConfigMaxSkillValue()) && reqSkillValue
> irand(skillValue
-25, skillValue
+37))
4220 return SPELL_FAILED_TRY_AGAIN
;
4224 case SPELL_EFFECT_SUMMON_DEAD_PET
:
4226 Creature
*pet
= m_caster
->GetPet();
4228 return SPELL_FAILED_NO_PET
;
4231 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4235 // This is generic summon effect
4236 case SPELL_EFFECT_SUMMON
:
4238 switch(m_spellInfo
->EffectMiscValueB
[i
])
4240 case SUMMON_TYPE_POSESSED
:
4241 case SUMMON_TYPE_POSESSED2
:
4242 case SUMMON_TYPE_DEMON
:
4243 case SUMMON_TYPE_SUMMON
:
4245 if(m_caster
->GetPetGUID())
4246 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4248 if(m_caster
->GetCharmGUID())
4249 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4255 // Not used for summon?
4256 case SPELL_EFFECT_SUMMON_PHANTASM
:
4258 if(m_caster
->GetPetGUID())
4259 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4261 if(m_caster
->GetCharmGUID())
4262 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4266 case SPELL_EFFECT_SUMMON_PET
:
4268 if(m_caster
->GetPetGUID()) //let warlock do a replacement summon
4271 Pet
* pet
= ((Player
*)m_caster
)->GetPet();
4273 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& m_caster
->getClass()==CLASS_WARLOCK
)
4275 if (strict
) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
4276 pet
->CastSpell(pet
, 32752, true, NULL
, NULL
, pet
->GetGUID());
4279 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4282 if(m_caster
->GetCharmGUID())
4283 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4287 case SPELL_EFFECT_SUMMON_PLAYER
:
4289 if(m_caster
->GetTypeId()!=TYPEID_PLAYER
)
4290 return SPELL_FAILED_BAD_TARGETS
;
4291 if(!((Player
*)m_caster
)->GetSelection())
4292 return SPELL_FAILED_BAD_TARGETS
;
4294 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
4295 if( !target
|| ((Player
*)m_caster
)==target
|| !target
->IsInSameRaidWith((Player
*)m_caster
) )
4296 return SPELL_FAILED_BAD_TARGETS
;
4298 // check if our map is dungeon
4299 if( sMapStore
.LookupEntry(m_caster
->GetMapId())->IsDungeon() )
4301 InstanceTemplate
const* instance
= ObjectMgr::GetInstanceTemplate(m_caster
->GetMapId());
4303 return SPELL_FAILED_TARGET_NOT_IN_INSTANCE
;
4304 if ( instance
->levelMin
> target
->getLevel() )
4305 return SPELL_FAILED_LOWLEVEL
;
4306 if ( instance
->levelMax
&& instance
->levelMax
< target
->getLevel() )
4307 return SPELL_FAILED_HIGHLEVEL
;
4311 case SPELL_EFFECT_LEAP
:
4312 case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
:
4314 float dis
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4315 float fx
= m_caster
->GetPositionX() + dis
* cos(m_caster
->GetOrientation());
4316 float fy
= m_caster
->GetPositionY() + dis
* sin(m_caster
->GetOrientation());
4317 // teleport a bit above terrain level to avoid falling below it
4318 float fz
= MapManager::Instance().GetBaseMap(m_caster
->GetMapId())->GetHeight(fx
,fy
,m_caster
->GetPositionZ(),true);
4319 if(fz
<= INVALID_HEIGHT
) // note: this also will prevent use effect in instances without vmaps height enabled
4320 return SPELL_FAILED_TRY_AGAIN
;
4322 float caster_pos_z
= m_caster
->GetPositionZ();
4323 // Control the caster to not climb or drop when +-fz > 8
4324 if(!(fz
<=caster_pos_z
+8 && fz
>=caster_pos_z
-8))
4325 return SPELL_FAILED_TRY_AGAIN
;
4327 // not allow use this effect at battleground until battleground start
4328 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
4329 if(BattleGround
const *bg
= ((Player
*)m_caster
)->GetBattleGround())
4330 if(bg
->GetStatus() != STATUS_IN_PROGRESS
)
4331 return SPELL_FAILED_TRY_AGAIN
;
4334 case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF
:
4336 if (m_targets
.getUnitTarget()==m_caster
)
4337 return SPELL_FAILED_BAD_TARGETS
;
4344 for (int i
= 0; i
< 3; ++i
)
4346 switch(m_spellInfo
->EffectApplyAuraName
[i
])
4348 case SPELL_AURA_DUMMY
:
4351 switch(m_spellInfo
->Id
)
4354 if(m_caster
->GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)m_caster
)->IsInFeralForm())
4355 return SPELL_FAILED_ONLY_SHAPESHIFT
;
4362 case SPELL_AURA_MOD_POSSESS
:
4363 case SPELL_AURA_MOD_CHARM
:
4365 if(m_caster
->GetPetGUID())
4366 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4368 if(m_caster
->GetCharmGUID())
4369 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4371 if(m_caster
->GetCharmerGUID())
4372 return SPELL_FAILED_CHARMED
;
4374 if(!m_targets
.getUnitTarget())
4375 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4377 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4378 return SPELL_FAILED_CHARMED
;
4380 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
4381 return SPELL_FAILED_HIGHLEVEL
;
4385 case SPELL_AURA_MOUNTED
:
4387 if (m_caster
->IsInWater())
4388 return SPELL_FAILED_ONLY_ABOVEWATER
;
4390 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetTransport())
4391 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4393 // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
4394 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& !sMapStore
.LookupEntry(m_caster
->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell
&& !m_spellInfo
->AreaGroupId
)
4395 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4397 ShapeshiftForm form
= m_caster
->m_form
;
4398 if( form
== FORM_CAT
|| form
== FORM_TREE
|| form
== FORM_TRAVEL
||
4399 form
== FORM_AQUA
|| form
== FORM_BEAR
|| form
== FORM_DIREBEAR
||
4400 form
== FORM_CREATUREBEAR
|| form
== FORM_GHOSTWOLF
|| form
== FORM_FLIGHT
||
4401 form
== FORM_FLIGHT_EPIC
|| form
== FORM_MOONKIN
|| form
== FORM_METAMORPHOSIS
)
4402 return SPELL_FAILED_NOT_SHAPESHIFT
;
4406 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
4408 if(!m_targets
.getUnitTarget())
4409 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4411 // can be casted at non-friendly unit or own pet/charm
4412 if(m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()))
4413 return SPELL_FAILED_TARGET_FRIENDLY
;
4417 case SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
:
4418 case SPELL_AURA_FLY
:
4420 // not allow cast fly spells at old maps by players (all spells is self target)
4421 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
4423 if( !((Player
*)m_caster
)->IsAllowUseFlyMountsHere() )
4424 return SPELL_FAILED_NOT_HERE
;
4429 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4431 if (!m_targets
.getUnitTarget())
4432 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4434 if (m_caster
->GetTypeId()!=TYPEID_PLAYER
|| m_CastItem
)
4437 if(m_targets
.getUnitTarget()->getPowerType()!=POWER_MANA
)
4438 return SPELL_FAILED_BAD_TARGETS
;
4448 return SPELL_CAST_OK
;
4451 SpellCastResult
Spell::CheckPetCast(Unit
* target
)
4453 if(!m_caster
->isAlive())
4454 return SPELL_FAILED_CASTER_DEAD
;
4456 if(m_caster
->IsNonMeleeSpellCasted(false)) //prevent spellcast interruption by another spellcast
4457 return SPELL_FAILED_SPELL_IN_PROGRESS
;
4458 if(m_caster
->isInCombat() && IsNonCombatSpell(m_spellInfo
))
4459 return SPELL_FAILED_AFFECTING_COMBAT
;
4461 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)m_caster
)->isPet() || m_caster
->isCharmed()))
4463 //dead owner (pets still alive when owners ressed?)
4464 if(m_caster
->GetCharmerOrOwner() && !m_caster
->GetCharmerOrOwner()->isAlive())
4465 return SPELL_FAILED_CASTER_DEAD
;
4467 if(!target
&& m_targets
.getUnitTarget())
4468 target
= m_targets
.getUnitTarget();
4471 for(uint32 i
= 0;i
<3;++i
)
4473 if(m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND
|| m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_DUELVSPLAYER
|| m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_PARTY
|| m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CURRENT_ENEMY_COORDINATES
)
4477 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4482 m_targets
.setUnitTarget(target
);
4484 Unit
* _target
= m_targets
.getUnitTarget();
4486 if(_target
) //for target dead/target not valid
4488 if(!_target
->isAlive())
4489 return SPELL_FAILED_BAD_TARGETS
;
4491 if(IsPositiveSpell(m_spellInfo
->Id
))
4493 if(m_caster
->IsHostileTo(_target
))
4494 return SPELL_FAILED_BAD_TARGETS
;
4498 bool duelvsplayertar
= false;
4499 for(int j
=0;j
<3;j
++)
4501 //TARGET_DUELVSPLAYER is positive AND negative
4502 duelvsplayertar
|= (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
);
4504 if(m_caster
->IsFriendlyTo(target
) && !duelvsplayertar
)
4506 return SPELL_FAILED_BAD_TARGETS
;
4511 if(((Creature
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
4512 return SPELL_FAILED_NOT_READY
;
4515 return CheckCast(true);
4518 SpellCastResult
Spell::CheckCasterAuras() const
4520 // Flag drop spells totally immuned to caster auras
4521 // FIXME: find more nice check for all totally immuned spells
4522 // AttributesEx3 & 0x10000000?
4523 if(m_spellInfo
->Id
==23336 || m_spellInfo
->Id
==23334 || m_spellInfo
->Id
==34991)
4524 return SPELL_CAST_OK
;
4526 uint8 school_immune
= 0;
4527 uint32 mechanic_immune
= 0;
4528 uint32 dispel_immune
= 0;
4530 //Check if the spell grants school or mechanic immunity.
4531 //We use bitmasks so the loop is done only once and not on every aura check below.
4532 if ( m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
4534 for(int i
= 0;i
< 3; i
++)
4536 if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_SCHOOL_IMMUNITY
)
4537 school_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
4538 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY
)
4539 mechanic_immune
|= 1 << uint32(m_spellInfo
->EffectMiscValue
[i
]);
4540 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_DISPEL_IMMUNITY
)
4541 dispel_immune
|= GetDispellMask(DispelType(m_spellInfo
->EffectMiscValue
[i
]));
4543 //immune movement impairment and loss of control
4544 if(m_spellInfo
->Id
==(uint32
)42292)
4545 mechanic_immune
= IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK
;
4548 //Check whether the cast should be prevented by any state you might have.
4549 SpellCastResult prevented_reason
= SPELL_CAST_OK
;
4550 // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
4551 uint32 unitflag
= m_caster
->GetUInt32Value(UNIT_FIELD_FLAGS
); // Get unit state
4552 if(unitflag
& UNIT_FLAG_STUNNED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4553 prevented_reason
= SPELL_FAILED_STUNNED
;
4554 else if(unitflag
& UNIT_FLAG_CONFUSED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4555 prevented_reason
= SPELL_FAILED_CONFUSED
;
4556 else if(unitflag
& UNIT_FLAG_FLEEING
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4557 prevented_reason
= SPELL_FAILED_FLEEING
;
4558 else if(unitflag
& UNIT_FLAG_SILENCED
&& m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_SILENCE
)
4559 prevented_reason
= SPELL_FAILED_SILENCED
;
4560 else if(unitflag
& UNIT_FLAG_PACIFIED
&& m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_PACIFY
)
4561 prevented_reason
= SPELL_FAILED_PACIFIED
;
4563 // Attr must make flag drop spell totally immune from all effects
4564 if(prevented_reason
!= SPELL_CAST_OK
)
4566 if(school_immune
|| mechanic_immune
|| dispel_immune
)
4568 //Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
4569 Unit::AuraMap
const& auras
= m_caster
->GetAuras();
4570 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
4574 if( GetSpellMechanicMask(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()) & mechanic_immune
)
4576 if( GetSpellSchoolMask(itr
->second
->GetSpellProto()) & school_immune
)
4578 if( (1<<(itr
->second
->GetSpellProto()->Dispel
)) & dispel_immune
)
4581 //Make a second check for spell failed so the right SPELL_FAILED message is returned.
4582 //That is needed when your casting is prevented by multiple states and you are only immune to some of them.
4583 switch(itr
->second
->GetModifier()->m_auraname
)
4585 case SPELL_AURA_MOD_STUN
:
4586 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4587 return SPELL_FAILED_STUNNED
;
4589 case SPELL_AURA_MOD_CONFUSE
:
4590 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4591 return SPELL_FAILED_CONFUSED
;
4593 case SPELL_AURA_MOD_FEAR
:
4594 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4595 return SPELL_FAILED_FLEEING
;
4597 case SPELL_AURA_MOD_SILENCE
:
4598 case SPELL_AURA_MOD_PACIFY
:
4599 case SPELL_AURA_MOD_PACIFY_SILENCE
:
4600 if( m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_PACIFY
)
4601 return SPELL_FAILED_PACIFIED
;
4602 else if ( m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_SILENCE
)
4603 return SPELL_FAILED_SILENCED
;
4609 //You are prevented from casting and the spell casted does not grant immunity. Return a failed error.
4611 return prevented_reason
;
4613 return SPELL_CAST_OK
;
4616 bool Spell::CanAutoCast(Unit
* target
)
4618 uint64 targetguid
= target
->GetGUID();
4620 for(uint32 j
= 0;j
<3;j
++)
4622 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
)
4624 if( m_spellInfo
->StackAmount
<= 1)
4626 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4631 if( target
->GetAuras().count(Unit::spellEffectPair(m_spellInfo
->Id
, j
)) >= m_spellInfo
->StackAmount
)
4635 else if ( IsAreaAuraEffect( m_spellInfo
->Effect
[j
] ))
4637 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4642 SpellCastResult result
= CheckPetCast(target
);
4644 if(result
== SPELL_CAST_OK
|| result
== SPELL_FAILED_UNIT_NOT_INFRONT
)
4647 //check if among target units, our WANTED target is as well (->only self cast spells return false)
4648 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
4649 if( ihit
->targetGUID
== targetguid
)
4652 return false; //target invalid
4655 SpellCastResult
Spell::CheckRange(bool strict
)
4659 // self cast doesn't need range checking -- also for Starshards fix
4660 if (m_spellInfo
->rangeIndex
== 1)
4661 return SPELL_CAST_OK
;
4663 if (strict
) //add radius of caster
4665 else //add radius of caster and ~5 yds "give"
4668 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4669 float max_range
= GetSpellMaxRange(srange
) + range_mod
;
4670 float min_range
= GetSpellMinRange(srange
);
4672 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4673 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RANGE
, max_range
, this);
4675 Unit
*target
= m_targets
.getUnitTarget();
4677 if(target
&& target
!= m_caster
)
4679 // distance from target in checks
4680 float dist
= m_caster
->GetCombatDistance(target
);
4682 if(dist
> max_range
)
4683 return SPELL_FAILED_OUT_OF_RANGE
; //0x5A;
4684 if(dist
< min_range
)
4685 return SPELL_FAILED_TOO_CLOSE
;
4686 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&&
4687 (m_spellInfo
->FacingCasterFlags
& SPELL_FACING_FLAG_INFRONT
) && !m_caster
->HasInArc( M_PI
, target
) )
4688 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4691 if(m_targets
.m_targetMask
== TARGET_FLAG_DEST_LOCATION
&& m_targets
.m_destX
!= 0 && m_targets
.m_destY
!= 0 && m_targets
.m_destZ
!= 0)
4693 if(!m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
,max_range
))
4694 return SPELL_FAILED_OUT_OF_RANGE
;
4695 if(m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
,min_range
))
4696 return SPELL_FAILED_TOO_CLOSE
;
4699 return SPELL_CAST_OK
;
4702 int32
Spell::CalculatePowerCost()
4704 // item cast not used power
4708 // Spell drain all exist power on cast (Only paladin lay of Hands)
4709 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DRAIN_ALL_POWER
)
4711 // If power type - health drain all
4712 if (m_spellInfo
->powerType
== POWER_HEALTH
)
4713 return m_caster
->GetHealth();
4714 // Else drain all power
4715 if (m_spellInfo
->powerType
< MAX_POWERS
)
4716 return m_caster
->GetPower(Powers(m_spellInfo
->powerType
));
4717 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4722 int32 powerCost
= m_spellInfo
->manaCost
;
4723 // PCT cost from total amount
4724 if (m_spellInfo
->ManaCostPercentage
)
4726 switch (m_spellInfo
->powerType
)
4728 // health as power used
4730 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateHealth() / 100;
4733 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateMana() / 100;
4738 case POWER_HAPPINESS
:
4739 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetMaxPower(Powers(m_spellInfo
->powerType
)) / 100;
4742 case POWER_RUNIC_POWER
:
4743 sLog
.outDebug("Spell::CalculateManaCost: Not implemented yet!");
4746 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4750 SpellSchools school
= GetFirstSchoolInMask(m_spellSchoolMask
);
4751 // Flat mod from caster auras by spell school
4752 powerCost
+= m_caster
->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER
+ school
);
4753 // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
4754 if ( m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST
)
4755 powerCost
+= m_caster
->GetAttackTime(OFF_ATTACK
)/100;
4756 // Apply cost mod by spell
4757 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4758 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, powerCost
, this);
4760 if(m_spellInfo
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
)
4761 powerCost
= int32(powerCost
/ (1.117f
* m_spellInfo
->spellLevel
/ m_caster
->getLevel() -0.1327f
));
4763 // PCT mod from user auras by school
4764 powerCost
= int32(powerCost
* (1.0f
+m_caster
->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+school
)));
4770 SpellCastResult
Spell::CheckPower()
4772 // item cast not used power
4774 return SPELL_CAST_OK
;
4776 // health as power used - need check health amount
4777 if(m_spellInfo
->powerType
== POWER_HEALTH
)
4779 if(m_caster
->GetHealth() <= m_powerCost
)
4780 return SPELL_FAILED_CASTER_AURASTATE
;
4781 return SPELL_CAST_OK
;
4783 // Check valid power type
4784 if( m_spellInfo
->powerType
>= MAX_POWERS
)
4786 sLog
.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo
->powerType
);
4787 return SPELL_FAILED_UNKNOWN
;
4790 SpellCastResult failReason
= CheckRuneCost(m_spellInfo
->runeCostID
);
4791 if(failReason
!= SPELL_CAST_OK
)
4794 // Check power amount
4795 Powers powerType
= Powers(m_spellInfo
->powerType
);
4796 if(m_caster
->GetPower(powerType
) < m_powerCost
)
4797 return SPELL_FAILED_NO_POWER
;
4799 return SPELL_CAST_OK
;
4802 SpellCastResult
Spell::CheckItems()
4804 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4805 return SPELL_CAST_OK
;
4807 Player
* p_caster
= (Player
*)m_caster
;
4812 uint32 itemid
= m_CastItem
->GetEntry();
4813 if( !p_caster
->HasItemCount(itemid
,1) )
4814 return SPELL_FAILED_ITEM_NOT_READY
;
4816 ItemPrototype
const *proto
= m_CastItem
->GetProto();
4818 return SPELL_FAILED_ITEM_NOT_READY
;
4820 for (int i
= 0; i
<5; ++i
)
4821 if (proto
->Spells
[i
].SpellCharges
)
4822 if(m_CastItem
->GetSpellCharges(i
)==0)
4823 return SPELL_FAILED_NO_CHARGES_REMAIN
;
4825 // consumable cast item checks
4826 if (proto
->Class
== ITEM_CLASS_CONSUMABLE
&& m_targets
.getUnitTarget())
4828 // such items should only fail if there is no suitable effect at all - see Rejuvenation Potions for example
4829 SpellCastResult failReason
= SPELL_CAST_OK
;
4830 for (int i
= 0; i
< 3; ++i
)
4832 // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster
4833 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_PET
)
4836 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_HEAL
)
4838 if (m_targets
.getUnitTarget()->GetHealth() == m_targets
.getUnitTarget()->GetMaxHealth())
4840 failReason
= SPELL_FAILED_ALREADY_AT_FULL_HEALTH
;
4845 failReason
= SPELL_CAST_OK
;
4850 // Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
4851 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
4853 if(m_spellInfo
->EffectMiscValue
[i
] < 0 || m_spellInfo
->EffectMiscValue
[i
] >= MAX_POWERS
)
4855 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
4859 Powers power
= Powers(m_spellInfo
->EffectMiscValue
[i
]);
4860 if (m_targets
.getUnitTarget()->GetPower(power
) == m_targets
.getUnitTarget()->GetMaxPower(power
))
4862 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
4867 failReason
= SPELL_CAST_OK
;
4872 if (failReason
!= SPELL_CAST_OK
)
4877 // check target item
4878 if(m_targets
.getItemTargetGUID())
4880 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4881 return SPELL_FAILED_BAD_TARGETS
;
4883 if(!m_targets
.getItemTarget())
4884 return SPELL_FAILED_ITEM_GONE
;
4886 if(!m_targets
.getItemTarget()->IsFitToSpellRequirements(m_spellInfo
))
4887 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
4889 // if not item target then required item must be equipped
4892 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !((Player
*)m_caster
)->HasItemFitToSpellReqirements(m_spellInfo
))
4893 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
4896 // check spell focus object
4897 if(m_spellInfo
->RequiresSpellFocus
)
4899 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4901 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4903 GameObject
* ok
= NULL
;
4904 MaNGOS::GameObjectFocusCheck
go_check(m_caster
,m_spellInfo
->RequiresSpellFocus
);
4905 MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
> checker(m_caster
,ok
,go_check
);
4907 TypeContainerVisitor
<MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
>, GridTypeMapContainer
> object_checker(checker
);
4908 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4909 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
4912 return SPELL_FAILED_REQUIRES_SPELL_FOCUS
;
4914 focusObject
= ok
; // game object found in range
4917 // check reagents (ignore triggered spells with reagents processed by original spell) and special reagent ignore case.
4918 if (!m_IsTriggeredSpell
&& !p_caster
->CanNoReagentCast(m_spellInfo
))
4920 for(uint32 i
=0;i
<8;++i
)
4922 if(m_spellInfo
->Reagent
[i
] <= 0)
4925 uint32 itemid
= m_spellInfo
->Reagent
[i
];
4926 uint32 itemcount
= m_spellInfo
->ReagentCount
[i
];
4928 // if CastItem is also spell reagent
4929 if( m_CastItem
&& m_CastItem
->GetEntry() == itemid
)
4931 ItemPrototype
const *proto
= m_CastItem
->GetProto();
4933 return SPELL_FAILED_ITEM_NOT_READY
;
4934 for(int s
=0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
4936 // CastItem will be used up and does not count as reagent
4937 int32 charges
= m_CastItem
->GetSpellCharges(s
);
4938 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
4945 if( !p_caster
->HasItemCount(itemid
,itemcount
) )
4946 return SPELL_FAILED_ITEM_NOT_READY
; //0x54
4950 // check totem-item requirements (items presence in inventory)
4952 for(int i
=0;i
<2;++i
)
4954 if(m_spellInfo
->Totem
[i
] != 0)
4956 if( p_caster
->HasItemCount(m_spellInfo
->Totem
[i
],1) )
4965 return SPELL_FAILED_TOTEMS
; //0x7C
4967 // Check items for TotemCategory (items presence in inventory)
4968 uint32 TotemCategory
= 2;
4969 for(int i
=0;i
<2;++i
)
4971 if(m_spellInfo
->TotemCategory
[i
] != 0)
4973 if( p_caster
->HasItemTotemCategory(m_spellInfo
->TotemCategory
[i
]) )
4982 if(TotemCategory
!= 0)
4983 return SPELL_FAILED_TOTEM_CATEGORY
; //0x7B
4985 // special checks for spell effects
4986 for(int i
= 0; i
< 3; ++i
)
4988 switch (m_spellInfo
->Effect
[i
])
4990 case SPELL_EFFECT_CREATE_ITEM
:
4992 if (!m_IsTriggeredSpell
&& m_spellInfo
->EffectItemType
[i
])
4994 ItemPosCountVec dest
;
4995 uint8 msg
= p_caster
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, m_spellInfo
->EffectItemType
[i
], 1 );
4996 if (msg
!= EQUIP_ERR_OK
)
4998 p_caster
->SendEquipError( msg
, NULL
, NULL
);
4999 return SPELL_FAILED_DONT_REPORT
;
5004 case SPELL_EFFECT_ENCHANT_ITEM
:
5005 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
5007 Item
* targetItem
= m_targets
.getItemTarget();
5009 return SPELL_FAILED_ITEM_NOT_FOUND
;
5011 if( targetItem
->GetProto()->ItemLevel
< m_spellInfo
->baseLevel
)
5012 return SPELL_FAILED_LOWLEVEL
;
5013 // Not allow enchant in trade slot for some enchant type
5014 if( targetItem
->GetOwner() != m_caster
)
5016 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5017 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5019 return SPELL_FAILED_ERROR
;
5020 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5021 return SPELL_FAILED_NOT_TRADEABLE
;
5025 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
5027 Item
*item
= m_targets
.getItemTarget();
5029 return SPELL_FAILED_ITEM_NOT_FOUND
;
5030 // Not allow enchant in trade slot for some enchant type
5031 if( item
->GetOwner() != m_caster
)
5033 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5034 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5036 return SPELL_FAILED_ERROR
;
5037 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5038 return SPELL_FAILED_NOT_TRADEABLE
;
5042 case SPELL_EFFECT_ENCHANT_HELD_ITEM
:
5043 // check item existence in effect code (not output errors at offhand hold item effect to main hand for example
5045 case SPELL_EFFECT_DISENCHANT
:
5047 if(!m_targets
.getItemTarget())
5048 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5050 // prevent disenchanting in trade slot
5051 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5052 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5054 ItemPrototype
const* itemProto
= m_targets
.getItemTarget()->GetProto();
5056 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5058 uint32 item_quality
= itemProto
->Quality
;
5059 // 2.0.x addon: Check player enchanting level against the item disenchanting requirements
5060 uint32 item_disenchantskilllevel
= itemProto
->RequiredDisenchantSkill
;
5061 if (item_disenchantskilllevel
== uint32(-1))
5062 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5063 if (item_disenchantskilllevel
> p_caster
->GetSkillValue(SKILL_ENCHANTING
))
5064 return SPELL_FAILED_LOW_CASTLEVEL
;
5065 if(item_quality
> 4 || item_quality
< 2)
5066 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5067 if(itemProto
->Class
!= ITEM_CLASS_WEAPON
&& itemProto
->Class
!= ITEM_CLASS_ARMOR
)
5068 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5069 if (!itemProto
->DisenchantID
)
5070 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5073 case SPELL_EFFECT_PROSPECTING
:
5075 if(!m_targets
.getItemTarget())
5076 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5077 //ensure item is a prospectable ore
5078 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_MINING_SUPP
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5079 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5080 //prevent prospecting in trade slot
5081 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5082 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5083 //Check for enough skill in jewelcrafting
5084 uint32 item_prospectingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5085 if(item_prospectingskilllevel
>p_caster
->GetSkillValue(SKILL_JEWELCRAFTING
))
5086 return SPELL_FAILED_LOW_CASTLEVEL
;
5087 //make sure the player has the required ores in inventory
5088 if(m_targets
.getItemTarget()->GetCount() < 5)
5089 return SPELL_FAILED_NEED_MORE_ITEMS
;
5091 if(!LootTemplates_Prospecting
.HaveLootFor(m_targets
.getItemTargetEntry()))
5092 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5096 case SPELL_EFFECT_MILLING
:
5098 if(!m_targets
.getItemTarget())
5099 return SPELL_FAILED_CANT_BE_MILLED
;
5100 //ensure item is a millable herb
5101 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_HERBS
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5102 return SPELL_FAILED_CANT_BE_MILLED
;
5103 //prevent milling in trade slot
5104 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5105 return SPELL_FAILED_CANT_BE_MILLED
;
5106 //Check for enough skill in inscription
5107 uint32 item_millingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5108 if(item_millingskilllevel
>p_caster
->GetSkillValue(SKILL_INSCRIPTION
))
5109 return SPELL_FAILED_LOW_CASTLEVEL
;
5110 //make sure the player has the required herbs in inventory
5111 if(m_targets
.getItemTarget()->GetCount() < 5)
5112 return SPELL_FAILED_NEED_MORE_ITEMS
;
5114 if(!LootTemplates_Milling
.HaveLootFor(m_targets
.getItemTargetEntry()))
5115 return SPELL_FAILED_CANT_BE_MILLED
;
5119 case SPELL_EFFECT_WEAPON_DAMAGE
:
5120 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
:
5122 if(m_caster
->GetTypeId() != TYPEID_PLAYER
) return SPELL_FAILED_TARGET_NOT_PLAYER
;
5123 if( m_attackType
!= RANGED_ATTACK
)
5125 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(m_attackType
);
5126 if(!pItem
|| pItem
->IsBroken())
5127 return SPELL_FAILED_EQUIPPED_ITEM
;
5129 switch(pItem
->GetProto()->SubClass
)
5131 case ITEM_SUBCLASS_WEAPON_THROWN
:
5133 uint32 ammo
= pItem
->GetEntry();
5134 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5135 return SPELL_FAILED_NO_AMMO
;
5137 case ITEM_SUBCLASS_WEAPON_GUN
:
5138 case ITEM_SUBCLASS_WEAPON_BOW
:
5139 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5141 uint32 ammo
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
5145 if(m_caster
->GetDummyAura(46699))
5146 break; // skip other checks
5148 return SPELL_FAILED_NO_AMMO
;
5151 ItemPrototype
const *ammoProto
= objmgr
.GetItemPrototype( ammo
);
5153 return SPELL_FAILED_NO_AMMO
;
5155 if(ammoProto
->Class
!= ITEM_CLASS_PROJECTILE
)
5156 return SPELL_FAILED_NO_AMMO
;
5158 // check ammo ws. weapon compatibility
5159 switch(pItem
->GetProto()->SubClass
)
5161 case ITEM_SUBCLASS_WEAPON_BOW
:
5162 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5163 if(ammoProto
->SubClass
!=ITEM_SUBCLASS_ARROW
)
5164 return SPELL_FAILED_NO_AMMO
;
5166 case ITEM_SUBCLASS_WEAPON_GUN
:
5167 if(ammoProto
->SubClass
!=ITEM_SUBCLASS_BULLET
)
5168 return SPELL_FAILED_NO_AMMO
;
5171 return SPELL_FAILED_NO_AMMO
;
5174 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5175 return SPELL_FAILED_NO_AMMO
;
5177 case ITEM_SUBCLASS_WEAPON_WAND
:
5187 return SPELL_CAST_OK
;
5190 void Spell::Delayed()
5192 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
5195 if (m_spellState
== SPELL_STATE_DELAYED
)
5196 return; // spell is active and can't be time-backed
5198 if(isDelayableNoMore()) // Spells may only be delayed twice
5201 // spells not loosing casting time ( slam, dynamites, bombs.. )
5202 if(!(m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_DAMAGE
))
5205 //check pushback reduce
5206 int32 delaytime
= 500; // spellcasting delay is normally 500ms
5207 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5208 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
,SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5209 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5210 if(delayReduce
>= 100)
5213 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5215 if(int32(m_timer
) + delaytime
> m_casttime
)
5217 delaytime
= m_casttime
- m_timer
;
5218 m_timer
= m_casttime
;
5221 m_timer
+= delaytime
;
5223 sLog
.outDetail("Spell %u partially interrupted for (%d) ms at damage",m_spellInfo
->Id
,delaytime
);
5225 WorldPacket
data(SMSG_SPELL_DELAYED
, 8+4);
5226 data
.append(m_caster
->GetPackGUID());
5227 data
<< uint32(delaytime
);
5229 m_caster
->SendMessageToSet(&data
,true);
5232 void Spell::DelayedChannel()
5234 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
|| getState() != SPELL_STATE_CASTING
)
5237 if(isDelayableNoMore()) // Spells may only be delayed twice
5240 //check pushback reduce
5241 int32 delaytime
= GetSpellDuration(m_spellInfo
) * 25 / 100; // channeling delay is normally 25% of its time per hit
5242 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5243 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
,SPELLMOD_NOT_LOSE_CASTING_TIME
,delayReduce
, this);
5244 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5245 if(delayReduce
>= 100)
5248 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5250 if(int32(m_timer
) < delaytime
)
5252 delaytime
= m_timer
;
5256 m_timer
-= delaytime
;
5258 sLog
.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo
->Id
, delaytime
, m_timer
);
5260 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
5262 if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
5264 Unit
* unit
= m_caster
->GetGUID()==ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
5267 for (int j
=0;j
<3;j
++)
5268 if( ihit
->effectMask
& (1<<j
) )
5269 unit
->DelayAura(m_spellInfo
->Id
, j
, delaytime
);
5275 for(int j
= 0; j
< 3; j
++)
5277 // partially interrupt persistent area auras
5278 DynamicObject
* dynObj
= m_caster
->GetDynObject(m_spellInfo
->Id
, j
);
5280 dynObj
->Delay(delaytime
);
5283 SendChannelUpdate(m_timer
);
5286 void Spell::UpdatePointers()
5288 if(m_originalCasterGUID
==m_caster
->GetGUID())
5289 m_originalCaster
= m_caster
;
5292 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
,m_originalCasterGUID
);
5293 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
5296 m_targets
.Update(m_caster
);
5299 bool Spell::IsAffectedByAura(Aura
*aura
)
5301 return spellmgr
.IsAffectedByMod(m_spellInfo
, aura
->getAuraSpellMod());
5304 bool Spell::CheckTargetCreatureType(Unit
* target
) const
5306 uint32 spellCreatureTargetMask
= m_spellInfo
->TargetCreatureType
;
5308 // Curse of Doom : not find another way to fix spell target check :/
5309 if(m_spellInfo
->SpellFamilyName
==SPELLFAMILY_WARLOCK
&& m_spellInfo
->SpellFamilyFlags
== 0x0200000000LL
)
5311 // not allow cast at player
5312 if(target
->GetTypeId()==TYPEID_PLAYER
)
5315 spellCreatureTargetMask
= 0x7FF;
5318 // Dismiss Pet and Taming Lesson skipped
5319 if(m_spellInfo
->Id
== 2641 || m_spellInfo
->Id
== 23356)
5320 spellCreatureTargetMask
= 0;
5322 if (spellCreatureTargetMask
)
5324 uint32 TargetCreatureType
= target
->GetCreatureTypeMask();
5326 return !TargetCreatureType
|| (spellCreatureTargetMask
& TargetCreatureType
);
5331 CurrentSpellTypes
Spell::GetCurrentContainer()
5333 if (IsNextMeleeSwingSpell())
5334 return(CURRENT_MELEE_SPELL
);
5335 else if (IsAutoRepeat())
5336 return(CURRENT_AUTOREPEAT_SPELL
);
5337 else if (IsChanneledSpell(m_spellInfo
))
5338 return(CURRENT_CHANNELED_SPELL
);
5340 return(CURRENT_GENERIC_SPELL
);
5343 bool Spell::CheckTarget( Unit
* target
, uint32 eff
)
5345 // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets)
5346 if(m_spellInfo
->EffectImplicitTargetA
[eff
]!=TARGET_SELF
)
5348 if (!CheckTargetCreatureType(target
))
5352 // Check Aura spell req (need for AoE spells)
5353 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
5355 if (m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
5358 // Check targets for not_selectable unit flag and remove
5359 // A player can cast spells on his pet (or other controlled unit) though in any state
5360 if (target
!= m_caster
&& target
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
5362 // any unattackable target skipped
5363 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
))
5366 // unselectable targets skipped in all cases except TARGET_SCRIPT targeting
5367 // in case TARGET_SCRIPT target selected by server always and can't be cheated
5368 if( target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NOT_SELECTABLE
) &&
5369 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SCRIPT
&&
5370 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_SCRIPT
)
5374 //Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
5375 if( target
!= m_caster
&& target
->GetTypeId()==TYPEID_PLAYER
)
5377 if(((Player
*)target
)->GetVisibility()==VISIBILITY_OFF
)
5380 if(((Player
*)target
)->isGameMaster() && !IsPositiveSpell(m_spellInfo
->Id
))
5384 //Check targets for LOS visibility (except spells without range limitations )
5385 switch(m_spellInfo
->Effect
[eff
])
5387 case SPELL_EFFECT_SUMMON_PLAYER
: // from anywhere
5389 case SPELL_EFFECT_DUMMY
:
5390 if(m_spellInfo
->Id
!=20577) // Cannibalize
5393 case SPELL_EFFECT_RESURRECT_NEW
:
5394 // player far away, maybe his corpse near?
5395 if(target
!=m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
5397 if(!m_targets
.getCorpseTargetGUID())
5400 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
5404 if(target
->GetGUID()!=corpse
->GetOwnerGUID())
5407 if(!corpse
->IsWithinLOSInMap(m_caster
))
5411 // all ok by some way or another, skip normal check
5413 default: // normal case
5414 // Get GO cast coordinates if original caster -> GO
5415 WorldObject
*caster
= NULL
;
5416 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
5417 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
5420 if(target
!=m_caster
&& !target
->IsWithinLOSInMap(caster
))
5428 bool Spell::IsNeedSendToClient() const
5430 return m_spellInfo
->SpellVisual
[0] || m_spellInfo
->SpellVisual
[1] || IsChanneledSpell(m_spellInfo
) ||
5431 m_spellInfo
->speed
> 0.0f
|| !m_triggeredByAuraSpell
&& !m_IsTriggeredSpell
;
5434 bool Spell::HaveTargetsForEffect( uint8 effect
) const
5436 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin();itr
!= m_UniqueTargetInfo
.end();++itr
)
5437 if(itr
->effectMask
& (1<<effect
))
5440 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin();itr
!= m_UniqueGOTargetInfo
.end();++itr
)
5441 if(itr
->effectMask
& (1<<effect
))
5444 for(std::list
<ItemTargetInfo
>::const_iterator itr
= m_UniqueItemInfo
.begin();itr
!= m_UniqueItemInfo
.end();++itr
)
5445 if(itr
->effectMask
& (1<<effect
))
5451 SpellEvent::SpellEvent(Spell
* spell
) : BasicEvent()
5456 SpellEvent::~SpellEvent()
5458 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5461 if (m_Spell
->IsDeletable())
5467 sLog
.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
5468 (m_Spell
->GetCaster()->GetTypeId()==TYPEID_PLAYER
?"Player":"Creature"), m_Spell
->GetCaster()->GetGUIDLow(),m_Spell
->m_spellInfo
->Id
);
5472 bool SpellEvent::Execute(uint64 e_time
, uint32 p_time
)
5474 // update spell if it is not finished
5475 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5476 m_Spell
->update(p_time
);
5478 // check spell state to process
5479 switch (m_Spell
->getState())
5481 case SPELL_STATE_FINISHED
:
5483 // spell was finished, check deletable state
5484 if (m_Spell
->IsDeletable())
5486 // check, if we do have unfinished triggered spells
5488 return(true); // spell is deletable, finish event
5490 // event will be re-added automatically at the end of routine)
5493 case SPELL_STATE_CASTING
:
5495 // this spell is in channeled state, process it on the next update
5496 // event will be re-added automatically at the end of routine)
5499 case SPELL_STATE_DELAYED
:
5501 // first, check, if we have just started
5502 if (m_Spell
->GetDelayStart() != 0)
5504 // no, we aren't, do the typical update
5505 // check, if we have channeled spell on our hands
5506 if (IsChanneledSpell(m_Spell
->m_spellInfo
))
5508 // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish
5509 // check, if we have casting anything else except this channeled spell and autorepeat
5510 if (m_Spell
->GetCaster()->IsNonMeleeSpellCasted(false, true, true))
5512 // another non-melee non-delayed spell is casted now, abort
5517 // do the action (pass spell to channeling state)
5518 m_Spell
->handle_immediate();
5520 // event will be re-added automatically at the end of routine)
5524 // run the spell handler and think about what we can do next
5525 uint64 t_offset
= e_time
- m_Spell
->GetDelayStart();
5526 uint64 n_offset
= m_Spell
->handle_delayed(t_offset
);
5529 // re-add us to the queue
5530 m_Spell
->GetCaster()->m_Events
.AddEvent(this, m_Spell
->GetDelayStart() + n_offset
, false);
5531 return(false); // event not complete
5534 // finish update event will be re-added automatically at the end of routine)
5539 // delaying had just started, record the moment
5540 m_Spell
->SetDelayStart(e_time
);
5541 // re-plan the event for the delay moment
5542 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ m_Spell
->GetDelayMoment(), false);
5543 return(false); // event not complete
5550 // event will be re-added automatically at the end of routine)
5554 // spell processing not complete, plan event on the next update interval
5555 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ 1, false);
5556 return(false); // event not complete
5559 void SpellEvent::Abort(uint64
/*e_time*/)
5561 // oops, the spell we try to do is aborted
5562 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5566 bool SpellEvent::IsDeletable() const
5568 return m_Spell
->IsDeletable();
5571 SpellCastResult
Spell::CanOpenLock(uint32 effIndex
, uint32 lockId
, SkillType
& skillId
, int32
& reqSkillValue
, int32
& skillValue
)
5573 if(!lockId
) // possible case for GO and maybe for items.
5574 return SPELL_CAST_OK
;
5577 LockEntry
const *lockInfo
= sLockStore
.LookupEntry(lockId
);
5580 return SPELL_FAILED_BAD_TARGETS
;
5582 bool reqKey
= false; // some locks not have reqs
5584 for(int j
= 0; j
< 8; ++j
)
5586 switch(lockInfo
->Type
[j
])
5588 // check key item (many fit cases can be)
5590 if(lockInfo
->Index
[j
] && m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->Index
[j
])
5591 return SPELL_CAST_OK
;
5594 // check key skill (only single first fit case can be)
5595 case LOCK_KEY_SKILL
:
5599 // wrong locktype, skip
5600 if(uint32(m_spellInfo
->EffectMiscValue
[effIndex
]) != lockInfo
->Index
[j
])
5603 skillId
= SkillByLockType(LockType(lockInfo
->Index
[j
]));
5605 if ( skillId
!= SKILL_NONE
)
5607 // skill bonus provided by casting spell (mostly item spells)
5608 // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value)
5609 uint32 spellSkillBonus
= uint32(m_currentBasePoints
[effIndex
]+1);
5610 reqSkillValue
= lockInfo
->Skill
[j
];
5612 // castitem check: rogue using skeleton keys. the skill values should not be added in this case.
5613 skillValue
= m_CastItem
|| m_caster
->GetTypeId()!= TYPEID_PLAYER
?
5614 0 : ((Player
*)m_caster
)->GetSkillValue(skillId
);
5616 skillValue
+= spellSkillBonus
;
5618 if (skillValue
< reqSkillValue
)
5619 return SPELL_FAILED_LOW_CASTLEVEL
;
5622 return SPELL_CAST_OK
;
5628 return SPELL_FAILED_BAD_TARGETS
;
5630 return SPELL_CAST_OK
;
5633 void Spell::FillAreaTargets( UnitList
& TagUnitMap
, float x
, float y
, float radius
, SpellNotifyPushType pushType
, SpellTargets spellTargets
)
5635 CellPair
p(MaNGOS::ComputeCellPair(x
, y
));
5637 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5639 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, pushType
, spellTargets
);
5640 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
5641 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
5642 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5643 cell_lock
->Visit(cell_lock
, world_notifier
, *m_caster
->GetMap());
5644 cell_lock
->Visit(cell_lock
, grid_notifier
, *m_caster
->GetMap());