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_MILLISECONDS)
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
.IsEmpty() ? caster
->GetMap()->GetGameObject(m_GOTargetGUID
) : NULL
;
187 m_unitTarget
= !m_unitTargetGUID
.IsEmpty() ?
188 ( m_unitTargetGUID
== caster
->GetObjectGuid() ? 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
.GetRawValue() < TRADE_SLOT_COUNT
)
200 m_itemTarget
= pTrader
->GetItemByPos(pTrader
->GetItemPosByTradeSlot(uint32(m_itemTargetGUID
.GetRawValue())));
203 m_itemTargetEntry
= m_itemTarget
->GetEntry();
207 void SpellCastTargets::read( ByteBuffer
& data
, Unit
*caster
)
209 data
>> m_targetMask
;
211 if(m_targetMask
== TARGET_FLAG_SELF
)
213 m_destX
= caster
->GetPositionX();
214 m_destY
= caster
->GetPositionY();
215 m_destZ
= caster
->GetPositionZ();
216 m_unitTarget
= caster
;
217 m_unitTargetGUID
= caster
->GetGUID();
221 // TARGET_FLAG_UNK2 is used for non-combat pets, maybe other?
222 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_UNK2
))
223 data
>> m_unitTargetGUID
.ReadAsPacked();
225 if( m_targetMask
& ( TARGET_FLAG_OBJECT
))
226 data
>> m_GOTargetGUID
.ReadAsPacked();
228 if(( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
)) && caster
->GetTypeId() == TYPEID_PLAYER
)
229 data
>> m_itemTargetGUID
.ReadAsPacked();
231 if( m_targetMask
& (TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
232 data
>> m_CorpseTargetGUID
.ReadAsPacked();
234 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
236 data
>> m_unitTargetGUID
.ReadAsPacked();
237 data
>> m_srcX
>> m_srcY
>> m_srcZ
;
238 if(!MaNGOS::IsValidMapCoord(m_srcX
, m_srcY
, m_srcZ
))
239 throw ByteBufferException(false, data
.rpos(), 0, data
.size());
242 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
244 data
>> m_unitTargetGUID
.ReadAsPacked();
245 data
>> m_destX
>> m_destY
>> m_destZ
;
246 if(!MaNGOS::IsValidMapCoord(m_destX
, m_destY
, m_destZ
))
247 throw ByteBufferException(false, data
.rpos(), 0, data
.size());
250 if( m_targetMask
& TARGET_FLAG_STRING
)
253 // find real units/GOs
257 void SpellCastTargets::write( ByteBuffer
& data
) const
259 data
<< uint32(m_targetMask
);
261 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_PVP_CORPSE
| TARGET_FLAG_OBJECT
| TARGET_FLAG_CORPSE
| TARGET_FLAG_UNK2
) )
263 if(m_targetMask
& TARGET_FLAG_UNIT
)
266 data
<< m_unitTarget
->GetPackGUID();
270 else if( m_targetMask
& TARGET_FLAG_OBJECT
)
273 data
<< m_GOTarget
->GetPackGUID();
277 else if( m_targetMask
& ( TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
278 data
<< m_CorpseTargetGUID
.WriteAsPacked();
283 if( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
) )
286 data
<< m_itemTarget
->GetPackGUID();
291 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
294 data
<< m_unitTarget
->GetPackGUID();
298 data
<< m_srcX
<< m_srcY
<< m_srcZ
;
301 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
304 data
<< m_unitTarget
->GetPackGUID();
308 data
<< m_destX
<< m_destY
<< m_destZ
;
311 if( m_targetMask
& TARGET_FLAG_STRING
)
315 Spell::Spell( Unit
* caster
, SpellEntry
const *info
, bool triggered
, ObjectGuid originalCasterGUID
, Spell
** triggeringContainer
)
317 ASSERT( caster
!= NULL
&& info
!= NULL
);
318 ASSERT( info
== sSpellStore
.LookupEntry( info
->Id
) && "`info` must be pointer to sSpellStore element");
320 if (info
->SpellDifficultyId
&& caster
->GetTypeId() != TYPEID_PLAYER
&& caster
->IsInWorld() && caster
->GetMap()->IsDungeon())
322 if (SpellEntry
const* spellEntry
= GetSpellEntryByDifficulty(info
->SpellDifficultyId
, caster
->GetMap()->GetDifficulty()))
323 m_spellInfo
= spellEntry
;
331 m_selfContainer
= NULL
;
332 m_triggeringContainer
= triggeringContainer
;
333 m_referencedFromCurrentSpell
= false;
334 m_executedCurrently
= false;
336 m_delayAtDamageCount
= 0;
338 m_applyMultiplierMask
= 0;
340 // Get data for type of attack
341 m_attackType
= GetWeaponAttackType(m_spellInfo
);
343 m_spellSchoolMask
= GetSpellSchoolMask(info
); // Can be override for some spell (wand shoot for example)
345 if(m_attackType
== RANGED_ATTACK
)
348 if((m_caster
->getClassMask() & CLASSMASK_WAND_USERS
) != 0 && m_caster
->GetTypeId() == TYPEID_PLAYER
)
350 if(Item
* pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(RANGED_ATTACK
))
351 m_spellSchoolMask
= SpellSchoolMask(1 << pItem
->GetProto()->Damage
[0].DamageType
);
354 // Set health leech amount to zero
357 if(!originalCasterGUID
.IsEmpty())
358 m_originalCasterGUID
= originalCasterGUID
;
360 m_originalCasterGUID
= m_caster
->GetObjectGuid();
362 UpdateOriginalCasterPointer();
364 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
365 m_currentBasePoints
[i
] = m_spellInfo
->CalculateSimpleValue(SpellEffectIndex(i
));
367 m_spellState
= SPELL_STATE_NULL
;
369 m_castPositionX
= m_castPositionY
= m_castPositionZ
= 0;
370 m_TriggerSpells
.clear();
371 m_preCastSpells
.clear();
372 m_IsTriggeredSpell
= triggered
;
373 //m_AreaAura = false;
378 gameObjTarget
= NULL
;
382 m_triggeredByAuraSpell
= NULL
;
384 //Auto Shot & Shoot (wand)
385 m_autoRepeat
= IsAutoRepeatRangedSpell(m_spellInfo
);
388 m_powerCost
= 0; // setup to correct value in Spell::prepare, don't must be used before.
389 m_casttime
= 0; // setup to correct value in Spell::prepare, don't must be used before.
390 m_timer
= 0; // will set to cast time in prepare
392 m_needAliveTargetMask
= 0;
394 // determine reflection
395 m_canReflect
= false;
397 if(m_spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
&& !(m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_CANT_REFLECTED
))
399 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
401 if (m_spellInfo
->Effect
[j
] == 0)
404 if(!IsPositiveTarget(m_spellInfo
->EffectImplicitTargetA
[j
], m_spellInfo
->EffectImplicitTargetB
[j
]))
407 m_canReflect
= (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NEGATIVE
) ? true : false;
424 WorldObject
* Spell::FindCorpseUsing()
426 // non-standard target selection
427 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
428 float max_range
= GetSpellMaxRange(srange
);
430 WorldObject
* result
= NULL
;
432 T
u_check(m_caster
, max_range
);
433 MaNGOS::WorldObjectSearcher
<T
> searcher(m_caster
, result
, u_check
);
435 Cell::VisitGridObjects(m_caster
, searcher
, max_range
);
438 Cell::VisitWorldObjects(m_caster
, searcher
, max_range
);
443 void Spell::FillTargetMap()
445 // TODO: ADD the correct target FILLS!!!!!!
447 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
449 // not call for empty effect.
450 // Also some spells use not used effect targets for store targets for dummy effect in triggered spells
451 if(m_spellInfo
->Effect
[i
] == 0)
454 // targets for TARGET_SCRIPT_COORDINATES (A) and TARGET_SCRIPT
455 // for TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT (A) all is checked in Spell::CheckCast and in Spell::CheckItem
456 // filled in Spell::CheckCast call
457 if(m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT_COORDINATES
||
458 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT
||
459 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
||
460 (m_spellInfo
->EffectImplicitTargetB
[i
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
))
463 // TODO: find a way so this is not needed?
464 // for area auras always add caster as target (needed for totems for example)
465 if(IsAreaAuraEffect(m_spellInfo
->Effect
[i
]))
466 AddUnitTarget(m_caster
, SpellEffectIndex(i
));
468 std::list
<Unit
*> tmpUnitMap
;
470 // TargetA/TargetB dependent from each other, we not switch to full support this dependences
471 // but need it support in some know cases
472 switch(m_spellInfo
->EffectImplicitTargetA
[i
])
475 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
478 SetTargetMap(SpellEffectIndex(i
), TARGET_EFFECT_SELECT
, tmpUnitMap
);
481 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
486 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
489 case TARGET_EFFECT_SELECT
:
490 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
492 case TARGET_AREAEFFECT_INSTANT
: // use B case that not dependent from from A in fact
493 if((m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
) == 0)
494 m_targets
.setDestination(m_caster
->GetPositionX(), m_caster
->GetPositionY(), m_caster
->GetPositionZ());
495 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
497 case TARGET_BEHIND_VICTIM
: // use B case that not dependent from from A in fact
498 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
501 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
502 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
506 case TARGET_EFFECT_SELECT
:
507 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
510 case TARGET_EFFECT_SELECT
:
511 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
513 case TARGET_INNKEEPER_COORDINATES
:
514 case TARGET_TABLE_X_Y_Z_COORDINATES
:
515 case TARGET_CASTER_COORDINATES
:
516 case TARGET_SCRIPT_COORDINATES
:
517 case TARGET_CURRENT_ENEMY_COORDINATES
:
518 case TARGET_DUELVSPLAYER_COORDINATES
:
519 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
520 case TARGET_POINT_AT_NORTH
:
521 case TARGET_POINT_AT_SOUTH
:
522 case TARGET_POINT_AT_EAST
:
523 case TARGET_POINT_AT_WEST
:
524 case TARGET_POINT_AT_NE
:
525 case TARGET_POINT_AT_NW
:
526 case TARGET_POINT_AT_SE
:
527 case TARGET_POINT_AT_SW
:
528 // need some target for processing
529 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
530 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
533 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
537 case TARGET_CASTER_COORDINATES
:
538 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
540 case TARGET_ALL_ENEMY_IN_AREA
:
541 // Note: this hack with search required until GO casting not implemented
542 // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support
543 // currently each enemy selected explicitly and self cast damage
544 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
)
546 if(m_targets
.getUnitTarget())
547 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
551 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
552 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
556 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
557 tmpUnitMap
.push_back(m_caster
);
560 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
561 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
565 case TARGET_TABLE_X_Y_Z_COORDINATES
:
566 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
569 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
571 // need some target for processing
572 SetTargetMap(SpellEffectIndex(i
), TARGET_EFFECT_SELECT
, tmpUnitMap
);
574 case TARGET_AREAEFFECT_INSTANT
: // All 17/7 pairs used for dest teleportation, A processed in effect code
575 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
578 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
579 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
584 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
587 case TARGET_EFFECT_SELECT
:
588 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
590 // most A/B target pairs is self->negative and not expect adding caster to target list
592 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
597 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
600 case TARGET_EFFECT_SELECT
:
601 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
603 case TARGET_SCRIPT_COORDINATES
: // B case filled in CheckCast but we need fill unit list base at A case
604 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
607 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetA
[i
], tmpUnitMap
);
608 SetTargetMap(SpellEffectIndex(i
), m_spellInfo
->EffectImplicitTargetB
[i
], tmpUnitMap
);
614 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
616 Player
*me
= (Player
*)m_caster
;
617 for (std::list
<Unit
*>::const_iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end(); ++itr
)
619 Unit
*owner
= (*itr
)->GetOwner();
620 Unit
*u
= owner
? owner
: (*itr
);
621 if(u
!=m_caster
&& u
->IsPvP() && (!me
->duel
|| me
->duel
->opponent
!= u
))
624 me
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
630 for (std::list
<Unit
*>::iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end();)
632 if (!CheckTarget (*itr
, SpellEffectIndex(i
)))
634 itr
= tmpUnitMap
.erase(itr
);
641 for(std::list
<Unit
*>::const_iterator iunit
= tmpUnitMap
.begin(); iunit
!= tmpUnitMap
.end(); ++iunit
)
642 AddUnitTarget((*iunit
), SpellEffectIndex(i
));
646 void Spell::prepareDataForTriggerSystem()
648 //==========================================================================================
649 // Now fill data for trigger system, need know:
650 // an spell trigger another or not ( m_canTrigger )
651 // Create base triggers flags for Attacker and Victim ( m_procAttacker and m_procVictim)
652 //==========================================================================================
653 // Fill flag can spell trigger or not
654 // TODO: possible exist spell attribute for this
655 m_canTrigger
= false;
658 m_canTrigger
= false; // Do not trigger from item cast spell
659 else if (!m_IsTriggeredSpell
)
660 m_canTrigger
= true; // Normal cast - can trigger
661 else if (!m_triggeredByAuraSpell
)
662 m_canTrigger
= true; // Triggered from SPELL_EFFECT_TRIGGER_SPELL - can trigger
664 if (!m_canTrigger
) // Exceptions (some periodic triggers)
666 switch (m_spellInfo
->SpellFamilyName
)
668 case SPELLFAMILY_MAGE
:
669 // Arcane Missles / Blizzard triggers need do it
670 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000200080))
672 // Clearcasting trigger need do it
673 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000200000000) && m_spellInfo
->SpellFamilyFlags2
& 0x8)
675 // Replenish Mana, item spell with triggered cases (Mana Agate, etc mana gems)
676 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000010000000000))
679 case SPELLFAMILY_WARLOCK
:
680 // For Hellfire Effect / Rain of Fire / Seed of Corruption triggers need do it
681 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000800000000060))
684 case SPELLFAMILY_PRIEST
:
685 // For Penance,Mind Sear,Mind Flay heal/damage triggers need do it
686 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0001800000800000) || (m_spellInfo
->SpellFamilyFlags2
& 0x00000040))
689 case SPELLFAMILY_ROGUE
:
690 // For poisons need do it
691 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x000000101001E000))
694 case SPELLFAMILY_HUNTER
:
695 // Hunter Rapid Killing/Explosive Trap Effect/Immolation Trap Effect/Frost Trap Aura/Snake Trap Effect/Explosive Shot
696 if ((m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0100200000000214)) ||
697 m_spellInfo
->SpellFamilyFlags2
& 0x200)
700 case SPELLFAMILY_PALADIN
:
701 // For Judgements (all) / Holy Shock triggers need do it
702 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0001000900B80400))
710 // Get data for type of attack and fill base info for trigger
711 switch (m_spellInfo
->DmgClass
)
713 case SPELL_DAMAGE_CLASS_MELEE
:
714 m_procAttacker
= PROC_FLAG_SUCCESSFUL_MELEE_SPELL_HIT
;
715 m_procVictim
= PROC_FLAG_TAKEN_MELEE_SPELL_HIT
;
717 case SPELL_DAMAGE_CLASS_RANGED
:
719 if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
)
721 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
722 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
724 else // Ranged spell attack
726 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_SPELL_HIT
;
727 m_procVictim
= PROC_FLAG_TAKEN_RANGED_SPELL_HIT
;
731 if (IsPositiveSpell(m_spellInfo
->Id
)) // Check for positive spell
733 m_procAttacker
= PROC_FLAG_SUCCESSFUL_POSITIVE_SPELL
;
734 m_procVictim
= PROC_FLAG_TAKEN_POSITIVE_SPELL
;
736 else if (m_spellInfo
->AttributesEx2
& SPELL_ATTR_EX2_AUTOREPEAT_FLAG
) // Wands auto attack
738 m_procAttacker
= PROC_FLAG_SUCCESSFUL_RANGED_HIT
;
739 m_procVictim
= PROC_FLAG_TAKEN_RANGED_HIT
;
741 else // Negative spell
743 m_procAttacker
= PROC_FLAG_SUCCESSFUL_NEGATIVE_SPELL_HIT
;
744 m_procVictim
= PROC_FLAG_TAKEN_NEGATIVE_SPELL_HIT
;
748 // Hunter traps spells (for Entrapment trigger)
749 // Gives your Immolation Trap, Frost Trap, Explosive Trap, and Snake Trap ....
750 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_HUNTER
&& (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x000020000000001C)))
751 m_procAttacker
|= PROC_FLAG_ON_TRAP_ACTIVATION
;
754 void Spell::CleanupTargetList()
756 m_UniqueTargetInfo
.clear();
757 m_UniqueGOTargetInfo
.clear();
758 m_UniqueItemInfo
.clear();
762 void Spell::AddUnitTarget(Unit
* pVictim
, SpellEffectIndex effIndex
)
764 if( m_spellInfo
->Effect
[effIndex
] == 0 )
767 // Check for effect immune skip if immuned
768 bool immuned
= pVictim
->IsImmunedToSpellEffect(m_spellInfo
, effIndex
);
770 ObjectGuid targetGUID
= pVictim
->GetObjectGuid();
772 // Lookup target in already in list
773 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
775 if (targetGUID
== ihit
->targetGUID
) // Found in list
778 ihit
->effectMask
|= (1 << effIndex
); // Add only effect mask if not immuned
783 // This is new target calculate data for him
785 // Get spell hit result on target
787 target
.targetGUID
= targetGUID
; // Store target GUID
788 target
.effectMask
= immuned
? 0 : (1 << effIndex
); // Store index of effect if not immuned
789 target
.processed
= false; // Effects not apply on target
791 // Calculate hit result
792 target
.missCondition
= m_caster
->SpellHitResult(pVictim
, m_spellInfo
, m_canReflect
);
794 // Spell have speed - need calculate incoming time
795 if (m_spellInfo
->speed
> 0.0f
)
797 // calculate spell incoming interval
798 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
799 if (dist
< 5.0f
) dist
= 5.0f
;
800 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
802 // Calculate minimum incoming time
803 if (m_delayMoment
== 0 || m_delayMoment
>target
.timeDelay
)
804 m_delayMoment
= target
.timeDelay
;
807 target
.timeDelay
= UI64LIT(0);
809 // If target reflect spell back to caster
810 if (target
.missCondition
== SPELL_MISS_REFLECT
)
812 // Calculate reflected spell result on caster
813 target
.reflectResult
= m_caster
->SpellHitResult(m_caster
, m_spellInfo
, m_canReflect
);
815 if (target
.reflectResult
== SPELL_MISS_REFLECT
) // Impossible reflect again, so simply deflect spell
816 target
.reflectResult
= SPELL_MISS_PARRY
;
818 // Increase time interval for reflected spells by 1.5
819 target
.timeDelay
+= target
.timeDelay
>> 1;
822 target
.reflectResult
= SPELL_MISS_NONE
;
824 // Add target to list
825 m_UniqueTargetInfo
.push_back(target
);
828 void Spell::AddUnitTarget(uint64 unitGUID
, SpellEffectIndex effIndex
)
830 Unit
* unit
= m_caster
->GetGUID() == unitGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, unitGUID
);
832 AddUnitTarget(unit
, effIndex
);
835 void Spell::AddGOTarget(GameObject
* pVictim
, SpellEffectIndex effIndex
)
837 if( m_spellInfo
->Effect
[effIndex
] == 0 )
840 ObjectGuid targetGUID
= pVictim
->GetObjectGuid();
842 // Lookup target in already in list
843 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
845 if (targetGUID
== ihit
->targetGUID
) // Found in list
847 ihit
->effectMask
|= (1 << effIndex
); // Add only effect mask
852 // This is new target calculate data for him
855 target
.targetGUID
= targetGUID
;
856 target
.effectMask
= (1 << effIndex
);
857 target
.processed
= false; // Effects not apply on target
859 // Spell have speed - need calculate incoming time
860 if (m_spellInfo
->speed
> 0.0f
)
862 // calculate spell incoming interval
863 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
866 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
867 if (m_delayMoment
== 0 || m_delayMoment
> target
.timeDelay
)
868 m_delayMoment
= target
.timeDelay
;
871 target
.timeDelay
= UI64LIT(0);
873 // Add target to list
874 m_UniqueGOTargetInfo
.push_back(target
);
877 void Spell::AddGOTarget(uint64 goGUID
, SpellEffectIndex effIndex
)
879 GameObject
* go
= m_caster
->GetMap()->GetGameObject(goGUID
);
881 AddGOTarget(go
, effIndex
);
884 void Spell::AddItemTarget(Item
* pitem
, SpellEffectIndex effIndex
)
886 if( m_spellInfo
->Effect
[effIndex
] == 0 )
889 // Lookup target in already in list
890 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin(); ihit
!= m_UniqueItemInfo
.end(); ++ihit
)
892 if (pitem
== ihit
->item
) // Found in list
894 ihit
->effectMask
|= (1 << effIndex
); // Add only effect mask
899 // This is new target add data
901 ItemTargetInfo target
;
903 target
.effectMask
= (1 << effIndex
);
904 m_UniqueItemInfo
.push_back(target
);
907 void Spell::DoAllEffectOnTarget(TargetInfo
*target
)
909 if (target
->processed
) // Check target
911 target
->processed
= true; // Target checked in apply effects procedure
913 // Get mask of effects for target
914 uint32 mask
= target
->effectMask
;
916 Unit
* unit
= m_caster
->GetObjectGuid() == target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, target
->targetGUID
);
920 // Get original caster (if exist) and calculate damage/healing from him data
921 Unit
*real_caster
= GetAffectiveCaster();
922 // FIXME: in case wild GO heal/damage spells will be used target bonuses
923 Unit
*caster
= real_caster
? real_caster
: m_caster
;
925 SpellMissInfo missInfo
= target
->missCondition
;
926 // Need init unitTarget by default unit (can changed in code on reflect)
927 // Or on missInfo!=SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem)
930 // Reset damage/healing counter
931 ResetEffectDamageAndHeal();
933 // Fill base trigger info
934 uint32 procAttacker
= m_procAttacker
;
935 uint32 procVictim
= m_procVictim
;
936 uint32 procEx
= PROC_EX_NONE
;
938 if (m_spellInfo
->speed
> 0)
940 // mark effects that were already handled in Spell::HandleDelayedSpellLaunch on spell launch as processed
941 for (int32 i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
942 if (IsEffectHandledOnDelayedSpellLaunch(m_spellInfo
, SpellEffectIndex(i
)))
945 // maybe used in effects that are handled on hit
946 m_damage
+= target
->damage
;
949 if (missInfo
==SPELL_MISS_NONE
) // In case spell hit target, do all effect on that target
950 DoSpellHitOnUnit(unit
, mask
);
951 else if (missInfo
== SPELL_MISS_REFLECT
) // In case spell reflect from target, do all effect on caster (if hit)
953 if (target
->reflectResult
== SPELL_MISS_NONE
) // If reflected spell hit caster -> do all effect on him
954 DoSpellHitOnUnit(m_caster
, mask
);
957 // All calculated do it!
958 // Do healing and triggers
961 bool crit
= real_caster
&& real_caster
->IsSpellCrit(unitTarget
, m_spellInfo
, m_spellSchoolMask
);
962 uint32 addhealth
= m_healing
;
965 procEx
|= PROC_EX_CRITICAL_HIT
;
966 addhealth
= caster
->SpellCriticalHealingBonus(m_spellInfo
, addhealth
, NULL
);
969 procEx
|= PROC_EX_NORMAL_HIT
;
971 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
972 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
974 caster
->ProcDamageAndSpell(unitTarget
, real_caster
? procAttacker
: PROC_FLAG_NONE
, procVictim
, procEx
, addhealth
, m_attackType
, m_spellInfo
);
977 int32 gain
= caster
->DealHeal(unitTarget
, addhealth
, m_spellInfo
, crit
);
980 unitTarget
->getHostileRefManager().threatAssist(real_caster
, float(gain
) * 0.5f
, m_spellInfo
);
982 // Do damage and triggers
985 // Fill base damage struct (unitTarget - is real spell target)
986 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
988 if (m_spellInfo
->speed
> 0)
990 damageInfo
.damage
= m_damage
;
991 damageInfo
.HitInfo
= target
->HitInfo
;
993 // Add bonuses and fill damageInfo struct
995 caster
->CalculateSpellDamage(&damageInfo
, m_damage
, m_spellInfo
, m_attackType
);
997 unitTarget
->CalculateAbsorbResistBlock(caster
, &damageInfo
, m_spellInfo
);
999 caster
->DealDamageMods(damageInfo
.target
, damageInfo
.damage
, &damageInfo
.absorb
);
1001 // Send log damage message to client
1002 caster
->SendSpellNonMeleeDamageLog(&damageInfo
);
1004 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1005 procVictim
|= PROC_FLAG_TAKEN_ANY_DAMAGE
;
1007 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1008 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1009 caster
->ProcDamageAndSpell(unitTarget
, real_caster
? procAttacker
: PROC_FLAG_NONE
, procVictim
, procEx
, damageInfo
.damage
, m_attackType
, m_spellInfo
);
1011 // Haunt (NOTE: for avoid use additional field damage stored in dummy value (replace unused 100%)
1012 // apply before deal damage because aura can be removed at target kill
1013 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& m_spellInfo
->SpellIconID
== 3172 &&
1014 (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0004000000000000)))
1015 if(Aura
* dummy
= unitTarget
->GetDummyAura(m_spellInfo
->Id
))
1016 dummy
->GetModifier()->m_amount
= damageInfo
.damage
;
1018 caster
->DealSpellDamage(&damageInfo
, true);
1020 // Scourge Strike, here because needs to use final damage in second part of the spell
1021 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_DEATHKNIGHT
&& m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0800000000000000))
1024 Unit::AuraMap
const& auras
= unitTarget
->GetAuras();
1025 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!=auras
.end(); ++itr
)
1027 if(itr
->second
->GetSpellProto()->Dispel
== DISPEL_DISEASE
&&
1028 itr
->second
->GetCasterGUID() == caster
->GetGUID() &&
1029 IsSpellLastAuraEffect(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()))
1035 int32 bp
= count
* CalculateDamage(EFFECT_INDEX_2
, unitTarget
) * damageInfo
.damage
/ 100;
1037 caster
->CastCustomSpell(unitTarget
, 70890, &bp
, NULL
, NULL
, true);
1041 // Passive spell hits/misses or active spells only misses (only triggers)
1044 // Fill base damage struct (unitTarget - is real spell target)
1045 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1046 procEx
= createProcExtendMask(&damageInfo
, missInfo
);
1047 // Do triggers for unit (reflect triggers passed on hit phase for correct drop charge)
1048 if (m_canTrigger
&& missInfo
!= SPELL_MISS_REFLECT
)
1049 caster
->ProcDamageAndSpell(unit
, real_caster
? procAttacker
: PROC_FLAG_NONE
, procVictim
, procEx
, 0, m_attackType
, m_spellInfo
);
1052 // Call scripted function for AI if this spell is casted upon a creature
1053 if (unit
->GetTypeId() == TYPEID_UNIT
)
1055 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1056 // ignore pets or autorepeat/melee casts for speed (not exist quest for spells (hm... )
1057 if (real_caster
&& !((Creature
*)unit
)->isPet() && !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive())
1058 if (Player
* p
= real_caster
->GetCharmerOrOwnerPlayerOrPlayerItself())
1059 p
->CastedCreatureOrGO(unit
->GetEntry(), unit
->GetObjectGuid(), m_spellInfo
->Id
);
1061 if(((Creature
*)unit
)->AI())
1062 ((Creature
*)unit
)->AI()->SpellHit(m_caster
, m_spellInfo
);
1065 // Call scripted function for AI if this spell is casted by a creature
1066 if (m_caster
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)m_caster
)->AI())
1067 ((Creature
*)m_caster
)->AI()->SpellHitTarget(unit
, m_spellInfo
);
1070 void Spell::DoSpellHitOnUnit(Unit
*unit
, const uint32 effectMask
)
1072 if (!unit
|| !effectMask
)
1075 Unit
* realCaster
= GetAffectiveCaster();
1077 // Recheck immune (only for delayed spells)
1078 if (m_spellInfo
->speed
&& (
1079 unit
->IsImmunedToDamage(GetSpellSchoolMask(m_spellInfo
)) ||
1080 unit
->IsImmunedToSpell(m_spellInfo
)))
1083 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_IMMUNE
);
1085 ResetEffectDamageAndHeal();
1089 if (unit
->GetTypeId() == TYPEID_PLAYER
)
1091 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET
, m_spellInfo
->Id
);
1092 ((Player
*)unit
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2
, m_spellInfo
->Id
);
1095 if (realCaster
&& realCaster
->GetTypeId() == TYPEID_PLAYER
)
1096 ((Player
*)realCaster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2
, m_spellInfo
->Id
, 0, unit
);
1098 if (realCaster
&& realCaster
!= unit
)
1100 // Recheck UNIT_FLAG_NON_ATTACKABLE for delayed spells
1101 if (m_spellInfo
->speed
> 0.0f
&&
1102 unit
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
) &&
1103 unit
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
1105 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1106 ResetEffectDamageAndHeal();
1110 if (!realCaster
->IsFriendlyTo(unit
))
1112 // for delayed spells ignore not visible explicit target
1113 if (m_spellInfo
->speed
> 0.0f
&& unit
== m_targets
.getUnitTarget() &&
1114 !unit
->isVisibleForOrDetect(m_caster
, m_caster
, false))
1116 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1117 ResetEffectDamageAndHeal();
1121 // not break stealth by cast targeting
1122 if (!(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_BREAK_STEALTH
))
1123 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1125 // can cause back attack (if detected), stealth removed at Spell::cast if spell break it
1126 if (!(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
) && !IsPositiveSpell(m_spellInfo
->Id
) &&
1127 m_caster
->isVisibleForOrDetect(unit
, unit
, false))
1129 // use speedup check to avoid re-remove after above lines
1130 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_BREAK_STEALTH
)
1131 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1133 // caster can be detected but have stealth aura
1134 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1136 if (!unit
->IsStandState() && !unit
->hasUnitState(UNIT_STAT_STUNNED
))
1137 unit
->SetStandState(UNIT_STAND_STATE_STAND
);
1139 if (!unit
->isInCombat() && unit
->GetTypeId() != TYPEID_PLAYER
&& ((Creature
*)unit
)->AI())
1140 ((Creature
*)unit
)->AI()->AttackedBy(realCaster
);
1142 unit
->AddThreat(realCaster
);
1143 unit
->SetInCombatWith(realCaster
);
1144 realCaster
->SetInCombatWith(unit
);
1146 if (Player
*attackedPlayer
= unit
->GetCharmerOrOwnerPlayerOrPlayerItself())
1147 realCaster
->SetContestedPvP(attackedPlayer
);
1152 // for delayed spells ignore negative spells (after duel end) for friendly targets
1153 if (m_spellInfo
->speed
> 0.0f
&& !IsPositiveSpell(m_spellInfo
->Id
))
1155 realCaster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1156 ResetEffectDamageAndHeal();
1160 // assisting case, healing and resurrection
1161 if (unit
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
1162 realCaster
->SetContestedPvP();
1164 if (unit
->isInCombat() && !(m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NO_INITIAL_AGGRO
))
1166 realCaster
->SetInCombatState(unit
->GetCombatTimer() > 0);
1167 unit
->getHostileRefManager().threatAssist(realCaster
, 0.0f
, m_spellInfo
);
1172 // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
1173 m_diminishGroup
= GetDiminishingReturnsGroupForSpell(m_spellInfo
,m_triggeredByAuraSpell
);
1174 m_diminishLevel
= unit
->GetDiminishing(m_diminishGroup
);
1175 // Increase Diminishing on unit, current informations for actually casts will use values above
1176 if ((GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_PLAYER
&& unit
->GetTypeId() == TYPEID_PLAYER
) ||
1177 GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_ALL
)
1178 unit
->IncrDiminishing(m_diminishGroup
);
1180 // Apply additional spell effects to target
1181 CastPreCastSpells(unit
);
1183 for(int effectNumber
= 0; effectNumber
< MAX_EFFECT_INDEX
; ++effectNumber
)
1185 if (effectMask
& (1 << effectNumber
))
1187 HandleEffects(unit
, NULL
, NULL
, SpellEffectIndex(effectNumber
), m_damageMultipliers
[effectNumber
]);
1188 if ( m_applyMultiplierMask
& (1 << effectNumber
) )
1191 float multiplier
= m_spellInfo
->DmgMultiplier
[effectNumber
];
1192 // Apply multiplier mods
1194 if(Player
* modOwner
= realCaster
->GetSpellModOwner())
1195 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_EFFECT_PAST_FIRST
, multiplier
, this);
1196 m_damageMultipliers
[effectNumber
] *= multiplier
;
1202 void Spell::DoAllEffectOnTarget(GOTargetInfo
*target
)
1204 if (target
->processed
) // Check target
1206 target
->processed
= true; // Target checked in apply effects procedure
1208 uint32 effectMask
= target
->effectMask
;
1212 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
1216 for(int effectNumber
= 0; effectNumber
< MAX_EFFECT_INDEX
; ++effectNumber
)
1217 if (effectMask
& (1 << effectNumber
))
1218 HandleEffects(NULL
, NULL
, go
, SpellEffectIndex(effectNumber
));
1220 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1221 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
1222 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1224 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
1225 p
->CastedCreatureOrGO(go
->GetEntry(), go
->GetObjectGuid(), m_spellInfo
->Id
);
1229 void Spell::DoAllEffectOnTarget(ItemTargetInfo
*target
)
1231 uint32 effectMask
= target
->effectMask
;
1232 if(!target
->item
|| !effectMask
)
1235 for(int effectNumber
= 0; effectNumber
< MAX_EFFECT_INDEX
; ++effectNumber
)
1236 if (effectMask
& (1 << effectNumber
))
1237 HandleEffects(NULL
, target
->item
, NULL
, SpellEffectIndex(effectNumber
));
1240 void Spell::HandleDelayedSpellLaunch(TargetInfo
*target
)
1242 // Get mask of effects for target
1243 uint32 mask
= target
->effectMask
;
1245 Unit
* unit
= m_caster
->GetObjectGuid() == target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, target
->targetGUID
);
1249 // Get original caster (if exist) and calculate damage/healing from him data
1250 Unit
*real_caster
= GetAffectiveCaster();
1251 // FIXME: in case wild GO heal/damage spells will be used target bonuses
1252 Unit
*caster
= real_caster
? real_caster
: m_caster
;
1254 SpellMissInfo missInfo
= target
->missCondition
;
1255 // Need init unitTarget by default unit (can changed in code on reflect)
1256 // Or on missInfo!=SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem)
1259 // Reset damage/healing counter
1261 m_healing
= 0; // healing maybe not needed at this point
1263 // Fill base damage struct (unitTarget - is real spell target)
1264 SpellNonMeleeDamage
damageInfo(caster
, unitTarget
, m_spellInfo
->Id
, m_spellSchoolMask
);
1266 if (missInfo
== SPELL_MISS_NONE
)
1268 for (int32 effectNumber
= 0; effectNumber
< MAX_EFFECT_INDEX
; ++effectNumber
)
1270 if (mask
& (1 << effectNumber
) && IsEffectHandledOnDelayedSpellLaunch(m_spellInfo
, SpellEffectIndex(effectNumber
)))
1272 HandleEffects(unit
, NULL
, NULL
, SpellEffectIndex(effectNumber
), m_damageMultipliers
[effectNumber
]);
1273 if ( m_applyMultiplierMask
& (1 << effectNumber
) )
1276 float multiplier
= m_spellInfo
->DmgMultiplier
[effectNumber
];
1277 // Apply multiplier mods
1279 if(Player
* modOwner
= real_caster
->GetSpellModOwner())
1280 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_EFFECT_PAST_FIRST
, multiplier
, this);
1281 m_damageMultipliers
[effectNumber
] *= multiplier
;
1287 caster
->CalculateSpellDamage(&damageInfo
, m_damage
, m_spellInfo
, m_attackType
);
1290 target
->damage
= damageInfo
.damage
;
1291 target
->HitInfo
= damageInfo
.HitInfo
;
1294 void Spell::InitializeDamageMultipliers()
1296 for (int32 i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
1298 if (m_spellInfo
->Effect
[i
] == 0)
1301 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[i
];
1302 if (Unit
* realCaster
= GetAffectiveCaster())
1303 if(Player
* modOwner
= realCaster
->GetSpellModOwner())
1304 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
1306 m_damageMultipliers
[i
] = 1.0f
;
1307 if( (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CHAIN_HEAL
) &&
1308 (EffectChainTarget
> 1) )
1309 m_applyMultiplierMask
|= (1 << i
);
1313 bool Spell::IsAliveUnitPresentInTargetList()
1315 // Not need check return true
1316 if (m_needAliveTargetMask
== 0)
1319 uint8 needAliveTargetMask
= m_needAliveTargetMask
;
1321 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
1323 if( ihit
->missCondition
== SPELL_MISS_NONE
&& (needAliveTargetMask
& ihit
->effectMask
) )
1325 Unit
*unit
= m_caster
->GetObjectGuid() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
1327 // either unit is alive and normal spell, or unit dead and deathonly-spell
1328 if (unit
&& (unit
->isAlive() != IsDeathOnlySpell(m_spellInfo
)))
1329 needAliveTargetMask
&= ~ihit
->effectMask
; // remove from need alive mask effect that have alive target
1333 // is all effects from m_needAliveTargetMask have alive targets
1334 return needAliveTargetMask
== 0;
1337 // Helper for Chain Healing
1338 // Spell target first
1339 // Raidmates then descending by injury suffered (MaxHealth - Health)
1340 // Other players/mobs then descending by injury suffered (MaxHealth - Health)
1341 struct ChainHealingOrder
: public std::binary_function
<const Unit
*, const Unit
*, bool>
1343 const Unit
* MainTarget
;
1344 ChainHealingOrder(Unit
const* Target
) : MainTarget(Target
) {};
1345 // functor for operator ">"
1346 bool operator()(Unit
const* _Left
, Unit
const* _Right
) const
1348 return (ChainHealingHash(_Left
) < ChainHealingHash(_Right
));
1350 int32
ChainHealingHash(Unit
const* Target
) const
1352 if (Target
== MainTarget
)
1354 else if (Target
->GetTypeId() == TYPEID_PLAYER
&& MainTarget
->GetTypeId() == TYPEID_PLAYER
&&
1355 ((Player
const*)Target
)->IsInSameRaidWith((Player
const*)MainTarget
))
1357 if (Target
->GetHealth() == Target
->GetMaxHealth())
1360 return 20000 - Target
->GetMaxHealth() + Target
->GetHealth();
1363 return 40000 - Target
->GetMaxHealth() + Target
->GetHealth();
1367 class ChainHealingFullHealth
: std::unary_function
<const Unit
*, bool>
1370 const Unit
* MainTarget
;
1371 ChainHealingFullHealth(const Unit
* Target
) : MainTarget(Target
) {};
1373 bool operator()(const Unit
* Target
)
1375 return (Target
!= MainTarget
&& Target
->GetHealth() == Target
->GetMaxHealth());
1379 // Helper for targets nearest to the spell target
1380 // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
1381 struct TargetDistanceOrder
: public std::binary_function
<const Unit
, const Unit
, bool>
1383 const Unit
* MainTarget
;
1384 TargetDistanceOrder(const Unit
* Target
) : MainTarget(Target
) {};
1385 // functor for operator ">"
1386 bool operator()(const Unit
* _Left
, const Unit
* _Right
) const
1388 return MainTarget
->GetDistanceOrder(_Left
, _Right
);
1392 void Spell::SetTargetMap(SpellEffectIndex effIndex
, uint32 targetMode
, UnitList
& targetUnitMap
)
1395 if (m_spellInfo
->EffectRadiusIndex
[effIndex
])
1396 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[effIndex
]));
1398 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
));
1400 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[effIndex
];
1402 if (Unit
* realCaster
= GetAffectiveCaster())
1404 if(Player
* modOwner
= realCaster
->GetSpellModOwner())
1406 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RADIUS
, radius
, this);
1407 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
1411 // Get spell max affected targets
1412 uint32 unMaxTargets
= m_spellInfo
->MaxAffectedTargets
;
1414 // custom target amount cases
1415 switch(m_spellInfo
->SpellFamilyName
)
1417 case SPELLFAMILY_GENERIC
:
1419 switch(m_spellInfo
->Id
)
1421 case 31347: // Doom TODO: exclude top threat target from target selection
1422 case 33711: // Murmur's Touch
1423 case 38794: // Murmur's Touch (h)
1426 case 28542: // Life Drain
1427 case 66013: // Penetrating Cold (10 man)
1428 case 68509: // Penetrating Cold (10 man heroic)
1431 case 28796: // Poison Bolt Volley
1432 case 29213: // Curse of the Plaguebringer
1433 case 31298: // Sleep
1436 case 30843: // Enfeeble TODO: exclude top threat target from target selection
1437 case 42005: // Bloodboil TODO: need to be 5 targets(players) furthest away from caster
1438 case 55665: // Life Drain (h)
1439 case 67700: // Penetrating Cold (25 man)
1440 case 68510: // Penetrating Cold (25 man, heroic)
1443 case 54098: // Poison Bolt Volley (h)
1444 case 54835: // Curse of the Plaguebringer (h)
1447 case 25991: // Poison Bolt Volley (Pincess Huhuran)
1453 case SPELLFAMILY_PALADIN
:
1454 if (m_spellInfo
->Id
== 20424) // Seal of Command (2 more target for single targeted spell)
1456 // overwrite EffectChainTarget for non single target spell
1457 if (Spell
* currSpell
= m_caster
->GetCurrentSpell(CURRENT_GENERIC_SPELL
))
1458 if (currSpell
->m_spellInfo
->MaxAffectedTargets
> 0 ||
1459 currSpell
->m_spellInfo
->EffectChainTarget
[EFFECT_INDEX_0
] > 0 ||
1460 currSpell
->m_spellInfo
->EffectChainTarget
[EFFECT_INDEX_1
] > 0 ||
1461 currSpell
->m_spellInfo
->EffectChainTarget
[EFFECT_INDEX_2
] > 0)
1462 EffectChainTarget
= 0; // no chain targets
1465 case SPELLFAMILY_DRUID
:
1467 if (m_spellInfo
->SpellFamilyFlags2
& 0x00000100)// Starfall
1475 Unit::AuraList
const& mod
= m_caster
->GetAurasByType(SPELL_AURA_MOD_MAX_AFFECTED_TARGETS
);
1476 for(Unit::AuraList::const_iterator m
= mod
.begin(); m
!= mod
.end(); ++m
)
1478 if (!(*m
)->isAffectedOnSpell(m_spellInfo
))
1480 unMaxTargets
+= (*m
)->GetModifier()->m_amount
;
1485 case TARGET_RANDOM_NEARBY_LOC
:
1486 radius
*= sqrtf(rand_norm_f()); // Get a random point in circle. Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates.
1487 // no 'break' expected since we use code in case TARGET_RANDOM_CIRCUMFERENCE_POINT!!!
1488 case TARGET_RANDOM_CIRCUMFERENCE_POINT
:
1490 float angle
= 2.0f
* M_PI_F
* rand_norm_f();
1491 float dest_x
, dest_y
, dest_z
;
1492 m_caster
->GetClosePoint(dest_x
, dest_y
, dest_z
, 0.0f
, radius
, angle
);
1493 m_targets
.setDestination(dest_x
, dest_y
, dest_z
);
1495 targetUnitMap
.push_back(m_caster
);
1498 case TARGET_RANDOM_NEARBY_DEST
:
1500 radius
*= sqrtf(rand_norm_f()); // Get a random point in circle. Use sqrt(rand) to correct distribution when converting polar to Cartesian coordinates.
1501 float angle
= 2.0f
* M_PI_F
* rand_norm_f();
1502 float dest_x
= m_targets
.m_destX
+ cos(angle
) * radius
;
1503 float dest_y
= m_targets
.m_destY
+ sin(angle
) * radius
;
1504 float dest_z
= m_caster
->GetPositionZ();
1505 m_caster
->UpdateGroundPositionZ(dest_x
, dest_y
, dest_z
);
1506 m_targets
.setDestination(dest_x
, dest_y
, dest_z
);
1510 // caster included here?
1511 FillAreaTargets(targetUnitMap
, dest_x
, dest_y
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1514 targetUnitMap
.push_back(m_caster
);
1518 case TARGET_TOTEM_EARTH
:
1519 case TARGET_TOTEM_WATER
:
1520 case TARGET_TOTEM_AIR
:
1521 case TARGET_TOTEM_FIRE
:
1524 case TARGET_AREAEFFECT_CUSTOM_2
:
1525 targetUnitMap
.push_back(m_caster
);
1527 case TARGET_RANDOM_ENEMY_CHAIN_IN_AREA
:
1529 m_targets
.m_targetMask
= 0;
1530 unMaxTargets
= EffectChainTarget
;
1531 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1533 std::list
<Unit
*> tempTargetUnitMap
;
1536 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(m_caster
, max_range
);
1537 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(m_caster
, tempTargetUnitMap
, u_check
);
1538 Cell::VisitAllObjects(m_caster
, searcher
, max_range
);
1541 if(tempTargetUnitMap
.empty())
1544 tempTargetUnitMap
.sort(TargetDistanceOrder(m_caster
));
1546 //Now to get us a random target that's in the initial range of the spell
1548 std::list
<Unit
*>::iterator itr
= tempTargetUnitMap
.begin();
1549 while(itr
!= tempTargetUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
, radius
))
1555 itr
= tempTargetUnitMap
.begin();
1556 std::advance(itr
, rand() % t
);
1557 Unit
*pUnitTarget
= *itr
;
1558 targetUnitMap
.push_back(pUnitTarget
);
1560 tempTargetUnitMap
.erase(itr
);
1562 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1564 t
= unMaxTargets
- 1;
1565 Unit
*prev
= pUnitTarget
;
1566 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
1568 while(t
&& next
!= tempTargetUnitMap
.end())
1570 if(!prev
->IsWithinDist(*next
, CHAIN_SPELL_JUMP_RADIUS
))
1573 if(!prev
->IsWithinLOSInMap(*next
))
1580 targetUnitMap
.push_back(prev
);
1581 tempTargetUnitMap
.erase(next
);
1582 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
1583 next
= tempTargetUnitMap
.begin();
1589 case TARGET_RANDOM_FRIEND_CHAIN_IN_AREA
:
1591 m_targets
.m_targetMask
= 0;
1592 unMaxTargets
= EffectChainTarget
;
1593 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1594 std::list
<Unit
*> tempTargetUnitMap
;
1596 MaNGOS::AnyFriendlyUnitInObjectRangeCheck
u_check(m_caster
, max_range
);
1597 MaNGOS::UnitListSearcher
<MaNGOS::AnyFriendlyUnitInObjectRangeCheck
> searcher(m_caster
, tempTargetUnitMap
, u_check
);
1598 Cell::VisitAllObjects(m_caster
, searcher
, max_range
);
1601 if(tempTargetUnitMap
.empty())
1604 tempTargetUnitMap
.sort(TargetDistanceOrder(m_caster
));
1606 //Now to get us a random target that's in the initial range of the spell
1608 std::list
<Unit
*>::iterator itr
= tempTargetUnitMap
.begin();
1609 while(itr
!= tempTargetUnitMap
.end() && (*itr
)->IsWithinDist(m_caster
, radius
))
1615 itr
= tempTargetUnitMap
.begin();
1616 std::advance(itr
, rand() % t
);
1617 Unit
*pUnitTarget
= *itr
;
1618 targetUnitMap
.push_back(pUnitTarget
);
1620 tempTargetUnitMap
.erase(itr
);
1622 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1624 t
= unMaxTargets
- 1;
1625 Unit
*prev
= pUnitTarget
;
1626 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
1628 while(t
&& next
!= tempTargetUnitMap
.end())
1630 if(!prev
->IsWithinDist(*next
, CHAIN_SPELL_JUMP_RADIUS
))
1633 if(!prev
->IsWithinLOSInMap(*next
))
1639 targetUnitMap
.push_back(prev
);
1640 tempTargetUnitMap
.erase(next
);
1641 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
1642 next
= tempTargetUnitMap
.begin();
1649 Pet
* tmpUnit
= m_caster
->GetPet();
1650 if (!tmpUnit
) break;
1651 targetUnitMap
.push_back(tmpUnit
);
1654 case TARGET_CHAIN_DAMAGE
:
1656 if (EffectChainTarget
<= 1)
1658 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1660 m_targets
.setUnitTarget(pUnitTarget
);
1661 targetUnitMap
.push_back(pUnitTarget
);
1666 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1667 WorldObject
* originalCaster
= GetAffectiveCasterObject();
1668 if(!pUnitTarget
|| !originalCaster
)
1671 unMaxTargets
= EffectChainTarget
;
1674 if(m_spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MELEE
)
1677 //FIXME: This very like horrible hack and wrong for most spells
1678 max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1680 std::list
<Unit
*> tempTargetUnitMap
;
1682 MaNGOS::AnyAoEVisibleTargetUnitInObjectRangeCheck
u_check(pUnitTarget
, originalCaster
, max_range
);
1683 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoEVisibleTargetUnitInObjectRangeCheck
> searcher(m_caster
, tempTargetUnitMap
, u_check
);
1684 Cell::VisitAllObjects(m_caster
, searcher
, max_range
);
1686 if (tempTargetUnitMap
.empty())
1689 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1691 if (*tempTargetUnitMap
.begin() == pUnitTarget
)
1692 tempTargetUnitMap
.erase(tempTargetUnitMap
.begin());
1694 targetUnitMap
.push_back(pUnitTarget
);
1695 uint32 t
= unMaxTargets
- 1;
1696 Unit
*prev
= pUnitTarget
;
1697 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
1699 while (t
&& next
!= tempTargetUnitMap
.end())
1701 if (!prev
->IsWithinDist (*next
,CHAIN_SPELL_JUMP_RADIUS
))
1703 if (!prev
->IsWithinLOSInMap (*next
))
1709 targetUnitMap
.push_back(prev
);
1710 tempTargetUnitMap
.erase(next
);
1711 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
1712 next
= tempTargetUnitMap
.begin();
1718 case TARGET_ALL_ENEMY_IN_AREA
:
1719 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1721 case TARGET_AREAEFFECT_INSTANT
:
1723 SpellTargets targetB
= SPELL_TARGETS_AOE_DAMAGE
;
1724 // Select friendly targets for positive effect
1725 if (IsPositiveEffect(m_spellInfo
->Id
, effIndex
))
1726 targetB
= SPELL_TARGETS_FRIENDLY
;
1728 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_DEST_CENTER
, targetB
);
1731 targetUnitMap
.remove(m_caster
);
1734 case TARGET_AREAEFFECT_CUSTOM
:
1736 if (m_spellInfo
->Effect
[effIndex
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1738 else if (m_spellInfo
->Effect
[effIndex
] == SPELL_EFFECT_SUMMON
)
1740 targetUnitMap
.push_back(m_caster
);
1744 UnitList tempTargetUnitMap
;
1745 SpellScriptTargetBounds bounds
= sSpellMgr
.GetSpellScriptTargetBounds(m_spellInfo
->Id
);
1746 // fill real target list if no spell script target defined
1747 FillAreaTargets(bounds
.first
!= bounds
.second
? tempTargetUnitMap
: targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_ALL
);
1749 if (!tempTargetUnitMap
.empty())
1751 for (UnitList::const_iterator iter
= tempTargetUnitMap
.begin(); iter
!= tempTargetUnitMap
.end(); ++iter
)
1753 if ((*iter
)->GetTypeId() != TYPEID_UNIT
)
1756 for(SpellScriptTarget::const_iterator i_spellST
= bounds
.first
; i_spellST
!= bounds
.second
; ++i_spellST
)
1758 // only creature entries supported for this target type
1759 if (i_spellST
->second
.type
== SPELL_TARGET_TYPE_GAMEOBJECT
)
1762 if ((*iter
)->GetEntry() == i_spellST
->second
.targetEntry
)
1764 targetUnitMap
.push_back((*iter
));
1772 // remove not targetable units if spell has no script targets
1773 for (UnitList::iterator itr
= targetUnitMap
.begin(); itr
!= targetUnitMap
.end(); )
1775 if (!(*itr
)->isTargetableForAttack(m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_CAST_ON_DEAD
))
1776 targetUnitMap
.erase(itr
++);
1783 case TARGET_ALL_ENEMY_IN_AREA_INSTANT
:
1785 // targets the ground, not the units in the area
1786 switch(m_spellInfo
->Effect
[effIndex
])
1788 case SPELL_EFFECT_PERSISTENT_AREA_AURA
:
1790 case SPELL_EFFECT_SUMMON
:
1791 targetUnitMap
.push_back(m_caster
);
1794 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1799 case TARGET_DUELVSPLAYER_COORDINATES
:
1801 if(Unit
* currentTarget
= m_targets
.getUnitTarget())
1803 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1804 targetUnitMap
.push_back(currentTarget
);
1808 case TARGET_ALL_PARTY_AROUND_CASTER
:
1809 case TARGET_ALL_PARTY_AROUND_CASTER_2
:
1810 case TARGET_ALL_PARTY
:
1811 FillRaidOrPartyTargets(targetUnitMap
, m_caster
, m_caster
, radius
, false, true, true);
1813 case TARGET_ALL_RAID_AROUND_CASTER
:
1815 if(m_spellInfo
->Id
== 57669) // Replenishment (special target selection)
1817 // in arena, target should be only caster
1818 if (m_caster
->GetMap()->IsBattleArena())
1819 targetUnitMap
.push_back(m_caster
);
1821 FillRaidOrPartyManaPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 10, true, false, true);
1823 else if (m_spellInfo
->Id
==52759) // Ancestral Awakening (special target selection)
1824 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 1, true, false, true);
1826 FillRaidOrPartyTargets(targetUnitMap
, m_caster
, m_caster
, radius
, true, true, true);
1829 case TARGET_SINGLE_FRIEND
:
1830 case TARGET_SINGLE_FRIEND_2
:
1831 if(m_targets
.getUnitTarget())
1832 targetUnitMap
.push_back(m_targets
.getUnitTarget());
1834 case TARGET_NONCOMBAT_PET
:
1835 if(Unit
* target
= m_targets
.getUnitTarget())
1836 if( target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet() && ((Pet
*)target
)->getPetType() == MINI_PET
)
1837 targetUnitMap
.push_back(target
);
1839 case TARGET_CASTER_COORDINATES
:
1841 // Check original caster is GO - set its coordinates as dst cast
1842 if (WorldObject
*caster
= GetCastingObject())
1843 m_targets
.setDestination(caster
->GetPositionX(), caster
->GetPositionY(), caster
->GetPositionZ());
1846 case TARGET_ALL_HOSTILE_UNITS_AROUND_CASTER
:
1847 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_SELF_CENTER
, SPELL_TARGETS_HOSTILE
);
1849 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER
:
1850 switch (m_spellInfo
->Id
)
1852 case 56153: // Guardian Aura - Ahn'Kahet
1853 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
1854 targetUnitMap
.remove(m_caster
);
1856 case 64844: // Divine Hymn
1857 // target amount stored in parent spell dummy effect but hard to access
1858 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 3, true, false, false);
1860 case 64904: // Hymn of Hope
1861 // target amount stored in parent spell dummy effect but hard to access
1862 FillRaidOrPartyManaPriorityTargets(targetUnitMap
, m_caster
, m_caster
, radius
, 3, true, false, false);
1865 // selected friendly units (for casting objects) around casting object
1866 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
, GetCastingObject());
1870 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA
:
1871 // Death Pact (in fact selection by player selection)
1872 if (m_spellInfo
->Id
== 48743)
1874 // checked in Spell::CheckCast
1875 if (m_caster
->GetTypeId()==TYPEID_PLAYER
)
1876 if (Unit
* target
= m_caster
->GetMap()->GetPet(((Player
*)m_caster
)->GetSelection()))
1877 targetUnitMap
.push_back(target
);
1879 // Circle of Healing
1880 else if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_PRIEST
&& m_spellInfo
->SpellVisual
[0] == 8253)
1882 Unit
* target
= m_targets
.getUnitTarget();
1887 // Glyph of Circle of Healing
1888 if(Aura
const* glyph
= m_caster
->GetDummyAura(55675))
1889 count
+= glyph
->GetModifier()->m_amount
;
1891 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, target
, radius
, count
, true, false, true);
1894 else if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_DRUID
&& m_spellInfo
->SpellIconID
== 2864)
1896 Unit
* target
= m_targets
.getUnitTarget();
1899 uint32 count
= CalculateDamage(EFFECT_INDEX_2
,m_caster
); // stored in dummy effect, affected by mods
1901 FillRaidOrPartyHealthPriorityTargets(targetUnitMap
, m_caster
, target
, radius
, count
, true, false, true);
1904 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_FRIENDLY
);
1906 // 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..)
1907 case TARGET_SINGLE_PARTY
:
1909 Unit
*target
= m_targets
.getUnitTarget();
1910 // Those spells apparently can't be casted on the caster.
1911 if( target
&& target
!= m_caster
)
1913 // Can only be casted on group's members or its pets
1914 Group
*pGroup
= NULL
;
1916 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1917 Unit
*targetOwner
= target
->GetCharmerOrOwner();
1920 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1922 if( target
== owner
)
1924 targetUnitMap
.push_back(target
);
1927 pGroup
= ((Player
*)owner
)->GetGroup();
1930 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1932 if( targetOwner
== m_caster
&& target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet())
1934 targetUnitMap
.push_back(target
);
1937 pGroup
= ((Player
*)m_caster
)->GetGroup();
1942 // Our target can also be a player's pet who's grouped with us or our pet. But can't be controlled player
1945 if( targetOwner
->GetTypeId() == TYPEID_PLAYER
&&
1946 target
->GetTypeId() == TYPEID_UNIT
&& (((Creature
*)target
)->isPet()) &&
1947 target
->GetOwnerGUID() == targetOwner
->GetGUID() &&
1948 pGroup
->IsMember(((Player
*)targetOwner
)->GetGUID()))
1950 targetUnitMap
.push_back(target
);
1953 // 1Our target can be a player who is on our group
1954 else if (target
->GetTypeId() == TYPEID_PLAYER
&& pGroup
->IsMember(((Player
*)target
)->GetGUID()))
1956 targetUnitMap
.push_back(target
);
1962 case TARGET_GAMEOBJECT
:
1963 if(m_targets
.getGOTarget())
1964 AddGOTarget(m_targets
.getGOTarget(), effIndex
);
1966 case TARGET_IN_FRONT_OF_CASTER
:
1968 bool inFront
= m_spellInfo
->SpellVisual
[0] != 3879;
1969 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, inFront
? PUSH_IN_FRONT
: PUSH_IN_BACK
, SPELL_TARGETS_AOE_DAMAGE
);
1972 case TARGET_LARGE_FRONTAL_CONE
:
1973 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_90
, SPELL_TARGETS_AOE_DAMAGE
);
1975 case TARGET_NARROW_FRONTAL_CONE
:
1976 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_15
, SPELL_TARGETS_AOE_DAMAGE
);
1978 case TARGET_IN_FRONT_OF_CASTER_30
:
1979 FillAreaTargets(targetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), radius
, PUSH_IN_FRONT_30
, SPELL_TARGETS_AOE_DAMAGE
);
1981 case TARGET_DUELVSPLAYER
:
1983 Unit
*target
= m_targets
.getUnitTarget();
1986 if(m_caster
->IsFriendlyTo(target
))
1988 targetUnitMap
.push_back(target
);
1992 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
1994 m_targets
.setUnitTarget(pUnitTarget
);
1995 targetUnitMap
.push_back(pUnitTarget
);
2001 case TARGET_GAMEOBJECT_ITEM
:
2002 if(m_targets
.getGOTargetGUID())
2003 AddGOTarget(m_targets
.getGOTarget(), effIndex
);
2004 else if(m_targets
.getItemTarget())
2005 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
2008 if(Unit
* owner
= m_caster
->GetCharmerOrOwner())
2009 targetUnitMap
.push_back(owner
);
2011 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED
:
2012 // targets the ground, not the units in the area
2013 if (m_spellInfo
->Effect
[effIndex
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2014 FillAreaTargets(targetUnitMap
, m_targets
.m_destX
, m_targets
.m_destY
, radius
, PUSH_DEST_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
2017 if(m_spellInfo
->Effect
[effIndex
] != SPELL_EFFECT_DUEL
)
2018 targetUnitMap
.push_back(m_caster
);
2020 case TARGET_SINGLE_ENEMY
:
2022 if(Unit
* pUnitTarget
= m_caster
->SelectMagnetTarget(m_targets
.getUnitTarget(), m_spellInfo
))
2024 m_targets
.setUnitTarget(pUnitTarget
);
2025 targetUnitMap
.push_back(pUnitTarget
);
2029 case TARGET_AREAEFFECT_PARTY
:
2031 Unit
* owner
= m_caster
->GetCharmerOrOwner();
2032 Player
*pTarget
= NULL
;
2036 targetUnitMap
.push_back(m_caster
);
2037 if(owner
->GetTypeId() == TYPEID_PLAYER
)
2038 pTarget
= (Player
*)owner
;
2040 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2042 if(Unit
* target
= m_targets
.getUnitTarget())
2044 if( target
->GetTypeId() != TYPEID_PLAYER
)
2046 if(((Creature
*)target
)->isPet())
2048 Unit
*targetOwner
= target
->GetOwner();
2049 if(targetOwner
->GetTypeId() == TYPEID_PLAYER
)
2050 pTarget
= (Player
*)targetOwner
;
2054 pTarget
= (Player
*)target
;
2058 Group
* pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
2062 uint8 subgroup
= pTarget
->GetSubGroup();
2064 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2066 Player
* Target
= itr
->getSource();
2068 // IsHostileTo check duel and controlled by enemy
2069 if(Target
&& Target
->GetSubGroup() == subgroup
&& !m_caster
->IsHostileTo(Target
))
2071 if( pTarget
->IsWithinDistInMap(Target
, radius
) )
2072 targetUnitMap
.push_back(Target
);
2074 if(Pet
* pet
= Target
->GetPet())
2075 if( pTarget
->IsWithinDistInMap(pet
, radius
) )
2076 targetUnitMap
.push_back(pet
);
2082 if(m_caster
->IsWithinDistInMap(owner
, radius
))
2083 targetUnitMap
.push_back(owner
);
2087 targetUnitMap
.push_back(pTarget
);
2089 if(Pet
* pet
= pTarget
->GetPet())
2090 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
2091 targetUnitMap
.push_back(pet
);
2097 if(m_targets
.getUnitTarget())
2098 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2099 if(m_targets
.getItemTarget())
2100 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
2103 case TARGET_SELF_FISHING
:
2104 targetUnitMap
.push_back(m_caster
);
2106 case TARGET_CHAIN_HEAL
:
2108 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
2112 if (EffectChainTarget
<= 1)
2113 targetUnitMap
.push_back(pUnitTarget
);
2116 unMaxTargets
= EffectChainTarget
;
2117 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
2119 UnitList tempTargetUnitMap
;
2121 FillAreaTargets(tempTargetUnitMap
, m_caster
->GetPositionX(), m_caster
->GetPositionY(), max_range
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
2123 if (m_caster
!= pUnitTarget
&& std::find(tempTargetUnitMap
.begin(), tempTargetUnitMap
.end(), m_caster
) == tempTargetUnitMap
.end())
2124 tempTargetUnitMap
.push_front(m_caster
);
2126 tempTargetUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
2128 if (tempTargetUnitMap
.empty())
2131 if (*tempTargetUnitMap
.begin() == pUnitTarget
)
2132 tempTargetUnitMap
.erase(tempTargetUnitMap
.begin());
2134 targetUnitMap
.push_back(pUnitTarget
);
2135 uint32 t
= unMaxTargets
- 1;
2136 Unit
*prev
= pUnitTarget
;
2137 std::list
<Unit
*>::iterator next
= tempTargetUnitMap
.begin();
2139 while(t
&& next
!= tempTargetUnitMap
.end())
2141 if(!prev
->IsWithinDist(*next
, CHAIN_SPELL_JUMP_RADIUS
))
2144 if(!prev
->IsWithinLOSInMap(*next
))
2150 if((*next
)->GetHealth() == (*next
)->GetMaxHealth())
2152 next
= tempTargetUnitMap
.erase(next
);
2157 targetUnitMap
.push_back(prev
);
2158 tempTargetUnitMap
.erase(next
);
2159 tempTargetUnitMap
.sort(TargetDistanceOrder(prev
));
2160 next
= tempTargetUnitMap
.begin();
2167 case TARGET_CURRENT_ENEMY_COORDINATES
:
2169 Unit
* currentTarget
= m_targets
.getUnitTarget();
2172 targetUnitMap
.push_back(currentTarget
);
2173 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
2174 if(m_spellInfo
->EffectImplicitTargetB
[effIndex
] == TARGET_ALL_ENEMY_IN_AREA_INSTANT
)
2175 FillAreaTargets(targetUnitMap
, currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), radius
, PUSH_TARGET_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
2179 case TARGET_AREAEFFECT_PARTY_AND_CLASS
:
2181 Player
* targetPlayer
= m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
2182 ? (Player
*)m_targets
.getUnitTarget() : NULL
;
2184 Group
* pGroup
= targetPlayer
? targetPlayer
->GetGroup() : NULL
;
2187 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
2189 Player
* Target
= itr
->getSource();
2191 // IsHostileTo check duel and controlled by enemy
2192 if( Target
&& targetPlayer
->IsWithinDistInMap(Target
, radius
) &&
2193 targetPlayer
->getClass() == Target
->getClass() &&
2194 !m_caster
->IsHostileTo(Target
) )
2196 targetUnitMap
.push_back(Target
);
2200 else if(m_targets
.getUnitTarget())
2201 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2204 case TARGET_TABLE_X_Y_Z_COORDINATES
:
2206 SpellTargetPosition
const* st
= sSpellMgr
.GetSpellTargetPosition(m_spellInfo
->Id
);
2209 // teleport spells are handled in another way
2210 if (m_spellInfo
->Effect
[effIndex
] == SPELL_EFFECT_TELEPORT_UNITS
)
2212 if (st
->target_mapId
== m_caster
->GetMapId())
2213 m_targets
.setDestination(st
->target_X
, st
->target_Y
, st
->target_Z
);
2215 sLog
.outError( "SPELL: wrong map (%u instead %u) target coordinates for spell ID %u", st
->target_mapId
, m_caster
->GetMapId(), m_spellInfo
->Id
);
2218 sLog
.outError( "SPELL: unknown target coordinates for spell ID %u", m_spellInfo
->Id
);
2221 case TARGET_INFRONT_OF_VICTIM
:
2222 case TARGET_BEHIND_VICTIM
:
2223 case TARGET_RIGHT_FROM_VICTIM
:
2224 case TARGET_LEFT_FROM_VICTIM
:
2226 Unit
*pTarget
= NULL
;
2228 // explicit cast data from client or server-side cast
2229 // some spell at client send caster
2230 if(m_targets
.getUnitTarget() && m_targets
.getUnitTarget()!=m_caster
)
2231 pTarget
= m_targets
.getUnitTarget();
2232 else if(m_caster
->getVictim())
2233 pTarget
= m_caster
->getVictim();
2234 else if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
2235 pTarget
= ObjectAccessor::GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection());
2240 float dist
= (radius
&& targetMode
!= TARGET_BEHIND_VICTIM
) ? radius
: CONTACT_DISTANCE
;
2244 case TARGET_INFRONT_OF_VICTIM
: break;
2245 case TARGET_BEHIND_VICTIM
: angle
= M_PI_F
; break;
2246 case TARGET_RIGHT_FROM_VICTIM
: angle
= -M_PI_F
/ 2; break;
2247 case TARGET_LEFT_FROM_VICTIM
: angle
= M_PI_F
/ 2; break;
2250 float _target_x
, _target_y
, _target_z
;
2251 pTarget
->GetClosePoint(_target_x
, _target_y
, _target_z
, pTarget
->GetObjectSize(), dist
, angle
);
2252 if(pTarget
->IsWithinLOS(_target_x
, _target_y
, _target_z
))
2254 targetUnitMap
.push_back(m_caster
);
2255 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2260 case TARGET_DYNAMIC_OBJECT_COORDINATES
:
2261 // if parent spell create dynamic object extract area from it
2262 if(DynamicObject
* dynObj
= m_caster
->GetDynObject(m_triggeredByAuraSpell
? m_triggeredByAuraSpell
->Id
: m_spellInfo
->Id
))
2263 m_targets
.setDestination(dynObj
->GetPositionX(), dynObj
->GetPositionY(), dynObj
->GetPositionZ());
2266 case TARGET_DYNAMIC_OBJECT_FRONT
:
2267 case TARGET_DYNAMIC_OBJECT_BEHIND
:
2268 case TARGET_DYNAMIC_OBJECT_LEFT_SIDE
:
2269 case TARGET_DYNAMIC_OBJECT_RIGHT_SIDE
:
2271 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2273 float angle
= m_caster
->GetOrientation();
2276 case TARGET_DYNAMIC_OBJECT_FRONT
: break;
2277 case TARGET_DYNAMIC_OBJECT_BEHIND
: angle
+= M_PI_F
; break;
2278 case TARGET_DYNAMIC_OBJECT_LEFT_SIDE
: angle
+= M_PI_F
/ 2; break;
2279 case TARGET_DYNAMIC_OBJECT_RIGHT_SIDE
: angle
-= M_PI_F
/ 2; break;
2283 m_caster
->GetNearPoint2D(x
, y
, radius
, angle
);
2284 m_targets
.setDestination(x
, y
, m_caster
->GetPositionZ());
2287 targetUnitMap
.push_back(m_caster
);
2290 case TARGET_POINT_AT_NORTH
:
2291 case TARGET_POINT_AT_SOUTH
:
2292 case TARGET_POINT_AT_EAST
:
2293 case TARGET_POINT_AT_WEST
:
2294 case TARGET_POINT_AT_NE
:
2295 case TARGET_POINT_AT_NW
:
2296 case TARGET_POINT_AT_SE
:
2297 case TARGET_POINT_AT_SW
:
2300 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2302 Unit
* currentTarget
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
2303 float angle
= currentTarget
!= m_caster
? currentTarget
->GetAngle(m_caster
) : m_caster
->GetOrientation();
2307 case TARGET_POINT_AT_NORTH
: break;
2308 case TARGET_POINT_AT_SOUTH
: angle
+= M_PI_F
; break;
2309 case TARGET_POINT_AT_EAST
: angle
-= M_PI_F
/ 2; break;
2310 case TARGET_POINT_AT_WEST
: angle
+= M_PI_F
/ 2; break;
2311 case TARGET_POINT_AT_NE
: angle
-= M_PI_F
/ 4; break;
2312 case TARGET_POINT_AT_NW
: angle
+= M_PI_F
/ 4; break;
2313 case TARGET_POINT_AT_SE
: angle
-= 3*M_PI_F
/ 4; break;
2314 case TARGET_POINT_AT_SW
: angle
+= 3*M_PI_F
/ 4; break;
2318 currentTarget
->GetNearPoint2D(x
, y
, radius
, angle
);
2319 m_targets
.setDestination(x
, y
, currentTarget
->GetPositionZ());
2323 case TARGET_DIRECTLY_FORWARD
:
2325 if (!(m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
))
2327 SpellRangeEntry
const* rEntry
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
2328 float minRange
= GetSpellMinRange(rEntry
);
2329 float maxRange
= GetSpellMaxRange(rEntry
);
2330 float dist
= minRange
+ rand_norm_f()*(maxRange
-minRange
);
2332 float _target_x
, _target_y
, _target_z
;
2333 m_caster
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), dist
);
2334 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
2337 targetUnitMap
.push_back(m_caster
);
2340 case TARGET_EFFECT_SELECT
:
2342 // add here custom effects that need default target.
2343 // FOR EVERY TARGET TYPE THERE IS A DIFFERENT FILL!!
2344 switch(m_spellInfo
->Effect
[effIndex
])
2346 case SPELL_EFFECT_DUMMY
:
2348 switch(m_spellInfo
->Id
)
2350 case 20577: // Cannibalize
2352 WorldObject
* result
= FindCorpseUsing
<MaNGOS::CannibalizeObjectCheck
> ();
2356 switch(result
->GetTypeId())
2360 targetUnitMap
.push_back((Unit
*)result
);
2363 m_targets
.setCorpseTarget((Corpse
*)result
);
2364 if (Player
* owner
= ObjectAccessor::FindPlayer(((Corpse
*)result
)->GetOwnerGUID()))
2365 targetUnitMap
.push_back(owner
);
2371 // clear cooldown at fail
2372 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2373 ((Player
*)m_caster
)->RemoveSpellCooldown(m_spellInfo
->Id
, true);
2374 SendCastResult(SPELL_FAILED_NO_EDIBLE_CORPSES
);
2380 if (m_targets
.getUnitTarget())
2381 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2386 case SPELL_EFFECT_BIND
:
2387 case SPELL_EFFECT_RESURRECT
:
2388 case SPELL_EFFECT_PARRY
:
2389 case SPELL_EFFECT_BLOCK
:
2390 case SPELL_EFFECT_CREATE_ITEM
:
2391 case SPELL_EFFECT_TRIGGER_SPELL
:
2392 case SPELL_EFFECT_TRIGGER_MISSILE
:
2393 case SPELL_EFFECT_LEARN_SPELL
:
2394 case SPELL_EFFECT_SKILL_STEP
:
2395 case SPELL_EFFECT_PROFICIENCY
:
2396 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
2397 case SPELL_EFFECT_SELF_RESURRECT
:
2398 case SPELL_EFFECT_REPUTATION
:
2399 case SPELL_EFFECT_SEND_TAXI
:
2400 if (m_targets
.getUnitTarget())
2401 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2402 // Triggered spells have additional spell targets - cast them even if no explicit unit target is given (required for spell 50516 for example)
2403 else if (m_spellInfo
->Effect
[effIndex
] == SPELL_EFFECT_TRIGGER_SPELL
)
2404 targetUnitMap
.push_back(m_caster
);
2406 case SPELL_EFFECT_SUMMON_PLAYER
:
2407 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetSelection())
2409 Player
* target
= sObjectMgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
2411 targetUnitMap
.push_back(target
);
2414 case SPELL_EFFECT_RESURRECT_NEW
:
2415 if (m_targets
.getUnitTarget())
2416 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2417 if (m_targets
.getCorpseTargetGUID())
2419 Corpse
*corpse
= m_caster
->GetMap()->GetCorpse(m_targets
.getCorpseTargetGUID());
2422 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
2424 targetUnitMap
.push_back(owner
);
2428 case SPELL_EFFECT_SUMMON
:
2429 case SPELL_EFFECT_SUMMON_CHANGE_ITEM
:
2430 case SPELL_EFFECT_TRANS_DOOR
:
2431 case SPELL_EFFECT_ADD_FARSIGHT
:
2432 case SPELL_EFFECT_APPLY_GLYPH
:
2433 case SPELL_EFFECT_STUCK
:
2434 case SPELL_EFFECT_BREAK_PLAYER_TARGETING
:
2435 case SPELL_EFFECT_SUMMON_ALL_TOTEMS
:
2436 case SPELL_EFFECT_FEED_PET
:
2437 case SPELL_EFFECT_DESTROY_ALL_TOTEMS
:
2438 case SPELL_EFFECT_SKILL
:
2439 targetUnitMap
.push_back(m_caster
);
2441 case SPELL_EFFECT_LEARN_PET_SPELL
:
2442 if (Pet
* pet
= m_caster
->GetPet())
2443 targetUnitMap
.push_back(pet
);
2445 case SPELL_EFFECT_ENCHANT_ITEM
:
2446 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
2447 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
2448 case SPELL_EFFECT_DISENCHANT
:
2449 case SPELL_EFFECT_PROSPECTING
:
2450 case SPELL_EFFECT_MILLING
:
2451 if (m_targets
.getItemTarget())
2452 AddItemTarget(m_targets
.getItemTarget(), effIndex
);
2454 case SPELL_EFFECT_APPLY_AURA
:
2455 switch(m_spellInfo
->EffectApplyAuraName
[effIndex
])
2457 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)
2458 case SPELL_AURA_ADD_PCT_MODIFIER
:
2459 targetUnitMap
.push_back(m_caster
);
2461 default: // apply to target in other case
2462 if (m_targets
.getUnitTarget())
2463 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2467 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY
:
2469 if(m_spellInfo
->Attributes
== 0x9050000 || m_spellInfo
->Attributes
== 0x10000)
2470 SetTargetMap(effIndex
, TARGET_AREAEFFECT_PARTY
, targetUnitMap
);
2472 case SPELL_EFFECT_SKIN_PLAYER_CORPSE
:
2473 if (m_targets
.getUnitTarget())
2474 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2475 else if (m_targets
.getCorpseTargetGUID())
2477 if (Corpse
*corpse
= m_caster
->GetMap()->GetCorpse(m_targets
.getCorpseTargetGUID()))
2478 if (Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID()))
2479 targetUnitMap
.push_back(owner
);
2489 //sLog.outError( "SPELL: Unknown implicit target (%u) for spell ID %u", targetMode, m_spellInfo->Id );
2493 if (unMaxTargets
&& targetUnitMap
.size() > unMaxTargets
)
2495 // make sure one unit is always removed per iteration
2496 uint32 removed_utarget
= 0;
2497 for (UnitList::iterator itr
= targetUnitMap
.begin(), next
; itr
!= targetUnitMap
.end(); itr
= next
)
2501 if (!*itr
) continue;
2502 if ((*itr
) == m_targets
.getUnitTarget())
2504 targetUnitMap
.erase(itr
);
2505 removed_utarget
= 1;
2509 // remove random units from the map
2510 while (targetUnitMap
.size() > unMaxTargets
- removed_utarget
)
2512 uint32 poz
= urand(0, targetUnitMap
.size()-1);
2513 for (UnitList::iterator itr
= targetUnitMap
.begin(); itr
!= targetUnitMap
.end(); ++itr
, --poz
)
2515 if (!*itr
) continue;
2519 targetUnitMap
.erase(itr
);
2524 // the player's target will always be added to the map
2525 if (removed_utarget
&& m_targets
.getUnitTarget())
2526 targetUnitMap
.push_back(m_targets
.getUnitTarget());
2530 void Spell::prepare(SpellCastTargets
const* targets
, Aura
* triggeredByAura
)
2532 m_targets
= *targets
;
2534 m_spellState
= SPELL_STATE_PREPARING
;
2536 m_castPositionX
= m_caster
->GetPositionX();
2537 m_castPositionY
= m_caster
->GetPositionY();
2538 m_castPositionZ
= m_caster
->GetPositionZ();
2539 m_castOrientation
= m_caster
->GetOrientation();
2542 m_triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
2544 // create and add update event for this spell
2545 SpellEvent
* Event
= new SpellEvent(this);
2546 m_caster
->m_Events
.AddEvent(Event
, m_caster
->m_Events
.CalculateTime(1));
2548 //Prevent casting at cast another spell (ServerSide check)
2549 if(m_caster
->IsNonMeleeSpellCasted(false, true, true) && m_cast_count
)
2551 SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS
);
2557 m_powerCost
= CalculatePowerCost();
2559 SpellCastResult result
= CheckCast(true);
2560 if(result
!= SPELL_CAST_OK
&& !IsAutoRepeat()) //always cast autorepeat dummy for triggering
2564 SendChannelUpdate(0);
2565 triggeredByAura
->SetAuraDuration(0);
2567 SendCastResult(result
);
2572 // Prepare data for triggers
2573 prepareDataForTriggerSystem();
2575 // calculate cast time (calculated after first CheckCast check to prevent charge counting for first CheckCast fail)
2576 m_casttime
= GetSpellCastTime(m_spellInfo
, this);
2578 // set timer base at cast time
2581 // stealth must be removed at cast starting (at show channel bar)
2582 // skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
2583 if ( !m_IsTriggeredSpell
&& isSpellBreakStealth(m_spellInfo
) )
2585 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
2586 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
2589 // add non-triggered (with cast time and without)
2590 if (!m_IsTriggeredSpell
)
2592 // add to cast type slot
2593 m_caster
->SetCurrentCastedSpell( this );
2595 // will show cast bar
2598 // execute triggered without cast time explicitly in call point
2599 else if(m_timer
== 0)
2601 // else triggered with cast time will execute execute at next tick or later
2602 // without adding to cast type slot
2603 // will not show cast bar but will show effects at casting time etc
2606 void Spell::cancel()
2608 if(m_spellState
== SPELL_STATE_FINISHED
)
2611 m_autoRepeat
= false;
2612 switch (m_spellState
)
2614 case SPELL_STATE_PREPARING
:
2615 case SPELL_STATE_DELAYED
:
2618 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2621 case SPELL_STATE_CASTING
:
2623 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2625 if( ihit
->missCondition
== SPELL_MISS_NONE
)
2627 Unit
* unit
= m_caster
->GetObjectGuid() == (*ihit
).targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2628 if( unit
&& unit
->isAlive() )
2629 unit
->RemoveAurasByCasterSpell(m_spellInfo
->Id
, m_caster
->GetGUID());
2633 SendChannelUpdate(0);
2635 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2644 m_caster
->RemoveDynObject(m_spellInfo
->Id
);
2645 m_caster
->RemoveGameObject(m_spellInfo
->Id
, true);
2648 void Spell::cast(bool skipCheck
)
2650 SetExecutedCurrently(true);
2652 if (!m_caster
->CheckAndIncreaseCastCounter())
2654 if (m_triggeredByAuraSpell
)
2655 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
);
2657 sLog
.outError("Spell %u too deep in cast chain for cast. Cast not allowed for prevent overflow stack crash.", m_spellInfo
->Id
);
2659 SendCastResult(SPELL_FAILED_ERROR
);
2661 SetExecutedCurrently(false);
2665 // update pointers base at GUIDs to prevent access to non-existed already object
2668 // cancel at lost main target unit
2669 if(!m_targets
.getUnitTarget() && m_targets
.getUnitTargetGUID() && m_targets
.getUnitTargetGUID() != m_caster
->GetGUID())
2672 m_caster
->DecreaseCastCounter();
2673 SetExecutedCurrently(false);
2677 if(m_caster
->GetTypeId() != TYPEID_PLAYER
&& m_targets
.getUnitTarget() && m_targets
.getUnitTarget() != m_caster
)
2678 m_caster
->SetInFront(m_targets
.getUnitTarget());
2680 SpellCastResult castResult
= CheckPower();
2681 if(castResult
!= SPELL_CAST_OK
)
2683 SendCastResult(castResult
);
2685 m_caster
->DecreaseCastCounter();
2686 SetExecutedCurrently(false);
2690 // triggered cast called from Spell::prepare where it was already checked
2693 castResult
= CheckCast(false);
2694 if(castResult
!= SPELL_CAST_OK
)
2696 SendCastResult(castResult
);
2698 m_caster
->DecreaseCastCounter();
2699 SetExecutedCurrently(false);
2704 // different triggred (for caster) and precast (casted before apply effect to target) cases
2705 switch(m_spellInfo
->SpellFamilyName
)
2707 case SPELLFAMILY_GENERIC
:
2709 if (m_spellInfo
->Mechanic
== MECHANIC_BANDAGE
) // Bandages
2710 AddPrecastSpell(11196); // Recently Bandaged
2711 else if(m_spellInfo
->Id
== 20594) // Stoneskin
2712 AddTriggeredSpell(65116); // Stoneskin - armor 10% for 8 sec
2713 else if(m_spellInfo
->Id
== 71904) // Chaos Bane strength buff
2714 AddTriggeredSpell(73422);
2717 case SPELLFAMILY_MAGE
:
2720 if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000008000000000))
2721 AddPrecastSpell(41425); // Hypothermia
2724 case SPELLFAMILY_PRIEST
:
2726 // Power Word: Shield
2727 if (m_spellInfo
->Mechanic
== MECHANIC_SHIELD
&&
2728 (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000000001)))
2729 AddPrecastSpell(6788); // Weakened Soul
2730 // Prayer of Mending (jump animation), we need formal caster instead original for correct animation
2731 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000002000000000))
2732 AddTriggeredSpell(41637);
2734 switch(m_spellInfo
->Id
)
2736 case 15237: AddTriggeredSpell(23455); break;// Holy Nova, rank 1
2737 case 15430: AddTriggeredSpell(23458); break;// Holy Nova, rank 2
2738 case 15431: AddTriggeredSpell(23459); break;// Holy Nova, rank 3
2739 case 27799: AddTriggeredSpell(27803); break;// Holy Nova, rank 4
2740 case 27800: AddTriggeredSpell(27804); break;// Holy Nova, rank 5
2741 case 27801: AddTriggeredSpell(27805); break;// Holy Nova, rank 6
2742 case 25331: AddTriggeredSpell(25329); break;// Holy Nova, rank 7
2743 case 48077: AddTriggeredSpell(48075); break;// Holy Nova, rank 8
2744 case 48078: AddTriggeredSpell(48076); break;// Holy Nova, rank 9
2749 case SPELLFAMILY_DRUID
:
2751 // Faerie Fire (Feral)
2752 if (m_spellInfo
->Id
== 16857 && m_caster
->m_form
!= FORM_CAT
)
2753 AddTriggeredSpell(60089);
2756 case SPELLFAMILY_ROGUE
:
2757 // Fan of Knives (main hand)
2758 if (m_spellInfo
->Id
== 51723 && m_caster
->GetTypeId() == TYPEID_PLAYER
&&
2759 ((Player
*)m_caster
)->haveOffhandWeapon())
2761 AddTriggeredSpell(52874); // Fan of Knives (offhand)
2764 case SPELLFAMILY_PALADIN
:
2766 // Hand of Reckoning
2767 if (m_spellInfo
->Id
== 62124)
2769 if (m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->getVictim() != m_caster
)
2770 AddPrecastSpell(67485); // Hand of Rekoning (no typos in name ;) )
2772 // Divine Shield, Divine Protection or Hand of Protection
2773 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000000400080))
2775 AddPrecastSpell(25771); // Forbearance
2776 AddPrecastSpell(61987); // Avenging Wrath Marker
2778 else if (m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x200000000000))
2779 AddPrecastSpell(61987); // Avenging Wrath Marker
2782 case SPELLFAMILY_SHAMAN
:
2785 if (m_spellInfo
->Id
== 2825)
2786 AddPrecastSpell(57724); // Sated
2788 else if (m_spellInfo
->Id
== 32182)
2789 AddPrecastSpell(57723); // Exhaustion
2791 else if (m_spellInfo
->Id
== 58875)
2792 AddPrecastSpell(58876);
2793 else if (m_spellInfo
->Effect
[EFFECT_INDEX_0
]==SPELL_EFFECT_APPLY_AREA_AURA_RAID
&& m_spellInfo
->SpellFamilyFlags
& UI64LIT(0x0000000004000000))
2794 // only for main totem spell cast
2795 AddTriggeredSpell(30708); // Totem of Wrath
2802 // traded items have trade slot instead of guid in m_itemTargetGUID
2803 // set to real guid to be sent later to the client
2804 m_targets
.updateTradeSlotItem();
2806 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2808 if (!m_IsTriggeredSpell
&& m_CastItem
)
2809 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM
, m_CastItem
->GetEntry());
2811 ((Player
*)m_caster
)->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL
, m_spellInfo
->Id
);
2816 if(m_spellState
== SPELL_STATE_FINISHED
) // stop cast if spell marked as finish somewhere in FillTargetMap
2818 m_caster
->DecreaseCastCounter();
2819 SetExecutedCurrently(false);
2824 SendSpellCooldown();
2827 TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
2829 SendCastResult(castResult
);
2830 SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2832 InitializeDamageMultipliers();
2834 // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2835 if (m_spellInfo
->speed
> 0.0f
)
2838 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2839 // in case delayed spell remove item at cast delay start
2842 // fill initial spell damage from caster for delayed casted spells
2843 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2844 HandleDelayedSpellLaunch(&(*ihit
));
2846 // Okay, maps created, now prepare flags
2847 m_immediateHandled
= false;
2848 m_spellState
= SPELL_STATE_DELAYED
;
2853 // Immediate spell, no big deal
2857 m_caster
->DecreaseCastCounter();
2858 SetExecutedCurrently(false);
2861 void Spell::handle_immediate()
2863 // start channeling if applicable
2864 if(IsChanneledSpell(m_spellInfo
))
2866 int32 duration
= GetSpellDuration(m_spellInfo
);
2869 // Apply duration mod
2870 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
2871 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_DURATION
, duration
);
2872 m_spellState
= SPELL_STATE_CASTING
;
2873 SendChannelStart(duration
);
2877 // process immediate effects (items, ground, etc.) also initialize some variables
2878 _handle_immediate_phase();
2880 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2881 DoAllEffectOnTarget(&(*ihit
));
2883 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
2884 DoAllEffectOnTarget(&(*ihit
));
2886 // spell is finished, perform some last features of the spell here
2887 _handle_finish_phase();
2889 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2892 if(m_spellState
!= SPELL_STATE_CASTING
)
2893 finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell)
2896 uint64
Spell::handle_delayed(uint64 t_offset
)
2898 uint64 next_time
= 0;
2900 if (!m_immediateHandled
)
2902 _handle_immediate_phase();
2903 m_immediateHandled
= true;
2906 // 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)
2907 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
2909 if (ihit
->processed
== false)
2911 if ( ihit
->timeDelay
<= t_offset
)
2912 DoAllEffectOnTarget(&(*ihit
));
2913 else if( next_time
== 0 || ihit
->timeDelay
< next_time
)
2914 next_time
= ihit
->timeDelay
;
2918 // now recheck gameobject targeting correctness
2919 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end(); ++ighit
)
2921 if (ighit
->processed
== false)
2923 if ( ighit
->timeDelay
<= t_offset
)
2924 DoAllEffectOnTarget(&(*ighit
));
2925 else if( next_time
== 0 || ighit
->timeDelay
< next_time
)
2926 next_time
= ighit
->timeDelay
;
2929 // All targets passed - need finish phase
2932 // spell is finished, perform some last features of the spell here
2933 _handle_finish_phase();
2935 finish(true); // successfully finish spell cast
2937 // return zero, spell is finished now
2942 // spell is unfinished, return next execution time
2947 void Spell::_handle_immediate_phase()
2949 // handle some immediate features of the spell here
2950 HandleThreatSpells(m_spellInfo
->Id
);
2952 m_needSpellLog
= IsNeedSendToClient();
2953 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
2955 if(m_spellInfo
->Effect
[j
] == 0)
2958 // apply Send Event effect to ground in case empty target lists
2959 if( m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
&& !HaveTargetsForEffect(SpellEffectIndex(j
)) )
2961 HandleEffects(NULL
, NULL
, NULL
, SpellEffectIndex(j
));
2965 // Don't do spell log, if is school damage spell
2966 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
|| m_spellInfo
->Effect
[j
] == 0)
2967 m_needSpellLog
= false;
2970 // initialize Diminishing Returns Data
2971 m_diminishLevel
= DIMINISHING_LEVEL_1
;
2972 m_diminishGroup
= DIMINISHING_NONE
;
2975 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin(); ihit
!= m_UniqueItemInfo
.end(); ++ihit
)
2976 DoAllEffectOnTarget(&(*ihit
));
2979 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
2981 // persistent area auras target only the ground
2982 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2983 HandleEffects(NULL
, NULL
, NULL
, SpellEffectIndex(j
));
2987 void Spell::_handle_finish_phase()
2994 void Spell::SendSpellCooldown()
2996 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
2999 Player
* _player
= (Player
*)m_caster
;
3001 // mana/health/etc potions, disabled by client (until combat out as declarate)
3002 if (m_CastItem
&& m_CastItem
->IsPotion())
3004 // need in some way provided data for Spell::finish SendCooldownEvent
3005 _player
->SetLastPotionId(m_CastItem
->GetEntry());
3009 // (1) have infinity cooldown but set at aura apply, (2) passive cooldown at triggering
3010 if(m_spellInfo
->Attributes
& (SPELL_ATTR_DISABLED_WHILE_ACTIVE
| SPELL_ATTR_PASSIVE
))
3013 _player
->AddSpellAndCategoryCooldowns(m_spellInfo
, m_CastItem
? m_CastItem
->GetEntry() : 0, this);
3016 void Spell::update(uint32 difftime
)
3018 // update pointers based at it's GUIDs
3021 if(m_targets
.getUnitTargetGUID() && !m_targets
.getUnitTarget())
3027 // check if the player caster has moved before the spell finished
3028 if ((m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_timer
!= 0) &&
3029 (m_castPositionX
!= m_caster
->GetPositionX() || m_castPositionY
!= m_caster
->GetPositionY() || m_castPositionZ
!= m_caster
->GetPositionZ()) &&
3030 (m_spellInfo
->Effect
[EFFECT_INDEX_0
] != SPELL_EFFECT_STUCK
|| !((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEFLAG_FALLINGFAR
)))
3032 // always cancel for channeled spells
3033 if( m_spellState
== SPELL_STATE_CASTING
)
3035 // don't cancel for melee, autorepeat, triggered and instant spells
3036 else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_MOVEMENT
))
3040 switch(m_spellState
)
3042 case SPELL_STATE_PREPARING
:
3046 if(difftime
>= m_timer
)
3049 m_timer
-= difftime
;
3052 if(m_timer
== 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat())
3055 case SPELL_STATE_CASTING
:
3059 if( m_caster
->GetTypeId() == TYPEID_PLAYER
)
3061 // check if player has jumped before the channeling finished
3062 if(((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEFLAG_FALLING
))
3065 // check for incapacitating player states
3066 if( m_caster
->hasUnitState(UNIT_STAT_CAN_NOT_REACT
))
3069 // check if player has turned if flag is set
3070 if( m_spellInfo
->ChannelInterruptFlags
& CHANNEL_FLAG_TURNING
&& m_castOrientation
!= m_caster
->GetOrientation() )
3074 // check if there are alive targets left
3075 if (!IsAliveUnitPresentInTargetList())
3077 SendChannelUpdate(0);
3081 if(difftime
>= m_timer
)
3084 m_timer
-= difftime
;
3089 SendChannelUpdate(0);
3091 // channeled spell processed independently for quest targeting
3092 // cast at creature (or GO) quest objectives update at successful cast channel finished
3093 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
3094 if( !IsAutoRepeat() && !IsNextMeleeSwingSpell() )
3096 if ( Player
* p
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself() )
3098 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3100 TargetInfo
* target
= &*ihit
;
3101 if(!target
->targetGUID
.IsCreature())
3104 Unit
* unit
= m_caster
->GetObjectGuid() == target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, target
->targetGUID
);
3108 p
->CastedCreatureOrGO(unit
->GetEntry(), unit
->GetObjectGuid(), m_spellInfo
->Id
);
3111 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin(); ihit
!= m_UniqueGOTargetInfo
.end(); ++ihit
)
3113 GOTargetInfo
* target
= &*ihit
;
3115 GameObject
* go
= m_caster
->GetMap()->GetGameObject(target
->targetGUID
);
3119 p
->CastedCreatureOrGO(go
->GetEntry(), go
->GetObjectGuid(), m_spellInfo
->Id
);
3133 void Spell::finish(bool ok
)
3138 if(m_spellState
== SPELL_STATE_FINISHED
)
3141 m_spellState
= SPELL_STATE_FINISHED
;
3143 // other code related only to successfully finished spells
3147 // remove spell mods
3148 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3149 ((Player
*)m_caster
)->RemoveSpellMods(this);
3151 // handle SPELL_AURA_ADD_TARGET_TRIGGER auras
3152 Unit::AuraList
const& targetTriggers
= m_caster
->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER
);
3153 for(Unit::AuraList::const_iterator i
= targetTriggers
.begin(); i
!= targetTriggers
.end(); ++i
)
3155 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
3157 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3159 if( ihit
->missCondition
== SPELL_MISS_NONE
)
3161 // check m_caster->GetGUID() let load auras at login and speedup most often case
3162 Unit
*unit
= m_caster
->GetObjectGuid() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
3163 if (unit
&& unit
->isAlive())
3165 SpellEntry
const *auraSpellInfo
= (*i
)->GetSpellProto();
3166 SpellEffectIndex auraSpellIdx
= (*i
)->GetEffIndex();
3167 // Calculate chance at that moment (can be depend for example from combo points)
3168 int32 auraBasePoints
= (*i
)->GetBasePoints();
3169 int32 chance
= m_caster
->CalculateSpellDamage(unit
, auraSpellInfo
, auraSpellIdx
, &auraBasePoints
);
3170 if(roll_chance_i(chance
))
3171 m_caster
->CastSpell(unit
, auraSpellInfo
->EffectTriggerSpell
[auraSpellIdx
], true, NULL
, (*i
));
3177 // Heal caster for all health leech from all targets
3179 m_caster
->DealHeal(m_caster
, uint32(m_healthLeech
), m_spellInfo
);
3181 if (IsMeleeAttackResetSpell())
3183 m_caster
->resetAttackTimer(BASE_ATTACK
);
3184 if(m_caster
->haveOffhandWeapon())
3185 m_caster
->resetAttackTimer(OFF_ATTACK
);
3188 /*if (IsRangedAttackResetSpell())
3189 m_caster->resetAttackTimer(RANGED_ATTACK);*/
3191 // Clear combo at finish state
3192 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& NeedsComboPoints(m_spellInfo
))
3194 // Not drop combopoints if negative spell and if any miss on enemy exist
3195 bool needDrop
= true;
3196 if (!IsPositiveSpell(m_spellInfo
->Id
))
3198 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3200 if (ihit
->missCondition
!= SPELL_MISS_NONE
&& ihit
->targetGUID
!= m_caster
->GetObjectGuid())
3208 ((Player
*)m_caster
)->ClearComboPoints();
3211 // potions disabled by client, send event "not in combat" if need
3212 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3213 ((Player
*)m_caster
)->UpdatePotionCooldown(this);
3215 // call triggered spell only at successful cast (after clear combo points -> for add some if need)
3216 if(!m_TriggerSpells
.empty())
3217 CastTriggerSpells();
3219 // Stop Attack for some spells
3220 if( m_spellInfo
->Attributes
& SPELL_ATTR_STOP_ATTACK_TARGET
)
3221 m_caster
->AttackStop();
3224 void Spell::SendCastResult(SpellCastResult result
)
3226 if(result
== SPELL_CAST_OK
)
3229 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3232 if(((Player
*)m_caster
)->GetSession()->PlayerLoading()) // don't send cast results at loading time
3235 SendCastResult((Player
*)m_caster
, m_spellInfo
, m_cast_count
, result
);
3238 void Spell::SendCastResult(Player
* caster
, SpellEntry
const* spellInfo
, uint8 cast_count
, SpellCastResult result
)
3240 if(result
== SPELL_CAST_OK
)
3243 WorldPacket
data(SMSG_CAST_FAILED
, (4+1+1));
3244 data
<< uint8(cast_count
); // single cast or multi 2.3 (0/1)
3245 data
<< uint32(spellInfo
->Id
);
3246 data
<< uint8(result
); // problem
3249 case SPELL_FAILED_REQUIRES_SPELL_FOCUS
:
3250 data
<< uint32(spellInfo
->RequiresSpellFocus
);
3252 case SPELL_FAILED_REQUIRES_AREA
:
3253 // hardcode areas limitation case
3254 switch(spellInfo
->Id
)
3256 case 41617: // Cenarion Mana Salve
3257 case 41619: // Cenarion Healing Salve
3258 data
<< uint32(3905);
3260 case 41618: // Bottled Nethergon Energy
3261 case 41620: // Bottled Nethergon Vapor
3262 data
<< uint32(3842);
3264 case 45373: // Bloodberry Elixir
3265 data
<< uint32(4075);
3267 default: // default case (don't must be)
3272 case SPELL_FAILED_TOTEMS
:
3273 for(int i
= 0; i
< MAX_SPELL_TOTEMS
; ++i
)
3274 if(spellInfo
->Totem
[i
])
3275 data
<< uint32(spellInfo
->Totem
[i
]);
3277 case SPELL_FAILED_TOTEM_CATEGORY
:
3278 for(int i
= 0; i
< MAX_SPELL_TOTEM_CATEGORIES
; ++i
)
3279 if(spellInfo
->TotemCategory
[i
])
3280 data
<< uint32(spellInfo
->TotemCategory
[i
]);
3282 case SPELL_FAILED_EQUIPPED_ITEM_CLASS
:
3283 data
<< uint32(spellInfo
->EquippedItemClass
);
3284 data
<< uint32(spellInfo
->EquippedItemSubClassMask
);
3285 //data << uint32(spellInfo->EquippedItemInventoryTypeMask);
3290 caster
->GetSession()->SendPacket(&data
);
3293 void Spell::SendSpellStart()
3295 if (!IsNeedSendToClient())
3298 DEBUG_LOG("Sending SMSG_SPELL_START id=%u", m_spellInfo
->Id
);
3300 uint32 castFlags
= CAST_FLAG_UNKNOWN1
;
3301 if (IsRangedSpell())
3302 castFlags
|= CAST_FLAG_AMMO
;
3304 if (m_spellInfo
->runeCostID
)
3305 castFlags
|= CAST_FLAG_UNKNOWN10
;
3307 WorldPacket
data(SMSG_SPELL_START
, (8+8+4+4+2));
3309 data
<< m_CastItem
->GetPackGUID();
3311 data
<< m_caster
->GetPackGUID();
3313 data
<< m_caster
->GetPackGUID();
3314 data
<< uint8(m_cast_count
); // pending spell cast?
3315 data
<< uint32(m_spellInfo
->Id
); // spellId
3316 data
<< uint32(castFlags
); // cast flags
3317 data
<< uint32(m_timer
); // delay?
3320 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // predicted power?
3323 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
3325 uint8 v1
= 0;//m_runesState;
3326 uint8 v2
= 0;//((Player*)m_caster)->GetRunesState();
3327 data
<< uint8(v1
); // runes state before
3328 data
<< uint8(v2
); // runes state after
3329 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
3332 if(m
& v1
) // usable before...
3333 if(!(m
& v2
)) // ...but on cooldown now...
3334 data
<< uint8(0); // some unknown byte (time?)
3338 if ( castFlags
& CAST_FLAG_AMMO
)
3339 WriteAmmoToPacket(&data
);
3341 if ( castFlags
& CAST_FLAG_UNKNOWN21
)
3347 m_caster
->SendMessageToSet(&data
, true);
3350 void Spell::SendSpellGo()
3352 // not send invisible spell casting
3353 if(!IsNeedSendToClient())
3356 DEBUG_LOG("Sending SMSG_SPELL_GO id=%u", m_spellInfo
->Id
);
3358 uint32 castFlags
= CAST_FLAG_UNKNOWN3
;
3360 castFlags
|= CAST_FLAG_AMMO
; // arrows/bullets visual
3362 if((m_caster
->GetTypeId() == TYPEID_PLAYER
) && (m_caster
->getClass() == CLASS_DEATH_KNIGHT
) && m_spellInfo
->runeCostID
)
3364 castFlags
|= CAST_FLAG_UNKNOWN10
; // same as in SMSG_SPELL_START
3365 castFlags
|= CAST_FLAG_UNKNOWN6
; // makes cooldowns visible
3366 castFlags
|= CAST_FLAG_UNKNOWN7
; // rune cooldowns list
3369 WorldPacket
data(SMSG_SPELL_GO
, 50); // guess size
3372 data
<< m_CastItem
->GetPackGUID();
3374 data
<< m_caster
->GetPackGUID();
3376 data
<< m_caster
->GetPackGUID();
3377 data
<< uint8(m_cast_count
); // pending spell cast?
3378 data
<< uint32(m_spellInfo
->Id
); // spellId
3379 data
<< uint32(castFlags
); // cast flags
3380 data
<< uint32(getMSTime()); // timestamp
3382 WriteSpellGoTargets(&data
);
3386 if ( castFlags
& CAST_FLAG_UNKNOWN6
) // unknown wotlk, predicted power?
3389 if ( castFlags
& CAST_FLAG_UNKNOWN7
) // rune cooldowns list
3391 uint8 v1
= m_runesState
;
3392 uint8 v2
= m_caster
->getClass() == CLASS_DEATH_KNIGHT
? ((Player
*)m_caster
)->GetRunesState() : 0;
3393 data
<< uint8(v1
); // runes state before
3394 data
<< uint8(v2
); // runes state after
3395 for(uint8 i
= 0; i
< MAX_RUNES
; ++i
)
3398 if(m
& v1
) // usable before...
3399 if(!(m
& v2
)) // ...but on cooldown now...
3400 data
<< uint8(0); // some unknown byte (time?)
3404 if ( castFlags
& CAST_FLAG_UNKNOWN4
) // unknown wotlk
3410 if ( castFlags
& CAST_FLAG_AMMO
)
3411 WriteAmmoToPacket(&data
);
3413 if ( castFlags
& CAST_FLAG_UNKNOWN5
) // unknown wotlk
3419 if ( m_targets
.m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
3424 m_caster
->SendMessageToSet(&data
, true);
3427 void Spell::WriteAmmoToPacket( WorldPacket
* data
)
3429 uint32 ammoInventoryType
= 0;
3430 uint32 ammoDisplayID
= 0;
3432 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
3434 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack( RANGED_ATTACK
);
3437 ammoInventoryType
= pItem
->GetProto()->InventoryType
;
3438 if( ammoInventoryType
== INVTYPE_THROWN
)
3439 ammoDisplayID
= pItem
->GetProto()->DisplayInfoID
;
3442 uint32 ammoID
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
3445 ItemPrototype
const *pProto
= ObjectMgr::GetItemPrototype( ammoID
);
3448 ammoDisplayID
= pProto
->DisplayInfoID
;
3449 ammoInventoryType
= pProto
->InventoryType
;
3452 else if(m_caster
->GetDummyAura(46699)) // Requires No Ammo
3454 ammoDisplayID
= 5996; // normal arrow
3455 ammoInventoryType
= INVTYPE_AMMO
;
3462 for (uint8 i
= 0; i
< 3; ++i
)
3464 if(uint32 item_id
= m_caster
->GetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_ID
+ i
))
3466 if(ItemEntry
const * itemEntry
= sItemStore
.LookupEntry(item_id
))
3468 if(itemEntry
->Class
== ITEM_CLASS_WEAPON
)
3470 switch(itemEntry
->SubClass
)
3472 case ITEM_SUBCLASS_WEAPON_THROWN
:
3473 ammoDisplayID
= itemEntry
->DisplayId
;
3474 ammoInventoryType
= itemEntry
->InventoryType
;
3476 case ITEM_SUBCLASS_WEAPON_BOW
:
3477 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
3478 ammoDisplayID
= 5996; // is this need fixing?
3479 ammoInventoryType
= INVTYPE_AMMO
;
3481 case ITEM_SUBCLASS_WEAPON_GUN
:
3482 ammoDisplayID
= 5998; // is this need fixing?
3483 ammoInventoryType
= INVTYPE_AMMO
;
3495 *data
<< uint32(ammoDisplayID
);
3496 *data
<< uint32(ammoInventoryType
);
3499 void Spell::WriteSpellGoTargets( WorldPacket
* data
)
3501 // This function also fill data for channeled spells:
3502 // m_needAliveTargetMask req for stop channeling if one target die
3503 uint32 hit
= m_UniqueGOTargetInfo
.size(); // Always hits on GO
3505 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3507 if ((*ihit
).effectMask
== 0) // No effect apply - all immuned add state
3509 // possibly SPELL_MISS_IMMUNE2 for this??
3510 ihit
->missCondition
= SPELL_MISS_IMMUNE2
;
3513 else if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
3519 *data
<< (uint8
)hit
;
3520 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3522 if ((*ihit
).missCondition
== SPELL_MISS_NONE
) // Add only hits
3524 *data
<< ihit
->targetGUID
;
3525 m_needAliveTargetMask
|=ihit
->effectMask
;
3529 for(std::list
<GOTargetInfo
>::const_iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end(); ++ighit
)
3530 *data
<< ighit
->targetGUID
; // Always hits
3532 *data
<< (uint8
)miss
;
3533 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
3535 if( ihit
->missCondition
!= SPELL_MISS_NONE
) // Add only miss
3537 *data
<< ihit
->targetGUID
;
3538 *data
<< uint8(ihit
->missCondition
);
3539 if( ihit
->missCondition
== SPELL_MISS_REFLECT
)
3540 *data
<< uint8(ihit
->reflectResult
);
3543 // Reset m_needAliveTargetMask for non channeled spell
3544 if(!IsChanneledSpell(m_spellInfo
))
3545 m_needAliveTargetMask
= 0;
3548 void Spell::SendLogExecute()
3550 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
3552 WorldPacket
data(SMSG_SPELLLOGEXECUTE
, (8+4+4+4+4+8));
3554 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
3555 data
<< m_caster
->GetPackGUID();
3557 data
<< target
->GetPackGUID();
3559 data
<< uint32(m_spellInfo
->Id
);
3561 data
<< uint32(count1
); // count1 (effect count?)
3562 for(uint32 i
= 0; i
< count1
; ++i
)
3564 data
<< uint32(m_spellInfo
->Effect
[EFFECT_INDEX_0
]);// spell effect
3566 data
<< uint32(count2
); // count2 (target count?)
3567 for(uint32 j
= 0; j
< count2
; ++j
)
3569 switch(m_spellInfo
->Effect
[EFFECT_INDEX_0
])
3571 case SPELL_EFFECT_POWER_DRAIN
:
3572 if(Unit
*unit
= m_targets
.getUnitTarget())
3573 data
<< unit
->GetPackGUID();
3580 case SPELL_EFFECT_ADD_EXTRA_ATTACKS
:
3581 if(Unit
*unit
= m_targets
.getUnitTarget())
3582 data
<< unit
->GetPackGUID();
3585 data
<< uint32(0); // count?
3587 case SPELL_EFFECT_INTERRUPT_CAST
:
3588 if(Unit
*unit
= m_targets
.getUnitTarget())
3589 data
<< unit
->GetPackGUID();
3592 data
<< uint32(0); // spellid
3594 case SPELL_EFFECT_DURABILITY_DAMAGE
:
3595 if(Unit
*unit
= m_targets
.getUnitTarget())
3596 data
<< unit
->GetPackGUID();
3602 case SPELL_EFFECT_OPEN_LOCK
:
3603 if(Item
*item
= m_targets
.getItemTarget())
3604 data
<< item
->GetPackGUID();
3608 case SPELL_EFFECT_CREATE_ITEM
:
3609 case SPELL_EFFECT_CREATE_ITEM_2
:
3610 data
<< uint32(m_spellInfo
->EffectItemType
[EFFECT_INDEX_0
]);
3612 case SPELL_EFFECT_SUMMON
:
3613 case SPELL_EFFECT_TRANS_DOOR
:
3614 case SPELL_EFFECT_SUMMON_PET
:
3615 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
3616 case SPELL_EFFECT_CREATE_HOUSE
:
3617 case SPELL_EFFECT_DUEL
:
3618 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1
:
3619 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2
:
3620 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3
:
3621 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4
:
3622 if(Unit
*unit
= m_targets
.getUnitTarget())
3623 data
<< unit
->GetPackGUID();
3624 else if(m_targets
.getItemTargetGUID())
3625 data
.appendPackGUID(m_targets
.getItemTargetGUID());
3626 else if(GameObject
*go
= m_targets
.getGOTarget())
3627 data
<< go
->GetPackGUID();
3629 data
<< uint8(0); // guid
3631 case SPELL_EFFECT_FEED_PET
:
3632 data
<< uint32(m_targets
.getItemTargetEntry());
3634 case SPELL_EFFECT_DISMISS_PET
:
3635 if(Unit
*unit
= m_targets
.getUnitTarget())
3636 data
<< unit
->GetPackGUID();
3640 case SPELL_EFFECT_RESURRECT
:
3641 case SPELL_EFFECT_RESURRECT_NEW
:
3642 if(Unit
*unit
= m_targets
.getUnitTarget())
3643 data
<< unit
->GetPackGUID();
3653 m_caster
->SendMessageToSet(&data
, true);
3656 void Spell::SendInterrupted(uint8 result
)
3658 WorldPacket
data(SMSG_SPELL_FAILURE
, (8+4+1));
3659 data
<< m_caster
->GetPackGUID();
3660 data
<< uint8(m_cast_count
);
3661 data
<< uint32(m_spellInfo
->Id
);
3662 data
<< uint8(result
);
3663 m_caster
->SendMessageToSet(&data
, true);
3665 data
.Initialize(SMSG_SPELL_FAILED_OTHER
, (8+4));
3666 data
<< m_caster
->GetPackGUID();
3667 data
<< uint8(m_cast_count
);
3668 data
<< uint32(m_spellInfo
->Id
);
3669 data
<< uint8(result
);
3670 m_caster
->SendMessageToSet(&data
, true);
3673 void Spell::SendChannelUpdate(uint32 time
)
3677 m_caster
->RemoveAurasByCasterSpell(m_spellInfo
->Id
, m_caster
->GetGUID());
3679 ObjectGuid target_guid
= m_caster
->GetChannelObjectGUID();
3680 if (target_guid
!= m_caster
->GetObjectGuid() && target_guid
.IsUnit())
3681 if (Unit
* target
= ObjectAccessor::GetUnit(*m_caster
, target_guid
))
3682 target
->RemoveAurasByCasterSpell(m_spellInfo
->Id
, m_caster
->GetGUID());
3684 m_caster
->SetChannelObjectGUID(0);
3685 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, 0);
3688 WorldPacket
data( MSG_CHANNEL_UPDATE
, 8+4 );
3689 data
<< m_caster
->GetPackGUID();
3690 data
<< uint32(time
);
3691 m_caster
->SendMessageToSet(&data
, true);
3694 void Spell::SendChannelStart(uint32 duration
)
3696 WorldObject
* target
= NULL
;
3698 // select first not resisted target from target list for _0_ effect
3699 if(!m_UniqueTargetInfo
.empty())
3701 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin(); itr
!= m_UniqueTargetInfo
.end(); ++itr
)
3703 if( (itr
->effectMask
& (1 << 0)) && itr
->reflectResult
== SPELL_MISS_NONE
&& itr
->targetGUID
!= m_caster
->GetObjectGuid())
3705 target
= ObjectAccessor::GetUnit(*m_caster
, itr
->targetGUID
);
3710 else if(!m_UniqueGOTargetInfo
.empty())
3712 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin(); itr
!= m_UniqueGOTargetInfo
.end(); ++itr
)
3714 if(itr
->effectMask
& (1 << 0) )
3716 target
= m_caster
->GetMap()->GetGameObject(itr
->targetGUID
);
3722 WorldPacket
data( MSG_CHANNEL_START
, (8+4+4) );
3723 data
<< m_caster
->GetPackGUID();
3724 data
<< uint32(m_spellInfo
->Id
);
3725 data
<< uint32(duration
);
3726 m_caster
->SendMessageToSet(&data
, true);
3731 m_caster
->SetChannelObjectGUID(target
->GetGUID());
3733 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, m_spellInfo
->Id
);
3736 void Spell::SendResurrectRequest(Player
* target
)
3738 // Both players and NPCs can resurrect using spells - have a look at creature 28487 for example
3739 // However, the packet structure differs slightly
3741 const char* sentName
= m_caster
->GetTypeId() == TYPEID_PLAYER
? "" : m_caster
->GetNameForLocaleIdx(target
->GetSession()->GetSessionDbLocaleIndex());
3743 WorldPacket
data(SMSG_RESURRECT_REQUEST
, (8+4+strlen(sentName
)+1+1+1));
3744 data
<< uint64(m_caster
->GetGUID());
3745 data
<< uint32(strlen(sentName
) + 1);
3750 data
<< uint8(m_caster
->GetTypeId() == TYPEID_PLAYER
? 0 : 1);
3751 target
->GetSession()->SendPacket(&data
);
3754 void Spell::SendPlaySpellVisual(uint32 SpellID
)
3756 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3759 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 8 + 4);
3760 data
<< uint64(m_caster
->GetGUID());
3761 data
<< uint32(SpellID
); // spell visual id?
3762 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
3765 void Spell::TakeCastItem()
3767 if(!m_CastItem
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
3770 // not remove cast item at triggered spell (equipping, weapon damage, etc)
3771 if(m_IsTriggeredSpell
)
3774 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3778 // This code is to avoid a crash
3779 // I'm not sure, if this is really an error, but I guess every item needs a prototype
3780 sLog
.outError("Cast item (%s) has no item prototype", m_CastItem
->GetObjectGuid().GetString().c_str());
3784 bool expendable
= false;
3785 bool withoutCharges
= false;
3787 for (int i
= 0; i
< MAX_ITEM_PROTO_SPELLS
; ++i
)
3789 if (proto
->Spells
[i
].SpellId
)
3791 // item has limited charges
3792 if (proto
->Spells
[i
].SpellCharges
)
3794 if (proto
->Spells
[i
].SpellCharges
< 0 && !(proto
->ExtraFlags
& ITEM_EXTRA_NON_CONSUMABLE
))
3797 int32 charges
= m_CastItem
->GetSpellCharges(i
);
3799 // item has charges left
3802 (charges
> 0) ? --charges
: ++charges
; // abs(charges) less at 1 after use
3803 if (proto
->Stackable
== 1)
3804 m_CastItem
->SetSpellCharges(i
, charges
);
3805 m_CastItem
->SetState(ITEM_CHANGED
, (Player
*)m_caster
);
3809 withoutCharges
= (charges
== 0);
3814 if (expendable
&& withoutCharges
)
3817 ((Player
*)m_caster
)->DestroyItemCount(m_CastItem
, count
, true);
3819 // prevent crash at access to deleted m_targets.getItemTarget
3820 if(m_CastItem
== m_targets
.getItemTarget())
3821 m_targets
.setItemTarget(NULL
);
3827 void Spell::TakePower()
3829 if(m_CastItem
|| m_triggeredByAuraSpell
)
3832 // health as power used
3833 if(m_spellInfo
->powerType
== POWER_HEALTH
)
3835 m_caster
->ModifyHealth( -(int32
)m_powerCost
);
3839 if(m_spellInfo
->powerType
>= MAX_POWERS
)
3841 sLog
.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo
->powerType
);
3845 Powers powerType
= Powers(m_spellInfo
->powerType
);
3847 if(powerType
== POWER_RUNE
)
3849 CheckOrTakeRunePower(true);
3853 m_caster
->ModifyPower(powerType
, -(int32
)m_powerCost
);
3855 // Set the five second timer
3856 if (powerType
== POWER_MANA
&& m_powerCost
> 0)
3857 m_caster
->SetLastManaUse();
3860 SpellCastResult
Spell::CheckOrTakeRunePower(bool take
)
3862 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
3863 return SPELL_CAST_OK
;
3865 Player
*plr
= (Player
*)m_caster
;
3867 if(plr
->getClass() != CLASS_DEATH_KNIGHT
)
3868 return SPELL_CAST_OK
;
3870 SpellRuneCostEntry
const *src
= sSpellRuneCostStore
.LookupEntry(m_spellInfo
->runeCostID
);
3873 return SPELL_CAST_OK
;
3875 if(src
->NoRuneCost() && (!take
|| src
->NoRunicPowerGain()))
3876 return SPELL_CAST_OK
;
3879 m_runesState
= plr
->GetRunesState(); // store previous state
3881 // at this moment for rune cost exist only no cost mods, and no percent mods
3882 int32 runeCostMod
= 10000;
3883 if(Player
* modOwner
= plr
->GetSpellModOwner())
3884 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, runeCostMod
, this);
3886 if (runeCostMod
> 0)
3888 int32 runeCost
[NUM_RUNE_TYPES
]; // blood, frost, unholy, death
3890 // init cost data and apply mods
3891 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3892 runeCost
[i
] = runeCostMod
> 0 ? src
->RuneCost
[i
] : 0;
3894 runeCost
[RUNE_DEATH
] = 0; // calculated later
3896 // scan non-death runes (death rune not used explicitly in rune costs)
3897 for(uint32 i
= 0; i
< MAX_RUNES
; ++i
)
3899 RuneType rune
= plr
->GetCurrentRune(i
);
3900 if (runeCost
[rune
] <= 0)
3904 if(plr
->GetRuneCooldown(i
) != 0)
3908 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3913 // collect all not counted rune costs to death runes cost
3914 for(uint32 i
= 0; i
< RUNE_DEATH
; ++i
)
3916 runeCost
[RUNE_DEATH
] += runeCost
[i
];
3919 if(runeCost
[RUNE_DEATH
] > 0)
3921 for(uint32 i
= 0; i
< MAX_RUNES
&& runeCost
[RUNE_DEATH
]; ++i
)
3923 RuneType rune
= plr
->GetCurrentRune(i
);
3924 if (rune
!= RUNE_DEATH
)
3928 if(plr
->GetRuneCooldown(i
) != 0)
3932 plr
->SetRuneCooldown(i
, RUNE_COOLDOWN
); // 5*2=10 sec
3937 plr
->ConvertRune(i
, plr
->GetBaseRune(i
));
3941 if(!take
&& runeCost
[RUNE_DEATH
] > 0)
3942 return SPELL_FAILED_NO_POWER
; // not sure if result code is correct
3947 // you can gain some runic power when use runes
3948 float rp
= float(src
->runePowerGain
);
3949 rp
*= sWorld
.getConfig(CONFIG_FLOAT_RATE_POWER_RUNICPOWER_INCOME
);
3950 plr
->ModifyPower(POWER_RUNIC_POWER
, (int32
)rp
);
3953 return SPELL_CAST_OK
;
3956 void Spell::TakeReagents()
3958 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3961 if (IgnoreItemRequirements()) // reagents used in triggered spell removed by original spell or don't must be removed.
3964 Player
* p_caster
= (Player
*)m_caster
;
3965 if (p_caster
->CanNoReagentCast(m_spellInfo
) )
3968 for(uint32 x
= 0; x
< MAX_SPELL_REAGENTS
; ++x
)
3970 if(m_spellInfo
->Reagent
[x
] <= 0)
3973 uint32 itemid
= m_spellInfo
->Reagent
[x
];
3974 uint32 itemcount
= m_spellInfo
->ReagentCount
[x
];
3976 // if CastItem is also spell reagent
3979 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3980 if( proto
&& proto
->ItemId
== itemid
)
3982 for(int s
= 0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
3984 // CastItem will be used up and does not count as reagent
3985 int32 charges
= m_CastItem
->GetSpellCharges(s
);
3986 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
3997 // if getItemTarget is also spell reagent
3998 if (m_targets
.getItemTargetEntry() == itemid
)
3999 m_targets
.setItemTarget(NULL
);
4001 p_caster
->DestroyItemCount(itemid
, itemcount
, true);
4005 void Spell::HandleThreatSpells(uint32 spellId
)
4007 if(!m_targets
.getUnitTarget() || !spellId
)
4010 if(!m_targets
.getUnitTarget()->CanHaveThreatList())
4013 uint16 threat
= sSpellMgr
.GetSpellThreat(spellId
);
4018 m_targets
.getUnitTarget()->AddThreat(m_caster
, float(threat
), false, GetSpellSchoolMask(m_spellInfo
), m_spellInfo
);
4020 DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId
, sSpellMgr
.GetSpellRank(spellId
), threat
);
4023 void Spell::HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,SpellEffectIndex i
, float DamageMultiplier
)
4025 unitTarget
= pUnitTarget
;
4026 itemTarget
= pItemTarget
;
4027 gameObjTarget
= pGOTarget
;
4029 uint8 eff
= m_spellInfo
->Effect
[i
];
4031 damage
= int32(CalculateDamage(i
, unitTarget
) * DamageMultiplier
);
4033 DEBUG_LOG("Spell %u Effect%d : %u", m_spellInfo
->Id
, i
, eff
);
4035 if(eff
< TOTAL_SPELL_EFFECTS
)
4037 //DEBUG_LOG( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff);
4038 (*this.*SpellEffects
[eff
])(i
);
4042 sLog
.outError("WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff
);
4046 void Spell::AddTriggeredSpell( uint32 spellId
)
4048 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
4052 sLog
.outError("Spell::AddTriggeredSpell: unknown spell id %u used as triggred spell for spell %u)", spellId
, m_spellInfo
->Id
);
4056 m_TriggerSpells
.push_back(spellInfo
);
4059 void Spell::AddPrecastSpell( uint32 spellId
)
4061 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(spellId
);
4065 sLog
.outError("Spell::AddPrecastSpell: unknown spell id %u used as pre-cast spell for spell %u)", spellId
, m_spellInfo
->Id
);
4069 m_preCastSpells
.push_back(spellInfo
);
4072 void Spell::CastTriggerSpells()
4074 for(SpellInfoList::const_iterator si
= m_TriggerSpells
.begin(); si
!= m_TriggerSpells
.end(); ++si
)
4076 Spell
* spell
= new Spell(m_caster
, (*si
), true, m_originalCasterGUID
, m_selfContainer
);
4077 spell
->prepare(&m_targets
); // use original spell original targets
4081 void Spell::CastPreCastSpells(Unit
* target
)
4083 for(SpellInfoList::const_iterator si
= m_preCastSpells
.begin(); si
!= m_preCastSpells
.end(); ++si
)
4084 m_caster
->CastSpell(target
, (*si
), true, m_CastItem
);
4087 SpellCastResult
Spell::CheckCast(bool strict
)
4089 // check cooldowns to prevent cheating (ignore passive spells, that client side visual only)
4090 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& !(m_spellInfo
->Attributes
& SPELL_ATTR_PASSIVE
) &&
4091 ((Player
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
4093 if(m_triggeredByAuraSpell
)
4094 return SPELL_FAILED_DONT_REPORT
;
4096 return SPELL_FAILED_NOT_READY
;
4099 // only allow triggered spells if at an ended battleground
4100 if( !m_IsTriggeredSpell
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
4101 if(BattleGround
* bg
= ((Player
*)m_caster
)->GetBattleGround())
4102 if(bg
->GetStatus() == STATUS_WAIT_LEAVE
)
4103 return SPELL_FAILED_DONT_REPORT
;
4105 // only check at first call, Stealth auras are already removed at second call
4106 // for now, ignore triggered spells
4107 if( strict
&& !m_IsTriggeredSpell
)
4109 bool checkForm
= true;
4110 // Ignore form req aura
4111 Unit::AuraList
const& ignore
= m_caster
->GetAurasByType(SPELL_AURA_MOD_IGNORE_SHAPESHIFT
);
4112 for(Unit::AuraList::const_iterator i
= ignore
.begin(); i
!= ignore
.end(); ++i
)
4114 if (!(*i
)->isAffectedOnSpell(m_spellInfo
))
4121 // Cannot be used in this stance/form
4122 SpellCastResult shapeError
= GetErrorAtShapeshiftedCast(m_spellInfo
, m_caster
->m_form
);
4123 if(shapeError
!= SPELL_CAST_OK
)
4126 if ((m_spellInfo
->Attributes
& SPELL_ATTR_ONLY_STEALTHED
) && !(m_caster
->HasStealthAura()))
4127 return SPELL_FAILED_ONLY_STEALTHED
;
4131 // caster state requirements
4132 if(m_spellInfo
->CasterAuraState
&& !m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraState
)))
4133 return SPELL_FAILED_CASTER_AURASTATE
;
4134 if(m_spellInfo
->CasterAuraStateNot
&& m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraStateNot
)))
4135 return SPELL_FAILED_CASTER_AURASTATE
;
4137 // Caster aura req check if need
4138 if(m_spellInfo
->casterAuraSpell
&& !m_caster
->HasAura(m_spellInfo
->casterAuraSpell
))
4139 return SPELL_FAILED_CASTER_AURASTATE
;
4140 if(m_spellInfo
->excludeCasterAuraSpell
)
4142 // Special cases of non existing auras handling
4143 if(m_spellInfo
->excludeCasterAuraSpell
== 61988)
4145 // Avenging Wrath Marker
4146 if(m_caster
->HasAura(61987))
4147 return SPELL_FAILED_CASTER_AURASTATE
;
4149 else if(m_caster
->HasAura(m_spellInfo
->excludeCasterAuraSpell
))
4150 return SPELL_FAILED_CASTER_AURASTATE
;
4153 // cancel autorepeat spells if cast start when moving
4154 // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
4155 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)m_caster
)->isMoving() )
4157 // skip stuck spell to allow use it in falling case and apply spell limitations at movement
4158 if( (!((Player
*)m_caster
)->m_movementInfo
.HasMovementFlag(MOVEFLAG_FALLINGFAR
) || m_spellInfo
->Effect
[EFFECT_INDEX_0
] != SPELL_EFFECT_STUCK
) &&
4159 (IsAutoRepeat() || (m_spellInfo
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_NOT_SEATED
) != 0) )
4160 return SPELL_FAILED_MOVING
;
4163 if(Unit
*target
= m_targets
.getUnitTarget())
4165 // target state requirements (not allowed state), apply to self also
4166 if(m_spellInfo
->TargetAuraStateNot
&& target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraStateNot
)))
4167 return SPELL_FAILED_TARGET_AURASTATE
;
4169 if (!m_IsTriggeredSpell
&& IsDeathOnlySpell(m_spellInfo
) && target
->isAlive())
4170 return SPELL_FAILED_TARGET_NOT_DEAD
;
4172 // Target aura req check if need
4173 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
4174 return SPELL_FAILED_CASTER_AURASTATE
;
4175 if(m_spellInfo
->excludeTargetAuraSpell
)
4177 // Special cases of non existing auras handling
4178 if (m_spellInfo
->excludeTargetAuraSpell
== 61988)
4180 // Avenging Wrath Marker
4181 if (target
->HasAura(61987))
4182 return SPELL_FAILED_CASTER_AURASTATE
;
4185 else if (target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
4186 return SPELL_FAILED_CASTER_AURASTATE
;
4189 bool non_caster_target
= target
!= m_caster
&& !IsSpellWithCasterSourceTargetsOnly(m_spellInfo
);
4191 if(non_caster_target
)
4193 // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds
4194 if(m_spellInfo
->TargetAuraState
&& !target
->HasAuraStateForCaster(AuraState(m_spellInfo
->TargetAuraState
),m_caster
->GetGUID()))
4195 return SPELL_FAILED_TARGET_AURASTATE
;
4197 // Not allow casting on flying player
4198 if (target
->isInFlight())
4199 return SPELL_FAILED_BAD_TARGETS
;
4201 if(!m_IsTriggeredSpell
&& VMAP::VMapFactory::checkSpellForLoS(m_spellInfo
->Id
) && !m_caster
->IsWithinLOSInMap(target
))
4202 return SPELL_FAILED_LINE_OF_SIGHT
;
4204 // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode
4205 // this case can be triggered if rank not found (too low-level target for first rank)
4206 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsPassiveSpell(m_spellInfo
->Id
) && !m_CastItem
)
4208 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4210 // check only spell that apply positive auras
4211 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_APPLY_AURA
&&
4212 IsPositiveEffect(m_spellInfo
->Id
, SpellEffectIndex(i
)) &&
4213 // at not self target
4214 !IsCasterSourceTarget(m_spellInfo
->EffectImplicitTargetA
[i
]) &&
4215 // and target low level
4216 target
->getLevel() + 10 < m_spellInfo
->spellLevel
)
4218 return SPELL_FAILED_LOWLEVEL
;
4223 else if (m_caster
== target
)
4226 if (m_caster
->GetTypeId() == TYPEID_PLAYER
) // Target - is player caster
4228 // Additional check for some spells
4229 // If 0 spell effect empty - client not send target data (need use selection)
4230 // TODO: check it on next client version
4231 if (m_targets
.m_targetMask
== TARGET_FLAG_SELF
&&
4232 m_spellInfo
->EffectImplicitTargetA
[EFFECT_INDEX_1
] == TARGET_CHAIN_DAMAGE
)
4234 if (target
= m_caster
->GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection()))
4235 m_targets
.setUnitTarget(target
);
4237 return SPELL_FAILED_BAD_TARGETS
;
4241 // Some special spells with non-caster only mode
4244 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&&
4245 m_spellInfo
->SpellIconID
== 16)
4246 return SPELL_FAILED_BAD_TARGETS
;
4248 // Focus Magic (main spell)
4249 if (m_spellInfo
->Id
== 54646)
4250 return SPELL_FAILED_BAD_TARGETS
;
4253 // check pet presents
4254 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4256 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_PET
)
4258 target
= m_caster
->GetPet();
4261 if(m_triggeredByAuraSpell
) // not report pet not existence for triggered spells
4262 return SPELL_FAILED_DONT_REPORT
;
4264 return SPELL_FAILED_NO_PET
;
4270 //check creature type
4271 //ignore self casts (including area casts when caster selected as target)
4272 if(non_caster_target
)
4274 if(!CheckTargetCreatureType(target
))
4276 if(target
->GetTypeId() == TYPEID_PLAYER
)
4277 return SPELL_FAILED_TARGET_IS_PLAYER
;
4279 return SPELL_FAILED_BAD_TARGETS
;
4283 if(non_caster_target
)
4286 bool explicit_target_mode
= false;
4287 bool target_hostile
= false;
4288 bool target_hostile_checked
= false;
4289 bool target_friendly
= false;
4290 bool target_friendly_checked
= false;
4291 for(int k
= 0; k
< MAX_EFFECT_INDEX
; ++k
)
4293 if (IsExplicitPositiveTarget(m_spellInfo
->EffectImplicitTargetA
[k
]))
4295 if (!target_hostile_checked
)
4297 target_hostile_checked
= true;
4298 target_hostile
= m_caster
->IsHostileTo(target
);
4302 return SPELL_FAILED_BAD_TARGETS
;
4304 explicit_target_mode
= true;
4306 else if (IsExplicitNegativeTarget(m_spellInfo
->EffectImplicitTargetA
[k
]))
4308 if (!target_friendly_checked
)
4310 target_friendly_checked
= true;
4311 target_friendly
= m_caster
->IsFriendlyTo(target
);
4315 return SPELL_FAILED_BAD_TARGETS
;
4317 explicit_target_mode
= true;
4320 // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
4321 // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
4322 if (!explicit_target_mode
&& m_caster
->GetTypeId() == TYPEID_UNIT
&& m_caster
->GetCharmerOrOwnerGUID())
4324 // check correctness positive/negative cast target (pet cast real check and cheating check)
4325 if(IsPositiveSpell(m_spellInfo
->Id
))
4327 if (!target_hostile_checked
)
4329 target_hostile_checked
= true;
4330 target_hostile
= m_caster
->IsHostileTo(target
);
4334 return SPELL_FAILED_BAD_TARGETS
;
4338 if (!target_friendly_checked
)
4340 target_friendly_checked
= true;
4341 target_friendly
= m_caster
->IsFriendlyTo(target
);
4345 return SPELL_FAILED_BAD_TARGETS
;
4350 if(IsPositiveSpell(m_spellInfo
->Id
))
4351 if(target
->IsImmunedToSpell(m_spellInfo
))
4352 return SPELL_FAILED_TARGET_AURASTATE
;
4354 //Must be behind the target.
4355 if( m_spellInfo
->AttributesEx2
== 0x100000 && (m_spellInfo
->AttributesEx
& 0x200) == 0x200 && target
->HasInArc(M_PI_F
, m_caster
) )
4357 // Exclusion for Pounce: Facing Limitation was removed in 2.0.1, but it still uses the same, old Ex-Flags
4358 // Exclusion for Mutilate:Facing Limitation was removed in 2.0.1 and 3.0.3, but they still use the same, old Ex-Flags
4359 // Exclusion for Throw: Facing limitation was added in 3.2.x, but that shouldn't be
4360 if ((m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_DRUID
|| (m_spellInfo
->SpellFamilyFlags
!= UI64LIT(0x0000000000020000))) &&
4361 (m_spellInfo
->SpellFamilyName
!= SPELLFAMILY_ROGUE
|| (m_spellInfo
->SpellFamilyFlags
!= UI64LIT(0x0020000000000000))) &&
4362 m_spellInfo
->Id
!= 2764)
4365 return SPELL_FAILED_NOT_BEHIND
;
4369 //Target must be facing you.
4370 if((m_spellInfo
->Attributes
== 0x150010) && !target
->HasInArc(M_PI_F
, m_caster
) )
4373 return SPELL_FAILED_NOT_INFRONT
;
4376 // check if target is in combat
4377 if (non_caster_target
&& (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET
) && target
->isInCombat())
4378 return SPELL_FAILED_TARGET_AFFECTING_COMBAT
;
4382 m_caster
->GetZoneAndAreaId(zone
, area
);
4384 SpellCastResult locRes
= sSpellMgr
.GetSpellAllowedInLocationError(m_spellInfo
, m_caster
->GetMapId(), zone
, area
,
4385 m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself());
4386 if (locRes
!= SPELL_CAST_OK
)
4389 // not let players cast spells at mount (and let do it to creatures)
4390 if (m_caster
->IsMounted() && m_caster
->GetTypeId()==TYPEID_PLAYER
&& !m_IsTriggeredSpell
&&
4391 !IsPassiveSpell(m_spellInfo
->Id
) && !(m_spellInfo
->Attributes
& SPELL_ATTR_CASTABLE_WHILE_MOUNTED
))
4393 if (m_caster
->isInFlight())
4394 return SPELL_FAILED_NOT_ON_TAXI
;
4396 return SPELL_FAILED_NOT_MOUNTED
;
4399 // always (except passive spells) check items (focus object can be required for any type casts)
4400 if (!IsPassiveSpell(m_spellInfo
->Id
))
4402 SpellCastResult castResult
= CheckItems();
4403 if(castResult
!= SPELL_CAST_OK
)
4407 // Database based targets from spell_target_script
4408 if (m_UniqueTargetInfo
.empty()) // skip second CheckCast apply (for delayed spells for example)
4410 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
4412 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
4413 (m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_SELF
) ||
4414 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4415 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
||
4416 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
)
4419 SpellScriptTargetBounds bounds
= sSpellMgr
.GetSpellScriptTargetBounds(m_spellInfo
->Id
);
4421 if (bounds
.first
== bounds
.second
)
4422 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
);
4424 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4425 float range
= GetSpellMaxRange(srange
);
4427 Creature
* creatureScriptTarget
= NULL
;
4428 GameObject
* goScriptTarget
= NULL
;
4430 for(SpellScriptTarget::const_iterator i_spellST
= bounds
.first
; i_spellST
!= bounds
.second
; ++i_spellST
)
4432 switch(i_spellST
->second
.type
)
4434 case SPELL_TARGET_TYPE_GAMEOBJECT
:
4436 GameObject
* p_GameObject
= NULL
;
4438 if (i_spellST
->second
.targetEntry
)
4440 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*m_caster
, i_spellST
->second
.targetEntry
, range
);
4441 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(m_caster
, p_GameObject
, go_check
);
4442 Cell::VisitGridObjects(m_caster
, checker
, range
);
4446 // remember found target and range, next attempt will find more near target with another entry
4447 creatureScriptTarget
= NULL
;
4448 goScriptTarget
= p_GameObject
;
4449 range
= go_check
.GetLastRange();
4452 else if (focusObject
) // Focus Object
4454 float frange
= m_caster
->GetDistance(focusObject
);
4455 if (range
>= frange
)
4457 creatureScriptTarget
= NULL
;
4458 goScriptTarget
= focusObject
;
4464 case SPELL_TARGET_TYPE_CREATURE
:
4465 case SPELL_TARGET_TYPE_DEAD
:
4468 Creature
*p_Creature
= NULL
;
4470 // check if explicit target is provided and check it up against database valid target entry/state
4471 if (Unit
* pTarget
= m_targets
.getUnitTarget())
4473 if (pTarget
->GetTypeId() == TYPEID_UNIT
&& pTarget
->GetEntry() == i_spellST
->second
.targetEntry
)
4475 if (i_spellST
->second
.type
== SPELL_TARGET_TYPE_DEAD
&& pTarget
->isDead())
4477 if (pTarget
->IsWithinDistInMap(m_caster
, range
))
4478 p_Creature
= (Creature
*)pTarget
;
4480 else if (i_spellST
->second
.type
== SPELL_TARGET_TYPE_CREATURE
&& pTarget
->isAlive())
4482 if (pTarget
->IsWithinDistInMap(m_caster
, range
))
4483 p_Creature
= (Creature
*)pTarget
;
4488 // no target provided or it was not valid, so use closest in range
4491 MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
u_check(*m_caster
, i_spellST
->second
.targetEntry
, i_spellST
->second
.type
!= SPELL_TARGET_TYPE_DEAD
, range
);
4492 MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
> searcher(m_caster
, p_Creature
, u_check
);
4494 Cell::VisitGridObjects(m_caster
, searcher
, range
);
4496 range
= u_check
.GetLastRange();
4501 creatureScriptTarget
= p_Creature
;
4502 goScriptTarget
= NULL
;
4510 if (creatureScriptTarget
)
4512 // store coordinates for TARGET_SCRIPT_COORDINATES
4513 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4514 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4516 m_targets
.setDestination(creatureScriptTarget
->GetPositionX(),creatureScriptTarget
->GetPositionY(),creatureScriptTarget
->GetPositionZ());
4518 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->Effect
[j
] != SPELL_EFFECT_PERSISTENT_AREA_AURA
)
4519 AddUnitTarget(creatureScriptTarget
, SpellEffectIndex(j
));
4521 // store explicit target for TARGET_SCRIPT
4524 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
4525 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
)
4526 AddUnitTarget(creatureScriptTarget
, SpellEffectIndex(j
));
4529 else if (goScriptTarget
)
4531 // store coordinates for TARGET_SCRIPT_COORDINATES
4532 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
4533 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
4535 m_targets
.setDestination(goScriptTarget
->GetPositionX(),goScriptTarget
->GetPositionY(),goScriptTarget
->GetPositionZ());
4537 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->Effect
[j
] != SPELL_EFFECT_PERSISTENT_AREA_AURA
)
4538 AddGOTarget(goScriptTarget
, SpellEffectIndex(j
));
4540 // store explicit target for TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
4543 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
||
4544 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
)
4545 AddGOTarget(goScriptTarget
, SpellEffectIndex(j
));
4548 //Missing DB Entry or targets for this spellEffect.
4551 /* For TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT makes DB targets optional not required for now
4552 * TODO: Makes more research for this target type
4554 if (m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_FOCUS_OR_SCRIPTED_GAMEOBJECT
)
4556 // not report target not existence for triggered spells
4557 if (m_triggeredByAuraSpell
|| m_IsTriggeredSpell
)
4558 return SPELL_FAILED_DONT_REPORT
;
4560 return SPELL_FAILED_BAD_TARGETS
;
4567 if(!m_IsTriggeredSpell
)
4569 SpellCastResult castResult
= CheckRange(strict
);
4570 if(castResult
!= SPELL_CAST_OK
)
4575 SpellCastResult castResult
= CheckPower();
4576 if(castResult
!= SPELL_CAST_OK
)
4580 if(!m_IsTriggeredSpell
) // triggered spell not affected by stun/etc
4582 SpellCastResult castResult
= CheckCasterAuras();
4583 if(castResult
!= SPELL_CAST_OK
)
4587 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4589 // for effects of spells that have only one target
4590 switch(m_spellInfo
->Effect
[i
])
4592 case SPELL_EFFECT_INSTAKILL
:
4594 if(m_spellInfo
->Id
== 48743)
4596 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4597 return SPELL_FAILED_ERROR
;
4599 if (!((Player
*)m_caster
)->GetSelection())
4600 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4601 Pet
* target
= m_caster
->GetMap()->GetPet(((Player
*)m_caster
)->GetSelection());
4604 if (!target
|| target
->isDead())
4605 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4607 if (target
->GetCreatureType() != CREATURE_TYPE_UNDEAD
)
4608 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4610 if (target
->GetOwnerGUID() != m_caster
->GetGUID())
4611 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4613 float dist
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4614 if (!target
->IsWithinDistInMap(m_caster
,dist
))
4615 return SPELL_FAILED_OUT_OF_RANGE
;
4617 // will set in target selection code
4620 case SPELL_EFFECT_DUMMY
:
4622 if(m_spellInfo
->SpellIconID
== 1648) // Execute
4624 if(!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4625 return SPELL_FAILED_BAD_TARGETS
;
4627 else if (m_spellInfo
->Id
== 51582) // Rocket Boots Engaged
4629 if(m_caster
->IsInWater())
4630 return SPELL_FAILED_ONLY_ABOVEWATER
;
4632 else if(m_spellInfo
->SpellIconID
== 156) // Holy Shock
4634 // spell different for friends and enemies
4635 // hart version required facing
4636 if(m_targets
.getUnitTarget() && !m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()) && !m_caster
->HasInArc( M_PI_F
, m_targets
.getUnitTarget() ))
4637 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4640 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_SHAMAN
&& m_spellInfo
->SpellIconID
== 33)
4643 if (!m_caster
->GetTotemGUID(TOTEM_SLOT_FIRE
))
4644 return SPELL_FAILED_TOTEMS
;
4648 case SPELL_EFFECT_SCHOOL_DAMAGE
:
4651 if(m_spellInfo
->SpellVisual
[0] == 7250)
4653 if (!m_targets
.getUnitTarget())
4654 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4656 if(m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
4657 return SPELL_FAILED_BAD_TARGETS
;
4661 case SPELL_EFFECT_TAMECREATURE
:
4663 // Spell can be triggered, we need to check original caster prior to caster
4664 Unit
* caster
= GetAffectiveCaster();
4665 if (!caster
|| caster
->GetTypeId() != TYPEID_PLAYER
||
4666 !m_targets
.getUnitTarget() ||
4667 m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
)
4668 return SPELL_FAILED_BAD_TARGETS
;
4670 Player
* plrCaster
= (Player
*)caster
;
4672 if(plrCaster
->getClass() != CLASS_HUNTER
)
4674 plrCaster
->SendPetTameFailure(PETTAME_UNITSCANTTAME
);
4675 return SPELL_FAILED_DONT_REPORT
;
4678 Creature
* target
= (Creature
*)m_targets
.getUnitTarget();
4680 if(target
->isPet() || target
->isCharmed())
4682 plrCaster
->SendPetTameFailure(PETTAME_CREATUREALREADYOWNED
);
4683 return SPELL_FAILED_DONT_REPORT
;
4686 if (target
->getLevel() > plrCaster
->getLevel())
4688 plrCaster
->SendPetTameFailure(PETTAME_TOOHIGHLEVEL
);
4689 return SPELL_FAILED_DONT_REPORT
;
4692 if (target
->GetCreatureInfo()->IsExotic() && !plrCaster
->CanTameExoticPets())
4694 plrCaster
->SendPetTameFailure(PETTAME_CANTCONTROLEXOTIC
);
4695 return SPELL_FAILED_DONT_REPORT
;
4698 if (!target
->GetCreatureInfo()->isTameable(plrCaster
->CanTameExoticPets()))
4700 plrCaster
->SendPetTameFailure(PETTAME_NOTTAMEABLE
);
4701 return SPELL_FAILED_DONT_REPORT
;
4704 if(plrCaster
->GetPetGUID() || plrCaster
->GetCharmGUID())
4706 plrCaster
->SendPetTameFailure(PETTAME_ANOTHERSUMMONACTIVE
);
4707 return SPELL_FAILED_DONT_REPORT
;
4712 case SPELL_EFFECT_LEARN_SPELL
:
4714 if(m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_PET
)
4717 Pet
* pet
= m_caster
->GetPet();
4720 return SPELL_FAILED_NO_PET
;
4722 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4724 if(!learn_spellproto
)
4725 return SPELL_FAILED_NOT_KNOWN
;
4727 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4728 return SPELL_FAILED_LOWLEVEL
;
4732 case SPELL_EFFECT_LEARN_PET_SPELL
:
4734 Pet
* pet
= m_caster
->GetPet();
4737 return SPELL_FAILED_NO_PET
;
4739 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
4741 if(!learn_spellproto
)
4742 return SPELL_FAILED_NOT_KNOWN
;
4744 if(m_spellInfo
->spellLevel
> pet
->getLevel())
4745 return SPELL_FAILED_LOWLEVEL
;
4749 case SPELL_EFFECT_APPLY_GLYPH
:
4751 uint32 glyphId
= m_spellInfo
->EffectMiscValue
[i
];
4752 if(GlyphPropertiesEntry
const *gp
= sGlyphPropertiesStore
.LookupEntry(glyphId
))
4753 if(m_caster
->HasAura(gp
->SpellId
))
4754 return SPELL_FAILED_UNIQUE_GLYPH
;
4757 case SPELL_EFFECT_FEED_PET
:
4759 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4760 return SPELL_FAILED_BAD_TARGETS
;
4762 Item
* foodItem
= m_targets
.getItemTarget();
4764 return SPELL_FAILED_BAD_TARGETS
;
4766 Pet
* pet
= m_caster
->GetPet();
4769 return SPELL_FAILED_NO_PET
;
4771 if(!pet
->HaveInDiet(foodItem
->GetProto()))
4772 return SPELL_FAILED_WRONG_PET_FOOD
;
4774 if(!pet
->GetCurrentFoodBenefitLevel(foodItem
->GetProto()->ItemLevel
))
4775 return SPELL_FAILED_FOOD_LOWLEVEL
;
4777 if(m_caster
->isInCombat() || pet
->isInCombat())
4778 return SPELL_FAILED_AFFECTING_COMBAT
;
4782 case SPELL_EFFECT_POWER_BURN
:
4783 case SPELL_EFFECT_POWER_DRAIN
:
4785 // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
4786 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4787 if(Unit
* target
= m_targets
.getUnitTarget())
4788 if(target
!= m_caster
&& target
->getPowerType() != m_spellInfo
->EffectMiscValue
[i
])
4789 return SPELL_FAILED_BAD_TARGETS
;
4792 case SPELL_EFFECT_CHARGE
:
4794 if (m_caster
->hasUnitState(UNIT_STAT_ROOT
))
4795 return SPELL_FAILED_ROOTED
;
4799 case SPELL_EFFECT_SKINNING
:
4801 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() != TYPEID_UNIT
)
4802 return SPELL_FAILED_BAD_TARGETS
;
4804 if( !(m_targets
.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS
) & UNIT_FLAG_SKINNABLE
) )
4805 return SPELL_FAILED_TARGET_UNSKINNABLE
;
4807 Creature
* creature
= (Creature
*)m_targets
.getUnitTarget();
4808 if ( creature
->GetCreatureType() != CREATURE_TYPE_CRITTER
&& ( !creature
->lootForBody
|| !creature
->loot
.empty() ) )
4810 return SPELL_FAILED_TARGET_NOT_LOOTED
;
4813 uint32 skill
= creature
->GetCreatureInfo()->GetRequiredLootSkill();
4815 int32 skillValue
= ((Player
*)m_caster
)->GetSkillValue(skill
);
4816 int32 TargetLevel
= m_targets
.getUnitTarget()->getLevel();
4817 int32 ReqValue
= (skillValue
< 100 ? (TargetLevel
-10) * 10 : TargetLevel
* 5);
4818 if (ReqValue
> skillValue
)
4819 return SPELL_FAILED_LOW_CASTLEVEL
;
4821 // chance for fail at orange skinning attempt
4822 if( (m_selfContainer
&& (*m_selfContainer
) == this) &&
4823 skillValue
< sWorld
.GetConfigMaxSkillValue() &&
4824 (ReqValue
< 0 ? 0 : ReqValue
) > irand(skillValue
- 25, skillValue
+ 37) )
4825 return SPELL_FAILED_TRY_AGAIN
;
4829 case SPELL_EFFECT_OPEN_LOCK
:
4831 if( m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT
&&
4832 m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT_ITEM
)
4835 if( m_caster
->GetTypeId() != TYPEID_PLAYER
// only players can open locks, gather etc.
4836 // we need a go target in case of TARGET_GAMEOBJECT
4837 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT
&& !m_targets
.getGOTarget()
4838 // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM
4839 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT_ITEM
&& !m_targets
.getGOTarget() &&
4840 (!m_targets
.getItemTarget() || !m_targets
.getItemTarget()->GetProto()->LockID
|| m_targets
.getItemTarget()->GetOwner() != m_caster
) )
4841 return SPELL_FAILED_BAD_TARGETS
;
4843 // In BattleGround players can use only flags and banners
4844 if( ((Player
*)m_caster
)->InBattleGround() &&
4845 !((Player
*)m_caster
)->CanUseBattleGroundObject() )
4846 return SPELL_FAILED_TRY_AGAIN
;
4848 // get the lock entry
4850 if (GameObject
* go
= m_targets
.getGOTarget())
4852 lockId
= go
->GetGOInfo()->GetLockId();
4854 return SPELL_FAILED_BAD_TARGETS
;
4856 else if(Item
* itm
= m_targets
.getItemTarget())
4857 lockId
= itm
->GetProto()->LockID
;
4859 SkillType skillId
= SKILL_NONE
;
4860 int32 reqSkillValue
= 0;
4861 int32 skillValue
= 0;
4863 // check lock compatibility
4864 SpellCastResult res
= CanOpenLock(SpellEffectIndex(i
), lockId
, skillId
, reqSkillValue
, skillValue
);
4865 if(res
!= SPELL_CAST_OK
)
4868 // chance for fail at orange mining/herb/LockPicking gathering attempt
4869 // second check prevent fail at rechecks
4870 if(skillId
!= SKILL_NONE
&& (!m_selfContainer
|| ((*m_selfContainer
) != this)))
4872 bool canFailAtMax
= skillId
!= SKILL_HERBALISM
&& skillId
!= SKILL_MINING
;
4874 // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill)
4875 if((canFailAtMax
|| skillValue
< sWorld
.GetConfigMaxSkillValue()) && reqSkillValue
> irand(skillValue
- 25, skillValue
+ 37))
4876 return SPELL_FAILED_TRY_AGAIN
;
4880 case SPELL_EFFECT_SUMMON_DEAD_PET
:
4882 Creature
*pet
= m_caster
->GetPet();
4884 return SPELL_FAILED_NO_PET
;
4887 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4891 // This is generic summon effect
4892 case SPELL_EFFECT_SUMMON
:
4894 if(SummonPropertiesEntry
const *summon_prop
= sSummonPropertiesStore
.LookupEntry(m_spellInfo
->EffectMiscValueB
[i
]))
4896 if(summon_prop
->Group
== SUMMON_PROP_GROUP_PETS
)
4898 if(m_caster
->GetPetGUID())
4899 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4901 if(m_caster
->GetCharmGUID())
4902 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4908 case SPELL_EFFECT_SUMMON_PET
:
4910 if(m_caster
->GetPetGUID()) //let warlock do a replacement summon
4913 Pet
* pet
= ((Player
*)m_caster
)->GetPet();
4915 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->getClass() == CLASS_WARLOCK
)
4917 if (strict
) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
4918 pet
->CastSpell(pet
, 32752, true, NULL
, NULL
, pet
->GetGUID());
4921 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
4924 if(m_caster
->GetCharmGUID())
4925 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
4929 case SPELL_EFFECT_SUMMON_PLAYER
:
4931 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4932 return SPELL_FAILED_BAD_TARGETS
;
4933 if(!((Player
*)m_caster
)->GetSelection())
4934 return SPELL_FAILED_BAD_TARGETS
;
4936 Player
* target
= sObjectMgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
4937 if( !target
|| ((Player
*)m_caster
) == target
|| !target
->IsInSameRaidWith((Player
*)m_caster
) )
4938 return SPELL_FAILED_BAD_TARGETS
;
4940 // check if our map is dungeon
4941 if( sMapStore
.LookupEntry(m_caster
->GetMapId())->IsDungeon() )
4943 InstanceTemplate
const* instance
= ObjectMgr::GetInstanceTemplate(m_caster
->GetMapId());
4945 return SPELL_FAILED_TARGET_NOT_IN_INSTANCE
;
4946 if ( instance
->levelMin
> target
->getLevel() )
4947 return SPELL_FAILED_LOWLEVEL
;
4948 if ( instance
->levelMax
&& instance
->levelMax
< target
->getLevel() )
4949 return SPELL_FAILED_HIGHLEVEL
;
4953 case SPELL_EFFECT_LEAP
:
4954 case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
:
4956 float dis
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
4957 float fx
= m_caster
->GetPositionX() + dis
* cos(m_caster
->GetOrientation());
4958 float fy
= m_caster
->GetPositionY() + dis
* sin(m_caster
->GetOrientation());
4959 // teleport a bit above terrain level to avoid falling below it
4960 float fz
= m_caster
->GetBaseMap()->GetHeight(fx
, fy
, m_caster
->GetPositionZ(), true);
4961 if(fz
<= INVALID_HEIGHT
) // note: this also will prevent use effect in instances without vmaps height enabled
4962 return SPELL_FAILED_TRY_AGAIN
;
4964 float caster_pos_z
= m_caster
->GetPositionZ();
4965 // Control the caster to not climb or drop when +-fz > 8
4966 if(!(fz
<= caster_pos_z
+ 8 && fz
>= caster_pos_z
- 8))
4967 return SPELL_FAILED_TRY_AGAIN
;
4969 // not allow use this effect at battleground until battleground start
4970 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
4971 if(BattleGround
const *bg
= ((Player
*)m_caster
)->GetBattleGround())
4972 if(bg
->GetStatus() != STATUS_IN_PROGRESS
)
4973 return SPELL_FAILED_TRY_AGAIN
;
4976 case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF
:
4978 if (m_targets
.getUnitTarget() == m_caster
)
4979 return SPELL_FAILED_BAD_TARGETS
;
4986 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
4988 switch(m_spellInfo
->EffectApplyAuraName
[i
])
4990 case SPELL_AURA_DUMMY
:
4993 switch(m_spellInfo
->Id
)
4996 if(m_caster
->GetTypeId() != TYPEID_PLAYER
|| !((Player
*)m_caster
)->IsInFeralForm())
4997 return SPELL_FAILED_ONLY_SHAPESHIFT
;
5004 case SPELL_AURA_MOD_POSSESS
:
5006 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
5007 return SPELL_FAILED_UNKNOWN
;
5009 if(m_targets
.getUnitTarget() == m_caster
)
5010 return SPELL_FAILED_BAD_TARGETS
;
5012 if(m_caster
->GetPetGUID())
5013 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
5015 if(m_caster
->GetCharmGUID())
5016 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
5018 if(m_caster
->GetCharmerGUID())
5019 return SPELL_FAILED_CHARMED
;
5021 if(!m_targets
.getUnitTarget())
5022 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
5024 if(m_targets
.getUnitTarget()->GetCharmerGUID())
5025 return SPELL_FAILED_CHARMED
;
5027 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(SpellEffectIndex(i
),m_targets
.getUnitTarget()))
5028 return SPELL_FAILED_HIGHLEVEL
;
5032 case SPELL_AURA_MOD_CHARM
:
5034 if(m_targets
.getUnitTarget() == m_caster
)
5035 return SPELL_FAILED_BAD_TARGETS
;
5037 if(m_caster
->GetPetGUID())
5038 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
5040 if(m_caster
->GetCharmGUID())
5041 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
5043 if(m_caster
->GetCharmerGUID())
5044 return SPELL_FAILED_CHARMED
;
5046 if(!m_targets
.getUnitTarget())
5047 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
5049 if(m_targets
.getUnitTarget()->GetCharmerGUID())
5050 return SPELL_FAILED_CHARMED
;
5052 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(SpellEffectIndex(i
),m_targets
.getUnitTarget()))
5053 return SPELL_FAILED_HIGHLEVEL
;
5057 case SPELL_AURA_MOD_POSSESS_PET
:
5059 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
5060 return SPELL_FAILED_UNKNOWN
;
5062 if(m_caster
->GetCharmGUID())
5063 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
5065 if(m_caster
->GetCharmerGUID())
5066 return SPELL_FAILED_CHARMED
;
5068 Pet
* pet
= m_caster
->GetPet();
5070 return SPELL_FAILED_NO_PET
;
5072 if(pet
->GetCharmerGUID())
5073 return SPELL_FAILED_CHARMED
;
5077 case SPELL_AURA_MOUNTED
:
5079 if (m_caster
->IsInWater())
5080 return SPELL_FAILED_ONLY_ABOVEWATER
;
5082 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetTransport())
5083 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
5085 // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
5086 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& !sMapStore
.LookupEntry(m_caster
->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell
&& !m_spellInfo
->AreaGroupId
)
5087 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
5089 ShapeshiftForm form
= m_caster
->m_form
;
5090 if( form
== FORM_CAT
|| form
== FORM_TREE
|| form
== FORM_TRAVEL
||
5091 form
== FORM_AQUA
|| form
== FORM_BEAR
|| form
== FORM_DIREBEAR
||
5092 form
== FORM_CREATUREBEAR
|| form
== FORM_GHOSTWOLF
|| form
== FORM_FLIGHT
||
5093 form
== FORM_FLIGHT_EPIC
|| form
== FORM_MOONKIN
|| form
== FORM_METAMORPHOSIS
)
5094 return SPELL_FAILED_NOT_SHAPESHIFT
;
5098 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
5100 if(!m_targets
.getUnitTarget())
5101 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
5103 // can be casted at non-friendly unit or own pet/charm
5104 if(m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()))
5105 return SPELL_FAILED_TARGET_FRIENDLY
;
5109 case SPELL_AURA_FLY
:
5110 case SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED
:
5112 // not allow cast fly spells if not have req. skills (all spells is self target)
5113 // allow always ghost flight spells
5114 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->isAlive())
5116 if (!((Player
*)m_caster
)->IsKnowHowFlyIn(m_caster
->GetMapId(),zone
))
5117 return m_IsTriggeredSpell
? SPELL_FAILED_DONT_REPORT
: SPELL_FAILED_NOT_HERE
;
5121 case SPELL_AURA_PERIODIC_MANA_LEECH
:
5123 if (!m_targets
.getUnitTarget())
5124 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
5126 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| m_CastItem
)
5129 if(m_targets
.getUnitTarget()->getPowerType() != POWER_MANA
)
5130 return SPELL_FAILED_BAD_TARGETS
;
5140 return SPELL_CAST_OK
;
5143 SpellCastResult
Spell::CheckPetCast(Unit
* target
)
5145 if(!m_caster
->isAlive())
5146 return SPELL_FAILED_CASTER_DEAD
;
5148 if(m_caster
->IsNonMeleeSpellCasted(false)) //prevent spellcast interruption by another spellcast
5149 return SPELL_FAILED_SPELL_IN_PROGRESS
;
5150 if(m_caster
->isInCombat() && IsNonCombatSpell(m_spellInfo
))
5151 return SPELL_FAILED_AFFECTING_COMBAT
;
5153 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)m_caster
)->isPet() || m_caster
->isCharmed()))
5155 //dead owner (pets still alive when owners ressed?)
5156 if(m_caster
->GetCharmerOrOwner() && !m_caster
->GetCharmerOrOwner()->isAlive())
5157 return SPELL_FAILED_CASTER_DEAD
;
5159 if(!target
&& m_targets
.getUnitTarget())
5160 target
= m_targets
.getUnitTarget();
5163 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
5165 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CHAIN_DAMAGE
||
5166 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND
||
5167 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND_2
||
5168 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_DUELVSPLAYER
||
5169 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_PARTY
||
5170 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CURRENT_ENEMY_COORDINATES
)
5174 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
5179 m_targets
.setUnitTarget(target
);
5181 Unit
* _target
= m_targets
.getUnitTarget();
5183 if(_target
) //for target dead/target not valid
5185 if(!_target
->isAlive())
5186 return SPELL_FAILED_BAD_TARGETS
;
5188 if(IsPositiveSpell(m_spellInfo
->Id
))
5190 if(m_caster
->IsHostileTo(_target
))
5191 return SPELL_FAILED_BAD_TARGETS
;
5195 bool duelvsplayertar
= false;
5196 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
5198 //TARGET_DUELVSPLAYER is positive AND negative
5199 duelvsplayertar
|= (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
);
5201 if(m_caster
->IsFriendlyTo(target
) && !duelvsplayertar
)
5203 return SPELL_FAILED_BAD_TARGETS
;
5208 if(((Creature
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
5209 return SPELL_FAILED_NOT_READY
;
5212 return CheckCast(true);
5215 SpellCastResult
Spell::CheckCasterAuras() const
5217 // Flag drop spells totally immuned to caster auras
5218 // FIXME: find more nice check for all totally immuned spells
5219 // AttributesEx3 & 0x10000000?
5220 if(m_spellInfo
->Id
== 23336 || m_spellInfo
->Id
== 23334 || m_spellInfo
->Id
== 34991)
5221 return SPELL_CAST_OK
;
5223 uint8 school_immune
= 0;
5224 uint32 mechanic_immune
= 0;
5225 uint32 dispel_immune
= 0;
5227 // Check if the spell grants school or mechanic immunity.
5228 // We use bitmasks so the loop is done only once and not on every aura check below.
5229 if ( m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
5231 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
5233 if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_SCHOOL_IMMUNITY
)
5234 school_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
5235 else if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY
)
5236 mechanic_immune
|= 1 << uint32(m_spellInfo
->EffectMiscValue
[i
]-1);
5237 else if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY_MASK
)
5238 mechanic_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
5239 else if (m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_DISPEL_IMMUNITY
)
5240 dispel_immune
|= GetDispellMask(DispelType(m_spellInfo
->EffectMiscValue
[i
]));
5242 // immune movement impairment and loss of control
5243 if (m_spellInfo
->Id
== 42292)
5244 mechanic_immune
= IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK
;
5247 // Check whether the cast should be prevented by any state you might have.
5248 SpellCastResult prevented_reason
= SPELL_CAST_OK
;
5249 // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
5250 uint32 unitflag
= m_caster
->GetUInt32Value(UNIT_FIELD_FLAGS
); // Get unit state
5251 if (unitflag
& UNIT_FLAG_STUNNED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
5252 prevented_reason
= SPELL_FAILED_STUNNED
;
5253 else if (unitflag
& UNIT_FLAG_CONFUSED
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
5254 prevented_reason
= SPELL_FAILED_CONFUSED
;
5255 else if (unitflag
& UNIT_FLAG_FLEEING
&& !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
5256 prevented_reason
= SPELL_FAILED_FLEEING
;
5257 else if (unitflag
& UNIT_FLAG_SILENCED
&& m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
)
5258 prevented_reason
= SPELL_FAILED_SILENCED
;
5259 else if (unitflag
& UNIT_FLAG_PACIFIED
&& m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
)
5260 prevented_reason
= SPELL_FAILED_PACIFIED
;
5261 else if(m_caster
->HasAuraType(SPELL_AURA_ALLOW_ONLY_ABILITY
))
5263 Unit::AuraList
const& casingLimit
= m_caster
->GetAurasByType(SPELL_AURA_ALLOW_ONLY_ABILITY
);
5264 for(Unit::AuraList::const_iterator itr
= casingLimit
.begin(); itr
!= casingLimit
.end(); ++itr
)
5266 if(!(*itr
)->isAffectedOnSpell(m_spellInfo
))
5268 prevented_reason
= SPELL_FAILED_CASTER_AURASTATE
;
5274 // Attr must make flag drop spell totally immune from all effects
5275 if (prevented_reason
!= SPELL_CAST_OK
)
5277 if (school_immune
|| mechanic_immune
|| dispel_immune
)
5279 //Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
5280 Unit::AuraMap
const& auras
= m_caster
->GetAuras();
5281 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); ++itr
)
5285 if (GetSpellMechanicMask(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()) & mechanic_immune
)
5287 if (GetSpellSchoolMask(itr
->second
->GetSpellProto()) & school_immune
)
5289 if ((1<<(itr
->second
->GetSpellProto()->Dispel
)) & dispel_immune
)
5292 // Make a second check for spell failed so the right SPELL_FAILED message is returned.
5293 // That is needed when your casting is prevented by multiple states and you are only immune to some of them.
5294 switch(itr
->second
->GetModifier()->m_auraname
)
5296 case SPELL_AURA_MOD_STUN
:
5297 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
5298 return SPELL_FAILED_STUNNED
;
5300 case SPELL_AURA_MOD_CONFUSE
:
5301 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
5302 return SPELL_FAILED_CONFUSED
;
5304 case SPELL_AURA_MOD_FEAR
:
5305 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
5306 return SPELL_FAILED_FLEEING
;
5308 case SPELL_AURA_MOD_SILENCE
:
5309 case SPELL_AURA_MOD_PACIFY
:
5310 case SPELL_AURA_MOD_PACIFY_SILENCE
:
5311 if( m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_PACIFY
)
5312 return SPELL_FAILED_PACIFIED
;
5313 else if ( m_spellInfo
->PreventionType
== SPELL_PREVENTION_TYPE_SILENCE
)
5314 return SPELL_FAILED_SILENCED
;
5321 // You are prevented from casting and the spell casted does not grant immunity. Return a failed error.
5323 return prevented_reason
;
5325 return SPELL_CAST_OK
;
5328 bool Spell::CanAutoCast(Unit
* target
)
5330 ObjectGuid targetguid
= target
->GetObjectGuid();
5332 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
5334 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
)
5336 if( m_spellInfo
->StackAmount
<= 1)
5338 if( target
->HasAura(m_spellInfo
->Id
, SpellEffectIndex(j
)) )
5343 if(Aura
* aura
= target
->GetAura(m_spellInfo
->Id
, SpellEffectIndex(j
)))
5344 if(aura
->GetStackAmount() >= m_spellInfo
->StackAmount
)
5348 else if ( IsAreaAuraEffect( m_spellInfo
->Effect
[j
] ))
5350 if( target
->HasAura(m_spellInfo
->Id
, SpellEffectIndex(j
)) )
5355 SpellCastResult result
= CheckPetCast(target
);
5357 if(result
== SPELL_CAST_OK
|| result
== SPELL_FAILED_UNIT_NOT_INFRONT
)
5360 //check if among target units, our WANTED target is as well (->only self cast spells return false)
5361 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
5362 if( ihit
->targetGUID
== targetguid
)
5365 return false; //target invalid
5368 SpellCastResult
Spell::CheckRange(bool strict
)
5372 // self cast doesn't need range checking -- also for Starshards fix
5373 if (m_spellInfo
->rangeIndex
== 1)
5374 return SPELL_CAST_OK
;
5376 if (strict
) //add radius of caster
5378 else //add radius of caster and ~5 yds "give"
5381 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
5382 Unit
*target
= m_targets
.getUnitTarget();
5383 bool friendly
= target
? target
->IsFriendlyTo(m_caster
) : false;
5384 float max_range
= GetSpellMaxRange(srange
, friendly
) + range_mod
;
5385 float min_range
= GetSpellMinRange(srange
, friendly
);
5387 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
5388 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RANGE
, max_range
, this);
5390 if(target
&& target
!= m_caster
)
5392 // distance from target in checks
5393 float dist
= m_caster
->GetCombatDistance(target
);
5395 if(dist
> max_range
)
5396 return SPELL_FAILED_OUT_OF_RANGE
;
5397 if(min_range
&& dist
< min_range
)
5398 return SPELL_FAILED_TOO_CLOSE
;
5399 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&&
5400 (m_spellInfo
->FacingCasterFlags
& SPELL_FACING_FLAG_INFRONT
) && !m_caster
->HasInArc( M_PI_F
, target
) )
5401 return SPELL_FAILED_UNIT_NOT_INFRONT
;
5404 if(m_targets
.m_targetMask
== TARGET_FLAG_DEST_LOCATION
&& m_targets
.m_destX
!= 0 && m_targets
.m_destY
!= 0 && m_targets
.m_destZ
!= 0)
5406 if(!m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
, max_range
))
5407 return SPELL_FAILED_OUT_OF_RANGE
;
5408 if(min_range
&& m_caster
->IsWithinDist3d(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
, min_range
))
5409 return SPELL_FAILED_TOO_CLOSE
;
5412 return SPELL_CAST_OK
;
5415 int32
Spell::CalculatePowerCost()
5417 // item cast not used power
5421 // Spell drain all exist power on cast (Only paladin lay of Hands)
5422 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DRAIN_ALL_POWER
)
5424 // If power type - health drain all
5425 if (m_spellInfo
->powerType
== POWER_HEALTH
)
5426 return m_caster
->GetHealth();
5427 // Else drain all power
5428 if (m_spellInfo
->powerType
< MAX_POWERS
)
5429 return m_caster
->GetPower(Powers(m_spellInfo
->powerType
));
5430 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
5435 int32 powerCost
= m_spellInfo
->manaCost
;
5436 // PCT cost from total amount
5437 if (m_spellInfo
->ManaCostPercentage
)
5439 switch (m_spellInfo
->powerType
)
5441 // health as power used
5443 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateHealth() / 100;
5446 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateMana() / 100;
5451 case POWER_HAPPINESS
:
5452 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetMaxPower(Powers(m_spellInfo
->powerType
)) / 100;
5455 case POWER_RUNIC_POWER
:
5456 DEBUG_LOG("Spell::CalculateManaCost: Not implemented yet!");
5459 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
5463 SpellSchools school
= GetFirstSchoolInMask(m_spellSchoolMask
);
5464 // Flat mod from caster auras by spell school
5465 powerCost
+= m_caster
->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER
+ school
);
5466 // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
5467 if ( m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST
)
5468 powerCost
+= m_caster
->GetAttackTime(OFF_ATTACK
) / 100;
5469 // Apply cost mod by spell
5470 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
5471 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, powerCost
, this);
5473 if(m_spellInfo
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
)
5474 powerCost
= int32(powerCost
/ (1.117f
* m_spellInfo
->spellLevel
/ m_caster
->getLevel() -0.1327f
));
5476 // PCT mod from user auras by school
5477 powerCost
= int32(powerCost
* (1.0f
+ m_caster
->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+ school
)));
5483 SpellCastResult
Spell::CheckPower()
5485 // item cast not used power
5487 return SPELL_CAST_OK
;
5489 // Do precise power regen on spell cast
5490 if (m_powerCost
> 0 && m_caster
->GetTypeId() == TYPEID_PLAYER
)
5492 Player
* playerCaster
= (Player
*)m_caster
;
5493 uint32 diff
= REGEN_TIME_FULL
- m_caster
->GetRegenTimer();
5494 if (diff
>= REGEN_TIME_PRECISE
)
5495 playerCaster
->RegenerateAll(diff
);
5498 // health as power used - need check health amount
5499 if(m_spellInfo
->powerType
== POWER_HEALTH
)
5501 if((int32
)m_caster
->GetHealth() <= m_powerCost
)
5502 return SPELL_FAILED_CASTER_AURASTATE
;
5503 return SPELL_CAST_OK
;
5505 // Check valid power type
5506 if( m_spellInfo
->powerType
>= MAX_POWERS
)
5508 sLog
.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo
->powerType
);
5509 return SPELL_FAILED_UNKNOWN
;
5512 //check rune cost only if a spell has PowerType == POWER_RUNE
5513 if(m_spellInfo
->powerType
== POWER_RUNE
)
5515 SpellCastResult failReason
= CheckOrTakeRunePower(false);
5516 if(failReason
!= SPELL_CAST_OK
)
5520 // Check power amount
5521 Powers powerType
= Powers(m_spellInfo
->powerType
);
5522 if((int32
)m_caster
->GetPower(powerType
) < m_powerCost
)
5523 return SPELL_FAILED_NO_POWER
;
5525 return SPELL_CAST_OK
;
5528 bool Spell::IgnoreItemRequirements() const
5530 if (m_IsTriggeredSpell
)
5533 /// Check if it's an enchant scroll. These have no required reagents even though their spell does.
5534 if (m_CastItem
&& m_CastItem
->HasFlag(ITEM_FIELD_FLAGS
, ITEM_FLAGS_ENCHANT_SCROLL
))
5540 SpellCastResult
Spell::CheckItems()
5542 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
5543 return SPELL_CAST_OK
;
5545 Player
* p_caster
= (Player
*)m_caster
;
5550 uint32 itemid
= m_CastItem
->GetEntry();
5551 if( !p_caster
->HasItemCount(itemid
, 1) )
5552 return SPELL_FAILED_ITEM_NOT_FOUND
;
5554 ItemPrototype
const *proto
= m_CastItem
->GetProto();
5556 return SPELL_FAILED_ITEM_NOT_FOUND
;
5558 for (int i
= 0; i
< 5; ++i
)
5559 if (proto
->Spells
[i
].SpellCharges
)
5560 if(m_CastItem
->GetSpellCharges(i
) == 0)
5561 return SPELL_FAILED_NO_CHARGES_REMAIN
;
5563 // consumable cast item checks
5564 if (proto
->Class
== ITEM_CLASS_CONSUMABLE
&& m_targets
.getUnitTarget())
5566 // such items should only fail if there is no suitable effect at all - see Rejuvenation Potions for example
5567 SpellCastResult failReason
= SPELL_CAST_OK
;
5568 for (int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
5570 // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster
5571 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_PET
)
5574 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_HEAL
)
5576 if (m_targets
.getUnitTarget()->GetHealth() == m_targets
.getUnitTarget()->GetMaxHealth())
5578 failReason
= SPELL_FAILED_ALREADY_AT_FULL_HEALTH
;
5583 failReason
= SPELL_CAST_OK
;
5588 // Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
5589 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
5591 if(m_spellInfo
->EffectMiscValue
[i
] < 0 || m_spellInfo
->EffectMiscValue
[i
] >= MAX_POWERS
)
5593 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
5597 Powers power
= Powers(m_spellInfo
->EffectMiscValue
[i
]);
5598 if (m_targets
.getUnitTarget()->GetPower(power
) == m_targets
.getUnitTarget()->GetMaxPower(power
))
5600 failReason
= SPELL_FAILED_ALREADY_AT_FULL_POWER
;
5605 failReason
= SPELL_CAST_OK
;
5610 if (failReason
!= SPELL_CAST_OK
)
5615 // check target item
5616 if(m_targets
.getItemTargetGUID())
5618 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
5619 return SPELL_FAILED_BAD_TARGETS
;
5621 if(!m_targets
.getItemTarget())
5622 return SPELL_FAILED_ITEM_GONE
;
5624 if(!m_targets
.getItemTarget()->IsFitToSpellRequirements(m_spellInfo
))
5625 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
5627 // if not item target then required item must be equipped
5630 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !((Player
*)m_caster
)->HasItemFitToSpellReqirements(m_spellInfo
))
5631 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
5634 // check spell focus object
5635 if(m_spellInfo
->RequiresSpellFocus
)
5637 GameObject
* ok
= NULL
;
5638 MaNGOS::GameObjectFocusCheck
go_check(m_caster
,m_spellInfo
->RequiresSpellFocus
);
5639 MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
> checker(m_caster
, ok
, go_check
);
5640 Cell::VisitGridObjects(m_caster
, checker
, m_caster
->GetMap()->GetVisibilityDistance());
5643 return SPELL_FAILED_REQUIRES_SPELL_FOCUS
;
5645 focusObject
= ok
; // game object found in range
5648 // check reagents (ignore triggered spells with reagents processed by original spell) and special reagent ignore case.
5649 if (!IgnoreItemRequirements())
5651 if (!p_caster
->CanNoReagentCast(m_spellInfo
))
5653 for(uint32 i
= 0; i
< MAX_SPELL_REAGENTS
; ++i
)
5655 if(m_spellInfo
->Reagent
[i
] <= 0)
5658 uint32 itemid
= m_spellInfo
->Reagent
[i
];
5659 uint32 itemcount
= m_spellInfo
->ReagentCount
[i
];
5661 // if CastItem is also spell reagent
5662 if (m_CastItem
&& m_CastItem
->GetEntry() == itemid
)
5664 ItemPrototype
const *proto
= m_CastItem
->GetProto();
5666 return SPELL_FAILED_REAGENTS
;
5667 for(int s
= 0; s
< MAX_ITEM_PROTO_SPELLS
; ++s
)
5669 // CastItem will be used up and does not count as reagent
5670 int32 charges
= m_CastItem
->GetSpellCharges(s
);
5671 if (proto
->Spells
[s
].SpellCharges
< 0 && !(proto
->ExtraFlags
& ITEM_EXTRA_NON_CONSUMABLE
) && abs(charges
) < 2)
5679 if (!p_caster
->HasItemCount(itemid
, itemcount
))
5680 return SPELL_FAILED_REAGENTS
;
5684 // check totem-item requirements (items presence in inventory)
5685 uint32 totems
= MAX_SPELL_TOTEMS
;
5686 for(int i
= 0; i
< MAX_SPELL_TOTEMS
; ++i
)
5688 if (m_spellInfo
->Totem
[i
] != 0)
5690 if (p_caster
->HasItemCount(m_spellInfo
->Totem
[i
], 1))
5701 return SPELL_FAILED_TOTEMS
;
5703 // Check items for TotemCategory (items presence in inventory)
5704 uint32 TotemCategory
= MAX_SPELL_TOTEM_CATEGORIES
;
5705 for(int i
= 0; i
< MAX_SPELL_TOTEM_CATEGORIES
; ++i
)
5707 if (m_spellInfo
->TotemCategory
[i
] != 0)
5709 if (p_caster
->HasItemTotemCategory(m_spellInfo
->TotemCategory
[i
]))
5719 if (TotemCategory
!= 0)
5720 return SPELL_FAILED_TOTEM_CATEGORY
;
5723 // special checks for spell effects
5724 for(int i
= 0; i
< MAX_EFFECT_INDEX
; ++i
)
5726 switch (m_spellInfo
->Effect
[i
])
5728 case SPELL_EFFECT_CREATE_ITEM
:
5730 if (!m_IsTriggeredSpell
&& m_spellInfo
->EffectItemType
[i
])
5732 // Conjure Mana Gem (skip same or low level ranks for later recharge)
5733 if (i
== EFFECT_INDEX_0
&& m_spellInfo
->Effect
[EFFECT_INDEX_1
] == SPELL_EFFECT_DUMMY
)
5735 if (ItemPrototype
const* itemProto
= ObjectMgr::GetItemPrototype(m_spellInfo
->EffectItemType
[i
]))
5737 if (Item
* item
= p_caster
->GetItemByLimitedCategory(itemProto
->ItemLimitCategory
))
5739 if (item
->GetProto()->ItemLevel
<= itemProto
->ItemLevel
)
5741 if (item
->HasMaxCharges())
5742 return SPELL_FAILED_ITEM_AT_MAX_CHARGES
;
5744 // will recharge in next effect
5751 ItemPosCountVec dest
;
5752 uint8 msg
= p_caster
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, m_spellInfo
->EffectItemType
[i
], 1 );
5753 if (msg
!= EQUIP_ERR_OK
)
5755 p_caster
->SendEquipError( msg
, NULL
, NULL
, m_spellInfo
->EffectItemType
[i
] );
5756 return SPELL_FAILED_DONT_REPORT
;
5761 case SPELL_EFFECT_RESTORE_ITEM_CHARGES
:
5763 if (Item
* item
= p_caster
->GetItemByEntry(m_spellInfo
->EffectItemType
[i
]))
5764 if (item
->HasMaxCharges())
5765 return SPELL_FAILED_ITEM_AT_MAX_CHARGES
;
5769 case SPELL_EFFECT_ENCHANT_ITEM
:
5770 case SPELL_EFFECT_ENCHANT_ITEM_PRISMATIC
:
5772 Item
* targetItem
= m_targets
.getItemTarget();
5774 return SPELL_FAILED_ITEM_NOT_FOUND
;
5776 if( targetItem
->GetProto()->ItemLevel
< m_spellInfo
->baseLevel
)
5777 return SPELL_FAILED_LOWLEVEL
;
5778 // Not allow enchant in trade slot for some enchant type
5779 if( targetItem
->GetOwner() != m_caster
)
5781 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5782 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5784 return SPELL_FAILED_ERROR
;
5785 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5786 return SPELL_FAILED_NOT_TRADEABLE
;
5790 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
5792 Item
*item
= m_targets
.getItemTarget();
5794 return SPELL_FAILED_ITEM_NOT_FOUND
;
5795 // Not allow enchant in trade slot for some enchant type
5796 if( item
->GetOwner() != m_caster
)
5798 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
5799 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
5801 return SPELL_FAILED_ERROR
;
5802 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
5803 return SPELL_FAILED_NOT_TRADEABLE
;
5807 case SPELL_EFFECT_ENCHANT_HELD_ITEM
:
5808 // check item existence in effect code (not output errors at offhand hold item effect to main hand for example
5810 case SPELL_EFFECT_DISENCHANT
:
5812 if(!m_targets
.getItemTarget())
5813 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5815 // prevent disenchanting in trade slot
5816 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5817 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5819 ItemPrototype
const* itemProto
= m_targets
.getItemTarget()->GetProto();
5821 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5823 uint32 item_quality
= itemProto
->Quality
;
5824 // 2.0.x addon: Check player enchanting level against the item disenchanting requirements
5825 uint32 item_disenchantskilllevel
= itemProto
->RequiredDisenchantSkill
;
5826 if (item_disenchantskilllevel
== uint32(-1))
5827 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5828 if (item_disenchantskilllevel
> p_caster
->GetSkillValue(SKILL_ENCHANTING
))
5829 return SPELL_FAILED_LOW_CASTLEVEL
;
5830 if(item_quality
> 4 || item_quality
< 2)
5831 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5832 if(itemProto
->Class
!= ITEM_CLASS_WEAPON
&& itemProto
->Class
!= ITEM_CLASS_ARMOR
)
5833 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5834 if (!itemProto
->DisenchantID
)
5835 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
5838 case SPELL_EFFECT_PROSPECTING
:
5840 if(!m_targets
.getItemTarget())
5841 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5842 // ensure item is a prospectable ore
5843 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_MINING_SUPP
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5844 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5845 // prevent prospecting in trade slot
5846 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5847 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5848 // Check for enough skill in jewelcrafting
5849 uint32 item_prospectingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5850 if(item_prospectingskilllevel
>p_caster
->GetSkillValue(SKILL_JEWELCRAFTING
))
5851 return SPELL_FAILED_LOW_CASTLEVEL
;
5852 // make sure the player has the required ores in inventory
5853 if(m_targets
.getItemTarget()->GetCount() < 5)
5854 return SPELL_FAILED_NEED_MORE_ITEMS
;
5856 if(!LootTemplates_Prospecting
.HaveLootFor(m_targets
.getItemTargetEntry()))
5857 return SPELL_FAILED_CANT_BE_PROSPECTED
;
5861 case SPELL_EFFECT_MILLING
:
5863 if(!m_targets
.getItemTarget())
5864 return SPELL_FAILED_CANT_BE_MILLED
;
5865 // ensure item is a millable herb
5866 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_HERBS
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
5867 return SPELL_FAILED_CANT_BE_MILLED
;
5868 // prevent milling in trade slot
5869 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
5870 return SPELL_FAILED_CANT_BE_MILLED
;
5871 // Check for enough skill in inscription
5872 uint32 item_millingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
5873 if(item_millingskilllevel
>p_caster
->GetSkillValue(SKILL_INSCRIPTION
))
5874 return SPELL_FAILED_LOW_CASTLEVEL
;
5875 // make sure the player has the required herbs in inventory
5876 if(m_targets
.getItemTarget()->GetCount() < 5)
5877 return SPELL_FAILED_NEED_MORE_ITEMS
;
5879 if(!LootTemplates_Milling
.HaveLootFor(m_targets
.getItemTargetEntry()))
5880 return SPELL_FAILED_CANT_BE_MILLED
;
5884 case SPELL_EFFECT_WEAPON_DAMAGE
:
5885 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
:
5887 if(m_caster
->GetTypeId() != TYPEID_PLAYER
) return SPELL_FAILED_TARGET_NOT_PLAYER
;
5888 if( m_attackType
!= RANGED_ATTACK
)
5890 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(m_attackType
,true,false);
5892 return SPELL_FAILED_EQUIPPED_ITEM
;
5894 switch(pItem
->GetProto()->SubClass
)
5896 case ITEM_SUBCLASS_WEAPON_THROWN
:
5898 uint32 ammo
= pItem
->GetEntry();
5899 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5900 return SPELL_FAILED_NO_AMMO
;
5902 case ITEM_SUBCLASS_WEAPON_GUN
:
5903 case ITEM_SUBCLASS_WEAPON_BOW
:
5904 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5906 uint32 ammo
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
5910 if(m_caster
->GetDummyAura(46699))
5911 break; // skip other checks
5913 return SPELL_FAILED_NO_AMMO
;
5916 ItemPrototype
const *ammoProto
= ObjectMgr::GetItemPrototype( ammo
);
5918 return SPELL_FAILED_NO_AMMO
;
5920 if(ammoProto
->Class
!= ITEM_CLASS_PROJECTILE
)
5921 return SPELL_FAILED_NO_AMMO
;
5923 // check ammo ws. weapon compatibility
5924 switch(pItem
->GetProto()->SubClass
)
5926 case ITEM_SUBCLASS_WEAPON_BOW
:
5927 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
5928 if(ammoProto
->SubClass
!= ITEM_SUBCLASS_ARROW
)
5929 return SPELL_FAILED_NO_AMMO
;
5931 case ITEM_SUBCLASS_WEAPON_GUN
:
5932 if(ammoProto
->SubClass
!= ITEM_SUBCLASS_BULLET
)
5933 return SPELL_FAILED_NO_AMMO
;
5936 return SPELL_FAILED_NO_AMMO
;
5939 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
5940 return SPELL_FAILED_NO_AMMO
;
5942 case ITEM_SUBCLASS_WEAPON_WAND
:
5953 return SPELL_CAST_OK
;
5956 void Spell::Delayed()
5958 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
5961 if (m_spellState
== SPELL_STATE_DELAYED
)
5962 return; // spell is active and can't be time-backed
5964 if(isDelayableNoMore()) // Spells may only be delayed twice
5967 // spells not loosing casting time ( slam, dynamites, bombs.. )
5968 if(!(m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_DAMAGE
))
5971 // check pushback reduce
5972 int32 delaytime
= 500; // spellcasting delay is normally 500ms
5973 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
5974 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
5975 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
5976 if(delayReduce
>= 100)
5979 delaytime
= delaytime
* (100 - delayReduce
) / 100;
5981 if(int32(m_timer
) + delaytime
> m_casttime
)
5983 delaytime
= m_casttime
- m_timer
;
5984 m_timer
= m_casttime
;
5987 m_timer
+= delaytime
;
5989 DETAIL_LOG("Spell %u partially interrupted for (%d) ms at damage", m_spellInfo
->Id
, delaytime
);
5991 WorldPacket
data(SMSG_SPELL_DELAYED
, 8+4);
5992 data
<< m_caster
->GetPackGUID();
5993 data
<< uint32(delaytime
);
5995 m_caster
->SendMessageToSet(&data
, true);
5998 void Spell::DelayedChannel()
6000 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
|| getState() != SPELL_STATE_CASTING
)
6003 if(isDelayableNoMore()) // Spells may only be delayed twice
6006 // check pushback reduce
6007 int32 delaytime
= GetSpellDuration(m_spellInfo
) * 25 / 100;// channeling delay is normally 25% of its time per hit
6008 int32 delayReduce
= 100; // must be initialized to 100 for percent modifiers
6009 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_NOT_LOSE_CASTING_TIME
, delayReduce
, this);
6010 delayReduce
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_REDUCE_PUSHBACK
) - 100;
6011 if(delayReduce
>= 100)
6014 delaytime
= delaytime
* (100 - delayReduce
) / 100;
6016 if(int32(m_timer
) < delaytime
)
6018 delaytime
= m_timer
;
6022 m_timer
-= delaytime
;
6024 DEBUG_LOG("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo
->Id
, delaytime
, m_timer
);
6026 for(std::list
<TargetInfo
>::const_iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end(); ++ihit
)
6028 if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
6030 if (Unit
* unit
= m_caster
->GetObjectGuid() == ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
))
6031 for (int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
6032 if (ihit
->effectMask
& (1 << j
))
6033 unit
->DelayAura(m_spellInfo
->Id
, SpellEffectIndex(j
), delaytime
);
6038 for(int j
= 0; j
< MAX_EFFECT_INDEX
; ++j
)
6040 // partially interrupt persistent area auras
6041 if (DynamicObject
* dynObj
= m_caster
->GetDynObject(m_spellInfo
->Id
, SpellEffectIndex(j
)))
6042 dynObj
->Delay(delaytime
);
6045 SendChannelUpdate(m_timer
);
6048 void Spell::UpdateOriginalCasterPointer()
6050 if(m_originalCasterGUID
== m_caster
->GetObjectGuid())
6051 m_originalCaster
= m_caster
;
6052 else if (m_originalCasterGUID
.IsGameobject())
6054 GameObject
* go
= m_caster
->IsInWorld() ? m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
) : NULL
;
6055 m_originalCaster
= go
? go
->GetOwner() : NULL
;
6059 Unit
* unit
= ObjectAccessor::GetUnit(*m_caster
, m_originalCasterGUID
);
6060 m_originalCaster
= unit
&& unit
->IsInWorld() ? unit
: NULL
;
6064 void Spell::UpdatePointers()
6066 UpdateOriginalCasterPointer();
6068 m_targets
.Update(m_caster
);
6071 bool Spell::CheckTargetCreatureType(Unit
* target
) const
6073 uint32 spellCreatureTargetMask
= m_spellInfo
->TargetCreatureType
;
6075 // Curse of Doom & Exorcism: not find another way to fix spell target check :/
6076 if (m_spellInfo
->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& m_spellInfo
->Category
== 1179)
6078 // not allow cast at player
6079 if(target
->GetTypeId() == TYPEID_PLAYER
)
6082 spellCreatureTargetMask
= 0x7FF;
6085 // Dismiss Pet and Taming Lesson skipped
6086 if(m_spellInfo
->Id
== 2641 || m_spellInfo
->Id
== 23356)
6087 spellCreatureTargetMask
= 0;
6089 if (spellCreatureTargetMask
)
6091 uint32 TargetCreatureType
= target
->GetCreatureTypeMask();
6093 return !TargetCreatureType
|| (spellCreatureTargetMask
& TargetCreatureType
);
6098 CurrentSpellTypes
Spell::GetCurrentContainer()
6100 if (IsNextMeleeSwingSpell())
6101 return(CURRENT_MELEE_SPELL
);
6102 else if (IsAutoRepeat())
6103 return(CURRENT_AUTOREPEAT_SPELL
);
6104 else if (IsChanneledSpell(m_spellInfo
))
6105 return(CURRENT_CHANNELED_SPELL
);
6107 return(CURRENT_GENERIC_SPELL
);
6110 bool Spell::CheckTarget( Unit
* target
, SpellEffectIndex eff
)
6112 // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets)
6113 if(m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SELF
)
6115 if (!CheckTargetCreatureType(target
))
6119 // Check Aura spell req (need for AoE spells)
6120 if(m_spellInfo
->targetAuraSpell
&& !target
->HasAura(m_spellInfo
->targetAuraSpell
))
6122 if (m_spellInfo
->excludeTargetAuraSpell
&& target
->HasAura(m_spellInfo
->excludeTargetAuraSpell
))
6125 // Check targets for not_selectable unit flag and remove
6126 // A player can cast spells on his pet (or other controlled unit) though in any state
6127 if (target
!= m_caster
&& target
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
6129 // any unattackable target skipped
6130 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
))
6133 // unselectable targets skipped in all cases except TARGET_SCRIPT targeting
6134 // in case TARGET_SCRIPT target selected by server always and can't be cheated
6135 if ((!m_IsTriggeredSpell
|| target
!= m_targets
.getUnitTarget()) &&
6136 target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NOT_SELECTABLE
) &&
6137 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SCRIPT
&&
6138 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_SCRIPT
&&
6139 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_AREAEFFECT_CUSTOM
&&
6140 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_AREAEFFECT_CUSTOM
)
6144 // Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
6145 if( target
!= m_caster
&& target
->GetTypeId() == TYPEID_PLAYER
)
6147 if(((Player
*)target
)->GetVisibility() == VISIBILITY_OFF
)
6150 if(((Player
*)target
)->isGameMaster() && !IsPositiveSpell(m_spellInfo
->Id
))
6154 // Check targets for LOS visibility (except spells without range limitations )
6155 switch(m_spellInfo
->Effect
[eff
])
6157 case SPELL_EFFECT_SUMMON_PLAYER
: // from anywhere
6159 case SPELL_EFFECT_DUMMY
:
6160 if(m_spellInfo
->Id
!= 20577) // Cannibalize
6163 case SPELL_EFFECT_RESURRECT_NEW
:
6164 // player far away, maybe his corpse near?
6165 if(target
!= m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
6167 if(!m_targets
.getCorpseTargetGUID())
6170 Corpse
*corpse
= m_caster
->GetMap()->GetCorpse(m_targets
.getCorpseTargetGUID());
6174 if(target
->GetGUID() != corpse
->GetOwnerGUID())
6177 if(!corpse
->IsWithinLOSInMap(m_caster
))
6181 // all ok by some way or another, skip normal check
6183 default: // normal case
6184 // Get GO cast coordinates if original caster -> GO
6185 if (target
!= m_caster
)
6186 if (WorldObject
*caster
= GetCastingObject())
6187 if (!target
->IsWithinLOSInMap(caster
))
6195 bool Spell::IsNeedSendToClient() const
6197 return m_spellInfo
->SpellVisual
[0] || m_spellInfo
->SpellVisual
[1] || IsChanneledSpell(m_spellInfo
) ||
6198 m_spellInfo
->speed
> 0.0f
|| !m_triggeredByAuraSpell
&& !m_IsTriggeredSpell
;
6202 bool Spell::IsTriggeredSpellWithRedundentData() const
6204 return m_IsTriggeredSpell
&& (m_spellInfo
->manaCost
|| m_spellInfo
->ManaCostPercentage
);
6207 bool Spell::HaveTargetsForEffect(SpellEffectIndex effect
) const
6209 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin(); itr
!= m_UniqueTargetInfo
.end(); ++itr
)
6210 if(itr
->effectMask
& (1 << effect
))
6213 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin(); itr
!= m_UniqueGOTargetInfo
.end(); ++itr
)
6214 if(itr
->effectMask
& (1 << effect
))
6217 for(std::list
<ItemTargetInfo
>::const_iterator itr
= m_UniqueItemInfo
.begin(); itr
!= m_UniqueItemInfo
.end(); ++itr
)
6218 if(itr
->effectMask
& (1 << effect
))
6224 SpellEvent::SpellEvent(Spell
* spell
) : BasicEvent()
6229 SpellEvent::~SpellEvent()
6231 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
6234 if (m_Spell
->IsDeletable())
6240 sLog
.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
6241 (m_Spell
->GetCaster()->GetTypeId() == TYPEID_PLAYER
? "Player" : "Creature"), m_Spell
->GetCaster()->GetGUIDLow(), m_Spell
->m_spellInfo
->Id
);
6245 bool SpellEvent::Execute(uint64 e_time
, uint32 p_time
)
6247 // update spell if it is not finished
6248 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
6249 m_Spell
->update(p_time
);
6251 // check spell state to process
6252 switch (m_Spell
->getState())
6254 case SPELL_STATE_FINISHED
:
6256 // spell was finished, check deletable state
6257 if (m_Spell
->IsDeletable())
6259 // check, if we do have unfinished triggered spells
6260 return true; // spell is deletable, finish event
6262 // event will be re-added automatically at the end of routine)
6265 case SPELL_STATE_CASTING
:
6267 // this spell is in channeled state, process it on the next update
6268 // event will be re-added automatically at the end of routine)
6271 case SPELL_STATE_DELAYED
:
6273 // first, check, if we have just started
6274 if (m_Spell
->GetDelayStart() != 0)
6276 // no, we aren't, do the typical update
6277 // check, if we have channeled spell on our hands
6278 if (IsChanneledSpell(m_Spell
->m_spellInfo
))
6280 // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish
6281 // check, if we have casting anything else except this channeled spell and autorepeat
6282 if (m_Spell
->GetCaster()->IsNonMeleeSpellCasted(false, true, true))
6284 // another non-melee non-delayed spell is casted now, abort
6289 // do the action (pass spell to channeling state)
6290 m_Spell
->handle_immediate();
6292 // event will be re-added automatically at the end of routine)
6296 // run the spell handler and think about what we can do next
6297 uint64 t_offset
= e_time
- m_Spell
->GetDelayStart();
6298 uint64 n_offset
= m_Spell
->handle_delayed(t_offset
);
6301 // re-add us to the queue
6302 m_Spell
->GetCaster()->m_Events
.AddEvent(this, m_Spell
->GetDelayStart() + n_offset
, false);
6303 return false; // event not complete
6306 // finish update event will be re-added automatically at the end of routine)
6311 // delaying had just started, record the moment
6312 m_Spell
->SetDelayStart(e_time
);
6313 // re-plan the event for the delay moment
6314 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ m_Spell
->GetDelayMoment(), false);
6315 return false; // event not complete
6322 // event will be re-added automatically at the end of routine)
6326 // spell processing not complete, plan event on the next update interval
6327 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ 1, false);
6328 return false; // event not complete
6331 void SpellEvent::Abort(uint64
/*e_time*/)
6333 // oops, the spell we try to do is aborted
6334 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
6338 bool SpellEvent::IsDeletable() const
6340 return m_Spell
->IsDeletable();
6343 SpellCastResult
Spell::CanOpenLock(SpellEffectIndex effIndex
, uint32 lockId
, SkillType
& skillId
, int32
& reqSkillValue
, int32
& skillValue
)
6345 if(!lockId
) // possible case for GO and maybe for items.
6346 return SPELL_CAST_OK
;
6349 LockEntry
const *lockInfo
= sLockStore
.LookupEntry(lockId
);
6352 return SPELL_FAILED_BAD_TARGETS
;
6354 bool reqKey
= false; // some locks not have reqs
6356 for(int j
= 0; j
< 8; ++j
)
6358 switch(lockInfo
->Type
[j
])
6360 // check key item (many fit cases can be)
6362 if(lockInfo
->Index
[j
] && m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->Index
[j
])
6363 return SPELL_CAST_OK
;
6366 // check key skill (only single first fit case can be)
6367 case LOCK_KEY_SKILL
:
6371 // wrong locktype, skip
6372 if(uint32(m_spellInfo
->EffectMiscValue
[effIndex
]) != lockInfo
->Index
[j
])
6375 skillId
= SkillByLockType(LockType(lockInfo
->Index
[j
]));
6377 if ( skillId
!= SKILL_NONE
)
6379 // skill bonus provided by casting spell (mostly item spells)
6380 // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value)
6381 uint32 spellSkillBonus
= uint32(m_currentBasePoints
[effIndex
]);
6382 reqSkillValue
= lockInfo
->Skill
[j
];
6384 // castitem check: rogue using skeleton keys. the skill values should not be added in this case.
6385 skillValue
= m_CastItem
|| m_caster
->GetTypeId()!= TYPEID_PLAYER
?
6386 0 : ((Player
*)m_caster
)->GetSkillValue(skillId
);
6388 skillValue
+= spellSkillBonus
;
6390 if (skillValue
< reqSkillValue
)
6391 return SPELL_FAILED_LOW_CASTLEVEL
;
6394 return SPELL_CAST_OK
;
6400 return SPELL_FAILED_BAD_TARGETS
;
6402 return SPELL_CAST_OK
;
6406 * Fill target list by units around (x,y) points at radius distance
6408 * @param targetUnitMap Reference to target list that filled by function
6409 * @param x X coordinates of center point for target search
6410 * @param y Y coordinates of center point for target search
6411 * @param radius Radius around (x,y) for target search
6412 * @param pushType Additional rules for target area selection (in front, angle, etc)
6413 * @param spellTargets Additional rules for target selection base at hostile/friendly state to original spell caster
6414 * @param originalCaster If provided set alternative original caster, if =NULL then used Spell::GetAffectiveObject() return
6416 void Spell::FillAreaTargets(UnitList
&targetUnitMap
, float x
, float y
, float radius
, SpellNotifyPushType pushType
, SpellTargets spellTargets
, WorldObject
* originalCaster
/*=NULL*/)
6418 CellPair
p(MaNGOS::ComputeCellPair(x
, y
));
6420 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
6422 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, targetUnitMap
, radius
, pushType
, spellTargets
, originalCaster
);
6423 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
6424 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
6425 cell
.Visit(p
, world_notifier
, *m_caster
->GetMap(), *m_caster
, radius
);
6426 cell
.Visit(p
, grid_notifier
, *m_caster
->GetMap(), *m_caster
, radius
);
6429 void Spell::FillRaidOrPartyTargets(UnitList
&targetUnitMap
, Unit
* member
, Unit
* center
, float radius
, bool raid
, bool withPets
, bool withcaster
)
6431 Player
*pMember
= member
->GetCharmerOrOwnerPlayerOrPlayerItself();
6432 Group
*pGroup
= pMember
? pMember
->GetGroup() : NULL
;
6436 uint8 subgroup
= pMember
->GetSubGroup();
6438 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
6440 Player
* Target
= itr
->getSource();
6442 // IsHostileTo check duel and controlled by enemy
6443 if (Target
&& (raid
|| subgroup
==Target
->GetSubGroup())
6444 && !m_caster
->IsHostileTo(Target
))
6446 if ((Target
== center
|| center
->IsWithinDistInMap(Target
, radius
)) &&
6447 (withcaster
|| Target
!= m_caster
))
6448 targetUnitMap
.push_back(Target
);
6451 if (Pet
* pet
= Target
->GetPet())
6452 if ((pet
== center
|| center
->IsWithinDistInMap(pet
, radius
)) &&
6453 (withcaster
|| pet
!= m_caster
))
6454 targetUnitMap
.push_back(pet
);
6460 Unit
* ownerOrSelf
= pMember
? pMember
: member
->GetCharmerOrOwnerOrSelf();
6461 if ((ownerOrSelf
== center
|| center
->IsWithinDistInMap(ownerOrSelf
, radius
)) &&
6462 (withcaster
|| ownerOrSelf
!= m_caster
))
6463 targetUnitMap
.push_back(ownerOrSelf
);
6466 if (Pet
* pet
= ownerOrSelf
->GetPet())
6467 if ((pet
== center
|| center
->IsWithinDistInMap(pet
, radius
)) &&
6468 (withcaster
|| pet
!= m_caster
))
6469 targetUnitMap
.push_back(pet
);
6473 void Spell::FillRaidOrPartyManaPriorityTargets(UnitList
&targetUnitMap
, Unit
* member
, Unit
* center
, float radius
, uint32 count
, bool raid
, bool withPets
, bool withCaster
)
6475 FillRaidOrPartyTargets(targetUnitMap
, member
, center
, radius
, raid
, withPets
, withCaster
);
6477 PrioritizeManaUnitQueue manaUsers
;
6478 for(UnitList::const_iterator itr
= targetUnitMap
.begin(); itr
!= targetUnitMap
.end() && manaUsers
.size() < count
; ++itr
)
6479 if ((*itr
)->getPowerType() == POWER_MANA
&& !(*itr
)->isDead())
6480 manaUsers
.push(PrioritizeManaUnitWraper(*itr
));
6482 targetUnitMap
.clear();
6483 while(!manaUsers
.empty())
6485 targetUnitMap
.push_back(manaUsers
.top().getUnit());
6490 void Spell::FillRaidOrPartyHealthPriorityTargets(UnitList
&targetUnitMap
, Unit
* member
, Unit
* center
, float radius
, uint32 count
, bool raid
, bool withPets
, bool withCaster
)
6492 FillRaidOrPartyTargets(targetUnitMap
, member
, center
, radius
, raid
, withPets
, withCaster
);
6494 PrioritizeHealthUnitQueue healthQueue
;
6495 for(UnitList::const_iterator itr
= targetUnitMap
.begin(); itr
!= targetUnitMap
.end() && healthQueue
.size() < count
; ++itr
)
6496 if (!(*itr
)->isDead())
6497 healthQueue
.push(PrioritizeHealthUnitWraper(*itr
));
6499 targetUnitMap
.clear();
6500 while(!healthQueue
.empty())
6502 targetUnitMap
.push_back(healthQueue
.top().getUnit());
6507 WorldObject
* Spell::GetAffectiveCasterObject() const
6509 if (m_originalCasterGUID
.IsEmpty())
6512 if (m_originalCasterGUID
.IsGameobject() && m_caster
->IsInWorld())
6513 return m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
);
6514 return m_originalCaster
;
6517 WorldObject
* Spell::GetCastingObject() const
6519 if (m_originalCasterGUID
.IsGameobject())
6520 return m_caster
->IsInWorld() ? m_caster
->GetMap()->GetGameObject(m_originalCasterGUID
) : NULL
;
6525 void Spell::ResetEffectDamageAndHeal()