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;
426 void Spell::FillTargetMap()
428 // TODO: ADD the correct target FILLS!!!!!!
430 for(uint32 i
=0;i
<3;++i
)
432 // not call for empty effect.
433 // Also some spells use not used effect targets for store targets for dummy effect in triggered spells
434 if(m_spellInfo
->Effect
[i
]==0)
437 // targets for TARGET_SCRIPT_COORDINATES (A) and TARGET_SCRIPT filled in Spell::CheckCast call
438 if( m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT_COORDINATES
||
439 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT
||
440 m_spellInfo
->EffectImplicitTargetB
[i
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
)
443 // TODO: find a way so this is not needed?
444 // for area auras always add caster as target (needed for totems for example)
445 if(IsAreaAuraEffect(m_spellInfo
->Effect
[i
]))
446 AddUnitTarget(m_caster
, i
);
448 std::list
<Unit
*> tmpUnitMap
;
450 // TargetA/TargetB dependent from each other, we not switch to full support this dependences
451 // but need it support in some know cases
452 switch(m_spellInfo
->EffectImplicitTargetA
[i
])
455 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
458 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
460 case TARGET_AREAEFFECT_INSTANT
: // use B case that not dependent from from A in fact
461 if((m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)==0)
462 m_targets
.setDestination(m_caster
->GetPositionX(),m_caster
->GetPositionY(),m_caster
->GetPositionZ());
463 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
465 case TARGET_BEHIND_VICTIM
: // use B case that not dependent from from A in fact
466 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
469 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
470 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
474 case TARGET_CASTER_COORDINATES
:
475 // Note: this hack with search required until GO casting not implemented
476 // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support
477 // currently each enemy selected explicitly and self cast damage
478 if(m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_ALL_ENEMY_IN_AREA
&& m_spellInfo
->Effect
[i
]==SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
)
480 if(m_targets
.getUnitTarget())
481 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
485 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
486 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
489 case TARGET_TABLE_X_Y_Z_COORDINATES
:
490 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
493 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
495 // need some target for proccesing
496 if(m_targets
.getUnitTarget())
497 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
499 tmpUnitMap
.push_back(m_caster
);
501 case TARGET_AREAEFFECT_INSTANT
: // All 17/7 pairs used for dest teleportation, A processed in effect code
502 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
505 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
506 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
511 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
514 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
516 case TARGET_SCRIPT_COORDINATES
: // B case filled in CheckCast but we need fill unit list base at A case
517 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
520 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
521 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
527 if( (m_spellInfo
->EffectImplicitTargetA
[i
]==0 || m_spellInfo
->EffectImplicitTargetA
[i
]==TARGET_EFFECT_SELECT
) &&
528 (m_spellInfo
->EffectImplicitTargetB
[i
]==0 || m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_EFFECT_SELECT
) )
530 // add here custom effects that need default target.
531 // FOR EVERY TARGET TYPE THERE IS A DIFFERENT FILL!!
532 switch(m_spellInfo
->Effect
[i
])
534 case SPELL_EFFECT_DUMMY
:
536 switch(m_spellInfo
->Id
)
538 case 20577: // Cannibalize
540 // non-standard target selection
541 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
542 float max_range
= GetSpellMaxRange(srange
);
544 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
546 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
549 WorldObject
* result
= NULL
;
551 MaNGOS::CannibalizeObjectCheck
u_check(m_caster
, max_range
);
552 MaNGOS::WorldObjectSearcher
<MaNGOS::CannibalizeObjectCheck
> searcher(m_caster
, result
, u_check
);
554 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<MaNGOS::CannibalizeObjectCheck
>, GridTypeMapContainer
> grid_searcher(searcher
);
555 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
556 cell_lock
->Visit(cell_lock
, grid_searcher
, *m_caster
->GetMap());
560 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<MaNGOS::CannibalizeObjectCheck
>, WorldTypeMapContainer
> world_searcher(searcher
);
561 cell_lock
->Visit(cell_lock
, world_searcher
, *m_caster
->GetMap());
566 switch(result
->GetTypeId())
570 tmpUnitMap
.push_back((Unit
*)result
);
573 m_targets
.setCorpseTarget((Corpse
*)result
);
574 if(Player
* owner
= ObjectAccessor::FindPlayer(((Corpse
*)result
)->GetOwnerGUID()))
575 tmpUnitMap
.push_back(owner
);
581 // clear cooldown at fail
582 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
584 ((Player
*)m_caster
)->RemoveSpellCooldown(m_spellInfo
->Id
);
586 WorldPacket
data(SMSG_CLEAR_COOLDOWN
, (4+8));
587 data
<< uint32(m_spellInfo
->Id
);
588 data
<< uint64(m_caster
->GetGUID());
589 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
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
);
1060 // Send log damage message to client
1061 caster
->SendSpellNonMeleeDamageLog(&damageInfo
);
1063 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1064 procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1066 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1067 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1068 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, damageInfo
.damage
, m_attackType
, m_spellInfo
);
1070 caster
->DealSpellDamage(&damageInfo
, true);
1072 // Judgement of Blood
1073 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& m_spellInfo
->SpellFamilyFlags
& 0x0000000800000000LL
&& m_spellInfo
->SpellIconID
==153)
1075 int32 damagePoint
= damageInfo
.damage
* 33 / 100;
1076 m_caster
->CastCustomSpell(m_caster
, 32220, &damagePoint
, NULL
, NULL
, true);
1079 // Passive spell hits/misses or active spells only misses (only triggers)
1082 // Fill base damage struct (unitTarget - is real spell target)
1083 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1084 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1085 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1086 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1087 caster
->ProcDamageAndSpell(unit
, procAttacker
, procVictim
, procEx
, 0, m_attackType
, m_spellInfo
);
1090 // Call scripted function for AI if this spell is casted upon a creature
1091 if(unit
->GetTypeId()==TYPEID_UNIT
)
1093 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1094 // ignore pets or autorepeat/melee casts for speed (not exist quest for spells (hm... )
1095 if( !((Creature
*)unit
)->isPet() && !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1097 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1098 p
->CastedCreatureOrGO(unit
->GetEntry(),unit
->GetGUID(),m_spellInfo
->Id
);
1101 if(((Creature
*)unit
)->AI())
1102 ((Creature
*)unit
)->AI()->SpellHit(m_caster
,m_spellInfo
);
1105 // Call scripted function for AI if this spell is casted by a creature
1106 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)m_caster
)->AI())
1107 ((Creature
*)m_caster
)->AI()->SpellHitTarget(unit
,m_spellInfo
);
1110 void Spell::DoSpellHitOnUnit(Unit
*unit
, const uint32 effectMask
)
1112 if(!unit
|| !effectMask
)
1115 // Recheck immune (only for delayed spells)
1116 if( m_spellInfo
->speed
&& (
1117 unit
->IsImmunedToDamage(GetSpellSchoolMask(m_spellInfo
)) ||
1118 unit
->IsImmunedToSpell(m_spellInfo
)))
1120 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_IMMUNE
);
1124 if (unit
->GetTypeId() == TYPEID_PLAYER
)
1126 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET
, m_spellInfo
->Id
);
1127 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2
, m_spellInfo
->Id
);
1130 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
1132 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2
, m_spellInfo
->Id
, 0, unit
);
1135 if( m_caster
!= unit
)
1137 // Recheck UNIT_FLAG_NON_ATTACKABLE for delayed spells
1138 if (m_spellInfo
->speed
> 0.0f
&&
1139 unit
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
) &&
1140 unit
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
1142 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1146 if( !m_caster
->IsFriendlyTo(unit
) )
1148 // for delayed spells ignore not visible explicit target
1149 if(m_spellInfo
->speed
> 0.0f
&& unit
==m_targets
.getUnitTarget() && !unit
->isVisibleForOrDetect(m_caster
,false))
1151 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1155 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1157 if( !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) )
1159 if(!unit
->IsStandState() && !unit
->hasUnitState(UNIT_STAT_STUNNED
))
1160 unit
->SetStandState(UNIT_STAND_STATE_STAND
);
1162 if(!unit
->isInCombat() && unit
->GetTypeId() != TYPEID_PLAYER
&& ((Creature
*)unit
)->AI())
1163 ((Creature
*)unit
)->AI()->AttackedBy(m_caster
);
1165 unit
->AddThreat(m_caster
, 0.0f
);
1166 unit
->SetInCombatWith(m_caster
);
1167 m_caster
->SetInCombatWith(unit
);
1169 if(Player
*attackedPlayer
= unit
->GetCharmerOrOwnerPlayerOrPlayerItself())
1171 m_caster
->SetContestedPvP(attackedPlayer
);
1177 // for delayed spells ignore negative spells (after duel end) for friendly targets
1178 if(m_spellInfo
->speed
> 0.0f
&& !IsPositiveSpell(m_spellInfo
->Id
))
1180 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1184 // assisting case, healing and resurrection
1185 if(unit
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
1186 m_caster
->SetContestedPvP();
1187 if( unit
->isInCombat() && !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) )
1189 m_caster
->SetInCombatState(unit
->GetCombatTimer() > 0);
1190 unit
->getHostilRefManager().threatAssist(m_caster
, 0.0f
);
1195 // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
1196 m_diminishGroup
= GetDiminishingReturnsGroupForSpell(m_spellInfo
,m_triggeredByAuraSpell
);
1197 m_diminishLevel
= unit
->GetDiminishing(m_diminishGroup
);
1198 // Increase Diminishing on unit, current informations for actually casts will use values above
1199 if((GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_PLAYER
&& unit
->GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_ALL
)
1200 unit
->IncrDiminishing(m_diminishGroup
);
1202 // Apply additional spell effects to target
1204 m_caster
->CastSpell(unit
,m_preCastSpell
, true, m_CastItem
);
1206 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1208 if (effectMask
& (1<<effectNumber
))
1210 HandleEffects(unit
,NULL
,NULL
,effectNumber
,m_damageMultipliers
[effectNumber
]);
1211 if ( m_applyMultiplierMask
& (1 << effectNumber
) )
1214 float multiplier
= m_spellInfo
->DmgMultiplier
[effectNumber
];
1215 // Apply multiplier mods
1216 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1217 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_EFFECT_PAST_FIRST
, multiplier
,this);
1218 m_damageMultipliers
[effectNumber
] *= multiplier
;
1224 void Spell::DoAllEffectOnTarget(GOTargetInfo
*target
)
1226 if (target
->processed
) // Check target
1228 target
->processed
= true; // Target checked in apply effects procedure
1230 uint32 effectMask
= target
->effectMask
;
1234 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
1238 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1239 if (effectMask
& (1<<effectNumber
))
1240 HandleEffects(NULL
,NULL
,go
,effectNumber
);
1242 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1243 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
1244 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1246 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1247 p
->CastedCreatureOrGO(go
->GetEntry(),go
->GetGUID(),m_spellInfo
->Id
);
1251 void Spell::DoAllEffectOnTarget(ItemTargetInfo
*target
)
1253 uint32 effectMask
= target
->effectMask
;
1254 if(!target
->item
|| !effectMask
)
1257 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1258 if (effectMask
& (1<<effectNumber
))
1259 HandleEffects(NULL
, target
->item
, NULL
, effectNumber
);
1262 bool Spell::IsAliveUnitPresentInTargetList()
1264 // Not need check return true
1265 if (m_needAliveTargetMask
== 0)
1268 uint8 needAliveTargetMask
= m_needAliveTargetMask
;
1270 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
1272 if( ihit
->missCondition
== SPELL_MISS_NONE
&& (needAliveTargetMask
& ihit
->effectMask
) )
1274 Unit
*unit
= m_caster
->GetGUID()==ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
1276 if (unit
&& unit
->isAlive())
1277 needAliveTargetMask
&= ~ihit
->effectMask
; // remove from need alive mask effect that have alive target
1281 // is all effects from m_needAliveTargetMask have alive targets
1282 return needAliveTargetMask
==0;
1285 // Helper for Chain Healing
1286 // Spell target first
1287 // Raidmates then descending by injury suffered (MaxHealth - Health)
1288 // Other players/mobs then descending by injury suffered (MaxHealth - Health)
1289 struct ChainHealingOrder
: public std::binary_function
<const Unit
*, const Unit
*, bool>
1291 const Unit
* MainTarget
;
1292 ChainHealingOrder(Unit
const* Target
) : MainTarget(Target
) {};
1293 // functor for operator ">"
1294 bool operator()(Unit
const* _Left
, Unit
const* _Right
) const
1296 return (ChainHealingHash(_Left
) < ChainHealingHash(_Right
));
1298 int32
ChainHealingHash(Unit
const* Target
) const
1300 if (Target
== MainTarget
)
1302 else if (Target
->GetTypeId() == TYPEID_PLAYER
&& MainTarget
->GetTypeId() == TYPEID_PLAYER
&&
1303 ((Player
const*)Target
)->IsInSameRaidWith((Player
const*)MainTarget
))
1305 if (Target
->GetHealth() == Target
->GetMaxHealth())
1308 return 20000 - Target
->GetMaxHealth() + Target
->GetHealth();
1311 return 40000 - Target
->GetMaxHealth() + Target
->GetHealth();
1315 class ChainHealingFullHealth
: std::unary_function
<const Unit
*, bool>
1318 const Unit
* MainTarget
;
1319 ChainHealingFullHealth(const Unit
* Target
) : MainTarget(Target
) {};
1321 bool operator()(const Unit
* Target
)
1323 return (Target
!= MainTarget
&& Target
->GetHealth() == Target
->GetMaxHealth());
1327 // Helper for targets nearest to the spell target
1328 // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
1329 struct TargetDistanceOrder
: public std::binary_function
<const Unit
, const Unit
, bool>
1331 const Unit
* MainTarget
;
1332 TargetDistanceOrder(const Unit
* Target
) : MainTarget(Target
) {};
1333 // functor for operator ">"
1334 bool operator()(const Unit
* _Left
, const Unit
* _Right
) const
1336 return (MainTarget
->GetDistance(_Left
) < MainTarget
->GetDistance(_Right
));
1340 void Spell::SetTargetMap(uint32 i
,uint32 cur
,UnitList
& TagUnitMap
)
1343 if (m_spellInfo
->EffectRadiusIndex
[i
])
1344 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
1346 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
));
1348 if(m_originalCaster
)
1349 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1350 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RADIUS
, radius
,this);
1352 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[i
];
1353 if(m_originalCaster
)
1354 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1355 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
1357 // Get spell max affected targets
1358 uint32 unMaxTargets
= m_spellInfo
->MaxAffectedTargets
;
1360 // custom target amount cases
1361 switch(m_spellInfo
->SpellFamilyName
)
1363 case SPELLFAMILY_DRUID
:
1365 if (m_spellInfo
->SpellFamilyFlags2
& 0x00000100LL
)
1372 Unit::AuraList
const& mod
= m_caster
->GetAurasByType(SPELL_AURA_MOD_MAX_AFFECTED_TARGETS
);
1373 for(Unit::AuraList::const_iterator m
= mod
.begin(); m
!= mod
.end(); ++m
)
1375 if (!(*m
)->isAffectedOnSpell(m_spellInfo
))
1377 unMaxTargets
+=(*m
)->GetModifier()->m_amount
;
1382 case TARGET_TOTEM_EARTH
:
1383 case TARGET_TOTEM_WATER
:
1384 case TARGET_TOTEM_AIR
:
1385 case TARGET_TOTEM_FIRE
:
1388 case TARGET_DYNAMIC_OBJECT
:
1389 case TARGET_AREAEFFECT_CUSTOM
:
1390 case TARGET_AREAEFFECT_CUSTOM_2
:
1393 TagUnitMap
.push_back(m_caster
);
1396 case TARGET_RANDOM_ENEMY_CHAIN_IN_AREA
:
1398 m_targets
.m_targetMask
= 0;
1399 unMaxTargets
= EffectChainTarget
;
1400 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1402 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1404 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1407 std::list
<Unit
*> tempUnitMap
;
1410 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1411 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1413 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1414 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1416 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1417 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1418 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1421 if(tempUnitMap
.empty())
1424 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1426 //Now to get us a random target that's in the initial range of the spell
1428 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1429 while(itr
!= tempUnitMap
.end() && (*itr
)->GetDistance(m_caster
) < radius
)
1435 itr
= tempUnitMap
.begin();
1436 std::advance(itr
, rand()%t
);
1437 Unit
*pUnitTarget
= *itr
;
1438 TagUnitMap
.push_back(pUnitTarget
);
1440 tempUnitMap
.erase(itr
);
1442 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1444 t
= unMaxTargets
- 1;
1445 Unit
*prev
= pUnitTarget
;
1446 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1448 while(t
&& next
!= tempUnitMap
.end() )
1450 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
1453 if(!prev
->IsWithinLOSInMap(*next
))
1460 TagUnitMap
.push_back(prev
);
1461 tempUnitMap
.erase(next
);
1462 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1463 next
= tempUnitMap
.begin();
1468 case TARGET_RANDOM_FRIEND_CHAIN_IN_AREA
:
1470 m_targets
.m_targetMask
= 0;
1471 unMaxTargets
= EffectChainTarget
;
1472 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1473 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1475 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1477 std::list
<Unit
*> tempUnitMap
;
1479 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1480 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1482 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1483 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1485 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1486 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1487 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1490 if(tempUnitMap
.empty())
1493 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1495 //Now to get us a random target that's in the initial range of the spell
1497 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1498 while(itr
!= tempUnitMap
.end() && (*itr
)->GetDistance(m_caster
) < radius
)
1504 itr
= tempUnitMap
.begin();
1505 std::advance(itr
, rand()%t
);
1506 Unit
*pUnitTarget
= *itr
;
1507 TagUnitMap
.push_back(pUnitTarget
);
1509 tempUnitMap
.erase(itr
);
1511 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1513 t
= unMaxTargets
- 1;
1514 Unit
*prev
= pUnitTarget
;
1515 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1517 while(t
&& next
!= tempUnitMap
.end() )
1519 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
1522 if(!prev
->IsWithinLOSInMap(*next
))
1528 TagUnitMap
.push_back(prev
);
1529 tempUnitMap
.erase(next
);
1530 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1531 next
= tempUnitMap
.begin();
1537 Pet
* tmpUnit
= m_caster
->GetPet();
1538 if (!tmpUnit
) break;
1539 TagUnitMap
.push_back(tmpUnit
);
1542 case TARGET_CHAIN_DAMAGE
:
1544 if (EffectChainTarget
<= 1)
1546 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1548 m_targets
.setUnitTarget(pUnitTarget
);
1549 TagUnitMap
.push_back(pUnitTarget
);
1554 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1558 unMaxTargets
= EffectChainTarget
;
1561 if(m_spellInfo
->DmgClass
==SPELL_DAMAGE_CLASS_MELEE
)
1562 max_range
= radius
; //
1564 //FIXME: This very like horrible hack and wrong for most spells
1565 max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1567 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1569 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1572 Unit
* originalCaster
= GetOriginalCaster();
1575 std::list
<Unit
*> tempUnitMap
;
1578 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(pUnitTarget
, originalCaster
, max_range
);
1579 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1581 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1582 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1584 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1585 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1586 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1589 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1591 if(tempUnitMap
.empty())
1594 if(*tempUnitMap
.begin() == pUnitTarget
)
1595 tempUnitMap
.erase(tempUnitMap
.begin());
1597 TagUnitMap
.push_back(pUnitTarget
);
1598 uint32 t
= unMaxTargets
- 1;
1599 Unit
*prev
= pUnitTarget
;
1600 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1602 while(t
&& next
!= tempUnitMap
.end() )
1604 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
1607 if(!prev
->IsWithinLOSInMap(*next
))
1614 TagUnitMap
.push_back(prev
);
1615 tempUnitMap
.erase(next
);
1616 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1617 next
= tempUnitMap
.begin();
1624 case TARGET_ALL_ENEMY_IN_AREA
:
1626 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1629 case TARGET_AREAEFFECT_INSTANT
:
1631 SpellTargets targetB
= SPELL_TARGETS_AOE_DAMAGE
;
1632 // Select friendly targets for positive effect
1633 if (IsPositiveEffect(m_spellInfo
->Id
, i
))
1634 targetB
= SPELL_TARGETS_FRIENDLY
;
1636 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),radius
, PUSH_DEST_CENTER
, targetB
);
1639 TagUnitMap
.remove(m_caster
);
1641 case TARGET_ALL_ENEMY_IN_AREA_INSTANT
:
1643 // targets the ground, not the units in the area
1644 if (m_spellInfo
->Effect
[i
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1646 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1648 // exclude caster (this can be important if this not original caster)
1649 TagUnitMap
.remove(m_caster
);
1652 case TARGET_DUELVSPLAYER_COORDINATES
:
1654 if(Unit
* currentTarget
= m_targets
.getUnitTarget())
1656 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1657 TagUnitMap
.push_back(currentTarget
);
1660 case TARGET_ALL_PARTY_AROUND_CASTER
:
1661 case TARGET_ALL_PARTY_AROUND_CASTER_2
:
1662 case TARGET_ALL_PARTY
:
1664 Player
*pTarget
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself();
1665 Group
*pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1669 uint8 subgroup
= pTarget
->GetSubGroup();
1671 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1673 Player
* Target
= itr
->getSource();
1675 // IsHostileTo check duel and controlled by enemy
1676 if( Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
) )
1678 if( m_caster
->IsWithinDistInMap(Target
, radius
) )
1679 TagUnitMap
.push_back(Target
);
1681 if(Pet
* pet
= Target
->GetPet())
1682 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1683 TagUnitMap
.push_back(pet
);
1689 Unit
* ownerOrSelf
= pTarget
? pTarget
: m_caster
->GetCharmerOrOwnerOrSelf();
1690 if(ownerOrSelf
==m_caster
|| m_caster
->IsWithinDistInMap(ownerOrSelf
, radius
))
1691 TagUnitMap
.push_back(ownerOrSelf
);
1692 if(Pet
* pet
= ownerOrSelf
->GetPet())
1693 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1694 TagUnitMap
.push_back(pet
);
1698 case TARGET_ALL_RAID_AROUND_CASTER
:
1700 Player
*pTarget
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself();
1701 Group
*pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1703 if(m_spellInfo
->Id
==57669) //Replenishment (special target selection)
1707 typedef std::priority_queue
<PrioritizeManaPlayerWraper
, std::vector
<PrioritizeManaPlayerWraper
>, PrioritizeMana
> Top10
;
1710 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
&& manaUsers
.size() < 10; itr
= itr
->next())
1712 Player
* Target
= itr
->getSource();
1713 if (m_caster
->GetGUID() != Target
->GetGUID() && Target
->getPowerType() == POWER_MANA
&&
1714 !Target
->isDead() && m_caster
->IsWithinDistInMap(Target
, radius
))
1716 PrioritizeManaPlayerWraper
WTarget(Target
);
1717 manaUsers
.push(WTarget
);
1721 while(!manaUsers
.empty())
1723 TagUnitMap
.push_back(manaUsers
.top().getPlayer());
1729 Unit
* ownerOrSelf
= pTarget
? pTarget
: m_caster
->GetCharmerOrOwnerOrSelf();
1730 if ((ownerOrSelf
==m_caster
|| m_caster
->IsWithinDistInMap(ownerOrSelf
, radius
)) &&
1731 ownerOrSelf
->getPowerType() == POWER_MANA
)
1732 TagUnitMap
.push_back(ownerOrSelf
);
1734 if(Pet
* pet
= ownerOrSelf
->GetPet())
1735 if( m_caster
->IsWithinDistInMap(pet
, radius
) && pet
->getPowerType() == POWER_MANA
)
1736 TagUnitMap
.push_back(pet
);
1743 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1745 Player
* Target
= itr
->getSource();
1747 // IsHostileTo check duel and controlled by enemy
1748 if( Target
&& !m_caster
->IsHostileTo(Target
) )
1750 if( m_caster
->IsWithinDistInMap(Target
, radius
) )
1751 TagUnitMap
.push_back(Target
);
1753 if(Pet
* pet
= Target
->GetPet())
1754 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1755 TagUnitMap
.push_back(pet
);
1761 Unit
* ownerOrSelf
= pTarget
? pTarget
: m_caster
->GetCharmerOrOwnerOrSelf();
1762 if(ownerOrSelf
==m_caster
|| m_caster
->IsWithinDistInMap(ownerOrSelf
, radius
))
1763 TagUnitMap
.push_back(ownerOrSelf
);
1764 if(Pet
* pet
= ownerOrSelf
->GetPet())
1765 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1766 TagUnitMap
.push_back(pet
);
1771 case TARGET_SINGLE_FRIEND
:
1772 case TARGET_SINGLE_FRIEND_2
:
1774 if(m_targets
.getUnitTarget())
1775 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1777 case TARGET_NONCOMBAT_PET
:
1779 if(Unit
* target
= m_targets
.getUnitTarget())
1780 if( target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet() && ((Pet
*)target
)->getPetType() == MINI_PET
)
1781 TagUnitMap
.push_back(target
);
1783 case TARGET_CASTER_COORDINATES
:
1785 // Check original caster is GO - set its coordinates as dst cast
1786 WorldObject
*caster
= NULL
;
1787 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
1788 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
1791 // Set dest for targets
1792 m_targets
.setDestination(caster
->GetPositionX(), caster
->GetPositionY(), caster
->GetPositionZ());
1794 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER
:
1795 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_SELF_CENTER
,SPELL_TARGETS_FRIENDLY
);
1797 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA
:
1798 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_FRIENDLY
);
1800 // 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..)
1801 case TARGET_SINGLE_PARTY
:
1803 Unit
*target
= m_targets
.getUnitTarget();
1804 // Thoses spells apparently can't be casted on the caster.
1805 if( target
&& target
!= m_caster
)
1807 // Can only be casted on group's members or its pets
1808 Group
*pGroup
= NULL
;
1810 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1811 Unit
*targetOwner
= target
->GetCharmerOrOwner();
1814 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1816 if( target
== owner
)
1818 TagUnitMap
.push_back(target
);
1821 pGroup
= ((Player
*)owner
)->GetGroup();
1824 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1826 if( targetOwner
== m_caster
&& target
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)target
)->isPet())
1828 TagUnitMap
.push_back(target
);
1831 pGroup
= ((Player
*)m_caster
)->GetGroup();
1836 // Our target can also be a player's pet who's grouped with us or our pet. But can't be controlled player
1839 if( targetOwner
->GetTypeId() == TYPEID_PLAYER
&&
1840 target
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)target
)->isPet()) &&
1841 target
->GetOwnerGUID()==targetOwner
->GetGUID() &&
1842 pGroup
->IsMember(((Player
*)targetOwner
)->GetGUID()))
1844 TagUnitMap
.push_back(target
);
1847 // 1Our target can be a player who is on our group
1848 else if (target
->GetTypeId() == TYPEID_PLAYER
&& pGroup
->IsMember(((Player
*)target
)->GetGUID()))
1850 TagUnitMap
.push_back(target
);
1855 case TARGET_GAMEOBJECT
:
1857 if(m_targets
.getGOTarget())
1858 AddGOTarget(m_targets
.getGOTarget(), i
);
1860 case TARGET_IN_FRONT_OF_CASTER
:
1862 bool inFront
= m_spellInfo
->SpellVisual
[0] != 3879;
1863 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),radius
,inFront
? PUSH_IN_FRONT
: PUSH_IN_BACK
,SPELL_TARGETS_AOE_DAMAGE
);
1866 case TARGET_DUELVSPLAYER
:
1868 Unit
*target
= m_targets
.getUnitTarget();
1871 if(m_caster
->IsFriendlyTo(target
))
1873 TagUnitMap
.push_back(target
);
1877 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1879 m_targets
.setUnitTarget(pUnitTarget
);
1880 TagUnitMap
.push_back(pUnitTarget
);
1885 case TARGET_GAMEOBJECT_ITEM
:
1887 if(m_targets
.getGOTargetGUID())
1888 AddGOTarget(m_targets
.getGOTarget(), i
);
1889 else if(m_targets
.getItemTarget())
1890 AddItemTarget(m_targets
.getItemTarget(), i
);
1895 if(Unit
* owner
= m_caster
->GetCharmerOrOwner())
1896 TagUnitMap
.push_back(owner
);
1899 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED
:
1901 // targets the ground, not the units in the area
1902 if (m_spellInfo
->Effect
[i
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1903 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1908 if(m_spellInfo
->Effect
[i
] != SPELL_EFFECT_DUEL
)
1909 TagUnitMap
.push_back(m_caster
);
1911 case TARGET_SINGLE_ENEMY
:
1913 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1915 m_targets
.setUnitTarget(pUnitTarget
);
1916 TagUnitMap
.push_back(pUnitTarget
);
1919 case TARGET_AREAEFFECT_PARTY
:
1921 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1922 Player
*pTarget
= NULL
;
1926 TagUnitMap
.push_back(m_caster
);
1927 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1928 pTarget
= (Player
*)owner
;
1930 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1932 if(Unit
* target
= m_targets
.getUnitTarget())
1934 if( target
->GetTypeId() != TYPEID_PLAYER
)
1936 if(((Creature
*)target
)->isPet())
1938 Unit
*targetOwner
= target
->GetOwner();
1939 if(targetOwner
->GetTypeId() == TYPEID_PLAYER
)
1940 pTarget
= (Player
*)targetOwner
;
1944 pTarget
= (Player
*)target
;
1948 Group
* pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1952 uint8 subgroup
= pTarget
->GetSubGroup();
1954 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1956 Player
* Target
= itr
->getSource();
1958 // IsHostileTo check duel and controlled by enemy
1959 if(Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
))
1961 if( pTarget
->IsWithinDistInMap(Target
, radius
) )
1962 TagUnitMap
.push_back(Target
);
1964 if(Pet
* pet
= Target
->GetPet())
1965 if( pTarget
->IsWithinDistInMap(pet
, radius
) )
1966 TagUnitMap
.push_back(pet
);
1972 if(m_caster
->IsWithinDistInMap(owner
, radius
))
1973 TagUnitMap
.push_back(owner
);
1977 TagUnitMap
.push_back(pTarget
);
1979 if(Pet
* pet
= pTarget
->GetPet())
1980 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1981 TagUnitMap
.push_back(pet
);
1987 if(m_targets
.getUnitTarget())
1988 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1989 if(m_targets
.getItemTarget())
1990 AddItemTarget(m_targets
.getItemTarget(), i
);
1992 case TARGET_SELF_FISHING
:
1994 TagUnitMap
.push_back(m_caster
);
1996 case TARGET_CHAIN_HEAL
:
1998 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
2002 if (EffectChainTarget
<= 1)
2003 TagUnitMap
.push_back(pUnitTarget
);
2006 unMaxTargets
= EffectChainTarget
;
2007 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
2009 UnitList tempUnitMap
;
2011 FillAreaTargets(tempUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),max_range
,PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
2013 if(m_caster
!= pUnitTarget
&& std::find(tempUnitMap
.begin(),tempUnitMap
.end(),m_caster
) == tempUnitMap
.end() )
2014 tempUnitMap
.push_front(m_caster
);
2016 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
2018 if(tempUnitMap
.empty())
2021 if(*tempUnitMap
.begin() == pUnitTarget
)
2022 tempUnitMap
.erase(tempUnitMap
.begin());
2024 TagUnitMap
.push_back(pUnitTarget
);
2025 uint32 t
= unMaxTargets
- 1;
2026 Unit
*prev
= pUnitTarget
;
2027 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
2029 while(t
&& next
!= tempUnitMap
.end() )
2031 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
2034 if(!prev
->IsWithinLOSInMap(*next
))
2040 if((*next
)->GetHealth() == (*next
)->GetMaxHealth())
2042 next
= tempUnitMap
.erase(next
);
2047 TagUnitMap
.push_back(prev
);
2048 tempUnitMap
.erase(next
);
2049 tempUnitMap
.sort(TargetDistanceOrder(prev
));
2050 next
= tempUnitMap
.begin();
2056 case TARGET_CURRENT_ENEMY_COORDINATES
:
2058 Unit
* currentTarget
= m_targets
.getUnitTarget();
2061 TagUnitMap
.push_back(currentTarget
);
2062 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
2063 if(m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_ALL_ENEMY_IN_AREA_INSTANT
)
2064 FillAreaTargets(TagUnitMap
, currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), radius
, PUSH_TARGET_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
2068 case TARGET_AREAEFFECT_PARTY_AND_CLASS
:
2070 Player
* targetPlayer
= m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
2071 ? (Player
*)m_targets
.getUnitTarget() : NULL
;
2073 Group
* pGroup
= targetPlayer
? targetPlayer
->GetGroup() : NULL
;
2076 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2078 Player
* Target
= itr
->getSource();
2080 // IsHostileTo check duel and controlled by enemy
2081 if( Target
&& targetPlayer
->IsWithinDistInMap(Target
, radius
) &&
2082 targetPlayer
->getClass() == Target
->getClass() &&
2083 !m_caster
->IsHostileTo(Target
) )
2085 TagUnitMap
.push_back(Target
);
2089 else if(m_targets
.getUnitTarget())
2090 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2093 case TARGET_TABLE_X_Y_Z_COORDINATES
:
2095 SpellTargetPosition
const* st
= spellmgr
.GetSpellTargetPosition(m_spellInfo
->Id
);
2098 if (st
->target_mapId
== m_caster
->GetMapId())
2099 m_targets
.setDestination(st
->target_X
, st
->target_Y
, st
->target_Z
);
2101 sLog
.outError( "SPELL: wrong map (%u instead %u) target coordinates for spell ID %u", st
->target_mapId
, m_caster
->GetMapId(), m_spellInfo
->Id
);
2104 sLog
.outError( "SPELL: unknown target coordinates for spell ID %u", m_spellInfo
->Id
);
2106 case TARGET_BEHIND_VICTIM
:
2108 Unit
*pTarget
= NULL
;
2110 // explicit cast data from client or server-side cast
2111 // some spell at client send caster
2112 if(m_targets
.getUnitTarget() && m_targets
.getUnitTarget()!=m_caster
)
2113 pTarget
= m_targets
.getUnitTarget();
2114 else if(m_caster
->getVictim())
2115 pTarget
= m_caster
->getVictim();
2116 else if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
2117 pTarget
= ObjectAccessor::GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection());
2121 float _target_x
, _target_y
, _target_z
;
2122 pTarget
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), CONTACT_DISTANCE
, M_PI
);
2123 if(pTarget
->IsWithinLOS(_target_x
,_target_y
,_target_z
))
2125 TagUnitMap
.push_back(m_caster
);
2126 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2131 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
2133 // if parent spell create dynamic object extract area from it
2134 if(DynamicObject
* dynObj
= m_caster
->GetDynObject(m_triggeredByAuraSpell
? m_triggeredByAuraSpell
->Id
: m_spellInfo
->Id
))
2135 m_targets
.setDestination(dynObj
->GetPositionX(), dynObj
->GetPositionY(), dynObj
->GetPositionZ());
2138 case TARGET_DIRECTLY_FORWARD
:
2140 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2142 SpellRangeEntry
const* rEntry
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
2143 float minRange
= GetSpellMinRange(rEntry
);
2144 float maxRange
= GetSpellMaxRange(rEntry
);
2145 float dist
= minRange
+ rand_norm()*(maxRange
-minRange
);
2147 float _target_x
, _target_y
, _target_z
;
2148 m_caster
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), dist
);
2149 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2152 TagUnitMap
.push_back(m_caster
);
2159 if (unMaxTargets
&& TagUnitMap
.size() > unMaxTargets
)
2161 // make sure one unit is always removed per iteration
2162 uint32 removed_utarget
= 0;
2163 for (UnitList::iterator itr
= TagUnitMap
.begin(), next
; itr
!= TagUnitMap
.end(); itr
= next
)
2167 if (!*itr
) continue;
2168 if ((*itr
) == m_targets
.getUnitTarget())
2170 TagUnitMap
.erase(itr
);
2171 removed_utarget
= 1;
2175 // remove random units from the map
2176 while (TagUnitMap
.size() > unMaxTargets
- removed_utarget
)
2178 uint32 poz
= urand(0, TagUnitMap
.size()-1);
2179 for (UnitList::iterator itr
= TagUnitMap
.begin(); itr
!= TagUnitMap
.end(); ++itr
, --poz
)
2181 if (!*itr
) continue;
2185 TagUnitMap
.erase(itr
);
2190 // the player's target will always be added to the map
2191 if (removed_utarget
&& m_targets
.getUnitTarget())
2192 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2196 void Spell::prepare(SpellCastTargets
const* targets
, Aura
* triggeredByAura
)
2198 m_targets
= *targets
;
2200 m_spellState
= SPELL_STATE_PREPARING
;
2202 m_castPositionX
= m_caster
->GetPositionX();
2203 m_castPositionY
= m_caster
->GetPositionY();
2204 m_castPositionZ
= m_caster
->GetPositionZ();
2205 m_castOrientation
= m_caster
->GetOrientation();
2208 m_triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
2210 // create and add update event for this spell
2211 SpellEvent
* Event
= new SpellEvent(this);
2212 m_caster
->m_Events
.AddEvent(Event
, m_caster
->m_Events
.CalculateTime(1));
2214 //Prevent casting at cast another spell (ServerSide check)
2215 if(m_caster
->IsNonMeleeSpellCasted(false, true, true) && m_cast_count
)
2217 SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS
);
2223 m_powerCost
= CalculatePowerCost();
2225 SpellCastResult result
= CheckCast(true);
2226 if(result
!= SPELL_CAST_OK
&& !IsAutoRepeat()) //always cast autorepeat dummy for triggering
2230 SendChannelUpdate(0);
2231 triggeredByAura
->SetAuraDuration(0);
2233 SendCastResult(result
);
2238 // Prepare data for triggers
2239 prepareDataForTriggerSystem();
2241 // calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
2242 m_casttime
= GetSpellCastTime(m_spellInfo
, this);
2244 // set timer base at cast time
2247 // stealth must be removed at cast starting (at show channel bar)
2248 // skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
2249 if ( !m_IsTriggeredSpell
&& isSpellBreakStealth(m_spellInfo
) )
2251 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
2252 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
2255 if(m_IsTriggeredSpell
)
2259 m_caster
->SetCurrentCastedSpell( this );
2260 m_selfContainer
= &(m_caster
->m_currentSpells
[GetCurrentContainer()]);
2265 void Spell::cancel()
2267 if(m_spellState
== SPELL_STATE_FINISHED
)
2270 m_autoRepeat
= false;
2271 switch (m_spellState
)
2273 case SPELL_STATE_PREPARING
:
2274 case SPELL_STATE_DELAYED
:
2277 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2280 case SPELL_STATE_CASTING
:
2282 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2284 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2286 Unit
* unit
= m_caster
->GetGUID()==(*ihit
).targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2287 if( unit
&& unit
->isAlive() )
2288 unit
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2292 m_caster
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2293 SendChannelUpdate(0);
2295 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2304 m_caster
->RemoveDynObject(m_spellInfo
->Id
);
2305 m_caster
->RemoveGameObject(m_spellInfo
->Id
,true);
2308 void Spell::cast(bool skipCheck
)
2310 SetExecutedCurrently(true);
2312 // update pointers base at GUIDs to prevent access to non-existed already object
2315 // cancel at lost main target unit
2316 if(!m_targets
.getUnitTarget() && m_targets
.getUnitTargetGUID() && m_targets
.getUnitTargetGUID() != m_caster
->GetGUID())
2319 SetExecutedCurrently(false);
2323 if(m_caster
->GetTypeId() != TYPEID_PLAYER
&& m_targets
.getUnitTarget() && m_targets
.getUnitTarget() != m_caster
)
2324 m_caster
->SetInFront(m_targets
.getUnitTarget());
2326 SpellCastResult castResult
= CheckPower();
2327 if(castResult
!= SPELL_CAST_OK
)
2329 SendCastResult(castResult
);
2331 SetExecutedCurrently(false);
2335 // triggered cast called from Spell::prepare where it was already checked
2338 castResult
= CheckCast(false);
2339 if(castResult
!= SPELL_CAST_OK
)
2341 SendCastResult(castResult
);
2343 SetExecutedCurrently(false);
2348 switch(m_spellInfo
->SpellFamilyName
)
2350 case SPELLFAMILY_GENERIC
:
2352 if (m_spellInfo
->Mechanic
== MECHANIC_BANDAGE
) // Bandages
2353 m_preCastSpell
= 11196; // Recently Bandaged
2354 else if(m_spellInfo
->SpellIconID
== 1662 && m_spellInfo
->AttributesEx
& 0x20) // Blood Fury (Racial)
2355 m_preCastSpell
= 23230; // Blood Fury - Healing Reduction
2358 case SPELLFAMILY_MAGE
:
2360 if (m_spellInfo
->SpellFamilyFlags
&0x0000008000000000LL
) // Ice Block
2361 m_preCastSpell
= 41425; // Hypothermia
2364 case SPELLFAMILY_PRIEST
:
2366 if (m_spellInfo
->Mechanic
== MECHANIC_SHIELD
&&
2367 m_spellInfo
->SpellIconID
== 566) // Power Word: Shield
2368 m_preCastSpell
= 6788; // Weakened Soul
2369 if (m_spellInfo
->Id
== 47585) // Dispersion (transform)
2370 m_preCastSpell
= 60069; // Dispersion (mana regen)
2373 case SPELLFAMILY_PALADIN
:
2375 if (m_spellInfo
->SpellFamilyFlags
&0x0000000000400080LL
) // Divine Shield, Divine Protection or Hand of Protection
2376 m_preCastSpell
= 25771; // Forbearance
2379 case SPELLFAMILY_SHAMAN
:
2381 if (m_spellInfo
->Id
== 2825) // Bloodlust
2382 m_preCastSpell
= 57724; // Sated
2383 else if (m_spellInfo
->Id
== 32182) // Heroism
2384 m_preCastSpell
= 57723; // Exhaustion
2391 // Conflagrate - consumes immolate
2392 if ((m_spellInfo
->TargetAuraState
== AURA_STATE_IMMOLATE
) && m_targets
.getUnitTarget())
2394 // for caster applied auras only
2395 Unit::AuraList
const &mPeriodic
= m_targets
.getUnitTarget()->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
2396 for(Unit::AuraList::const_iterator i
= mPeriodic
.begin(); i
!= mPeriodic
.end(); ++i
)
2398 if( (*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& ((*i
)->GetSpellProto()->SpellFamilyFlags
& 4) &&
2399 (*i
)->GetCasterGUID()==m_caster
->GetGUID() )
2401 m_targets
.getUnitTarget()->RemoveAura((*i
)->GetId(), (*i
)->GetEffIndex());
2407 // traded items have trade slot instead of guid in m_itemTargetGUID
2408 // set to real guid to be sent later to the client
2409 m_targets
.updateTradeSlotItem();
2411 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2413 if (!m_IsTriggeredSpell
&& m_CastItem
)
2414 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM
, m_CastItem
->GetEntry());
2416 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL
, m_spellInfo
->Id
);
2420 SendSpellCooldown();
2423 TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
2426 if(m_spellState
== SPELL_STATE_FINISHED
) // stop cast if spell marked as finish somewhere in Take*/FillTargetMap
2428 SetExecutedCurrently(false);
2432 SendCastResult(castResult
);
2433 SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2435 // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2436 if (m_spellInfo
->speed
> 0.0f
)
2439 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2440 // in case delayed spell remove item at cast delay start
2443 // Okay, maps created, now prepare flags
2444 m_immediateHandled
= false;
2445 m_spellState
= SPELL_STATE_DELAYED
;
2450 // Immediate spell, no big deal
2454 SetExecutedCurrently(false);
2457 void Spell::handle_immediate()
2459 // start channeling if applicable
2460 if(IsChanneledSpell(m_spellInfo
))
2462 int32 duration
= GetSpellDuration(m_spellInfo
);
2465 // Apply duration mod
2466 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
2467 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_DURATION
, duration
);
2468 m_spellState
= SPELL_STATE_CASTING
;
2469 SendChannelStart(duration
);
2473 // process immediate effects (items, ground, etc.) also initialize some variables
2474 _handle_immediate_phase();
2476 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2477 DoAllEffectOnTarget(&(*ihit
));
2479 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2480 DoAllEffectOnTarget(&(*ihit
));
2482 // spell is finished, perform some last features of the spell here
2483 _handle_finish_phase();
2485 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2488 if(m_spellState
!= SPELL_STATE_CASTING
)
2489 finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell)
2492 uint64
Spell::handle_delayed(uint64 t_offset
)
2494 uint64 next_time
= 0;
2496 if (!m_immediateHandled
)
2498 _handle_immediate_phase();
2499 m_immediateHandled
= true;
2502 // 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)
2503 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2505 if (ihit
->processed
== false)
2507 if ( ihit
->timeDelay
<= t_offset
)
2508 DoAllEffectOnTarget(&(*ihit
));
2509 else if( next_time
== 0 || ihit
->timeDelay
< next_time
)
2510 next_time
= ihit
->timeDelay
;
2514 // now recheck gameobject targeting correctness
2515 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
2517 if (ighit
->processed
== false)
2519 if ( ighit
->timeDelay
<= t_offset
)
2520 DoAllEffectOnTarget(&(*ighit
));
2521 else if( next_time
== 0 || ighit
->timeDelay
< next_time
)
2522 next_time
= ighit
->timeDelay
;
2525 // All targets passed - need finish phase
2528 // spell is finished, perform some last features of the spell here
2529 _handle_finish_phase();
2531 finish(true); // successfully finish spell cast
2533 // return zero, spell is finished now
2538 // spell is unfinished, return next execution time
2543 void Spell::_handle_immediate_phase()
2545 // handle some immediate features of the spell here
2546 HandleThreatSpells(m_spellInfo
->Id
);
2548 m_needSpellLog
= IsNeedSendToClient();
2549 for(uint32 j
= 0;j
<3;j
++)
2551 if(m_spellInfo
->Effect
[j
]==0)
2554 // apply Send Event effect to ground in case empty target lists
2555 if( m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
&& !HaveTargetsForEffect(j
) )
2557 HandleEffects(NULL
,NULL
,NULL
, j
);
2561 // Don't do spell log, if is school damage spell
2562 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
|| m_spellInfo
->Effect
[j
] == 0)
2563 m_needSpellLog
= false;
2565 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[j
];
2566 if(m_originalCaster
)
2567 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
2568 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
2570 // initialize multipliers
2571 m_damageMultipliers
[j
] = 1.0f
;
2572 if( (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_HEAL
) &&
2573 (EffectChainTarget
> 1) )
2574 m_applyMultiplierMask
|= 1 << j
;
2577 // initialize Diminishing Returns Data
2578 m_diminishLevel
= DIMINISHING_LEVEL_1
;
2579 m_diminishGroup
= DIMINISHING_NONE
;
2582 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
2583 DoAllEffectOnTarget(&(*ihit
));
2586 for(uint32 j
= 0;j
<3;j
++)
2588 // persistent area auras target only the ground
2589 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2590 HandleEffects(NULL
,NULL
,NULL
, j
);
2594 void Spell::_handle_finish_phase()
2601 void Spell::SendSpellCooldown()
2603 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
2606 Player
* _player
= (Player
*)m_caster
;
2608 // mana/health/etc potions, disabled by client (until combat out as declarate)
2609 if (m_CastItem
&& m_CastItem
->IsPotion())
2611 // need in some way provided data for Spell::finish SendCooldownEvent
2612 _player
->SetLastPotionId(m_CastItem
->GetEntry());
2616 // have infinity cooldown but set at aura apply
2617 if(m_spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
2620 _player
->AddSpellAndCategoryCooldowns(m_spellInfo
,m_CastItem
? m_CastItem
->GetEntry() : 0, this);
2623 void Spell::update(uint32 difftime
)
2625 // update pointers based at it's GUIDs
2628 if(m_targets
.getUnitTargetGUID() && !m_targets
.getUnitTarget())
2634 // check if the player caster has moved before the spell finished
2635 if ((m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_timer
!= 0) &&
2636 (m_castPositionX
!= m_caster
->GetPositionX() || m_castPositionY
!= m_caster
->GetPositionY() || m_castPositionZ
!= m_caster
->GetPositionZ()) &&
2637 (m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
|| !m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_FALLING
)))
2639 // always cancel for channeled spells
2640 if( m_spellState
== SPELL_STATE_CASTING
)
2642 // don't cancel for melee, autorepeat, triggered and instant spells
2643 else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_MOVEMENT
))
2647 switch(m_spellState
)
2649 case SPELL_STATE_PREPARING
:
2653 if(difftime
>= m_timer
)
2656 m_timer
-= difftime
;
2659 if(m_timer
== 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat())
2662 case SPELL_STATE_CASTING
:
2666 if( m_caster
->GetTypeId() == TYPEID_PLAYER
)
2668 // check if player has jumped before the channeling finished
2669 if(m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_JUMPING
))
2672 // check for incapacitating player states
2673 if( m_caster
->hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_CONFUSED
))
2676 // check if player has turned if flag is set
2677 if( m_spellInfo
->ChannelInterruptFlags
& CHANNEL_FLAG_TURNING
&& m_castOrientation
!= m_caster
->GetOrientation() )
2681 // check if there are alive targets left
2682 if (!IsAliveUnitPresentInTargetList())
2684 SendChannelUpdate(0);
2688 if(difftime
>= m_timer
)
2691 m_timer
-= difftime
;
2696 SendChannelUpdate(0);
2698 // channeled spell processed independently for quest targeting
2699 // cast at creature (or GO) quest objectives update at successful cast channel finished
2700 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
2701 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() )
2703 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
2705 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2707 TargetInfo
* target
= &*ihit
;
2708 if(!IS_CREATURE_GUID(target
->targetGUID
))
2711 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
2715 p
->CastedCreatureOrGO(unit
->GetEntry(),unit
->GetGUID(),m_spellInfo
->Id
);
2718 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2720 GOTargetInfo
* target
= &*ihit
;
2722 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
2726 p
->CastedCreatureOrGO(go
->GetEntry(),go
->GetGUID(),m_spellInfo
->Id
);
2740 void Spell::finish(bool ok
)
2745 if(m_spellState
== SPELL_STATE_FINISHED
)
2748 m_spellState
= SPELL_STATE_FINISHED
;
2750 // other code related only to successfully finished spells
2755 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2756 ((Player
*)m_caster
)->RemoveSpellMods(this);
2758 // handle SPELL_AURA_ADD_TARGET_TRIGGER auras
2759 Unit::AuraList
const& targetTriggers
= m_caster
->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER
);
2760 for(Unit::AuraList::const_iterator i
= targetTriggers
.begin(); i
!= targetTriggers
.end(); ++i
)
2762 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
2764 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2765 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2767 // check m_caster->GetGUID() let load auras at login and speedup most often case
2768 Unit
*unit
= m_caster
->GetGUID()== ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2769 if (unit
&& unit
->isAlive())
2771 SpellEntry
const *auraSpellInfo
= (*i
)->GetSpellProto();
2772 uint32 auraSpellIdx
= (*i
)->GetEffIndex();
2773 // Calculate chance at that moment (can be depend for example from combo points)
2774 int32 chance
= m_caster
->CalculateSpellDamage(auraSpellInfo
, auraSpellIdx
, (*i
)->GetBasePoints(),unit
);
2775 if(roll_chance_i(chance
))
2776 m_caster
->CastSpell(unit
, auraSpellInfo
->EffectTriggerSpell
[auraSpellIdx
], true, NULL
, (*i
));
2781 // Heal caster for all health leech from all targets
2783 m_caster
->DealHeal(m_caster
, uint32(m_healthLeech
), m_spellInfo
);
2785 if (IsMeleeAttackResetSpell())
2787 m_caster
->resetAttackTimer(BASE_ATTACK
);
2788 if(m_caster
->haveOffhandWeapon())
2789 m_caster
->resetAttackTimer(OFF_ATTACK
);
2792 /*if (IsRangedAttackResetSpell())
2793 m_caster->resetAttackTimer(RANGED_ATTACK);*/
2795 // Clear combo at finish state
2796 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& NeedsComboPoints(m_spellInfo
))
2798 // Not drop combopoints if negative spell and if any miss on enemy exist
2799 bool needDrop
= true;
2800 if (!IsPositiveSpell(m_spellInfo
->Id
))
2801 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2802 if (ihit
->missCondition
!= SPELL_MISS_NONE
&& ihit
->targetGUID
!=m_caster
->GetGUID())
2808 ((Player
*)m_caster
)->ClearComboPoints();
2811 // potions disabled by client, send event "not in combat" if need
2812 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2813 ((Player
*)m_caster
)->UpdatePotionCooldown(this);
2815 // call triggered spell only at successful cast (after clear combo points -> for add some if need)
2816 if(!m_TriggerSpells
.empty())
2819 // Stop Attack for some spells
2820 if( m_spellInfo
->Attributes
& SPELL_ATTR_STOP_ATTACK_TARGET
)
2821 m_caster
->AttackStop();
2824 void Spell::SendCastResult(SpellCastResult result
)
2826 if(result
== SPELL_CAST_OK
)
2829 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
2832 if(((Player
*)m_caster
)->GetSession()->PlayerLoading()) // don't send cast results at loading time
2835 WorldPacket
data(SMSG_CAST_FAILED
, (4+1+1));
2836 data
<< uint8(m_cast_count
); // single cast or multi 2.3 (0/1)
2837 data
<< uint32(m_spellInfo
->Id
);
2838 data
<< uint8(result
); // problem
2841 case SPELL_FAILED_REQUIRES_SPELL_FOCUS
:
2842 data
<< uint32(m_spellInfo
->RequiresSpellFocus
);
2844 case SPELL_FAILED_REQUIRES_AREA
:
2845 // hardcode areas limitation case
2846 switch(m_spellInfo
->Id
)
2848 case 41617: // Cenarion Mana Salve
2849 case 41619: // Cenarion Healing Salve
2850 data
<< uint32(3905);
2852 case 41618: // Bottled Nethergon Energy
2853 case 41620: // Bottled Nethergon Vapor
2854 data
<< uint32(3842);
2856 case 45373: // Bloodberry Elixir
2857 data
<< uint32(4075);
2859 default: // default case (don't must be)
2864 case SPELL_FAILED_TOTEMS
:
2865 if(m_spellInfo
->Totem
[0])
2866 data
<< uint32(m_spellInfo
->Totem
[0]);
2867 if(m_spellInfo
->Totem
[1])
2868 data
<< uint32(m_spellInfo
->Totem
[1]);
2870 case SPELL_FAILED_TOTEM_CATEGORY
:
2871 if(m_spellInfo
->TotemCategory
[0])
2872 data
<< uint32(m_spellInfo
->TotemCategory
[0]);
2873 if(m_spellInfo
->TotemCategory
[1])
2874 data
<< uint32(m_spellInfo
->TotemCategory
[1]);
2876 case SPELL_FAILED_EQUIPPED_ITEM_CLASS
:
2877 data
<< uint32(m_spellInfo
->EquippedItemClass
);
2878 data
<< uint32(m_spellInfo
->EquippedItemSubClassMask
);
2879 //data << uint32(m_spellInfo->EquippedItemInventoryTypeMask);
2884 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
2887 void Spell::SendSpellStart()
2889 if(!IsNeedSendToClient())
2892 sLog
.outDebug("Sending SMSG_SPELL_START id=%u", m_spellInfo
->Id
);
2894 uint32 castFlags
= CAST_FLAG_UNKNOWN1
;
2896 castFlags
|= CAST_FLAG_AMMO
;
2898 if(m_spellInfo
->runeCostID
)
2899 castFlags
|= CAST_FLAG_UNKNOWN10
;
2901 WorldPacket
data(SMSG_SPELL_START
, (8+8+4+4+2));
2903 data
.append(m_CastItem
->GetPackGUID());
2905 data
.append(m_caster
->GetPackGUID());
2907 data
.append(m_caster
->GetPackGUID());
2908 data
<< uint8(m_cast_count
); // pending spell cast?
2909 data
<< uint32(m_spellInfo
->Id
); // spellId
2910 data
<< uint32(castFlags
); // cast flags
2911 data
<< uint32(m_timer
); // delay?
2913 m_targets
.write(&data
);
2915 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // predicted power?
2918 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
2920 uint8 v1
= 0;//m_runesState;
2921 uint8 v2
= 0;//((Player*)m_caster)->GetRunesState();
2922 data
<< uint8(v1
); // runes state before
2923 data
<< uint8(v2
); // runes state after
2924 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
2927 if(m
& v1
) // usable before...
2928 if(!(m
& v2
)) // ...but on cooldown now...
2929 data
<< uint8(0); // some unknown byte (time?)
2933 if ( castFlags
& CAST_FLAG_AMMO
)
2934 WriteAmmoToPacket(&data
);
2936 m_caster
->SendMessageToSet(&data
, true);
2939 void Spell::SendSpellGo()
2941 // not send invisible spell casting
2942 if(!IsNeedSendToClient())
2945 sLog
.outDebug("Sending SMSG_SPELL_GO id=%u", m_spellInfo
->Id
);
2947 uint32 castFlags
= CAST_FLAG_UNKNOWN3
;
2949 castFlags
|= CAST_FLAG_AMMO
; // arrows/bullets visual
2951 if((m_caster
->GetTypeId() == TYPEID_PLAYER
) && (m_caster
->getClass() == CLASS_DEATH_KNIGHT
) && m_spellInfo
->runeCostID
)
2953 castFlags
|= CAST_FLAG_UNKNOWN10
; // same as in SMSG_SPELL_START
2954 castFlags
|= CAST_FLAG_UNKNOWN6
; // makes cooldowns visible
2955 castFlags
|= CAST_FLAG_UNKNOWN7
; // rune cooldowns list
2958 WorldPacket
data(SMSG_SPELL_GO
, 50); // guess size
2961 data
.append(m_CastItem
->GetPackGUID());
2963 data
.append(m_caster
->GetPackGUID());
2965 data
.append(m_caster
->GetPackGUID());
2966 data
<< uint8(m_cast_count
); // pending spell cast?
2967 data
<< uint32(m_spellInfo
->Id
); // spellId
2968 data
<< uint32(castFlags
); // cast flags
2969 data
<< uint32(getMSTime()); // timestamp
2971 WriteSpellGoTargets(&data
);
2973 m_targets
.write(&data
);
2975 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // unknown wotlk, predicted power?
2978 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
2980 uint8 v1
= m_runesState
;
2981 uint8 v2
= ((Player
*)m_caster
)->GetRunesState();
2982 data
<< uint8(v1
); // runes state before
2983 data
<< uint8(v2
); // runes state after
2984 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
2987 if(m
& v1
) // usable before...
2988 if(!(m
& v2
)) // ...but on cooldown now...
2989 data
<< uint8(0); // some unknown byte (time?)
2993 if ( castFlags
& CAST_FLAG_UNKNOWN4
) // unknown wotlk
2999 if ( castFlags
& CAST_FLAG_AMMO
)
3000 WriteAmmoToPacket(&data
);
3002 if ( castFlags
& CAST_FLAG_UNKNOWN5
) // unknown wotlk
3008 if ( m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
3013 m_caster
->SendMessageToSet(&data
, true);
3016 void Spell::WriteAmmoToPacket( WorldPacket
* data
)
3018 uint32 ammoInventoryType
= 0;
3019 uint32 ammoDisplayID
= 0;
3021 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3023 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack( RANGED_ATTACK
);
3026 ammoInventoryType
= pItem
->GetProto()->InventoryType
;
3027 if( ammoInventoryType
== INVTYPE_THROWN
)
3028 ammoDisplayID
= pItem
->GetProto()->DisplayInfoID
;
3031 uint32 ammoID
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
3034 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( ammoID
);
3037 ammoDisplayID
= pProto
->DisplayInfoID
;
3038 ammoInventoryType
= pProto
->InventoryType
;
3041 else if(m_caster
->GetDummyAura(46699)) // Requires No Ammo
3043 ammoDisplayID
= 5996; // normal arrow
3044 ammoInventoryType
= INVTYPE_AMMO
;
3049 // TODO: implement selection ammo data based at ranged weapon stored in equipmodel/equipinfo/equipslot fields
3051 *data
<< uint32(ammoDisplayID
);
3052 *data
<< uint32(ammoInventoryType
);
3055 void Spell::WriteSpellGoTargets( WorldPacket
* data
)
3057 // This function also fill data for channeled spells:
3058 // m_needAliveTargetMask req for stop channelig if one target die
3059 uint32 hit
= m_UniqueGOTargetInfo
.size(); // Always hits on GO
3061 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3063 if ((*ihit
).effectMask
== 0) // No effect apply - all immuned add state
3065 // possibly SPELL_MISS_IMMUNE2 for this??
3066 ihit
->missCondition
= SPELL_MISS_IMMUNE2
;
3069 else if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
3075 *data
<< (uint8
)hit
;
3076 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3077 if ((*ihit
).missCondition
== SPELL_MISS_NONE
) // Add only hits
3079 *data
<< uint64(ihit
->targetGUID
);
3080 m_needAliveTargetMask
|=ihit
->effectMask
;
3083 for(std::list
<GOTargetInfo
>::const_iterator ighit
= m_UniqueGOTargetInfo
.begin();ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
3084 *data
<< uint64(ighit
->targetGUID
); // Always hits
3086 *data
<< (uint8
)miss
;
3087 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3089 if( ihit
->missCondition
!= SPELL_MISS_NONE
) // Add only miss
3091 *data
<< uint64(ihit
->targetGUID
);
3092 *data
<< uint8(ihit
->missCondition
);
3093 if( ihit
->missCondition
== SPELL_MISS_REFLECT
)
3094 *data
<< uint8(ihit
->reflectResult
);
3097 // Reset m_needAliveTargetMask for non channeled spell
3098 if(!IsChanneledSpell(m_spellInfo
))
3099 m_needAliveTargetMask
= 0;
3102 void Spell::SendLogExecute()
3104 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
3106 WorldPacket
data(SMSG_SPELLLOGEXECUTE
, (8+4+4+4+4+8));
3108 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
3109 data
.append(m_caster
->GetPackGUID());
3111 data
.append(target
->GetPackGUID());
3113 data
<< uint32(m_spellInfo
->Id
);
3115 data
<< uint32(count1
); // count1 (effect count?)
3116 for(uint32 i
= 0; i
< count1
; ++i
)
3118 data
<< uint32(m_spellInfo
->Effect
[0]); // spell effect
3120 data
<< uint32(count2
); // count2 (target count?)
3121 for(uint32 j
= 0; j
< count2
; ++j
)
3123 switch(m_spellInfo
->Effect
[0])
3125 case SPELL_EFFECT_POWER_DRAIN
:
3126 if(Unit
*unit
= m_targets
.getUnitTarget())
3127 data
.append(unit
->GetPackGUID());
3134 case SPELL_EFFECT_ADD_EXTRA_ATTACKS
:
3135 if(Unit
*unit
= m_targets
.getUnitTarget())
3136 data
.append(unit
->GetPackGUID());
3139 data
<< uint32(0); // count?
3141 case SPELL_EFFECT_INTERRUPT_CAST
:
3142 if(Unit
*unit
= m_targets
.getUnitTarget())
3143 data
.append(unit
->GetPackGUID());
3146 data
<< uint32(0); // spellid
3148 case SPELL_EFFECT_DURABILITY_DAMAGE
:
3149 if(Unit
*unit
= m_targets
.getUnitTarget())
3150 data
.append(unit
->GetPackGUID());
3156 case SPELL_EFFECT_OPEN_LOCK
:
3157 if(Item
*item
= m_targets
.getItemTarget())
3158 data
.append(item
->GetPackGUID());
3162 case SPELL_EFFECT_CREATE_ITEM
:
3163 case SPELL_EFFECT_CREATE_ITEM_2
:
3164 data
<< uint32(m_spellInfo
->EffectItemType
[0]);
3166 case SPELL_EFFECT_SUMMON
:
3167 case SPELL_EFFECT_TRANS_DOOR
:
3168 case SPELL_EFFECT_SUMMON_PET
:
3169 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
3170 case SPELL_EFFECT_CREATE_HOUSE
:
3171 case SPELL_EFFECT_DUEL
:
3172 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1
:
3173 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2
:
3174 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3
:
3175 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4
:
3176 if(Unit
*unit
= m_targets
.getUnitTarget())
3177 data
.append(unit
->GetPackGUID());
3178 else if(m_targets
.getItemTargetGUID())
3179 data
.appendPackGUID(m_targets
.getItemTargetGUID());
3180 else if(GameObject
*go
= m_targets
.getGOTarget())
3181 data
.append(go
->GetPackGUID());
3183 data
<< uint8(0); // guid
3185 case SPELL_EFFECT_FEED_PET
:
3186 data
<< uint32(m_targets
.getItemTargetEntry());
3188 case SPELL_EFFECT_DISMISS_PET
:
3189 if(Unit
*unit
= m_targets
.getUnitTarget())
3190 data
.append(unit
->GetPackGUID());
3194 case SPELL_EFFECT_RESURRECT
:
3195 case SPELL_EFFECT_RESURRECT_NEW
:
3196 if(Unit
*unit
= m_targets
.getUnitTarget())
3197 data
.append(unit
->GetPackGUID());
3207 m_caster
->SendMessageToSet(&data
, true);
3210 void Spell::SendInterrupted(uint8 result
)
3212 WorldPacket
data(SMSG_SPELL_FAILURE
, (8+4+1));
3213 data
.append(m_caster
->GetPackGUID());
3214 data
<< uint8(m_cast_count
);
3215 data
<< uint32(m_spellInfo
->Id
);
3216 data
<< uint8(result
);
3217 m_caster
->SendMessageToSet(&data
, true);
3219 data
.Initialize(SMSG_SPELL_FAILED_OTHER
, (8+4));
3220 data
.append(m_caster
->GetPackGUID());
3221 data
<< uint8(m_cast_count
);
3222 data
<< uint32(m_spellInfo
->Id
);
3223 data
<< uint8(result
);
3224 m_caster
->SendMessageToSet(&data
, true);
3227 void Spell::SendChannelUpdate(uint32 time
)
3231 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
,0);
3232 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
,0);
3235 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3238 WorldPacket
data( MSG_CHANNEL_UPDATE
, 8+4 );
3239 data
.append(m_caster
->GetPackGUID());
3240 data
<< uint32(time
);
3242 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3245 void Spell::SendChannelStart(uint32 duration
)
3247 WorldObject
* target
= NULL
;
3249 // select first not resisted target from target list for _0_ effect
3250 if(!m_UniqueTargetInfo
.empty())
3252 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin();itr
!= m_UniqueTargetInfo
.end();++itr
)
3254 if( (itr
->effectMask
& (1<<0)) && itr
->reflectResult
==SPELL_MISS_NONE
&& itr
->targetGUID
!= m_caster
->GetGUID())
3256 target
= ObjectAccessor::GetUnit(*m_caster
, itr
->targetGUID
);
3261 else if(!m_UniqueGOTargetInfo
.empty())
3263 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin();itr
!= m_UniqueGOTargetInfo
.end();++itr
)
3265 if(itr
->effectMask
& (1<<0) )
3267 target
= m_caster
->GetMap()->GetGameObject(itr
->targetGUID
);
3273 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3275 WorldPacket
data( MSG_CHANNEL_START
, (8+4+4) );
3276 data
.append(m_caster
->GetPackGUID());
3277 data
<< uint32(m_spellInfo
->Id
);
3278 data
<< uint32(duration
);
3280 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3285 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, target
->GetGUID());
3286 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, m_spellInfo
->Id
);
3289 void Spell::SendResurrectRequest(Player
* target
)
3291 // Both players and NPCs can resurrect using spells - have a look at creature 28487 for example
3292 // However, the packet structure differs slightly
3294 const char* sentName
= m_caster
->GetTypeId()==TYPEID_PLAYER
?"":m_caster
->GetNameForLocaleIdx(target
->GetSession()->GetSessionDbLocaleIndex());
3296 WorldPacket
data(SMSG_RESURRECT_REQUEST
, (8+4+strlen(sentName
)+1+1+1));
3297 data
<< uint64(m_caster
->GetGUID());
3298 data
<< uint32(strlen(sentName
)+1);
3303 data
<< uint8(m_caster
->GetTypeId()==TYPEID_PLAYER
?0:1);
3304 target
->GetSession()->SendPacket(&data
);
3307 void Spell::SendPlaySpellVisual(uint32 SpellID
)
3309 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3312 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 12);
3313 data
<< uint64(m_caster
->GetGUID());
3314 data
<< uint32(SpellID
); // spell visual id?
3315 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
3318 void Spell::TakeCastItem()
3320 if(!m_CastItem
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
3323 // not remove cast item at triggered spell (equipping, weapon damage, etc)
3324 if(m_IsTriggeredSpell
)
3327 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3331 // This code is to avoid a crash
3332 // I'm not sure, if this is really an error, but I guess every item needs a prototype
3333 sLog
.outError("Cast item has no item prototype highId=%d, lowId=%d",m_CastItem
->GetGUIDHigh(), m_CastItem
->GetGUIDLow());
3337 bool expendable
= false;
3338 bool withoutCharges
= false;
3340 for (int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
3342 if (proto
->Spells
[i
].SpellId
)
3344 // item has limited charges
3345 if (proto
->Spells
[i
].SpellCharges
)
3347 if (proto
->Spells
[i
].SpellCharges
< 0)
3350 int32 charges
= m_CastItem
->GetSpellCharges(i
);
3352 // item has charges left
3355 (charges
> 0) ? --charges
: ++charges
; // abs(charges) less at 1 after use
3356 if (proto
->Stackable
== 1)
3357 m_CastItem
->SetSpellCharges(i
, charges
);
3358 m_CastItem
->SetState(ITEM_CHANGED
, (Player
*)m_caster
);
3362 withoutCharges
= (charges
== 0);
3367 if (expendable
&& withoutCharges
)
3370 ((Player
*)m_caster
)->DestroyItemCount(m_CastItem
, count
, true);
3372 // prevent crash at access to deleted m_targets.getItemTarget
3373 if(m_CastItem
==m_targets
.getItemTarget())
3374 m_targets
.setItemTarget(NULL
);
3380 void Spell::TakePower()
3382 if(m_CastItem
|| m_triggeredByAuraSpell
)
3385 // health as power used
3386 if(m_spellInfo
->powerType
== POWER_HEALTH
)
3388 m_caster
->ModifyHealth( -(int32
)m_powerCost
);
3392 if(m_spellInfo
->powerType
>= MAX_POWERS
)
3394 sLog
.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo
->powerType
);
3398 Powers powerType
= Powers(m_spellInfo
->powerType
);
3400 if(powerType
== POWER_RUNE
)
3406 m_caster
->ModifyPower(powerType
, -(int32
)m_powerCost
);
3408 // Set the five second timer
3409 if (powerType
== POWER_MANA
&& m_powerCost
> 0)
3410 m_caster
->SetLastManaUse(getMSTime());
3413 SpellCastResult
Spell::CheckRuneCost(uint32 runeCostID
)
3415 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3416 return SPELL_CAST_OK
;
3418 Player
*plr
= (Player
*)m_caster
;
3420 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3421 return SPELL_CAST_OK
;
3423 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(runeCostID
);
3426 return SPELL_CAST_OK
;
3428 if(src
->NoRuneCost())
3429 return SPELL_CAST_OK
;
3431 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3433 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3434 runeCost
[i
] = src
->RuneCost
[i
];
3436 runeCost
[RUNE_DEATH
] = MAX_RUNES
; // calculated later
3438 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3440 uint8 rune
= plr
->GetCurrentRune(i
);
3441 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3445 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3447 runeCost
[RUNE_DEATH
] += runeCost
[i
];
3449 if(runeCost
[RUNE_DEATH
] > MAX_RUNES
)
3450 return SPELL_FAILED_NO_POWER
; // not sure if result code is correct
3452 return SPELL_CAST_OK
;
3455 void Spell::TakeRunePower()
3457 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3460 Player
*plr
= (Player
*)m_caster
;
3462 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3465 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(m_spellInfo
->runeCostID
);
3467 if(!src
|| (src
->NoRuneCost() && src
->NoRunicPowerGain()))
3470 m_runesState
= plr
->GetRunesState(); // store previous state
3472 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3474 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3476 runeCost
[i
] = src
->RuneCost
[i
];
3479 runeCost
[RUNE_DEATH
] = 0; // calculated later
3481 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3483 uint8 rune
= plr
->GetCurrentRune(i
);
3484 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3486 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3491 runeCost
[RUNE_DEATH
] = runeCost
[RUNE_BLOOD
] + runeCost
[RUNE_UNHOLY
] + runeCost
[RUNE_FROST
];
3493 if(runeCost
[RUNE_DEATH
] > 0)
3495 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3497 uint8 rune
= plr
->GetCurrentRune(i
);
3498 if((plr
->GetRuneCooldown(i
) == 0) && (rune
== RUNE_DEATH
))
3500 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3502 plr
->ConvertRune(i
, plr
->GetBaseRune(i
));
3503 if(runeCost
[RUNE_DEATH
] == 0)
3509 // you can gain some runic power when use runes
3510 float rp
= src
->runePowerGain
;;
3511 rp
*= sWorld
.getRate(RATE_POWER_RUNICPOWER_INCOME
);
3512 plr
->ModifyPower(POWER_RUNIC_POWER
, (int32
)rp
);
3515 void Spell::TakeReagents()
3517 if(m_IsTriggeredSpell
) // reagents used in triggered spell removed by original spell or don't must be removed.
3520 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3523 Player
* p_caster
= (Player
*)m_caster
;
3524 if (p_caster
->CanNoReagentCast(m_spellInfo
))
3527 for(uint32 x
=0;x
<8;x
++)
3529 if(m_spellInfo
->Reagent
[x
] <= 0)
3532 uint32 itemid
= m_spellInfo
->Reagent
[x
];
3533 uint32 itemcount
= m_spellInfo
->ReagentCount
[x
];
3535 // if CastItem is also spell reagent
3538 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3539 if( proto
&& proto
->ItemId
== itemid
)
3541 for(int s
=0;s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
3543 // CastItem will be used up and does not count as reagent
3544 int32 charges
= m_CastItem
->GetSpellCharges(s
);
3545 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
3556 // if getItemTarget is also spell reagent
3557 if (m_targets
.getItemTargetEntry()==itemid
)
3558 m_targets
.setItemTarget(NULL
);
3560 p_caster
->DestroyItemCount(itemid
, itemcount
, true);
3564 void Spell::HandleThreatSpells(uint32 spellId
)
3566 if(!m_targets
.getUnitTarget() || !spellId
)
3569 if(!m_targets
.getUnitTarget()->CanHaveThreatList())
3572 SpellThreatEntry
const *threatSpell
= sSpellThreatStore
.LookupEntry
<SpellThreatEntry
>(spellId
);
3576 m_targets
.getUnitTarget()->AddThreat(m_caster
, float(threatSpell
->threat
));
3578 DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId
, spellmgr
.GetSpellRank(spellId
), threatSpell
->threat
);
3581 void Spell::HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,uint32 i
, float DamageMultiplier
)
3583 unitTarget
= pUnitTarget
;
3584 itemTarget
= pItemTarget
;
3585 gameObjTarget
= pGOTarget
;
3587 uint8 eff
= m_spellInfo
->Effect
[i
];
3589 damage
= int32(CalculateDamage((uint8
)i
,unitTarget
)*DamageMultiplier
);
3591 sLog
.outDebug( "Spell: Effect : %u", eff
);
3593 if(eff
<TOTAL_SPELL_EFFECTS
)
3595 //sLog.outDebug( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff);
3596 (*this.*SpellEffects
[eff
])(i
);
3601 sLog.outDebug( "WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff);
3603 EffectEnchantItemTmp(i);
3606 sLog.outError("SPELL: unknown effect %u spell id %u",
3607 eff, m_spellInfo->Id);
3613 void Spell::TriggerSpell()
3615 for(TriggerSpells::const_iterator si
=m_TriggerSpells
.begin(); si
!=m_TriggerSpells
.end(); ++si
)
3617 Spell
* spell
= new Spell(m_caster
, (*si
), true, m_originalCasterGUID
, m_selfContainer
);
3618 spell
->prepare(&m_targets
); // use original spell original targets
3622 SpellCastResult
Spell::CheckCast(bool strict
)
3624 // check cooldowns to prevent cheating
3625 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
3627 if(m_triggeredByAuraSpell
)
3628 return SPELL_FAILED_DONT_REPORT
;
3630 return SPELL_FAILED_NOT_READY
;
3633 // only allow triggered spells if at an ended battleground
3634 if( !m_IsTriggeredSpell
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
3635 if(BattleGround
* bg
= ((Player
*)m_caster
)->GetBattleGround())
3636 if(bg
->GetStatus() == STATUS_WAIT_LEAVE
)
3637 return SPELL_FAILED_DONT_REPORT
;
3639 // only check at first call, Stealth auras are already removed at second call
3640 // for now, ignore triggered spells
3641 if( strict
&& !m_IsTriggeredSpell
)
3643 bool checkForm
= true;
3644 // Ignore form req aura
3645 Unit::AuraList
const& ignore
= m_caster
->GetAurasByType(SPELL_AURA_MOD_IGNORE_SHAPESHIFT
);
3646 for(Unit::AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
3648 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
3655 // Cannot be used in this stance/form
3656 SpellCastResult shapeError
= GetErrorAtShapeshiftedCast(m_spellInfo
, m_caster
->m_form
);
3657 if(shapeError
!= SPELL_CAST_OK
)
3660 if ((m_spellInfo
->Attributes
& SPELL_ATTR_ONLY_STEALTHED
) && !(m_caster
->HasStealthAura()))
3661 return SPELL_FAILED_ONLY_STEALTHED
;
3665 // caster state requirements
3666 if(m_spellInfo
->CasterAuraState
&& !m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraState
)))
3667 return SPELL_FAILED_CASTER_AURASTATE
;
3668 if(m_spellInfo
->CasterAuraStateNot
&& m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraStateNot
)))
3669 return SPELL_FAILED_CASTER_AURASTATE
;
3671 // Caster aura req check if need
3672 if(m_spellInfo
->casterAuraSpell
&& !m_caster
->HasAura(m_spellInfo
->casterAuraSpell
))
3673 return SPELL_FAILED_CASTER_AURASTATE
;
3674 if(m_spellInfo
->excludeCasterAuraSpell
&& m_caster
->HasAura(m_spellInfo
->excludeCasterAuraSpell
))
3675 return SPELL_FAILED_CASTER_AURASTATE
;
3677 // cancel autorepeat spells if cast start when moving
3678 // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
3679 if( m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->isMoving() )
3681 // skip stuck spell to allow use it in falling case and apply spell limitations at movement
3682 if( (!((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEMENTFLAG_FALLING
) || m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
) &&
3683 (IsAutoRepeat() || (m_spellInfo
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_NOT_SEATED
) != 0) )
3684 return SPELL_FAILED_MOVING
;
3687 if(Unit
*target
= m_targets
.getUnitTarget())
3689 // target state requirements (not allowed state), apply to self also
3690 if(m_spellInfo
->TargetAuraStateNot
&& target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraStateNot
)))
3691 return SPELL_FAILED_TARGET_AURASTATE
;
3693 // Target aura req check if need
3694 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
3695 return SPELL_FAILED_CASTER_AURASTATE
;
3696 if(m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
3697 return SPELL_FAILED_CASTER_AURASTATE
;
3699 if(target
!= m_caster
)
3701 // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds
3702 if(m_spellInfo
->TargetAuraState
&& !target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraState
)))
3703 return SPELL_FAILED_TARGET_AURASTATE
;
3705 // Not allow casting on flying player
3706 if (target
->isInFlight())
3707 return SPELL_FAILED_BAD_TARGETS
;
3709 if(!m_IsTriggeredSpell
&& VMAP::VMapFactory::checkSpellForLoS(m_spellInfo
->Id
) && !m_caster
->IsWithinLOSInMap(target
))
3710 return SPELL_FAILED_LINE_OF_SIGHT
;
3712 // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode
3713 // this case can be triggered if rank not found (too low-level target for first rank)
3714 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsPassiveSpell(m_spellInfo
->Id
) && !m_CastItem
)
3715 for(int i
=0;i
<3;++i
)
3716 if(IsPositiveEffect(m_spellInfo
->Id
, i
) && m_spellInfo
->Effect
[i
] == SPELL_EFFECT_APPLY_AURA
)
3717 if(target
->getLevel() + 10 < m_spellInfo
->spellLevel
)
3718 return SPELL_FAILED_LOWLEVEL
;
3720 else if (m_caster
->GetTypeId()==TYPEID_PLAYER
) // Target - is player caster
3722 // Additional check for some spells
3723 // If 0 spell effect empty - client not send target data (need use selection)
3724 // TODO: check it on next client version
3725 if (m_targets
.m_targetMask
== TARGET_FLAG_SELF
&&
3726 m_spellInfo
->EffectImplicitTargetA
[1] == TARGET_CHAIN_DAMAGE
)
3728 if (target
= m_caster
->GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection()))
3729 m_targets
.setUnitTarget(target
);
3731 return SPELL_FAILED_BAD_TARGETS
;
3735 // check pet presents
3736 for(int j
=0;j
<3;j
++)
3738 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_PET
)
3740 target
= m_caster
->GetPet();
3743 if(m_triggeredByAuraSpell
) // not report pet not existence for triggered spells
3744 return SPELL_FAILED_DONT_REPORT
;
3746 return SPELL_FAILED_NO_PET
;
3752 //check creature type
3753 //ignore self casts (including area casts when caster selected as target)
3754 if(target
!= m_caster
)
3756 if(!CheckTargetCreatureType(target
))
3758 if(target
->GetTypeId()==TYPEID_PLAYER
)
3759 return SPELL_FAILED_TARGET_IS_PLAYER
;
3761 return SPELL_FAILED_BAD_TARGETS
;
3765 // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
3766 // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
3767 if(m_caster
!= target
&& m_caster
->GetTypeId()==TYPEID_UNIT
&& m_caster
->GetCharmerOrOwnerGUID())
3769 // check correctness positive/negative cast target (pet cast real check and cheating check)
3770 if(IsPositiveSpell(m_spellInfo
->Id
))
3772 if(m_caster
->IsHostileTo(target
))
3773 return SPELL_FAILED_BAD_TARGETS
;
3777 if(m_caster
->IsFriendlyTo(target
))
3778 return SPELL_FAILED_BAD_TARGETS
;
3782 if(IsPositiveSpell(m_spellInfo
->Id
))
3783 if(target
->IsImmunedToSpell(m_spellInfo
))
3784 return SPELL_FAILED_TARGET_AURASTATE
;
3786 //Must be behind the target.
3787 if( m_spellInfo
->AttributesEx2
== 0x100000 && (m_spellInfo
->AttributesEx
& 0x200) == 0x200 && target
->HasInArc(M_PI
, m_caster
) )
3789 //Exclusion for Pounce: Facing Limitation was removed in 2.0.1, but it still uses the same, old Ex-Flags
3790 if( m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_DRUID
|| m_spellInfo
->SpellFamilyFlags
!= 0x0000000000020000LL
)
3793 return SPELL_FAILED_NOT_BEHIND
;
3797 //Target must be facing you.
3798 if((m_spellInfo
->Attributes
== 0x150010) && !target
->HasInArc(M_PI
, m_caster
) )
3801 return SPELL_FAILED_NOT_INFRONT
;
3804 // check if target is in combat
3805 if (target
!= m_caster
&& (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET
) && target
->isInCombat())
3806 return SPELL_FAILED_TARGET_AFFECTING_COMBAT
;
3809 // Spell casted only on battleground
3810 if((m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_BATTLEGROUND
) && m_caster
->GetTypeId()==TYPEID_PLAYER
)
3811 if(!((Player
*)m_caster
)->InBattleGround())
3812 return SPELL_FAILED_ONLY_BATTLEGROUNDS
;
3814 // do not allow spells to be cast in arenas
3815 // - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag
3816 // - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag
3817 if( (m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA
) ||
3818 GetSpellRecoveryTime(m_spellInfo
) > 15 * MINUTE
* IN_MILISECONDS
&& !(m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_USABLE_IN_ARENA
) )
3819 if(MapEntry
const* mapEntry
= sMapStore
.LookupEntry(m_caster
->GetMapId()))
3820 if(mapEntry
->IsBattleArena())
3821 return SPELL_FAILED_NOT_IN_ARENA
;
3825 m_caster
->GetZoneAndAreaId(zone
,area
);
3827 SpellCastResult locRes
= spellmgr
.GetSpellAllowedInLocationError(m_spellInfo
,m_caster
->GetMapId(),zone
,area
,
3828 m_caster
->GetTypeId()==TYPEID_PLAYER
? ((Player
*)m_caster
) : NULL
);
3829 if(locRes
!= SPELL_CAST_OK
)
3832 // not let players cast spells at mount (and let do it to creatures)
3833 if( m_caster
->IsMounted() && m_caster
->GetTypeId()==TYPEID_PLAYER
&& !m_IsTriggeredSpell
&&
3834 !IsPassiveSpell(m_spellInfo
->Id
) && !(m_spellInfo
->Attributes
& SPELL_ATTR_CASTABLE_WHILE_MOUNTED
) )
3836 if(m_caster
->isInFlight())
3837 return SPELL_FAILED_NOT_FLYING
;
3839 return SPELL_FAILED_NOT_MOUNTED
;
3842 // always (except passive spells) check items (focus object can be required for any type casts)
3843 if(!IsPassiveSpell(m_spellInfo
->Id
))
3845 SpellCastResult castResult
= CheckItems();
3846 if(castResult
!= SPELL_CAST_OK
)
3850 //ImpliciteTargetA-B = 38, If fact there is 0 Spell with ImpliciteTargetB=38
3851 if(m_UniqueTargetInfo
.empty()) // skip second CheckCast apply (for delayed spells for example)
3853 for(uint8 j
= 0; j
< 3; j
++)
3855 if( m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
3856 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_SELF
||
3857 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3858 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3860 SpellScriptTarget::const_iterator lower
= spellmgr
.GetBeginSpellScriptTarget(m_spellInfo
->Id
);
3861 SpellScriptTarget::const_iterator upper
= spellmgr
.GetEndSpellScriptTarget(m_spellInfo
->Id
);
3863 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
);
3865 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
3866 float range
= GetSpellMaxRange(srange
);
3868 Creature
* creatureScriptTarget
= NULL
;
3869 GameObject
* goScriptTarget
= NULL
;
3871 for(SpellScriptTarget::const_iterator i_spellST
= lower
; i_spellST
!= upper
; ++i_spellST
)
3873 switch(i_spellST
->second
.type
)
3875 case SPELL_TARGET_TYPE_GAMEOBJECT
:
3877 GameObject
* p_GameObject
= NULL
;
3879 if(i_spellST
->second
.targetEntry
)
3881 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
3883 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3885 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*m_caster
,i_spellST
->second
.targetEntry
,range
);
3886 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(m_caster
, p_GameObject
,go_check
);
3888 TypeContainerVisitor
<MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
>, GridTypeMapContainer
> object_checker(checker
);
3889 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3890 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
3894 // remember found target and range, next attempt will find more near target with another entry
3895 creatureScriptTarget
= NULL
;
3896 goScriptTarget
= p_GameObject
;
3897 range
= go_check
.GetLastRange();
3900 else if( focusObject
) //Focus Object
3902 float frange
= m_caster
->GetDistance(focusObject
);
3905 creatureScriptTarget
= NULL
;
3906 goScriptTarget
= focusObject
;
3912 case SPELL_TARGET_TYPE_CREATURE
:
3913 case SPELL_TARGET_TYPE_DEAD
:
3916 Creature
*p_Creature
= NULL
;
3918 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
3920 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3921 cell
.SetNoCreate(); // Really don't know what is that???
3923 MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
u_check(*m_caster
,i_spellST
->second
.targetEntry
,i_spellST
->second
.type
!=SPELL_TARGET_TYPE_DEAD
,range
);
3924 MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
> searcher(m_caster
, p_Creature
, u_check
);
3926 TypeContainerVisitor
<MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
>, GridTypeMapContainer
> grid_creature_searcher(searcher
);
3928 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3929 cell_lock
->Visit(cell_lock
, grid_creature_searcher
, *m_caster
->GetMap());
3933 creatureScriptTarget
= p_Creature
;
3934 goScriptTarget
= NULL
;
3935 range
= u_check
.GetLastRange();
3942 if(creatureScriptTarget
)
3944 // store coordinates for TARGET_SCRIPT_COORDINATES
3945 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3946 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3948 m_targets
.setDestination(creatureScriptTarget
->GetPositionX(),creatureScriptTarget
->GetPositionY(),creatureScriptTarget
->GetPositionZ());
3950 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3951 AddUnitTarget(creatureScriptTarget
, j
);
3953 // store explicit target for TARGET_SCRIPT
3955 AddUnitTarget(creatureScriptTarget
, j
);
3957 else if(goScriptTarget
)
3959 // store coordinates for TARGET_SCRIPT_COORDINATES
3960 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3961 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3963 m_targets
.setDestination(goScriptTarget
->GetPositionX(),goScriptTarget
->GetPositionY(),goScriptTarget
->GetPositionZ());
3965 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3966 AddGOTarget(goScriptTarget
, j
);
3968 // store explicit target for TARGET_SCRIPT
3970 AddGOTarget(goScriptTarget
, j
);
3972 //Missing DB Entry or targets for this spellEffect.
3975 // not report target not existence for triggered spells
3976 if(m_triggeredByAuraSpell
|| m_IsTriggeredSpell
)
3977 return SPELL_FAILED_DONT_REPORT
;
3979 return SPELL_FAILED_BAD_TARGETS
;
3985 if(!m_IsTriggeredSpell
)
3987 SpellCastResult castResult
= CheckRange(strict
);
3988 if(castResult
!= SPELL_CAST_OK
)
3993 SpellCastResult castResult
= CheckPower();
3994 if(castResult
!= SPELL_CAST_OK
)
3998 if(!m_IsTriggeredSpell
) // triggered spell not affected by stun/etc
4000 SpellCastResult castResult
= CheckCasterAuras();
4001 if(castResult
!= SPELL_CAST_OK
)
4005 for (int i
= 0; i
< 3; ++i
)
4007 // for effects of spells that have only one target
4008 switch(m_spellInfo
->Effect
[i
])
4010 case SPELL_EFFECT_DUMMY
:
4012 if(m_spellInfo
->SpellIconID
== 1648) // Execute
4014 if(!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4015 return SPELL_FAILED_BAD_TARGETS
;
4017 else if (m_spellInfo
->Id
== 51582) // Rocket Boots Engaged
4019 if(m_caster
->IsInWater())
4020 return SPELL_FAILED_ONLY_ABOVEWATER
;
4022 else if(m_spellInfo
->SpellIconID
==156) // Holy Shock
4024 // spell different for friends and enemies
4025 // hart version required facing
4026 if(m_targets
.getUnitTarget() && !m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()) && !m_caster
->HasInArc( M_PI
, m_targets
.getUnitTarget() ))
4027 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4031 case SPELL_EFFECT_SCHOOL_DAMAGE
:
4034 if(m_spellInfo
->SpellVisual
[0] == 7250)
4036 if (!m_targets
.getUnitTarget())
4037 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4039 if(m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4040 return SPELL_FAILED_BAD_TARGETS
;
4044 case SPELL_EFFECT_TAMECREATURE
:
4046 if (!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
)
4047 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4049 if (m_targets
.getUnitTarget()->getLevel() > m_caster
->getLevel())
4050 return SPELL_FAILED_HIGHLEVEL
;
4052 // use SMSG_PET_TAME_FAILURE?
4053 if (!((Creature
*)m_targets
.getUnitTarget())->GetCreatureInfo()->isTameable ())
4054 return SPELL_FAILED_BAD_TARGETS
;
4056 if(m_caster
->GetPetGUID())
4057 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4059 if(m_caster
->GetCharmGUID())
4060 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4064 case SPELL_EFFECT_LEARN_SPELL
:
4066 if(m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_PET
)
4069 Pet
* pet
= m_caster
->GetPet();
4072 return SPELL_FAILED_NO_PET
;
4074 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4076 if(!learn_spellproto
)
4077 return SPELL_FAILED_NOT_KNOWN
;
4079 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4080 return SPELL_FAILED_LOWLEVEL
;
4084 case SPELL_EFFECT_LEARN_PET_SPELL
:
4086 Pet
* pet
= m_caster
->GetPet();
4089 return SPELL_FAILED_NO_PET
;
4091 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4093 if(!learn_spellproto
)
4094 return SPELL_FAILED_NOT_KNOWN
;
4096 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4097 return SPELL_FAILED_LOWLEVEL
;
4101 case SPELL_EFFECT_FEED_PET
:
4103 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4104 return SPELL_FAILED_BAD_TARGETS
;
4106 Item
* foodItem
= m_targets
.getItemTarget();
4108 return SPELL_FAILED_BAD_TARGETS
;
4110 Pet
* pet
= m_caster
->GetPet();
4113 return SPELL_FAILED_NO_PET
;
4115 if(!pet
->HaveInDiet(foodItem
->GetProto()))
4116 return SPELL_FAILED_WRONG_PET_FOOD
;
4118 if(!pet
->GetCurrentFoodBenefitLevel(foodItem
->GetProto()->ItemLevel
))
4119 return SPELL_FAILED_FOOD_LOWLEVEL
;
4121 if(m_caster
->isInCombat() || pet
->isInCombat())
4122 return SPELL_FAILED_AFFECTING_COMBAT
;
4126 case SPELL_EFFECT_POWER_BURN
:
4127 case SPELL_EFFECT_POWER_DRAIN
:
4129 // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
4130 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4131 if(Unit
* target
= m_targets
.getUnitTarget())
4132 if(target
!=m_caster
&& target
->getPowerType()!=m_spellInfo
->EffectMiscValue
[i
])
4133 return SPELL_FAILED_BAD_TARGETS
;
4136 case SPELL_EFFECT_CHARGE
:
4138 if (m_caster
->hasUnitState(UNIT_STAT_ROOT
))
4139 return SPELL_FAILED_ROOTED
;
4143 case SPELL_EFFECT_SKINNING
:
4145 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() != TYPEID_UNIT
)
4146 return SPELL_FAILED_BAD_TARGETS
;
4148 if( !(m_targets
.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS
) & UNIT_FLAG_SKINNABLE
) )
4149 return SPELL_FAILED_TARGET_UNSKINNABLE
;
4151 Creature
* creature
= (Creature
*)m_targets
.getUnitTarget();
4152 if ( creature
->GetCreatureType() != CREATURE_TYPE_CRITTER
&& ( !creature
->lootForBody
|| !creature
->loot
.empty() ) )
4154 return SPELL_FAILED_TARGET_NOT_LOOTED
;
4157 uint32 skill
= creature
->GetCreatureInfo()->GetRequiredLootSkill();
4159 int32 skillValue
= ((Player
*)m_caster
)->GetSkillValue(skill
);
4160 int32 TargetLevel
= m_targets
.getUnitTarget()->getLevel();
4161 int32 ReqValue
= (skillValue
< 100 ? (TargetLevel
-10)*10 : TargetLevel
*5);
4162 if (ReqValue
> skillValue
)
4163 return SPELL_FAILED_LOW_CASTLEVEL
;
4165 // chance for fail at orange skinning attempt
4166 if( (m_selfContainer
&& (*m_selfContainer
) == this) &&
4167 skillValue
< sWorld
.GetConfigMaxSkillValue() &&
4168 (ReqValue
< 0 ? 0 : ReqValue
) > irand(skillValue
-25, skillValue
+37) )
4169 return SPELL_FAILED_TRY_AGAIN
;
4173 case SPELL_EFFECT_OPEN_LOCK_ITEM
:
4174 case SPELL_EFFECT_OPEN_LOCK
:
4176 if( m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT
&&
4177 m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT_ITEM
)
4180 if( m_caster
->GetTypeId() != TYPEID_PLAYER
// only players can open locks, gather etc.
4181 // we need a go target in case of TARGET_GAMEOBJECT
4182 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT
&& !m_targets
.getGOTarget()
4183 // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM
4184 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT_ITEM
&& !m_targets
.getGOTarget() &&
4185 (!m_targets
.getItemTarget() || !m_targets
.getItemTarget()->GetProto()->LockID
|| m_targets
.getItemTarget()->GetOwner() != m_caster
) )
4186 return SPELL_FAILED_BAD_TARGETS
;
4188 // In BattleGround players can use only flags and banners
4189 if( ((Player
*)m_caster
)->InBattleGround() &&
4190 !((Player
*)m_caster
)->CanUseBattleGroundObject() )
4191 return SPELL_FAILED_TRY_AGAIN
;
4193 // get the lock entry
4195 if (GameObject
* go
=m_targets
.getGOTarget())
4196 lockId
= go
->GetLockId();
4197 else if(Item
* itm
=m_targets
.getItemTarget())
4198 lockId
= itm
->GetProto()->LockID
;
4200 SkillType skillId
=SKILL_NONE
;
4201 int32 reqSkillValue
= 0;
4202 int32 skillValue
= 0;
4204 // check lock compatibility
4205 SpellCastResult res
= CanOpenLock(i
,lockId
,skillId
,reqSkillValue
,skillValue
);
4206 if(res
!= SPELL_CAST_OK
)
4209 // chance for fail at orange mining/herb/LockPicking gathering attempt
4210 // second check prevent fail at rechecks
4211 if(skillId
!= SKILL_NONE
&& (!m_selfContainer
|| ((*m_selfContainer
) != this)))
4213 bool canFailAtMax
= skillId
!= SKILL_HERBALISM
&& skillId
!= SKILL_MINING
;
4215 // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill)
4216 if((canFailAtMax
|| skillValue
< sWorld
.GetConfigMaxSkillValue()) && reqSkillValue
> irand(skillValue
-25, skillValue
+37))
4217 return SPELL_FAILED_TRY_AGAIN
;
4221 case SPELL_EFFECT_SUMMON_DEAD_PET
:
4223 Creature
*pet
= m_caster
->GetPet();
4225 return SPELL_FAILED_NO_PET
;
4228 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4232 // This is generic summon effect
4233 case SPELL_EFFECT_SUMMON
:
4235 switch(m_spellInfo
->EffectMiscValueB
[i
])
4237 case SUMMON_TYPE_POSESSED
:
4238 case SUMMON_TYPE_POSESSED2
:
4239 case SUMMON_TYPE_DEMON
:
4240 case SUMMON_TYPE_SUMMON
:
4242 if(m_caster
->GetPetGUID())
4243 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4245 if(m_caster
->GetCharmGUID())
4246 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4252 // Not used for summon?
4253 case SPELL_EFFECT_SUMMON_PHANTASM
:
4255 if(m_caster
->GetPetGUID())
4256 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4258 if(m_caster
->GetCharmGUID())
4259 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4263 case SPELL_EFFECT_SUMMON_PET
:
4265 if(m_caster
->GetPetGUID()) //let warlock do a replacement summon
4268 Pet
* pet
= ((Player
*)m_caster
)->GetPet();
4270 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& m_caster
->getClass()==CLASS_WARLOCK
)
4272 if (strict
) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
4273 pet
->CastSpell(pet
, 32752, true, NULL
, NULL
, pet
->GetGUID());
4276 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4279 if(m_caster
->GetCharmGUID())
4280 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4284 case SPELL_EFFECT_SUMMON_PLAYER
:
4286 if(m_caster
->GetTypeId()!=TYPEID_PLAYER
)
4287 return SPELL_FAILED_BAD_TARGETS
;
4288 if(!((Player
*)m_caster
)->GetSelection())
4289 return SPELL_FAILED_BAD_TARGETS
;
4291 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
4292 if( !target
|| ((Player
*)m_caster
)==target
|| !target
->IsInSameRaidWith((Player
*)m_caster
) )
4293 return SPELL_FAILED_BAD_TARGETS
;
4295 // check if our map is dungeon
4296 if( sMapStore
.LookupEntry(m_caster
->GetMapId())->IsDungeon() )
4298 InstanceTemplate
const* instance
= ObjectMgr::GetInstanceTemplate(m_caster
->GetMapId());
4300 return SPELL_FAILED_TARGET_NOT_IN_INSTANCE
;
4301 if ( instance
->levelMin
> target
->getLevel() )
4302 return SPELL_FAILED_LOWLEVEL
;
4303 if ( instance
->levelMax
&& instance
->levelMax
< target
->getLevel() )
4304 return SPELL_FAILED_HIGHLEVEL
;
4308 case SPELL_EFFECT_LEAP
:
4309 case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
:
4311 float dis
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4312 float fx
= m_caster
->GetPositionX() + dis
* cos(m_caster
->GetOrientation());
4313 float fy
= m_caster
->GetPositionY() + dis
* sin(m_caster
->GetOrientation());
4314 // teleport a bit above terrain level to avoid falling below it
4315 float fz
= MapManager::Instance().GetBaseMap(m_caster
->GetMapId())->GetHeight(fx
,fy
,m_caster
->GetPositionZ(),true);
4316 if(fz
<= INVALID_HEIGHT
) // note: this also will prevent use effect in instances without vmaps height enabled
4317 return SPELL_FAILED_TRY_AGAIN
;
4319 float caster_pos_z
= m_caster
->GetPositionZ();
4320 // Control the caster to not climb or drop when +-fz > 8
4321 if(!(fz
<=caster_pos_z
+8 && fz
>=caster_pos_z
-8))
4322 return SPELL_FAILED_TRY_AGAIN
;
4324 // not allow use this effect at battleground until battleground start
4325 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
4326 if(BattleGround
const *bg
= ((Player
*)m_caster
)->GetBattleGround())
4327 if(bg
->GetStatus() != STATUS_IN_PROGRESS
)
4328 return SPELL_FAILED_TRY_AGAIN
;
4331 case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF
:
4333 if (m_targets
.getUnitTarget()==m_caster
)
4334 return SPELL_FAILED_BAD_TARGETS
;
4341 for (int i
= 0; i
< 3; ++i
)
4343 switch(m_spellInfo
->EffectApplyAuraName
[i
])
4345 case SPELL_AURA_DUMMY
:
4348 switch(m_spellInfo
->Id
)
4351 if(m_caster
->GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)m_caster
)->IsInFeralForm())
4352 return SPELL_FAILED_ONLY_SHAPESHIFT
;
4359 case SPELL_AURA_MOD_POSSESS
:
4360 case SPELL_AURA_MOD_CHARM
:
4362 if(m_caster
->GetPetGUID())
4363 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4365 if(m_caster
->GetCharmGUID())
4366 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4368 if(m_caster
->GetCharmerGUID())
4369 return SPELL_FAILED_CHARMED
;
4371 if(!m_targets
.getUnitTarget())
4372 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4374 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4375 return SPELL_FAILED_CHARMED
;
4377 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
4378 return SPELL_FAILED_HIGHLEVEL
;
4382 case SPELL_AURA_MOUNTED
:
4384 if (m_caster
->IsInWater())
4385 return SPELL_FAILED_ONLY_ABOVEWATER
;
4387 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetTransport())
4388 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4390 // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
4391 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& !sMapStore
.LookupEntry(m_caster
->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell
&& !m_spellInfo
->AreaGroupId
)
4392 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4394 ShapeshiftForm form
= m_caster
->m_form
;
4395 if( form
== FORM_CAT
|| form
== FORM_TREE
|| form
== FORM_TRAVEL
||
4396 form
== FORM_AQUA
|| form
== FORM_BEAR
|| form
== FORM_DIREBEAR
||
4397 form
== FORM_CREATUREBEAR
|| form
== FORM_GHOSTWOLF
|| form
== FORM_FLIGHT
||
4398 form
== FORM_FLIGHT_EPIC
|| form
== FORM_MOONKIN
|| form
== FORM_METAMORPHOSIS
)
4399 return SPELL_FAILED_NOT_SHAPESHIFT
;
4403 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
4405 if(!m_targets
.getUnitTarget())
4406 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4408 // can be casted at non-friendly unit or own pet/charm
4409 if(m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()))
4410 return SPELL_FAILED_TARGET_FRIENDLY
;
4414 case SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
:
4415 case SPELL_AURA_FLY
:
4417 // not allow cast fly spells at old maps by players (all spells is self target)
4418 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
4420 if( !((Player
*)m_caster
)->IsAllowUseFlyMountsHere() )
4421 return SPELL_FAILED_NOT_HERE
;
4426 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4428 if (!m_targets
.getUnitTarget())
4429 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4431 if (m_caster
->GetTypeId()!=TYPEID_PLAYER
|| m_CastItem
)
4434 if(m_targets
.getUnitTarget()->getPowerType()!=POWER_MANA
)
4435 return SPELL_FAILED_BAD_TARGETS
;
4445 return SPELL_CAST_OK
;
4448 SpellCastResult
Spell::CheckPetCast(Unit
* target
)
4450 if(!m_caster
->isAlive())
4451 return SPELL_FAILED_CASTER_DEAD
;
4453 if(m_caster
->IsNonMeleeSpellCasted(false)) //prevent spellcast interruption by another spellcast
4454 return SPELL_FAILED_SPELL_IN_PROGRESS
;
4455 if(m_caster
->isInCombat() && IsNonCombatSpell(m_spellInfo
))
4456 return SPELL_FAILED_AFFECTING_COMBAT
;
4458 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)m_caster
)->isPet() || m_caster
->isCharmed()))
4460 //dead owner (pets still alive when owners ressed?)
4461 if(m_caster
->GetCharmerOrOwner() && !m_caster
->GetCharmerOrOwner()->isAlive())
4462 return SPELL_FAILED_CASTER_DEAD
;
4464 if(!target
&& m_targets
.getUnitTarget())
4465 target
= m_targets
.getUnitTarget();
4468 for(uint32 i
= 0;i
<3;++i
)
4470 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
)
4474 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4479 m_targets
.setUnitTarget(target
);
4481 Unit
* _target
= m_targets
.getUnitTarget();
4483 if(_target
) //for target dead/target not valid
4485 if(!_target
->isAlive())
4486 return SPELL_FAILED_BAD_TARGETS
;
4488 if(IsPositiveSpell(m_spellInfo
->Id
))
4490 if(m_caster
->IsHostileTo(_target
))
4491 return SPELL_FAILED_BAD_TARGETS
;
4495 bool duelvsplayertar
= false;
4496 for(int j
=0;j
<3;j
++)
4498 //TARGET_DUELVSPLAYER is positive AND negative
4499 duelvsplayertar
|= (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
);
4501 if(m_caster
->IsFriendlyTo(target
) && !duelvsplayertar
)
4503 return SPELL_FAILED_BAD_TARGETS
;
4508 if(((Creature
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
4509 return SPELL_FAILED_NOT_READY
;
4512 return CheckCast(true);
4515 SpellCastResult
Spell::CheckCasterAuras() const
4517 // Flag drop spells totally immuned to caster auras
4518 // FIXME: find more nice check for all totally immuned spells
4519 // AttributesEx3 & 0x10000000?
4520 if(m_spellInfo
->Id
==23336 || m_spellInfo
->Id
==23334 || m_spellInfo
->Id
==34991)
4521 return SPELL_CAST_OK
;
4523 uint8 school_immune
= 0;
4524 uint32 mechanic_immune
= 0;
4525 uint32 dispel_immune
= 0;
4527 //Check if the spell grants school or mechanic immunity.
4528 //We use bitmasks so the loop is done only once and not on every aura check below.
4529 if ( m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
4531 for(int i
= 0;i
< 3; i
++)
4533 if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_SCHOOL_IMMUNITY
)
4534 school_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
4535 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY
)
4536 mechanic_immune
|= 1 << uint32(m_spellInfo
->EffectMiscValue
[i
]);
4537 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_DISPEL_IMMUNITY
)
4538 dispel_immune
|= GetDispellMask(DispelType(m_spellInfo
->EffectMiscValue
[i
]));
4540 //immune movement impairment and loss of control
4541 if(m_spellInfo
->Id
==(uint32
)42292)
4542 mechanic_immune
= IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK
;
4545 //Check whether the cast should be prevented by any state you might have.
4546 SpellCastResult prevented_reason
= SPELL_CAST_OK
;
4547 // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
4548 uint32 unitflag
= m_caster
->GetUInt32Value(UNIT_FIELD_FLAGS
); // Get unit state
4549 if(unitflag
& UNIT_FLAG_STUNNED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4550 prevented_reason
= SPELL_FAILED_STUNNED
;
4551 else if(unitflag
& UNIT_FLAG_CONFUSED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4552 prevented_reason
= SPELL_FAILED_CONFUSED
;
4553 else if(unitflag
& UNIT_FLAG_FLEEING
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4554 prevented_reason
= SPELL_FAILED_FLEEING
;
4555 else if(unitflag
& UNIT_FLAG_SILENCED
&& m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_SILENCE
)
4556 prevented_reason
= SPELL_FAILED_SILENCED
;
4557 else if(unitflag
& UNIT_FLAG_PACIFIED
&& m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_PACIFY
)
4558 prevented_reason
= SPELL_FAILED_PACIFIED
;
4560 // Attr must make flag drop spell totally immune from all effects
4561 if(prevented_reason
!= SPELL_CAST_OK
)
4563 if(school_immune
|| mechanic_immune
|| dispel_immune
)
4565 //Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
4566 Unit::AuraMap
const& auras
= m_caster
->GetAuras();
4567 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
4571 if( GetSpellMechanicMask(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()) & mechanic_immune
)
4573 if( GetSpellSchoolMask(itr
->second
->GetSpellProto()) & school_immune
)
4575 if( (1<<(itr
->second
->GetSpellProto()->Dispel
)) & dispel_immune
)
4578 //Make a second check for spell failed so the right SPELL_FAILED message is returned.
4579 //That is needed when your casting is prevented by multiple states and you are only immune to some of them.
4580 switch(itr
->second
->GetModifier()->m_auraname
)
4582 case SPELL_AURA_MOD_STUN
:
4583 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4584 return SPELL_FAILED_STUNNED
;
4586 case SPELL_AURA_MOD_CONFUSE
:
4587 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4588 return SPELL_FAILED_CONFUSED
;
4590 case SPELL_AURA_MOD_FEAR
:
4591 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4592 return SPELL_FAILED_FLEEING
;
4594 case SPELL_AURA_MOD_SILENCE
:
4595 case SPELL_AURA_MOD_PACIFY
:
4596 case SPELL_AURA_MOD_PACIFY_SILENCE
:
4597 if( m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_PACIFY
)
4598 return SPELL_FAILED_PACIFIED
;
4599 else if ( m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_SILENCE
)
4600 return SPELL_FAILED_SILENCED
;
4606 //You are prevented from casting and the spell casted does not grant immunity. Return a failed error.
4608 return prevented_reason
;
4610 return SPELL_CAST_OK
;
4613 bool Spell::CanAutoCast(Unit
* target
)
4615 uint64 targetguid
= target
->GetGUID();
4617 for(uint32 j
= 0;j
<3;j
++)
4619 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
)
4621 if( m_spellInfo
->StackAmount
<= 1)
4623 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4628 if( target
->GetAuras().count(Unit::spellEffectPair(m_spellInfo
->Id
, j
)) >= m_spellInfo
->StackAmount
)
4632 else if ( IsAreaAuraEffect( m_spellInfo
->Effect
[j
] ))
4634 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4639 SpellCastResult result
= CheckPetCast(target
);
4641 if(result
== SPELL_CAST_OK
|| result
== SPELL_FAILED_UNIT_NOT_INFRONT
)
4644 //check if among target units, our WANTED target is as well (->only self cast spells return false)
4645 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
4646 if( ihit
->targetGUID
== targetguid
)
4649 return false; //target invalid
4652 SpellCastResult
Spell::CheckRange(bool strict
)
4656 // self cast doesn't need range checking -- also for Starshards fix
4657 if (m_spellInfo
->rangeIndex
== 1)
4658 return SPELL_CAST_OK
;
4660 if (strict
) //add radius of caster
4662 else //add radius of caster and ~5 yds "give"
4665 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4666 float max_range
= GetSpellMaxRange(srange
) + range_mod
;
4667 float min_range
= GetSpellMinRange(srange
);
4669 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4670 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RANGE
, max_range
, this);
4672 Unit
*target
= m_targets
.getUnitTarget();
4674 if(target
&& target
!= m_caster
)
4676 // distance from target in checks
4677 float dist
= m_caster
->GetCombatDistance(target
);
4679 if(dist
> max_range
)
4680 return SPELL_FAILED_OUT_OF_RANGE
; //0x5A;
4681 if(dist
< min_range
)
4682 return SPELL_FAILED_TOO_CLOSE
;
4683 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&&
4684 (m_spellInfo
->FacingCasterFlags
& SPELL_FACING_FLAG_INFRONT
) && !m_caster
->HasInArc( M_PI
, target
) )
4685 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4688 if(m_targets
.m_targetMask
== TARGET_FLAG_DEST_LOCATION
&& m_targets
.m_destX
!= 0 && m_targets
.m_destY
!= 0 && m_targets
.m_destZ
!= 0)
4690 float dist
= m_caster
->GetDistance(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
);
4691 if(dist
> max_range
)
4692 return SPELL_FAILED_OUT_OF_RANGE
;
4693 if(dist
< min_range
)
4694 return SPELL_FAILED_TOO_CLOSE
;
4697 return SPELL_CAST_OK
;
4700 int32
Spell::CalculatePowerCost()
4702 // item cast not used power
4706 // Spell drain all exist power on cast (Only paladin lay of Hands)
4707 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DRAIN_ALL_POWER
)
4709 // If power type - health drain all
4710 if (m_spellInfo
->powerType
== POWER_HEALTH
)
4711 return m_caster
->GetHealth();
4712 // Else drain all power
4713 if (m_spellInfo
->powerType
< MAX_POWERS
)
4714 return m_caster
->GetPower(Powers(m_spellInfo
->powerType
));
4715 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4720 int32 powerCost
= m_spellInfo
->manaCost
;
4721 // PCT cost from total amount
4722 if (m_spellInfo
->ManaCostPercentage
)
4724 switch (m_spellInfo
->powerType
)
4726 // health as power used
4728 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateHealth() / 100;
4731 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateMana() / 100;
4736 case POWER_HAPPINESS
:
4737 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetMaxPower(Powers(m_spellInfo
->powerType
)) / 100;
4740 case POWER_RUNIC_POWER
:
4741 sLog
.outDebug("Spell::CalculateManaCost: Not implemented yet!");
4744 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4748 SpellSchools school
= GetFirstSchoolInMask(m_spellSchoolMask
);
4749 // Flat mod from caster auras by spell school
4750 powerCost
+= m_caster
->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER
+ school
);
4751 // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
4752 if ( m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST
)
4753 powerCost
+= m_caster
->GetAttackTime(OFF_ATTACK
)/100;
4754 // Apply cost mod by spell
4755 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4756 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, powerCost
, this);
4758 if(m_spellInfo
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
)
4759 powerCost
= int32(powerCost
/ (1.117f
* m_spellInfo
->spellLevel
/ m_caster
->getLevel() -0.1327f
));
4761 // PCT mod from user auras by school
4762 powerCost
= int32(powerCost
* (1.0f
+m_caster
->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+school
)));
4768 SpellCastResult
Spell::CheckPower()
4770 // item cast not used power
4772 return SPELL_CAST_OK
;
4774 // health as power used - need check health amount
4775 if(m_spellInfo
->powerType
== POWER_HEALTH
)
4777 if(m_caster
->GetHealth() <= m_powerCost
)
4778 return SPELL_FAILED_CASTER_AURASTATE
;
4779 return SPELL_CAST_OK
;
4781 // Check valid power type
4782 if( m_spellInfo
->powerType
>= MAX_POWERS
)
4784 sLog
.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo
->powerType
);
4785 return SPELL_FAILED_UNKNOWN
;
4788 SpellCastResult failReason
= CheckRuneCost(m_spellInfo
->runeCostID
);
4789 if(failReason
!= SPELL_CAST_OK
)
4792 // Check power amount
4793 Powers powerType
= Powers(m_spellInfo
->powerType
);
4794 if(m_caster
->GetPower(powerType
) < m_powerCost
)
4795 return SPELL_FAILED_NO_POWER
;
4797 return SPELL_CAST_OK
;
4800 SpellCastResult
Spell::CheckItems()
4802 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4803 return SPELL_CAST_OK
;
4805 Player
* p_caster
= (Player
*)m_caster
;
4810 uint32 itemid
= m_CastItem
->GetEntry();
4811 if( !p_caster
->HasItemCount(itemid
,1) )
4812 return SPELL_FAILED_ITEM_NOT_READY
;
4814 ItemPrototype
const *proto
= m_CastItem
->GetProto();
4816 return SPELL_FAILED_ITEM_NOT_READY
;
4818 for (int i
= 0; i
<5; ++i
)
4819 if (proto
->Spells
[i
].SpellCharges
)
4820 if(m_CastItem
->GetSpellCharges(i
)==0)
4821 return SPELL_FAILED_NO_CHARGES_REMAIN
;
4823 // consumable cast item checks
4824 if (proto
->Class
== ITEM_CLASS_CONSUMABLE
&& m_targets
.getUnitTarget())
4826 // such items should only fail if there is no suitable effect at all - see Rejuvenation Potions for example
4827 SpellCastResult failReason
= SPELL_CAST_OK
;
4828 for (int i
= 0; i
< 3; ++i
)
4830 // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster
4831 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_PET
)
4834 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_HEAL
)
4836 if (m_targets
.getUnitTarget()->GetHealth() == m_targets
.getUnitTarget()->GetMaxHealth())
4838 failReason
= SPELL_FAILED_ALREADY_AT_FULL_HEALTH
;
4843 failReason
= SPELL_CAST_OK
;
4848 // Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
4849 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
4851 if(m_spellInfo
->EffectMiscValue
[i
] < 0 || m_spellInfo
->EffectMiscValue
[i
] >= MAX_POWERS
)
4853 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
4857 Powers power
= Powers(m_spellInfo
->EffectMiscValue
[i
]);
4858 if (m_targets
.getUnitTarget()->GetPower(power
) == m_targets
.getUnitTarget()->GetMaxPower(power
))
4860 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
4865 failReason
= SPELL_CAST_OK
;
4870 if (failReason
!= SPELL_CAST_OK
)
4875 // check target item
4876 if(m_targets
.getItemTargetGUID())
4878 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4879 return SPELL_FAILED_BAD_TARGETS
;
4881 if(!m_targets
.getItemTarget())
4882 return SPELL_FAILED_ITEM_GONE
;
4884 if(!m_targets
.getItemTarget()->IsFitToSpellRequirements(m_spellInfo
))
4885 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
4887 // if not item target then required item must be equipped
4890 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !((Player
*)m_caster
)->HasItemFitToSpellReqirements(m_spellInfo
))
4891 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
4894 // check spell focus object
4895 if(m_spellInfo
->RequiresSpellFocus
)
4897 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4899 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4901 GameObject
* ok
= NULL
;
4902 MaNGOS::GameObjectFocusCheck
go_check(m_caster
,m_spellInfo
->RequiresSpellFocus
);
4903 MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
> checker(m_caster
,ok
,go_check
);
4905 TypeContainerVisitor
<MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
>, GridTypeMapContainer
> object_checker(checker
);
4906 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4907 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
4910 return SPELL_FAILED_REQUIRES_SPELL_FOCUS
;
4912 focusObject
= ok
; // game object found in range
4915 // check reagents (ignore triggered spells with reagents processed by original spell) and special reagent ignore case.
4916 if (!m_IsTriggeredSpell
&& !p_caster
->CanNoReagentCast(m_spellInfo
))
4918 for(uint32 i
=0;i
<8;++i
)
4920 if(m_spellInfo
->Reagent
[i
] <= 0)
4923 uint32 itemid
= m_spellInfo
->Reagent
[i
];
4924 uint32 itemcount
= m_spellInfo
->ReagentCount
[i
];
4926 // if CastItem is also spell reagent
4927 if( m_CastItem
&& m_CastItem
->GetEntry() == itemid
)
4929 ItemPrototype
const *proto
= m_CastItem
->GetProto();
4931 return SPELL_FAILED_ITEM_NOT_READY
;
4932 for(int s
=0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
4934 // CastItem will be used up and does not count as reagent
4935 int32 charges
= m_CastItem
->GetSpellCharges(s
);
4936 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
4943 if( !p_caster
->HasItemCount(itemid
,itemcount
) )
4944 return SPELL_FAILED_ITEM_NOT_READY
; //0x54
4948 // check totem-item requirements (items presence in inventory)
4950 for(int i
=0;i
<2;++i
)
4952 if(m_spellInfo
->Totem
[i
] != 0)
4954 if( p_caster
->HasItemCount(m_spellInfo
->Totem
[i
],1) )
4963 return SPELL_FAILED_TOTEMS
; //0x7C
4965 // Check items for TotemCategory (items presence in inventory)
4966 uint32 TotemCategory
= 2;
4967 for(int i
=0;i
<2;++i
)
4969 if(m_spellInfo
->TotemCategory
[i
] != 0)
4971 if( p_caster
->HasItemTotemCategory(m_spellInfo
->TotemCategory
[i
]) )
4980 if(TotemCategory
!= 0)
4981 return SPELL_FAILED_TOTEM_CATEGORY
; //0x7B
4983 // special checks for spell effects
4984 for(int i
= 0; i
< 3; ++i
)
4986 switch (m_spellInfo
->Effect
[i
])
4988 case SPELL_EFFECT_CREATE_ITEM
:
4990 if (!m_IsTriggeredSpell
&& m_spellInfo
->EffectItemType
[i
])
4992 ItemPosCountVec dest
;
4993 uint8 msg
= p_caster
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, m_spellInfo
->EffectItemType
[i
], 1 );
4994 if (msg
!= EQUIP_ERR_OK
)
4996 p_caster
->SendEquipError( msg
, NULL
, NULL
);
4997 return SPELL_FAILED_DONT_REPORT
;
5002 case SPELL_EFFECT_ENCHANT_ITEM
:
5003 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
5005 Item
* targetItem
= m_targets
.getItemTarget();
5007 return SPELL_FAILED_ITEM_NOT_FOUND
;
5009 if( targetItem
->GetProto()->ItemLevel
< m_spellInfo
->baseLevel
)
5010 return SPELL_FAILED_LOWLEVEL
;
5011 // Not allow enchant in trade slot for some enchant type
5012 if( targetItem
->GetOwner() != m_caster
)
5014 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5015 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5017 return SPELL_FAILED_ERROR
;
5018 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5019 return SPELL_FAILED_NOT_TRADEABLE
;
5023 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
5025 Item
*item
= m_targets
.getItemTarget();
5027 return SPELL_FAILED_ITEM_NOT_FOUND
;
5028 // Not allow enchant in trade slot for some enchant type
5029 if( item
->GetOwner() != m_caster
)
5031 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5032 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5034 return SPELL_FAILED_ERROR
;
5035 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5036 return SPELL_FAILED_NOT_TRADEABLE
;
5040 case SPELL_EFFECT_ENCHANT_HELD_ITEM
:
5041 // check item existence in effect code (not output errors at offhand hold item effect to main hand for example
5043 case SPELL_EFFECT_DISENCHANT
:
5045 if(!m_targets
.getItemTarget())
5046 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5048 // prevent disenchanting in trade slot
5049 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5050 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5052 ItemPrototype
const* itemProto
= m_targets
.getItemTarget()->GetProto();
5054 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5056 uint32 item_quality
= itemProto
->Quality
;
5057 // 2.0.x addon: Check player enchanting level against the item disenchanting requirements
5058 uint32 item_disenchantskilllevel
= itemProto
->RequiredDisenchantSkill
;
5059 if (item_disenchantskilllevel
== uint32(-1))
5060 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5061 if (item_disenchantskilllevel
> p_caster
->GetSkillValue(SKILL_ENCHANTING
))
5062 return SPELL_FAILED_LOW_CASTLEVEL
;
5063 if(item_quality
> 4 || item_quality
< 2)
5064 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5065 if(itemProto
->Class
!= ITEM_CLASS_WEAPON
&& itemProto
->Class
!= ITEM_CLASS_ARMOR
)
5066 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5067 if (!itemProto
->DisenchantID
)
5068 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5071 case SPELL_EFFECT_PROSPECTING
:
5073 if(!m_targets
.getItemTarget())
5074 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5075 //ensure item is a prospectable ore
5076 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_MINING_SUPP
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5077 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5078 //prevent prospecting in trade slot
5079 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5080 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5081 //Check for enough skill in jewelcrafting
5082 uint32 item_prospectingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5083 if(item_prospectingskilllevel
>p_caster
->GetSkillValue(SKILL_JEWELCRAFTING
))
5084 return SPELL_FAILED_LOW_CASTLEVEL
;
5085 //make sure the player has the required ores in inventory
5086 if(m_targets
.getItemTarget()->GetCount() < 5)
5087 return SPELL_FAILED_NEED_MORE_ITEMS
;
5089 if(!LootTemplates_Prospecting
.HaveLootFor(m_targets
.getItemTargetEntry()))
5090 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5094 case SPELL_EFFECT_MILLING
:
5096 if(!m_targets
.getItemTarget())
5097 return SPELL_FAILED_CANT_BE_MILLED
;
5098 //ensure item is a millable herb
5099 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_HERBS
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5100 return SPELL_FAILED_CANT_BE_MILLED
;
5101 //prevent milling in trade slot
5102 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5103 return SPELL_FAILED_CANT_BE_MILLED
;
5104 //Check for enough skill in inscription
5105 uint32 item_millingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5106 if(item_millingskilllevel
>p_caster
->GetSkillValue(SKILL_INSCRIPTION
))
5107 return SPELL_FAILED_LOW_CASTLEVEL
;
5108 //make sure the player has the required herbs in inventory
5109 if(m_targets
.getItemTarget()->GetCount() < 5)
5110 return SPELL_FAILED_NEED_MORE_ITEMS
;
5112 if(!LootTemplates_Milling
.HaveLootFor(m_targets
.getItemTargetEntry()))
5113 return SPELL_FAILED_CANT_BE_MILLED
;
5117 case SPELL_EFFECT_WEAPON_DAMAGE
:
5118 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
:
5120 if(m_caster
->GetTypeId() != TYPEID_PLAYER
) return SPELL_FAILED_TARGET_NOT_PLAYER
;
5121 if( m_attackType
!= RANGED_ATTACK
)
5123 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(m_attackType
);
5124 if(!pItem
|| pItem
->IsBroken())
5125 return SPELL_FAILED_EQUIPPED_ITEM
;
5127 switch(pItem
->GetProto()->SubClass
)
5129 case ITEM_SUBCLASS_WEAPON_THROWN
:
5131 uint32 ammo
= pItem
->GetEntry();
5132 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5133 return SPELL_FAILED_NO_AMMO
;
5135 case ITEM_SUBCLASS_WEAPON_GUN
:
5136 case ITEM_SUBCLASS_WEAPON_BOW
:
5137 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5139 uint32 ammo
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
5143 if(m_caster
->GetDummyAura(46699))
5144 break; // skip other checks
5146 return SPELL_FAILED_NO_AMMO
;
5149 ItemPrototype
const *ammoProto
= objmgr
.GetItemPrototype( ammo
);
5151 return SPELL_FAILED_NO_AMMO
;
5153 if(ammoProto
->Class
!= ITEM_CLASS_PROJECTILE
)
5154 return SPELL_FAILED_NO_AMMO
;
5156 // check ammo ws. weapon compatibility
5157 switch(pItem
->GetProto()->SubClass
)
5159 case ITEM_SUBCLASS_WEAPON_BOW
:
5160 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5161 if(ammoProto
->SubClass
!=ITEM_SUBCLASS_ARROW
)
5162 return SPELL_FAILED_NO_AMMO
;
5164 case ITEM_SUBCLASS_WEAPON_GUN
:
5165 if(ammoProto
->SubClass
!=ITEM_SUBCLASS_BULLET
)
5166 return SPELL_FAILED_NO_AMMO
;
5169 return SPELL_FAILED_NO_AMMO
;
5172 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5173 return SPELL_FAILED_NO_AMMO
;
5175 case ITEM_SUBCLASS_WEAPON_WAND
:
5185 return SPELL_CAST_OK
;
5188 void Spell::Delayed()
5190 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
5193 if (m_spellState
== SPELL_STATE_DELAYED
)
5194 return; // spell is active and can't be time-backed
5196 if(isDelayableNoMore()) // Spells may only be delayed twice
5199 // spells not loosing casting time ( slam, dynamites, bombs.. )
5200 if(!(m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_DAMAGE
))
5203 //check pushback reduce
5204 int32 delaytime
= 500; // spellcasting delay is normally 500ms
5205 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5206 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
,SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5207 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5208 if(delayReduce
>= 100)
5211 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5213 if(int32(m_timer
) + delaytime
> m_casttime
)
5215 delaytime
= m_casttime
- m_timer
;
5216 m_timer
= m_casttime
;
5219 m_timer
+= delaytime
;
5221 sLog
.outDetail("Spell %u partially interrupted for (%d) ms at damage",m_spellInfo
->Id
,delaytime
);
5223 WorldPacket
data(SMSG_SPELL_DELAYED
, 8+4);
5224 data
.append(m_caster
->GetPackGUID());
5225 data
<< uint32(delaytime
);
5227 m_caster
->SendMessageToSet(&data
,true);
5230 void Spell::DelayedChannel()
5232 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
|| getState() != SPELL_STATE_CASTING
)
5235 if(isDelayableNoMore()) // Spells may only be delayed twice
5238 //check pushback reduce
5239 int32 delaytime
= GetSpellDuration(m_spellInfo
) * 25 / 100; // channeling delay is normally 25% of its time per hit
5240 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5241 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
,SPELLMOD_NOT_LOSE_CASTING_TIME
,delayReduce
, this);
5242 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5243 if(delayReduce
>= 100)
5246 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5248 if(int32(m_timer
) < delaytime
)
5250 delaytime
= m_timer
;
5254 m_timer
-= delaytime
;
5256 sLog
.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo
->Id
, delaytime
, m_timer
);
5258 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
5260 if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
5262 Unit
* unit
= m_caster
->GetGUID()==ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
5265 for (int j
=0;j
<3;j
++)
5266 if( ihit
->effectMask
& (1<<j
) )
5267 unit
->DelayAura(m_spellInfo
->Id
, j
, delaytime
);
5273 for(int j
= 0; j
< 3; j
++)
5275 // partially interrupt persistent area auras
5276 DynamicObject
* dynObj
= m_caster
->GetDynObject(m_spellInfo
->Id
, j
);
5278 dynObj
->Delay(delaytime
);
5281 SendChannelUpdate(m_timer
);
5284 void Spell::UpdatePointers()
5286 if(m_originalCasterGUID
==m_caster
->GetGUID())
5287 m_originalCaster
= m_caster
;
5290 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
,m_originalCasterGUID
);
5291 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
5294 m_targets
.Update(m_caster
);
5297 bool Spell::IsAffectedByAura(Aura
*aura
)
5299 return spellmgr
.IsAffectedByMod(m_spellInfo
, aura
->getAuraSpellMod());
5302 bool Spell::CheckTargetCreatureType(Unit
* target
) const
5304 uint32 spellCreatureTargetMask
= m_spellInfo
->TargetCreatureType
;
5306 // Curse of Doom : not find another way to fix spell target check :/
5307 if(m_spellInfo
->SpellFamilyName
==SPELLFAMILY_WARLOCK
&& m_spellInfo
->SpellFamilyFlags
== 0x0200000000LL
)
5309 // not allow cast at player
5310 if(target
->GetTypeId()==TYPEID_PLAYER
)
5313 spellCreatureTargetMask
= 0x7FF;
5316 // Dismiss Pet and Taming Lesson skipped
5317 if(m_spellInfo
->Id
== 2641 || m_spellInfo
->Id
== 23356)
5318 spellCreatureTargetMask
= 0;
5320 if (spellCreatureTargetMask
)
5322 uint32 TargetCreatureType
= target
->GetCreatureTypeMask();
5324 return !TargetCreatureType
|| (spellCreatureTargetMask
& TargetCreatureType
);
5329 CurrentSpellTypes
Spell::GetCurrentContainer()
5331 if (IsNextMeleeSwingSpell())
5332 return(CURRENT_MELEE_SPELL
);
5333 else if (IsAutoRepeat())
5334 return(CURRENT_AUTOREPEAT_SPELL
);
5335 else if (IsChanneledSpell(m_spellInfo
))
5336 return(CURRENT_CHANNELED_SPELL
);
5338 return(CURRENT_GENERIC_SPELL
);
5341 bool Spell::CheckTarget( Unit
* target
, uint32 eff
)
5343 // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets)
5344 if(m_spellInfo
->EffectImplicitTargetA
[eff
]!=TARGET_SELF
)
5346 if (!CheckTargetCreatureType(target
))
5350 // Check Aura spell req (need for AoE spells)
5351 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
5353 if (m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
5356 // Check targets for not_selectable unit flag and remove
5357 // A player can cast spells on his pet (or other controlled unit) though in any state
5358 if (target
!= m_caster
&& target
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
5360 // any unattackable target skipped
5361 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
))
5364 // unselectable targets skipped in all cases except TARGET_SCRIPT targeting
5365 // in case TARGET_SCRIPT target selected by server always and can't be cheated
5366 if( target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NOT_SELECTABLE
) &&
5367 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SCRIPT
&&
5368 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_SCRIPT
)
5372 //Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
5373 if( target
!= m_caster
&& target
->GetTypeId()==TYPEID_PLAYER
)
5375 if(((Player
*)target
)->GetVisibility()==VISIBILITY_OFF
)
5378 if(((Player
*)target
)->isGameMaster() && !IsPositiveSpell(m_spellInfo
->Id
))
5382 //Check targets for LOS visibility (except spells without range limitations )
5383 switch(m_spellInfo
->Effect
[eff
])
5385 case SPELL_EFFECT_SUMMON_PLAYER
: // from anywhere
5387 case SPELL_EFFECT_DUMMY
:
5388 if(m_spellInfo
->Id
!=20577) // Cannibalize
5391 case SPELL_EFFECT_RESURRECT_NEW
:
5392 // player far away, maybe his corpse near?
5393 if(target
!=m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
5395 if(!m_targets
.getCorpseTargetGUID())
5398 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
5402 if(target
->GetGUID()!=corpse
->GetOwnerGUID())
5405 if(!corpse
->IsWithinLOSInMap(m_caster
))
5409 // all ok by some way or another, skip normal check
5411 default: // normal case
5412 // Get GO cast coordinates if original caster -> GO
5413 WorldObject
*caster
= NULL
;
5414 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
5415 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
5418 if(target
!=m_caster
&& !target
->IsWithinLOSInMap(caster
))
5426 bool Spell::IsNeedSendToClient() const
5428 return m_spellInfo
->SpellVisual
[0] || m_spellInfo
->SpellVisual
[1] || IsChanneledSpell(m_spellInfo
) ||
5429 m_spellInfo
->speed
> 0.0f
|| !m_triggeredByAuraSpell
&& !m_IsTriggeredSpell
;
5432 bool Spell::HaveTargetsForEffect( uint8 effect
) const
5434 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin();itr
!= m_UniqueTargetInfo
.end();++itr
)
5435 if(itr
->effectMask
& (1<<effect
))
5438 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin();itr
!= m_UniqueGOTargetInfo
.end();++itr
)
5439 if(itr
->effectMask
& (1<<effect
))
5442 for(std::list
<ItemTargetInfo
>::const_iterator itr
= m_UniqueItemInfo
.begin();itr
!= m_UniqueItemInfo
.end();++itr
)
5443 if(itr
->effectMask
& (1<<effect
))
5449 SpellEvent::SpellEvent(Spell
* spell
) : BasicEvent()
5454 SpellEvent::~SpellEvent()
5456 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5459 if (m_Spell
->IsDeletable())
5465 sLog
.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
5466 (m_Spell
->GetCaster()->GetTypeId()==TYPEID_PLAYER
?"Player":"Creature"), m_Spell
->GetCaster()->GetGUIDLow(),m_Spell
->m_spellInfo
->Id
);
5470 bool SpellEvent::Execute(uint64 e_time
, uint32 p_time
)
5472 // update spell if it is not finished
5473 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5474 m_Spell
->update(p_time
);
5476 // check spell state to process
5477 switch (m_Spell
->getState())
5479 case SPELL_STATE_FINISHED
:
5481 // spell was finished, check deletable state
5482 if (m_Spell
->IsDeletable())
5484 // check, if we do have unfinished triggered spells
5486 return(true); // spell is deletable, finish event
5488 // event will be re-added automatically at the end of routine)
5491 case SPELL_STATE_CASTING
:
5493 // this spell is in channeled state, process it on the next update
5494 // event will be re-added automatically at the end of routine)
5497 case SPELL_STATE_DELAYED
:
5499 // first, check, if we have just started
5500 if (m_Spell
->GetDelayStart() != 0)
5502 // no, we aren't, do the typical update
5503 // check, if we have channeled spell on our hands
5504 if (IsChanneledSpell(m_Spell
->m_spellInfo
))
5506 // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish
5507 // check, if we have casting anything else except this channeled spell and autorepeat
5508 if (m_Spell
->GetCaster()->IsNonMeleeSpellCasted(false, true, true))
5510 // another non-melee non-delayed spell is casted now, abort
5515 // do the action (pass spell to channeling state)
5516 m_Spell
->handle_immediate();
5518 // event will be re-added automatically at the end of routine)
5522 // run the spell handler and think about what we can do next
5523 uint64 t_offset
= e_time
- m_Spell
->GetDelayStart();
5524 uint64 n_offset
= m_Spell
->handle_delayed(t_offset
);
5527 // re-add us to the queue
5528 m_Spell
->GetCaster()->m_Events
.AddEvent(this, m_Spell
->GetDelayStart() + n_offset
, false);
5529 return(false); // event not complete
5532 // finish update event will be re-added automatically at the end of routine)
5537 // delaying had just started, record the moment
5538 m_Spell
->SetDelayStart(e_time
);
5539 // re-plan the event for the delay moment
5540 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ m_Spell
->GetDelayMoment(), false);
5541 return(false); // event not complete
5548 // event will be re-added automatically at the end of routine)
5552 // spell processing not complete, plan event on the next update interval
5553 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ 1, false);
5554 return(false); // event not complete
5557 void SpellEvent::Abort(uint64
/*e_time*/)
5559 // oops, the spell we try to do is aborted
5560 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5564 bool SpellEvent::IsDeletable() const
5566 return m_Spell
->IsDeletable();
5569 SpellCastResult
Spell::CanOpenLock(uint32 effIndex
, uint32 lockId
, SkillType
& skillId
, int32
& reqSkillValue
, int32
& skillValue
)
5571 if(!lockId
) // possible case for GO and maybe for items.
5572 return SPELL_CAST_OK
;
5575 LockEntry
const *lockInfo
= sLockStore
.LookupEntry(lockId
);
5578 return SPELL_FAILED_BAD_TARGETS
;
5580 bool reqKey
= false; // some locks not have reqs
5582 for(int j
= 0; j
< 8; ++j
)
5584 switch(lockInfo
->Type
[j
])
5586 // check key item (many fit cases can be)
5588 if(lockInfo
->Index
[j
] && m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->Index
[j
])
5589 return SPELL_CAST_OK
;
5592 // check key skill (only single first fit case can be)
5593 case LOCK_KEY_SKILL
:
5597 // wrong locktype, skip
5598 if(uint32(m_spellInfo
->EffectMiscValue
[effIndex
]) != lockInfo
->Index
[j
])
5601 skillId
= SkillByLockType(LockType(lockInfo
->Index
[j
]));
5603 if ( skillId
!= SKILL_NONE
)
5605 // skill bonus provided by casting spell (mostly item spells)
5606 // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value)
5607 uint32 spellSkillBonus
= uint32(m_currentBasePoints
[effIndex
]+1);
5608 reqSkillValue
= lockInfo
->Skill
[j
];
5610 // castitem check: rogue using skeleton keys. the skill values should not be added in this case.
5611 skillValue
= m_CastItem
|| m_caster
->GetTypeId()!= TYPEID_PLAYER
?
5612 0 : ((Player
*)m_caster
)->GetSkillValue(skillId
);
5614 skillValue
+= spellSkillBonus
;
5616 if (skillValue
< reqSkillValue
)
5617 return SPELL_FAILED_LOW_CASTLEVEL
;
5620 return SPELL_CAST_OK
;
5626 return SPELL_FAILED_BAD_TARGETS
;
5628 return SPELL_CAST_OK
;
5631 void Spell::FillAreaTargets( UnitList
& TagUnitMap
, float x
, float y
, float radius
, SpellNotifyPushType pushType
, SpellTargets spellTargets
)
5633 CellPair
p(MaNGOS::ComputeCellPair(x
, y
));
5635 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5637 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, pushType
, spellTargets
);
5638 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
5639 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
5640 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5641 cell_lock
->Visit(cell_lock
, world_notifier
, *m_caster
->GetMap());
5642 cell_lock
->Visit(cell_lock
, grid_notifier
, *m_caster
->GetMap());