2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "GridNotifiers.h"
24 #include "GridNotifiersImpl.h"
27 #include "UpdateMask.h"
29 #include "ObjectMgr.h"
35 #include "DynamicObject.h"
37 #include "UpdateData.h"
38 #include "MapManager.h"
39 #include "ObjectAccessor.h"
41 #include "Policies/SingletonImp.h"
42 #include "SharedDefines.h"
44 #include "VMapFactory.h"
45 #include "BattleGround.h"
48 #define SPELL_CHANNEL_UPDATE_INTERVAL (1 * IN_MILISECONDS)
50 extern pEffect SpellEffects
[TOTAL_SPELL_EFFECTS
];
52 class 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() + 4 + 4 + 4 > data
->size())
245 *data
>> m_srcX
>> m_srcY
>> m_srcZ
;
246 if(!MaNGOS::IsValidMapCoord(m_srcX
, m_srcY
, m_srcZ
))
250 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
252 if(data
->rpos() + 1 + 4 + 4 + 4 > data
->size())
255 if(!data
->readPackGUID(m_unitTargetGUID
))
258 *data
>> m_destX
>> m_destY
>> m_destZ
;
259 if(!MaNGOS::IsValidMapCoord(m_destX
, m_destY
, m_destZ
))
263 if( m_targetMask
& TARGET_FLAG_STRING
)
265 if(data
->rpos() + 1 > data
->size())
268 *data
>> m_strTarget
;
271 // find real units/GOs
276 void SpellCastTargets::write ( WorldPacket
* data
)
278 *data
<< uint32(m_targetMask
);
280 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_PVP_CORPSE
| TARGET_FLAG_OBJECT
| TARGET_FLAG_CORPSE
| TARGET_FLAG_UNK2
) )
282 if(m_targetMask
& TARGET_FLAG_UNIT
)
285 data
->append(m_unitTarget
->GetPackGUID());
289 else if( m_targetMask
& TARGET_FLAG_OBJECT
)
292 data
->append(m_GOTarget
->GetPackGUID());
296 else if( m_targetMask
& ( TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
297 data
->appendPackGUID(m_CorpseTargetGUID
);
302 if( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
) )
305 data
->append(m_itemTarget
->GetPackGUID());
310 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
311 *data
<< m_srcX
<< m_srcY
<< m_srcZ
;
313 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
316 data
->append(m_unitTarget
->GetPackGUID());
320 *data
<< m_destX
<< m_destY
<< m_destZ
;
323 if( m_targetMask
& TARGET_FLAG_STRING
)
324 *data
<< m_strTarget
;
327 Spell::Spell( Unit
* Caster
, SpellEntry
const *info
, bool triggered
, uint64 originalCasterGUID
, Spell
** triggeringContainer
)
329 ASSERT( Caster
!= NULL
&& info
!= NULL
);
330 ASSERT( info
== sSpellStore
.LookupEntry( info
->Id
) && "`info` must be pointer to sSpellStore element");
334 m_selfContainer
= NULL
;
335 m_triggeringContainer
= triggeringContainer
;
336 m_referencedFromCurrentSpell
= false;
337 m_executedCurrently
= false;
339 m_delayAtDamageCount
= 0;
341 m_applyMultiplierMask
= 0;
343 // Get data for type of attack
344 switch (m_spellInfo
->DmgClass
)
346 case SPELL_DAMAGE_CLASS_MELEE
:
347 if (m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_REQ_OFFHAND
)
348 m_attackType
= OFF_ATTACK
;
350 m_attackType
= BASE_ATTACK
;
352 case SPELL_DAMAGE_CLASS_RANGED
:
353 m_attackType
= RANGED_ATTACK
;
357 if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
)
358 m_attackType
= RANGED_ATTACK
;
360 m_attackType
= BASE_ATTACK
;
364 m_spellSchoolMask
= GetSpellSchoolMask(info
); // Can be override for some spell (wand shoot for example)
366 if(m_attackType
== RANGED_ATTACK
)
369 if((m_caster
->getClassMask() & CLASSMASK_WAND_USERS
) != 0 && m_caster
->GetTypeId() == TYPEID_PLAYER
)
371 if(Item
* pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(RANGED_ATTACK
))
372 m_spellSchoolMask
= SpellSchoolMask(1 << pItem
->GetProto()->Damage
[0].DamageType
);
375 // Set health leech amount to zero
378 if(originalCasterGUID
)
379 m_originalCasterGUID
= originalCasterGUID
;
381 m_originalCasterGUID
= m_caster
->GetGUID();
383 if(m_originalCasterGUID
== m_caster
->GetGUID())
384 m_originalCaster
= m_caster
;
387 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
, m_originalCasterGUID
);
388 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
391 for(int i
=0; i
<3; ++i
)
392 m_currentBasePoints
[i
] = m_spellInfo
->EffectBasePoints
[i
];
394 m_spellState
= SPELL_STATE_NULL
;
396 m_castPositionX
= m_castPositionY
= m_castPositionZ
= 0;
397 m_TriggerSpells
.clear();
398 m_preCastSpells
.clear();
399 m_IsTriggeredSpell
= triggered
;
400 //m_AreaAura = false;
405 gameObjTarget
= NULL
;
409 m_triggeredByAuraSpell
= NULL
;
411 //Auto Shot & Shoot (wand)
412 m_autoRepeat
= IsAutoRepeatRangedSpell(m_spellInfo
);
415 m_powerCost
= 0; // setup to correct value in Spell::prepare, don't must be used before.
416 m_casttime
= 0; // setup to correct value in Spell::prepare, don't must be used before.
417 m_timer
= 0; // will set to castime in prepare
419 m_needAliveTargetMask
= 0;
421 // determine reflection
422 m_canReflect
= false;
424 if(m_spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
&& !(m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
))
426 for(int j
= 0;j
< 3; ++j
)
428 if (m_spellInfo
->Effect
[j
] == 0)
431 if(!IsPositiveTarget(m_spellInfo
->EffectImplicitTargetA
[j
], m_spellInfo
->EffectImplicitTargetB
[j
]))
434 m_canReflect
= (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NEGATIVE
) ? true : false;
451 WorldObject
* Spell::FindCorpseUsing()
453 // non-standard target selection
454 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
455 float max_range
= GetSpellMaxRange(srange
);
457 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
459 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
462 WorldObject
* result
= NULL
;
464 T
u_check(m_caster
, max_range
);
465 MaNGOS::WorldObjectSearcher
<T
> searcher(m_caster
, result
, u_check
);
467 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<T
>, GridTypeMapContainer
> grid_searcher(searcher
);
468 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
469 cell_lock
->Visit(cell_lock
, grid_searcher
, *m_caster
->GetMap());
473 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<T
>, WorldTypeMapContainer
> world_searcher(searcher
);
474 cell_lock
->Visit(cell_lock
, world_searcher
, *m_caster
->GetMap());
480 void Spell::FillTargetMap()
482 // TODO: ADD the correct target FILLS!!!!!!
484 for(uint32 i
= 0; i
< 3; ++i
)
486 // not call for empty effect.
487 // Also some spells use not used effect targets for store targets for dummy effect in triggered spells
488 if(m_spellInfo
->Effect
[i
] == 0)
491 // targets for TARGET_SCRIPT_COORDINATES (A) and TARGET_SCRIPT filled in Spell::CheckCast call
492 if( m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT_COORDINATES
||
493 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT
||
494 m_spellInfo
->EffectImplicitTargetB
[i
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
)
497 // TODO: find a way so this is not needed?
498 // for area auras always add caster as target (needed for totems for example)
499 if(IsAreaAuraEffect(m_spellInfo
->Effect
[i
]))
500 AddUnitTarget(m_caster
, i
);
502 std::list
<Unit
*> tmpUnitMap
;
504 // TargetA/TargetB dependent from each other, we not switch to full support this dependences
505 // but need it support in some know cases
506 switch(m_spellInfo
->EffectImplicitTargetA
[i
])
509 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
512 SetTargetMap(i
, TARGET_EFFECT_SELECT
, tmpUnitMap
);
515 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
519 case TARGET_EFFECT_SELECT
:
520 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
523 case TARGET_EFFECT_SELECT
:
524 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
526 case TARGET_INNKEEPER_COORDINATES
:
527 case TARGET_TABLE_X_Y_Z_COORDINATES
:
528 case TARGET_CASTER_COORDINATES
:
529 case TARGET_SCRIPT_COORDINATES
:
530 case TARGET_CURRENT_ENEMY_COORDINATES
:
531 case TARGET_DUELVSPLAYER_COORDINATES
:
532 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
533 case TARGET_POINT_AT_NORTH
:
534 case TARGET_POINT_AT_SOUTH
:
535 case TARGET_POINT_AT_EAST
:
536 case TARGET_POINT_AT_WEST
:
537 case TARGET_POINT_AT_NE
:
538 case TARGET_POINT_AT_NW
:
539 case TARGET_POINT_AT_SE
:
540 case TARGET_POINT_AT_SW
:
541 // need some target for proccesing
542 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
543 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
546 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
551 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
554 case TARGET_EFFECT_SELECT
:
555 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
557 case TARGET_AREAEFFECT_INSTANT
: // use B case that not dependent from from A in fact
558 if((m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
) == 0)
559 m_targets
.setDestination(m_caster
->GetPositionX(), m_caster
->GetPositionY(), m_caster
->GetPositionZ());
560 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
562 case TARGET_BEHIND_VICTIM
: // use B case that not dependent from from A in fact
563 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
566 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
567 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
571 case TARGET_CASTER_COORDINATES
:
572 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
574 case TARGET_ALL_ENEMY_IN_AREA
:
575 // Note: this hack with search required until GO casting not implemented
576 // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support
577 // currently each enemy selected explicitly and self cast damage
578 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
)
580 if(m_targets
.getUnitTarget())
581 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
585 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
586 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
591 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
592 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
597 case TARGET_TABLE_X_Y_Z_COORDINATES
:
598 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
601 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
603 // need some target for proccesing
604 SetTargetMap(i
, TARGET_EFFECT_SELECT
, tmpUnitMap
);
606 case TARGET_AREAEFFECT_INSTANT
: // All 17/7 pairs used for dest teleportation, A processed in effect code
607 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
610 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
611 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
616 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
619 case TARGET_EFFECT_SELECT
:
620 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
622 case TARGET_SCRIPT_COORDINATES
: // B case filled in CheckCast but we need fill unit list base at A case
623 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
626 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
627 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
633 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
635 Player
*me
= (Player
*)m_caster
;
636 for (std::list
<Unit
*>::const_iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end(); ++itr
)
638 Unit
*owner
= (*itr
)->GetOwner();
639 Unit
*u
= owner
? owner
: (*itr
);
640 if(u
!=m_caster
&& u
->IsPvP() && (!me
->duel
|| me
->duel
->opponent
!= u
))
643 me
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
649 for (std::list
<Unit
*>::iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end();)
651 if (!CheckTarget (*itr
, i
))
653 itr
= tmpUnitMap
.erase(itr
);
660 for(std::list
<Unit
*>::const_iterator iunit
= tmpUnitMap
.begin(); iunit
!= tmpUnitMap
.end(); ++iunit
)
661 AddUnitTarget((*iunit
), i
);
665 void Spell::prepareDataForTriggerSystem()
667 //==========================================================================================
668 // Now fill data for trigger system, need know:
669 // an spell trigger another or not ( m_canTrigger )
670 // Create base triggers flags for Attacker and Victim ( m_procAttacker and m_procVictim)
671 //==========================================================================================
672 // Fill flag can spell trigger or not
673 // TODO: possible exist spell attribute for this
674 m_canTrigger
= false;
677 m_canTrigger
= false; // Do not trigger from item cast spell
678 else if (!m_IsTriggeredSpell
)
679 m_canTrigger
= true; // Normal cast - can trigger
680 else if (!m_triggeredByAuraSpell
)
681 m_canTrigger
= true; // Triggered from SPELL_EFFECT_TRIGGER_SPELL - can trigger
683 if (!m_canTrigger
) // Exceptions (some periodic triggers)
685 switch (m_spellInfo
->SpellFamilyName
)
687 case SPELLFAMILY_MAGE
:
688 // Arcane Missles / Blizzard triggers need do it
689 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000200080))
691 // Clearcasting trigger need do it
692 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000200000000) && m_spellInfo
->SpellFamilyFlags2
& 0x8)
695 case SPELLFAMILY_WARLOCK
: // For Hellfire Effect / Rain of Fire / Seed of Corruption triggers need do it
696 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000800000000060))
699 case SPELLFAMILY_PRIEST
: // For Penance heal/damage triggers need do it
700 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0001800000000000))
703 case SPELLFAMILY_ROGUE
: // For poisons need do it
704 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x000000101001E000))
707 case SPELLFAMILY_HUNTER
: // Hunter Rapid Killing/Explosive Trap Effect/Immolation Trap Effect/Frost Trap Aura/Snake Trap Effect/Explosive Shot
708 if ((m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0100200000000214)) ||
709 m_spellInfo
->SpellFamilyFlags2
& 0x200)
712 case SPELLFAMILY_PALADIN
: // For Judgements (all) / Holy Shock triggers need do it
713 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0001000900B80400))
721 // Get data for type of attack and fill base info for trigger
722 switch (m_spellInfo
->DmgClass
)
724 case SPELL_DAMAGE_CLASS_MELEE
:
725 m_procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT
;
726 m_procVictim
= PROC_FLAG_TAKEN_MELEE_SPELL_HIT
;
728 case SPELL_DAMAGE_CLASS_RANGED
:
730 if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
)
732 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
733 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
735 else // Ranged spell attack
737 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT
;
738 m_procVictim
= PROC_FLAG_TAKEN_RANGED_SPELL_HIT
;
742 if (IsPositiveSpell(m_spellInfo
->Id
)) // Check for positive spell
744 m_procAttacker
= PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
;
745 m_procVictim
= PROC_FLAG_TAKEN_POSITIVE_SPELL
;
747 else if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
) // Wands auto attack
749 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
750 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
752 else // Negative spell
754 m_procAttacker
= PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT
;
755 m_procVictim
= PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
;
759 // Hunter traps spells (for Entrapment trigger)
760 // Gives your Immolation Trap, Frost Trap, Explosive Trap, and Snake Trap ....
761 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_HUNTER
&& (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x000020000000001C)))
762 m_procAttacker
|= PROC_FLAG_ON_TRAP_ACTIVATION
;
765 void Spell::CleanupTargetList()
767 m_UniqueTargetInfo
.clear();
768 m_UniqueGOTargetInfo
.clear();
769 m_UniqueItemInfo
.clear();
773 void Spell::AddUnitTarget(Unit
* pVictim
, uint32 effIndex
)
775 if( m_spellInfo
->Effect
[effIndex
] == 0 )
778 // Check for effect immune skip if immuned
779 bool immuned
= pVictim
->IsImmunedToSpellEffect(m_spellInfo
, effIndex
);
781 uint64 targetGUID
= pVictim
->GetGUID();
783 // Lookup target in already in list
784 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
786 if (targetGUID
== ihit
->targetGUID
) // Found in list
789 ihit
->effectMask
|= 1 << effIndex
; // Add only effect mask if not immuned
794 // This is new target calculate data for him
796 // Get spell hit result on target
798 target
.targetGUID
= targetGUID
; // Store target GUID
799 target
.effectMask
= immuned
? 0 : 1 << effIndex
; // Store index of effect if not immuned
800 target
.processed
= false; // Effects not apply on target
802 // Calculate hit result
803 target
.missCondition
= m_caster
->SpellHitResult(pVictim
, m_spellInfo
, m_canReflect
);
805 // Spell have speed - need calculate incoming time
806 if (m_spellInfo
->speed
> 0.0f
)
808 // calculate spell incoming interval
809 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
810 if (dist
< 5.0f
) dist
= 5.0f
;
811 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
813 // Calculate minimum incoming time
814 if (m_delayMoment
== 0 || m_delayMoment
>target
.timeDelay
)
815 m_delayMoment
= target
.timeDelay
;
818 target
.timeDelay
= UI64LIT(0);
820 // If target reflect spell back to caster
821 if (target
.missCondition
== SPELL_MISS_REFLECT
)
823 // Calculate reflected spell result on caster
824 target
.reflectResult
= m_caster
->SpellHitResult(m_caster
, m_spellInfo
, m_canReflect
);
826 if (target
.reflectResult
== SPELL_MISS_REFLECT
) // Impossible reflect again, so simply deflect spell
827 target
.reflectResult
= SPELL_MISS_PARRY
;
829 // Increase time interval for reflected spells by 1.5
830 target
.timeDelay
+= target
.timeDelay
>> 1;
833 target
.reflectResult
= SPELL_MISS_NONE
;
835 // Add target to list
836 m_UniqueTargetInfo
.push_back(target
);
839 void Spell::AddUnitTarget(uint64 unitGUID
, uint32 effIndex
)
841 Unit
* unit
= m_caster
->GetGUID() == unitGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, unitGUID
);
843 AddUnitTarget(unit
, effIndex
);
846 void Spell::AddGOTarget(GameObject
* pVictim
, uint32 effIndex
)
848 if( m_spellInfo
->Effect
[effIndex
] == 0 )
851 uint64 targetGUID
= pVictim
->GetGUID();
853 // Lookup target in already in list
854 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
856 if (targetGUID
== ihit
->targetGUID
) // Found in list
858 ihit
->effectMask
|= 1 << effIndex
; // Add only effect mask
863 // This is new target calculate data for him
866 target
.targetGUID
= targetGUID
;
867 target
.effectMask
= 1 << effIndex
;
868 target
.processed
= false; // Effects not apply on target
870 // Spell have speed - need calculate incoming time
871 if (m_spellInfo
->speed
> 0.0f
)
873 // calculate spell incoming interval
874 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
875 if (dist
< 5.0f
) dist
= 5.0f
;
876 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
877 if (m_delayMoment
==0 || m_delayMoment
>target
.timeDelay
)
878 m_delayMoment
= target
.timeDelay
;
881 target
.timeDelay
= UI64LIT(0);
883 // Add target to list
884 m_UniqueGOTargetInfo
.push_back(target
);
887 void Spell::AddGOTarget(uint64 goGUID
, uint32 effIndex
)
889 GameObject
* go
= m_caster
->GetMap()->GetGameObject(goGUID
);
891 AddGOTarget(go
, effIndex
);
894 void Spell::AddItemTarget(Item
* pitem
, uint32 effIndex
)
896 if( m_spellInfo
->Effect
[effIndex
] == 0 )
899 // Lookup target in already in list
900 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin(); ihit
!= m_UniqueItemInfo
.end(); ++ihit
)
902 if (pitem
== ihit
->item
) // Found in list
904 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask
909 // This is new target add data
911 ItemTargetInfo target
;
913 target
.effectMask
= 1 << effIndex
;
914 m_UniqueItemInfo
.push_back(target
);
917 void Spell::DoAllEffectOnTarget(TargetInfo
*target
)
919 if (target
->processed
) // Check target
921 target
->processed
= true; // Target checked in apply effects procedure
923 // Get mask of effects for target
924 uint32 mask
= target
->effectMask
;
926 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
930 // Get original caster (if exist) and calculate damage/healing from him data
931 Unit
*caster
= m_originalCaster
? m_originalCaster
: m_caster
;
933 // Skip if m_originalCaster not available
937 SpellMissInfo missInfo
= target
->missCondition
;
938 // Need init unitTarget by default unit (can changed in code on reflect)
939 // Or on missInfo!=SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem)
942 // Reset damage/healing counter
946 // Fill base trigger info
947 uint32 procAttacker
= m_procAttacker
;
948 uint32 procVictim
= m_procVictim
;
949 uint32 procEx
= PROC_EX_NONE
;
951 if (missInfo
==SPELL_MISS_NONE
) // In case spell hit target, do all effect on that target
952 DoSpellHitOnUnit(unit
, mask
);
953 else if (missInfo
== SPELL_MISS_REFLECT
) // In case spell reflect from target, do all effect on caster (if hit)
955 if (target
->reflectResult
== SPELL_MISS_NONE
) // If reflected spell hit caster -> do all effect on him
956 DoSpellHitOnUnit(m_caster
, mask
);
959 // All calculated do it!
960 // Do healing and triggers
963 bool crit
= caster
->isSpellCrit(NULL
, m_spellInfo
, m_spellSchoolMask
);
964 uint32 addhealth
= m_healing
;
967 procEx
|= PROC_EX_CRITICAL_HIT
;
968 addhealth
= caster
->SpellCriticalHealingBonus(m_spellInfo
, addhealth
, NULL
);
971 procEx
|= PROC_EX_NORMAL_HIT
;
973 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
974 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
975 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, addhealth
, m_attackType
, m_spellInfo
);
977 int32 gain
= caster
->DealHeal(unitTarget
, addhealth
, m_spellInfo
, crit
);
978 unitTarget
->getHostilRefManager().threatAssist(caster
, float(gain
) * 0.5f
, m_spellInfo
);
980 // Do damage and triggers
983 // Fill base damage struct (unitTarget - is real spell target)
984 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
986 // Add bonuses and fill damageInfo struct
987 caster
->CalculateSpellDamage(&damageInfo
, m_damage
, m_spellInfo
);
988 caster
->DealDamageMods(damageInfo
.target
, damageInfo
.damage
, &damageInfo
.absorb
);
990 // Send log damage message to client
991 caster
->SendSpellNonMeleeDamageLog(&damageInfo
);
993 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
994 procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
996 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
997 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
998 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, damageInfo
.damage
, m_attackType
, m_spellInfo
);
1000 caster
->DealSpellDamage(&damageInfo
, true);
1002 // Judgement of Blood
1003 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000800000000)) && m_spellInfo
->SpellIconID
==153)
1005 int32 damagePoint
= damageInfo
.damage
* 33 / 100;
1006 m_caster
->CastCustomSpell(m_caster
, 32220, &damagePoint
, NULL
, NULL
, true);
1009 // Passive spell hits/misses or active spells only misses (only triggers)
1012 // Fill base damage struct (unitTarget - is real spell target)
1013 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1014 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1015 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1016 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1017 caster
->ProcDamageAndSpell(unit
, procAttacker
, procVictim
, procEx
, 0, m_attackType
, m_spellInfo
);
1020 // Call scripted function for AI if this spell is casted upon a creature
1021 if(unit
->GetTypeId()==TYPEID_UNIT
)
1023 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1024 // ignore pets or autorepeat/melee casts for speed (not exist quest for spells (hm... )
1025 if( !((Creature
*)unit
)->isPet() && !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1027 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1028 p
->CastedCreatureOrGO(unit
->GetEntry(), unit
->GetGUID(), m_spellInfo
->Id
);
1031 if(((Creature
*)unit
)->AI())
1032 ((Creature
*)unit
)->AI()->SpellHit(m_caster
,m_spellInfo
);
1035 // Call scripted function for AI if this spell is casted by a creature
1036 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)m_caster
)->AI())
1037 ((Creature
*)m_caster
)->AI()->SpellHitTarget(unit
, m_spellInfo
);
1040 void Spell::DoSpellHitOnUnit(Unit
*unit
, const uint32 effectMask
)
1042 if (!unit
|| !effectMask
)
1045 Unit
* realCaster
= m_originalCaster
? m_originalCaster
: m_caster
;
1047 // Recheck immune (only for delayed spells)
1048 if (m_spellInfo
->speed
&& (
1049 unit
->IsImmunedToDamage(GetSpellSchoolMask(m_spellInfo
)) ||
1050 unit
->IsImmunedToSpell(m_spellInfo
)))
1052 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_IMMUNE
);
1056 if (unit
->GetTypeId() == TYPEID_PLAYER
)
1058 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET
, m_spellInfo
->Id
);
1059 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2
, m_spellInfo
->Id
);
1062 if (realCaster
->GetTypeId() == TYPEID_PLAYER
)
1063 ((Player
*)realCaster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2
, m_spellInfo
->Id
, 0, unit
);
1065 if (realCaster
!= unit
)
1067 // Recheck UNIT_FLAG_NON_ATTACKABLE for delayed spells
1068 if (m_spellInfo
->speed
> 0.0f
&&
1069 unit
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
) &&
1070 unit
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
1072 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1076 if (!realCaster
->IsFriendlyTo(unit
))
1078 // for delayed spells ignore not visible explicit target
1079 if (m_spellInfo
->speed
> 0.0f
&& unit
== m_targets
.getUnitTarget() &&
1080 !unit
->isVisibleForOrDetect(m_caster
,m_caster
,false))
1082 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1086 // not break stealth by cast targeting
1087 if (!(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_BREAK_STEALTH
))
1088 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1090 // can cause back attack (if detected), stealth removed at Spell::cast if spell break it
1091 if (!(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) && !IsPositiveSpell(m_spellInfo
->Id
) &&
1092 m_caster
->isVisibleForOrDetect(unit
,unit
,false))
1094 // use speedup check to avoid re-remove after above lines
1095 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_BREAK_STEALTH
)
1096 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1098 // caster can be detected but have stealth aura
1099 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1101 if (!unit
->IsStandState() && !unit
->hasUnitState(UNIT_STAT_STUNNED
))
1102 unit
->SetStandState(UNIT_STAND_STATE_STAND
);
1104 if (!unit
->isInCombat() && unit
->GetTypeId() != TYPEID_PLAYER
&& ((Creature
*)unit
)->AI())
1105 ((Creature
*)unit
)->AI()->AttackedBy(realCaster
);
1107 unit
->AddThreat(realCaster
, 0.0f
);
1108 unit
->SetInCombatWith(realCaster
);
1109 realCaster
->SetInCombatWith(unit
);
1111 if (Player
*attackedPlayer
= unit
->GetCharmerOrOwnerPlayerOrPlayerItself())
1112 realCaster
->SetContestedPvP(attackedPlayer
);
1117 // for delayed spells ignore negative spells (after duel end) for friendly targets
1118 if (m_spellInfo
->speed
> 0.0f
&& !IsPositiveSpell(m_spellInfo
->Id
))
1120 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1124 // assisting case, healing and resurrection
1125 if (unit
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
1126 realCaster
->SetContestedPvP();
1128 if (unit
->isInCombat() && !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
))
1130 realCaster
->SetInCombatState(unit
->GetCombatTimer() > 0);
1131 unit
->getHostilRefManager().threatAssist(realCaster
, 0.0f
);
1136 // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
1137 m_diminishGroup
= GetDiminishingReturnsGroupForSpell(m_spellInfo
,m_triggeredByAuraSpell
);
1138 m_diminishLevel
= unit
->GetDiminishing(m_diminishGroup
);
1139 // Increase Diminishing on unit, current informations for actually casts will use values above
1140 if ((GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_PLAYER
&& unit
->GetTypeId() == TYPEID_PLAYER
) ||
1141 GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_ALL
)
1142 unit
->IncrDiminishing(m_diminishGroup
);
1144 // Apply additional spell effects to target
1145 CastPreCastSpells(unit
);
1147 for(uint32 effectNumber
= 0; effectNumber
< 3; ++effectNumber
)
1149 if (effectMask
& (1 << effectNumber
))
1151 HandleEffects(unit
, NULL
, NULL
, effectNumber
, m_damageMultipliers
[effectNumber
]);
1152 if ( m_applyMultiplierMask
& (1 << effectNumber
) )
1155 float multiplier
= m_spellInfo
->DmgMultiplier
[effectNumber
];
1156 // Apply multiplier mods
1157 if(Player
* modOwner
= realCaster
->GetSpellModOwner())
1158 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_EFFECT_PAST_FIRST
, multiplier
, this);
1159 m_damageMultipliers
[effectNumber
] *= multiplier
;
1165 void Spell::DoAllEffectOnTarget(GOTargetInfo
*target
)
1167 if (target
->processed
) // Check target
1169 target
->processed
= true; // Target checked in apply effects procedure
1171 uint32 effectMask
= target
->effectMask
;
1175 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
1179 for(uint32 effectNumber
= 0; effectNumber
< 3; ++effectNumber
)
1180 if (effectMask
& (1 << effectNumber
))
1181 HandleEffects(NULL
, NULL
, go
, effectNumber
);
1183 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1184 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
1185 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1187 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1188 p
->CastedCreatureOrGO(go
->GetEntry(), go
->GetGUID(), m_spellInfo
->Id
);
1192 void Spell::DoAllEffectOnTarget(ItemTargetInfo
*target
)
1194 uint32 effectMask
= target
->effectMask
;
1195 if(!target
->item
|| !effectMask
)
1198 for(uint32 effectNumber
= 0; effectNumber
< 3; ++effectNumber
)
1199 if (effectMask
& (1 << effectNumber
))
1200 HandleEffects(NULL
, target
->item
, NULL
, effectNumber
);
1203 bool Spell::IsAliveUnitPresentInTargetList()
1205 // Not need check return true
1206 if (m_needAliveTargetMask
== 0)
1209 uint8 needAliveTargetMask
= m_needAliveTargetMask
;
1211 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
1213 if( ihit
->missCondition
== SPELL_MISS_NONE
&& (needAliveTargetMask
& ihit
->effectMask
) )
1215 Unit
*unit
= m_caster
->GetGUID() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
1217 if (unit
&& unit
->isAlive())
1218 needAliveTargetMask
&= ~ihit
->effectMask
; // remove from need alive mask effect that have alive target
1222 // is all effects from m_needAliveTargetMask have alive targets
1223 return needAliveTargetMask
== 0;
1226 // Helper for Chain Healing
1227 // Spell target first
1228 // Raidmates then descending by injury suffered (MaxHealth - Health)
1229 // Other players/mobs then descending by injury suffered (MaxHealth - Health)
1230 struct ChainHealingOrder
: public std::binary_function
<const Unit
*, const Unit
*, bool>
1232 const Unit
* MainTarget
;
1233 ChainHealingOrder(Unit
const* Target
) : MainTarget(Target
) {};
1234 // functor for operator ">"
1235 bool operator()(Unit
const* _Left
, Unit
const* _Right
) const
1237 return (ChainHealingHash(_Left
) < ChainHealingHash(_Right
));
1239 int32
ChainHealingHash(Unit
const* Target
) const
1241 if (Target
== MainTarget
)
1243 else if (Target
->GetTypeId() == TYPEID_PLAYER
&& MainTarget
->GetTypeId() == TYPEID_PLAYER
&&
1244 ((Player
const*)Target
)->IsInSameRaidWith((Player
const*)MainTarget
))
1246 if (Target
->GetHealth() == Target
->GetMaxHealth())
1249 return 20000 - Target
->GetMaxHealth() + Target
->GetHealth();
1252 return 40000 - Target
->GetMaxHealth() + Target
->GetHealth();
1256 class ChainHealingFullHealth
: std::unary_function
<const Unit
*, bool>
1259 const Unit
* MainTarget
;
1260 ChainHealingFullHealth(const Unit
* Target
) : MainTarget(Target
) {};
1262 bool operator()(const Unit
* Target
)
1264 return (Target
!= MainTarget
&& Target
->GetHealth() == Target
->GetMaxHealth());
1268 // Helper for targets nearest to the spell target
1269 // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
1270 struct TargetDistanceOrder
: public std::binary_function
<const Unit
, const Unit
, bool>
1272 const Unit
* MainTarget
;
1273 TargetDistanceOrder(const Unit
* Target
) : MainTarget(Target
) {};
1274 // functor for operator ">"
1275 bool operator()(const Unit
* _Left
, const Unit
* _Right
) const
1277 return MainTarget
->GetDistanceOrder(_Left
,_Right
);
1281 void Spell::SetTargetMap(uint32 effIndex
,uint32 targetMode
,UnitList
& TagUnitMap
)
1284 if (m_spellInfo
->EffectRadiusIndex
[effIndex
])
1285 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[effIndex
]));
1287 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
));
1289 if(m_originalCaster
)
1290 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1291 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RADIUS
, radius
, this);
1293 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[effIndex
];
1294 if(m_originalCaster
)
1295 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1296 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
1298 // Get spell max affected targets
1299 uint32 unMaxTargets
= m_spellInfo
->MaxAffectedTargets
;
1301 // custom target amount cases
1302 switch(m_spellInfo
->SpellFamilyName
)
1304 case SPELLFAMILY_DRUID
:
1306 if (m_spellInfo
->SpellFamilyFlags2
& UI64LIT(0x00000100))
1313 Unit::AuraList
const& mod
= m_caster
->GetAurasByType(SPELL_AURA_MOD_MAX_AFFECTED_TARGETS
);
1314 for(Unit::AuraList::const_iterator m
= mod
.begin(); m
!= mod
.end(); ++m
)
1316 if (!(*m
)->isAffectedOnSpell(m_spellInfo
))
1318 unMaxTargets
+=(*m
)->GetModifier()->m_amount
;
1323 case TARGET_TOTEM_EARTH
:
1324 case TARGET_TOTEM_WATER
:
1325 case TARGET_TOTEM_AIR
:
1326 case TARGET_TOTEM_FIRE
:
1329 case TARGET_DYNAMIC_OBJECT
:
1330 case TARGET_AREAEFFECT_CUSTOM
:
1331 case TARGET_AREAEFFECT_CUSTOM_2
:
1333 TagUnitMap
.push_back(m_caster
);
1335 case TARGET_RANDOM_ENEMY_CHAIN_IN_AREA
:
1337 m_targets
.m_targetMask
= 0;
1338 unMaxTargets
= EffectChainTarget
;
1339 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1341 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1343 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1346 std::list
<Unit
*> tempUnitMap
;
1349 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1350 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1352 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1353 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1355 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1356 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1357 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1360 if(tempUnitMap
.empty())
1363 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1365 //Now to get us a random target that's in the initial range of the spell
1367 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1368 while(itr
!= tempUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
,radius
))
1374 itr
= tempUnitMap
.begin();
1375 std::advance(itr
, rand()%t
);
1376 Unit
*pUnitTarget
= *itr
;
1377 TagUnitMap
.push_back(pUnitTarget
);
1379 tempUnitMap
.erase(itr
);
1381 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1383 t
= unMaxTargets
- 1;
1384 Unit
*prev
= pUnitTarget
;
1385 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1387 while(t
&& next
!= tempUnitMap
.end() )
1389 if(!prev
->IsWithinDist(*next
,CHAIN_SPELL_JUMP_RADIUS
))
1392 if(!prev
->IsWithinLOSInMap(*next
))
1399 TagUnitMap
.push_back(prev
);
1400 tempUnitMap
.erase(next
);
1401 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1402 next
= tempUnitMap
.begin();
1408 case TARGET_RANDOM_FRIEND_CHAIN_IN_AREA
:
1410 m_targets
.m_targetMask
= 0;
1411 unMaxTargets
= EffectChainTarget
;
1412 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1413 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1415 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1417 std::list
<Unit
*> tempUnitMap
;
1419 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1420 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1422 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1423 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1425 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1426 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1427 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1430 if(tempUnitMap
.empty())
1433 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1435 //Now to get us a random target that's in the initial range of the spell
1437 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1438 while(itr
!= tempUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
,radius
))
1444 itr
= tempUnitMap
.begin();
1445 std::advance(itr
, rand()%t
);
1446 Unit
*pUnitTarget
= *itr
;
1447 TagUnitMap
.push_back(pUnitTarget
);
1449 tempUnitMap
.erase(itr
);
1451 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1453 t
= unMaxTargets
- 1;
1454 Unit
*prev
= pUnitTarget
;
1455 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1457 while(t
&& next
!= tempUnitMap
.end() )
1459 if(!prev
->IsWithinDist(*next
,CHAIN_SPELL_JUMP_RADIUS
))
1462 if(!prev
->IsWithinLOSInMap(*next
))
1468 TagUnitMap
.push_back(prev
);
1469 tempUnitMap
.erase(next
);
1470 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1471 next
= tempUnitMap
.begin();
1478 Pet
* tmpUnit
= m_caster
->GetPet();
1479 if (!tmpUnit
) break;
1480 TagUnitMap
.push_back(tmpUnit
);
1483 case TARGET_CHAIN_DAMAGE
:
1485 if (EffectChainTarget
<= 1)
1487 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1489 m_targets
.setUnitTarget(pUnitTarget
);
1490 TagUnitMap
.push_back(pUnitTarget
);
1495 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1496 Unit
* originalCaster
= GetOriginalCaster();
1497 if(!pUnitTarget
|| !originalCaster
)
1500 unMaxTargets
= EffectChainTarget
;
1503 if(m_spellInfo
->DmgClass
==SPELL_DAMAGE_CLASS_MELEE
)
1504 max_range
= radius
; //
1506 //FIXME: This very like horrible hack and wrong for most spells
1507 max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1509 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1511 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1514 std::list
<Unit
*> tempUnitMap
;
1516 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(pUnitTarget
, originalCaster
, max_range
, false);
1517 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1518 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1519 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1520 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1522 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1523 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1525 if (tempUnitMap
.empty())
1528 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1530 if (*tempUnitMap
.begin() == pUnitTarget
)
1531 tempUnitMap
.erase (tempUnitMap
.begin());
1533 TagUnitMap
.push_back(pUnitTarget
);
1534 uint32 t
= unMaxTargets
- 1;
1535 Unit
*prev
= pUnitTarget
;
1536 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1538 while (t
&& next
!= tempUnitMap
.end())
1540 if (!prev
->IsWithinDist (*next
,CHAIN_SPELL_JUMP_RADIUS
))
1542 if (!prev
->IsWithinLOSInMap (*next
))
1548 TagUnitMap
.push_back(prev
);
1549 tempUnitMap
.erase(next
);
1550 tempUnitMap
.sort (TargetDistanceOrder(prev
));
1551 next
= tempUnitMap
.begin();
1557 case TARGET_ALL_ENEMY_IN_AREA
:
1558 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1560 case TARGET_AREAEFFECT_INSTANT
:
1562 SpellTargets targetB
= SPELL_TARGETS_AOE_DAMAGE
;
1563 // Select friendly targets for positive effect
1564 if (IsPositiveEffect(m_spellInfo
->Id
, effIndex
))
1565 targetB
= SPELL_TARGETS_FRIENDLY
;
1567 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),radius
, PUSH_DEST_CENTER
, targetB
);
1570 TagUnitMap
.remove(m_caster
);
1573 case TARGET_ALL_ENEMY_IN_AREA_INSTANT
:
1575 // targets the ground, not the units in the area
1576 switch(m_spellInfo
->Effect
[effIndex
])
1578 case SPELL_EFFECT_PERSISTENT_AREA_AURA
:
1580 case SPELL_EFFECT_SUMMON
:
1581 TagUnitMap
.push_back(m_caster
);
1584 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1586 // exclude caster (this can be important if this not original caster)
1587 TagUnitMap
.remove(m_caster
);
1592 case TARGET_DUELVSPLAYER_COORDINATES
:
1594 if(Unit
* currentTarget
= m_targets
.getUnitTarget())
1596 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1597 TagUnitMap
.push_back(currentTarget
);
1601 case TARGET_ALL_PARTY_AROUND_CASTER
:
1602 case TARGET_ALL_PARTY_AROUND_CASTER_2
:
1603 case TARGET_ALL_PARTY
:
1604 FillRaidOrPartyTargets(TagUnitMap
, m_caster
, m_caster
, radius
, false, true, true);
1606 case TARGET_ALL_RAID_AROUND_CASTER
:
1608 if(m_spellInfo
->Id
== 57669) // Replenishment (special target selection)
1609 FillRaidOrPartyManaPriorityTargets(TagUnitMap
, m_caster
, m_caster
, radius
, 10, true, false, true);
1610 else if (m_spellInfo
->Id
==52759) // Ancestral Awakening (special target selection)
1611 FillRaidOrPartyHealthPriorityTargets(TagUnitMap
, m_caster
, m_caster
, radius
, 1, true, false, true);
1613 FillRaidOrPartyTargets(TagUnitMap
, m_caster
, m_caster
, radius
, true, true, true);
1616 case TARGET_SINGLE_FRIEND
:
1617 case TARGET_SINGLE_FRIEND_2
:
1618 if(m_targets
.getUnitTarget())
1619 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1621 case TARGET_NONCOMBAT_PET
:
1622 if(Unit
* target
= m_targets
.getUnitTarget())
1623 if( target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet() && ((Pet
*)target
)->getPetType() == MINI_PET
)
1624 TagUnitMap
.push_back(target
);
1626 case TARGET_CASTER_COORDINATES
:
1628 // Check original caster is GO - set its coordinates as dst cast
1629 WorldObject
*caster
= NULL
;
1630 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
1631 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
1634 // Set dest for targets
1635 m_targets
.setDestination(caster
->GetPositionX(), caster
->GetPositionY(), caster
->GetPositionZ());
1638 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER
:
1639 // special target order
1640 if (m_spellInfo
->Id
==64904) // Hymn of Hope
1641 // target amount stored in parent spell dummy effect but hard for access
1642 FillRaidOrPartyManaPriorityTargets(TagUnitMap
, m_caster
, m_caster
, radius
, 3, true, false, false);
1644 FillAreaTargets(TagUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
1646 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA
:
1648 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_DRUID
&& m_spellInfo
->SpellIconID
== 2864)
1650 Unit
* target
= m_targets
.getUnitTarget();
1653 uint32 count
= CalculateDamage(2,m_caster
); // stored in dummy effect, affected by mods
1655 FillRaidOrPartyHealthPriorityTargets(TagUnitMap
, m_caster
, target
, radius
, count
, true, false, true);
1658 FillAreaTargets(TagUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_FRIENDLY
);
1660 // 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..)
1661 case TARGET_SINGLE_PARTY
:
1663 Unit
*target
= m_targets
.getUnitTarget();
1664 // Thoses spells apparently can't be casted on the caster.
1665 if( target
&& target
!= m_caster
)
1667 // Can only be casted on group's members or its pets
1668 Group
*pGroup
= NULL
;
1670 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1671 Unit
*targetOwner
= target
->GetCharmerOrOwner();
1674 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1676 if( target
== owner
)
1678 TagUnitMap
.push_back(target
);
1681 pGroup
= ((Player
*)owner
)->GetGroup();
1684 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1686 if( targetOwner
== m_caster
&& target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet())
1688 TagUnitMap
.push_back(target
);
1691 pGroup
= ((Player
*)m_caster
)->GetGroup();
1696 // Our target can also be a player's pet who's grouped with us or our pet. But can't be controlled player
1699 if( targetOwner
->GetTypeId() == TYPEID_PLAYER
&&
1700 target
->GetTypeId() == TYPEID_UNIT
&& (((Creature
*)target
)->isPet()) &&
1701 target
->GetOwnerGUID() == targetOwner
->GetGUID() &&
1702 pGroup
->IsMember(((Player
*)targetOwner
)->GetGUID()))
1704 TagUnitMap
.push_back(target
);
1707 // 1Our target can be a player who is on our group
1708 else if (target
->GetTypeId() == TYPEID_PLAYER
&& pGroup
->IsMember(((Player
*)target
)->GetGUID()))
1710 TagUnitMap
.push_back(target
);
1716 case TARGET_GAMEOBJECT
:
1717 if(m_targets
.getGOTarget())
1718 AddGOTarget(m_targets
.getGOTarget(), effIndex
);
1720 case TARGET_IN_FRONT_OF_CASTER
:
1722 bool inFront
= m_spellInfo
->SpellVisual
[0] != 3879;
1723 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),radius
,inFront
? PUSH_IN_FRONT
: PUSH_IN_BACK
,SPELL_TARGETS_AOE_DAMAGE
);
1726 case TARGET_IN_FRONT_OF_CASTER_30
:
1727 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_30
, SPELL_TARGETS_AOE_DAMAGE
);
1729 case TARGET_DUELVSPLAYER
:
1731 Unit
*target
= m_targets
.getUnitTarget();
1734 if(m_caster
->IsFriendlyTo(target
))
1736 TagUnitMap
.push_back(target
);
1740 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1742 m_targets
.setUnitTarget(pUnitTarget
);
1743 TagUnitMap
.push_back(pUnitTarget
);
1749 case TARGET_GAMEOBJECT_ITEM
:
1750 if(m_targets
.getGOTargetGUID())
1751 AddGOTarget(m_targets
.getGOTarget(), effIndex
);
1752 else if(m_targets
.getItemTarget())
1753 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
1756 if(Unit
* owner
= m_caster
->GetCharmerOrOwner())
1757 TagUnitMap
.push_back(owner
);
1759 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED
:
1760 // targets the ground, not the units in the area
1761 if (m_spellInfo
->Effect
[effIndex
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1762 FillAreaTargets(TagUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1765 if(m_spellInfo
->Effect
[effIndex
] != SPELL_EFFECT_DUEL
)
1766 TagUnitMap
.push_back(m_caster
);
1768 case TARGET_SINGLE_ENEMY
:
1770 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1772 m_targets
.setUnitTarget(pUnitTarget
);
1773 TagUnitMap
.push_back(pUnitTarget
);
1777 case TARGET_AREAEFFECT_PARTY
:
1779 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1780 Player
*pTarget
= NULL
;
1784 TagUnitMap
.push_back(m_caster
);
1785 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1786 pTarget
= (Player
*)owner
;
1788 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1790 if(Unit
* target
= m_targets
.getUnitTarget())
1792 if( target
->GetTypeId() != TYPEID_PLAYER
)
1794 if(((Creature
*)target
)->isPet())
1796 Unit
*targetOwner
= target
->GetOwner();
1797 if(targetOwner
->GetTypeId() == TYPEID_PLAYER
)
1798 pTarget
= (Player
*)targetOwner
;
1802 pTarget
= (Player
*)target
;
1806 Group
* pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1810 uint8 subgroup
= pTarget
->GetSubGroup();
1812 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1814 Player
* Target
= itr
->getSource();
1816 // IsHostileTo check duel and controlled by enemy
1817 if(Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
))
1819 if( pTarget
->IsWithinDistInMap(Target
, radius
) )
1820 TagUnitMap
.push_back(Target
);
1822 if(Pet
* pet
= Target
->GetPet())
1823 if( pTarget
->IsWithinDistInMap(pet
, radius
) )
1824 TagUnitMap
.push_back(pet
);
1830 if(m_caster
->IsWithinDistInMap(owner
, radius
))
1831 TagUnitMap
.push_back(owner
);
1835 TagUnitMap
.push_back(pTarget
);
1837 if(Pet
* pet
= pTarget
->GetPet())
1838 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1839 TagUnitMap
.push_back(pet
);
1845 if(m_targets
.getUnitTarget())
1846 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1847 if(m_targets
.getItemTarget())
1848 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
1851 case TARGET_SELF_FISHING
:
1852 TagUnitMap
.push_back(m_caster
);
1854 case TARGET_CHAIN_HEAL
:
1856 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1860 if (EffectChainTarget
<= 1)
1861 TagUnitMap
.push_back(pUnitTarget
);
1864 unMaxTargets
= EffectChainTarget
;
1865 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1867 UnitList tempUnitMap
;
1869 FillAreaTargets(tempUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), max_range
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
1871 if(m_caster
!= pUnitTarget
&& std::find(tempUnitMap
.begin(),tempUnitMap
.end(), m_caster
) == tempUnitMap
.end() )
1872 tempUnitMap
.push_front(m_caster
);
1874 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1876 if(tempUnitMap
.empty())
1879 if(*tempUnitMap
.begin() == pUnitTarget
)
1880 tempUnitMap
.erase(tempUnitMap
.begin());
1882 TagUnitMap
.push_back(pUnitTarget
);
1883 uint32 t
= unMaxTargets
- 1;
1884 Unit
*prev
= pUnitTarget
;
1885 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1887 while(t
&& next
!= tempUnitMap
.end() )
1889 if(!prev
->IsWithinDist(*next
, CHAIN_SPELL_JUMP_RADIUS
))
1892 if(!prev
->IsWithinLOSInMap(*next
))
1898 if((*next
)->GetHealth() == (*next
)->GetMaxHealth())
1900 next
= tempUnitMap
.erase(next
);
1905 TagUnitMap
.push_back(prev
);
1906 tempUnitMap
.erase(next
);
1907 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1908 next
= tempUnitMap
.begin();
1915 case TARGET_CURRENT_ENEMY_COORDINATES
:
1917 Unit
* currentTarget
= m_targets
.getUnitTarget();
1920 TagUnitMap
.push_back(currentTarget
);
1921 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1922 if(m_spellInfo
->EffectImplicitTargetB
[effIndex
]==TARGET_ALL_ENEMY_IN_AREA_INSTANT
)
1923 FillAreaTargets(TagUnitMap
, currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), radius
, PUSH_TARGET_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1927 case TARGET_AREAEFFECT_PARTY_AND_CLASS
:
1929 Player
* targetPlayer
= m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
1930 ? (Player
*)m_targets
.getUnitTarget() : NULL
;
1932 Group
* pGroup
= targetPlayer
? targetPlayer
->GetGroup() : NULL
;
1935 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1937 Player
* Target
= itr
->getSource();
1939 // IsHostileTo check duel and controlled by enemy
1940 if( Target
&& targetPlayer
->IsWithinDistInMap(Target
, radius
) &&
1941 targetPlayer
->getClass() == Target
->getClass() &&
1942 !m_caster
->IsHostileTo(Target
) )
1944 TagUnitMap
.push_back(Target
);
1948 else if(m_targets
.getUnitTarget())
1949 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1952 case TARGET_TABLE_X_Y_Z_COORDINATES
:
1954 SpellTargetPosition
const* st
= spellmgr
.GetSpellTargetPosition(m_spellInfo
->Id
);
1957 if (st
->target_mapId
== m_caster
->GetMapId())
1958 m_targets
.setDestination(st
->target_X
, st
->target_Y
, st
->target_Z
);
1960 sLog
.outError( "SPELL: wrong map (%u instead %u) target coordinates for spell ID %u", st
->target_mapId
, m_caster
->GetMapId(), m_spellInfo
->Id
);
1963 sLog
.outError( "SPELL: unknown target coordinates for spell ID %u", m_spellInfo
->Id
);
1966 case TARGET_BEHIND_VICTIM
:
1968 Unit
*pTarget
= NULL
;
1970 // explicit cast data from client or server-side cast
1971 // some spell at client send caster
1972 if(m_targets
.getUnitTarget() && m_targets
.getUnitTarget()!=m_caster
)
1973 pTarget
= m_targets
.getUnitTarget();
1974 else if(m_caster
->getVictim())
1975 pTarget
= m_caster
->getVictim();
1976 else if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
1977 pTarget
= ObjectAccessor::GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection());
1981 float _target_x
, _target_y
, _target_z
;
1982 pTarget
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), CONTACT_DISTANCE
, M_PI
);
1983 if(pTarget
->IsWithinLOS(_target_x
, _target_y
, _target_z
))
1985 TagUnitMap
.push_back(m_caster
);
1986 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
1991 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
1992 // if parent spell create dynamic object extract area from it
1993 if(DynamicObject
* dynObj
= m_caster
->GetDynObject(m_triggeredByAuraSpell
? m_triggeredByAuraSpell
->Id
: m_spellInfo
->Id
))
1994 m_targets
.setDestination(dynObj
->GetPositionX(), dynObj
->GetPositionY(), dynObj
->GetPositionZ());
1996 case TARGET_POINT_AT_NORTH
:
1997 case TARGET_POINT_AT_SOUTH
:
1998 case TARGET_POINT_AT_EAST
:
1999 case TARGET_POINT_AT_WEST
:
2000 case TARGET_POINT_AT_NE
:
2001 case TARGET_POINT_AT_NW
:
2002 case TARGET_POINT_AT_SE
:
2003 case TARGET_POINT_AT_SW
:
2006 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2008 Unit
* currentTarget
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
2009 float angle
= currentTarget
!= m_caster
? currentTarget
->GetAngle(m_caster
) : m_caster
->GetOrientation();
2013 case TARGET_POINT_AT_NORTH
: break;
2014 case TARGET_POINT_AT_SOUTH
: angle
+= M_PI
; break;
2015 case TARGET_POINT_AT_EAST
: angle
-= M_PI
/2; break;
2016 case TARGET_POINT_AT_WEST
: angle
+= M_PI
/2; break;
2017 case TARGET_POINT_AT_NE
: angle
-= M_PI
/4; break;
2018 case TARGET_POINT_AT_NW
: angle
+= M_PI
/4; break;
2019 case TARGET_POINT_AT_SE
: angle
-= 3*M_PI
/4; break;
2020 case TARGET_POINT_AT_SW
: angle
+= 3*M_PI
/4; break;
2024 currentTarget
->GetNearPoint2D(x
,y
,radius
,angle
);
2025 m_targets
.setDestination(x
,y
,currentTarget
->GetPositionZ());
2029 case TARGET_DIRECTLY_FORWARD
:
2031 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2033 SpellRangeEntry
const* rEntry
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
2034 float minRange
= GetSpellMinRange(rEntry
);
2035 float maxRange
= GetSpellMaxRange(rEntry
);
2036 float dist
= minRange
+ rand_norm()*(maxRange
-minRange
);
2038 float _target_x
, _target_y
, _target_z
;
2039 m_caster
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), dist
);
2040 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2043 TagUnitMap
.push_back(m_caster
);
2046 case TARGET_EFFECT_SELECT
:
2048 // add here custom effects that need default target.
2049 // FOR EVERY TARGET TYPE THERE IS A DIFFERENT FILL!!
2050 switch(m_spellInfo
->Effect
[effIndex
])
2052 case SPELL_EFFECT_DUMMY
:
2054 switch(m_spellInfo
->Id
)
2056 case 20577: // Cannibalize
2058 WorldObject
* result
= FindCorpseUsing
<MaNGOS::CannibalizeObjectCheck
> ();
2062 switch(result
->GetTypeId())
2066 TagUnitMap
.push_back((Unit
*)result
);
2069 m_targets
.setCorpseTarget((Corpse
*)result
);
2070 if (Player
* owner
= ObjectAccessor::FindPlayer(((Corpse
*)result
)->GetOwnerGUID()))
2071 TagUnitMap
.push_back(owner
);
2077 // clear cooldown at fail
2078 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2079 ((Player
*)m_caster
)->RemoveSpellCooldown(m_spellInfo
->Id
, true);
2080 SendCastResult(SPELL_FAILED_NO_EDIBLE_CORPSES
);
2086 if (m_targets
.getUnitTarget())
2087 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2092 case SPELL_EFFECT_RESURRECT
:
2093 case SPELL_EFFECT_PARRY
:
2094 case SPELL_EFFECT_BLOCK
:
2095 case SPELL_EFFECT_CREATE_ITEM
:
2096 case SPELL_EFFECT_TRIGGER_SPELL
:
2097 case SPELL_EFFECT_TRIGGER_MISSILE
:
2098 case SPELL_EFFECT_LEARN_SPELL
:
2099 case SPELL_EFFECT_SKILL_STEP
:
2100 case SPELL_EFFECT_PROFICIENCY
:
2101 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
2102 case SPELL_EFFECT_SELF_RESURRECT
:
2103 case SPELL_EFFECT_REPUTATION
:
2104 case SPELL_EFFECT_SEND_TAXI
:
2105 if (m_targets
.getUnitTarget())
2106 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2107 // Triggered spells have additional spell targets - cast them even if no explicit unit target is given (required for spell 50516 for example)
2108 else if (m_spellInfo
->Effect
[effIndex
] == SPELL_EFFECT_TRIGGER_SPELL
)
2109 TagUnitMap
.push_back(m_caster
);
2111 case SPELL_EFFECT_SUMMON_PLAYER
:
2112 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetSelection())
2114 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
2116 TagUnitMap
.push_back(target
);
2119 case SPELL_EFFECT_RESURRECT_NEW
:
2120 if (m_targets
.getUnitTarget())
2121 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2122 if (m_targets
.getCorpseTargetGUID())
2124 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
, m_targets
.getCorpseTargetGUID());
2127 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
2129 TagUnitMap
.push_back(owner
);
2133 case SPELL_EFFECT_SUMMON
:
2134 if (m_spellInfo
->EffectMiscValueB
[effIndex
] == SUMMON_TYPE_POSESSED
||
2135 m_spellInfo
->EffectMiscValueB
[effIndex
] == SUMMON_TYPE_POSESSED2
)
2137 if (m_targets
.getUnitTarget())
2138 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2141 TagUnitMap
.push_back(m_caster
);
2143 case SPELL_EFFECT_SUMMON_CHANGE_ITEM
:
2144 case SPELL_EFFECT_TRANS_DOOR
:
2145 case SPELL_EFFECT_ADD_FARSIGHT
:
2146 case SPELL_EFFECT_APPLY_GLYPH
:
2147 case SPELL_EFFECT_STUCK
:
2148 case SPELL_EFFECT_FEED_PET
:
2149 case SPELL_EFFECT_DESTROY_ALL_TOTEMS
:
2150 case SPELL_EFFECT_SKILL
:
2151 TagUnitMap
.push_back(m_caster
);
2153 case SPELL_EFFECT_LEARN_PET_SPELL
:
2154 if (Pet
* pet
= m_caster
->GetPet())
2155 TagUnitMap
.push_back(pet
);
2157 case SPELL_EFFECT_ENCHANT_ITEM
:
2158 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
2159 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
2160 case SPELL_EFFECT_DISENCHANT
:
2161 case SPELL_EFFECT_PROSPECTING
:
2162 case SPELL_EFFECT_MILLING
:
2163 if (m_targets
.getItemTarget())
2164 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
2166 case SPELL_EFFECT_APPLY_AURA
:
2167 switch(m_spellInfo
->EffectApplyAuraName
[effIndex
])
2169 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)
2170 case SPELL_AURA_ADD_PCT_MODIFIER
:
2171 TagUnitMap
.push_back(m_caster
);
2173 default: // apply to target in other case
2174 if (m_targets
.getUnitTarget())
2175 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2179 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY
:
2181 if(m_spellInfo
->Attributes
== 0x9050000 || m_spellInfo
->Attributes
== 0x10000)
2182 SetTargetMap(effIndex
,TARGET_AREAEFFECT_PARTY
, TagUnitMap
);
2184 case SPELL_EFFECT_SKIN_PLAYER_CORPSE
:
2185 if (m_targets
.getUnitTarget())
2186 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2187 else if (m_targets
.getCorpseTargetGUID())
2189 if (Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID()))
2190 if (Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID()))
2191 TagUnitMap
.push_back(owner
);
2203 if (unMaxTargets
&& TagUnitMap
.size() > unMaxTargets
)
2205 // make sure one unit is always removed per iteration
2206 uint32 removed_utarget
= 0;
2207 for (UnitList::iterator itr
= TagUnitMap
.begin(), next
; itr
!= TagUnitMap
.end(); itr
= next
)
2211 if (!*itr
) continue;
2212 if ((*itr
) == m_targets
.getUnitTarget())
2214 TagUnitMap
.erase(itr
);
2215 removed_utarget
= 1;
2219 // remove random units from the map
2220 while (TagUnitMap
.size() > unMaxTargets
- removed_utarget
)
2222 uint32 poz
= urand(0, TagUnitMap
.size()-1);
2223 for (UnitList::iterator itr
= TagUnitMap
.begin(); itr
!= TagUnitMap
.end(); ++itr
, --poz
)
2225 if (!*itr
) continue;
2229 TagUnitMap
.erase(itr
);
2234 // the player's target will always be added to the map
2235 if (removed_utarget
&& m_targets
.getUnitTarget())
2236 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2240 void Spell::prepare(SpellCastTargets
const* targets
, Aura
* triggeredByAura
)
2242 m_targets
= *targets
;
2244 m_spellState
= SPELL_STATE_PREPARING
;
2246 m_castPositionX
= m_caster
->GetPositionX();
2247 m_castPositionY
= m_caster
->GetPositionY();
2248 m_castPositionZ
= m_caster
->GetPositionZ();
2249 m_castOrientation
= m_caster
->GetOrientation();
2252 m_triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
2254 // create and add update event for this spell
2255 SpellEvent
* Event
= new SpellEvent(this);
2256 m_caster
->m_Events
.AddEvent(Event
, m_caster
->m_Events
.CalculateTime(1));
2258 //Prevent casting at cast another spell (ServerSide check)
2259 if(m_caster
->IsNonMeleeSpellCasted(false, true, true) && m_cast_count
)
2261 SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS
);
2267 m_powerCost
= CalculatePowerCost();
2269 SpellCastResult result
= CheckCast(true);
2270 if(result
!= SPELL_CAST_OK
&& !IsAutoRepeat()) //always cast autorepeat dummy for triggering
2274 SendChannelUpdate(0);
2275 triggeredByAura
->SetAuraDuration(0);
2277 SendCastResult(result
);
2282 // Prepare data for triggers
2283 prepareDataForTriggerSystem();
2285 // calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
2286 m_casttime
= GetSpellCastTime(m_spellInfo
, this);
2288 // set timer base at cast time
2291 // stealth must be removed at cast starting (at show channel bar)
2292 // skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
2293 if ( !m_IsTriggeredSpell
&& isSpellBreakStealth(m_spellInfo
) )
2295 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
2296 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
2299 if(m_IsTriggeredSpell
)
2303 m_caster
->SetCurrentCastedSpell( this );
2308 void Spell::cancel()
2310 if(m_spellState
== SPELL_STATE_FINISHED
)
2313 m_autoRepeat
= false;
2314 switch (m_spellState
)
2316 case SPELL_STATE_PREPARING
:
2317 case SPELL_STATE_DELAYED
:
2320 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2323 case SPELL_STATE_CASTING
:
2325 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2327 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2329 Unit
* unit
= m_caster
->GetGUID()==(*ihit
).targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2330 if( unit
&& unit
->isAlive() )
2331 unit
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2335 m_caster
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2336 SendChannelUpdate(0);
2338 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2347 m_caster
->RemoveDynObject(m_spellInfo
->Id
);
2348 m_caster
->RemoveGameObject(m_spellInfo
->Id
,true);
2351 void Spell::cast(bool skipCheck
)
2353 SetExecutedCurrently(true);
2355 // update pointers base at GUIDs to prevent access to non-existed already object
2358 // cancel at lost main target unit
2359 if(!m_targets
.getUnitTarget() && m_targets
.getUnitTargetGUID() && m_targets
.getUnitTargetGUID() != m_caster
->GetGUID())
2362 SetExecutedCurrently(false);
2366 if(m_caster
->GetTypeId() != TYPEID_PLAYER
&& m_targets
.getUnitTarget() && m_targets
.getUnitTarget() != m_caster
)
2367 m_caster
->SetInFront(m_targets
.getUnitTarget());
2369 SpellCastResult castResult
= CheckPower();
2370 if(castResult
!= SPELL_CAST_OK
)
2372 SendCastResult(castResult
);
2374 SetExecutedCurrently(false);
2378 // triggered cast called from Spell::prepare where it was already checked
2381 castResult
= CheckCast(false);
2382 if(castResult
!= SPELL_CAST_OK
)
2384 SendCastResult(castResult
);
2386 SetExecutedCurrently(false);
2391 // different triggred (for caster) and precast (casted before apply effect to target) cases
2392 switch(m_spellInfo
->SpellFamilyName
)
2394 case SPELLFAMILY_GENERIC
:
2396 if (m_spellInfo
->Mechanic
== MECHANIC_BANDAGE
) // Bandages
2397 AddPrecastSpell(11196); // Recently Bandaged
2398 else if(m_spellInfo
->SpellIconID
== 1662 && m_spellInfo
->AttributesEx
& 0x20)
2399 // Blood Fury (Racial)
2400 AddPrecastSpell(23230); // Blood Fury - Healing Reduction
2403 case SPELLFAMILY_MAGE
:
2406 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000008000000000))
2407 AddPrecastSpell(41425); // Hypothermia
2410 case SPELLFAMILY_PRIEST
:
2412 // Power Word: Shield
2413 if (m_spellInfo
->Mechanic
== MECHANIC_SHIELD
&&
2414 (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000001)))
2415 AddPrecastSpell(6788); // Weakened Soul
2416 // Prayer of Mending (jump animation), we need formal caster instead original for correct animation
2417 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000002000000000))
2418 AddTriggeredSpell(41637);
2420 switch(m_spellInfo
->Id
)
2422 case 15237: AddTriggeredSpell(23455); break;// Holy Nova, rank 1
2423 case 15430: AddTriggeredSpell(23458); break;// Holy Nova, rank 2
2424 case 15431: AddTriggeredSpell(23459); break;// Holy Nova, rank 3
2425 case 27799: AddTriggeredSpell(27803); break;// Holy Nova, rank 4
2426 case 27800: AddTriggeredSpell(27804); break;// Holy Nova, rank 5
2427 case 27801: AddTriggeredSpell(27805); break;// Holy Nova, rank 6
2428 case 25331: AddTriggeredSpell(25329); break;// Holy Nova, rank 7
2429 case 48077: AddTriggeredSpell(48075); break;// Holy Nova, rank 8
2430 case 48078: AddTriggeredSpell(48076); break;// Holy Nova, rank 9
2435 case SPELLFAMILY_ROGUE
:
2436 // Fan of Knives (main hand)
2437 if (m_spellInfo
->Id
== 51723 && m_caster
->GetTypeId() == TYPEID_PLAYER
&&
2438 ((Player
*)m_caster
)->haveOffhandWeapon())
2440 AddTriggeredSpell(52874); // Fan of Knives (offhand)
2443 case SPELLFAMILY_PALADIN
:
2445 // Divine Shield, Divine Protection or Hand of Protection
2446 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000400080))
2448 AddPrecastSpell(25771); // Forbearance
2449 AddPrecastSpell(61987); // Avenging Wrath Marker
2451 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x200000000000))
2452 AddPrecastSpell(61987); // Avenging Wrath Marker
2455 case SPELLFAMILY_SHAMAN
:
2458 if (m_spellInfo
->Id
== 2825)
2459 AddPrecastSpell(57724); // Sated
2461 else if (m_spellInfo
->Id
== 32182)
2462 AddPrecastSpell(57723); // Exhaustion
2469 // traded items have trade slot instead of guid in m_itemTargetGUID
2470 // set to real guid to be sent later to the client
2471 m_targets
.updateTradeSlotItem();
2473 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2475 if (!m_IsTriggeredSpell
&& m_CastItem
)
2476 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM
, m_CastItem
->GetEntry());
2478 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL
, m_spellInfo
->Id
);
2483 if(m_spellState
== SPELL_STATE_FINISHED
) // stop cast if spell marked as finish somewhere in FillTargetMap
2485 SetExecutedCurrently(false);
2490 SendSpellCooldown();
2493 TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
2495 SendCastResult(castResult
);
2496 SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2498 // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2499 if (m_spellInfo
->speed
> 0.0f
)
2502 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2503 // in case delayed spell remove item at cast delay start
2506 // Okay, maps created, now prepare flags
2507 m_immediateHandled
= false;
2508 m_spellState
= SPELL_STATE_DELAYED
;
2513 // Immediate spell, no big deal
2517 SetExecutedCurrently(false);
2520 void Spell::handle_immediate()
2522 // start channeling if applicable
2523 if(IsChanneledSpell(m_spellInfo
))
2525 int32 duration
= GetSpellDuration(m_spellInfo
);
2528 // Apply duration mod
2529 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
2530 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_DURATION
, duration
);
2531 m_spellState
= SPELL_STATE_CASTING
;
2532 SendChannelStart(duration
);
2536 // process immediate effects (items, ground, etc.) also initialize some variables
2537 _handle_immediate_phase();
2539 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2540 DoAllEffectOnTarget(&(*ihit
));
2542 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2543 DoAllEffectOnTarget(&(*ihit
));
2545 // spell is finished, perform some last features of the spell here
2546 _handle_finish_phase();
2548 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2551 if(m_spellState
!= SPELL_STATE_CASTING
)
2552 finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell)
2555 uint64
Spell::handle_delayed(uint64 t_offset
)
2557 uint64 next_time
= 0;
2559 if (!m_immediateHandled
)
2561 _handle_immediate_phase();
2562 m_immediateHandled
= true;
2565 // 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)
2566 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2568 if (ihit
->processed
== false)
2570 if ( ihit
->timeDelay
<= t_offset
)
2571 DoAllEffectOnTarget(&(*ihit
));
2572 else if( next_time
== 0 || ihit
->timeDelay
< next_time
)
2573 next_time
= ihit
->timeDelay
;
2577 // now recheck gameobject targeting correctness
2578 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
2580 if (ighit
->processed
== false)
2582 if ( ighit
->timeDelay
<= t_offset
)
2583 DoAllEffectOnTarget(&(*ighit
));
2584 else if( next_time
== 0 || ighit
->timeDelay
< next_time
)
2585 next_time
= ighit
->timeDelay
;
2588 // All targets passed - need finish phase
2591 // spell is finished, perform some last features of the spell here
2592 _handle_finish_phase();
2594 finish(true); // successfully finish spell cast
2596 // return zero, spell is finished now
2601 // spell is unfinished, return next execution time
2606 void Spell::_handle_immediate_phase()
2608 // handle some immediate features of the spell here
2609 HandleThreatSpells(m_spellInfo
->Id
);
2611 m_needSpellLog
= IsNeedSendToClient();
2612 for(uint32 j
= 0; j
< 3; ++j
)
2614 if(m_spellInfo
->Effect
[j
] == 0)
2617 // apply Send Event effect to ground in case empty target lists
2618 if( m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
&& !HaveTargetsForEffect(j
) )
2620 HandleEffects(NULL
, NULL
, NULL
, j
);
2624 // Don't do spell log, if is school damage spell
2625 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
|| m_spellInfo
->Effect
[j
] == 0)
2626 m_needSpellLog
= false;
2628 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[j
];
2629 if(m_originalCaster
)
2630 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
2631 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
2633 // initialize multipliers
2634 m_damageMultipliers
[j
] = 1.0f
;
2635 if( (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_HEAL
) &&
2636 (EffectChainTarget
> 1) )
2637 m_applyMultiplierMask
|= 1 << j
;
2640 // initialize Diminishing Returns Data
2641 m_diminishLevel
= DIMINISHING_LEVEL_1
;
2642 m_diminishGroup
= DIMINISHING_NONE
;
2645 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
2646 DoAllEffectOnTarget(&(*ihit
));
2649 for(uint32 j
= 0; j
< 3; ++j
)
2651 // persistent area auras target only the ground
2652 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2653 HandleEffects(NULL
, NULL
, NULL
, j
);
2657 void Spell::_handle_finish_phase()
2664 void Spell::SendSpellCooldown()
2666 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
2669 Player
* _player
= (Player
*)m_caster
;
2671 // mana/health/etc potions, disabled by client (until combat out as declarate)
2672 if (m_CastItem
&& m_CastItem
->IsPotion())
2674 // need in some way provided data for Spell::finish SendCooldownEvent
2675 _player
->SetLastPotionId(m_CastItem
->GetEntry());
2679 // have infinity cooldown but set at aura apply
2680 if(m_spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
2683 _player
->AddSpellAndCategoryCooldowns(m_spellInfo
,m_CastItem
? m_CastItem
->GetEntry() : 0, this);
2686 void Spell::update(uint32 difftime
)
2688 // update pointers based at it's GUIDs
2691 if(m_targets
.getUnitTargetGUID() && !m_targets
.getUnitTarget())
2697 // check if the player caster has moved before the spell finished
2698 if ((m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_timer
!= 0) &&
2699 (m_castPositionX
!= m_caster
->GetPositionX() || m_castPositionY
!= m_caster
->GetPositionY() || m_castPositionZ
!= m_caster
->GetPositionZ()) &&
2700 (m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
|| !((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEMENTFLAG_FALLING
)))
2702 // always cancel for channeled spells
2703 if( m_spellState
== SPELL_STATE_CASTING
)
2705 // don't cancel for melee, autorepeat, triggered and instant spells
2706 else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_MOVEMENT
))
2710 switch(m_spellState
)
2712 case SPELL_STATE_PREPARING
:
2716 if(difftime
>= m_timer
)
2719 m_timer
-= difftime
;
2722 if(m_timer
== 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat())
2725 case SPELL_STATE_CASTING
:
2729 if( m_caster
->GetTypeId() == TYPEID_PLAYER
)
2731 // check if player has jumped before the channeling finished
2732 if(((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEMENTFLAG_JUMPING
))
2735 // check for incapacitating player states
2736 if( m_caster
->hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_CONFUSED
))
2739 // check if player has turned if flag is set
2740 if( m_spellInfo
->ChannelInterruptFlags
& CHANNEL_FLAG_TURNING
&& m_castOrientation
!= m_caster
->GetOrientation() )
2744 // check if there are alive targets left
2745 if (!IsAliveUnitPresentInTargetList())
2747 SendChannelUpdate(0);
2751 if(difftime
>= m_timer
)
2754 m_timer
-= difftime
;
2759 SendChannelUpdate(0);
2761 // channeled spell processed independently for quest targeting
2762 // cast at creature (or GO) quest objectives update at successful cast channel finished
2763 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
2764 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() )
2766 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
2768 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2770 TargetInfo
* target
= &*ihit
;
2771 if(!IS_CREATURE_GUID(target
->targetGUID
))
2774 Unit
* unit
= m_caster
->GetGUID() == target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, target
->targetGUID
);
2778 p
->CastedCreatureOrGO(unit
->GetEntry(), unit
->GetGUID(), m_spellInfo
->Id
);
2781 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
2783 GOTargetInfo
* target
= &*ihit
;
2785 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
2789 p
->CastedCreatureOrGO(go
->GetEntry(), go
->GetGUID(), m_spellInfo
->Id
);
2803 void Spell::finish(bool ok
)
2808 if(m_spellState
== SPELL_STATE_FINISHED
)
2811 m_spellState
= SPELL_STATE_FINISHED
;
2813 // other code related only to successfully finished spells
2818 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2819 ((Player
*)m_caster
)->RemoveSpellMods(this);
2821 // handle SPELL_AURA_ADD_TARGET_TRIGGER auras
2822 Unit::AuraList
const& targetTriggers
= m_caster
->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER
);
2823 for(Unit::AuraList::const_iterator i
= targetTriggers
.begin(); i
!= targetTriggers
.end(); ++i
)
2825 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
2827 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2828 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2830 // check m_caster->GetGUID() let load auras at login and speedup most often case
2831 Unit
*unit
= m_caster
->GetGUID()== ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2832 if (unit
&& unit
->isAlive())
2834 SpellEntry
const *auraSpellInfo
= (*i
)->GetSpellProto();
2835 uint32 auraSpellIdx
= (*i
)->GetEffIndex();
2836 // Calculate chance at that moment (can be depend for example from combo points)
2837 int32 chance
= m_caster
->CalculateSpellDamage(auraSpellInfo
, auraSpellIdx
, (*i
)->GetBasePoints(),unit
);
2838 if(roll_chance_i(chance
))
2839 m_caster
->CastSpell(unit
, auraSpellInfo
->EffectTriggerSpell
[auraSpellIdx
], true, NULL
, (*i
));
2844 // Heal caster for all health leech from all targets
2846 m_caster
->DealHeal(m_caster
, uint32(m_healthLeech
), m_spellInfo
);
2848 if (IsMeleeAttackResetSpell())
2850 m_caster
->resetAttackTimer(BASE_ATTACK
);
2851 if(m_caster
->haveOffhandWeapon())
2852 m_caster
->resetAttackTimer(OFF_ATTACK
);
2855 /*if (IsRangedAttackResetSpell())
2856 m_caster->resetAttackTimer(RANGED_ATTACK);*/
2858 // Clear combo at finish state
2859 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& NeedsComboPoints(m_spellInfo
))
2861 // Not drop combopoints if negative spell and if any miss on enemy exist
2862 bool needDrop
= true;
2863 if (!IsPositiveSpell(m_spellInfo
->Id
))
2865 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2867 if (ihit
->missCondition
!= SPELL_MISS_NONE
&& ihit
->targetGUID
!=m_caster
->GetGUID())
2875 ((Player
*)m_caster
)->ClearComboPoints();
2878 // potions disabled by client, send event "not in combat" if need
2879 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2880 ((Player
*)m_caster
)->UpdatePotionCooldown(this);
2882 // call triggered spell only at successful cast (after clear combo points -> for add some if need)
2883 if(!m_TriggerSpells
.empty())
2884 CastTriggerSpells();
2886 // Stop Attack for some spells
2887 if( m_spellInfo
->Attributes
& SPELL_ATTR_STOP_ATTACK_TARGET
)
2888 m_caster
->AttackStop();
2891 void Spell::SendCastResult(SpellCastResult result
)
2893 if(result
== SPELL_CAST_OK
)
2896 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
2899 if(((Player
*)m_caster
)->GetSession()->PlayerLoading()) // don't send cast results at loading time
2902 SendCastResult((Player
*)m_caster
,m_spellInfo
,m_cast_count
,result
);
2905 void Spell::SendCastResult(Player
* caster
, SpellEntry
const* spellInfo
, uint8 cast_count
, SpellCastResult result
)
2907 if(result
== SPELL_CAST_OK
)
2910 WorldPacket
data(SMSG_CAST_FAILED
, (4+1+1));
2911 data
<< uint8(cast_count
); // single cast or multi 2.3 (0/1)
2912 data
<< uint32(spellInfo
->Id
);
2913 data
<< uint8(result
); // problem
2916 case SPELL_FAILED_REQUIRES_SPELL_FOCUS
:
2917 data
<< uint32(spellInfo
->RequiresSpellFocus
);
2919 case SPELL_FAILED_REQUIRES_AREA
:
2920 // hardcode areas limitation case
2921 switch(spellInfo
->Id
)
2923 case 41617: // Cenarion Mana Salve
2924 case 41619: // Cenarion Healing Salve
2925 data
<< uint32(3905);
2927 case 41618: // Bottled Nethergon Energy
2928 case 41620: // Bottled Nethergon Vapor
2929 data
<< uint32(3842);
2931 case 45373: // Bloodberry Elixir
2932 data
<< uint32(4075);
2934 default: // default case (don't must be)
2939 case SPELL_FAILED_TOTEMS
:
2940 if(spellInfo
->Totem
[0])
2941 data
<< uint32(spellInfo
->Totem
[0]);
2942 if(spellInfo
->Totem
[1])
2943 data
<< uint32(spellInfo
->Totem
[1]);
2945 case SPELL_FAILED_TOTEM_CATEGORY
:
2946 if(spellInfo
->TotemCategory
[0])
2947 data
<< uint32(spellInfo
->TotemCategory
[0]);
2948 if(spellInfo
->TotemCategory
[1])
2949 data
<< uint32(spellInfo
->TotemCategory
[1]);
2951 case SPELL_FAILED_EQUIPPED_ITEM_CLASS
:
2952 data
<< uint32(spellInfo
->EquippedItemClass
);
2953 data
<< uint32(spellInfo
->EquippedItemSubClassMask
);
2954 //data << uint32(spellInfo->EquippedItemInventoryTypeMask);
2959 caster
->GetSession()->SendPacket(&data
);
2962 void Spell::SendSpellStart()
2964 if(!IsNeedSendToClient())
2967 sLog
.outDebug("Sending SMSG_SPELL_START id=%u", m_spellInfo
->Id
);
2969 uint32 castFlags
= CAST_FLAG_UNKNOWN1
;
2971 castFlags
|= CAST_FLAG_AMMO
;
2973 if(m_spellInfo
->runeCostID
)
2974 castFlags
|= CAST_FLAG_UNKNOWN10
;
2976 WorldPacket
data(SMSG_SPELL_START
, (8+8+4+4+2));
2978 data
.append(m_CastItem
->GetPackGUID());
2980 data
.append(m_caster
->GetPackGUID());
2982 data
.append(m_caster
->GetPackGUID());
2983 data
<< uint8(m_cast_count
); // pending spell cast?
2984 data
<< uint32(m_spellInfo
->Id
); // spellId
2985 data
<< uint32(castFlags
); // cast flags
2986 data
<< uint32(m_timer
); // delay?
2988 m_targets
.write(&data
);
2990 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // predicted power?
2993 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
2995 uint8 v1
= 0;//m_runesState;
2996 uint8 v2
= 0;//((Player*)m_caster)->GetRunesState();
2997 data
<< uint8(v1
); // runes state before
2998 data
<< uint8(v2
); // runes state after
2999 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
3002 if(m
& v1
) // usable before...
3003 if(!(m
& v2
)) // ...but on cooldown now...
3004 data
<< uint8(0); // some unknown byte (time?)
3008 if ( castFlags
& CAST_FLAG_AMMO
)
3009 WriteAmmoToPacket(&data
);
3011 m_caster
->SendMessageToSet(&data
, true);
3014 void Spell::SendSpellGo()
3016 // not send invisible spell casting
3017 if(!IsNeedSendToClient())
3020 sLog
.outDebug("Sending SMSG_SPELL_GO id=%u", m_spellInfo
->Id
);
3022 uint32 castFlags
= CAST_FLAG_UNKNOWN3
;
3024 castFlags
|= CAST_FLAG_AMMO
; // arrows/bullets visual
3026 if((m_caster
->GetTypeId() == TYPEID_PLAYER
) && (m_caster
->getClass() == CLASS_DEATH_KNIGHT
) && m_spellInfo
->runeCostID
)
3028 castFlags
|= CAST_FLAG_UNKNOWN10
; // same as in SMSG_SPELL_START
3029 castFlags
|= CAST_FLAG_UNKNOWN6
; // makes cooldowns visible
3030 castFlags
|= CAST_FLAG_UNKNOWN7
; // rune cooldowns list
3033 WorldPacket
data(SMSG_SPELL_GO
, 50); // guess size
3036 data
.append(m_CastItem
->GetPackGUID());
3038 data
.append(m_caster
->GetPackGUID());
3040 data
.append(m_caster
->GetPackGUID());
3041 data
<< uint8(m_cast_count
); // pending spell cast?
3042 data
<< uint32(m_spellInfo
->Id
); // spellId
3043 data
<< uint32(castFlags
); // cast flags
3044 data
<< uint32(getMSTime()); // timestamp
3046 WriteSpellGoTargets(&data
);
3048 m_targets
.write(&data
);
3050 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // unknown wotlk, predicted power?
3053 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
3055 uint8 v1
= m_runesState
;
3056 uint8 v2
= ((Player
*)m_caster
)->GetRunesState();
3057 data
<< uint8(v1
); // runes state before
3058 data
<< uint8(v2
); // runes state after
3059 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
3062 if(m
& v1
) // usable before...
3063 if(!(m
& v2
)) // ...but on cooldown now...
3064 data
<< uint8(0); // some unknown byte (time?)
3068 if ( castFlags
& CAST_FLAG_UNKNOWN4
) // unknown wotlk
3074 if ( castFlags
& CAST_FLAG_AMMO
)
3075 WriteAmmoToPacket(&data
);
3077 if ( castFlags
& CAST_FLAG_UNKNOWN5
) // unknown wotlk
3083 if ( m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
3088 m_caster
->SendMessageToSet(&data
, true);
3091 void Spell::WriteAmmoToPacket( WorldPacket
* data
)
3093 uint32 ammoInventoryType
= 0;
3094 uint32 ammoDisplayID
= 0;
3096 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3098 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack( RANGED_ATTACK
);
3101 ammoInventoryType
= pItem
->GetProto()->InventoryType
;
3102 if( ammoInventoryType
== INVTYPE_THROWN
)
3103 ammoDisplayID
= pItem
->GetProto()->DisplayInfoID
;
3106 uint32 ammoID
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
3109 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( ammoID
);
3112 ammoDisplayID
= pProto
->DisplayInfoID
;
3113 ammoInventoryType
= pProto
->InventoryType
;
3116 else if(m_caster
->GetDummyAura(46699)) // Requires No Ammo
3118 ammoDisplayID
= 5996; // normal arrow
3119 ammoInventoryType
= INVTYPE_AMMO
;
3126 for (uint8 i
= 0; i
< 3; ++i
)
3128 if(uint32 item_id
= m_caster
->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID
+ i
))
3130 if(ItemEntry
const * itemEntry
= sItemStore
.LookupEntry(item_id
))
3132 if(itemEntry
->Class
==ITEM_CLASS_WEAPON
)
3134 switch(itemEntry
->SubClass
)
3136 case ITEM_SUBCLASS_WEAPON_THROWN
:
3137 ammoDisplayID
= itemEntry
->DisplayId
;
3138 ammoInventoryType
= itemEntry
->InventoryType
;
3140 case ITEM_SUBCLASS_WEAPON_BOW
:
3141 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
3142 ammoDisplayID
= 5996; // is this need fixing?
3143 ammoInventoryType
= INVTYPE_AMMO
;
3145 case ITEM_SUBCLASS_WEAPON_GUN
:
3146 ammoDisplayID
= 5998; // is this need fixing?
3147 ammoInventoryType
= INVTYPE_AMMO
;
3159 *data
<< uint32(ammoDisplayID
);
3160 *data
<< uint32(ammoInventoryType
);
3163 void Spell::WriteSpellGoTargets( WorldPacket
* data
)
3165 // This function also fill data for channeled spells:
3166 // m_needAliveTargetMask req for stop channelig if one target die
3167 uint32 hit
= m_UniqueGOTargetInfo
.size(); // Always hits on GO
3169 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3171 if ((*ihit
).effectMask
== 0) // No effect apply - all immuned add state
3173 // possibly SPELL_MISS_IMMUNE2 for this??
3174 ihit
->missCondition
= SPELL_MISS_IMMUNE2
;
3177 else if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
3183 *data
<< (uint8
)hit
;
3184 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3186 if ((*ihit
).missCondition
== SPELL_MISS_NONE
) // Add only hits
3188 *data
<< uint64(ihit
->targetGUID
);
3189 m_needAliveTargetMask
|=ihit
->effectMask
;
3193 for(std::list
<GOTargetInfo
>::const_iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end(); ++ighit
)
3194 *data
<< uint64(ighit
->targetGUID
); // Always hits
3196 *data
<< (uint8
)miss
;
3197 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3199 if( ihit
->missCondition
!= SPELL_MISS_NONE
) // Add only miss
3201 *data
<< uint64(ihit
->targetGUID
);
3202 *data
<< uint8(ihit
->missCondition
);
3203 if( ihit
->missCondition
== SPELL_MISS_REFLECT
)
3204 *data
<< uint8(ihit
->reflectResult
);
3207 // Reset m_needAliveTargetMask for non channeled spell
3208 if(!IsChanneledSpell(m_spellInfo
))
3209 m_needAliveTargetMask
= 0;
3212 void Spell::SendLogExecute()
3214 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
3216 WorldPacket
data(SMSG_SPELLLOGEXECUTE
, (8+4+4+4+4+8));
3218 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
3219 data
.append(m_caster
->GetPackGUID());
3221 data
.append(target
->GetPackGUID());
3223 data
<< uint32(m_spellInfo
->Id
);
3225 data
<< uint32(count1
); // count1 (effect count?)
3226 for(uint32 i
= 0; i
< count1
; ++i
)
3228 data
<< uint32(m_spellInfo
->Effect
[0]); // spell effect
3230 data
<< uint32(count2
); // count2 (target count?)
3231 for(uint32 j
= 0; j
< count2
; ++j
)
3233 switch(m_spellInfo
->Effect
[0])
3235 case SPELL_EFFECT_POWER_DRAIN
:
3236 if(Unit
*unit
= m_targets
.getUnitTarget())
3237 data
.append(unit
->GetPackGUID());
3244 case SPELL_EFFECT_ADD_EXTRA_ATTACKS
:
3245 if(Unit
*unit
= m_targets
.getUnitTarget())
3246 data
.append(unit
->GetPackGUID());
3249 data
<< uint32(0); // count?
3251 case SPELL_EFFECT_INTERRUPT_CAST
:
3252 if(Unit
*unit
= m_targets
.getUnitTarget())
3253 data
.append(unit
->GetPackGUID());
3256 data
<< uint32(0); // spellid
3258 case SPELL_EFFECT_DURABILITY_DAMAGE
:
3259 if(Unit
*unit
= m_targets
.getUnitTarget())
3260 data
.append(unit
->GetPackGUID());
3266 case SPELL_EFFECT_OPEN_LOCK
:
3267 if(Item
*item
= m_targets
.getItemTarget())
3268 data
.append(item
->GetPackGUID());
3272 case SPELL_EFFECT_CREATE_ITEM
:
3273 case SPELL_EFFECT_CREATE_ITEM_2
:
3274 data
<< uint32(m_spellInfo
->EffectItemType
[0]);
3276 case SPELL_EFFECT_SUMMON
:
3277 case SPELL_EFFECT_TRANS_DOOR
:
3278 case SPELL_EFFECT_SUMMON_PET
:
3279 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
3280 case SPELL_EFFECT_CREATE_HOUSE
:
3281 case SPELL_EFFECT_DUEL
:
3282 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1
:
3283 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2
:
3284 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3
:
3285 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4
:
3286 if(Unit
*unit
= m_targets
.getUnitTarget())
3287 data
.append(unit
->GetPackGUID());
3288 else if(m_targets
.getItemTargetGUID())
3289 data
.appendPackGUID(m_targets
.getItemTargetGUID());
3290 else if(GameObject
*go
= m_targets
.getGOTarget())
3291 data
.append(go
->GetPackGUID());
3293 data
<< uint8(0); // guid
3295 case SPELL_EFFECT_FEED_PET
:
3296 data
<< uint32(m_targets
.getItemTargetEntry());
3298 case SPELL_EFFECT_DISMISS_PET
:
3299 if(Unit
*unit
= m_targets
.getUnitTarget())
3300 data
.append(unit
->GetPackGUID());
3304 case SPELL_EFFECT_RESURRECT
:
3305 case SPELL_EFFECT_RESURRECT_NEW
:
3306 if(Unit
*unit
= m_targets
.getUnitTarget())
3307 data
.append(unit
->GetPackGUID());
3317 m_caster
->SendMessageToSet(&data
, true);
3320 void Spell::SendInterrupted(uint8 result
)
3322 WorldPacket
data(SMSG_SPELL_FAILURE
, (8+4+1));
3323 data
.append(m_caster
->GetPackGUID());
3324 data
<< uint8(m_cast_count
);
3325 data
<< uint32(m_spellInfo
->Id
);
3326 data
<< uint8(result
);
3327 m_caster
->SendMessageToSet(&data
, true);
3329 data
.Initialize(SMSG_SPELL_FAILED_OTHER
, (8+4));
3330 data
.append(m_caster
->GetPackGUID());
3331 data
<< uint8(m_cast_count
);
3332 data
<< uint32(m_spellInfo
->Id
);
3333 data
<< uint8(result
);
3334 m_caster
->SendMessageToSet(&data
, true);
3337 void Spell::SendChannelUpdate(uint32 time
)
3341 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, 0);
3342 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, 0);
3345 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3348 WorldPacket
data( MSG_CHANNEL_UPDATE
, 8+4 );
3349 data
.append(m_caster
->GetPackGUID());
3350 data
<< uint32(time
);
3352 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3355 void Spell::SendChannelStart(uint32 duration
)
3357 WorldObject
* target
= NULL
;
3359 // select first not resisted target from target list for _0_ effect
3360 if(!m_UniqueTargetInfo
.empty())
3362 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin(); itr
!= m_UniqueTargetInfo
.end(); ++itr
)
3364 if( (itr
->effectMask
& (1 << 0)) && itr
->reflectResult
== SPELL_MISS_NONE
&& itr
->targetGUID
!= m_caster
->GetGUID())
3366 target
= ObjectAccessor::GetUnit(*m_caster
, itr
->targetGUID
);
3371 else if(!m_UniqueGOTargetInfo
.empty())
3373 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin(); itr
!= m_UniqueGOTargetInfo
.end(); ++itr
)
3375 if(itr
->effectMask
& (1 << 0) )
3377 target
= m_caster
->GetMap()->GetGameObject(itr
->targetGUID
);
3383 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3385 WorldPacket
data( MSG_CHANNEL_START
, (8+4+4) );
3386 data
.append(m_caster
->GetPackGUID());
3387 data
<< uint32(m_spellInfo
->Id
);
3388 data
<< uint32(duration
);
3390 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3395 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, target
->GetGUID());
3396 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, m_spellInfo
->Id
);
3399 void Spell::SendResurrectRequest(Player
* target
)
3401 // Both players and NPCs can resurrect using spells - have a look at creature 28487 for example
3402 // However, the packet structure differs slightly
3404 const char* sentName
= m_caster
->GetTypeId() == TYPEID_PLAYER
? "" : m_caster
->GetNameForLocaleIdx(target
->GetSession()->GetSessionDbLocaleIndex());
3406 WorldPacket
data(SMSG_RESURRECT_REQUEST
, (8+4+strlen(sentName
)+1+1+1));
3407 data
<< uint64(m_caster
->GetGUID());
3408 data
<< uint32(strlen(sentName
) + 1);
3413 data
<< uint8(m_caster
->GetTypeId() == TYPEID_PLAYER
? 0 : 1);
3414 target
->GetSession()->SendPacket(&data
);
3417 void Spell::SendPlaySpellVisual(uint32 SpellID
)
3419 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3422 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 8 + 4);
3423 data
<< uint64(m_caster
->GetGUID());
3424 data
<< uint32(SpellID
); // spell visual id?
3425 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
3428 void Spell::TakeCastItem()
3430 if(!m_CastItem
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
3433 // not remove cast item at triggered spell (equipping, weapon damage, etc)
3434 if(m_IsTriggeredSpell
)
3437 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3441 // This code is to avoid a crash
3442 // I'm not sure, if this is really an error, but I guess every item needs a prototype
3443 sLog
.outError("Cast item has no item prototype highId=%d, lowId=%d",m_CastItem
->GetGUIDHigh(), m_CastItem
->GetGUIDLow());
3447 bool expendable
= false;
3448 bool withoutCharges
= false;
3450 for (int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
3452 if (proto
->Spells
[i
].SpellId
)
3454 // item has limited charges
3455 if (proto
->Spells
[i
].SpellCharges
)
3457 if (proto
->Spells
[i
].SpellCharges
< 0)
3460 int32 charges
= m_CastItem
->GetSpellCharges(i
);
3462 // item has charges left
3465 (charges
> 0) ? --charges
: ++charges
; // abs(charges) less at 1 after use
3466 if (proto
->Stackable
== 1)
3467 m_CastItem
->SetSpellCharges(i
, charges
);
3468 m_CastItem
->SetState(ITEM_CHANGED
, (Player
*)m_caster
);
3472 withoutCharges
= (charges
== 0);
3477 if (expendable
&& withoutCharges
)
3480 ((Player
*)m_caster
)->DestroyItemCount(m_CastItem
, count
, true);
3482 // prevent crash at access to deleted m_targets.getItemTarget
3483 if(m_CastItem
==m_targets
.getItemTarget())
3484 m_targets
.setItemTarget(NULL
);
3490 void Spell::TakePower()
3492 if(m_CastItem
|| m_triggeredByAuraSpell
)
3495 // health as power used
3496 if(m_spellInfo
->powerType
== POWER_HEALTH
)
3498 m_caster
->ModifyHealth( -(int32
)m_powerCost
);
3502 if(m_spellInfo
->powerType
>= MAX_POWERS
)
3504 sLog
.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo
->powerType
);
3508 Powers powerType
= Powers(m_spellInfo
->powerType
);
3510 if(powerType
== POWER_RUNE
)
3516 m_caster
->ModifyPower(powerType
, -(int32
)m_powerCost
);
3518 // Set the five second timer
3519 if (powerType
== POWER_MANA
&& m_powerCost
> 0)
3520 m_caster
->SetLastManaUse();
3523 SpellCastResult
Spell::CheckRuneCost(uint32 runeCostID
)
3525 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3526 return SPELL_CAST_OK
;
3528 Player
*plr
= (Player
*)m_caster
;
3530 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3531 return SPELL_CAST_OK
;
3533 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(runeCostID
);
3536 return SPELL_CAST_OK
;
3538 if(src
->NoRuneCost())
3539 return SPELL_CAST_OK
;
3541 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3543 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3544 runeCost
[i
] = src
->RuneCost
[i
];
3546 runeCost
[RUNE_DEATH
] = MAX_RUNES
; // calculated later
3548 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3550 uint8 rune
= plr
->GetCurrentRune(i
);
3551 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3555 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3557 runeCost
[RUNE_DEATH
] += runeCost
[i
];
3559 if(runeCost
[RUNE_DEATH
] > MAX_RUNES
)
3560 return SPELL_FAILED_NO_POWER
; // not sure if result code is correct
3562 return SPELL_CAST_OK
;
3565 void Spell::TakeRunePower()
3567 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3570 Player
*plr
= (Player
*)m_caster
;
3572 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3575 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(m_spellInfo
->runeCostID
);
3577 if(!src
|| (src
->NoRuneCost() && src
->NoRunicPowerGain()))
3580 m_runesState
= plr
->GetRunesState(); // store previous state
3582 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3584 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3586 runeCost
[i
] = src
->RuneCost
[i
];
3589 runeCost
[RUNE_DEATH
] = 0; // calculated later
3591 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3593 uint8 rune
= plr
->GetCurrentRune(i
);
3594 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3596 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3601 runeCost
[RUNE_DEATH
] = runeCost
[RUNE_BLOOD
] + runeCost
[RUNE_UNHOLY
] + runeCost
[RUNE_FROST
];
3603 if(runeCost
[RUNE_DEATH
] > 0)
3605 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3607 uint8 rune
= plr
->GetCurrentRune(i
);
3608 if((plr
->GetRuneCooldown(i
) == 0) && (rune
== RUNE_DEATH
))
3610 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3612 plr
->ConvertRune(i
, plr
->GetBaseRune(i
));
3613 if(runeCost
[RUNE_DEATH
] == 0)
3619 // you can gain some runic power when use runes
3620 float rp
= src
->runePowerGain
;;
3621 rp
*= sWorld
.getRate(RATE_POWER_RUNICPOWER_INCOME
);
3622 plr
->ModifyPower(POWER_RUNIC_POWER
, (int32
)rp
);
3625 void Spell::TakeReagents()
3627 if(m_IsTriggeredSpell
) // reagents used in triggered spell removed by original spell or don't must be removed.
3630 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3633 Player
* p_caster
= (Player
*)m_caster
;
3634 if (p_caster
->CanNoReagentCast(m_spellInfo
))
3637 for(uint32 x
= 0; x
< 8; ++x
)
3639 if(m_spellInfo
->Reagent
[x
] <= 0)
3642 uint32 itemid
= m_spellInfo
->Reagent
[x
];
3643 uint32 itemcount
= m_spellInfo
->ReagentCount
[x
];
3645 // if CastItem is also spell reagent
3648 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3649 if( proto
&& proto
->ItemId
== itemid
)
3651 for(int s
= 0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
3653 // CastItem will be used up and does not count as reagent
3654 int32 charges
= m_CastItem
->GetSpellCharges(s
);
3655 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
3666 // if getItemTarget is also spell reagent
3667 if (m_targets
.getItemTargetEntry() == itemid
)
3668 m_targets
.setItemTarget(NULL
);
3670 p_caster
->DestroyItemCount(itemid
, itemcount
, true);
3674 void Spell::HandleThreatSpells(uint32 spellId
)
3676 if(!m_targets
.getUnitTarget() || !spellId
)
3679 if(!m_targets
.getUnitTarget()->CanHaveThreatList())
3682 uint16 threat
= spellmgr
.GetSpellThreat(spellId
);
3687 m_targets
.getUnitTarget()->AddThreat(m_caster
, float(threat
));
3689 DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId
, spellmgr
.GetSpellRank(spellId
), threat
);
3692 void Spell::HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,uint32 i
, float DamageMultiplier
)
3694 unitTarget
= pUnitTarget
;
3695 itemTarget
= pItemTarget
;
3696 gameObjTarget
= pGOTarget
;
3698 uint8 eff
= m_spellInfo
->Effect
[i
];
3700 damage
= int32(CalculateDamage((uint8
)i
, unitTarget
) * DamageMultiplier
);
3702 sLog
.outDebug( "Spell: Effect : %u", eff
);
3704 if(eff
<TOTAL_SPELL_EFFECTS
)
3706 //sLog.outDebug( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff);
3707 (*this.*SpellEffects
[eff
])(i
);
3712 sLog.outDebug( "WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff);
3714 EffectEnchantItemTmp(i);
3717 sLog.outError("SPELL: unknown effect %u spell id %u",
3718 eff, m_spellInfo->Id);
3725 void Spell::AddTriggeredSpell( uint32 spellId
)
3727 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3731 sLog
.outError("Spell::AddTriggeredSpell: unknown spell id %u used as triggred spell for spell %u)", spellId
, m_spellInfo
->Id
);
3735 m_TriggerSpells
.push_back(spellInfo
);
3738 void Spell::AddPrecastSpell( uint32 spellId
)
3740 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3744 sLog
.outError("Spell::AddPrecastSpell: unknown spell id %u used as pre-cast spell for spell %u)", spellId
, m_spellInfo
->Id
);
3748 m_preCastSpells
.push_back(spellInfo
);
3751 void Spell::CastTriggerSpells()
3753 for(SpellInfoList::const_iterator si
=m_TriggerSpells
.begin(); si
!=m_TriggerSpells
.end(); ++si
)
3755 Spell
* spell
= new Spell(m_caster
, (*si
), true, m_originalCasterGUID
, m_selfContainer
);
3756 spell
->prepare(&m_targets
); // use original spell original targets
3760 void Spell::CastPreCastSpells(Unit
* target
)
3762 for(SpellInfoList::const_iterator si
=m_preCastSpells
.begin(); si
!=m_preCastSpells
.end(); ++si
)
3763 m_caster
->CastSpell(target
, (*si
), true, m_CastItem
);
3766 SpellCastResult
Spell::CheckCast(bool strict
)
3768 // check cooldowns to prevent cheating
3769 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
3771 if(m_triggeredByAuraSpell
)
3772 return SPELL_FAILED_DONT_REPORT
;
3774 return SPELL_FAILED_NOT_READY
;
3777 // only allow triggered spells if at an ended battleground
3778 if( !m_IsTriggeredSpell
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
3779 if(BattleGround
* bg
= ((Player
*)m_caster
)->GetBattleGround())
3780 if(bg
->GetStatus() == STATUS_WAIT_LEAVE
)
3781 return SPELL_FAILED_DONT_REPORT
;
3783 // only check at first call, Stealth auras are already removed at second call
3784 // for now, ignore triggered spells
3785 if( strict
&& !m_IsTriggeredSpell
)
3787 bool checkForm
= true;
3788 // Ignore form req aura
3789 Unit::AuraList
const& ignore
= m_caster
->GetAurasByType(SPELL_AURA_MOD_IGNORE_SHAPESHIFT
);
3790 for(Unit::AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
3792 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
3799 // Cannot be used in this stance/form
3800 SpellCastResult shapeError
= GetErrorAtShapeshiftedCast(m_spellInfo
, m_caster
->m_form
);
3801 if(shapeError
!= SPELL_CAST_OK
)
3804 if ((m_spellInfo
->Attributes
& SPELL_ATTR_ONLY_STEALTHED
) && !(m_caster
->HasStealthAura()))
3805 return SPELL_FAILED_ONLY_STEALTHED
;
3809 // caster state requirements
3810 if(m_spellInfo
->CasterAuraState
&& !m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraState
)))
3811 return SPELL_FAILED_CASTER_AURASTATE
;
3812 if(m_spellInfo
->CasterAuraStateNot
&& m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraStateNot
)))
3813 return SPELL_FAILED_CASTER_AURASTATE
;
3815 // Caster aura req check if need
3816 if(m_spellInfo
->casterAuraSpell
&& !m_caster
->HasAura(m_spellInfo
->casterAuraSpell
))
3817 return SPELL_FAILED_CASTER_AURASTATE
;
3818 if(m_spellInfo
->excludeCasterAuraSpell
)
3820 // Special cases of non existing auras handling
3821 if(m_spellInfo
->excludeCasterAuraSpell
== 61988)
3823 // Avenging Wrath Marker
3824 if(m_caster
->HasAura(61987))
3825 return SPELL_FAILED_CASTER_AURASTATE
;
3827 else if(m_caster
->HasAura(m_spellInfo
->excludeCasterAuraSpell
))
3828 return SPELL_FAILED_CASTER_AURASTATE
;
3831 // cancel autorepeat spells if cast start when moving
3832 // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
3833 if( m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->isMoving() )
3835 // skip stuck spell to allow use it in falling case and apply spell limitations at movement
3836 if( (!((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEMENTFLAG_FALLING
) || m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
) &&
3837 (IsAutoRepeat() || (m_spellInfo
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_NOT_SEATED
) != 0) )
3838 return SPELL_FAILED_MOVING
;
3841 if(Unit
*target
= m_targets
.getUnitTarget())
3843 // target state requirements (not allowed state), apply to self also
3844 if(m_spellInfo
->TargetAuraStateNot
&& target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraStateNot
)))
3845 return SPELL_FAILED_TARGET_AURASTATE
;
3847 // Target aura req check if need
3848 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
3849 return SPELL_FAILED_CASTER_AURASTATE
;
3850 if(m_spellInfo
->excludeTargetAuraSpell
)
3852 // Special cases of non existing auras handling
3853 if (m_spellInfo
->excludeTargetAuraSpell
== 61988)
3855 // Avenging Wrath Marker
3856 if (target
->HasAura(61987))
3857 return SPELL_FAILED_CASTER_AURASTATE
;
3860 else if (target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
3861 return SPELL_FAILED_CASTER_AURASTATE
;
3864 bool non_caster_target
= target
!= m_caster
&& !IsSpellWithCasterSourceTargetsOnly(m_spellInfo
);
3866 if(non_caster_target
)
3868 // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds
3869 if(m_spellInfo
->TargetAuraState
&& !target
->HasAuraStateForCaster(AuraState(m_spellInfo
->TargetAuraState
),m_caster
->GetGUID()))
3870 return SPELL_FAILED_TARGET_AURASTATE
;
3872 // Not allow casting on flying player
3873 if (target
->isInFlight())
3874 return SPELL_FAILED_BAD_TARGETS
;
3876 if(!m_IsTriggeredSpell
&& VMAP::VMapFactory::checkSpellForLoS(m_spellInfo
->Id
) && !m_caster
->IsWithinLOSInMap(target
))
3877 return SPELL_FAILED_LINE_OF_SIGHT
;
3879 // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode
3880 // this case can be triggered if rank not found (too low-level target for first rank)
3881 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsPassiveSpell(m_spellInfo
->Id
) && !m_CastItem
)
3883 for(int i
=0;i
<3;++i
)
3885 // check only spell that apply positive auras
3886 if (IsPositiveEffect(m_spellInfo
->Id
, i
) && m_spellInfo
->Effect
[i
] == SPELL_EFFECT_APPLY_AURA
&&
3887 // at not self target
3888 !IsCasterSourceTarget(m_spellInfo
->EffectImplicitTargetA
[i
]) &&
3889 // and target low level
3890 target
->getLevel() + 10 < m_spellInfo
->spellLevel
)
3892 return SPELL_FAILED_LOWLEVEL
;
3897 else if (m_caster
== target
)
3900 if (m_caster
->GetTypeId() == TYPEID_PLAYER
) // Target - is player caster
3902 // Additional check for some spells
3903 // If 0 spell effect empty - client not send target data (need use selection)
3904 // TODO: check it on next client version
3905 if (m_targets
.m_targetMask
== TARGET_FLAG_SELF
&&
3906 m_spellInfo
->EffectImplicitTargetA
[1] == TARGET_CHAIN_DAMAGE
)
3908 if (target
= m_caster
->GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection()))
3909 m_targets
.setUnitTarget(target
);
3911 return SPELL_FAILED_BAD_TARGETS
;
3915 // Some special spells with non-caster only mode
3918 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
3919 m_spellInfo
->SpellIconID
== 16)
3920 return SPELL_FAILED_BAD_TARGETS
;
3922 // Focus Magic (main spell)
3923 if (m_spellInfo
->Id
== 54646)
3924 return SPELL_FAILED_BAD_TARGETS
;
3927 // check pet presents
3928 for(int j
= 0; j
< 3; ++j
)
3930 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_PET
)
3932 target
= m_caster
->GetPet();
3935 if(m_triggeredByAuraSpell
) // not report pet not existence for triggered spells
3936 return SPELL_FAILED_DONT_REPORT
;
3938 return SPELL_FAILED_NO_PET
;
3944 //check creature type
3945 //ignore self casts (including area casts when caster selected as target)
3946 if(non_caster_target
)
3948 if(!CheckTargetCreatureType(target
))
3950 if(target
->GetTypeId() == TYPEID_PLAYER
)
3951 return SPELL_FAILED_TARGET_IS_PLAYER
;
3953 return SPELL_FAILED_BAD_TARGETS
;
3957 // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
3958 // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
3959 if(non_caster_target
&& m_caster
->GetTypeId() == TYPEID_UNIT
&& m_caster
->GetCharmerOrOwnerGUID())
3961 // check correctness positive/negative cast target (pet cast real check and cheating check)
3962 if(IsPositiveSpell(m_spellInfo
->Id
))
3964 if(m_caster
->IsHostileTo(target
))
3965 return SPELL_FAILED_BAD_TARGETS
;
3969 if(m_caster
->IsFriendlyTo(target
))
3970 return SPELL_FAILED_BAD_TARGETS
;
3974 if(IsPositiveSpell(m_spellInfo
->Id
))
3975 if(target
->IsImmunedToSpell(m_spellInfo
))
3976 return SPELL_FAILED_TARGET_AURASTATE
;
3978 //Must be behind the target.
3979 if( m_spellInfo
->AttributesEx2
== 0x100000 && (m_spellInfo
->AttributesEx
& 0x200) == 0x200 && target
->HasInArc(M_PI
, m_caster
) )
3981 //Exclusion for Pounce: Facing Limitation was removed in 2.0.1, but it still uses the same, old Ex-Flags
3982 //Exclusion for Mutilate:Facing Limitation was removed in 2.0.1 and 3.0.3, but they still use the same, old Ex-Flags
3983 if ((m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_DRUID
|| (m_spellInfo
->SpellFamilyFlags
!= UI64LIT(0x0000000000020000))) &&
3984 (m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_ROGUE
|| (m_spellInfo
->SpellFamilyFlags
!= UI64LIT(0x0020000000000000))))
3987 return SPELL_FAILED_NOT_BEHIND
;
3991 //Target must be facing you.
3992 if((m_spellInfo
->Attributes
== 0x150010) && !target
->HasInArc(M_PI
, m_caster
) )
3995 return SPELL_FAILED_NOT_INFRONT
;
3998 // check if target is in combat
3999 if (non_caster_target
&& (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET
) && target
->isInCombat())
4000 return SPELL_FAILED_TARGET_AFFECTING_COMBAT
;
4003 // Spell casted only on battleground
4004 if ((m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_BATTLEGROUND
) && m_caster
->GetTypeId() == TYPEID_PLAYER
)
4005 if(!((Player
*)m_caster
)->InBattleGround())
4006 return SPELL_FAILED_ONLY_BATTLEGROUNDS
;
4008 // do not allow spells to be cast in arenas
4009 // - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag
4010 // - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag
4011 if ((m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA
) ||
4012 GetSpellRecoveryTime(m_spellInfo
) > 15 * MINUTE
* IN_MILISECONDS
&& !(m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_USABLE_IN_ARENA
))
4013 if(MapEntry
const* mapEntry
= sMapStore
.LookupEntry(m_caster
->GetMapId()))
4014 if(mapEntry
->IsBattleArena())
4015 return SPELL_FAILED_NOT_IN_ARENA
;
4019 m_caster
->GetZoneAndAreaId(zone
, area
);
4021 SpellCastResult locRes
= spellmgr
.GetSpellAllowedInLocationError(m_spellInfo
,m_caster
->GetMapId(),zone
,area
,
4022 m_caster
->GetTypeId() == TYPEID_PLAYER
? ((Player
*)m_caster
) : NULL
);
4023 if (locRes
!= SPELL_CAST_OK
)
4026 // not let players cast spells at mount (and let do it to creatures)
4027 if (m_caster
->IsMounted() && m_caster
->GetTypeId()==TYPEID_PLAYER
&& !m_IsTriggeredSpell
&&
4028 !IsPassiveSpell(m_spellInfo
->Id
) && !(m_spellInfo
->Attributes
& SPELL_ATTR_CASTABLE_WHILE_MOUNTED
))
4030 if (m_caster
->isInFlight())
4031 return SPELL_FAILED_NOT_FLYING
;
4033 return SPELL_FAILED_NOT_MOUNTED
;
4036 // always (except passive spells) check items (focus object can be required for any type casts)
4037 if (!IsPassiveSpell(m_spellInfo
->Id
))
4039 SpellCastResult castResult
= CheckItems();
4040 if(castResult
!= SPELL_CAST_OK
)
4044 //ImpliciteTargetA-B = 38, If fact there is 0 Spell with ImpliciteTargetB=38
4045 if (m_UniqueTargetInfo
.empty()) // skip second CheckCast apply (for delayed spells for example)
4047 for(uint8 j
= 0; j
< 3; ++j
)
4049 if( m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
4050 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_SELF
||
4051 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4052 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4054 SpellScriptTargetBounds bounds
= spellmgr
.GetSpellScriptTargetBounds(m_spellInfo
->Id
);
4055 if(bounds
.first
==bounds
.second
)
4056 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
);
4058 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4059 float range
= GetSpellMaxRange(srange
);
4061 Creature
* creatureScriptTarget
= NULL
;
4062 GameObject
* goScriptTarget
= NULL
;
4064 for(SpellScriptTarget::const_iterator i_spellST
= bounds
.first
; i_spellST
!= bounds
.second
; ++i_spellST
)
4066 switch(i_spellST
->second
.type
)
4068 case SPELL_TARGET_TYPE_GAMEOBJECT
:
4070 GameObject
* p_GameObject
= NULL
;
4072 if (i_spellST
->second
.targetEntry
)
4074 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4076 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4078 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*m_caster
,i_spellST
->second
.targetEntry
,range
);
4079 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(m_caster
, p_GameObject
,go_check
);
4081 TypeContainerVisitor
<MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
>, GridTypeMapContainer
> object_checker(checker
);
4082 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4083 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
4087 // remember found target and range, next attempt will find more near target with another entry
4088 creatureScriptTarget
= NULL
;
4089 goScriptTarget
= p_GameObject
;
4090 range
= go_check
.GetLastRange();
4093 else if (focusObject
) // Focus Object
4095 float frange
= m_caster
->GetDistance(focusObject
);
4096 if (range
>= frange
)
4098 creatureScriptTarget
= NULL
;
4099 goScriptTarget
= focusObject
;
4105 case SPELL_TARGET_TYPE_CREATURE
:
4106 case SPELL_TARGET_TYPE_DEAD
:
4109 Creature
*p_Creature
= NULL
;
4111 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4113 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4114 cell
.SetNoCreate(); // Really don't know what is that???
4116 MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
u_check(*m_caster
,i_spellST
->second
.targetEntry
,i_spellST
->second
.type
!=SPELL_TARGET_TYPE_DEAD
,range
);
4117 MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
> searcher(m_caster
, p_Creature
, u_check
);
4119 TypeContainerVisitor
<MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
>, GridTypeMapContainer
> grid_creature_searcher(searcher
);
4121 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4122 cell_lock
->Visit(cell_lock
, grid_creature_searcher
, *m_caster
->GetMap());
4126 creatureScriptTarget
= p_Creature
;
4127 goScriptTarget
= NULL
;
4128 range
= u_check
.GetLastRange();
4135 if(creatureScriptTarget
)
4137 // store coordinates for TARGET_SCRIPT_COORDINATES
4138 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4139 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4141 m_targets
.setDestination(creatureScriptTarget
->GetPositionX(),creatureScriptTarget
->GetPositionY(),creatureScriptTarget
->GetPositionZ());
4143 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
4144 AddUnitTarget(creatureScriptTarget
, j
);
4146 // store explicit target for TARGET_SCRIPT
4148 AddUnitTarget(creatureScriptTarget
, j
);
4150 else if(goScriptTarget
)
4152 // store coordinates for TARGET_SCRIPT_COORDINATES
4153 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4154 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4156 m_targets
.setDestination(goScriptTarget
->GetPositionX(),goScriptTarget
->GetPositionY(),goScriptTarget
->GetPositionZ());
4158 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
4159 AddGOTarget(goScriptTarget
, j
);
4161 // store explicit target for TARGET_SCRIPT
4163 AddGOTarget(goScriptTarget
, j
);
4165 //Missing DB Entry or targets for this spellEffect.
4168 // not report target not existence for triggered spells
4169 if(m_triggeredByAuraSpell
|| m_IsTriggeredSpell
)
4170 return SPELL_FAILED_DONT_REPORT
;
4172 return SPELL_FAILED_BAD_TARGETS
;
4178 if(!m_IsTriggeredSpell
)
4180 SpellCastResult castResult
= CheckRange(strict
);
4181 if(castResult
!= SPELL_CAST_OK
)
4186 SpellCastResult castResult
= CheckPower();
4187 if(castResult
!= SPELL_CAST_OK
)
4191 if(!m_IsTriggeredSpell
) // triggered spell not affected by stun/etc
4193 SpellCastResult castResult
= CheckCasterAuras();
4194 if(castResult
!= SPELL_CAST_OK
)
4198 for (int i
= 0; i
< 3; ++i
)
4200 // for effects of spells that have only one target
4201 switch(m_spellInfo
->Effect
[i
])
4203 case SPELL_EFFECT_DUMMY
:
4205 if(m_spellInfo
->SpellIconID
== 1648) // Execute
4207 if(!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4208 return SPELL_FAILED_BAD_TARGETS
;
4210 else if (m_spellInfo
->Id
== 51582) // Rocket Boots Engaged
4212 if(m_caster
->IsInWater())
4213 return SPELL_FAILED_ONLY_ABOVEWATER
;
4215 else if(m_spellInfo
->SpellIconID
== 156) // Holy Shock
4217 // spell different for friends and enemies
4218 // hart version required facing
4219 if(m_targets
.getUnitTarget() && !m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()) && !m_caster
->HasInArc( M_PI
, m_targets
.getUnitTarget() ))
4220 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4224 case SPELL_EFFECT_SCHOOL_DAMAGE
:
4227 if(m_spellInfo
->SpellVisual
[0] == 7250)
4229 if (!m_targets
.getUnitTarget())
4230 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4232 if(m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4233 return SPELL_FAILED_BAD_TARGETS
;
4237 case SPELL_EFFECT_TAMECREATURE
:
4239 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4240 return SPELL_FAILED_BAD_TARGETS
;
4242 if (!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
)
4243 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4245 Creature
* target
= (Creature
*)m_targets
.getUnitTarget();
4247 if (target
->getLevel() > m_caster
->getLevel())
4248 return SPELL_FAILED_HIGHLEVEL
;
4250 // use SMSG_PET_TAME_FAILURE?
4251 if (!target
->GetCreatureInfo()->isTameable (((Player
*)m_caster
)->CanTameExoticPets()))
4252 return SPELL_FAILED_BAD_TARGETS
;
4254 if(m_caster
->GetPetGUID())
4255 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4257 if(m_caster
->GetCharmGUID())
4258 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4262 case SPELL_EFFECT_LEARN_SPELL
:
4264 if(m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_PET
)
4267 Pet
* pet
= m_caster
->GetPet();
4270 return SPELL_FAILED_NO_PET
;
4272 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4274 if(!learn_spellproto
)
4275 return SPELL_FAILED_NOT_KNOWN
;
4277 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4278 return SPELL_FAILED_LOWLEVEL
;
4282 case SPELL_EFFECT_LEARN_PET_SPELL
:
4284 Pet
* pet
= m_caster
->GetPet();
4287 return SPELL_FAILED_NO_PET
;
4289 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4291 if(!learn_spellproto
)
4292 return SPELL_FAILED_NOT_KNOWN
;
4294 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4295 return SPELL_FAILED_LOWLEVEL
;
4299 case SPELL_EFFECT_APPLY_GLYPH
:
4301 uint32 glyphId
= m_spellInfo
->EffectMiscValue
[i
];
4302 if(GlyphPropertiesEntry
const *gp
= sGlyphPropertiesStore
.LookupEntry(glyphId
))
4303 if(m_caster
->HasAura(gp
->SpellId
))
4304 return SPELL_FAILED_UNIQUE_GLYPH
;
4307 case SPELL_EFFECT_FEED_PET
:
4309 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4310 return SPELL_FAILED_BAD_TARGETS
;
4312 Item
* foodItem
= m_targets
.getItemTarget();
4314 return SPELL_FAILED_BAD_TARGETS
;
4316 Pet
* pet
= m_caster
->GetPet();
4319 return SPELL_FAILED_NO_PET
;
4321 if(!pet
->HaveInDiet(foodItem
->GetProto()))
4322 return SPELL_FAILED_WRONG_PET_FOOD
;
4324 if(!pet
->GetCurrentFoodBenefitLevel(foodItem
->GetProto()->ItemLevel
))
4325 return SPELL_FAILED_FOOD_LOWLEVEL
;
4327 if(m_caster
->isInCombat() || pet
->isInCombat())
4328 return SPELL_FAILED_AFFECTING_COMBAT
;
4332 case SPELL_EFFECT_POWER_BURN
:
4333 case SPELL_EFFECT_POWER_DRAIN
:
4335 // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
4336 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4337 if(Unit
* target
= m_targets
.getUnitTarget())
4338 if(target
!= m_caster
&& target
->getPowerType() != m_spellInfo
->EffectMiscValue
[i
])
4339 return SPELL_FAILED_BAD_TARGETS
;
4342 case SPELL_EFFECT_CHARGE
:
4344 if (m_caster
->hasUnitState(UNIT_STAT_ROOT
))
4345 return SPELL_FAILED_ROOTED
;
4349 case SPELL_EFFECT_SKINNING
:
4351 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() != TYPEID_UNIT
)
4352 return SPELL_FAILED_BAD_TARGETS
;
4354 if( !(m_targets
.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS
) & UNIT_FLAG_SKINNABLE
) )
4355 return SPELL_FAILED_TARGET_UNSKINNABLE
;
4357 Creature
* creature
= (Creature
*)m_targets
.getUnitTarget();
4358 if ( creature
->GetCreatureType() != CREATURE_TYPE_CRITTER
&& ( !creature
->lootForBody
|| !creature
->loot
.empty() ) )
4360 return SPELL_FAILED_TARGET_NOT_LOOTED
;
4363 uint32 skill
= creature
->GetCreatureInfo()->GetRequiredLootSkill();
4365 int32 skillValue
= ((Player
*)m_caster
)->GetSkillValue(skill
);
4366 int32 TargetLevel
= m_targets
.getUnitTarget()->getLevel();
4367 int32 ReqValue
= (skillValue
< 100 ? (TargetLevel
-10) * 10 : TargetLevel
* 5);
4368 if (ReqValue
> skillValue
)
4369 return SPELL_FAILED_LOW_CASTLEVEL
;
4371 // chance for fail at orange skinning attempt
4372 if( (m_selfContainer
&& (*m_selfContainer
) == this) &&
4373 skillValue
< sWorld
.GetConfigMaxSkillValue() &&
4374 (ReqValue
< 0 ? 0 : ReqValue
) > irand(skillValue
- 25, skillValue
+ 37) )
4375 return SPELL_FAILED_TRY_AGAIN
;
4379 case SPELL_EFFECT_OPEN_LOCK
:
4381 if( m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT
&&
4382 m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT_ITEM
)
4385 if( m_caster
->GetTypeId() != TYPEID_PLAYER
// only players can open locks, gather etc.
4386 // we need a go target in case of TARGET_GAMEOBJECT
4387 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT
&& !m_targets
.getGOTarget()
4388 // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM
4389 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT_ITEM
&& !m_targets
.getGOTarget() &&
4390 (!m_targets
.getItemTarget() || !m_targets
.getItemTarget()->GetProto()->LockID
|| m_targets
.getItemTarget()->GetOwner() != m_caster
) )
4391 return SPELL_FAILED_BAD_TARGETS
;
4393 // In BattleGround players can use only flags and banners
4394 if( ((Player
*)m_caster
)->InBattleGround() &&
4395 !((Player
*)m_caster
)->CanUseBattleGroundObject() )
4396 return SPELL_FAILED_TRY_AGAIN
;
4398 // get the lock entry
4400 if (GameObject
* go
= m_targets
.getGOTarget())
4402 lockId
= go
->GetGOInfo()->GetLockId();
4404 return SPELL_FAILED_BAD_TARGETS
;
4406 else if(Item
* itm
= m_targets
.getItemTarget())
4407 lockId
= itm
->GetProto()->LockID
;
4409 SkillType skillId
= SKILL_NONE
;
4410 int32 reqSkillValue
= 0;
4411 int32 skillValue
= 0;
4413 // check lock compatibility
4414 SpellCastResult res
= CanOpenLock(i
, lockId
, skillId
, reqSkillValue
, skillValue
);
4415 if(res
!= SPELL_CAST_OK
)
4418 // chance for fail at orange mining/herb/LockPicking gathering attempt
4419 // second check prevent fail at rechecks
4420 if(skillId
!= SKILL_NONE
&& (!m_selfContainer
|| ((*m_selfContainer
) != this)))
4422 bool canFailAtMax
= skillId
!= SKILL_HERBALISM
&& skillId
!= SKILL_MINING
;
4424 // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill)
4425 if((canFailAtMax
|| skillValue
< sWorld
.GetConfigMaxSkillValue()) && reqSkillValue
> irand(skillValue
- 25, skillValue
+ 37))
4426 return SPELL_FAILED_TRY_AGAIN
;
4430 case SPELL_EFFECT_SUMMON_DEAD_PET
:
4432 Creature
*pet
= m_caster
->GetPet();
4434 return SPELL_FAILED_NO_PET
;
4437 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4441 // This is generic summon effect
4442 case SPELL_EFFECT_SUMMON
:
4444 switch(m_spellInfo
->EffectMiscValueB
[i
])
4446 case SUMMON_TYPE_POSESSED
:
4447 case SUMMON_TYPE_POSESSED2
:
4448 case SUMMON_TYPE_DEMON
:
4449 case SUMMON_TYPE_SUMMON
:
4450 case SUMMON_TYPE_ELEMENTAL
:
4451 case SUMMON_TYPE_INFERNO
:
4453 if(m_caster
->GetPetGUID())
4454 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4456 if(m_caster
->GetCharmGUID())
4457 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4463 // Not used for summon?
4464 case SPELL_EFFECT_SUMMON_PHANTASM
:
4466 if(m_caster
->GetPetGUID())
4467 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4469 if(m_caster
->GetCharmGUID())
4470 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4474 case SPELL_EFFECT_SUMMON_PET
:
4476 if(m_caster
->GetPetGUID()) //let warlock do a replacement summon
4479 Pet
* pet
= ((Player
*)m_caster
)->GetPet();
4481 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->getClass() == CLASS_WARLOCK
)
4483 if (strict
) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
4484 pet
->CastSpell(pet
, 32752, true, NULL
, NULL
, pet
->GetGUID());
4487 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4490 if(m_caster
->GetCharmGUID())
4491 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4495 case SPELL_EFFECT_SUMMON_PLAYER
:
4497 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4498 return SPELL_FAILED_BAD_TARGETS
;
4499 if(!((Player
*)m_caster
)->GetSelection())
4500 return SPELL_FAILED_BAD_TARGETS
;
4502 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
4503 if( !target
|| ((Player
*)m_caster
) == target
|| !target
->IsInSameRaidWith((Player
*)m_caster
) )
4504 return SPELL_FAILED_BAD_TARGETS
;
4506 // check if our map is dungeon
4507 if( sMapStore
.LookupEntry(m_caster
->GetMapId())->IsDungeon() )
4509 InstanceTemplate
const* instance
= ObjectMgr::GetInstanceTemplate(m_caster
->GetMapId());
4511 return SPELL_FAILED_TARGET_NOT_IN_INSTANCE
;
4512 if ( instance
->levelMin
> target
->getLevel() )
4513 return SPELL_FAILED_LOWLEVEL
;
4514 if ( instance
->levelMax
&& instance
->levelMax
< target
->getLevel() )
4515 return SPELL_FAILED_HIGHLEVEL
;
4519 case SPELL_EFFECT_LEAP
:
4520 case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
:
4522 float dis
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4523 float fx
= m_caster
->GetPositionX() + dis
* cos(m_caster
->GetOrientation());
4524 float fy
= m_caster
->GetPositionY() + dis
* sin(m_caster
->GetOrientation());
4525 // teleport a bit above terrain level to avoid falling below it
4526 float fz
= m_caster
->GetBaseMap()->GetHeight(fx
,fy
,m_caster
->GetPositionZ(),true);
4527 if(fz
<= INVALID_HEIGHT
) // note: this also will prevent use effect in instances without vmaps height enabled
4528 return SPELL_FAILED_TRY_AGAIN
;
4530 float caster_pos_z
= m_caster
->GetPositionZ();
4531 // Control the caster to not climb or drop when +-fz > 8
4532 if(!(fz
<= caster_pos_z
+ 8 && fz
>= caster_pos_z
- 8))
4533 return SPELL_FAILED_TRY_AGAIN
;
4535 // not allow use this effect at battleground until battleground start
4536 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4537 if(BattleGround
const *bg
= ((Player
*)m_caster
)->GetBattleGround())
4538 if(bg
->GetStatus() != STATUS_IN_PROGRESS
)
4539 return SPELL_FAILED_TRY_AGAIN
;
4542 case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF
:
4544 if (m_targets
.getUnitTarget() == m_caster
)
4545 return SPELL_FAILED_BAD_TARGETS
;
4552 for (int i
= 0; i
< 3; ++i
)
4554 switch(m_spellInfo
->EffectApplyAuraName
[i
])
4556 case SPELL_AURA_DUMMY
:
4559 switch(m_spellInfo
->Id
)
4562 if(m_caster
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)m_caster
)->IsInFeralForm())
4563 return SPELL_FAILED_ONLY_SHAPESHIFT
;
4570 case SPELL_AURA_MOD_POSSESS
:
4572 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4573 return SPELL_FAILED_UNKNOWN
;
4575 if(m_targets
.getUnitTarget() == m_caster
)
4576 return SPELL_FAILED_BAD_TARGETS
;
4578 if(m_caster
->GetPetGUID())
4579 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4581 if(m_caster
->GetCharmGUID())
4582 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4584 if(m_caster
->GetCharmerGUID())
4585 return SPELL_FAILED_CHARMED
;
4587 if(!m_targets
.getUnitTarget())
4588 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4590 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4591 return SPELL_FAILED_CHARMED
;
4593 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
4594 return SPELL_FAILED_HIGHLEVEL
;
4598 case SPELL_AURA_MOD_CHARM
:
4600 if(m_targets
.getUnitTarget() == m_caster
)
4601 return SPELL_FAILED_BAD_TARGETS
;
4603 if(m_caster
->GetPetGUID())
4604 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4606 if(m_caster
->GetCharmGUID())
4607 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4609 if(m_caster
->GetCharmerGUID())
4610 return SPELL_FAILED_CHARMED
;
4612 if(!m_targets
.getUnitTarget())
4613 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4615 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4616 return SPELL_FAILED_CHARMED
;
4618 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
4619 return SPELL_FAILED_HIGHLEVEL
;
4623 case SPELL_AURA_MOD_POSSESS_PET
:
4625 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4626 return SPELL_FAILED_UNKNOWN
;
4628 if(m_caster
->GetCharmGUID())
4629 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4631 if(m_caster
->GetCharmerGUID())
4632 return SPELL_FAILED_CHARMED
;
4634 Pet
* pet
= m_caster
->GetPet();
4636 return SPELL_FAILED_NO_PET
;
4638 if(pet
->GetCharmerGUID())
4639 return SPELL_FAILED_CHARMED
;
4643 case SPELL_AURA_MOUNTED
:
4645 if (m_caster
->IsInWater())
4646 return SPELL_FAILED_ONLY_ABOVEWATER
;
4648 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetTransport())
4649 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4651 // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
4652 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& !sMapStore
.LookupEntry(m_caster
->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell
&& !m_spellInfo
->AreaGroupId
)
4653 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4655 ShapeshiftForm form
= m_caster
->m_form
;
4656 if( form
== FORM_CAT
|| form
== FORM_TREE
|| form
== FORM_TRAVEL
||
4657 form
== FORM_AQUA
|| form
== FORM_BEAR
|| form
== FORM_DIREBEAR
||
4658 form
== FORM_CREATUREBEAR
|| form
== FORM_GHOSTWOLF
|| form
== FORM_FLIGHT
||
4659 form
== FORM_FLIGHT_EPIC
|| form
== FORM_MOONKIN
|| form
== FORM_METAMORPHOSIS
)
4660 return SPELL_FAILED_NOT_SHAPESHIFT
;
4664 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
4666 if(!m_targets
.getUnitTarget())
4667 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4669 // can be casted at non-friendly unit or own pet/charm
4670 if(m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()))
4671 return SPELL_FAILED_TARGET_FRIENDLY
;
4675 case SPELL_AURA_FLY
:
4676 case SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
:
4678 // not allow cast fly spells if not have req. skills (all spells is self target)
4679 // allow always ghost flight spells
4680 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->isAlive())
4682 if (!((Player
*)m_caster
)->IsKnowHowFlyIn(m_caster
->GetMapId(),zone
))
4683 return m_IsTriggeredSpell
? SPELL_FAILED_DONT_REPORT
: SPELL_FAILED_NOT_HERE
;
4687 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4689 if (!m_targets
.getUnitTarget())
4690 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4692 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| m_CastItem
)
4695 if(m_targets
.getUnitTarget()->getPowerType() != POWER_MANA
)
4696 return SPELL_FAILED_BAD_TARGETS
;
4706 return SPELL_CAST_OK
;
4709 SpellCastResult
Spell::CheckPetCast(Unit
* target
)
4711 if(!m_caster
->isAlive())
4712 return SPELL_FAILED_CASTER_DEAD
;
4714 if(m_caster
->IsNonMeleeSpellCasted(false)) //prevent spellcast interruption by another spellcast
4715 return SPELL_FAILED_SPELL_IN_PROGRESS
;
4716 if(m_caster
->isInCombat() && IsNonCombatSpell(m_spellInfo
))
4717 return SPELL_FAILED_AFFECTING_COMBAT
;
4719 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)m_caster
)->isPet() || m_caster
->isCharmed()))
4721 //dead owner (pets still alive when owners ressed?)
4722 if(m_caster
->GetCharmerOrOwner() && !m_caster
->GetCharmerOrOwner()->isAlive())
4723 return SPELL_FAILED_CASTER_DEAD
;
4725 if(!target
&& m_targets
.getUnitTarget())
4726 target
= m_targets
.getUnitTarget();
4729 for(uint32 i
= 0; i
< 3; ++i
)
4731 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CHAIN_DAMAGE
||
4732 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND
||
4733 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND_2
||
4734 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_DUELVSPLAYER
||
4735 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_PARTY
||
4736 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CURRENT_ENEMY_COORDINATES
)
4740 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4745 m_targets
.setUnitTarget(target
);
4747 Unit
* _target
= m_targets
.getUnitTarget();
4749 if(_target
) //for target dead/target not valid
4751 if(!_target
->isAlive())
4752 return SPELL_FAILED_BAD_TARGETS
;
4754 if(IsPositiveSpell(m_spellInfo
->Id
))
4756 if(m_caster
->IsHostileTo(_target
))
4757 return SPELL_FAILED_BAD_TARGETS
;
4761 bool duelvsplayertar
= false;
4762 for(int j
= 0; j
< 3; ++j
)
4764 //TARGET_DUELVSPLAYER is positive AND negative
4765 duelvsplayertar
|= (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
);
4767 if(m_caster
->IsFriendlyTo(target
) && !duelvsplayertar
)
4769 return SPELL_FAILED_BAD_TARGETS
;
4774 if(((Creature
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
4775 return SPELL_FAILED_NOT_READY
;
4778 return CheckCast(true);
4781 SpellCastResult
Spell::CheckCasterAuras() const
4783 // Flag drop spells totally immuned to caster auras
4784 // FIXME: find more nice check for all totally immuned spells
4785 // AttributesEx3 & 0x10000000?
4786 if(m_spellInfo
->Id
== 23336 || m_spellInfo
->Id
== 23334 || m_spellInfo
->Id
== 34991)
4787 return SPELL_CAST_OK
;
4789 uint8 school_immune
= 0;
4790 uint32 mechanic_immune
= 0;
4791 uint32 dispel_immune
= 0;
4793 // Check if the spell grants school or mechanic immunity.
4794 // We use bitmasks so the loop is done only once and not on every aura check below.
4795 if ( m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
4797 for(int i
= 0; i
< 3; ++i
)
4799 if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_SCHOOL_IMMUNITY
)
4800 school_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
4801 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY
)
4802 mechanic_immune
|= 1 << uint32(m_spellInfo
->EffectMiscValue
[i
]);
4803 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_DISPEL_IMMUNITY
)
4804 dispel_immune
|= GetDispellMask(DispelType(m_spellInfo
->EffectMiscValue
[i
]));
4806 // immune movement impairment and loss of control
4807 if(m_spellInfo
->Id
== 42292)
4808 mechanic_immune
= IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK
;
4811 // Check whether the cast should be prevented by any state you might have.
4812 SpellCastResult prevented_reason
= SPELL_CAST_OK
;
4813 // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
4814 uint32 unitflag
= m_caster
->GetUInt32Value(UNIT_FIELD_FLAGS
); // Get unit state
4815 if(unitflag
& UNIT_FLAG_STUNNED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4816 prevented_reason
= SPELL_FAILED_STUNNED
;
4817 else if(unitflag
& UNIT_FLAG_CONFUSED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4818 prevented_reason
= SPELL_FAILED_CONFUSED
;
4819 else if(unitflag
& UNIT_FLAG_FLEEING
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4820 prevented_reason
= SPELL_FAILED_FLEEING
;
4821 else if(unitflag
& UNIT_FLAG_SILENCED
&& m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
)
4822 prevented_reason
= SPELL_FAILED_SILENCED
;
4823 else if(unitflag
& UNIT_FLAG_PACIFIED
&& m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
)
4824 prevented_reason
= SPELL_FAILED_PACIFIED
;
4826 // Attr must make flag drop spell totally immune from all effects
4827 if(prevented_reason
!= SPELL_CAST_OK
)
4829 if(school_immune
|| mechanic_immune
|| dispel_immune
)
4831 //Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
4832 Unit::AuraMap
const& auras
= m_caster
->GetAuras();
4833 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
4837 if( GetSpellMechanicMask(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()) & mechanic_immune
)
4839 if( GetSpellSchoolMask(itr
->second
->GetSpellProto()) & school_immune
)
4841 if( (1<<(itr
->second
->GetSpellProto()->Dispel
)) & dispel_immune
)
4844 // Make a second check for spell failed so the right SPELL_FAILED message is returned.
4845 // That is needed when your casting is prevented by multiple states and you are only immune to some of them.
4846 switch(itr
->second
->GetModifier()->m_auraname
)
4848 case SPELL_AURA_MOD_STUN
:
4849 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4850 return SPELL_FAILED_STUNNED
;
4852 case SPELL_AURA_MOD_CONFUSE
:
4853 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4854 return SPELL_FAILED_CONFUSED
;
4856 case SPELL_AURA_MOD_FEAR
:
4857 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4858 return SPELL_FAILED_FLEEING
;
4860 case SPELL_AURA_MOD_SILENCE
:
4861 case SPELL_AURA_MOD_PACIFY
:
4862 case SPELL_AURA_MOD_PACIFY_SILENCE
:
4863 if( m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
)
4864 return SPELL_FAILED_PACIFIED
;
4865 else if ( m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
)
4866 return SPELL_FAILED_SILENCED
;
4873 // You are prevented from casting and the spell casted does not grant immunity. Return a failed error.
4875 return prevented_reason
;
4877 return SPELL_CAST_OK
;
4880 bool Spell::CanAutoCast(Unit
* target
)
4882 uint64 targetguid
= target
->GetGUID();
4884 for(uint32 j
= 0; j
< 3; ++j
)
4886 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
)
4888 if( m_spellInfo
->StackAmount
<= 1)
4890 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4895 if(Aura
* aura
= target
->GetAura(m_spellInfo
->Id
, j
))
4896 if(aura
->GetStackAmount() >= m_spellInfo
->StackAmount
)
4900 else if ( IsAreaAuraEffect( m_spellInfo
->Effect
[j
] ))
4902 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4907 SpellCastResult result
= CheckPetCast(target
);
4909 if(result
== SPELL_CAST_OK
|| result
== SPELL_FAILED_UNIT_NOT_INFRONT
)
4912 //check if among target units, our WANTED target is as well (->only self cast spells return false)
4913 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
4914 if( ihit
->targetGUID
== targetguid
)
4917 return false; //target invalid
4920 SpellCastResult
Spell::CheckRange(bool strict
)
4924 // self cast doesn't need range checking -- also for Starshards fix
4925 if (m_spellInfo
->rangeIndex
== 1)
4926 return SPELL_CAST_OK
;
4928 if (strict
) //add radius of caster
4930 else //add radius of caster and ~5 yds "give"
4933 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4934 Unit
*target
= m_targets
.getUnitTarget();
4935 bool friendly
= target
? target
->IsFriendlyTo(m_caster
) : false;
4936 float max_range
= GetSpellMaxRange(srange
, friendly
) + range_mod
;
4937 float min_range
= GetSpellMinRange(srange
, friendly
);
4939 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4940 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RANGE
, max_range
, this);
4942 if(target
&& target
!= m_caster
)
4944 // distance from target in checks
4945 float dist
= m_caster
->GetCombatDistance(target
);
4947 if(dist
> max_range
)
4948 return SPELL_FAILED_OUT_OF_RANGE
; //0x5A;
4949 if(min_range
&& dist
< min_range
)
4950 return SPELL_FAILED_TOO_CLOSE
;
4951 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&&
4952 (m_spellInfo
->FacingCasterFlags
& SPELL_FACING_FLAG_INFRONT
) && !m_caster
->HasInArc( M_PI
, target
) )
4953 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4956 if(m_targets
.m_targetMask
== TARGET_FLAG_DEST_LOCATION
&& m_targets
.m_destX
!= 0 && m_targets
.m_destY
!= 0 && m_targets
.m_destZ
!= 0)
4958 if(!m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
, max_range
))
4959 return SPELL_FAILED_OUT_OF_RANGE
;
4960 if(min_range
&& m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
, min_range
))
4961 return SPELL_FAILED_TOO_CLOSE
;
4964 return SPELL_CAST_OK
;
4967 int32
Spell::CalculatePowerCost()
4969 // item cast not used power
4973 // Spell drain all exist power on cast (Only paladin lay of Hands)
4974 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DRAIN_ALL_POWER
)
4976 // If power type - health drain all
4977 if (m_spellInfo
->powerType
== POWER_HEALTH
)
4978 return m_caster
->GetHealth();
4979 // Else drain all power
4980 if (m_spellInfo
->powerType
< MAX_POWERS
)
4981 return m_caster
->GetPower(Powers(m_spellInfo
->powerType
));
4982 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4987 int32 powerCost
= m_spellInfo
->manaCost
;
4988 // PCT cost from total amount
4989 if (m_spellInfo
->ManaCostPercentage
)
4991 switch (m_spellInfo
->powerType
)
4993 // health as power used
4995 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateHealth() / 100;
4998 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateMana() / 100;
5003 case POWER_HAPPINESS
:
5004 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetMaxPower(Powers(m_spellInfo
->powerType
)) / 100;
5007 case POWER_RUNIC_POWER
:
5008 sLog
.outDebug("Spell::CalculateManaCost: Not implemented yet!");
5011 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
5015 SpellSchools school
= GetFirstSchoolInMask(m_spellSchoolMask
);
5016 // Flat mod from caster auras by spell school
5017 powerCost
+= m_caster
->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER
+ school
);
5018 // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
5019 if ( m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST
)
5020 powerCost
+= m_caster
->GetAttackTime(OFF_ATTACK
)/100;
5021 // Apply cost mod by spell
5022 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
5023 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, powerCost
, this);
5025 if(m_spellInfo
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
)
5026 powerCost
= int32(powerCost
/ (1.117f
* m_spellInfo
->spellLevel
/ m_caster
->getLevel() -0.1327f
));
5028 // PCT mod from user auras by school
5029 powerCost
= int32(powerCost
* (1.0f
+m_caster
->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+school
)));
5035 SpellCastResult
Spell::CheckPower()
5037 // item cast not used power
5039 return SPELL_CAST_OK
;
5041 // Do precise power regen on spell cast
5042 if (m_powerCost
> 0 && m_caster
->GetTypeId() == TYPEID_PLAYER
)
5044 Player
* playerCaster
= (Player
*)m_caster
;
5045 uint32 diff
= REGEN_TIME_FULL
- m_caster
->GetRegenTimer();
5046 if (diff
>= REGEN_TIME_PRECISE
)
5047 playerCaster
->RegenerateAll(diff
);
5050 // health as power used - need check health amount
5051 if(m_spellInfo
->powerType
== POWER_HEALTH
)
5053 if(m_caster
->GetHealth() <= m_powerCost
)
5054 return SPELL_FAILED_CASTER_AURASTATE
;
5055 return SPELL_CAST_OK
;
5057 // Check valid power type
5058 if( m_spellInfo
->powerType
>= MAX_POWERS
)
5060 sLog
.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo
->powerType
);
5061 return SPELL_FAILED_UNKNOWN
;
5064 SpellCastResult failReason
= CheckRuneCost(m_spellInfo
->runeCostID
);
5065 if(failReason
!= SPELL_CAST_OK
)
5068 // Check power amount
5069 Powers powerType
= Powers(m_spellInfo
->powerType
);
5070 if(m_caster
->GetPower(powerType
) < m_powerCost
)
5071 return SPELL_FAILED_NO_POWER
;
5073 return SPELL_CAST_OK
;
5076 SpellCastResult
Spell::CheckItems()
5078 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
5079 return SPELL_CAST_OK
;
5081 Player
* p_caster
= (Player
*)m_caster
;
5086 uint32 itemid
= m_CastItem
->GetEntry();
5087 if( !p_caster
->HasItemCount(itemid
, 1) )
5088 return SPELL_FAILED_ITEM_NOT_READY
;
5090 ItemPrototype
const *proto
= m_CastItem
->GetProto();
5092 return SPELL_FAILED_ITEM_NOT_READY
;
5094 for (int i
= 0; i
< 5; ++i
)
5095 if (proto
->Spells
[i
].SpellCharges
)
5096 if(m_CastItem
->GetSpellCharges(i
) == 0)
5097 return SPELL_FAILED_NO_CHARGES_REMAIN
;
5099 // consumable cast item checks
5100 if (proto
->Class
== ITEM_CLASS_CONSUMABLE
&& m_targets
.getUnitTarget())
5102 // such items should only fail if there is no suitable effect at all - see Rejuvenation Potions for example
5103 SpellCastResult failReason
= SPELL_CAST_OK
;
5104 for (int i
= 0; i
< 3; ++i
)
5106 // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster
5107 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_PET
)
5110 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_HEAL
)
5112 if (m_targets
.getUnitTarget()->GetHealth() == m_targets
.getUnitTarget()->GetMaxHealth())
5114 failReason
= SPELL_FAILED_ALREADY_AT_FULL_HEALTH
;
5119 failReason
= SPELL_CAST_OK
;
5124 // Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
5125 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
5127 if(m_spellInfo
->EffectMiscValue
[i
] < 0 || m_spellInfo
->EffectMiscValue
[i
] >= MAX_POWERS
)
5129 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
5133 Powers power
= Powers(m_spellInfo
->EffectMiscValue
[i
]);
5134 if (m_targets
.getUnitTarget()->GetPower(power
) == m_targets
.getUnitTarget()->GetMaxPower(power
))
5136 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
5141 failReason
= SPELL_CAST_OK
;
5146 if (failReason
!= SPELL_CAST_OK
)
5151 // check target item
5152 if(m_targets
.getItemTargetGUID())
5154 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
5155 return SPELL_FAILED_BAD_TARGETS
;
5157 if(!m_targets
.getItemTarget())
5158 return SPELL_FAILED_ITEM_GONE
;
5160 if(!m_targets
.getItemTarget()->IsFitToSpellRequirements(m_spellInfo
))
5161 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
5163 // if not item target then required item must be equipped
5166 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !((Player
*)m_caster
)->HasItemFitToSpellReqirements(m_spellInfo
))
5167 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
5170 // check spell focus object
5171 if(m_spellInfo
->RequiresSpellFocus
)
5173 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
5175 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5177 GameObject
* ok
= NULL
;
5178 MaNGOS::GameObjectFocusCheck
go_check(m_caster
,m_spellInfo
->RequiresSpellFocus
);
5179 MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
> checker(m_caster
, ok
, go_check
);
5181 TypeContainerVisitor
<MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
>, GridTypeMapContainer
> object_checker(checker
);
5182 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5183 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
5186 return SPELL_FAILED_REQUIRES_SPELL_FOCUS
;
5188 focusObject
= ok
; // game object found in range
5191 // check reagents (ignore triggered spells with reagents processed by original spell) and special reagent ignore case.
5192 if (!m_IsTriggeredSpell
&& !p_caster
->CanNoReagentCast(m_spellInfo
))
5194 for(uint32 i
= 0; i
< 8; ++i
)
5196 if(m_spellInfo
->Reagent
[i
] <= 0)
5199 uint32 itemid
= m_spellInfo
->Reagent
[i
];
5200 uint32 itemcount
= m_spellInfo
->ReagentCount
[i
];
5202 // if CastItem is also spell reagent
5203 if( m_CastItem
&& m_CastItem
->GetEntry() == itemid
)
5205 ItemPrototype
const *proto
= m_CastItem
->GetProto();
5207 return SPELL_FAILED_ITEM_NOT_READY
;
5208 for(int s
= 0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
5210 // CastItem will be used up and does not count as reagent
5211 int32 charges
= m_CastItem
->GetSpellCharges(s
);
5212 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
5219 if( !p_caster
->HasItemCount(itemid
, itemcount
) )
5220 return SPELL_FAILED_ITEM_NOT_READY
; //0x54
5224 // check totem-item requirements (items presence in inventory)
5226 for(int i
= 0; i
< 2 ; ++i
)
5228 if(m_spellInfo
->Totem
[i
] != 0)
5230 if( p_caster
->HasItemCount(m_spellInfo
->Totem
[i
], 1) )
5239 return SPELL_FAILED_TOTEMS
; //0x7C
5241 // Check items for TotemCategory (items presence in inventory)
5242 uint32 TotemCategory
= 2;
5243 for(int i
= 0; i
< 2; ++i
)
5245 if(m_spellInfo
->TotemCategory
[i
] != 0)
5247 if( p_caster
->HasItemTotemCategory(m_spellInfo
->TotemCategory
[i
]) )
5256 if(TotemCategory
!= 0)
5257 return SPELL_FAILED_TOTEM_CATEGORY
; //0x7B
5259 // special checks for spell effects
5260 for(int i
= 0; i
< 3; ++i
)
5262 switch (m_spellInfo
->Effect
[i
])
5264 case SPELL_EFFECT_CREATE_ITEM
:
5266 if (!m_IsTriggeredSpell
&& m_spellInfo
->EffectItemType
[i
])
5268 ItemPosCountVec dest
;
5269 uint8 msg
= p_caster
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, m_spellInfo
->EffectItemType
[i
], 1 );
5270 if (msg
!= EQUIP_ERR_OK
)
5272 p_caster
->SendEquipError( msg
, NULL
, NULL
);
5273 return SPELL_FAILED_DONT_REPORT
;
5278 case SPELL_EFFECT_ENCHANT_ITEM
:
5279 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
5281 Item
* targetItem
= m_targets
.getItemTarget();
5283 return SPELL_FAILED_ITEM_NOT_FOUND
;
5285 if( targetItem
->GetProto()->ItemLevel
< m_spellInfo
->baseLevel
)
5286 return SPELL_FAILED_LOWLEVEL
;
5287 // Not allow enchant in trade slot for some enchant type
5288 if( targetItem
->GetOwner() != m_caster
)
5290 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5291 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5293 return SPELL_FAILED_ERROR
;
5294 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5295 return SPELL_FAILED_NOT_TRADEABLE
;
5299 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
5301 Item
*item
= m_targets
.getItemTarget();
5303 return SPELL_FAILED_ITEM_NOT_FOUND
;
5304 // Not allow enchant in trade slot for some enchant type
5305 if( item
->GetOwner() != m_caster
)
5307 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5308 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5310 return SPELL_FAILED_ERROR
;
5311 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5312 return SPELL_FAILED_NOT_TRADEABLE
;
5316 case SPELL_EFFECT_ENCHANT_HELD_ITEM
:
5317 // check item existence in effect code (not output errors at offhand hold item effect to main hand for example
5319 case SPELL_EFFECT_DISENCHANT
:
5321 if(!m_targets
.getItemTarget())
5322 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5324 // prevent disenchanting in trade slot
5325 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5326 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5328 ItemPrototype
const* itemProto
= m_targets
.getItemTarget()->GetProto();
5330 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5332 uint32 item_quality
= itemProto
->Quality
;
5333 // 2.0.x addon: Check player enchanting level against the item disenchanting requirements
5334 uint32 item_disenchantskilllevel
= itemProto
->RequiredDisenchantSkill
;
5335 if (item_disenchantskilllevel
== uint32(-1))
5336 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5337 if (item_disenchantskilllevel
> p_caster
->GetSkillValue(SKILL_ENCHANTING
))
5338 return SPELL_FAILED_LOW_CASTLEVEL
;
5339 if(item_quality
> 4 || item_quality
< 2)
5340 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5341 if(itemProto
->Class
!= ITEM_CLASS_WEAPON
&& itemProto
->Class
!= ITEM_CLASS_ARMOR
)
5342 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5343 if (!itemProto
->DisenchantID
)
5344 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5347 case SPELL_EFFECT_PROSPECTING
:
5349 if(!m_targets
.getItemTarget())
5350 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5351 //ensure item is a prospectable ore
5352 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_MINING_SUPP
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5353 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5354 //prevent prospecting in trade slot
5355 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5356 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5357 //Check for enough skill in jewelcrafting
5358 uint32 item_prospectingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5359 if(item_prospectingskilllevel
>p_caster
->GetSkillValue(SKILL_JEWELCRAFTING
))
5360 return SPELL_FAILED_LOW_CASTLEVEL
;
5361 //make sure the player has the required ores in inventory
5362 if(m_targets
.getItemTarget()->GetCount() < 5)
5363 return SPELL_FAILED_NEED_MORE_ITEMS
;
5365 if(!LootTemplates_Prospecting
.HaveLootFor(m_targets
.getItemTargetEntry()))
5366 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5370 case SPELL_EFFECT_MILLING
:
5372 if(!m_targets
.getItemTarget())
5373 return SPELL_FAILED_CANT_BE_MILLED
;
5374 //ensure item is a millable herb
5375 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_HERBS
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5376 return SPELL_FAILED_CANT_BE_MILLED
;
5377 //prevent milling in trade slot
5378 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5379 return SPELL_FAILED_CANT_BE_MILLED
;
5380 //Check for enough skill in inscription
5381 uint32 item_millingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5382 if(item_millingskilllevel
>p_caster
->GetSkillValue(SKILL_INSCRIPTION
))
5383 return SPELL_FAILED_LOW_CASTLEVEL
;
5384 //make sure the player has the required herbs in inventory
5385 if(m_targets
.getItemTarget()->GetCount() < 5)
5386 return SPELL_FAILED_NEED_MORE_ITEMS
;
5388 if(!LootTemplates_Milling
.HaveLootFor(m_targets
.getItemTargetEntry()))
5389 return SPELL_FAILED_CANT_BE_MILLED
;
5393 case SPELL_EFFECT_WEAPON_DAMAGE
:
5394 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
:
5396 if(m_caster
->GetTypeId() != TYPEID_PLAYER
) return SPELL_FAILED_TARGET_NOT_PLAYER
;
5397 if( m_attackType
!= RANGED_ATTACK
)
5399 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(m_attackType
);
5400 if(!pItem
|| pItem
->IsBroken())
5401 return SPELL_FAILED_EQUIPPED_ITEM
;
5403 switch(pItem
->GetProto()->SubClass
)
5405 case ITEM_SUBCLASS_WEAPON_THROWN
:
5407 uint32 ammo
= pItem
->GetEntry();
5408 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5409 return SPELL_FAILED_NO_AMMO
;
5411 case ITEM_SUBCLASS_WEAPON_GUN
:
5412 case ITEM_SUBCLASS_WEAPON_BOW
:
5413 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5415 uint32 ammo
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
5419 if(m_caster
->GetDummyAura(46699))
5420 break; // skip other checks
5422 return SPELL_FAILED_NO_AMMO
;
5425 ItemPrototype
const *ammoProto
= objmgr
.GetItemPrototype( ammo
);
5427 return SPELL_FAILED_NO_AMMO
;
5429 if(ammoProto
->Class
!= ITEM_CLASS_PROJECTILE
)
5430 return SPELL_FAILED_NO_AMMO
;
5432 // check ammo ws. weapon compatibility
5433 switch(pItem
->GetProto()->SubClass
)
5435 case ITEM_SUBCLASS_WEAPON_BOW
:
5436 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5437 if(ammoProto
->SubClass
!= ITEM_SUBCLASS_ARROW
)
5438 return SPELL_FAILED_NO_AMMO
;
5440 case ITEM_SUBCLASS_WEAPON_GUN
:
5441 if(ammoProto
->SubClass
!= ITEM_SUBCLASS_BULLET
)
5442 return SPELL_FAILED_NO_AMMO
;
5445 return SPELL_FAILED_NO_AMMO
;
5448 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5449 return SPELL_FAILED_NO_AMMO
;
5451 case ITEM_SUBCLASS_WEAPON_WAND
:
5462 return SPELL_CAST_OK
;
5465 void Spell::Delayed()
5467 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
5470 if (m_spellState
== SPELL_STATE_DELAYED
)
5471 return; // spell is active and can't be time-backed
5473 if(isDelayableNoMore()) // Spells may only be delayed twice
5476 // spells not loosing casting time ( slam, dynamites, bombs.. )
5477 if(!(m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_DAMAGE
))
5480 //check pushback reduce
5481 int32 delaytime
= 500; // spellcasting delay is normally 500ms
5482 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5483 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5484 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5485 if(delayReduce
>= 100)
5488 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5490 if(int32(m_timer
) + delaytime
> m_casttime
)
5492 delaytime
= m_casttime
- m_timer
;
5493 m_timer
= m_casttime
;
5496 m_timer
+= delaytime
;
5498 sLog
.outDetail("Spell %u partially interrupted for (%d) ms at damage", m_spellInfo
->Id
, delaytime
);
5500 WorldPacket
data(SMSG_SPELL_DELAYED
, 8+4);
5501 data
.append(m_caster
->GetPackGUID());
5502 data
<< uint32(delaytime
);
5504 m_caster
->SendMessageToSet(&data
, true);
5507 void Spell::DelayedChannel()
5509 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
|| getState() != SPELL_STATE_CASTING
)
5512 if(isDelayableNoMore()) // Spells may only be delayed twice
5515 //check pushback reduce
5516 int32 delaytime
= GetSpellDuration(m_spellInfo
) * 25 / 100; // channeling delay is normally 25% of its time per hit
5517 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5518 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5519 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5520 if(delayReduce
>= 100)
5523 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5525 if(int32(m_timer
) < delaytime
)
5527 delaytime
= m_timer
;
5531 m_timer
-= delaytime
;
5533 sLog
.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo
->Id
, delaytime
, m_timer
);
5535 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
5537 if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
5539 Unit
* unit
= m_caster
->GetGUID() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
5542 for (int j
= 0; j
< 3; ++j
)
5543 if( ihit
->effectMask
& (1 << j
) )
5544 unit
->DelayAura(m_spellInfo
->Id
, j
, delaytime
);
5550 for(int j
= 0; j
< 3; ++j
)
5552 // partially interrupt persistent area auras
5553 DynamicObject
* dynObj
= m_caster
->GetDynObject(m_spellInfo
->Id
, j
);
5555 dynObj
->Delay(delaytime
);
5558 SendChannelUpdate(m_timer
);
5561 void Spell::UpdatePointers()
5563 if(m_originalCasterGUID
==m_caster
->GetGUID())
5564 m_originalCaster
= m_caster
;
5567 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
,m_originalCasterGUID
);
5568 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
5571 m_targets
.Update(m_caster
);
5574 bool Spell::IsAffectedByAura(Aura
*aura
)
5576 return spellmgr
.IsAffectedByMod(m_spellInfo
, aura
->getAuraSpellMod());
5579 bool Spell::CheckTargetCreatureType(Unit
* target
) const
5581 uint32 spellCreatureTargetMask
= m_spellInfo
->TargetCreatureType
;
5583 // Curse of Doom & Exorcism: not find another way to fix spell target check :/
5584 if (m_spellInfo
->SpellFamilyName
==SPELLFAMILY_WARLOCK
&& m_spellInfo
->Category
== 1179 ||
5585 // TODO: will be removed in 3.2.x
5586 m_spellInfo
->SpellFamilyName
==SPELLFAMILY_PALADIN
&& m_spellInfo
->Category
== 19)
5588 // not allow cast at player
5589 if(target
->GetTypeId()==TYPEID_PLAYER
)
5592 spellCreatureTargetMask
= 0x7FF;
5595 // Dismiss Pet and Taming Lesson skipped
5596 if(m_spellInfo
->Id
== 2641 || m_spellInfo
->Id
== 23356)
5597 spellCreatureTargetMask
= 0;
5599 if (spellCreatureTargetMask
)
5601 uint32 TargetCreatureType
= target
->GetCreatureTypeMask();
5603 return !TargetCreatureType
|| (spellCreatureTargetMask
& TargetCreatureType
);
5608 CurrentSpellTypes
Spell::GetCurrentContainer()
5610 if (IsNextMeleeSwingSpell())
5611 return(CURRENT_MELEE_SPELL
);
5612 else if (IsAutoRepeat())
5613 return(CURRENT_AUTOREPEAT_SPELL
);
5614 else if (IsChanneledSpell(m_spellInfo
))
5615 return(CURRENT_CHANNELED_SPELL
);
5617 return(CURRENT_GENERIC_SPELL
);
5620 bool Spell::CheckTarget( Unit
* target
, uint32 eff
)
5622 // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets)
5623 if(m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SELF
)
5625 if (!CheckTargetCreatureType(target
))
5629 // Check Aura spell req (need for AoE spells)
5630 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
5632 if (m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
5635 // Check targets for not_selectable unit flag and remove
5636 // A player can cast spells on his pet (or other controlled unit) though in any state
5637 if (target
!= m_caster
&& target
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
5639 // any unattackable target skipped
5640 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
))
5643 // unselectable targets skipped in all cases except TARGET_SCRIPT targeting
5644 // in case TARGET_SCRIPT target selected by server always and can't be cheated
5645 if( target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NOT_SELECTABLE
) &&
5646 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SCRIPT
&&
5647 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_SCRIPT
)
5651 //Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
5652 if( target
!= m_caster
&& target
->GetTypeId() == TYPEID_PLAYER
)
5654 if(((Player
*)target
)->GetVisibility() == VISIBILITY_OFF
)
5657 if(((Player
*)target
)->isGameMaster() && !IsPositiveSpell(m_spellInfo
->Id
))
5661 //Check targets for LOS visibility (except spells without range limitations )
5662 switch(m_spellInfo
->Effect
[eff
])
5664 case SPELL_EFFECT_SUMMON_PLAYER
: // from anywhere
5666 case SPELL_EFFECT_DUMMY
:
5667 if(m_spellInfo
->Id
!= 20577) // Cannibalize
5670 case SPELL_EFFECT_RESURRECT_NEW
:
5671 // player far away, maybe his corpse near?
5672 if(target
!= m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
5674 if(!m_targets
.getCorpseTargetGUID())
5677 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
, m_targets
.getCorpseTargetGUID());
5681 if(target
->GetGUID() != corpse
->GetOwnerGUID())
5684 if(!corpse
->IsWithinLOSInMap(m_caster
))
5688 // all ok by some way or another, skip normal check
5690 default: // normal case
5691 // Get GO cast coordinates if original caster -> GO
5692 WorldObject
*caster
= NULL
;
5693 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
5694 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
5697 if(target
!= m_caster
&& !target
->IsWithinLOSInMap(caster
))
5705 bool Spell::IsNeedSendToClient() const
5707 return m_spellInfo
->SpellVisual
[0] || m_spellInfo
->SpellVisual
[1] || IsChanneledSpell(m_spellInfo
) ||
5708 m_spellInfo
->speed
> 0.0f
|| !m_triggeredByAuraSpell
&& !m_IsTriggeredSpell
;
5711 bool Spell::HaveTargetsForEffect( uint8 effect
) const
5713 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin(); itr
!= m_UniqueTargetInfo
.end(); ++itr
)
5714 if(itr
->effectMask
& (1 << effect
))
5717 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin(); itr
!= m_UniqueGOTargetInfo
.end(); ++itr
)
5718 if(itr
->effectMask
& (1 << effect
))
5721 for(std::list
<ItemTargetInfo
>::const_iterator itr
= m_UniqueItemInfo
.begin(); itr
!= m_UniqueItemInfo
.end(); ++itr
)
5722 if(itr
->effectMask
& (1 << effect
))
5728 SpellEvent::SpellEvent(Spell
* spell
) : BasicEvent()
5733 SpellEvent::~SpellEvent()
5735 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5738 if (m_Spell
->IsDeletable())
5744 sLog
.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
5745 (m_Spell
->GetCaster()->GetTypeId() == TYPEID_PLAYER
? "Player" : "Creature"), m_Spell
->GetCaster()->GetGUIDLow(), m_Spell
->m_spellInfo
->Id
);
5749 bool SpellEvent::Execute(uint64 e_time
, uint32 p_time
)
5751 // update spell if it is not finished
5752 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5753 m_Spell
->update(p_time
);
5755 // check spell state to process
5756 switch (m_Spell
->getState())
5758 case SPELL_STATE_FINISHED
:
5760 // spell was finished, check deletable state
5761 if (m_Spell
->IsDeletable())
5763 // check, if we do have unfinished triggered spells
5764 return true; // spell is deletable, finish event
5766 // event will be re-added automatically at the end of routine)
5769 case SPELL_STATE_CASTING
:
5771 // this spell is in channeled state, process it on the next update
5772 // event will be re-added automatically at the end of routine)
5775 case SPELL_STATE_DELAYED
:
5777 // first, check, if we have just started
5778 if (m_Spell
->GetDelayStart() != 0)
5780 // no, we aren't, do the typical update
5781 // check, if we have channeled spell on our hands
5782 if (IsChanneledSpell(m_Spell
->m_spellInfo
))
5784 // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish
5785 // check, if we have casting anything else except this channeled spell and autorepeat
5786 if (m_Spell
->GetCaster()->IsNonMeleeSpellCasted(false, true, true))
5788 // another non-melee non-delayed spell is casted now, abort
5793 // do the action (pass spell to channeling state)
5794 m_Spell
->handle_immediate();
5796 // event will be re-added automatically at the end of routine)
5800 // run the spell handler and think about what we can do next
5801 uint64 t_offset
= e_time
- m_Spell
->GetDelayStart();
5802 uint64 n_offset
= m_Spell
->handle_delayed(t_offset
);
5805 // re-add us to the queue
5806 m_Spell
->GetCaster()->m_Events
.AddEvent(this, m_Spell
->GetDelayStart() + n_offset
, false);
5807 return false; // event not complete
5810 // finish update event will be re-added automatically at the end of routine)
5815 // delaying had just started, record the moment
5816 m_Spell
->SetDelayStart(e_time
);
5817 // re-plan the event for the delay moment
5818 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ m_Spell
->GetDelayMoment(), false);
5819 return false; // event not complete
5826 // event will be re-added automatically at the end of routine)
5830 // spell processing not complete, plan event on the next update interval
5831 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ 1, false);
5832 return false; // event not complete
5835 void SpellEvent::Abort(uint64
/*e_time*/)
5837 // oops, the spell we try to do is aborted
5838 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5842 bool SpellEvent::IsDeletable() const
5844 return m_Spell
->IsDeletable();
5847 SpellCastResult
Spell::CanOpenLock(uint32 effIndex
, uint32 lockId
, SkillType
& skillId
, int32
& reqSkillValue
, int32
& skillValue
)
5849 if(!lockId
) // possible case for GO and maybe for items.
5850 return SPELL_CAST_OK
;
5853 LockEntry
const *lockInfo
= sLockStore
.LookupEntry(lockId
);
5856 return SPELL_FAILED_BAD_TARGETS
;
5858 bool reqKey
= false; // some locks not have reqs
5860 for(int j
= 0; j
< 8; ++j
)
5862 switch(lockInfo
->Type
[j
])
5864 // check key item (many fit cases can be)
5866 if(lockInfo
->Index
[j
] && m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->Index
[j
])
5867 return SPELL_CAST_OK
;
5870 // check key skill (only single first fit case can be)
5871 case LOCK_KEY_SKILL
:
5875 // wrong locktype, skip
5876 if(uint32(m_spellInfo
->EffectMiscValue
[effIndex
]) != lockInfo
->Index
[j
])
5879 skillId
= SkillByLockType(LockType(lockInfo
->Index
[j
]));
5881 if ( skillId
!= SKILL_NONE
)
5883 // skill bonus provided by casting spell (mostly item spells)
5884 // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value)
5885 uint32 spellSkillBonus
= uint32(m_currentBasePoints
[effIndex
]+1);
5886 reqSkillValue
= lockInfo
->Skill
[j
];
5888 // castitem check: rogue using skeleton keys. the skill values should not be added in this case.
5889 skillValue
= m_CastItem
|| m_caster
->GetTypeId()!= TYPEID_PLAYER
?
5890 0 : ((Player
*)m_caster
)->GetSkillValue(skillId
);
5892 skillValue
+= spellSkillBonus
;
5894 if (skillValue
< reqSkillValue
)
5895 return SPELL_FAILED_LOW_CASTLEVEL
;
5898 return SPELL_CAST_OK
;
5904 return SPELL_FAILED_BAD_TARGETS
;
5906 return SPELL_CAST_OK
;
5909 void Spell::FillAreaTargets( UnitList
& TagUnitMap
, float x
, float y
, float radius
, SpellNotifyPushType pushType
, SpellTargets spellTargets
)
5911 CellPair
p(MaNGOS::ComputeCellPair(x
, y
));
5913 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5915 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, pushType
, spellTargets
);
5916 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
5917 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
5918 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5919 cell_lock
->Visit(cell_lock
, world_notifier
, *m_caster
->GetMap());
5920 cell_lock
->Visit(cell_lock
, grid_notifier
, *m_caster
->GetMap());
5923 void Spell::FillRaidOrPartyTargets( UnitList
&TagUnitMap
, Unit
* member
, Unit
* center
, float radius
, bool raid
, bool withPets
, bool withcaster
)
5925 Player
*pMember
= member
->GetCharmerOrOwnerPlayerOrPlayerItself();
5926 Group
*pGroup
= pMember
? pMember
->GetGroup() : NULL
;
5930 uint8 subgroup
= pMember
->GetSubGroup();
5932 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
5934 Player
* Target
= itr
->getSource();
5936 // IsHostileTo check duel and controlled by enemy
5937 if (Target
&& (raid
|| subgroup
==Target
->GetSubGroup())
5938 && !m_caster
->IsHostileTo(Target
))
5940 if ((Target
==center
|| center
->IsWithinDistInMap(Target
, radius
)) &&
5941 (withcaster
|| Target
!= m_caster
))
5942 TagUnitMap
.push_back(Target
);
5945 if (Pet
* pet
= Target
->GetPet())
5946 if ((pet
==center
|| center
->IsWithinDistInMap(pet
, radius
)) &&
5947 (withcaster
|| pet
!= m_caster
))
5948 TagUnitMap
.push_back(pet
);
5954 Unit
* ownerOrSelf
= pMember
? pMember
: member
->GetCharmerOrOwnerOrSelf();
5955 if ((ownerOrSelf
==center
|| center
->IsWithinDistInMap(ownerOrSelf
, radius
)) &&
5956 (withcaster
|| ownerOrSelf
!= m_caster
))
5957 TagUnitMap
.push_back(ownerOrSelf
);
5960 if (Pet
* pet
= ownerOrSelf
->GetPet())
5961 if ((pet
==center
|| center
->IsWithinDistInMap(pet
, radius
)) &&
5962 (withcaster
|| pet
!= m_caster
))
5963 TagUnitMap
.push_back(pet
);
5967 void Spell::FillRaidOrPartyManaPriorityTargets( UnitList
&TagUnitMap
, Unit
* member
, Unit
* center
, float radius
, uint32 count
, bool raid
, bool withPets
, bool withCaster
)
5969 FillRaidOrPartyTargets(TagUnitMap
, member
, center
, radius
, raid
, withPets
, withCaster
);
5971 PrioritizeManaUnitQueue manaUsers
;
5972 for(UnitList::const_iterator itr
= TagUnitMap
.begin(); itr
!= TagUnitMap
.end() && manaUsers
.size() < count
; ++itr
)
5973 if ((*itr
)->getPowerType() == POWER_MANA
&& !(*itr
)->isDead())
5974 manaUsers
.push(PrioritizeManaUnitWraper(*itr
));
5977 while(!manaUsers
.empty())
5979 TagUnitMap
.push_back(manaUsers
.top().getUnit());
5984 void Spell::FillRaidOrPartyHealthPriorityTargets( UnitList
&TagUnitMap
, Unit
* member
, Unit
* center
, float radius
, uint32 count
, bool raid
, bool withPets
, bool withCaster
)
5986 FillRaidOrPartyTargets(TagUnitMap
, member
, center
, radius
, raid
, withPets
, withCaster
);
5988 PrioritizeHealthUnitQueue healthQueue
;
5989 for(UnitList::const_iterator itr
= TagUnitMap
.begin(); itr
!= TagUnitMap
.end() && healthQueue
.size() < count
; ++itr
)
5990 if (!(*itr
)->isDead())
5991 healthQueue
.push(PrioritizeHealthUnitWraper(*itr
));
5994 while(!healthQueue
.empty())
5996 TagUnitMap
.push_back(healthQueue
.top().getUnit());