2 * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "GridNotifiers.h"
24 #include "GridNotifiersImpl.h"
27 #include "UpdateMask.h"
29 #include "ObjectMgr.h"
35 #include "DynamicObject.h"
37 #include "UpdateData.h"
38 #include "MapManager.h"
39 #include "ObjectAccessor.h"
41 #include "Policies/SingletonImp.h"
42 #include "SharedDefines.h"
44 #include "VMapFactory.h"
45 #include "BattleGround.h"
48 #define SPELL_CHANNEL_UPDATE_INTERVAL (1 * IN_MILISECONDS)
50 extern pEffect SpellEffects
[TOTAL_SPELL_EFFECTS
];
52 class PrioritizeManaUnitWraper
55 explicit PrioritizeManaUnitWraper(Unit
* unit
) : i_unit(unit
)
57 uint32 maxmana
= unit
->GetMaxPower(POWER_MANA
);
58 i_percent
= maxmana
? unit
->GetPower(POWER_MANA
) * 100 / maxmana
: 101;
60 Unit
* getUnit() const { return i_unit
; }
61 uint32
getPercent() const { return i_percent
; }
69 int operator()( PrioritizeManaUnitWraper
const& x
, PrioritizeManaUnitWraper
const& y
) const
71 return x
.getPercent() < y
.getPercent();
75 typedef std::priority_queue
<PrioritizeManaUnitWraper
, std::vector
<PrioritizeManaUnitWraper
>, PrioritizeMana
> PrioritizeManaUnitQueue
;
77 class PrioritizeHealthUnitWraper
80 explicit PrioritizeHealthUnitWraper(Unit
* unit
) : i_unit(unit
)
82 i_percent
= unit
->GetHealth() * 100 / unit
->GetMaxHealth();
84 Unit
* getUnit() const { return i_unit
; }
85 uint32
getPercent() const { return i_percent
; }
91 struct PrioritizeHealth
93 int operator()( PrioritizeHealthUnitWraper
const& x
, PrioritizeHealthUnitWraper
const& y
) const
95 return x
.getPercent() < y
.getPercent();
99 typedef std::priority_queue
<PrioritizeHealthUnitWraper
, std::vector
<PrioritizeHealthUnitWraper
>, PrioritizeHealth
> PrioritizeHealthUnitQueue
;
101 bool IsQuestTameSpell(uint32 spellId
)
103 SpellEntry
const *spellproto
= sSpellStore
.LookupEntry(spellId
);
107 return spellproto
->Effect
[EFFECT_INDEX_0
] == SPELL_EFFECT_THREAT
108 && spellproto
->Effect
[EFFECT_INDEX_1
] == SPELL_EFFECT_APPLY_AURA
&& spellproto
->EffectApplyAuraName
[EFFECT_INDEX_1
] == SPELL_AURA_DUMMY
;
111 SpellCastTargets::SpellCastTargets()
117 m_unitTargetGUID
= 0;
119 m_CorpseTargetGUID
= 0;
120 m_itemTargetGUID
= 0;
121 m_itemTargetEntry
= 0;
123 m_srcX
= m_srcY
= m_srcZ
= m_destX
= m_destY
= m_destZ
= 0.0f
;
128 SpellCastTargets::~SpellCastTargets()
132 void SpellCastTargets::setUnitTarget(Unit
*target
)
137 m_destX
= target
->GetPositionX();
138 m_destY
= target
->GetPositionY();
139 m_destZ
= target
->GetPositionZ();
140 m_unitTarget
= target
;
141 m_unitTargetGUID
= target
->GetGUID();
142 m_targetMask
|= TARGET_FLAG_UNIT
;
145 void SpellCastTargets::setDestination(float x
, float y
, float z
)
150 m_targetMask
|= TARGET_FLAG_DEST_LOCATION
;
153 void SpellCastTargets::setSource(float x
, float y
, float z
)
158 m_targetMask
|= TARGET_FLAG_SOURCE_LOCATION
;
161 void SpellCastTargets::setGOTarget(GameObject
*target
)
164 m_GOTargetGUID
= target
->GetGUID();
165 // m_targetMask |= TARGET_FLAG_OBJECT;
168 void SpellCastTargets::setItemTarget(Item
* item
)
174 m_itemTargetGUID
= item
->GetGUID();
175 m_itemTargetEntry
= item
->GetEntry();
176 m_targetMask
|= TARGET_FLAG_ITEM
;
179 void SpellCastTargets::setCorpseTarget(Corpse
* corpse
)
181 m_CorpseTargetGUID
= corpse
->GetGUID();
184 void SpellCastTargets::Update(Unit
* caster
)
186 m_GOTarget
= m_GOTargetGUID
? caster
->GetMap()->GetGameObject(m_GOTargetGUID
) : NULL
;
187 m_unitTarget
= m_unitTargetGUID
?
188 ( m_unitTargetGUID
== caster
->GetGUID() ? caster
: ObjectAccessor::GetUnit(*caster
, m_unitTargetGUID
) ) :
192 if(caster
->GetTypeId() == TYPEID_PLAYER
)
194 if(m_targetMask
& TARGET_FLAG_ITEM
)
195 m_itemTarget
= ((Player
*)caster
)->GetItemByGuid(m_itemTargetGUID
);
196 else if(m_targetMask
& TARGET_FLAG_TRADE_ITEM
)
198 Player
* pTrader
= ((Player
*)caster
)->GetTrader();
199 if(pTrader
&& m_itemTargetGUID
< TRADE_SLOT_COUNT
)
200 m_itemTarget
= pTrader
->GetItemByPos(pTrader
->GetItemPosByTradeSlot(uint32(m_itemTargetGUID
)));
203 m_itemTargetEntry
= m_itemTarget
->GetEntry();
207 bool SpellCastTargets::read ( WorldPacket
* data
, Unit
*caster
)
209 if(data
->rpos() + 4 > data
->size())
212 *data
>> m_targetMask
;
214 if(m_targetMask
== TARGET_FLAG_SELF
)
216 m_destX
= caster
->GetPositionX();
217 m_destY
= caster
->GetPositionY();
218 m_destZ
= caster
->GetPositionZ();
219 m_unitTarget
= caster
;
220 m_unitTargetGUID
= caster
->GetGUID();
224 // TARGET_FLAG_UNK2 is used for non-combat pets, maybe other?
225 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_UNK2
))
226 if(!data
->readPackGUID(m_unitTargetGUID
))
229 if( m_targetMask
& ( TARGET_FLAG_OBJECT
))
230 if(!data
->readPackGUID(m_GOTargetGUID
))
233 if(( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
)) && caster
->GetTypeId() == TYPEID_PLAYER
)
234 if(!data
->readPackGUID(m_itemTargetGUID
))
237 if( m_targetMask
& (TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
238 if(!data
->readPackGUID(m_CorpseTargetGUID
))
241 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
243 if(data
->rpos() + 1 + 4 + 4 + 4 > data
->size())
246 if(!data
->readPackGUID(m_unitTargetGUID
))
249 *data
>> m_srcX
>> m_srcY
>> m_srcZ
;
250 if(!MaNGOS::IsValidMapCoord(m_srcX
, m_srcY
, m_srcZ
))
254 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
256 if(data
->rpos() + 1 + 4 + 4 + 4 > data
->size())
259 if(!data
->readPackGUID(m_unitTargetGUID
))
262 *data
>> m_destX
>> m_destY
>> m_destZ
;
263 if(!MaNGOS::IsValidMapCoord(m_destX
, m_destY
, m_destZ
))
267 if( m_targetMask
& TARGET_FLAG_STRING
)
269 if(data
->rpos() + 1 > data
->size())
272 *data
>> m_strTarget
;
275 // find real units/GOs
280 void SpellCastTargets::write ( WorldPacket
* data
)
282 *data
<< uint32(m_targetMask
);
284 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_PVP_CORPSE
| TARGET_FLAG_OBJECT
| TARGET_FLAG_CORPSE
| TARGET_FLAG_UNK2
) )
286 if(m_targetMask
& TARGET_FLAG_UNIT
)
289 data
->append(m_unitTarget
->GetPackGUID());
293 else if( m_targetMask
& TARGET_FLAG_OBJECT
)
296 data
->append(m_GOTarget
->GetPackGUID());
300 else if( m_targetMask
& ( TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
301 data
->appendPackGUID(m_CorpseTargetGUID
);
306 if( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
) )
309 data
->append(m_itemTarget
->GetPackGUID());
314 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
317 data
->append(m_unitTarget
->GetPackGUID());
321 *data
<< m_srcX
<< m_srcY
<< m_srcZ
;
324 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
327 data
->append(m_unitTarget
->GetPackGUID());
331 *data
<< m_destX
<< m_destY
<< m_destZ
;
334 if( m_targetMask
& TARGET_FLAG_STRING
)
335 *data
<< m_strTarget
;
338 Spell::Spell( Unit
* Caster
, SpellEntry
const *info
, bool triggered
, uint64 originalCasterGUID
, Spell
** triggeringContainer
)
340 ASSERT( Caster
!= NULL
&& info
!= NULL
);
341 ASSERT( info
== sSpellStore
.LookupEntry( info
->Id
) && "`info` must be pointer to sSpellStore element");
345 m_selfContainer
= NULL
;
346 m_triggeringContainer
= triggeringContainer
;
347 m_referencedFromCurrentSpell
= false;
348 m_executedCurrently
= false;
350 m_delayAtDamageCount
= 0;
352 m_applyMultiplierMask
= 0;
354 // Get data for type of attack
355 m_attackType
= GetWeaponAttackType(m_spellInfo
);
357 m_spellSchoolMask
= GetSpellSchoolMask(info
); // Can be override for some spell (wand shoot for example)
359 if(m_attackType
== RANGED_ATTACK
)
362 if((m_caster
->getClassMask() & CLASSMASK_WAND_USERS
) != 0 && m_caster
->GetTypeId() == TYPEID_PLAYER
)
364 if(Item
* pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(RANGED_ATTACK
))
365 m_spellSchoolMask
= SpellSchoolMask(1 << pItem
->GetProto()->Damage
[0].DamageType
);
368 // Set health leech amount to zero
371 if(originalCasterGUID
)
372 m_originalCasterGUID
= originalCasterGUID
;
374 m_originalCasterGUID
= m_caster
->GetGUID();
376 UpdateOriginalCasterPointer();
378 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
379 m_currentBasePoints
[i
] = m_spellInfo
->EffectBasePoints
[i
];
381 m_spellState
= SPELL_STATE_NULL
;
383 m_castPositionX
= m_castPositionY
= m_castPositionZ
= 0;
384 m_TriggerSpells
.clear();
385 m_preCastSpells
.clear();
386 m_IsTriggeredSpell
= triggered
;
387 //m_AreaAura = false;
392 gameObjTarget
= NULL
;
396 m_triggeredByAuraSpell
= NULL
;
398 //Auto Shot & Shoot (wand)
399 m_autoRepeat
= IsAutoRepeatRangedSpell(m_spellInfo
);
402 m_powerCost
= 0; // setup to correct value in Spell::prepare, don't must be used before.
403 m_casttime
= 0; // setup to correct value in Spell::prepare, don't must be used before.
404 m_timer
= 0; // will set to cast time in prepare
406 m_needAliveTargetMask
= 0;
408 // determine reflection
409 m_canReflect
= false;
411 if(m_spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
&& !(m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
))
413 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
415 if (m_spellInfo
->Effect
[j
] == 0)
418 if(!IsPositiveTarget(m_spellInfo
->EffectImplicitTargetA
[j
], m_spellInfo
->EffectImplicitTargetB
[j
]))
421 m_canReflect
= (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NEGATIVE
) ? true : false;
438 WorldObject
* Spell::FindCorpseUsing()
440 // non-standard target selection
441 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
442 float max_range
= GetSpellMaxRange(srange
);
444 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
446 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
449 WorldObject
* result
= NULL
;
451 T
u_check(m_caster
, max_range
);
452 MaNGOS::WorldObjectSearcher
<T
> searcher(m_caster
, result
, u_check
);
454 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<T
>, GridTypeMapContainer
> grid_searcher(searcher
);
455 cell
.Visit(p
, grid_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
459 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<T
>, WorldTypeMapContainer
> world_searcher(searcher
);
460 cell
.Visit(p
, world_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
466 void Spell::FillTargetMap()
468 // TODO: ADD the correct target FILLS!!!!!!
470 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
472 // not call for empty effect.
473 // Also some spells use not used effect targets for store targets for dummy effect in triggered spells
474 if(m_spellInfo
->Effect
[i
] == 0)
477 // targets for TARGET_SCRIPT_COORDINATES (A) and TARGET_SCRIPT
478 // for TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT (A) all is checked in Spell::CheckCast and in Spell::CheckItem
479 // filled in Spell::CheckCast call
480 if(m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT_COORDINATES
||
481 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT
||
482 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
||
483 (m_spellInfo
->EffectImplicitTargetB
[i
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
))
486 // TODO: find a way so this is not needed?
487 // for area auras always add caster as target (needed for totems for example)
488 if(IsAreaAuraEffect(m_spellInfo
->Effect
[i
]))
489 AddUnitTarget(m_caster
, SpellEffectIndex(i
));
491 std::list
<Unit
*> tmpUnitMap
;
493 // TargetA/TargetB dependent from each other, we not switch to full support this dependences
494 // but need it support in some know cases
495 switch(m_spellInfo
->EffectImplicitTargetA
[i
])
498 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
501 SetTargetMap(SpellEffectIndex(i
), TARGET_EFFECT_SELECT
, tmpUnitMap
);
504 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
509 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
512 case TARGET_EFFECT_SELECT
:
513 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
515 case TARGET_AREAEFFECT_INSTANT
: // use B case that not dependent from from A in fact
516 if((m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
) == 0)
517 m_targets
.setDestination(m_caster
->GetPositionX(), m_caster
->GetPositionY(), m_caster
->GetPositionZ());
518 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
520 case TARGET_BEHIND_VICTIM
: // use B case that not dependent from from A in fact
521 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
524 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
525 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
529 case TARGET_EFFECT_SELECT
:
530 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
533 case TARGET_EFFECT_SELECT
:
534 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
536 case TARGET_INNKEEPER_COORDINATES
:
537 case TARGET_TABLE_X_Y_Z_COORDINATES
:
538 case TARGET_CASTER_COORDINATES
:
539 case TARGET_SCRIPT_COORDINATES
:
540 case TARGET_CURRENT_ENEMY_COORDINATES
:
541 case TARGET_DUELVSPLAYER_COORDINATES
:
542 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
543 case TARGET_POINT_AT_NORTH
:
544 case TARGET_POINT_AT_SOUTH
:
545 case TARGET_POINT_AT_EAST
:
546 case TARGET_POINT_AT_WEST
:
547 case TARGET_POINT_AT_NE
:
548 case TARGET_POINT_AT_NW
:
549 case TARGET_POINT_AT_SE
:
550 case TARGET_POINT_AT_SW
:
551 // need some target for processing
552 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
553 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
556 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
560 case TARGET_CASTER_COORDINATES
:
561 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
563 case TARGET_ALL_ENEMY_IN_AREA
:
564 // Note: this hack with search required until GO casting not implemented
565 // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support
566 // currently each enemy selected explicitly and self cast damage
567 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
)
569 if(m_targets
.getUnitTarget())
570 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
574 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
575 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
579 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
580 tmpUnitMap
.push_back(m_caster
);
583 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
584 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
588 case TARGET_TABLE_X_Y_Z_COORDINATES
:
589 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
592 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
594 // need some target for processing
595 SetTargetMap(SpellEffectIndex(i
), TARGET_EFFECT_SELECT
, tmpUnitMap
);
597 case TARGET_AREAEFFECT_INSTANT
: // All 17/7 pairs used for dest teleportation, A processed in effect code
598 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
601 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
602 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
607 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
610 case TARGET_EFFECT_SELECT
:
611 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
613 // most A/B target pairs is self->negative and not expect adding caster to target list
615 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
620 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
623 case TARGET_EFFECT_SELECT
:
624 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
626 case TARGET_SCRIPT_COORDINATES
: // B case filled in CheckCast but we need fill unit list base at A case
627 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
630 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
631 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
637 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
639 Player
*me
= (Player
*)m_caster
;
640 for (std::list
<Unit
*>::const_iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end(); ++itr
)
642 Unit
*owner
= (*itr
)->GetOwner();
643 Unit
*u
= owner
? owner
: (*itr
);
644 if(u
!=m_caster
&& u
->IsPvP() && (!me
->duel
|| me
->duel
->opponent
!= u
))
647 me
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
653 for (std::list
<Unit
*>::iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end();)
655 if (!CheckTarget (*itr
, SpellEffectIndex(i
)))
657 itr
= tmpUnitMap
.erase(itr
);
664 for(std::list
<Unit
*>::const_iterator iunit
= tmpUnitMap
.begin(); iunit
!= tmpUnitMap
.end(); ++iunit
)
665 AddUnitTarget((*iunit
), SpellEffectIndex(i
));
669 void Spell::prepareDataForTriggerSystem()
671 //==========================================================================================
672 // Now fill data for trigger system, need know:
673 // an spell trigger another or not ( m_canTrigger )
674 // Create base triggers flags for Attacker and Victim ( m_procAttacker and m_procVictim)
675 //==========================================================================================
676 // Fill flag can spell trigger or not
677 // TODO: possible exist spell attribute for this
678 m_canTrigger
= false;
681 m_canTrigger
= false; // Do not trigger from item cast spell
682 else if (!m_IsTriggeredSpell
)
683 m_canTrigger
= true; // Normal cast - can trigger
684 else if (!m_triggeredByAuraSpell
)
685 m_canTrigger
= true; // Triggered from SPELL_EFFECT_TRIGGER_SPELL - can trigger
687 if (!m_canTrigger
) // Exceptions (some periodic triggers)
689 switch (m_spellInfo
->SpellFamilyName
)
691 case SPELLFAMILY_MAGE
:
692 // Arcane Missles / Blizzard triggers need do it
693 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000200080))
695 // Clearcasting trigger need do it
696 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000200000000) && m_spellInfo
->SpellFamilyFlags2
& 0x8)
698 // Replenish Mana, item spell with triggered cases (Mana Agate, etc mana gems)
699 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000010000000000))
702 case SPELLFAMILY_WARLOCK
:
703 // For Hellfire Effect / Rain of Fire / Seed of Corruption triggers need do it
704 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000800000000060))
707 case SPELLFAMILY_PRIEST
:
708 // For Penance,Mind Sear,Mind Flay heal/damage triggers need do it
709 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0001800000800000) || (m_spellInfo
->SpellFamilyFlags2
& 0x00000040))
712 case SPELLFAMILY_ROGUE
:
713 // For poisons need do it
714 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x000000101001E000))
717 case SPELLFAMILY_HUNTER
:
718 // Hunter Rapid Killing/Explosive Trap Effect/Immolation Trap Effect/Frost Trap Aura/Snake Trap Effect/Explosive Shot
719 if ((m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0100200000000214)) ||
720 m_spellInfo
->SpellFamilyFlags2
& 0x200)
723 case SPELLFAMILY_PALADIN
:
724 // For Judgements (all) / Holy Shock triggers need do it
725 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0001000900B80400))
733 // Get data for type of attack and fill base info for trigger
734 switch (m_spellInfo
->DmgClass
)
736 case SPELL_DAMAGE_CLASS_MELEE
:
737 m_procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT
;
738 m_procVictim
= PROC_FLAG_TAKEN_MELEE_SPELL_HIT
;
740 case SPELL_DAMAGE_CLASS_RANGED
:
742 if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
)
744 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
745 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
747 else // Ranged spell attack
749 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT
;
750 m_procVictim
= PROC_FLAG_TAKEN_RANGED_SPELL_HIT
;
754 if (IsPositiveSpell(m_spellInfo
->Id
)) // Check for positive spell
756 m_procAttacker
= PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
;
757 m_procVictim
= PROC_FLAG_TAKEN_POSITIVE_SPELL
;
759 else if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
) // Wands auto attack
761 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
762 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
764 else // Negative spell
766 m_procAttacker
= PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT
;
767 m_procVictim
= PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
;
771 // Hunter traps spells (for Entrapment trigger)
772 // Gives your Immolation Trap, Frost Trap, Explosive Trap, and Snake Trap ....
773 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_HUNTER
&& (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x000020000000001C)))
774 m_procAttacker
|= PROC_FLAG_ON_TRAP_ACTIVATION
;
777 void Spell::CleanupTargetList()
779 m_UniqueTargetInfo
.clear();
780 m_UniqueGOTargetInfo
.clear();
781 m_UniqueItemInfo
.clear();
785 void Spell::AddUnitTarget(Unit
* pVictim
, SpellEffectIndex effIndex
)
787 if( m_spellInfo
->Effect
[effIndex
] == 0 )
790 // Check for effect immune skip if immuned
791 bool immuned
= pVictim
->IsImmunedToSpellEffect(m_spellInfo
, effIndex
);
793 uint64 targetGUID
= pVictim
->GetGUID();
795 // Lookup target in already in list
796 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
798 if (targetGUID
== ihit
->targetGUID
) // Found in list
801 ihit
->effectMask
|= (1 << effIndex
); // Add only effect mask if not immuned
806 // This is new target calculate data for him
808 // Get spell hit result on target
810 target
.targetGUID
= targetGUID
; // Store target GUID
811 target
.effectMask
= immuned
? 0 : (1 << effIndex
); // Store index of effect if not immuned
812 target
.processed
= false; // Effects not apply on target
814 // Calculate hit result
815 target
.missCondition
= m_caster
->SpellHitResult(pVictim
, m_spellInfo
, m_canReflect
);
817 // Spell have speed - need calculate incoming time
818 if (m_spellInfo
->speed
> 0.0f
)
820 // calculate spell incoming interval
821 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
822 if (dist
< 5.0f
) dist
= 5.0f
;
823 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
825 // Calculate minimum incoming time
826 if (m_delayMoment
== 0 || m_delayMoment
>target
.timeDelay
)
827 m_delayMoment
= target
.timeDelay
;
830 target
.timeDelay
= UI64LIT(0);
832 // If target reflect spell back to caster
833 if (target
.missCondition
== SPELL_MISS_REFLECT
)
835 // Calculate reflected spell result on caster
836 target
.reflectResult
= m_caster
->SpellHitResult(m_caster
, m_spellInfo
, m_canReflect
);
838 if (target
.reflectResult
== SPELL_MISS_REFLECT
) // Impossible reflect again, so simply deflect spell
839 target
.reflectResult
= SPELL_MISS_PARRY
;
841 // Increase time interval for reflected spells by 1.5
842 target
.timeDelay
+= target
.timeDelay
>> 1;
845 target
.reflectResult
= SPELL_MISS_NONE
;
847 // Add target to list
848 m_UniqueTargetInfo
.push_back(target
);
851 void Spell::AddUnitTarget(uint64 unitGUID
, SpellEffectIndex effIndex
)
853 Unit
* unit
= m_caster
->GetGUID() == unitGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, unitGUID
);
855 AddUnitTarget(unit
, effIndex
);
858 void Spell::AddGOTarget(GameObject
* pVictim
, SpellEffectIndex effIndex
)
860 if( m_spellInfo
->Effect
[effIndex
] == 0 )
863 uint64 targetGUID
= pVictim
->GetGUID();
865 // Lookup target in already in list
866 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
868 if (targetGUID
== ihit
->targetGUID
) // Found in list
870 ihit
->effectMask
|= (1 << effIndex
); // Add only effect mask
875 // This is new target calculate data for him
878 target
.targetGUID
= targetGUID
;
879 target
.effectMask
= (1 << effIndex
);
880 target
.processed
= false; // Effects not apply on target
882 // Spell have speed - need calculate incoming time
883 if (m_spellInfo
->speed
> 0.0f
)
885 // calculate spell incoming interval
886 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
889 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
890 if (m_delayMoment
== 0 || m_delayMoment
> target
.timeDelay
)
891 m_delayMoment
= target
.timeDelay
;
894 target
.timeDelay
= UI64LIT(0);
896 // Add target to list
897 m_UniqueGOTargetInfo
.push_back(target
);
900 void Spell::AddGOTarget(uint64 goGUID
, SpellEffectIndex effIndex
)
902 GameObject
* go
= m_caster
->GetMap()->GetGameObject(goGUID
);
904 AddGOTarget(go
, effIndex
);
907 void Spell::AddItemTarget(Item
* pitem
, SpellEffectIndex effIndex
)
909 if( m_spellInfo
->Effect
[effIndex
] == 0 )
912 // Lookup target in already in list
913 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin(); ihit
!= m_UniqueItemInfo
.end(); ++ihit
)
915 if (pitem
== ihit
->item
) // Found in list
917 ihit
->effectMask
|= (1 << effIndex
); // Add only effect mask
922 // This is new target add data
924 ItemTargetInfo target
;
926 target
.effectMask
= (1 << effIndex
);
927 m_UniqueItemInfo
.push_back(target
);
930 void Spell::DoAllEffectOnTarget(TargetInfo
*target
)
932 if (target
->processed
) // Check target
934 target
->processed
= true; // Target checked in apply effects procedure
936 // Get mask of effects for target
937 uint32 mask
= target
->effectMask
;
939 Unit
* unit
= m_caster
->GetGUID() == target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, target
->targetGUID
);
943 // Get original caster (if exist) and calculate damage/healing from him data
944 Unit
*real_caster
= GetAffectiveCaster();
945 // FIXME: in case wild GO heal/damage spells will be used target bonuses
946 Unit
*caster
= real_caster
? real_caster
: m_caster
;
948 SpellMissInfo missInfo
= target
->missCondition
;
949 // Need init unitTarget by default unit (can changed in code on reflect)
950 // Or on missInfo!=SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem)
953 // Reset damage/healing counter
957 // Fill base trigger info
958 uint32 procAttacker
= m_procAttacker
;
959 uint32 procVictim
= m_procVictim
;
960 uint32 procEx
= PROC_EX_NONE
;
962 if (missInfo
==SPELL_MISS_NONE
) // In case spell hit target, do all effect on that target
963 DoSpellHitOnUnit(unit
, mask
);
964 else if (missInfo
== SPELL_MISS_REFLECT
) // In case spell reflect from target, do all effect on caster (if hit)
966 if (target
->reflectResult
== SPELL_MISS_NONE
) // If reflected spell hit caster -> do all effect on him
967 DoSpellHitOnUnit(m_caster
, mask
);
970 // All calculated do it!
971 // Do healing and triggers
974 bool crit
= real_caster
&& real_caster
->isSpellCrit(unitTarget
, m_spellInfo
, m_spellSchoolMask
);
975 uint32 addhealth
= m_healing
;
978 procEx
|= PROC_EX_CRITICAL_HIT
;
979 addhealth
= caster
->SpellCriticalHealingBonus(m_spellInfo
, addhealth
, NULL
);
982 procEx
|= PROC_EX_NORMAL_HIT
;
984 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
985 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
987 caster
->ProcDamageAndSpell(unitTarget
, real_caster
? procAttacker
: PROC_FLAG_NONE
, procVictim
, procEx
, addhealth
, m_attackType
, m_spellInfo
);
990 int32 gain
= caster
->DealHeal(unitTarget
, addhealth
, m_spellInfo
, crit
);
993 unitTarget
->getHostileRefManager().threatAssist(real_caster
, float(gain
) * 0.5f
, m_spellInfo
);
995 // Do damage and triggers
998 // Fill base damage struct (unitTarget - is real spell target)
999 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1001 // Add bonuses and fill damageInfo struct
1002 caster
->CalculateSpellDamage(&damageInfo
, m_damage
, m_spellInfo
, m_attackType
);
1004 caster
->DealDamageMods(damageInfo
.target
, damageInfo
.damage
, &damageInfo
.absorb
);
1006 // Send log damage message to client
1007 caster
->SendSpellNonMeleeDamageLog(&damageInfo
);
1009 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1010 procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1012 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1013 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1014 caster
->ProcDamageAndSpell(unitTarget
, real_caster
? procAttacker
: PROC_FLAG_NONE
, procVictim
, procEx
, damageInfo
.damage
, m_attackType
, m_spellInfo
);
1016 // Haunt (NOTE: for avoid use additional field damage stored in dummy value (replace unused 100%)
1017 // apply before deal damage because aura can be removed at target kill
1018 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& m_spellInfo
->SpellIconID
== 3172 &&
1019 (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0004000000000000)))
1020 if(Aura
* dummy
= unitTarget
->GetDummyAura(m_spellInfo
->Id
))
1021 dummy
->GetModifier()->m_amount
= damageInfo
.damage
;
1023 caster
->DealSpellDamage(&damageInfo
, true);
1025 // Passive spell hits/misses or active spells only misses (only triggers)
1028 // Fill base damage struct (unitTarget - is real spell target)
1029 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1030 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1031 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1032 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1033 caster
->ProcDamageAndSpell(unit
, real_caster
? procAttacker
: PROC_FLAG_NONE
, procVictim
, procEx
, 0, m_attackType
, m_spellInfo
);
1036 // Call scripted function for AI if this spell is casted upon a creature
1037 if (unit
->GetTypeId() == TYPEID_UNIT
)
1039 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1040 // ignore pets or autorepeat/melee casts for speed (not exist quest for spells (hm... )
1041 if (real_caster
&& !((Creature
*)unit
)->isPet() && !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive())
1042 if (Player
* p
= real_caster
->GetCharmerOrOwnerPlayerOrPlayerItself())
1043 p
->CastedCreatureOrGO(unit
->GetEntry(), unit
->GetGUID(), m_spellInfo
->Id
);
1045 if(((Creature
*)unit
)->AI())
1046 ((Creature
*)unit
)->AI()->SpellHit(m_caster
, m_spellInfo
);
1049 // Call scripted function for AI if this spell is casted by a creature
1050 if (m_caster
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)m_caster
)->AI())
1051 ((Creature
*)m_caster
)->AI()->SpellHitTarget(unit
, m_spellInfo
);
1054 void Spell::DoSpellHitOnUnit(Unit
*unit
, const uint32 effectMask
)
1056 if (!unit
|| !effectMask
)
1059 Unit
* realCaster
= GetAffectiveCaster();
1061 // Recheck immune (only for delayed spells)
1062 if (m_spellInfo
->speed
&& (
1063 unit
->IsImmunedToDamage(GetSpellSchoolMask(m_spellInfo
)) ||
1064 unit
->IsImmunedToSpell(m_spellInfo
)))
1067 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_IMMUNE
);
1071 if (unit
->GetTypeId() == TYPEID_PLAYER
)
1073 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET
, m_spellInfo
->Id
);
1074 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2
, m_spellInfo
->Id
);
1077 if (realCaster
&& realCaster
->GetTypeId() == TYPEID_PLAYER
)
1078 ((Player
*)realCaster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2
, m_spellInfo
->Id
, 0, unit
);
1080 if (realCaster
&& realCaster
!= unit
)
1082 // Recheck UNIT_FLAG_NON_ATTACKABLE for delayed spells
1083 if (m_spellInfo
->speed
> 0.0f
&&
1084 unit
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
) &&
1085 unit
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
1087 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1091 if (!realCaster
->IsFriendlyTo(unit
))
1093 // for delayed spells ignore not visible explicit target
1094 if (m_spellInfo
->speed
> 0.0f
&& unit
== m_targets
.getUnitTarget() &&
1095 !unit
->isVisibleForOrDetect(m_caster
, m_caster
, false))
1097 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1101 // not break stealth by cast targeting
1102 if (!(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_BREAK_STEALTH
))
1103 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1105 // can cause back attack (if detected), stealth removed at Spell::cast if spell break it
1106 if (!(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) && !IsPositiveSpell(m_spellInfo
->Id
) &&
1107 m_caster
->isVisibleForOrDetect(unit
, unit
, false))
1109 // use speedup check to avoid re-remove after above lines
1110 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_BREAK_STEALTH
)
1111 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1113 // caster can be detected but have stealth aura
1114 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1116 if (!unit
->IsStandState() && !unit
->hasUnitState(UNIT_STAT_STUNNED
))
1117 unit
->SetStandState(UNIT_STAND_STATE_STAND
);
1119 if (!unit
->isInCombat() && unit
->GetTypeId() != TYPEID_PLAYER
&& ((Creature
*)unit
)->AI())
1120 ((Creature
*)unit
)->AI()->AttackedBy(realCaster
);
1122 unit
->AddThreat(realCaster
);
1123 unit
->SetInCombatWith(realCaster
);
1124 realCaster
->SetInCombatWith(unit
);
1126 if (Player
*attackedPlayer
= unit
->GetCharmerOrOwnerPlayerOrPlayerItself())
1127 realCaster
->SetContestedPvP(attackedPlayer
);
1132 // for delayed spells ignore negative spells (after duel end) for friendly targets
1133 if (m_spellInfo
->speed
> 0.0f
&& !IsPositiveSpell(m_spellInfo
->Id
))
1135 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1139 // assisting case, healing and resurrection
1140 if (unit
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
1141 realCaster
->SetContestedPvP();
1143 if (unit
->isInCombat() && !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
))
1145 realCaster
->SetInCombatState(unit
->GetCombatTimer() > 0);
1146 unit
->getHostileRefManager().threatAssist(realCaster
, 0.0f
, m_spellInfo
);
1151 // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
1152 m_diminishGroup
= GetDiminishingReturnsGroupForSpell(m_spellInfo
,m_triggeredByAuraSpell
);
1153 m_diminishLevel
= unit
->GetDiminishing(m_diminishGroup
);
1154 // Increase Diminishing on unit, current informations for actually casts will use values above
1155 if ((GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_PLAYER
&& unit
->GetTypeId() == TYPEID_PLAYER
) ||
1156 GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_ALL
)
1157 unit
->IncrDiminishing(m_diminishGroup
);
1159 // Apply additional spell effects to target
1160 CastPreCastSpells(unit
);
1162 for(int effectNumber
= 0; effectNumber
< MAX_EFFECT_INDEX
; ++effectNumber
)
1164 if (effectMask
& (1 << effectNumber
))
1166 HandleEffects(unit
, NULL
, NULL
, SpellEffectIndex(effectNumber
), m_damageMultipliers
[effectNumber
]);
1167 if ( m_applyMultiplierMask
& (1 << effectNumber
) )
1170 float multiplier
= m_spellInfo
->DmgMultiplier
[effectNumber
];
1171 // Apply multiplier mods
1173 if(Player
* modOwner
= realCaster
->GetSpellModOwner())
1174 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_EFFECT_PAST_FIRST
, multiplier
, this);
1175 m_damageMultipliers
[effectNumber
] *= multiplier
;
1181 void Spell::DoAllEffectOnTarget(GOTargetInfo
*target
)
1183 if (target
->processed
) // Check target
1185 target
->processed
= true; // Target checked in apply effects procedure
1187 uint32 effectMask
= target
->effectMask
;
1191 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
1195 for(int effectNumber
= 0; effectNumber
< MAX_EFFECT_INDEX
; ++effectNumber
)
1196 if (effectMask
& (1 << effectNumber
))
1197 HandleEffects(NULL
, NULL
, go
, SpellEffectIndex(effectNumber
));
1199 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1200 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
1201 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1203 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1204 p
->CastedCreatureOrGO(go
->GetEntry(), go
->GetGUID(), m_spellInfo
->Id
);
1208 void Spell::DoAllEffectOnTarget(ItemTargetInfo
*target
)
1210 uint32 effectMask
= target
->effectMask
;
1211 if(!target
->item
|| !effectMask
)
1214 for(int effectNumber
= 0; effectNumber
< MAX_EFFECT_INDEX
; ++effectNumber
)
1215 if (effectMask
& (1 << effectNumber
))
1216 HandleEffects(NULL
, target
->item
, NULL
, SpellEffectIndex(effectNumber
));
1219 bool Spell::IsAliveUnitPresentInTargetList()
1221 // Not need check return true
1222 if (m_needAliveTargetMask
== 0)
1225 uint8 needAliveTargetMask
= m_needAliveTargetMask
;
1227 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
1229 if( ihit
->missCondition
== SPELL_MISS_NONE
&& (needAliveTargetMask
& ihit
->effectMask
) )
1231 Unit
*unit
= m_caster
->GetGUID() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
1233 // either unit is alive and normal spell, or unit dead and deathonly-spell
1234 if (unit
&& (unit
->isAlive() != IsDeathOnlySpell(m_spellInfo
)))
1235 needAliveTargetMask
&= ~ihit
->effectMask
; // remove from need alive mask effect that have alive target
1239 // is all effects from m_needAliveTargetMask have alive targets
1240 return needAliveTargetMask
== 0;
1243 // Helper for Chain Healing
1244 // Spell target first
1245 // Raidmates then descending by injury suffered (MaxHealth - Health)
1246 // Other players/mobs then descending by injury suffered (MaxHealth - Health)
1247 struct ChainHealingOrder
: public std::binary_function
<const Unit
*, const Unit
*, bool>
1249 const Unit
* MainTarget
;
1250 ChainHealingOrder(Unit
const* Target
) : MainTarget(Target
) {};
1251 // functor for operator ">"
1252 bool operator()(Unit
const* _Left
, Unit
const* _Right
) const
1254 return (ChainHealingHash(_Left
) < ChainHealingHash(_Right
));
1256 int32
ChainHealingHash(Unit
const* Target
) const
1258 if (Target
== MainTarget
)
1260 else if (Target
->GetTypeId() == TYPEID_PLAYER
&& MainTarget
->GetTypeId() == TYPEID_PLAYER
&&
1261 ((Player
const*)Target
)->IsInSameRaidWith((Player
const*)MainTarget
))
1263 if (Target
->GetHealth() == Target
->GetMaxHealth())
1266 return 20000 - Target
->GetMaxHealth() + Target
->GetHealth();
1269 return 40000 - Target
->GetMaxHealth() + Target
->GetHealth();
1273 class ChainHealingFullHealth
: std::unary_function
<const Unit
*, bool>
1276 const Unit
* MainTarget
;
1277 ChainHealingFullHealth(const Unit
* Target
) : MainTarget(Target
) {};
1279 bool operator()(const Unit
* Target
)
1281 return (Target
!= MainTarget
&& Target
->GetHealth() == Target
->GetMaxHealth());
1285 // Helper for targets nearest to the spell target
1286 // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
1287 struct TargetDistanceOrder
: public std::binary_function
<const Unit
, const Unit
, bool>
1289 const Unit
* MainTarget
;
1290 TargetDistanceOrder(const Unit
* Target
) : MainTarget(Target
) {};
1291 // functor for operator ">"
1292 bool operator()(const Unit
* _Left
, const Unit
* _Right
) const
1294 return MainTarget
->GetDistanceOrder(_Left
, _Right
);
1298 void Spell::SetTargetMap(SpellEffectIndex effIndex
, uint32 targetMode
, UnitList
& targetUnitMap
)
1301 if (m_spellInfo
->EffectRadiusIndex
[effIndex
])
1302 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[effIndex
]));
1304 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
));
1306 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[effIndex
];
1308 if (Unit
* realCaster
= GetAffectiveCaster())
1310 if(Player
* modOwner
= realCaster
->GetSpellModOwner())
1312 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RADIUS
, radius
, this);
1313 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
1317 // Get spell max affected targets
1318 uint32 unMaxTargets
= m_spellInfo
->MaxAffectedTargets
;
1320 // custom target amount cases
1321 switch(m_spellInfo
->SpellFamilyName
)
1323 case SPELLFAMILY_GENERIC
:
1325 switch(m_spellInfo
->Id
)
1327 case 31347: // Doom TODO: exclude top threat target from target selection
1328 case 33711: // Murmur's Touch
1329 case 38794: // Murmur's Touch (h)
1332 case 28542: // Life Drain
1333 case 66013: // Penetrating Cold (10 man)
1334 case 68509: // Penetrating Cold (10 man heroic)
1337 case 28796: // Poison Bolt Volley
1338 case 29213: // Curse of the Plaguebringer
1339 case 31298: // Sleep
1342 case 30843: // Enfeeble TODO: exclude top threat target from target selection
1343 case 42005: // Bloodboil TODO: need to be 5 targets(players) furthest away from caster
1344 case 55665: // Life Drain (h)
1345 case 67700: // Penetrating Cold (25 man)
1346 case 68510: // Penetrating Cold (25 man, heroic)
1349 case 54098: // Poison Bolt Volley (h)
1350 case 54835: // Curse of the Plaguebringer (h)
1353 case 25991: // Poison Bolt Volley (Pincess Huhuran)
1359 case SPELLFAMILY_PALADIN
:
1360 if (m_spellInfo
->Id
== 20424) // Seal of Command (2 more target for single targeted spell)
1362 // overwrite EffectChainTarget for non single target spell
1363 if (Spell
* currSpell
= m_caster
->GetCurrentSpell(CURRENT_GENERIC_SPELL
))
1364 if (currSpell
->m_spellInfo
->MaxAffectedTargets
> 0 ||
1365 currSpell
->m_spellInfo
->EffectChainTarget
[EFFECT_INDEX_0
] > 0 ||
1366 currSpell
->m_spellInfo
->EffectChainTarget
[EFFECT_INDEX_1
] > 0 ||
1367 currSpell
->m_spellInfo
->EffectChainTarget
[EFFECT_INDEX_2
] > 0)
1368 EffectChainTarget
= 0; // no chain targets
1371 case SPELLFAMILY_DRUID
:
1373 if (m_spellInfo
->SpellFamilyFlags2
& 0x00000100)// Starfall
1381 Unit::AuraList
const& mod
= m_caster
->GetAurasByType(SPELL_AURA_MOD_MAX_AFFECTED_TARGETS
);
1382 for(Unit::AuraList::const_iterator m
= mod
.begin(); m
!= mod
.end(); ++m
)
1384 if (!(*m
)->isAffectedOnSpell(m_spellInfo
))
1386 unMaxTargets
+= (*m
)->GetModifier()->m_amount
;
1391 case TARGET_RANDOM_NEARBY_LOC
:
1392 radius
*= sqrtf(rand_norm_f()); // Get a random point in circle. Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates.
1393 // no 'break' expected since we use code in case TARGET_RANDOM_CIRCUMFERENCE_POINT!!!
1394 case TARGET_RANDOM_CIRCUMFERENCE_POINT
:
1396 float angle
= 2.0f
* M_PI_F
* rand_norm_f();
1397 float dest_x
, dest_y
, dest_z
;
1398 m_caster
->GetClosePoint(dest_x
, dest_y
, dest_z
, 0.0f
, radius
, angle
);
1399 m_targets
.setDestination(dest_x
, dest_y
, dest_z
);
1401 targetUnitMap
.push_back(m_caster
);
1404 case TARGET_RANDOM_NEARBY_DEST
:
1406 radius
*= sqrtf(rand_norm_f()); // Get a random point in circle. Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates.
1407 float angle
= 2.0f
* M_PI_F
* rand_norm_f();
1408 float dest_x
= m_targets
.m_destX
+ cos(angle
) * radius
;
1409 float dest_y
= m_targets
.m_destY
+ sin(angle
) * radius
;
1410 float dest_z
= m_caster
->GetPositionZ();
1411 m_caster
->UpdateGroundPositionZ(dest_x
, dest_y
, dest_z
);
1412 m_targets
.setDestination(dest_x
, dest_y
, dest_z
);
1416 // caster included here?
1417 FillAreaTargets(targetUnitMap
, dest_x
, dest_y
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1420 targetUnitMap
.push_back(m_caster
);
1424 case TARGET_TOTEM_EARTH
:
1425 case TARGET_TOTEM_WATER
:
1426 case TARGET_TOTEM_AIR
:
1427 case TARGET_TOTEM_FIRE
:
1430 case TARGET_AREAEFFECT_CUSTOM
:
1431 case TARGET_AREAEFFECT_CUSTOM_2
:
1432 targetUnitMap
.push_back(m_caster
);
1434 case TARGET_RANDOM_ENEMY_CHAIN_IN_AREA
:
1436 m_targets
.m_targetMask
= 0;
1437 unMaxTargets
= EffectChainTarget
;
1438 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1440 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1442 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1445 std::list
<Unit
*> tempTargetUnitMap
;
1448 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(m_caster
, max_range
);
1449 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempTargetUnitMap
, u_check
);
1451 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1452 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1454 cell
.Visit(p
, world_unit_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
1455 cell
.Visit(p
, grid_unit_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
1458 if(tempTargetUnitMap
.empty())
1461 tempTargetUnitMap
.sort(TargetDistanceOrder(m_caster
));
1463 //Now to get us a random target that's in the initial range of the spell
1465 std::list
<Unit
*>::iterator itr
= tempTargetUnitMap
.begin();
1466 while(itr
!= tempTargetUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
, radius
))
1472 itr
= tempTargetUnitMap
.begin();
1473 std::advance(itr
, rand() % t
);
1474 Unit
*pUnitTarget
= *itr
;
1475 targetUnitMap
.push_back(pUnitTarget
);
1477 tempTargetUnitMap
.erase(itr
);
1479 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1481 t
= unMaxTargets
- 1;
1482 Unit
*prev
= pUnitTarget
;
1483 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
1485 while(t
&& next
!= tempTargetUnitMap
.end())
1487 if(!prev
->IsWithinDist(*next
, CHAIN_SPELL_JUMP_RADIUS
))
1490 if(!prev
->IsWithinLOSInMap(*next
))
1497 targetUnitMap
.push_back(prev
);
1498 tempTargetUnitMap
.erase(next
);
1499 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
1500 next
= tempTargetUnitMap
.begin();
1506 case TARGET_RANDOM_FRIEND_CHAIN_IN_AREA
:
1508 m_targets
.m_targetMask
= 0;
1509 unMaxTargets
= EffectChainTarget
;
1510 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1511 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1513 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1515 std::list
<Unit
*> tempTargetUnitMap
;
1517 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(m_caster
, max_range
);
1518 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(m_caster
, tempTargetUnitMap
, u_check
);
1520 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1521 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1523 cell
.Visit(p
, world_unit_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
1524 cell
.Visit(p
, grid_unit_searcher
, *m_caster
->GetMap(), *m_caster
, max_range
);
1527 if(tempTargetUnitMap
.empty())
1530 tempTargetUnitMap
.sort(TargetDistanceOrder(m_caster
));
1532 //Now to get us a random target that's in the initial range of the spell
1534 std::list
<Unit
*>::iterator itr
= tempTargetUnitMap
.begin();
1535 while(itr
!= tempTargetUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
, radius
))
1541 itr
= tempTargetUnitMap
.begin();
1542 std::advance(itr
, rand() % t
);
1543 Unit
*pUnitTarget
= *itr
;
1544 targetUnitMap
.push_back(pUnitTarget
);
1546 tempTargetUnitMap
.erase(itr
);
1548 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1550 t
= unMaxTargets
- 1;
1551 Unit
*prev
= pUnitTarget
;
1552 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
1554 while(t
&& next
!= tempTargetUnitMap
.end())
1556 if(!prev
->IsWithinDist(*next
, CHAIN_SPELL_JUMP_RADIUS
))
1559 if(!prev
->IsWithinLOSInMap(*next
))
1565 targetUnitMap
.push_back(prev
);
1566 tempTargetUnitMap
.erase(next
);
1567 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
1568 next
= tempTargetUnitMap
.begin();
1575 Pet
* tmpUnit
= m_caster
->GetPet();
1576 if (!tmpUnit
) break;
1577 targetUnitMap
.push_back(tmpUnit
);
1580 case TARGET_CHAIN_DAMAGE
:
1582 if (EffectChainTarget
<= 1)
1584 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1586 m_targets
.setUnitTarget(pUnitTarget
);
1587 targetUnitMap
.push_back(pUnitTarget
);
1592 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1593 Unit
* originalCaster
= GetAffectiveCaster();
1594 if(!pUnitTarget
|| !originalCaster
)
1597 unMaxTargets
= EffectChainTarget
;
1600 if(m_spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MELEE
)
1603 //FIXME: This very like horrible hack and wrong for most spells
1604 max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1606 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1608 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1611 std::list
<Unit
*> tempTargetUnitMap
;
1613 MaNGOS::AnyAoEVisibleTargetUnitInObjectRangeCheck
u_check(pUnitTarget
, originalCaster
, max_range
);
1614 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoEVisibleTargetUnitInObjectRangeCheck
> searcher(m_caster
, tempTargetUnitMap
, u_check
);
1615 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoEVisibleTargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1616 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoEVisibleTargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1618 cell
.Visit(p
, world_unit_searcher
, *m_caster
->GetMap(), *pUnitTarget
, max_range
);
1619 cell
.Visit(p
, grid_unit_searcher
, *m_caster
->GetMap(), *pUnitTarget
, max_range
);
1621 if (tempTargetUnitMap
.empty())
1624 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1626 if (*tempTargetUnitMap
.begin() == pUnitTarget
)
1627 tempTargetUnitMap
.erase(tempTargetUnitMap
.begin());
1629 targetUnitMap
.push_back(pUnitTarget
);
1630 uint32 t
= unMaxTargets
- 1;
1631 Unit
*prev
= pUnitTarget
;
1632 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
1634 while (t
&& next
!= tempTargetUnitMap
.end())
1636 if (!prev
->IsWithinDist (*next
,CHAIN_SPELL_JUMP_RADIUS
))
1638 if (!prev
->IsWithinLOSInMap (*next
))
1644 targetUnitMap
.push_back(prev
);
1645 tempTargetUnitMap
.erase(next
);
1646 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
1647 next
= tempTargetUnitMap
.begin();
1653 case TARGET_ALL_ENEMY_IN_AREA
:
1654 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1656 case TARGET_AREAEFFECT_INSTANT
:
1658 SpellTargets targetB
= SPELL_TARGETS_AOE_DAMAGE
;
1659 // Select friendly targets for positive effect
1660 if (IsPositiveEffect(m_spellInfo
->Id
, effIndex
))
1661 targetB
= SPELL_TARGETS_FRIENDLY
;
1663 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_DEST_CENTER
, targetB
);
1666 targetUnitMap
.remove(m_caster
);
1669 case TARGET_ALL_ENEMY_IN_AREA_INSTANT
:
1671 // targets the ground, not the units in the area
1672 switch(m_spellInfo
->Effect
[effIndex
])
1674 case SPELL_EFFECT_PERSISTENT_AREA_AURA
:
1676 case SPELL_EFFECT_SUMMON
:
1677 targetUnitMap
.push_back(m_caster
);
1680 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1685 case TARGET_DUELVSPLAYER_COORDINATES
:
1687 if(Unit
* currentTarget
= m_targets
.getUnitTarget())
1689 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1690 targetUnitMap
.push_back(currentTarget
);
1694 case TARGET_ALL_PARTY_AROUND_CASTER
:
1695 case TARGET_ALL_PARTY_AROUND_CASTER_2
:
1696 case TARGET_ALL_PARTY
:
1697 FillRaidOrPartyTargets(targetUnitMap
, m_caster
, m_caster
, radius
, false, true, true);
1699 case TARGET_ALL_RAID_AROUND_CASTER
:
1701 if(m_spellInfo
->Id
== 57669) // Replenishment (special target selection)
1702 FillRaidOrPartyManaPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 10, true, false, true);
1703 else if (m_spellInfo
->Id
==52759) // Ancestral Awakening (special target selection)
1704 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 1, true, false, true);
1706 FillRaidOrPartyTargets(targetUnitMap
, m_caster
, m_caster
, radius
, true, true, true);
1709 case TARGET_SINGLE_FRIEND
:
1710 case TARGET_SINGLE_FRIEND_2
:
1711 if(m_targets
.getUnitTarget())
1712 targetUnitMap
.push_back(m_targets
.getUnitTarget());
1714 case TARGET_NONCOMBAT_PET
:
1715 if(Unit
* target
= m_targets
.getUnitTarget())
1716 if( target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet() && ((Pet
*)target
)->getPetType() == MINI_PET
)
1717 targetUnitMap
.push_back(target
);
1719 case TARGET_CASTER_COORDINATES
:
1721 // Check original caster is GO - set its coordinates as dst cast
1722 if (WorldObject
*caster
= GetCastingObject())
1723 m_targets
.setDestination(caster
->GetPositionX(), caster
->GetPositionY(), caster
->GetPositionZ());
1726 case TARGET_ALL_HOSTILE_UNITS_AROUND_CASTER
:
1727 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_SELF_CENTER
, SPELL_TARGETS_HOSTILE
);
1729 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER
:
1730 switch (m_spellInfo
->Id
)
1732 case 64844: // Divine Hymn
1733 // target amount stored in parent spell dummy effect but hard to access
1734 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 3, true, false, false);
1736 case 64904: // Hymn of Hope
1737 // target amount stored in parent spell dummy effect but hard to access
1738 FillRaidOrPartyManaPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 3, true, false, false);
1741 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
1745 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA
:
1746 // Death Pact (in fact selection by player selection)
1747 if (m_spellInfo
->Id
== 48743)
1749 // checked in Spell::CheckCast
1750 if (m_caster
->GetTypeId()==TYPEID_PLAYER
)
1751 if (Unit
* target
= m_caster
->GetMap()->GetPet(((Player
*)m_caster
)->GetSelection()))
1752 targetUnitMap
.push_back(target
);
1754 // Circle of Healing
1755 else if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_PRIEST
&& m_spellInfo
->SpellVisual
[0] == 8253)
1757 Unit
* target
= m_targets
.getUnitTarget();
1762 // Glyph of Circle of Healing
1763 if(Aura
const* glyph
= m_caster
->GetDummyAura(55675))
1764 count
+= glyph
->GetModifier()->m_amount
;
1766 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, target
, radius
, count
, true, false, true);
1769 else if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_DRUID
&& m_spellInfo
->SpellIconID
== 2864)
1771 Unit
* target
= m_targets
.getUnitTarget();
1774 uint32 count
= CalculateDamage(EFFECT_INDEX_2
,m_caster
); // stored in dummy effect, affected by mods
1776 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, target
, radius
, count
, true, false, true);
1779 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_FRIENDLY
);
1781 // 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..)
1782 case TARGET_SINGLE_PARTY
:
1784 Unit
*target
= m_targets
.getUnitTarget();
1785 // Those spells apparently can't be casted on the caster.
1786 if( target
&& target
!= m_caster
)
1788 // Can only be casted on group's members or its pets
1789 Group
*pGroup
= NULL
;
1791 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1792 Unit
*targetOwner
= target
->GetCharmerOrOwner();
1795 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1797 if( target
== owner
)
1799 targetUnitMap
.push_back(target
);
1802 pGroup
= ((Player
*)owner
)->GetGroup();
1805 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1807 if( targetOwner
== m_caster
&& target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet())
1809 targetUnitMap
.push_back(target
);
1812 pGroup
= ((Player
*)m_caster
)->GetGroup();
1817 // Our target can also be a player's pet who's grouped with us or our pet. But can't be controlled player
1820 if( targetOwner
->GetTypeId() == TYPEID_PLAYER
&&
1821 target
->GetTypeId() == TYPEID_UNIT
&& (((Creature
*)target
)->isPet()) &&
1822 target
->GetOwnerGUID() == targetOwner
->GetGUID() &&
1823 pGroup
->IsMember(((Player
*)targetOwner
)->GetGUID()))
1825 targetUnitMap
.push_back(target
);
1828 // 1Our target can be a player who is on our group
1829 else if (target
->GetTypeId() == TYPEID_PLAYER
&& pGroup
->IsMember(((Player
*)target
)->GetGUID()))
1831 targetUnitMap
.push_back(target
);
1837 case TARGET_GAMEOBJECT
:
1838 if(m_targets
.getGOTarget())
1839 AddGOTarget(m_targets
.getGOTarget(), effIndex
);
1841 case TARGET_IN_FRONT_OF_CASTER
:
1843 bool inFront
= m_spellInfo
->SpellVisual
[0] != 3879;
1844 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, inFront
? PUSH_IN_FRONT
: PUSH_IN_BACK
, SPELL_TARGETS_AOE_DAMAGE
);
1847 case TARGET_LARGE_FRONTAL_CONE
:
1848 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_90
, SPELL_TARGETS_AOE_DAMAGE
);
1850 case TARGET_NARROW_FRONTAL_CONE
:
1851 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_15
, SPELL_TARGETS_AOE_DAMAGE
);
1853 case TARGET_IN_FRONT_OF_CASTER_30
:
1854 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_30
, SPELL_TARGETS_AOE_DAMAGE
);
1856 case TARGET_DUELVSPLAYER
:
1858 Unit
*target
= m_targets
.getUnitTarget();
1861 if(m_caster
->IsFriendlyTo(target
))
1863 targetUnitMap
.push_back(target
);
1867 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1869 m_targets
.setUnitTarget(pUnitTarget
);
1870 targetUnitMap
.push_back(pUnitTarget
);
1876 case TARGET_GAMEOBJECT_ITEM
:
1877 if(m_targets
.getGOTargetGUID())
1878 AddGOTarget(m_targets
.getGOTarget(), effIndex
);
1879 else if(m_targets
.getItemTarget())
1880 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
1883 if(Unit
* owner
= m_caster
->GetCharmerOrOwner())
1884 targetUnitMap
.push_back(owner
);
1886 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED
:
1887 // targets the ground, not the units in the area
1888 if (m_spellInfo
->Effect
[effIndex
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1889 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1892 if(m_spellInfo
->Effect
[effIndex
] != SPELL_EFFECT_DUEL
)
1893 targetUnitMap
.push_back(m_caster
);
1895 case TARGET_SINGLE_ENEMY
:
1897 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1899 m_targets
.setUnitTarget(pUnitTarget
);
1900 targetUnitMap
.push_back(pUnitTarget
);
1904 case TARGET_AREAEFFECT_PARTY
:
1906 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1907 Player
*pTarget
= NULL
;
1911 targetUnitMap
.push_back(m_caster
);
1912 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1913 pTarget
= (Player
*)owner
;
1915 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1917 if(Unit
* target
= m_targets
.getUnitTarget())
1919 if( target
->GetTypeId() != TYPEID_PLAYER
)
1921 if(((Creature
*)target
)->isPet())
1923 Unit
*targetOwner
= target
->GetOwner();
1924 if(targetOwner
->GetTypeId() == TYPEID_PLAYER
)
1925 pTarget
= (Player
*)targetOwner
;
1929 pTarget
= (Player
*)target
;
1933 Group
* pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1937 uint8 subgroup
= pTarget
->GetSubGroup();
1939 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1941 Player
* Target
= itr
->getSource();
1943 // IsHostileTo check duel and controlled by enemy
1944 if(Target
&& Target
->GetSubGroup() == subgroup
&& !m_caster
->IsHostileTo(Target
))
1946 if( pTarget
->IsWithinDistInMap(Target
, radius
) )
1947 targetUnitMap
.push_back(Target
);
1949 if(Pet
* pet
= Target
->GetPet())
1950 if( pTarget
->IsWithinDistInMap(pet
, radius
) )
1951 targetUnitMap
.push_back(pet
);
1957 if(m_caster
->IsWithinDistInMap(owner
, radius
))
1958 targetUnitMap
.push_back(owner
);
1962 targetUnitMap
.push_back(pTarget
);
1964 if(Pet
* pet
= pTarget
->GetPet())
1965 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1966 targetUnitMap
.push_back(pet
);
1972 if(m_targets
.getUnitTarget())
1973 targetUnitMap
.push_back(m_targets
.getUnitTarget());
1974 if(m_targets
.getItemTarget())
1975 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
1978 case TARGET_SELF_FISHING
:
1979 targetUnitMap
.push_back(m_caster
);
1981 case TARGET_CHAIN_HEAL
:
1983 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1987 if (EffectChainTarget
<= 1)
1988 targetUnitMap
.push_back(pUnitTarget
);
1991 unMaxTargets
= EffectChainTarget
;
1992 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1994 UnitList tempTargetUnitMap
;
1996 FillAreaTargets(tempTargetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), max_range
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
1998 if (m_caster
!= pUnitTarget
&& std::find(tempTargetUnitMap
.begin(), tempTargetUnitMap
.end(), m_caster
) == tempTargetUnitMap
.end())
1999 tempTargetUnitMap
.push_front(m_caster
);
2001 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
2003 if (tempTargetUnitMap
.empty())
2006 if (*tempTargetUnitMap
.begin() == pUnitTarget
)
2007 tempTargetUnitMap
.erase(tempTargetUnitMap
.begin());
2009 targetUnitMap
.push_back(pUnitTarget
);
2010 uint32 t
= unMaxTargets
- 1;
2011 Unit
*prev
= pUnitTarget
;
2012 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
2014 while(t
&& next
!= tempTargetUnitMap
.end())
2016 if(!prev
->IsWithinDist(*next
, CHAIN_SPELL_JUMP_RADIUS
))
2019 if(!prev
->IsWithinLOSInMap(*next
))
2025 if((*next
)->GetHealth() == (*next
)->GetMaxHealth())
2027 next
= tempTargetUnitMap
.erase(next
);
2032 targetUnitMap
.push_back(prev
);
2033 tempTargetUnitMap
.erase(next
);
2034 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
2035 next
= tempTargetUnitMap
.begin();
2042 case TARGET_CURRENT_ENEMY_COORDINATES
:
2044 Unit
* currentTarget
= m_targets
.getUnitTarget();
2047 targetUnitMap
.push_back(currentTarget
);
2048 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
2049 if(m_spellInfo
->EffectImplicitTargetB
[effIndex
] == TARGET_ALL_ENEMY_IN_AREA_INSTANT
)
2050 FillAreaTargets(targetUnitMap
, currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), radius
, PUSH_TARGET_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
2054 case TARGET_AREAEFFECT_PARTY_AND_CLASS
:
2056 Player
* targetPlayer
= m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
2057 ? (Player
*)m_targets
.getUnitTarget() : NULL
;
2059 Group
* pGroup
= targetPlayer
? targetPlayer
->GetGroup() : NULL
;
2062 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2064 Player
* Target
= itr
->getSource();
2066 // IsHostileTo check duel and controlled by enemy
2067 if( Target
&& targetPlayer
->IsWithinDistInMap(Target
, radius
) &&
2068 targetPlayer
->getClass() == Target
->getClass() &&
2069 !m_caster
->IsHostileTo(Target
) )
2071 targetUnitMap
.push_back(Target
);
2075 else if(m_targets
.getUnitTarget())
2076 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2079 case TARGET_TABLE_X_Y_Z_COORDINATES
:
2081 SpellTargetPosition
const* st
= sSpellMgr
.GetSpellTargetPosition(m_spellInfo
->Id
);
2084 // teleport spells are handled in another way
2085 if (m_spellInfo
->Effect
[effIndex
] == SPELL_EFFECT_TELEPORT_UNITS
)
2087 if (st
->target_mapId
== m_caster
->GetMapId())
2088 m_targets
.setDestination(st
->target_X
, st
->target_Y
, st
->target_Z
);
2090 sLog
.outError( "SPELL: wrong map (%u instead %u) target coordinates for spell ID %u", st
->target_mapId
, m_caster
->GetMapId(), m_spellInfo
->Id
);
2093 sLog
.outError( "SPELL: unknown target coordinates for spell ID %u", m_spellInfo
->Id
);
2096 case TARGET_INFRONT_OF_VICTIM
:
2097 case TARGET_BEHIND_VICTIM
:
2098 case TARGET_RIGHT_FROM_VICTIM
:
2099 case TARGET_LEFT_FROM_VICTIM
:
2101 Unit
*pTarget
= NULL
;
2103 // explicit cast data from client or server-side cast
2104 // some spell at client send caster
2105 if(m_targets
.getUnitTarget() && m_targets
.getUnitTarget()!=m_caster
)
2106 pTarget
= m_targets
.getUnitTarget();
2107 else if(m_caster
->getVictim())
2108 pTarget
= m_caster
->getVictim();
2109 else if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
2110 pTarget
= ObjectAccessor::GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection());
2115 float dist
= (radius
&& targetMode
!= TARGET_BEHIND_VICTIM
) ? radius
: CONTACT_DISTANCE
;
2119 case TARGET_INFRONT_OF_VICTIM
: break;
2120 case TARGET_BEHIND_VICTIM
: angle
= M_PI_F
; break;
2121 case TARGET_RIGHT_FROM_VICTIM
: angle
= -M_PI_F
/ 2; break;
2122 case TARGET_LEFT_FROM_VICTIM
: angle
= M_PI_F
/ 2; break;
2125 float _target_x
, _target_y
, _target_z
;
2126 pTarget
->GetClosePoint(_target_x
, _target_y
, _target_z
, pTarget
->GetObjectSize(), dist
, angle
);
2127 if(pTarget
->IsWithinLOS(_target_x
, _target_y
, _target_z
))
2129 targetUnitMap
.push_back(m_caster
);
2130 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2135 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
2136 // if parent spell create dynamic object extract area from it
2137 if(DynamicObject
* dynObj
= m_caster
->GetDynObject(m_triggeredByAuraSpell
? m_triggeredByAuraSpell
->Id
: m_spellInfo
->Id
))
2138 m_targets
.setDestination(dynObj
->GetPositionX(), dynObj
->GetPositionY(), dynObj
->GetPositionZ());
2141 case TARGET_DYNAMIC_OBJECT_FRONT
:
2142 case TARGET_DYNAMIC_OBJECT_BEHIND
:
2143 case TARGET_DYNAMIC_OBJECT_LEFT_SIDE
:
2144 case TARGET_DYNAMIC_OBJECT_RIGHT_SIDE
:
2146 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2148 float angle
= m_caster
->GetOrientation();
2151 case TARGET_DYNAMIC_OBJECT_FRONT
: break;
2152 case TARGET_DYNAMIC_OBJECT_BEHIND
: angle
+= M_PI_F
; break;
2153 case TARGET_DYNAMIC_OBJECT_LEFT_SIDE
: angle
+= M_PI_F
/ 2; break;
2154 case TARGET_DYNAMIC_OBJECT_RIGHT_SIDE
: angle
-= M_PI_F
/ 2; break;
2158 m_caster
->GetNearPoint2D(x
, y
, radius
, angle
);
2159 m_targets
.setDestination(x
, y
, m_caster
->GetPositionZ());
2162 targetUnitMap
.push_back(m_caster
);
2165 case TARGET_POINT_AT_NORTH
:
2166 case TARGET_POINT_AT_SOUTH
:
2167 case TARGET_POINT_AT_EAST
:
2168 case TARGET_POINT_AT_WEST
:
2169 case TARGET_POINT_AT_NE
:
2170 case TARGET_POINT_AT_NW
:
2171 case TARGET_POINT_AT_SE
:
2172 case TARGET_POINT_AT_SW
:
2175 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2177 Unit
* currentTarget
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
2178 float angle
= currentTarget
!= m_caster
? currentTarget
->GetAngle(m_caster
) : m_caster
->GetOrientation();
2182 case TARGET_POINT_AT_NORTH
: break;
2183 case TARGET_POINT_AT_SOUTH
: angle
+= M_PI_F
; break;
2184 case TARGET_POINT_AT_EAST
: angle
-= M_PI_F
/ 2; break;
2185 case TARGET_POINT_AT_WEST
: angle
+= M_PI_F
/ 2; break;
2186 case TARGET_POINT_AT_NE
: angle
-= M_PI_F
/ 4; break;
2187 case TARGET_POINT_AT_NW
: angle
+= M_PI_F
/ 4; break;
2188 case TARGET_POINT_AT_SE
: angle
-= 3*M_PI_F
/ 4; break;
2189 case TARGET_POINT_AT_SW
: angle
+= 3*M_PI_F
/ 4; break;
2193 currentTarget
->GetNearPoint2D(x
, y
, radius
, angle
);
2194 m_targets
.setDestination(x
, y
, currentTarget
->GetPositionZ());
2198 case TARGET_DIRECTLY_FORWARD
:
2200 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2202 SpellRangeEntry
const* rEntry
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
2203 float minRange
= GetSpellMinRange(rEntry
);
2204 float maxRange
= GetSpellMaxRange(rEntry
);
2205 float dist
= minRange
+ rand_norm_f()*(maxRange
-minRange
);
2207 float _target_x
, _target_y
, _target_z
;
2208 m_caster
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), dist
);
2209 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2212 targetUnitMap
.push_back(m_caster
);
2215 case TARGET_EFFECT_SELECT
:
2217 // add here custom effects that need default target.
2218 // FOR EVERY TARGET TYPE THERE IS A DIFFERENT FILL!!
2219 switch(m_spellInfo
->Effect
[effIndex
])
2221 case SPELL_EFFECT_DUMMY
:
2223 switch(m_spellInfo
->Id
)
2225 case 20577: // Cannibalize
2227 WorldObject
* result
= FindCorpseUsing
<MaNGOS::CannibalizeObjectCheck
> ();
2231 switch(result
->GetTypeId())
2235 targetUnitMap
.push_back((Unit
*)result
);
2238 m_targets
.setCorpseTarget((Corpse
*)result
);
2239 if (Player
* owner
= ObjectAccessor::FindPlayer(((Corpse
*)result
)->GetOwnerGUID()))
2240 targetUnitMap
.push_back(owner
);
2246 // clear cooldown at fail
2247 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2248 ((Player
*)m_caster
)->RemoveSpellCooldown(m_spellInfo
->Id
, true);
2249 SendCastResult(SPELL_FAILED_NO_EDIBLE_CORPSES
);
2255 if (m_targets
.getUnitTarget())
2256 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2261 case SPELL_EFFECT_BIND
:
2262 case SPELL_EFFECT_RESURRECT
:
2263 case SPELL_EFFECT_PARRY
:
2264 case SPELL_EFFECT_BLOCK
:
2265 case SPELL_EFFECT_CREATE_ITEM
:
2266 case SPELL_EFFECT_TRIGGER_SPELL
:
2267 case SPELL_EFFECT_TRIGGER_MISSILE
:
2268 case SPELL_EFFECT_LEARN_SPELL
:
2269 case SPELL_EFFECT_SKILL_STEP
:
2270 case SPELL_EFFECT_PROFICIENCY
:
2271 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
2272 case SPELL_EFFECT_SELF_RESURRECT
:
2273 case SPELL_EFFECT_REPUTATION
:
2274 case SPELL_EFFECT_SEND_TAXI
:
2275 if (m_targets
.getUnitTarget())
2276 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2277 // Triggered spells have additional spell targets - cast them even if no explicit unit target is given (required for spell 50516 for example)
2278 else if (m_spellInfo
->Effect
[effIndex
] == SPELL_EFFECT_TRIGGER_SPELL
)
2279 targetUnitMap
.push_back(m_caster
);
2281 case SPELL_EFFECT_SUMMON_PLAYER
:
2282 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetSelection())
2284 Player
* target
= sObjectMgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
2286 targetUnitMap
.push_back(target
);
2289 case SPELL_EFFECT_RESURRECT_NEW
:
2290 if (m_targets
.getUnitTarget())
2291 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2292 if (m_targets
.getCorpseTargetGUID())
2294 Corpse
*corpse
= m_caster
->GetMap()->GetCorpse(m_targets
.getCorpseTargetGUID());
2297 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
2299 targetUnitMap
.push_back(owner
);
2303 case SPELL_EFFECT_SUMMON
:
2304 case SPELL_EFFECT_SUMMON_CHANGE_ITEM
:
2305 case SPELL_EFFECT_TRANS_DOOR
:
2306 case SPELL_EFFECT_ADD_FARSIGHT
:
2307 case SPELL_EFFECT_APPLY_GLYPH
:
2308 case SPELL_EFFECT_STUCK
:
2309 case SPELL_EFFECT_SUMMON_ALL_TOTEMS
:
2310 case SPELL_EFFECT_FEED_PET
:
2311 case SPELL_EFFECT_DESTROY_ALL_TOTEMS
:
2312 case SPELL_EFFECT_SKILL
:
2313 targetUnitMap
.push_back(m_caster
);
2315 case SPELL_EFFECT_LEARN_PET_SPELL
:
2316 if (Pet
* pet
= m_caster
->GetPet())
2317 targetUnitMap
.push_back(pet
);
2319 case SPELL_EFFECT_ENCHANT_ITEM
:
2320 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
2321 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
2322 case SPELL_EFFECT_DISENCHANT
:
2323 case SPELL_EFFECT_PROSPECTING
:
2324 case SPELL_EFFECT_MILLING
:
2325 if (m_targets
.getItemTarget())
2326 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
2328 case SPELL_EFFECT_APPLY_AURA
:
2329 switch(m_spellInfo
->EffectApplyAuraName
[effIndex
])
2331 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)
2332 case SPELL_AURA_ADD_PCT_MODIFIER
:
2333 targetUnitMap
.push_back(m_caster
);
2335 default: // apply to target in other case
2336 if (m_targets
.getUnitTarget())
2337 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2341 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY
:
2343 if(m_spellInfo
->Attributes
== 0x9050000 || m_spellInfo
->Attributes
== 0x10000)
2344 SetTargetMap(effIndex
, TARGET_AREAEFFECT_PARTY
, targetUnitMap
);
2346 case SPELL_EFFECT_SKIN_PLAYER_CORPSE
:
2347 if (m_targets
.getUnitTarget())
2348 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2349 else if (m_targets
.getCorpseTargetGUID())
2351 if (Corpse
*corpse
= m_caster
->GetMap()->GetCorpse(m_targets
.getCorpseTargetGUID()))
2352 if (Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID()))
2353 targetUnitMap
.push_back(owner
);
2363 //sLog.outError( "SPELL: Unknown implicit target (%u) for spell ID %u", targetMode, m_spellInfo->Id );
2367 if (unMaxTargets
&& targetUnitMap
.size() > unMaxTargets
)
2369 // make sure one unit is always removed per iteration
2370 uint32 removed_utarget
= 0;
2371 for (UnitList::iterator itr
= targetUnitMap
.begin(), next
; itr
!= targetUnitMap
.end(); itr
= next
)
2375 if (!*itr
) continue;
2376 if ((*itr
) == m_targets
.getUnitTarget())
2378 targetUnitMap
.erase(itr
);
2379 removed_utarget
= 1;
2383 // remove random units from the map
2384 while (targetUnitMap
.size() > unMaxTargets
- removed_utarget
)
2386 uint32 poz
= urand(0, targetUnitMap
.size()-1);
2387 for (UnitList::iterator itr
= targetUnitMap
.begin(); itr
!= targetUnitMap
.end(); ++itr
, --poz
)
2389 if (!*itr
) continue;
2393 targetUnitMap
.erase(itr
);
2398 // the player's target will always be added to the map
2399 if (removed_utarget
&& m_targets
.getUnitTarget())
2400 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2404 void Spell::prepare(SpellCastTargets
const* targets
, Aura
* triggeredByAura
)
2406 m_targets
= *targets
;
2408 m_spellState
= SPELL_STATE_PREPARING
;
2410 m_castPositionX
= m_caster
->GetPositionX();
2411 m_castPositionY
= m_caster
->GetPositionY();
2412 m_castPositionZ
= m_caster
->GetPositionZ();
2413 m_castOrientation
= m_caster
->GetOrientation();
2416 m_triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
2418 // create and add update event for this spell
2419 SpellEvent
* Event
= new SpellEvent(this);
2420 m_caster
->m_Events
.AddEvent(Event
, m_caster
->m_Events
.CalculateTime(1));
2422 //Prevent casting at cast another spell (ServerSide check)
2423 if(m_caster
->IsNonMeleeSpellCasted(false, true, true) && m_cast_count
)
2425 SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS
);
2431 m_powerCost
= CalculatePowerCost();
2433 SpellCastResult result
= CheckCast(true);
2434 if(result
!= SPELL_CAST_OK
&& !IsAutoRepeat()) //always cast autorepeat dummy for triggering
2438 SendChannelUpdate(0);
2439 triggeredByAura
->SetAuraDuration(0);
2441 SendCastResult(result
);
2446 // Prepare data for triggers
2447 prepareDataForTriggerSystem();
2449 // calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
2450 m_casttime
= GetSpellCastTime(m_spellInfo
, this);
2452 // set timer base at cast time
2455 // stealth must be removed at cast starting (at show channel bar)
2456 // skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
2457 if ( !m_IsTriggeredSpell
&& isSpellBreakStealth(m_spellInfo
) )
2459 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
2460 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
2463 // add non-triggered (with cast time and without)
2464 if (!m_IsTriggeredSpell
)
2466 // add to cast type slot
2467 m_caster
->SetCurrentCastedSpell( this );
2469 // will show cast bar
2472 // execute triggered without cast time explicitly in call point
2473 else if(m_timer
== 0)
2475 // else triggered with cast time will execute execute at next tick or later
2476 // without adding to cast type slot
2477 // will not show cast bar but will show effects at casting time etc
2480 void Spell::cancel()
2482 if(m_spellState
== SPELL_STATE_FINISHED
)
2485 m_autoRepeat
= false;
2486 switch (m_spellState
)
2488 case SPELL_STATE_PREPARING
:
2489 case SPELL_STATE_DELAYED
:
2492 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2495 case SPELL_STATE_CASTING
:
2497 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2499 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2501 Unit
* unit
= m_caster
->GetGUID() == (*ihit
).targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2502 if( unit
&& unit
->isAlive() )
2503 unit
->RemoveAurasByCasterSpell(m_spellInfo
->Id
, m_caster
->GetGUID());
2507 SendChannelUpdate(0);
2509 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2518 m_caster
->RemoveDynObject(m_spellInfo
->Id
);
2519 m_caster
->RemoveGameObject(m_spellInfo
->Id
, true);
2522 void Spell::cast(bool skipCheck
)
2524 SetExecutedCurrently(true);
2526 if (!m_caster
->CheckAndIncreaseCastCounter())
2528 if (m_triggeredByAuraSpell
)
2529 sLog
.outError("Spell %u triggered by aura spell %u too deep in cast chain for cast. Cast not allowed for prevent overflow stack crash.", m_spellInfo
->Id
, m_triggeredByAuraSpell
->Id
);
2531 sLog
.outError("Spell %u too deep in cast chain for cast. Cast not allowed for prevent overflow stack crash.", m_spellInfo
->Id
);
2533 SendCastResult(SPELL_FAILED_ERROR
);
2535 SetExecutedCurrently(false);
2539 // update pointers base at GUIDs to prevent access to non-existed already object
2542 // cancel at lost main target unit
2543 if(!m_targets
.getUnitTarget() && m_targets
.getUnitTargetGUID() && m_targets
.getUnitTargetGUID() != m_caster
->GetGUID())
2546 m_caster
->DecreaseCastCounter();
2547 SetExecutedCurrently(false);
2551 if(m_caster
->GetTypeId() != TYPEID_PLAYER
&& m_targets
.getUnitTarget() && m_targets
.getUnitTarget() != m_caster
)
2552 m_caster
->SetInFront(m_targets
.getUnitTarget());
2554 SpellCastResult castResult
= CheckPower();
2555 if(castResult
!= SPELL_CAST_OK
)
2557 SendCastResult(castResult
);
2559 m_caster
->DecreaseCastCounter();
2560 SetExecutedCurrently(false);
2564 // triggered cast called from Spell::prepare where it was already checked
2567 castResult
= CheckCast(false);
2568 if(castResult
!= SPELL_CAST_OK
)
2570 SendCastResult(castResult
);
2572 m_caster
->DecreaseCastCounter();
2573 SetExecutedCurrently(false);
2578 // different triggred (for caster) and precast (casted before apply effect to target) cases
2579 switch(m_spellInfo
->SpellFamilyName
)
2581 case SPELLFAMILY_GENERIC
:
2583 if (m_spellInfo
->Mechanic
== MECHANIC_BANDAGE
) // Bandages
2584 AddPrecastSpell(11196); // Recently Bandaged
2585 else if(m_spellInfo
->SpellIconID
== 1662 && m_spellInfo
->AttributesEx
& 0x20)
2586 // Blood Fury (Racial)
2587 AddPrecastSpell(23230); // Blood Fury - Healing Reduction
2588 else if(m_spellInfo
->Id
== 20594) // Stoneskin
2589 AddTriggeredSpell(65116); // Stoneskin - armor 10% for 8 sec
2592 case SPELLFAMILY_MAGE
:
2595 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000008000000000))
2596 AddPrecastSpell(41425); // Hypothermia
2599 case SPELLFAMILY_PRIEST
:
2601 // Power Word: Shield
2602 if (m_spellInfo
->Mechanic
== MECHANIC_SHIELD
&&
2603 (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000001)))
2604 AddPrecastSpell(6788); // Weakened Soul
2605 // Prayer of Mending (jump animation), we need formal caster instead original for correct animation
2606 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000002000000000))
2607 AddTriggeredSpell(41637);
2609 switch(m_spellInfo
->Id
)
2611 case 15237: AddTriggeredSpell(23455); break;// Holy Nova, rank 1
2612 case 15430: AddTriggeredSpell(23458); break;// Holy Nova, rank 2
2613 case 15431: AddTriggeredSpell(23459); break;// Holy Nova, rank 3
2614 case 27799: AddTriggeredSpell(27803); break;// Holy Nova, rank 4
2615 case 27800: AddTriggeredSpell(27804); break;// Holy Nova, rank 5
2616 case 27801: AddTriggeredSpell(27805); break;// Holy Nova, rank 6
2617 case 25331: AddTriggeredSpell(25329); break;// Holy Nova, rank 7
2618 case 48077: AddTriggeredSpell(48075); break;// Holy Nova, rank 8
2619 case 48078: AddTriggeredSpell(48076); break;// Holy Nova, rank 9
2624 case SPELLFAMILY_DRUID
:
2626 // Faerie Fire (Feral)
2627 if (m_spellInfo
->Id
== 16857 && m_caster
->m_form
!= FORM_CAT
)
2628 AddTriggeredSpell(60089);
2631 case SPELLFAMILY_ROGUE
:
2632 // Fan of Knives (main hand)
2633 if (m_spellInfo
->Id
== 51723 && m_caster
->GetTypeId() == TYPEID_PLAYER
&&
2634 ((Player
*)m_caster
)->haveOffhandWeapon())
2636 AddTriggeredSpell(52874); // Fan of Knives (offhand)
2639 case SPELLFAMILY_PALADIN
:
2641 // Hand of Reckoning
2642 if (m_spellInfo
->Id
== 62124)
2644 if (m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->getVictim() != m_caster
)
2645 AddPrecastSpell(67485); // Hand of Rekoning (no typos in name ;) )
2647 // Divine Shield, Divine Protection or Hand of Protection
2648 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000400080))
2650 AddPrecastSpell(25771); // Forbearance
2651 AddPrecastSpell(61987); // Avenging Wrath Marker
2653 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x200000000000))
2654 AddPrecastSpell(61987); // Avenging Wrath Marker
2657 case SPELLFAMILY_SHAMAN
:
2660 if (m_spellInfo
->Id
== 2825)
2661 AddPrecastSpell(57724); // Sated
2663 else if (m_spellInfo
->Id
== 32182)
2664 AddPrecastSpell(57723); // Exhaustion
2665 else if (m_spellInfo
->Effect
[EFFECT_INDEX_0
]==SPELL_EFFECT_APPLY_AREA_AURA_RAID
&& m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000004000000))
2666 // only for main totem spell cast
2667 AddTriggeredSpell(30708); // Totem of Wrath
2674 // traded items have trade slot instead of guid in m_itemTargetGUID
2675 // set to real guid to be sent later to the client
2676 m_targets
.updateTradeSlotItem();
2678 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2680 if (!m_IsTriggeredSpell
&& m_CastItem
)
2681 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM
, m_CastItem
->GetEntry());
2683 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL
, m_spellInfo
->Id
);
2688 if(m_spellState
== SPELL_STATE_FINISHED
) // stop cast if spell marked as finish somewhere in FillTargetMap
2690 m_caster
->DecreaseCastCounter();
2691 SetExecutedCurrently(false);
2696 SendSpellCooldown();
2699 TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
2701 SendCastResult(castResult
);
2702 SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2704 // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2705 if (m_spellInfo
->speed
> 0.0f
)
2708 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2709 // in case delayed spell remove item at cast delay start
2712 // Okay, maps created, now prepare flags
2713 m_immediateHandled
= false;
2714 m_spellState
= SPELL_STATE_DELAYED
;
2719 // Immediate spell, no big deal
2723 m_caster
->DecreaseCastCounter();
2724 SetExecutedCurrently(false);
2727 void Spell::handle_immediate()
2729 // start channeling if applicable
2730 if(IsChanneledSpell(m_spellInfo
))
2732 int32 duration
= GetSpellDuration(m_spellInfo
);
2735 // Apply duration mod
2736 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
2737 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_DURATION
, duration
);
2738 m_spellState
= SPELL_STATE_CASTING
;
2739 SendChannelStart(duration
);
2743 // process immediate effects (items, ground, etc.) also initialize some variables
2744 _handle_immediate_phase();
2746 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2747 DoAllEffectOnTarget(&(*ihit
));
2749 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
2750 DoAllEffectOnTarget(&(*ihit
));
2752 // spell is finished, perform some last features of the spell here
2753 _handle_finish_phase();
2755 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2758 if(m_spellState
!= SPELL_STATE_CASTING
)
2759 finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell)
2762 uint64
Spell::handle_delayed(uint64 t_offset
)
2764 uint64 next_time
= 0;
2766 if (!m_immediateHandled
)
2768 _handle_immediate_phase();
2769 m_immediateHandled
= true;
2772 // 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)
2773 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2775 if (ihit
->processed
== false)
2777 if ( ihit
->timeDelay
<= t_offset
)
2778 DoAllEffectOnTarget(&(*ihit
));
2779 else if( next_time
== 0 || ihit
->timeDelay
< next_time
)
2780 next_time
= ihit
->timeDelay
;
2784 // now recheck gameobject targeting correctness
2785 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end(); ++ighit
)
2787 if (ighit
->processed
== false)
2789 if ( ighit
->timeDelay
<= t_offset
)
2790 DoAllEffectOnTarget(&(*ighit
));
2791 else if( next_time
== 0 || ighit
->timeDelay
< next_time
)
2792 next_time
= ighit
->timeDelay
;
2795 // All targets passed - need finish phase
2798 // spell is finished, perform some last features of the spell here
2799 _handle_finish_phase();
2801 finish(true); // successfully finish spell cast
2803 // return zero, spell is finished now
2808 // spell is unfinished, return next execution time
2813 void Spell::_handle_immediate_phase()
2815 // handle some immediate features of the spell here
2816 HandleThreatSpells(m_spellInfo
->Id
);
2818 m_needSpellLog
= IsNeedSendToClient();
2819 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
2821 if(m_spellInfo
->Effect
[j
] == 0)
2824 // apply Send Event effect to ground in case empty target lists
2825 if( m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
&& !HaveTargetsForEffect(SpellEffectIndex(j
)) )
2827 HandleEffects(NULL
, NULL
, NULL
, SpellEffectIndex(j
));
2831 // Don't do spell log, if is school damage spell
2832 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
|| m_spellInfo
->Effect
[j
] == 0)
2833 m_needSpellLog
= false;
2835 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[j
];
2836 if (Unit
* realCaster
= GetAffectiveCaster())
2837 if(Player
* modOwner
= realCaster
->GetSpellModOwner())
2838 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
2840 // initialize multipliers
2841 m_damageMultipliers
[j
] = 1.0f
;
2842 if( (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_HEAL
) &&
2843 (EffectChainTarget
> 1) )
2844 m_applyMultiplierMask
|= (1 << j
);
2847 // initialize Diminishing Returns Data
2848 m_diminishLevel
= DIMINISHING_LEVEL_1
;
2849 m_diminishGroup
= DIMINISHING_NONE
;
2852 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin(); ihit
!= m_UniqueItemInfo
.end(); ++ihit
)
2853 DoAllEffectOnTarget(&(*ihit
));
2856 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
2858 // persistent area auras target only the ground
2859 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2860 HandleEffects(NULL
, NULL
, NULL
, SpellEffectIndex(j
));
2864 void Spell::_handle_finish_phase()
2871 void Spell::SendSpellCooldown()
2873 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
2876 Player
* _player
= (Player
*)m_caster
;
2878 // mana/health/etc potions, disabled by client (until combat out as declarate)
2879 if (m_CastItem
&& m_CastItem
->IsPotion())
2881 // need in some way provided data for Spell::finish SendCooldownEvent
2882 _player
->SetLastPotionId(m_CastItem
->GetEntry());
2886 // (1) have infinity cooldown but set at aura apply, (2) passive cooldown at triggering
2887 if(m_spellInfo
->Attributes
& (SPELL_ATTR_DISABLED_WHILE_ACTIVE
| SPELL_ATTR_PASSIVE
))
2890 _player
->AddSpellAndCategoryCooldowns(m_spellInfo
, m_CastItem
? m_CastItem
->GetEntry() : 0, this);
2893 void Spell::update(uint32 difftime
)
2895 // update pointers based at it's GUIDs
2898 if(m_targets
.getUnitTargetGUID() && !m_targets
.getUnitTarget())
2904 // check if the player caster has moved before the spell finished
2905 if ((m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_timer
!= 0) &&
2906 (m_castPositionX
!= m_caster
->GetPositionX() || m_castPositionY
!= m_caster
->GetPositionY() || m_castPositionZ
!= m_caster
->GetPositionZ()) &&
2907 (m_spellInfo
->Effect
[EFFECT_INDEX_0
] != SPELL_EFFECT_STUCK
|| !((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEFLAG_FALLINGFAR
)))
2909 // always cancel for channeled spells
2910 if( m_spellState
== SPELL_STATE_CASTING
)
2912 // don't cancel for melee, autorepeat, triggered and instant spells
2913 else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_MOVEMENT
))
2917 switch(m_spellState
)
2919 case SPELL_STATE_PREPARING
:
2923 if(difftime
>= m_timer
)
2926 m_timer
-= difftime
;
2929 if(m_timer
== 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat())
2932 case SPELL_STATE_CASTING
:
2936 if( m_caster
->GetTypeId() == TYPEID_PLAYER
)
2938 // check if player has jumped before the channeling finished
2939 if(((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEFLAG_FALLING
))
2942 // check for incapacitating player states
2943 if( m_caster
->hasUnitState(UNIT_STAT_CAN_NOT_REACT
))
2946 // check if player has turned if flag is set
2947 if( m_spellInfo
->ChannelInterruptFlags
& CHANNEL_FLAG_TURNING
&& m_castOrientation
!= m_caster
->GetOrientation() )
2951 // check if there are alive targets left
2952 if (!IsAliveUnitPresentInTargetList())
2954 SendChannelUpdate(0);
2958 if(difftime
>= m_timer
)
2961 m_timer
-= difftime
;
2966 SendChannelUpdate(0);
2968 // channeled spell processed independently for quest targeting
2969 // cast at creature (or GO) quest objectives update at successful cast channel finished
2970 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
2971 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() )
2973 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
2975 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2977 TargetInfo
* target
= &*ihit
;
2978 if(!IS_CREATURE_GUID(target
->targetGUID
))
2981 Unit
* unit
= m_caster
->GetGUID() == target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, target
->targetGUID
);
2985 p
->CastedCreatureOrGO(unit
->GetEntry(), unit
->GetGUID(), m_spellInfo
->Id
);
2988 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
2990 GOTargetInfo
* target
= &*ihit
;
2992 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
2996 p
->CastedCreatureOrGO(go
->GetEntry(), go
->GetGUID(), m_spellInfo
->Id
);
3010 void Spell::finish(bool ok
)
3015 if(m_spellState
== SPELL_STATE_FINISHED
)
3018 m_spellState
= SPELL_STATE_FINISHED
;
3020 // other code related only to successfully finished spells
3024 // remove spell mods
3025 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3026 ((Player
*)m_caster
)->RemoveSpellMods(this);
3028 // handle SPELL_AURA_ADD_TARGET_TRIGGER auras
3029 Unit::AuraList
const& targetTriggers
= m_caster
->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER
);
3030 for(Unit::AuraList::const_iterator i
= targetTriggers
.begin(); i
!= targetTriggers
.end(); ++i
)
3032 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
3034 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3036 if( ihit
->missCondition
== SPELL_MISS_NONE
)
3038 // check m_caster->GetGUID() let load auras at login and speedup most often case
3039 Unit
*unit
= m_caster
->GetGUID()== ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
3040 if (unit
&& unit
->isAlive())
3042 SpellEntry
const *auraSpellInfo
= (*i
)->GetSpellProto();
3043 SpellEffectIndex auraSpellIdx
= (*i
)->GetEffIndex();
3044 // Calculate chance at that moment (can be depend for example from combo points)
3045 int32 chance
= m_caster
->CalculateSpellDamage(auraSpellInfo
, auraSpellIdx
, (*i
)->GetBasePoints(),unit
);
3046 if(roll_chance_i(chance
))
3047 m_caster
->CastSpell(unit
, auraSpellInfo
->EffectTriggerSpell
[auraSpellIdx
], true, NULL
, (*i
));
3053 // Heal caster for all health leech from all targets
3055 m_caster
->DealHeal(m_caster
, uint32(m_healthLeech
), m_spellInfo
);
3057 if (IsMeleeAttackResetSpell())
3059 m_caster
->resetAttackTimer(BASE_ATTACK
);
3060 if(m_caster
->haveOffhandWeapon())
3061 m_caster
->resetAttackTimer(OFF_ATTACK
);
3064 /*if (IsRangedAttackResetSpell())
3065 m_caster->resetAttackTimer(RANGED_ATTACK);*/
3067 // Clear combo at finish state
3068 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& NeedsComboPoints(m_spellInfo
))
3070 // Not drop combopoints if negative spell and if any miss on enemy exist
3071 bool needDrop
= true;
3072 if (!IsPositiveSpell(m_spellInfo
->Id
))
3074 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3076 if (ihit
->missCondition
!= SPELL_MISS_NONE
&& ihit
->targetGUID
!= m_caster
->GetGUID())
3084 ((Player
*)m_caster
)->ClearComboPoints();
3087 // potions disabled by client, send event "not in combat" if need
3088 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3089 ((Player
*)m_caster
)->UpdatePotionCooldown(this);
3091 // call triggered spell only at successful cast (after clear combo points -> for add some if need)
3092 if(!m_TriggerSpells
.empty())
3093 CastTriggerSpells();
3095 // Stop Attack for some spells
3096 if( m_spellInfo
->Attributes
& SPELL_ATTR_STOP_ATTACK_TARGET
)
3097 m_caster
->AttackStop();
3100 void Spell::SendCastResult(SpellCastResult result
)
3102 if(result
== SPELL_CAST_OK
)
3105 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3108 if(((Player
*)m_caster
)->GetSession()->PlayerLoading()) // don't send cast results at loading time
3111 SendCastResult((Player
*)m_caster
, m_spellInfo
, m_cast_count
, result
);
3114 void Spell::SendCastResult(Player
* caster
, SpellEntry
const* spellInfo
, uint8 cast_count
, SpellCastResult result
)
3116 if(result
== SPELL_CAST_OK
)
3119 WorldPacket
data(SMSG_CAST_FAILED
, (4+1+1));
3120 data
<< uint8(cast_count
); // single cast or multi 2.3 (0/1)
3121 data
<< uint32(spellInfo
->Id
);
3122 data
<< uint8(result
); // problem
3125 case SPELL_FAILED_REQUIRES_SPELL_FOCUS
:
3126 data
<< uint32(spellInfo
->RequiresSpellFocus
);
3128 case SPELL_FAILED_REQUIRES_AREA
:
3129 // hardcode areas limitation case
3130 switch(spellInfo
->Id
)
3132 case 41617: // Cenarion Mana Salve
3133 case 41619: // Cenarion Healing Salve
3134 data
<< uint32(3905);
3136 case 41618: // Bottled Nethergon Energy
3137 case 41620: // Bottled Nethergon Vapor
3138 data
<< uint32(3842);
3140 case 45373: // Bloodberry Elixir
3141 data
<< uint32(4075);
3143 default: // default case (don't must be)
3148 case SPELL_FAILED_TOTEMS
:
3149 if(spellInfo
->Totem
[0])
3150 data
<< uint32(spellInfo
->Totem
[0]);
3151 if(spellInfo
->Totem
[1])
3152 data
<< uint32(spellInfo
->Totem
[1]);
3154 case SPELL_FAILED_TOTEM_CATEGORY
:
3155 if(spellInfo
->TotemCategory
[0])
3156 data
<< uint32(spellInfo
->TotemCategory
[0]);
3157 if(spellInfo
->TotemCategory
[1])
3158 data
<< uint32(spellInfo
->TotemCategory
[1]);
3160 case SPELL_FAILED_EQUIPPED_ITEM_CLASS
:
3161 data
<< uint32(spellInfo
->EquippedItemClass
);
3162 data
<< uint32(spellInfo
->EquippedItemSubClassMask
);
3163 //data << uint32(spellInfo->EquippedItemInventoryTypeMask);
3168 caster
->GetSession()->SendPacket(&data
);
3171 void Spell::SendSpellStart()
3173 if (!IsNeedSendToClient())
3176 sLog
.outDebug("Sending SMSG_SPELL_START id=%u", m_spellInfo
->Id
);
3178 uint32 castFlags
= CAST_FLAG_UNKNOWN1
;
3179 if (IsRangedSpell())
3180 castFlags
|= CAST_FLAG_AMMO
;
3182 if (m_spellInfo
->runeCostID
)
3183 castFlags
|= CAST_FLAG_UNKNOWN10
;
3185 WorldPacket
data(SMSG_SPELL_START
, (8+8+4+4+2));
3187 data
.append(m_CastItem
->GetPackGUID());
3189 data
.append(m_caster
->GetPackGUID());
3191 data
.append(m_caster
->GetPackGUID());
3192 data
<< uint8(m_cast_count
); // pending spell cast?
3193 data
<< uint32(m_spellInfo
->Id
); // spellId
3194 data
<< uint32(castFlags
); // cast flags
3195 data
<< uint32(m_timer
); // delay?
3197 m_targets
.write(&data
);
3199 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // predicted power?
3202 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
3204 uint8 v1
= 0;//m_runesState;
3205 uint8 v2
= 0;//((Player*)m_caster)->GetRunesState();
3206 data
<< uint8(v1
); // runes state before
3207 data
<< uint8(v2
); // runes state after
3208 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
3211 if(m
& v1
) // usable before...
3212 if(!(m
& v2
)) // ...but on cooldown now...
3213 data
<< uint8(0); // some unknown byte (time?)
3217 if ( castFlags
& CAST_FLAG_AMMO
)
3218 WriteAmmoToPacket(&data
);
3220 if ( castFlags
& CAST_FLAG_UNKNOWN21
)
3226 m_caster
->SendMessageToSet(&data
, true);
3229 void Spell::SendSpellGo()
3231 // not send invisible spell casting
3232 if(!IsNeedSendToClient())
3235 sLog
.outDebug("Sending SMSG_SPELL_GO id=%u", m_spellInfo
->Id
);
3237 uint32 castFlags
= CAST_FLAG_UNKNOWN3
;
3239 castFlags
|= CAST_FLAG_AMMO
; // arrows/bullets visual
3241 if((m_caster
->GetTypeId() == TYPEID_PLAYER
) && (m_caster
->getClass() == CLASS_DEATH_KNIGHT
) && m_spellInfo
->runeCostID
)
3243 castFlags
|= CAST_FLAG_UNKNOWN10
; // same as in SMSG_SPELL_START
3244 castFlags
|= CAST_FLAG_UNKNOWN6
; // makes cooldowns visible
3245 castFlags
|= CAST_FLAG_UNKNOWN7
; // rune cooldowns list
3248 WorldPacket
data(SMSG_SPELL_GO
, 50); // guess size
3251 data
.append(m_CastItem
->GetPackGUID());
3253 data
.append(m_caster
->GetPackGUID());
3255 data
.append(m_caster
->GetPackGUID());
3256 data
<< uint8(m_cast_count
); // pending spell cast?
3257 data
<< uint32(m_spellInfo
->Id
); // spellId
3258 data
<< uint32(castFlags
); // cast flags
3259 data
<< uint32(getMSTime()); // timestamp
3261 WriteSpellGoTargets(&data
);
3263 m_targets
.write(&data
);
3265 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // unknown wotlk, predicted power?
3268 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
3270 uint8 v1
= m_runesState
;
3271 uint8 v2
= m_caster
->getClass() == CLASS_DEATH_KNIGHT
? ((Player
*)m_caster
)->GetRunesState() : 0;
3272 data
<< uint8(v1
); // runes state before
3273 data
<< uint8(v2
); // runes state after
3274 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
3277 if(m
& v1
) // usable before...
3278 if(!(m
& v2
)) // ...but on cooldown now...
3279 data
<< uint8(0); // some unknown byte (time?)
3283 if ( castFlags
& CAST_FLAG_UNKNOWN4
) // unknown wotlk
3289 if ( castFlags
& CAST_FLAG_AMMO
)
3290 WriteAmmoToPacket(&data
);
3292 if ( castFlags
& CAST_FLAG_UNKNOWN5
) // unknown wotlk
3298 if ( m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
3303 m_caster
->SendMessageToSet(&data
, true);
3306 void Spell::WriteAmmoToPacket( WorldPacket
* data
)
3308 uint32 ammoInventoryType
= 0;
3309 uint32 ammoDisplayID
= 0;
3311 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3313 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack( RANGED_ATTACK
);
3316 ammoInventoryType
= pItem
->GetProto()->InventoryType
;
3317 if( ammoInventoryType
== INVTYPE_THROWN
)
3318 ammoDisplayID
= pItem
->GetProto()->DisplayInfoID
;
3321 uint32 ammoID
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
3324 ItemPrototype
const *pProto
= ObjectMgr::GetItemPrototype( ammoID
);
3327 ammoDisplayID
= pProto
->DisplayInfoID
;
3328 ammoInventoryType
= pProto
->InventoryType
;
3331 else if(m_caster
->GetDummyAura(46699)) // Requires No Ammo
3333 ammoDisplayID
= 5996; // normal arrow
3334 ammoInventoryType
= INVTYPE_AMMO
;
3341 for (uint8 i
= 0; i
< 3; ++i
)
3343 if(uint32 item_id
= m_caster
->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID
+ i
))
3345 if(ItemEntry
const * itemEntry
= sItemStore
.LookupEntry(item_id
))
3347 if(itemEntry
->Class
== ITEM_CLASS_WEAPON
)
3349 switch(itemEntry
->SubClass
)
3351 case ITEM_SUBCLASS_WEAPON_THROWN
:
3352 ammoDisplayID
= itemEntry
->DisplayId
;
3353 ammoInventoryType
= itemEntry
->InventoryType
;
3355 case ITEM_SUBCLASS_WEAPON_BOW
:
3356 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
3357 ammoDisplayID
= 5996; // is this need fixing?
3358 ammoInventoryType
= INVTYPE_AMMO
;
3360 case ITEM_SUBCLASS_WEAPON_GUN
:
3361 ammoDisplayID
= 5998; // is this need fixing?
3362 ammoInventoryType
= INVTYPE_AMMO
;
3374 *data
<< uint32(ammoDisplayID
);
3375 *data
<< uint32(ammoInventoryType
);
3378 void Spell::WriteSpellGoTargets( WorldPacket
* data
)
3380 // This function also fill data for channeled spells:
3381 // m_needAliveTargetMask req for stop channeling if one target die
3382 uint32 hit
= m_UniqueGOTargetInfo
.size(); // Always hits on GO
3384 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3386 if ((*ihit
).effectMask
== 0) // No effect apply - all immuned add state
3388 // possibly SPELL_MISS_IMMUNE2 for this??
3389 ihit
->missCondition
= SPELL_MISS_IMMUNE2
;
3392 else if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
3398 *data
<< (uint8
)hit
;
3399 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3401 if ((*ihit
).missCondition
== SPELL_MISS_NONE
) // Add only hits
3403 *data
<< uint64(ihit
->targetGUID
);
3404 m_needAliveTargetMask
|=ihit
->effectMask
;
3408 for(std::list
<GOTargetInfo
>::const_iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end(); ++ighit
)
3409 *data
<< uint64(ighit
->targetGUID
); // Always hits
3411 *data
<< (uint8
)miss
;
3412 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3414 if( ihit
->missCondition
!= SPELL_MISS_NONE
) // Add only miss
3416 *data
<< uint64(ihit
->targetGUID
);
3417 *data
<< uint8(ihit
->missCondition
);
3418 if( ihit
->missCondition
== SPELL_MISS_REFLECT
)
3419 *data
<< uint8(ihit
->reflectResult
);
3422 // Reset m_needAliveTargetMask for non channeled spell
3423 if(!IsChanneledSpell(m_spellInfo
))
3424 m_needAliveTargetMask
= 0;
3427 void Spell::SendLogExecute()
3429 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
3431 WorldPacket
data(SMSG_SPELLLOGEXECUTE
, (8+4+4+4+4+8));
3433 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
3434 data
.append(m_caster
->GetPackGUID());
3436 data
.append(target
->GetPackGUID());
3438 data
<< uint32(m_spellInfo
->Id
);
3440 data
<< uint32(count1
); // count1 (effect count?)
3441 for(uint32 i
= 0; i
< count1
; ++i
)
3443 data
<< uint32(m_spellInfo
->Effect
[EFFECT_INDEX_0
]);// spell effect
3445 data
<< uint32(count2
); // count2 (target count?)
3446 for(uint32 j
= 0; j
< count2
; ++j
)
3448 switch(m_spellInfo
->Effect
[EFFECT_INDEX_0
])
3450 case SPELL_EFFECT_POWER_DRAIN
:
3451 if(Unit
*unit
= m_targets
.getUnitTarget())
3452 data
.append(unit
->GetPackGUID());
3459 case SPELL_EFFECT_ADD_EXTRA_ATTACKS
:
3460 if(Unit
*unit
= m_targets
.getUnitTarget())
3461 data
.append(unit
->GetPackGUID());
3464 data
<< uint32(0); // count?
3466 case SPELL_EFFECT_INTERRUPT_CAST
:
3467 if(Unit
*unit
= m_targets
.getUnitTarget())
3468 data
.append(unit
->GetPackGUID());
3471 data
<< uint32(0); // spellid
3473 case SPELL_EFFECT_DURABILITY_DAMAGE
:
3474 if(Unit
*unit
= m_targets
.getUnitTarget())
3475 data
.append(unit
->GetPackGUID());
3481 case SPELL_EFFECT_OPEN_LOCK
:
3482 if(Item
*item
= m_targets
.getItemTarget())
3483 data
.append(item
->GetPackGUID());
3487 case SPELL_EFFECT_CREATE_ITEM
:
3488 case SPELL_EFFECT_CREATE_ITEM_2
:
3489 data
<< uint32(m_spellInfo
->EffectItemType
[EFFECT_INDEX_0
]);
3491 case SPELL_EFFECT_SUMMON
:
3492 case SPELL_EFFECT_TRANS_DOOR
:
3493 case SPELL_EFFECT_SUMMON_PET
:
3494 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
3495 case SPELL_EFFECT_CREATE_HOUSE
:
3496 case SPELL_EFFECT_DUEL
:
3497 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1
:
3498 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2
:
3499 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3
:
3500 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4
:
3501 if(Unit
*unit
= m_targets
.getUnitTarget())
3502 data
.append(unit
->GetPackGUID());
3503 else if(m_targets
.getItemTargetGUID())
3504 data
.appendPackGUID(m_targets
.getItemTargetGUID());
3505 else if(GameObject
*go
= m_targets
.getGOTarget())
3506 data
.append(go
->GetPackGUID());
3508 data
<< uint8(0); // guid
3510 case SPELL_EFFECT_FEED_PET
:
3511 data
<< uint32(m_targets
.getItemTargetEntry());
3513 case SPELL_EFFECT_DISMISS_PET
:
3514 if(Unit
*unit
= m_targets
.getUnitTarget())
3515 data
.append(unit
->GetPackGUID());
3519 case SPELL_EFFECT_RESURRECT
:
3520 case SPELL_EFFECT_RESURRECT_NEW
:
3521 if(Unit
*unit
= m_targets
.getUnitTarget())
3522 data
.append(unit
->GetPackGUID());
3532 m_caster
->SendMessageToSet(&data
, true);
3535 void Spell::SendInterrupted(uint8 result
)
3537 WorldPacket
data(SMSG_SPELL_FAILURE
, (8+4+1));
3538 data
.append(m_caster
->GetPackGUID());
3539 data
<< uint8(m_cast_count
);
3540 data
<< uint32(m_spellInfo
->Id
);
3541 data
<< uint8(result
);
3542 m_caster
->SendMessageToSet(&data
, true);
3544 data
.Initialize(SMSG_SPELL_FAILED_OTHER
, (8+4));
3545 data
.append(m_caster
->GetPackGUID());
3546 data
<< uint8(m_cast_count
);
3547 data
<< uint32(m_spellInfo
->Id
);
3548 data
<< uint8(result
);
3549 m_caster
->SendMessageToSet(&data
, true);
3552 void Spell::SendChannelUpdate(uint32 time
)
3556 m_caster
->RemoveAurasByCasterSpell(m_spellInfo
->Id
, m_caster
->GetGUID());
3558 if(uint64 target_guid
= m_caster
->GetChannelObjectGUID())
3559 if(target_guid
!= m_caster
->GetGUID() && IS_UNIT_GUID(target_guid
))
3560 if(Unit
* target
= ObjectAccessor::GetUnit(*m_caster
, target_guid
))
3561 target
->RemoveAurasByCasterSpell(m_spellInfo
->Id
, m_caster
->GetGUID());
3563 m_caster
->SetChannelObjectGUID(0);
3564 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, 0);
3567 WorldPacket
data( MSG_CHANNEL_UPDATE
, 8+4 );
3568 data
.append(m_caster
->GetPackGUID());
3569 data
<< uint32(time
);
3570 m_caster
->SendMessageToSet(&data
, true);
3573 void Spell::SendChannelStart(uint32 duration
)
3575 WorldObject
* target
= NULL
;
3577 // select first not resisted target from target list for _0_ effect
3578 if(!m_UniqueTargetInfo
.empty())
3580 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin(); itr
!= m_UniqueTargetInfo
.end(); ++itr
)
3582 if( (itr
->effectMask
& (1 << 0)) && itr
->reflectResult
== SPELL_MISS_NONE
&& itr
->targetGUID
!= m_caster
->GetGUID())
3584 target
= ObjectAccessor::GetUnit(*m_caster
, itr
->targetGUID
);
3589 else if(!m_UniqueGOTargetInfo
.empty())
3591 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin(); itr
!= m_UniqueGOTargetInfo
.end(); ++itr
)
3593 if(itr
->effectMask
& (1 << 0) )
3595 target
= m_caster
->GetMap()->GetGameObject(itr
->targetGUID
);
3601 WorldPacket
data( MSG_CHANNEL_START
, (8+4+4) );
3602 data
.append(m_caster
->GetPackGUID());
3603 data
<< uint32(m_spellInfo
->Id
);
3604 data
<< uint32(duration
);
3605 m_caster
->SendMessageToSet(&data
, true);
3610 m_caster
->SetChannelObjectGUID(target
->GetGUID());
3612 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, m_spellInfo
->Id
);
3615 void Spell::SendResurrectRequest(Player
* target
)
3617 // Both players and NPCs can resurrect using spells - have a look at creature 28487 for example
3618 // However, the packet structure differs slightly
3620 const char* sentName
= m_caster
->GetTypeId() == TYPEID_PLAYER
? "" : m_caster
->GetNameForLocaleIdx(target
->GetSession()->GetSessionDbLocaleIndex());
3622 WorldPacket
data(SMSG_RESURRECT_REQUEST
, (8+4+strlen(sentName
)+1+1+1));
3623 data
<< uint64(m_caster
->GetGUID());
3624 data
<< uint32(strlen(sentName
) + 1);
3629 data
<< uint8(m_caster
->GetTypeId() == TYPEID_PLAYER
? 0 : 1);
3630 target
->GetSession()->SendPacket(&data
);
3633 void Spell::SendPlaySpellVisual(uint32 SpellID
)
3635 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3638 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 8 + 4);
3639 data
<< uint64(m_caster
->GetGUID());
3640 data
<< uint32(SpellID
); // spell visual id?
3641 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
3644 void Spell::TakeCastItem()
3646 if(!m_CastItem
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
3649 // not remove cast item at triggered spell (equipping, weapon damage, etc)
3650 if(m_IsTriggeredSpell
)
3653 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3657 // This code is to avoid a crash
3658 // I'm not sure, if this is really an error, but I guess every item needs a prototype
3659 sLog
.outError("Cast item has no item prototype highId=%d, lowId=%d",m_CastItem
->GetGUIDHigh(), m_CastItem
->GetGUIDLow());
3663 bool expendable
= false;
3664 bool withoutCharges
= false;
3666 for (int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
3668 if (proto
->Spells
[i
].SpellId
)
3670 // item has limited charges
3671 if (proto
->Spells
[i
].SpellCharges
)
3673 if (proto
->Spells
[i
].SpellCharges
< 0 && !proto
->NonConsumable
)
3676 int32 charges
= m_CastItem
->GetSpellCharges(i
);
3678 // item has charges left
3681 (charges
> 0) ? --charges
: ++charges
; // abs(charges) less at 1 after use
3682 if (proto
->Stackable
== 1)
3683 m_CastItem
->SetSpellCharges(i
, charges
);
3684 m_CastItem
->SetState(ITEM_CHANGED
, (Player
*)m_caster
);
3688 withoutCharges
= (charges
== 0);
3693 if (expendable
&& withoutCharges
)
3696 ((Player
*)m_caster
)->DestroyItemCount(m_CastItem
, count
, true);
3698 // prevent crash at access to deleted m_targets.getItemTarget
3699 if(m_CastItem
==m_targets
.getItemTarget())
3700 m_targets
.setItemTarget(NULL
);
3706 void Spell::TakePower()
3708 if(m_CastItem
|| m_triggeredByAuraSpell
)
3711 // health as power used
3712 if(m_spellInfo
->powerType
== POWER_HEALTH
)
3714 m_caster
->ModifyHealth( -(int32
)m_powerCost
);
3718 if(m_spellInfo
->powerType
>= MAX_POWERS
)
3720 sLog
.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo
->powerType
);
3724 Powers powerType
= Powers(m_spellInfo
->powerType
);
3726 if(powerType
== POWER_RUNE
)
3728 CheckOrTakeRunePower(true);
3732 m_caster
->ModifyPower(powerType
, -(int32
)m_powerCost
);
3734 // Set the five second timer
3735 if (powerType
== POWER_MANA
&& m_powerCost
> 0)
3736 m_caster
->SetLastManaUse();
3739 SpellCastResult
Spell::CheckOrTakeRunePower(bool take
)
3741 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3742 return SPELL_CAST_OK
;
3744 Player
*plr
= (Player
*)m_caster
;
3746 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3747 return SPELL_CAST_OK
;
3749 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(m_spellInfo
->runeCostID
);
3752 return SPELL_CAST_OK
;
3754 if(src
->NoRuneCost() && (!take
|| src
->NoRunicPowerGain()))
3755 return SPELL_CAST_OK
;
3758 m_runesState
= plr
->GetRunesState(); // store previous state
3760 // at this moment for rune cost exist only no cost mods, and no percent mods
3761 int32 runeCostMod
= 10000;
3762 if(Player
* modOwner
= plr
->GetSpellModOwner())
3763 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, runeCostMod
, this);
3765 if (runeCostMod
> 0)
3767 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3769 // init cost data and apply mods
3770 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3771 runeCost
[i
] = runeCostMod
> 0 ? src
->RuneCost
[i
] : 0;
3773 runeCost
[RUNE_DEATH
] = 0; // calculated later
3775 // scan non-death runes (death rune not used explicitly in rune costs)
3776 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3778 RuneType rune
= plr
->GetCurrentRune(i
);
3779 if (runeCost
[rune
] <= 0)
3783 if(plr
->GetRuneCooldown(i
) != 0)
3787 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3792 // collect all not counted rune costs to death runes cost
3793 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3795 runeCost
[RUNE_DEATH
] += runeCost
[i
];
3798 if(runeCost
[RUNE_DEATH
] > 0)
3800 for(uint32 i
= 0; i
< MAX_RUNES
&& runeCost
[RUNE_DEATH
]; ++i
)
3802 RuneType rune
= plr
->GetCurrentRune(i
);
3803 if (rune
!= RUNE_DEATH
)
3807 if(plr
->GetRuneCooldown(i
) != 0)
3811 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3816 plr
->ConvertRune(i
, plr
->GetBaseRune(i
));
3820 if(!take
&& runeCost
[RUNE_DEATH
] > 0)
3821 return SPELL_FAILED_NO_POWER
; // not sure if result code is correct
3826 // you can gain some runic power when use runes
3827 float rp
= float(src
->runePowerGain
);
3828 rp
*= sWorld
.getConfig(CONFIG_FLOAT_RATE_POWER_RUNICPOWER_INCOME
);
3829 plr
->ModifyPower(POWER_RUNIC_POWER
, (int32
)rp
);
3832 return SPELL_CAST_OK
;
3835 void Spell::TakeReagents()
3837 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3840 if (IgnoreItemRequirements()) // reagents used in triggered spell removed by original spell or don't must be removed.
3843 Player
* p_caster
= (Player
*)m_caster
;
3844 if (p_caster
->CanNoReagentCast(m_spellInfo
) )
3847 for(uint32 x
= 0; x
< 8; ++x
)
3849 if(m_spellInfo
->Reagent
[x
] <= 0)
3852 uint32 itemid
= m_spellInfo
->Reagent
[x
];
3853 uint32 itemcount
= m_spellInfo
->ReagentCount
[x
];
3855 // if CastItem is also spell reagent
3858 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3859 if( proto
&& proto
->ItemId
== itemid
)
3861 for(int s
= 0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
3863 // CastItem will be used up and does not count as reagent
3864 int32 charges
= m_CastItem
->GetSpellCharges(s
);
3865 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
3876 // if getItemTarget is also spell reagent
3877 if (m_targets
.getItemTargetEntry() == itemid
)
3878 m_targets
.setItemTarget(NULL
);
3880 p_caster
->DestroyItemCount(itemid
, itemcount
, true);
3884 void Spell::HandleThreatSpells(uint32 spellId
)
3886 if(!m_targets
.getUnitTarget() || !spellId
)
3889 if(!m_targets
.getUnitTarget()->CanHaveThreatList())
3892 uint16 threat
= sSpellMgr
.GetSpellThreat(spellId
);
3897 m_targets
.getUnitTarget()->AddThreat(m_caster
, float(threat
), false, GetSpellSchoolMask(m_spellInfo
), m_spellInfo
);
3899 DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId
, sSpellMgr
.GetSpellRank(spellId
), threat
);
3902 void Spell::HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,SpellEffectIndex i
, float DamageMultiplier
)
3904 unitTarget
= pUnitTarget
;
3905 itemTarget
= pItemTarget
;
3906 gameObjTarget
= pGOTarget
;
3908 uint8 eff
= m_spellInfo
->Effect
[i
];
3910 damage
= int32(CalculateDamage(i
, unitTarget
) * DamageMultiplier
);
3912 sLog
.outDebug( "Spell %u Effect%d : %u", m_spellInfo
->Id
, i
, eff
);
3914 if(eff
<TOTAL_SPELL_EFFECTS
)
3916 //sLog.outDebug( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff);
3917 (*this.*SpellEffects
[eff
])(i
);
3922 sLog.outDebug( "WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff);
3924 EffectEnchantItemTmp(i);
3927 sLog.outError("SPELL: unknown effect %u spell id %u",
3928 eff, m_spellInfo->Id);
3935 void Spell::AddTriggeredSpell( uint32 spellId
)
3937 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3941 sLog
.outError("Spell::AddTriggeredSpell: unknown spell id %u used as triggred spell for spell %u)", spellId
, m_spellInfo
->Id
);
3945 m_TriggerSpells
.push_back(spellInfo
);
3948 void Spell::AddPrecastSpell( uint32 spellId
)
3950 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
3954 sLog
.outError("Spell::AddPrecastSpell: unknown spell id %u used as pre-cast spell for spell %u)", spellId
, m_spellInfo
->Id
);
3958 m_preCastSpells
.push_back(spellInfo
);
3961 void Spell::CastTriggerSpells()
3963 for(SpellInfoList::const_iterator si
= m_TriggerSpells
.begin(); si
!= m_TriggerSpells
.end(); ++si
)
3965 Spell
* spell
= new Spell(m_caster
, (*si
), true, m_originalCasterGUID
, m_selfContainer
);
3966 spell
->prepare(&m_targets
); // use original spell original targets
3970 void Spell::CastPreCastSpells(Unit
* target
)
3972 for(SpellInfoList::const_iterator si
= m_preCastSpells
.begin(); si
!= m_preCastSpells
.end(); ++si
)
3973 m_caster
->CastSpell(target
, (*si
), true, m_CastItem
);
3976 SpellCastResult
Spell::CheckCast(bool strict
)
3978 // check cooldowns to prevent cheating (ignore passive spells, that client side visual only)
3979 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& !(m_spellInfo
->Attributes
& SPELL_ATTR_PASSIVE
) &&
3980 ((Player
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
3982 if(m_triggeredByAuraSpell
)
3983 return SPELL_FAILED_DONT_REPORT
;
3985 return SPELL_FAILED_NOT_READY
;
3988 // only allow triggered spells if at an ended battleground
3989 if( !m_IsTriggeredSpell
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
3990 if(BattleGround
* bg
= ((Player
*)m_caster
)->GetBattleGround())
3991 if(bg
->GetStatus() == STATUS_WAIT_LEAVE
)
3992 return SPELL_FAILED_DONT_REPORT
;
3994 // only check at first call, Stealth auras are already removed at second call
3995 // for now, ignore triggered spells
3996 if( strict
&& !m_IsTriggeredSpell
)
3998 bool checkForm
= true;
3999 // Ignore form req aura
4000 Unit::AuraList
const& ignore
= m_caster
->GetAurasByType(SPELL_AURA_MOD_IGNORE_SHAPESHIFT
);
4001 for(Unit::AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
4003 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
4010 // Cannot be used in this stance/form
4011 SpellCastResult shapeError
= GetErrorAtShapeshiftedCast(m_spellInfo
, m_caster
->m_form
);
4012 if(shapeError
!= SPELL_CAST_OK
)
4015 if ((m_spellInfo
->Attributes
& SPELL_ATTR_ONLY_STEALTHED
) && !(m_caster
->HasStealthAura()))
4016 return SPELL_FAILED_ONLY_STEALTHED
;
4020 // caster state requirements
4021 if(m_spellInfo
->CasterAuraState
&& !m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraState
)))
4022 return SPELL_FAILED_CASTER_AURASTATE
;
4023 if(m_spellInfo
->CasterAuraStateNot
&& m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraStateNot
)))
4024 return SPELL_FAILED_CASTER_AURASTATE
;
4026 // Caster aura req check if need
4027 if(m_spellInfo
->casterAuraSpell
&& !m_caster
->HasAura(m_spellInfo
->casterAuraSpell
))
4028 return SPELL_FAILED_CASTER_AURASTATE
;
4029 if(m_spellInfo
->excludeCasterAuraSpell
)
4031 // Special cases of non existing auras handling
4032 if(m_spellInfo
->excludeCasterAuraSpell
== 61988)
4034 // Avenging Wrath Marker
4035 if(m_caster
->HasAura(61987))
4036 return SPELL_FAILED_CASTER_AURASTATE
;
4038 else if(m_caster
->HasAura(m_spellInfo
->excludeCasterAuraSpell
))
4039 return SPELL_FAILED_CASTER_AURASTATE
;
4042 // cancel autorepeat spells if cast start when moving
4043 // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
4044 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)m_caster
)->isMoving() )
4046 // skip stuck spell to allow use it in falling case and apply spell limitations at movement
4047 if( (!((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEFLAG_FALLINGFAR
) || m_spellInfo
->Effect
[EFFECT_INDEX_0
] != SPELL_EFFECT_STUCK
) &&
4048 (IsAutoRepeat() || (m_spellInfo
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_NOT_SEATED
) != 0) )
4049 return SPELL_FAILED_MOVING
;
4052 if(Unit
*target
= m_targets
.getUnitTarget())
4054 // target state requirements (not allowed state), apply to self also
4055 if(m_spellInfo
->TargetAuraStateNot
&& target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraStateNot
)))
4056 return SPELL_FAILED_TARGET_AURASTATE
;
4058 if (!m_IsTriggeredSpell
&& IsDeathOnlySpell(m_spellInfo
) && target
->isAlive())
4059 return SPELL_FAILED_TARGET_NOT_DEAD
;
4061 // Target aura req check if need
4062 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
4063 return SPELL_FAILED_CASTER_AURASTATE
;
4064 if(m_spellInfo
->excludeTargetAuraSpell
)
4066 // Special cases of non existing auras handling
4067 if (m_spellInfo
->excludeTargetAuraSpell
== 61988)
4069 // Avenging Wrath Marker
4070 if (target
->HasAura(61987))
4071 return SPELL_FAILED_CASTER_AURASTATE
;
4074 else if (target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
4075 return SPELL_FAILED_CASTER_AURASTATE
;
4078 bool non_caster_target
= target
!= m_caster
&& !IsSpellWithCasterSourceTargetsOnly(m_spellInfo
);
4080 if(non_caster_target
)
4082 // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds
4083 if(m_spellInfo
->TargetAuraState
&& !target
->HasAuraStateForCaster(AuraState(m_spellInfo
->TargetAuraState
),m_caster
->GetGUID()))
4084 return SPELL_FAILED_TARGET_AURASTATE
;
4086 // Not allow casting on flying player
4087 if (target
->isInFlight())
4088 return SPELL_FAILED_BAD_TARGETS
;
4090 if(!m_IsTriggeredSpell
&& VMAP::VMapFactory::checkSpellForLoS(m_spellInfo
->Id
) && !m_caster
->IsWithinLOSInMap(target
))
4091 return SPELL_FAILED_LINE_OF_SIGHT
;
4093 // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode
4094 // this case can be triggered if rank not found (too low-level target for first rank)
4095 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsPassiveSpell(m_spellInfo
->Id
) && !m_CastItem
)
4097 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4099 // check only spell that apply positive auras
4100 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_APPLY_AURA
&&
4101 IsPositiveEffect(m_spellInfo
->Id
, SpellEffectIndex(i
)) &&
4102 // at not self target
4103 !IsCasterSourceTarget(m_spellInfo
->EffectImplicitTargetA
[i
]) &&
4104 // and target low level
4105 target
->getLevel() + 10 < m_spellInfo
->spellLevel
)
4107 return SPELL_FAILED_LOWLEVEL
;
4112 else if (m_caster
== target
)
4115 if (m_caster
->GetTypeId() == TYPEID_PLAYER
) // Target - is player caster
4117 // Additional check for some spells
4118 // If 0 spell effect empty - client not send target data (need use selection)
4119 // TODO: check it on next client version
4120 if (m_targets
.m_targetMask
== TARGET_FLAG_SELF
&&
4121 m_spellInfo
->EffectImplicitTargetA
[EFFECT_INDEX_1
] == TARGET_CHAIN_DAMAGE
)
4123 if (target
= m_caster
->GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection()))
4124 m_targets
.setUnitTarget(target
);
4126 return SPELL_FAILED_BAD_TARGETS
;
4130 // Some special spells with non-caster only mode
4133 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
4134 m_spellInfo
->SpellIconID
== 16)
4135 return SPELL_FAILED_BAD_TARGETS
;
4137 // Focus Magic (main spell)
4138 if (m_spellInfo
->Id
== 54646)
4139 return SPELL_FAILED_BAD_TARGETS
;
4142 // check pet presents
4143 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4145 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_PET
)
4147 target
= m_caster
->GetPet();
4150 if(m_triggeredByAuraSpell
) // not report pet not existence for triggered spells
4151 return SPELL_FAILED_DONT_REPORT
;
4153 return SPELL_FAILED_NO_PET
;
4159 //check creature type
4160 //ignore self casts (including area casts when caster selected as target)
4161 if(non_caster_target
)
4163 if(!CheckTargetCreatureType(target
))
4165 if(target
->GetTypeId() == TYPEID_PLAYER
)
4166 return SPELL_FAILED_TARGET_IS_PLAYER
;
4168 return SPELL_FAILED_BAD_TARGETS
;
4172 if(non_caster_target
)
4175 bool explicit_target_mode
= false;
4176 bool target_hostile
= false;
4177 bool target_hostile_checked
= false;
4178 bool target_friendly
= false;
4179 bool target_friendly_checked
= false;
4180 for(int k
= 0; k
< MAX_EFFECT_INDEX
; ++k
)
4182 if (IsExplicitPositiveTarget(m_spellInfo
->EffectImplicitTargetA
[k
]))
4184 if (!target_hostile_checked
)
4186 target_hostile_checked
= true;
4187 target_hostile
= m_caster
->IsHostileTo(target
);
4191 return SPELL_FAILED_BAD_TARGETS
;
4193 explicit_target_mode
= true;
4195 else if (IsExplicitNegativeTarget(m_spellInfo
->EffectImplicitTargetA
[k
]))
4197 if (!target_friendly_checked
)
4199 target_friendly_checked
= true;
4200 target_friendly
= m_caster
->IsFriendlyTo(target
);
4204 return SPELL_FAILED_BAD_TARGETS
;
4206 explicit_target_mode
= true;
4209 // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
4210 // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
4211 if (!explicit_target_mode
&& m_caster
->GetTypeId() == TYPEID_UNIT
&& m_caster
->GetCharmerOrOwnerGUID())
4213 // check correctness positive/negative cast target (pet cast real check and cheating check)
4214 if(IsPositiveSpell(m_spellInfo
->Id
))
4216 if (!target_hostile_checked
)
4218 target_hostile_checked
= true;
4219 target_hostile
= m_caster
->IsHostileTo(target
);
4223 return SPELL_FAILED_BAD_TARGETS
;
4227 if (!target_friendly_checked
)
4229 target_friendly_checked
= true;
4230 target_friendly
= m_caster
->IsFriendlyTo(target
);
4234 return SPELL_FAILED_BAD_TARGETS
;
4239 if(IsPositiveSpell(m_spellInfo
->Id
))
4240 if(target
->IsImmunedToSpell(m_spellInfo
))
4241 return SPELL_FAILED_TARGET_AURASTATE
;
4243 //Must be behind the target.
4244 if( m_spellInfo
->AttributesEx2
== 0x100000 && (m_spellInfo
->AttributesEx
& 0x200) == 0x200 && target
->HasInArc(M_PI_F
, m_caster
) )
4246 // Exclusion for Pounce: Facing Limitation was removed in 2.0.1, but it still uses the same, old Ex-Flags
4247 // Exclusion for Mutilate:Facing Limitation was removed in 2.0.1 and 3.0.3, but they still use the same, old Ex-Flags
4248 // Exclusion for Throw: Facing limitation was added in 3.2.x, but that shouldn't be
4249 if ((m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_DRUID
|| (m_spellInfo
->SpellFamilyFlags
!= UI64LIT(0x0000000000020000))) &&
4250 (m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_ROGUE
|| (m_spellInfo
->SpellFamilyFlags
!= UI64LIT(0x0020000000000000))) &&
4251 m_spellInfo
->Id
!= 2764)
4254 return SPELL_FAILED_NOT_BEHIND
;
4258 //Target must be facing you.
4259 if((m_spellInfo
->Attributes
== 0x150010) && !target
->HasInArc(M_PI_F
, m_caster
) )
4262 return SPELL_FAILED_NOT_INFRONT
;
4265 // check if target is in combat
4266 if (non_caster_target
&& (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET
) && target
->isInCombat())
4267 return SPELL_FAILED_TARGET_AFFECTING_COMBAT
;
4271 m_caster
->GetZoneAndAreaId(zone
, area
);
4273 SpellCastResult locRes
= sSpellMgr
.GetSpellAllowedInLocationError(m_spellInfo
, m_caster
->GetMapId(), zone
, area
,
4274 m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself());
4275 if (locRes
!= SPELL_CAST_OK
)
4278 // not let players cast spells at mount (and let do it to creatures)
4279 if (m_caster
->IsMounted() && m_caster
->GetTypeId()==TYPEID_PLAYER
&& !m_IsTriggeredSpell
&&
4280 !IsPassiveSpell(m_spellInfo
->Id
) && !(m_spellInfo
->Attributes
& SPELL_ATTR_CASTABLE_WHILE_MOUNTED
))
4282 if (m_caster
->isInFlight())
4283 return SPELL_FAILED_NOT_ON_TAXI
;
4285 return SPELL_FAILED_NOT_MOUNTED
;
4288 // always (except passive spells) check items (focus object can be required for any type casts)
4289 if (!IsPassiveSpell(m_spellInfo
->Id
))
4291 SpellCastResult castResult
= CheckItems();
4292 if(castResult
!= SPELL_CAST_OK
)
4296 // Database based targets from spell_target_script
4297 if (m_UniqueTargetInfo
.empty()) // skip second CheckCast apply (for delayed spells for example)
4299 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4301 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
4302 (m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_SELF
) ||
4303 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4304 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
||
4305 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
)
4308 SpellScriptTargetBounds bounds
= sSpellMgr
.GetSpellScriptTargetBounds(m_spellInfo
->Id
);
4310 if (bounds
.first
== bounds
.second
)
4311 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
);
4313 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4314 float range
= GetSpellMaxRange(srange
);
4316 Creature
* creatureScriptTarget
= NULL
;
4317 GameObject
* goScriptTarget
= NULL
;
4319 for(SpellScriptTarget::const_iterator i_spellST
= bounds
.first
; i_spellST
!= bounds
.second
; ++i_spellST
)
4321 switch(i_spellST
->second
.type
)
4323 case SPELL_TARGET_TYPE_GAMEOBJECT
:
4325 GameObject
* p_GameObject
= NULL
;
4327 if (i_spellST
->second
.targetEntry
)
4329 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4331 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4333 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*m_caster
, i_spellST
->second
.targetEntry
, range
);
4334 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(m_caster
, p_GameObject
, go_check
);
4336 TypeContainerVisitor
<MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
>, GridTypeMapContainer
> object_checker(checker
);
4337 cell
.Visit(p
, object_checker
, *m_caster
->GetMap(), *m_caster
, range
);
4341 // remember found target and range, next attempt will find more near target with another entry
4342 creatureScriptTarget
= NULL
;
4343 goScriptTarget
= p_GameObject
;
4344 range
= go_check
.GetLastRange();
4347 else if (focusObject
) // Focus Object
4349 float frange
= m_caster
->GetDistance(focusObject
);
4350 if (range
>= frange
)
4352 creatureScriptTarget
= NULL
;
4353 goScriptTarget
= focusObject
;
4359 case SPELL_TARGET_TYPE_CREATURE
:
4360 case SPELL_TARGET_TYPE_DEAD
:
4363 Creature
*p_Creature
= NULL
;
4365 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4367 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4370 MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
u_check(*m_caster
, i_spellST
->second
.targetEntry
, i_spellST
->second
.type
!= SPELL_TARGET_TYPE_DEAD
, range
);
4371 MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
> searcher(m_caster
, p_Creature
, u_check
);
4373 TypeContainerVisitor
<MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
>, GridTypeMapContainer
> grid_creature_searcher(searcher
);
4375 cell
.Visit(p
, grid_creature_searcher
, *m_caster
->GetMap(), *m_caster
, range
);
4379 creatureScriptTarget
= p_Creature
;
4380 goScriptTarget
= NULL
;
4381 range
= u_check
.GetLastRange();
4388 if (creatureScriptTarget
)
4390 // store coordinates for TARGET_SCRIPT_COORDINATES
4391 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4392 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4394 m_targets
.setDestination(creatureScriptTarget
->GetPositionX(),creatureScriptTarget
->GetPositionY(),creatureScriptTarget
->GetPositionZ());
4396 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->Effect
[j
] != SPELL_EFFECT_PERSISTENT_AREA_AURA
)
4397 AddUnitTarget(creatureScriptTarget
, SpellEffectIndex(j
));
4399 // store explicit target for TARGET_SCRIPT
4402 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
4403 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
)
4404 AddUnitTarget(creatureScriptTarget
, SpellEffectIndex(j
));
4407 else if (goScriptTarget
)
4409 // store coordinates for TARGET_SCRIPT_COORDINATES
4410 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4411 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4413 m_targets
.setDestination(goScriptTarget
->GetPositionX(),goScriptTarget
->GetPositionY(),goScriptTarget
->GetPositionZ());
4415 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->Effect
[j
] != SPELL_EFFECT_PERSISTENT_AREA_AURA
)
4416 AddGOTarget(goScriptTarget
, SpellEffectIndex(j
));
4418 // store explicit target for TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
4421 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
||
4422 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
)
4423 AddGOTarget(goScriptTarget
, SpellEffectIndex(j
));
4426 //Missing DB Entry or targets for this spellEffect.
4429 /* For TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT makes DB targets optional not required for now
4430 * TODO: Makes more research for this target type
4432 if (m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
)
4434 // not report target not existence for triggered spells
4435 if (m_triggeredByAuraSpell
|| m_IsTriggeredSpell
)
4436 return SPELL_FAILED_DONT_REPORT
;
4438 return SPELL_FAILED_BAD_TARGETS
;
4445 if(!m_IsTriggeredSpell
)
4447 SpellCastResult castResult
= CheckRange(strict
);
4448 if(castResult
!= SPELL_CAST_OK
)
4453 SpellCastResult castResult
= CheckPower();
4454 if(castResult
!= SPELL_CAST_OK
)
4458 if(!m_IsTriggeredSpell
) // triggered spell not affected by stun/etc
4460 SpellCastResult castResult
= CheckCasterAuras();
4461 if(castResult
!= SPELL_CAST_OK
)
4465 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4467 // for effects of spells that have only one target
4468 switch(m_spellInfo
->Effect
[i
])
4470 case SPELL_EFFECT_INSTAKILL
:
4472 if(m_spellInfo
->Id
== 48743)
4474 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4475 return SPELL_FAILED_ERROR
;
4477 if (!((Player
*)m_caster
)->GetSelection())
4478 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4479 Pet
* target
= m_caster
->GetMap()->GetPet(((Player
*)m_caster
)->GetSelection());
4482 if (!target
|| target
->isDead())
4483 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4485 if (target
->GetCreatureType() != CREATURE_TYPE_UNDEAD
)
4486 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4488 if (target
->GetOwnerGUID() != m_caster
->GetGUID())
4489 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4491 float dist
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4492 if (!target
->IsWithinDistInMap(m_caster
,dist
))
4493 return SPELL_FAILED_OUT_OF_RANGE
;
4495 // will set in target selection code
4498 case SPELL_EFFECT_DUMMY
:
4500 if(m_spellInfo
->SpellIconID
== 1648) // Execute
4502 if(!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4503 return SPELL_FAILED_BAD_TARGETS
;
4505 else if (m_spellInfo
->Id
== 51582) // Rocket Boots Engaged
4507 if(m_caster
->IsInWater())
4508 return SPELL_FAILED_ONLY_ABOVEWATER
;
4510 else if(m_spellInfo
->SpellIconID
== 156) // Holy Shock
4512 // spell different for friends and enemies
4513 // hart version required facing
4514 if(m_targets
.getUnitTarget() && !m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()) && !m_caster
->HasInArc( M_PI_F
, m_targets
.getUnitTarget() ))
4515 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4518 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& m_spellInfo
->SpellIconID
== 33)
4521 if (!m_caster
->GetTotemGUID(TOTEM_SLOT_FIRE
))
4522 return SPELL_FAILED_TOTEMS
;
4526 case SPELL_EFFECT_SCHOOL_DAMAGE
:
4529 if(m_spellInfo
->SpellVisual
[0] == 7250)
4531 if (!m_targets
.getUnitTarget())
4532 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4534 if(m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4535 return SPELL_FAILED_BAD_TARGETS
;
4539 case SPELL_EFFECT_TAMECREATURE
:
4541 // Spell can be triggered, we need to check original caster prior to caster
4542 Unit
* caster
= GetAffectiveCaster();
4543 if (!caster
|| caster
->GetTypeId() != TYPEID_PLAYER
||
4544 !m_targets
.getUnitTarget() ||
4545 m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
)
4546 return SPELL_FAILED_BAD_TARGETS
;
4548 Player
* plrCaster
= (Player
*)caster
;
4550 if(plrCaster
->getClass() != CLASS_HUNTER
)
4552 plrCaster
->SendPetTameFailure(PETTAME_UNITSCANTTAME
);
4553 return SPELL_FAILED_DONT_REPORT
;
4556 Creature
* target
= (Creature
*)m_targets
.getUnitTarget();
4558 if(target
->isPet() || target
->isCharmed())
4560 plrCaster
->SendPetTameFailure(PETTAME_CREATUREALREADYOWNED
);
4561 return SPELL_FAILED_DONT_REPORT
;
4564 if (target
->getLevel() > plrCaster
->getLevel())
4566 plrCaster
->SendPetTameFailure(PETTAME_TOOHIGHLEVEL
);
4567 return SPELL_FAILED_DONT_REPORT
;
4570 if (target
->GetCreatureInfo()->IsExotic() && !plrCaster
->CanTameExoticPets())
4572 plrCaster
->SendPetTameFailure(PETTAME_CANTCONTROLEXOTIC
);
4573 return SPELL_FAILED_DONT_REPORT
;
4576 if (!target
->GetCreatureInfo()->isTameable(plrCaster
->CanTameExoticPets()))
4578 plrCaster
->SendPetTameFailure(PETTAME_NOTTAMEABLE
);
4579 return SPELL_FAILED_DONT_REPORT
;
4582 if(plrCaster
->GetPetGUID() || plrCaster
->GetCharmGUID())
4584 plrCaster
->SendPetTameFailure(PETTAME_ANOTHERSUMMONACTIVE
);
4585 return SPELL_FAILED_DONT_REPORT
;
4590 case SPELL_EFFECT_LEARN_SPELL
:
4592 if(m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_PET
)
4595 Pet
* pet
= m_caster
->GetPet();
4598 return SPELL_FAILED_NO_PET
;
4600 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4602 if(!learn_spellproto
)
4603 return SPELL_FAILED_NOT_KNOWN
;
4605 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4606 return SPELL_FAILED_LOWLEVEL
;
4610 case SPELL_EFFECT_LEARN_PET_SPELL
:
4612 Pet
* pet
= m_caster
->GetPet();
4615 return SPELL_FAILED_NO_PET
;
4617 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4619 if(!learn_spellproto
)
4620 return SPELL_FAILED_NOT_KNOWN
;
4622 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4623 return SPELL_FAILED_LOWLEVEL
;
4627 case SPELL_EFFECT_APPLY_GLYPH
:
4629 uint32 glyphId
= m_spellInfo
->EffectMiscValue
[i
];
4630 if(GlyphPropertiesEntry
const *gp
= sGlyphPropertiesStore
.LookupEntry(glyphId
))
4631 if(m_caster
->HasAura(gp
->SpellId
))
4632 return SPELL_FAILED_UNIQUE_GLYPH
;
4635 case SPELL_EFFECT_FEED_PET
:
4637 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4638 return SPELL_FAILED_BAD_TARGETS
;
4640 Item
* foodItem
= m_targets
.getItemTarget();
4642 return SPELL_FAILED_BAD_TARGETS
;
4644 Pet
* pet
= m_caster
->GetPet();
4647 return SPELL_FAILED_NO_PET
;
4649 if(!pet
->HaveInDiet(foodItem
->GetProto()))
4650 return SPELL_FAILED_WRONG_PET_FOOD
;
4652 if(!pet
->GetCurrentFoodBenefitLevel(foodItem
->GetProto()->ItemLevel
))
4653 return SPELL_FAILED_FOOD_LOWLEVEL
;
4655 if(m_caster
->isInCombat() || pet
->isInCombat())
4656 return SPELL_FAILED_AFFECTING_COMBAT
;
4660 case SPELL_EFFECT_POWER_BURN
:
4661 case SPELL_EFFECT_POWER_DRAIN
:
4663 // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
4664 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4665 if(Unit
* target
= m_targets
.getUnitTarget())
4666 if(target
!= m_caster
&& target
->getPowerType() != m_spellInfo
->EffectMiscValue
[i
])
4667 return SPELL_FAILED_BAD_TARGETS
;
4670 case SPELL_EFFECT_CHARGE
:
4672 if (m_caster
->hasUnitState(UNIT_STAT_ROOT
))
4673 return SPELL_FAILED_ROOTED
;
4677 case SPELL_EFFECT_SKINNING
:
4679 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() != TYPEID_UNIT
)
4680 return SPELL_FAILED_BAD_TARGETS
;
4682 if( !(m_targets
.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS
) & UNIT_FLAG_SKINNABLE
) )
4683 return SPELL_FAILED_TARGET_UNSKINNABLE
;
4685 Creature
* creature
= (Creature
*)m_targets
.getUnitTarget();
4686 if ( creature
->GetCreatureType() != CREATURE_TYPE_CRITTER
&& ( !creature
->lootForBody
|| !creature
->loot
.empty() ) )
4688 return SPELL_FAILED_TARGET_NOT_LOOTED
;
4691 uint32 skill
= creature
->GetCreatureInfo()->GetRequiredLootSkill();
4693 int32 skillValue
= ((Player
*)m_caster
)->GetSkillValue(skill
);
4694 int32 TargetLevel
= m_targets
.getUnitTarget()->getLevel();
4695 int32 ReqValue
= (skillValue
< 100 ? (TargetLevel
-10) * 10 : TargetLevel
* 5);
4696 if (ReqValue
> skillValue
)
4697 return SPELL_FAILED_LOW_CASTLEVEL
;
4699 // chance for fail at orange skinning attempt
4700 if( (m_selfContainer
&& (*m_selfContainer
) == this) &&
4701 skillValue
< sWorld
.GetConfigMaxSkillValue() &&
4702 (ReqValue
< 0 ? 0 : ReqValue
) > irand(skillValue
- 25, skillValue
+ 37) )
4703 return SPELL_FAILED_TRY_AGAIN
;
4707 case SPELL_EFFECT_OPEN_LOCK
:
4709 if( m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT
&&
4710 m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT_ITEM
)
4713 if( m_caster
->GetTypeId() != TYPEID_PLAYER
// only players can open locks, gather etc.
4714 // we need a go target in case of TARGET_GAMEOBJECT
4715 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT
&& !m_targets
.getGOTarget()
4716 // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM
4717 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT_ITEM
&& !m_targets
.getGOTarget() &&
4718 (!m_targets
.getItemTarget() || !m_targets
.getItemTarget()->GetProto()->LockID
|| m_targets
.getItemTarget()->GetOwner() != m_caster
) )
4719 return SPELL_FAILED_BAD_TARGETS
;
4721 // In BattleGround players can use only flags and banners
4722 if( ((Player
*)m_caster
)->InBattleGround() &&
4723 !((Player
*)m_caster
)->CanUseBattleGroundObject() )
4724 return SPELL_FAILED_TRY_AGAIN
;
4726 // get the lock entry
4728 if (GameObject
* go
= m_targets
.getGOTarget())
4730 lockId
= go
->GetGOInfo()->GetLockId();
4732 return SPELL_FAILED_BAD_TARGETS
;
4734 else if(Item
* itm
= m_targets
.getItemTarget())
4735 lockId
= itm
->GetProto()->LockID
;
4737 SkillType skillId
= SKILL_NONE
;
4738 int32 reqSkillValue
= 0;
4739 int32 skillValue
= 0;
4741 // check lock compatibility
4742 SpellCastResult res
= CanOpenLock(SpellEffectIndex(i
), lockId
, skillId
, reqSkillValue
, skillValue
);
4743 if(res
!= SPELL_CAST_OK
)
4746 // chance for fail at orange mining/herb/LockPicking gathering attempt
4747 // second check prevent fail at rechecks
4748 if(skillId
!= SKILL_NONE
&& (!m_selfContainer
|| ((*m_selfContainer
) != this)))
4750 bool canFailAtMax
= skillId
!= SKILL_HERBALISM
&& skillId
!= SKILL_MINING
;
4752 // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill)
4753 if((canFailAtMax
|| skillValue
< sWorld
.GetConfigMaxSkillValue()) && reqSkillValue
> irand(skillValue
- 25, skillValue
+ 37))
4754 return SPELL_FAILED_TRY_AGAIN
;
4758 case SPELL_EFFECT_SUMMON_DEAD_PET
:
4760 Creature
*pet
= m_caster
->GetPet();
4762 return SPELL_FAILED_NO_PET
;
4765 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4769 // This is generic summon effect
4770 case SPELL_EFFECT_SUMMON
:
4772 if(SummonPropertiesEntry
const *summon_prop
= sSummonPropertiesStore
.LookupEntry(m_spellInfo
->EffectMiscValueB
[i
]))
4774 if(summon_prop
->Group
== SUMMON_PROP_GROUP_PETS
)
4776 if(m_caster
->GetPetGUID())
4777 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4779 if(m_caster
->GetCharmGUID())
4780 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4786 case SPELL_EFFECT_SUMMON_PET
:
4788 if(m_caster
->GetPetGUID()) //let warlock do a replacement summon
4791 Pet
* pet
= ((Player
*)m_caster
)->GetPet();
4793 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->getClass() == CLASS_WARLOCK
)
4795 if (strict
) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
4796 pet
->CastSpell(pet
, 32752, true, NULL
, NULL
, pet
->GetGUID());
4799 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4802 if(m_caster
->GetCharmGUID())
4803 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4807 case SPELL_EFFECT_SUMMON_PLAYER
:
4809 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4810 return SPELL_FAILED_BAD_TARGETS
;
4811 if(!((Player
*)m_caster
)->GetSelection())
4812 return SPELL_FAILED_BAD_TARGETS
;
4814 Player
* target
= sObjectMgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
4815 if( !target
|| ((Player
*)m_caster
) == target
|| !target
->IsInSameRaidWith((Player
*)m_caster
) )
4816 return SPELL_FAILED_BAD_TARGETS
;
4818 // check if our map is dungeon
4819 if( sMapStore
.LookupEntry(m_caster
->GetMapId())->IsDungeon() )
4821 InstanceTemplate
const* instance
= ObjectMgr::GetInstanceTemplate(m_caster
->GetMapId());
4823 return SPELL_FAILED_TARGET_NOT_IN_INSTANCE
;
4824 if ( instance
->levelMin
> target
->getLevel() )
4825 return SPELL_FAILED_LOWLEVEL
;
4826 if ( instance
->levelMax
&& instance
->levelMax
< target
->getLevel() )
4827 return SPELL_FAILED_HIGHLEVEL
;
4831 case SPELL_EFFECT_LEAP
:
4832 case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
:
4834 float dis
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4835 float fx
= m_caster
->GetPositionX() + dis
* cos(m_caster
->GetOrientation());
4836 float fy
= m_caster
->GetPositionY() + dis
* sin(m_caster
->GetOrientation());
4837 // teleport a bit above terrain level to avoid falling below it
4838 float fz
= m_caster
->GetBaseMap()->GetHeight(fx
, fy
, m_caster
->GetPositionZ(), true);
4839 if(fz
<= INVALID_HEIGHT
) // note: this also will prevent use effect in instances without vmaps height enabled
4840 return SPELL_FAILED_TRY_AGAIN
;
4842 float caster_pos_z
= m_caster
->GetPositionZ();
4843 // Control the caster to not climb or drop when +-fz > 8
4844 if(!(fz
<= caster_pos_z
+ 8 && fz
>= caster_pos_z
- 8))
4845 return SPELL_FAILED_TRY_AGAIN
;
4847 // not allow use this effect at battleground until battleground start
4848 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4849 if(BattleGround
const *bg
= ((Player
*)m_caster
)->GetBattleGround())
4850 if(bg
->GetStatus() != STATUS_IN_PROGRESS
)
4851 return SPELL_FAILED_TRY_AGAIN
;
4854 case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF
:
4856 if (m_targets
.getUnitTarget() == m_caster
)
4857 return SPELL_FAILED_BAD_TARGETS
;
4864 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4866 switch(m_spellInfo
->EffectApplyAuraName
[i
])
4868 case SPELL_AURA_DUMMY
:
4871 switch(m_spellInfo
->Id
)
4874 if(m_caster
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)m_caster
)->IsInFeralForm())
4875 return SPELL_FAILED_ONLY_SHAPESHIFT
;
4882 case SPELL_AURA_MOD_POSSESS
:
4884 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4885 return SPELL_FAILED_UNKNOWN
;
4887 if(m_targets
.getUnitTarget() == m_caster
)
4888 return SPELL_FAILED_BAD_TARGETS
;
4890 if(m_caster
->GetPetGUID())
4891 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4893 if(m_caster
->GetCharmGUID())
4894 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4896 if(m_caster
->GetCharmerGUID())
4897 return SPELL_FAILED_CHARMED
;
4899 if(!m_targets
.getUnitTarget())
4900 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4902 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4903 return SPELL_FAILED_CHARMED
;
4905 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(SpellEffectIndex(i
),m_targets
.getUnitTarget()))
4906 return SPELL_FAILED_HIGHLEVEL
;
4910 case SPELL_AURA_MOD_CHARM
:
4912 if(m_targets
.getUnitTarget() == m_caster
)
4913 return SPELL_FAILED_BAD_TARGETS
;
4915 if(m_caster
->GetPetGUID())
4916 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4918 if(m_caster
->GetCharmGUID())
4919 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4921 if(m_caster
->GetCharmerGUID())
4922 return SPELL_FAILED_CHARMED
;
4924 if(!m_targets
.getUnitTarget())
4925 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4927 if(m_targets
.getUnitTarget()->GetCharmerGUID())
4928 return SPELL_FAILED_CHARMED
;
4930 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(SpellEffectIndex(i
),m_targets
.getUnitTarget()))
4931 return SPELL_FAILED_HIGHLEVEL
;
4935 case SPELL_AURA_MOD_POSSESS_PET
:
4937 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4938 return SPELL_FAILED_UNKNOWN
;
4940 if(m_caster
->GetCharmGUID())
4941 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4943 if(m_caster
->GetCharmerGUID())
4944 return SPELL_FAILED_CHARMED
;
4946 Pet
* pet
= m_caster
->GetPet();
4948 return SPELL_FAILED_NO_PET
;
4950 if(pet
->GetCharmerGUID())
4951 return SPELL_FAILED_CHARMED
;
4955 case SPELL_AURA_MOUNTED
:
4957 if (m_caster
->IsInWater())
4958 return SPELL_FAILED_ONLY_ABOVEWATER
;
4960 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetTransport())
4961 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4963 // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
4964 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& !sMapStore
.LookupEntry(m_caster
->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell
&& !m_spellInfo
->AreaGroupId
)
4965 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
4967 ShapeshiftForm form
= m_caster
->m_form
;
4968 if( form
== FORM_CAT
|| form
== FORM_TREE
|| form
== FORM_TRAVEL
||
4969 form
== FORM_AQUA
|| form
== FORM_BEAR
|| form
== FORM_DIREBEAR
||
4970 form
== FORM_CREATUREBEAR
|| form
== FORM_GHOSTWOLF
|| form
== FORM_FLIGHT
||
4971 form
== FORM_FLIGHT_EPIC
|| form
== FORM_MOONKIN
|| form
== FORM_METAMORPHOSIS
)
4972 return SPELL_FAILED_NOT_SHAPESHIFT
;
4976 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
4978 if(!m_targets
.getUnitTarget())
4979 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4981 // can be casted at non-friendly unit or own pet/charm
4982 if(m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()))
4983 return SPELL_FAILED_TARGET_FRIENDLY
;
4987 case SPELL_AURA_FLY
:
4988 case SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
:
4990 // not allow cast fly spells if not have req. skills (all spells is self target)
4991 // allow always ghost flight spells
4992 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->isAlive())
4994 if (!((Player
*)m_caster
)->IsKnowHowFlyIn(m_caster
->GetMapId(),zone
))
4995 return m_IsTriggeredSpell
? SPELL_FAILED_DONT_REPORT
: SPELL_FAILED_NOT_HERE
;
4999 case SPELL_AURA_PERIODIC_MANA_LEECH
:
5001 if (!m_targets
.getUnitTarget())
5002 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
5004 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| m_CastItem
)
5007 if(m_targets
.getUnitTarget()->getPowerType() != POWER_MANA
)
5008 return SPELL_FAILED_BAD_TARGETS
;
5018 return SPELL_CAST_OK
;
5021 SpellCastResult
Spell::CheckPetCast(Unit
* target
)
5023 if(!m_caster
->isAlive())
5024 return SPELL_FAILED_CASTER_DEAD
;
5026 if(m_caster
->IsNonMeleeSpellCasted(false)) //prevent spellcast interruption by another spellcast
5027 return SPELL_FAILED_SPELL_IN_PROGRESS
;
5028 if(m_caster
->isInCombat() && IsNonCombatSpell(m_spellInfo
))
5029 return SPELL_FAILED_AFFECTING_COMBAT
;
5031 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)m_caster
)->isPet() || m_caster
->isCharmed()))
5033 //dead owner (pets still alive when owners ressed?)
5034 if(m_caster
->GetCharmerOrOwner() && !m_caster
->GetCharmerOrOwner()->isAlive())
5035 return SPELL_FAILED_CASTER_DEAD
;
5037 if(!target
&& m_targets
.getUnitTarget())
5038 target
= m_targets
.getUnitTarget();
5041 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
5043 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CHAIN_DAMAGE
||
5044 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND
||
5045 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND_2
||
5046 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_DUELVSPLAYER
||
5047 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_PARTY
||
5048 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CURRENT_ENEMY_COORDINATES
)
5052 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
5057 m_targets
.setUnitTarget(target
);
5059 Unit
* _target
= m_targets
.getUnitTarget();
5061 if(_target
) //for target dead/target not valid
5063 if(!_target
->isAlive())
5064 return SPELL_FAILED_BAD_TARGETS
;
5066 if(IsPositiveSpell(m_spellInfo
->Id
))
5068 if(m_caster
->IsHostileTo(_target
))
5069 return SPELL_FAILED_BAD_TARGETS
;
5073 bool duelvsplayertar
= false;
5074 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
5076 //TARGET_DUELVSPLAYER is positive AND negative
5077 duelvsplayertar
|= (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
);
5079 if(m_caster
->IsFriendlyTo(target
) && !duelvsplayertar
)
5081 return SPELL_FAILED_BAD_TARGETS
;
5086 if(((Creature
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
5087 return SPELL_FAILED_NOT_READY
;
5090 return CheckCast(true);
5093 SpellCastResult
Spell::CheckCasterAuras() const
5095 // Flag drop spells totally immuned to caster auras
5096 // FIXME: find more nice check for all totally immuned spells
5097 // AttributesEx3 & 0x10000000?
5098 if(m_spellInfo
->Id
== 23336 || m_spellInfo
->Id
== 23334 || m_spellInfo
->Id
== 34991)
5099 return SPELL_CAST_OK
;
5101 uint8 school_immune
= 0;
5102 uint32 mechanic_immune
= 0;
5103 uint32 dispel_immune
= 0;
5105 // Check if the spell grants school or mechanic immunity.
5106 // We use bitmasks so the loop is done only once and not on every aura check below.
5107 if ( m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
5109 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
5111 if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_SCHOOL_IMMUNITY
)
5112 school_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
5113 else if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY
)
5114 mechanic_immune
|= 1 << uint32(m_spellInfo
->EffectMiscValue
[i
]-1);
5115 else if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY_MASK
)
5116 mechanic_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
5117 else if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_DISPEL_IMMUNITY
)
5118 dispel_immune
|= GetDispellMask(DispelType(m_spellInfo
->EffectMiscValue
[i
]));
5120 // immune movement impairment and loss of control
5121 if (m_spellInfo
->Id
== 42292)
5122 mechanic_immune
= IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK
;
5125 // Check whether the cast should be prevented by any state you might have.
5126 SpellCastResult prevented_reason
= SPELL_CAST_OK
;
5127 // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
5128 uint32 unitflag
= m_caster
->GetUInt32Value(UNIT_FIELD_FLAGS
); // Get unit state
5129 if (unitflag
& UNIT_FLAG_STUNNED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
5130 prevented_reason
= SPELL_FAILED_STUNNED
;
5131 else if (unitflag
& UNIT_FLAG_CONFUSED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
5132 prevented_reason
= SPELL_FAILED_CONFUSED
;
5133 else if (unitflag
& UNIT_FLAG_FLEEING
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
5134 prevented_reason
= SPELL_FAILED_FLEEING
;
5135 else if (unitflag
& UNIT_FLAG_SILENCED
&& m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
)
5136 prevented_reason
= SPELL_FAILED_SILENCED
;
5137 else if (unitflag
& UNIT_FLAG_PACIFIED
&& m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
)
5138 prevented_reason
= SPELL_FAILED_PACIFIED
;
5139 else if(m_caster
->HasAuraType(SPELL_AURA_ALLOW_ONLY_ABILITY
))
5141 Unit::AuraList
const& casingLimit
= m_caster
->GetAurasByType(SPELL_AURA_ALLOW_ONLY_ABILITY
);
5142 for(Unit::AuraList::const_iterator itr
= casingLimit
.begin(); itr
!= casingLimit
.end(); ++itr
)
5144 if(!IsAffectedByAura(*itr
))
5146 prevented_reason
= SPELL_FAILED_CASTER_AURASTATE
;
5152 // Attr must make flag drop spell totally immune from all effects
5153 if (prevented_reason
!= SPELL_CAST_OK
)
5155 if (school_immune
|| mechanic_immune
|| dispel_immune
)
5157 //Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
5158 Unit::AuraMap
const& auras
= m_caster
->GetAuras();
5159 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
5163 if (GetSpellMechanicMask(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()) & mechanic_immune
)
5165 if (GetSpellSchoolMask(itr
->second
->GetSpellProto()) & school_immune
)
5167 if ((1<<(itr
->second
->GetSpellProto()->Dispel
)) & dispel_immune
)
5170 // Make a second check for spell failed so the right SPELL_FAILED message is returned.
5171 // That is needed when your casting is prevented by multiple states and you are only immune to some of them.
5172 switch(itr
->second
->GetModifier()->m_auraname
)
5174 case SPELL_AURA_MOD_STUN
:
5175 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
5176 return SPELL_FAILED_STUNNED
;
5178 case SPELL_AURA_MOD_CONFUSE
:
5179 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
5180 return SPELL_FAILED_CONFUSED
;
5182 case SPELL_AURA_MOD_FEAR
:
5183 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
5184 return SPELL_FAILED_FLEEING
;
5186 case SPELL_AURA_MOD_SILENCE
:
5187 case SPELL_AURA_MOD_PACIFY
:
5188 case SPELL_AURA_MOD_PACIFY_SILENCE
:
5189 if( m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
)
5190 return SPELL_FAILED_PACIFIED
;
5191 else if ( m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
)
5192 return SPELL_FAILED_SILENCED
;
5199 // You are prevented from casting and the spell casted does not grant immunity. Return a failed error.
5201 return prevented_reason
;
5203 return SPELL_CAST_OK
;
5206 bool Spell::CanAutoCast(Unit
* target
)
5208 uint64 targetguid
= target
->GetGUID();
5210 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
5212 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
)
5214 if( m_spellInfo
->StackAmount
<= 1)
5216 if( target
->HasAura(m_spellInfo
->Id
, SpellEffectIndex(j
)) )
5221 if(Aura
* aura
= target
->GetAura(m_spellInfo
->Id
, SpellEffectIndex(j
)))
5222 if(aura
->GetStackAmount() >= m_spellInfo
->StackAmount
)
5226 else if ( IsAreaAuraEffect( m_spellInfo
->Effect
[j
] ))
5228 if( target
->HasAura(m_spellInfo
->Id
, SpellEffectIndex(j
)) )
5233 SpellCastResult result
= CheckPetCast(target
);
5235 if(result
== SPELL_CAST_OK
|| result
== SPELL_FAILED_UNIT_NOT_INFRONT
)
5238 //check if among target units, our WANTED target is as well (->only self cast spells return false)
5239 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
5240 if( ihit
->targetGUID
== targetguid
)
5243 return false; //target invalid
5246 SpellCastResult
Spell::CheckRange(bool strict
)
5250 // self cast doesn't need range checking -- also for Starshards fix
5251 if (m_spellInfo
->rangeIndex
== 1)
5252 return SPELL_CAST_OK
;
5254 if (strict
) //add radius of caster
5256 else //add radius of caster and ~5 yds "give"
5259 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
5260 Unit
*target
= m_targets
.getUnitTarget();
5261 bool friendly
= target
? target
->IsFriendlyTo(m_caster
) : false;
5262 float max_range
= GetSpellMaxRange(srange
, friendly
) + range_mod
;
5263 float min_range
= GetSpellMinRange(srange
, friendly
);
5265 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
5266 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RANGE
, max_range
, this);
5268 if(target
&& target
!= m_caster
)
5270 // distance from target in checks
5271 float dist
= m_caster
->GetCombatDistance(target
);
5273 if(dist
> max_range
)
5274 return SPELL_FAILED_OUT_OF_RANGE
;
5275 if(min_range
&& dist
< min_range
)
5276 return SPELL_FAILED_TOO_CLOSE
;
5277 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&&
5278 (m_spellInfo
->FacingCasterFlags
& SPELL_FACING_FLAG_INFRONT
) && !m_caster
->HasInArc( M_PI_F
, target
) )
5279 return SPELL_FAILED_UNIT_NOT_INFRONT
;
5282 if(m_targets
.m_targetMask
== TARGET_FLAG_DEST_LOCATION
&& m_targets
.m_destX
!= 0 && m_targets
.m_destY
!= 0 && m_targets
.m_destZ
!= 0)
5284 if(!m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
, max_range
))
5285 return SPELL_FAILED_OUT_OF_RANGE
;
5286 if(min_range
&& m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
, min_range
))
5287 return SPELL_FAILED_TOO_CLOSE
;
5290 return SPELL_CAST_OK
;
5293 int32
Spell::CalculatePowerCost()
5295 // item cast not used power
5299 // Spell drain all exist power on cast (Only paladin lay of Hands)
5300 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DRAIN_ALL_POWER
)
5302 // If power type - health drain all
5303 if (m_spellInfo
->powerType
== POWER_HEALTH
)
5304 return m_caster
->GetHealth();
5305 // Else drain all power
5306 if (m_spellInfo
->powerType
< MAX_POWERS
)
5307 return m_caster
->GetPower(Powers(m_spellInfo
->powerType
));
5308 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
5313 int32 powerCost
= m_spellInfo
->manaCost
;
5314 // PCT cost from total amount
5315 if (m_spellInfo
->ManaCostPercentage
)
5317 switch (m_spellInfo
->powerType
)
5319 // health as power used
5321 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateHealth() / 100;
5324 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateMana() / 100;
5329 case POWER_HAPPINESS
:
5330 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetMaxPower(Powers(m_spellInfo
->powerType
)) / 100;
5333 case POWER_RUNIC_POWER
:
5334 sLog
.outDebug("Spell::CalculateManaCost: Not implemented yet!");
5337 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
5341 SpellSchools school
= GetFirstSchoolInMask(m_spellSchoolMask
);
5342 // Flat mod from caster auras by spell school
5343 powerCost
+= m_caster
->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER
+ school
);
5344 // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
5345 if ( m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST
)
5346 powerCost
+= m_caster
->GetAttackTime(OFF_ATTACK
) / 100;
5347 // Apply cost mod by spell
5348 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
5349 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, powerCost
, this);
5351 if(m_spellInfo
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
)
5352 powerCost
= int32(powerCost
/ (1.117f
* m_spellInfo
->spellLevel
/ m_caster
->getLevel() -0.1327f
));
5354 // PCT mod from user auras by school
5355 powerCost
= int32(powerCost
* (1.0f
+ m_caster
->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+ school
)));
5361 SpellCastResult
Spell::CheckPower()
5363 // item cast not used power
5365 return SPELL_CAST_OK
;
5367 // Do precise power regen on spell cast
5368 if (m_powerCost
> 0 && m_caster
->GetTypeId() == TYPEID_PLAYER
)
5370 Player
* playerCaster
= (Player
*)m_caster
;
5371 uint32 diff
= REGEN_TIME_FULL
- m_caster
->GetRegenTimer();
5372 if (diff
>= REGEN_TIME_PRECISE
)
5373 playerCaster
->RegenerateAll(diff
);
5376 // health as power used - need check health amount
5377 if(m_spellInfo
->powerType
== POWER_HEALTH
)
5379 if((int32
)m_caster
->GetHealth() <= m_powerCost
)
5380 return SPELL_FAILED_CASTER_AURASTATE
;
5381 return SPELL_CAST_OK
;
5383 // Check valid power type
5384 if( m_spellInfo
->powerType
>= MAX_POWERS
)
5386 sLog
.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo
->powerType
);
5387 return SPELL_FAILED_UNKNOWN
;
5390 //check rune cost only if a spell has PowerType == POWER_RUNE
5391 if(m_spellInfo
->powerType
== POWER_RUNE
)
5393 SpellCastResult failReason
= CheckOrTakeRunePower(false);
5394 if(failReason
!= SPELL_CAST_OK
)
5398 // Check power amount
5399 Powers powerType
= Powers(m_spellInfo
->powerType
);
5400 if((int32
)m_caster
->GetPower(powerType
) < m_powerCost
)
5401 return SPELL_FAILED_NO_POWER
;
5403 return SPELL_CAST_OK
;
5406 bool Spell::IgnoreItemRequirements() const
5408 if (m_IsTriggeredSpell
)
5411 /// Check if it's an enchant scroll. These have no required reagents even though their spell does.
5412 if (m_CastItem
&& m_CastItem
->HasFlag(ITEM_FIELD_FLAGS
, ITEM_FLAGS_ENCHANT_SCROLL
))
5418 SpellCastResult
Spell::CheckItems()
5420 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
5421 return SPELL_CAST_OK
;
5423 Player
* p_caster
= (Player
*)m_caster
;
5428 uint32 itemid
= m_CastItem
->GetEntry();
5429 if( !p_caster
->HasItemCount(itemid
, 1) )
5430 return SPELL_FAILED_ITEM_NOT_FOUND
;
5432 ItemPrototype
const *proto
= m_CastItem
->GetProto();
5434 return SPELL_FAILED_ITEM_NOT_FOUND
;
5436 for (int i
= 0; i
< 5; ++i
)
5437 if (proto
->Spells
[i
].SpellCharges
)
5438 if(m_CastItem
->GetSpellCharges(i
) == 0)
5439 return SPELL_FAILED_NO_CHARGES_REMAIN
;
5441 // consumable cast item checks
5442 if (proto
->Class
== ITEM_CLASS_CONSUMABLE
&& m_targets
.getUnitTarget())
5444 // such items should only fail if there is no suitable effect at all - see Rejuvenation Potions for example
5445 SpellCastResult failReason
= SPELL_CAST_OK
;
5446 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
5448 // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster
5449 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_PET
)
5452 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_HEAL
)
5454 if (m_targets
.getUnitTarget()->GetHealth() == m_targets
.getUnitTarget()->GetMaxHealth())
5456 failReason
= SPELL_FAILED_ALREADY_AT_FULL_HEALTH
;
5461 failReason
= SPELL_CAST_OK
;
5466 // Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
5467 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
5469 if(m_spellInfo
->EffectMiscValue
[i
] < 0 || m_spellInfo
->EffectMiscValue
[i
] >= MAX_POWERS
)
5471 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
5475 Powers power
= Powers(m_spellInfo
->EffectMiscValue
[i
]);
5476 if (m_targets
.getUnitTarget()->GetPower(power
) == m_targets
.getUnitTarget()->GetMaxPower(power
))
5478 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
5483 failReason
= SPELL_CAST_OK
;
5488 if (failReason
!= SPELL_CAST_OK
)
5493 // check target item
5494 if(m_targets
.getItemTargetGUID())
5496 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
5497 return SPELL_FAILED_BAD_TARGETS
;
5499 if(!m_targets
.getItemTarget())
5500 return SPELL_FAILED_ITEM_GONE
;
5502 if(!m_targets
.getItemTarget()->IsFitToSpellRequirements(m_spellInfo
))
5503 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
5505 // if not item target then required item must be equipped
5508 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !((Player
*)m_caster
)->HasItemFitToSpellReqirements(m_spellInfo
))
5509 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
5512 // check spell focus object
5513 if(m_spellInfo
->RequiresSpellFocus
)
5515 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
5517 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5519 GameObject
* ok
= NULL
;
5520 MaNGOS::GameObjectFocusCheck
go_check(m_caster
,m_spellInfo
->RequiresSpellFocus
);
5521 MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
> checker(m_caster
, ok
, go_check
);
5523 TypeContainerVisitor
<MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
>, GridTypeMapContainer
> object_checker(checker
);
5524 Map
& map
= *m_caster
->GetMap();
5525 cell
.Visit(p
, object_checker
, map
, *m_caster
, map
.GetVisibilityDistance());
5528 return SPELL_FAILED_REQUIRES_SPELL_FOCUS
;
5530 focusObject
= ok
; // game object found in range
5533 // check reagents (ignore triggered spells with reagents processed by original spell) and special reagent ignore case.
5534 if (!IgnoreItemRequirements())
5536 if (!p_caster
->CanNoReagentCast(m_spellInfo
))
5538 for(uint32 i
= 0; i
< 8; ++i
)
5540 if(m_spellInfo
->Reagent
[i
] <= 0)
5543 uint32 itemid
= m_spellInfo
->Reagent
[i
];
5544 uint32 itemcount
= m_spellInfo
->ReagentCount
[i
];
5546 // if CastItem is also spell reagent
5547 if (m_CastItem
&& m_CastItem
->GetEntry() == itemid
)
5549 ItemPrototype
const *proto
= m_CastItem
->GetProto();
5551 return SPELL_FAILED_REAGENTS
;
5552 for(int s
= 0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
5554 // CastItem will be used up and does not count as reagent
5555 int32 charges
= m_CastItem
->GetSpellCharges(s
);
5556 if (proto
->Spells
[s
].SpellCharges
< 0 && !proto
->NonConsumable
&& abs(charges
) < 2)
5564 if (!p_caster
->HasItemCount(itemid
, itemcount
))
5565 return SPELL_FAILED_REAGENTS
;
5569 // check totem-item requirements (items presence in inventory)
5571 for(int i
= 0; i
< 2 ; ++i
)
5573 if (m_spellInfo
->Totem
[i
] != 0)
5575 if (p_caster
->HasItemCount(m_spellInfo
->Totem
[i
], 1))
5586 return SPELL_FAILED_TOTEMS
;
5588 // Check items for TotemCategory (items presence in inventory)
5589 uint32 TotemCategory
= 2;
5590 for(int i
= 0; i
< 2; ++i
)
5592 if (m_spellInfo
->TotemCategory
[i
] != 0)
5594 if (p_caster
->HasItemTotemCategory(m_spellInfo
->TotemCategory
[i
]))
5604 if (TotemCategory
!= 0)
5605 return SPELL_FAILED_TOTEM_CATEGORY
;
5608 // special checks for spell effects
5609 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
5611 switch (m_spellInfo
->Effect
[i
])
5613 case SPELL_EFFECT_CREATE_ITEM
:
5615 if (!m_IsTriggeredSpell
&& m_spellInfo
->EffectItemType
[i
])
5617 // Conjure Mana Gem (skip same or low level ranks for later recharge)
5618 if (i
== EFFECT_INDEX_0
&& m_spellInfo
->Effect
[EFFECT_INDEX_1
] == SPELL_EFFECT_DUMMY
)
5620 if (ItemPrototype
const* itemProto
= ObjectMgr::GetItemPrototype(m_spellInfo
->EffectItemType
[i
]))
5622 if (Item
* item
= p_caster
->GetItemByLimitedCategory(itemProto
->ItemLimitCategory
))
5624 if (item
->GetProto()->ItemLevel
<= itemProto
->ItemLevel
)
5626 if (item
->HasMaxCharges())
5627 return SPELL_FAILED_ITEM_AT_MAX_CHARGES
;
5629 // will recharge in next effect
5636 ItemPosCountVec dest
;
5637 uint8 msg
= p_caster
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, m_spellInfo
->EffectItemType
[i
], 1 );
5638 if (msg
!= EQUIP_ERR_OK
)
5640 p_caster
->SendEquipError( msg
, NULL
, NULL
, m_spellInfo
->EffectItemType
[i
] );
5641 return SPELL_FAILED_DONT_REPORT
;
5646 case SPELL_EFFECT_RESTORE_ITEM_CHARGES
:
5648 if (Item
* item
= p_caster
->GetItemByEntry(m_spellInfo
->EffectItemType
[i
]))
5649 if (item
->HasMaxCharges())
5650 return SPELL_FAILED_ITEM_AT_MAX_CHARGES
;
5654 case SPELL_EFFECT_ENCHANT_ITEM
:
5655 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
5657 Item
* targetItem
= m_targets
.getItemTarget();
5659 return SPELL_FAILED_ITEM_NOT_FOUND
;
5661 if( targetItem
->GetProto()->ItemLevel
< m_spellInfo
->baseLevel
)
5662 return SPELL_FAILED_LOWLEVEL
;
5663 // Not allow enchant in trade slot for some enchant type
5664 if( targetItem
->GetOwner() != m_caster
)
5666 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5667 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5669 return SPELL_FAILED_ERROR
;
5670 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5671 return SPELL_FAILED_NOT_TRADEABLE
;
5675 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
5677 Item
*item
= m_targets
.getItemTarget();
5679 return SPELL_FAILED_ITEM_NOT_FOUND
;
5680 // Not allow enchant in trade slot for some enchant type
5681 if( item
->GetOwner() != m_caster
)
5683 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5684 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5686 return SPELL_FAILED_ERROR
;
5687 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5688 return SPELL_FAILED_NOT_TRADEABLE
;
5692 case SPELL_EFFECT_ENCHANT_HELD_ITEM
:
5693 // check item existence in effect code (not output errors at offhand hold item effect to main hand for example
5695 case SPELL_EFFECT_DISENCHANT
:
5697 if(!m_targets
.getItemTarget())
5698 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5700 // prevent disenchanting in trade slot
5701 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5702 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5704 ItemPrototype
const* itemProto
= m_targets
.getItemTarget()->GetProto();
5706 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5708 uint32 item_quality
= itemProto
->Quality
;
5709 // 2.0.x addon: Check player enchanting level against the item disenchanting requirements
5710 uint32 item_disenchantskilllevel
= itemProto
->RequiredDisenchantSkill
;
5711 if (item_disenchantskilllevel
== uint32(-1))
5712 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5713 if (item_disenchantskilllevel
> p_caster
->GetSkillValue(SKILL_ENCHANTING
))
5714 return SPELL_FAILED_LOW_CASTLEVEL
;
5715 if(item_quality
> 4 || item_quality
< 2)
5716 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5717 if(itemProto
->Class
!= ITEM_CLASS_WEAPON
&& itemProto
->Class
!= ITEM_CLASS_ARMOR
)
5718 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5719 if (!itemProto
->DisenchantID
)
5720 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5723 case SPELL_EFFECT_PROSPECTING
:
5725 if(!m_targets
.getItemTarget())
5726 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5727 // ensure item is a prospectable ore
5728 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_MINING_SUPP
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5729 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5730 // prevent prospecting in trade slot
5731 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5732 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5733 // Check for enough skill in jewelcrafting
5734 uint32 item_prospectingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5735 if(item_prospectingskilllevel
>p_caster
->GetSkillValue(SKILL_JEWELCRAFTING
))
5736 return SPELL_FAILED_LOW_CASTLEVEL
;
5737 // make sure the player has the required ores in inventory
5738 if(m_targets
.getItemTarget()->GetCount() < 5)
5739 return SPELL_FAILED_NEED_MORE_ITEMS
;
5741 if(!LootTemplates_Prospecting
.HaveLootFor(m_targets
.getItemTargetEntry()))
5742 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5746 case SPELL_EFFECT_MILLING
:
5748 if(!m_targets
.getItemTarget())
5749 return SPELL_FAILED_CANT_BE_MILLED
;
5750 // ensure item is a millable herb
5751 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_HERBS
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5752 return SPELL_FAILED_CANT_BE_MILLED
;
5753 // prevent milling in trade slot
5754 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5755 return SPELL_FAILED_CANT_BE_MILLED
;
5756 // Check for enough skill in inscription
5757 uint32 item_millingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5758 if(item_millingskilllevel
>p_caster
->GetSkillValue(SKILL_INSCRIPTION
))
5759 return SPELL_FAILED_LOW_CASTLEVEL
;
5760 // make sure the player has the required herbs in inventory
5761 if(m_targets
.getItemTarget()->GetCount() < 5)
5762 return SPELL_FAILED_NEED_MORE_ITEMS
;
5764 if(!LootTemplates_Milling
.HaveLootFor(m_targets
.getItemTargetEntry()))
5765 return SPELL_FAILED_CANT_BE_MILLED
;
5769 case SPELL_EFFECT_WEAPON_DAMAGE
:
5770 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
:
5772 if(m_caster
->GetTypeId() != TYPEID_PLAYER
) return SPELL_FAILED_TARGET_NOT_PLAYER
;
5773 if( m_attackType
!= RANGED_ATTACK
)
5775 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(m_attackType
,true,false);
5777 return SPELL_FAILED_EQUIPPED_ITEM
;
5779 switch(pItem
->GetProto()->SubClass
)
5781 case ITEM_SUBCLASS_WEAPON_THROWN
:
5783 uint32 ammo
= pItem
->GetEntry();
5784 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5785 return SPELL_FAILED_NO_AMMO
;
5787 case ITEM_SUBCLASS_WEAPON_GUN
:
5788 case ITEM_SUBCLASS_WEAPON_BOW
:
5789 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5791 uint32 ammo
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
5795 if(m_caster
->GetDummyAura(46699))
5796 break; // skip other checks
5798 return SPELL_FAILED_NO_AMMO
;
5801 ItemPrototype
const *ammoProto
= ObjectMgr::GetItemPrototype( ammo
);
5803 return SPELL_FAILED_NO_AMMO
;
5805 if(ammoProto
->Class
!= ITEM_CLASS_PROJECTILE
)
5806 return SPELL_FAILED_NO_AMMO
;
5808 // check ammo ws. weapon compatibility
5809 switch(pItem
->GetProto()->SubClass
)
5811 case ITEM_SUBCLASS_WEAPON_BOW
:
5812 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5813 if(ammoProto
->SubClass
!= ITEM_SUBCLASS_ARROW
)
5814 return SPELL_FAILED_NO_AMMO
;
5816 case ITEM_SUBCLASS_WEAPON_GUN
:
5817 if(ammoProto
->SubClass
!= ITEM_SUBCLASS_BULLET
)
5818 return SPELL_FAILED_NO_AMMO
;
5821 return SPELL_FAILED_NO_AMMO
;
5824 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5825 return SPELL_FAILED_NO_AMMO
;
5827 case ITEM_SUBCLASS_WEAPON_WAND
:
5838 return SPELL_CAST_OK
;
5841 void Spell::Delayed()
5843 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
5846 if (m_spellState
== SPELL_STATE_DELAYED
)
5847 return; // spell is active and can't be time-backed
5849 if(isDelayableNoMore()) // Spells may only be delayed twice
5852 // spells not loosing casting time ( slam, dynamites, bombs.. )
5853 if(!(m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_DAMAGE
))
5856 // check pushback reduce
5857 int32 delaytime
= 500; // spellcasting delay is normally 500ms
5858 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5859 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5860 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5861 if(delayReduce
>= 100)
5864 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5866 if(int32(m_timer
) + delaytime
> m_casttime
)
5868 delaytime
= m_casttime
- m_timer
;
5869 m_timer
= m_casttime
;
5872 m_timer
+= delaytime
;
5874 sLog
.outDetail("Spell %u partially interrupted for (%d) ms at damage", m_spellInfo
->Id
, delaytime
);
5876 WorldPacket
data(SMSG_SPELL_DELAYED
, 8+4);
5877 data
.append(m_caster
->GetPackGUID());
5878 data
<< uint32(delaytime
);
5880 m_caster
->SendMessageToSet(&data
, true);
5883 void Spell::DelayedChannel()
5885 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
|| getState() != SPELL_STATE_CASTING
)
5888 if(isDelayableNoMore()) // Spells may only be delayed twice
5891 // check pushback reduce
5892 int32 delaytime
= GetSpellDuration(m_spellInfo
) * 25 / 100;// channeling delay is normally 25% of its time per hit
5893 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5894 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5895 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5896 if(delayReduce
>= 100)
5899 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5901 if(int32(m_timer
) < delaytime
)
5903 delaytime
= m_timer
;
5907 m_timer
-= delaytime
;
5909 sLog
.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo
->Id
, delaytime
, m_timer
);
5911 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
5913 if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
5915 if (Unit
* unit
= m_caster
->GetGUID() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
))
5916 for (int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
5917 if (ihit
->effectMask
& (1 << j
))
5918 unit
->DelayAura(m_spellInfo
->Id
, SpellEffectIndex(j
), delaytime
);
5923 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
5925 // partially interrupt persistent area auras
5926 if (DynamicObject
* dynObj
= m_caster
->GetDynObject(m_spellInfo
->Id
, SpellEffectIndex(j
)))
5927 dynObj
->Delay(delaytime
);
5930 SendChannelUpdate(m_timer
);
5933 void Spell::UpdateOriginalCasterPointer()
5935 if(m_originalCasterGUID
== m_caster
->GetGUID())
5936 m_originalCaster
= m_caster
;
5937 else if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
5939 GameObject
* go
= m_caster
->IsInWorld() ? m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
) : NULL
;
5940 m_originalCaster
= go
? go
->GetOwner() : NULL
;
5944 Unit
* unit
= ObjectAccessor::GetUnit(*m_caster
, m_originalCasterGUID
);
5945 m_originalCaster
= unit
&& unit
->IsInWorld() ? unit
: NULL
;
5949 void Spell::UpdatePointers()
5951 UpdateOriginalCasterPointer();
5953 m_targets
.Update(m_caster
);
5956 bool Spell::IsAffectedByAura(Aura
*aura
) const
5958 if(SpellModifier
* mod
= aura
->getAuraSpellMod())
5959 return mod
->isAffectedOnSpell(m_spellInfo
);
5964 bool Spell::CheckTargetCreatureType(Unit
* target
) const
5966 uint32 spellCreatureTargetMask
= m_spellInfo
->TargetCreatureType
;
5968 // Curse of Doom & Exorcism: not find another way to fix spell target check :/
5969 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& m_spellInfo
->Category
== 1179)
5971 // not allow cast at player
5972 if(target
->GetTypeId() == TYPEID_PLAYER
)
5975 spellCreatureTargetMask
= 0x7FF;
5978 // Dismiss Pet and Taming Lesson skipped
5979 if(m_spellInfo
->Id
== 2641 || m_spellInfo
->Id
== 23356)
5980 spellCreatureTargetMask
= 0;
5982 if (spellCreatureTargetMask
)
5984 uint32 TargetCreatureType
= target
->GetCreatureTypeMask();
5986 return !TargetCreatureType
|| (spellCreatureTargetMask
& TargetCreatureType
);
5991 CurrentSpellTypes
Spell::GetCurrentContainer()
5993 if (IsNextMeleeSwingSpell())
5994 return(CURRENT_MELEE_SPELL
);
5995 else if (IsAutoRepeat())
5996 return(CURRENT_AUTOREPEAT_SPELL
);
5997 else if (IsChanneledSpell(m_spellInfo
))
5998 return(CURRENT_CHANNELED_SPELL
);
6000 return(CURRENT_GENERIC_SPELL
);
6003 bool Spell::CheckTarget( Unit
* target
, SpellEffectIndex eff
)
6005 // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets)
6006 if(m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SELF
)
6008 if (!CheckTargetCreatureType(target
))
6012 // Check Aura spell req (need for AoE spells)
6013 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
6015 if (m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
6018 // Check targets for not_selectable unit flag and remove
6019 // A player can cast spells on his pet (or other controlled unit) though in any state
6020 if (target
!= m_caster
&& target
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
6022 // any unattackable target skipped
6023 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
))
6026 // unselectable targets skipped in all cases except TARGET_SCRIPT targeting
6027 // in case TARGET_SCRIPT target selected by server always and can't be cheated
6028 if( target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NOT_SELECTABLE
) &&
6029 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SCRIPT
&&
6030 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_SCRIPT
)
6034 // Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
6035 if( target
!= m_caster
&& target
->GetTypeId() == TYPEID_PLAYER
)
6037 if(((Player
*)target
)->GetVisibility() == VISIBILITY_OFF
)
6040 if(((Player
*)target
)->isGameMaster() && !IsPositiveSpell(m_spellInfo
->Id
))
6044 // Check targets for LOS visibility (except spells without range limitations )
6045 switch(m_spellInfo
->Effect
[eff
])
6047 case SPELL_EFFECT_SUMMON_PLAYER
: // from anywhere
6049 case SPELL_EFFECT_DUMMY
:
6050 if(m_spellInfo
->Id
!= 20577) // Cannibalize
6053 case SPELL_EFFECT_RESURRECT_NEW
:
6054 // player far away, maybe his corpse near?
6055 if(target
!= m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
6057 if(!m_targets
.getCorpseTargetGUID())
6060 Corpse
*corpse
= m_caster
->GetMap()->GetCorpse(m_targets
.getCorpseTargetGUID());
6064 if(target
->GetGUID() != corpse
->GetOwnerGUID())
6067 if(!corpse
->IsWithinLOSInMap(m_caster
))
6071 // all ok by some way or another, skip normal check
6073 default: // normal case
6074 // Get GO cast coordinates if original caster -> GO
6075 if (target
!= m_caster
)
6076 if (WorldObject
*caster
= GetCastingObject())
6077 if (!target
->IsWithinLOSInMap(caster
))
6085 bool Spell::IsNeedSendToClient() const
6087 return m_spellInfo
->SpellVisual
[0] || m_spellInfo
->SpellVisual
[1] || IsChanneledSpell(m_spellInfo
) ||
6088 m_spellInfo
->speed
> 0.0f
|| !m_triggeredByAuraSpell
&& !m_IsTriggeredSpell
;
6092 bool Spell::IsTriggeredSpellWithRedundentData() const
6094 return m_IsTriggeredSpell
&& (m_spellInfo
->manaCost
|| m_spellInfo
->ManaCostPercentage
);
6097 bool Spell::HaveTargetsForEffect(SpellEffectIndex effect
) const
6099 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin(); itr
!= m_UniqueTargetInfo
.end(); ++itr
)
6100 if(itr
->effectMask
& (1 << effect
))
6103 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin(); itr
!= m_UniqueGOTargetInfo
.end(); ++itr
)
6104 if(itr
->effectMask
& (1 << effect
))
6107 for(std::list
<ItemTargetInfo
>::const_iterator itr
= m_UniqueItemInfo
.begin(); itr
!= m_UniqueItemInfo
.end(); ++itr
)
6108 if(itr
->effectMask
& (1 << effect
))
6114 SpellEvent::SpellEvent(Spell
* spell
) : BasicEvent()
6119 SpellEvent::~SpellEvent()
6121 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
6124 if (m_Spell
->IsDeletable())
6130 sLog
.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
6131 (m_Spell
->GetCaster()->GetTypeId() == TYPEID_PLAYER
? "Player" : "Creature"), m_Spell
->GetCaster()->GetGUIDLow(), m_Spell
->m_spellInfo
->Id
);
6135 bool SpellEvent::Execute(uint64 e_time
, uint32 p_time
)
6137 // update spell if it is not finished
6138 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
6139 m_Spell
->update(p_time
);
6141 // check spell state to process
6142 switch (m_Spell
->getState())
6144 case SPELL_STATE_FINISHED
:
6146 // spell was finished, check deletable state
6147 if (m_Spell
->IsDeletable())
6149 // check, if we do have unfinished triggered spells
6150 return true; // spell is deletable, finish event
6152 // event will be re-added automatically at the end of routine)
6155 case SPELL_STATE_CASTING
:
6157 // this spell is in channeled state, process it on the next update
6158 // event will be re-added automatically at the end of routine)
6161 case SPELL_STATE_DELAYED
:
6163 // first, check, if we have just started
6164 if (m_Spell
->GetDelayStart() != 0)
6166 // no, we aren't, do the typical update
6167 // check, if we have channeled spell on our hands
6168 if (IsChanneledSpell(m_Spell
->m_spellInfo
))
6170 // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish
6171 // check, if we have casting anything else except this channeled spell and autorepeat
6172 if (m_Spell
->GetCaster()->IsNonMeleeSpellCasted(false, true, true))
6174 // another non-melee non-delayed spell is casted now, abort
6179 // do the action (pass spell to channeling state)
6180 m_Spell
->handle_immediate();
6182 // event will be re-added automatically at the end of routine)
6186 // run the spell handler and think about what we can do next
6187 uint64 t_offset
= e_time
- m_Spell
->GetDelayStart();
6188 uint64 n_offset
= m_Spell
->handle_delayed(t_offset
);
6191 // re-add us to the queue
6192 m_Spell
->GetCaster()->m_Events
.AddEvent(this, m_Spell
->GetDelayStart() + n_offset
, false);
6193 return false; // event not complete
6196 // finish update event will be re-added automatically at the end of routine)
6201 // delaying had just started, record the moment
6202 m_Spell
->SetDelayStart(e_time
);
6203 // re-plan the event for the delay moment
6204 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ m_Spell
->GetDelayMoment(), false);
6205 return false; // event not complete
6212 // event will be re-added automatically at the end of routine)
6216 // spell processing not complete, plan event on the next update interval
6217 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ 1, false);
6218 return false; // event not complete
6221 void SpellEvent::Abort(uint64
/*e_time*/)
6223 // oops, the spell we try to do is aborted
6224 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
6228 bool SpellEvent::IsDeletable() const
6230 return m_Spell
->IsDeletable();
6233 SpellCastResult
Spell::CanOpenLock(SpellEffectIndex effIndex
, uint32 lockId
, SkillType
& skillId
, int32
& reqSkillValue
, int32
& skillValue
)
6235 if(!lockId
) // possible case for GO and maybe for items.
6236 return SPELL_CAST_OK
;
6239 LockEntry
const *lockInfo
= sLockStore
.LookupEntry(lockId
);
6242 return SPELL_FAILED_BAD_TARGETS
;
6244 bool reqKey
= false; // some locks not have reqs
6246 for(int j
= 0; j
< 8; ++j
)
6248 switch(lockInfo
->Type
[j
])
6250 // check key item (many fit cases can be)
6252 if(lockInfo
->Index
[j
] && m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->Index
[j
])
6253 return SPELL_CAST_OK
;
6256 // check key skill (only single first fit case can be)
6257 case LOCK_KEY_SKILL
:
6261 // wrong locktype, skip
6262 if(uint32(m_spellInfo
->EffectMiscValue
[effIndex
]) != lockInfo
->Index
[j
])
6265 skillId
= SkillByLockType(LockType(lockInfo
->Index
[j
]));
6267 if ( skillId
!= SKILL_NONE
)
6269 // skill bonus provided by casting spell (mostly item spells)
6270 // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value)
6271 uint32 spellSkillBonus
= uint32(m_currentBasePoints
[effIndex
]+1);
6272 reqSkillValue
= lockInfo
->Skill
[j
];
6274 // castitem check: rogue using skeleton keys. the skill values should not be added in this case.
6275 skillValue
= m_CastItem
|| m_caster
->GetTypeId()!= TYPEID_PLAYER
?
6276 0 : ((Player
*)m_caster
)->GetSkillValue(skillId
);
6278 skillValue
+= spellSkillBonus
;
6280 if (skillValue
< reqSkillValue
)
6281 return SPELL_FAILED_LOW_CASTLEVEL
;
6284 return SPELL_CAST_OK
;
6290 return SPELL_FAILED_BAD_TARGETS
;
6292 return SPELL_CAST_OK
;
6295 void Spell::FillAreaTargets(UnitList
&targetUnitMap
, float x
, float y
, float radius
, SpellNotifyPushType pushType
, SpellTargets spellTargets
)
6297 CellPair
p(MaNGOS::ComputeCellPair(x
, y
));
6299 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
6301 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, targetUnitMap
, radius
, pushType
, spellTargets
);
6302 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
6303 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
6304 cell
.Visit(p
, world_notifier
, *m_caster
->GetMap(), *m_caster
, radius
);
6305 cell
.Visit(p
, grid_notifier
, *m_caster
->GetMap(), *m_caster
, radius
);
6308 void Spell::FillRaidOrPartyTargets(UnitList
&targetUnitMap
, Unit
* member
, Unit
* center
, float radius
, bool raid
, bool withPets
, bool withcaster
)
6310 Player
*pMember
= member
->GetCharmerOrOwnerPlayerOrPlayerItself();
6311 Group
*pGroup
= pMember
? pMember
->GetGroup() : NULL
;
6315 uint8 subgroup
= pMember
->GetSubGroup();
6317 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
6319 Player
* Target
= itr
->getSource();
6321 // IsHostileTo check duel and controlled by enemy
6322 if (Target
&& (raid
|| subgroup
==Target
->GetSubGroup())
6323 && !m_caster
->IsHostileTo(Target
))
6325 if ((Target
== center
|| center
->IsWithinDistInMap(Target
, radius
)) &&
6326 (withcaster
|| Target
!= m_caster
))
6327 targetUnitMap
.push_back(Target
);
6330 if (Pet
* pet
= Target
->GetPet())
6331 if ((pet
== center
|| center
->IsWithinDistInMap(pet
, radius
)) &&
6332 (withcaster
|| pet
!= m_caster
))
6333 targetUnitMap
.push_back(pet
);
6339 Unit
* ownerOrSelf
= pMember
? pMember
: member
->GetCharmerOrOwnerOrSelf();
6340 if ((ownerOrSelf
== center
|| center
->IsWithinDistInMap(ownerOrSelf
, radius
)) &&
6341 (withcaster
|| ownerOrSelf
!= m_caster
))
6342 targetUnitMap
.push_back(ownerOrSelf
);
6345 if (Pet
* pet
= ownerOrSelf
->GetPet())
6346 if ((pet
== center
|| center
->IsWithinDistInMap(pet
, radius
)) &&
6347 (withcaster
|| pet
!= m_caster
))
6348 targetUnitMap
.push_back(pet
);
6352 void Spell::FillRaidOrPartyManaPriorityTargets(UnitList
&targetUnitMap
, Unit
* member
, Unit
* center
, float radius
, uint32 count
, bool raid
, bool withPets
, bool withCaster
)
6354 FillRaidOrPartyTargets(targetUnitMap
, member
, center
, radius
, raid
, withPets
, withCaster
);
6356 PrioritizeManaUnitQueue manaUsers
;
6357 for(UnitList::const_iterator itr
= targetUnitMap
.begin(); itr
!= targetUnitMap
.end() && manaUsers
.size() < count
; ++itr
)
6358 if ((*itr
)->getPowerType() == POWER_MANA
&& !(*itr
)->isDead())
6359 manaUsers
.push(PrioritizeManaUnitWraper(*itr
));
6361 targetUnitMap
.clear();
6362 while(!manaUsers
.empty())
6364 targetUnitMap
.push_back(manaUsers
.top().getUnit());
6369 void Spell::FillRaidOrPartyHealthPriorityTargets(UnitList
&targetUnitMap
, Unit
* member
, Unit
* center
, float radius
, uint32 count
, bool raid
, bool withPets
, bool withCaster
)
6371 FillRaidOrPartyTargets(targetUnitMap
, member
, center
, radius
, raid
, withPets
, withCaster
);
6373 PrioritizeHealthUnitQueue healthQueue
;
6374 for(UnitList::const_iterator itr
= targetUnitMap
.begin(); itr
!= targetUnitMap
.end() && healthQueue
.size() < count
; ++itr
)
6375 if (!(*itr
)->isDead())
6376 healthQueue
.push(PrioritizeHealthUnitWraper(*itr
));
6378 targetUnitMap
.clear();
6379 while(!healthQueue
.empty())
6381 targetUnitMap
.push_back(healthQueue
.top().getUnit());
6386 WorldObject
* Spell::GetCastingObject() const
6388 if (IS_GAMEOBJECT_GUID(m_originalCasterGUID
))
6389 return m_caster
->IsInWorld() ? m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
) : NULL
;