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
])
514 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
519 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
522 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
524 case TARGET_AREAEFFECT_INSTANT
: // use B case that not dependent from from A in fact
525 if((m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
) == 0)
526 m_targets
.setDestination(m_caster
->GetPositionX(), m_caster
->GetPositionY(), m_caster
->GetPositionZ());
527 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
529 case TARGET_BEHIND_VICTIM
: // use B case that not dependent from from A in fact
530 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
533 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
534 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
538 case TARGET_CASTER_COORDINATES
:
539 // Note: this hack with search required until GO casting not implemented
540 // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support
541 // currently each enemy selected explicitly and self cast damage
542 if(m_spellInfo
->EffectImplicitTargetB
[i
] == TARGET_ALL_ENEMY_IN_AREA
&& m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
)
544 if(m_targets
.getUnitTarget())
545 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
549 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
550 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
553 case TARGET_TABLE_X_Y_Z_COORDINATES
:
554 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
557 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
559 // need some target for proccesing
560 if(m_targets
.getUnitTarget())
561 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
563 tmpUnitMap
.push_back(m_caster
);
565 case TARGET_AREAEFFECT_INSTANT
: // All 17/7 pairs used for dest teleportation, A processed in effect code
566 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
569 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
570 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
575 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
578 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
580 case TARGET_SCRIPT_COORDINATES
: // B case filled in CheckCast but we need fill unit list base at A case
581 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
584 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
585 SetTargetMap(i
, m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
591 if( (m_spellInfo
->EffectImplicitTargetA
[i
] == 0 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_EFFECT_SELECT
) &&
592 (m_spellInfo
->EffectImplicitTargetB
[i
] == 0 || m_spellInfo
->EffectImplicitTargetB
[i
] == TARGET_EFFECT_SELECT
) )
594 // add here custom effects that need default target.
595 // FOR EVERY TARGET TYPE THERE IS A DIFFERENT FILL!!
596 switch(m_spellInfo
->Effect
[i
])
598 case SPELL_EFFECT_DUMMY
:
600 switch(m_spellInfo
->Id
)
602 case 20577: // Cannibalize
604 WorldObject
* result
= FindCorpseUsing
<MaNGOS::CannibalizeObjectCheck
> ();
608 switch(result
->GetTypeId())
612 tmpUnitMap
.push_back((Unit
*)result
);
615 m_targets
.setCorpseTarget((Corpse
*)result
);
616 if(Player
* owner
= ObjectAccessor::FindPlayer(((Corpse
*)result
)->GetOwnerGUID()))
617 tmpUnitMap
.push_back(owner
);
623 // clear cooldown at fail
624 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
625 ((Player
*)m_caster
)->RemoveSpellCooldown(m_spellInfo
->Id
, true);
626 SendCastResult(SPELL_FAILED_NO_EDIBLE_CORPSES
);
632 if(m_targets
.getUnitTarget())
633 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
638 case SPELL_EFFECT_RESURRECT
:
639 case SPELL_EFFECT_PARRY
:
640 case SPELL_EFFECT_BLOCK
:
641 case SPELL_EFFECT_CREATE_ITEM
:
642 case SPELL_EFFECT_TRIGGER_SPELL
:
643 case SPELL_EFFECT_TRIGGER_MISSILE
:
644 case SPELL_EFFECT_LEARN_SPELL
:
645 case SPELL_EFFECT_SKILL_STEP
:
646 case SPELL_EFFECT_PROFICIENCY
:
647 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
648 case SPELL_EFFECT_SELF_RESURRECT
:
649 case SPELL_EFFECT_REPUTATION
:
650 case SPELL_EFFECT_SEND_TAXI
:
651 if(m_targets
.getUnitTarget())
652 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
653 // Triggered spells have additional spell targets - cast them even if no explicit unit target is given (required for spell 50516 for example)
654 else if(m_spellInfo
->Effect
[i
] == SPELL_EFFECT_TRIGGER_SPELL
)
655 tmpUnitMap
.push_back(m_caster
);
657 case SPELL_EFFECT_SUMMON_PLAYER
:
658 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetSelection())
660 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
662 tmpUnitMap
.push_back(target
);
665 case SPELL_EFFECT_RESURRECT_NEW
:
666 if(m_targets
.getUnitTarget())
667 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
668 if(m_targets
.getCorpseTargetGUID())
670 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
, m_targets
.getCorpseTargetGUID());
673 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
675 tmpUnitMap
.push_back(owner
);
679 case SPELL_EFFECT_SUMMON
:
680 if(m_spellInfo
->EffectMiscValueB
[i
] == SUMMON_TYPE_POSESSED
|| m_spellInfo
->EffectMiscValueB
[i
] == SUMMON_TYPE_POSESSED2
)
682 if(m_targets
.getUnitTarget())
683 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
686 tmpUnitMap
.push_back(m_caster
);
688 case SPELL_EFFECT_SUMMON_CHANGE_ITEM
:
689 case SPELL_EFFECT_TRANS_DOOR
:
690 case SPELL_EFFECT_ADD_FARSIGHT
:
691 case SPELL_EFFECT_APPLY_GLYPH
:
692 case SPELL_EFFECT_STUCK
:
693 case SPELL_EFFECT_FEED_PET
:
694 case SPELL_EFFECT_DESTROY_ALL_TOTEMS
:
695 case SPELL_EFFECT_SKILL
:
696 tmpUnitMap
.push_back(m_caster
);
698 case SPELL_EFFECT_LEARN_PET_SPELL
:
699 if(Pet
* pet
= m_caster
->GetPet())
700 tmpUnitMap
.push_back(pet
);
702 case SPELL_EFFECT_ENCHANT_ITEM
:
703 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
704 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
705 case SPELL_EFFECT_DISENCHANT
:
706 case SPELL_EFFECT_PROSPECTING
:
707 case SPELL_EFFECT_MILLING
:
708 if(m_targets
.getItemTarget())
709 AddItemTarget(m_targets
.getItemTarget(), i
);
711 case SPELL_EFFECT_APPLY_AURA
:
712 switch(m_spellInfo
->EffectApplyAuraName
[i
])
714 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)
715 case SPELL_AURA_ADD_PCT_MODIFIER
:
716 tmpUnitMap
.push_back(m_caster
);
718 default: // apply to target in other case
719 if(m_targets
.getUnitTarget())
720 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
724 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY
:
726 if(m_spellInfo
->Attributes
== 0x9050000 || m_spellInfo
->Attributes
== 0x10000)
727 SetTargetMap(i
,TARGET_AREAEFFECT_PARTY
, tmpUnitMap
);
729 case SPELL_EFFECT_SKIN_PLAYER_CORPSE
:
730 if(m_targets
.getUnitTarget())
732 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
734 else if (m_targets
.getCorpseTargetGUID())
736 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
739 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
741 tmpUnitMap
.push_back(owner
);
750 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
752 Player
*me
= (Player
*)m_caster
;
753 for (std::list
<Unit
*>::const_iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end(); ++itr
)
755 Unit
*owner
= (*itr
)->GetOwner();
756 Unit
*u
= owner
? owner
: (*itr
);
757 if(u
!=m_caster
&& u
->IsPvP() && (!me
->duel
|| me
->duel
->opponent
!= u
))
760 me
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
766 for (std::list
<Unit
*>::iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end();)
768 if (!CheckTarget (*itr
, i
))
770 itr
= tmpUnitMap
.erase(itr
);
777 for(std::list
<Unit
*>::const_iterator iunit
= tmpUnitMap
.begin(); iunit
!= tmpUnitMap
.end(); ++iunit
)
778 AddUnitTarget((*iunit
), i
);
782 void Spell::prepareDataForTriggerSystem()
784 //==========================================================================================
785 // Now fill data for trigger system, need know:
786 // an spell trigger another or not ( m_canTrigger )
787 // Create base triggers flags for Attacker and Victim ( m_procAttacker and m_procVictim)
788 //==========================================================================================
789 // Fill flag can spell trigger or not
790 // TODO: possible exist spell attribute for this
791 m_canTrigger
= false;
794 m_canTrigger
= false; // Do not trigger from item cast spell
795 else if (!m_IsTriggeredSpell
)
796 m_canTrigger
= true; // Normal cast - can trigger
797 else if (!m_triggeredByAuraSpell
)
798 m_canTrigger
= true; // Triggered from SPELL_EFFECT_TRIGGER_SPELL - can trigger
800 if (!m_canTrigger
) // Exceptions (some periodic triggers)
802 switch (m_spellInfo
->SpellFamilyName
)
804 case SPELLFAMILY_MAGE
:
805 // Arcane Missles / Blizzard triggers need do it
806 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000200080))
808 // Clearcasting trigger need do it
809 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000200000000) && m_spellInfo
->SpellFamilyFlags2
& 0x8)
812 case SPELLFAMILY_WARLOCK
: // For Hellfire Effect / Rain of Fire / Seed of Corruption triggers need do it
813 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000800000000060))
816 case SPELLFAMILY_PRIEST
: // For Penance heal/damage triggers need do it
817 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0001800000000000))
820 case SPELLFAMILY_ROGUE
: // For poisons need do it
821 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x000000101001E000))
824 case SPELLFAMILY_HUNTER
: // Hunter Rapid Killing/Explosive Trap Effect/Immolation Trap Effect/Frost Trap Aura/Snake Trap Effect/Explosive Shot
825 if ((m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0100200000000214)) ||
826 m_spellInfo
->SpellFamilyFlags2
& 0x200)
829 case SPELLFAMILY_PALADIN
: // For Judgements (all) / Holy Shock triggers need do it
830 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0001000900B80400))
838 // Get data for type of attack and fill base info for trigger
839 switch (m_spellInfo
->DmgClass
)
841 case SPELL_DAMAGE_CLASS_MELEE
:
842 m_procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT
;
843 m_procVictim
= PROC_FLAG_TAKEN_MELEE_SPELL_HIT
;
845 case SPELL_DAMAGE_CLASS_RANGED
:
847 if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
)
849 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
850 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
852 else // Ranged spell attack
854 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT
;
855 m_procVictim
= PROC_FLAG_TAKEN_RANGED_SPELL_HIT
;
859 if (IsPositiveSpell(m_spellInfo
->Id
)) // Check for positive spell
861 m_procAttacker
= PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
;
862 m_procVictim
= PROC_FLAG_TAKEN_POSITIVE_SPELL
;
864 else if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
) // Wands auto attack
866 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
867 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
869 else // Negative spell
871 m_procAttacker
= PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT
;
872 m_procVictim
= PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
;
876 // Hunter traps spells (for Entrapment trigger)
877 // Gives your Immolation Trap, Frost Trap, Explosive Trap, and Snake Trap ....
878 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_HUNTER
&& (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x000020000000001C)))
879 m_procAttacker
|= PROC_FLAG_ON_TRAP_ACTIVATION
;
882 void Spell::CleanupTargetList()
884 m_UniqueTargetInfo
.clear();
885 m_UniqueGOTargetInfo
.clear();
886 m_UniqueItemInfo
.clear();
890 void Spell::AddUnitTarget(Unit
* pVictim
, uint32 effIndex
)
892 if( m_spellInfo
->Effect
[effIndex
] == 0 )
895 // Check for effect immune skip if immuned
896 bool immuned
= pVictim
->IsImmunedToSpellEffect(m_spellInfo
, effIndex
);
898 uint64 targetGUID
= pVictim
->GetGUID();
900 // Lookup target in already in list
901 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
903 if (targetGUID
== ihit
->targetGUID
) // Found in list
906 ihit
->effectMask
|= 1 << effIndex
; // Add only effect mask if not immuned
911 // This is new target calculate data for him
913 // Get spell hit result on target
915 target
.targetGUID
= targetGUID
; // Store target GUID
916 target
.effectMask
= immuned
? 0 : 1 << effIndex
; // Store index of effect if not immuned
917 target
.processed
= false; // Effects not apply on target
919 // Calculate hit result
920 target
.missCondition
= m_caster
->SpellHitResult(pVictim
, m_spellInfo
, m_canReflect
);
922 // Spell have speed - need calculate incoming time
923 if (m_spellInfo
->speed
> 0.0f
)
925 // calculate spell incoming interval
926 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
927 if (dist
< 5.0f
) dist
= 5.0f
;
928 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
930 // Calculate minimum incoming time
931 if (m_delayMoment
== 0 || m_delayMoment
>target
.timeDelay
)
932 m_delayMoment
= target
.timeDelay
;
935 target
.timeDelay
= UI64LIT(0);
937 // If target reflect spell back to caster
938 if (target
.missCondition
== SPELL_MISS_REFLECT
)
940 // Calculate reflected spell result on caster
941 target
.reflectResult
= m_caster
->SpellHitResult(m_caster
, m_spellInfo
, m_canReflect
);
943 if (target
.reflectResult
== SPELL_MISS_REFLECT
) // Impossible reflect again, so simply deflect spell
944 target
.reflectResult
= SPELL_MISS_PARRY
;
946 // Increase time interval for reflected spells by 1.5
947 target
.timeDelay
+= target
.timeDelay
>> 1;
950 target
.reflectResult
= SPELL_MISS_NONE
;
952 // Add target to list
953 m_UniqueTargetInfo
.push_back(target
);
956 void Spell::AddUnitTarget(uint64 unitGUID
, uint32 effIndex
)
958 Unit
* unit
= m_caster
->GetGUID() == unitGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, unitGUID
);
960 AddUnitTarget(unit
, effIndex
);
963 void Spell::AddGOTarget(GameObject
* pVictim
, uint32 effIndex
)
965 if( m_spellInfo
->Effect
[effIndex
] == 0 )
968 uint64 targetGUID
= pVictim
->GetGUID();
970 // Lookup target in already in list
971 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
973 if (targetGUID
== ihit
->targetGUID
) // Found in list
975 ihit
->effectMask
|= 1 << effIndex
; // Add only effect mask
980 // This is new target calculate data for him
983 target
.targetGUID
= targetGUID
;
984 target
.effectMask
= 1 << effIndex
;
985 target
.processed
= false; // Effects not apply on target
987 // Spell have speed - need calculate incoming time
988 if (m_spellInfo
->speed
> 0.0f
)
990 // calculate spell incoming interval
991 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
992 if (dist
< 5.0f
) dist
= 5.0f
;
993 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
994 if (m_delayMoment
==0 || m_delayMoment
>target
.timeDelay
)
995 m_delayMoment
= target
.timeDelay
;
998 target
.timeDelay
= UI64LIT(0);
1000 // Add target to list
1001 m_UniqueGOTargetInfo
.push_back(target
);
1004 void Spell::AddGOTarget(uint64 goGUID
, uint32 effIndex
)
1006 GameObject
* go
= m_caster
->GetMap()->GetGameObject(goGUID
);
1008 AddGOTarget(go
, effIndex
);
1011 void Spell::AddItemTarget(Item
* pitem
, uint32 effIndex
)
1013 if( m_spellInfo
->Effect
[effIndex
] == 0 )
1016 // Lookup target in already in list
1017 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin(); ihit
!= m_UniqueItemInfo
.end(); ++ihit
)
1019 if (pitem
== ihit
->item
) // Found in list
1021 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask
1026 // This is new target add data
1028 ItemTargetInfo target
;
1029 target
.item
= pitem
;
1030 target
.effectMask
= 1 << effIndex
;
1031 m_UniqueItemInfo
.push_back(target
);
1034 void Spell::DoAllEffectOnTarget(TargetInfo
*target
)
1036 if (target
->processed
) // Check target
1038 target
->processed
= true; // Target checked in apply effects procedure
1040 // Get mask of effects for target
1041 uint32 mask
= target
->effectMask
;
1043 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
1047 // Get original caster (if exist) and calculate damage/healing from him data
1048 Unit
*caster
= m_originalCaster
? m_originalCaster
: m_caster
;
1050 // Skip if m_originalCaster not available
1054 SpellMissInfo missInfo
= target
->missCondition
;
1055 // Need init unitTarget by default unit (can changed in code on reflect)
1056 // Or on missInfo!=SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem)
1059 // Reset damage/healing counter
1063 // Fill base trigger info
1064 uint32 procAttacker
= m_procAttacker
;
1065 uint32 procVictim
= m_procVictim
;
1066 uint32 procEx
= PROC_EX_NONE
;
1068 if (missInfo
==SPELL_MISS_NONE
) // In case spell hit target, do all effect on that target
1069 DoSpellHitOnUnit(unit
, mask
);
1070 else if (missInfo
== SPELL_MISS_REFLECT
) // In case spell reflect from target, do all effect on caster (if hit)
1072 if (target
->reflectResult
== SPELL_MISS_NONE
) // If reflected spell hit caster -> do all effect on him
1073 DoSpellHitOnUnit(m_caster
, mask
);
1076 // All calculated do it!
1077 // Do healing and triggers
1080 bool crit
= caster
->isSpellCrit(NULL
, m_spellInfo
, m_spellSchoolMask
);
1081 uint32 addhealth
= m_healing
;
1084 procEx
|= PROC_EX_CRITICAL_HIT
;
1085 addhealth
= caster
->SpellCriticalHealingBonus(m_spellInfo
, addhealth
, NULL
);
1088 procEx
|= PROC_EX_NORMAL_HIT
;
1090 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1091 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1092 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, addhealth
, m_attackType
, m_spellInfo
);
1094 int32 gain
= caster
->DealHeal(unitTarget
, addhealth
, m_spellInfo
, crit
);
1095 unitTarget
->getHostilRefManager().threatAssist(caster
, float(gain
) * 0.5f
, m_spellInfo
);
1097 // Do damage and triggers
1100 // Fill base damage struct (unitTarget - is real spell target)
1101 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1103 // Add bonuses and fill damageInfo struct
1104 caster
->CalculateSpellDamage(&damageInfo
, m_damage
, m_spellInfo
);
1105 caster
->DealDamageMods(damageInfo
.target
, damageInfo
.damage
, &damageInfo
.absorb
);
1107 // Send log damage message to client
1108 caster
->SendSpellNonMeleeDamageLog(&damageInfo
);
1110 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1111 procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1113 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1114 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1115 caster
->ProcDamageAndSpell(unitTarget
, procAttacker
, procVictim
, procEx
, damageInfo
.damage
, m_attackType
, m_spellInfo
);
1117 caster
->DealSpellDamage(&damageInfo
, true);
1119 // Judgement of Blood
1120 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_PALADIN
&& (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000800000000)) && m_spellInfo
->SpellIconID
==153)
1122 int32 damagePoint
= damageInfo
.damage
* 33 / 100;
1123 m_caster
->CastCustomSpell(m_caster
, 32220, &damagePoint
, NULL
, NULL
, true);
1126 // Passive spell hits/misses or active spells only misses (only triggers)
1129 // Fill base damage struct (unitTarget - is real spell target)
1130 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1131 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1132 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1133 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1134 caster
->ProcDamageAndSpell(unit
, procAttacker
, procVictim
, procEx
, 0, m_attackType
, m_spellInfo
);
1137 // Call scripted function for AI if this spell is casted upon a creature
1138 if(unit
->GetTypeId()==TYPEID_UNIT
)
1140 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1141 // ignore pets or autorepeat/melee casts for speed (not exist quest for spells (hm... )
1142 if( !((Creature
*)unit
)->isPet() && !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1144 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1145 p
->CastedCreatureOrGO(unit
->GetEntry(), unit
->GetGUID(), m_spellInfo
->Id
);
1148 if(((Creature
*)unit
)->AI())
1149 ((Creature
*)unit
)->AI()->SpellHit(m_caster
,m_spellInfo
);
1152 // Call scripted function for AI if this spell is casted by a creature
1153 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)m_caster
)->AI())
1154 ((Creature
*)m_caster
)->AI()->SpellHitTarget(unit
, m_spellInfo
);
1157 void Spell::DoSpellHitOnUnit(Unit
*unit
, const uint32 effectMask
)
1159 if (!unit
|| !effectMask
)
1162 Unit
* realCaster
= m_originalCaster
? m_originalCaster
: m_caster
;
1164 // Recheck immune (only for delayed spells)
1165 if (m_spellInfo
->speed
&& (
1166 unit
->IsImmunedToDamage(GetSpellSchoolMask(m_spellInfo
)) ||
1167 unit
->IsImmunedToSpell(m_spellInfo
)))
1169 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_IMMUNE
);
1173 if (unit
->GetTypeId() == TYPEID_PLAYER
)
1175 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET
, m_spellInfo
->Id
);
1176 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2
, m_spellInfo
->Id
);
1179 if (realCaster
->GetTypeId() == TYPEID_PLAYER
)
1180 ((Player
*)realCaster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2
, m_spellInfo
->Id
, 0, unit
);
1182 if (realCaster
!= unit
)
1184 // Recheck UNIT_FLAG_NON_ATTACKABLE for delayed spells
1185 if (m_spellInfo
->speed
> 0.0f
&&
1186 unit
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
) &&
1187 unit
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
1189 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1193 if (!realCaster
->IsFriendlyTo(unit
))
1195 // for delayed spells ignore not visible explicit target
1196 if (m_spellInfo
->speed
> 0.0f
&& unit
== m_targets
.getUnitTarget() &&
1197 !unit
->isVisibleForOrDetect(m_caster
,m_caster
,false))
1199 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1203 // not break stealth by cast targeting
1204 if (!(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_BREAK_STEALTH
))
1205 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1207 // can cause back attack (if detected), stealth removed at Spell::cast if spell break it
1208 if (!(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) && !IsPositiveSpell(m_spellInfo
->Id
) &&
1209 m_caster
->isVisibleForOrDetect(unit
,unit
,false))
1211 // use speedup check to avoid re-remove after above lines
1212 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_BREAK_STEALTH
)
1213 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1215 // caster can be detected but have stealth aura
1216 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1218 if (!unit
->IsStandState() && !unit
->hasUnitState(UNIT_STAT_STUNNED
))
1219 unit
->SetStandState(UNIT_STAND_STATE_STAND
);
1221 if (!unit
->isInCombat() && unit
->GetTypeId() != TYPEID_PLAYER
&& ((Creature
*)unit
)->AI())
1222 ((Creature
*)unit
)->AI()->AttackedBy(realCaster
);
1224 unit
->AddThreat(realCaster
, 0.0f
);
1225 unit
->SetInCombatWith(realCaster
);
1226 realCaster
->SetInCombatWith(unit
);
1228 if (Player
*attackedPlayer
= unit
->GetCharmerOrOwnerPlayerOrPlayerItself())
1229 realCaster
->SetContestedPvP(attackedPlayer
);
1234 // for delayed spells ignore negative spells (after duel end) for friendly targets
1235 if (m_spellInfo
->speed
> 0.0f
&& !IsPositiveSpell(m_spellInfo
->Id
))
1237 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1241 // assisting case, healing and resurrection
1242 if (unit
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
1243 realCaster
->SetContestedPvP();
1245 if (unit
->isInCombat() && !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
))
1247 realCaster
->SetInCombatState(unit
->GetCombatTimer() > 0);
1248 unit
->getHostilRefManager().threatAssist(realCaster
, 0.0f
);
1253 // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
1254 m_diminishGroup
= GetDiminishingReturnsGroupForSpell(m_spellInfo
,m_triggeredByAuraSpell
);
1255 m_diminishLevel
= unit
->GetDiminishing(m_diminishGroup
);
1256 // Increase Diminishing on unit, current informations for actually casts will use values above
1257 if ((GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_PLAYER
&& unit
->GetTypeId() == TYPEID_PLAYER
) ||
1258 GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_ALL
)
1259 unit
->IncrDiminishing(m_diminishGroup
);
1261 // Apply additional spell effects to target
1262 CastPreCastSpells(unit
);
1264 for(uint32 effectNumber
= 0; effectNumber
< 3; ++effectNumber
)
1266 if (effectMask
& (1 << effectNumber
))
1268 HandleEffects(unit
, NULL
, NULL
, effectNumber
, m_damageMultipliers
[effectNumber
]);
1269 if ( m_applyMultiplierMask
& (1 << effectNumber
) )
1272 float multiplier
= m_spellInfo
->DmgMultiplier
[effectNumber
];
1273 // Apply multiplier mods
1274 if(Player
* modOwner
= realCaster
->GetSpellModOwner())
1275 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_EFFECT_PAST_FIRST
, multiplier
, this);
1276 m_damageMultipliers
[effectNumber
] *= multiplier
;
1282 void Spell::DoAllEffectOnTarget(GOTargetInfo
*target
)
1284 if (target
->processed
) // Check target
1286 target
->processed
= true; // Target checked in apply effects procedure
1288 uint32 effectMask
= target
->effectMask
;
1292 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
1296 for(uint32 effectNumber
= 0; effectNumber
< 3; ++effectNumber
)
1297 if (effectMask
& (1 << effectNumber
))
1298 HandleEffects(NULL
, NULL
, go
, effectNumber
);
1300 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1301 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
1302 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1304 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1305 p
->CastedCreatureOrGO(go
->GetEntry(), go
->GetGUID(), m_spellInfo
->Id
);
1309 void Spell::DoAllEffectOnTarget(ItemTargetInfo
*target
)
1311 uint32 effectMask
= target
->effectMask
;
1312 if(!target
->item
|| !effectMask
)
1315 for(uint32 effectNumber
= 0; effectNumber
< 3; ++effectNumber
)
1316 if (effectMask
& (1 << effectNumber
))
1317 HandleEffects(NULL
, target
->item
, NULL
, effectNumber
);
1320 bool Spell::IsAliveUnitPresentInTargetList()
1322 // Not need check return true
1323 if (m_needAliveTargetMask
== 0)
1326 uint8 needAliveTargetMask
= m_needAliveTargetMask
;
1328 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
1330 if( ihit
->missCondition
== SPELL_MISS_NONE
&& (needAliveTargetMask
& ihit
->effectMask
) )
1332 Unit
*unit
= m_caster
->GetGUID() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
1334 if (unit
&& unit
->isAlive())
1335 needAliveTargetMask
&= ~ihit
->effectMask
; // remove from need alive mask effect that have alive target
1339 // is all effects from m_needAliveTargetMask have alive targets
1340 return needAliveTargetMask
== 0;
1343 // Helper for Chain Healing
1344 // Spell target first
1345 // Raidmates then descending by injury suffered (MaxHealth - Health)
1346 // Other players/mobs then descending by injury suffered (MaxHealth - Health)
1347 struct ChainHealingOrder
: public std::binary_function
<const Unit
*, const Unit
*, bool>
1349 const Unit
* MainTarget
;
1350 ChainHealingOrder(Unit
const* Target
) : MainTarget(Target
) {};
1351 // functor for operator ">"
1352 bool operator()(Unit
const* _Left
, Unit
const* _Right
) const
1354 return (ChainHealingHash(_Left
) < ChainHealingHash(_Right
));
1356 int32
ChainHealingHash(Unit
const* Target
) const
1358 if (Target
== MainTarget
)
1360 else if (Target
->GetTypeId() == TYPEID_PLAYER
&& MainTarget
->GetTypeId() == TYPEID_PLAYER
&&
1361 ((Player
const*)Target
)->IsInSameRaidWith((Player
const*)MainTarget
))
1363 if (Target
->GetHealth() == Target
->GetMaxHealth())
1366 return 20000 - Target
->GetMaxHealth() + Target
->GetHealth();
1369 return 40000 - Target
->GetMaxHealth() + Target
->GetHealth();
1373 class ChainHealingFullHealth
: std::unary_function
<const Unit
*, bool>
1376 const Unit
* MainTarget
;
1377 ChainHealingFullHealth(const Unit
* Target
) : MainTarget(Target
) {};
1379 bool operator()(const Unit
* Target
)
1381 return (Target
!= MainTarget
&& Target
->GetHealth() == Target
->GetMaxHealth());
1385 // Helper for targets nearest to the spell target
1386 // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
1387 struct TargetDistanceOrder
: public std::binary_function
<const Unit
, const Unit
, bool>
1389 const Unit
* MainTarget
;
1390 TargetDistanceOrder(const Unit
* Target
) : MainTarget(Target
) {};
1391 // functor for operator ">"
1392 bool operator()(const Unit
* _Left
, const Unit
* _Right
) const
1394 return MainTarget
->GetDistanceOrder(_Left
,_Right
);
1398 void Spell::SetTargetMap(uint32 i
,uint32 cur
,UnitList
& TagUnitMap
)
1401 if (m_spellInfo
->EffectRadiusIndex
[i
])
1402 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
1404 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
));
1406 if(m_originalCaster
)
1407 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1408 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RADIUS
, radius
, this);
1410 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[i
];
1411 if(m_originalCaster
)
1412 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1413 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
1415 // Get spell max affected targets
1416 uint32 unMaxTargets
= m_spellInfo
->MaxAffectedTargets
;
1418 // custom target amount cases
1419 switch(m_spellInfo
->SpellFamilyName
)
1421 case SPELLFAMILY_DRUID
:
1423 if (m_spellInfo
->SpellFamilyFlags2
& UI64LIT(0x00000100))
1430 Unit::AuraList
const& mod
= m_caster
->GetAurasByType(SPELL_AURA_MOD_MAX_AFFECTED_TARGETS
);
1431 for(Unit::AuraList::const_iterator m
= mod
.begin(); m
!= mod
.end(); ++m
)
1433 if (!(*m
)->isAffectedOnSpell(m_spellInfo
))
1435 unMaxTargets
+=(*m
)->GetModifier()->m_amount
;
1440 case TARGET_TOTEM_EARTH
:
1441 case TARGET_TOTEM_WATER
:
1442 case TARGET_TOTEM_AIR
:
1443 case TARGET_TOTEM_FIRE
:
1446 case TARGET_DYNAMIC_OBJECT
:
1447 case TARGET_AREAEFFECT_CUSTOM
:
1448 case TARGET_AREAEFFECT_CUSTOM_2
:
1450 TagUnitMap
.push_back(m_caster
);
1452 case TARGET_RANDOM_ENEMY_CHAIN_IN_AREA
:
1454 m_targets
.m_targetMask
= 0;
1455 unMaxTargets
= EffectChainTarget
;
1456 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1458 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1460 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1463 std::list
<Unit
*> tempUnitMap
;
1466 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1467 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1469 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1470 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1472 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1473 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1474 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1477 if(tempUnitMap
.empty())
1480 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1482 //Now to get us a random target that's in the initial range of the spell
1484 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1485 while(itr
!= tempUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
,radius
))
1491 itr
= tempUnitMap
.begin();
1492 std::advance(itr
, rand()%t
);
1493 Unit
*pUnitTarget
= *itr
;
1494 TagUnitMap
.push_back(pUnitTarget
);
1496 tempUnitMap
.erase(itr
);
1498 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1500 t
= unMaxTargets
- 1;
1501 Unit
*prev
= pUnitTarget
;
1502 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1504 while(t
&& next
!= tempUnitMap
.end() )
1506 if(!prev
->IsWithinDist(*next
,CHAIN_SPELL_JUMP_RADIUS
))
1509 if(!prev
->IsWithinLOSInMap(*next
))
1516 TagUnitMap
.push_back(prev
);
1517 tempUnitMap
.erase(next
);
1518 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1519 next
= tempUnitMap
.begin();
1525 case TARGET_RANDOM_FRIEND_CHAIN_IN_AREA
:
1527 m_targets
.m_targetMask
= 0;
1528 unMaxTargets
= EffectChainTarget
;
1529 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1530 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1532 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1534 std::list
<Unit
*> tempUnitMap
;
1536 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1537 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1539 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1540 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1542 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1543 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1544 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1547 if(tempUnitMap
.empty())
1550 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1552 //Now to get us a random target that's in the initial range of the spell
1554 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1555 while(itr
!= tempUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
,radius
))
1561 itr
= tempUnitMap
.begin();
1562 std::advance(itr
, rand()%t
);
1563 Unit
*pUnitTarget
= *itr
;
1564 TagUnitMap
.push_back(pUnitTarget
);
1566 tempUnitMap
.erase(itr
);
1568 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1570 t
= unMaxTargets
- 1;
1571 Unit
*prev
= pUnitTarget
;
1572 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1574 while(t
&& next
!= tempUnitMap
.end() )
1576 if(!prev
->IsWithinDist(*next
,CHAIN_SPELL_JUMP_RADIUS
))
1579 if(!prev
->IsWithinLOSInMap(*next
))
1585 TagUnitMap
.push_back(prev
);
1586 tempUnitMap
.erase(next
);
1587 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1588 next
= tempUnitMap
.begin();
1595 Pet
* tmpUnit
= m_caster
->GetPet();
1596 if (!tmpUnit
) break;
1597 TagUnitMap
.push_back(tmpUnit
);
1600 case TARGET_CHAIN_DAMAGE
:
1602 if (EffectChainTarget
<= 1)
1604 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1606 m_targets
.setUnitTarget(pUnitTarget
);
1607 TagUnitMap
.push_back(pUnitTarget
);
1612 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1613 Unit
* originalCaster
= GetOriginalCaster();
1614 if(!pUnitTarget
|| !originalCaster
)
1617 unMaxTargets
= EffectChainTarget
;
1620 if(m_spellInfo
->DmgClass
==SPELL_DAMAGE_CLASS_MELEE
)
1621 max_range
= radius
; //
1623 //FIXME: This very like horrible hack and wrong for most spells
1624 max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1626 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1628 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1631 std::list
<Unit
*> tempUnitMap
;
1633 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(pUnitTarget
, originalCaster
, max_range
, false);
1634 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempUnitMap
, u_check
);
1635 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1636 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1637 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1639 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *m_caster
->GetMap());
1640 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *m_caster
->GetMap());
1642 if (tempUnitMap
.empty())
1645 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1647 if (*tempUnitMap
.begin() == pUnitTarget
)
1648 tempUnitMap
.erase (tempUnitMap
.begin());
1650 TagUnitMap
.push_back(pUnitTarget
);
1651 uint32 t
= unMaxTargets
- 1;
1652 Unit
*prev
= pUnitTarget
;
1653 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1655 while (t
&& next
!= tempUnitMap
.end())
1657 if (!prev
->IsWithinDist (*next
,CHAIN_SPELL_JUMP_RADIUS
))
1659 if (!prev
->IsWithinLOSInMap (*next
))
1665 TagUnitMap
.push_back(prev
);
1666 tempUnitMap
.erase(next
);
1667 tempUnitMap
.sort (TargetDistanceOrder(prev
));
1668 next
= tempUnitMap
.begin();
1674 case TARGET_ALL_ENEMY_IN_AREA
:
1675 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1677 case TARGET_AREAEFFECT_INSTANT
:
1679 SpellTargets targetB
= SPELL_TARGETS_AOE_DAMAGE
;
1680 // Select friendly targets for positive effect
1681 if (IsPositiveEffect(m_spellInfo
->Id
, i
))
1682 targetB
= SPELL_TARGETS_FRIENDLY
;
1684 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),radius
, PUSH_DEST_CENTER
, targetB
);
1687 TagUnitMap
.remove(m_caster
);
1690 case TARGET_ALL_ENEMY_IN_AREA_INSTANT
:
1692 // targets the ground, not the units in the area
1693 switch(m_spellInfo
->Effect
[i
])
1695 case SPELL_EFFECT_PERSISTENT_AREA_AURA
:
1697 case SPELL_EFFECT_SUMMON
:
1698 TagUnitMap
.push_back(m_caster
);
1701 FillAreaTargets(TagUnitMap
,m_targets
.m_destX
, m_targets
.m_destY
,radius
,PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1703 // exclude caster (this can be important if this not original caster)
1704 TagUnitMap
.remove(m_caster
);
1709 case TARGET_DUELVSPLAYER_COORDINATES
:
1711 if(Unit
* currentTarget
= m_targets
.getUnitTarget())
1713 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1714 TagUnitMap
.push_back(currentTarget
);
1718 case TARGET_ALL_PARTY_AROUND_CASTER
:
1719 case TARGET_ALL_PARTY_AROUND_CASTER_2
:
1720 case TARGET_ALL_PARTY
:
1721 FillRaidOrPartyTargets(TagUnitMap
, m_caster
, m_caster
, radius
, false, true, true);
1723 case TARGET_ALL_RAID_AROUND_CASTER
:
1725 if(m_spellInfo
->Id
== 57669) // Replenishment (special target selection)
1726 FillRaidOrPartyManaPriorityTargets(TagUnitMap
, m_caster
, m_caster
, radius
, 10, true, false, true);
1727 else if (m_spellInfo
->Id
==52759) // Ancestral Awakening (special target selection)
1728 FillRaidOrPartyHealthPriorityTargets(TagUnitMap
, m_caster
, m_caster
, radius
, 1, true, false, true);
1730 FillRaidOrPartyTargets(TagUnitMap
, m_caster
, m_caster
, radius
, true, true, true);
1733 case TARGET_SINGLE_FRIEND
:
1734 case TARGET_SINGLE_FRIEND_2
:
1735 if(m_targets
.getUnitTarget())
1736 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1738 case TARGET_NONCOMBAT_PET
:
1739 if(Unit
* target
= m_targets
.getUnitTarget())
1740 if( target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet() && ((Pet
*)target
)->getPetType() == MINI_PET
)
1741 TagUnitMap
.push_back(target
);
1743 case TARGET_CASTER_COORDINATES
:
1745 // Check original caster is GO - set its coordinates as dst cast
1746 WorldObject
*caster
= NULL
;
1747 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
1748 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
1751 // Set dest for targets
1752 m_targets
.setDestination(caster
->GetPositionX(), caster
->GetPositionY(), caster
->GetPositionZ());
1755 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER
:
1756 // special target order
1757 if (m_spellInfo
->Id
==64904) // Hymn of Hope
1758 // target amount stored in parent spell dummy effect but hard for access
1759 FillRaidOrPartyManaPriorityTargets(TagUnitMap
, m_caster
, m_caster
, radius
, 3, true, false, false);
1761 FillAreaTargets(TagUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
1763 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA
:
1765 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_DRUID
&& m_spellInfo
->SpellIconID
== 2864)
1767 Unit
* target
= m_targets
.getUnitTarget();
1770 uint32 count
= CalculateDamage(2,m_caster
); // stored in dummy effect, affected by mods
1772 FillRaidOrPartyHealthPriorityTargets(TagUnitMap
, m_caster
, target
, radius
, count
, true, false, true);
1775 FillAreaTargets(TagUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_FRIENDLY
);
1777 // 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..)
1778 case TARGET_SINGLE_PARTY
:
1780 Unit
*target
= m_targets
.getUnitTarget();
1781 // Thoses spells apparently can't be casted on the caster.
1782 if( target
&& target
!= m_caster
)
1784 // Can only be casted on group's members or its pets
1785 Group
*pGroup
= NULL
;
1787 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1788 Unit
*targetOwner
= target
->GetCharmerOrOwner();
1791 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1793 if( target
== owner
)
1795 TagUnitMap
.push_back(target
);
1798 pGroup
= ((Player
*)owner
)->GetGroup();
1801 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1803 if( targetOwner
== m_caster
&& target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet())
1805 TagUnitMap
.push_back(target
);
1808 pGroup
= ((Player
*)m_caster
)->GetGroup();
1813 // Our target can also be a player's pet who's grouped with us or our pet. But can't be controlled player
1816 if( targetOwner
->GetTypeId() == TYPEID_PLAYER
&&
1817 target
->GetTypeId() == TYPEID_UNIT
&& (((Creature
*)target
)->isPet()) &&
1818 target
->GetOwnerGUID() == targetOwner
->GetGUID() &&
1819 pGroup
->IsMember(((Player
*)targetOwner
)->GetGUID()))
1821 TagUnitMap
.push_back(target
);
1824 // 1Our target can be a player who is on our group
1825 else if (target
->GetTypeId() == TYPEID_PLAYER
&& pGroup
->IsMember(((Player
*)target
)->GetGUID()))
1827 TagUnitMap
.push_back(target
);
1833 case TARGET_GAMEOBJECT
:
1834 if(m_targets
.getGOTarget())
1835 AddGOTarget(m_targets
.getGOTarget(), i
);
1837 case TARGET_IN_FRONT_OF_CASTER
:
1839 bool inFront
= m_spellInfo
->SpellVisual
[0] != 3879;
1840 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(),radius
,inFront
? PUSH_IN_FRONT
: PUSH_IN_BACK
,SPELL_TARGETS_AOE_DAMAGE
);
1843 case TARGET_IN_FRONT_OF_CASTER_30
:
1844 FillAreaTargets(TagUnitMap
,m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_30
, SPELL_TARGETS_AOE_DAMAGE
);
1846 case TARGET_DUELVSPLAYER
:
1848 Unit
*target
= m_targets
.getUnitTarget();
1851 if(m_caster
->IsFriendlyTo(target
))
1853 TagUnitMap
.push_back(target
);
1857 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1859 m_targets
.setUnitTarget(pUnitTarget
);
1860 TagUnitMap
.push_back(pUnitTarget
);
1866 case TARGET_GAMEOBJECT_ITEM
:
1867 if(m_targets
.getGOTargetGUID())
1868 AddGOTarget(m_targets
.getGOTarget(), i
);
1869 else if(m_targets
.getItemTarget())
1870 AddItemTarget(m_targets
.getItemTarget(), i
);
1873 if(Unit
* owner
= m_caster
->GetCharmerOrOwner())
1874 TagUnitMap
.push_back(owner
);
1876 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED
:
1877 // targets the ground, not the units in the area
1878 if (m_spellInfo
->Effect
[i
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1879 FillAreaTargets(TagUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1882 if(m_spellInfo
->Effect
[i
] != SPELL_EFFECT_DUEL
)
1883 TagUnitMap
.push_back(m_caster
);
1885 case TARGET_SINGLE_ENEMY
:
1887 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1889 m_targets
.setUnitTarget(pUnitTarget
);
1890 TagUnitMap
.push_back(pUnitTarget
);
1894 case TARGET_AREAEFFECT_PARTY
:
1896 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1897 Player
*pTarget
= NULL
;
1901 TagUnitMap
.push_back(m_caster
);
1902 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1903 pTarget
= (Player
*)owner
;
1905 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1907 if(Unit
* target
= m_targets
.getUnitTarget())
1909 if( target
->GetTypeId() != TYPEID_PLAYER
)
1911 if(((Creature
*)target
)->isPet())
1913 Unit
*targetOwner
= target
->GetOwner();
1914 if(targetOwner
->GetTypeId() == TYPEID_PLAYER
)
1915 pTarget
= (Player
*)targetOwner
;
1919 pTarget
= (Player
*)target
;
1923 Group
* pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1927 uint8 subgroup
= pTarget
->GetSubGroup();
1929 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1931 Player
* Target
= itr
->getSource();
1933 // IsHostileTo check duel and controlled by enemy
1934 if(Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
))
1936 if( pTarget
->IsWithinDistInMap(Target
, radius
) )
1937 TagUnitMap
.push_back(Target
);
1939 if(Pet
* pet
= Target
->GetPet())
1940 if( pTarget
->IsWithinDistInMap(pet
, radius
) )
1941 TagUnitMap
.push_back(pet
);
1947 if(m_caster
->IsWithinDistInMap(owner
, radius
))
1948 TagUnitMap
.push_back(owner
);
1952 TagUnitMap
.push_back(pTarget
);
1954 if(Pet
* pet
= pTarget
->GetPet())
1955 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1956 TagUnitMap
.push_back(pet
);
1962 if(m_targets
.getUnitTarget())
1963 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1964 if(m_targets
.getItemTarget())
1965 AddItemTarget(m_targets
.getItemTarget(), i
);
1968 case TARGET_SELF_FISHING
:
1969 TagUnitMap
.push_back(m_caster
);
1971 case TARGET_CHAIN_HEAL
:
1973 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1977 if (EffectChainTarget
<= 1)
1978 TagUnitMap
.push_back(pUnitTarget
);
1981 unMaxTargets
= EffectChainTarget
;
1982 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1984 UnitList tempUnitMap
;
1986 FillAreaTargets(tempUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), max_range
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
1988 if(m_caster
!= pUnitTarget
&& std::find(tempUnitMap
.begin(),tempUnitMap
.end(), m_caster
) == tempUnitMap
.end() )
1989 tempUnitMap
.push_front(m_caster
);
1991 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1993 if(tempUnitMap
.empty())
1996 if(*tempUnitMap
.begin() == pUnitTarget
)
1997 tempUnitMap
.erase(tempUnitMap
.begin());
1999 TagUnitMap
.push_back(pUnitTarget
);
2000 uint32 t
= unMaxTargets
- 1;
2001 Unit
*prev
= pUnitTarget
;
2002 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
2004 while(t
&& next
!= tempUnitMap
.end() )
2006 if(!prev
->IsWithinDist(*next
, CHAIN_SPELL_JUMP_RADIUS
))
2009 if(!prev
->IsWithinLOSInMap(*next
))
2015 if((*next
)->GetHealth() == (*next
)->GetMaxHealth())
2017 next
= tempUnitMap
.erase(next
);
2022 TagUnitMap
.push_back(prev
);
2023 tempUnitMap
.erase(next
);
2024 tempUnitMap
.sort(TargetDistanceOrder(prev
));
2025 next
= tempUnitMap
.begin();
2032 case TARGET_CURRENT_ENEMY_COORDINATES
:
2034 Unit
* currentTarget
= m_targets
.getUnitTarget();
2037 TagUnitMap
.push_back(currentTarget
);
2038 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
2039 if(m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_ALL_ENEMY_IN_AREA_INSTANT
)
2040 FillAreaTargets(TagUnitMap
, currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), radius
, PUSH_TARGET_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
2044 case TARGET_AREAEFFECT_PARTY_AND_CLASS
:
2046 Player
* targetPlayer
= m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
2047 ? (Player
*)m_targets
.getUnitTarget() : NULL
;
2049 Group
* pGroup
= targetPlayer
? targetPlayer
->GetGroup() : NULL
;
2052 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2054 Player
* Target
= itr
->getSource();
2056 // IsHostileTo check duel and controlled by enemy
2057 if( Target
&& targetPlayer
->IsWithinDistInMap(Target
, radius
) &&
2058 targetPlayer
->getClass() == Target
->getClass() &&
2059 !m_caster
->IsHostileTo(Target
) )
2061 TagUnitMap
.push_back(Target
);
2065 else if(m_targets
.getUnitTarget())
2066 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2069 case TARGET_TABLE_X_Y_Z_COORDINATES
:
2071 SpellTargetPosition
const* st
= spellmgr
.GetSpellTargetPosition(m_spellInfo
->Id
);
2074 if (st
->target_mapId
== m_caster
->GetMapId())
2075 m_targets
.setDestination(st
->target_X
, st
->target_Y
, st
->target_Z
);
2077 sLog
.outError( "SPELL: wrong map (%u instead %u) target coordinates for spell ID %u", st
->target_mapId
, m_caster
->GetMapId(), m_spellInfo
->Id
);
2080 sLog
.outError( "SPELL: unknown target coordinates for spell ID %u", m_spellInfo
->Id
);
2083 case TARGET_BEHIND_VICTIM
:
2085 Unit
*pTarget
= NULL
;
2087 // explicit cast data from client or server-side cast
2088 // some spell at client send caster
2089 if(m_targets
.getUnitTarget() && m_targets
.getUnitTarget()!=m_caster
)
2090 pTarget
= m_targets
.getUnitTarget();
2091 else if(m_caster
->getVictim())
2092 pTarget
= m_caster
->getVictim();
2093 else if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
2094 pTarget
= ObjectAccessor::GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection());
2098 float _target_x
, _target_y
, _target_z
;
2099 pTarget
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), CONTACT_DISTANCE
, M_PI
);
2100 if(pTarget
->IsWithinLOS(_target_x
, _target_y
, _target_z
))
2102 TagUnitMap
.push_back(m_caster
);
2103 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2108 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
2109 // if parent spell create dynamic object extract area from it
2110 if(DynamicObject
* dynObj
= m_caster
->GetDynObject(m_triggeredByAuraSpell
? m_triggeredByAuraSpell
->Id
: m_spellInfo
->Id
))
2111 m_targets
.setDestination(dynObj
->GetPositionX(), dynObj
->GetPositionY(), dynObj
->GetPositionZ());
2113 case TARGET_POINT_AT_NORTH
:
2114 case TARGET_POINT_AT_SOUTH
:
2115 case TARGET_POINT_AT_EAST
:
2116 case TARGET_POINT_AT_WEST
:
2117 case TARGET_POINT_AT_NE
:
2118 case TARGET_POINT_AT_NW
:
2119 case TARGET_POINT_AT_SE
:
2120 case TARGET_POINT_AT_SW
:
2123 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2125 Unit
* currentTarget
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
2126 float angle
= currentTarget
!= m_caster
? currentTarget
->GetAngle(m_caster
) : m_caster
->GetOrientation();
2130 case TARGET_POINT_AT_NORTH
: break;
2131 case TARGET_POINT_AT_SOUTH
: angle
+= M_PI
; break;
2132 case TARGET_POINT_AT_EAST
: angle
-= M_PI
/2; break;
2133 case TARGET_POINT_AT_WEST
: angle
+= M_PI
/2; break;
2134 case TARGET_POINT_AT_NE
: angle
-= M_PI
/4; break;
2135 case TARGET_POINT_AT_NW
: angle
+= M_PI
/4; break;
2136 case TARGET_POINT_AT_SE
: angle
-= 3*M_PI
/4; break;
2137 case TARGET_POINT_AT_SW
: angle
+= 3*M_PI
/4; break;
2141 currentTarget
->GetNearPoint2D(x
,y
,radius
,angle
);
2142 m_targets
.setDestination(x
,y
,currentTarget
->GetPositionZ());
2146 case TARGET_DIRECTLY_FORWARD
:
2148 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2150 SpellRangeEntry
const* rEntry
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
2151 float minRange
= GetSpellMinRange(rEntry
);
2152 float maxRange
= GetSpellMaxRange(rEntry
);
2153 float dist
= minRange
+ rand_norm()*(maxRange
-minRange
);
2155 float _target_x
, _target_y
, _target_z
;
2156 m_caster
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), dist
);
2157 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2160 TagUnitMap
.push_back(m_caster
);
2167 if (unMaxTargets
&& TagUnitMap
.size() > unMaxTargets
)
2169 // make sure one unit is always removed per iteration
2170 uint32 removed_utarget
= 0;
2171 for (UnitList::iterator itr
= TagUnitMap
.begin(), next
; itr
!= TagUnitMap
.end(); itr
= next
)
2175 if (!*itr
) continue;
2176 if ((*itr
) == m_targets
.getUnitTarget())
2178 TagUnitMap
.erase(itr
);
2179 removed_utarget
= 1;
2183 // remove random units from the map
2184 while (TagUnitMap
.size() > unMaxTargets
- removed_utarget
)
2186 uint32 poz
= urand(0, TagUnitMap
.size()-1);
2187 for (UnitList::iterator itr
= TagUnitMap
.begin(); itr
!= TagUnitMap
.end(); ++itr
, --poz
)
2189 if (!*itr
) continue;
2193 TagUnitMap
.erase(itr
);
2198 // the player's target will always be added to the map
2199 if (removed_utarget
&& m_targets
.getUnitTarget())
2200 TagUnitMap
.push_back(m_targets
.getUnitTarget());
2204 void Spell::prepare(SpellCastTargets
const* targets
, Aura
* triggeredByAura
)
2206 m_targets
= *targets
;
2208 m_spellState
= SPELL_STATE_PREPARING
;
2210 m_castPositionX
= m_caster
->GetPositionX();
2211 m_castPositionY
= m_caster
->GetPositionY();
2212 m_castPositionZ
= m_caster
->GetPositionZ();
2213 m_castOrientation
= m_caster
->GetOrientation();
2216 m_triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
2218 // create and add update event for this spell
2219 SpellEvent
* Event
= new SpellEvent(this);
2220 m_caster
->m_Events
.AddEvent(Event
, m_caster
->m_Events
.CalculateTime(1));
2222 //Prevent casting at cast another spell (ServerSide check)
2223 if(m_caster
->IsNonMeleeSpellCasted(false, true, true) && m_cast_count
)
2225 SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS
);
2231 m_powerCost
= CalculatePowerCost();
2233 SpellCastResult result
= CheckCast(true);
2234 if(result
!= SPELL_CAST_OK
&& !IsAutoRepeat()) //always cast autorepeat dummy for triggering
2238 SendChannelUpdate(0);
2239 triggeredByAura
->SetAuraDuration(0);
2241 SendCastResult(result
);
2246 // Prepare data for triggers
2247 prepareDataForTriggerSystem();
2249 // calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
2250 m_casttime
= GetSpellCastTime(m_spellInfo
, this);
2252 // set timer base at cast time
2255 // stealth must be removed at cast starting (at show channel bar)
2256 // skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
2257 if ( !m_IsTriggeredSpell
&& isSpellBreakStealth(m_spellInfo
) )
2259 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
2260 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
2263 if(m_IsTriggeredSpell
)
2267 m_caster
->SetCurrentCastedSpell( this );
2272 void Spell::cancel()
2274 if(m_spellState
== SPELL_STATE_FINISHED
)
2277 m_autoRepeat
= false;
2278 switch (m_spellState
)
2280 case SPELL_STATE_PREPARING
:
2281 case SPELL_STATE_DELAYED
:
2284 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2287 case SPELL_STATE_CASTING
:
2289 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2291 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2293 Unit
* unit
= m_caster
->GetGUID()==(*ihit
).targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2294 if( unit
&& unit
->isAlive() )
2295 unit
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2299 m_caster
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2300 SendChannelUpdate(0);
2302 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2311 m_caster
->RemoveDynObject(m_spellInfo
->Id
);
2312 m_caster
->RemoveGameObject(m_spellInfo
->Id
,true);
2315 void Spell::cast(bool skipCheck
)
2317 SetExecutedCurrently(true);
2319 // update pointers base at GUIDs to prevent access to non-existed already object
2322 // cancel at lost main target unit
2323 if(!m_targets
.getUnitTarget() && m_targets
.getUnitTargetGUID() && m_targets
.getUnitTargetGUID() != m_caster
->GetGUID())
2326 SetExecutedCurrently(false);
2330 if(m_caster
->GetTypeId() != TYPEID_PLAYER
&& m_targets
.getUnitTarget() && m_targets
.getUnitTarget() != m_caster
)
2331 m_caster
->SetInFront(m_targets
.getUnitTarget());
2333 SpellCastResult castResult
= CheckPower();
2334 if(castResult
!= SPELL_CAST_OK
)
2336 SendCastResult(castResult
);
2338 SetExecutedCurrently(false);
2342 // triggered cast called from Spell::prepare where it was already checked
2345 castResult
= CheckCast(false);
2346 if(castResult
!= SPELL_CAST_OK
)
2348 SendCastResult(castResult
);
2350 SetExecutedCurrently(false);
2355 // different triggred (for caster) and precast (casted before apply effect to target) cases
2356 switch(m_spellInfo
->SpellFamilyName
)
2358 case SPELLFAMILY_GENERIC
:
2360 if (m_spellInfo
->Mechanic
== MECHANIC_BANDAGE
) // Bandages
2361 AddPrecastSpell(11196); // Recently Bandaged
2362 else if(m_spellInfo
->SpellIconID
== 1662 && m_spellInfo
->AttributesEx
& 0x20)
2363 // Blood Fury (Racial)
2364 AddPrecastSpell(23230); // Blood Fury - Healing Reduction
2367 case SPELLFAMILY_MAGE
:
2370 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000008000000000))
2371 AddPrecastSpell(41425); // Hypothermia
2374 case SPELLFAMILY_PRIEST
:
2376 // Power Word: Shield
2377 if (m_spellInfo
->Mechanic
== MECHANIC_SHIELD
&&
2378 (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000001)))
2379 AddPrecastSpell(6788); // Weakened Soul
2380 // Prayer of Mending (jump animation), we need formal caster instead original for correct animation
2381 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000002000000000))
2382 AddTriggeredSpell(41637);
2384 switch(m_spellInfo
->Id
)
2386 case 47585: AddPrecastSpell(60069); break; // Dispersion (transform)
2387 case 15237: AddTriggeredSpell(23455); break;// Holy Nova, rank 1
2388 case 15430: AddTriggeredSpell(23458); break;// Holy Nova, rank 2
2389 case 15431: AddTriggeredSpell(23459); break;// Holy Nova, rank 3
2390 case 27799: AddTriggeredSpell(27803); break;// Holy Nova, rank 4
2391 case 27800: AddTriggeredSpell(27804); break;// Holy Nova, rank 5
2392 case 27801: AddTriggeredSpell(27805); break;// Holy Nova, rank 6
2393 case 25331: AddTriggeredSpell(25329); break;// Holy Nova, rank 7
2394 case 48077: AddTriggeredSpell(48075); break;// Holy Nova, rank 8
2395 case 48078: AddTriggeredSpell(48076); break;// Holy Nova, rank 9
2400 case SPELLFAMILY_ROGUE
:
2401 // Fan of Knives (main hand)
2402 if (m_spellInfo
->Id
== 51723 && m_caster
->GetTypeId() == TYPEID_PLAYER
&&
2403 ((Player
*)m_caster
)->haveOffhandWeapon())
2405 AddTriggeredSpell(52874); // Fan of Knives (offhand)
2408 case SPELLFAMILY_PALADIN
:
2410 // Divine Shield, Divine Protection or Hand of Protection
2411 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000400080))
2413 AddPrecastSpell(25771); // Forbearance
2414 AddPrecastSpell(61987); // Avenging Wrath Marker
2416 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x200000000000))
2417 AddPrecastSpell(61987); // Avenging Wrath Marker
2420 case SPELLFAMILY_SHAMAN
:
2423 if (m_spellInfo
->Id
== 2825)
2424 AddPrecastSpell(57724); // Sated
2426 else if (m_spellInfo
->Id
== 32182)
2427 AddPrecastSpell(57723); // Exhaustion
2434 // traded items have trade slot instead of guid in m_itemTargetGUID
2435 // set to real guid to be sent later to the client
2436 m_targets
.updateTradeSlotItem();
2438 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2440 if (!m_IsTriggeredSpell
&& m_CastItem
)
2441 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM
, m_CastItem
->GetEntry());
2443 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL
, m_spellInfo
->Id
);
2448 if(m_spellState
== SPELL_STATE_FINISHED
) // stop cast if spell marked as finish somewhere in FillTargetMap
2450 SetExecutedCurrently(false);
2455 SendSpellCooldown();
2458 TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
2460 SendCastResult(castResult
);
2461 SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2463 // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2464 if (m_spellInfo
->speed
> 0.0f
)
2467 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2468 // in case delayed spell remove item at cast delay start
2471 // Okay, maps created, now prepare flags
2472 m_immediateHandled
= false;
2473 m_spellState
= SPELL_STATE_DELAYED
;
2478 // Immediate spell, no big deal
2482 SetExecutedCurrently(false);
2485 void Spell::handle_immediate()
2487 // start channeling if applicable
2488 if(IsChanneledSpell(m_spellInfo
))
2490 int32 duration
= GetSpellDuration(m_spellInfo
);
2493 // Apply duration mod
2494 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
2495 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_DURATION
, duration
);
2496 m_spellState
= SPELL_STATE_CASTING
;
2497 SendChannelStart(duration
);
2501 // process immediate effects (items, ground, etc.) also initialize some variables
2502 _handle_immediate_phase();
2504 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2505 DoAllEffectOnTarget(&(*ihit
));
2507 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2508 DoAllEffectOnTarget(&(*ihit
));
2510 // spell is finished, perform some last features of the spell here
2511 _handle_finish_phase();
2513 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2516 if(m_spellState
!= SPELL_STATE_CASTING
)
2517 finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell)
2520 uint64
Spell::handle_delayed(uint64 t_offset
)
2522 uint64 next_time
= 0;
2524 if (!m_immediateHandled
)
2526 _handle_immediate_phase();
2527 m_immediateHandled
= true;
2530 // 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)
2531 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2533 if (ihit
->processed
== false)
2535 if ( ihit
->timeDelay
<= t_offset
)
2536 DoAllEffectOnTarget(&(*ihit
));
2537 else if( next_time
== 0 || ihit
->timeDelay
< next_time
)
2538 next_time
= ihit
->timeDelay
;
2542 // now recheck gameobject targeting correctness
2543 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
2545 if (ighit
->processed
== false)
2547 if ( ighit
->timeDelay
<= t_offset
)
2548 DoAllEffectOnTarget(&(*ighit
));
2549 else if( next_time
== 0 || ighit
->timeDelay
< next_time
)
2550 next_time
= ighit
->timeDelay
;
2553 // All targets passed - need finish phase
2556 // spell is finished, perform some last features of the spell here
2557 _handle_finish_phase();
2559 finish(true); // successfully finish spell cast
2561 // return zero, spell is finished now
2566 // spell is unfinished, return next execution time
2571 void Spell::_handle_immediate_phase()
2573 // handle some immediate features of the spell here
2574 HandleThreatSpells(m_spellInfo
->Id
);
2576 m_needSpellLog
= IsNeedSendToClient();
2577 for(uint32 j
= 0; j
< 3; ++j
)
2579 if(m_spellInfo
->Effect
[j
] == 0)
2582 // apply Send Event effect to ground in case empty target lists
2583 if( m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
&& !HaveTargetsForEffect(j
) )
2585 HandleEffects(NULL
, NULL
, NULL
, j
);
2589 // Don't do spell log, if is school damage spell
2590 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
|| m_spellInfo
->Effect
[j
] == 0)
2591 m_needSpellLog
= false;
2593 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[j
];
2594 if(m_originalCaster
)
2595 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
2596 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
2598 // initialize multipliers
2599 m_damageMultipliers
[j
] = 1.0f
;
2600 if( (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_HEAL
) &&
2601 (EffectChainTarget
> 1) )
2602 m_applyMultiplierMask
|= 1 << j
;
2605 // initialize Diminishing Returns Data
2606 m_diminishLevel
= DIMINISHING_LEVEL_1
;
2607 m_diminishGroup
= DIMINISHING_NONE
;
2610 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
2611 DoAllEffectOnTarget(&(*ihit
));
2614 for(uint32 j
= 0; j
< 3; ++j
)
2616 // persistent area auras target only the ground
2617 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2618 HandleEffects(NULL
, NULL
, NULL
, j
);
2622 void Spell::_handle_finish_phase()
2629 void Spell::SendSpellCooldown()
2631 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
2634 Player
* _player
= (Player
*)m_caster
;
2636 // mana/health/etc potions, disabled by client (until combat out as declarate)
2637 if (m_CastItem
&& m_CastItem
->IsPotion())
2639 // need in some way provided data for Spell::finish SendCooldownEvent
2640 _player
->SetLastPotionId(m_CastItem
->GetEntry());
2644 // have infinity cooldown but set at aura apply
2645 if(m_spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
2648 _player
->AddSpellAndCategoryCooldowns(m_spellInfo
,m_CastItem
? m_CastItem
->GetEntry() : 0, this);
2651 void Spell::update(uint32 difftime
)
2653 // update pointers based at it's GUIDs
2656 if(m_targets
.getUnitTargetGUID() && !m_targets
.getUnitTarget())
2662 // check if the player caster has moved before the spell finished
2663 if ((m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_timer
!= 0) &&
2664 (m_castPositionX
!= m_caster
->GetPositionX() || m_castPositionY
!= m_caster
->GetPositionY() || m_castPositionZ
!= m_caster
->GetPositionZ()) &&
2665 (m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
|| !((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEMENTFLAG_FALLING
)))
2667 // always cancel for channeled spells
2668 if( m_spellState
== SPELL_STATE_CASTING
)
2670 // don't cancel for melee, autorepeat, triggered and instant spells
2671 else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_MOVEMENT
))
2675 switch(m_spellState
)
2677 case SPELL_STATE_PREPARING
:
2681 if(difftime
>= m_timer
)
2684 m_timer
-= difftime
;
2687 if(m_timer
== 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat())
2690 case SPELL_STATE_CASTING
:
2694 if( m_caster
->GetTypeId() == TYPEID_PLAYER
)
2696 // check if player has jumped before the channeling finished
2697 if(((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEMENTFLAG_JUMPING
))
2700 // check for incapacitating player states
2701 if( m_caster
->hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_CONFUSED
))
2704 // check if player has turned if flag is set
2705 if( m_spellInfo
->ChannelInterruptFlags
& CHANNEL_FLAG_TURNING
&& m_castOrientation
!= m_caster
->GetOrientation() )
2709 // check if there are alive targets left
2710 if (!IsAliveUnitPresentInTargetList())
2712 SendChannelUpdate(0);
2716 if(difftime
>= m_timer
)
2719 m_timer
-= difftime
;
2724 SendChannelUpdate(0);
2726 // channeled spell processed independently for quest targeting
2727 // cast at creature (or GO) quest objectives update at successful cast channel finished
2728 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
2729 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() )
2731 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
2733 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2735 TargetInfo
* target
= &*ihit
;
2736 if(!IS_CREATURE_GUID(target
->targetGUID
))
2739 Unit
* unit
= m_caster
->GetGUID() == target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, target
->targetGUID
);
2743 p
->CastedCreatureOrGO(unit
->GetEntry(), unit
->GetGUID(), m_spellInfo
->Id
);
2746 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
2748 GOTargetInfo
* target
= &*ihit
;
2750 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
2754 p
->CastedCreatureOrGO(go
->GetEntry(), go
->GetGUID(), m_spellInfo
->Id
);
2768 void Spell::finish(bool ok
)
2773 if(m_spellState
== SPELL_STATE_FINISHED
)
2776 m_spellState
= SPELL_STATE_FINISHED
;
2778 // other code related only to successfully finished spells
2783 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2784 ((Player
*)m_caster
)->RemoveSpellMods(this);
2786 // handle SPELL_AURA_ADD_TARGET_TRIGGER auras
2787 Unit::AuraList
const& targetTriggers
= m_caster
->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER
);
2788 for(Unit::AuraList::const_iterator i
= targetTriggers
.begin(); i
!= targetTriggers
.end(); ++i
)
2790 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
2792 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2793 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2795 // check m_caster->GetGUID() let load auras at login and speedup most often case
2796 Unit
*unit
= m_caster
->GetGUID()== ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2797 if (unit
&& unit
->isAlive())
2799 SpellEntry
const *auraSpellInfo
= (*i
)->GetSpellProto();
2800 uint32 auraSpellIdx
= (*i
)->GetEffIndex();
2801 // Calculate chance at that moment (can be depend for example from combo points)
2802 int32 chance
= m_caster
->CalculateSpellDamage(auraSpellInfo
, auraSpellIdx
, (*i
)->GetBasePoints(),unit
);
2803 if(roll_chance_i(chance
))
2804 m_caster
->CastSpell(unit
, auraSpellInfo
->EffectTriggerSpell
[auraSpellIdx
], true, NULL
, (*i
));
2809 // Heal caster for all health leech from all targets
2811 m_caster
->DealHeal(m_caster
, uint32(m_healthLeech
), m_spellInfo
);
2813 if (IsMeleeAttackResetSpell())
2815 m_caster
->resetAttackTimer(BASE_ATTACK
);
2816 if(m_caster
->haveOffhandWeapon())
2817 m_caster
->resetAttackTimer(OFF_ATTACK
);
2820 /*if (IsRangedAttackResetSpell())
2821 m_caster->resetAttackTimer(RANGED_ATTACK);*/
2823 // Clear combo at finish state
2824 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& NeedsComboPoints(m_spellInfo
))
2826 // Not drop combopoints if negative spell and if any miss on enemy exist
2827 bool needDrop
= true;
2828 if (!IsPositiveSpell(m_spellInfo
->Id
))
2830 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2832 if (ihit
->missCondition
!= SPELL_MISS_NONE
&& ihit
->targetGUID
!=m_caster
->GetGUID())
2840 ((Player
*)m_caster
)->ClearComboPoints();
2843 // potions disabled by client, send event "not in combat" if need
2844 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2845 ((Player
*)m_caster
)->UpdatePotionCooldown(this);
2847 // call triggered spell only at successful cast (after clear combo points -> for add some if need)
2848 if(!m_TriggerSpells
.empty())
2849 CastTriggerSpells();
2851 // Stop Attack for some spells
2852 if( m_spellInfo
->Attributes
& SPELL_ATTR_STOP_ATTACK_TARGET
)
2853 m_caster
->AttackStop();
2856 void Spell::SendCastResult(SpellCastResult result
)
2858 if(result
== SPELL_CAST_OK
)
2861 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
2864 if(((Player
*)m_caster
)->GetSession()->PlayerLoading()) // don't send cast results at loading time
2867 SendCastResult((Player
*)m_caster
,m_spellInfo
,m_cast_count
,result
);
2870 void Spell::SendCastResult(Player
* caster
, SpellEntry
const* spellInfo
, uint8 cast_count
, SpellCastResult result
)
2872 if(result
== SPELL_CAST_OK
)
2875 WorldPacket
data(SMSG_CAST_FAILED
, (4+1+1));
2876 data
<< uint8(cast_count
); // single cast or multi 2.3 (0/1)
2877 data
<< uint32(spellInfo
->Id
);
2878 data
<< uint8(result
); // problem
2881 case SPELL_FAILED_REQUIRES_SPELL_FOCUS
:
2882 data
<< uint32(spellInfo
->RequiresSpellFocus
);
2884 case SPELL_FAILED_REQUIRES_AREA
:
2885 // hardcode areas limitation case
2886 switch(spellInfo
->Id
)
2888 case 41617: // Cenarion Mana Salve
2889 case 41619: // Cenarion Healing Salve
2890 data
<< uint32(3905);
2892 case 41618: // Bottled Nethergon Energy
2893 case 41620: // Bottled Nethergon Vapor
2894 data
<< uint32(3842);
2896 case 45373: // Bloodberry Elixir
2897 data
<< uint32(4075);
2899 default: // default case (don't must be)
2904 case SPELL_FAILED_TOTEMS
:
2905 if(spellInfo
->Totem
[0])
2906 data
<< uint32(spellInfo
->Totem
[0]);
2907 if(spellInfo
->Totem
[1])
2908 data
<< uint32(spellInfo
->Totem
[1]);
2910 case SPELL_FAILED_TOTEM_CATEGORY
:
2911 if(spellInfo
->TotemCategory
[0])
2912 data
<< uint32(spellInfo
->TotemCategory
[0]);
2913 if(spellInfo
->TotemCategory
[1])
2914 data
<< uint32(spellInfo
->TotemCategory
[1]);
2916 case SPELL_FAILED_EQUIPPED_ITEM_CLASS
:
2917 data
<< uint32(spellInfo
->EquippedItemClass
);
2918 data
<< uint32(spellInfo
->EquippedItemSubClassMask
);
2919 //data << uint32(spellInfo->EquippedItemInventoryTypeMask);
2924 caster
->GetSession()->SendPacket(&data
);
2927 void Spell::SendSpellStart()
2929 if(!IsNeedSendToClient())
2932 sLog
.outDebug("Sending SMSG_SPELL_START id=%u", m_spellInfo
->Id
);
2934 uint32 castFlags
= CAST_FLAG_UNKNOWN1
;
2936 castFlags
|= CAST_FLAG_AMMO
;
2938 if(m_spellInfo
->runeCostID
)
2939 castFlags
|= CAST_FLAG_UNKNOWN10
;
2941 WorldPacket
data(SMSG_SPELL_START
, (8+8+4+4+2));
2943 data
.append(m_CastItem
->GetPackGUID());
2945 data
.append(m_caster
->GetPackGUID());
2947 data
.append(m_caster
->GetPackGUID());
2948 data
<< uint8(m_cast_count
); // pending spell cast?
2949 data
<< uint32(m_spellInfo
->Id
); // spellId
2950 data
<< uint32(castFlags
); // cast flags
2951 data
<< uint32(m_timer
); // delay?
2953 m_targets
.write(&data
);
2955 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // predicted power?
2958 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
2960 uint8 v1
= 0;//m_runesState;
2961 uint8 v2
= 0;//((Player*)m_caster)->GetRunesState();
2962 data
<< uint8(v1
); // runes state before
2963 data
<< uint8(v2
); // runes state after
2964 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
2967 if(m
& v1
) // usable before...
2968 if(!(m
& v2
)) // ...but on cooldown now...
2969 data
<< uint8(0); // some unknown byte (time?)
2973 if ( castFlags
& CAST_FLAG_AMMO
)
2974 WriteAmmoToPacket(&data
);
2976 m_caster
->SendMessageToSet(&data
, true);
2979 void Spell::SendSpellGo()
2981 // not send invisible spell casting
2982 if(!IsNeedSendToClient())
2985 sLog
.outDebug("Sending SMSG_SPELL_GO id=%u", m_spellInfo
->Id
);
2987 uint32 castFlags
= CAST_FLAG_UNKNOWN3
;
2989 castFlags
|= CAST_FLAG_AMMO
; // arrows/bullets visual
2991 if((m_caster
->GetTypeId() == TYPEID_PLAYER
) && (m_caster
->getClass() == CLASS_DEATH_KNIGHT
) && m_spellInfo
->runeCostID
)
2993 castFlags
|= CAST_FLAG_UNKNOWN10
; // same as in SMSG_SPELL_START
2994 castFlags
|= CAST_FLAG_UNKNOWN6
; // makes cooldowns visible
2995 castFlags
|= CAST_FLAG_UNKNOWN7
; // rune cooldowns list
2998 WorldPacket
data(SMSG_SPELL_GO
, 50); // guess size
3001 data
.append(m_CastItem
->GetPackGUID());
3003 data
.append(m_caster
->GetPackGUID());
3005 data
.append(m_caster
->GetPackGUID());
3006 data
<< uint8(m_cast_count
); // pending spell cast?
3007 data
<< uint32(m_spellInfo
->Id
); // spellId
3008 data
<< uint32(castFlags
); // cast flags
3009 data
<< uint32(getMSTime()); // timestamp
3011 WriteSpellGoTargets(&data
);
3013 m_targets
.write(&data
);
3015 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // unknown wotlk, predicted power?
3018 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
3020 uint8 v1
= m_runesState
;
3021 uint8 v2
= ((Player
*)m_caster
)->GetRunesState();
3022 data
<< uint8(v1
); // runes state before
3023 data
<< uint8(v2
); // runes state after
3024 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
3027 if(m
& v1
) // usable before...
3028 if(!(m
& v2
)) // ...but on cooldown now...
3029 data
<< uint8(0); // some unknown byte (time?)
3033 if ( castFlags
& CAST_FLAG_UNKNOWN4
) // unknown wotlk
3039 if ( castFlags
& CAST_FLAG_AMMO
)
3040 WriteAmmoToPacket(&data
);
3042 if ( castFlags
& CAST_FLAG_UNKNOWN5
) // unknown wotlk
3048 if ( m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
3053 m_caster
->SendMessageToSet(&data
, true);
3056 void Spell::WriteAmmoToPacket( WorldPacket
* data
)
3058 uint32 ammoInventoryType
= 0;
3059 uint32 ammoDisplayID
= 0;
3061 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3063 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack( RANGED_ATTACK
);
3066 ammoInventoryType
= pItem
->GetProto()->InventoryType
;
3067 if( ammoInventoryType
== INVTYPE_THROWN
)
3068 ammoDisplayID
= pItem
->GetProto()->DisplayInfoID
;
3071 uint32 ammoID
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
3074 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( ammoID
);
3077 ammoDisplayID
= pProto
->DisplayInfoID
;
3078 ammoInventoryType
= pProto
->InventoryType
;
3081 else if(m_caster
->GetDummyAura(46699)) // Requires No Ammo
3083 ammoDisplayID
= 5996; // normal arrow
3084 ammoInventoryType
= INVTYPE_AMMO
;
3091 for (uint8 i
= 0; i
< 3; ++i
)
3093 if(uint32 item_id
= m_caster
->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID
+ i
))
3095 if(ItemEntry
const * itemEntry
= sItemStore
.LookupEntry(item_id
))
3097 if(itemEntry
->Class
==ITEM_CLASS_WEAPON
)
3099 switch(itemEntry
->SubClass
)
3101 case ITEM_SUBCLASS_WEAPON_THROWN
:
3102 ammoDisplayID
= itemEntry
->DisplayId
;
3103 ammoInventoryType
= itemEntry
->InventoryType
;
3105 case ITEM_SUBCLASS_WEAPON_BOW
:
3106 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
3107 ammoDisplayID
= 5996; // is this need fixing?
3108 ammoInventoryType
= INVTYPE_AMMO
;
3110 case ITEM_SUBCLASS_WEAPON_GUN
:
3111 ammoDisplayID
= 5998; // is this need fixing?
3112 ammoInventoryType
= INVTYPE_AMMO
;
3124 *data
<< uint32(ammoDisplayID
);
3125 *data
<< uint32(ammoInventoryType
);
3128 void Spell::WriteSpellGoTargets( WorldPacket
* data
)
3130 // This function also fill data for channeled spells:
3131 // m_needAliveTargetMask req for stop channelig if one target die
3132 uint32 hit
= m_UniqueGOTargetInfo
.size(); // Always hits on GO
3134 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3136 if ((*ihit
).effectMask
== 0) // No effect apply - all immuned add state
3138 // possibly SPELL_MISS_IMMUNE2 for this??
3139 ihit
->missCondition
= SPELL_MISS_IMMUNE2
;
3142 else if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
3148 *data
<< (uint8
)hit
;
3149 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3151 if ((*ihit
).missCondition
== SPELL_MISS_NONE
) // Add only hits
3153 *data
<< uint64(ihit
->targetGUID
);
3154 m_needAliveTargetMask
|=ihit
->effectMask
;
3158 for(std::list
<GOTargetInfo
>::const_iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end(); ++ighit
)
3159 *data
<< uint64(ighit
->targetGUID
); // Always hits
3161 *data
<< (uint8
)miss
;
3162 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3164 if( ihit
->missCondition
!= SPELL_MISS_NONE
) // Add only miss
3166 *data
<< uint64(ihit
->targetGUID
);
3167 *data
<< uint8(ihit
->missCondition
);
3168 if( ihit
->missCondition
== SPELL_MISS_REFLECT
)
3169 *data
<< uint8(ihit
->reflectResult
);
3172 // Reset m_needAliveTargetMask for non channeled spell
3173 if(!IsChanneledSpell(m_spellInfo
))
3174 m_needAliveTargetMask
= 0;
3177 void Spell::SendLogExecute()
3179 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
3181 WorldPacket
data(SMSG_SPELLLOGEXECUTE
, (8+4+4+4+4+8));
3183 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
3184 data
.append(m_caster
->GetPackGUID());
3186 data
.append(target
->GetPackGUID());
3188 data
<< uint32(m_spellInfo
->Id
);
3190 data
<< uint32(count1
); // count1 (effect count?)
3191 for(uint32 i
= 0; i
< count1
; ++i
)
3193 data
<< uint32(m_spellInfo
->Effect
[0]); // spell effect
3195 data
<< uint32(count2
); // count2 (target count?)
3196 for(uint32 j
= 0; j
< count2
; ++j
)
3198 switch(m_spellInfo
->Effect
[0])
3200 case SPELL_EFFECT_POWER_DRAIN
:
3201 if(Unit
*unit
= m_targets
.getUnitTarget())
3202 data
.append(unit
->GetPackGUID());
3209 case SPELL_EFFECT_ADD_EXTRA_ATTACKS
:
3210 if(Unit
*unit
= m_targets
.getUnitTarget())
3211 data
.append(unit
->GetPackGUID());
3214 data
<< uint32(0); // count?
3216 case SPELL_EFFECT_INTERRUPT_CAST
:
3217 if(Unit
*unit
= m_targets
.getUnitTarget())
3218 data
.append(unit
->GetPackGUID());
3221 data
<< uint32(0); // spellid
3223 case SPELL_EFFECT_DURABILITY_DAMAGE
:
3224 if(Unit
*unit
= m_targets
.getUnitTarget())
3225 data
.append(unit
->GetPackGUID());
3231 case SPELL_EFFECT_OPEN_LOCK
:
3232 if(Item
*item
= m_targets
.getItemTarget())
3233 data
.append(item
->GetPackGUID());
3237 case SPELL_EFFECT_CREATE_ITEM
:
3238 case SPELL_EFFECT_CREATE_ITEM_2
:
3239 data
<< uint32(m_spellInfo
->EffectItemType
[0]);
3241 case SPELL_EFFECT_SUMMON
:
3242 case SPELL_EFFECT_TRANS_DOOR
:
3243 case SPELL_EFFECT_SUMMON_PET
:
3244 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
3245 case SPELL_EFFECT_CREATE_HOUSE
:
3246 case SPELL_EFFECT_DUEL
:
3247 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1
:
3248 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2
:
3249 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3
:
3250 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4
:
3251 if(Unit
*unit
= m_targets
.getUnitTarget())
3252 data
.append(unit
->GetPackGUID());
3253 else if(m_targets
.getItemTargetGUID())
3254 data
.appendPackGUID(m_targets
.getItemTargetGUID());
3255 else if(GameObject
*go
= m_targets
.getGOTarget())
3256 data
.append(go
->GetPackGUID());
3258 data
<< uint8(0); // guid
3260 case SPELL_EFFECT_FEED_PET
:
3261 data
<< uint32(m_targets
.getItemTargetEntry());
3263 case SPELL_EFFECT_DISMISS_PET
:
3264 if(Unit
*unit
= m_targets
.getUnitTarget())
3265 data
.append(unit
->GetPackGUID());
3269 case SPELL_EFFECT_RESURRECT
:
3270 case SPELL_EFFECT_RESURRECT_NEW
:
3271 if(Unit
*unit
= m_targets
.getUnitTarget())
3272 data
.append(unit
->GetPackGUID());
3282 m_caster
->SendMessageToSet(&data
, true);
3285 void Spell::SendInterrupted(uint8 result
)
3287 WorldPacket
data(SMSG_SPELL_FAILURE
, (8+4+1));
3288 data
.append(m_caster
->GetPackGUID());
3289 data
<< uint8(m_cast_count
);
3290 data
<< uint32(m_spellInfo
->Id
);
3291 data
<< uint8(result
);
3292 m_caster
->SendMessageToSet(&data
, true);
3294 data
.Initialize(SMSG_SPELL_FAILED_OTHER
, (8+4));
3295 data
.append(m_caster
->GetPackGUID());
3296 data
<< uint8(m_cast_count
);
3297 data
<< uint32(m_spellInfo
->Id
);
3298 data
<< uint8(result
);
3299 m_caster
->SendMessageToSet(&data
, true);
3302 void Spell::SendChannelUpdate(uint32 time
)
3306 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, 0);
3307 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, 0);
3310 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3313 WorldPacket
data( MSG_CHANNEL_UPDATE
, 8+4 );
3314 data
.append(m_caster
->GetPackGUID());
3315 data
<< uint32(time
);
3317 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3320 void Spell::SendChannelStart(uint32 duration
)
3322 WorldObject
* target
= NULL
;
3324 // select first not resisted target from target list for _0_ effect
3325 if(!m_UniqueTargetInfo
.empty())
3327 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin(); itr
!= m_UniqueTargetInfo
.end(); ++itr
)
3329 if( (itr
->effectMask
& (1 << 0)) && itr
->reflectResult
== SPELL_MISS_NONE
&& itr
->targetGUID
!= m_caster
->GetGUID())
3331 target
= ObjectAccessor::GetUnit(*m_caster
, itr
->targetGUID
);
3336 else if(!m_UniqueGOTargetInfo
.empty())
3338 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin(); itr
!= m_UniqueGOTargetInfo
.end(); ++itr
)
3340 if(itr
->effectMask
& (1 << 0) )
3342 target
= m_caster
->GetMap()->GetGameObject(itr
->targetGUID
);
3348 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3350 WorldPacket
data( MSG_CHANNEL_START
, (8+4+4) );
3351 data
.append(m_caster
->GetPackGUID());
3352 data
<< uint32(m_spellInfo
->Id
);
3353 data
<< uint32(duration
);
3355 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
3360 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, target
->GetGUID());
3361 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, m_spellInfo
->Id
);
3364 void Spell::SendResurrectRequest(Player
* target
)
3366 // Both players and NPCs can resurrect using spells - have a look at creature 28487 for example
3367 // However, the packet structure differs slightly
3369 const char* sentName
= m_caster
->GetTypeId() == TYPEID_PLAYER
? "" : m_caster
->GetNameForLocaleIdx(target
->GetSession()->GetSessionDbLocaleIndex());
3371 WorldPacket
data(SMSG_RESURRECT_REQUEST
, (8+4+strlen(sentName
)+1+1+1));
3372 data
<< uint64(m_caster
->GetGUID());
3373 data
<< uint32(strlen(sentName
) + 1);
3378 data
<< uint8(m_caster
->GetTypeId() == TYPEID_PLAYER
? 0 : 1);
3379 target
->GetSession()->SendPacket(&data
);
3382 void Spell::SendPlaySpellVisual(uint32 SpellID
)
3384 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3387 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 8 + 4);
3388 data
<< uint64(m_caster
->GetGUID());
3389 data
<< uint32(SpellID
); // spell visual id?
3390 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
3393 void Spell::TakeCastItem()
3395 if(!m_CastItem
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
3398 // not remove cast item at triggered spell (equipping, weapon damage, etc)
3399 if(m_IsTriggeredSpell
)
3402 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3406 // This code is to avoid a crash
3407 // I'm not sure, if this is really an error, but I guess every item needs a prototype
3408 sLog
.outError("Cast item has no item prototype highId=%d, lowId=%d",m_CastItem
->GetGUIDHigh(), m_CastItem
->GetGUIDLow());
3412 bool expendable
= false;
3413 bool withoutCharges
= false;
3415 for (int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
3417 if (proto
->Spells
[i
].SpellId
)
3419 // item has limited charges
3420 if (proto
->Spells
[i
].SpellCharges
)
3422 if (proto
->Spells
[i
].SpellCharges
< 0)
3425 int32 charges
= m_CastItem
->GetSpellCharges(i
);
3427 // item has charges left
3430 (charges
> 0) ? --charges
: ++charges
; // abs(charges) less at 1 after use
3431 if (proto
->Stackable
== 1)
3432 m_CastItem
->SetSpellCharges(i
, charges
);
3433 m_CastItem
->SetState(ITEM_CHANGED
, (Player
*)m_caster
);
3437 withoutCharges
= (charges
== 0);
3442 if (expendable
&& withoutCharges
)
3445 ((Player
*)m_caster
)->DestroyItemCount(m_CastItem
, count
, true);
3447 // prevent crash at access to deleted m_targets.getItemTarget
3448 if(m_CastItem
==m_targets
.getItemTarget())
3449 m_targets
.setItemTarget(NULL
);
3455 void Spell::TakePower()
3457 if(m_CastItem
|| m_triggeredByAuraSpell
)
3460 // health as power used
3461 if(m_spellInfo
->powerType
== POWER_HEALTH
)
3463 m_caster
->ModifyHealth( -(int32
)m_powerCost
);
3467 if(m_spellInfo
->powerType
>= MAX_POWERS
)
3469 sLog
.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo
->powerType
);
3473 Powers powerType
= Powers(m_spellInfo
->powerType
);
3475 if(powerType
== POWER_RUNE
)
3481 m_caster
->ModifyPower(powerType
, -(int32
)m_powerCost
);
3483 // Set the five second timer
3484 if (powerType
== POWER_MANA
&& m_powerCost
> 0)
3485 m_caster
->SetLastManaUse(getMSTime());
3488 SpellCastResult
Spell::CheckRuneCost(uint32 runeCostID
)
3490 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3491 return SPELL_CAST_OK
;
3493 Player
*plr
= (Player
*)m_caster
;
3495 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3496 return SPELL_CAST_OK
;
3498 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(runeCostID
);
3501 return SPELL_CAST_OK
;
3503 if(src
->NoRuneCost())
3504 return SPELL_CAST_OK
;
3506 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3508 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3509 runeCost
[i
] = src
->RuneCost
[i
];
3511 runeCost
[RUNE_DEATH
] = MAX_RUNES
; // calculated later
3513 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3515 uint8 rune
= plr
->GetCurrentRune(i
);
3516 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3520 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3522 runeCost
[RUNE_DEATH
] += runeCost
[i
];
3524 if(runeCost
[RUNE_DEATH
] > MAX_RUNES
)
3525 return SPELL_FAILED_NO_POWER
; // not sure if result code is correct
3527 return SPELL_CAST_OK
;
3530 void Spell::TakeRunePower()
3532 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3535 Player
*plr
= (Player
*)m_caster
;
3537 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3540 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(m_spellInfo
->runeCostID
);
3542 if(!src
|| (src
->NoRuneCost() && src
->NoRunicPowerGain()))
3545 m_runesState
= plr
->GetRunesState(); // store previous state
3547 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3549 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3551 runeCost
[i
] = src
->RuneCost
[i
];
3554 runeCost
[RUNE_DEATH
] = 0; // calculated later
3556 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3558 uint8 rune
= plr
->GetCurrentRune(i
);
3559 if((plr
->GetRuneCooldown(i
) == 0) && (runeCost
[rune
] > 0))
3561 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3566 runeCost
[RUNE_DEATH
] = runeCost
[RUNE_BLOOD
] + runeCost
[RUNE_UNHOLY
] + runeCost
[RUNE_FROST
];
3568 if(runeCost
[RUNE_DEATH
] > 0)
3570 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3572 uint8 rune
= plr
->GetCurrentRune(i
);
3573 if((plr
->GetRuneCooldown(i
) == 0) && (rune
== RUNE_DEATH
))
3575 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3577 plr
->ConvertRune(i
, plr
->GetBaseRune(i
));
3578 if(runeCost
[RUNE_DEATH
] == 0)
3584 // you can gain some runic power when use runes
3585 float rp
= src
->runePowerGain
;;
3586 rp
*= sWorld
.getRate(RATE_POWER_RUNICPOWER_INCOME
);
3587 plr
->ModifyPower(POWER_RUNIC_POWER
, (int32
)rp
);
3590 void Spell::TakeReagents()
3592 if(m_IsTriggeredSpell
) // reagents used in triggered spell removed by original spell or don't must be removed.
3595 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3598 Player
* p_caster
= (Player
*)m_caster
;
3599 if (p_caster
->CanNoReagentCast(m_spellInfo
))
3602 for(uint32 x
= 0; x
< 8; ++x
)
3604 if(m_spellInfo
->Reagent
[x
] <= 0)
3607 uint32 itemid
= m_spellInfo
->Reagent
[x
];
3608 uint32 itemcount
= m_spellInfo
->ReagentCount
[x
];
3610 // if CastItem is also spell reagent
3613 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3614 if( proto
&& proto
->ItemId
== itemid
)
3616 for(int s
= 0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
3618 // CastItem will be used up and does not count as reagent
3619 int32 charges
= m_CastItem
->GetSpellCharges(s
);
3620 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
3631 // if getItemTarget is also spell reagent
3632 if (m_targets
.getItemTargetEntry() == itemid
)
3633 m_targets
.setItemTarget(NULL
);
3635 p_caster
->DestroyItemCount(itemid
, itemcount
, true);
3639 void Spell::HandleThreatSpells(uint32 spellId
)
3641 if(!m_targets
.getUnitTarget() || !spellId
)
3644 if(!m_targets
.getUnitTarget()->CanHaveThreatList())
3647 uint16 threat
= spellmgr
.GetSpellThreat(spellId
);
3652 m_targets
.getUnitTarget()->AddThreat(m_caster
, float(threat
));
3654 DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId
, spellmgr
.GetSpellRank(spellId
), threat
);
3657 void Spell::HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,uint32 i
, float DamageMultiplier
)
3659 unitTarget
= pUnitTarget
;
3660 itemTarget
= pItemTarget
;
3661 gameObjTarget
= pGOTarget
;
3663 uint8 eff
= m_spellInfo
->Effect
[i
];
3665 damage
= int32(CalculateDamage((uint8
)i
, unitTarget
) * DamageMultiplier
);
3667 sLog
.outDebug( "Spell: Effect : %u", eff
);
3669 if(eff
<TOTAL_SPELL_EFFECTS
)
3671 //sLog.outDebug( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff);
3672 (*this.*SpellEffects
[eff
])(i
);
3677 sLog.outDebug( "WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff);
3679 EffectEnchantItemTmp(i);
3682 sLog.outError("SPELL: unknown effect %u spell id %u",
3683 eff, m_spellInfo->Id);
3690 void Spell::AddTriggeredSpell( uint32 spellId
)
3692 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3696 sLog
.outError("Spell::AddTriggeredSpell: unknown spell id %u used as triggred spell for spell %u)", spellId
, m_spellInfo
->Id
);
3700 m_TriggerSpells
.push_back(spellInfo
);
3703 void Spell::AddPrecastSpell( uint32 spellId
)
3705 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3709 sLog
.outError("Spell::AddPrecastSpell: unknown spell id %u used as pre-cast spell for spell %u)", spellId
, m_spellInfo
->Id
);
3713 m_preCastSpells
.push_back(spellInfo
);
3716 void Spell::CastTriggerSpells()
3718 for(SpellInfoList::const_iterator si
=m_TriggerSpells
.begin(); si
!=m_TriggerSpells
.end(); ++si
)
3720 Spell
* spell
= new Spell(m_caster
, (*si
), true, m_originalCasterGUID
, m_selfContainer
);
3721 spell
->prepare(&m_targets
); // use original spell original targets
3725 void Spell::CastPreCastSpells(Unit
* target
)
3727 for(SpellInfoList::const_iterator si
=m_preCastSpells
.begin(); si
!=m_preCastSpells
.end(); ++si
)
3728 m_caster
->CastSpell(target
, (*si
), true, m_CastItem
);
3731 SpellCastResult
Spell::CheckCast(bool strict
)
3733 // check cooldowns to prevent cheating
3734 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
3736 if(m_triggeredByAuraSpell
)
3737 return SPELL_FAILED_DONT_REPORT
;
3739 return SPELL_FAILED_NOT_READY
;
3742 // only allow triggered spells if at an ended battleground
3743 if( !m_IsTriggeredSpell
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
3744 if(BattleGround
* bg
= ((Player
*)m_caster
)->GetBattleGround())
3745 if(bg
->GetStatus() == STATUS_WAIT_LEAVE
)
3746 return SPELL_FAILED_DONT_REPORT
;
3748 // only check at first call, Stealth auras are already removed at second call
3749 // for now, ignore triggered spells
3750 if( strict
&& !m_IsTriggeredSpell
)
3752 bool checkForm
= true;
3753 // Ignore form req aura
3754 Unit::AuraList
const& ignore
= m_caster
->GetAurasByType(SPELL_AURA_MOD_IGNORE_SHAPESHIFT
);
3755 for(Unit::AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
3757 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
3764 // Cannot be used in this stance/form
3765 SpellCastResult shapeError
= GetErrorAtShapeshiftedCast(m_spellInfo
, m_caster
->m_form
);
3766 if(shapeError
!= SPELL_CAST_OK
)
3769 if ((m_spellInfo
->Attributes
& SPELL_ATTR_ONLY_STEALTHED
) && !(m_caster
->HasStealthAura()))
3770 return SPELL_FAILED_ONLY_STEALTHED
;
3774 // caster state requirements
3775 if(m_spellInfo
->CasterAuraState
&& !m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraState
)))
3776 return SPELL_FAILED_CASTER_AURASTATE
;
3777 if(m_spellInfo
->CasterAuraStateNot
&& m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraStateNot
)))
3778 return SPELL_FAILED_CASTER_AURASTATE
;
3780 // Caster aura req check if need
3781 if(m_spellInfo
->casterAuraSpell
&& !m_caster
->HasAura(m_spellInfo
->casterAuraSpell
))
3782 return SPELL_FAILED_CASTER_AURASTATE
;
3783 if(m_spellInfo
->excludeCasterAuraSpell
)
3785 // Special cases of non existing auras handling
3786 if(m_spellInfo
->excludeCasterAuraSpell
== 61988)
3788 // Avenging Wrath Marker
3789 if(m_caster
->HasAura(61987))
3790 return SPELL_FAILED_CASTER_AURASTATE
;
3792 else if(m_caster
->HasAura(m_spellInfo
->excludeCasterAuraSpell
))
3793 return SPELL_FAILED_CASTER_AURASTATE
;
3796 // cancel autorepeat spells if cast start when moving
3797 // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
3798 if( m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->isMoving() )
3800 // skip stuck spell to allow use it in falling case and apply spell limitations at movement
3801 if( (!((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEMENTFLAG_FALLING
) || m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
) &&
3802 (IsAutoRepeat() || (m_spellInfo
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_NOT_SEATED
) != 0) )
3803 return SPELL_FAILED_MOVING
;
3806 if(Unit
*target
= m_targets
.getUnitTarget())
3808 // target state requirements (not allowed state), apply to self also
3809 if(m_spellInfo
->TargetAuraStateNot
&& target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraStateNot
)))
3810 return SPELL_FAILED_TARGET_AURASTATE
;
3812 // Target aura req check if need
3813 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
3814 return SPELL_FAILED_CASTER_AURASTATE
;
3815 if(m_spellInfo
->excludeTargetAuraSpell
)
3817 // Special cases of non existing auras handling
3818 if (m_spellInfo
->excludeTargetAuraSpell
== 61988)
3820 // Avenging Wrath Marker
3821 if (target
->HasAura(61987))
3822 return SPELL_FAILED_CASTER_AURASTATE
;
3825 else if (target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
3826 return SPELL_FAILED_CASTER_AURASTATE
;
3829 bool non_caster_target
= target
!= m_caster
&& !IsSpellWithCasterSourceTargetsOnly(m_spellInfo
);
3831 if(non_caster_target
)
3833 // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds
3834 if(m_spellInfo
->TargetAuraState
&& !target
->HasAuraStateForCaster(AuraState(m_spellInfo
->TargetAuraState
),m_caster
->GetGUID()))
3835 return SPELL_FAILED_TARGET_AURASTATE
;
3837 // Not allow casting on flying player
3838 if (target
->isInFlight())
3839 return SPELL_FAILED_BAD_TARGETS
;
3841 if(!m_IsTriggeredSpell
&& VMAP::VMapFactory::checkSpellForLoS(m_spellInfo
->Id
) && !m_caster
->IsWithinLOSInMap(target
))
3842 return SPELL_FAILED_LINE_OF_SIGHT
;
3844 // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode
3845 // this case can be triggered if rank not found (too low-level target for first rank)
3846 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsPassiveSpell(m_spellInfo
->Id
) && !m_CastItem
)
3848 for(int i
=0;i
<3;++i
)
3850 // check only spell that apply positive auras
3851 if (IsPositiveEffect(m_spellInfo
->Id
, i
) && m_spellInfo
->Effect
[i
] == SPELL_EFFECT_APPLY_AURA
&&
3852 // at not self target
3853 !IsCasterSourceTarget(m_spellInfo
->EffectImplicitTargetA
[i
]) &&
3854 // and target low level
3855 target
->getLevel() + 10 < m_spellInfo
->spellLevel
)
3857 return SPELL_FAILED_LOWLEVEL
;
3862 else if (m_caster
== target
)
3865 if (m_caster
->GetTypeId() == TYPEID_PLAYER
) // Target - is player caster
3867 // Additional check for some spells
3868 // If 0 spell effect empty - client not send target data (need use selection)
3869 // TODO: check it on next client version
3870 if (m_targets
.m_targetMask
== TARGET_FLAG_SELF
&&
3871 m_spellInfo
->EffectImplicitTargetA
[1] == TARGET_CHAIN_DAMAGE
)
3873 if (target
= m_caster
->GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection()))
3874 m_targets
.setUnitTarget(target
);
3876 return SPELL_FAILED_BAD_TARGETS
;
3880 // Some special spells with non-caster only mode
3883 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
3884 m_spellInfo
->SpellIconID
== 16)
3885 return SPELL_FAILED_BAD_TARGETS
;
3887 // Focus Magic (main spell)
3888 if (m_spellInfo
->Id
== 54646)
3889 return SPELL_FAILED_BAD_TARGETS
;
3892 // check pet presents
3893 for(int j
= 0; j
< 3; ++j
)
3895 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_PET
)
3897 target
= m_caster
->GetPet();
3900 if(m_triggeredByAuraSpell
) // not report pet not existence for triggered spells
3901 return SPELL_FAILED_DONT_REPORT
;
3903 return SPELL_FAILED_NO_PET
;
3909 //check creature type
3910 //ignore self casts (including area casts when caster selected as target)
3911 if(non_caster_target
)
3913 if(!CheckTargetCreatureType(target
))
3915 if(target
->GetTypeId() == TYPEID_PLAYER
)
3916 return SPELL_FAILED_TARGET_IS_PLAYER
;
3918 return SPELL_FAILED_BAD_TARGETS
;
3922 // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
3923 // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
3924 if(non_caster_target
&& m_caster
->GetTypeId() == TYPEID_UNIT
&& m_caster
->GetCharmerOrOwnerGUID())
3926 // check correctness positive/negative cast target (pet cast real check and cheating check)
3927 if(IsPositiveSpell(m_spellInfo
->Id
))
3929 if(m_caster
->IsHostileTo(target
))
3930 return SPELL_FAILED_BAD_TARGETS
;
3934 if(m_caster
->IsFriendlyTo(target
))
3935 return SPELL_FAILED_BAD_TARGETS
;
3939 if(IsPositiveSpell(m_spellInfo
->Id
))
3940 if(target
->IsImmunedToSpell(m_spellInfo
))
3941 return SPELL_FAILED_TARGET_AURASTATE
;
3943 //Must be behind the target.
3944 if( m_spellInfo
->AttributesEx2
== 0x100000 && (m_spellInfo
->AttributesEx
& 0x200) == 0x200 && target
->HasInArc(M_PI
, m_caster
) )
3946 //Exclusion for Pounce: Facing Limitation was removed in 2.0.1, but it still uses the same, old Ex-Flags
3947 //Exclusion for Mutilate:Facing Limitation was removed in 2.0.1 and 3.0.3, but they still use the same, old Ex-Flags
3948 if ((m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_DRUID
|| (m_spellInfo
->SpellFamilyFlags
!= UI64LIT(0x0000000000020000))) &&
3949 (m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_ROGUE
|| (m_spellInfo
->SpellFamilyFlags
!= UI64LIT(0x0020000000000000))))
3952 return SPELL_FAILED_NOT_BEHIND
;
3956 //Target must be facing you.
3957 if((m_spellInfo
->Attributes
== 0x150010) && !target
->HasInArc(M_PI
, m_caster
) )
3960 return SPELL_FAILED_NOT_INFRONT
;
3963 // check if target is in combat
3964 if (non_caster_target
&& (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET
) && target
->isInCombat())
3965 return SPELL_FAILED_TARGET_AFFECTING_COMBAT
;
3968 // Spell casted only on battleground
3969 if ((m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_BATTLEGROUND
) && m_caster
->GetTypeId() == TYPEID_PLAYER
)
3970 if(!((Player
*)m_caster
)->InBattleGround())
3971 return SPELL_FAILED_ONLY_BATTLEGROUNDS
;
3973 // do not allow spells to be cast in arenas
3974 // - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag
3975 // - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag
3976 if ((m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA
) ||
3977 GetSpellRecoveryTime(m_spellInfo
) > 15 * MINUTE
* IN_MILISECONDS
&& !(m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_USABLE_IN_ARENA
))
3978 if(MapEntry
const* mapEntry
= sMapStore
.LookupEntry(m_caster
->GetMapId()))
3979 if(mapEntry
->IsBattleArena())
3980 return SPELL_FAILED_NOT_IN_ARENA
;
3984 m_caster
->GetZoneAndAreaId(zone
, area
);
3986 SpellCastResult locRes
= spellmgr
.GetSpellAllowedInLocationError(m_spellInfo
,m_caster
->GetMapId(),zone
,area
,
3987 m_caster
->GetTypeId() == TYPEID_PLAYER
? ((Player
*)m_caster
) : NULL
);
3988 if (locRes
!= SPELL_CAST_OK
)
3991 // not let players cast spells at mount (and let do it to creatures)
3992 if (m_caster
->IsMounted() && m_caster
->GetTypeId()==TYPEID_PLAYER
&& !m_IsTriggeredSpell
&&
3993 !IsPassiveSpell(m_spellInfo
->Id
) && !(m_spellInfo
->Attributes
& SPELL_ATTR_CASTABLE_WHILE_MOUNTED
))
3995 if (m_caster
->isInFlight())
3996 return SPELL_FAILED_NOT_FLYING
;
3998 return SPELL_FAILED_NOT_MOUNTED
;
4001 // always (except passive spells) check items (focus object can be required for any type casts)
4002 if (!IsPassiveSpell(m_spellInfo
->Id
))
4004 SpellCastResult castResult
= CheckItems();
4005 if(castResult
!= SPELL_CAST_OK
)
4009 //ImpliciteTargetA-B = 38, If fact there is 0 Spell with ImpliciteTargetB=38
4010 if (m_UniqueTargetInfo
.empty()) // skip second CheckCast apply (for delayed spells for example)
4012 for(uint8 j
= 0; j
< 3; ++j
)
4014 if( m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
4015 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_SELF
||
4016 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4017 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4019 SpellScriptTargetBounds bounds
= spellmgr
.GetSpellScriptTargetBounds(m_spellInfo
->Id
);
4020 if(bounds
.first
==bounds
.second
)
4021 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
);
4023 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4024 float range
= GetSpellMaxRange(srange
);
4026 Creature
* creatureScriptTarget
= NULL
;
4027 GameObject
* goScriptTarget
= NULL
;
4029 for(SpellScriptTarget::const_iterator i_spellST
= bounds
.first
; i_spellST
!= bounds
.second
; ++i_spellST
)
4031 switch(i_spellST
->second
.type
)
4033 case SPELL_TARGET_TYPE_GAMEOBJECT
:
4035 GameObject
* p_GameObject
= NULL
;
4037 if (i_spellST
->second
.targetEntry
)
4039 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4041 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4043 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*m_caster
,i_spellST
->second
.targetEntry
,range
);
4044 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(m_caster
, p_GameObject
,go_check
);
4046 TypeContainerVisitor
<MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
>, GridTypeMapContainer
> object_checker(checker
);
4047 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4048 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
4052 // remember found target and range, next attempt will find more near target with another entry
4053 creatureScriptTarget
= NULL
;
4054 goScriptTarget
= p_GameObject
;
4055 range
= go_check
.GetLastRange();
4058 else if (focusObject
) // Focus Object
4060 float frange
= m_caster
->GetDistance(focusObject
);
4061 if (range
>= frange
)
4063 creatureScriptTarget
= NULL
;
4064 goScriptTarget
= focusObject
;
4070 case SPELL_TARGET_TYPE_CREATURE
:
4071 case SPELL_TARGET_TYPE_DEAD
:
4074 Creature
*p_Creature
= NULL
;
4076 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4078 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4079 cell
.SetNoCreate(); // Really don't know what is that???
4081 MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
u_check(*m_caster
,i_spellST
->second
.targetEntry
,i_spellST
->second
.type
!=SPELL_TARGET_TYPE_DEAD
,range
);
4082 MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
> searcher(m_caster
, p_Creature
, u_check
);
4084 TypeContainerVisitor
<MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
>, GridTypeMapContainer
> grid_creature_searcher(searcher
);
4086 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4087 cell_lock
->Visit(cell_lock
, grid_creature_searcher
, *m_caster
->GetMap());
4091 creatureScriptTarget
= p_Creature
;
4092 goScriptTarget
= NULL
;
4093 range
= u_check
.GetLastRange();
4100 if(creatureScriptTarget
)
4102 // store coordinates for TARGET_SCRIPT_COORDINATES
4103 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4104 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4106 m_targets
.setDestination(creatureScriptTarget
->GetPositionX(),creatureScriptTarget
->GetPositionY(),creatureScriptTarget
->GetPositionZ());
4108 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
4109 AddUnitTarget(creatureScriptTarget
, j
);
4111 // store explicit target for TARGET_SCRIPT
4113 AddUnitTarget(creatureScriptTarget
, j
);
4115 else if(goScriptTarget
)
4117 // store coordinates for TARGET_SCRIPT_COORDINATES
4118 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4119 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4121 m_targets
.setDestination(goScriptTarget
->GetPositionX(),goScriptTarget
->GetPositionY(),goScriptTarget
->GetPositionZ());
4123 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
4124 AddGOTarget(goScriptTarget
, j
);
4126 // store explicit target for TARGET_SCRIPT
4128 AddGOTarget(goScriptTarget
, j
);
4130 //Missing DB Entry or targets for this spellEffect.
4133 // not report target not existence for triggered spells
4134 if(m_triggeredByAuraSpell
|| m_IsTriggeredSpell
)
4135 return SPELL_FAILED_DONT_REPORT
;
4137 return SPELL_FAILED_BAD_TARGETS
;
4143 if(!m_IsTriggeredSpell
)
4145 SpellCastResult castResult
= CheckRange(strict
);
4146 if(castResult
!= SPELL_CAST_OK
)
4151 SpellCastResult castResult
= CheckPower();
4152 if(castResult
!= SPELL_CAST_OK
)
4156 if(!m_IsTriggeredSpell
) // triggered spell not affected by stun/etc
4158 SpellCastResult castResult
= CheckCasterAuras();
4159 if(castResult
!= SPELL_CAST_OK
)
4163 for (int i
= 0; i
< 3; ++i
)
4165 // for effects of spells that have only one target
4166 switch(m_spellInfo
->Effect
[i
])
4168 case SPELL_EFFECT_DUMMY
:
4170 if(m_spellInfo
->SpellIconID
== 1648) // Execute
4172 if(!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4173 return SPELL_FAILED_BAD_TARGETS
;
4175 else if (m_spellInfo
->Id
== 51582) // Rocket Boots Engaged
4177 if(m_caster
->IsInWater())
4178 return SPELL_FAILED_ONLY_ABOVEWATER
;
4180 else if(m_spellInfo
->SpellIconID
== 156) // Holy Shock
4182 // spell different for friends and enemies
4183 // hart version required facing
4184 if(m_targets
.getUnitTarget() && !m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()) && !m_caster
->HasInArc( M_PI
, m_targets
.getUnitTarget() ))
4185 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4189 case SPELL_EFFECT_SCHOOL_DAMAGE
:
4192 if(m_spellInfo
->SpellVisual
[0] == 7250)
4194 if (!m_targets
.getUnitTarget())
4195 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4197 if(m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4198 return SPELL_FAILED_BAD_TARGETS
;
4202 case SPELL_EFFECT_TAMECREATURE
:
4204 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4205 return SPELL_FAILED_BAD_TARGETS
;
4207 if (!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
)
4208 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4210 Creature
* target
= (Creature
*)m_targets
.getUnitTarget();
4212 if (target
->getLevel() > m_caster
->getLevel())
4213 return SPELL_FAILED_HIGHLEVEL
;
4215 // use SMSG_PET_TAME_FAILURE?
4216 if (!target
->GetCreatureInfo()->isTameable (((Player
*)m_caster
)->CanTameExoticPets()))
4217 return SPELL_FAILED_BAD_TARGETS
;
4219 if(m_caster
->GetPetGUID())
4220 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4222 if(m_caster
->GetCharmGUID())
4223 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4227 case SPELL_EFFECT_LEARN_SPELL
:
4229 if(m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_PET
)
4232 Pet
* pet
= m_caster
->GetPet();
4235 return SPELL_FAILED_NO_PET
;
4237 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4239 if(!learn_spellproto
)
4240 return SPELL_FAILED_NOT_KNOWN
;
4242 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4243 return SPELL_FAILED_LOWLEVEL
;
4247 case SPELL_EFFECT_LEARN_PET_SPELL
:
4249 Pet
* pet
= m_caster
->GetPet();
4252 return SPELL_FAILED_NO_PET
;
4254 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4256 if(!learn_spellproto
)
4257 return SPELL_FAILED_NOT_KNOWN
;
4259 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4260 return SPELL_FAILED_LOWLEVEL
;
4264 case SPELL_EFFECT_APPLY_GLYPH
:
4266 uint32 glyphId
= m_spellInfo
->EffectMiscValue
[i
];
4267 if(GlyphPropertiesEntry
const *gp
= sGlyphPropertiesStore
.LookupEntry(glyphId
))
4268 if(m_caster
->HasAura(gp
->SpellId
))
4269 return SPELL_FAILED_UNIQUE_GLYPH
;
4272 case SPELL_EFFECT_FEED_PET
:
4274 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4275 return SPELL_FAILED_BAD_TARGETS
;
4277 Item
* foodItem
= m_targets
.getItemTarget();
4279 return SPELL_FAILED_BAD_TARGETS
;
4281 Pet
* pet
= m_caster
->GetPet();
4284 return SPELL_FAILED_NO_PET
;
4286 if(!pet
->HaveInDiet(foodItem
->GetProto()))
4287 return SPELL_FAILED_WRONG_PET_FOOD
;
4289 if(!pet
->GetCurrentFoodBenefitLevel(foodItem
->GetProto()->ItemLevel
))
4290 return SPELL_FAILED_FOOD_LOWLEVEL
;
4292 if(m_caster
->isInCombat() || pet
->isInCombat())
4293 return SPELL_FAILED_AFFECTING_COMBAT
;
4297 case SPELL_EFFECT_POWER_BURN
:
4298 case SPELL_EFFECT_POWER_DRAIN
:
4300 // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
4301 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4302 if(Unit
* target
= m_targets
.getUnitTarget())
4303 if(target
!= m_caster
&& target
->getPowerType() != m_spellInfo
->EffectMiscValue
[i
])
4304 return SPELL_FAILED_BAD_TARGETS
;
4307 case SPELL_EFFECT_CHARGE
:
4309 if (m_caster
->hasUnitState(UNIT_STAT_ROOT
))
4310 return SPELL_FAILED_ROOTED
;
4314 case SPELL_EFFECT_SKINNING
:
4316 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() != TYPEID_UNIT
)
4317 return SPELL_FAILED_BAD_TARGETS
;
4319 if( !(m_targets
.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS
) & UNIT_FLAG_SKINNABLE
) )
4320 return SPELL_FAILED_TARGET_UNSKINNABLE
;
4322 Creature
* creature
= (Creature
*)m_targets
.getUnitTarget();
4323 if ( creature
->GetCreatureType() != CREATURE_TYPE_CRITTER
&& ( !creature
->lootForBody
|| !creature
->loot
.empty() ) )
4325 return SPELL_FAILED_TARGET_NOT_LOOTED
;
4328 uint32 skill
= creature
->GetCreatureInfo()->GetRequiredLootSkill();
4330 int32 skillValue
= ((Player
*)m_caster
)->GetSkillValue(skill
);
4331 int32 TargetLevel
= m_targets
.getUnitTarget()->getLevel();
4332 int32 ReqValue
= (skillValue
< 100 ? (TargetLevel
-10) * 10 : TargetLevel
* 5);
4333 if (ReqValue
> skillValue
)
4334 return SPELL_FAILED_LOW_CASTLEVEL
;
4336 // chance for fail at orange skinning attempt
4337 if( (m_selfContainer
&& (*m_selfContainer
) == this) &&
4338 skillValue
< sWorld
.GetConfigMaxSkillValue() &&
4339 (ReqValue
< 0 ? 0 : ReqValue
) > irand(skillValue
- 25, skillValue
+ 37) )
4340 return SPELL_FAILED_TRY_AGAIN
;
4344 case SPELL_EFFECT_OPEN_LOCK
:
4346 if( m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT
&&
4347 m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT_ITEM
)
4350 if( m_caster
->GetTypeId() != TYPEID_PLAYER
// only players can open locks, gather etc.
4351 // we need a go target in case of TARGET_GAMEOBJECT
4352 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT
&& !m_targets
.getGOTarget()
4353 // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM
4354 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT_ITEM
&& !m_targets
.getGOTarget() &&
4355 (!m_targets
.getItemTarget() || !m_targets
.getItemTarget()->GetProto()->LockID
|| m_targets
.getItemTarget()->GetOwner() != m_caster
) )
4356 return SPELL_FAILED_BAD_TARGETS
;
4358 // In BattleGround players can use only flags and banners
4359 if( ((Player
*)m_caster
)->InBattleGround() &&
4360 !((Player
*)m_caster
)->CanUseBattleGroundObject() )
4361 return SPELL_FAILED_TRY_AGAIN
;
4363 // get the lock entry
4365 if (GameObject
* go
= m_targets
.getGOTarget())
4367 lockId
= go
->GetGOInfo()->GetLockId();
4369 return SPELL_FAILED_BAD_TARGETS
;
4371 else if(Item
* itm
= m_targets
.getItemTarget())
4372 lockId
= itm
->GetProto()->LockID
;
4374 SkillType skillId
= SKILL_NONE
;
4375 int32 reqSkillValue
= 0;
4376 int32 skillValue
= 0;
4378 // check lock compatibility
4379 SpellCastResult res
= CanOpenLock(i
, lockId
, skillId
, reqSkillValue
, skillValue
);
4380 if(res
!= SPELL_CAST_OK
)
4383 // chance for fail at orange mining/herb/LockPicking gathering attempt
4384 // second check prevent fail at rechecks
4385 if(skillId
!= SKILL_NONE
&& (!m_selfContainer
|| ((*m_selfContainer
) != this)))
4387 bool canFailAtMax
= skillId
!= SKILL_HERBALISM
&& skillId
!= SKILL_MINING
;
4389 // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill)
4390 if((canFailAtMax
|| skillValue
< sWorld
.GetConfigMaxSkillValue()) && reqSkillValue
> irand(skillValue
- 25, skillValue
+ 37))
4391 return SPELL_FAILED_TRY_AGAIN
;
4395 case SPELL_EFFECT_SUMMON_DEAD_PET
:
4397 Creature
*pet
= m_caster
->GetPet();
4399 return SPELL_FAILED_NO_PET
;
4402 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4406 // This is generic summon effect
4407 case SPELL_EFFECT_SUMMON
:
4409 switch(m_spellInfo
->EffectMiscValueB
[i
])
4411 case SUMMON_TYPE_POSESSED
:
4412 case SUMMON_TYPE_POSESSED2
:
4413 case SUMMON_TYPE_DEMON
:
4414 case SUMMON_TYPE_SUMMON
:
4415 case SUMMON_TYPE_ELEMENTAL
:
4416 case SUMMON_TYPE_INFERNO
:
4418 if(m_caster
->GetPetGUID())
4419 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4421 if(m_caster
->GetCharmGUID())
4422 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4428 // Not used for summon?
4429 case SPELL_EFFECT_SUMMON_PHANTASM
:
4431 if(m_caster
->GetPetGUID())
4432 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4434 if(m_caster
->GetCharmGUID())
4435 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4439 case SPELL_EFFECT_SUMMON_PET
:
4441 if(m_caster
->GetPetGUID()) //let warlock do a replacement summon
4444 Pet
* pet
= ((Player
*)m_caster
)->GetPet();
4446 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->getClass() == CLASS_WARLOCK
)
4448 if (strict
) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
4449 pet
->CastSpell(pet
, 32752, true, NULL
, NULL
, pet
->GetGUID());
4452 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4455 if(m_caster
->GetCharmGUID())
4456 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4460 case SPELL_EFFECT_SUMMON_PLAYER
:
4462 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4463 return SPELL_FAILED_BAD_TARGETS
;
4464 if(!((Player
*)m_caster
)->GetSelection())
4465 return SPELL_FAILED_BAD_TARGETS
;
4467 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
4468 if( !target
|| ((Player
*)m_caster
) == target
|| !target
->IsInSameRaidWith((Player
*)m_caster
) )
4469 return SPELL_FAILED_BAD_TARGETS
;
4471 // check if our map is dungeon
4472 if( sMapStore
.LookupEntry(m_caster
->GetMapId())->IsDungeon() )
4474 InstanceTemplate
const* instance
= ObjectMgr::GetInstanceTemplate(m_caster
->GetMapId());
4476 return SPELL_FAILED_TARGET_NOT_IN_INSTANCE
;
4477 if ( instance
->levelMin
> target
->getLevel() )
4478 return SPELL_FAILED_LOWLEVEL
;
4479 if ( instance
->levelMax
&& instance
->levelMax
< target
->getLevel() )
4480 return SPELL_FAILED_HIGHLEVEL
;
4484 case SPELL_EFFECT_LEAP
:
4485 case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
:
4487 float dis
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4488 float fx
= m_caster
->GetPositionX() + dis
* cos(m_caster
->GetOrientation());
4489 float fy
= m_caster
->GetPositionY() + dis
* sin(m_caster
->GetOrientation());
4490 // teleport a bit above terrain level to avoid falling below it
4491 float fz
= m_caster
->GetBaseMap()->GetHeight(fx
,fy
,m_caster
->GetPositionZ(),true);
4492 if(fz
<= INVALID_HEIGHT
) // note: this also will prevent use effect in instances without vmaps height enabled
4493 return SPELL_FAILED_TRY_AGAIN
;
4495 float caster_pos_z
= m_caster
->GetPositionZ();
4496 // Control the caster to not climb or drop when +-fz > 8
4497 if(!(fz
<= caster_pos_z
+ 8 && fz
>= caster_pos_z
- 8))
4498 return SPELL_FAILED_TRY_AGAIN
;
4500 // not allow use this effect at battleground until battleground start
4501 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4502 if(BattleGround
const *bg
= ((Player
*)m_caster
)->GetBattleGround())
4503 if(bg
->GetStatus() != STATUS_IN_PROGRESS
)
4504 return SPELL_FAILED_TRY_AGAIN
;
4507 case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF
:
4509 if (m_targets
.getUnitTarget() == m_caster
)
4510 return SPELL_FAILED_BAD_TARGETS
;
4517 for (int i
= 0; i
< 3; ++i
)
4519 switch(m_spellInfo
->EffectApplyAuraName
[i
])
4521 case SPELL_AURA_DUMMY
:
4524 switch(m_spellInfo
->Id
)
4527 if(m_caster
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)m_caster
)->IsInFeralForm())
4528 return SPELL_FAILED_ONLY_SHAPESHIFT
;
4535 case SPELL_AURA_MOD_POSSESS
:
4537 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4538 return SPELL_FAILED_UNKNOWN
;
4540 if(m_targets
.getUnitTarget() == m_caster
)
4541 return SPELL_FAILED_BAD_TARGETS
;
4543 if(m_caster
->GetPetGUID())
4544 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4546 if(m_caster
->GetCharmGUID())
4547 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4549 if(m_caster
->GetCharmerGUID())
4550 return SPELL_FAILED_CHARMED
;
4552 if(!m_targets
.getUnitTarget())
4553 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4555 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4556 return SPELL_FAILED_CHARMED
;
4558 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
4559 return SPELL_FAILED_HIGHLEVEL
;
4563 case SPELL_AURA_MOD_CHARM
:
4565 if(m_targets
.getUnitTarget() == m_caster
)
4566 return SPELL_FAILED_BAD_TARGETS
;
4568 if(m_caster
->GetPetGUID())
4569 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4571 if(m_caster
->GetCharmGUID())
4572 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4574 if(m_caster
->GetCharmerGUID())
4575 return SPELL_FAILED_CHARMED
;
4577 if(!m_targets
.getUnitTarget())
4578 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4580 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4581 return SPELL_FAILED_CHARMED
;
4583 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
4584 return SPELL_FAILED_HIGHLEVEL
;
4588 case SPELL_AURA_MOD_POSSESS_PET
:
4590 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4591 return SPELL_FAILED_UNKNOWN
;
4593 if(m_caster
->GetCharmGUID())
4594 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4596 if(m_caster
->GetCharmerGUID())
4597 return SPELL_FAILED_CHARMED
;
4599 Pet
* pet
= m_caster
->GetPet();
4601 return SPELL_FAILED_NO_PET
;
4603 if(pet
->GetCharmerGUID())
4604 return SPELL_FAILED_CHARMED
;
4608 case SPELL_AURA_MOUNTED
:
4610 if (m_caster
->IsInWater())
4611 return SPELL_FAILED_ONLY_ABOVEWATER
;
4613 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetTransport())
4614 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4616 // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
4617 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& !sMapStore
.LookupEntry(m_caster
->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell
&& !m_spellInfo
->AreaGroupId
)
4618 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4620 ShapeshiftForm form
= m_caster
->m_form
;
4621 if( form
== FORM_CAT
|| form
== FORM_TREE
|| form
== FORM_TRAVEL
||
4622 form
== FORM_AQUA
|| form
== FORM_BEAR
|| form
== FORM_DIREBEAR
||
4623 form
== FORM_CREATUREBEAR
|| form
== FORM_GHOSTWOLF
|| form
== FORM_FLIGHT
||
4624 form
== FORM_FLIGHT_EPIC
|| form
== FORM_MOONKIN
|| form
== FORM_METAMORPHOSIS
)
4625 return SPELL_FAILED_NOT_SHAPESHIFT
;
4629 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
4631 if(!m_targets
.getUnitTarget())
4632 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4634 // can be casted at non-friendly unit or own pet/charm
4635 if(m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()))
4636 return SPELL_FAILED_TARGET_FRIENDLY
;
4640 case SPELL_AURA_FLY
:
4641 case SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
:
4643 // not allow cast fly spells if not have req. skills (all spells is self target)
4644 // allow always ghost flight spells
4645 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->isAlive())
4647 if (!((Player
*)m_caster
)->IsKnowHowFlyIn(m_caster
->GetMapId(),zone
))
4648 return m_IsTriggeredSpell
? SPELL_FAILED_DONT_REPORT
: SPELL_FAILED_NOT_HERE
;
4652 case SPELL_AURA_PERIODIC_MANA_LEECH
:
4654 if (!m_targets
.getUnitTarget())
4655 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4657 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| m_CastItem
)
4660 if(m_targets
.getUnitTarget()->getPowerType() != POWER_MANA
)
4661 return SPELL_FAILED_BAD_TARGETS
;
4671 return SPELL_CAST_OK
;
4674 SpellCastResult
Spell::CheckPetCast(Unit
* target
)
4676 if(!m_caster
->isAlive())
4677 return SPELL_FAILED_CASTER_DEAD
;
4679 if(m_caster
->IsNonMeleeSpellCasted(false)) //prevent spellcast interruption by another spellcast
4680 return SPELL_FAILED_SPELL_IN_PROGRESS
;
4681 if(m_caster
->isInCombat() && IsNonCombatSpell(m_spellInfo
))
4682 return SPELL_FAILED_AFFECTING_COMBAT
;
4684 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)m_caster
)->isPet() || m_caster
->isCharmed()))
4686 //dead owner (pets still alive when owners ressed?)
4687 if(m_caster
->GetCharmerOrOwner() && !m_caster
->GetCharmerOrOwner()->isAlive())
4688 return SPELL_FAILED_CASTER_DEAD
;
4690 if(!target
&& m_targets
.getUnitTarget())
4691 target
= m_targets
.getUnitTarget();
4694 for(uint32 i
= 0; i
< 3; ++i
)
4696 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CHAIN_DAMAGE
||
4697 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND
||
4698 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND_2
||
4699 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_DUELVSPLAYER
||
4700 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_PARTY
||
4701 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CURRENT_ENEMY_COORDINATES
)
4705 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4710 m_targets
.setUnitTarget(target
);
4712 Unit
* _target
= m_targets
.getUnitTarget();
4714 if(_target
) //for target dead/target not valid
4716 if(!_target
->isAlive())
4717 return SPELL_FAILED_BAD_TARGETS
;
4719 if(IsPositiveSpell(m_spellInfo
->Id
))
4721 if(m_caster
->IsHostileTo(_target
))
4722 return SPELL_FAILED_BAD_TARGETS
;
4726 bool duelvsplayertar
= false;
4727 for(int j
= 0; j
< 3; ++j
)
4729 //TARGET_DUELVSPLAYER is positive AND negative
4730 duelvsplayertar
|= (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
);
4732 if(m_caster
->IsFriendlyTo(target
) && !duelvsplayertar
)
4734 return SPELL_FAILED_BAD_TARGETS
;
4739 if(((Creature
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
4740 return SPELL_FAILED_NOT_READY
;
4743 return CheckCast(true);
4746 SpellCastResult
Spell::CheckCasterAuras() const
4748 // Flag drop spells totally immuned to caster auras
4749 // FIXME: find more nice check for all totally immuned spells
4750 // AttributesEx3 & 0x10000000?
4751 if(m_spellInfo
->Id
== 23336 || m_spellInfo
->Id
== 23334 || m_spellInfo
->Id
== 34991)
4752 return SPELL_CAST_OK
;
4754 uint8 school_immune
= 0;
4755 uint32 mechanic_immune
= 0;
4756 uint32 dispel_immune
= 0;
4758 // Check if the spell grants school or mechanic immunity.
4759 // We use bitmasks so the loop is done only once and not on every aura check below.
4760 if ( m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
4762 for(int i
= 0; i
< 3; ++i
)
4764 if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_SCHOOL_IMMUNITY
)
4765 school_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
4766 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY
)
4767 mechanic_immune
|= 1 << uint32(m_spellInfo
->EffectMiscValue
[i
]);
4768 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_DISPEL_IMMUNITY
)
4769 dispel_immune
|= GetDispellMask(DispelType(m_spellInfo
->EffectMiscValue
[i
]));
4771 // immune movement impairment and loss of control
4772 if(m_spellInfo
->Id
== 42292)
4773 mechanic_immune
= IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK
;
4776 // Check whether the cast should be prevented by any state you might have.
4777 SpellCastResult prevented_reason
= SPELL_CAST_OK
;
4778 // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
4779 uint32 unitflag
= m_caster
->GetUInt32Value(UNIT_FIELD_FLAGS
); // Get unit state
4780 if(unitflag
& UNIT_FLAG_STUNNED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4781 prevented_reason
= SPELL_FAILED_STUNNED
;
4782 else if(unitflag
& UNIT_FLAG_CONFUSED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4783 prevented_reason
= SPELL_FAILED_CONFUSED
;
4784 else if(unitflag
& UNIT_FLAG_FLEEING
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4785 prevented_reason
= SPELL_FAILED_FLEEING
;
4786 else if(unitflag
& UNIT_FLAG_SILENCED
&& m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
)
4787 prevented_reason
= SPELL_FAILED_SILENCED
;
4788 else if(unitflag
& UNIT_FLAG_PACIFIED
&& m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
)
4789 prevented_reason
= SPELL_FAILED_PACIFIED
;
4791 // Attr must make flag drop spell totally immune from all effects
4792 if(prevented_reason
!= SPELL_CAST_OK
)
4794 if(school_immune
|| mechanic_immune
|| dispel_immune
)
4796 //Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
4797 Unit::AuraMap
const& auras
= m_caster
->GetAuras();
4798 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
4802 if( GetSpellMechanicMask(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()) & mechanic_immune
)
4804 if( GetSpellSchoolMask(itr
->second
->GetSpellProto()) & school_immune
)
4806 if( (1<<(itr
->second
->GetSpellProto()->Dispel
)) & dispel_immune
)
4809 // Make a second check for spell failed so the right SPELL_FAILED message is returned.
4810 // That is needed when your casting is prevented by multiple states and you are only immune to some of them.
4811 switch(itr
->second
->GetModifier()->m_auraname
)
4813 case SPELL_AURA_MOD_STUN
:
4814 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4815 return SPELL_FAILED_STUNNED
;
4817 case SPELL_AURA_MOD_CONFUSE
:
4818 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4819 return SPELL_FAILED_CONFUSED
;
4821 case SPELL_AURA_MOD_FEAR
:
4822 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4823 return SPELL_FAILED_FLEEING
;
4825 case SPELL_AURA_MOD_SILENCE
:
4826 case SPELL_AURA_MOD_PACIFY
:
4827 case SPELL_AURA_MOD_PACIFY_SILENCE
:
4828 if( m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
)
4829 return SPELL_FAILED_PACIFIED
;
4830 else if ( m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
)
4831 return SPELL_FAILED_SILENCED
;
4837 // You are prevented from casting and the spell casted does not grant immunity. Return a failed error.
4839 return prevented_reason
;
4841 return SPELL_CAST_OK
;
4844 bool Spell::CanAutoCast(Unit
* target
)
4846 uint64 targetguid
= target
->GetGUID();
4848 for(uint32 j
= 0; j
< 3; ++j
)
4850 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
)
4852 if( m_spellInfo
->StackAmount
<= 1)
4854 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4859 if(Aura
* aura
= target
->GetAura(m_spellInfo
->Id
, j
))
4860 if(aura
->GetStackAmount() >= m_spellInfo
->StackAmount
)
4864 else if ( IsAreaAuraEffect( m_spellInfo
->Effect
[j
] ))
4866 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4871 SpellCastResult result
= CheckPetCast(target
);
4873 if(result
== SPELL_CAST_OK
|| result
== SPELL_FAILED_UNIT_NOT_INFRONT
)
4876 //check if among target units, our WANTED target is as well (->only self cast spells return false)
4877 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
4878 if( ihit
->targetGUID
== targetguid
)
4881 return false; //target invalid
4884 SpellCastResult
Spell::CheckRange(bool strict
)
4888 // self cast doesn't need range checking -- also for Starshards fix
4889 if (m_spellInfo
->rangeIndex
== 1)
4890 return SPELL_CAST_OK
;
4892 if (strict
) //add radius of caster
4894 else //add radius of caster and ~5 yds "give"
4897 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4898 Unit
*target
= m_targets
.getUnitTarget();
4899 bool friendly
= target
? target
->IsFriendlyTo(m_caster
) : false;
4900 float max_range
= GetSpellMaxRange(srange
, friendly
) + range_mod
;
4901 float min_range
= GetSpellMinRange(srange
, friendly
);
4903 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4904 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RANGE
, max_range
, this);
4906 if(target
&& target
!= m_caster
)
4908 // distance from target in checks
4909 float dist
= m_caster
->GetCombatDistance(target
);
4911 if(dist
> max_range
)
4912 return SPELL_FAILED_OUT_OF_RANGE
; //0x5A;
4913 if(min_range
&& dist
< min_range
)
4914 return SPELL_FAILED_TOO_CLOSE
;
4915 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&&
4916 (m_spellInfo
->FacingCasterFlags
& SPELL_FACING_FLAG_INFRONT
) && !m_caster
->HasInArc( M_PI
, target
) )
4917 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4920 if(m_targets
.m_targetMask
== TARGET_FLAG_DEST_LOCATION
&& m_targets
.m_destX
!= 0 && m_targets
.m_destY
!= 0 && m_targets
.m_destZ
!= 0)
4922 if(!m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
, max_range
))
4923 return SPELL_FAILED_OUT_OF_RANGE
;
4924 if(min_range
&& m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
, min_range
))
4925 return SPELL_FAILED_TOO_CLOSE
;
4928 return SPELL_CAST_OK
;
4931 int32
Spell::CalculatePowerCost()
4933 // item cast not used power
4937 // Spell drain all exist power on cast (Only paladin lay of Hands)
4938 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DRAIN_ALL_POWER
)
4940 // If power type - health drain all
4941 if (m_spellInfo
->powerType
== POWER_HEALTH
)
4942 return m_caster
->GetHealth();
4943 // Else drain all power
4944 if (m_spellInfo
->powerType
< MAX_POWERS
)
4945 return m_caster
->GetPower(Powers(m_spellInfo
->powerType
));
4946 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4951 int32 powerCost
= m_spellInfo
->manaCost
;
4952 // PCT cost from total amount
4953 if (m_spellInfo
->ManaCostPercentage
)
4955 switch (m_spellInfo
->powerType
)
4957 // health as power used
4959 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateHealth() / 100;
4962 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateMana() / 100;
4967 case POWER_HAPPINESS
:
4968 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetMaxPower(Powers(m_spellInfo
->powerType
)) / 100;
4971 case POWER_RUNIC_POWER
:
4972 sLog
.outDebug("Spell::CalculateManaCost: Not implemented yet!");
4975 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4979 SpellSchools school
= GetFirstSchoolInMask(m_spellSchoolMask
);
4980 // Flat mod from caster auras by spell school
4981 powerCost
+= m_caster
->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER
+ school
);
4982 // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
4983 if ( m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST
)
4984 powerCost
+= m_caster
->GetAttackTime(OFF_ATTACK
)/100;
4985 // Apply cost mod by spell
4986 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4987 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, powerCost
, this);
4989 if(m_spellInfo
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
)
4990 powerCost
= int32(powerCost
/ (1.117f
* m_spellInfo
->spellLevel
/ m_caster
->getLevel() -0.1327f
));
4992 // PCT mod from user auras by school
4993 powerCost
= int32(powerCost
* (1.0f
+m_caster
->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+school
)));
4999 SpellCastResult
Spell::CheckPower()
5001 // item cast not used power
5003 return SPELL_CAST_OK
;
5005 // health as power used - need check health amount
5006 if(m_spellInfo
->powerType
== POWER_HEALTH
)
5008 if(m_caster
->GetHealth() <= m_powerCost
)
5009 return SPELL_FAILED_CASTER_AURASTATE
;
5010 return SPELL_CAST_OK
;
5012 // Check valid power type
5013 if( m_spellInfo
->powerType
>= MAX_POWERS
)
5015 sLog
.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo
->powerType
);
5016 return SPELL_FAILED_UNKNOWN
;
5019 SpellCastResult failReason
= CheckRuneCost(m_spellInfo
->runeCostID
);
5020 if(failReason
!= SPELL_CAST_OK
)
5023 // Check power amount
5024 Powers powerType
= Powers(m_spellInfo
->powerType
);
5025 if(m_caster
->GetPower(powerType
) < m_powerCost
)
5026 return SPELL_FAILED_NO_POWER
;
5028 return SPELL_CAST_OK
;
5031 SpellCastResult
Spell::CheckItems()
5033 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
5034 return SPELL_CAST_OK
;
5036 Player
* p_caster
= (Player
*)m_caster
;
5041 uint32 itemid
= m_CastItem
->GetEntry();
5042 if( !p_caster
->HasItemCount(itemid
, 1) )
5043 return SPELL_FAILED_ITEM_NOT_READY
;
5045 ItemPrototype
const *proto
= m_CastItem
->GetProto();
5047 return SPELL_FAILED_ITEM_NOT_READY
;
5049 for (int i
= 0; i
< 5; ++i
)
5050 if (proto
->Spells
[i
].SpellCharges
)
5051 if(m_CastItem
->GetSpellCharges(i
) == 0)
5052 return SPELL_FAILED_NO_CHARGES_REMAIN
;
5054 // consumable cast item checks
5055 if (proto
->Class
== ITEM_CLASS_CONSUMABLE
&& m_targets
.getUnitTarget())
5057 // such items should only fail if there is no suitable effect at all - see Rejuvenation Potions for example
5058 SpellCastResult failReason
= SPELL_CAST_OK
;
5059 for (int i
= 0; i
< 3; ++i
)
5061 // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster
5062 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_PET
)
5065 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_HEAL
)
5067 if (m_targets
.getUnitTarget()->GetHealth() == m_targets
.getUnitTarget()->GetMaxHealth())
5069 failReason
= SPELL_FAILED_ALREADY_AT_FULL_HEALTH
;
5074 failReason
= SPELL_CAST_OK
;
5079 // Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
5080 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
5082 if(m_spellInfo
->EffectMiscValue
[i
] < 0 || m_spellInfo
->EffectMiscValue
[i
] >= MAX_POWERS
)
5084 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
5088 Powers power
= Powers(m_spellInfo
->EffectMiscValue
[i
]);
5089 if (m_targets
.getUnitTarget()->GetPower(power
) == m_targets
.getUnitTarget()->GetMaxPower(power
))
5091 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
5096 failReason
= SPELL_CAST_OK
;
5101 if (failReason
!= SPELL_CAST_OK
)
5106 // check target item
5107 if(m_targets
.getItemTargetGUID())
5109 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
5110 return SPELL_FAILED_BAD_TARGETS
;
5112 if(!m_targets
.getItemTarget())
5113 return SPELL_FAILED_ITEM_GONE
;
5115 if(!m_targets
.getItemTarget()->IsFitToSpellRequirements(m_spellInfo
))
5116 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
5118 // if not item target then required item must be equipped
5121 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !((Player
*)m_caster
)->HasItemFitToSpellReqirements(m_spellInfo
))
5122 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
5125 // check spell focus object
5126 if(m_spellInfo
->RequiresSpellFocus
)
5128 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
5130 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5132 GameObject
* ok
= NULL
;
5133 MaNGOS::GameObjectFocusCheck
go_check(m_caster
,m_spellInfo
->RequiresSpellFocus
);
5134 MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
> checker(m_caster
, ok
, go_check
);
5136 TypeContainerVisitor
<MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
>, GridTypeMapContainer
> object_checker(checker
);
5137 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5138 cell_lock
->Visit(cell_lock
, object_checker
, *m_caster
->GetMap());
5141 return SPELL_FAILED_REQUIRES_SPELL_FOCUS
;
5143 focusObject
= ok
; // game object found in range
5146 // check reagents (ignore triggered spells with reagents processed by original spell) and special reagent ignore case.
5147 if (!m_IsTriggeredSpell
&& !p_caster
->CanNoReagentCast(m_spellInfo
))
5149 for(uint32 i
= 0; i
< 8; ++i
)
5151 if(m_spellInfo
->Reagent
[i
] <= 0)
5154 uint32 itemid
= m_spellInfo
->Reagent
[i
];
5155 uint32 itemcount
= m_spellInfo
->ReagentCount
[i
];
5157 // if CastItem is also spell reagent
5158 if( m_CastItem
&& m_CastItem
->GetEntry() == itemid
)
5160 ItemPrototype
const *proto
= m_CastItem
->GetProto();
5162 return SPELL_FAILED_ITEM_NOT_READY
;
5163 for(int s
= 0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
5165 // CastItem will be used up and does not count as reagent
5166 int32 charges
= m_CastItem
->GetSpellCharges(s
);
5167 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
5174 if( !p_caster
->HasItemCount(itemid
, itemcount
) )
5175 return SPELL_FAILED_ITEM_NOT_READY
; //0x54
5179 // check totem-item requirements (items presence in inventory)
5181 for(int i
= 0; i
< 2 ; ++i
)
5183 if(m_spellInfo
->Totem
[i
] != 0)
5185 if( p_caster
->HasItemCount(m_spellInfo
->Totem
[i
], 1) )
5194 return SPELL_FAILED_TOTEMS
; //0x7C
5196 // Check items for TotemCategory (items presence in inventory)
5197 uint32 TotemCategory
= 2;
5198 for(int i
= 0; i
< 2; ++i
)
5200 if(m_spellInfo
->TotemCategory
[i
] != 0)
5202 if( p_caster
->HasItemTotemCategory(m_spellInfo
->TotemCategory
[i
]) )
5211 if(TotemCategory
!= 0)
5212 return SPELL_FAILED_TOTEM_CATEGORY
; //0x7B
5214 // special checks for spell effects
5215 for(int i
= 0; i
< 3; ++i
)
5217 switch (m_spellInfo
->Effect
[i
])
5219 case SPELL_EFFECT_CREATE_ITEM
:
5221 if (!m_IsTriggeredSpell
&& m_spellInfo
->EffectItemType
[i
])
5223 ItemPosCountVec dest
;
5224 uint8 msg
= p_caster
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, m_spellInfo
->EffectItemType
[i
], 1 );
5225 if (msg
!= EQUIP_ERR_OK
)
5227 p_caster
->SendEquipError( msg
, NULL
, NULL
);
5228 return SPELL_FAILED_DONT_REPORT
;
5233 case SPELL_EFFECT_ENCHANT_ITEM
:
5234 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
5236 Item
* targetItem
= m_targets
.getItemTarget();
5238 return SPELL_FAILED_ITEM_NOT_FOUND
;
5240 if( targetItem
->GetProto()->ItemLevel
< m_spellInfo
->baseLevel
)
5241 return SPELL_FAILED_LOWLEVEL
;
5242 // Not allow enchant in trade slot for some enchant type
5243 if( targetItem
->GetOwner() != m_caster
)
5245 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5246 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5248 return SPELL_FAILED_ERROR
;
5249 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5250 return SPELL_FAILED_NOT_TRADEABLE
;
5254 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
5256 Item
*item
= m_targets
.getItemTarget();
5258 return SPELL_FAILED_ITEM_NOT_FOUND
;
5259 // Not allow enchant in trade slot for some enchant type
5260 if( item
->GetOwner() != m_caster
)
5262 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5263 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5265 return SPELL_FAILED_ERROR
;
5266 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5267 return SPELL_FAILED_NOT_TRADEABLE
;
5271 case SPELL_EFFECT_ENCHANT_HELD_ITEM
:
5272 // check item existence in effect code (not output errors at offhand hold item effect to main hand for example
5274 case SPELL_EFFECT_DISENCHANT
:
5276 if(!m_targets
.getItemTarget())
5277 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5279 // prevent disenchanting in trade slot
5280 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5281 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5283 ItemPrototype
const* itemProto
= m_targets
.getItemTarget()->GetProto();
5285 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5287 uint32 item_quality
= itemProto
->Quality
;
5288 // 2.0.x addon: Check player enchanting level against the item disenchanting requirements
5289 uint32 item_disenchantskilllevel
= itemProto
->RequiredDisenchantSkill
;
5290 if (item_disenchantskilllevel
== uint32(-1))
5291 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5292 if (item_disenchantskilllevel
> p_caster
->GetSkillValue(SKILL_ENCHANTING
))
5293 return SPELL_FAILED_LOW_CASTLEVEL
;
5294 if(item_quality
> 4 || item_quality
< 2)
5295 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5296 if(itemProto
->Class
!= ITEM_CLASS_WEAPON
&& itemProto
->Class
!= ITEM_CLASS_ARMOR
)
5297 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5298 if (!itemProto
->DisenchantID
)
5299 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5302 case SPELL_EFFECT_PROSPECTING
:
5304 if(!m_targets
.getItemTarget())
5305 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5306 //ensure item is a prospectable ore
5307 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_MINING_SUPP
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5308 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5309 //prevent prospecting in trade slot
5310 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5311 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5312 //Check for enough skill in jewelcrafting
5313 uint32 item_prospectingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5314 if(item_prospectingskilllevel
>p_caster
->GetSkillValue(SKILL_JEWELCRAFTING
))
5315 return SPELL_FAILED_LOW_CASTLEVEL
;
5316 //make sure the player has the required ores in inventory
5317 if(m_targets
.getItemTarget()->GetCount() < 5)
5318 return SPELL_FAILED_NEED_MORE_ITEMS
;
5320 if(!LootTemplates_Prospecting
.HaveLootFor(m_targets
.getItemTargetEntry()))
5321 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5325 case SPELL_EFFECT_MILLING
:
5327 if(!m_targets
.getItemTarget())
5328 return SPELL_FAILED_CANT_BE_MILLED
;
5329 //ensure item is a millable herb
5330 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_HERBS
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5331 return SPELL_FAILED_CANT_BE_MILLED
;
5332 //prevent milling in trade slot
5333 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5334 return SPELL_FAILED_CANT_BE_MILLED
;
5335 //Check for enough skill in inscription
5336 uint32 item_millingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5337 if(item_millingskilllevel
>p_caster
->GetSkillValue(SKILL_INSCRIPTION
))
5338 return SPELL_FAILED_LOW_CASTLEVEL
;
5339 //make sure the player has the required herbs in inventory
5340 if(m_targets
.getItemTarget()->GetCount() < 5)
5341 return SPELL_FAILED_NEED_MORE_ITEMS
;
5343 if(!LootTemplates_Milling
.HaveLootFor(m_targets
.getItemTargetEntry()))
5344 return SPELL_FAILED_CANT_BE_MILLED
;
5348 case SPELL_EFFECT_WEAPON_DAMAGE
:
5349 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
:
5351 if(m_caster
->GetTypeId() != TYPEID_PLAYER
) return SPELL_FAILED_TARGET_NOT_PLAYER
;
5352 if( m_attackType
!= RANGED_ATTACK
)
5354 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(m_attackType
);
5355 if(!pItem
|| pItem
->IsBroken())
5356 return SPELL_FAILED_EQUIPPED_ITEM
;
5358 switch(pItem
->GetProto()->SubClass
)
5360 case ITEM_SUBCLASS_WEAPON_THROWN
:
5362 uint32 ammo
= pItem
->GetEntry();
5363 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5364 return SPELL_FAILED_NO_AMMO
;
5366 case ITEM_SUBCLASS_WEAPON_GUN
:
5367 case ITEM_SUBCLASS_WEAPON_BOW
:
5368 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5370 uint32 ammo
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
5374 if(m_caster
->GetDummyAura(46699))
5375 break; // skip other checks
5377 return SPELL_FAILED_NO_AMMO
;
5380 ItemPrototype
const *ammoProto
= objmgr
.GetItemPrototype( ammo
);
5382 return SPELL_FAILED_NO_AMMO
;
5384 if(ammoProto
->Class
!= ITEM_CLASS_PROJECTILE
)
5385 return SPELL_FAILED_NO_AMMO
;
5387 // check ammo ws. weapon compatibility
5388 switch(pItem
->GetProto()->SubClass
)
5390 case ITEM_SUBCLASS_WEAPON_BOW
:
5391 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5392 if(ammoProto
->SubClass
!= ITEM_SUBCLASS_ARROW
)
5393 return SPELL_FAILED_NO_AMMO
;
5395 case ITEM_SUBCLASS_WEAPON_GUN
:
5396 if(ammoProto
->SubClass
!= ITEM_SUBCLASS_BULLET
)
5397 return SPELL_FAILED_NO_AMMO
;
5400 return SPELL_FAILED_NO_AMMO
;
5403 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5404 return SPELL_FAILED_NO_AMMO
;
5406 case ITEM_SUBCLASS_WEAPON_WAND
:
5417 return SPELL_CAST_OK
;
5420 void Spell::Delayed()
5422 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
5425 if (m_spellState
== SPELL_STATE_DELAYED
)
5426 return; // spell is active and can't be time-backed
5428 if(isDelayableNoMore()) // Spells may only be delayed twice
5431 // spells not loosing casting time ( slam, dynamites, bombs.. )
5432 if(!(m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_DAMAGE
))
5435 //check pushback reduce
5436 int32 delaytime
= 500; // spellcasting delay is normally 500ms
5437 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5438 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5439 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5440 if(delayReduce
>= 100)
5443 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5445 if(int32(m_timer
) + delaytime
> m_casttime
)
5447 delaytime
= m_casttime
- m_timer
;
5448 m_timer
= m_casttime
;
5451 m_timer
+= delaytime
;
5453 sLog
.outDetail("Spell %u partially interrupted for (%d) ms at damage", m_spellInfo
->Id
, delaytime
);
5455 WorldPacket
data(SMSG_SPELL_DELAYED
, 8+4);
5456 data
.append(m_caster
->GetPackGUID());
5457 data
<< uint32(delaytime
);
5459 m_caster
->SendMessageToSet(&data
, true);
5462 void Spell::DelayedChannel()
5464 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
|| getState() != SPELL_STATE_CASTING
)
5467 if(isDelayableNoMore()) // Spells may only be delayed twice
5470 //check pushback reduce
5471 int32 delaytime
= GetSpellDuration(m_spellInfo
) * 25 / 100; // channeling delay is normally 25% of its time per hit
5472 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5473 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5474 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5475 if(delayReduce
>= 100)
5478 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5480 if(int32(m_timer
) < delaytime
)
5482 delaytime
= m_timer
;
5486 m_timer
-= delaytime
;
5488 sLog
.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo
->Id
, delaytime
, m_timer
);
5490 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
5492 if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
5494 Unit
* unit
= m_caster
->GetGUID() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
5497 for (int j
= 0; j
< 3; ++j
)
5498 if( ihit
->effectMask
& (1 << j
) )
5499 unit
->DelayAura(m_spellInfo
->Id
, j
, delaytime
);
5505 for(int j
= 0; j
< 3; ++j
)
5507 // partially interrupt persistent area auras
5508 DynamicObject
* dynObj
= m_caster
->GetDynObject(m_spellInfo
->Id
, j
);
5510 dynObj
->Delay(delaytime
);
5513 SendChannelUpdate(m_timer
);
5516 void Spell::UpdatePointers()
5518 if(m_originalCasterGUID
==m_caster
->GetGUID())
5519 m_originalCaster
= m_caster
;
5522 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
,m_originalCasterGUID
);
5523 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
5526 m_targets
.Update(m_caster
);
5529 bool Spell::IsAffectedByAura(Aura
*aura
)
5531 return spellmgr
.IsAffectedByMod(m_spellInfo
, aura
->getAuraSpellMod());
5534 bool Spell::CheckTargetCreatureType(Unit
* target
) const
5536 uint32 spellCreatureTargetMask
= m_spellInfo
->TargetCreatureType
;
5538 // Curse of Doom & Exorcism: not find another way to fix spell target check :/
5539 if (m_spellInfo
->SpellFamilyName
==SPELLFAMILY_WARLOCK
&& m_spellInfo
->Category
== 1179 ||
5540 // TODO: will be removed in 3.2.x
5541 m_spellInfo
->SpellFamilyName
==SPELLFAMILY_PALADIN
&& m_spellInfo
->Category
== 19)
5543 // not allow cast at player
5544 if(target
->GetTypeId()==TYPEID_PLAYER
)
5547 spellCreatureTargetMask
= 0x7FF;
5550 // Dismiss Pet and Taming Lesson skipped
5551 if(m_spellInfo
->Id
== 2641 || m_spellInfo
->Id
== 23356)
5552 spellCreatureTargetMask
= 0;
5554 if (spellCreatureTargetMask
)
5556 uint32 TargetCreatureType
= target
->GetCreatureTypeMask();
5558 return !TargetCreatureType
|| (spellCreatureTargetMask
& TargetCreatureType
);
5563 CurrentSpellTypes
Spell::GetCurrentContainer()
5565 if (IsNextMeleeSwingSpell())
5566 return(CURRENT_MELEE_SPELL
);
5567 else if (IsAutoRepeat())
5568 return(CURRENT_AUTOREPEAT_SPELL
);
5569 else if (IsChanneledSpell(m_spellInfo
))
5570 return(CURRENT_CHANNELED_SPELL
);
5572 return(CURRENT_GENERIC_SPELL
);
5575 bool Spell::CheckTarget( Unit
* target
, uint32 eff
)
5577 // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets)
5578 if(m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SELF
)
5580 if (!CheckTargetCreatureType(target
))
5584 // Check Aura spell req (need for AoE spells)
5585 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
5587 if (m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
5590 // Check targets for not_selectable unit flag and remove
5591 // A player can cast spells on his pet (or other controlled unit) though in any state
5592 if (target
!= m_caster
&& target
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
5594 // any unattackable target skipped
5595 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
))
5598 // unselectable targets skipped in all cases except TARGET_SCRIPT targeting
5599 // in case TARGET_SCRIPT target selected by server always and can't be cheated
5600 if( target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NOT_SELECTABLE
) &&
5601 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SCRIPT
&&
5602 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_SCRIPT
)
5606 //Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
5607 if( target
!= m_caster
&& target
->GetTypeId() == TYPEID_PLAYER
)
5609 if(((Player
*)target
)->GetVisibility() == VISIBILITY_OFF
)
5612 if(((Player
*)target
)->isGameMaster() && !IsPositiveSpell(m_spellInfo
->Id
))
5616 //Check targets for LOS visibility (except spells without range limitations )
5617 switch(m_spellInfo
->Effect
[eff
])
5619 case SPELL_EFFECT_SUMMON_PLAYER
: // from anywhere
5621 case SPELL_EFFECT_DUMMY
:
5622 if(m_spellInfo
->Id
!= 20577) // Cannibalize
5625 case SPELL_EFFECT_RESURRECT_NEW
:
5626 // player far away, maybe his corpse near?
5627 if(target
!= m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
5629 if(!m_targets
.getCorpseTargetGUID())
5632 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
, m_targets
.getCorpseTargetGUID());
5636 if(target
->GetGUID() != corpse
->GetOwnerGUID())
5639 if(!corpse
->IsWithinLOSInMap(m_caster
))
5643 // all ok by some way or another, skip normal check
5645 default: // normal case
5646 // Get GO cast coordinates if original caster -> GO
5647 WorldObject
*caster
= NULL
;
5648 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
5649 caster
= m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
5652 if(target
!= m_caster
&& !target
->IsWithinLOSInMap(caster
))
5660 bool Spell::IsNeedSendToClient() const
5662 return m_spellInfo
->SpellVisual
[0] || m_spellInfo
->SpellVisual
[1] || IsChanneledSpell(m_spellInfo
) ||
5663 m_spellInfo
->speed
> 0.0f
|| !m_triggeredByAuraSpell
&& !m_IsTriggeredSpell
;
5666 bool Spell::HaveTargetsForEffect( uint8 effect
) const
5668 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin(); itr
!= m_UniqueTargetInfo
.end(); ++itr
)
5669 if(itr
->effectMask
& (1 << effect
))
5672 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin(); itr
!= m_UniqueGOTargetInfo
.end(); ++itr
)
5673 if(itr
->effectMask
& (1 << effect
))
5676 for(std::list
<ItemTargetInfo
>::const_iterator itr
= m_UniqueItemInfo
.begin(); itr
!= m_UniqueItemInfo
.end(); ++itr
)
5677 if(itr
->effectMask
& (1 << effect
))
5683 SpellEvent::SpellEvent(Spell
* spell
) : BasicEvent()
5688 SpellEvent::~SpellEvent()
5690 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5693 if (m_Spell
->IsDeletable())
5699 sLog
.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
5700 (m_Spell
->GetCaster()->GetTypeId() == TYPEID_PLAYER
? "Player" : "Creature"), m_Spell
->GetCaster()->GetGUIDLow(), m_Spell
->m_spellInfo
->Id
);
5704 bool SpellEvent::Execute(uint64 e_time
, uint32 p_time
)
5706 // update spell if it is not finished
5707 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5708 m_Spell
->update(p_time
);
5710 // check spell state to process
5711 switch (m_Spell
->getState())
5713 case SPELL_STATE_FINISHED
:
5715 // spell was finished, check deletable state
5716 if (m_Spell
->IsDeletable())
5718 // check, if we do have unfinished triggered spells
5719 return true; // spell is deletable, finish event
5721 // event will be re-added automatically at the end of routine)
5724 case SPELL_STATE_CASTING
:
5726 // this spell is in channeled state, process it on the next update
5727 // event will be re-added automatically at the end of routine)
5730 case SPELL_STATE_DELAYED
:
5732 // first, check, if we have just started
5733 if (m_Spell
->GetDelayStart() != 0)
5735 // no, we aren't, do the typical update
5736 // check, if we have channeled spell on our hands
5737 if (IsChanneledSpell(m_Spell
->m_spellInfo
))
5739 // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish
5740 // check, if we have casting anything else except this channeled spell and autorepeat
5741 if (m_Spell
->GetCaster()->IsNonMeleeSpellCasted(false, true, true))
5743 // another non-melee non-delayed spell is casted now, abort
5748 // do the action (pass spell to channeling state)
5749 m_Spell
->handle_immediate();
5751 // event will be re-added automatically at the end of routine)
5755 // run the spell handler and think about what we can do next
5756 uint64 t_offset
= e_time
- m_Spell
->GetDelayStart();
5757 uint64 n_offset
= m_Spell
->handle_delayed(t_offset
);
5760 // re-add us to the queue
5761 m_Spell
->GetCaster()->m_Events
.AddEvent(this, m_Spell
->GetDelayStart() + n_offset
, false);
5762 return false; // event not complete
5765 // finish update event will be re-added automatically at the end of routine)
5770 // delaying had just started, record the moment
5771 m_Spell
->SetDelayStart(e_time
);
5772 // re-plan the event for the delay moment
5773 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ m_Spell
->GetDelayMoment(), false);
5774 return false; // event not complete
5781 // event will be re-added automatically at the end of routine)
5785 // spell processing not complete, plan event on the next update interval
5786 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ 1, false);
5787 return false; // event not complete
5790 void SpellEvent::Abort(uint64
/*e_time*/)
5792 // oops, the spell we try to do is aborted
5793 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
5797 bool SpellEvent::IsDeletable() const
5799 return m_Spell
->IsDeletable();
5802 SpellCastResult
Spell::CanOpenLock(uint32 effIndex
, uint32 lockId
, SkillType
& skillId
, int32
& reqSkillValue
, int32
& skillValue
)
5804 if(!lockId
) // possible case for GO and maybe for items.
5805 return SPELL_CAST_OK
;
5808 LockEntry
const *lockInfo
= sLockStore
.LookupEntry(lockId
);
5811 return SPELL_FAILED_BAD_TARGETS
;
5813 bool reqKey
= false; // some locks not have reqs
5815 for(int j
= 0; j
< 8; ++j
)
5817 switch(lockInfo
->Type
[j
])
5819 // check key item (many fit cases can be)
5821 if(lockInfo
->Index
[j
] && m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->Index
[j
])
5822 return SPELL_CAST_OK
;
5825 // check key skill (only single first fit case can be)
5826 case LOCK_KEY_SKILL
:
5830 // wrong locktype, skip
5831 if(uint32(m_spellInfo
->EffectMiscValue
[effIndex
]) != lockInfo
->Index
[j
])
5834 skillId
= SkillByLockType(LockType(lockInfo
->Index
[j
]));
5836 if ( skillId
!= SKILL_NONE
)
5838 // skill bonus provided by casting spell (mostly item spells)
5839 // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value)
5840 uint32 spellSkillBonus
= uint32(m_currentBasePoints
[effIndex
]+1);
5841 reqSkillValue
= lockInfo
->Skill
[j
];
5843 // castitem check: rogue using skeleton keys. the skill values should not be added in this case.
5844 skillValue
= m_CastItem
|| m_caster
->GetTypeId()!= TYPEID_PLAYER
?
5845 0 : ((Player
*)m_caster
)->GetSkillValue(skillId
);
5847 skillValue
+= spellSkillBonus
;
5849 if (skillValue
< reqSkillValue
)
5850 return SPELL_FAILED_LOW_CASTLEVEL
;
5853 return SPELL_CAST_OK
;
5859 return SPELL_FAILED_BAD_TARGETS
;
5861 return SPELL_CAST_OK
;
5864 void Spell::FillAreaTargets( UnitList
& TagUnitMap
, float x
, float y
, float radius
, SpellNotifyPushType pushType
, SpellTargets spellTargets
)
5866 CellPair
p(MaNGOS::ComputeCellPair(x
, y
));
5868 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5870 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, pushType
, spellTargets
);
5871 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
5872 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
5873 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5874 cell_lock
->Visit(cell_lock
, world_notifier
, *m_caster
->GetMap());
5875 cell_lock
->Visit(cell_lock
, grid_notifier
, *m_caster
->GetMap());
5878 void Spell::FillRaidOrPartyTargets( UnitList
&TagUnitMap
, Unit
* member
, Unit
* center
, float radius
, bool raid
, bool withPets
, bool withcaster
)
5880 Player
*pMember
= member
->GetCharmerOrOwnerPlayerOrPlayerItself();
5881 Group
*pGroup
= pMember
? pMember
->GetGroup() : NULL
;
5885 uint8 subgroup
= pMember
->GetSubGroup();
5887 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
5889 Player
* Target
= itr
->getSource();
5891 // IsHostileTo check duel and controlled by enemy
5892 if (Target
&& (raid
|| subgroup
==Target
->GetSubGroup())
5893 && !m_caster
->IsHostileTo(Target
))
5895 if ((Target
==center
|| center
->IsWithinDistInMap(Target
, radius
)) &&
5896 (withcaster
|| Target
!= m_caster
))
5897 TagUnitMap
.push_back(Target
);
5900 if (Pet
* pet
= Target
->GetPet())
5901 if ((pet
==center
|| center
->IsWithinDistInMap(pet
, radius
)) &&
5902 (withcaster
|| pet
!= m_caster
))
5903 TagUnitMap
.push_back(pet
);
5909 Unit
* ownerOrSelf
= pMember
? pMember
: member
->GetCharmerOrOwnerOrSelf();
5910 if ((ownerOrSelf
==center
|| center
->IsWithinDistInMap(ownerOrSelf
, radius
)) &&
5911 (withcaster
|| ownerOrSelf
!= m_caster
))
5912 TagUnitMap
.push_back(ownerOrSelf
);
5915 if (Pet
* pet
= ownerOrSelf
->GetPet())
5916 if ((pet
==center
|| center
->IsWithinDistInMap(pet
, radius
)) &&
5917 (withcaster
|| pet
!= m_caster
))
5918 TagUnitMap
.push_back(pet
);
5922 void Spell::FillRaidOrPartyManaPriorityTargets( UnitList
&TagUnitMap
, Unit
* member
, Unit
* center
, float radius
, uint32 count
, bool raid
, bool withPets
, bool withCaster
)
5924 FillRaidOrPartyTargets(TagUnitMap
, member
, center
, radius
, raid
, withPets
, withCaster
);
5926 PrioritizeManaUnitQueue manaUsers
;
5927 for(UnitList::const_iterator itr
= TagUnitMap
.begin(); itr
!= TagUnitMap
.end() && manaUsers
.size() < count
; ++itr
)
5928 if ((*itr
)->getPowerType() == POWER_MANA
&& !(*itr
)->isDead())
5929 manaUsers
.push(PrioritizeManaUnitWraper(*itr
));
5932 while(!manaUsers
.empty())
5934 TagUnitMap
.push_back(manaUsers
.top().getUnit());
5939 void Spell::FillRaidOrPartyHealthPriorityTargets( UnitList
&TagUnitMap
, Unit
* member
, Unit
* center
, float radius
, uint32 count
, bool raid
, bool withPets
, bool withCaster
)
5941 FillRaidOrPartyTargets(TagUnitMap
, member
, center
, radius
, raid
, withPets
, withCaster
);
5943 PrioritizeHealthUnitQueue healthQueue
;
5944 for(UnitList::const_iterator itr
= TagUnitMap
.begin(); itr
!= TagUnitMap
.end() && healthQueue
.size() < count
; ++itr
)
5945 if (!(*itr
)->isDead())
5946 healthQueue
.push(PrioritizeHealthUnitWraper(*itr
));
5949 while(!healthQueue
.empty())
5951 TagUnitMap
.push_back(healthQueue
.top().getUnit());