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
? ObjectAccessor::GetGameObject(*caster
,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 if(m_targets
.getUnitTarget())
617 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
618 // Triggered spells have additional spell targets - cast them even if no explicit unit target is given (required for spell 50516 for example)
619 else if(m_spellInfo
->Effect
[i
] == SPELL_EFFECT_TRIGGER_SPELL
)
620 tmpUnitMap
.push_back(m_caster
);
622 case SPELL_EFFECT_SUMMON_PLAYER
:
623 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetSelection())
625 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
627 tmpUnitMap
.push_back(target
);
630 case SPELL_EFFECT_RESURRECT_NEW
:
631 if(m_targets
.getUnitTarget())
632 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
633 if(m_targets
.getCorpseTargetGUID())
635 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
638 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
640 tmpUnitMap
.push_back(owner
);
644 case SPELL_EFFECT_SUMMON
:
645 if(m_spellInfo
->EffectMiscValueB
[i
] == SUMMON_TYPE_POSESSED
|| m_spellInfo
->EffectMiscValueB
[i
] == SUMMON_TYPE_POSESSED2
)
647 if(m_targets
.getUnitTarget())
648 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
651 tmpUnitMap
.push_back(m_caster
);
653 case SPELL_EFFECT_SUMMON_CHANGE_ITEM
:
654 case SPELL_EFFECT_TRANS_DOOR
:
655 case SPELL_EFFECT_ADD_FARSIGHT
:
656 case SPELL_EFFECT_APPLY_GLYPH
:
657 case SPELL_EFFECT_STUCK
:
658 case SPELL_EFFECT_FEED_PET
:
659 case SPELL_EFFECT_DESTROY_ALL_TOTEMS
:
660 case SPELL_EFFECT_SKILL
:
661 tmpUnitMap
.push_back(m_caster
);
663 case SPELL_EFFECT_LEARN_PET_SPELL
:
664 if(Pet
* pet
= m_caster
->GetPet())
665 tmpUnitMap
.push_back(pet
);
667 case SPELL_EFFECT_ENCHANT_ITEM
:
668 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
669 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
670 case SPELL_EFFECT_DISENCHANT
:
671 case SPELL_EFFECT_PROSPECTING
:
672 case SPELL_EFFECT_MILLING
:
673 if(m_targets
.getItemTarget())
674 AddItemTarget(m_targets
.getItemTarget(), i
);
676 case SPELL_EFFECT_APPLY_AURA
:
677 switch(m_spellInfo
->EffectApplyAuraName
[i
])
679 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)
680 case SPELL_AURA_ADD_PCT_MODIFIER
:
681 tmpUnitMap
.push_back(m_caster
);
683 default: // apply to target in other case
684 if(m_targets
.getUnitTarget())
685 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
689 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY
:
691 if(m_spellInfo
->Attributes
== 0x9050000 || m_spellInfo
->Attributes
== 0x10000)
692 SetTargetMap(i
,TARGET_AREAEFFECT_PARTY
,tmpUnitMap
);
694 case SPELL_EFFECT_SKIN_PLAYER_CORPSE
:
695 if(m_targets
.getUnitTarget())
697 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
699 else if (m_targets
.getCorpseTargetGUID())
701 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
704 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
706 tmpUnitMap
.push_back(owner
);
715 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
717 Player
*me
= (Player
*)m_caster
;
718 for (std::list
<Unit
*>::const_iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end(); ++itr
)
720 Unit
*owner
= (*itr
)->GetOwner();
721 Unit
*u
= owner
? owner
: (*itr
);
722 if(u
!=m_caster
&& u
->IsPvP() && (!me
->duel
|| me
->duel
->opponent
!= u
))
725 me
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
731 for (std::list
<Unit
*>::iterator itr
= tmpUnitMap
.begin() ; itr
!= tmpUnitMap
.end();)
733 if (!CheckTarget (*itr
, i
))
735 itr
= tmpUnitMap
.erase(itr
);
742 for(std::list
<Unit
*>::iterator iunit
= tmpUnitMap
.begin();iunit
!= tmpUnitMap
.end();++iunit
)
743 AddUnitTarget((*iunit
), i
);
747 void Spell::prepareDataForTriggerSystem()
749 //==========================================================================================
750 // Now fill data for trigger system, need know:
751 // Ñan spell trigger another or not ( m_canTrigger )
752 // Create base triggers flags for Attacker and Victim ( m_procAttacker and m_procVictim)
753 //==========================================================================================
754 // Fill flag can spell trigger or not
755 // TODO: possible exist spell attribute for this
756 m_canTrigger
= false;
759 m_canTrigger
= false; // Do not trigger from item cast spell
760 else if (!m_IsTriggeredSpell
)
761 m_canTrigger
= true; // Normal cast - can trigger
762 else if (!m_triggeredByAuraSpell
)
763 m_canTrigger
= true; // Triggered from SPELL_EFFECT_TRIGGER_SPELL - can trigger
765 if (!m_canTrigger
) // Exceptions (some periodic triggers)
767 switch (m_spellInfo
->SpellFamilyName
)
769 case SPELLFAMILY_MAGE
: // Arcane Missles / Blizzard triggers need do it
770 if (m_spellInfo
->SpellFamilyFlags
& 0x0000000000200080LL
) m_canTrigger
= true;
772 case SPELLFAMILY_WARLOCK
: // For Hellfire Effect / Rain of Fire / Seed of Corruption triggers need do it
773 if (m_spellInfo
->SpellFamilyFlags
& 0x0000800000000060LL
) m_canTrigger
= true;
775 case SPELLFAMILY_PRIEST
: // For Penance heal/damage triggers need do it
776 if (m_spellInfo
->SpellFamilyFlags
& 0x0001800000000000LL
) m_canTrigger
= true;
778 case SPELLFAMILY_ROGUE
: // For poisons need do it
779 if (m_spellInfo
->SpellFamilyFlags
& 0x000000101001E000LL
) m_canTrigger
= true;
781 case SPELLFAMILY_HUNTER
: // Hunter Rapid Killing/Explosive Trap Effect/Immolation Trap Effect/Frost Trap Aura/Snake Trap Effect/Explosive Shot
782 if (m_spellInfo
->SpellFamilyFlags
& 0x0100200000000214LL
||
783 m_spellInfo
->SpellFamilyFlags2
& 0x200) m_canTrigger
= true;
785 case SPELLFAMILY_PALADIN
: // For Judgements (all) / Holy Shock triggers need do it
786 if (m_spellInfo
->SpellFamilyFlags
& 0x0001000900B80400LL
) m_canTrigger
= true;
791 // Get data for type of attack and fill base info for trigger
792 switch (m_spellInfo
->DmgClass
)
794 case SPELL_DAMAGE_CLASS_MELEE
:
795 m_procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT
;
796 m_procVictim
= PROC_FLAG_TAKEN_MELEE_SPELL_HIT
;
798 case SPELL_DAMAGE_CLASS_RANGED
:
800 if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
)
802 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
803 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
805 else // Ranged spell attack
807 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT
;
808 m_procVictim
= PROC_FLAG_TAKEN_RANGED_SPELL_HIT
;
812 if (IsPositiveSpell(m_spellInfo
->Id
)) // Check for positive spell
814 m_procAttacker
= PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
;
815 m_procVictim
= PROC_FLAG_TAKEN_POSITIVE_SPELL
;
817 else if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
) // Wands auto attack
819 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
820 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
822 else // Negative spell
824 m_procAttacker
= PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT
;
825 m_procVictim
= PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
;
829 // Hunter traps spells (for Entrapment trigger)
830 // Gives your Immolation Trap, Frost Trap, Explosive Trap, and Snake Trap ....
831 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_HUNTER
&& m_spellInfo
->SpellFamilyFlags
& 0x000020000000001CLL
)
832 m_procAttacker
|= PROC_FLAG_ON_TRAP_ACTIVATION
;
835 void Spell::CleanupTargetList()
837 m_UniqueTargetInfo
.clear();
838 m_UniqueGOTargetInfo
.clear();
839 m_UniqueItemInfo
.clear();
843 void Spell::AddUnitTarget(Unit
* pVictim
, uint32 effIndex
)
845 if( m_spellInfo
->Effect
[effIndex
]==0 )
848 // Check for effect immune skip if immuned
849 bool immuned
= pVictim
->IsImmunedToSpellEffect(m_spellInfo
, effIndex
);
851 uint64 targetGUID
= pVictim
->GetGUID();
853 // Lookup target in already in list
854 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
856 if (targetGUID
== ihit
->targetGUID
) // Found in list
859 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask if not immuned
864 // This is new target calculate data for him
866 // Get spell hit result on target
868 target
.targetGUID
= targetGUID
; // Store target GUID
869 target
.effectMask
= immuned
? 0 : 1<<effIndex
; // Store index of effect if not immuned
870 target
.processed
= false; // Effects not apply on target
872 // Calculate hit result
873 target
.missCondition
= m_caster
->SpellHitResult(pVictim
, m_spellInfo
, m_canReflect
);
875 // Spell have speed - need calculate incoming time
876 if (m_spellInfo
->speed
> 0.0f
)
878 // calculate spell incoming interval
879 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
880 if (dist
< 5.0f
) dist
= 5.0f
;
881 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
883 // Calculate minimum incoming time
884 if (m_delayMoment
==0 || m_delayMoment
>target
.timeDelay
)
885 m_delayMoment
= target
.timeDelay
;
888 target
.timeDelay
= 0LL;
890 // If target reflect spell back to caster
891 if (target
.missCondition
==SPELL_MISS_REFLECT
)
893 // Calculate reflected spell result on caster
894 target
.reflectResult
= m_caster
->SpellHitResult(m_caster
, m_spellInfo
, m_canReflect
);
896 if (target
.reflectResult
== SPELL_MISS_REFLECT
) // Impossible reflect again, so simply deflect spell
897 target
.reflectResult
= SPELL_MISS_PARRY
;
899 // Increase time interval for reflected spells by 1.5
900 target
.timeDelay
+=target
.timeDelay
>>1;
903 target
.reflectResult
= SPELL_MISS_NONE
;
905 // Add target to list
906 m_UniqueTargetInfo
.push_back(target
);
909 void Spell::AddUnitTarget(uint64 unitGUID
, uint32 effIndex
)
911 Unit
* unit
= m_caster
->GetGUID()==unitGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, unitGUID
);
913 AddUnitTarget(unit
, effIndex
);
916 void Spell::AddGOTarget(GameObject
* pVictim
, uint32 effIndex
)
918 if( m_spellInfo
->Effect
[effIndex
]==0 )
921 uint64 targetGUID
= pVictim
->GetGUID();
923 // Lookup target in already in list
924 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
926 if (targetGUID
== ihit
->targetGUID
) // Found in list
928 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask
933 // This is new target calculate data for him
936 target
.targetGUID
= targetGUID
;
937 target
.effectMask
= 1<<effIndex
;
938 target
.processed
= false; // Effects not apply on target
940 // Spell have speed - need calculate incoming time
941 if (m_spellInfo
->speed
> 0.0f
)
943 // calculate spell incoming interval
944 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
945 if (dist
< 5.0f
) dist
= 5.0f
;
946 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
947 if (m_delayMoment
==0 || m_delayMoment
>target
.timeDelay
)
948 m_delayMoment
= target
.timeDelay
;
951 target
.timeDelay
= 0LL;
953 // Add target to list
954 m_UniqueGOTargetInfo
.push_back(target
);
957 void Spell::AddGOTarget(uint64 goGUID
, uint32 effIndex
)
959 GameObject
* go
= ObjectAccessor::GetGameObject(*m_caster
, goGUID
);
961 AddGOTarget(go
, effIndex
);
964 void Spell::AddItemTarget(Item
* pitem
, uint32 effIndex
)
966 if( m_spellInfo
->Effect
[effIndex
]==0 )
969 // Lookup target in already in list
970 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
972 if (pitem
== ihit
->item
) // Found in list
974 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask
979 // This is new target add data
981 ItemTargetInfo target
;
983 target
.effectMask
= 1<<effIndex
;
984 m_UniqueItemInfo
.push_back(target
);
987 void Spell::DoAllEffectOnTarget(TargetInfo
*target
)
989 if (target
->processed
) // Check target
991 target
->processed
= true; // Target checked in apply effects procedure
993 // Get mask of effects for target
994 uint32 mask
= target
->effectMask
;
996 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
1000 // Get original caster (if exist) and calculate damage/healing from him data
1001 Unit
*caster
= m_originalCaster
? m_originalCaster
: m_caster
;
1003 // Skip if m_originalCaster not available
1007 SpellMissInfo missInfo
= target
->missCondition
;
1008 // Need init unitTarget by default unit (can changed in code on reflect)
1009 // Or on missInfo!=SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem)
1012 // Reset damage/healing counter
1016 // Fill base trigger info
1017 uint32 procAttacker
= m_procAttacker
;
1018 uint32 procVictim
= m_procVictim
;
1019 uint32 procEx
= PROC_EX_NONE
;
1021 if (missInfo
==SPELL_MISS_NONE
) // In case spell hit target, do all effect on that target
1022 DoSpellHitOnUnit(unit
, mask
);
1023 else if (missInfo
== SPELL_MISS_REFLECT
) // In case spell reflect from target, do all effect on caster (if hit)
1025 if (target
->reflectResult
== SPELL_MISS_NONE
) // If reflected spell hit caster -> do all effect on him
1026 DoSpellHitOnUnit(m_caster
, mask
);
1029 // All calculated do it!
1030 // Do healing and triggers
1033 bool crit
= caster
->isSpellCrit(NULL
, m_spellInfo
, m_spellSchoolMask
);
1034 uint32 addhealth
= m_healing
;
1037 procEx
|= PROC_EX_CRITICAL_HIT
;
1038 addhealth
= caster
->SpellCriticalHealingBonus(m_spellInfo
, addhealth
, NULL
);
1041 procEx
|= PROC_EX_NORMAL_HIT
;
1043 caster
->SendHealSpellLog(unitTarget
, m_spellInfo
->Id
, addhealth
, crit
);
1045 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1046 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1047 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, addhealth
, m_attackType
, m_spellInfo
);
1049 int32 gain
= unitTarget
->ModifyHealth( int32(addhealth
) );
1051 unitTarget
->getHostilRefManager().threatAssist(caster
, float(gain
) * 0.5f
, m_spellInfo
);
1052 if(caster
->GetTypeId()==TYPEID_PLAYER
)
1053 if(BattleGround
*bg
= ((Player
*)caster
)->GetBattleGround())
1054 bg
->UpdatePlayerScore(((Player
*)caster
), SCORE_HEALING_DONE
, gain
);
1056 // Do damage and triggers
1059 // Fill base damage struct (unitTarget - is real spell target)
1060 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1062 // Add bonuses and fill damageInfo struct
1063 caster
->CalculateSpellDamage(&damageInfo
, m_damage
, m_spellInfo
);
1065 // Send log damage message to client
1066 caster
->SendSpellNonMeleeDamageLog(&damageInfo
);
1068 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1069 procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1071 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1072 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1073 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, damageInfo
.damage
, m_attackType
, m_spellInfo
);
1075 caster
->DealSpellDamage(&damageInfo
, true);
1077 // Judgement of Blood
1078 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& m_spellInfo
->SpellFamilyFlags
& 0x0000000800000000LL
&& m_spellInfo
->SpellIconID
==153)
1080 int32 damagePoint
= damageInfo
.damage
* 33 / 100;
1081 m_caster
->CastCustomSpell(m_caster
, 32220, &damagePoint
, NULL
, NULL
, true);
1084 // Passive spell hits/misses or active spells only misses (only triggers)
1087 // Fill base damage struct (unitTarget - is real spell target)
1088 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1089 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1090 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1091 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1092 caster
->ProcDamageAndSpell(unit
, procAttacker
, procVictim
, procEx
, 0, m_attackType
, m_spellInfo
);
1095 // Call scripted function for AI if this spell is casted upon a creature
1096 if(unit
->GetTypeId()==TYPEID_UNIT
)
1098 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1099 // ignore pets or autorepeat/melee casts for speed (not exist quest for spells (hm... )
1100 if( !((Creature
*)unit
)->isPet() && m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1101 ((Player
*)m_caster
)->CastedCreatureOrGO(unit
->GetEntry(),unit
->GetGUID(),m_spellInfo
->Id
);
1103 if(((Creature
*)unit
)->AI())
1104 ((Creature
*)unit
)->AI()->SpellHit(m_caster
,m_spellInfo
);
1107 // Call scripted function for AI if this spell is casted by a creature
1108 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)m_caster
)->AI())
1109 ((Creature
*)m_caster
)->AI()->SpellHitTarget(unit
,m_spellInfo
);
1112 void Spell::DoSpellHitOnUnit(Unit
*unit
, const uint32 effectMask
)
1114 if(!unit
|| !effectMask
)
1117 // Recheck immune (only for delayed spells)
1118 if( m_spellInfo
->speed
&& (
1119 unit
->IsImmunedToDamage(GetSpellSchoolMask(m_spellInfo
)) ||
1120 unit
->IsImmunedToSpell(m_spellInfo
)))
1122 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_IMMUNE
);
1126 if (unit
->GetTypeId() == TYPEID_PLAYER
)
1128 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET
, m_spellInfo
->Id
);
1129 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2
, m_spellInfo
->Id
);
1132 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
1134 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2
, m_spellInfo
->Id
, 0, unit
);
1137 if( m_caster
!= unit
)
1139 // Recheck UNIT_FLAG_NON_ATTACKABLE for delayed spells
1140 if (m_spellInfo
->speed
> 0.0f
&&
1141 unit
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
) &&
1142 unit
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
1144 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1148 if( !m_caster
->IsFriendlyTo(unit
) )
1150 // for delayed spells ignore not visible explicit target
1151 if(m_spellInfo
->speed
> 0.0f
&& unit
==m_targets
.getUnitTarget() && !unit
->isVisibleForOrDetect(m_caster
,false))
1153 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1157 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1159 if( !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) )
1161 if(!unit
->IsStandState() && !unit
->hasUnitState(UNIT_STAT_STUNNED
))
1162 unit
->SetStandState(UNIT_STAND_STATE_STAND
);
1164 if(!unit
->isInCombat() && unit
->GetTypeId() != TYPEID_PLAYER
&& ((Creature
*)unit
)->AI())
1165 ((Creature
*)unit
)->AI()->AttackedBy(m_caster
);
1167 unit
->SetInCombatWith(m_caster
);
1168 m_caster
->SetInCombatWith(unit
);
1170 if(Player
*attackedPlayer
= unit
->GetCharmerOrOwnerPlayerOrPlayerItself())
1172 m_caster
->SetContestedPvP(attackedPlayer
);
1174 unit
->AddThreat(m_caster
, 0.0f
);
1179 // for delayed spells ignore negative spells (after duel end) for friendly targets
1180 if(m_spellInfo
->speed
> 0.0f
&& !IsPositiveSpell(m_spellInfo
->Id
))
1182 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1186 // assisting case, healing and resurrection
1187 if(unit
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
1188 m_caster
->SetContestedPvP();
1189 if( unit
->isInCombat() && !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) )
1191 m_caster
->SetInCombatState(unit
->GetCombatTimer() > 0);
1192 unit
->getHostilRefManager().threatAssist(m_caster
, 0.0f
);
1197 // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
1198 m_diminishGroup
= GetDiminishingReturnsGroupForSpell(m_spellInfo
,m_triggeredByAuraSpell
);
1199 m_diminishLevel
= unit
->GetDiminishing(m_diminishGroup
);
1200 // Increase Diminishing on unit, current informations for actually casts will use values above
1201 if((GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_PLAYER
&& unit
->GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_ALL
)
1202 unit
->IncrDiminishing(m_diminishGroup
);
1204 // Apply additional spell effects to target
1206 m_caster
->CastSpell(unit
,m_preCastSpell
, true, m_CastItem
);
1208 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1210 if (effectMask
& (1<<effectNumber
))
1212 HandleEffects(unit
,NULL
,NULL
,effectNumber
,m_damageMultipliers
[effectNumber
]);
1213 if ( m_applyMultiplierMask
& (1 << effectNumber
) )
1216 float multiplier
= m_spellInfo
->DmgMultiplier
[effectNumber
];
1217 // Apply multiplier mods
1218 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1219 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_EFFECT_PAST_FIRST
, multiplier
,this);
1220 m_damageMultipliers
[effectNumber
] *= multiplier
;
1226 void Spell::DoAllEffectOnTarget(GOTargetInfo
*target
)
1228 if (target
->processed
) // Check target
1230 target
->processed
= true; // Target checked in apply effects procedure
1232 uint32 effectMask
= target
->effectMask
;
1236 GameObject
* go
= ObjectAccessor::GetGameObject(*m_caster
, target
->targetGUID
);
1240 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1241 if (effectMask
& (1<<effectNumber
))
1242 HandleEffects(NULL
,NULL
,go
,effectNumber
);
1244 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1245 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
1246 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1247 ((Player
*)m_caster
)->CastedCreatureOrGO(go
->GetEntry(),go
->GetGUID(),m_spellInfo
->Id
);
1250 void Spell::DoAllEffectOnTarget(ItemTargetInfo
*target
)
1252 uint32 effectMask
= target
->effectMask
;
1253 if(!target
->item
|| !effectMask
)
1256 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1257 if (effectMask
& (1<<effectNumber
))
1258 HandleEffects(NULL
, target
->item
, NULL
, effectNumber
);
1261 bool Spell::IsAliveUnitPresentInTargetList()
1263 // Not need check return true
1264 if (m_needAliveTargetMask
== 0)
1267 uint8 needAliveTargetMask
= m_needAliveTargetMask
;
1269 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
1271 if( ihit
->missCondition
== SPELL_MISS_NONE
&& (needAliveTargetMask
& ihit
->effectMask
) )
1273 Unit
*unit
= m_caster
->GetGUID()==ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
1275 if (unit
&& unit
->isAlive())
1276 needAliveTargetMask
&= ~ihit
->effectMask
; // remove from need alive mask effect that have alive target
1280 // is all effects from m_needAliveTargetMask have alive targets
1281 return needAliveTargetMask
==0;
1284 // Helper for Chain Healing
1285 // Spell target first
1286 // Raidmates then descending by injury suffered (MaxHealth - Health)
1287 // Other players/mobs then descending by injury suffered (MaxHealth - Health)
1288 struct ChainHealingOrder
: public std::binary_function
<const Unit
*, const Unit
*, bool>
1290 const Unit
* MainTarget
;
1291 ChainHealingOrder(Unit
const* Target
) : MainTarget(Target
) {};
1292 // functor for operator ">"
1293 bool operator()(Unit
const* _Left
, Unit
const* _Right
) const
1295 return (ChainHealingHash(_Left
) < ChainHealingHash(_Right
));
1297 int32
ChainHealingHash(Unit
const* Target
) const
1299 if (Target
== MainTarget
)
1301 else if (Target
->GetTypeId() == TYPEID_PLAYER
&& MainTarget
->GetTypeId() == TYPEID_PLAYER
&&
1302 ((Player
const*)Target
)->IsInSameRaidWith((Player
const*)MainTarget
))
1304 if (Target
->GetHealth() == Target
->GetMaxHealth())
1307 return 20000 - Target
->GetMaxHealth() + Target
->GetHealth();
1310 return 40000 - Target
->GetMaxHealth() + Target
->GetHealth();
1314 class ChainHealingFullHealth
: std::unary_function
<const Unit
*, bool>
1317 const Unit
* MainTarget
;
1318 ChainHealingFullHealth(const Unit
* Target
) : MainTarget(Target
) {};
1320 bool operator()(const Unit
* Target
)
1322 return (Target
!= MainTarget
&& Target
->GetHealth() == Target
->GetMaxHealth());
1326 // Helper for targets nearest to the spell target
1327 // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
1328 struct TargetDistanceOrder
: public std::binary_function
<const Unit
, const Unit
, bool>
1330 const Unit
* MainTarget
;
1331 TargetDistanceOrder(const Unit
* Target
) : MainTarget(Target
) {};
1332 // functor for operator ">"
1333 bool operator()(const Unit
* _Left
, const Unit
* _Right
) const
1335 return (MainTarget
->GetDistance(_Left
) < MainTarget
->GetDistance(_Right
));
1339 void Spell::SetTargetMap(uint32 i
,uint32 cur
,UnitList
& TagUnitMap
)
1342 if (m_spellInfo
->EffectRadiusIndex
[i
])
1343 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
1345 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
));
1347 if(m_originalCaster
)
1348 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1349 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RADIUS
, radius
,this);
1351 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[i
];
1352 if(m_originalCaster
)
1353 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1354 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
1356 // Get spell max affected targets
1357 uint32 unMaxTargets
= m_spellInfo
->MaxAffectedTargets
;
1359 // custom target amount cases
1360 switch(m_spellInfo
->SpellFamilyName
)
1362 case SPELLFAMILY_DRUID
:
1364 if (m_spellInfo
->SpellFamilyFlags2
& 0x00000100LL
)
1371 Unit::AuraList
const& mod
= m_caster
->GetAurasByType(SPELL_AURA_MOD_MAX_AFFECTED_TARGETS
);
1372 for(Unit::AuraList::const_iterator m
= mod
.begin(); m
!= mod
.end(); ++m
)
1374 if (!(*m
)->isAffectedOnSpell(m_spellInfo
))
1376 unMaxTargets
+=(*m
)->GetModifier()->m_amount
;
1381 case TARGET_TOTEM_EARTH
:
1382 case TARGET_TOTEM_WATER
:
1383 case TARGET_TOTEM_AIR
:
1384 case TARGET_TOTEM_FIRE
:
1387 case TARGET_DYNAMIC_OBJECT
:
1388 case TARGET_AREAEFFECT_CUSTOM
:
1389 case TARGET_AREAEFFECT_CUSTOM_2
:
1392 TagUnitMap
.push_back(m_caster
);
1395 case TARGET_RANDOM_ENEMY_CHAIN_IN_AREA
:
1397 m_targets
.m_targetMask
= 0;
1398 unMaxTargets
= EffectChainTarget
;
1399 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1401 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1403 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1406 std::list
<Unit
*> tempUnitMap
;
1409 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1410 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1412 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1413 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1415 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1416 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1417 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1420 if(tempUnitMap
.empty())
1423 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1425 //Now to get us a random target that's in the initial range of the spell
1427 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1428 while(itr
!= tempUnitMap
.end() && (*itr
)->GetDistance(m_caster
) < radius
)
1434 itr
= tempUnitMap
.begin();
1435 std::advance(itr
, rand()%t
);
1436 Unit
*pUnitTarget
= *itr
;
1437 TagUnitMap
.push_back(pUnitTarget
);
1439 tempUnitMap
.erase(itr
);
1441 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1443 t
= unMaxTargets
- 1;
1444 Unit
*prev
= pUnitTarget
;
1445 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1447 while(t
&& next
!= tempUnitMap
.end() )
1449 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
1452 if(!prev
->IsWithinLOSInMap(*next
))
1459 TagUnitMap
.push_back(prev
);
1460 tempUnitMap
.erase(next
);
1461 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1462 next
= tempUnitMap
.begin();
1467 case TARGET_RANDOM_FRIEND_CHAIN_IN_AREA
:
1469 m_targets
.m_targetMask
= 0;
1470 unMaxTargets
= EffectChainTarget
;
1471 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1472 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1474 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1476 std::list
<Unit
*> tempUnitMap
;
1478 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1479 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1481 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1482 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1484 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1485 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1486 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1489 if(tempUnitMap
.empty())
1492 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1494 //Now to get us a random target that's in the initial range of the spell
1496 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1497 while(itr
!= tempUnitMap
.end() && (*itr
)->GetDistance(m_caster
) < radius
)
1503 itr
= tempUnitMap
.begin();
1504 std::advance(itr
, rand()%t
);
1505 Unit
*pUnitTarget
= *itr
;
1506 TagUnitMap
.push_back(pUnitTarget
);
1508 tempUnitMap
.erase(itr
);
1510 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1512 t
= unMaxTargets
- 1;
1513 Unit
*prev
= pUnitTarget
;
1514 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1516 while(t
&& next
!= tempUnitMap
.end() )
1518 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
1521 if(!prev
->IsWithinLOSInMap(*next
))
1527 TagUnitMap
.push_back(prev
);
1528 tempUnitMap
.erase(next
);
1529 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1530 next
= tempUnitMap
.begin();
1536 Pet
* tmpUnit
= m_caster
->GetPet();
1537 if (!tmpUnit
) break;
1538 TagUnitMap
.push_back(tmpUnit
);
1541 case TARGET_CHAIN_DAMAGE
:
1543 if (EffectChainTarget
<= 1)
1545 Unit
* pUnitTarget
= SelectMagnetTarget();
1547 TagUnitMap
.push_back(pUnitTarget
);
1551 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1555 unMaxTargets
= EffectChainTarget
;
1558 if(m_spellInfo
->DmgClass
==SPELL_DAMAGE_CLASS_MELEE
)
1559 max_range
= radius
; //
1561 //FIXME: This very like horrible hack and wrong for most spells
1562 max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1564 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1566 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1569 Unit
* originalCaster
= GetOriginalCaster();
1572 std::list
<Unit
*> tempUnitMap
;
1575 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(pUnitTarget
, originalCaster
, max_range
);
1576 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1578 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1579 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1581 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1582 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1583 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1586 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1588 if(tempUnitMap
.empty())
1591 if(*tempUnitMap
.begin() == pUnitTarget
)
1592 tempUnitMap
.erase(tempUnitMap
.begin());
1594 TagUnitMap
.push_back(pUnitTarget
);
1595 uint32 t
= unMaxTargets
- 1;
1596 Unit
*prev
= pUnitTarget
;
1597 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1599 while(t
&& next
!= tempUnitMap
.end() )
1601 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
1604 if(!prev
->IsWithinLOSInMap(*next
))
1611 TagUnitMap
.push_back(prev
);
1612 tempUnitMap
.erase(next
);
1613 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1614 next
= tempUnitMap
.begin();
1621 case TARGET_ALL_ENEMY_IN_AREA
:
1623 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1626 case TARGET_AREAEFFECT_INSTANT
:
1628 SpellTargets targetB
= SPELL_TARGETS_AOE_DAMAGE
;
1629 // Select friendly targets for positive effect
1630 if (IsPositiveEffect(m_spellInfo
->Id
, i
))
1631 targetB
= SPELL_TARGETS_FRIENDLY
;
1633 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),radius
, PUSH_DEST_CENTER
, targetB
);
1636 TagUnitMap
.remove(m_caster
);
1638 case TARGET_ALL_ENEMY_IN_AREA_INSTANT
:
1640 // targets the ground, not the units in the area
1641 if (m_spellInfo
->Effect
[i
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1643 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1645 // exclude caster (this can be important if this not original caster)
1646 TagUnitMap
.remove(m_caster
);
1649 case TARGET_DUELVSPLAYER_COORDINATES
:
1651 if(Unit
* currentTarget
= m_targets
.getUnitTarget())
1653 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1654 TagUnitMap
.push_back(currentTarget
);
1657 case TARGET_ALL_PARTY_AROUND_CASTER
:
1658 case TARGET_ALL_PARTY_AROUND_CASTER_2
:
1659 case TARGET_ALL_PARTY
:
1661 Player
*pTarget
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself();
1662 Group
*pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1666 uint8 subgroup
= pTarget
->GetSubGroup();
1668 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1670 Player
* Target
= itr
->getSource();
1672 // IsHostileTo check duel and controlled by enemy
1673 if( Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
) )
1675 if( m_caster
->IsWithinDistInMap(Target
, radius
) )
1676 TagUnitMap
.push_back(Target
);
1678 if(Pet
* pet
= Target
->GetPet())
1679 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1680 TagUnitMap
.push_back(pet
);
1686 Unit
* ownerOrSelf
= pTarget
? pTarget
: m_caster
->GetCharmerOrOwnerOrSelf();
1687 if(ownerOrSelf
==m_caster
|| m_caster
->IsWithinDistInMap(ownerOrSelf
, radius
))
1688 TagUnitMap
.push_back(ownerOrSelf
);
1689 if(Pet
* pet
= ownerOrSelf
->GetPet())
1690 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1691 TagUnitMap
.push_back(pet
);
1695 case TARGET_ALL_RAID_AROUND_CASTER
:
1697 Player
*pTarget
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself();
1698 Group
*pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1700 if(m_spellInfo
->Id
==57669) //Replenishment (special target selection)
1704 typedef std::priority_queue
<PrioritizeManaPlayerWraper
, std::vector
<PrioritizeManaPlayerWraper
>, PrioritizeMana
> Top10
;
1707 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
&& manaUsers
.size() < 10; itr
= itr
->next())
1709 Player
* Target
= itr
->getSource();
1710 if (m_caster
->GetGUID() != Target
->GetGUID() && Target
->getPowerType() == POWER_MANA
&&
1711 !Target
->isDead() && m_caster
->IsWithinDistInMap(Target
, radius
))
1713 PrioritizeManaPlayerWraper
WTarget(Target
);
1714 manaUsers
.push(WTarget
);
1718 while(!manaUsers
.empty())
1720 TagUnitMap
.push_back(manaUsers
.top().getPlayer());
1726 Unit
* ownerOrSelf
= pTarget
? pTarget
: m_caster
->GetCharmerOrOwnerOrSelf();
1727 if ((ownerOrSelf
==m_caster
|| m_caster
->IsWithinDistInMap(ownerOrSelf
, radius
)) &&
1728 ownerOrSelf
->getPowerType() == POWER_MANA
)
1729 TagUnitMap
.push_back(ownerOrSelf
);
1731 if(Pet
* pet
= ownerOrSelf
->GetPet())
1732 if( m_caster
->IsWithinDistInMap(pet
, radius
) && pet
->getPowerType() == POWER_MANA
)
1733 TagUnitMap
.push_back(pet
);
1740 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1742 Player
* Target
= itr
->getSource();
1744 // IsHostileTo check duel and controlled by enemy
1745 if( Target
&& !m_caster
->IsHostileTo(Target
) )
1747 if( m_caster
->IsWithinDistInMap(Target
, radius
) )
1748 TagUnitMap
.push_back(Target
);
1750 if(Pet
* pet
= Target
->GetPet())
1751 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1752 TagUnitMap
.push_back(pet
);
1758 Unit
* ownerOrSelf
= pTarget
? pTarget
: m_caster
->GetCharmerOrOwnerOrSelf();
1759 if(ownerOrSelf
==m_caster
|| m_caster
->IsWithinDistInMap(ownerOrSelf
, radius
))
1760 TagUnitMap
.push_back(ownerOrSelf
);
1761 if(Pet
* pet
= ownerOrSelf
->GetPet())
1762 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1763 TagUnitMap
.push_back(pet
);
1768 case TARGET_SINGLE_FRIEND
:
1769 case TARGET_SINGLE_FRIEND_2
:
1771 if(m_targets
.getUnitTarget())
1772 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1774 case TARGET_NONCOMBAT_PET
:
1776 if(Unit
* target
= m_targets
.getUnitTarget())
1777 if( target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet() && ((Pet
*)target
)->getPetType() == MINI_PET
)
1778 TagUnitMap
.push_back(target
);
1780 case TARGET_CASTER_COORDINATES
:
1782 // Check original caster is GO - set its coordinates as dst cast
1783 WorldObject
*caster
= NULL
;
1784 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
1785 caster
= ObjectAccessor::GetGameObject(*m_caster
, m_originalCasterGUID
);
1788 // Set dest for targets
1789 m_targets
.setDestination(caster
->GetPositionX(), caster
->GetPositionY(), caster
->GetPositionZ());
1791 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER
:
1792 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_SELF_CENTER
,SPELL_TARGETS_FRIENDLY
);
1794 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA
:
1795 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_FRIENDLY
);
1797 // 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..)
1798 case TARGET_SINGLE_PARTY
:
1800 Unit
*target
= m_targets
.getUnitTarget();
1801 // Thoses spells apparently can't be casted on the caster.
1802 if( target
&& target
!= m_caster
)
1804 // Can only be casted on group's members or its pets
1805 Group
*pGroup
= NULL
;
1807 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1808 Unit
*targetOwner
= target
->GetCharmerOrOwner();
1811 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1813 if( target
== owner
)
1815 TagUnitMap
.push_back(target
);
1818 pGroup
= ((Player
*)owner
)->GetGroup();
1821 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1823 if( targetOwner
== m_caster
&& target
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)target
)->isPet())
1825 TagUnitMap
.push_back(target
);
1828 pGroup
= ((Player
*)m_caster
)->GetGroup();
1833 // Our target can also be a player's pet who's grouped with us or our pet. But can't be controlled player
1836 if( targetOwner
->GetTypeId() == TYPEID_PLAYER
&&
1837 target
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)target
)->isPet()) &&
1838 target
->GetOwnerGUID()==targetOwner
->GetGUID() &&
1839 pGroup
->IsMember(((Player
*)targetOwner
)->GetGUID()))
1841 TagUnitMap
.push_back(target
);
1844 // 1Our target can be a player who is on our group
1845 else if (target
->GetTypeId() == TYPEID_PLAYER
&& pGroup
->IsMember(((Player
*)target
)->GetGUID()))
1847 TagUnitMap
.push_back(target
);
1852 case TARGET_GAMEOBJECT
:
1854 if(m_targets
.getGOTarget())
1855 AddGOTarget(m_targets
.getGOTarget(), i
);
1857 case TARGET_IN_FRONT_OF_CASTER
:
1859 bool inFront
= m_spellInfo
->SpellVisual
[0] != 3879;
1860 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),radius
,inFront
? PUSH_IN_FRONT
: PUSH_IN_BACK
,SPELL_TARGETS_AOE_DAMAGE
);
1863 case TARGET_DUELVSPLAYER
:
1865 Unit
*target
= m_targets
.getUnitTarget();
1868 if(m_caster
->IsFriendlyTo(target
))
1870 TagUnitMap
.push_back(target
);
1874 Unit
* pUnitTarget
= SelectMagnetTarget();
1876 TagUnitMap
.push_back(pUnitTarget
);
1880 case TARGET_GAMEOBJECT_ITEM
:
1882 if(m_targets
.getGOTargetGUID())
1883 AddGOTarget(m_targets
.getGOTarget(), i
);
1884 else if(m_targets
.getItemTarget())
1885 AddItemTarget(m_targets
.getItemTarget(), i
);
1890 if(Unit
* owner
= m_caster
->GetCharmerOrOwner())
1891 TagUnitMap
.push_back(owner
);
1894 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED
:
1896 // targets the ground, not the units in the area
1897 if (m_spellInfo
->Effect
[i
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1898 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1903 if(m_spellInfo
->Effect
[i
] != SPELL_EFFECT_DUEL
)
1904 TagUnitMap
.push_back(m_caster
);
1906 case TARGET_SINGLE_ENEMY
:
1908 Unit
* pUnitTarget
= SelectMagnetTarget();
1910 TagUnitMap
.push_back(pUnitTarget
);
1912 case TARGET_AREAEFFECT_PARTY
:
1914 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1915 Player
*pTarget
= NULL
;
1919 TagUnitMap
.push_back(m_caster
);
1920 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1921 pTarget
= (Player
*)owner
;
1923 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1925 if(Unit
* target
= m_targets
.getUnitTarget())
1927 if( target
->GetTypeId() != TYPEID_PLAYER
)
1929 if(((Creature
*)target
)->isPet())
1931 Unit
*targetOwner
= target
->GetOwner();
1932 if(targetOwner
->GetTypeId() == TYPEID_PLAYER
)
1933 pTarget
= (Player
*)targetOwner
;
1937 pTarget
= (Player
*)target
;
1941 Group
* pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1945 uint8 subgroup
= pTarget
->GetSubGroup();
1947 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1949 Player
* Target
= itr
->getSource();
1951 // IsHostileTo check duel and controlled by enemy
1952 if(Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
))
1954 if( pTarget
->IsWithinDistInMap(Target
, radius
) )
1955 TagUnitMap
.push_back(Target
);
1957 if(Pet
* pet
= Target
->GetPet())
1958 if( pTarget
->IsWithinDistInMap(pet
, radius
) )
1959 TagUnitMap
.push_back(pet
);
1965 if(m_caster
->IsWithinDistInMap(owner
, radius
))
1966 TagUnitMap
.push_back(owner
);
1970 TagUnitMap
.push_back(pTarget
);
1972 if(Pet
* pet
= pTarget
->GetPet())
1973 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1974 TagUnitMap
.push_back(pet
);
1980 if(m_targets
.getUnitTarget())
1981 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1982 if(m_targets
.getItemTarget())
1983 AddItemTarget(m_targets
.getItemTarget(), i
);
1985 case TARGET_SELF_FISHING
:
1987 TagUnitMap
.push_back(m_caster
);
1989 case TARGET_CHAIN_HEAL
:
1991 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1995 if (EffectChainTarget
<= 1)
1996 TagUnitMap
.push_back(pUnitTarget
);
1999 unMaxTargets
= EffectChainTarget
;
2000 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
2002 UnitList tempUnitMap
;
2004 FillAreaTargets(tempUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),max_range
,PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
2006 if(m_caster
!= pUnitTarget
&& std::find(tempUnitMap
.begin(),tempUnitMap
.end(),m_caster
) == tempUnitMap
.end() )
2007 tempUnitMap
.push_front(m_caster
);
2009 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
2011 if(tempUnitMap
.empty())
2014 if(*tempUnitMap
.begin() == pUnitTarget
)
2015 tempUnitMap
.erase(tempUnitMap
.begin());
2017 TagUnitMap
.push_back(pUnitTarget
);
2018 uint32 t
= unMaxTargets
- 1;
2019 Unit
*prev
= pUnitTarget
;
2020 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
2022 while(t
&& next
!= tempUnitMap
.end() )
2024 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
2027 if(!prev
->IsWithinLOSInMap(*next
))
2033 if((*next
)->GetHealth() == (*next
)->GetMaxHealth())
2035 next
= tempUnitMap
.erase(next
);
2040 TagUnitMap
.push_back(prev
);
2041 tempUnitMap
.erase(next
);
2042 tempUnitMap
.sort(TargetDistanceOrder(prev
));
2043 next
= tempUnitMap
.begin();
2049 case TARGET_CURRENT_ENEMY_COORDINATES
:
2051 Unit
* currentTarget
= m_targets
.getUnitTarget();
2054 TagUnitMap
.push_back(currentTarget
);
2055 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
2056 if(m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_ALL_ENEMY_IN_AREA_INSTANT
)
2057 FillAreaTargets(TagUnitMap
, currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), radius
, PUSH_TARGET_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
2061 case TARGET_AREAEFFECT_PARTY_AND_CLASS
:
2063 Player
* targetPlayer
= m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
2064 ? (Player
*)m_targets
.getUnitTarget() : NULL
;
2066 Group
* pGroup
= targetPlayer
? targetPlayer
->GetGroup() : NULL
;
2069 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2071 Player
* Target
= itr
->getSource();
2073 // IsHostileTo check duel and controlled by enemy
2074 if( Target
&& targetPlayer
->IsWithinDistInMap(Target
, radius
) &&
2075 targetPlayer
->getClass() == Target
->getClass() &&
2076 !m_caster
->IsHostileTo(Target
) )
2078 TagUnitMap
.push_back(Target
);
2082 else if(m_targets
.getUnitTarget())
2083 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2086 case TARGET_TABLE_X_Y_Z_COORDINATES
:
2088 SpellTargetPosition
const* st
= spellmgr
.GetSpellTargetPosition(m_spellInfo
->Id
);
2091 if (st
->target_mapId
== m_caster
->GetMapId())
2092 m_targets
.setDestination(st
->target_X
, st
->target_Y
, st
->target_Z
);
2094 sLog
.outError( "SPELL: wrong map (%u instead %u) target coordinates for spell ID %u", st
->target_mapId
, m_caster
->GetMapId(), m_spellInfo
->Id
);
2097 sLog
.outError( "SPELL: unknown target coordinates for spell ID %u", m_spellInfo
->Id
);
2099 case TARGET_BEHIND_VICTIM
:
2101 Unit
*pTarget
= NULL
;
2103 // explicit cast data from client or server-side cast
2104 // some spell at client send caster
2105 if(m_targets
.getUnitTarget() && m_targets
.getUnitTarget()!=m_caster
)
2106 pTarget
= m_targets
.getUnitTarget();
2107 else if(m_caster
->getVictim())
2108 pTarget
= m_caster
->getVictim();
2109 else if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
2110 pTarget
= ObjectAccessor::GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection());
2114 float _target_x
, _target_y
, _target_z
;
2115 pTarget
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), CONTACT_DISTANCE
, M_PI
);
2116 if(pTarget
->IsWithinLOS(_target_x
,_target_y
,_target_z
))
2118 TagUnitMap
.push_back(m_caster
);
2119 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2124 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
2126 // if parent spell create dynamic object extract area from it
2127 if(DynamicObject
* dynObj
= m_caster
->GetDynObject(m_triggeredByAuraSpell
? m_triggeredByAuraSpell
->Id
: m_spellInfo
->Id
))
2128 m_targets
.setDestination(dynObj
->GetPositionX(), dynObj
->GetPositionY(), dynObj
->GetPositionZ());
2131 case TARGET_DIRECTLY_FORWARD
:
2133 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2135 SpellRangeEntry
const* rEntry
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
2136 float minRange
= GetSpellMinRange(rEntry
);
2137 float maxRange
= GetSpellMaxRange(rEntry
);
2138 float dist
= minRange
+ rand_norm()*(maxRange
-minRange
);
2140 float _target_x
, _target_y
, _target_z
;
2141 m_caster
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), dist
);
2142 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2145 TagUnitMap
.push_back(m_caster
);
2152 if (unMaxTargets
&& TagUnitMap
.size() > unMaxTargets
)
2154 // make sure one unit is always removed per iteration
2155 uint32 removed_utarget
= 0;
2156 for (UnitList::iterator itr
= TagUnitMap
.begin(), next
; itr
!= TagUnitMap
.end(); itr
= next
)
2160 if (!*itr
) continue;
2161 if ((*itr
) == m_targets
.getUnitTarget())
2163 TagUnitMap
.erase(itr
);
2164 removed_utarget
= 1;
2168 // remove random units from the map
2169 while (TagUnitMap
.size() > unMaxTargets
- removed_utarget
)
2171 uint32 poz
= urand(0, TagUnitMap
.size()-1);
2172 for (UnitList::iterator itr
= TagUnitMap
.begin(); itr
!= TagUnitMap
.end(); ++itr
, --poz
)
2174 if (!*itr
) continue;
2178 TagUnitMap
.erase(itr
);
2183 // the player's target will always be added to the map
2184 if (removed_utarget
&& m_targets
.getUnitTarget())
2185 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2189 void Spell::prepare(SpellCastTargets
const* targets
, Aura
* triggeredByAura
)
2191 m_targets
= *targets
;
2193 m_spellState
= SPELL_STATE_PREPARING
;
2195 m_castPositionX
= m_caster
->GetPositionX();
2196 m_castPositionY
= m_caster
->GetPositionY();
2197 m_castPositionZ
= m_caster
->GetPositionZ();
2198 m_castOrientation
= m_caster
->GetOrientation();
2201 m_triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
2203 // create and add update event for this spell
2204 SpellEvent
* Event
= new SpellEvent(this);
2205 m_caster
->m_Events
.AddEvent(Event
, m_caster
->m_Events
.CalculateTime(1));
2207 //Prevent casting at cast another spell (ServerSide check)
2208 if(m_caster
->IsNonMeleeSpellCasted(false, true, true) && m_cast_count
)
2210 SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS
);
2216 m_powerCost
= CalculatePowerCost();
2218 SpellCastResult result
= CheckCast(true);
2219 if(result
!= SPELL_CAST_OK
&& !IsAutoRepeat()) //always cast autorepeat dummy for triggering
2223 SendChannelUpdate(0);
2224 triggeredByAura
->SetAuraDuration(0);
2226 SendCastResult(result
);
2231 // Prepare data for triggers
2232 prepareDataForTriggerSystem();
2234 // calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
2235 m_casttime
= GetSpellCastTime(m_spellInfo
, this);
2237 // set timer base at cast time
2240 // stealth must be removed at cast starting (at show channel bar)
2241 // skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
2242 if ( !m_IsTriggeredSpell
&& isSpellBreakStealth(m_spellInfo
) )
2244 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
2245 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
2248 if(m_IsTriggeredSpell
)
2252 m_caster
->SetCurrentCastedSpell( this );
2253 m_selfContainer
= &(m_caster
->m_currentSpells
[GetCurrentContainer()]);
2258 void Spell::cancel()
2260 if(m_spellState
== SPELL_STATE_FINISHED
)
2263 m_autoRepeat
= false;
2264 switch (m_spellState
)
2266 case SPELL_STATE_PREPARING
:
2267 case SPELL_STATE_DELAYED
:
2270 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2273 case SPELL_STATE_CASTING
:
2275 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2277 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2279 Unit
* unit
= m_caster
->GetGUID()==(*ihit
).targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2280 if( unit
&& unit
->isAlive() )
2281 unit
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2285 m_caster
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2286 SendChannelUpdate(0);
2288 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2297 m_caster
->RemoveDynObject(m_spellInfo
->Id
);
2298 m_caster
->RemoveGameObject(m_spellInfo
->Id
,true);
2301 void Spell::cast(bool skipCheck
)
2303 SetExecutedCurrently(true);
2305 // update pointers base at GUIDs to prevent access to non-existed already object
2308 // cancel at lost main target unit
2309 if(!m_targets
.getUnitTarget() && m_targets
.getUnitTargetGUID() && m_targets
.getUnitTargetGUID() != m_caster
->GetGUID())
2312 SetExecutedCurrently(false);
2316 if(m_caster
->GetTypeId() != TYPEID_PLAYER
&& m_targets
.getUnitTarget() && m_targets
.getUnitTarget() != m_caster
)
2317 m_caster
->SetInFront(m_targets
.getUnitTarget());
2319 SpellCastResult castResult
= CheckPower();
2320 if(castResult
!= SPELL_CAST_OK
)
2322 SendCastResult(castResult
);
2324 SetExecutedCurrently(false);
2328 // triggered cast called from Spell::prepare where it was already checked
2331 castResult
= CheckCast(false);
2332 if(castResult
!= SPELL_CAST_OK
)
2334 SendCastResult(castResult
);
2336 SetExecutedCurrently(false);
2341 switch(m_spellInfo
->SpellFamilyName
)
2343 case SPELLFAMILY_GENERIC
:
2345 if (m_spellInfo
->Mechanic
== MECHANIC_BANDAGE
) // Bandages
2346 m_preCastSpell
= 11196; // Recently Bandaged
2347 else if(m_spellInfo
->SpellIconID
== 1662 && m_spellInfo
->AttributesEx
& 0x20) // Blood Fury (Racial)
2348 m_preCastSpell
= 23230; // Blood Fury - Healing Reduction
2351 case SPELLFAMILY_MAGE
:
2353 if (m_spellInfo
->SpellFamilyFlags
&0x0000008000000000LL
) // Ice Block
2354 m_preCastSpell
= 41425; // Hypothermia
2357 case SPELLFAMILY_PRIEST
:
2359 if (m_spellInfo
->Mechanic
== MECHANIC_SHIELD
&&
2360 m_spellInfo
->SpellIconID
== 566) // Power Word: Shield
2361 m_preCastSpell
= 6788; // Weakened Soul
2362 if (m_spellInfo
->Id
== 47585) // Dispersion (transform)
2363 m_preCastSpell
= 60069; // Dispersion (mana regen)
2366 case SPELLFAMILY_PALADIN
:
2368 if (m_spellInfo
->SpellFamilyFlags
&0x0000000000400080LL
) // Divine Shield, Divine Protection or Hand of Protection
2369 m_preCastSpell
= 25771; // Forbearance
2372 case SPELLFAMILY_SHAMAN
:
2374 if (m_spellInfo
->Id
== 2825) // Bloodlust
2375 m_preCastSpell
= 57724; // Sated
2376 else if (m_spellInfo
->Id
== 32182) // Heroism
2377 m_preCastSpell
= 57723; // Exhaustion
2384 // Conflagrate - consumes immolate
2385 if ((m_spellInfo
->TargetAuraState
== AURA_STATE_IMMOLATE
) && m_targets
.getUnitTarget())
2387 // for caster applied auras only
2388 Unit::AuraList
const &mPeriodic
= m_targets
.getUnitTarget()->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
2389 for(Unit::AuraList::const_iterator i
= mPeriodic
.begin(); i
!= mPeriodic
.end(); ++i
)
2391 if( (*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& ((*i
)->GetSpellProto()->SpellFamilyFlags
& 4) &&
2392 (*i
)->GetCasterGUID()==m_caster
->GetGUID() )
2394 m_targets
.getUnitTarget()->RemoveAura((*i
)->GetId(), (*i
)->GetEffIndex());
2400 // traded items have trade slot instead of guid in m_itemTargetGUID
2401 // set to real guid to be sent later to the client
2402 m_targets
.updateTradeSlotItem();
2404 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2406 if (!m_IsTriggeredSpell
&& m_CastItem
)
2407 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM
, m_CastItem
->GetEntry());
2409 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL
, m_spellInfo
->Id
);
2413 SendSpellCooldown();
2416 TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
2419 if(m_spellState
== SPELL_STATE_FINISHED
) // stop cast if spell marked as finish somewhere in Take*/FillTargetMap
2421 SetExecutedCurrently(false);
2425 SendCastResult(castResult
);
2426 SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2428 // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2429 if (m_spellInfo
->speed
> 0.0f
)
2432 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2433 // in case delayed spell remove item at cast delay start
2436 // Okay, maps created, now prepare flags
2437 m_immediateHandled
= false;
2438 m_spellState
= SPELL_STATE_DELAYED
;
2443 // Immediate spell, no big deal
2447 SetExecutedCurrently(false);
2450 void Spell::handle_immediate()
2452 // start channeling if applicable
2453 if(IsChanneledSpell(m_spellInfo
))
2455 int32 duration
= GetSpellDuration(m_spellInfo
);
2458 // Apply duration mod
2459 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
2460 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_DURATION
, duration
);
2461 m_spellState
= SPELL_STATE_CASTING
;
2462 SendChannelStart(duration
);
2466 // process immediate effects (items, ground, etc.) also initialize some variables
2467 _handle_immediate_phase();
2469 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2470 DoAllEffectOnTarget(&(*ihit
));
2472 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2473 DoAllEffectOnTarget(&(*ihit
));
2475 // spell is finished, perform some last features of the spell here
2476 _handle_finish_phase();
2478 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2481 if(m_spellState
!= SPELL_STATE_CASTING
)
2482 finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell)
2485 uint64
Spell::handle_delayed(uint64 t_offset
)
2487 uint64 next_time
= 0;
2489 if (!m_immediateHandled
)
2491 _handle_immediate_phase();
2492 m_immediateHandled
= true;
2495 // 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)
2496 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2498 if (ihit
->processed
== false)
2500 if ( ihit
->timeDelay
<= t_offset
)
2501 DoAllEffectOnTarget(&(*ihit
));
2502 else if( next_time
== 0 || ihit
->timeDelay
< next_time
)
2503 next_time
= ihit
->timeDelay
;
2507 // now recheck gameobject targeting correctness
2508 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
2510 if (ighit
->processed
== false)
2512 if ( ighit
->timeDelay
<= t_offset
)
2513 DoAllEffectOnTarget(&(*ighit
));
2514 else if( next_time
== 0 || ighit
->timeDelay
< next_time
)
2515 next_time
= ighit
->timeDelay
;
2518 // All targets passed - need finish phase
2521 // spell is finished, perform some last features of the spell here
2522 _handle_finish_phase();
2524 finish(true); // successfully finish spell cast
2526 // return zero, spell is finished now
2531 // spell is unfinished, return next execution time
2536 void Spell::_handle_immediate_phase()
2538 // handle some immediate features of the spell here
2539 HandleThreatSpells(m_spellInfo
->Id
);
2541 m_needSpellLog
= IsNeedSendToClient();
2542 for(uint32 j
= 0;j
<3;j
++)
2544 if(m_spellInfo
->Effect
[j
]==0)
2547 // apply Send Event effect to ground in case empty target lists
2548 if( m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
&& !HaveTargetsForEffect(j
) )
2550 HandleEffects(NULL
,NULL
,NULL
, j
);
2554 // Don't do spell log, if is school damage spell
2555 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
|| m_spellInfo
->Effect
[j
] == 0)
2556 m_needSpellLog
= false;
2558 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[j
];
2559 if(m_originalCaster
)
2560 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
2561 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
2563 // initialize multipliers
2564 m_damageMultipliers
[j
] = 1.0f
;
2565 if( (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_HEAL
) &&
2566 (EffectChainTarget
> 1) )
2567 m_applyMultiplierMask
|= 1 << j
;
2570 // initialize Diminishing Returns Data
2571 m_diminishLevel
= DIMINISHING_LEVEL_1
;
2572 m_diminishGroup
= DIMINISHING_NONE
;
2575 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
2576 DoAllEffectOnTarget(&(*ihit
));
2579 for(uint32 j
= 0;j
<3;j
++)
2581 // persistent area auras target only the ground
2582 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2583 HandleEffects(NULL
,NULL
,NULL
, j
);
2587 void Spell::_handle_finish_phase()
2594 void Spell::SendSpellCooldown()
2596 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
2599 Player
* _player
= (Player
*)m_caster
;
2601 // mana/health/etc potions, disabled by client (until combat out as declarate)
2602 if (m_CastItem
&& m_CastItem
->IsPotion())
2604 // need in some way provided data for Spell::finish SendCooldownEvent
2605 _player
->SetLastPotionId(m_CastItem
->GetEntry());
2609 // have infinity cooldown but set at aura apply
2610 if(m_spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
2613 _player
->AddSpellAndCategoryCooldowns(m_spellInfo
,m_CastItem
? m_CastItem
->GetEntry() : 0, this);
2616 void Spell::update(uint32 difftime
)
2618 // update pointers based at it's GUIDs
2621 if(m_targets
.getUnitTargetGUID() && !m_targets
.getUnitTarget())
2627 // check if the player caster has moved before the spell finished
2628 if ((m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_timer
!= 0) &&
2629 (m_castPositionX
!= m_caster
->GetPositionX() || m_castPositionY
!= m_caster
->GetPositionY() || m_castPositionZ
!= m_caster
->GetPositionZ()) &&
2630 (m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
|| !m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_FALLING
)))
2632 // always cancel for channeled spells
2633 if( m_spellState
== SPELL_STATE_CASTING
)
2635 // don't cancel for melee, autorepeat, triggered and instant spells
2636 else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_MOVEMENT
))
2640 switch(m_spellState
)
2642 case SPELL_STATE_PREPARING
:
2646 if(difftime
>= m_timer
)
2649 m_timer
-= difftime
;
2652 if(m_timer
== 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat())
2655 case SPELL_STATE_CASTING
:
2659 if( m_caster
->GetTypeId() == TYPEID_PLAYER
)
2661 // check if player has jumped before the channeling finished
2662 if(m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_JUMPING
))
2665 // check for incapacitating player states
2666 if( m_caster
->hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_CONFUSED
))
2669 // check if player has turned if flag is set
2670 if( m_spellInfo
->ChannelInterruptFlags
& CHANNEL_FLAG_TURNING
&& m_castOrientation
!= m_caster
->GetOrientation() )
2674 // check if there are alive targets left
2675 if (!IsAliveUnitPresentInTargetList())
2677 SendChannelUpdate(0);
2681 if(difftime
>= m_timer
)
2684 m_timer
-= difftime
;
2689 SendChannelUpdate(0);
2691 // channeled spell processed independently for quest targeting
2692 // cast at creature (or GO) quest objectives update at successful cast channel finished
2693 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
2694 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsAutoRepeat() && !IsNextMeleeSwingSpell() )
2696 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2698 TargetInfo
* target
= &*ihit
;
2699 if(!IS_CREATURE_GUID(target
->targetGUID
))
2702 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
2706 ((Player
*)m_caster
)->CastedCreatureOrGO(unit
->GetEntry(),unit
->GetGUID(),m_spellInfo
->Id
);
2709 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2711 GOTargetInfo
* target
= &*ihit
;
2713 GameObject
* go
= ObjectAccessor::GetGameObject(*m_caster
, target
->targetGUID
);
2717 ((Player
*)m_caster
)->CastedCreatureOrGO(go
->GetEntry(),go
->GetGUID(),m_spellInfo
->Id
);
2730 void Spell::finish(bool ok
)
2735 if(m_spellState
== SPELL_STATE_FINISHED
)
2738 m_spellState
= SPELL_STATE_FINISHED
;
2740 // other code related only to successfully finished spells
2745 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2746 ((Player
*)m_caster
)->RemoveSpellMods(this);
2748 // handle SPELL_AURA_ADD_TARGET_TRIGGER auras
2749 Unit::AuraList
const& targetTriggers
= m_caster
->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER
);
2750 for(Unit::AuraList::const_iterator i
= targetTriggers
.begin(); i
!= targetTriggers
.end(); ++i
)
2752 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
2754 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2755 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2757 // check m_caster->GetGUID() let load auras at login and speedup most often case
2758 Unit
*unit
= m_caster
->GetGUID()== ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2759 if (unit
&& unit
->isAlive())
2761 SpellEntry
const *auraSpellInfo
= (*i
)->GetSpellProto();
2762 uint32 auraSpellIdx
= (*i
)->GetEffIndex();
2763 // Calculate chance at that moment (can be depend for example from combo points)
2764 int32 chance
= m_caster
->CalculateSpellDamage(auraSpellInfo
, auraSpellIdx
, (*i
)->GetBasePoints(),unit
);
2765 if(roll_chance_i(chance
))
2766 m_caster
->CastSpell(unit
, auraSpellInfo
->EffectTriggerSpell
[auraSpellIdx
], true, NULL
, (*i
));
2771 // Heal caster for all health leech from all targets
2774 m_caster
->ModifyHealth(m_healthLeech
);
2775 m_caster
->SendHealSpellLog(m_caster
, m_spellInfo
->Id
, uint32(m_healthLeech
));
2778 if (IsMeleeAttackResetSpell())
2780 m_caster
->resetAttackTimer(BASE_ATTACK
);
2781 if(m_caster
->haveOffhandWeapon())
2782 m_caster
->resetAttackTimer(OFF_ATTACK
);
2785 /*if (IsRangedAttackResetSpell())
2786 m_caster->resetAttackTimer(RANGED_ATTACK);*/
2788 // Clear combo at finish state
2789 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& NeedsComboPoints(m_spellInfo
))
2791 // Not drop combopoints if negative spell and if any miss on enemy exist
2792 bool needDrop
= true;
2793 if (!IsPositiveSpell(m_spellInfo
->Id
))
2794 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2795 if (ihit
->missCondition
!= SPELL_MISS_NONE
&& ihit
->targetGUID
!=m_caster
->GetGUID())
2801 ((Player
*)m_caster
)->ClearComboPoints();
2804 // potions disabled by client, send event "not in combat" if need
2805 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2806 ((Player
*)m_caster
)->UpdatePotionCooldown(this);
2808 // call triggered spell only at successful cast (after clear combo points -> for add some if need)
2809 if(!m_TriggerSpells
.empty())
2812 // Stop Attack for some spells
2813 if( m_spellInfo
->Attributes
& SPELL_ATTR_STOP_ATTACK_TARGET
)
2814 m_caster
->AttackStop();
2817 void Spell::SendCastResult(SpellCastResult result
)
2819 if(result
== SPELL_CAST_OK
)
2822 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
2825 if(((Player
*)m_caster
)->GetSession()->PlayerLoading()) // don't send cast results at loading time
2828 WorldPacket
data(SMSG_CAST_FAILED
, (4+1+1));
2829 data
<< uint8(m_cast_count
); // single cast or multi 2.3 (0/1)
2830 data
<< uint32(m_spellInfo
->Id
);
2831 data
<< uint8(result
); // problem
2834 case SPELL_FAILED_REQUIRES_SPELL_FOCUS
:
2835 data
<< uint32(m_spellInfo
->RequiresSpellFocus
);
2837 case SPELL_FAILED_REQUIRES_AREA
:
2838 // hardcode areas limitation case
2839 switch(m_spellInfo
->Id
)
2841 case 41617: // Cenarion Mana Salve
2842 case 41619: // Cenarion Healing Salve
2843 data
<< uint32(3905);
2845 case 41618: // Bottled Nethergon Energy
2846 case 41620: // Bottled Nethergon Vapor
2847 data
<< uint32(3842);
2849 case 45373: // Bloodberry Elixir
2850 data
<< uint32(4075);
2852 default: // default case (don't must be)
2857 case SPELL_FAILED_TOTEMS
:
2858 if(m_spellInfo
->Totem
[0])
2859 data
<< uint32(m_spellInfo
->Totem
[0]);
2860 if(m_spellInfo
->Totem
[1])
2861 data
<< uint32(m_spellInfo
->Totem
[1]);
2863 case SPELL_FAILED_TOTEM_CATEGORY
:
2864 if(m_spellInfo
->TotemCategory
[0])
2865 data
<< uint32(m_spellInfo
->TotemCategory
[0]);
2866 if(m_spellInfo
->TotemCategory
[1])
2867 data
<< uint32(m_spellInfo
->TotemCategory
[1]);
2869 case SPELL_FAILED_EQUIPPED_ITEM_CLASS
:
2870 data
<< uint32(m_spellInfo
->EquippedItemClass
);
2871 data
<< uint32(m_spellInfo
->EquippedItemSubClassMask
);
2872 //data << uint32(m_spellInfo->EquippedItemInventoryTypeMask);
2875 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
2878 void Spell::SendSpellStart()
2880 if(!IsNeedSendToClient())
2883 sLog
.outDebug("Sending SMSG_SPELL_START id=%u", m_spellInfo
->Id
);
2885 uint32 castFlags
= CAST_FLAG_UNKNOWN1
;
2887 castFlags
|= CAST_FLAG_AMMO
;
2889 if(m_spellInfo
->runeCostID
)
2890 castFlags
|= CAST_FLAG_UNKNOWN10
;
2892 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
2894 WorldPacket
data(SMSG_SPELL_START
, (8+8+4+4+2));
2896 data
.append(m_CastItem
->GetPackGUID());
2898 data
.append(m_caster
->GetPackGUID());
2900 data
.append(m_caster
->GetPackGUID());
2901 data
<< uint8(m_cast_count
); // pending spell cast?
2902 data
<< uint32(m_spellInfo
->Id
); // spellId
2903 data
<< uint32(castFlags
); // cast flags
2904 data
<< uint32(m_timer
); // delay?
2906 m_targets
.write(&data
);
2908 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // predicted power?
2911 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
2913 uint8 v1
= 0;//m_runesState;
2914 uint8 v2
= 0;//((Player*)m_caster)->GetRunesState();
2915 data
<< uint8(v1
); // runes state before
2916 data
<< uint8(v2
); // runes state after
2917 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
2920 if(m
& v1
) // usable before...
2921 if(!(m
& v2
)) // ...but on cooldown now...
2922 data
<< uint8(0); // some unknown byte (time?)
2926 if ( castFlags
& CAST_FLAG_AMMO
)
2927 WriteAmmoToPacket(&data
);
2929 m_caster
->SendMessageToSet(&data
, true);
2932 void Spell::SendSpellGo()
2934 // not send invisible spell casting
2935 if(!IsNeedSendToClient())
2938 sLog
.outDebug("Sending SMSG_SPELL_GO id=%u", m_spellInfo
->Id
);
2940 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
2942 uint32 castFlags
= CAST_FLAG_UNKNOWN3
;
2944 castFlags
|= CAST_FLAG_AMMO
; // arrows/bullets visual
2946 if((m_caster
->GetTypeId() == TYPEID_PLAYER
) && (m_caster
->getClass() == CLASS_DEATH_KNIGHT
) && m_spellInfo
->runeCostID
)
2948 castFlags
|= CAST_FLAG_UNKNOWN10
; // same as in SMSG_SPELL_START
2949 castFlags
|= CAST_FLAG_UNKNOWN6
; // makes cooldowns visible
2950 castFlags
|= CAST_FLAG_UNKNOWN7
; // rune cooldowns list
2953 WorldPacket
data(SMSG_SPELL_GO
, 50); // guess size
2956 data
.append(m_CastItem
->GetPackGUID());
2958 data
.append(m_caster
->GetPackGUID());
2960 data
.append(m_caster
->GetPackGUID());
2961 data
<< uint8(m_cast_count
); // pending spell cast?
2962 data
<< uint32(m_spellInfo
->Id
); // spellId
2963 data
<< uint32(castFlags
); // cast flags
2964 data
<< uint32(getMSTime()); // timestamp
2966 WriteSpellGoTargets(&data
);
2968 m_targets
.write(&data
);
2970 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // unknown wotlk, predicted power?
2973 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
2975 uint8 v1
= m_runesState
;
2976 uint8 v2
= ((Player
*)m_caster
)->GetRunesState();
2977 data
<< uint8(v1
); // runes state before
2978 data
<< uint8(v2
); // runes state after
2979 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
2982 if(m
& v1
) // usable before...
2983 if(!(m
& v2
)) // ...but on cooldown now...
2984 data
<< uint8(0); // some unknown byte (time?)
2988 if ( castFlags
& CAST_FLAG_UNKNOWN4
) // unknown wotlk
2994 if ( castFlags
& CAST_FLAG_AMMO
)
2995 WriteAmmoToPacket(&data
);
2997 if ( castFlags
& CAST_FLAG_UNKNOWN5
) // unknown wotlk
3003 if ( m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
3008 m_caster
->SendMessageToSet(&data
, true);
3011 void Spell::WriteAmmoToPacket( WorldPacket
* data
)
3013 uint32 ammoInventoryType
= 0;
3014 uint32 ammoDisplayID
= 0;
3016 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3018 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack( RANGED_ATTACK
);
3021 ammoInventoryType
= pItem
->GetProto()->InventoryType
;
3022 if( ammoInventoryType
== INVTYPE_THROWN
)
3023 ammoDisplayID
= pItem
->GetProto()->DisplayInfoID
;
3026 uint32 ammoID
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
3029 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( ammoID
);
3032 ammoDisplayID
= pProto
->DisplayInfoID
;
3033 ammoInventoryType
= pProto
->InventoryType
;
3036 else if(m_caster
->GetDummyAura(46699)) // Requires No Ammo
3038 ammoDisplayID
= 5996; // normal arrow
3039 ammoInventoryType
= INVTYPE_AMMO
;
3044 // TODO: implement selection ammo data based at ranged weapon stored in equipmodel/equipinfo/equipslot fields
3046 *data
<< uint32(ammoDisplayID
);
3047 *data
<< uint32(ammoInventoryType
);
3050 void Spell::WriteSpellGoTargets( WorldPacket
* data
)
3052 // This function also fill data for channeled spells:
3053 // m_needAliveTargetMask req for stop channelig if one target die
3054 uint32 hit
= m_UniqueGOTargetInfo
.size(); // Always hits on GO
3056 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3058 if ((*ihit
).effectMask
== 0) // No effect apply - all immuned add state
3060 // possibly SPELL_MISS_IMMUNE2 for this??
3061 ihit
->missCondition
= SPELL_MISS_IMMUNE2
;
3064 else if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
3070 *data
<< (uint8
)hit
;
3071 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3072 if ((*ihit
).missCondition
== SPELL_MISS_NONE
) // Add only hits
3074 *data
<< uint64(ihit
->targetGUID
);
3075 m_needAliveTargetMask
|=ihit
->effectMask
;
3078 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin();ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
3079 *data
<< uint64(ighit
->targetGUID
); // Always hits
3081 *data
<< (uint8
)miss
;
3082 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3084 if( ihit
->missCondition
!= SPELL_MISS_NONE
) // Add only miss
3086 *data
<< uint64(ihit
->targetGUID
);
3087 *data
<< uint8(ihit
->missCondition
);
3088 if( ihit
->missCondition
== SPELL_MISS_REFLECT
)
3089 *data
<< uint8(ihit
->reflectResult
);
3092 // Reset m_needAliveTargetMask for non channeled spell
3093 if(!IsChanneledSpell(m_spellInfo
))
3094 m_needAliveTargetMask
= 0;
3097 void Spell::SendLogExecute()
3099 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
3101 WorldPacket
data(SMSG_SPELLLOGEXECUTE
, (8+4+4+4+4+8));
3103 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
3104 data
.append(m_caster
->GetPackGUID());
3106 data
.append(target
->GetPackGUID());
3108 data
<< uint32(m_spellInfo
->Id
);
3110 data
<< uint32(count1
); // count1 (effect count?)
3111 for(uint32 i
= 0; i
< count1
; ++i
)
3113 data
<< uint32(m_spellInfo
->Effect
[0]); // spell effect
3115 data
<< uint32(count2
); // count2 (target count?)
3116 for(uint32 j
= 0; j
< count2
; ++j
)
3118 switch(m_spellInfo
->Effect
[0])
3120 case SPELL_EFFECT_POWER_DRAIN
:
3121 if(Unit
*unit
= m_targets
.getUnitTarget())
3122 data
.append(unit
->GetPackGUID());
3129 case SPELL_EFFECT_ADD_EXTRA_ATTACKS
:
3130 if(Unit
*unit
= m_targets
.getUnitTarget())
3131 data
.append(unit
->GetPackGUID());
3134 data
<< uint32(0); // count?
3136 case SPELL_EFFECT_INTERRUPT_CAST
:
3137 if(Unit
*unit
= m_targets
.getUnitTarget())
3138 data
.append(unit
->GetPackGUID());
3141 data
<< uint32(0); // spellid
3143 case SPELL_EFFECT_DURABILITY_DAMAGE
:
3144 if(Unit
*unit
= m_targets
.getUnitTarget())
3145 data
.append(unit
->GetPackGUID());
3151 case SPELL_EFFECT_OPEN_LOCK
:
3152 case SPELL_EFFECT_OPEN_LOCK_ITEM
:
3153 if(Item
*item
= m_targets
.getItemTarget())
3154 data
.append(item
->GetPackGUID());
3158 case SPELL_EFFECT_CREATE_ITEM
:
3159 case SPELL_EFFECT_CREATE_ITEM_2
:
3160 data
<< uint32(m_spellInfo
->EffectItemType
[0]);
3162 case SPELL_EFFECT_SUMMON
:
3163 case SPELL_EFFECT_TRANS_DOOR
:
3164 case SPELL_EFFECT_SUMMON_PET
:
3165 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
3166 case SPELL_EFFECT_CREATE_HOUSE
:
3167 case SPELL_EFFECT_DUEL
:
3168 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1
:
3169 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2
:
3170 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3
:
3171 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4
:
3172 if(Unit
*unit
= m_targets
.getUnitTarget())
3173 data
.append(unit
->GetPackGUID());
3174 else if(m_targets
.getItemTargetGUID())
3175 data
.appendPackGUID(m_targets
.getItemTargetGUID());
3176 else if(GameObject
*go
= m_targets
.getGOTarget())
3177 data
.append(go
->GetPackGUID());
3179 data
<< uint8(0); // guid
3181 case SPELL_EFFECT_FEED_PET
:
3182 data
<< uint32(m_targets
.getItemTargetEntry());
3184 case SPELL_EFFECT_DISMISS_PET
:
3185 if(Unit
*unit
= m_targets
.getUnitTarget())
3186 data
.append(unit
->GetPackGUID());
3190 case SPELL_EFFECT_RESURRECT
:
3191 case SPELL_EFFECT_RESURRECT_NEW
:
3192 if(Unit
*unit
= m_targets
.getUnitTarget())
3193 data
.append(unit
->GetPackGUID());
3203 m_caster
->SendMessageToSet(&data
, true);
3206 void Spell::SendInterrupted(uint8 result
)
3208 WorldPacket
data(SMSG_SPELL_FAILURE
, (8+4+1));
3209 data
.append(m_caster
->GetPackGUID());
3210 data
<< uint8(m_cast_count
);
3211 data
<< uint32(m_spellInfo
->Id
);
3212 data
<< uint8(result
);
3213 m_caster
->SendMessageToSet(&data
, true);
3215 data
.Initialize(SMSG_SPELL_FAILED_OTHER
, (8+4));
3216 data
.append(m_caster
->GetPackGUID());
3217 data
<< uint8(m_cast_count
);
3218 data
<< uint32(m_spellInfo
->Id
);
3219 data
<< uint8(result
);
3220 m_caster
->SendMessageToSet(&data
, true);
3223 void Spell::SendChannelUpdate(uint32 time
)
3227 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
,0);
3228 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
,0);
3231 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3234 WorldPacket
data( MSG_CHANNEL_UPDATE
, 8+4 );
3235 data
.append(m_caster
->GetPackGUID());
3236 data
<< uint32(time
);
3238 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3241 void Spell::SendChannelStart(uint32 duration
)
3243 WorldObject
* target
= NULL
;
3245 // select first not resisted target from target list for _0_ effect
3246 if(!m_UniqueTargetInfo
.empty())
3248 for(std::list
<TargetInfo
>::iterator itr
= m_UniqueTargetInfo
.begin();itr
!= m_UniqueTargetInfo
.end();++itr
)
3250 if( (itr
->effectMask
& (1<<0)) && itr
->reflectResult
==SPELL_MISS_NONE
&& itr
->targetGUID
!= m_caster
->GetGUID())
3252 target
= ObjectAccessor::GetUnit(*m_caster
, itr
->targetGUID
);
3257 else if(!m_UniqueGOTargetInfo
.empty())
3259 for(std::list
<GOTargetInfo
>::iterator itr
= m_UniqueGOTargetInfo
.begin();itr
!= m_UniqueGOTargetInfo
.end();++itr
)
3261 if(itr
->effectMask
& (1<<0) )
3263 target
= ObjectAccessor::GetGameObject(*m_caster
, itr
->targetGUID
);
3269 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3271 WorldPacket
data( MSG_CHANNEL_START
, (8+4+4) );
3272 data
.append(m_caster
->GetPackGUID());
3273 data
<< uint32(m_spellInfo
->Id
);
3274 data
<< uint32(duration
);
3276 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3281 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, target
->GetGUID());
3282 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, m_spellInfo
->Id
);
3285 void Spell::SendResurrectRequest(Player
* target
)
3287 // Both players and NPCs can resurrect using spells - have a look at creature 28487 for example
3288 // However, the packet structure differs slightly
3290 const char* sentName
= m_caster
->GetTypeId()==TYPEID_PLAYER
?"":m_caster
->GetNameForLocaleIdx(target
->GetSession()->GetSessionDbLocaleIndex());
3292 WorldPacket
data(SMSG_RESURRECT_REQUEST
, (8+4+strlen(sentName
)+1+1+1));
3293 data
<< uint64(m_caster
->GetGUID());
3294 data
<< uint32(strlen(sentName
)+1);
3299 data
<< uint8(m_caster
->GetTypeId()==TYPEID_PLAYER
?0:1);
3300 target
->GetSession()->SendPacket(&data
);
3303 void Spell::SendPlaySpellVisual(uint32 SpellID
)
3305 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3308 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 12);
3309 data
<< uint64(m_caster
->GetGUID());
3310 data
<< uint32(SpellID
); // spell visual id?
3311 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
3314 void Spell::TakeCastItem()
3316 if(!m_CastItem
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
3319 // not remove cast item at triggered spell (equipping, weapon damage, etc)
3320 if(m_IsTriggeredSpell
)
3323 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3327 // This code is to avoid a crash
3328 // I'm not sure, if this is really an error, but I guess every item needs a prototype
3329 sLog
.outError("Cast item has no item prototype highId=%d, lowId=%d",m_CastItem
->GetGUIDHigh(), m_CastItem
->GetGUIDLow());
3333 bool expendable
= false;
3334 bool withoutCharges
= false;
3336 for (int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
3338 if (proto
->Spells
[i
].SpellId
)
3340 // item has limited charges
3341 if (proto
->Spells
[i
].SpellCharges
)
3343 if (proto
->Spells
[i
].SpellCharges
< 0)
3346 int32 charges
= m_CastItem
->GetSpellCharges(i
);
3348 // item has charges left
3351 (charges
> 0) ? --charges
: ++charges
; // abs(charges) less at 1 after use
3352 if (proto
->Stackable
== 1)
3353 m_CastItem
->SetSpellCharges(i
, charges
);
3354 m_CastItem
->SetState(ITEM_CHANGED
, (Player
*)m_caster
);
3358 withoutCharges
= (charges
== 0);
3363 if (expendable
&& withoutCharges
)
3366 ((Player
*)m_caster
)->DestroyItemCount(m_CastItem
, count
, true);
3368 // prevent crash at access to deleted m_targets.getItemTarget
3369 if(m_CastItem
==m_targets
.getItemTarget())
3370 m_targets
.setItemTarget(NULL
);
3376 void Spell::TakePower()
3378 if(m_CastItem
|| m_triggeredByAuraSpell
)
3381 // health as power used
3382 if(m_spellInfo
->powerType
== POWER_HEALTH
)
3384 m_caster
->ModifyHealth( -(int32
)m_powerCost
);
3388 if(m_spellInfo
->powerType
>= MAX_POWERS
)
3390 sLog
.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo
->powerType
);
3394 Powers powerType
= Powers(m_spellInfo
->powerType
);
3396 if(powerType
== POWER_RUNE
)
3402 m_caster
->ModifyPower(powerType
, -(int32
)m_powerCost
);
3404 // Set the five second timer
3405 if (powerType
== POWER_MANA
&& m_powerCost
> 0)
3406 m_caster
->SetLastManaUse(getMSTime());
3409 SpellCastResult
Spell::CheckRuneCost(uint32 runeCostID
)
3411 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3412 return SPELL_CAST_OK
;
3414 Player
*plr
= (Player
*)m_caster
;
3416 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3417 return SPELL_CAST_OK
;
3419 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(runeCostID
);
3422 return SPELL_CAST_OK
;
3424 if(src
->NoRuneCost())
3425 return SPELL_CAST_OK
;
3427 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3429 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3430 runeCost
[i
] = src
->RuneCost
[i
];
3432 runeCost
[RUNE_DEATH
] = MAX_RUNES
; // calculated later
3434 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3436 uint8 rune
= plr
->GetCurrentRune(i
);
3437 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3441 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3443 runeCost
[RUNE_DEATH
] += runeCost
[i
];
3445 if(runeCost
[RUNE_DEATH
] > MAX_RUNES
)
3446 return SPELL_FAILED_NO_POWER
; // not sure if result code is correct
3448 return SPELL_CAST_OK
;
3451 void Spell::TakeRunePower()
3453 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3456 Player
*plr
= (Player
*)m_caster
;
3458 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3461 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(m_spellInfo
->runeCostID
);
3463 if(!src
|| (src
->NoRuneCost() && src
->NoRunicPowerGain()))
3466 m_runesState
= plr
->GetRunesState(); // store previous state
3468 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3470 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3472 runeCost
[i
] = src
->RuneCost
[i
];
3475 runeCost
[RUNE_DEATH
] = 0; // calculated later
3477 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3479 uint8 rune
= plr
->GetCurrentRune(i
);
3480 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3482 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3487 runeCost
[RUNE_DEATH
] = runeCost
[RUNE_BLOOD
] + runeCost
[RUNE_UNHOLY
] + runeCost
[RUNE_FROST
];
3489 if(runeCost
[RUNE_DEATH
] > 0)
3491 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3493 uint8 rune
= plr
->GetCurrentRune(i
);
3494 if((plr
->GetRuneCooldown(i
) == 0) && (rune
== RUNE_DEATH
))
3496 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3498 plr
->ConvertRune(i
, plr
->GetBaseRune(i
));
3499 if(runeCost
[RUNE_DEATH
] == 0)
3505 // you can gain some runic power when use runes
3506 float rp
= src
->runePowerGain
;;
3507 rp
*= sWorld
.getRate(RATE_POWER_RUNICPOWER_INCOME
);
3508 plr
->ModifyPower(POWER_RUNIC_POWER
, (int32
)rp
);
3511 void Spell::TakeReagents()
3513 if(m_IsTriggeredSpell
) // reagents used in triggered spell removed by original spell or don't must be removed.
3516 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3519 Player
* p_caster
= (Player
*)m_caster
;
3520 if (p_caster
->CanNoReagentCast(m_spellInfo
))
3523 for(uint32 x
=0;x
<8;x
++)
3525 if(m_spellInfo
->Reagent
[x
] <= 0)
3528 uint32 itemid
= m_spellInfo
->Reagent
[x
];
3529 uint32 itemcount
= m_spellInfo
->ReagentCount
[x
];
3531 // if CastItem is also spell reagent
3534 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3535 if( proto
&& proto
->ItemId
== itemid
)
3537 for(int s
=0;s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
3539 // CastItem will be used up and does not count as reagent
3540 int32 charges
= m_CastItem
->GetSpellCharges(s
);
3541 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
3552 // if getItemTarget is also spell reagent
3553 if (m_targets
.getItemTargetEntry()==itemid
)
3554 m_targets
.setItemTarget(NULL
);
3556 p_caster
->DestroyItemCount(itemid
, itemcount
, true);
3560 void Spell::HandleThreatSpells(uint32 spellId
)
3562 if(!m_targets
.getUnitTarget() || !spellId
)
3565 if(!m_targets
.getUnitTarget()->CanHaveThreatList())
3568 SpellThreatEntry
const *threatSpell
= sSpellThreatStore
.LookupEntry
<SpellThreatEntry
>(spellId
);
3572 m_targets
.getUnitTarget()->AddThreat(m_caster
, float(threatSpell
->threat
));
3574 DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId
, spellmgr
.GetSpellRank(spellId
), threatSpell
->threat
);
3577 void Spell::HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,uint32 i
, float DamageMultiplier
)
3579 unitTarget
= pUnitTarget
;
3580 itemTarget
= pItemTarget
;
3581 gameObjTarget
= pGOTarget
;
3583 uint8 eff
= m_spellInfo
->Effect
[i
];
3585 damage
= int32(CalculateDamage((uint8
)i
,unitTarget
)*DamageMultiplier
);
3587 sLog
.outDebug( "Spell: Effect : %u", eff
);
3589 if(eff
<TOTAL_SPELL_EFFECTS
)
3591 //sLog.outDebug( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff);
3592 (*this.*SpellEffects
[eff
])(i
);
3597 sLog.outDebug( "WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff);
3599 EffectEnchantItemTmp(i);
3602 sLog.outError("SPELL: unknown effect %u spell id %u",
3603 eff, m_spellInfo->Id);
3609 void Spell::TriggerSpell()
3611 for(TriggerSpells::iterator si
=m_TriggerSpells
.begin(); si
!=m_TriggerSpells
.end(); ++si
)
3613 Spell
* spell
= new Spell(m_caster
, (*si
), true, m_originalCasterGUID
, m_selfContainer
);
3614 spell
->prepare(&m_targets
); // use original spell original targets
3618 SpellCastResult
Spell::CheckCast(bool strict
)
3620 // check cooldowns to prevent cheating
3621 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
3623 if(m_triggeredByAuraSpell
)
3624 return SPELL_FAILED_DONT_REPORT
;
3626 return SPELL_FAILED_NOT_READY
;
3629 // only allow triggered spells if at an ended battleground
3630 if( !m_IsTriggeredSpell
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
3631 if(BattleGround
* bg
= ((Player
*)m_caster
)->GetBattleGround())
3632 if(bg
->GetStatus() == STATUS_WAIT_LEAVE
)
3633 return SPELL_FAILED_DONT_REPORT
;
3635 // only check at first call, Stealth auras are already removed at second call
3636 // for now, ignore triggered spells
3637 if( strict
&& !m_IsTriggeredSpell
)
3639 bool checkForm
= true;
3640 // Ignore form req aura
3641 Unit::AuraList
const& ignore
= m_caster
->GetAurasByType(SPELL_AURA_MOD_IGNORE_SHAPESHIFT
);
3642 for(Unit::AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
3644 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
3651 // Cannot be used in this stance/form
3652 SpellCastResult shapeError
= GetErrorAtShapeshiftedCast(m_spellInfo
, m_caster
->m_form
);
3653 if(shapeError
!= SPELL_CAST_OK
)
3656 if ((m_spellInfo
->Attributes
& SPELL_ATTR_ONLY_STEALTHED
) && !(m_caster
->HasStealthAura()))
3657 return SPELL_FAILED_ONLY_STEALTHED
;
3661 // caster state requirements
3662 if(m_spellInfo
->CasterAuraState
&& !m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraState
)))
3663 return SPELL_FAILED_CASTER_AURASTATE
;
3664 if(m_spellInfo
->CasterAuraStateNot
&& m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraStateNot
)))
3665 return SPELL_FAILED_CASTER_AURASTATE
;
3667 // Caster aura req check if need
3668 if(m_spellInfo
->casterAuraSpell
&& !m_caster
->HasAura(m_spellInfo
->casterAuraSpell
))
3669 return SPELL_FAILED_CASTER_AURASTATE
;
3670 if(m_spellInfo
->excludeCasterAuraSpell
&& m_caster
->HasAura(m_spellInfo
->excludeCasterAuraSpell
))
3671 return SPELL_FAILED_CASTER_AURASTATE
;
3673 // cancel autorepeat spells if cast start when moving
3674 // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
3675 if( m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->isMoving() )
3677 // skip stuck spell to allow use it in falling case and apply spell limitations at movement
3678 if( (!m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_FALLING
) || m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
) &&
3679 (IsAutoRepeat() || (m_spellInfo
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_NOT_SEATED
) != 0) )
3680 return SPELL_FAILED_MOVING
;
3683 if(Unit
*target
= m_targets
.getUnitTarget())
3685 // target state requirements (not allowed state), apply to self also
3686 if(m_spellInfo
->TargetAuraStateNot
&& target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraStateNot
)))
3687 return SPELL_FAILED_TARGET_AURASTATE
;
3689 // Target aura req check if need
3690 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
3691 return SPELL_FAILED_CASTER_AURASTATE
;
3692 if(m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
3693 return SPELL_FAILED_CASTER_AURASTATE
;
3695 if(target
!= m_caster
)
3697 // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds
3698 if(m_spellInfo
->TargetAuraState
&& !target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraState
)))
3699 return SPELL_FAILED_TARGET_AURASTATE
;
3701 // Not allow casting on flying player
3702 if (target
->isInFlight())
3703 return SPELL_FAILED_BAD_TARGETS
;
3705 if(!m_IsTriggeredSpell
&& VMAP::VMapFactory::checkSpellForLoS(m_spellInfo
->Id
) && !m_caster
->IsWithinLOSInMap(target
))
3706 return SPELL_FAILED_LINE_OF_SIGHT
;
3708 // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode
3709 // this case can be triggered if rank not found (too low-level target for first rank)
3710 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsPassiveSpell(m_spellInfo
->Id
) && !m_CastItem
)
3711 for(int i
=0;i
<3;i
++)
3712 if(IsPositiveEffect(m_spellInfo
->Id
, i
) && m_spellInfo
->Effect
[i
] == SPELL_EFFECT_APPLY_AURA
)
3713 if(target
->getLevel() + 10 < m_spellInfo
->spellLevel
)
3714 return SPELL_FAILED_LOWLEVEL
;
3716 else if (m_caster
->GetTypeId()==TYPEID_PLAYER
) // Target - is player caster
3718 // Additional check for some spells
3719 // If 0 spell effect empty - client not send target data (need use selection)
3720 // TODO: check it on next client version
3721 if (m_targets
.m_targetMask
== TARGET_FLAG_SELF
&&
3722 m_spellInfo
->EffectImplicitTargetA
[1] == TARGET_CHAIN_DAMAGE
)
3724 if (target
= m_caster
->GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection()))
3725 m_targets
.setUnitTarget(target
);
3727 return SPELL_FAILED_BAD_TARGETS
;
3731 // check pet presents
3732 for(int j
=0;j
<3;j
++)
3734 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_PET
)
3736 target
= m_caster
->GetPet();
3739 if(m_triggeredByAuraSpell
) // not report pet not existence for triggered spells
3740 return SPELL_FAILED_DONT_REPORT
;
3742 return SPELL_FAILED_NO_PET
;
3748 //check creature type
3749 //ignore self casts (including area casts when caster selected as target)
3750 if(target
!= m_caster
)
3752 if(!CheckTargetCreatureType(target
))
3754 if(target
->GetTypeId()==TYPEID_PLAYER
)
3755 return SPELL_FAILED_TARGET_IS_PLAYER
;
3757 return SPELL_FAILED_BAD_TARGETS
;
3761 // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
3762 // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
3763 if(m_caster
!= target
&& m_caster
->GetTypeId()==TYPEID_UNIT
&& m_caster
->GetCharmerOrOwnerGUID())
3765 // check correctness positive/negative cast target (pet cast real check and cheating check)
3766 if(IsPositiveSpell(m_spellInfo
->Id
))
3768 if(m_caster
->IsHostileTo(target
))
3769 return SPELL_FAILED_BAD_TARGETS
;
3773 if(m_caster
->IsFriendlyTo(target
))
3774 return SPELL_FAILED_BAD_TARGETS
;
3778 if(IsPositiveSpell(m_spellInfo
->Id
))
3779 if(target
->IsImmunedToSpell(m_spellInfo
))
3780 return SPELL_FAILED_TARGET_AURASTATE
;
3782 //Must be behind the target.
3783 if( m_spellInfo
->AttributesEx2
== 0x100000 && (m_spellInfo
->AttributesEx
& 0x200) == 0x200 && target
->HasInArc(M_PI
, m_caster
) )
3785 //Exclusion for Pounce: Facing Limitation was removed in 2.0.1, but it still uses the same, old Ex-Flags
3786 if( m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_DRUID
|| m_spellInfo
->SpellFamilyFlags
!= 0x0000000000020000LL
)
3789 return SPELL_FAILED_NOT_BEHIND
;
3793 //Target must be facing you.
3794 if((m_spellInfo
->Attributes
== 0x150010) && !target
->HasInArc(M_PI
, m_caster
) )
3797 return SPELL_FAILED_NOT_INFRONT
;
3800 // check if target is in combat
3801 if (target
!= m_caster
&& (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET
) && target
->isInCombat())
3802 return SPELL_FAILED_TARGET_AFFECTING_COMBAT
;
3805 // Spell casted only on battleground
3806 if((m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_BATTLEGROUND
) && m_caster
->GetTypeId()==TYPEID_PLAYER
)
3807 if(!((Player
*)m_caster
)->InBattleGround())
3808 return SPELL_FAILED_ONLY_BATTLEGROUNDS
;
3810 // do not allow spells to be cast in arenas
3811 // - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag
3812 // - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag
3813 if( (m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA
) ||
3814 GetSpellRecoveryTime(m_spellInfo
) > 15 * MINUTE
* IN_MILISECONDS
&& !(m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_USABLE_IN_ARENA
) )
3815 if(MapEntry
const* mapEntry
= sMapStore
.LookupEntry(m_caster
->GetMapId()))
3816 if(mapEntry
->IsBattleArena())
3817 return SPELL_FAILED_NOT_IN_ARENA
;
3821 m_caster
->GetZoneAndAreaId(zone
,area
);
3823 SpellCastResult locRes
= spellmgr
.GetSpellAllowedInLocationError(m_spellInfo
,m_caster
->GetMapId(),zone
,area
,
3824 m_caster
->GetTypeId()==TYPEID_PLAYER
? ((Player
*)m_caster
) : NULL
);
3825 if(locRes
!= SPELL_CAST_OK
)
3828 // not let players cast spells at mount (and let do it to creatures)
3829 if( m_caster
->IsMounted() && m_caster
->GetTypeId()==TYPEID_PLAYER
&& !m_IsTriggeredSpell
&&
3830 !IsPassiveSpell(m_spellInfo
->Id
) && !(m_spellInfo
->Attributes
& SPELL_ATTR_CASTABLE_WHILE_MOUNTED
) )
3832 if(m_caster
->isInFlight())
3833 return SPELL_FAILED_NOT_FLYING
;
3835 return SPELL_FAILED_NOT_MOUNTED
;
3838 // always (except passive spells) check items (focus object can be required for any type casts)
3839 if(!IsPassiveSpell(m_spellInfo
->Id
))
3841 SpellCastResult castResult
= CheckItems();
3842 if(castResult
!= SPELL_CAST_OK
)
3846 //ImpliciteTargetA-B = 38, If fact there is 0 Spell with ImpliciteTargetB=38
3847 if(m_UniqueTargetInfo
.empty()) // skip second CheckCast apply (for delayed spells for example)
3849 for(uint8 j
= 0; j
< 3; j
++)
3851 if( m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
3852 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_SELF
||
3853 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3854 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3856 SpellScriptTarget::const_iterator lower
= spellmgr
.GetBeginSpellScriptTarget(m_spellInfo
->Id
);
3857 SpellScriptTarget::const_iterator upper
= spellmgr
.GetEndSpellScriptTarget(m_spellInfo
->Id
);
3859 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
);
3861 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
3862 float range
= GetSpellMaxRange(srange
);
3864 Creature
* creatureScriptTarget
= NULL
;
3865 GameObject
* goScriptTarget
= NULL
;
3867 for(SpellScriptTarget::const_iterator i_spellST
= lower
; i_spellST
!= upper
; ++i_spellST
)
3869 switch(i_spellST
->second
.type
)
3871 case SPELL_TARGET_TYPE_GAMEOBJECT
:
3873 GameObject
* p_GameObject
= NULL
;
3875 if(i_spellST
->second
.targetEntry
)
3877 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
3879 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3881 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*m_caster
,i_spellST
->second
.targetEntry
,range
);
3882 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(m_caster
, p_GameObject
,go_check
);
3884 TypeContainerVisitor
<MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
>, GridTypeMapContainer
> object_checker(checker
);
3885 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3886 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
3890 // remember found target and range, next attempt will find more near target with another entry
3891 creatureScriptTarget
= NULL
;
3892 goScriptTarget
= p_GameObject
;
3893 range
= go_check
.GetLastRange();
3896 else if( focusObject
) //Focus Object
3898 float frange
= m_caster
->GetDistance(focusObject
);
3901 creatureScriptTarget
= NULL
;
3902 goScriptTarget
= focusObject
;
3908 case SPELL_TARGET_TYPE_CREATURE
:
3909 case SPELL_TARGET_TYPE_DEAD
:
3912 Creature
*p_Creature
= NULL
;
3914 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
3916 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3917 cell
.SetNoCreate(); // Really don't know what is that???
3919 MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
u_check(*m_caster
,i_spellST
->second
.targetEntry
,i_spellST
->second
.type
!=SPELL_TARGET_TYPE_DEAD
,range
);
3920 MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
> searcher(m_caster
, p_Creature
, u_check
);
3922 TypeContainerVisitor
<MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
>, GridTypeMapContainer
> grid_creature_searcher(searcher
);
3924 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3925 cell_lock
->Visit(cell_lock
, grid_creature_searcher
, *m_caster
->GetMap());
3929 creatureScriptTarget
= p_Creature
;
3930 goScriptTarget
= NULL
;
3931 range
= u_check
.GetLastRange();
3938 if(creatureScriptTarget
)
3940 // store coordinates for TARGET_SCRIPT_COORDINATES
3941 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3942 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3944 m_targets
.setDestination(creatureScriptTarget
->GetPositionX(),creatureScriptTarget
->GetPositionY(),creatureScriptTarget
->GetPositionZ());
3946 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3947 AddUnitTarget(creatureScriptTarget
, j
);
3949 // store explicit target for TARGET_SCRIPT
3951 AddUnitTarget(creatureScriptTarget
, j
);
3953 else if(goScriptTarget
)
3955 // store coordinates for TARGET_SCRIPT_COORDINATES
3956 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3957 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3959 m_targets
.setDestination(goScriptTarget
->GetPositionX(),goScriptTarget
->GetPositionY(),goScriptTarget
->GetPositionZ());
3961 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3962 AddGOTarget(goScriptTarget
, j
);
3964 // store explicit target for TARGET_SCRIPT
3966 AddGOTarget(goScriptTarget
, j
);
3968 //Missing DB Entry or targets for this spellEffect.
3971 // not report target not existence for triggered spells
3972 if(m_triggeredByAuraSpell
|| m_IsTriggeredSpell
)
3973 return SPELL_FAILED_DONT_REPORT
;
3975 return SPELL_FAILED_BAD_TARGETS
;
3981 if(!m_IsTriggeredSpell
)
3983 SpellCastResult castResult
= CheckRange(strict
);
3984 if(castResult
!= SPELL_CAST_OK
)
3989 SpellCastResult castResult
= CheckPower();
3990 if(castResult
!= SPELL_CAST_OK
)
3994 if(!m_IsTriggeredSpell
) // triggered spell not affected by stun/etc
3996 SpellCastResult castResult
= CheckCasterAuras();
3997 if(castResult
!= SPELL_CAST_OK
)
4001 for (int i
= 0; i
< 3; i
++)
4003 // for effects of spells that have only one target
4004 switch(m_spellInfo
->Effect
[i
])
4006 case SPELL_EFFECT_DUMMY
:
4008 if(m_spellInfo
->SpellIconID
== 1648) // Execute
4010 if(!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4011 return SPELL_FAILED_BAD_TARGETS
;
4013 else if (m_spellInfo
->Id
== 51582) // Rocket Boots Engaged
4015 if(m_caster
->IsInWater())
4016 return SPELL_FAILED_ONLY_ABOVEWATER
;
4018 else if(m_spellInfo
->SpellIconID
==156) // Holy Shock
4020 // spell different for friends and enemies
4021 // hart version required facing
4022 if(m_targets
.getUnitTarget() && !m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()) && !m_caster
->HasInArc( M_PI
, m_targets
.getUnitTarget() ))
4023 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4027 case SPELL_EFFECT_SCHOOL_DAMAGE
:
4030 if(m_spellInfo
->SpellVisual
[0] == 7250)
4032 if (!m_targets
.getUnitTarget())
4033 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4035 if(m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4036 return SPELL_FAILED_BAD_TARGETS
;
4040 case SPELL_EFFECT_TAMECREATURE
:
4042 if (!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
)
4043 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4045 if (m_targets
.getUnitTarget()->getLevel() > m_caster
->getLevel())
4046 return SPELL_FAILED_HIGHLEVEL
;
4048 // use SMSG_PET_TAME_FAILURE?
4049 if (!((Creature
*)m_targets
.getUnitTarget())->GetCreatureInfo()->isTameable ())
4050 return SPELL_FAILED_BAD_TARGETS
;
4052 if(m_caster
->GetPetGUID())
4053 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4055 if(m_caster
->GetCharmGUID())
4056 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4060 case SPELL_EFFECT_LEARN_SPELL
:
4062 if(m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_PET
)
4065 Pet
* pet
= m_caster
->GetPet();
4068 return SPELL_FAILED_NO_PET
;
4070 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4072 if(!learn_spellproto
)
4073 return SPELL_FAILED_NOT_KNOWN
;
4075 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4076 return SPELL_FAILED_LOWLEVEL
;
4080 case SPELL_EFFECT_LEARN_PET_SPELL
:
4082 Pet
* pet
= m_caster
->GetPet();
4085 return SPELL_FAILED_NO_PET
;
4087 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4089 if(!learn_spellproto
)
4090 return SPELL_FAILED_NOT_KNOWN
;
4092 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4093 return SPELL_FAILED_LOWLEVEL
;
4097 case SPELL_EFFECT_FEED_PET
:
4099 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4100 return SPELL_FAILED_BAD_TARGETS
;
4102 Item
* foodItem
= m_targets
.getItemTarget();
4104 return SPELL_FAILED_BAD_TARGETS
;
4106 Pet
* pet
= m_caster
->GetPet();
4109 return SPELL_FAILED_NO_PET
;
4111 if(!pet
->HaveInDiet(foodItem
->GetProto()))
4112 return SPELL_FAILED_WRONG_PET_FOOD
;
4114 if(!pet
->GetCurrentFoodBenefitLevel(foodItem
->GetProto()->ItemLevel
))
4115 return SPELL_FAILED_FOOD_LOWLEVEL
;
4117 if(m_caster
->isInCombat() || pet
->isInCombat())
4118 return SPELL_FAILED_AFFECTING_COMBAT
;
4122 case SPELL_EFFECT_POWER_BURN
:
4123 case SPELL_EFFECT_POWER_DRAIN
:
4125 // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
4126 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4127 if(Unit
* target
= m_targets
.getUnitTarget())
4128 if(target
!=m_caster
&& target
->getPowerType()!=m_spellInfo
->EffectMiscValue
[i
])
4129 return SPELL_FAILED_BAD_TARGETS
;
4132 case SPELL_EFFECT_CHARGE
:
4134 if (m_caster
->hasUnitState(UNIT_STAT_ROOT
))
4135 return SPELL_FAILED_ROOTED
;
4139 case SPELL_EFFECT_SKINNING
:
4141 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() != TYPEID_UNIT
)
4142 return SPELL_FAILED_BAD_TARGETS
;
4144 if( !(m_targets
.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS
) & UNIT_FLAG_SKINNABLE
) )
4145 return SPELL_FAILED_TARGET_UNSKINNABLE
;
4147 Creature
* creature
= (Creature
*)m_targets
.getUnitTarget();
4148 if ( creature
->GetCreatureType() != CREATURE_TYPE_CRITTER
&& ( !creature
->lootForBody
|| !creature
->loot
.empty() ) )
4150 return SPELL_FAILED_TARGET_NOT_LOOTED
;
4153 uint32 skill
= creature
->GetCreatureInfo()->GetRequiredLootSkill();
4155 int32 skillValue
= ((Player
*)m_caster
)->GetSkillValue(skill
);
4156 int32 TargetLevel
= m_targets
.getUnitTarget()->getLevel();
4157 int32 ReqValue
= (skillValue
< 100 ? (TargetLevel
-10)*10 : TargetLevel
*5);
4158 if (ReqValue
> skillValue
)
4159 return SPELL_FAILED_LOW_CASTLEVEL
;
4161 // chance for fail at orange skinning attempt
4162 if( (m_selfContainer
&& (*m_selfContainer
) == this) &&
4163 skillValue
< sWorld
.GetConfigMaxSkillValue() &&
4164 (ReqValue
< 0 ? 0 : ReqValue
) > irand(skillValue
-25, skillValue
+37) )
4165 return SPELL_FAILED_TRY_AGAIN
;
4169 case SPELL_EFFECT_OPEN_LOCK_ITEM
:
4170 case SPELL_EFFECT_OPEN_LOCK
:
4172 if( m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT
&&
4173 m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT_ITEM
)
4176 if( m_caster
->GetTypeId() != TYPEID_PLAYER
// only players can open locks, gather etc.
4177 // we need a go target in case of TARGET_GAMEOBJECT
4178 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT
&& !m_targets
.getGOTarget()
4179 // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM
4180 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT_ITEM
&& !m_targets
.getGOTarget() &&
4181 (!m_targets
.getItemTarget() || !m_targets
.getItemTarget()->GetProto()->LockID
|| m_targets
.getItemTarget()->GetOwner() != m_caster
) )
4182 return SPELL_FAILED_BAD_TARGETS
;
4184 // In BattleGround players can use only flags and banners
4185 if( ((Player
*)m_caster
)->InBattleGround() &&
4186 !((Player
*)m_caster
)->CanUseBattleGroundObject() )
4187 return SPELL_FAILED_TRY_AGAIN
;
4189 // get the lock entry
4191 if (GameObject
* go
=m_targets
.getGOTarget())
4192 lockId
= go
->GetLockId();
4193 else if(Item
* itm
=m_targets
.getItemTarget())
4194 lockId
= itm
->GetProto()->LockID
;
4196 SkillType skillId
=SKILL_NONE
;
4197 int32 reqSkillValue
= 0;
4198 int32 skillValue
= 0;
4200 // check lock compatibility
4201 SpellCastResult res
= CanOpenLock(i
,lockId
,skillId
,reqSkillValue
,skillValue
);
4202 if(res
!= SPELL_CAST_OK
)
4205 // chance for fail at orange mining/herb/LockPicking gathering attempt
4206 // second check prevent fail at rechecks
4207 if(skillId
!= SKILL_NONE
&& (!m_selfContainer
|| ((*m_selfContainer
) != this)))
4209 bool canFailAtMax
= skillId
!= SKILL_HERBALISM
&& skillId
!= SKILL_MINING
;
4211 // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill)
4212 if((canFailAtMax
|| skillValue
< sWorld
.GetConfigMaxSkillValue()) && reqSkillValue
> irand(skillValue
-25, skillValue
+37))
4213 return SPELL_FAILED_TRY_AGAIN
;
4217 case SPELL_EFFECT_SUMMON_DEAD_PET
:
4219 Creature
*pet
= m_caster
->GetPet();
4221 return SPELL_FAILED_NO_PET
;
4224 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4228 // This is generic summon effect
4229 case SPELL_EFFECT_SUMMON
:
4231 switch(m_spellInfo
->EffectMiscValueB
[i
])
4233 case SUMMON_TYPE_POSESSED
:
4234 case SUMMON_TYPE_POSESSED2
:
4235 case SUMMON_TYPE_DEMON
:
4236 case SUMMON_TYPE_SUMMON
:
4238 if(m_caster
->GetPetGUID())
4239 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4241 if(m_caster
->GetCharmGUID())
4242 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4248 // Not used for summon?
4249 case SPELL_EFFECT_SUMMON_PHANTASM
:
4251 if(m_caster
->GetPetGUID())
4252 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4254 if(m_caster
->GetCharmGUID())
4255 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4259 case SPELL_EFFECT_SUMMON_PET
:
4261 if(m_caster
->GetPetGUID()) //let warlock do a replacement summon
4264 Pet
* pet
= ((Player
*)m_caster
)->GetPet();
4266 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& m_caster
->getClass()==CLASS_WARLOCK
)
4268 if (strict
) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
4269 pet
->CastSpell(pet
, 32752, true, NULL
, NULL
, pet
->GetGUID());
4272 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4275 if(m_caster
->GetCharmGUID())
4276 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4280 case SPELL_EFFECT_SUMMON_PLAYER
:
4282 if(m_caster
->GetTypeId()!=TYPEID_PLAYER
)
4283 return SPELL_FAILED_BAD_TARGETS
;
4284 if(!((Player
*)m_caster
)->GetSelection())
4285 return SPELL_FAILED_BAD_TARGETS
;
4287 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
4288 if( !target
|| ((Player
*)m_caster
)==target
|| !target
->IsInSameRaidWith((Player
*)m_caster
) )
4289 return SPELL_FAILED_BAD_TARGETS
;
4291 // check if our map is dungeon
4292 if( sMapStore
.LookupEntry(m_caster
->GetMapId())->IsDungeon() )
4294 InstanceTemplate
const* instance
= ObjectMgr::GetInstanceTemplate(m_caster
->GetMapId());
4296 return SPELL_FAILED_TARGET_NOT_IN_INSTANCE
;
4297 if ( instance
->levelMin
> target
->getLevel() )
4298 return SPELL_FAILED_LOWLEVEL
;
4299 if ( instance
->levelMax
&& instance
->levelMax
< target
->getLevel() )
4300 return SPELL_FAILED_HIGHLEVEL
;
4304 case SPELL_EFFECT_LEAP
:
4305 case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
:
4307 float dis
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4308 float fx
= m_caster
->GetPositionX() + dis
* cos(m_caster
->GetOrientation());
4309 float fy
= m_caster
->GetPositionY() + dis
* sin(m_caster
->GetOrientation());
4310 // teleport a bit above terrain level to avoid falling below it
4311 float fz
= MapManager::Instance().GetBaseMap(m_caster
->GetMapId())->GetHeight(fx
,fy
,m_caster
->GetPositionZ(),true);
4312 if(fz
<= INVALID_HEIGHT
) // note: this also will prevent use effect in instances without vmaps height enabled
4313 return SPELL_FAILED_TRY_AGAIN
;
4315 float caster_pos_z
= m_caster
->GetPositionZ();
4316 // Control the caster to not climb or drop when +-fz > 8
4317 if(!(fz
<=caster_pos_z
+8 && fz
>=caster_pos_z
-8))
4318 return SPELL_FAILED_TRY_AGAIN
;
4320 // not allow use this effect at battleground until battleground start
4321 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
4322 if(BattleGround
const *bg
= ((Player
*)m_caster
)->GetBattleGround())
4323 if(bg
->GetStatus() != STATUS_IN_PROGRESS
)
4324 return SPELL_FAILED_TRY_AGAIN
;
4327 case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF
:
4329 if (m_targets
.getUnitTarget()==m_caster
)
4330 return SPELL_FAILED_BAD_TARGETS
;
4337 for (int i
= 0; i
< 3; i
++)
4339 switch(m_spellInfo
->EffectApplyAuraName
[i
])
4341 case SPELL_AURA_DUMMY
:
4344 switch(m_spellInfo
->Id
)
4347 if(m_caster
->GetTypeId()!=TYPEID_PLAYER
|| !((Player
*)m_caster
)->IsInFeralForm())
4348 return SPELL_FAILED_ONLY_SHAPESHIFT
;
4355 case SPELL_AURA_MOD_POSSESS
:
4356 case SPELL_AURA_MOD_CHARM
:
4358 if(m_caster
->GetPetGUID())
4359 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4361 if(m_caster
->GetCharmGUID())
4362 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4364 if(m_caster
->GetCharmerGUID())
4365 return SPELL_FAILED_CHARMED
;
4367 if(!m_targets
.getUnitTarget())
4368 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4370 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4371 return SPELL_FAILED_CHARMED
;
4373 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
4374 return SPELL_FAILED_HIGHLEVEL
;
4378 case SPELL_AURA_MOUNTED
:
4380 if (m_caster
->IsInWater())
4381 return SPELL_FAILED_ONLY_ABOVEWATER
;
4383 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetTransport())
4384 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4386 // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
4387 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& !sMapStore
.LookupEntry(m_caster
->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell
&& !m_spellInfo
->AreaGroupId
)
4388 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4390 ShapeshiftForm form
= m_caster
->m_form
;
4391 if( form
== FORM_CAT
|| form
== FORM_TREE
|| form
== FORM_TRAVEL
||
4392 form
== FORM_AQUA
|| form
== FORM_BEAR
|| form
== FORM_DIREBEAR
||
4393 form
== FORM_CREATUREBEAR
|| form
== FORM_GHOSTWOLF
|| form
== FORM_FLIGHT
||
4394 form
== FORM_FLIGHT_EPIC
|| form
== FORM_MOONKIN
|| form
== FORM_METAMORPHOSIS
)
4395 return SPELL_FAILED_NOT_SHAPESHIFT
;
4399 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
4401 if(!m_targets
.getUnitTarget())
4402 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4404 // can be casted at non-friendly unit or own pet/charm
4405 if(m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()))
4406 return SPELL_FAILED_TARGET_FRIENDLY
;
4410 case SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
:
4411 case SPELL_AURA_FLY
:
4413 // not allow cast fly spells at old maps by players (all spells is self target)
4414 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
4416 if( !((Player
*)m_caster
)->IsAllowUseFlyMountsHere() )
4417 return SPELL_FAILED_NOT_HERE
;
4422 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4424 if (!m_targets
.getUnitTarget())
4425 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4427 if (m_caster
->GetTypeId()!=TYPEID_PLAYER
|| m_CastItem
)
4430 if(m_targets
.getUnitTarget()->getPowerType()!=POWER_MANA
)
4431 return SPELL_FAILED_BAD_TARGETS
;
4441 return SPELL_CAST_OK
;
4444 SpellCastResult
Spell::CheckPetCast(Unit
* target
)
4446 if(!m_caster
->isAlive())
4447 return SPELL_FAILED_CASTER_DEAD
;
4449 if(m_caster
->IsNonMeleeSpellCasted(false)) //prevent spellcast interruption by another spellcast
4450 return SPELL_FAILED_SPELL_IN_PROGRESS
;
4451 if(m_caster
->isInCombat() && IsNonCombatSpell(m_spellInfo
))
4452 return SPELL_FAILED_AFFECTING_COMBAT
;
4454 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)m_caster
)->isPet() || m_caster
->isCharmed()))
4456 //dead owner (pets still alive when owners ressed?)
4457 if(m_caster
->GetCharmerOrOwner() && !m_caster
->GetCharmerOrOwner()->isAlive())
4458 return SPELL_FAILED_CASTER_DEAD
;
4460 if(!target
&& m_targets
.getUnitTarget())
4461 target
= m_targets
.getUnitTarget();
4464 for(uint32 i
= 0;i
<3;i
++)
4466 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
)
4470 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4475 m_targets
.setUnitTarget(target
);
4477 Unit
* _target
= m_targets
.getUnitTarget();
4479 if(_target
) //for target dead/target not valid
4481 if(!_target
->isAlive())
4482 return SPELL_FAILED_BAD_TARGETS
;
4484 if(IsPositiveSpell(m_spellInfo
->Id
))
4486 if(m_caster
->IsHostileTo(_target
))
4487 return SPELL_FAILED_BAD_TARGETS
;
4491 bool duelvsplayertar
= false;
4492 for(int j
=0;j
<3;j
++)
4494 //TARGET_DUELVSPLAYER is positive AND negative
4495 duelvsplayertar
|= (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
);
4497 if(m_caster
->IsFriendlyTo(target
) && !duelvsplayertar
)
4499 return SPELL_FAILED_BAD_TARGETS
;
4504 if(((Creature
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
4505 return SPELL_FAILED_NOT_READY
;
4508 return CheckCast(true);
4511 SpellCastResult
Spell::CheckCasterAuras() const
4513 // Flag drop spells totally immuned to caster auras
4514 // FIXME: find more nice check for all totally immuned spells
4515 // AttributesEx3 & 0x10000000?
4516 if(m_spellInfo
->Id
==23336 || m_spellInfo
->Id
==23334 || m_spellInfo
->Id
==34991)
4517 return SPELL_CAST_OK
;
4519 uint8 school_immune
= 0;
4520 uint32 mechanic_immune
= 0;
4521 uint32 dispel_immune
= 0;
4523 //Check if the spell grants school or mechanic immunity.
4524 //We use bitmasks so the loop is done only once and not on every aura check below.
4525 if ( m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
4527 for(int i
= 0;i
< 3; i
++)
4529 if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_SCHOOL_IMMUNITY
)
4530 school_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
4531 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY
)
4532 mechanic_immune
|= 1 << uint32(m_spellInfo
->EffectMiscValue
[i
]);
4533 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_DISPEL_IMMUNITY
)
4534 dispel_immune
|= GetDispellMask(DispelType(m_spellInfo
->EffectMiscValue
[i
]));
4536 //immune movement impairment and loss of control
4537 if(m_spellInfo
->Id
==(uint32
)42292)
4538 mechanic_immune
= IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK
;
4541 //Check whether the cast should be prevented by any state you might have.
4542 SpellCastResult prevented_reason
= SPELL_CAST_OK
;
4543 // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
4544 uint32 unitflag
= m_caster
->GetUInt32Value(UNIT_FIELD_FLAGS
); // Get unit state
4545 if(unitflag
& UNIT_FLAG_STUNNED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4546 prevented_reason
= SPELL_FAILED_STUNNED
;
4547 else if(unitflag
& UNIT_FLAG_CONFUSED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4548 prevented_reason
= SPELL_FAILED_CONFUSED
;
4549 else if(unitflag
& UNIT_FLAG_FLEEING
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4550 prevented_reason
= SPELL_FAILED_FLEEING
;
4551 else if(unitflag
& UNIT_FLAG_SILENCED
&& m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_SILENCE
)
4552 prevented_reason
= SPELL_FAILED_SILENCED
;
4553 else if(unitflag
& UNIT_FLAG_PACIFIED
&& m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_PACIFY
)
4554 prevented_reason
= SPELL_FAILED_PACIFIED
;
4556 // Attr must make flag drop spell totally immune from all effects
4557 if(prevented_reason
!= SPELL_CAST_OK
)
4559 if(school_immune
|| mechanic_immune
|| dispel_immune
)
4561 //Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
4562 Unit::AuraMap
const& auras
= m_caster
->GetAuras();
4563 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
4567 if( GetSpellMechanicMask(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()) & mechanic_immune
)
4569 if( GetSpellSchoolMask(itr
->second
->GetSpellProto()) & school_immune
)
4571 if( (1<<(itr
->second
->GetSpellProto()->Dispel
)) & dispel_immune
)
4574 //Make a second check for spell failed so the right SPELL_FAILED message is returned.
4575 //That is needed when your casting is prevented by multiple states and you are only immune to some of them.
4576 switch(itr
->second
->GetModifier()->m_auraname
)
4578 case SPELL_AURA_MOD_STUN
:
4579 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4580 return SPELL_FAILED_STUNNED
;
4582 case SPELL_AURA_MOD_CONFUSE
:
4583 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4584 return SPELL_FAILED_CONFUSED
;
4586 case SPELL_AURA_MOD_FEAR
:
4587 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4588 return SPELL_FAILED_FLEEING
;
4590 case SPELL_AURA_MOD_SILENCE
:
4591 case SPELL_AURA_MOD_PACIFY
:
4592 case SPELL_AURA_MOD_PACIFY_SILENCE
:
4593 if( m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_PACIFY
)
4594 return SPELL_FAILED_PACIFIED
;
4595 else if ( m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_SILENCE
)
4596 return SPELL_FAILED_SILENCED
;
4602 //You are prevented from casting and the spell casted does not grant immunity. Return a failed error.
4604 return prevented_reason
;
4606 return SPELL_CAST_OK
;
4609 bool Spell::CanAutoCast(Unit
* target
)
4611 uint64 targetguid
= target
->GetGUID();
4613 for(uint32 j
= 0;j
<3;j
++)
4615 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
)
4617 if( m_spellInfo
->StackAmount
<= 1)
4619 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4624 if( target
->GetAuras().count(Unit::spellEffectPair(m_spellInfo
->Id
, j
)) >= m_spellInfo
->StackAmount
)
4628 else if ( IsAreaAuraEffect( m_spellInfo
->Effect
[j
] ))
4630 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4635 SpellCastResult result
= CheckPetCast(target
);
4637 if(result
== SPELL_CAST_OK
|| result
== SPELL_FAILED_UNIT_NOT_INFRONT
)
4640 //check if among target units, our WANTED target is as well (->only self cast spells return false)
4641 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
4642 if( ihit
->targetGUID
== targetguid
)
4645 return false; //target invalid
4648 SpellCastResult
Spell::CheckRange(bool strict
)
4652 // self cast doesn't need range checking -- also for Starshards fix
4653 if (m_spellInfo
->rangeIndex
== 1)
4654 return SPELL_CAST_OK
;
4656 if (strict
) //add radius of caster
4658 else //add radius of caster and ~5 yds "give"
4661 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4662 float max_range
= GetSpellMaxRange(srange
) + range_mod
;
4663 float min_range
= GetSpellMinRange(srange
);
4665 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4666 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RANGE
, max_range
, this);
4668 Unit
*target
= m_targets
.getUnitTarget();
4670 if(target
&& target
!= m_caster
)
4672 // distance from target in checks
4673 float dist
= m_caster
->GetCombatDistance(target
);
4675 if(dist
> max_range
)
4676 return SPELL_FAILED_OUT_OF_RANGE
; //0x5A;
4677 if(dist
< min_range
)
4678 return SPELL_FAILED_TOO_CLOSE
;
4679 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&&
4680 (m_spellInfo
->FacingCasterFlags
& SPELL_FACING_FLAG_INFRONT
) && !m_caster
->HasInArc( M_PI
, target
) )
4681 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4684 if(m_targets
.m_targetMask
== TARGET_FLAG_DEST_LOCATION
&& m_targets
.m_destX
!= 0 && m_targets
.m_destY
!= 0 && m_targets
.m_destZ
!= 0)
4686 float dist
= m_caster
->GetDistance(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
);
4687 if(dist
> max_range
)
4688 return SPELL_FAILED_OUT_OF_RANGE
;
4689 if(dist
< min_range
)
4690 return SPELL_FAILED_TOO_CLOSE
;
4693 return SPELL_CAST_OK
;
4696 int32
Spell::CalculatePowerCost()
4698 // item cast not used power
4702 // Spell drain all exist power on cast (Only paladin lay of Hands)
4703 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DRAIN_ALL_POWER
)
4705 // If power type - health drain all
4706 if (m_spellInfo
->powerType
== POWER_HEALTH
)
4707 return m_caster
->GetHealth();
4708 // Else drain all power
4709 if (m_spellInfo
->powerType
< MAX_POWERS
)
4710 return m_caster
->GetPower(Powers(m_spellInfo
->powerType
));
4711 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4716 int32 powerCost
= m_spellInfo
->manaCost
;
4717 // PCT cost from total amount
4718 if (m_spellInfo
->ManaCostPercentage
)
4720 switch (m_spellInfo
->powerType
)
4722 // health as power used
4724 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateHealth() / 100;
4727 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateMana() / 100;
4732 case POWER_HAPPINESS
:
4733 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetMaxPower(Powers(m_spellInfo
->powerType
)) / 100;
4736 case POWER_RUNIC_POWER
:
4737 sLog
.outDebug("Spell::CalculateManaCost: Not implemented yet!");
4740 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4744 SpellSchools school
= GetFirstSchoolInMask(m_spellSchoolMask
);
4745 // Flat mod from caster auras by spell school
4746 powerCost
+= m_caster
->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER
+ school
);
4747 // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
4748 if ( m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST
)
4749 powerCost
+= m_caster
->GetAttackTime(OFF_ATTACK
)/100;
4750 // Apply cost mod by spell
4751 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4752 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, powerCost
, this);
4754 if(m_spellInfo
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
)
4755 powerCost
= int32(powerCost
/ (1.117f
* m_spellInfo
->spellLevel
/ m_caster
->getLevel() -0.1327f
));
4757 // PCT mod from user auras by school
4758 powerCost
= int32(powerCost
* (1.0f
+m_caster
->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+school
)));
4764 SpellCastResult
Spell::CheckPower()
4766 // item cast not used power
4768 return SPELL_CAST_OK
;
4770 // health as power used - need check health amount
4771 if(m_spellInfo
->powerType
== POWER_HEALTH
)
4773 if(m_caster
->GetHealth() <= m_powerCost
)
4774 return SPELL_FAILED_CASTER_AURASTATE
;
4775 return SPELL_CAST_OK
;
4777 // Check valid power type
4778 if( m_spellInfo
->powerType
>= MAX_POWERS
)
4780 sLog
.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo
->powerType
);
4781 return SPELL_FAILED_UNKNOWN
;
4784 SpellCastResult failReason
= CheckRuneCost(m_spellInfo
->runeCostID
);
4785 if(failReason
!= SPELL_CAST_OK
)
4788 // Check power amount
4789 Powers powerType
= Powers(m_spellInfo
->powerType
);
4790 if(m_caster
->GetPower(powerType
) < m_powerCost
)
4791 return SPELL_FAILED_NO_POWER
;
4793 return SPELL_CAST_OK
;
4796 SpellCastResult
Spell::CheckItems()
4798 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4799 return SPELL_CAST_OK
;
4801 Player
* p_caster
= (Player
*)m_caster
;
4806 uint32 itemid
= m_CastItem
->GetEntry();
4807 if( !p_caster
->HasItemCount(itemid
,1) )
4808 return SPELL_FAILED_ITEM_NOT_READY
;
4810 ItemPrototype
const *proto
= m_CastItem
->GetProto();
4812 return SPELL_FAILED_ITEM_NOT_READY
;
4814 for (int i
= 0; i
<5; i
++)
4815 if (proto
->Spells
[i
].SpellCharges
)
4816 if(m_CastItem
->GetSpellCharges(i
)==0)
4817 return SPELL_FAILED_NO_CHARGES_REMAIN
;
4819 // consumable cast item checks
4820 if (proto
->Class
== ITEM_CLASS_CONSUMABLE
&& m_targets
.getUnitTarget())
4822 // such items should only fail if there is no suitable effect at all - see Rejuvenation Potions for example
4823 SpellCastResult failReason
= SPELL_CAST_OK
;
4824 for (int i
= 0; i
< 3; i
++)
4826 // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster
4827 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_PET
)
4830 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_HEAL
)
4832 if (m_targets
.getUnitTarget()->GetHealth() == m_targets
.getUnitTarget()->GetMaxHealth())
4834 failReason
= SPELL_FAILED_ALREADY_AT_FULL_HEALTH
;
4839 failReason
= SPELL_CAST_OK
;
4844 // Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
4845 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
4847 if(m_spellInfo
->EffectMiscValue
[i
] < 0 || m_spellInfo
->EffectMiscValue
[i
] >= MAX_POWERS
)
4849 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
4853 Powers power
= Powers(m_spellInfo
->EffectMiscValue
[i
]);
4854 if (m_targets
.getUnitTarget()->GetPower(power
) == m_targets
.getUnitTarget()->GetMaxPower(power
))
4856 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
4861 failReason
= SPELL_CAST_OK
;
4866 if (failReason
!= SPELL_CAST_OK
)
4871 // check target item
4872 if(m_targets
.getItemTargetGUID())
4874 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4875 return SPELL_FAILED_BAD_TARGETS
;
4877 if(!m_targets
.getItemTarget())
4878 return SPELL_FAILED_ITEM_GONE
;
4880 if(!m_targets
.getItemTarget()->IsFitToSpellRequirements(m_spellInfo
))
4881 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
4883 // if not item target then required item must be equipped
4886 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !((Player
*)m_caster
)->HasItemFitToSpellReqirements(m_spellInfo
))
4887 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
4890 // check spell focus object
4891 if(m_spellInfo
->RequiresSpellFocus
)
4893 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4895 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4897 GameObject
* ok
= NULL
;
4898 MaNGOS::GameObjectFocusCheck
go_check(m_caster
,m_spellInfo
->RequiresSpellFocus
);
4899 MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
> checker(m_caster
,ok
,go_check
);
4901 TypeContainerVisitor
<MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
>, GridTypeMapContainer
> object_checker(checker
);
4902 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4903 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
4906 return SPELL_FAILED_REQUIRES_SPELL_FOCUS
;
4908 focusObject
= ok
; // game object found in range
4911 // check reagents (ignore triggered spells with reagents processed by original spell) and special reagent ignore case.
4912 if (!m_IsTriggeredSpell
&& !p_caster
->CanNoReagentCast(m_spellInfo
))
4914 for(uint32 i
=0;i
<8;i
++)
4916 if(m_spellInfo
->Reagent
[i
] <= 0)
4919 uint32 itemid
= m_spellInfo
->Reagent
[i
];
4920 uint32 itemcount
= m_spellInfo
->ReagentCount
[i
];
4922 // if CastItem is also spell reagent
4923 if( m_CastItem
&& m_CastItem
->GetEntry() == itemid
)
4925 ItemPrototype
const *proto
= m_CastItem
->GetProto();
4927 return SPELL_FAILED_ITEM_NOT_READY
;
4928 for(int s
=0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
4930 // CastItem will be used up and does not count as reagent
4931 int32 charges
= m_CastItem
->GetSpellCharges(s
);
4932 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
4939 if( !p_caster
->HasItemCount(itemid
,itemcount
) )
4940 return SPELL_FAILED_ITEM_NOT_READY
; //0x54
4944 // check totem-item requirements (items presence in inventory)
4946 for(int i
=0;i
<2;++i
)
4948 if(m_spellInfo
->Totem
[i
] != 0)
4950 if( p_caster
->HasItemCount(m_spellInfo
->Totem
[i
],1) )
4959 return SPELL_FAILED_TOTEMS
; //0x7C
4961 // Check items for TotemCategory (items presence in inventory)
4962 uint32 TotemCategory
= 2;
4963 for(int i
=0;i
<2;++i
)
4965 if(m_spellInfo
->TotemCategory
[i
] != 0)
4967 if( p_caster
->HasItemTotemCategory(m_spellInfo
->TotemCategory
[i
]) )
4976 if(TotemCategory
!= 0)
4977 return SPELL_FAILED_TOTEM_CATEGORY
; //0x7B
4979 // special checks for spell effects
4980 for(int i
= 0; i
< 3; i
++)
4982 switch (m_spellInfo
->Effect
[i
])
4984 case SPELL_EFFECT_CREATE_ITEM
:
4986 if (!m_IsTriggeredSpell
&& m_spellInfo
->EffectItemType
[i
])
4988 ItemPosCountVec dest
;
4989 uint8 msg
= p_caster
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, m_spellInfo
->EffectItemType
[i
], 1 );
4990 if (msg
!= EQUIP_ERR_OK
)
4992 p_caster
->SendEquipError( msg
, NULL
, NULL
);
4993 return SPELL_FAILED_DONT_REPORT
;
4998 case SPELL_EFFECT_ENCHANT_ITEM
:
4999 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
5001 Item
* targetItem
= m_targets
.getItemTarget();
5003 return SPELL_FAILED_ITEM_NOT_FOUND
;
5005 if( targetItem
->GetProto()->ItemLevel
< m_spellInfo
->baseLevel
)
5006 return SPELL_FAILED_LOWLEVEL
;
5007 // Not allow enchant in trade slot for some enchant type
5008 if( targetItem
->GetOwner() != m_caster
)
5010 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5011 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5013 return SPELL_FAILED_ERROR
;
5014 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5015 return SPELL_FAILED_NOT_TRADEABLE
;
5019 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
5021 Item
*item
= m_targets
.getItemTarget();
5023 return SPELL_FAILED_ITEM_NOT_FOUND
;
5024 // Not allow enchant in trade slot for some enchant type
5025 if( item
->GetOwner() != m_caster
)
5027 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5028 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5030 return SPELL_FAILED_ERROR
;
5031 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5032 return SPELL_FAILED_NOT_TRADEABLE
;
5036 case SPELL_EFFECT_ENCHANT_HELD_ITEM
:
5037 // check item existence in effect code (not output errors at offhand hold item effect to main hand for example
5039 case SPELL_EFFECT_DISENCHANT
:
5041 if(!m_targets
.getItemTarget())
5042 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5044 // prevent disenchanting in trade slot
5045 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5046 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5048 ItemPrototype
const* itemProto
= m_targets
.getItemTarget()->GetProto();
5050 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5052 uint32 item_quality
= itemProto
->Quality
;
5053 // 2.0.x addon: Check player enchanting level against the item disenchanting requirements
5054 uint32 item_disenchantskilllevel
= itemProto
->RequiredDisenchantSkill
;
5055 if (item_disenchantskilllevel
== uint32(-1))
5056 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5057 if (item_disenchantskilllevel
> p_caster
->GetSkillValue(SKILL_ENCHANTING
))
5058 return SPELL_FAILED_LOW_CASTLEVEL
;
5059 if(item_quality
> 4 || item_quality
< 2)
5060 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5061 if(itemProto
->Class
!= ITEM_CLASS_WEAPON
&& itemProto
->Class
!= ITEM_CLASS_ARMOR
)
5062 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5063 if (!itemProto
->DisenchantID
)
5064 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5067 case SPELL_EFFECT_PROSPECTING
:
5069 if(!m_targets
.getItemTarget())
5070 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5071 //ensure item is a prospectable ore
5072 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_MINING_SUPP
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5073 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5074 //prevent prospecting in trade slot
5075 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5076 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5077 //Check for enough skill in jewelcrafting
5078 uint32 item_prospectingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5079 if(item_prospectingskilllevel
>p_caster
->GetSkillValue(SKILL_JEWELCRAFTING
))
5080 return SPELL_FAILED_LOW_CASTLEVEL
;
5081 //make sure the player has the required ores in inventory
5082 if(m_targets
.getItemTarget()->GetCount() < 5)
5083 return SPELL_FAILED_NEED_MORE_ITEMS
;
5085 if(!LootTemplates_Prospecting
.HaveLootFor(m_targets
.getItemTargetEntry()))
5086 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5090 case SPELL_EFFECT_MILLING
:
5092 if(!m_targets
.getItemTarget())
5093 return SPELL_FAILED_CANT_BE_MILLED
;
5094 //ensure item is a millable herb
5095 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_HERBS
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5096 return SPELL_FAILED_CANT_BE_MILLED
;
5097 //prevent milling in trade slot
5098 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5099 return SPELL_FAILED_CANT_BE_MILLED
;
5100 //Check for enough skill in inscription
5101 uint32 item_millingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5102 if(item_millingskilllevel
>p_caster
->GetSkillValue(SKILL_INSCRIPTION
))
5103 return SPELL_FAILED_LOW_CASTLEVEL
;
5104 //make sure the player has the required herbs in inventory
5105 if(m_targets
.getItemTarget()->GetCount() < 5)
5106 return SPELL_FAILED_NEED_MORE_ITEMS
;
5108 if(!LootTemplates_Milling
.HaveLootFor(m_targets
.getItemTargetEntry()))
5109 return SPELL_FAILED_CANT_BE_MILLED
;
5113 case SPELL_EFFECT_WEAPON_DAMAGE
:
5114 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
:
5116 if(m_caster
->GetTypeId() != TYPEID_PLAYER
) return SPELL_FAILED_TARGET_NOT_PLAYER
;
5117 if( m_attackType
!= RANGED_ATTACK
)
5119 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(m_attackType
);
5120 if(!pItem
|| pItem
->IsBroken())
5121 return SPELL_FAILED_EQUIPPED_ITEM
;
5123 switch(pItem
->GetProto()->SubClass
)
5125 case ITEM_SUBCLASS_WEAPON_THROWN
:
5127 uint32 ammo
= pItem
->GetEntry();
5128 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5129 return SPELL_FAILED_NO_AMMO
;
5131 case ITEM_SUBCLASS_WEAPON_GUN
:
5132 case ITEM_SUBCLASS_WEAPON_BOW
:
5133 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5135 uint32 ammo
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
5139 if(m_caster
->GetDummyAura(46699))
5140 break; // skip other checks
5142 return SPELL_FAILED_NO_AMMO
;
5145 ItemPrototype
const *ammoProto
= objmgr
.GetItemPrototype( ammo
);
5147 return SPELL_FAILED_NO_AMMO
;
5149 if(ammoProto
->Class
!= ITEM_CLASS_PROJECTILE
)
5150 return SPELL_FAILED_NO_AMMO
;
5152 // check ammo ws. weapon compatibility
5153 switch(pItem
->GetProto()->SubClass
)
5155 case ITEM_SUBCLASS_WEAPON_BOW
:
5156 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5157 if(ammoProto
->SubClass
!=ITEM_SUBCLASS_ARROW
)
5158 return SPELL_FAILED_NO_AMMO
;
5160 case ITEM_SUBCLASS_WEAPON_GUN
:
5161 if(ammoProto
->SubClass
!=ITEM_SUBCLASS_BULLET
)
5162 return SPELL_FAILED_NO_AMMO
;
5165 return SPELL_FAILED_NO_AMMO
;
5168 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5169 return SPELL_FAILED_NO_AMMO
;
5171 case ITEM_SUBCLASS_WEAPON_WAND
:
5181 return SPELL_CAST_OK
;
5184 void Spell::Delayed()
5186 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
5189 if (m_spellState
== SPELL_STATE_DELAYED
)
5190 return; // spell is active and can't be time-backed
5192 if(isDelayableNoMore()) // Spells may only be delayed twice
5195 // spells not loosing casting time ( slam, dynamites, bombs.. )
5196 if(!(m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_DAMAGE
))
5199 //check pushback reduce
5200 int32 delaytime
= 500; // spellcasting delay is normally 500ms
5201 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5202 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
,SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5203 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5204 if(delayReduce
>= 100)
5207 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5209 if(int32(m_timer
) + delaytime
> m_casttime
)
5211 delaytime
= m_casttime
- m_timer
;
5212 m_timer
= m_casttime
;
5215 m_timer
+= delaytime
;
5217 sLog
.outDetail("Spell %u partially interrupted for (%d) ms at damage",m_spellInfo
->Id
,delaytime
);
5219 WorldPacket
data(SMSG_SPELL_DELAYED
, 8+4);
5220 data
.append(m_caster
->GetPackGUID());
5221 data
<< uint32(delaytime
);
5223 m_caster
->SendMessageToSet(&data
,true);
5226 void Spell::DelayedChannel()
5228 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
|| getState() != SPELL_STATE_CASTING
)
5231 if(isDelayableNoMore()) // Spells may only be delayed twice
5234 //check pushback reduce
5235 int32 delaytime
= GetSpellDuration(m_spellInfo
) * 25 / 100; // channeling delay is normally 25% of its time per hit
5236 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5237 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
,SPELLMOD_NOT_LOSE_CASTING_TIME
,delayReduce
, this);
5238 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5239 if(delayReduce
>= 100)
5242 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5244 if(int32(m_timer
) < delaytime
)
5246 delaytime
= m_timer
;
5250 m_timer
-= delaytime
;
5252 sLog
.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo
->Id
, delaytime
, m_timer
);
5254 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
5256 if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
5258 Unit
* unit
= m_caster
->GetGUID()==ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
5261 for (int j
=0;j
<3;j
++)
5262 if( ihit
->effectMask
& (1<<j
) )
5263 unit
->DelayAura(m_spellInfo
->Id
, j
, delaytime
);
5269 for(int j
= 0; j
< 3; j
++)
5271 // partially interrupt persistent area auras
5272 DynamicObject
* dynObj
= m_caster
->GetDynObject(m_spellInfo
->Id
, j
);
5274 dynObj
->Delay(delaytime
);
5277 SendChannelUpdate(m_timer
);
5280 void Spell::UpdatePointers()
5282 if(m_originalCasterGUID
==m_caster
->GetGUID())
5283 m_originalCaster
= m_caster
;
5286 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
,m_originalCasterGUID
);
5287 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
5290 m_targets
.Update(m_caster
);
5293 bool Spell::IsAffectedByAura(Aura
*aura
)
5295 return spellmgr
.IsAffectedByMod(m_spellInfo
, aura
->getAuraSpellMod());
5298 bool Spell::CheckTargetCreatureType(Unit
* target
) const
5300 uint32 spellCreatureTargetMask
= m_spellInfo
->TargetCreatureType
;
5302 // Curse of Doom : not find another way to fix spell target check :/
5303 if(m_spellInfo
->SpellFamilyName
==SPELLFAMILY_WARLOCK
&& m_spellInfo
->SpellFamilyFlags
== 0x0200000000LL
)
5305 // not allow cast at player
5306 if(target
->GetTypeId()==TYPEID_PLAYER
)
5309 spellCreatureTargetMask
= 0x7FF;
5312 // Dismiss Pet and Taming Lesson skipped
5313 if(m_spellInfo
->Id
== 2641 || m_spellInfo
->Id
== 23356)
5314 spellCreatureTargetMask
= 0;
5316 if (spellCreatureTargetMask
)
5318 uint32 TargetCreatureType
= target
->GetCreatureTypeMask();
5320 return !TargetCreatureType
|| (spellCreatureTargetMask
& TargetCreatureType
);
5325 CurrentSpellTypes
Spell::GetCurrentContainer()
5327 if (IsNextMeleeSwingSpell())
5328 return(CURRENT_MELEE_SPELL
);
5329 else if (IsAutoRepeat())
5330 return(CURRENT_AUTOREPEAT_SPELL
);
5331 else if (IsChanneledSpell(m_spellInfo
))
5332 return(CURRENT_CHANNELED_SPELL
);
5334 return(CURRENT_GENERIC_SPELL
);
5337 bool Spell::CheckTarget( Unit
* target
, uint32 eff
)
5339 // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets)
5340 if(m_spellInfo
->EffectImplicitTargetA
[eff
]!=TARGET_SELF
)
5342 if (!CheckTargetCreatureType(target
))
5346 // Check Aura spell req (need for AoE spells)
5347 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
5349 if (m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
5352 // Check targets for not_selectable unit flag and remove
5353 // A player can cast spells on his pet (or other controlled unit) though in any state
5354 if (target
!= m_caster
&& target
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
5356 // any unattackable target skipped
5357 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
))
5360 // unselectable targets skipped in all cases except TARGET_SCRIPT targeting
5361 // in case TARGET_SCRIPT target selected by server always and can't be cheated
5362 if( target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NOT_SELECTABLE
) &&
5363 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SCRIPT
&&
5364 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_SCRIPT
)
5368 //Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
5369 if( target
!= m_caster
&& target
->GetTypeId()==TYPEID_PLAYER
)
5371 if(((Player
*)target
)->GetVisibility()==VISIBILITY_OFF
)
5374 if(((Player
*)target
)->isGameMaster() && !IsPositiveSpell(m_spellInfo
->Id
))
5378 //Check targets for LOS visibility (except spells without range limitations )
5379 switch(m_spellInfo
->Effect
[eff
])
5381 case SPELL_EFFECT_SUMMON_PLAYER
: // from anywhere
5383 case SPELL_EFFECT_DUMMY
:
5384 if(m_spellInfo
->Id
!=20577) // Cannibalize
5387 case SPELL_EFFECT_RESURRECT_NEW
:
5388 // player far away, maybe his corpse near?
5389 if(target
!=m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
5391 if(!m_targets
.getCorpseTargetGUID())
5394 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
5398 if(target
->GetGUID()!=corpse
->GetOwnerGUID())
5401 if(!corpse
->IsWithinLOSInMap(m_caster
))
5405 // all ok by some way or another, skip normal check
5407 default: // normal case
5408 // Get GO cast coordinates if original caster -> GO
5409 WorldObject
*caster
= NULL
;
5410 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
5411 caster
= ObjectAccessor::GetGameObject(*m_caster
, m_originalCasterGUID
);
5414 if(target
!=m_caster
&& !target
->IsWithinLOSInMap(caster
))
5422 Unit
* Spell::SelectMagnetTarget()
5424 Unit
* target
= m_targets
.getUnitTarget();
5426 if(target
&& target
->HasAuraType(SPELL_AURA_SPELL_MAGNET
) && !(m_spellInfo
->Attributes
& 0x10))
5428 Unit::AuraList
const& magnetAuras
= target
->GetAurasByType(SPELL_AURA_SPELL_MAGNET
);
5429 for(Unit::AuraList::const_iterator itr
= magnetAuras
.begin(); itr
!= magnetAuras
.end(); ++itr
)
5431 if(Unit
* magnet
= (*itr
)->GetCaster())
5433 if(magnet
->IsWithinLOSInMap(m_caster
))
5436 m_targets
.setUnitTarget(target
);
5446 bool Spell::IsNeedSendToClient() const
5448 return m_spellInfo
->SpellVisual
[0] || m_spellInfo
->SpellVisual
[1] || IsChanneledSpell(m_spellInfo
) ||
5449 m_spellInfo
->speed
> 0.0f
|| !m_triggeredByAuraSpell
&& !m_IsTriggeredSpell
;
5452 bool Spell::HaveTargetsForEffect( uint8 effect
) const
5454 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin();itr
!= m_UniqueTargetInfo
.end();++itr
)
5455 if(itr
->effectMask
& (1<<effect
))
5458 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin();itr
!= m_UniqueGOTargetInfo
.end();++itr
)
5459 if(itr
->effectMask
& (1<<effect
))
5462 for(std::list
<ItemTargetInfo
>::const_iterator itr
= m_UniqueItemInfo
.begin();itr
!= m_UniqueItemInfo
.end();++itr
)
5463 if(itr
->effectMask
& (1<<effect
))
5469 SpellEvent::SpellEvent(Spell
* spell
) : BasicEvent()
5474 SpellEvent::~SpellEvent()
5476 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5479 if (m_Spell
->IsDeletable())
5485 sLog
.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
5486 (m_Spell
->GetCaster()->GetTypeId()==TYPEID_PLAYER
?"Player":"Creature"), m_Spell
->GetCaster()->GetGUIDLow(),m_Spell
->m_spellInfo
->Id
);
5490 bool SpellEvent::Execute(uint64 e_time
, uint32 p_time
)
5492 // update spell if it is not finished
5493 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5494 m_Spell
->update(p_time
);
5496 // check spell state to process
5497 switch (m_Spell
->getState())
5499 case SPELL_STATE_FINISHED
:
5501 // spell was finished, check deletable state
5502 if (m_Spell
->IsDeletable())
5504 // check, if we do have unfinished triggered spells
5506 return(true); // spell is deletable, finish event
5508 // event will be re-added automatically at the end of routine)
5511 case SPELL_STATE_CASTING
:
5513 // this spell is in channeled state, process it on the next update
5514 // event will be re-added automatically at the end of routine)
5517 case SPELL_STATE_DELAYED
:
5519 // first, check, if we have just started
5520 if (m_Spell
->GetDelayStart() != 0)
5522 // no, we aren't, do the typical update
5523 // check, if we have channeled spell on our hands
5524 if (IsChanneledSpell(m_Spell
->m_spellInfo
))
5526 // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish
5527 // check, if we have casting anything else except this channeled spell and autorepeat
5528 if (m_Spell
->GetCaster()->IsNonMeleeSpellCasted(false, true, true))
5530 // another non-melee non-delayed spell is casted now, abort
5535 // do the action (pass spell to channeling state)
5536 m_Spell
->handle_immediate();
5538 // event will be re-added automatically at the end of routine)
5542 // run the spell handler and think about what we can do next
5543 uint64 t_offset
= e_time
- m_Spell
->GetDelayStart();
5544 uint64 n_offset
= m_Spell
->handle_delayed(t_offset
);
5547 // re-add us to the queue
5548 m_Spell
->GetCaster()->m_Events
.AddEvent(this, m_Spell
->GetDelayStart() + n_offset
, false);
5549 return(false); // event not complete
5552 // finish update event will be re-added automatically at the end of routine)
5557 // delaying had just started, record the moment
5558 m_Spell
->SetDelayStart(e_time
);
5559 // re-plan the event for the delay moment
5560 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ m_Spell
->GetDelayMoment(), false);
5561 return(false); // event not complete
5568 // event will be re-added automatically at the end of routine)
5572 // spell processing not complete, plan event on the next update interval
5573 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ 1, false);
5574 return(false); // event not complete
5577 void SpellEvent::Abort(uint64
/*e_time*/)
5579 // oops, the spell we try to do is aborted
5580 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5584 bool SpellEvent::IsDeletable() const
5586 return m_Spell
->IsDeletable();
5589 SpellCastResult
Spell::CanOpenLock(uint32 effIndex
, uint32 lockId
, SkillType
& skillId
, int32
& reqSkillValue
, int32
& skillValue
)
5591 if(!lockId
) // possible case for GO and maybe for items.
5592 return SPELL_CAST_OK
;
5595 LockEntry
const *lockInfo
= sLockStore
.LookupEntry(lockId
);
5598 return SPELL_FAILED_BAD_TARGETS
;
5600 bool reqKey
= false; // some locks not have reqs
5602 for(int j
= 0; j
< 8; ++j
)
5604 switch(lockInfo
->Type
[j
])
5606 // check key item (many fit cases can be)
5608 if(lockInfo
->Index
[j
] && m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->Index
[j
])
5609 return SPELL_CAST_OK
;
5612 // check key skill (only single first fit case can be)
5613 case LOCK_KEY_SKILL
:
5617 // wrong locktype, skip
5618 if(uint32(m_spellInfo
->EffectMiscValue
[effIndex
]) != lockInfo
->Index
[j
])
5621 skillId
= SkillByLockType(LockType(lockInfo
->Index
[j
]));
5623 if ( skillId
!= SKILL_NONE
)
5625 // skill bonus provided by casting spell (mostly item spells)
5626 // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value)
5627 uint32 spellSkillBonus
= uint32(m_currentBasePoints
[effIndex
]+1);
5628 reqSkillValue
= lockInfo
->Skill
[j
];
5630 // castitem check: rogue using skeleton keys. the skill values should not be added in this case.
5631 skillValue
= m_CastItem
|| m_caster
->GetTypeId()!= TYPEID_PLAYER
?
5632 0 : ((Player
*)m_caster
)->GetSkillValue(skillId
);
5634 skillValue
+= spellSkillBonus
;
5636 if (skillValue
< reqSkillValue
)
5637 return SPELL_FAILED_LOW_CASTLEVEL
;
5640 return SPELL_CAST_OK
;
5646 return SPELL_FAILED_BAD_TARGETS
;
5648 return SPELL_CAST_OK
;
5651 void Spell::FillAreaTargets( UnitList
& TagUnitMap
, float x
, float y
, float radius
, SpellNotifyPushType pushType
, SpellTargets spellTargets
)
5653 CellPair
p(MaNGOS::ComputeCellPair(x
, y
));
5655 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5657 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, pushType
, spellTargets
);
5658 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
5659 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
5660 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5661 cell_lock
->Visit(cell_lock
, world_notifier
, *m_caster
->GetMap());
5662 cell_lock
->Visit(cell_lock
, grid_notifier
, *m_caster
->GetMap());