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
);
2421 SendSpellCooldown();
2424 TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
2427 if(m_spellState
== SPELL_STATE_FINISHED
) // stop cast if spell marked as finish somewhere in Take*/FillTargetMap
2429 SetExecutedCurrently(false);
2433 SendCastResult(castResult
);
2434 SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2436 // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2437 if (m_spellInfo
->speed
> 0.0f
)
2440 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2441 // in case delayed spell remove item at cast delay start
2444 // Okay, maps created, now prepare flags
2445 m_immediateHandled
= false;
2446 m_spellState
= SPELL_STATE_DELAYED
;
2451 // Immediate spell, no big deal
2455 SetExecutedCurrently(false);
2458 void Spell::handle_immediate()
2460 // start channeling if applicable
2461 if(IsChanneledSpell(m_spellInfo
))
2463 int32 duration
= GetSpellDuration(m_spellInfo
);
2466 // Apply duration mod
2467 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
2468 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_DURATION
, duration
);
2469 m_spellState
= SPELL_STATE_CASTING
;
2470 SendChannelStart(duration
);
2474 // process immediate effects (items, ground, etc.) also initialize some variables
2475 _handle_immediate_phase();
2477 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2478 DoAllEffectOnTarget(&(*ihit
));
2480 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2481 DoAllEffectOnTarget(&(*ihit
));
2483 // spell is finished, perform some last features of the spell here
2484 _handle_finish_phase();
2486 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2489 if(m_spellState
!= SPELL_STATE_CASTING
)
2490 finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell)
2493 uint64
Spell::handle_delayed(uint64 t_offset
)
2495 uint64 next_time
= 0;
2497 if (!m_immediateHandled
)
2499 _handle_immediate_phase();
2500 m_immediateHandled
= true;
2503 // 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)
2504 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2506 if (ihit
->processed
== false)
2508 if ( ihit
->timeDelay
<= t_offset
)
2509 DoAllEffectOnTarget(&(*ihit
));
2510 else if( next_time
== 0 || ihit
->timeDelay
< next_time
)
2511 next_time
= ihit
->timeDelay
;
2515 // now recheck gameobject targeting correctness
2516 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
2518 if (ighit
->processed
== false)
2520 if ( ighit
->timeDelay
<= t_offset
)
2521 DoAllEffectOnTarget(&(*ighit
));
2522 else if( next_time
== 0 || ighit
->timeDelay
< next_time
)
2523 next_time
= ighit
->timeDelay
;
2526 // All targets passed - need finish phase
2529 // spell is finished, perform some last features of the spell here
2530 _handle_finish_phase();
2532 finish(true); // successfully finish spell cast
2534 // return zero, spell is finished now
2539 // spell is unfinished, return next execution time
2544 void Spell::_handle_immediate_phase()
2546 // handle some immediate features of the spell here
2547 HandleThreatSpells(m_spellInfo
->Id
);
2549 m_needSpellLog
= IsNeedSendToClient();
2550 for(uint32 j
= 0;j
<3;j
++)
2552 if(m_spellInfo
->Effect
[j
]==0)
2555 // apply Send Event effect to ground in case empty target lists
2556 if( m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
&& !HaveTargetsForEffect(j
) )
2558 HandleEffects(NULL
,NULL
,NULL
, j
);
2562 // Don't do spell log, if is school damage spell
2563 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
|| m_spellInfo
->Effect
[j
] == 0)
2564 m_needSpellLog
= false;
2566 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[j
];
2567 if(m_originalCaster
)
2568 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
2569 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
2571 // initialize multipliers
2572 m_damageMultipliers
[j
] = 1.0f
;
2573 if( (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_HEAL
) &&
2574 (EffectChainTarget
> 1) )
2575 m_applyMultiplierMask
|= 1 << j
;
2578 // initialize Diminishing Returns Data
2579 m_diminishLevel
= DIMINISHING_LEVEL_1
;
2580 m_diminishGroup
= DIMINISHING_NONE
;
2583 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
2584 DoAllEffectOnTarget(&(*ihit
));
2587 for(uint32 j
= 0;j
<3;j
++)
2589 // persistent area auras target only the ground
2590 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2591 HandleEffects(NULL
,NULL
,NULL
, j
);
2595 void Spell::_handle_finish_phase()
2602 void Spell::SendSpellCooldown()
2604 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
2607 Player
* _player
= (Player
*)m_caster
;
2609 // mana/health/etc potions, disabled by client (until combat out as declarate)
2610 if (m_CastItem
&& m_CastItem
->IsPotion())
2612 // need in some way provided data for Spell::finish SendCooldownEvent
2613 _player
->SetLastPotionId(m_CastItem
->GetEntry());
2617 // have infinity cooldown but set at aura apply
2618 if(m_spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
2621 _player
->AddSpellAndCategoryCooldowns(m_spellInfo
,m_CastItem
? m_CastItem
->GetEntry() : 0, this);
2624 void Spell::update(uint32 difftime
)
2626 // update pointers based at it's GUIDs
2629 if(m_targets
.getUnitTargetGUID() && !m_targets
.getUnitTarget())
2635 // check if the player caster has moved before the spell finished
2636 if ((m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_timer
!= 0) &&
2637 (m_castPositionX
!= m_caster
->GetPositionX() || m_castPositionY
!= m_caster
->GetPositionY() || m_castPositionZ
!= m_caster
->GetPositionZ()) &&
2638 (m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
|| !m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_FALLING
)))
2640 // always cancel for channeled spells
2641 if( m_spellState
== SPELL_STATE_CASTING
)
2643 // don't cancel for melee, autorepeat, triggered and instant spells
2644 else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_MOVEMENT
))
2648 switch(m_spellState
)
2650 case SPELL_STATE_PREPARING
:
2654 if(difftime
>= m_timer
)
2657 m_timer
-= difftime
;
2660 if(m_timer
== 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat())
2663 case SPELL_STATE_CASTING
:
2667 if( m_caster
->GetTypeId() == TYPEID_PLAYER
)
2669 // check if player has jumped before the channeling finished
2670 if(m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_JUMPING
))
2673 // check for incapacitating player states
2674 if( m_caster
->hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_CONFUSED
))
2677 // check if player has turned if flag is set
2678 if( m_spellInfo
->ChannelInterruptFlags
& CHANNEL_FLAG_TURNING
&& m_castOrientation
!= m_caster
->GetOrientation() )
2682 // check if there are alive targets left
2683 if (!IsAliveUnitPresentInTargetList())
2685 SendChannelUpdate(0);
2689 if(difftime
>= m_timer
)
2692 m_timer
-= difftime
;
2697 SendChannelUpdate(0);
2699 // channeled spell processed independently for quest targeting
2700 // cast at creature (or GO) quest objectives update at successful cast channel finished
2701 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
2702 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() )
2704 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
2706 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2708 TargetInfo
* target
= &*ihit
;
2709 if(!IS_CREATURE_GUID(target
->targetGUID
))
2712 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
2716 p
->CastedCreatureOrGO(unit
->GetEntry(),unit
->GetGUID(),m_spellInfo
->Id
);
2719 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2721 GOTargetInfo
* target
= &*ihit
;
2723 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
2727 p
->CastedCreatureOrGO(go
->GetEntry(),go
->GetGUID(),m_spellInfo
->Id
);
2741 void Spell::finish(bool ok
)
2746 if(m_spellState
== SPELL_STATE_FINISHED
)
2749 m_spellState
= SPELL_STATE_FINISHED
;
2751 // other code related only to successfully finished spells
2756 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2757 ((Player
*)m_caster
)->RemoveSpellMods(this);
2759 // handle SPELL_AURA_ADD_TARGET_TRIGGER auras
2760 Unit::AuraList
const& targetTriggers
= m_caster
->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER
);
2761 for(Unit::AuraList::const_iterator i
= targetTriggers
.begin(); i
!= targetTriggers
.end(); ++i
)
2763 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
2765 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2766 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2768 // check m_caster->GetGUID() let load auras at login and speedup most often case
2769 Unit
*unit
= m_caster
->GetGUID()== ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2770 if (unit
&& unit
->isAlive())
2772 SpellEntry
const *auraSpellInfo
= (*i
)->GetSpellProto();
2773 uint32 auraSpellIdx
= (*i
)->GetEffIndex();
2774 // Calculate chance at that moment (can be depend for example from combo points)
2775 int32 chance
= m_caster
->CalculateSpellDamage(auraSpellInfo
, auraSpellIdx
, (*i
)->GetBasePoints(),unit
);
2776 if(roll_chance_i(chance
))
2777 m_caster
->CastSpell(unit
, auraSpellInfo
->EffectTriggerSpell
[auraSpellIdx
], true, NULL
, (*i
));
2782 // Heal caster for all health leech from all targets
2784 m_caster
->DealHeal(m_caster
, uint32(m_healthLeech
), m_spellInfo
);
2786 if (IsMeleeAttackResetSpell())
2788 m_caster
->resetAttackTimer(BASE_ATTACK
);
2789 if(m_caster
->haveOffhandWeapon())
2790 m_caster
->resetAttackTimer(OFF_ATTACK
);
2793 /*if (IsRangedAttackResetSpell())
2794 m_caster->resetAttackTimer(RANGED_ATTACK);*/
2796 // Clear combo at finish state
2797 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& NeedsComboPoints(m_spellInfo
))
2799 // Not drop combopoints if negative spell and if any miss on enemy exist
2800 bool needDrop
= true;
2801 if (!IsPositiveSpell(m_spellInfo
->Id
))
2802 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2803 if (ihit
->missCondition
!= SPELL_MISS_NONE
&& ihit
->targetGUID
!=m_caster
->GetGUID())
2809 ((Player
*)m_caster
)->ClearComboPoints();
2812 // potions disabled by client, send event "not in combat" if need
2813 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2814 ((Player
*)m_caster
)->UpdatePotionCooldown(this);
2816 // call triggered spell only at successful cast (after clear combo points -> for add some if need)
2817 if(!m_TriggerSpells
.empty())
2820 // Stop Attack for some spells
2821 if( m_spellInfo
->Attributes
& SPELL_ATTR_STOP_ATTACK_TARGET
)
2822 m_caster
->AttackStop();
2825 void Spell::SendCastResult(SpellCastResult result
)
2827 if(result
== SPELL_CAST_OK
)
2830 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
2833 if(((Player
*)m_caster
)->GetSession()->PlayerLoading()) // don't send cast results at loading time
2836 WorldPacket
data(SMSG_CAST_FAILED
, (4+1+1));
2837 data
<< uint8(m_cast_count
); // single cast or multi 2.3 (0/1)
2838 data
<< uint32(m_spellInfo
->Id
);
2839 data
<< uint8(result
); // problem
2842 case SPELL_FAILED_REQUIRES_SPELL_FOCUS
:
2843 data
<< uint32(m_spellInfo
->RequiresSpellFocus
);
2845 case SPELL_FAILED_REQUIRES_AREA
:
2846 // hardcode areas limitation case
2847 switch(m_spellInfo
->Id
)
2849 case 41617: // Cenarion Mana Salve
2850 case 41619: // Cenarion Healing Salve
2851 data
<< uint32(3905);
2853 case 41618: // Bottled Nethergon Energy
2854 case 41620: // Bottled Nethergon Vapor
2855 data
<< uint32(3842);
2857 case 45373: // Bloodberry Elixir
2858 data
<< uint32(4075);
2860 default: // default case (don't must be)
2865 case SPELL_FAILED_TOTEMS
:
2866 if(m_spellInfo
->Totem
[0])
2867 data
<< uint32(m_spellInfo
->Totem
[0]);
2868 if(m_spellInfo
->Totem
[1])
2869 data
<< uint32(m_spellInfo
->Totem
[1]);
2871 case SPELL_FAILED_TOTEM_CATEGORY
:
2872 if(m_spellInfo
->TotemCategory
[0])
2873 data
<< uint32(m_spellInfo
->TotemCategory
[0]);
2874 if(m_spellInfo
->TotemCategory
[1])
2875 data
<< uint32(m_spellInfo
->TotemCategory
[1]);
2877 case SPELL_FAILED_EQUIPPED_ITEM_CLASS
:
2878 data
<< uint32(m_spellInfo
->EquippedItemClass
);
2879 data
<< uint32(m_spellInfo
->EquippedItemSubClassMask
);
2880 //data << uint32(m_spellInfo->EquippedItemInventoryTypeMask);
2885 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
2888 void Spell::SendSpellStart()
2890 if(!IsNeedSendToClient())
2893 sLog
.outDebug("Sending SMSG_SPELL_START id=%u", m_spellInfo
->Id
);
2895 uint32 castFlags
= CAST_FLAG_UNKNOWN1
;
2897 castFlags
|= CAST_FLAG_AMMO
;
2899 if(m_spellInfo
->runeCostID
)
2900 castFlags
|= CAST_FLAG_UNKNOWN10
;
2902 WorldPacket
data(SMSG_SPELL_START
, (8+8+4+4+2));
2904 data
.append(m_CastItem
->GetPackGUID());
2906 data
.append(m_caster
->GetPackGUID());
2908 data
.append(m_caster
->GetPackGUID());
2909 data
<< uint8(m_cast_count
); // pending spell cast?
2910 data
<< uint32(m_spellInfo
->Id
); // spellId
2911 data
<< uint32(castFlags
); // cast flags
2912 data
<< uint32(m_timer
); // delay?
2914 m_targets
.write(&data
);
2916 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // predicted power?
2919 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
2921 uint8 v1
= 0;//m_runesState;
2922 uint8 v2
= 0;//((Player*)m_caster)->GetRunesState();
2923 data
<< uint8(v1
); // runes state before
2924 data
<< uint8(v2
); // runes state after
2925 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
2928 if(m
& v1
) // usable before...
2929 if(!(m
& v2
)) // ...but on cooldown now...
2930 data
<< uint8(0); // some unknown byte (time?)
2934 if ( castFlags
& CAST_FLAG_AMMO
)
2935 WriteAmmoToPacket(&data
);
2937 m_caster
->SendMessageToSet(&data
, true);
2940 void Spell::SendSpellGo()
2942 // not send invisible spell casting
2943 if(!IsNeedSendToClient())
2946 sLog
.outDebug("Sending SMSG_SPELL_GO id=%u", m_spellInfo
->Id
);
2948 uint32 castFlags
= CAST_FLAG_UNKNOWN3
;
2950 castFlags
|= CAST_FLAG_AMMO
; // arrows/bullets visual
2952 if((m_caster
->GetTypeId() == TYPEID_PLAYER
) && (m_caster
->getClass() == CLASS_DEATH_KNIGHT
) && m_spellInfo
->runeCostID
)
2954 castFlags
|= CAST_FLAG_UNKNOWN10
; // same as in SMSG_SPELL_START
2955 castFlags
|= CAST_FLAG_UNKNOWN6
; // makes cooldowns visible
2956 castFlags
|= CAST_FLAG_UNKNOWN7
; // rune cooldowns list
2959 WorldPacket
data(SMSG_SPELL_GO
, 50); // guess size
2962 data
.append(m_CastItem
->GetPackGUID());
2964 data
.append(m_caster
->GetPackGUID());
2966 data
.append(m_caster
->GetPackGUID());
2967 data
<< uint8(m_cast_count
); // pending spell cast?
2968 data
<< uint32(m_spellInfo
->Id
); // spellId
2969 data
<< uint32(castFlags
); // cast flags
2970 data
<< uint32(getMSTime()); // timestamp
2972 WriteSpellGoTargets(&data
);
2974 m_targets
.write(&data
);
2976 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // unknown wotlk, predicted power?
2979 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
2981 uint8 v1
= m_runesState
;
2982 uint8 v2
= ((Player
*)m_caster
)->GetRunesState();
2983 data
<< uint8(v1
); // runes state before
2984 data
<< uint8(v2
); // runes state after
2985 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
2988 if(m
& v1
) // usable before...
2989 if(!(m
& v2
)) // ...but on cooldown now...
2990 data
<< uint8(0); // some unknown byte (time?)
2994 if ( castFlags
& CAST_FLAG_UNKNOWN4
) // unknown wotlk
3000 if ( castFlags
& CAST_FLAG_AMMO
)
3001 WriteAmmoToPacket(&data
);
3003 if ( castFlags
& CAST_FLAG_UNKNOWN5
) // unknown wotlk
3009 if ( m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
3014 m_caster
->SendMessageToSet(&data
, true);
3017 void Spell::WriteAmmoToPacket( WorldPacket
* data
)
3019 uint32 ammoInventoryType
= 0;
3020 uint32 ammoDisplayID
= 0;
3022 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3024 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack( RANGED_ATTACK
);
3027 ammoInventoryType
= pItem
->GetProto()->InventoryType
;
3028 if( ammoInventoryType
== INVTYPE_THROWN
)
3029 ammoDisplayID
= pItem
->GetProto()->DisplayInfoID
;
3032 uint32 ammoID
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
3035 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( ammoID
);
3038 ammoDisplayID
= pProto
->DisplayInfoID
;
3039 ammoInventoryType
= pProto
->InventoryType
;
3042 else if(m_caster
->GetDummyAura(46699)) // Requires No Ammo
3044 ammoDisplayID
= 5996; // normal arrow
3045 ammoInventoryType
= INVTYPE_AMMO
;
3050 // TODO: implement selection ammo data based at ranged weapon stored in equipmodel/equipinfo/equipslot fields
3052 *data
<< uint32(ammoDisplayID
);
3053 *data
<< uint32(ammoInventoryType
);
3056 void Spell::WriteSpellGoTargets( WorldPacket
* data
)
3058 // This function also fill data for channeled spells:
3059 // m_needAliveTargetMask req for stop channelig if one target die
3060 uint32 hit
= m_UniqueGOTargetInfo
.size(); // Always hits on GO
3062 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3064 if ((*ihit
).effectMask
== 0) // No effect apply - all immuned add state
3066 // possibly SPELL_MISS_IMMUNE2 for this??
3067 ihit
->missCondition
= SPELL_MISS_IMMUNE2
;
3070 else if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
3076 *data
<< (uint8
)hit
;
3077 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3078 if ((*ihit
).missCondition
== SPELL_MISS_NONE
) // Add only hits
3080 *data
<< uint64(ihit
->targetGUID
);
3081 m_needAliveTargetMask
|=ihit
->effectMask
;
3084 for(std::list
<GOTargetInfo
>::const_iterator ighit
= m_UniqueGOTargetInfo
.begin();ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
3085 *data
<< uint64(ighit
->targetGUID
); // Always hits
3087 *data
<< (uint8
)miss
;
3088 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3090 if( ihit
->missCondition
!= SPELL_MISS_NONE
) // Add only miss
3092 *data
<< uint64(ihit
->targetGUID
);
3093 *data
<< uint8(ihit
->missCondition
);
3094 if( ihit
->missCondition
== SPELL_MISS_REFLECT
)
3095 *data
<< uint8(ihit
->reflectResult
);
3098 // Reset m_needAliveTargetMask for non channeled spell
3099 if(!IsChanneledSpell(m_spellInfo
))
3100 m_needAliveTargetMask
= 0;
3103 void Spell::SendLogExecute()
3105 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
3107 WorldPacket
data(SMSG_SPELLLOGEXECUTE
, (8+4+4+4+4+8));
3109 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
3110 data
.append(m_caster
->GetPackGUID());
3112 data
.append(target
->GetPackGUID());
3114 data
<< uint32(m_spellInfo
->Id
);
3116 data
<< uint32(count1
); // count1 (effect count?)
3117 for(uint32 i
= 0; i
< count1
; ++i
)
3119 data
<< uint32(m_spellInfo
->Effect
[0]); // spell effect
3121 data
<< uint32(count2
); // count2 (target count?)
3122 for(uint32 j
= 0; j
< count2
; ++j
)
3124 switch(m_spellInfo
->Effect
[0])
3126 case SPELL_EFFECT_POWER_DRAIN
:
3127 if(Unit
*unit
= m_targets
.getUnitTarget())
3128 data
.append(unit
->GetPackGUID());
3135 case SPELL_EFFECT_ADD_EXTRA_ATTACKS
:
3136 if(Unit
*unit
= m_targets
.getUnitTarget())
3137 data
.append(unit
->GetPackGUID());
3140 data
<< uint32(0); // count?
3142 case SPELL_EFFECT_INTERRUPT_CAST
:
3143 if(Unit
*unit
= m_targets
.getUnitTarget())
3144 data
.append(unit
->GetPackGUID());
3147 data
<< uint32(0); // spellid
3149 case SPELL_EFFECT_DURABILITY_DAMAGE
:
3150 if(Unit
*unit
= m_targets
.getUnitTarget())
3151 data
.append(unit
->GetPackGUID());
3157 case SPELL_EFFECT_OPEN_LOCK
:
3158 case SPELL_EFFECT_OPEN_LOCK_ITEM
:
3159 if(Item
*item
= m_targets
.getItemTarget())
3160 data
.append(item
->GetPackGUID());
3164 case SPELL_EFFECT_CREATE_ITEM
:
3165 case SPELL_EFFECT_CREATE_ITEM_2
:
3166 data
<< uint32(m_spellInfo
->EffectItemType
[0]);
3168 case SPELL_EFFECT_SUMMON
:
3169 case SPELL_EFFECT_TRANS_DOOR
:
3170 case SPELL_EFFECT_SUMMON_PET
:
3171 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
3172 case SPELL_EFFECT_CREATE_HOUSE
:
3173 case SPELL_EFFECT_DUEL
:
3174 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1
:
3175 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2
:
3176 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3
:
3177 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4
:
3178 if(Unit
*unit
= m_targets
.getUnitTarget())
3179 data
.append(unit
->GetPackGUID());
3180 else if(m_targets
.getItemTargetGUID())
3181 data
.appendPackGUID(m_targets
.getItemTargetGUID());
3182 else if(GameObject
*go
= m_targets
.getGOTarget())
3183 data
.append(go
->GetPackGUID());
3185 data
<< uint8(0); // guid
3187 case SPELL_EFFECT_FEED_PET
:
3188 data
<< uint32(m_targets
.getItemTargetEntry());
3190 case SPELL_EFFECT_DISMISS_PET
:
3191 if(Unit
*unit
= m_targets
.getUnitTarget())
3192 data
.append(unit
->GetPackGUID());
3196 case SPELL_EFFECT_RESURRECT
:
3197 case SPELL_EFFECT_RESURRECT_NEW
:
3198 if(Unit
*unit
= m_targets
.getUnitTarget())
3199 data
.append(unit
->GetPackGUID());
3209 m_caster
->SendMessageToSet(&data
, true);
3212 void Spell::SendInterrupted(uint8 result
)
3214 WorldPacket
data(SMSG_SPELL_FAILURE
, (8+4+1));
3215 data
.append(m_caster
->GetPackGUID());
3216 data
<< uint8(m_cast_count
);
3217 data
<< uint32(m_spellInfo
->Id
);
3218 data
<< uint8(result
);
3219 m_caster
->SendMessageToSet(&data
, true);
3221 data
.Initialize(SMSG_SPELL_FAILED_OTHER
, (8+4));
3222 data
.append(m_caster
->GetPackGUID());
3223 data
<< uint8(m_cast_count
);
3224 data
<< uint32(m_spellInfo
->Id
);
3225 data
<< uint8(result
);
3226 m_caster
->SendMessageToSet(&data
, true);
3229 void Spell::SendChannelUpdate(uint32 time
)
3233 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
,0);
3234 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
,0);
3237 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3240 WorldPacket
data( MSG_CHANNEL_UPDATE
, 8+4 );
3241 data
.append(m_caster
->GetPackGUID());
3242 data
<< uint32(time
);
3244 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3247 void Spell::SendChannelStart(uint32 duration
)
3249 WorldObject
* target
= NULL
;
3251 // select first not resisted target from target list for _0_ effect
3252 if(!m_UniqueTargetInfo
.empty())
3254 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin();itr
!= m_UniqueTargetInfo
.end();++itr
)
3256 if( (itr
->effectMask
& (1<<0)) && itr
->reflectResult
==SPELL_MISS_NONE
&& itr
->targetGUID
!= m_caster
->GetGUID())
3258 target
= ObjectAccessor::GetUnit(*m_caster
, itr
->targetGUID
);
3263 else if(!m_UniqueGOTargetInfo
.empty())
3265 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin();itr
!= m_UniqueGOTargetInfo
.end();++itr
)
3267 if(itr
->effectMask
& (1<<0) )
3269 target
= m_caster
->GetMap()->GetGameObject(itr
->targetGUID
);
3275 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3277 WorldPacket
data( MSG_CHANNEL_START
, (8+4+4) );
3278 data
.append(m_caster
->GetPackGUID());
3279 data
<< uint32(m_spellInfo
->Id
);
3280 data
<< uint32(duration
);
3282 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3287 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, target
->GetGUID());
3288 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, m_spellInfo
->Id
);
3291 void Spell::SendResurrectRequest(Player
* target
)
3293 // Both players and NPCs can resurrect using spells - have a look at creature 28487 for example
3294 // However, the packet structure differs slightly
3296 const char* sentName
= m_caster
->GetTypeId()==TYPEID_PLAYER
?"":m_caster
->GetNameForLocaleIdx(target
->GetSession()->GetSessionDbLocaleIndex());
3298 WorldPacket
data(SMSG_RESURRECT_REQUEST
, (8+4+strlen(sentName
)+1+1+1));
3299 data
<< uint64(m_caster
->GetGUID());
3300 data
<< uint32(strlen(sentName
)+1);
3305 data
<< uint8(m_caster
->GetTypeId()==TYPEID_PLAYER
?0:1);
3306 target
->GetSession()->SendPacket(&data
);
3309 void Spell::SendPlaySpellVisual(uint32 SpellID
)
3311 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3314 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 12);
3315 data
<< uint64(m_caster
->GetGUID());
3316 data
<< uint32(SpellID
); // spell visual id?
3317 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
3320 void Spell::TakeCastItem()
3322 if(!m_CastItem
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
3325 // not remove cast item at triggered spell (equipping, weapon damage, etc)
3326 if(m_IsTriggeredSpell
)
3329 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3333 // This code is to avoid a crash
3334 // I'm not sure, if this is really an error, but I guess every item needs a prototype
3335 sLog
.outError("Cast item has no item prototype highId=%d, lowId=%d",m_CastItem
->GetGUIDHigh(), m_CastItem
->GetGUIDLow());
3339 bool expendable
= false;
3340 bool withoutCharges
= false;
3342 for (int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
3344 if (proto
->Spells
[i
].SpellId
)
3346 // item has limited charges
3347 if (proto
->Spells
[i
].SpellCharges
)
3349 if (proto
->Spells
[i
].SpellCharges
< 0)
3352 int32 charges
= m_CastItem
->GetSpellCharges(i
);
3354 // item has charges left
3357 (charges
> 0) ? --charges
: ++charges
; // abs(charges) less at 1 after use
3358 if (proto
->Stackable
== 1)
3359 m_CastItem
->SetSpellCharges(i
, charges
);
3360 m_CastItem
->SetState(ITEM_CHANGED
, (Player
*)m_caster
);
3364 withoutCharges
= (charges
== 0);
3369 if (expendable
&& withoutCharges
)
3372 ((Player
*)m_caster
)->DestroyItemCount(m_CastItem
, count
, true);
3374 // prevent crash at access to deleted m_targets.getItemTarget
3375 if(m_CastItem
==m_targets
.getItemTarget())
3376 m_targets
.setItemTarget(NULL
);
3382 void Spell::TakePower()
3384 if(m_CastItem
|| m_triggeredByAuraSpell
)
3387 // health as power used
3388 if(m_spellInfo
->powerType
== POWER_HEALTH
)
3390 m_caster
->ModifyHealth( -(int32
)m_powerCost
);
3394 if(m_spellInfo
->powerType
>= MAX_POWERS
)
3396 sLog
.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo
->powerType
);
3400 Powers powerType
= Powers(m_spellInfo
->powerType
);
3402 if(powerType
== POWER_RUNE
)
3408 m_caster
->ModifyPower(powerType
, -(int32
)m_powerCost
);
3410 // Set the five second timer
3411 if (powerType
== POWER_MANA
&& m_powerCost
> 0)
3412 m_caster
->SetLastManaUse(getMSTime());
3415 SpellCastResult
Spell::CheckRuneCost(uint32 runeCostID
)
3417 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3418 return SPELL_CAST_OK
;
3420 Player
*plr
= (Player
*)m_caster
;
3422 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3423 return SPELL_CAST_OK
;
3425 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(runeCostID
);
3428 return SPELL_CAST_OK
;
3430 if(src
->NoRuneCost())
3431 return SPELL_CAST_OK
;
3433 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3435 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3436 runeCost
[i
] = src
->RuneCost
[i
];
3438 runeCost
[RUNE_DEATH
] = MAX_RUNES
; // calculated later
3440 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3442 uint8 rune
= plr
->GetCurrentRune(i
);
3443 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3447 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3449 runeCost
[RUNE_DEATH
] += runeCost
[i
];
3451 if(runeCost
[RUNE_DEATH
] > MAX_RUNES
)
3452 return SPELL_FAILED_NO_POWER
; // not sure if result code is correct
3454 return SPELL_CAST_OK
;
3457 void Spell::TakeRunePower()
3459 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3462 Player
*plr
= (Player
*)m_caster
;
3464 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3467 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(m_spellInfo
->runeCostID
);
3469 if(!src
|| (src
->NoRuneCost() && src
->NoRunicPowerGain()))
3472 m_runesState
= plr
->GetRunesState(); // store previous state
3474 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3476 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3478 runeCost
[i
] = src
->RuneCost
[i
];
3481 runeCost
[RUNE_DEATH
] = 0; // calculated later
3483 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3485 uint8 rune
= plr
->GetCurrentRune(i
);
3486 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3488 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3493 runeCost
[RUNE_DEATH
] = runeCost
[RUNE_BLOOD
] + runeCost
[RUNE_UNHOLY
] + runeCost
[RUNE_FROST
];
3495 if(runeCost
[RUNE_DEATH
] > 0)
3497 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3499 uint8 rune
= plr
->GetCurrentRune(i
);
3500 if((plr
->GetRuneCooldown(i
) == 0) && (rune
== RUNE_DEATH
))
3502 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3504 plr
->ConvertRune(i
, plr
->GetBaseRune(i
));
3505 if(runeCost
[RUNE_DEATH
] == 0)
3511 // you can gain some runic power when use runes
3512 float rp
= src
->runePowerGain
;;
3513 rp
*= sWorld
.getRate(RATE_POWER_RUNICPOWER_INCOME
);
3514 plr
->ModifyPower(POWER_RUNIC_POWER
, (int32
)rp
);
3517 void Spell::TakeReagents()
3519 if(m_IsTriggeredSpell
) // reagents used in triggered spell removed by original spell or don't must be removed.
3522 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3525 Player
* p_caster
= (Player
*)m_caster
;
3526 if (p_caster
->CanNoReagentCast(m_spellInfo
))
3529 for(uint32 x
=0;x
<8;x
++)
3531 if(m_spellInfo
->Reagent
[x
] <= 0)
3534 uint32 itemid
= m_spellInfo
->Reagent
[x
];
3535 uint32 itemcount
= m_spellInfo
->ReagentCount
[x
];
3537 // if CastItem is also spell reagent
3540 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3541 if( proto
&& proto
->ItemId
== itemid
)
3543 for(int s
=0;s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
3545 // CastItem will be used up and does not count as reagent
3546 int32 charges
= m_CastItem
->GetSpellCharges(s
);
3547 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
3558 // if getItemTarget is also spell reagent
3559 if (m_targets
.getItemTargetEntry()==itemid
)
3560 m_targets
.setItemTarget(NULL
);
3562 p_caster
->DestroyItemCount(itemid
, itemcount
, true);
3566 void Spell::HandleThreatSpells(uint32 spellId
)
3568 if(!m_targets
.getUnitTarget() || !spellId
)
3571 if(!m_targets
.getUnitTarget()->CanHaveThreatList())
3574 SpellThreatEntry
const *threatSpell
= sSpellThreatStore
.LookupEntry
<SpellThreatEntry
>(spellId
);
3578 m_targets
.getUnitTarget()->AddThreat(m_caster
, float(threatSpell
->threat
));
3580 DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId
, spellmgr
.GetSpellRank(spellId
), threatSpell
->threat
);
3583 void Spell::HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,uint32 i
, float DamageMultiplier
)
3585 unitTarget
= pUnitTarget
;
3586 itemTarget
= pItemTarget
;
3587 gameObjTarget
= pGOTarget
;
3589 uint8 eff
= m_spellInfo
->Effect
[i
];
3591 damage
= int32(CalculateDamage((uint8
)i
,unitTarget
)*DamageMultiplier
);
3593 sLog
.outDebug( "Spell: Effect : %u", eff
);
3595 if(eff
<TOTAL_SPELL_EFFECTS
)
3597 //sLog.outDebug( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff);
3598 (*this.*SpellEffects
[eff
])(i
);
3603 sLog.outDebug( "WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff);
3605 EffectEnchantItemTmp(i);
3608 sLog.outError("SPELL: unknown effect %u spell id %u",
3609 eff, m_spellInfo->Id);
3615 void Spell::TriggerSpell()
3617 for(TriggerSpells::const_iterator si
=m_TriggerSpells
.begin(); si
!=m_TriggerSpells
.end(); ++si
)
3619 Spell
* spell
= new Spell(m_caster
, (*si
), true, m_originalCasterGUID
, m_selfContainer
);
3620 spell
->prepare(&m_targets
); // use original spell original targets
3624 SpellCastResult
Spell::CheckCast(bool strict
)
3626 // check cooldowns to prevent cheating
3627 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
3629 if(m_triggeredByAuraSpell
)
3630 return SPELL_FAILED_DONT_REPORT
;
3632 return SPELL_FAILED_NOT_READY
;
3635 // only allow triggered spells if at an ended battleground
3636 if( !m_IsTriggeredSpell
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
3637 if(BattleGround
* bg
= ((Player
*)m_caster
)->GetBattleGround())
3638 if(bg
->GetStatus() == STATUS_WAIT_LEAVE
)
3639 return SPELL_FAILED_DONT_REPORT
;
3641 // only check at first call, Stealth auras are already removed at second call
3642 // for now, ignore triggered spells
3643 if( strict
&& !m_IsTriggeredSpell
)
3645 bool checkForm
= true;
3646 // Ignore form req aura
3647 Unit::AuraList
const& ignore
= m_caster
->GetAurasByType(SPELL_AURA_MOD_IGNORE_SHAPESHIFT
);
3648 for(Unit::AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
3650 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
3657 // Cannot be used in this stance/form
3658 SpellCastResult shapeError
= GetErrorAtShapeshiftedCast(m_spellInfo
, m_caster
->m_form
);
3659 if(shapeError
!= SPELL_CAST_OK
)
3662 if ((m_spellInfo
->Attributes
& SPELL_ATTR_ONLY_STEALTHED
) && !(m_caster
->HasStealthAura()))
3663 return SPELL_FAILED_ONLY_STEALTHED
;
3667 // caster state requirements
3668 if(m_spellInfo
->CasterAuraState
&& !m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraState
)))
3669 return SPELL_FAILED_CASTER_AURASTATE
;
3670 if(m_spellInfo
->CasterAuraStateNot
&& m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraStateNot
)))
3671 return SPELL_FAILED_CASTER_AURASTATE
;
3673 // Caster aura req check if need
3674 if(m_spellInfo
->casterAuraSpell
&& !m_caster
->HasAura(m_spellInfo
->casterAuraSpell
))
3675 return SPELL_FAILED_CASTER_AURASTATE
;
3676 if(m_spellInfo
->excludeCasterAuraSpell
&& m_caster
->HasAura(m_spellInfo
->excludeCasterAuraSpell
))
3677 return SPELL_FAILED_CASTER_AURASTATE
;
3679 // cancel autorepeat spells if cast start when moving
3680 // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
3681 if( m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->isMoving() )
3683 // skip stuck spell to allow use it in falling case and apply spell limitations at movement
3684 if( (!m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_FALLING
) || m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
) &&
3685 (IsAutoRepeat() || (m_spellInfo
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_NOT_SEATED
) != 0) )
3686 return SPELL_FAILED_MOVING
;
3689 if(Unit
*target
= m_targets
.getUnitTarget())
3691 // target state requirements (not allowed state), apply to self also
3692 if(m_spellInfo
->TargetAuraStateNot
&& target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraStateNot
)))
3693 return SPELL_FAILED_TARGET_AURASTATE
;
3695 // Target aura req check if need
3696 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
3697 return SPELL_FAILED_CASTER_AURASTATE
;
3698 if(m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
3699 return SPELL_FAILED_CASTER_AURASTATE
;
3701 if(target
!= m_caster
)
3703 // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds
3704 if(m_spellInfo
->TargetAuraState
&& !target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraState
)))
3705 return SPELL_FAILED_TARGET_AURASTATE
;
3707 // Not allow casting on flying player
3708 if (target
->isInFlight())
3709 return SPELL_FAILED_BAD_TARGETS
;
3711 if(!m_IsTriggeredSpell
&& VMAP::VMapFactory::checkSpellForLoS(m_spellInfo
->Id
) && !m_caster
->IsWithinLOSInMap(target
))
3712 return SPELL_FAILED_LINE_OF_SIGHT
;
3714 // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode
3715 // this case can be triggered if rank not found (too low-level target for first rank)
3716 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsPassiveSpell(m_spellInfo
->Id
) && !m_CastItem
)
3717 for(int i
=0;i
<3;++i
)
3718 if(IsPositiveEffect(m_spellInfo
->Id
, i
) && m_spellInfo
->Effect
[i
] == SPELL_EFFECT_APPLY_AURA
)
3719 if(target
->getLevel() + 10 < m_spellInfo
->spellLevel
)
3720 return SPELL_FAILED_LOWLEVEL
;
3722 else if (m_caster
->GetTypeId()==TYPEID_PLAYER
) // Target - is player caster
3724 // Additional check for some spells
3725 // If 0 spell effect empty - client not send target data (need use selection)
3726 // TODO: check it on next client version
3727 if (m_targets
.m_targetMask
== TARGET_FLAG_SELF
&&
3728 m_spellInfo
->EffectImplicitTargetA
[1] == TARGET_CHAIN_DAMAGE
)
3730 if (target
= m_caster
->GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection()))
3731 m_targets
.setUnitTarget(target
);
3733 return SPELL_FAILED_BAD_TARGETS
;
3737 // check pet presents
3738 for(int j
=0;j
<3;j
++)
3740 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_PET
)
3742 target
= m_caster
->GetPet();
3745 if(m_triggeredByAuraSpell
) // not report pet not existence for triggered spells
3746 return SPELL_FAILED_DONT_REPORT
;
3748 return SPELL_FAILED_NO_PET
;
3754 //check creature type
3755 //ignore self casts (including area casts when caster selected as target)
3756 if(target
!= m_caster
)
3758 if(!CheckTargetCreatureType(target
))
3760 if(target
->GetTypeId()==TYPEID_PLAYER
)
3761 return SPELL_FAILED_TARGET_IS_PLAYER
;
3763 return SPELL_FAILED_BAD_TARGETS
;
3767 // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
3768 // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
3769 if(m_caster
!= target
&& m_caster
->GetTypeId()==TYPEID_UNIT
&& m_caster
->GetCharmerOrOwnerGUID())
3771 // check correctness positive/negative cast target (pet cast real check and cheating check)
3772 if(IsPositiveSpell(m_spellInfo
->Id
))
3774 if(m_caster
->IsHostileTo(target
))
3775 return SPELL_FAILED_BAD_TARGETS
;
3779 if(m_caster
->IsFriendlyTo(target
))
3780 return SPELL_FAILED_BAD_TARGETS
;
3784 if(IsPositiveSpell(m_spellInfo
->Id
))
3785 if(target
->IsImmunedToSpell(m_spellInfo
))
3786 return SPELL_FAILED_TARGET_AURASTATE
;
3788 //Must be behind the target.
3789 if( m_spellInfo
->AttributesEx2
== 0x100000 && (m_spellInfo
->AttributesEx
& 0x200) == 0x200 && target
->HasInArc(M_PI
, m_caster
) )
3791 //Exclusion for Pounce: Facing Limitation was removed in 2.0.1, but it still uses the same, old Ex-Flags
3792 if( m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_DRUID
|| m_spellInfo
->SpellFamilyFlags
!= 0x0000000000020000LL
)
3795 return SPELL_FAILED_NOT_BEHIND
;
3799 //Target must be facing you.
3800 if((m_spellInfo
->Attributes
== 0x150010) && !target
->HasInArc(M_PI
, m_caster
) )
3803 return SPELL_FAILED_NOT_INFRONT
;
3806 // check if target is in combat
3807 if (target
!= m_caster
&& (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET
) && target
->isInCombat())
3808 return SPELL_FAILED_TARGET_AFFECTING_COMBAT
;
3811 // Spell casted only on battleground
3812 if((m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_BATTLEGROUND
) && m_caster
->GetTypeId()==TYPEID_PLAYER
)
3813 if(!((Player
*)m_caster
)->InBattleGround())
3814 return SPELL_FAILED_ONLY_BATTLEGROUNDS
;
3816 // do not allow spells to be cast in arenas
3817 // - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag
3818 // - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag
3819 if( (m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA
) ||
3820 GetSpellRecoveryTime(m_spellInfo
) > 15 * MINUTE
* IN_MILISECONDS
&& !(m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_USABLE_IN_ARENA
) )
3821 if(MapEntry
const* mapEntry
= sMapStore
.LookupEntry(m_caster
->GetMapId()))
3822 if(mapEntry
->IsBattleArena())
3823 return SPELL_FAILED_NOT_IN_ARENA
;
3827 m_caster
->GetZoneAndAreaId(zone
,area
);
3829 SpellCastResult locRes
= spellmgr
.GetSpellAllowedInLocationError(m_spellInfo
,m_caster
->GetMapId(),zone
,area
,
3830 m_caster
->GetTypeId()==TYPEID_PLAYER
? ((Player
*)m_caster
) : NULL
);
3831 if(locRes
!= SPELL_CAST_OK
)
3834 // not let players cast spells at mount (and let do it to creatures)
3835 if( m_caster
->IsMounted() && m_caster
->GetTypeId()==TYPEID_PLAYER
&& !m_IsTriggeredSpell
&&
3836 !IsPassiveSpell(m_spellInfo
->Id
) && !(m_spellInfo
->Attributes
& SPELL_ATTR_CASTABLE_WHILE_MOUNTED
) )
3838 if(m_caster
->isInFlight())
3839 return SPELL_FAILED_NOT_FLYING
;
3841 return SPELL_FAILED_NOT_MOUNTED
;
3844 // always (except passive spells) check items (focus object can be required for any type casts)
3845 if(!IsPassiveSpell(m_spellInfo
->Id
))
3847 SpellCastResult castResult
= CheckItems();
3848 if(castResult
!= SPELL_CAST_OK
)
3852 //ImpliciteTargetA-B = 38, If fact there is 0 Spell with ImpliciteTargetB=38
3853 if(m_UniqueTargetInfo
.empty()) // skip second CheckCast apply (for delayed spells for example)
3855 for(uint8 j
= 0; j
< 3; j
++)
3857 if( m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
3858 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_SELF
||
3859 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3860 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3862 SpellScriptTarget::const_iterator lower
= spellmgr
.GetBeginSpellScriptTarget(m_spellInfo
->Id
);
3863 SpellScriptTarget::const_iterator upper
= spellmgr
.GetEndSpellScriptTarget(m_spellInfo
->Id
);
3865 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
);
3867 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
3868 float range
= GetSpellMaxRange(srange
);
3870 Creature
* creatureScriptTarget
= NULL
;
3871 GameObject
* goScriptTarget
= NULL
;
3873 for(SpellScriptTarget::const_iterator i_spellST
= lower
; i_spellST
!= upper
; ++i_spellST
)
3875 switch(i_spellST
->second
.type
)
3877 case SPELL_TARGET_TYPE_GAMEOBJECT
:
3879 GameObject
* p_GameObject
= NULL
;
3881 if(i_spellST
->second
.targetEntry
)
3883 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
3885 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3887 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*m_caster
,i_spellST
->second
.targetEntry
,range
);
3888 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(m_caster
, p_GameObject
,go_check
);
3890 TypeContainerVisitor
<MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
>, GridTypeMapContainer
> object_checker(checker
);
3891 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3892 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
3896 // remember found target and range, next attempt will find more near target with another entry
3897 creatureScriptTarget
= NULL
;
3898 goScriptTarget
= p_GameObject
;
3899 range
= go_check
.GetLastRange();
3902 else if( focusObject
) //Focus Object
3904 float frange
= m_caster
->GetDistance(focusObject
);
3907 creatureScriptTarget
= NULL
;
3908 goScriptTarget
= focusObject
;
3914 case SPELL_TARGET_TYPE_CREATURE
:
3915 case SPELL_TARGET_TYPE_DEAD
:
3918 Creature
*p_Creature
= NULL
;
3920 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
3922 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3923 cell
.SetNoCreate(); // Really don't know what is that???
3925 MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
u_check(*m_caster
,i_spellST
->second
.targetEntry
,i_spellST
->second
.type
!=SPELL_TARGET_TYPE_DEAD
,range
);
3926 MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
> searcher(m_caster
, p_Creature
, u_check
);
3928 TypeContainerVisitor
<MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
>, GridTypeMapContainer
> grid_creature_searcher(searcher
);
3930 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3931 cell_lock
->Visit(cell_lock
, grid_creature_searcher
, *m_caster
->GetMap());
3935 creatureScriptTarget
= p_Creature
;
3936 goScriptTarget
= NULL
;
3937 range
= u_check
.GetLastRange();
3944 if(creatureScriptTarget
)
3946 // store coordinates for TARGET_SCRIPT_COORDINATES
3947 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3948 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3950 m_targets
.setDestination(creatureScriptTarget
->GetPositionX(),creatureScriptTarget
->GetPositionY(),creatureScriptTarget
->GetPositionZ());
3952 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3953 AddUnitTarget(creatureScriptTarget
, j
);
3955 // store explicit target for TARGET_SCRIPT
3957 AddUnitTarget(creatureScriptTarget
, j
);
3959 else if(goScriptTarget
)
3961 // store coordinates for TARGET_SCRIPT_COORDINATES
3962 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3963 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3965 m_targets
.setDestination(goScriptTarget
->GetPositionX(),goScriptTarget
->GetPositionY(),goScriptTarget
->GetPositionZ());
3967 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3968 AddGOTarget(goScriptTarget
, j
);
3970 // store explicit target for TARGET_SCRIPT
3972 AddGOTarget(goScriptTarget
, j
);
3974 //Missing DB Entry or targets for this spellEffect.
3977 // not report target not existence for triggered spells
3978 if(m_triggeredByAuraSpell
|| m_IsTriggeredSpell
)
3979 return SPELL_FAILED_DONT_REPORT
;
3981 return SPELL_FAILED_BAD_TARGETS
;
3987 if(!m_IsTriggeredSpell
)
3989 SpellCastResult castResult
= CheckRange(strict
);
3990 if(castResult
!= SPELL_CAST_OK
)
3995 SpellCastResult castResult
= CheckPower();
3996 if(castResult
!= SPELL_CAST_OK
)
4000 if(!m_IsTriggeredSpell
) // triggered spell not affected by stun/etc
4002 SpellCastResult castResult
= CheckCasterAuras();
4003 if(castResult
!= SPELL_CAST_OK
)
4007 for (int i
= 0; i
< 3; ++i
)
4009 // for effects of spells that have only one target
4010 switch(m_spellInfo
->Effect
[i
])
4012 case SPELL_EFFECT_DUMMY
:
4014 if(m_spellInfo
->SpellIconID
== 1648) // Execute
4016 if(!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4017 return SPELL_FAILED_BAD_TARGETS
;
4019 else if (m_spellInfo
->Id
== 51582) // Rocket Boots Engaged
4021 if(m_caster
->IsInWater())
4022 return SPELL_FAILED_ONLY_ABOVEWATER
;
4024 else if(m_spellInfo
->SpellIconID
==156) // Holy Shock
4026 // spell different for friends and enemies
4027 // hart version required facing
4028 if(m_targets
.getUnitTarget() && !m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()) && !m_caster
->HasInArc( M_PI
, m_targets
.getUnitTarget() ))
4029 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4033 case SPELL_EFFECT_SCHOOL_DAMAGE
:
4036 if(m_spellInfo
->SpellVisual
[0] == 7250)
4038 if (!m_targets
.getUnitTarget())
4039 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4041 if(m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4042 return SPELL_FAILED_BAD_TARGETS
;
4046 case SPELL_EFFECT_TAMECREATURE
:
4048 if (!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
)
4049 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4051 if (m_targets
.getUnitTarget()->getLevel() > m_caster
->getLevel())
4052 return SPELL_FAILED_HIGHLEVEL
;
4054 // use SMSG_PET_TAME_FAILURE?
4055 if (!((Creature
*)m_targets
.getUnitTarget())->GetCreatureInfo()->isTameable ())
4056 return SPELL_FAILED_BAD_TARGETS
;
4058 if(m_caster
->GetPetGUID())
4059 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4061 if(m_caster
->GetCharmGUID())
4062 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4066 case SPELL_EFFECT_LEARN_SPELL
:
4068 if(m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_PET
)
4071 Pet
* pet
= m_caster
->GetPet();
4074 return SPELL_FAILED_NO_PET
;
4076 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4078 if(!learn_spellproto
)
4079 return SPELL_FAILED_NOT_KNOWN
;
4081 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4082 return SPELL_FAILED_LOWLEVEL
;
4086 case SPELL_EFFECT_LEARN_PET_SPELL
:
4088 Pet
* pet
= m_caster
->GetPet();
4091 return SPELL_FAILED_NO_PET
;
4093 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4095 if(!learn_spellproto
)
4096 return SPELL_FAILED_NOT_KNOWN
;
4098 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4099 return SPELL_FAILED_LOWLEVEL
;
4103 case SPELL_EFFECT_FEED_PET
:
4105 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4106 return SPELL_FAILED_BAD_TARGETS
;
4108 Item
* foodItem
= m_targets
.getItemTarget();
4110 return SPELL_FAILED_BAD_TARGETS
;
4112 Pet
* pet
= m_caster
->GetPet();
4115 return SPELL_FAILED_NO_PET
;
4117 if(!pet
->HaveInDiet(foodItem
->GetProto()))
4118 return SPELL_FAILED_WRONG_PET_FOOD
;
4120 if(!pet
->GetCurrentFoodBenefitLevel(foodItem
->GetProto()->ItemLevel
))
4121 return SPELL_FAILED_FOOD_LOWLEVEL
;
4123 if(m_caster
->isInCombat() || pet
->isInCombat())
4124 return SPELL_FAILED_AFFECTING_COMBAT
;
4128 case SPELL_EFFECT_POWER_BURN
:
4129 case SPELL_EFFECT_POWER_DRAIN
:
4131 // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
4132 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4133 if(Unit
* target
= m_targets
.getUnitTarget())
4134 if(target
!=m_caster
&& target
->getPowerType()!=m_spellInfo
->EffectMiscValue
[i
])
4135 return SPELL_FAILED_BAD_TARGETS
;
4138 case SPELL_EFFECT_CHARGE
:
4140 if (m_caster
->hasUnitState(UNIT_STAT_ROOT
))
4141 return SPELL_FAILED_ROOTED
;
4145 case SPELL_EFFECT_SKINNING
:
4147 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() != TYPEID_UNIT
)
4148 return SPELL_FAILED_BAD_TARGETS
;
4150 if( !(m_targets
.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS
) & UNIT_FLAG_SKINNABLE
) )
4151 return SPELL_FAILED_TARGET_UNSKINNABLE
;
4153 Creature
* creature
= (Creature
*)m_targets
.getUnitTarget();
4154 if ( creature
->GetCreatureType() != CREATURE_TYPE_CRITTER
&& ( !creature
->lootForBody
|| !creature
->loot
.empty() ) )
4156 return SPELL_FAILED_TARGET_NOT_LOOTED
;
4159 uint32 skill
= creature
->GetCreatureInfo()->GetRequiredLootSkill();
4161 int32 skillValue
= ((Player
*)m_caster
)->GetSkillValue(skill
);
4162 int32 TargetLevel
= m_targets
.getUnitTarget()->getLevel();
4163 int32 ReqValue
= (skillValue
< 100 ? (TargetLevel
-10)*10 : TargetLevel
*5);
4164 if (ReqValue
> skillValue
)
4165 return SPELL_FAILED_LOW_CASTLEVEL
;
4167 // chance for fail at orange skinning attempt
4168 if( (m_selfContainer
&& (*m_selfContainer
) == this) &&
4169 skillValue
< sWorld
.GetConfigMaxSkillValue() &&
4170 (ReqValue
< 0 ? 0 : ReqValue
) > irand(skillValue
-25, skillValue
+37) )
4171 return SPELL_FAILED_TRY_AGAIN
;
4175 case SPELL_EFFECT_OPEN_LOCK_ITEM
:
4176 case SPELL_EFFECT_OPEN_LOCK
:
4178 if( m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT
&&
4179 m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT_ITEM
)
4182 if( m_caster
->GetTypeId() != TYPEID_PLAYER
// only players can open locks, gather etc.
4183 // we need a go target in case of TARGET_GAMEOBJECT
4184 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT
&& !m_targets
.getGOTarget()
4185 // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM
4186 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT_ITEM
&& !m_targets
.getGOTarget() &&
4187 (!m_targets
.getItemTarget() || !m_targets
.getItemTarget()->GetProto()->LockID
|| m_targets
.getItemTarget()->GetOwner() != m_caster
) )
4188 return SPELL_FAILED_BAD_TARGETS
;
4190 // In BattleGround players can use only flags and banners
4191 if( ((Player
*)m_caster
)->InBattleGround() &&
4192 !((Player
*)m_caster
)->CanUseBattleGroundObject() )
4193 return SPELL_FAILED_TRY_AGAIN
;
4195 // get the lock entry
4197 if (GameObject
* go
=m_targets
.getGOTarget())
4198 lockId
= go
->GetLockId();
4199 else if(Item
* itm
=m_targets
.getItemTarget())
4200 lockId
= itm
->GetProto()->LockID
;
4202 SkillType skillId
=SKILL_NONE
;
4203 int32 reqSkillValue
= 0;
4204 int32 skillValue
= 0;
4206 // check lock compatibility
4207 SpellCastResult res
= CanOpenLock(i
,lockId
,skillId
,reqSkillValue
,skillValue
);
4208 if(res
!= SPELL_CAST_OK
)
4211 // chance for fail at orange mining/herb/LockPicking gathering attempt
4212 // second check prevent fail at rechecks
4213 if(skillId
!= SKILL_NONE
&& (!m_selfContainer
|| ((*m_selfContainer
) != this)))
4215 bool canFailAtMax
= skillId
!= SKILL_HERBALISM
&& skillId
!= SKILL_MINING
;
4217 // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill)
4218 if((canFailAtMax
|| skillValue
< sWorld
.GetConfigMaxSkillValue()) && reqSkillValue
> irand(skillValue
-25, skillValue
+37))
4219 return SPELL_FAILED_TRY_AGAIN
;
4223 case SPELL_EFFECT_SUMMON_DEAD_PET
:
4225 Creature
*pet
= m_caster
->GetPet();
4227 return SPELL_FAILED_NO_PET
;
4230 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4234 // This is generic summon effect
4235 case SPELL_EFFECT_SUMMON
:
4237 switch(m_spellInfo
->EffectMiscValueB
[i
])
4239 case SUMMON_TYPE_POSESSED
:
4240 case SUMMON_TYPE_POSESSED2
:
4241 case SUMMON_TYPE_DEMON
:
4242 case SUMMON_TYPE_SUMMON
:
4244 if(m_caster
->GetPetGUID())
4245 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4247 if(m_caster
->GetCharmGUID())
4248 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4254 // Not used for summon?
4255 case SPELL_EFFECT_SUMMON_PHANTASM
:
4257 if(m_caster
->GetPetGUID())
4258 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4260 if(m_caster
->GetCharmGUID())
4261 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4265 case SPELL_EFFECT_SUMMON_PET
:
4267 if(m_caster
->GetPetGUID()) //let warlock do a replacement summon
4270 Pet
* pet
= ((Player
*)m_caster
)->GetPet();
4272 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& m_caster
->getClass()==CLASS_WARLOCK
)
4274 if (strict
) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
4275 pet
->CastSpell(pet
, 32752, true, NULL
, NULL
, pet
->GetGUID());
4278 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4281 if(m_caster
->GetCharmGUID())
4282 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4286 case SPELL_EFFECT_SUMMON_PLAYER
:
4288 if(m_caster
->GetTypeId()!=TYPEID_PLAYER
)
4289 return SPELL_FAILED_BAD_TARGETS
;
4290 if(!((Player
*)m_caster
)->GetSelection())
4291 return SPELL_FAILED_BAD_TARGETS
;
4293 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
4294 if( !target
|| ((Player
*)m_caster
)==target
|| !target
->IsInSameRaidWith((Player
*)m_caster
) )
4295 return SPELL_FAILED_BAD_TARGETS
;
4297 // check if our map is dungeon
4298 if( sMapStore
.LookupEntry(m_caster
->GetMapId())->IsDungeon() )
4300 InstanceTemplate
const* instance
= ObjectMgr::GetInstanceTemplate(m_caster
->GetMapId());
4302 return SPELL_FAILED_TARGET_NOT_IN_INSTANCE
;
4303 if ( instance
->levelMin
> target
->getLevel() )
4304 return SPELL_FAILED_LOWLEVEL
;
4305 if ( instance
->levelMax
&& instance
->levelMax
< target
->getLevel() )
4306 return SPELL_FAILED_HIGHLEVEL
;
4310 case SPELL_EFFECT_LEAP
:
4311 case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
:
4313 float dis
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4314 float fx
= m_caster
->GetPositionX() + dis
* cos(m_caster
->GetOrientation());
4315 float fy
= m_caster
->GetPositionY() + dis
* sin(m_caster
->GetOrientation());
4316 // teleport a bit above terrain level to avoid falling below it
4317 float fz
= MapManager::Instance().GetBaseMap(m_caster
->GetMapId())->GetHeight(fx
,fy
,m_caster
->GetPositionZ(),true);
4318 if(fz
<= INVALID_HEIGHT
) // note: this also will prevent use effect in instances without vmaps height enabled
4319 return SPELL_FAILED_TRY_AGAIN
;
4321 float caster_pos_z
= m_caster
->GetPositionZ();
4322 // Control the caster to not climb or drop when +-fz > 8
4323 if(!(fz
<=caster_pos_z
+8 && fz
>=caster_pos_z
-8))
4324 return SPELL_FAILED_TRY_AGAIN
;
4326 // not allow use this effect at battleground until battleground start
4327 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
4328 if(BattleGround
const *bg
= ((Player
*)m_caster
)->GetBattleGround())
4329 if(bg
->GetStatus() != STATUS_IN_PROGRESS
)
4330 return SPELL_FAILED_TRY_AGAIN
;
4333 case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF
:
4335 if (m_targets
.getUnitTarget()==m_caster
)
4336 return SPELL_FAILED_BAD_TARGETS
;
4343 for (int i
= 0; i
< 3; ++i
)
4345 switch(m_spellInfo
->EffectApplyAuraName
[i
])
4347 case SPELL_AURA_DUMMY
:
4350 switch(m_spellInfo
->Id
)
4353 if(m_caster
->GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)m_caster
)->IsInFeralForm())
4354 return SPELL_FAILED_ONLY_SHAPESHIFT
;
4361 case SPELL_AURA_MOD_POSSESS
:
4362 case SPELL_AURA_MOD_CHARM
:
4364 if(m_caster
->GetPetGUID())
4365 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4367 if(m_caster
->GetCharmGUID())
4368 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4370 if(m_caster
->GetCharmerGUID())
4371 return SPELL_FAILED_CHARMED
;
4373 if(!m_targets
.getUnitTarget())
4374 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4376 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4377 return SPELL_FAILED_CHARMED
;
4379 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
4380 return SPELL_FAILED_HIGHLEVEL
;
4384 case SPELL_AURA_MOUNTED
:
4386 if (m_caster
->IsInWater())
4387 return SPELL_FAILED_ONLY_ABOVEWATER
;
4389 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetTransport())
4390 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4392 // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
4393 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& !sMapStore
.LookupEntry(m_caster
->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell
&& !m_spellInfo
->AreaGroupId
)
4394 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4396 ShapeshiftForm form
= m_caster
->m_form
;
4397 if( form
== FORM_CAT
|| form
== FORM_TREE
|| form
== FORM_TRAVEL
||
4398 form
== FORM_AQUA
|| form
== FORM_BEAR
|| form
== FORM_DIREBEAR
||
4399 form
== FORM_CREATUREBEAR
|| form
== FORM_GHOSTWOLF
|| form
== FORM_FLIGHT
||
4400 form
== FORM_FLIGHT_EPIC
|| form
== FORM_MOONKIN
|| form
== FORM_METAMORPHOSIS
)
4401 return SPELL_FAILED_NOT_SHAPESHIFT
;
4405 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
4407 if(!m_targets
.getUnitTarget())
4408 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4410 // can be casted at non-friendly unit or own pet/charm
4411 if(m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()))
4412 return SPELL_FAILED_TARGET_FRIENDLY
;
4416 case SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
:
4417 case SPELL_AURA_FLY
:
4419 // not allow cast fly spells at old maps by players (all spells is self target)
4420 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
4422 if( !((Player
*)m_caster
)->IsAllowUseFlyMountsHere() )
4423 return SPELL_FAILED_NOT_HERE
;
4428 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4430 if (!m_targets
.getUnitTarget())
4431 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4433 if (m_caster
->GetTypeId()!=TYPEID_PLAYER
|| m_CastItem
)
4436 if(m_targets
.getUnitTarget()->getPowerType()!=POWER_MANA
)
4437 return SPELL_FAILED_BAD_TARGETS
;
4447 return SPELL_CAST_OK
;
4450 SpellCastResult
Spell::CheckPetCast(Unit
* target
)
4452 if(!m_caster
->isAlive())
4453 return SPELL_FAILED_CASTER_DEAD
;
4455 if(m_caster
->IsNonMeleeSpellCasted(false)) //prevent spellcast interruption by another spellcast
4456 return SPELL_FAILED_SPELL_IN_PROGRESS
;
4457 if(m_caster
->isInCombat() && IsNonCombatSpell(m_spellInfo
))
4458 return SPELL_FAILED_AFFECTING_COMBAT
;
4460 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)m_caster
)->isPet() || m_caster
->isCharmed()))
4462 //dead owner (pets still alive when owners ressed?)
4463 if(m_caster
->GetCharmerOrOwner() && !m_caster
->GetCharmerOrOwner()->isAlive())
4464 return SPELL_FAILED_CASTER_DEAD
;
4466 if(!target
&& m_targets
.getUnitTarget())
4467 target
= m_targets
.getUnitTarget();
4470 for(uint32 i
= 0;i
<3;++i
)
4472 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
)
4476 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4481 m_targets
.setUnitTarget(target
);
4483 Unit
* _target
= m_targets
.getUnitTarget();
4485 if(_target
) //for target dead/target not valid
4487 if(!_target
->isAlive())
4488 return SPELL_FAILED_BAD_TARGETS
;
4490 if(IsPositiveSpell(m_spellInfo
->Id
))
4492 if(m_caster
->IsHostileTo(_target
))
4493 return SPELL_FAILED_BAD_TARGETS
;
4497 bool duelvsplayertar
= false;
4498 for(int j
=0;j
<3;j
++)
4500 //TARGET_DUELVSPLAYER is positive AND negative
4501 duelvsplayertar
|= (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
);
4503 if(m_caster
->IsFriendlyTo(target
) && !duelvsplayertar
)
4505 return SPELL_FAILED_BAD_TARGETS
;
4510 if(((Creature
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
4511 return SPELL_FAILED_NOT_READY
;
4514 return CheckCast(true);
4517 SpellCastResult
Spell::CheckCasterAuras() const
4519 // Flag drop spells totally immuned to caster auras
4520 // FIXME: find more nice check for all totally immuned spells
4521 // AttributesEx3 & 0x10000000?
4522 if(m_spellInfo
->Id
==23336 || m_spellInfo
->Id
==23334 || m_spellInfo
->Id
==34991)
4523 return SPELL_CAST_OK
;
4525 uint8 school_immune
= 0;
4526 uint32 mechanic_immune
= 0;
4527 uint32 dispel_immune
= 0;
4529 //Check if the spell grants school or mechanic immunity.
4530 //We use bitmasks so the loop is done only once and not on every aura check below.
4531 if ( m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
4533 for(int i
= 0;i
< 3; i
++)
4535 if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_SCHOOL_IMMUNITY
)
4536 school_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
4537 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY
)
4538 mechanic_immune
|= 1 << uint32(m_spellInfo
->EffectMiscValue
[i
]);
4539 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_DISPEL_IMMUNITY
)
4540 dispel_immune
|= GetDispellMask(DispelType(m_spellInfo
->EffectMiscValue
[i
]));
4542 //immune movement impairment and loss of control
4543 if(m_spellInfo
->Id
==(uint32
)42292)
4544 mechanic_immune
= IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK
;
4547 //Check whether the cast should be prevented by any state you might have.
4548 SpellCastResult prevented_reason
= SPELL_CAST_OK
;
4549 // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
4550 uint32 unitflag
= m_caster
->GetUInt32Value(UNIT_FIELD_FLAGS
); // Get unit state
4551 if(unitflag
& UNIT_FLAG_STUNNED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4552 prevented_reason
= SPELL_FAILED_STUNNED
;
4553 else if(unitflag
& UNIT_FLAG_CONFUSED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4554 prevented_reason
= SPELL_FAILED_CONFUSED
;
4555 else if(unitflag
& UNIT_FLAG_FLEEING
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4556 prevented_reason
= SPELL_FAILED_FLEEING
;
4557 else if(unitflag
& UNIT_FLAG_SILENCED
&& m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_SILENCE
)
4558 prevented_reason
= SPELL_FAILED_SILENCED
;
4559 else if(unitflag
& UNIT_FLAG_PACIFIED
&& m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_PACIFY
)
4560 prevented_reason
= SPELL_FAILED_PACIFIED
;
4562 // Attr must make flag drop spell totally immune from all effects
4563 if(prevented_reason
!= SPELL_CAST_OK
)
4565 if(school_immune
|| mechanic_immune
|| dispel_immune
)
4567 //Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
4568 Unit::AuraMap
const& auras
= m_caster
->GetAuras();
4569 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
4573 if( GetSpellMechanicMask(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()) & mechanic_immune
)
4575 if( GetSpellSchoolMask(itr
->second
->GetSpellProto()) & school_immune
)
4577 if( (1<<(itr
->second
->GetSpellProto()->Dispel
)) & dispel_immune
)
4580 //Make a second check for spell failed so the right SPELL_FAILED message is returned.
4581 //That is needed when your casting is prevented by multiple states and you are only immune to some of them.
4582 switch(itr
->second
->GetModifier()->m_auraname
)
4584 case SPELL_AURA_MOD_STUN
:
4585 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4586 return SPELL_FAILED_STUNNED
;
4588 case SPELL_AURA_MOD_CONFUSE
:
4589 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4590 return SPELL_FAILED_CONFUSED
;
4592 case SPELL_AURA_MOD_FEAR
:
4593 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4594 return SPELL_FAILED_FLEEING
;
4596 case SPELL_AURA_MOD_SILENCE
:
4597 case SPELL_AURA_MOD_PACIFY
:
4598 case SPELL_AURA_MOD_PACIFY_SILENCE
:
4599 if( m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_PACIFY
)
4600 return SPELL_FAILED_PACIFIED
;
4601 else if ( m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_SILENCE
)
4602 return SPELL_FAILED_SILENCED
;
4608 //You are prevented from casting and the spell casted does not grant immunity. Return a failed error.
4610 return prevented_reason
;
4612 return SPELL_CAST_OK
;
4615 bool Spell::CanAutoCast(Unit
* target
)
4617 uint64 targetguid
= target
->GetGUID();
4619 for(uint32 j
= 0;j
<3;j
++)
4621 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
)
4623 if( m_spellInfo
->StackAmount
<= 1)
4625 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4630 if( target
->GetAuras().count(Unit::spellEffectPair(m_spellInfo
->Id
, j
)) >= m_spellInfo
->StackAmount
)
4634 else if ( IsAreaAuraEffect( m_spellInfo
->Effect
[j
] ))
4636 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4641 SpellCastResult result
= CheckPetCast(target
);
4643 if(result
== SPELL_CAST_OK
|| result
== SPELL_FAILED_UNIT_NOT_INFRONT
)
4646 //check if among target units, our WANTED target is as well (->only self cast spells return false)
4647 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
4648 if( ihit
->targetGUID
== targetguid
)
4651 return false; //target invalid
4654 SpellCastResult
Spell::CheckRange(bool strict
)
4658 // self cast doesn't need range checking -- also for Starshards fix
4659 if (m_spellInfo
->rangeIndex
== 1)
4660 return SPELL_CAST_OK
;
4662 if (strict
) //add radius of caster
4664 else //add radius of caster and ~5 yds "give"
4667 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4668 float max_range
= GetSpellMaxRange(srange
) + range_mod
;
4669 float min_range
= GetSpellMinRange(srange
);
4671 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4672 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RANGE
, max_range
, this);
4674 Unit
*target
= m_targets
.getUnitTarget();
4676 if(target
&& target
!= m_caster
)
4678 // distance from target in checks
4679 float dist
= m_caster
->GetCombatDistance(target
);
4681 if(dist
> max_range
)
4682 return SPELL_FAILED_OUT_OF_RANGE
; //0x5A;
4683 if(dist
< min_range
)
4684 return SPELL_FAILED_TOO_CLOSE
;
4685 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&&
4686 (m_spellInfo
->FacingCasterFlags
& SPELL_FACING_FLAG_INFRONT
) && !m_caster
->HasInArc( M_PI
, target
) )
4687 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4690 if(m_targets
.m_targetMask
== TARGET_FLAG_DEST_LOCATION
&& m_targets
.m_destX
!= 0 && m_targets
.m_destY
!= 0 && m_targets
.m_destZ
!= 0)
4692 if(!m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
,max_range
))
4693 return SPELL_FAILED_OUT_OF_RANGE
;
4694 if(m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
,min_range
))
4695 return SPELL_FAILED_TOO_CLOSE
;
4698 return SPELL_CAST_OK
;
4701 int32
Spell::CalculatePowerCost()
4703 // item cast not used power
4707 // Spell drain all exist power on cast (Only paladin lay of Hands)
4708 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DRAIN_ALL_POWER
)
4710 // If power type - health drain all
4711 if (m_spellInfo
->powerType
== POWER_HEALTH
)
4712 return m_caster
->GetHealth();
4713 // Else drain all power
4714 if (m_spellInfo
->powerType
< MAX_POWERS
)
4715 return m_caster
->GetPower(Powers(m_spellInfo
->powerType
));
4716 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4721 int32 powerCost
= m_spellInfo
->manaCost
;
4722 // PCT cost from total amount
4723 if (m_spellInfo
->ManaCostPercentage
)
4725 switch (m_spellInfo
->powerType
)
4727 // health as power used
4729 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateHealth() / 100;
4732 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateMana() / 100;
4737 case POWER_HAPPINESS
:
4738 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetMaxPower(Powers(m_spellInfo
->powerType
)) / 100;
4741 case POWER_RUNIC_POWER
:
4742 sLog
.outDebug("Spell::CalculateManaCost: Not implemented yet!");
4745 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4749 SpellSchools school
= GetFirstSchoolInMask(m_spellSchoolMask
);
4750 // Flat mod from caster auras by spell school
4751 powerCost
+= m_caster
->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER
+ school
);
4752 // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
4753 if ( m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST
)
4754 powerCost
+= m_caster
->GetAttackTime(OFF_ATTACK
)/100;
4755 // Apply cost mod by spell
4756 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4757 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, powerCost
, this);
4759 if(m_spellInfo
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
)
4760 powerCost
= int32(powerCost
/ (1.117f
* m_spellInfo
->spellLevel
/ m_caster
->getLevel() -0.1327f
));
4762 // PCT mod from user auras by school
4763 powerCost
= int32(powerCost
* (1.0f
+m_caster
->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+school
)));
4769 SpellCastResult
Spell::CheckPower()
4771 // item cast not used power
4773 return SPELL_CAST_OK
;
4775 // health as power used - need check health amount
4776 if(m_spellInfo
->powerType
== POWER_HEALTH
)
4778 if(m_caster
->GetHealth() <= m_powerCost
)
4779 return SPELL_FAILED_CASTER_AURASTATE
;
4780 return SPELL_CAST_OK
;
4782 // Check valid power type
4783 if( m_spellInfo
->powerType
>= MAX_POWERS
)
4785 sLog
.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo
->powerType
);
4786 return SPELL_FAILED_UNKNOWN
;
4789 SpellCastResult failReason
= CheckRuneCost(m_spellInfo
->runeCostID
);
4790 if(failReason
!= SPELL_CAST_OK
)
4793 // Check power amount
4794 Powers powerType
= Powers(m_spellInfo
->powerType
);
4795 if(m_caster
->GetPower(powerType
) < m_powerCost
)
4796 return SPELL_FAILED_NO_POWER
;
4798 return SPELL_CAST_OK
;
4801 SpellCastResult
Spell::CheckItems()
4803 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4804 return SPELL_CAST_OK
;
4806 Player
* p_caster
= (Player
*)m_caster
;
4811 uint32 itemid
= m_CastItem
->GetEntry();
4812 if( !p_caster
->HasItemCount(itemid
,1) )
4813 return SPELL_FAILED_ITEM_NOT_READY
;
4815 ItemPrototype
const *proto
= m_CastItem
->GetProto();
4817 return SPELL_FAILED_ITEM_NOT_READY
;
4819 for (int i
= 0; i
<5; ++i
)
4820 if (proto
->Spells
[i
].SpellCharges
)
4821 if(m_CastItem
->GetSpellCharges(i
)==0)
4822 return SPELL_FAILED_NO_CHARGES_REMAIN
;
4824 // consumable cast item checks
4825 if (proto
->Class
== ITEM_CLASS_CONSUMABLE
&& m_targets
.getUnitTarget())
4827 // such items should only fail if there is no suitable effect at all - see Rejuvenation Potions for example
4828 SpellCastResult failReason
= SPELL_CAST_OK
;
4829 for (int i
= 0; i
< 3; ++i
)
4831 // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster
4832 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_PET
)
4835 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_HEAL
)
4837 if (m_targets
.getUnitTarget()->GetHealth() == m_targets
.getUnitTarget()->GetMaxHealth())
4839 failReason
= SPELL_FAILED_ALREADY_AT_FULL_HEALTH
;
4844 failReason
= SPELL_CAST_OK
;
4849 // Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
4850 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
4852 if(m_spellInfo
->EffectMiscValue
[i
] < 0 || m_spellInfo
->EffectMiscValue
[i
] >= MAX_POWERS
)
4854 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
4858 Powers power
= Powers(m_spellInfo
->EffectMiscValue
[i
]);
4859 if (m_targets
.getUnitTarget()->GetPower(power
) == m_targets
.getUnitTarget()->GetMaxPower(power
))
4861 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
4866 failReason
= SPELL_CAST_OK
;
4871 if (failReason
!= SPELL_CAST_OK
)
4876 // check target item
4877 if(m_targets
.getItemTargetGUID())
4879 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4880 return SPELL_FAILED_BAD_TARGETS
;
4882 if(!m_targets
.getItemTarget())
4883 return SPELL_FAILED_ITEM_GONE
;
4885 if(!m_targets
.getItemTarget()->IsFitToSpellRequirements(m_spellInfo
))
4886 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
4888 // if not item target then required item must be equipped
4891 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !((Player
*)m_caster
)->HasItemFitToSpellReqirements(m_spellInfo
))
4892 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
4895 // check spell focus object
4896 if(m_spellInfo
->RequiresSpellFocus
)
4898 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4900 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4902 GameObject
* ok
= NULL
;
4903 MaNGOS::GameObjectFocusCheck
go_check(m_caster
,m_spellInfo
->RequiresSpellFocus
);
4904 MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
> checker(m_caster
,ok
,go_check
);
4906 TypeContainerVisitor
<MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
>, GridTypeMapContainer
> object_checker(checker
);
4907 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4908 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
4911 return SPELL_FAILED_REQUIRES_SPELL_FOCUS
;
4913 focusObject
= ok
; // game object found in range
4916 // check reagents (ignore triggered spells with reagents processed by original spell) and special reagent ignore case.
4917 if (!m_IsTriggeredSpell
&& !p_caster
->CanNoReagentCast(m_spellInfo
))
4919 for(uint32 i
=0;i
<8;++i
)
4921 if(m_spellInfo
->Reagent
[i
] <= 0)
4924 uint32 itemid
= m_spellInfo
->Reagent
[i
];
4925 uint32 itemcount
= m_spellInfo
->ReagentCount
[i
];
4927 // if CastItem is also spell reagent
4928 if( m_CastItem
&& m_CastItem
->GetEntry() == itemid
)
4930 ItemPrototype
const *proto
= m_CastItem
->GetProto();
4932 return SPELL_FAILED_ITEM_NOT_READY
;
4933 for(int s
=0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
4935 // CastItem will be used up and does not count as reagent
4936 int32 charges
= m_CastItem
->GetSpellCharges(s
);
4937 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
4944 if( !p_caster
->HasItemCount(itemid
,itemcount
) )
4945 return SPELL_FAILED_ITEM_NOT_READY
; //0x54
4949 // check totem-item requirements (items presence in inventory)
4951 for(int i
=0;i
<2;++i
)
4953 if(m_spellInfo
->Totem
[i
] != 0)
4955 if( p_caster
->HasItemCount(m_spellInfo
->Totem
[i
],1) )
4964 return SPELL_FAILED_TOTEMS
; //0x7C
4966 // Check items for TotemCategory (items presence in inventory)
4967 uint32 TotemCategory
= 2;
4968 for(int i
=0;i
<2;++i
)
4970 if(m_spellInfo
->TotemCategory
[i
] != 0)
4972 if( p_caster
->HasItemTotemCategory(m_spellInfo
->TotemCategory
[i
]) )
4981 if(TotemCategory
!= 0)
4982 return SPELL_FAILED_TOTEM_CATEGORY
; //0x7B
4984 // special checks for spell effects
4985 for(int i
= 0; i
< 3; ++i
)
4987 switch (m_spellInfo
->Effect
[i
])
4989 case SPELL_EFFECT_CREATE_ITEM
:
4991 if (!m_IsTriggeredSpell
&& m_spellInfo
->EffectItemType
[i
])
4993 ItemPosCountVec dest
;
4994 uint8 msg
= p_caster
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, m_spellInfo
->EffectItemType
[i
], 1 );
4995 if (msg
!= EQUIP_ERR_OK
)
4997 p_caster
->SendEquipError( msg
, NULL
, NULL
);
4998 return SPELL_FAILED_DONT_REPORT
;
5003 case SPELL_EFFECT_ENCHANT_ITEM
:
5004 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
5006 Item
* targetItem
= m_targets
.getItemTarget();
5008 return SPELL_FAILED_ITEM_NOT_FOUND
;
5010 if( targetItem
->GetProto()->ItemLevel
< m_spellInfo
->baseLevel
)
5011 return SPELL_FAILED_LOWLEVEL
;
5012 // Not allow enchant in trade slot for some enchant type
5013 if( targetItem
->GetOwner() != m_caster
)
5015 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5016 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5018 return SPELL_FAILED_ERROR
;
5019 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5020 return SPELL_FAILED_NOT_TRADEABLE
;
5024 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
5026 Item
*item
= m_targets
.getItemTarget();
5028 return SPELL_FAILED_ITEM_NOT_FOUND
;
5029 // Not allow enchant in trade slot for some enchant type
5030 if( item
->GetOwner() != m_caster
)
5032 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5033 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5035 return SPELL_FAILED_ERROR
;
5036 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5037 return SPELL_FAILED_NOT_TRADEABLE
;
5041 case SPELL_EFFECT_ENCHANT_HELD_ITEM
:
5042 // check item existence in effect code (not output errors at offhand hold item effect to main hand for example
5044 case SPELL_EFFECT_DISENCHANT
:
5046 if(!m_targets
.getItemTarget())
5047 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5049 // prevent disenchanting in trade slot
5050 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5051 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5053 ItemPrototype
const* itemProto
= m_targets
.getItemTarget()->GetProto();
5055 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5057 uint32 item_quality
= itemProto
->Quality
;
5058 // 2.0.x addon: Check player enchanting level against the item disenchanting requirements
5059 uint32 item_disenchantskilllevel
= itemProto
->RequiredDisenchantSkill
;
5060 if (item_disenchantskilllevel
== uint32(-1))
5061 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5062 if (item_disenchantskilllevel
> p_caster
->GetSkillValue(SKILL_ENCHANTING
))
5063 return SPELL_FAILED_LOW_CASTLEVEL
;
5064 if(item_quality
> 4 || item_quality
< 2)
5065 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5066 if(itemProto
->Class
!= ITEM_CLASS_WEAPON
&& itemProto
->Class
!= ITEM_CLASS_ARMOR
)
5067 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5068 if (!itemProto
->DisenchantID
)
5069 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5072 case SPELL_EFFECT_PROSPECTING
:
5074 if(!m_targets
.getItemTarget())
5075 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5076 //ensure item is a prospectable ore
5077 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_MINING_SUPP
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5078 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5079 //prevent prospecting in trade slot
5080 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5081 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5082 //Check for enough skill in jewelcrafting
5083 uint32 item_prospectingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5084 if(item_prospectingskilllevel
>p_caster
->GetSkillValue(SKILL_JEWELCRAFTING
))
5085 return SPELL_FAILED_LOW_CASTLEVEL
;
5086 //make sure the player has the required ores in inventory
5087 if(m_targets
.getItemTarget()->GetCount() < 5)
5088 return SPELL_FAILED_NEED_MORE_ITEMS
;
5090 if(!LootTemplates_Prospecting
.HaveLootFor(m_targets
.getItemTargetEntry()))
5091 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5095 case SPELL_EFFECT_MILLING
:
5097 if(!m_targets
.getItemTarget())
5098 return SPELL_FAILED_CANT_BE_MILLED
;
5099 //ensure item is a millable herb
5100 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_HERBS
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5101 return SPELL_FAILED_CANT_BE_MILLED
;
5102 //prevent milling in trade slot
5103 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5104 return SPELL_FAILED_CANT_BE_MILLED
;
5105 //Check for enough skill in inscription
5106 uint32 item_millingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5107 if(item_millingskilllevel
>p_caster
->GetSkillValue(SKILL_INSCRIPTION
))
5108 return SPELL_FAILED_LOW_CASTLEVEL
;
5109 //make sure the player has the required herbs in inventory
5110 if(m_targets
.getItemTarget()->GetCount() < 5)
5111 return SPELL_FAILED_NEED_MORE_ITEMS
;
5113 if(!LootTemplates_Milling
.HaveLootFor(m_targets
.getItemTargetEntry()))
5114 return SPELL_FAILED_CANT_BE_MILLED
;
5118 case SPELL_EFFECT_WEAPON_DAMAGE
:
5119 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
:
5121 if(m_caster
->GetTypeId() != TYPEID_PLAYER
) return SPELL_FAILED_TARGET_NOT_PLAYER
;
5122 if( m_attackType
!= RANGED_ATTACK
)
5124 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(m_attackType
);
5125 if(!pItem
|| pItem
->IsBroken())
5126 return SPELL_FAILED_EQUIPPED_ITEM
;
5128 switch(pItem
->GetProto()->SubClass
)
5130 case ITEM_SUBCLASS_WEAPON_THROWN
:
5132 uint32 ammo
= pItem
->GetEntry();
5133 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5134 return SPELL_FAILED_NO_AMMO
;
5136 case ITEM_SUBCLASS_WEAPON_GUN
:
5137 case ITEM_SUBCLASS_WEAPON_BOW
:
5138 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5140 uint32 ammo
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
5144 if(m_caster
->GetDummyAura(46699))
5145 break; // skip other checks
5147 return SPELL_FAILED_NO_AMMO
;
5150 ItemPrototype
const *ammoProto
= objmgr
.GetItemPrototype( ammo
);
5152 return SPELL_FAILED_NO_AMMO
;
5154 if(ammoProto
->Class
!= ITEM_CLASS_PROJECTILE
)
5155 return SPELL_FAILED_NO_AMMO
;
5157 // check ammo ws. weapon compatibility
5158 switch(pItem
->GetProto()->SubClass
)
5160 case ITEM_SUBCLASS_WEAPON_BOW
:
5161 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5162 if(ammoProto
->SubClass
!=ITEM_SUBCLASS_ARROW
)
5163 return SPELL_FAILED_NO_AMMO
;
5165 case ITEM_SUBCLASS_WEAPON_GUN
:
5166 if(ammoProto
->SubClass
!=ITEM_SUBCLASS_BULLET
)
5167 return SPELL_FAILED_NO_AMMO
;
5170 return SPELL_FAILED_NO_AMMO
;
5173 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5174 return SPELL_FAILED_NO_AMMO
;
5176 case ITEM_SUBCLASS_WEAPON_WAND
:
5186 return SPELL_CAST_OK
;
5189 void Spell::Delayed()
5191 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
5194 if (m_spellState
== SPELL_STATE_DELAYED
)
5195 return; // spell is active and can't be time-backed
5197 if(isDelayableNoMore()) // Spells may only be delayed twice
5200 // spells not loosing casting time ( slam, dynamites, bombs.. )
5201 if(!(m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_DAMAGE
))
5204 //check pushback reduce
5205 int32 delaytime
= 500; // spellcasting delay is normally 500ms
5206 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5207 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
,SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5208 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5209 if(delayReduce
>= 100)
5212 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5214 if(int32(m_timer
) + delaytime
> m_casttime
)
5216 delaytime
= m_casttime
- m_timer
;
5217 m_timer
= m_casttime
;
5220 m_timer
+= delaytime
;
5222 sLog
.outDetail("Spell %u partially interrupted for (%d) ms at damage",m_spellInfo
->Id
,delaytime
);
5224 WorldPacket
data(SMSG_SPELL_DELAYED
, 8+4);
5225 data
.append(m_caster
->GetPackGUID());
5226 data
<< uint32(delaytime
);
5228 m_caster
->SendMessageToSet(&data
,true);
5231 void Spell::DelayedChannel()
5233 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
|| getState() != SPELL_STATE_CASTING
)
5236 if(isDelayableNoMore()) // Spells may only be delayed twice
5239 //check pushback reduce
5240 int32 delaytime
= GetSpellDuration(m_spellInfo
) * 25 / 100; // channeling delay is normally 25% of its time per hit
5241 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5242 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
,SPELLMOD_NOT_LOSE_CASTING_TIME
,delayReduce
, this);
5243 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5244 if(delayReduce
>= 100)
5247 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5249 if(int32(m_timer
) < delaytime
)
5251 delaytime
= m_timer
;
5255 m_timer
-= delaytime
;
5257 sLog
.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo
->Id
, delaytime
, m_timer
);
5259 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
5261 if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
5263 Unit
* unit
= m_caster
->GetGUID()==ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
5266 for (int j
=0;j
<3;j
++)
5267 if( ihit
->effectMask
& (1<<j
) )
5268 unit
->DelayAura(m_spellInfo
->Id
, j
, delaytime
);
5274 for(int j
= 0; j
< 3; j
++)
5276 // partially interrupt persistent area auras
5277 DynamicObject
* dynObj
= m_caster
->GetDynObject(m_spellInfo
->Id
, j
);
5279 dynObj
->Delay(delaytime
);
5282 SendChannelUpdate(m_timer
);
5285 void Spell::UpdatePointers()
5287 if(m_originalCasterGUID
==m_caster
->GetGUID())
5288 m_originalCaster
= m_caster
;
5291 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
,m_originalCasterGUID
);
5292 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
5295 m_targets
.Update(m_caster
);
5298 bool Spell::IsAffectedByAura(Aura
*aura
)
5300 return spellmgr
.IsAffectedByMod(m_spellInfo
, aura
->getAuraSpellMod());
5303 bool Spell::CheckTargetCreatureType(Unit
* target
) const
5305 uint32 spellCreatureTargetMask
= m_spellInfo
->TargetCreatureType
;
5307 // Curse of Doom : not find another way to fix spell target check :/
5308 if(m_spellInfo
->SpellFamilyName
==SPELLFAMILY_WARLOCK
&& m_spellInfo
->SpellFamilyFlags
== 0x0200000000LL
)
5310 // not allow cast at player
5311 if(target
->GetTypeId()==TYPEID_PLAYER
)
5314 spellCreatureTargetMask
= 0x7FF;
5317 // Dismiss Pet and Taming Lesson skipped
5318 if(m_spellInfo
->Id
== 2641 || m_spellInfo
->Id
== 23356)
5319 spellCreatureTargetMask
= 0;
5321 if (spellCreatureTargetMask
)
5323 uint32 TargetCreatureType
= target
->GetCreatureTypeMask();
5325 return !TargetCreatureType
|| (spellCreatureTargetMask
& TargetCreatureType
);
5330 CurrentSpellTypes
Spell::GetCurrentContainer()
5332 if (IsNextMeleeSwingSpell())
5333 return(CURRENT_MELEE_SPELL
);
5334 else if (IsAutoRepeat())
5335 return(CURRENT_AUTOREPEAT_SPELL
);
5336 else if (IsChanneledSpell(m_spellInfo
))
5337 return(CURRENT_CHANNELED_SPELL
);
5339 return(CURRENT_GENERIC_SPELL
);
5342 bool Spell::CheckTarget( Unit
* target
, uint32 eff
)
5344 // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets)
5345 if(m_spellInfo
->EffectImplicitTargetA
[eff
]!=TARGET_SELF
)
5347 if (!CheckTargetCreatureType(target
))
5351 // Check Aura spell req (need for AoE spells)
5352 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
5354 if (m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
5357 // Check targets for not_selectable unit flag and remove
5358 // A player can cast spells on his pet (or other controlled unit) though in any state
5359 if (target
!= m_caster
&& target
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
5361 // any unattackable target skipped
5362 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
))
5365 // unselectable targets skipped in all cases except TARGET_SCRIPT targeting
5366 // in case TARGET_SCRIPT target selected by server always and can't be cheated
5367 if( target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NOT_SELECTABLE
) &&
5368 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SCRIPT
&&
5369 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_SCRIPT
)
5373 //Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
5374 if( target
!= m_caster
&& target
->GetTypeId()==TYPEID_PLAYER
)
5376 if(((Player
*)target
)->GetVisibility()==VISIBILITY_OFF
)
5379 if(((Player
*)target
)->isGameMaster() && !IsPositiveSpell(m_spellInfo
->Id
))
5383 //Check targets for LOS visibility (except spells without range limitations )
5384 switch(m_spellInfo
->Effect
[eff
])
5386 case SPELL_EFFECT_SUMMON_PLAYER
: // from anywhere
5388 case SPELL_EFFECT_DUMMY
:
5389 if(m_spellInfo
->Id
!=20577) // Cannibalize
5392 case SPELL_EFFECT_RESURRECT_NEW
:
5393 // player far away, maybe his corpse near?
5394 if(target
!=m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
5396 if(!m_targets
.getCorpseTargetGUID())
5399 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
5403 if(target
->GetGUID()!=corpse
->GetOwnerGUID())
5406 if(!corpse
->IsWithinLOSInMap(m_caster
))
5410 // all ok by some way or another, skip normal check
5412 default: // normal case
5413 // Get GO cast coordinates if original caster -> GO
5414 WorldObject
*caster
= NULL
;
5415 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
5416 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
5419 if(target
!=m_caster
&& !target
->IsWithinLOSInMap(caster
))
5427 bool Spell::IsNeedSendToClient() const
5429 return m_spellInfo
->SpellVisual
[0] || m_spellInfo
->SpellVisual
[1] || IsChanneledSpell(m_spellInfo
) ||
5430 m_spellInfo
->speed
> 0.0f
|| !m_triggeredByAuraSpell
&& !m_IsTriggeredSpell
;
5433 bool Spell::HaveTargetsForEffect( uint8 effect
) const
5435 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin();itr
!= m_UniqueTargetInfo
.end();++itr
)
5436 if(itr
->effectMask
& (1<<effect
))
5439 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin();itr
!= m_UniqueGOTargetInfo
.end();++itr
)
5440 if(itr
->effectMask
& (1<<effect
))
5443 for(std::list
<ItemTargetInfo
>::const_iterator itr
= m_UniqueItemInfo
.begin();itr
!= m_UniqueItemInfo
.end();++itr
)
5444 if(itr
->effectMask
& (1<<effect
))
5450 SpellEvent::SpellEvent(Spell
* spell
) : BasicEvent()
5455 SpellEvent::~SpellEvent()
5457 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5460 if (m_Spell
->IsDeletable())
5466 sLog
.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
5467 (m_Spell
->GetCaster()->GetTypeId()==TYPEID_PLAYER
?"Player":"Creature"), m_Spell
->GetCaster()->GetGUIDLow(),m_Spell
->m_spellInfo
->Id
);
5471 bool SpellEvent::Execute(uint64 e_time
, uint32 p_time
)
5473 // update spell if it is not finished
5474 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5475 m_Spell
->update(p_time
);
5477 // check spell state to process
5478 switch (m_Spell
->getState())
5480 case SPELL_STATE_FINISHED
:
5482 // spell was finished, check deletable state
5483 if (m_Spell
->IsDeletable())
5485 // check, if we do have unfinished triggered spells
5487 return(true); // spell is deletable, finish event
5489 // event will be re-added automatically at the end of routine)
5492 case SPELL_STATE_CASTING
:
5494 // this spell is in channeled state, process it on the next update
5495 // event will be re-added automatically at the end of routine)
5498 case SPELL_STATE_DELAYED
:
5500 // first, check, if we have just started
5501 if (m_Spell
->GetDelayStart() != 0)
5503 // no, we aren't, do the typical update
5504 // check, if we have channeled spell on our hands
5505 if (IsChanneledSpell(m_Spell
->m_spellInfo
))
5507 // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish
5508 // check, if we have casting anything else except this channeled spell and autorepeat
5509 if (m_Spell
->GetCaster()->IsNonMeleeSpellCasted(false, true, true))
5511 // another non-melee non-delayed spell is casted now, abort
5516 // do the action (pass spell to channeling state)
5517 m_Spell
->handle_immediate();
5519 // event will be re-added automatically at the end of routine)
5523 // run the spell handler and think about what we can do next
5524 uint64 t_offset
= e_time
- m_Spell
->GetDelayStart();
5525 uint64 n_offset
= m_Spell
->handle_delayed(t_offset
);
5528 // re-add us to the queue
5529 m_Spell
->GetCaster()->m_Events
.AddEvent(this, m_Spell
->GetDelayStart() + n_offset
, false);
5530 return(false); // event not complete
5533 // finish update event will be re-added automatically at the end of routine)
5538 // delaying had just started, record the moment
5539 m_Spell
->SetDelayStart(e_time
);
5540 // re-plan the event for the delay moment
5541 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ m_Spell
->GetDelayMoment(), false);
5542 return(false); // event not complete
5549 // event will be re-added automatically at the end of routine)
5553 // spell processing not complete, plan event on the next update interval
5554 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ 1, false);
5555 return(false); // event not complete
5558 void SpellEvent::Abort(uint64
/*e_time*/)
5560 // oops, the spell we try to do is aborted
5561 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5565 bool SpellEvent::IsDeletable() const
5567 return m_Spell
->IsDeletable();
5570 SpellCastResult
Spell::CanOpenLock(uint32 effIndex
, uint32 lockId
, SkillType
& skillId
, int32
& reqSkillValue
, int32
& skillValue
)
5572 if(!lockId
) // possible case for GO and maybe for items.
5573 return SPELL_CAST_OK
;
5576 LockEntry
const *lockInfo
= sLockStore
.LookupEntry(lockId
);
5579 return SPELL_FAILED_BAD_TARGETS
;
5581 bool reqKey
= false; // some locks not have reqs
5583 for(int j
= 0; j
< 8; ++j
)
5585 switch(lockInfo
->Type
[j
])
5587 // check key item (many fit cases can be)
5589 if(lockInfo
->Index
[j
] && m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->Index
[j
])
5590 return SPELL_CAST_OK
;
5593 // check key skill (only single first fit case can be)
5594 case LOCK_KEY_SKILL
:
5598 // wrong locktype, skip
5599 if(uint32(m_spellInfo
->EffectMiscValue
[effIndex
]) != lockInfo
->Index
[j
])
5602 skillId
= SkillByLockType(LockType(lockInfo
->Index
[j
]));
5604 if ( skillId
!= SKILL_NONE
)
5606 // skill bonus provided by casting spell (mostly item spells)
5607 // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value)
5608 uint32 spellSkillBonus
= uint32(m_currentBasePoints
[effIndex
]+1);
5609 reqSkillValue
= lockInfo
->Skill
[j
];
5611 // castitem check: rogue using skeleton keys. the skill values should not be added in this case.
5612 skillValue
= m_CastItem
|| m_caster
->GetTypeId()!= TYPEID_PLAYER
?
5613 0 : ((Player
*)m_caster
)->GetSkillValue(skillId
);
5615 skillValue
+= spellSkillBonus
;
5617 if (skillValue
< reqSkillValue
)
5618 return SPELL_FAILED_LOW_CASTLEVEL
;
5621 return SPELL_CAST_OK
;
5627 return SPELL_FAILED_BAD_TARGETS
;
5629 return SPELL_CAST_OK
;
5632 void Spell::FillAreaTargets( UnitList
& TagUnitMap
, float x
, float y
, float radius
, SpellNotifyPushType pushType
, SpellTargets spellTargets
)
5634 CellPair
p(MaNGOS::ComputeCellPair(x
, y
));
5636 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5638 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, pushType
, spellTargets
);
5639 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
5640 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
5641 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5642 cell_lock
->Visit(cell_lock
, world_notifier
, *m_caster
->GetMap());
5643 cell_lock
->Visit(cell_lock
, grid_notifier
, *m_caster
->GetMap());