2 * Copyright (C) 2005-2010 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 PrioritizeManaUnitWraper
55 explicit PrioritizeManaUnitWraper(Unit
* unit
) : i_unit(unit
)
57 uint32 maxmana
= unit
->GetMaxPower(POWER_MANA
);
58 i_percent
= maxmana
? unit
->GetPower(POWER_MANA
) * 100 / maxmana
: 101;
60 Unit
* getUnit() const { return i_unit
; }
61 uint32
getPercent() const { return i_percent
; }
69 int operator()( PrioritizeManaUnitWraper
const& x
, PrioritizeManaUnitWraper
const& y
) const
71 return x
.getPercent() < y
.getPercent();
75 typedef std::priority_queue
<PrioritizeManaUnitWraper
, std::vector
<PrioritizeManaUnitWraper
>, PrioritizeMana
> PrioritizeManaUnitQueue
;
77 class PrioritizeHealthUnitWraper
80 explicit PrioritizeHealthUnitWraper(Unit
* unit
) : i_unit(unit
)
82 i_percent
= unit
->GetHealth() * 100 / unit
->GetMaxHealth();
84 Unit
* getUnit() const { return i_unit
; }
85 uint32
getPercent() const { return i_percent
; }
91 struct PrioritizeHealth
93 int operator()( PrioritizeHealthUnitWraper
const& x
, PrioritizeHealthUnitWraper
const& y
) const
95 return x
.getPercent() < y
.getPercent();
99 typedef std::priority_queue
<PrioritizeHealthUnitWraper
, std::vector
<PrioritizeHealthUnitWraper
>, PrioritizeHealth
> PrioritizeHealthUnitQueue
;
101 bool IsQuestTameSpell(uint32 spellId
)
103 SpellEntry
const *spellproto
= sSpellStore
.LookupEntry(spellId
);
104 if (!spellproto
) return false;
106 return spellproto
->Effect
[0] == SPELL_EFFECT_THREAT
107 && spellproto
->Effect
[1] == SPELL_EFFECT_APPLY_AURA
&& spellproto
->EffectApplyAuraName
[1] == SPELL_AURA_DUMMY
;
110 SpellCastTargets::SpellCastTargets()
116 m_unitTargetGUID
= 0;
118 m_CorpseTargetGUID
= 0;
119 m_itemTargetGUID
= 0;
120 m_itemTargetEntry
= 0;
122 m_srcX
= m_srcY
= m_srcZ
= m_destX
= m_destY
= m_destZ
= 0;
127 SpellCastTargets::~SpellCastTargets()
131 void SpellCastTargets::setUnitTarget(Unit
*target
)
136 m_destX
= target
->GetPositionX();
137 m_destY
= target
->GetPositionY();
138 m_destZ
= target
->GetPositionZ();
139 m_unitTarget
= target
;
140 m_unitTargetGUID
= target
->GetGUID();
141 m_targetMask
|= TARGET_FLAG_UNIT
;
144 void SpellCastTargets::setDestination(float x
, float y
, float z
)
149 m_targetMask
|= TARGET_FLAG_DEST_LOCATION
;
152 void SpellCastTargets::setSource(float x
, float y
, float z
)
157 m_targetMask
|= TARGET_FLAG_SOURCE_LOCATION
;
160 void SpellCastTargets::setGOTarget(GameObject
*target
)
163 m_GOTargetGUID
= target
->GetGUID();
164 // m_targetMask |= TARGET_FLAG_OBJECT;
167 void SpellCastTargets::setItemTarget(Item
* item
)
173 m_itemTargetGUID
= item
->GetGUID();
174 m_itemTargetEntry
= item
->GetEntry();
175 m_targetMask
|= TARGET_FLAG_ITEM
;
178 void SpellCastTargets::setCorpseTarget(Corpse
* corpse
)
180 m_CorpseTargetGUID
= corpse
->GetGUID();
183 void SpellCastTargets::Update(Unit
* caster
)
185 m_GOTarget
= m_GOTargetGUID
? caster
->GetMap()->GetGameObject(m_GOTargetGUID
) : NULL
;
186 m_unitTarget
= m_unitTargetGUID
?
187 ( m_unitTargetGUID
== caster
->GetGUID() ? caster
: ObjectAccessor::GetUnit(*caster
, m_unitTargetGUID
) ) :
191 if(caster
->GetTypeId() == TYPEID_PLAYER
)
193 if(m_targetMask
& TARGET_FLAG_ITEM
)
194 m_itemTarget
= ((Player
*)caster
)->GetItemByGuid(m_itemTargetGUID
);
197 Player
* pTrader
= ((Player
*)caster
)->GetTrader();
198 if(pTrader
&& m_itemTargetGUID
< TRADE_SLOT_COUNT
)
199 m_itemTarget
= pTrader
->GetItemByPos(pTrader
->GetItemPosByTradeSlot(m_itemTargetGUID
));
202 m_itemTargetEntry
= m_itemTarget
->GetEntry();
206 bool SpellCastTargets::read ( WorldPacket
* data
, Unit
*caster
)
208 if(data
->rpos() + 4 > data
->size())
211 *data
>> m_targetMask
;
213 if(m_targetMask
== TARGET_FLAG_SELF
)
215 m_destX
= caster
->GetPositionX();
216 m_destY
= caster
->GetPositionY();
217 m_destZ
= caster
->GetPositionZ();
218 m_unitTarget
= caster
;
219 m_unitTargetGUID
= caster
->GetGUID();
223 // TARGET_FLAG_UNK2 is used for non-combat pets, maybe other?
224 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_UNK2
))
225 if(!data
->readPackGUID(m_unitTargetGUID
))
228 if( m_targetMask
& ( TARGET_FLAG_OBJECT
))
229 if(!data
->readPackGUID(m_GOTargetGUID
))
232 if(( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
)) && caster
->GetTypeId() == TYPEID_PLAYER
)
233 if(!data
->readPackGUID(m_itemTargetGUID
))
236 if( m_targetMask
& (TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
237 if(!data
->readPackGUID(m_CorpseTargetGUID
))
240 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
242 if(data
->rpos() + 1 + 4 + 4 + 4 > data
->size())
245 if(!data
->readPackGUID(m_unitTargetGUID
))
248 *data
>> m_srcX
>> m_srcY
>> m_srcZ
;
249 if(!MaNGOS::IsValidMapCoord(m_srcX
, m_srcY
, m_srcZ
))
253 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
255 if(data
->rpos() + 1 + 4 + 4 + 4 > data
->size())
258 if(!data
->readPackGUID(m_unitTargetGUID
))
261 *data
>> m_destX
>> m_destY
>> m_destZ
;
262 if(!MaNGOS::IsValidMapCoord(m_destX
, m_destY
, m_destZ
))
266 if( m_targetMask
& TARGET_FLAG_STRING
)
268 if(data
->rpos() + 1 > data
->size())
271 *data
>> m_strTarget
;
274 // find real units/GOs
279 void SpellCastTargets::write ( WorldPacket
* data
)
281 *data
<< uint32(m_targetMask
);
283 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_PVP_CORPSE
| TARGET_FLAG_OBJECT
| TARGET_FLAG_CORPSE
| TARGET_FLAG_UNK2
) )
285 if(m_targetMask
& TARGET_FLAG_UNIT
)
288 data
->append(m_unitTarget
->GetPackGUID());
292 else if( m_targetMask
& TARGET_FLAG_OBJECT
)
295 data
->append(m_GOTarget
->GetPackGUID());
299 else if( m_targetMask
& ( TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
300 data
->appendPackGUID(m_CorpseTargetGUID
);
305 if( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
) )
308 data
->append(m_itemTarget
->GetPackGUID());
313 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
316 data
->append(m_unitTarget
->GetPackGUID());
320 *data
<< m_srcX
<< m_srcY
<< m_srcZ
;
323 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
326 data
->append(m_unitTarget
->GetPackGUID());
330 *data
<< m_destX
<< m_destY
<< m_destZ
;
333 if( m_targetMask
& TARGET_FLAG_STRING
)
334 *data
<< m_strTarget
;
337 Spell::Spell( Unit
* Caster
, SpellEntry
const *info
, bool triggered
, uint64 originalCasterGUID
, Spell
** triggeringContainer
)
339 ASSERT( Caster
!= NULL
&& info
!= NULL
);
340 ASSERT( info
== sSpellStore
.LookupEntry( info
->Id
) && "`info` must be pointer to sSpellStore element");
344 m_selfContainer
= NULL
;
345 m_triggeringContainer
= triggeringContainer
;
346 m_referencedFromCurrentSpell
= false;
347 m_executedCurrently
= false;
349 m_delayAtDamageCount
= 0;
351 m_applyMultiplierMask
= 0;
353 // Get data for type of attack
354 m_attackType
= GetWeaponAttackType(m_spellInfo
);
356 m_spellSchoolMask
= GetSpellSchoolMask(info
); // Can be override for some spell (wand shoot for example)
358 if(m_attackType
== RANGED_ATTACK
)
361 if((m_caster
->getClassMask() & CLASSMASK_WAND_USERS
) != 0 && m_caster
->GetTypeId() == TYPEID_PLAYER
)
363 if(Item
* pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(RANGED_ATTACK
))
364 m_spellSchoolMask
= SpellSchoolMask(1 << pItem
->GetProto()->Damage
[0].DamageType
);
367 // Set health leech amount to zero
370 if(originalCasterGUID
)
371 m_originalCasterGUID
= originalCasterGUID
;
373 m_originalCasterGUID
= m_caster
->GetGUID();
375 if(m_originalCasterGUID
== m_caster
->GetGUID())
376 m_originalCaster
= m_caster
;
379 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
, m_originalCasterGUID
);
380 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
383 for(int i
=0; i
<3; ++i
)
384 m_currentBasePoints
[i
] = m_spellInfo
->EffectBasePoints
[i
];
386 m_spellState
= SPELL_STATE_NULL
;
388 m_castPositionX
= m_castPositionY
= m_castPositionZ
= 0;
389 m_TriggerSpells
.clear();
390 m_preCastSpells
.clear();
391 m_IsTriggeredSpell
= triggered
;
392 //m_AreaAura = false;
397 gameObjTarget
= NULL
;
401 m_triggeredByAuraSpell
= NULL
;
403 //Auto Shot & Shoot (wand)
404 m_autoRepeat
= IsAutoRepeatRangedSpell(m_spellInfo
);
407 m_powerCost
= 0; // setup to correct value in Spell::prepare, don't must be used before.
408 m_casttime
= 0; // setup to correct value in Spell::prepare, don't must be used before.
409 m_timer
= 0; // will set to castime in prepare
411 m_needAliveTargetMask
= 0;
413 // determine reflection
414 m_canReflect
= false;
416 if(m_spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
&& !(m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
))
418 for(int j
= 0;j
< 3; ++j
)
420 if (m_spellInfo
->Effect
[j
] == 0)
423 if(!IsPositiveTarget(m_spellInfo
->EffectImplicitTargetA
[j
], m_spellInfo
->EffectImplicitTargetB
[j
]))
426 m_canReflect
= (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NEGATIVE
) ? true : false;
443 WorldObject
* Spell::FindCorpseUsing()
445 // non-standard target selection
446 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
447 float max_range
= GetSpellMaxRange(srange
);
449 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
451 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
454 WorldObject
* result
= NULL
;
456 T
u_check(m_caster
, max_range
);
457 MaNGOS::WorldObjectSearcher
<T
> searcher(m_caster
, result
, u_check
);
459 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<T
>, GridTypeMapContainer
> grid_searcher(searcher
);
460 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
461 cell_lock
->Visit(cell_lock
, grid_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
465 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<T
>, WorldTypeMapContainer
> world_searcher(searcher
);
466 cell_lock
->Visit(cell_lock
, world_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
472 void Spell::FillTargetMap()
474 // TODO: ADD the correct target FILLS!!!!!!
476 for(uint32 i
= 0; i
< 3; ++i
)
478 // not call for empty effect.
479 // Also some spells use not used effect targets for store targets for dummy effect in triggered spells
480 if(m_spellInfo
->Effect
[i
] == 0)
483 // targets for TARGET_SCRIPT_COORDINATES (A) and TARGET_SCRIPT
484 // for TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT (A) all is checked in Spell::CheckCast and in Spell::CheckItem
485 // filled in Spell::CheckCast call
486 if(m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT_COORDINATES
||
487 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT
||
488 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
||
489 (m_spellInfo
->EffectImplicitTargetB
[i
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
))
492 // TODO: find a way so this is not needed?
493 // for area auras always add caster as target (needed for totems for example)
494 if(IsAreaAuraEffect(m_spellInfo
->Effect
[i
]))
495 AddUnitTarget(m_caster
, i
);
497 std::list
<Unit
*> tmpUnitMap
;
499 // TargetA/TargetB dependent from each other, we not switch to full support this dependences
500 // but need it support in some know cases
501 switch(m_spellInfo
->EffectImplicitTargetA
[i
])
504 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
507 SetTargetMap(i
, TARGET_EFFECT_SELECT
, tmpUnitMap
);
510 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
515 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
518 case TARGET_EFFECT_SELECT
:
519 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
521 case TARGET_AREAEFFECT_INSTANT
: // use B case that not dependent from from A in fact
522 if((m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
) == 0)
523 m_targets
.setDestination(m_caster
->GetPositionX(), m_caster
->GetPositionY(), m_caster
->GetPositionZ());
524 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
526 case TARGET_BEHIND_VICTIM
: // use B case that not dependent from from A in fact
527 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
530 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
531 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
535 case TARGET_EFFECT_SELECT
:
536 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
539 case TARGET_EFFECT_SELECT
:
540 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
542 case TARGET_INNKEEPER_COORDINATES
:
543 case TARGET_TABLE_X_Y_Z_COORDINATES
:
544 case TARGET_CASTER_COORDINATES
:
545 case TARGET_SCRIPT_COORDINATES
:
546 case TARGET_CURRENT_ENEMY_COORDINATES
:
547 case TARGET_DUELVSPLAYER_COORDINATES
:
548 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
549 case TARGET_POINT_AT_NORTH
:
550 case TARGET_POINT_AT_SOUTH
:
551 case TARGET_POINT_AT_EAST
:
552 case TARGET_POINT_AT_WEST
:
553 case TARGET_POINT_AT_NE
:
554 case TARGET_POINT_AT_NW
:
555 case TARGET_POINT_AT_SE
:
556 case TARGET_POINT_AT_SW
:
557 // need some target for proccesing
558 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
559 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
562 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
566 case TARGET_CASTER_COORDINATES
:
567 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
569 case TARGET_ALL_ENEMY_IN_AREA
:
570 // Note: this hack with search required until GO casting not implemented
571 // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support
572 // currently each enemy selected explicitly and self cast damage
573 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
)
575 if(m_targets
.getUnitTarget())
576 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
580 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
581 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
585 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
586 tmpUnitMap
.push_back(m_caster
);
589 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
590 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
594 case TARGET_TABLE_X_Y_Z_COORDINATES
:
595 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
598 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
600 // need some target for proccesing
601 SetTargetMap(i
, TARGET_EFFECT_SELECT
, tmpUnitMap
);
603 case TARGET_AREAEFFECT_INSTANT
: // All 17/7 pairs used for dest teleportation, A processed in effect code
604 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
607 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
608 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
613 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
616 case TARGET_EFFECT_SELECT
:
617 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
619 // most A/B target pairs is slef->negative and not expect adding caster to target list
621 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
626 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
629 case TARGET_EFFECT_SELECT
:
630 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
632 case TARGET_SCRIPT_COORDINATES
: // B case filled in CheckCast but we need fill unit list base at A case
633 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
636 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
637 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
643 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
645 Player
*me
= (Player
*)m_caster
;
646 for (std::list
<Unit
*>::const_iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end(); ++itr
)
648 Unit
*owner
= (*itr
)->GetOwner();
649 Unit
*u
= owner
? owner
: (*itr
);
650 if(u
!=m_caster
&& u
->IsPvP() && (!me
->duel
|| me
->duel
->opponent
!= u
))
653 me
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
659 for (std::list
<Unit
*>::iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end();)
661 if (!CheckTarget (*itr
, i
))
663 itr
= tmpUnitMap
.erase(itr
);
670 for(std::list
<Unit
*>::const_iterator iunit
= tmpUnitMap
.begin(); iunit
!= tmpUnitMap
.end(); ++iunit
)
671 AddUnitTarget((*iunit
), i
);
675 void Spell::prepareDataForTriggerSystem()
677 //==========================================================================================
678 // Now fill data for trigger system, need know:
679 // an spell trigger another or not ( m_canTrigger )
680 // Create base triggers flags for Attacker and Victim ( m_procAttacker and m_procVictim)
681 //==========================================================================================
682 // Fill flag can spell trigger or not
683 // TODO: possible exist spell attribute for this
684 m_canTrigger
= false;
687 m_canTrigger
= false; // Do not trigger from item cast spell
688 else if (!m_IsTriggeredSpell
)
689 m_canTrigger
= true; // Normal cast - can trigger
690 else if (!m_triggeredByAuraSpell
)
691 m_canTrigger
= true; // Triggered from SPELL_EFFECT_TRIGGER_SPELL - can trigger
693 if (!m_canTrigger
) // Exceptions (some periodic triggers)
695 switch (m_spellInfo
->SpellFamilyName
)
697 case SPELLFAMILY_MAGE
:
698 // Arcane Missles / Blizzard triggers need do it
699 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000200080))
701 // Clearcasting trigger need do it
702 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000200000000) && m_spellInfo
->SpellFamilyFlags2
& 0x8)
704 // Replenish Mana, item spell with triggered cases (Mana Agate, etc mana gems)
705 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000010000000000))
708 case SPELLFAMILY_WARLOCK
:
709 // For Hellfire Effect / Rain of Fire / Seed of Corruption triggers need do it
710 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000800000000060))
713 case SPELLFAMILY_PRIEST
:
714 // For Penance,Mind Sear,Mind Flay heal/damage triggers need do it
715 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0001800000800000) || (m_spellInfo
->SpellFamilyFlags2
& 0x00000040))
718 case SPELLFAMILY_ROGUE
:
719 // For poisons need do it
720 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x000000101001E000))
723 case SPELLFAMILY_HUNTER
:
724 // Hunter Rapid Killing/Explosive Trap Effect/Immolation Trap Effect/Frost Trap Aura/Snake Trap Effect/Explosive Shot
725 if ((m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0100200000000214)) ||
726 m_spellInfo
->SpellFamilyFlags2
& 0x200)
729 case SPELLFAMILY_PALADIN
:
730 // For Judgements (all) / Holy Shock triggers need do it
731 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0001000900B80400))
739 // Get data for type of attack and fill base info for trigger
740 switch (m_spellInfo
->DmgClass
)
742 case SPELL_DAMAGE_CLASS_MELEE
:
743 m_procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT
;
744 m_procVictim
= PROC_FLAG_TAKEN_MELEE_SPELL_HIT
;
746 case SPELL_DAMAGE_CLASS_RANGED
:
748 if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
)
750 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
751 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
753 else // Ranged spell attack
755 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT
;
756 m_procVictim
= PROC_FLAG_TAKEN_RANGED_SPELL_HIT
;
760 if (IsPositiveSpell(m_spellInfo
->Id
)) // Check for positive spell
762 m_procAttacker
= PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
;
763 m_procVictim
= PROC_FLAG_TAKEN_POSITIVE_SPELL
;
765 else if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
) // Wands auto attack
767 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
768 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
770 else // Negative spell
772 m_procAttacker
= PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT
;
773 m_procVictim
= PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
;
777 // Hunter traps spells (for Entrapment trigger)
778 // Gives your Immolation Trap, Frost Trap, Explosive Trap, and Snake Trap ....
779 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_HUNTER
&& (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x000020000000001C)))
780 m_procAttacker
|= PROC_FLAG_ON_TRAP_ACTIVATION
;
783 void Spell::CleanupTargetList()
785 m_UniqueTargetInfo
.clear();
786 m_UniqueGOTargetInfo
.clear();
787 m_UniqueItemInfo
.clear();
791 void Spell::AddUnitTarget(Unit
* pVictim
, uint32 effIndex
)
793 if( m_spellInfo
->Effect
[effIndex
] == 0 )
796 // Check for effect immune skip if immuned
797 bool immuned
= pVictim
->IsImmunedToSpellEffect(m_spellInfo
, effIndex
);
799 uint64 targetGUID
= pVictim
->GetGUID();
801 // Lookup target in already in list
802 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
804 if (targetGUID
== ihit
->targetGUID
) // Found in list
807 ihit
->effectMask
|= 1 << effIndex
; // Add only effect mask if not immuned
812 // This is new target calculate data for him
814 // Get spell hit result on target
816 target
.targetGUID
= targetGUID
; // Store target GUID
817 target
.effectMask
= immuned
? 0 : 1 << effIndex
; // Store index of effect if not immuned
818 target
.processed
= false; // Effects not apply on target
820 // Calculate hit result
821 target
.missCondition
= m_caster
->SpellHitResult(pVictim
, m_spellInfo
, m_canReflect
);
823 // Spell have speed - need calculate incoming time
824 if (m_spellInfo
->speed
> 0.0f
)
826 // calculate spell incoming interval
827 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
828 if (dist
< 5.0f
) dist
= 5.0f
;
829 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
831 // Calculate minimum incoming time
832 if (m_delayMoment
== 0 || m_delayMoment
>target
.timeDelay
)
833 m_delayMoment
= target
.timeDelay
;
836 target
.timeDelay
= UI64LIT(0);
838 // If target reflect spell back to caster
839 if (target
.missCondition
== SPELL_MISS_REFLECT
)
841 // Calculate reflected spell result on caster
842 target
.reflectResult
= m_caster
->SpellHitResult(m_caster
, m_spellInfo
, m_canReflect
);
844 if (target
.reflectResult
== SPELL_MISS_REFLECT
) // Impossible reflect again, so simply deflect spell
845 target
.reflectResult
= SPELL_MISS_PARRY
;
847 // Increase time interval for reflected spells by 1.5
848 target
.timeDelay
+= target
.timeDelay
>> 1;
851 target
.reflectResult
= SPELL_MISS_NONE
;
853 // Add target to list
854 m_UniqueTargetInfo
.push_back(target
);
857 void Spell::AddUnitTarget(uint64 unitGUID
, uint32 effIndex
)
859 Unit
* unit
= m_caster
->GetGUID() == unitGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, unitGUID
);
861 AddUnitTarget(unit
, effIndex
);
864 void Spell::AddGOTarget(GameObject
* pVictim
, uint32 effIndex
)
866 if( m_spellInfo
->Effect
[effIndex
] == 0 )
869 uint64 targetGUID
= pVictim
->GetGUID();
871 // Lookup target in already in list
872 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
874 if (targetGUID
== ihit
->targetGUID
) // Found in list
876 ihit
->effectMask
|= 1 << effIndex
; // Add only effect mask
881 // This is new target calculate data for him
884 target
.targetGUID
= targetGUID
;
885 target
.effectMask
= 1 << effIndex
;
886 target
.processed
= false; // Effects not apply on target
888 // Spell have speed - need calculate incoming time
889 if (m_spellInfo
->speed
> 0.0f
)
891 // calculate spell incoming interval
892 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
893 if (dist
< 5.0f
) dist
= 5.0f
;
894 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
895 if (m_delayMoment
==0 || m_delayMoment
>target
.timeDelay
)
896 m_delayMoment
= target
.timeDelay
;
899 target
.timeDelay
= UI64LIT(0);
901 // Add target to list
902 m_UniqueGOTargetInfo
.push_back(target
);
905 void Spell::AddGOTarget(uint64 goGUID
, uint32 effIndex
)
907 GameObject
* go
= m_caster
->GetMap()->GetGameObject(goGUID
);
909 AddGOTarget(go
, effIndex
);
912 void Spell::AddItemTarget(Item
* pitem
, uint32 effIndex
)
914 if( m_spellInfo
->Effect
[effIndex
] == 0 )
917 // Lookup target in already in list
918 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin(); ihit
!= m_UniqueItemInfo
.end(); ++ihit
)
920 if (pitem
== ihit
->item
) // Found in list
922 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask
927 // This is new target add data
929 ItemTargetInfo target
;
931 target
.effectMask
= 1 << effIndex
;
932 m_UniqueItemInfo
.push_back(target
);
935 void Spell::DoAllEffectOnTarget(TargetInfo
*target
)
937 if (target
->processed
) // Check target
939 target
->processed
= true; // Target checked in apply effects procedure
941 // Get mask of effects for target
942 uint32 mask
= target
->effectMask
;
944 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
948 // Get original caster (if exist) and calculate damage/healing from him data
949 Unit
*caster
= m_originalCaster
? m_originalCaster
: m_caster
;
951 // Skip if m_originalCaster not available
955 SpellMissInfo missInfo
= target
->missCondition
;
956 // Need init unitTarget by default unit (can changed in code on reflect)
957 // Or on missInfo!=SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem)
960 // Reset damage/healing counter
964 // Fill base trigger info
965 uint32 procAttacker
= m_procAttacker
;
966 uint32 procVictim
= m_procVictim
;
967 uint32 procEx
= PROC_EX_NONE
;
969 if (missInfo
==SPELL_MISS_NONE
) // In case spell hit target, do all effect on that target
970 DoSpellHitOnUnit(unit
, mask
);
971 else if (missInfo
== SPELL_MISS_REFLECT
) // In case spell reflect from target, do all effect on caster (if hit)
973 if (target
->reflectResult
== SPELL_MISS_NONE
) // If reflected spell hit caster -> do all effect on him
974 DoSpellHitOnUnit(m_caster
, mask
);
977 // All calculated do it!
978 // Do healing and triggers
981 bool crit
= caster
->isSpellCrit(unitTarget
, m_spellInfo
, m_spellSchoolMask
);
982 uint32 addhealth
= m_healing
;
985 procEx
|= PROC_EX_CRITICAL_HIT
;
986 addhealth
= caster
->SpellCriticalHealingBonus(m_spellInfo
, addhealth
, NULL
);
989 procEx
|= PROC_EX_NORMAL_HIT
;
991 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
992 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
993 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, addhealth
, m_attackType
, m_spellInfo
);
995 int32 gain
= caster
->DealHeal(unitTarget
, addhealth
, m_spellInfo
, crit
);
996 unitTarget
->getHostileRefManager().threatAssist(caster
, float(gain
) * 0.5f
, m_spellInfo
);
998 // Do damage and triggers
1001 // Fill base damage struct (unitTarget - is real spell target)
1002 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1004 // Add bonuses and fill damageInfo struct
1005 caster
->CalculateSpellDamage(&damageInfo
, m_damage
, m_spellInfo
, m_attackType
);
1006 caster
->DealDamageMods(damageInfo
.target
, damageInfo
.damage
, &damageInfo
.absorb
);
1008 // Send log damage message to client
1009 caster
->SendSpellNonMeleeDamageLog(&damageInfo
);
1011 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1012 procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1014 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1015 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1016 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, damageInfo
.damage
, m_attackType
, m_spellInfo
);
1018 // Haunt (NOTE: for avoid use additional field damage stored in dummy value (replace unused 100%)
1019 // apply before deal damage because aura can be removed at target kill
1020 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& m_spellInfo
->SpellIconID
== 3172 &&
1021 (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0004000000000000)))
1022 if(Aura
* dummy
= unitTarget
->GetDummyAura(m_spellInfo
->Id
))
1023 dummy
->GetModifier()->m_amount
= damageInfo
.damage
;
1025 caster
->DealSpellDamage(&damageInfo
, true);
1027 // Passive spell hits/misses or active spells only misses (only triggers)
1030 // Fill base damage struct (unitTarget - is real spell target)
1031 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1032 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1033 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1034 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1035 caster
->ProcDamageAndSpell(unit
, procAttacker
, procVictim
, procEx
, 0, m_attackType
, m_spellInfo
);
1038 // Call scripted function for AI if this spell is casted upon a creature
1039 if(unit
->GetTypeId()==TYPEID_UNIT
)
1041 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1042 // ignore pets or autorepeat/melee casts for speed (not exist quest for spells (hm... )
1043 if( !((Creature
*)unit
)->isPet() && !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1045 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1046 p
->CastedCreatureOrGO(unit
->GetEntry(), unit
->GetGUID(), m_spellInfo
->Id
);
1049 if(((Creature
*)unit
)->AI())
1050 ((Creature
*)unit
)->AI()->SpellHit(m_caster
,m_spellInfo
);
1053 // Call scripted function for AI if this spell is casted by a creature
1054 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)m_caster
)->AI())
1055 ((Creature
*)m_caster
)->AI()->SpellHitTarget(unit
, m_spellInfo
);
1058 void Spell::DoSpellHitOnUnit(Unit
*unit
, const uint32 effectMask
)
1060 if (!unit
|| !effectMask
)
1063 Unit
* realCaster
= m_originalCaster
? m_originalCaster
: m_caster
;
1065 // Recheck immune (only for delayed spells)
1066 if (m_spellInfo
->speed
&& (
1067 unit
->IsImmunedToDamage(GetSpellSchoolMask(m_spellInfo
)) ||
1068 unit
->IsImmunedToSpell(m_spellInfo
)))
1070 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_IMMUNE
);
1074 if (unit
->GetTypeId() == TYPEID_PLAYER
)
1076 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET
, m_spellInfo
->Id
);
1077 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2
, m_spellInfo
->Id
);
1080 if (realCaster
->GetTypeId() == TYPEID_PLAYER
)
1081 ((Player
*)realCaster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2
, m_spellInfo
->Id
, 0, unit
);
1083 if (realCaster
!= unit
)
1085 // Recheck UNIT_FLAG_NON_ATTACKABLE for delayed spells
1086 if (m_spellInfo
->speed
> 0.0f
&&
1087 unit
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
) &&
1088 unit
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
1090 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1094 if (!realCaster
->IsFriendlyTo(unit
))
1096 // for delayed spells ignore not visible explicit target
1097 if (m_spellInfo
->speed
> 0.0f
&& unit
== m_targets
.getUnitTarget() &&
1098 !unit
->isVisibleForOrDetect(m_caster
,m_caster
,false))
1100 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1104 // not break stealth by cast targeting
1105 if (!(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_BREAK_STEALTH
))
1106 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1108 // can cause back attack (if detected), stealth removed at Spell::cast if spell break it
1109 if (!(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) && !IsPositiveSpell(m_spellInfo
->Id
) &&
1110 m_caster
->isVisibleForOrDetect(unit
,unit
,false))
1112 // use speedup check to avoid re-remove after above lines
1113 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_BREAK_STEALTH
)
1114 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1116 // caster can be detected but have stealth aura
1117 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1119 if (!unit
->IsStandState() && !unit
->hasUnitState(UNIT_STAT_STUNNED
))
1120 unit
->SetStandState(UNIT_STAND_STATE_STAND
);
1122 if (!unit
->isInCombat() && unit
->GetTypeId() != TYPEID_PLAYER
&& ((Creature
*)unit
)->AI())
1123 ((Creature
*)unit
)->AI()->AttackedBy(realCaster
);
1125 unit
->AddThreat(realCaster
);
1126 unit
->SetInCombatWith(realCaster
);
1127 realCaster
->SetInCombatWith(unit
);
1129 if (Player
*attackedPlayer
= unit
->GetCharmerOrOwnerPlayerOrPlayerItself())
1130 realCaster
->SetContestedPvP(attackedPlayer
);
1135 // for delayed spells ignore negative spells (after duel end) for friendly targets
1136 if (m_spellInfo
->speed
> 0.0f
&& !IsPositiveSpell(m_spellInfo
->Id
))
1138 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1142 // assisting case, healing and resurrection
1143 if (unit
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
1144 realCaster
->SetContestedPvP();
1146 if (unit
->isInCombat() && !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
))
1148 realCaster
->SetInCombatState(unit
->GetCombatTimer() > 0);
1149 unit
->getHostileRefManager().threatAssist(realCaster
, 0.0f
, m_spellInfo
);
1154 // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
1155 m_diminishGroup
= GetDiminishingReturnsGroupForSpell(m_spellInfo
,m_triggeredByAuraSpell
);
1156 m_diminishLevel
= unit
->GetDiminishing(m_diminishGroup
);
1157 // Increase Diminishing on unit, current informations for actually casts will use values above
1158 if ((GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_PLAYER
&& unit
->GetTypeId() == TYPEID_PLAYER
) ||
1159 GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_ALL
)
1160 unit
->IncrDiminishing(m_diminishGroup
);
1162 // Apply additional spell effects to target
1163 CastPreCastSpells(unit
);
1165 for(uint32 effectNumber
= 0; effectNumber
< 3; ++effectNumber
)
1167 if (effectMask
& (1 << effectNumber
))
1169 HandleEffects(unit
, NULL
, NULL
, effectNumber
, m_damageMultipliers
[effectNumber
]);
1170 if ( m_applyMultiplierMask
& (1 << effectNumber
) )
1173 float multiplier
= m_spellInfo
->DmgMultiplier
[effectNumber
];
1174 // Apply multiplier mods
1175 if(Player
* modOwner
= realCaster
->GetSpellModOwner())
1176 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_EFFECT_PAST_FIRST
, multiplier
, this);
1177 m_damageMultipliers
[effectNumber
] *= multiplier
;
1183 void Spell::DoAllEffectOnTarget(GOTargetInfo
*target
)
1185 if (target
->processed
) // Check target
1187 target
->processed
= true; // Target checked in apply effects procedure
1189 uint32 effectMask
= target
->effectMask
;
1193 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
1197 for(uint32 effectNumber
= 0; effectNumber
< 3; ++effectNumber
)
1198 if (effectMask
& (1 << effectNumber
))
1199 HandleEffects(NULL
, NULL
, go
, effectNumber
);
1201 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1202 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
1203 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1205 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1206 p
->CastedCreatureOrGO(go
->GetEntry(), go
->GetGUID(), m_spellInfo
->Id
);
1210 void Spell::DoAllEffectOnTarget(ItemTargetInfo
*target
)
1212 uint32 effectMask
= target
->effectMask
;
1213 if(!target
->item
|| !effectMask
)
1216 for(uint32 effectNumber
= 0; effectNumber
< 3; ++effectNumber
)
1217 if (effectMask
& (1 << effectNumber
))
1218 HandleEffects(NULL
, target
->item
, NULL
, effectNumber
);
1221 bool Spell::IsAliveUnitPresentInTargetList()
1223 // Not need check return true
1224 if (m_needAliveTargetMask
== 0)
1227 uint8 needAliveTargetMask
= m_needAliveTargetMask
;
1229 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
1231 if( ihit
->missCondition
== SPELL_MISS_NONE
&& (needAliveTargetMask
& ihit
->effectMask
) )
1233 Unit
*unit
= m_caster
->GetGUID() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
1235 // either unit is alive and normal spell, or unit dead and deathonly-spell
1236 if (unit
&& (unit
->isAlive() != IsDeathOnlySpell(m_spellInfo
)))
1237 needAliveTargetMask
&= ~ihit
->effectMask
; // remove from need alive mask effect that have alive target
1241 // is all effects from m_needAliveTargetMask have alive targets
1242 return needAliveTargetMask
== 0;
1245 // Helper for Chain Healing
1246 // Spell target first
1247 // Raidmates then descending by injury suffered (MaxHealth - Health)
1248 // Other players/mobs then descending by injury suffered (MaxHealth - Health)
1249 struct ChainHealingOrder
: public std::binary_function
<const Unit
*, const Unit
*, bool>
1251 const Unit
* MainTarget
;
1252 ChainHealingOrder(Unit
const* Target
) : MainTarget(Target
) {};
1253 // functor for operator ">"
1254 bool operator()(Unit
const* _Left
, Unit
const* _Right
) const
1256 return (ChainHealingHash(_Left
) < ChainHealingHash(_Right
));
1258 int32
ChainHealingHash(Unit
const* Target
) const
1260 if (Target
== MainTarget
)
1262 else if (Target
->GetTypeId() == TYPEID_PLAYER
&& MainTarget
->GetTypeId() == TYPEID_PLAYER
&&
1263 ((Player
const*)Target
)->IsInSameRaidWith((Player
const*)MainTarget
))
1265 if (Target
->GetHealth() == Target
->GetMaxHealth())
1268 return 20000 - Target
->GetMaxHealth() + Target
->GetHealth();
1271 return 40000 - Target
->GetMaxHealth() + Target
->GetHealth();
1275 class ChainHealingFullHealth
: std::unary_function
<const Unit
*, bool>
1278 const Unit
* MainTarget
;
1279 ChainHealingFullHealth(const Unit
* Target
) : MainTarget(Target
) {};
1281 bool operator()(const Unit
* Target
)
1283 return (Target
!= MainTarget
&& Target
->GetHealth() == Target
->GetMaxHealth());
1287 // Helper for targets nearest to the spell target
1288 // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
1289 struct TargetDistanceOrder
: public std::binary_function
<const Unit
, const Unit
, bool>
1291 const Unit
* MainTarget
;
1292 TargetDistanceOrder(const Unit
* Target
) : MainTarget(Target
) {};
1293 // functor for operator ">"
1294 bool operator()(const Unit
* _Left
, const Unit
* _Right
) const
1296 return MainTarget
->GetDistanceOrder(_Left
,_Right
);
1300 void Spell::SetTargetMap(uint32 effIndex
, uint32 targetMode
, UnitList
& targetUnitMap
)
1303 if (m_spellInfo
->EffectRadiusIndex
[effIndex
])
1304 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[effIndex
]));
1306 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
));
1308 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[effIndex
];
1310 if(m_originalCaster
)
1312 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1314 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RADIUS
, radius
, this);
1315 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
1319 // Get spell max affected targets
1320 uint32 unMaxTargets
= m_spellInfo
->MaxAffectedTargets
;
1322 // custom target amount cases
1323 switch(m_spellInfo
->SpellFamilyName
)
1325 case SPELLFAMILY_GENERIC
:
1327 switch(m_spellInfo
->Id
)
1329 case 31347: // Doom TODO: exclude top threat target from target selection
1330 case 33711: // Murmur's Touch
1331 case 38794: // Murmur's Touch (h)
1334 case 28542: // Life Drain
1337 case 28796: // Poison Bolt Volley
1338 case 29213: // Curse of the Plaguebringer
1339 case 31298: // Sleep
1342 case 30843: // Enfeeble TODO: exclude top threat target from target selection
1343 case 42005: // Bloodboil TODO: need to be 5 targets(players) furthest away from caster
1344 case 55665: // Life Drain (h)
1347 case 54098: // Poison Bolt Volley (h)
1348 case 54835: // Curse of the Plaguebringer (h)
1354 case SPELLFAMILY_PALADIN
:
1355 if (m_spellInfo
->Id
== 20424) // Seal of Command (2 more target for single targeted spell)
1357 // overwrite EffectChainTarget for non single target spell
1358 if (Spell
* currSpell
= m_caster
->GetCurrentSpell(CURRENT_GENERIC_SPELL
))
1359 if (currSpell
->m_spellInfo
->MaxAffectedTargets
> 0 ||
1360 currSpell
->m_spellInfo
->EffectChainTarget
[0] > 0 ||
1361 currSpell
->m_spellInfo
->EffectChainTarget
[1] > 0 ||
1362 currSpell
->m_spellInfo
->EffectChainTarget
[2] > 0)
1363 EffectChainTarget
= 0; // no chain targets
1366 case SPELLFAMILY_DRUID
:
1368 if (m_spellInfo
->SpellFamilyFlags2
& 0x00000100)// Starfall
1376 Unit::AuraList
const& mod
= m_caster
->GetAurasByType(SPELL_AURA_MOD_MAX_AFFECTED_TARGETS
);
1377 for(Unit::AuraList::const_iterator m
= mod
.begin(); m
!= mod
.end(); ++m
)
1379 if (!(*m
)->isAffectedOnSpell(m_spellInfo
))
1381 unMaxTargets
+=(*m
)->GetModifier()->m_amount
;
1386 case TARGET_RANDOM_NEARBY_LOC
:
1387 radius
*= sqrt(rand_norm()); // Get a random point in circle. Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates.
1388 // no 'break' expected since we use code in case TARGET_RANDOM_CIRCUMFERENCE_POINT!!!
1389 case TARGET_RANDOM_CIRCUMFERENCE_POINT
:
1391 float angle
= 2.0 * M_PI
* rand_norm();
1392 float dest_x
, dest_y
, dest_z
;
1393 m_caster
->GetClosePoint(dest_x
, dest_y
, dest_z
, 0.0f
, radius
, angle
);
1394 m_targets
.setDestination(dest_x
, dest_y
, dest_z
);
1396 targetUnitMap
.push_back(m_caster
);
1399 case TARGET_RANDOM_NEARBY_DEST
:
1401 radius
*= sqrt(rand_norm()); // Get a random point in circle. Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates.
1402 float angle
= 2.0 * M_PI
* rand_norm();
1403 float dest_x
= m_targets
.m_destX
+ cos(angle
) * radius
;
1404 float dest_y
= m_targets
.m_destY
+ sin(angle
) * radius
;
1405 float dest_z
= m_caster
->GetPositionZ();
1406 m_caster
->UpdateGroundPositionZ(dest_x
, dest_y
, dest_z
);
1407 m_targets
.setDestination(dest_x
, dest_y
, dest_z
);
1411 // caster included here?
1412 FillAreaTargets(targetUnitMap
, dest_x
, dest_y
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1415 targetUnitMap
.push_back(m_caster
);
1419 case TARGET_TOTEM_EARTH
:
1420 case TARGET_TOTEM_WATER
:
1421 case TARGET_TOTEM_AIR
:
1422 case TARGET_TOTEM_FIRE
:
1425 case TARGET_AREAEFFECT_CUSTOM
:
1426 case TARGET_AREAEFFECT_CUSTOM_2
:
1427 targetUnitMap
.push_back(m_caster
);
1429 case TARGET_RANDOM_ENEMY_CHAIN_IN_AREA
:
1431 m_targets
.m_targetMask
= 0;
1432 unMaxTargets
= EffectChainTarget
;
1433 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1435 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1437 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1440 std::list
<Unit
*> tempTargetUnitMap
;
1443 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1444 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempTargetUnitMap
, u_check
);
1446 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1447 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1449 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1450 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
1451 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
1454 if(tempTargetUnitMap
.empty())
1457 tempTargetUnitMap
.sort(TargetDistanceOrder(m_caster
));
1459 //Now to get us a random target that's in the initial range of the spell
1461 std::list
<Unit
*>::iterator itr
= tempTargetUnitMap
.begin();
1462 while(itr
!= tempTargetUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
, radius
))
1468 itr
= tempTargetUnitMap
.begin();
1469 std::advance(itr
, rand()%t
);
1470 Unit
*pUnitTarget
= *itr
;
1471 targetUnitMap
.push_back(pUnitTarget
);
1473 tempTargetUnitMap
.erase(itr
);
1475 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1477 t
= unMaxTargets
- 1;
1478 Unit
*prev
= pUnitTarget
;
1479 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
1481 while(t
&& next
!= tempTargetUnitMap
.end() )
1483 if(!prev
->IsWithinDist(*next
,CHAIN_SPELL_JUMP_RADIUS
))
1486 if(!prev
->IsWithinLOSInMap(*next
))
1493 targetUnitMap
.push_back(prev
);
1494 tempTargetUnitMap
.erase(next
);
1495 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
1496 next
= tempTargetUnitMap
.begin();
1502 case TARGET_RANDOM_FRIEND_CHAIN_IN_AREA
:
1504 m_targets
.m_targetMask
= 0;
1505 unMaxTargets
= EffectChainTarget
;
1506 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1507 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1509 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1511 std::list
<Unit
*> tempTargetUnitMap
;
1513 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1514 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(m_caster
, tempTargetUnitMap
, u_check
);
1516 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1517 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1519 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1520 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
1521 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
1524 if(tempTargetUnitMap
.empty())
1527 tempTargetUnitMap
.sort(TargetDistanceOrder(m_caster
));
1529 //Now to get us a random target that's in the initial range of the spell
1531 std::list
<Unit
*>::iterator itr
= tempTargetUnitMap
.begin();
1532 while(itr
!= tempTargetUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
, radius
))
1538 itr
= tempTargetUnitMap
.begin();
1539 std::advance(itr
, rand()%t
);
1540 Unit
*pUnitTarget
= *itr
;
1541 targetUnitMap
.push_back(pUnitTarget
);
1543 tempTargetUnitMap
.erase(itr
);
1545 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1547 t
= unMaxTargets
- 1;
1548 Unit
*prev
= pUnitTarget
;
1549 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
1551 while(t
&& next
!= tempTargetUnitMap
.end())
1553 if(!prev
->IsWithinDist(*next
,CHAIN_SPELL_JUMP_RADIUS
))
1556 if(!prev
->IsWithinLOSInMap(*next
))
1562 targetUnitMap
.push_back(prev
);
1563 tempTargetUnitMap
.erase(next
);
1564 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
1565 next
= tempTargetUnitMap
.begin();
1572 Pet
* tmpUnit
= m_caster
->GetPet();
1573 if (!tmpUnit
) break;
1574 targetUnitMap
.push_back(tmpUnit
);
1577 case TARGET_CHAIN_DAMAGE
:
1579 if (EffectChainTarget
<= 1)
1581 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1583 m_targets
.setUnitTarget(pUnitTarget
);
1584 targetUnitMap
.push_back(pUnitTarget
);
1589 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1590 Unit
* originalCaster
= GetOriginalCaster();
1591 if(!pUnitTarget
|| !originalCaster
)
1594 unMaxTargets
= EffectChainTarget
;
1597 if(m_spellInfo
->DmgClass
==SPELL_DAMAGE_CLASS_MELEE
)
1598 max_range
= radius
; //
1600 //FIXME: This very like horrible hack and wrong for most spells
1601 max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1603 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1605 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1608 std::list
<Unit
*> tempTargetUnitMap
;
1610 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(pUnitTarget
, originalCaster
, max_range
, false);
1611 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempTargetUnitMap
, u_check
);
1612 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1613 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1614 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1616 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap(), *pUnitTarget
, max_range
);
1617 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap(), *pUnitTarget
, max_range
);
1619 if (tempTargetUnitMap
.empty())
1622 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1624 if (*tempTargetUnitMap
.begin() == pUnitTarget
)
1625 tempTargetUnitMap
.erase(tempTargetUnitMap
.begin());
1627 targetUnitMap
.push_back(pUnitTarget
);
1628 uint32 t
= unMaxTargets
- 1;
1629 Unit
*prev
= pUnitTarget
;
1630 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
1632 while (t
&& next
!= tempTargetUnitMap
.end())
1634 if (!prev
->IsWithinDist (*next
,CHAIN_SPELL_JUMP_RADIUS
))
1636 if (!prev
->IsWithinLOSInMap (*next
))
1642 targetUnitMap
.push_back(prev
);
1643 tempTargetUnitMap
.erase(next
);
1644 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
1645 next
= tempTargetUnitMap
.begin();
1651 case TARGET_ALL_ENEMY_IN_AREA
:
1652 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1654 case TARGET_AREAEFFECT_INSTANT
:
1656 SpellTargets targetB
= SPELL_TARGETS_AOE_DAMAGE
;
1657 // Select friendly targets for positive effect
1658 if (IsPositiveEffect(m_spellInfo
->Id
, effIndex
))
1659 targetB
= SPELL_TARGETS_FRIENDLY
;
1661 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_DEST_CENTER
, targetB
);
1664 targetUnitMap
.remove(m_caster
);
1667 case TARGET_ALL_ENEMY_IN_AREA_INSTANT
:
1669 // targets the ground, not the units in the area
1670 switch(m_spellInfo
->Effect
[effIndex
])
1672 case SPELL_EFFECT_PERSISTENT_AREA_AURA
:
1674 case SPELL_EFFECT_SUMMON
:
1675 targetUnitMap
.push_back(m_caster
);
1678 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1683 case TARGET_DUELVSPLAYER_COORDINATES
:
1685 if(Unit
* currentTarget
= m_targets
.getUnitTarget())
1687 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1688 targetUnitMap
.push_back(currentTarget
);
1692 case TARGET_ALL_PARTY_AROUND_CASTER
:
1693 case TARGET_ALL_PARTY_AROUND_CASTER_2
:
1694 case TARGET_ALL_PARTY
:
1695 FillRaidOrPartyTargets(targetUnitMap
, m_caster
, m_caster
, radius
, false, true, true);
1697 case TARGET_ALL_RAID_AROUND_CASTER
:
1699 if(m_spellInfo
->Id
== 57669) // Replenishment (special target selection)
1700 FillRaidOrPartyManaPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 10, true, false, true);
1701 else if (m_spellInfo
->Id
==52759) // Ancestral Awakening (special target selection)
1702 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 1, true, false, true);
1704 FillRaidOrPartyTargets(targetUnitMap
, m_caster
, m_caster
, radius
, true, true, true);
1707 case TARGET_SINGLE_FRIEND
:
1708 case TARGET_SINGLE_FRIEND_2
:
1709 if(m_targets
.getUnitTarget())
1710 targetUnitMap
.push_back(m_targets
.getUnitTarget());
1712 case TARGET_NONCOMBAT_PET
:
1713 if(Unit
* target
= m_targets
.getUnitTarget())
1714 if( target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet() && ((Pet
*)target
)->getPetType() == MINI_PET
)
1715 targetUnitMap
.push_back(target
);
1717 case TARGET_CASTER_COORDINATES
:
1719 // Check original caster is GO - set its coordinates as dst cast
1720 WorldObject
*caster
= NULL
;
1721 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
1722 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
1725 // Set dest for targets
1726 m_targets
.setDestination(caster
->GetPositionX(), caster
->GetPositionY(), caster
->GetPositionZ());
1729 case TARGET_ALL_HOSTILE_UNITS_AROUND_CASTER
:
1730 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_SELF_CENTER
, SPELL_TARGETS_HOSTILE
);
1732 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER
:
1733 switch (m_spellInfo
->Id
)
1735 case 64844: // Divine Hymn
1736 // target amount stored in parent spell dummy effect but hard to access
1737 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 3, true, false, false);
1739 case 64904: // Hymn of Hope
1740 // target amount stored in parent spell dummy effect but hard to access
1741 FillRaidOrPartyManaPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 3, true, false, false);
1744 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
1748 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA
:
1749 // Death Pact (in fact selection by player selection)
1750 if (m_spellInfo
->Id
== 48743)
1752 // checked in Spell::CheckCast
1753 if (m_caster
->GetTypeId()==TYPEID_PLAYER
)
1754 if (Unit
* target
= m_caster
->GetMap()->GetPet(((Player
*)m_caster
)->GetSelection()))
1755 targetUnitMap
.push_back(target
);
1757 // Circle of Healing
1758 else if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_PRIEST
&& m_spellInfo
->SpellVisual
[0] == 8253)
1760 Unit
* target
= m_targets
.getUnitTarget();
1765 // Glyph of Circle of Healing
1766 if(Aura
const* glyph
= m_caster
->GetDummyAura(55675))
1767 count
+= glyph
->GetModifier()->m_amount
;
1769 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, target
, radius
, count
, true, false, true);
1772 else if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_DRUID
&& m_spellInfo
->SpellIconID
== 2864)
1774 Unit
* target
= m_targets
.getUnitTarget();
1777 uint32 count
= CalculateDamage(2,m_caster
); // stored in dummy effect, affected by mods
1779 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, target
, radius
, count
, true, false, true);
1782 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_FRIENDLY
);
1784 // 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..)
1785 case TARGET_SINGLE_PARTY
:
1787 Unit
*target
= m_targets
.getUnitTarget();
1788 // Thoses spells apparently can't be casted on the caster.
1789 if( target
&& target
!= m_caster
)
1791 // Can only be casted on group's members or its pets
1792 Group
*pGroup
= NULL
;
1794 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1795 Unit
*targetOwner
= target
->GetCharmerOrOwner();
1798 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1800 if( target
== owner
)
1802 targetUnitMap
.push_back(target
);
1805 pGroup
= ((Player
*)owner
)->GetGroup();
1808 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1810 if( targetOwner
== m_caster
&& target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet())
1812 targetUnitMap
.push_back(target
);
1815 pGroup
= ((Player
*)m_caster
)->GetGroup();
1820 // Our target can also be a player's pet who's grouped with us or our pet. But can't be controlled player
1823 if( targetOwner
->GetTypeId() == TYPEID_PLAYER
&&
1824 target
->GetTypeId() == TYPEID_UNIT
&& (((Creature
*)target
)->isPet()) &&
1825 target
->GetOwnerGUID() == targetOwner
->GetGUID() &&
1826 pGroup
->IsMember(((Player
*)targetOwner
)->GetGUID()))
1828 targetUnitMap
.push_back(target
);
1831 // 1Our target can be a player who is on our group
1832 else if (target
->GetTypeId() == TYPEID_PLAYER
&& pGroup
->IsMember(((Player
*)target
)->GetGUID()))
1834 targetUnitMap
.push_back(target
);
1840 case TARGET_GAMEOBJECT
:
1841 if(m_targets
.getGOTarget())
1842 AddGOTarget(m_targets
.getGOTarget(), effIndex
);
1844 case TARGET_IN_FRONT_OF_CASTER
:
1846 bool inFront
= m_spellInfo
->SpellVisual
[0] != 3879;
1847 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, inFront
? PUSH_IN_FRONT
: PUSH_IN_BACK
, SPELL_TARGETS_AOE_DAMAGE
);
1850 case TARGET_LARGE_FRONTAL_CONE
:
1851 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_90
, SPELL_TARGETS_AOE_DAMAGE
);
1853 case TARGET_NARROW_FRONTAL_CONE
:
1854 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_15
, SPELL_TARGETS_AOE_DAMAGE
);
1856 case TARGET_IN_FRONT_OF_CASTER_30
:
1857 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_30
, SPELL_TARGETS_AOE_DAMAGE
);
1859 case TARGET_DUELVSPLAYER
:
1861 Unit
*target
= m_targets
.getUnitTarget();
1864 if(m_caster
->IsFriendlyTo(target
))
1866 targetUnitMap
.push_back(target
);
1870 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1872 m_targets
.setUnitTarget(pUnitTarget
);
1873 targetUnitMap
.push_back(pUnitTarget
);
1879 case TARGET_GAMEOBJECT_ITEM
:
1880 if(m_targets
.getGOTargetGUID())
1881 AddGOTarget(m_targets
.getGOTarget(), effIndex
);
1882 else if(m_targets
.getItemTarget())
1883 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
1886 if(Unit
* owner
= m_caster
->GetCharmerOrOwner())
1887 targetUnitMap
.push_back(owner
);
1889 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED
:
1890 // targets the ground, not the units in the area
1891 if (m_spellInfo
->Effect
[effIndex
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1892 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1895 if(m_spellInfo
->Effect
[effIndex
] != SPELL_EFFECT_DUEL
)
1896 targetUnitMap
.push_back(m_caster
);
1898 case TARGET_SINGLE_ENEMY
:
1900 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1902 m_targets
.setUnitTarget(pUnitTarget
);
1903 targetUnitMap
.push_back(pUnitTarget
);
1907 case TARGET_AREAEFFECT_PARTY
:
1909 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1910 Player
*pTarget
= NULL
;
1914 targetUnitMap
.push_back(m_caster
);
1915 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1916 pTarget
= (Player
*)owner
;
1918 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1920 if(Unit
* target
= m_targets
.getUnitTarget())
1922 if( target
->GetTypeId() != TYPEID_PLAYER
)
1924 if(((Creature
*)target
)->isPet())
1926 Unit
*targetOwner
= target
->GetOwner();
1927 if(targetOwner
->GetTypeId() == TYPEID_PLAYER
)
1928 pTarget
= (Player
*)targetOwner
;
1932 pTarget
= (Player
*)target
;
1936 Group
* pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1940 uint8 subgroup
= pTarget
->GetSubGroup();
1942 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1944 Player
* Target
= itr
->getSource();
1946 // IsHostileTo check duel and controlled by enemy
1947 if(Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
))
1949 if( pTarget
->IsWithinDistInMap(Target
, radius
) )
1950 targetUnitMap
.push_back(Target
);
1952 if(Pet
* pet
= Target
->GetPet())
1953 if( pTarget
->IsWithinDistInMap(pet
, radius
) )
1954 targetUnitMap
.push_back(pet
);
1960 if(m_caster
->IsWithinDistInMap(owner
, radius
))
1961 targetUnitMap
.push_back(owner
);
1965 targetUnitMap
.push_back(pTarget
);
1967 if(Pet
* pet
= pTarget
->GetPet())
1968 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1969 targetUnitMap
.push_back(pet
);
1975 if(m_targets
.getUnitTarget())
1976 targetUnitMap
.push_back(m_targets
.getUnitTarget());
1977 if(m_targets
.getItemTarget())
1978 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
1981 case TARGET_SELF_FISHING
:
1982 targetUnitMap
.push_back(m_caster
);
1984 case TARGET_CHAIN_HEAL
:
1986 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1990 if (EffectChainTarget
<= 1)
1991 targetUnitMap
.push_back(pUnitTarget
);
1994 unMaxTargets
= EffectChainTarget
;
1995 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1997 UnitList tempTargetUnitMap
;
1999 FillAreaTargets(tempTargetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), max_range
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
2001 if (m_caster
!= pUnitTarget
&& std::find(tempTargetUnitMap
.begin(), tempTargetUnitMap
.end(), m_caster
) == tempTargetUnitMap
.end())
2002 tempTargetUnitMap
.push_front(m_caster
);
2004 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
2006 if (tempTargetUnitMap
.empty())
2009 if (*tempTargetUnitMap
.begin() == pUnitTarget
)
2010 tempTargetUnitMap
.erase(tempTargetUnitMap
.begin());
2012 targetUnitMap
.push_back(pUnitTarget
);
2013 uint32 t
= unMaxTargets
- 1;
2014 Unit
*prev
= pUnitTarget
;
2015 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
2017 while(t
&& next
!= tempTargetUnitMap
.end())
2019 if(!prev
->IsWithinDist(*next
, CHAIN_SPELL_JUMP_RADIUS
))
2022 if(!prev
->IsWithinLOSInMap(*next
))
2028 if((*next
)->GetHealth() == (*next
)->GetMaxHealth())
2030 next
= tempTargetUnitMap
.erase(next
);
2035 targetUnitMap
.push_back(prev
);
2036 tempTargetUnitMap
.erase(next
);
2037 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
2038 next
= tempTargetUnitMap
.begin();
2045 case TARGET_CURRENT_ENEMY_COORDINATES
:
2047 Unit
* currentTarget
= m_targets
.getUnitTarget();
2050 targetUnitMap
.push_back(currentTarget
);
2051 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
2052 if(m_spellInfo
->EffectImplicitTargetB
[effIndex
]==TARGET_ALL_ENEMY_IN_AREA_INSTANT
)
2053 FillAreaTargets(targetUnitMap
, currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), radius
, PUSH_TARGET_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
2057 case TARGET_AREAEFFECT_PARTY_AND_CLASS
:
2059 Player
* targetPlayer
= m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
2060 ? (Player
*)m_targets
.getUnitTarget() : NULL
;
2062 Group
* pGroup
= targetPlayer
? targetPlayer
->GetGroup() : NULL
;
2065 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2067 Player
* Target
= itr
->getSource();
2069 // IsHostileTo check duel and controlled by enemy
2070 if( Target
&& targetPlayer
->IsWithinDistInMap(Target
, radius
) &&
2071 targetPlayer
->getClass() == Target
->getClass() &&
2072 !m_caster
->IsHostileTo(Target
) )
2074 targetUnitMap
.push_back(Target
);
2078 else if(m_targets
.getUnitTarget())
2079 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2082 case TARGET_TABLE_X_Y_Z_COORDINATES
:
2084 SpellTargetPosition
const* st
= sSpellMgr
.GetSpellTargetPosition(m_spellInfo
->Id
);
2087 // teleportspells are handled in another way
2088 if (m_spellInfo
->Effect
[effIndex
] == SPELL_EFFECT_TELEPORT_UNITS
)
2090 if (st
->target_mapId
== m_caster
->GetMapId())
2091 m_targets
.setDestination(st
->target_X
, st
->target_Y
, st
->target_Z
);
2093 sLog
.outError( "SPELL: wrong map (%u instead %u) target coordinates for spell ID %u", st
->target_mapId
, m_caster
->GetMapId(), m_spellInfo
->Id
);
2096 sLog
.outError( "SPELL: unknown target coordinates for spell ID %u", m_spellInfo
->Id
);
2099 case TARGET_INFRONT_OF_VICTIM
:
2100 case TARGET_BEHIND_VICTIM
:
2101 case TARGET_RIGHT_FROM_VICTIM
:
2102 case TARGET_LEFT_FROM_VICTIM
:
2104 Unit
*pTarget
= NULL
;
2106 // explicit cast data from client or server-side cast
2107 // some spell at client send caster
2108 if(m_targets
.getUnitTarget() && m_targets
.getUnitTarget()!=m_caster
)
2109 pTarget
= m_targets
.getUnitTarget();
2110 else if(m_caster
->getVictim())
2111 pTarget
= m_caster
->getVictim();
2112 else if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
2113 pTarget
= ObjectAccessor::GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection());
2118 float dist
= (radius
&& targetMode
!= TARGET_BEHIND_VICTIM
) ? radius
: CONTACT_DISTANCE
;
2122 case TARGET_INFRONT_OF_VICTIM
: break;
2123 case TARGET_BEHIND_VICTIM
: angle
= M_PI
; break;
2124 case TARGET_RIGHT_FROM_VICTIM
: angle
= -M_PI
/2; break;
2125 case TARGET_LEFT_FROM_VICTIM
: angle
= M_PI
/2; break;
2128 float _target_x
, _target_y
, _target_z
;
2129 pTarget
->GetClosePoint(_target_x
, _target_y
, _target_z
, pTarget
->GetObjectSize(), dist
, angle
);
2130 if(pTarget
->IsWithinLOS(_target_x
, _target_y
, _target_z
))
2132 targetUnitMap
.push_back(m_caster
);
2133 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2138 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
2139 // if parent spell create dynamic object extract area from it
2140 if(DynamicObject
* dynObj
= m_caster
->GetDynObject(m_triggeredByAuraSpell
? m_triggeredByAuraSpell
->Id
: m_spellInfo
->Id
))
2141 m_targets
.setDestination(dynObj
->GetPositionX(), dynObj
->GetPositionY(), dynObj
->GetPositionZ());
2144 case TARGET_DYNAMIC_OBJECT_FRONT
:
2145 case TARGET_DYNAMIC_OBJECT_BEHIND
:
2146 case TARGET_DYNAMIC_OBJECT_LEFT_SIDE
:
2147 case TARGET_DYNAMIC_OBJECT_RIGHT_SIDE
:
2149 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2151 float angle
= m_caster
->GetOrientation();
2154 case TARGET_DYNAMIC_OBJECT_FRONT
: break;
2155 case TARGET_DYNAMIC_OBJECT_BEHIND
: angle
+= M_PI
; break;
2156 case TARGET_DYNAMIC_OBJECT_LEFT_SIDE
: angle
+= M_PI
/2; break;
2157 case TARGET_DYNAMIC_OBJECT_RIGHT_SIDE
: angle
-= M_PI
/2; break;
2161 m_caster
->GetNearPoint2D(x
,y
,radius
,angle
);
2162 m_targets
.setDestination(x
,y
,m_caster
->GetPositionZ());
2165 targetUnitMap
.push_back(m_caster
);
2168 case TARGET_POINT_AT_NORTH
:
2169 case TARGET_POINT_AT_SOUTH
:
2170 case TARGET_POINT_AT_EAST
:
2171 case TARGET_POINT_AT_WEST
:
2172 case TARGET_POINT_AT_NE
:
2173 case TARGET_POINT_AT_NW
:
2174 case TARGET_POINT_AT_SE
:
2175 case TARGET_POINT_AT_SW
:
2178 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2180 Unit
* currentTarget
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
2181 float angle
= currentTarget
!= m_caster
? currentTarget
->GetAngle(m_caster
) : m_caster
->GetOrientation();
2185 case TARGET_POINT_AT_NORTH
: break;
2186 case TARGET_POINT_AT_SOUTH
: angle
+= M_PI
; break;
2187 case TARGET_POINT_AT_EAST
: angle
-= M_PI
/2; break;
2188 case TARGET_POINT_AT_WEST
: angle
+= M_PI
/2; break;
2189 case TARGET_POINT_AT_NE
: angle
-= M_PI
/4; break;
2190 case TARGET_POINT_AT_NW
: angle
+= M_PI
/4; break;
2191 case TARGET_POINT_AT_SE
: angle
-= 3*M_PI
/4; break;
2192 case TARGET_POINT_AT_SW
: angle
+= 3*M_PI
/4; break;
2196 currentTarget
->GetNearPoint2D(x
,y
,radius
,angle
);
2197 m_targets
.setDestination(x
,y
,currentTarget
->GetPositionZ());
2201 case TARGET_DIRECTLY_FORWARD
:
2203 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2205 SpellRangeEntry
const* rEntry
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
2206 float minRange
= GetSpellMinRange(rEntry
);
2207 float maxRange
= GetSpellMaxRange(rEntry
);
2208 float dist
= minRange
+ rand_norm()*(maxRange
-minRange
);
2210 float _target_x
, _target_y
, _target_z
;
2211 m_caster
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), dist
);
2212 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2215 targetUnitMap
.push_back(m_caster
);
2218 case TARGET_EFFECT_SELECT
:
2220 // add here custom effects that need default target.
2221 // FOR EVERY TARGET TYPE THERE IS A DIFFERENT FILL!!
2222 switch(m_spellInfo
->Effect
[effIndex
])
2224 case SPELL_EFFECT_DUMMY
:
2226 switch(m_spellInfo
->Id
)
2228 case 20577: // Cannibalize
2230 WorldObject
* result
= FindCorpseUsing
<MaNGOS::CannibalizeObjectCheck
> ();
2234 switch(result
->GetTypeId())
2238 targetUnitMap
.push_back((Unit
*)result
);
2241 m_targets
.setCorpseTarget((Corpse
*)result
);
2242 if (Player
* owner
= ObjectAccessor::FindPlayer(((Corpse
*)result
)->GetOwnerGUID()))
2243 targetUnitMap
.push_back(owner
);
2249 // clear cooldown at fail
2250 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2251 ((Player
*)m_caster
)->RemoveSpellCooldown(m_spellInfo
->Id
, true);
2252 SendCastResult(SPELL_FAILED_NO_EDIBLE_CORPSES
);
2258 if (m_targets
.getUnitTarget())
2259 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2264 case SPELL_EFFECT_RESURRECT
:
2265 case SPELL_EFFECT_PARRY
:
2266 case SPELL_EFFECT_BLOCK
:
2267 case SPELL_EFFECT_CREATE_ITEM
:
2268 case SPELL_EFFECT_TRIGGER_SPELL
:
2269 case SPELL_EFFECT_TRIGGER_MISSILE
:
2270 case SPELL_EFFECT_LEARN_SPELL
:
2271 case SPELL_EFFECT_SKILL_STEP
:
2272 case SPELL_EFFECT_PROFICIENCY
:
2273 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
2274 case SPELL_EFFECT_SELF_RESURRECT
:
2275 case SPELL_EFFECT_REPUTATION
:
2276 case SPELL_EFFECT_SEND_TAXI
:
2277 if (m_targets
.getUnitTarget())
2278 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2279 // Triggered spells have additional spell targets - cast them even if no explicit unit target is given (required for spell 50516 for example)
2280 else if (m_spellInfo
->Effect
[effIndex
] == SPELL_EFFECT_TRIGGER_SPELL
)
2281 targetUnitMap
.push_back(m_caster
);
2283 case SPELL_EFFECT_SUMMON_PLAYER
:
2284 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetSelection())
2286 Player
* target
= sObjectMgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
2288 targetUnitMap
.push_back(target
);
2291 case SPELL_EFFECT_RESURRECT_NEW
:
2292 if (m_targets
.getUnitTarget())
2293 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2294 if (m_targets
.getCorpseTargetGUID())
2296 Corpse
*corpse
= m_caster
->GetMap()->GetCorpse(m_targets
.getCorpseTargetGUID());
2299 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
2301 targetUnitMap
.push_back(owner
);
2305 case SPELL_EFFECT_SUMMON
:
2306 targetUnitMap
.push_back(m_caster
);
2308 case SPELL_EFFECT_SUMMON_CHANGE_ITEM
:
2309 case SPELL_EFFECT_TRANS_DOOR
:
2310 case SPELL_EFFECT_ADD_FARSIGHT
:
2311 case SPELL_EFFECT_APPLY_GLYPH
:
2312 case SPELL_EFFECT_STUCK
:
2313 case SPELL_EFFECT_FEED_PET
:
2314 case SPELL_EFFECT_DESTROY_ALL_TOTEMS
:
2315 case SPELL_EFFECT_SKILL
:
2316 targetUnitMap
.push_back(m_caster
);
2318 case SPELL_EFFECT_LEARN_PET_SPELL
:
2319 if (Pet
* pet
= m_caster
->GetPet())
2320 targetUnitMap
.push_back(pet
);
2322 case SPELL_EFFECT_ENCHANT_ITEM
:
2323 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
2324 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
2325 case SPELL_EFFECT_DISENCHANT
:
2326 case SPELL_EFFECT_PROSPECTING
:
2327 case SPELL_EFFECT_MILLING
:
2328 if (m_targets
.getItemTarget())
2329 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
2331 case SPELL_EFFECT_APPLY_AURA
:
2332 switch(m_spellInfo
->EffectApplyAuraName
[effIndex
])
2334 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)
2335 case SPELL_AURA_ADD_PCT_MODIFIER
:
2336 targetUnitMap
.push_back(m_caster
);
2338 default: // apply to target in other case
2339 if (m_targets
.getUnitTarget())
2340 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2344 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY
:
2346 if(m_spellInfo
->Attributes
== 0x9050000 || m_spellInfo
->Attributes
== 0x10000)
2347 SetTargetMap(effIndex
, TARGET_AREAEFFECT_PARTY
, targetUnitMap
);
2349 case SPELL_EFFECT_SKIN_PLAYER_CORPSE
:
2350 if (m_targets
.getUnitTarget())
2351 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2352 else if (m_targets
.getCorpseTargetGUID())
2354 if (Corpse
*corpse
= m_caster
->GetMap()->GetCorpse(m_targets
.getCorpseTargetGUID()))
2355 if (Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID()))
2356 targetUnitMap
.push_back(owner
);
2366 //sLog.outError( "SPELL: Unknown implicit target (%u) for spell ID %u", targetMode, m_spellInfo->Id );
2370 if (unMaxTargets
&& targetUnitMap
.size() > unMaxTargets
)
2372 // make sure one unit is always removed per iteration
2373 uint32 removed_utarget
= 0;
2374 for (UnitList::iterator itr
= targetUnitMap
.begin(), next
; itr
!= targetUnitMap
.end(); itr
= next
)
2378 if (!*itr
) continue;
2379 if ((*itr
) == m_targets
.getUnitTarget())
2381 targetUnitMap
.erase(itr
);
2382 removed_utarget
= 1;
2386 // remove random units from the map
2387 while (targetUnitMap
.size() > unMaxTargets
- removed_utarget
)
2389 uint32 poz
= urand(0, targetUnitMap
.size()-1);
2390 for (UnitList::iterator itr
= targetUnitMap
.begin(); itr
!= targetUnitMap
.end(); ++itr
, --poz
)
2392 if (!*itr
) continue;
2396 targetUnitMap
.erase(itr
);
2401 // the player's target will always be added to the map
2402 if (removed_utarget
&& m_targets
.getUnitTarget())
2403 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2407 void Spell::prepare(SpellCastTargets
const* targets
, Aura
* triggeredByAura
)
2409 m_targets
= *targets
;
2411 m_spellState
= SPELL_STATE_PREPARING
;
2413 m_castPositionX
= m_caster
->GetPositionX();
2414 m_castPositionY
= m_caster
->GetPositionY();
2415 m_castPositionZ
= m_caster
->GetPositionZ();
2416 m_castOrientation
= m_caster
->GetOrientation();
2419 m_triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
2421 // create and add update event for this spell
2422 SpellEvent
* Event
= new SpellEvent(this);
2423 m_caster
->m_Events
.AddEvent(Event
, m_caster
->m_Events
.CalculateTime(1));
2425 //Prevent casting at cast another spell (ServerSide check)
2426 if(m_caster
->IsNonMeleeSpellCasted(false, true, true) && m_cast_count
)
2428 SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS
);
2434 m_powerCost
= CalculatePowerCost();
2436 SpellCastResult result
= CheckCast(true);
2437 if(result
!= SPELL_CAST_OK
&& !IsAutoRepeat()) //always cast autorepeat dummy for triggering
2441 SendChannelUpdate(0);
2442 triggeredByAura
->SetAuraDuration(0);
2444 SendCastResult(result
);
2449 // Prepare data for triggers
2450 prepareDataForTriggerSystem();
2452 // calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
2453 m_casttime
= GetSpellCastTime(m_spellInfo
, this);
2455 // set timer base at cast time
2458 // stealth must be removed at cast starting (at show channel bar)
2459 // skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
2460 if ( !m_IsTriggeredSpell
&& isSpellBreakStealth(m_spellInfo
) )
2462 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
2463 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
2466 // add non-triggered (with cast time and without)
2467 if (!m_IsTriggeredSpell
)
2469 // add to cast type slot
2470 m_caster
->SetCurrentCastedSpell( this );
2472 // will show cast bar
2475 // execute triggered without cast time explicitly in call point
2476 else if(m_timer
== 0)
2478 // else triggered with cast time will execute execute at next tick or later
2479 // without adding to cast type slot
2480 // will not show cast bar but will show effects at casting time etc
2483 void Spell::cancel()
2485 if(m_spellState
== SPELL_STATE_FINISHED
)
2488 m_autoRepeat
= false;
2489 switch (m_spellState
)
2491 case SPELL_STATE_PREPARING
:
2492 case SPELL_STATE_DELAYED
:
2495 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2498 case SPELL_STATE_CASTING
:
2500 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2502 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2504 Unit
* unit
= m_caster
->GetGUID()==(*ihit
).targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2505 if( unit
&& unit
->isAlive() )
2506 unit
->RemoveAurasByCasterSpell(m_spellInfo
->Id
,m_caster
->GetGUID());
2510 SendChannelUpdate(0);
2512 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2521 m_caster
->RemoveDynObject(m_spellInfo
->Id
);
2522 m_caster
->RemoveGameObject(m_spellInfo
->Id
,true);
2525 void Spell::cast(bool skipCheck
)
2527 SetExecutedCurrently(true);
2529 // update pointers base at GUIDs to prevent access to non-existed already object
2532 // cancel at lost main target unit
2533 if(!m_targets
.getUnitTarget() && m_targets
.getUnitTargetGUID() && m_targets
.getUnitTargetGUID() != m_caster
->GetGUID())
2536 SetExecutedCurrently(false);
2540 if(m_caster
->GetTypeId() != TYPEID_PLAYER
&& m_targets
.getUnitTarget() && m_targets
.getUnitTarget() != m_caster
)
2541 m_caster
->SetInFront(m_targets
.getUnitTarget());
2543 SpellCastResult castResult
= CheckPower();
2544 if(castResult
!= SPELL_CAST_OK
)
2546 SendCastResult(castResult
);
2548 SetExecutedCurrently(false);
2552 // triggered cast called from Spell::prepare where it was already checked
2555 castResult
= CheckCast(false);
2556 if(castResult
!= SPELL_CAST_OK
)
2558 SendCastResult(castResult
);
2560 SetExecutedCurrently(false);
2565 // different triggred (for caster) and precast (casted before apply effect to target) cases
2566 switch(m_spellInfo
->SpellFamilyName
)
2568 case SPELLFAMILY_GENERIC
:
2570 if (m_spellInfo
->Mechanic
== MECHANIC_BANDAGE
) // Bandages
2571 AddPrecastSpell(11196); // Recently Bandaged
2572 else if(m_spellInfo
->SpellIconID
== 1662 && m_spellInfo
->AttributesEx
& 0x20)
2573 // Blood Fury (Racial)
2574 AddPrecastSpell(23230); // Blood Fury - Healing Reduction
2575 else if(m_spellInfo
->Id
== 20594) // Stoneskin
2576 AddTriggeredSpell(65116); // Stoneskin - armor 10% for 8 sec
2579 case SPELLFAMILY_MAGE
:
2582 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000008000000000))
2583 AddPrecastSpell(41425); // Hypothermia
2586 case SPELLFAMILY_PRIEST
:
2588 // Power Word: Shield
2589 if (m_spellInfo
->Mechanic
== MECHANIC_SHIELD
&&
2590 (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000001)))
2591 AddPrecastSpell(6788); // Weakened Soul
2592 // Prayer of Mending (jump animation), we need formal caster instead original for correct animation
2593 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000002000000000))
2594 AddTriggeredSpell(41637);
2596 switch(m_spellInfo
->Id
)
2598 case 15237: AddTriggeredSpell(23455); break;// Holy Nova, rank 1
2599 case 15430: AddTriggeredSpell(23458); break;// Holy Nova, rank 2
2600 case 15431: AddTriggeredSpell(23459); break;// Holy Nova, rank 3
2601 case 27799: AddTriggeredSpell(27803); break;// Holy Nova, rank 4
2602 case 27800: AddTriggeredSpell(27804); break;// Holy Nova, rank 5
2603 case 27801: AddTriggeredSpell(27805); break;// Holy Nova, rank 6
2604 case 25331: AddTriggeredSpell(25329); break;// Holy Nova, rank 7
2605 case 48077: AddTriggeredSpell(48075); break;// Holy Nova, rank 8
2606 case 48078: AddTriggeredSpell(48076); break;// Holy Nova, rank 9
2611 case SPELLFAMILY_DRUID
:
2613 // Faerie Fire (Feral)
2614 if (m_spellInfo
->Id
== 16857 && m_caster
->m_form
!= FORM_CAT
)
2615 AddTriggeredSpell(60089);
2618 case SPELLFAMILY_ROGUE
:
2619 // Fan of Knives (main hand)
2620 if (m_spellInfo
->Id
== 51723 && m_caster
->GetTypeId() == TYPEID_PLAYER
&&
2621 ((Player
*)m_caster
)->haveOffhandWeapon())
2623 AddTriggeredSpell(52874); // Fan of Knives (offhand)
2626 case SPELLFAMILY_PALADIN
:
2628 // Hand of Reckoning
2629 if (m_spellInfo
->Id
== 62124)
2631 if (m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->getVictim() != m_caster
)
2632 AddPrecastSpell(67485); // Hand of Rekoning (no typos in name ;) )
2634 // Divine Shield, Divine Protection or Hand of Protection
2635 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000400080))
2637 AddPrecastSpell(25771); // Forbearance
2638 AddPrecastSpell(61987); // Avenging Wrath Marker
2640 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x200000000000))
2641 AddPrecastSpell(61987); // Avenging Wrath Marker
2644 case SPELLFAMILY_SHAMAN
:
2647 if (m_spellInfo
->Id
== 2825)
2648 AddPrecastSpell(57724); // Sated
2650 else if (m_spellInfo
->Id
== 32182)
2651 AddPrecastSpell(57723); // Exhaustion
2658 // traded items have trade slot instead of guid in m_itemTargetGUID
2659 // set to real guid to be sent later to the client
2660 m_targets
.updateTradeSlotItem();
2662 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2664 if (!m_IsTriggeredSpell
&& m_CastItem
)
2665 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM
, m_CastItem
->GetEntry());
2667 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL
, m_spellInfo
->Id
);
2672 if(m_spellState
== SPELL_STATE_FINISHED
) // stop cast if spell marked as finish somewhere in FillTargetMap
2674 SetExecutedCurrently(false);
2679 SendSpellCooldown();
2682 TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
2684 SendCastResult(castResult
);
2685 SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2687 // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2688 if (m_spellInfo
->speed
> 0.0f
)
2691 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2692 // in case delayed spell remove item at cast delay start
2695 // Okay, maps created, now prepare flags
2696 m_immediateHandled
= false;
2697 m_spellState
= SPELL_STATE_DELAYED
;
2702 // Immediate spell, no big deal
2706 SetExecutedCurrently(false);
2709 void Spell::handle_immediate()
2711 // start channeling if applicable
2712 if(IsChanneledSpell(m_spellInfo
))
2714 int32 duration
= GetSpellDuration(m_spellInfo
);
2717 // Apply duration mod
2718 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
2719 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_DURATION
, duration
);
2720 m_spellState
= SPELL_STATE_CASTING
;
2721 SendChannelStart(duration
);
2725 // process immediate effects (items, ground, etc.) also initialize some variables
2726 _handle_immediate_phase();
2728 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2729 DoAllEffectOnTarget(&(*ihit
));
2731 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2732 DoAllEffectOnTarget(&(*ihit
));
2734 // spell is finished, perform some last features of the spell here
2735 _handle_finish_phase();
2737 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2740 if(m_spellState
!= SPELL_STATE_CASTING
)
2741 finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell)
2744 uint64
Spell::handle_delayed(uint64 t_offset
)
2746 uint64 next_time
= 0;
2748 if (!m_immediateHandled
)
2750 _handle_immediate_phase();
2751 m_immediateHandled
= true;
2754 // 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)
2755 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2757 if (ihit
->processed
== false)
2759 if ( ihit
->timeDelay
<= t_offset
)
2760 DoAllEffectOnTarget(&(*ihit
));
2761 else if( next_time
== 0 || ihit
->timeDelay
< next_time
)
2762 next_time
= ihit
->timeDelay
;
2766 // now recheck gameobject targeting correctness
2767 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
2769 if (ighit
->processed
== false)
2771 if ( ighit
->timeDelay
<= t_offset
)
2772 DoAllEffectOnTarget(&(*ighit
));
2773 else if( next_time
== 0 || ighit
->timeDelay
< next_time
)
2774 next_time
= ighit
->timeDelay
;
2777 // All targets passed - need finish phase
2780 // spell is finished, perform some last features of the spell here
2781 _handle_finish_phase();
2783 finish(true); // successfully finish spell cast
2785 // return zero, spell is finished now
2790 // spell is unfinished, return next execution time
2795 void Spell::_handle_immediate_phase()
2797 // handle some immediate features of the spell here
2798 HandleThreatSpells(m_spellInfo
->Id
);
2800 m_needSpellLog
= IsNeedSendToClient();
2801 for(uint32 j
= 0; j
< 3; ++j
)
2803 if(m_spellInfo
->Effect
[j
] == 0)
2806 // apply Send Event effect to ground in case empty target lists
2807 if( m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
&& !HaveTargetsForEffect(j
) )
2809 HandleEffects(NULL
, NULL
, NULL
, j
);
2813 // Don't do spell log, if is school damage spell
2814 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
|| m_spellInfo
->Effect
[j
] == 0)
2815 m_needSpellLog
= false;
2817 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[j
];
2818 if(m_originalCaster
)
2819 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
2820 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
2822 // initialize multipliers
2823 m_damageMultipliers
[j
] = 1.0f
;
2824 if( (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_HEAL
) &&
2825 (EffectChainTarget
> 1) )
2826 m_applyMultiplierMask
|= 1 << j
;
2829 // initialize Diminishing Returns Data
2830 m_diminishLevel
= DIMINISHING_LEVEL_1
;
2831 m_diminishGroup
= DIMINISHING_NONE
;
2834 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
2835 DoAllEffectOnTarget(&(*ihit
));
2838 for(uint32 j
= 0; j
< 3; ++j
)
2840 // persistent area auras target only the ground
2841 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2842 HandleEffects(NULL
, NULL
, NULL
, j
);
2846 void Spell::_handle_finish_phase()
2853 void Spell::SendSpellCooldown()
2855 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
2858 Player
* _player
= (Player
*)m_caster
;
2860 // mana/health/etc potions, disabled by client (until combat out as declarate)
2861 if (m_CastItem
&& m_CastItem
->IsPotion())
2863 // need in some way provided data for Spell::finish SendCooldownEvent
2864 _player
->SetLastPotionId(m_CastItem
->GetEntry());
2868 // (1) have infinity cooldown but set at aura apply, (2) passive cooldown at triggering
2869 if(m_spellInfo
->Attributes
& (SPELL_ATTR_DISABLED_WHILE_ACTIVE
| SPELL_ATTR_PASSIVE
))
2872 _player
->AddSpellAndCategoryCooldowns(m_spellInfo
,m_CastItem
? m_CastItem
->GetEntry() : 0, this);
2875 void Spell::update(uint32 difftime
)
2877 // update pointers based at it's GUIDs
2880 if(m_targets
.getUnitTargetGUID() && !m_targets
.getUnitTarget())
2886 // check if the player caster has moved before the spell finished
2887 if ((m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_timer
!= 0) &&
2888 (m_castPositionX
!= m_caster
->GetPositionX() || m_castPositionY
!= m_caster
->GetPositionY() || m_castPositionZ
!= m_caster
->GetPositionZ()) &&
2889 (m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
|| !((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEMENTFLAG_FALLING
)))
2891 // always cancel for channeled spells
2892 if( m_spellState
== SPELL_STATE_CASTING
)
2894 // don't cancel for melee, autorepeat, triggered and instant spells
2895 else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_MOVEMENT
))
2899 switch(m_spellState
)
2901 case SPELL_STATE_PREPARING
:
2905 if(difftime
>= m_timer
)
2908 m_timer
-= difftime
;
2911 if(m_timer
== 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat())
2914 case SPELL_STATE_CASTING
:
2918 if( m_caster
->GetTypeId() == TYPEID_PLAYER
)
2920 // check if player has jumped before the channeling finished
2921 if(((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEMENTFLAG_JUMPING
))
2924 // check for incapacitating player states
2925 if( m_caster
->hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_CONFUSED
))
2928 // check if player has turned if flag is set
2929 if( m_spellInfo
->ChannelInterruptFlags
& CHANNEL_FLAG_TURNING
&& m_castOrientation
!= m_caster
->GetOrientation() )
2933 // check if there are alive targets left
2934 if (!IsAliveUnitPresentInTargetList())
2936 SendChannelUpdate(0);
2940 if(difftime
>= m_timer
)
2943 m_timer
-= difftime
;
2948 SendChannelUpdate(0);
2950 // channeled spell processed independently for quest targeting
2951 // cast at creature (or GO) quest objectives update at successful cast channel finished
2952 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
2953 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() )
2955 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
2957 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2959 TargetInfo
* target
= &*ihit
;
2960 if(!IS_CREATURE_GUID(target
->targetGUID
))
2963 Unit
* unit
= m_caster
->GetGUID() == target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, target
->targetGUID
);
2967 p
->CastedCreatureOrGO(unit
->GetEntry(), unit
->GetGUID(), m_spellInfo
->Id
);
2970 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
2972 GOTargetInfo
* target
= &*ihit
;
2974 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
2978 p
->CastedCreatureOrGO(go
->GetEntry(), go
->GetGUID(), m_spellInfo
->Id
);
2992 void Spell::finish(bool ok
)
2997 if(m_spellState
== SPELL_STATE_FINISHED
)
3000 m_spellState
= SPELL_STATE_FINISHED
;
3002 // other code related only to successfully finished spells
3007 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3008 ((Player
*)m_caster
)->RemoveSpellMods(this);
3010 // handle SPELL_AURA_ADD_TARGET_TRIGGER auras
3011 Unit::AuraList
const& targetTriggers
= m_caster
->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER
);
3012 for(Unit::AuraList::const_iterator i
= targetTriggers
.begin(); i
!= targetTriggers
.end(); ++i
)
3014 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
3016 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3017 if( ihit
->missCondition
== SPELL_MISS_NONE
)
3019 // check m_caster->GetGUID() let load auras at login and speedup most often case
3020 Unit
*unit
= m_caster
->GetGUID()== ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
3021 if (unit
&& unit
->isAlive())
3023 SpellEntry
const *auraSpellInfo
= (*i
)->GetSpellProto();
3024 uint32 auraSpellIdx
= (*i
)->GetEffIndex();
3025 // Calculate chance at that moment (can be depend for example from combo points)
3026 int32 chance
= m_caster
->CalculateSpellDamage(auraSpellInfo
, auraSpellIdx
, (*i
)->GetBasePoints(),unit
);
3027 if(roll_chance_i(chance
))
3028 m_caster
->CastSpell(unit
, auraSpellInfo
->EffectTriggerSpell
[auraSpellIdx
], true, NULL
, (*i
));
3033 // Heal caster for all health leech from all targets
3035 m_caster
->DealHeal(m_caster
, uint32(m_healthLeech
), m_spellInfo
);
3037 if (IsMeleeAttackResetSpell())
3039 m_caster
->resetAttackTimer(BASE_ATTACK
);
3040 if(m_caster
->haveOffhandWeapon())
3041 m_caster
->resetAttackTimer(OFF_ATTACK
);
3044 /*if (IsRangedAttackResetSpell())
3045 m_caster->resetAttackTimer(RANGED_ATTACK);*/
3047 // Clear combo at finish state
3048 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& NeedsComboPoints(m_spellInfo
))
3050 // Not drop combopoints if negative spell and if any miss on enemy exist
3051 bool needDrop
= true;
3052 if (!IsPositiveSpell(m_spellInfo
->Id
))
3054 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
3056 if (ihit
->missCondition
!= SPELL_MISS_NONE
&& ihit
->targetGUID
!=m_caster
->GetGUID())
3064 ((Player
*)m_caster
)->ClearComboPoints();
3067 // potions disabled by client, send event "not in combat" if need
3068 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3069 ((Player
*)m_caster
)->UpdatePotionCooldown(this);
3071 // call triggered spell only at successful cast (after clear combo points -> for add some if need)
3072 if(!m_TriggerSpells
.empty())
3073 CastTriggerSpells();
3075 // Stop Attack for some spells
3076 if( m_spellInfo
->Attributes
& SPELL_ATTR_STOP_ATTACK_TARGET
)
3077 m_caster
->AttackStop();
3080 void Spell::SendCastResult(SpellCastResult result
)
3082 if(result
== SPELL_CAST_OK
)
3085 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3088 if(((Player
*)m_caster
)->GetSession()->PlayerLoading()) // don't send cast results at loading time
3091 SendCastResult((Player
*)m_caster
,m_spellInfo
,m_cast_count
,result
);
3094 void Spell::SendCastResult(Player
* caster
, SpellEntry
const* spellInfo
, uint8 cast_count
, SpellCastResult result
)
3096 if(result
== SPELL_CAST_OK
)
3099 WorldPacket
data(SMSG_CAST_FAILED
, (4+1+1));
3100 data
<< uint8(cast_count
); // single cast or multi 2.3 (0/1)
3101 data
<< uint32(spellInfo
->Id
);
3102 data
<< uint8(result
); // problem
3105 case SPELL_FAILED_REQUIRES_SPELL_FOCUS
:
3106 data
<< uint32(spellInfo
->RequiresSpellFocus
);
3108 case SPELL_FAILED_REQUIRES_AREA
:
3109 // hardcode areas limitation case
3110 switch(spellInfo
->Id
)
3112 case 41617: // Cenarion Mana Salve
3113 case 41619: // Cenarion Healing Salve
3114 data
<< uint32(3905);
3116 case 41618: // Bottled Nethergon Energy
3117 case 41620: // Bottled Nethergon Vapor
3118 data
<< uint32(3842);
3120 case 45373: // Bloodberry Elixir
3121 data
<< uint32(4075);
3123 default: // default case (don't must be)
3128 case SPELL_FAILED_TOTEMS
:
3129 if(spellInfo
->Totem
[0])
3130 data
<< uint32(spellInfo
->Totem
[0]);
3131 if(spellInfo
->Totem
[1])
3132 data
<< uint32(spellInfo
->Totem
[1]);
3134 case SPELL_FAILED_TOTEM_CATEGORY
:
3135 if(spellInfo
->TotemCategory
[0])
3136 data
<< uint32(spellInfo
->TotemCategory
[0]);
3137 if(spellInfo
->TotemCategory
[1])
3138 data
<< uint32(spellInfo
->TotemCategory
[1]);
3140 case SPELL_FAILED_EQUIPPED_ITEM_CLASS
:
3141 data
<< uint32(spellInfo
->EquippedItemClass
);
3142 data
<< uint32(spellInfo
->EquippedItemSubClassMask
);
3143 //data << uint32(spellInfo->EquippedItemInventoryTypeMask);
3148 caster
->GetSession()->SendPacket(&data
);
3151 void Spell::SendSpellStart()
3153 if(!IsNeedSendToClient())
3156 sLog
.outDebug("Sending SMSG_SPELL_START id=%u", m_spellInfo
->Id
);
3158 uint32 castFlags
= CAST_FLAG_UNKNOWN1
;
3160 castFlags
|= CAST_FLAG_AMMO
;
3162 if(m_spellInfo
->runeCostID
)
3163 castFlags
|= CAST_FLAG_UNKNOWN10
;
3165 WorldPacket
data(SMSG_SPELL_START
, (8+8+4+4+2));
3167 data
.append(m_CastItem
->GetPackGUID());
3169 data
.append(m_caster
->GetPackGUID());
3171 data
.append(m_caster
->GetPackGUID());
3172 data
<< uint8(m_cast_count
); // pending spell cast?
3173 data
<< uint32(m_spellInfo
->Id
); // spellId
3174 data
<< uint32(castFlags
); // cast flags
3175 data
<< uint32(m_timer
); // delay?
3177 m_targets
.write(&data
);
3179 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // predicted power?
3182 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
3184 uint8 v1
= 0;//m_runesState;
3185 uint8 v2
= 0;//((Player*)m_caster)->GetRunesState();
3186 data
<< uint8(v1
); // runes state before
3187 data
<< uint8(v2
); // runes state after
3188 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
3191 if(m
& v1
) // usable before...
3192 if(!(m
& v2
)) // ...but on cooldown now...
3193 data
<< uint8(0); // some unknown byte (time?)
3197 if ( castFlags
& CAST_FLAG_AMMO
)
3198 WriteAmmoToPacket(&data
);
3200 if ( castFlags
& CAST_FLAG_UNKNOWN21
)
3206 m_caster
->SendMessageToSet(&data
, true);
3209 void Spell::SendSpellGo()
3211 // not send invisible spell casting
3212 if(!IsNeedSendToClient())
3215 sLog
.outDebug("Sending SMSG_SPELL_GO id=%u", m_spellInfo
->Id
);
3217 uint32 castFlags
= CAST_FLAG_UNKNOWN3
;
3219 castFlags
|= CAST_FLAG_AMMO
; // arrows/bullets visual
3221 if((m_caster
->GetTypeId() == TYPEID_PLAYER
) && (m_caster
->getClass() == CLASS_DEATH_KNIGHT
) && m_spellInfo
->runeCostID
)
3223 castFlags
|= CAST_FLAG_UNKNOWN10
; // same as in SMSG_SPELL_START
3224 castFlags
|= CAST_FLAG_UNKNOWN6
; // makes cooldowns visible
3225 castFlags
|= CAST_FLAG_UNKNOWN7
; // rune cooldowns list
3228 WorldPacket
data(SMSG_SPELL_GO
, 50); // guess size
3231 data
.append(m_CastItem
->GetPackGUID());
3233 data
.append(m_caster
->GetPackGUID());
3235 data
.append(m_caster
->GetPackGUID());
3236 data
<< uint8(m_cast_count
); // pending spell cast?
3237 data
<< uint32(m_spellInfo
->Id
); // spellId
3238 data
<< uint32(castFlags
); // cast flags
3239 data
<< uint32(getMSTime()); // timestamp
3241 WriteSpellGoTargets(&data
);
3243 m_targets
.write(&data
);
3245 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // unknown wotlk, predicted power?
3248 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
3250 uint8 v1
= m_runesState
;
3251 uint8 v2
= m_caster
->getClass() == CLASS_DEATH_KNIGHT
? ((Player
*)m_caster
)->GetRunesState() : 0;
3252 data
<< uint8(v1
); // runes state before
3253 data
<< uint8(v2
); // runes state after
3254 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
3257 if(m
& v1
) // usable before...
3258 if(!(m
& v2
)) // ...but on cooldown now...
3259 data
<< uint8(0); // some unknown byte (time?)
3263 if ( castFlags
& CAST_FLAG_UNKNOWN4
) // unknown wotlk
3269 if ( castFlags
& CAST_FLAG_AMMO
)
3270 WriteAmmoToPacket(&data
);
3272 if ( castFlags
& CAST_FLAG_UNKNOWN5
) // unknown wotlk
3278 if ( m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
3283 m_caster
->SendMessageToSet(&data
, true);
3286 void Spell::WriteAmmoToPacket( WorldPacket
* data
)
3288 uint32 ammoInventoryType
= 0;
3289 uint32 ammoDisplayID
= 0;
3291 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3293 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack( RANGED_ATTACK
);
3296 ammoInventoryType
= pItem
->GetProto()->InventoryType
;
3297 if( ammoInventoryType
== INVTYPE_THROWN
)
3298 ammoDisplayID
= pItem
->GetProto()->DisplayInfoID
;
3301 uint32 ammoID
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
3304 ItemPrototype
const *pProto
= ObjectMgr::GetItemPrototype( ammoID
);
3307 ammoDisplayID
= pProto
->DisplayInfoID
;
3308 ammoInventoryType
= pProto
->InventoryType
;
3311 else if(m_caster
->GetDummyAura(46699)) // Requires No Ammo
3313 ammoDisplayID
= 5996; // normal arrow
3314 ammoInventoryType
= INVTYPE_AMMO
;
3321 for (uint8 i
= 0; i
< 3; ++i
)
3323 if(uint32 item_id
= m_caster
->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID
+ i
))
3325 if(ItemEntry
const * itemEntry
= sItemStore
.LookupEntry(item_id
))
3327 if(itemEntry
->Class
==ITEM_CLASS_WEAPON
)
3329 switch(itemEntry
->SubClass
)
3331 case ITEM_SUBCLASS_WEAPON_THROWN
:
3332 ammoDisplayID
= itemEntry
->DisplayId
;
3333 ammoInventoryType
= itemEntry
->InventoryType
;
3335 case ITEM_SUBCLASS_WEAPON_BOW
:
3336 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
3337 ammoDisplayID
= 5996; // is this need fixing?
3338 ammoInventoryType
= INVTYPE_AMMO
;
3340 case ITEM_SUBCLASS_WEAPON_GUN
:
3341 ammoDisplayID
= 5998; // is this need fixing?
3342 ammoInventoryType
= INVTYPE_AMMO
;
3354 *data
<< uint32(ammoDisplayID
);
3355 *data
<< uint32(ammoInventoryType
);
3358 void Spell::WriteSpellGoTargets( WorldPacket
* data
)
3360 // This function also fill data for channeled spells:
3361 // m_needAliveTargetMask req for stop channelig if one target die
3362 uint32 hit
= m_UniqueGOTargetInfo
.size(); // Always hits on GO
3364 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3366 if ((*ihit
).effectMask
== 0) // No effect apply - all immuned add state
3368 // possibly SPELL_MISS_IMMUNE2 for this??
3369 ihit
->missCondition
= SPELL_MISS_IMMUNE2
;
3372 else if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
3378 *data
<< (uint8
)hit
;
3379 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3381 if ((*ihit
).missCondition
== SPELL_MISS_NONE
) // Add only hits
3383 *data
<< uint64(ihit
->targetGUID
);
3384 m_needAliveTargetMask
|=ihit
->effectMask
;
3388 for(std::list
<GOTargetInfo
>::const_iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end(); ++ighit
)
3389 *data
<< uint64(ighit
->targetGUID
); // Always hits
3391 *data
<< (uint8
)miss
;
3392 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3394 if( ihit
->missCondition
!= SPELL_MISS_NONE
) // Add only miss
3396 *data
<< uint64(ihit
->targetGUID
);
3397 *data
<< uint8(ihit
->missCondition
);
3398 if( ihit
->missCondition
== SPELL_MISS_REFLECT
)
3399 *data
<< uint8(ihit
->reflectResult
);
3402 // Reset m_needAliveTargetMask for non channeled spell
3403 if(!IsChanneledSpell(m_spellInfo
))
3404 m_needAliveTargetMask
= 0;
3407 void Spell::SendLogExecute()
3409 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
3411 WorldPacket
data(SMSG_SPELLLOGEXECUTE
, (8+4+4+4+4+8));
3413 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
3414 data
.append(m_caster
->GetPackGUID());
3416 data
.append(target
->GetPackGUID());
3418 data
<< uint32(m_spellInfo
->Id
);
3420 data
<< uint32(count1
); // count1 (effect count?)
3421 for(uint32 i
= 0; i
< count1
; ++i
)
3423 data
<< uint32(m_spellInfo
->Effect
[0]); // spell effect
3425 data
<< uint32(count2
); // count2 (target count?)
3426 for(uint32 j
= 0; j
< count2
; ++j
)
3428 switch(m_spellInfo
->Effect
[0])
3430 case SPELL_EFFECT_POWER_DRAIN
:
3431 if(Unit
*unit
= m_targets
.getUnitTarget())
3432 data
.append(unit
->GetPackGUID());
3439 case SPELL_EFFECT_ADD_EXTRA_ATTACKS
:
3440 if(Unit
*unit
= m_targets
.getUnitTarget())
3441 data
.append(unit
->GetPackGUID());
3444 data
<< uint32(0); // count?
3446 case SPELL_EFFECT_INTERRUPT_CAST
:
3447 if(Unit
*unit
= m_targets
.getUnitTarget())
3448 data
.append(unit
->GetPackGUID());
3451 data
<< uint32(0); // spellid
3453 case SPELL_EFFECT_DURABILITY_DAMAGE
:
3454 if(Unit
*unit
= m_targets
.getUnitTarget())
3455 data
.append(unit
->GetPackGUID());
3461 case SPELL_EFFECT_OPEN_LOCK
:
3462 if(Item
*item
= m_targets
.getItemTarget())
3463 data
.append(item
->GetPackGUID());
3467 case SPELL_EFFECT_CREATE_ITEM
:
3468 case SPELL_EFFECT_CREATE_ITEM_2
:
3469 data
<< uint32(m_spellInfo
->EffectItemType
[0]);
3471 case SPELL_EFFECT_SUMMON
:
3472 case SPELL_EFFECT_TRANS_DOOR
:
3473 case SPELL_EFFECT_SUMMON_PET
:
3474 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
3475 case SPELL_EFFECT_CREATE_HOUSE
:
3476 case SPELL_EFFECT_DUEL
:
3477 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1
:
3478 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2
:
3479 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3
:
3480 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4
:
3481 if(Unit
*unit
= m_targets
.getUnitTarget())
3482 data
.append(unit
->GetPackGUID());
3483 else if(m_targets
.getItemTargetGUID())
3484 data
.appendPackGUID(m_targets
.getItemTargetGUID());
3485 else if(GameObject
*go
= m_targets
.getGOTarget())
3486 data
.append(go
->GetPackGUID());
3488 data
<< uint8(0); // guid
3490 case SPELL_EFFECT_FEED_PET
:
3491 data
<< uint32(m_targets
.getItemTargetEntry());
3493 case SPELL_EFFECT_DISMISS_PET
:
3494 if(Unit
*unit
= m_targets
.getUnitTarget())
3495 data
.append(unit
->GetPackGUID());
3499 case SPELL_EFFECT_RESURRECT
:
3500 case SPELL_EFFECT_RESURRECT_NEW
:
3501 if(Unit
*unit
= m_targets
.getUnitTarget())
3502 data
.append(unit
->GetPackGUID());
3512 m_caster
->SendMessageToSet(&data
, true);
3515 void Spell::SendInterrupted(uint8 result
)
3517 WorldPacket
data(SMSG_SPELL_FAILURE
, (8+4+1));
3518 data
.append(m_caster
->GetPackGUID());
3519 data
<< uint8(m_cast_count
);
3520 data
<< uint32(m_spellInfo
->Id
);
3521 data
<< uint8(result
);
3522 m_caster
->SendMessageToSet(&data
, true);
3524 data
.Initialize(SMSG_SPELL_FAILED_OTHER
, (8+4));
3525 data
.append(m_caster
->GetPackGUID());
3526 data
<< uint8(m_cast_count
);
3527 data
<< uint32(m_spellInfo
->Id
);
3528 data
<< uint8(result
);
3529 m_caster
->SendMessageToSet(&data
, true);
3532 void Spell::SendChannelUpdate(uint32 time
)
3536 m_caster
->RemoveAurasByCasterSpell(m_spellInfo
->Id
,m_caster
->GetGUID());
3538 if(uint64 target_guid
= m_caster
->GetChannelObjectGUID())
3539 if(target_guid
!= m_caster
->GetGUID() && IS_UNIT_GUID(target_guid
))
3540 if(Unit
* target
= ObjectAccessor::GetUnit(*m_caster
, target_guid
))
3541 target
->RemoveAurasByCasterSpell(m_spellInfo
->Id
,m_caster
->GetGUID());
3543 m_caster
->SetChannelObjectGUID(0);
3544 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, 0);
3547 WorldPacket
data( MSG_CHANNEL_UPDATE
, 8+4 );
3548 data
.append(m_caster
->GetPackGUID());
3549 data
<< uint32(time
);
3551 m_caster
->SendMessageToSet(&data
, true);
3554 void Spell::SendChannelStart(uint32 duration
)
3556 WorldObject
* target
= NULL
;
3558 // select first not resisted target from target list for _0_ effect
3559 if(!m_UniqueTargetInfo
.empty())
3561 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin(); itr
!= m_UniqueTargetInfo
.end(); ++itr
)
3563 if( (itr
->effectMask
& (1 << 0)) && itr
->reflectResult
== SPELL_MISS_NONE
&& itr
->targetGUID
!= m_caster
->GetGUID())
3565 target
= ObjectAccessor::GetUnit(*m_caster
, itr
->targetGUID
);
3570 else if(!m_UniqueGOTargetInfo
.empty())
3572 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin(); itr
!= m_UniqueGOTargetInfo
.end(); ++itr
)
3574 if(itr
->effectMask
& (1 << 0) )
3576 target
= m_caster
->GetMap()->GetGameObject(itr
->targetGUID
);
3582 WorldPacket
data( MSG_CHANNEL_START
, (8+4+4) );
3583 data
.append(m_caster
->GetPackGUID());
3584 data
<< uint32(m_spellInfo
->Id
);
3585 data
<< uint32(duration
);
3587 m_caster
->SendMessageToSet(&data
, true);
3591 m_caster
->SetChannelObjectGUID(target
->GetGUID());
3592 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, m_spellInfo
->Id
);
3595 void Spell::SendResurrectRequest(Player
* target
)
3597 // Both players and NPCs can resurrect using spells - have a look at creature 28487 for example
3598 // However, the packet structure differs slightly
3600 const char* sentName
= m_caster
->GetTypeId() == TYPEID_PLAYER
? "" : m_caster
->GetNameForLocaleIdx(target
->GetSession()->GetSessionDbLocaleIndex());
3602 WorldPacket
data(SMSG_RESURRECT_REQUEST
, (8+4+strlen(sentName
)+1+1+1));
3603 data
<< uint64(m_caster
->GetGUID());
3604 data
<< uint32(strlen(sentName
) + 1);
3609 data
<< uint8(m_caster
->GetTypeId() == TYPEID_PLAYER
? 0 : 1);
3610 target
->GetSession()->SendPacket(&data
);
3613 void Spell::SendPlaySpellVisual(uint32 SpellID
)
3615 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3618 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 8 + 4);
3619 data
<< uint64(m_caster
->GetGUID());
3620 data
<< uint32(SpellID
); // spell visual id?
3621 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
3624 void Spell::TakeCastItem()
3626 if(!m_CastItem
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
3629 // not remove cast item at triggered spell (equipping, weapon damage, etc)
3630 if(m_IsTriggeredSpell
)
3633 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3637 // This code is to avoid a crash
3638 // I'm not sure, if this is really an error, but I guess every item needs a prototype
3639 sLog
.outError("Cast item has no item prototype highId=%d, lowId=%d",m_CastItem
->GetGUIDHigh(), m_CastItem
->GetGUIDLow());
3643 bool expendable
= false;
3644 bool withoutCharges
= false;
3646 for (int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
3648 if (proto
->Spells
[i
].SpellId
)
3650 // item has limited charges
3651 if (proto
->Spells
[i
].SpellCharges
)
3653 if (proto
->Spells
[i
].SpellCharges
< 0)
3656 int32 charges
= m_CastItem
->GetSpellCharges(i
);
3658 // item has charges left
3661 (charges
> 0) ? --charges
: ++charges
; // abs(charges) less at 1 after use
3662 if (proto
->Stackable
== 1)
3663 m_CastItem
->SetSpellCharges(i
, charges
);
3664 m_CastItem
->SetState(ITEM_CHANGED
, (Player
*)m_caster
);
3668 withoutCharges
= (charges
== 0);
3673 if (expendable
&& withoutCharges
)
3676 ((Player
*)m_caster
)->DestroyItemCount(m_CastItem
, count
, true);
3678 // prevent crash at access to deleted m_targets.getItemTarget
3679 if(m_CastItem
==m_targets
.getItemTarget())
3680 m_targets
.setItemTarget(NULL
);
3686 void Spell::TakePower()
3688 if(m_CastItem
|| m_triggeredByAuraSpell
)
3691 // health as power used
3692 if(m_spellInfo
->powerType
== POWER_HEALTH
)
3694 m_caster
->ModifyHealth( -(int32
)m_powerCost
);
3698 if(m_spellInfo
->powerType
>= MAX_POWERS
)
3700 sLog
.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo
->powerType
);
3704 Powers powerType
= Powers(m_spellInfo
->powerType
);
3706 if(powerType
== POWER_RUNE
)
3712 m_caster
->ModifyPower(powerType
, -(int32
)m_powerCost
);
3714 // Set the five second timer
3715 if (powerType
== POWER_MANA
&& m_powerCost
> 0)
3716 m_caster
->SetLastManaUse();
3719 SpellCastResult
Spell::CheckRuneCost(uint32 runeCostID
)
3721 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3722 return SPELL_CAST_OK
;
3724 Player
*plr
= (Player
*)m_caster
;
3726 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3727 return SPELL_CAST_OK
;
3729 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(runeCostID
);
3732 return SPELL_CAST_OK
;
3734 if(src
->NoRuneCost())
3735 return SPELL_CAST_OK
;
3737 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3739 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3740 runeCost
[i
] = src
->RuneCost
[i
];
3742 runeCost
[RUNE_DEATH
] = MAX_RUNES
; // calculated later
3744 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3746 RuneType rune
= plr
->GetCurrentRune(i
);
3747 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3751 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3753 runeCost
[RUNE_DEATH
] += runeCost
[i
];
3755 if(runeCost
[RUNE_DEATH
] > MAX_RUNES
)
3756 return SPELL_FAILED_NO_POWER
; // not sure if result code is correct
3758 return SPELL_CAST_OK
;
3761 void Spell::TakeRunePower()
3763 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3766 Player
*plr
= (Player
*)m_caster
;
3768 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3771 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(m_spellInfo
->runeCostID
);
3773 if(!src
|| (src
->NoRuneCost() && src
->NoRunicPowerGain()))
3776 m_runesState
= plr
->GetRunesState(); // store previous state
3778 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3780 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3782 runeCost
[i
] = src
->RuneCost
[i
];
3785 runeCost
[RUNE_DEATH
] = 0; // calculated later
3787 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3789 RuneType rune
= plr
->GetCurrentRune(i
);
3790 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3792 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3797 runeCost
[RUNE_DEATH
] = runeCost
[RUNE_BLOOD
] + runeCost
[RUNE_UNHOLY
] + runeCost
[RUNE_FROST
];
3799 if(runeCost
[RUNE_DEATH
] > 0)
3801 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3803 RuneType rune
= plr
->GetCurrentRune(i
);
3804 if((plr
->GetRuneCooldown(i
) == 0) && (rune
== RUNE_DEATH
))
3806 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3808 plr
->ConvertRune(i
, plr
->GetBaseRune(i
));
3809 if(runeCost
[RUNE_DEATH
] == 0)
3815 // you can gain some runic power when use runes
3816 float rp
= src
->runePowerGain
;;
3817 rp
*= sWorld
.getRate(RATE_POWER_RUNICPOWER_INCOME
);
3818 plr
->ModifyPower(POWER_RUNIC_POWER
, (int32
)rp
);
3821 void Spell::TakeReagents()
3823 if(m_IsTriggeredSpell
) // reagents used in triggered spell removed by original spell or don't must be removed.
3826 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3829 Player
* p_caster
= (Player
*)m_caster
;
3830 if (p_caster
->CanNoReagentCast(m_spellInfo
))
3833 for(uint32 x
= 0; x
< 8; ++x
)
3835 if(m_spellInfo
->Reagent
[x
] <= 0)
3838 uint32 itemid
= m_spellInfo
->Reagent
[x
];
3839 uint32 itemcount
= m_spellInfo
->ReagentCount
[x
];
3841 // if CastItem is also spell reagent
3844 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3845 if( proto
&& proto
->ItemId
== itemid
)
3847 for(int s
= 0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
3849 // CastItem will be used up and does not count as reagent
3850 int32 charges
= m_CastItem
->GetSpellCharges(s
);
3851 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
3862 // if getItemTarget is also spell reagent
3863 if (m_targets
.getItemTargetEntry() == itemid
)
3864 m_targets
.setItemTarget(NULL
);
3866 p_caster
->DestroyItemCount(itemid
, itemcount
, true);
3870 void Spell::HandleThreatSpells(uint32 spellId
)
3872 if(!m_targets
.getUnitTarget() || !spellId
)
3875 if(!m_targets
.getUnitTarget()->CanHaveThreatList())
3878 uint16 threat
= sSpellMgr
.GetSpellThreat(spellId
);
3883 m_targets
.getUnitTarget()->AddThreat(m_caster
, float(threat
), false, GetSpellSchoolMask(m_spellInfo
), m_spellInfo
);
3885 DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId
, sSpellMgr
.GetSpellRank(spellId
), threat
);
3888 void Spell::HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,uint32 i
, float DamageMultiplier
)
3890 unitTarget
= pUnitTarget
;
3891 itemTarget
= pItemTarget
;
3892 gameObjTarget
= pGOTarget
;
3894 uint8 eff
= m_spellInfo
->Effect
[i
];
3896 damage
= int32(CalculateDamage((uint8
)i
, unitTarget
) * DamageMultiplier
);
3898 sLog
.outDebug( "Spell %u Effect%d : %u", m_spellInfo
->Id
, i
, eff
);
3900 if(eff
<TOTAL_SPELL_EFFECTS
)
3902 //sLog.outDebug( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff);
3903 (*this.*SpellEffects
[eff
])(i
);
3908 sLog.outDebug( "WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff);
3910 EffectEnchantItemTmp(i);
3913 sLog.outError("SPELL: unknown effect %u spell id %u",
3914 eff, m_spellInfo->Id);
3921 void Spell::AddTriggeredSpell( uint32 spellId
)
3923 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3927 sLog
.outError("Spell::AddTriggeredSpell: unknown spell id %u used as triggred spell for spell %u)", spellId
, m_spellInfo
->Id
);
3931 m_TriggerSpells
.push_back(spellInfo
);
3934 void Spell::AddPrecastSpell( uint32 spellId
)
3936 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3940 sLog
.outError("Spell::AddPrecastSpell: unknown spell id %u used as pre-cast spell for spell %u)", spellId
, m_spellInfo
->Id
);
3944 m_preCastSpells
.push_back(spellInfo
);
3947 void Spell::CastTriggerSpells()
3949 for(SpellInfoList::const_iterator si
=m_TriggerSpells
.begin(); si
!=m_TriggerSpells
.end(); ++si
)
3951 Spell
* spell
= new Spell(m_caster
, (*si
), true, m_originalCasterGUID
, m_selfContainer
);
3952 spell
->prepare(&m_targets
); // use original spell original targets
3956 void Spell::CastPreCastSpells(Unit
* target
)
3958 for(SpellInfoList::const_iterator si
=m_preCastSpells
.begin(); si
!=m_preCastSpells
.end(); ++si
)
3959 m_caster
->CastSpell(target
, (*si
), true, m_CastItem
);
3962 SpellCastResult
Spell::CheckCast(bool strict
)
3964 // check cooldowns to prevent cheating (ignore passive spells, that client side visual only)
3965 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& !(m_spellInfo
->Attributes
& SPELL_ATTR_PASSIVE
) &&
3966 ((Player
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
3968 if(m_triggeredByAuraSpell
)
3969 return SPELL_FAILED_DONT_REPORT
;
3971 return SPELL_FAILED_NOT_READY
;
3974 // only allow triggered spells if at an ended battleground
3975 if( !m_IsTriggeredSpell
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
3976 if(BattleGround
* bg
= ((Player
*)m_caster
)->GetBattleGround())
3977 if(bg
->GetStatus() == STATUS_WAIT_LEAVE
)
3978 return SPELL_FAILED_DONT_REPORT
;
3980 // only check at first call, Stealth auras are already removed at second call
3981 // for now, ignore triggered spells
3982 if( strict
&& !m_IsTriggeredSpell
)
3984 bool checkForm
= true;
3985 // Ignore form req aura
3986 Unit::AuraList
const& ignore
= m_caster
->GetAurasByType(SPELL_AURA_MOD_IGNORE_SHAPESHIFT
);
3987 for(Unit::AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
3989 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
3996 // Cannot be used in this stance/form
3997 SpellCastResult shapeError
= GetErrorAtShapeshiftedCast(m_spellInfo
, m_caster
->m_form
);
3998 if(shapeError
!= SPELL_CAST_OK
)
4001 if ((m_spellInfo
->Attributes
& SPELL_ATTR_ONLY_STEALTHED
) && !(m_caster
->HasStealthAura()))
4002 return SPELL_FAILED_ONLY_STEALTHED
;
4006 // caster state requirements
4007 if(m_spellInfo
->CasterAuraState
&& !m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraState
)))
4008 return SPELL_FAILED_CASTER_AURASTATE
;
4009 if(m_spellInfo
->CasterAuraStateNot
&& m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraStateNot
)))
4010 return SPELL_FAILED_CASTER_AURASTATE
;
4012 // Caster aura req check if need
4013 if(m_spellInfo
->casterAuraSpell
&& !m_caster
->HasAura(m_spellInfo
->casterAuraSpell
))
4014 return SPELL_FAILED_CASTER_AURASTATE
;
4015 if(m_spellInfo
->excludeCasterAuraSpell
)
4017 // Special cases of non existing auras handling
4018 if(m_spellInfo
->excludeCasterAuraSpell
== 61988)
4020 // Avenging Wrath Marker
4021 if(m_caster
->HasAura(61987))
4022 return SPELL_FAILED_CASTER_AURASTATE
;
4024 else if(m_caster
->HasAura(m_spellInfo
->excludeCasterAuraSpell
))
4025 return SPELL_FAILED_CASTER_AURASTATE
;
4028 // cancel autorepeat spells if cast start when moving
4029 // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
4030 if( m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->isMoving() )
4032 // skip stuck spell to allow use it in falling case and apply spell limitations at movement
4033 if( (!((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEMENTFLAG_FALLING
) || m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
) &&
4034 (IsAutoRepeat() || (m_spellInfo
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_NOT_SEATED
) != 0) )
4035 return SPELL_FAILED_MOVING
;
4038 if(Unit
*target
= m_targets
.getUnitTarget())
4040 // target state requirements (not allowed state), apply to self also
4041 if(m_spellInfo
->TargetAuraStateNot
&& target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraStateNot
)))
4042 return SPELL_FAILED_TARGET_AURASTATE
;
4044 if (!m_IsTriggeredSpell
&& IsDeathOnlySpell(m_spellInfo
) && target
->isAlive())
4045 return SPELL_FAILED_TARGET_NOT_DEAD
;
4047 // Target aura req check if need
4048 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
4049 return SPELL_FAILED_CASTER_AURASTATE
;
4050 if(m_spellInfo
->excludeTargetAuraSpell
)
4052 // Special cases of non existing auras handling
4053 if (m_spellInfo
->excludeTargetAuraSpell
== 61988)
4055 // Avenging Wrath Marker
4056 if (target
->HasAura(61987))
4057 return SPELL_FAILED_CASTER_AURASTATE
;
4060 else if (target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
4061 return SPELL_FAILED_CASTER_AURASTATE
;
4064 bool non_caster_target
= target
!= m_caster
&& !IsSpellWithCasterSourceTargetsOnly(m_spellInfo
);
4066 if(non_caster_target
)
4068 // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds
4069 if(m_spellInfo
->TargetAuraState
&& !target
->HasAuraStateForCaster(AuraState(m_spellInfo
->TargetAuraState
),m_caster
->GetGUID()))
4070 return SPELL_FAILED_TARGET_AURASTATE
;
4072 // Not allow casting on flying player
4073 if (target
->isInFlight())
4074 return SPELL_FAILED_BAD_TARGETS
;
4076 if(!m_IsTriggeredSpell
&& VMAP::VMapFactory::checkSpellForLoS(m_spellInfo
->Id
) && !m_caster
->IsWithinLOSInMap(target
))
4077 return SPELL_FAILED_LINE_OF_SIGHT
;
4079 // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode
4080 // this case can be triggered if rank not found (too low-level target for first rank)
4081 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsPassiveSpell(m_spellInfo
->Id
) && !m_CastItem
)
4083 for(int i
=0;i
<3;++i
)
4085 // check only spell that apply positive auras
4086 if (IsPositiveEffect(m_spellInfo
->Id
, i
) && m_spellInfo
->Effect
[i
] == SPELL_EFFECT_APPLY_AURA
&&
4087 // at not self target
4088 !IsCasterSourceTarget(m_spellInfo
->EffectImplicitTargetA
[i
]) &&
4089 // and target low level
4090 target
->getLevel() + 10 < m_spellInfo
->spellLevel
)
4092 return SPELL_FAILED_LOWLEVEL
;
4097 else if (m_caster
== target
)
4100 if (m_caster
->GetTypeId() == TYPEID_PLAYER
) // Target - is player caster
4102 // Additional check for some spells
4103 // If 0 spell effect empty - client not send target data (need use selection)
4104 // TODO: check it on next client version
4105 if (m_targets
.m_targetMask
== TARGET_FLAG_SELF
&&
4106 m_spellInfo
->EffectImplicitTargetA
[1] == TARGET_CHAIN_DAMAGE
)
4108 if (target
= m_caster
->GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection()))
4109 m_targets
.setUnitTarget(target
);
4111 return SPELL_FAILED_BAD_TARGETS
;
4115 // Some special spells with non-caster only mode
4118 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
4119 m_spellInfo
->SpellIconID
== 16)
4120 return SPELL_FAILED_BAD_TARGETS
;
4122 // Focus Magic (main spell)
4123 if (m_spellInfo
->Id
== 54646)
4124 return SPELL_FAILED_BAD_TARGETS
;
4127 // check pet presents
4128 for(int j
= 0; j
< 3; ++j
)
4130 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_PET
)
4132 target
= m_caster
->GetPet();
4135 if(m_triggeredByAuraSpell
) // not report pet not existence for triggered spells
4136 return SPELL_FAILED_DONT_REPORT
;
4138 return SPELL_FAILED_NO_PET
;
4144 //check creature type
4145 //ignore self casts (including area casts when caster selected as target)
4146 if(non_caster_target
)
4148 if(!CheckTargetCreatureType(target
))
4150 if(target
->GetTypeId() == TYPEID_PLAYER
)
4151 return SPELL_FAILED_TARGET_IS_PLAYER
;
4153 return SPELL_FAILED_BAD_TARGETS
;
4157 if(non_caster_target
)
4160 bool explicit_target_mode
= false;
4161 bool target_hostile
= false;
4162 bool target_hostile_checked
= false;
4163 bool target_friendly
= false;
4164 bool target_friendly_checked
= false;
4165 for(int k
= 0; k
< 3; ++k
)
4167 if (IsExplicitPositiveTarget(m_spellInfo
->EffectImplicitTargetA
[k
]))
4169 if (!target_hostile_checked
)
4171 target_hostile_checked
= true;
4172 target_hostile
= m_caster
->IsHostileTo(target
);
4176 return SPELL_FAILED_BAD_TARGETS
;
4178 explicit_target_mode
= true;
4180 else if (IsExplicitNegativeTarget(m_spellInfo
->EffectImplicitTargetA
[k
]))
4182 if (!target_friendly_checked
)
4184 target_friendly_checked
= true;
4185 target_friendly
= m_caster
->IsFriendlyTo(target
);
4189 return SPELL_FAILED_BAD_TARGETS
;
4191 explicit_target_mode
= true;
4194 // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
4195 // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
4196 if (!explicit_target_mode
&& m_caster
->GetTypeId() == TYPEID_UNIT
&& m_caster
->GetCharmerOrOwnerGUID())
4198 // check correctness positive/negative cast target (pet cast real check and cheating check)
4199 if(IsPositiveSpell(m_spellInfo
->Id
))
4201 if (!target_hostile_checked
)
4203 target_hostile_checked
= true;
4204 target_hostile
= m_caster
->IsHostileTo(target
);
4208 return SPELL_FAILED_BAD_TARGETS
;
4212 if (!target_friendly_checked
)
4214 target_friendly_checked
= true;
4215 target_friendly
= m_caster
->IsFriendlyTo(target
);
4219 return SPELL_FAILED_BAD_TARGETS
;
4224 if(IsPositiveSpell(m_spellInfo
->Id
))
4225 if(target
->IsImmunedToSpell(m_spellInfo
))
4226 return SPELL_FAILED_TARGET_AURASTATE
;
4228 //Must be behind the target.
4229 if( m_spellInfo
->AttributesEx2
== 0x100000 && (m_spellInfo
->AttributesEx
& 0x200) == 0x200 && target
->HasInArc(M_PI
, m_caster
) )
4231 //Exclusion for Pounce: Facing Limitation was removed in 2.0.1, but it still uses the same, old Ex-Flags
4232 //Exclusion for Mutilate:Facing Limitation was removed in 2.0.1 and 3.0.3, but they still use the same, old Ex-Flags
4233 if ((m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_DRUID
|| (m_spellInfo
->SpellFamilyFlags
!= UI64LIT(0x0000000000020000))) &&
4234 (m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_ROGUE
|| (m_spellInfo
->SpellFamilyFlags
!= UI64LIT(0x0020000000000000))))
4237 return SPELL_FAILED_NOT_BEHIND
;
4241 //Target must be facing you.
4242 if((m_spellInfo
->Attributes
== 0x150010) && !target
->HasInArc(M_PI
, m_caster
) )
4245 return SPELL_FAILED_NOT_INFRONT
;
4248 // check if target is in combat
4249 if (non_caster_target
&& (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET
) && target
->isInCombat())
4250 return SPELL_FAILED_TARGET_AFFECTING_COMBAT
;
4254 m_caster
->GetZoneAndAreaId(zone
, area
);
4256 SpellCastResult locRes
= sSpellMgr
.GetSpellAllowedInLocationError(m_spellInfo
,m_caster
->GetMapId(),zone
,area
,
4257 m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself());
4258 if (locRes
!= SPELL_CAST_OK
)
4261 // not let players cast spells at mount (and let do it to creatures)
4262 if (m_caster
->IsMounted() && m_caster
->GetTypeId()==TYPEID_PLAYER
&& !m_IsTriggeredSpell
&&
4263 !IsPassiveSpell(m_spellInfo
->Id
) && !(m_spellInfo
->Attributes
& SPELL_ATTR_CASTABLE_WHILE_MOUNTED
))
4265 if (m_caster
->isInFlight())
4266 return SPELL_FAILED_NOT_ON_TAXI
;
4268 return SPELL_FAILED_NOT_MOUNTED
;
4271 // always (except passive spells) check items (focus object can be required for any type casts)
4272 if (!IsPassiveSpell(m_spellInfo
->Id
))
4274 SpellCastResult castResult
= CheckItems();
4275 if(castResult
!= SPELL_CAST_OK
)
4279 // Database based targets from spell_target_script
4280 if (m_UniqueTargetInfo
.empty()) // skip second CheckCast apply (for delayed spells for example)
4282 for(uint8 j
= 0; j
< 3; ++j
)
4284 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
4285 (m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_SELF
) ||
4286 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4287 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
||
4288 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
)
4291 SpellScriptTargetBounds bounds
= sSpellMgr
.GetSpellScriptTargetBounds(m_spellInfo
->Id
);
4293 if (bounds
.first
==bounds
.second
)
4294 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
);
4296 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4297 float range
= GetSpellMaxRange(srange
);
4299 Creature
* creatureScriptTarget
= NULL
;
4300 GameObject
* goScriptTarget
= NULL
;
4302 for(SpellScriptTarget::const_iterator i_spellST
= bounds
.first
; i_spellST
!= bounds
.second
; ++i_spellST
)
4304 switch(i_spellST
->second
.type
)
4306 case SPELL_TARGET_TYPE_GAMEOBJECT
:
4308 GameObject
* p_GameObject
= NULL
;
4310 if (i_spellST
->second
.targetEntry
)
4312 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4314 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4316 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*m_caster
, i_spellST
->second
.targetEntry
, range
);
4317 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(m_caster
, p_GameObject
, go_check
);
4319 TypeContainerVisitor
<MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
>, GridTypeMapContainer
> object_checker(checker
);
4320 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4321 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap(), *m_caster
, range
);
4325 // remember found target and range, next attempt will find more near target with another entry
4326 creatureScriptTarget
= NULL
;
4327 goScriptTarget
= p_GameObject
;
4328 range
= go_check
.GetLastRange();
4331 else if (focusObject
) // Focus Object
4333 float frange
= m_caster
->GetDistance(focusObject
);
4334 if (range
>= frange
)
4336 creatureScriptTarget
= NULL
;
4337 goScriptTarget
= focusObject
;
4343 case SPELL_TARGET_TYPE_CREATURE
:
4344 case SPELL_TARGET_TYPE_DEAD
:
4347 Creature
*p_Creature
= NULL
;
4349 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4351 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4354 MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
u_check(*m_caster
,i_spellST
->second
.targetEntry
,i_spellST
->second
.type
!=SPELL_TARGET_TYPE_DEAD
,range
);
4355 MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
> searcher(m_caster
, p_Creature
, u_check
);
4357 TypeContainerVisitor
<MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
>, GridTypeMapContainer
> grid_creature_searcher(searcher
);
4359 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4360 cell_lock
->Visit(cell_lock
, grid_creature_searcher
, *m_caster
->GetMap(), *m_caster
, range
);
4364 creatureScriptTarget
= p_Creature
;
4365 goScriptTarget
= NULL
;
4366 range
= u_check
.GetLastRange();
4373 if (creatureScriptTarget
)
4375 // store coordinates for TARGET_SCRIPT_COORDINATES
4376 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4377 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4379 m_targets
.setDestination(creatureScriptTarget
->GetPositionX(),creatureScriptTarget
->GetPositionY(),creatureScriptTarget
->GetPositionZ());
4381 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->Effect
[j
] != SPELL_EFFECT_PERSISTENT_AREA_AURA
)
4382 AddUnitTarget(creatureScriptTarget
, j
);
4384 // store explicit target for TARGET_SCRIPT
4387 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
4388 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
)
4389 AddUnitTarget(creatureScriptTarget
, j
);
4392 else if (goScriptTarget
)
4394 // store coordinates for TARGET_SCRIPT_COORDINATES
4395 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4396 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4398 m_targets
.setDestination(goScriptTarget
->GetPositionX(),goScriptTarget
->GetPositionY(),goScriptTarget
->GetPositionZ());
4400 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->Effect
[j
] != SPELL_EFFECT_PERSISTENT_AREA_AURA
)
4401 AddGOTarget(goScriptTarget
, j
);
4403 // store explicit target for TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
4406 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
||
4407 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
)
4408 AddGOTarget(goScriptTarget
, j
);
4411 //Missing DB Entry or targets for this spellEffect.
4414 /* For TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT makes DB targets optional not required for now
4415 * TODO: Makes more research for this target type
4417 if (m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
)
4419 // not report target not existence for triggered spells
4420 if (m_triggeredByAuraSpell
|| m_IsTriggeredSpell
)
4421 return SPELL_FAILED_DONT_REPORT
;
4423 return SPELL_FAILED_BAD_TARGETS
;
4430 if(!m_IsTriggeredSpell
)
4432 SpellCastResult castResult
= CheckRange(strict
);
4433 if(castResult
!= SPELL_CAST_OK
)
4438 SpellCastResult castResult
= CheckPower();
4439 if(castResult
!= SPELL_CAST_OK
)
4443 if(!m_IsTriggeredSpell
) // triggered spell not affected by stun/etc
4445 SpellCastResult castResult
= CheckCasterAuras();
4446 if(castResult
!= SPELL_CAST_OK
)
4450 for (int i
= 0; i
< 3; ++i
)
4452 // for effects of spells that have only one target
4453 switch(m_spellInfo
->Effect
[i
])
4455 case SPELL_EFFECT_INSTAKILL
:
4457 if(m_spellInfo
->Id
== 48743)
4459 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4460 return SPELL_FAILED_ERROR
;
4462 if (!((Player
*)m_caster
)->GetSelection())
4463 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4464 Pet
* target
= m_caster
->GetMap()->GetPet(((Player
*)m_caster
)->GetSelection());
4467 if (!target
|| target
->isDead())
4468 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4470 if (target
->GetCreatureType() != CREATURE_TYPE_UNDEAD
)
4471 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4473 if (target
->GetOwnerGUID() != m_caster
->GetGUID())
4474 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4476 float dist
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4477 if (!target
->IsWithinDistInMap(m_caster
,dist
))
4478 return SPELL_FAILED_OUT_OF_RANGE
;
4480 // will set in target selection code
4483 case SPELL_EFFECT_DUMMY
:
4485 if(m_spellInfo
->SpellIconID
== 1648) // Execute
4487 if(!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4488 return SPELL_FAILED_BAD_TARGETS
;
4490 else if (m_spellInfo
->Id
== 51582) // Rocket Boots Engaged
4492 if(m_caster
->IsInWater())
4493 return SPELL_FAILED_ONLY_ABOVEWATER
;
4495 else if(m_spellInfo
->SpellIconID
== 156) // Holy Shock
4497 // spell different for friends and enemies
4498 // hart version required facing
4499 if(m_targets
.getUnitTarget() && !m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()) && !m_caster
->HasInArc( M_PI
, m_targets
.getUnitTarget() ))
4500 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4504 case SPELL_EFFECT_SCHOOL_DAMAGE
:
4507 if(m_spellInfo
->SpellVisual
[0] == 7250)
4509 if (!m_targets
.getUnitTarget())
4510 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4512 if(m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4513 return SPELL_FAILED_BAD_TARGETS
;
4517 case SPELL_EFFECT_TAMECREATURE
:
4519 // Spell can be triggered, we need to check original caster prior to caster
4520 Unit
* caster
= m_originalCaster
? m_originalCaster
: m_caster
;
4522 if (caster
->GetTypeId() != TYPEID_PLAYER
||
4523 !m_targets
.getUnitTarget() ||
4524 m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
)
4525 return SPELL_FAILED_BAD_TARGETS
;
4527 Player
* plrCaster
= (Player
*)caster
;
4529 if(plrCaster
->getClass() != CLASS_HUNTER
)
4531 plrCaster
->SendPetTameFailure(PETTAME_UNITSCANTTAME
);
4532 return SPELL_FAILED_DONT_REPORT
;
4535 Creature
* target
= (Creature
*)m_targets
.getUnitTarget();
4537 if(target
->isPet() || target
->isCharmed())
4539 plrCaster
->SendPetTameFailure(PETTAME_CREATUREALREADYOWNED
);
4540 return SPELL_FAILED_DONT_REPORT
;
4543 if (target
->getLevel() > plrCaster
->getLevel())
4545 plrCaster
->SendPetTameFailure(PETTAME_TOOHIGHLEVEL
);
4546 return SPELL_FAILED_DONT_REPORT
;
4549 if (target
->GetCreatureInfo()->IsExotic() && !plrCaster
->CanTameExoticPets())
4551 plrCaster
->SendPetTameFailure(PETTAME_CANTCONTROLEXOTIC
);
4552 return SPELL_FAILED_DONT_REPORT
;
4555 if (!target
->GetCreatureInfo()->isTameable(plrCaster
->CanTameExoticPets()))
4557 plrCaster
->SendPetTameFailure(PETTAME_NOTTAMEABLE
);
4558 return SPELL_FAILED_DONT_REPORT
;
4561 if(plrCaster
->GetPetGUID() || plrCaster
->GetCharmGUID())
4563 plrCaster
->SendPetTameFailure(PETTAME_ANOTHERSUMMONACTIVE
);
4564 return SPELL_FAILED_DONT_REPORT
;
4569 case SPELL_EFFECT_LEARN_SPELL
:
4571 if(m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_PET
)
4574 Pet
* pet
= m_caster
->GetPet();
4577 return SPELL_FAILED_NO_PET
;
4579 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4581 if(!learn_spellproto
)
4582 return SPELL_FAILED_NOT_KNOWN
;
4584 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4585 return SPELL_FAILED_LOWLEVEL
;
4589 case SPELL_EFFECT_LEARN_PET_SPELL
:
4591 Pet
* pet
= m_caster
->GetPet();
4594 return SPELL_FAILED_NO_PET
;
4596 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4598 if(!learn_spellproto
)
4599 return SPELL_FAILED_NOT_KNOWN
;
4601 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4602 return SPELL_FAILED_LOWLEVEL
;
4606 case SPELL_EFFECT_APPLY_GLYPH
:
4608 uint32 glyphId
= m_spellInfo
->EffectMiscValue
[i
];
4609 if(GlyphPropertiesEntry
const *gp
= sGlyphPropertiesStore
.LookupEntry(glyphId
))
4610 if(m_caster
->HasAura(gp
->SpellId
))
4611 return SPELL_FAILED_UNIQUE_GLYPH
;
4614 case SPELL_EFFECT_FEED_PET
:
4616 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4617 return SPELL_FAILED_BAD_TARGETS
;
4619 Item
* foodItem
= m_targets
.getItemTarget();
4621 return SPELL_FAILED_BAD_TARGETS
;
4623 Pet
* pet
= m_caster
->GetPet();
4626 return SPELL_FAILED_NO_PET
;
4628 if(!pet
->HaveInDiet(foodItem
->GetProto()))
4629 return SPELL_FAILED_WRONG_PET_FOOD
;
4631 if(!pet
->GetCurrentFoodBenefitLevel(foodItem
->GetProto()->ItemLevel
))
4632 return SPELL_FAILED_FOOD_LOWLEVEL
;
4634 if(m_caster
->isInCombat() || pet
->isInCombat())
4635 return SPELL_FAILED_AFFECTING_COMBAT
;
4639 case SPELL_EFFECT_POWER_BURN
:
4640 case SPELL_EFFECT_POWER_DRAIN
:
4642 // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
4643 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4644 if(Unit
* target
= m_targets
.getUnitTarget())
4645 if(target
!= m_caster
&& target
->getPowerType() != m_spellInfo
->EffectMiscValue
[i
])
4646 return SPELL_FAILED_BAD_TARGETS
;
4649 case SPELL_EFFECT_CHARGE
:
4651 if (m_caster
->hasUnitState(UNIT_STAT_ROOT
))
4652 return SPELL_FAILED_ROOTED
;
4656 case SPELL_EFFECT_SKINNING
:
4658 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() != TYPEID_UNIT
)
4659 return SPELL_FAILED_BAD_TARGETS
;
4661 if( !(m_targets
.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS
) & UNIT_FLAG_SKINNABLE
) )
4662 return SPELL_FAILED_TARGET_UNSKINNABLE
;
4664 Creature
* creature
= (Creature
*)m_targets
.getUnitTarget();
4665 if ( creature
->GetCreatureType() != CREATURE_TYPE_CRITTER
&& ( !creature
->lootForBody
|| !creature
->loot
.empty() ) )
4667 return SPELL_FAILED_TARGET_NOT_LOOTED
;
4670 uint32 skill
= creature
->GetCreatureInfo()->GetRequiredLootSkill();
4672 int32 skillValue
= ((Player
*)m_caster
)->GetSkillValue(skill
);
4673 int32 TargetLevel
= m_targets
.getUnitTarget()->getLevel();
4674 int32 ReqValue
= (skillValue
< 100 ? (TargetLevel
-10) * 10 : TargetLevel
* 5);
4675 if (ReqValue
> skillValue
)
4676 return SPELL_FAILED_LOW_CASTLEVEL
;
4678 // chance for fail at orange skinning attempt
4679 if( (m_selfContainer
&& (*m_selfContainer
) == this) &&
4680 skillValue
< sWorld
.GetConfigMaxSkillValue() &&
4681 (ReqValue
< 0 ? 0 : ReqValue
) > irand(skillValue
- 25, skillValue
+ 37) )
4682 return SPELL_FAILED_TRY_AGAIN
;
4686 case SPELL_EFFECT_OPEN_LOCK
:
4688 if( m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT
&&
4689 m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT_ITEM
)
4692 if( m_caster
->GetTypeId() != TYPEID_PLAYER
// only players can open locks, gather etc.
4693 // we need a go target in case of TARGET_GAMEOBJECT
4694 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT
&& !m_targets
.getGOTarget()
4695 // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM
4696 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT_ITEM
&& !m_targets
.getGOTarget() &&
4697 (!m_targets
.getItemTarget() || !m_targets
.getItemTarget()->GetProto()->LockID
|| m_targets
.getItemTarget()->GetOwner() != m_caster
) )
4698 return SPELL_FAILED_BAD_TARGETS
;
4700 // In BattleGround players can use only flags and banners
4701 if( ((Player
*)m_caster
)->InBattleGround() &&
4702 !((Player
*)m_caster
)->CanUseBattleGroundObject() )
4703 return SPELL_FAILED_TRY_AGAIN
;
4705 // get the lock entry
4707 if (GameObject
* go
= m_targets
.getGOTarget())
4709 lockId
= go
->GetGOInfo()->GetLockId();
4711 return SPELL_FAILED_BAD_TARGETS
;
4713 else if(Item
* itm
= m_targets
.getItemTarget())
4714 lockId
= itm
->GetProto()->LockID
;
4716 SkillType skillId
= SKILL_NONE
;
4717 int32 reqSkillValue
= 0;
4718 int32 skillValue
= 0;
4720 // check lock compatibility
4721 SpellCastResult res
= CanOpenLock(i
, lockId
, skillId
, reqSkillValue
, skillValue
);
4722 if(res
!= SPELL_CAST_OK
)
4725 // chance for fail at orange mining/herb/LockPicking gathering attempt
4726 // second check prevent fail at rechecks
4727 if(skillId
!= SKILL_NONE
&& (!m_selfContainer
|| ((*m_selfContainer
) != this)))
4729 bool canFailAtMax
= skillId
!= SKILL_HERBALISM
&& skillId
!= SKILL_MINING
;
4731 // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill)
4732 if((canFailAtMax
|| skillValue
< sWorld
.GetConfigMaxSkillValue()) && reqSkillValue
> irand(skillValue
- 25, skillValue
+ 37))
4733 return SPELL_FAILED_TRY_AGAIN
;
4737 case SPELL_EFFECT_SUMMON_DEAD_PET
:
4739 Creature
*pet
= m_caster
->GetPet();
4741 return SPELL_FAILED_NO_PET
;
4744 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4748 // This is generic summon effect
4749 case SPELL_EFFECT_SUMMON
:
4751 if(SummonPropertiesEntry
const *summon_prop
= sSummonPropertiesStore
.LookupEntry(m_spellInfo
->EffectMiscValueB
[i
]))
4753 if(summon_prop
->Group
== SUMMON_PROP_GROUP_PETS
)
4755 if(m_caster
->GetPetGUID())
4756 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4758 if(m_caster
->GetCharmGUID())
4759 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4763 // Not used for summon?
4764 case SPELL_EFFECT_SUMMON_PHANTASM
:
4766 if(m_caster
->GetPetGUID())
4767 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4769 if(m_caster
->GetCharmGUID())
4770 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4774 case SPELL_EFFECT_SUMMON_PET
:
4776 if(m_caster
->GetPetGUID()) //let warlock do a replacement summon
4779 Pet
* pet
= ((Player
*)m_caster
)->GetPet();
4781 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->getClass() == CLASS_WARLOCK
)
4783 if (strict
) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
4784 pet
->CastSpell(pet
, 32752, true, NULL
, NULL
, pet
->GetGUID());
4787 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4790 if(m_caster
->GetCharmGUID())
4791 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4795 case SPELL_EFFECT_SUMMON_PLAYER
:
4797 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4798 return SPELL_FAILED_BAD_TARGETS
;
4799 if(!((Player
*)m_caster
)->GetSelection())
4800 return SPELL_FAILED_BAD_TARGETS
;
4802 Player
* target
= sObjectMgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
4803 if( !target
|| ((Player
*)m_caster
) == target
|| !target
->IsInSameRaidWith((Player
*)m_caster
) )
4804 return SPELL_FAILED_BAD_TARGETS
;
4806 // check if our map is dungeon
4807 if( sMapStore
.LookupEntry(m_caster
->GetMapId())->IsDungeon() )
4809 InstanceTemplate
const* instance
= ObjectMgr::GetInstanceTemplate(m_caster
->GetMapId());
4811 return SPELL_FAILED_TARGET_NOT_IN_INSTANCE
;
4812 if ( instance
->levelMin
> target
->getLevel() )
4813 return SPELL_FAILED_LOWLEVEL
;
4814 if ( instance
->levelMax
&& instance
->levelMax
< target
->getLevel() )
4815 return SPELL_FAILED_HIGHLEVEL
;
4819 case SPELL_EFFECT_LEAP
:
4820 case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
:
4822 float dis
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4823 float fx
= m_caster
->GetPositionX() + dis
* cos(m_caster
->GetOrientation());
4824 float fy
= m_caster
->GetPositionY() + dis
* sin(m_caster
->GetOrientation());
4825 // teleport a bit above terrain level to avoid falling below it
4826 float fz
= m_caster
->GetBaseMap()->GetHeight(fx
,fy
,m_caster
->GetPositionZ(),true);
4827 if(fz
<= INVALID_HEIGHT
) // note: this also will prevent use effect in instances without vmaps height enabled
4828 return SPELL_FAILED_TRY_AGAIN
;
4830 float caster_pos_z
= m_caster
->GetPositionZ();
4831 // Control the caster to not climb or drop when +-fz > 8
4832 if(!(fz
<= caster_pos_z
+ 8 && fz
>= caster_pos_z
- 8))
4833 return SPELL_FAILED_TRY_AGAIN
;
4835 // not allow use this effect at battleground until battleground start
4836 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4837 if(BattleGround
const *bg
= ((Player
*)m_caster
)->GetBattleGround())
4838 if(bg
->GetStatus() != STATUS_IN_PROGRESS
)
4839 return SPELL_FAILED_TRY_AGAIN
;
4842 case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF
:
4844 if (m_targets
.getUnitTarget() == m_caster
)
4845 return SPELL_FAILED_BAD_TARGETS
;
4852 for (int i
= 0; i
< 3; ++i
)
4854 switch(m_spellInfo
->EffectApplyAuraName
[i
])
4856 case SPELL_AURA_DUMMY
:
4859 switch(m_spellInfo
->Id
)
4862 if(m_caster
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)m_caster
)->IsInFeralForm())
4863 return SPELL_FAILED_ONLY_SHAPESHIFT
;
4870 case SPELL_AURA_MOD_POSSESS
:
4872 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4873 return SPELL_FAILED_UNKNOWN
;
4875 if(m_targets
.getUnitTarget() == m_caster
)
4876 return SPELL_FAILED_BAD_TARGETS
;
4878 if(m_caster
->GetPetGUID())
4879 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4881 if(m_caster
->GetCharmGUID())
4882 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4884 if(m_caster
->GetCharmerGUID())
4885 return SPELL_FAILED_CHARMED
;
4887 if(!m_targets
.getUnitTarget())
4888 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4890 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4891 return SPELL_FAILED_CHARMED
;
4893 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
4894 return SPELL_FAILED_HIGHLEVEL
;
4898 case SPELL_AURA_MOD_CHARM
:
4900 if(m_targets
.getUnitTarget() == m_caster
)
4901 return SPELL_FAILED_BAD_TARGETS
;
4903 if(m_caster
->GetPetGUID())
4904 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4906 if(m_caster
->GetCharmGUID())
4907 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4909 if(m_caster
->GetCharmerGUID())
4910 return SPELL_FAILED_CHARMED
;
4912 if(!m_targets
.getUnitTarget())
4913 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4915 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4916 return SPELL_FAILED_CHARMED
;
4918 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
4919 return SPELL_FAILED_HIGHLEVEL
;
4923 case SPELL_AURA_MOD_POSSESS_PET
:
4925 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4926 return SPELL_FAILED_UNKNOWN
;
4928 if(m_caster
->GetCharmGUID())
4929 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4931 if(m_caster
->GetCharmerGUID())
4932 return SPELL_FAILED_CHARMED
;
4934 Pet
* pet
= m_caster
->GetPet();
4936 return SPELL_FAILED_NO_PET
;
4938 if(pet
->GetCharmerGUID())
4939 return SPELL_FAILED_CHARMED
;
4943 case SPELL_AURA_MOUNTED
:
4945 if (m_caster
->IsInWater())
4946 return SPELL_FAILED_ONLY_ABOVEWATER
;
4948 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetTransport())
4949 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4951 // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
4952 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& !sMapStore
.LookupEntry(m_caster
->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell
&& !m_spellInfo
->AreaGroupId
)
4953 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4955 ShapeshiftForm form
= m_caster
->m_form
;
4956 if( form
== FORM_CAT
|| form
== FORM_TREE
|| form
== FORM_TRAVEL
||
4957 form
== FORM_AQUA
|| form
== FORM_BEAR
|| form
== FORM_DIREBEAR
||
4958 form
== FORM_CREATUREBEAR
|| form
== FORM_GHOSTWOLF
|| form
== FORM_FLIGHT
||
4959 form
== FORM_FLIGHT_EPIC
|| form
== FORM_MOONKIN
|| form
== FORM_METAMORPHOSIS
)
4960 return SPELL_FAILED_NOT_SHAPESHIFT
;
4964 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
4966 if(!m_targets
.getUnitTarget())
4967 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4969 // can be casted at non-friendly unit or own pet/charm
4970 if(m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()))
4971 return SPELL_FAILED_TARGET_FRIENDLY
;
4975 case SPELL_AURA_FLY
:
4976 case SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
:
4978 // not allow cast fly spells if not have req. skills (all spells is self target)
4979 // allow always ghost flight spells
4980 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->isAlive())
4982 if (!((Player
*)m_caster
)->IsKnowHowFlyIn(m_caster
->GetMapId(),zone
))
4983 return m_IsTriggeredSpell
? SPELL_FAILED_DONT_REPORT
: SPELL_FAILED_NOT_HERE
;
4987 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4989 if (!m_targets
.getUnitTarget())
4990 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4992 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| m_CastItem
)
4995 if(m_targets
.getUnitTarget()->getPowerType() != POWER_MANA
)
4996 return SPELL_FAILED_BAD_TARGETS
;
5006 return SPELL_CAST_OK
;
5009 SpellCastResult
Spell::CheckPetCast(Unit
* target
)
5011 if(!m_caster
->isAlive())
5012 return SPELL_FAILED_CASTER_DEAD
;
5014 if(m_caster
->IsNonMeleeSpellCasted(false)) //prevent spellcast interruption by another spellcast
5015 return SPELL_FAILED_SPELL_IN_PROGRESS
;
5016 if(m_caster
->isInCombat() && IsNonCombatSpell(m_spellInfo
))
5017 return SPELL_FAILED_AFFECTING_COMBAT
;
5019 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)m_caster
)->isPet() || m_caster
->isCharmed()))
5021 //dead owner (pets still alive when owners ressed?)
5022 if(m_caster
->GetCharmerOrOwner() && !m_caster
->GetCharmerOrOwner()->isAlive())
5023 return SPELL_FAILED_CASTER_DEAD
;
5025 if(!target
&& m_targets
.getUnitTarget())
5026 target
= m_targets
.getUnitTarget();
5029 for(uint32 i
= 0; i
< 3; ++i
)
5031 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CHAIN_DAMAGE
||
5032 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND
||
5033 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND_2
||
5034 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_DUELVSPLAYER
||
5035 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_PARTY
||
5036 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CURRENT_ENEMY_COORDINATES
)
5040 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
5045 m_targets
.setUnitTarget(target
);
5047 Unit
* _target
= m_targets
.getUnitTarget();
5049 if(_target
) //for target dead/target not valid
5051 if(!_target
->isAlive())
5052 return SPELL_FAILED_BAD_TARGETS
;
5054 if(IsPositiveSpell(m_spellInfo
->Id
))
5056 if(m_caster
->IsHostileTo(_target
))
5057 return SPELL_FAILED_BAD_TARGETS
;
5061 bool duelvsplayertar
= false;
5062 for(int j
= 0; j
< 3; ++j
)
5064 //TARGET_DUELVSPLAYER is positive AND negative
5065 duelvsplayertar
|= (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
);
5067 if(m_caster
->IsFriendlyTo(target
) && !duelvsplayertar
)
5069 return SPELL_FAILED_BAD_TARGETS
;
5074 if(((Creature
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
5075 return SPELL_FAILED_NOT_READY
;
5078 return CheckCast(true);
5081 SpellCastResult
Spell::CheckCasterAuras() const
5083 // Flag drop spells totally immuned to caster auras
5084 // FIXME: find more nice check for all totally immuned spells
5085 // AttributesEx3 & 0x10000000?
5086 if(m_spellInfo
->Id
== 23336 || m_spellInfo
->Id
== 23334 || m_spellInfo
->Id
== 34991)
5087 return SPELL_CAST_OK
;
5089 uint8 school_immune
= 0;
5090 uint32 mechanic_immune
= 0;
5091 uint32 dispel_immune
= 0;
5093 // Check if the spell grants school or mechanic immunity.
5094 // We use bitmasks so the loop is done only once and not on every aura check below.
5095 if ( m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
5097 for(int i
= 0; i
< 3; ++i
)
5099 if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_SCHOOL_IMMUNITY
)
5100 school_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
5101 else if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY
)
5102 mechanic_immune
|= 1 << uint32(m_spellInfo
->EffectMiscValue
[i
]-1);
5103 else if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY_MASK
)
5104 mechanic_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
5105 else if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_DISPEL_IMMUNITY
)
5106 dispel_immune
|= GetDispellMask(DispelType(m_spellInfo
->EffectMiscValue
[i
]));
5108 // immune movement impairment and loss of control
5109 if (m_spellInfo
->Id
== 42292)
5110 mechanic_immune
= IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK
;
5113 // Check whether the cast should be prevented by any state you might have.
5114 SpellCastResult prevented_reason
= SPELL_CAST_OK
;
5115 // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
5116 uint32 unitflag
= m_caster
->GetUInt32Value(UNIT_FIELD_FLAGS
); // Get unit state
5117 if (unitflag
& UNIT_FLAG_STUNNED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
5118 prevented_reason
= SPELL_FAILED_STUNNED
;
5119 else if (unitflag
& UNIT_FLAG_CONFUSED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
5120 prevented_reason
= SPELL_FAILED_CONFUSED
;
5121 else if (unitflag
& UNIT_FLAG_FLEEING
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
5122 prevented_reason
= SPELL_FAILED_FLEEING
;
5123 else if (unitflag
& UNIT_FLAG_SILENCED
&& m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
)
5124 prevented_reason
= SPELL_FAILED_SILENCED
;
5125 else if (unitflag
& UNIT_FLAG_PACIFIED
&& m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
)
5126 prevented_reason
= SPELL_FAILED_PACIFIED
;
5127 else if(m_caster
->HasAuraType(SPELL_AURA_ALLOW_ONLY_ABILITY
))
5129 Unit::AuraList
const& casingLimit
= m_caster
->GetAurasByType(SPELL_AURA_ALLOW_ONLY_ABILITY
);
5130 for(Unit::AuraList::const_iterator itr
= casingLimit
.begin(); itr
!= casingLimit
.end(); ++itr
)
5132 if(!IsAffectedByAura(*itr
))
5134 prevented_reason
= SPELL_FAILED_CASTER_AURASTATE
;
5140 // Attr must make flag drop spell totally immune from all effects
5141 if (prevented_reason
!= SPELL_CAST_OK
)
5143 if (school_immune
|| mechanic_immune
|| dispel_immune
)
5145 //Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
5146 Unit::AuraMap
const& auras
= m_caster
->GetAuras();
5147 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
5151 if (GetSpellMechanicMask(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()) & mechanic_immune
)
5153 if (GetSpellSchoolMask(itr
->second
->GetSpellProto()) & school_immune
)
5155 if ((1<<(itr
->second
->GetSpellProto()->Dispel
)) & dispel_immune
)
5158 // Make a second check for spell failed so the right SPELL_FAILED message is returned.
5159 // That is needed when your casting is prevented by multiple states and you are only immune to some of them.
5160 switch(itr
->second
->GetModifier()->m_auraname
)
5162 case SPELL_AURA_MOD_STUN
:
5163 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
5164 return SPELL_FAILED_STUNNED
;
5166 case SPELL_AURA_MOD_CONFUSE
:
5167 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
5168 return SPELL_FAILED_CONFUSED
;
5170 case SPELL_AURA_MOD_FEAR
:
5171 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
5172 return SPELL_FAILED_FLEEING
;
5174 case SPELL_AURA_MOD_SILENCE
:
5175 case SPELL_AURA_MOD_PACIFY
:
5176 case SPELL_AURA_MOD_PACIFY_SILENCE
:
5177 if( m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
)
5178 return SPELL_FAILED_PACIFIED
;
5179 else if ( m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
)
5180 return SPELL_FAILED_SILENCED
;
5187 // You are prevented from casting and the spell casted does not grant immunity. Return a failed error.
5189 return prevented_reason
;
5191 return SPELL_CAST_OK
;
5194 bool Spell::CanAutoCast(Unit
* target
)
5196 uint64 targetguid
= target
->GetGUID();
5198 for(uint32 j
= 0; j
< 3; ++j
)
5200 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
)
5202 if( m_spellInfo
->StackAmount
<= 1)
5204 if( target
->HasAura(m_spellInfo
->Id
, j
) )
5209 if(Aura
* aura
= target
->GetAura(m_spellInfo
->Id
, j
))
5210 if(aura
->GetStackAmount() >= m_spellInfo
->StackAmount
)
5214 else if ( IsAreaAuraEffect( m_spellInfo
->Effect
[j
] ))
5216 if( target
->HasAura(m_spellInfo
->Id
, j
) )
5221 SpellCastResult result
= CheckPetCast(target
);
5223 if(result
== SPELL_CAST_OK
|| result
== SPELL_FAILED_UNIT_NOT_INFRONT
)
5226 //check if among target units, our WANTED target is as well (->only self cast spells return false)
5227 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
5228 if( ihit
->targetGUID
== targetguid
)
5231 return false; //target invalid
5234 SpellCastResult
Spell::CheckRange(bool strict
)
5238 // self cast doesn't need range checking -- also for Starshards fix
5239 if (m_spellInfo
->rangeIndex
== 1)
5240 return SPELL_CAST_OK
;
5242 if (strict
) //add radius of caster
5244 else //add radius of caster and ~5 yds "give"
5247 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
5248 Unit
*target
= m_targets
.getUnitTarget();
5249 bool friendly
= target
? target
->IsFriendlyTo(m_caster
) : false;
5250 float max_range
= GetSpellMaxRange(srange
, friendly
) + range_mod
;
5251 float min_range
= GetSpellMinRange(srange
, friendly
);
5253 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
5254 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RANGE
, max_range
, this);
5256 if(target
&& target
!= m_caster
)
5258 // distance from target in checks
5259 float dist
= m_caster
->GetCombatDistance(target
);
5261 if(dist
> max_range
)
5262 return SPELL_FAILED_OUT_OF_RANGE
; //0x5A;
5263 if(min_range
&& dist
< min_range
)
5264 return SPELL_FAILED_TOO_CLOSE
;
5265 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&&
5266 (m_spellInfo
->FacingCasterFlags
& SPELL_FACING_FLAG_INFRONT
) && !m_caster
->HasInArc( M_PI
, target
) )
5267 return SPELL_FAILED_UNIT_NOT_INFRONT
;
5270 if(m_targets
.m_targetMask
== TARGET_FLAG_DEST_LOCATION
&& m_targets
.m_destX
!= 0 && m_targets
.m_destY
!= 0 && m_targets
.m_destZ
!= 0)
5272 if(!m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
, max_range
))
5273 return SPELL_FAILED_OUT_OF_RANGE
;
5274 if(min_range
&& m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
, min_range
))
5275 return SPELL_FAILED_TOO_CLOSE
;
5278 return SPELL_CAST_OK
;
5281 int32
Spell::CalculatePowerCost()
5283 // item cast not used power
5287 // Spell drain all exist power on cast (Only paladin lay of Hands)
5288 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DRAIN_ALL_POWER
)
5290 // If power type - health drain all
5291 if (m_spellInfo
->powerType
== POWER_HEALTH
)
5292 return m_caster
->GetHealth();
5293 // Else drain all power
5294 if (m_spellInfo
->powerType
< MAX_POWERS
)
5295 return m_caster
->GetPower(Powers(m_spellInfo
->powerType
));
5296 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
5301 int32 powerCost
= m_spellInfo
->manaCost
;
5302 // PCT cost from total amount
5303 if (m_spellInfo
->ManaCostPercentage
)
5305 switch (m_spellInfo
->powerType
)
5307 // health as power used
5309 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateHealth() / 100;
5312 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateMana() / 100;
5317 case POWER_HAPPINESS
:
5318 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetMaxPower(Powers(m_spellInfo
->powerType
)) / 100;
5321 case POWER_RUNIC_POWER
:
5322 sLog
.outDebug("Spell::CalculateManaCost: Not implemented yet!");
5325 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
5329 SpellSchools school
= GetFirstSchoolInMask(m_spellSchoolMask
);
5330 // Flat mod from caster auras by spell school
5331 powerCost
+= m_caster
->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER
+ school
);
5332 // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
5333 if ( m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST
)
5334 powerCost
+= m_caster
->GetAttackTime(OFF_ATTACK
)/100;
5335 // Apply cost mod by spell
5336 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
5337 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, powerCost
, this);
5339 if(m_spellInfo
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
)
5340 powerCost
= int32(powerCost
/ (1.117f
* m_spellInfo
->spellLevel
/ m_caster
->getLevel() -0.1327f
));
5342 // PCT mod from user auras by school
5343 powerCost
= int32(powerCost
* (1.0f
+m_caster
->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+school
)));
5349 SpellCastResult
Spell::CheckPower()
5351 // item cast not used power
5353 return SPELL_CAST_OK
;
5355 // Do precise power regen on spell cast
5356 if (m_powerCost
> 0 && m_caster
->GetTypeId() == TYPEID_PLAYER
)
5358 Player
* playerCaster
= (Player
*)m_caster
;
5359 uint32 diff
= REGEN_TIME_FULL
- m_caster
->GetRegenTimer();
5360 if (diff
>= REGEN_TIME_PRECISE
)
5361 playerCaster
->RegenerateAll(diff
);
5364 // health as power used - need check health amount
5365 if(m_spellInfo
->powerType
== POWER_HEALTH
)
5367 if(m_caster
->GetHealth() <= m_powerCost
)
5368 return SPELL_FAILED_CASTER_AURASTATE
;
5369 return SPELL_CAST_OK
;
5371 // Check valid power type
5372 if( m_spellInfo
->powerType
>= MAX_POWERS
)
5374 sLog
.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo
->powerType
);
5375 return SPELL_FAILED_UNKNOWN
;
5378 //check rune cost only if a spell has PowerType == POWER_RUNE
5379 if(m_spellInfo
->powerType
== POWER_RUNE
)
5381 SpellCastResult failReason
= CheckRuneCost(m_spellInfo
->runeCostID
);
5382 if(failReason
!= SPELL_CAST_OK
)
5386 // Check power amount
5387 Powers powerType
= Powers(m_spellInfo
->powerType
);
5388 if(m_caster
->GetPower(powerType
) < m_powerCost
)
5389 return SPELL_FAILED_NO_POWER
;
5391 return SPELL_CAST_OK
;
5394 SpellCastResult
Spell::CheckItems()
5396 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
5397 return SPELL_CAST_OK
;
5399 Player
* p_caster
= (Player
*)m_caster
;
5404 uint32 itemid
= m_CastItem
->GetEntry();
5405 if( !p_caster
->HasItemCount(itemid
, 1) )
5406 return SPELL_FAILED_ITEM_NOT_FOUND
;
5408 ItemPrototype
const *proto
= m_CastItem
->GetProto();
5410 return SPELL_FAILED_ITEM_NOT_FOUND
;
5412 for (int i
= 0; i
< 5; ++i
)
5413 if (proto
->Spells
[i
].SpellCharges
)
5414 if(m_CastItem
->GetSpellCharges(i
) == 0)
5415 return SPELL_FAILED_NO_CHARGES_REMAIN
;
5417 // consumable cast item checks
5418 if (proto
->Class
== ITEM_CLASS_CONSUMABLE
&& m_targets
.getUnitTarget())
5420 // such items should only fail if there is no suitable effect at all - see Rejuvenation Potions for example
5421 SpellCastResult failReason
= SPELL_CAST_OK
;
5422 for (int i
= 0; i
< 3; ++i
)
5424 // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster
5425 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_PET
)
5428 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_HEAL
)
5430 if (m_targets
.getUnitTarget()->GetHealth() == m_targets
.getUnitTarget()->GetMaxHealth())
5432 failReason
= SPELL_FAILED_ALREADY_AT_FULL_HEALTH
;
5437 failReason
= SPELL_CAST_OK
;
5442 // Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
5443 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
5445 if(m_spellInfo
->EffectMiscValue
[i
] < 0 || m_spellInfo
->EffectMiscValue
[i
] >= MAX_POWERS
)
5447 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
5451 Powers power
= Powers(m_spellInfo
->EffectMiscValue
[i
]);
5452 if (m_targets
.getUnitTarget()->GetPower(power
) == m_targets
.getUnitTarget()->GetMaxPower(power
))
5454 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
5459 failReason
= SPELL_CAST_OK
;
5464 if (failReason
!= SPELL_CAST_OK
)
5469 // check target item
5470 if(m_targets
.getItemTargetGUID())
5472 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
5473 return SPELL_FAILED_BAD_TARGETS
;
5475 if(!m_targets
.getItemTarget())
5476 return SPELL_FAILED_ITEM_GONE
;
5478 if(!m_targets
.getItemTarget()->IsFitToSpellRequirements(m_spellInfo
))
5479 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
5481 // if not item target then required item must be equipped
5484 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !((Player
*)m_caster
)->HasItemFitToSpellReqirements(m_spellInfo
))
5485 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
5488 // check spell focus object
5489 if(m_spellInfo
->RequiresSpellFocus
)
5491 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
5493 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5495 GameObject
* ok
= NULL
;
5496 MaNGOS::GameObjectFocusCheck
go_check(m_caster
,m_spellInfo
->RequiresSpellFocus
);
5497 MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
> checker(m_caster
, ok
, go_check
);
5499 TypeContainerVisitor
<MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
>, GridTypeMapContainer
> object_checker(checker
);
5500 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5501 Map
& map
= *m_caster
->GetMap();
5502 cell_lock
->Visit(cell_lock
, object_checker
, map
, *m_caster
, map
.GetVisibilityDistance());
5505 return SPELL_FAILED_REQUIRES_SPELL_FOCUS
;
5507 focusObject
= ok
; // game object found in range
5510 // check reagents (ignore triggered spells with reagents processed by original spell) and special reagent ignore case.
5511 if (!m_IsTriggeredSpell
&& !p_caster
->CanNoReagentCast(m_spellInfo
))
5513 for(uint32 i
= 0; i
< 8; ++i
)
5515 if(m_spellInfo
->Reagent
[i
] <= 0)
5518 uint32 itemid
= m_spellInfo
->Reagent
[i
];
5519 uint32 itemcount
= m_spellInfo
->ReagentCount
[i
];
5521 // if CastItem is also spell reagent
5522 if( m_CastItem
&& m_CastItem
->GetEntry() == itemid
)
5524 ItemPrototype
const *proto
= m_CastItem
->GetProto();
5526 return SPELL_FAILED_REAGENTS
;
5527 for(int s
= 0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
5529 // CastItem will be used up and does not count as reagent
5530 int32 charges
= m_CastItem
->GetSpellCharges(s
);
5531 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
5538 if( !p_caster
->HasItemCount(itemid
, itemcount
) )
5539 return SPELL_FAILED_REAGENTS
;
5543 // check totem-item requirements (items presence in inventory)
5545 for(int i
= 0; i
< 2 ; ++i
)
5547 if(m_spellInfo
->Totem
[i
] != 0)
5549 if( p_caster
->HasItemCount(m_spellInfo
->Totem
[i
], 1) )
5558 return SPELL_FAILED_TOTEMS
; //0x7C
5560 // Check items for TotemCategory (items presence in inventory)
5561 uint32 TotemCategory
= 2;
5562 for(int i
= 0; i
< 2; ++i
)
5564 if(m_spellInfo
->TotemCategory
[i
] != 0)
5566 if( p_caster
->HasItemTotemCategory(m_spellInfo
->TotemCategory
[i
]) )
5575 if(TotemCategory
!= 0)
5576 return SPELL_FAILED_TOTEM_CATEGORY
; //0x7B
5578 // special checks for spell effects
5579 for(int i
= 0; i
< 3; ++i
)
5581 switch (m_spellInfo
->Effect
[i
])
5583 case SPELL_EFFECT_CREATE_ITEM
:
5585 if (!m_IsTriggeredSpell
&& m_spellInfo
->EffectItemType
[i
])
5587 ItemPosCountVec dest
;
5588 uint8 msg
= p_caster
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, m_spellInfo
->EffectItemType
[i
], 1 );
5589 if (msg
!= EQUIP_ERR_OK
)
5591 p_caster
->SendEquipError( msg
, NULL
, NULL
);
5592 return SPELL_FAILED_DONT_REPORT
;
5597 case SPELL_EFFECT_ENCHANT_ITEM
:
5598 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
5600 Item
* targetItem
= m_targets
.getItemTarget();
5602 return SPELL_FAILED_ITEM_NOT_FOUND
;
5604 if( targetItem
->GetProto()->ItemLevel
< m_spellInfo
->baseLevel
)
5605 return SPELL_FAILED_LOWLEVEL
;
5606 // Not allow enchant in trade slot for some enchant type
5607 if( targetItem
->GetOwner() != m_caster
)
5609 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5610 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5612 return SPELL_FAILED_ERROR
;
5613 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5614 return SPELL_FAILED_NOT_TRADEABLE
;
5618 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
5620 Item
*item
= m_targets
.getItemTarget();
5622 return SPELL_FAILED_ITEM_NOT_FOUND
;
5623 // Not allow enchant in trade slot for some enchant type
5624 if( item
->GetOwner() != m_caster
)
5626 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5627 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5629 return SPELL_FAILED_ERROR
;
5630 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5631 return SPELL_FAILED_NOT_TRADEABLE
;
5635 case SPELL_EFFECT_ENCHANT_HELD_ITEM
:
5636 // check item existence in effect code (not output errors at offhand hold item effect to main hand for example
5638 case SPELL_EFFECT_DISENCHANT
:
5640 if(!m_targets
.getItemTarget())
5641 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5643 // prevent disenchanting in trade slot
5644 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5645 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5647 ItemPrototype
const* itemProto
= m_targets
.getItemTarget()->GetProto();
5649 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5651 uint32 item_quality
= itemProto
->Quality
;
5652 // 2.0.x addon: Check player enchanting level against the item disenchanting requirements
5653 uint32 item_disenchantskilllevel
= itemProto
->RequiredDisenchantSkill
;
5654 if (item_disenchantskilllevel
== uint32(-1))
5655 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5656 if (item_disenchantskilllevel
> p_caster
->GetSkillValue(SKILL_ENCHANTING
))
5657 return SPELL_FAILED_LOW_CASTLEVEL
;
5658 if(item_quality
> 4 || item_quality
< 2)
5659 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5660 if(itemProto
->Class
!= ITEM_CLASS_WEAPON
&& itemProto
->Class
!= ITEM_CLASS_ARMOR
)
5661 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5662 if (!itemProto
->DisenchantID
)
5663 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5666 case SPELL_EFFECT_PROSPECTING
:
5668 if(!m_targets
.getItemTarget())
5669 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5670 //ensure item is a prospectable ore
5671 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_MINING_SUPP
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5672 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5673 //prevent prospecting in trade slot
5674 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5675 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5676 //Check for enough skill in jewelcrafting
5677 uint32 item_prospectingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5678 if(item_prospectingskilllevel
>p_caster
->GetSkillValue(SKILL_JEWELCRAFTING
))
5679 return SPELL_FAILED_LOW_CASTLEVEL
;
5680 //make sure the player has the required ores in inventory
5681 if(m_targets
.getItemTarget()->GetCount() < 5)
5682 return SPELL_FAILED_NEED_MORE_ITEMS
;
5684 if(!LootTemplates_Prospecting
.HaveLootFor(m_targets
.getItemTargetEntry()))
5685 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5689 case SPELL_EFFECT_MILLING
:
5691 if(!m_targets
.getItemTarget())
5692 return SPELL_FAILED_CANT_BE_MILLED
;
5693 //ensure item is a millable herb
5694 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_HERBS
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5695 return SPELL_FAILED_CANT_BE_MILLED
;
5696 //prevent milling in trade slot
5697 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5698 return SPELL_FAILED_CANT_BE_MILLED
;
5699 //Check for enough skill in inscription
5700 uint32 item_millingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5701 if(item_millingskilllevel
>p_caster
->GetSkillValue(SKILL_INSCRIPTION
))
5702 return SPELL_FAILED_LOW_CASTLEVEL
;
5703 //make sure the player has the required herbs in inventory
5704 if(m_targets
.getItemTarget()->GetCount() < 5)
5705 return SPELL_FAILED_NEED_MORE_ITEMS
;
5707 if(!LootTemplates_Milling
.HaveLootFor(m_targets
.getItemTargetEntry()))
5708 return SPELL_FAILED_CANT_BE_MILLED
;
5712 case SPELL_EFFECT_WEAPON_DAMAGE
:
5713 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
:
5715 if(m_caster
->GetTypeId() != TYPEID_PLAYER
) return SPELL_FAILED_TARGET_NOT_PLAYER
;
5716 if( m_attackType
!= RANGED_ATTACK
)
5718 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(m_attackType
,true,false);
5720 return SPELL_FAILED_EQUIPPED_ITEM
;
5722 switch(pItem
->GetProto()->SubClass
)
5724 case ITEM_SUBCLASS_WEAPON_THROWN
:
5726 uint32 ammo
= pItem
->GetEntry();
5727 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5728 return SPELL_FAILED_NO_AMMO
;
5730 case ITEM_SUBCLASS_WEAPON_GUN
:
5731 case ITEM_SUBCLASS_WEAPON_BOW
:
5732 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5734 uint32 ammo
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
5738 if(m_caster
->GetDummyAura(46699))
5739 break; // skip other checks
5741 return SPELL_FAILED_NO_AMMO
;
5744 ItemPrototype
const *ammoProto
= ObjectMgr::GetItemPrototype( ammo
);
5746 return SPELL_FAILED_NO_AMMO
;
5748 if(ammoProto
->Class
!= ITEM_CLASS_PROJECTILE
)
5749 return SPELL_FAILED_NO_AMMO
;
5751 // check ammo ws. weapon compatibility
5752 switch(pItem
->GetProto()->SubClass
)
5754 case ITEM_SUBCLASS_WEAPON_BOW
:
5755 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5756 if(ammoProto
->SubClass
!= ITEM_SUBCLASS_ARROW
)
5757 return SPELL_FAILED_NO_AMMO
;
5759 case ITEM_SUBCLASS_WEAPON_GUN
:
5760 if(ammoProto
->SubClass
!= ITEM_SUBCLASS_BULLET
)
5761 return SPELL_FAILED_NO_AMMO
;
5764 return SPELL_FAILED_NO_AMMO
;
5767 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5768 return SPELL_FAILED_NO_AMMO
;
5770 case ITEM_SUBCLASS_WEAPON_WAND
:
5781 return SPELL_CAST_OK
;
5784 void Spell::Delayed()
5786 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
5789 if (m_spellState
== SPELL_STATE_DELAYED
)
5790 return; // spell is active and can't be time-backed
5792 if(isDelayableNoMore()) // Spells may only be delayed twice
5795 // spells not loosing casting time ( slam, dynamites, bombs.. )
5796 if(!(m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_DAMAGE
))
5799 //check pushback reduce
5800 int32 delaytime
= 500; // spellcasting delay is normally 500ms
5801 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5802 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5803 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5804 if(delayReduce
>= 100)
5807 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5809 if(int32(m_timer
) + delaytime
> m_casttime
)
5811 delaytime
= m_casttime
- m_timer
;
5812 m_timer
= m_casttime
;
5815 m_timer
+= delaytime
;
5817 sLog
.outDetail("Spell %u partially interrupted for (%d) ms at damage", m_spellInfo
->Id
, delaytime
);
5819 WorldPacket
data(SMSG_SPELL_DELAYED
, 8+4);
5820 data
.append(m_caster
->GetPackGUID());
5821 data
<< uint32(delaytime
);
5823 m_caster
->SendMessageToSet(&data
, true);
5826 void Spell::DelayedChannel()
5828 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
|| getState() != SPELL_STATE_CASTING
)
5831 if(isDelayableNoMore()) // Spells may only be delayed twice
5834 //check pushback reduce
5835 int32 delaytime
= GetSpellDuration(m_spellInfo
) * 25 / 100; // channeling delay is normally 25% of its time per hit
5836 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5837 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5838 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5839 if(delayReduce
>= 100)
5842 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5844 if(int32(m_timer
) < delaytime
)
5846 delaytime
= m_timer
;
5850 m_timer
-= delaytime
;
5852 sLog
.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo
->Id
, delaytime
, m_timer
);
5854 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
5856 if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
5858 Unit
* unit
= m_caster
->GetGUID() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
5861 for (int j
= 0; j
< 3; ++j
)
5862 if( ihit
->effectMask
& (1 << j
) )
5863 unit
->DelayAura(m_spellInfo
->Id
, j
, delaytime
);
5869 for(int j
= 0; j
< 3; ++j
)
5871 // partially interrupt persistent area auras
5872 DynamicObject
* dynObj
= m_caster
->GetDynObject(m_spellInfo
->Id
, j
);
5874 dynObj
->Delay(delaytime
);
5877 SendChannelUpdate(m_timer
);
5880 void Spell::UpdatePointers()
5882 if(m_originalCasterGUID
==m_caster
->GetGUID())
5883 m_originalCaster
= m_caster
;
5886 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
,m_originalCasterGUID
);
5887 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
5890 m_targets
.Update(m_caster
);
5893 bool Spell::IsAffectedByAura(Aura
*aura
) const
5895 if(SpellModifier
* mod
= aura
->getAuraSpellMod())
5896 return mod
->isAffectedOnSpell(m_spellInfo
);
5901 bool Spell::CheckTargetCreatureType(Unit
* target
) const
5903 uint32 spellCreatureTargetMask
= m_spellInfo
->TargetCreatureType
;
5905 // Curse of Doom & Exorcism: not find another way to fix spell target check :/
5906 if (m_spellInfo
->SpellFamilyName
==SPELLFAMILY_WARLOCK
&& m_spellInfo
->Category
== 1179)
5908 // not allow cast at player
5909 if(target
->GetTypeId()==TYPEID_PLAYER
)
5912 spellCreatureTargetMask
= 0x7FF;
5915 // Dismiss Pet and Taming Lesson skipped
5916 if(m_spellInfo
->Id
== 2641 || m_spellInfo
->Id
== 23356)
5917 spellCreatureTargetMask
= 0;
5919 if (spellCreatureTargetMask
)
5921 uint32 TargetCreatureType
= target
->GetCreatureTypeMask();
5923 return !TargetCreatureType
|| (spellCreatureTargetMask
& TargetCreatureType
);
5928 CurrentSpellTypes
Spell::GetCurrentContainer()
5930 if (IsNextMeleeSwingSpell())
5931 return(CURRENT_MELEE_SPELL
);
5932 else if (IsAutoRepeat())
5933 return(CURRENT_AUTOREPEAT_SPELL
);
5934 else if (IsChanneledSpell(m_spellInfo
))
5935 return(CURRENT_CHANNELED_SPELL
);
5937 return(CURRENT_GENERIC_SPELL
);
5940 bool Spell::CheckTarget( Unit
* target
, uint32 eff
)
5942 // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets)
5943 if(m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SELF
)
5945 if (!CheckTargetCreatureType(target
))
5949 // Check Aura spell req (need for AoE spells)
5950 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
5952 if (m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
5955 // Check targets for not_selectable unit flag and remove
5956 // A player can cast spells on his pet (or other controlled unit) though in any state
5957 if (target
!= m_caster
&& target
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
5959 // any unattackable target skipped
5960 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
))
5963 // unselectable targets skipped in all cases except TARGET_SCRIPT targeting
5964 // in case TARGET_SCRIPT target selected by server always and can't be cheated
5965 if( target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NOT_SELECTABLE
) &&
5966 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SCRIPT
&&
5967 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_SCRIPT
)
5971 //Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
5972 if( target
!= m_caster
&& target
->GetTypeId() == TYPEID_PLAYER
)
5974 if(((Player
*)target
)->GetVisibility() == VISIBILITY_OFF
)
5977 if(((Player
*)target
)->isGameMaster() && !IsPositiveSpell(m_spellInfo
->Id
))
5981 //Check targets for LOS visibility (except spells without range limitations )
5982 switch(m_spellInfo
->Effect
[eff
])
5984 case SPELL_EFFECT_SUMMON_PLAYER
: // from anywhere
5986 case SPELL_EFFECT_DUMMY
:
5987 if(m_spellInfo
->Id
!= 20577) // Cannibalize
5990 case SPELL_EFFECT_RESURRECT_NEW
:
5991 // player far away, maybe his corpse near?
5992 if(target
!= m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
5994 if(!m_targets
.getCorpseTargetGUID())
5997 Corpse
*corpse
= m_caster
->GetMap()->GetCorpse(m_targets
.getCorpseTargetGUID());
6001 if(target
->GetGUID() != corpse
->GetOwnerGUID())
6004 if(!corpse
->IsWithinLOSInMap(m_caster
))
6008 // all ok by some way or another, skip normal check
6010 default: // normal case
6011 // Get GO cast coordinates if original caster -> GO
6012 WorldObject
*caster
= NULL
;
6013 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
6014 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
6017 if(target
!= m_caster
&& !target
->IsWithinLOSInMap(caster
))
6025 bool Spell::IsNeedSendToClient() const
6027 return m_spellInfo
->SpellVisual
[0] || m_spellInfo
->SpellVisual
[1] || IsChanneledSpell(m_spellInfo
) ||
6028 m_spellInfo
->speed
> 0.0f
|| !m_triggeredByAuraSpell
&& !m_IsTriggeredSpell
;
6031 bool Spell::HaveTargetsForEffect( uint8 effect
) const
6033 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin(); itr
!= m_UniqueTargetInfo
.end(); ++itr
)
6034 if(itr
->effectMask
& (1 << effect
))
6037 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin(); itr
!= m_UniqueGOTargetInfo
.end(); ++itr
)
6038 if(itr
->effectMask
& (1 << effect
))
6041 for(std::list
<ItemTargetInfo
>::const_iterator itr
= m_UniqueItemInfo
.begin(); itr
!= m_UniqueItemInfo
.end(); ++itr
)
6042 if(itr
->effectMask
& (1 << effect
))
6048 SpellEvent::SpellEvent(Spell
* spell
) : BasicEvent()
6053 SpellEvent::~SpellEvent()
6055 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
6058 if (m_Spell
->IsDeletable())
6064 sLog
.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
6065 (m_Spell
->GetCaster()->GetTypeId() == TYPEID_PLAYER
? "Player" : "Creature"), m_Spell
->GetCaster()->GetGUIDLow(), m_Spell
->m_spellInfo
->Id
);
6069 bool SpellEvent::Execute(uint64 e_time
, uint32 p_time
)
6071 // update spell if it is not finished
6072 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
6073 m_Spell
->update(p_time
);
6075 // check spell state to process
6076 switch (m_Spell
->getState())
6078 case SPELL_STATE_FINISHED
:
6080 // spell was finished, check deletable state
6081 if (m_Spell
->IsDeletable())
6083 // check, if we do have unfinished triggered spells
6084 return true; // spell is deletable, finish event
6086 // event will be re-added automatically at the end of routine)
6089 case SPELL_STATE_CASTING
:
6091 // this spell is in channeled state, process it on the next update
6092 // event will be re-added automatically at the end of routine)
6095 case SPELL_STATE_DELAYED
:
6097 // first, check, if we have just started
6098 if (m_Spell
->GetDelayStart() != 0)
6100 // no, we aren't, do the typical update
6101 // check, if we have channeled spell on our hands
6102 if (IsChanneledSpell(m_Spell
->m_spellInfo
))
6104 // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish
6105 // check, if we have casting anything else except this channeled spell and autorepeat
6106 if (m_Spell
->GetCaster()->IsNonMeleeSpellCasted(false, true, true))
6108 // another non-melee non-delayed spell is casted now, abort
6113 // do the action (pass spell to channeling state)
6114 m_Spell
->handle_immediate();
6116 // event will be re-added automatically at the end of routine)
6120 // run the spell handler and think about what we can do next
6121 uint64 t_offset
= e_time
- m_Spell
->GetDelayStart();
6122 uint64 n_offset
= m_Spell
->handle_delayed(t_offset
);
6125 // re-add us to the queue
6126 m_Spell
->GetCaster()->m_Events
.AddEvent(this, m_Spell
->GetDelayStart() + n_offset
, false);
6127 return false; // event not complete
6130 // finish update event will be re-added automatically at the end of routine)
6135 // delaying had just started, record the moment
6136 m_Spell
->SetDelayStart(e_time
);
6137 // re-plan the event for the delay moment
6138 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ m_Spell
->GetDelayMoment(), false);
6139 return false; // event not complete
6146 // event will be re-added automatically at the end of routine)
6150 // spell processing not complete, plan event on the next update interval
6151 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ 1, false);
6152 return false; // event not complete
6155 void SpellEvent::Abort(uint64
/*e_time*/)
6157 // oops, the spell we try to do is aborted
6158 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
6162 bool SpellEvent::IsDeletable() const
6164 return m_Spell
->IsDeletable();
6167 SpellCastResult
Spell::CanOpenLock(uint32 effIndex
, uint32 lockId
, SkillType
& skillId
, int32
& reqSkillValue
, int32
& skillValue
)
6169 if(!lockId
) // possible case for GO and maybe for items.
6170 return SPELL_CAST_OK
;
6173 LockEntry
const *lockInfo
= sLockStore
.LookupEntry(lockId
);
6176 return SPELL_FAILED_BAD_TARGETS
;
6178 bool reqKey
= false; // some locks not have reqs
6180 for(int j
= 0; j
< 8; ++j
)
6182 switch(lockInfo
->Type
[j
])
6184 // check key item (many fit cases can be)
6186 if(lockInfo
->Index
[j
] && m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->Index
[j
])
6187 return SPELL_CAST_OK
;
6190 // check key skill (only single first fit case can be)
6191 case LOCK_KEY_SKILL
:
6195 // wrong locktype, skip
6196 if(uint32(m_spellInfo
->EffectMiscValue
[effIndex
]) != lockInfo
->Index
[j
])
6199 skillId
= SkillByLockType(LockType(lockInfo
->Index
[j
]));
6201 if ( skillId
!= SKILL_NONE
)
6203 // skill bonus provided by casting spell (mostly item spells)
6204 // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value)
6205 uint32 spellSkillBonus
= uint32(m_currentBasePoints
[effIndex
]+1);
6206 reqSkillValue
= lockInfo
->Skill
[j
];
6208 // castitem check: rogue using skeleton keys. the skill values should not be added in this case.
6209 skillValue
= m_CastItem
|| m_caster
->GetTypeId()!= TYPEID_PLAYER
?
6210 0 : ((Player
*)m_caster
)->GetSkillValue(skillId
);
6212 skillValue
+= spellSkillBonus
;
6214 if (skillValue
< reqSkillValue
)
6215 return SPELL_FAILED_LOW_CASTLEVEL
;
6218 return SPELL_CAST_OK
;
6224 return SPELL_FAILED_BAD_TARGETS
;
6226 return SPELL_CAST_OK
;
6229 void Spell::FillAreaTargets(UnitList
&targetUnitMap
, float x
, float y
, float radius
, SpellNotifyPushType pushType
, SpellTargets spellTargets
)
6231 CellPair
p(MaNGOS::ComputeCellPair(x
, y
));
6233 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
6235 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, targetUnitMap
, radius
, pushType
, spellTargets
);
6236 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
6237 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
6238 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
6239 cell_lock
->Visit(cell_lock
, world_notifier
, *m_caster
->GetMap(), *m_caster
, radius
);
6240 cell_lock
->Visit(cell_lock
, grid_notifier
, *m_caster
->GetMap(), *m_caster
, radius
);
6243 void Spell::FillRaidOrPartyTargets(UnitList
&targetUnitMap
, Unit
* member
, Unit
* center
, float radius
, bool raid
, bool withPets
, bool withcaster
)
6245 Player
*pMember
= member
->GetCharmerOrOwnerPlayerOrPlayerItself();
6246 Group
*pGroup
= pMember
? pMember
->GetGroup() : NULL
;
6250 uint8 subgroup
= pMember
->GetSubGroup();
6252 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
6254 Player
* Target
= itr
->getSource();
6256 // IsHostileTo check duel and controlled by enemy
6257 if (Target
&& (raid
|| subgroup
==Target
->GetSubGroup())
6258 && !m_caster
->IsHostileTo(Target
))
6260 if ((Target
==center
|| center
->IsWithinDistInMap(Target
, radius
)) &&
6261 (withcaster
|| Target
!= m_caster
))
6262 targetUnitMap
.push_back(Target
);
6265 if (Pet
* pet
= Target
->GetPet())
6266 if ((pet
==center
|| center
->IsWithinDistInMap(pet
, radius
)) &&
6267 (withcaster
|| pet
!= m_caster
))
6268 targetUnitMap
.push_back(pet
);
6274 Unit
* ownerOrSelf
= pMember
? pMember
: member
->GetCharmerOrOwnerOrSelf();
6275 if ((ownerOrSelf
==center
|| center
->IsWithinDistInMap(ownerOrSelf
, radius
)) &&
6276 (withcaster
|| ownerOrSelf
!= m_caster
))
6277 targetUnitMap
.push_back(ownerOrSelf
);
6280 if (Pet
* pet
= ownerOrSelf
->GetPet())
6281 if ((pet
==center
|| center
->IsWithinDistInMap(pet
, radius
)) &&
6282 (withcaster
|| pet
!= m_caster
))
6283 targetUnitMap
.push_back(pet
);
6287 void Spell::FillRaidOrPartyManaPriorityTargets(UnitList
&targetUnitMap
, Unit
* member
, Unit
* center
, float radius
, uint32 count
, bool raid
, bool withPets
, bool withCaster
)
6289 FillRaidOrPartyTargets(targetUnitMap
, member
, center
, radius
, raid
, withPets
, withCaster
);
6291 PrioritizeManaUnitQueue manaUsers
;
6292 for(UnitList::const_iterator itr
= targetUnitMap
.begin(); itr
!= targetUnitMap
.end() && manaUsers
.size() < count
; ++itr
)
6293 if ((*itr
)->getPowerType() == POWER_MANA
&& !(*itr
)->isDead())
6294 manaUsers
.push(PrioritizeManaUnitWraper(*itr
));
6296 targetUnitMap
.clear();
6297 while(!manaUsers
.empty())
6299 targetUnitMap
.push_back(manaUsers
.top().getUnit());
6304 void Spell::FillRaidOrPartyHealthPriorityTargets(UnitList
&targetUnitMap
, Unit
* member
, Unit
* center
, float radius
, uint32 count
, bool raid
, bool withPets
, bool withCaster
)
6306 FillRaidOrPartyTargets(targetUnitMap
, member
, center
, radius
, raid
, withPets
, withCaster
);
6308 PrioritizeHealthUnitQueue healthQueue
;
6309 for(UnitList::const_iterator itr
= targetUnitMap
.begin(); itr
!= targetUnitMap
.end() && healthQueue
.size() < count
; ++itr
)
6310 if (!(*itr
)->isDead())
6311 healthQueue
.push(PrioritizeHealthUnitWraper(*itr
));
6313 targetUnitMap
.clear();
6314 while(!healthQueue
.empty())
6316 targetUnitMap
.push_back(healthQueue
.top().getUnit());