2 * Copyright (C) 2005-2008 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"
36 #include "SpellAuras.h"
38 #include "UpdateData.h"
39 #include "MapManager.h"
40 #include "ObjectAccessor.h"
42 #include "Policies/SingletonImp.h"
43 #include "SharedDefines.h"
46 #include "VMapFactory.h"
47 #include "BattleGround.h"
50 #define SPELL_CHANNEL_UPDATE_INTERVAL 1000
52 extern pEffect SpellEffects
[TOTAL_SPELL_EFFECTS
];
54 bool IsQuestTameSpell(uint32 spellId
)
56 SpellEntry
const *spellproto
= sSpellStore
.LookupEntry(spellId
);
57 if (!spellproto
) return false;
59 return spellproto
->Effect
[0] == SPELL_EFFECT_THREAT
60 && spellproto
->Effect
[1] == SPELL_EFFECT_APPLY_AURA
&& spellproto
->EffectApplyAuraName
[1] == SPELL_AURA_DUMMY
;
63 SpellCastTargets::SpellCastTargets()
71 m_CorpseTargetGUID
= 0;
73 m_itemTargetEntry
= 0;
75 m_srcX
= m_srcY
= m_srcZ
= m_destX
= m_destY
= m_destZ
= 0;
80 SpellCastTargets::~SpellCastTargets()
84 void SpellCastTargets::setUnitTarget(Unit
*target
)
89 m_destX
= target
->GetPositionX();
90 m_destY
= target
->GetPositionY();
91 m_destZ
= target
->GetPositionZ();
92 m_unitTarget
= target
;
93 m_unitTargetGUID
= target
->GetGUID();
94 m_targetMask
|= TARGET_FLAG_UNIT
;
97 void SpellCastTargets::setDestination(float x
, float y
, float z
)
102 m_targetMask
|= TARGET_FLAG_DEST_LOCATION
;
105 void SpellCastTargets::setGOTarget(GameObject
*target
)
108 m_GOTargetGUID
= target
->GetGUID();
109 // m_targetMask |= TARGET_FLAG_OBJECT;
112 void SpellCastTargets::setItemTarget(Item
* item
)
118 m_itemTargetGUID
= item
->GetGUID();
119 m_itemTargetEntry
= item
->GetEntry();
120 m_targetMask
|= TARGET_FLAG_ITEM
;
123 void SpellCastTargets::setCorpseTarget(Corpse
* corpse
)
125 m_CorpseTargetGUID
= corpse
->GetGUID();
128 void SpellCastTargets::Update(Unit
* caster
)
130 m_GOTarget
= m_GOTargetGUID
? ObjectAccessor::GetGameObject(*caster
,m_GOTargetGUID
) : NULL
;
131 m_unitTarget
= m_unitTargetGUID
?
132 ( m_unitTargetGUID
==caster
->GetGUID() ? caster
: ObjectAccessor::GetUnit(*caster
, m_unitTargetGUID
) ) :
136 if(caster
->GetTypeId()==TYPEID_PLAYER
)
138 if(m_targetMask
& TARGET_FLAG_ITEM
)
139 m_itemTarget
= ((Player
*)caster
)->GetItemByGuid(m_itemTargetGUID
);
142 Player
* pTrader
= ((Player
*)caster
)->GetTrader();
143 if(pTrader
&& m_itemTargetGUID
< TRADE_SLOT_COUNT
)
144 m_itemTarget
= pTrader
->GetItemByPos(pTrader
->GetItemPosByTradeSlot(m_itemTargetGUID
));
147 m_itemTargetEntry
= m_itemTarget
->GetEntry();
151 bool SpellCastTargets::read ( WorldPacket
* data
, Unit
*caster
)
153 if(data
->rpos()+4 > data
->size())
156 *data
>> m_targetMask
;
158 if(m_targetMask
== TARGET_FLAG_SELF
)
160 m_destX
= caster
->GetPositionX();
161 m_destY
= caster
->GetPositionY();
162 m_destZ
= caster
->GetPositionZ();
163 m_unitTarget
= caster
;
164 m_unitTargetGUID
= caster
->GetGUID();
168 // TARGET_FLAG_UNK2 is used for non-combat pets, maybe other?
169 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_UNK2
))
170 if(!readGUID(*data
, m_unitTargetGUID
))
173 if( m_targetMask
& ( TARGET_FLAG_OBJECT
| TARGET_FLAG_OBJECT_UNK
))
174 if(!readGUID(*data
, m_GOTargetGUID
))
177 if(( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
)) && caster
->GetTypeId() == TYPEID_PLAYER
)
178 if(!readGUID(*data
, m_itemTargetGUID
))
181 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
183 if(data
->rpos()+4+4+4 > data
->size())
186 *data
>> m_srcX
>> m_srcY
>> m_srcZ
;
187 if(!MaNGOS::IsValidMapCoord(m_srcX
, m_srcY
, m_srcZ
))
191 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
193 if(data
->rpos()+4+4+4 > data
->size())
196 *data
>> m_destX
>> m_destY
>> m_destZ
;
197 if(!MaNGOS::IsValidMapCoord(m_destX
, m_destY
, m_destZ
))
201 if( m_targetMask
& TARGET_FLAG_STRING
)
203 if(data
->rpos()+1 > data
->size())
206 *data
>> m_strTarget
;
209 if( m_targetMask
& (TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
210 if(!readGUID(*data
, m_CorpseTargetGUID
))
213 // find real units/GOs
218 void SpellCastTargets::write ( WorldPacket
* data
)
220 *data
<< uint32(m_targetMask
);
222 if( m_targetMask
& ( TARGET_FLAG_UNIT
| TARGET_FLAG_PVP_CORPSE
| TARGET_FLAG_OBJECT
| TARGET_FLAG_CORPSE
| TARGET_FLAG_UNK2
) )
224 if(m_targetMask
& TARGET_FLAG_UNIT
)
227 data
->append(m_unitTarget
->GetPackGUID());
231 else if( m_targetMask
& ( TARGET_FLAG_OBJECT
| TARGET_FLAG_OBJECT_UNK
) )
234 data
->append(m_GOTarget
->GetPackGUID());
238 else if( m_targetMask
& ( TARGET_FLAG_CORPSE
| TARGET_FLAG_PVP_CORPSE
) )
239 data
->appendPackGUID(m_CorpseTargetGUID
);
244 if( m_targetMask
& ( TARGET_FLAG_ITEM
| TARGET_FLAG_TRADE_ITEM
) )
247 data
->append(m_itemTarget
->GetPackGUID());
252 if( m_targetMask
& TARGET_FLAG_SOURCE_LOCATION
)
253 *data
<< m_srcX
<< m_srcY
<< m_srcZ
;
255 if( m_targetMask
& TARGET_FLAG_DEST_LOCATION
)
256 *data
<< m_destX
<< m_destY
<< m_destZ
;
258 if( m_targetMask
& TARGET_FLAG_STRING
)
259 *data
<< m_strTarget
;
262 Spell::Spell( Unit
* Caster
, SpellEntry
const *info
, bool triggered
, uint64 originalCasterGUID
, Spell
** triggeringContainer
)
264 ASSERT( Caster
!= NULL
&& info
!= NULL
);
265 ASSERT( info
== sSpellStore
.LookupEntry( info
->Id
) && "`info` must be pointer to sSpellStore element");
269 m_selfContainer
= NULL
;
270 m_triggeringContainer
= triggeringContainer
;
272 m_delayAtDamageCount
= 0;
274 m_applyMultiplierMask
= 0;
276 // Get data for type of attack
277 switch (m_spellInfo
->DmgClass
)
279 case SPELL_DAMAGE_CLASS_MELEE
:
280 if (m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_REQ_OFFHAND
)
281 m_attackType
= OFF_ATTACK
;
283 m_attackType
= BASE_ATTACK
;
285 case SPELL_DAMAGE_CLASS_RANGED
:
286 m_attackType
= RANGED_ATTACK
;
290 if (m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_REQ_WAND
)
291 m_attackType
= RANGED_ATTACK
;
293 m_attackType
= BASE_ATTACK
;
297 m_spellSchoolMask
= GetSpellSchoolMask(info
); // Can be override for some spell (wand shoot for example)
299 if(m_attackType
== RANGED_ATTACK
)
302 if((m_caster
->getClassMask() & CLASSMASK_WAND_USERS
) != 0 && m_caster
->GetTypeId()==TYPEID_PLAYER
)
304 if(Item
* pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(RANGED_ATTACK
))
305 m_spellSchoolMask
= SpellSchoolMask(1 << pItem
->GetProto()->Damage
->DamageType
);
309 if(originalCasterGUID
)
310 m_originalCasterGUID
= originalCasterGUID
;
312 m_originalCasterGUID
= m_caster
->GetGUID();
314 if(m_originalCasterGUID
==m_caster
->GetGUID())
315 m_originalCaster
= m_caster
;
318 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
,m_originalCasterGUID
);
319 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
322 for(int i
=0; i
<3; ++i
)
323 m_currentBasePoints
[i
] = m_spellInfo
->EffectBasePoints
[i
];
325 m_spellState
= SPELL_STATE_NULL
;
327 m_castPositionX
= m_castPositionY
= m_castPositionZ
= 0;
328 m_TriggerSpells
.clear();
329 m_IsTriggeredSpell
= triggered
;
330 //m_AreaAura = false;
335 gameObjTarget
= NULL
;
338 m_triggeredByAuraSpell
= NULL
;
341 if( m_spellInfo
->AttributesEx2
== 0x000020 && !triggered
)
344 m_autoRepeat
= false;
346 m_powerCost
= 0; // setup to correct value in Spell::prepare, don't must be used before.
347 m_casttime
= 0; // setup to correct value in Spell::prepare, don't must be used before.
348 m_timer
= 0; // will set to castime in preper
350 m_needAliveTargetMask
= 0;
352 // determine reflection
353 m_canReflect
= false;
355 if(m_spellInfo
->DmgClass
== SPELL_DAMAGE_CLASS_MAGIC
&& (m_spellInfo
->AttributesEx2
& 0x4)==0)
359 if (m_spellInfo
->Effect
[j
]==0)
362 if(!IsPositiveTarget(m_spellInfo
->EffectImplicitTargetA
[j
],m_spellInfo
->EffectImplicitTargetB
[j
]))
365 m_canReflect
= (m_spellInfo
->AttributesEx
& (1<<7)) ? true : false;
381 void Spell::FillTargetMap()
383 // TODO: ADD the correct target FILLS!!!!!!
385 for(uint32 i
=0;i
<3;i
++)
387 // not call for empty effect.
388 // Also some spells use not used effect targets for store targets for dummy effect in triggered spells
389 if(m_spellInfo
->Effect
[i
]==0)
392 // targets for TARGET_SCRIPT_COORDINATES (A) and TARGET_SCRIPT filled in Spell::canCast call
393 if( m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT_COORDINATES
||
394 m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SCRIPT
||
395 m_spellInfo
->EffectImplicitTargetB
[i
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_SELF
)
398 // TODO: find a way so this is not needed?
399 // for area auras always add caster as target (needed for totems for example)
400 if(IsAreaAuraEffect(m_spellInfo
->Effect
[i
]))
401 AddUnitTarget(m_caster
, i
);
403 std::list
<Unit
*> tmpUnitMap
;
405 // TargetA/TargetB dependent from each other, we not switch to full support this dependences
406 // but need it support in some know cases
407 switch(m_spellInfo
->EffectImplicitTargetA
[i
])
409 case TARGET_ALL_AROUND_CASTER
:
410 if( m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_ALL_PARTY
||
411 m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER
||
412 m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_RANDOM_RAID_MEMBER
)
414 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
416 // Note: this hack with search required until GO casting not implemented
417 // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support
418 // currently each enemy selected explicitly and self cast damage
419 else if(m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_ALL_ENEMY_IN_AREA
&& m_spellInfo
->Effect
[i
]==SPELL_EFFECT_ENVIRONMENTAL_DAMAGE
)
421 if(m_targets
.getUnitTarget())
422 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
426 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
427 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
430 case TARGET_TABLE_X_Y_Z_COORDINATES
:
431 // Only if target A, for target B (used in teleports) dest select in effect
432 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
435 switch(m_spellInfo
->EffectImplicitTargetB
[i
])
437 case TARGET_SCRIPT_COORDINATES
: // B case filled in canCast but we need fill unit list base at A case
438 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
441 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetA
[i
],tmpUnitMap
);
442 SetTargetMap(i
,m_spellInfo
->EffectImplicitTargetB
[i
],tmpUnitMap
);
448 if( (m_spellInfo
->EffectImplicitTargetA
[i
]==0 || m_spellInfo
->EffectImplicitTargetA
[i
]==TARGET_EFFECT_SELECT
) &&
449 (m_spellInfo
->EffectImplicitTargetB
[i
]==0 || m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_EFFECT_SELECT
) )
451 // add here custom effects that need default target.
452 // FOR EVERY TARGET TYPE THERE IS A DIFFERENT FILL!!
453 switch(m_spellInfo
->Effect
[i
])
455 case SPELL_EFFECT_DUMMY
:
457 switch(m_spellInfo
->Id
)
459 case 20577: // Cannibalize
461 // non-standard target selection
462 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
463 float max_range
= GetSpellMaxRange(srange
);
465 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
467 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
470 WorldObject
* result
= NULL
;
472 MaNGOS::CannibalizeObjectCheck
u_check(m_caster
, max_range
);
473 MaNGOS::WorldObjectSearcher
<MaNGOS::CannibalizeObjectCheck
> searcher(result
, u_check
);
475 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<MaNGOS::CannibalizeObjectCheck
>, GridTypeMapContainer
> grid_searcher(searcher
);
476 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
477 cell_lock
->Visit(cell_lock
, grid_searcher
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
481 TypeContainerVisitor
<MaNGOS::WorldObjectSearcher
<MaNGOS::CannibalizeObjectCheck
>, WorldTypeMapContainer
> world_searcher(searcher
);
482 cell_lock
->Visit(cell_lock
, world_searcher
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
487 switch(result
->GetTypeId())
491 tmpUnitMap
.push_back((Unit
*)result
);
494 m_targets
.setCorpseTarget((Corpse
*)result
);
495 if(Player
* owner
= ObjectAccessor::FindPlayer(((Corpse
*)result
)->GetOwnerGUID()))
496 tmpUnitMap
.push_back(owner
);
502 // clear cooldown at fail
503 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
505 ((Player
*)m_caster
)->RemoveSpellCooldown(m_spellInfo
->Id
);
507 WorldPacket
data(SMSG_CLEAR_COOLDOWN
, (4+8));
508 data
<< uint32(m_spellInfo
->Id
);
509 data
<< uint64(m_caster
->GetGUID());
510 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
513 SendCastResult(SPELL_FAILED_NO_EDIBLE_CORPSES
);
519 if(m_targets
.getUnitTarget())
520 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
525 case SPELL_EFFECT_RESURRECT
:
526 case SPELL_EFFECT_PARRY
:
527 case SPELL_EFFECT_BLOCK
:
528 case SPELL_EFFECT_CREATE_ITEM
:
529 case SPELL_EFFECT_TRIGGER_SPELL
:
530 case SPELL_EFFECT_TRIGGER_MISSILE
:
531 case SPELL_EFFECT_LEARN_SPELL
:
532 case SPELL_EFFECT_SKILL_STEP
:
533 case SPELL_EFFECT_PROFICIENCY
:
534 case SPELL_EFFECT_SUMMON_POSSESSED
:
535 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
536 case SPELL_EFFECT_SELF_RESURRECT
:
537 case SPELL_EFFECT_REPUTATION
:
538 if(m_targets
.getUnitTarget())
539 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
541 case SPELL_EFFECT_SUMMON_PLAYER
:
542 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetSelection())
544 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
546 tmpUnitMap
.push_back(target
);
549 case SPELL_EFFECT_RESURRECT_NEW
:
550 if(m_targets
.getUnitTarget())
551 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
552 if(m_targets
.getCorpseTargetGUID())
554 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
557 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
559 tmpUnitMap
.push_back(owner
);
563 case SPELL_EFFECT_SUMMON
:
564 if(m_spellInfo
->EffectMiscValueB
[i
] == SUMMON_TYPE_POSESSED
|| m_spellInfo
->EffectMiscValueB
[i
] == SUMMON_TYPE_POSESSED2
)
566 if(m_targets
.getUnitTarget())
567 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
570 tmpUnitMap
.push_back(m_caster
);
572 case SPELL_EFFECT_SUMMON_CHANGE_ITEM
:
573 case SPELL_EFFECT_SUMMON_WILD
:
574 case SPELL_EFFECT_SUMMON_GUARDIAN
:
575 case SPELL_EFFECT_TRANS_DOOR
:
576 case SPELL_EFFECT_ADD_FARSIGHT
:
577 case SPELL_EFFECT_STUCK
:
578 case SPELL_EFFECT_DESTROY_ALL_TOTEMS
:
579 case SPELL_EFFECT_SUMMON_DEMON
:
580 case SPELL_EFFECT_SKILL
:
581 tmpUnitMap
.push_back(m_caster
);
583 case SPELL_EFFECT_LEARN_PET_SPELL
:
584 if(Pet
* pet
= m_caster
->GetPet())
585 tmpUnitMap
.push_back(pet
);
587 case SPELL_EFFECT_ENCHANT_ITEM
:
588 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
589 case SPELL_EFFECT_DISENCHANT
:
590 case SPELL_EFFECT_FEED_PET
:
591 case SPELL_EFFECT_PROSPECTING
:
592 if(m_targets
.getItemTarget())
593 AddItemTarget(m_targets
.getItemTarget(), i
);
595 case SPELL_EFFECT_APPLY_AURA
:
596 switch(m_spellInfo
->EffectApplyAuraName
[i
])
598 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)
599 case SPELL_AURA_ADD_PCT_MODIFIER
:
600 tmpUnitMap
.push_back(m_caster
);
602 default: // apply to target in other case
603 if(m_targets
.getUnitTarget())
604 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
608 case SPELL_EFFECT_APPLY_AREA_AURA_PARTY
:
610 if(m_spellInfo
->Attributes
== 0x9050000 || m_spellInfo
->Attributes
== 0x10000)
611 SetTargetMap(i
,TARGET_AREAEFFECT_PARTY
,tmpUnitMap
);
613 case SPELL_EFFECT_SKIN_PLAYER_CORPSE
:
614 if(m_targets
.getUnitTarget())
616 tmpUnitMap
.push_back(m_targets
.getUnitTarget());
618 else if (m_targets
.getCorpseTargetGUID())
620 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
623 Player
* owner
= ObjectAccessor::FindPlayer(corpse
->GetOwnerGUID());
625 tmpUnitMap
.push_back(owner
);
633 if(IsChanneledSpell(m_spellInfo
) && !tmpUnitMap
.empty())
634 m_needAliveTargetMask
|= (1<<i
);
636 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
638 Player
*me
= (Player
*)m_caster
;
639 for (std::list
<Unit
*>::const_iterator itr
= tmpUnitMap
.begin(); itr
!= tmpUnitMap
.end(); itr
++)
641 Unit
*owner
= (*itr
)->GetOwner();
642 Unit
*u
= owner
? owner
: (*itr
);
643 if(u
!=m_caster
&& u
->IsPvP() && (!me
->duel
|| me
->duel
->opponent
!= u
))
646 me
->RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_ENTER_PVP_COMBAT
);
652 for (std::list
<Unit
*>::iterator itr
= tmpUnitMap
.begin() ; itr
!= tmpUnitMap
.end();)
654 if(!CheckTarget(*itr
, i
, false ))
656 itr
= tmpUnitMap
.erase(itr
);
663 for(std::list
<Unit
*>::iterator iunit
= tmpUnitMap
.begin();iunit
!= tmpUnitMap
.end();++iunit
)
664 AddUnitTarget((*iunit
), i
);
668 void Spell::CleanupTargetList()
670 m_UniqueTargetInfo
.clear();
671 m_UniqueGOTargetInfo
.clear();
672 m_UniqueItemInfo
.clear();
678 void Spell::AddUnitTarget(Unit
* pVictim
, uint32 effIndex
)
680 if( m_spellInfo
->Effect
[effIndex
]==0 )
683 uint64 targetGUID
= pVictim
->GetGUID();
685 // Lookup target in already in list
686 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
688 if (targetGUID
== ihit
->targetGUID
) // Found in list
690 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask
695 // This is new target calculate data for him
697 // Get spell hit result on target
699 target
.targetGUID
= targetGUID
; // Store target GUID
700 target
.effectMask
= 1<<effIndex
; // Store index of effect
701 target
.processed
= false; // Effects not apply on target
703 // Calculate hit result
704 target
.missCondition
= m_caster
->SpellHitResult(pVictim
, m_spellInfo
, m_canReflect
);
705 if (target
.missCondition
== SPELL_MISS_NONE
)
710 // Spell have speed - need calculate incoming time
711 if (m_spellInfo
->speed
> 0.0f
)
713 // calculate spell incoming interval
714 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
715 if (dist
< 5.0f
) dist
= 5.0f
;
716 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
718 // Calculate minimum incoming time
719 if (m_delayMoment
==0 || m_delayMoment
>target
.timeDelay
)
720 m_delayMoment
= target
.timeDelay
;
723 target
.timeDelay
= 0LL;
725 // If target reflect spell back to caster
726 if (target
.missCondition
==SPELL_MISS_REFLECT
)
728 // Calculate reflected spell result on caster
729 target
.reflectResult
= m_caster
->SpellHitResult(m_caster
, m_spellInfo
, m_canReflect
);
731 if (target
.reflectResult
== SPELL_MISS_REFLECT
) // Impossible reflect again, so simply deflect spell
732 target
.reflectResult
= SPELL_MISS_PARRY
;
734 // Increase time interval for reflected spells by 1.5
735 target
.timeDelay
+=target
.timeDelay
>>1;
738 target
.reflectResult
= SPELL_MISS_NONE
;
740 // Add target to list
741 m_UniqueTargetInfo
.push_back(target
);
744 void Spell::AddUnitTarget(uint64 unitGUID
, uint32 effIndex
)
746 Unit
* unit
= m_caster
->GetGUID()==unitGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, unitGUID
);
748 AddUnitTarget(unit
, effIndex
);
751 void Spell::AddGOTarget(GameObject
* pVictim
, uint32 effIndex
)
753 if( m_spellInfo
->Effect
[effIndex
]==0 )
756 uint64 targetGUID
= pVictim
->GetGUID();
758 // Lookup target in already in list
759 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
761 if (targetGUID
== ihit
->targetGUID
) // Found in list
763 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask
768 // This is new target calculate data for him
771 target
.targetGUID
= targetGUID
;
772 target
.effectMask
= 1<<effIndex
;
773 target
.processed
= false; // Effects not apply on target
775 // Spell have speed - need calculate incoming time
776 if (m_spellInfo
->speed
> 0.0f
)
778 // calculate spell incoming interval
779 float dist
= m_caster
->GetDistance(pVictim
->GetPositionX(), pVictim
->GetPositionY(), pVictim
->GetPositionZ());
780 if (dist
< 5.0f
) dist
= 5.0f
;
781 target
.timeDelay
= (uint64
) floor(dist
/ m_spellInfo
->speed
* 1000.0f
);
782 if (m_delayMoment
==0 || m_delayMoment
>target
.timeDelay
)
783 m_delayMoment
= target
.timeDelay
;
786 target
.timeDelay
= 0LL;
790 // Add target to list
791 m_UniqueGOTargetInfo
.push_back(target
);
794 void Spell::AddGOTarget(uint64 goGUID
, uint32 effIndex
)
796 GameObject
* go
= ObjectAccessor::GetGameObject(*m_caster
, goGUID
);
798 AddGOTarget(go
, effIndex
);
801 void Spell::AddItemTarget(Item
* pitem
, uint32 effIndex
)
803 if( m_spellInfo
->Effect
[effIndex
]==0 )
806 // Lookup target in already in list
807 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
809 if (pitem
== ihit
->item
) // Found in list
811 ihit
->effectMask
|= 1<<effIndex
; // Add only effect mask
816 // This is new target add data
818 ItemTargetInfo target
;
820 target
.effectMask
= 1<<effIndex
;
821 m_UniqueItemInfo
.push_back(target
);
824 void Spell::doTriggers(SpellMissInfo missInfo
, uint32 damage
, SpellSchoolMask damageSchoolMask
, uint32 block
, uint32 absorb
, bool crit
)
826 // Do triggers depends from hit result (triggers on hit do in effects)
827 // Set aura states depends from hit result
828 if (missInfo
!=SPELL_MISS_NONE
)
830 // Miss/dodge/parry/block only for melee based spells
831 // Resist only for magic based spells
834 case SPELL_MISS_MISS
:
835 if(m_caster
->GetTypeId()== TYPEID_PLAYER
)
836 ((Player
*)m_caster
)->UpdateWeaponSkill(BASE_ATTACK
);
838 m_caster
->CastMeleeProcDamageAndSpell(unitTarget
, 0, damageSchoolMask
, m_attackType
, MELEE_HIT_MISS
, m_spellInfo
, m_IsTriggeredSpell
);
840 case SPELL_MISS_RESIST
:
841 m_caster
->ProcDamageAndSpell(unitTarget
, PROC_FLAG_TARGET_RESISTS
, PROC_FLAG_RESIST_SPELL
, 0, damageSchoolMask
, m_spellInfo
, m_IsTriggeredSpell
);
843 case SPELL_MISS_DODGE
:
844 if(unitTarget
->GetTypeId() == TYPEID_PLAYER
)
845 ((Player
*)unitTarget
)->UpdateDefense();
848 if (m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_caster
->getClass() == CLASS_WARRIOR
)
850 ((Player
*) m_caster
)->AddComboPoints(unitTarget
, 1);
851 m_caster
->StartReactiveTimer( REACTIVE_OVERPOWER
);
855 if (unitTarget
->getClass() != CLASS_ROGUE
)
857 unitTarget
->ModifyAuraState(AURA_STATE_DEFENSE
, true);
858 unitTarget
->StartReactiveTimer( REACTIVE_DEFENSE
);
861 m_caster
->CastMeleeProcDamageAndSpell(unitTarget
, 0, damageSchoolMask
, m_attackType
, MELEE_HIT_DODGE
, m_spellInfo
, m_IsTriggeredSpell
);
863 case SPELL_MISS_PARRY
:
864 // Update victim defense ?
865 if(unitTarget
->GetTypeId() == TYPEID_PLAYER
)
866 ((Player
*)unitTarget
)->UpdateDefense();
867 // Mongoose bite - set only Counterattack here
868 if (unitTarget
->getClass() == CLASS_HUNTER
)
870 unitTarget
->ModifyAuraState(AURA_STATE_HUNTER_PARRY
,true);
871 unitTarget
->StartReactiveTimer( REACTIVE_HUNTER_PARRY
);
875 unitTarget
->ModifyAuraState(AURA_STATE_DEFENSE
, true);
876 unitTarget
->StartReactiveTimer( REACTIVE_DEFENSE
);
878 m_caster
->CastMeleeProcDamageAndSpell(unitTarget
, 0, damageSchoolMask
, m_attackType
, MELEE_HIT_PARRY
, m_spellInfo
, m_IsTriggeredSpell
);
880 case SPELL_MISS_BLOCK
:
881 unitTarget
->ModifyAuraState(AURA_STATE_DEFENSE
, true);
882 unitTarget
->StartReactiveTimer( REACTIVE_DEFENSE
);
884 m_caster
->CastMeleeProcDamageAndSpell(unitTarget
, 0, damageSchoolMask
, m_attackType
, MELEE_HIT_BLOCK
, m_spellInfo
, m_IsTriggeredSpell
);
886 // Trigger from this events not supported
887 case SPELL_MISS_EVADE
:
888 case SPELL_MISS_IMMUNE
:
889 case SPELL_MISS_IMMUNE2
:
890 case SPELL_MISS_DEFLECT
:
891 case SPELL_MISS_ABSORB
:
892 // Trigger from reflects need do after get reflect result
893 case SPELL_MISS_REFLECT
:
901 void Spell::DoAllEffectOnTarget(TargetInfo
*target
)
903 if (target
->processed
) // Check target
905 target
->processed
= true; // Target checked in apply effects procedure
907 // Get mask of effects for target
908 uint32 mask
= target
->effectMask
;
909 if (mask
== 0) // No effects
912 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
916 SpellMissInfo missInfo
= target
->missCondition
;
917 // Need init unitTarget by default unit (can changed in code on reflect)
918 // Or on missInfo!=SPELL_MISS_NONE unitTarget undefined (but need in trigger subsystem)
921 if (missInfo
==SPELL_MISS_NONE
) // In case spell hit target, do all effect on that target
922 DoSpellHitOnUnit(unit
, mask
);
923 else if (missInfo
== SPELL_MISS_REFLECT
) // In case spell reflect from target, do all effect on caster (if hit)
925 if (target
->reflectResult
== SPELL_MISS_NONE
) // If reflected spell hit caster -> do all effect on him
926 DoSpellHitOnUnit(m_caster
, mask
);
929 // Do triggers only on miss/resist/parry/dodge
930 if (missInfo
!=SPELL_MISS_NONE
)
931 doTriggers(missInfo
);
933 // Call scripted function for AI if this spell is casted upon a creature (except pets)
934 if(IS_CREATURE_GUID(target
->targetGUID
))
936 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
937 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
938 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
939 ((Player
*)m_caster
)->CastedCreatureOrGO(unit
->GetEntry(),unit
->GetGUID(),m_spellInfo
->Id
);
941 if(((Creature
*)unit
)->AI())
942 ((Creature
*)unit
)->AI()->SpellHit(m_caster
,m_spellInfo
);
946 void Spell::DoSpellHitOnUnit(Unit
*unit
, const uint32 effectMask
)
948 if(!unit
|| !effectMask
)
951 // Recheck immune (only for delayed spells)
952 if( m_spellInfo
->speed
&& (
953 unit
->IsImmunedToDamage(GetSpellSchoolMask(m_spellInfo
),true) ||
954 unit
->IsImmunedToSpell(m_spellInfo
,true) ))
956 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_IMMUNE
);
960 if( m_caster
!= unit
)
962 if( !m_caster
->IsFriendlyTo(unit
) )
964 // for delayed spells ignore not visible explicit target
965 if(m_spellInfo
->speed
> 0.0f
&& unit
==m_targets
.getUnitTarget() && !unit
->isVisibleForOrDetect(m_caster
,false))
967 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
971 // exclude Arcane Missiles Dummy Aura aura for now (attack on hit)
972 // TODO: find way to not need this?
973 if(!(m_spellInfo
->SpellFamilyName
== SPELLFAMILY_MAGE
&&
974 m_spellInfo
->SpellFamilyFlags
& 0x800LL
))
976 unit
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
978 if( !(m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_NO_INITIAL_AGGRO
) )
980 if(!unit
->IsStandState() && !unit
->hasUnitState(UNIT_STAT_STUNNED
))
981 unit
->SetStandState(PLAYER_STATE_NONE
);
983 if(!unit
->isInCombat() && unit
->GetTypeId() != TYPEID_PLAYER
&& ((Creature
*)unit
)->AI())
984 ((Creature
*)unit
)->AI()->AttackStart(m_caster
);
986 unit
->SetInCombatWith(m_caster
);
987 m_caster
->SetInCombatWith(unit
);
989 if(Player
*attackedPlayer
= unit
->GetCharmerOrOwnerPlayerOrPlayerItself())
991 m_caster
->SetContestedPvP(attackedPlayer
);
993 unit
->AddThreat(m_caster
, 0.0f
);
999 // for delayed spells ignore negative spells (after duel end) for friendly targets
1000 if(m_spellInfo
->speed
> 0.0f
&& !IsPositiveSpell(m_spellInfo
->Id
))
1002 m_caster
->SendSpellMiss(unit
, m_spellInfo
->Id
, SPELL_MISS_EVADE
);
1006 // assisting case, healing and resurrection
1007 if(unit
->hasUnitState(UNIT_STAT_ATTACK_PLAYER
))
1008 m_caster
->SetContestedPvP();
1009 if( unit
->isInCombat() && !(m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_NO_INITIAL_AGGRO
) )
1011 m_caster
->SetInCombatState(unit
->GetCombatTimer() > 0);
1012 unit
->getHostilRefManager().threatAssist(m_caster
, 0.0f
);
1017 // Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
1018 m_diminishGroup
= GetDiminishingReturnsGroupForSpell(m_spellInfo
,m_triggeredByAuraSpell
);
1019 m_diminishLevel
= unit
->GetDiminishing(m_diminishGroup
);
1020 // Increase Diminishing on unit, current informations for actually casts will use values above
1021 if((GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_PLAYER
&& unit
->GetTypeId() == TYPEID_PLAYER
) || GetDiminishingReturnsGroupType(m_diminishGroup
) == DRTYPE_ALL
)
1022 unit
->IncrDiminishing(m_diminishGroup
);
1024 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1026 if (effectMask
& (1<<effectNumber
))
1028 HandleEffects(unit
,NULL
,NULL
,effectNumber
,m_damageMultipliers
[effectNumber
]);
1029 if ( m_applyMultiplierMask
& (1 << effectNumber
) )
1032 float multiplier
= m_spellInfo
->DmgMultiplier
[effectNumber
];
1033 // Apply multiplier mods
1034 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1035 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_EFFECT_PAST_FIRST
, multiplier
,this);
1036 m_damageMultipliers
[effectNumber
] *= multiplier
;
1042 void Spell::DoAllEffectOnTarget(GOTargetInfo
*target
)
1044 if (target
->processed
) // Check target
1046 target
->processed
= true; // Target checked in apply effects procedure
1048 uint32 effectMask
= target
->effectMask
;
1052 GameObject
* go
= ObjectAccessor::GetGameObject(*m_caster
, target
->targetGUID
);
1056 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1057 if (effectMask
& (1<<effectNumber
))
1058 HandleEffects(NULL
,NULL
,go
,effectNumber
);
1060 // cast at creature (or GO) quest objectives update at successful cast finished (+channel finished)
1061 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
1062 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsAutoRepeat() && !IsNextMeleeSwingSpell() && !IsChannelActive() )
1063 ((Player
*)m_caster
)->CastedCreatureOrGO(go
->GetEntry(),go
->GetGUID(),m_spellInfo
->Id
);
1066 void Spell::DoAllEffectOnTarget(ItemTargetInfo
*target
)
1068 uint32 effectMask
= target
->effectMask
;
1069 if(!target
->item
|| !effectMask
)
1072 for(uint32 effectNumber
=0;effectNumber
<3;effectNumber
++)
1073 if (effectMask
& (1<<effectNumber
))
1074 HandleEffects(NULL
, target
->item
, NULL
, effectNumber
);
1077 bool Spell::IsAliveUnitPresentInTargetList()
1079 // Not need check return true
1080 if (m_needAliveTargetMask
== 0)
1083 uint8 needAliveTargetMask
= m_needAliveTargetMask
;
1085 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
1087 if( ihit
->missCondition
== SPELL_MISS_NONE
&& (needAliveTargetMask
& ihit
->effectMask
) )
1089 Unit
*unit
= m_caster
->GetGUID()==ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
1091 if (unit
&& unit
->isAlive())
1092 needAliveTargetMask
&= ~ihit
->effectMask
; // remove from need alive mask effect that have alive target
1096 // is all effects from m_needAliveTargetMask have alive targets
1097 return needAliveTargetMask
==0;
1100 // Helper for Chain Healing
1101 // Spell target first
1102 // Raidmates then descending by injury suffered (MaxHealth - Health)
1103 // Other players/mobs then descending by injury suffered (MaxHealth - Health)
1104 struct ChainHealingOrder
: public std::binary_function
<const Unit
*, const Unit
*, bool>
1106 const Unit
* MainTarget
;
1107 ChainHealingOrder(Unit
const* Target
) : MainTarget(Target
) {};
1108 // functor for operator ">"
1109 bool operator()(Unit
const* _Left
, Unit
const* _Right
) const
1111 return (ChainHealingHash(_Left
) < ChainHealingHash(_Right
));
1113 int32
ChainHealingHash(Unit
const* Target
) const
1115 if (Target
== MainTarget
)
1117 else if (Target
->GetTypeId() == TYPEID_PLAYER
&& MainTarget
->GetTypeId() == TYPEID_PLAYER
&&
1118 ((Player
const*)Target
)->IsInSameRaidWith((Player
const*)MainTarget
))
1120 if (Target
->GetHealth() == Target
->GetMaxHealth())
1123 return 20000 - Target
->GetMaxHealth() + Target
->GetHealth();
1126 return 40000 - Target
->GetMaxHealth() + Target
->GetHealth();
1130 class ChainHealingFullHealth
: std::unary_function
<const Unit
*, bool>
1133 const Unit
* MainTarget
;
1134 ChainHealingFullHealth(const Unit
* Target
) : MainTarget(Target
) {};
1136 bool operator()(const Unit
* Target
)
1138 return (Target
!= MainTarget
&& Target
->GetHealth() == Target
->GetMaxHealth());
1142 // Helper for targets nearest to the spell target
1143 // The spell target is always first unless there is a target at _completely_ the same position (unbelievable case)
1144 struct TargetDistanceOrder
: public std::binary_function
<const Unit
, const Unit
, bool>
1146 const Unit
* MainTarget
;
1147 TargetDistanceOrder(const Unit
* Target
) : MainTarget(Target
) {};
1148 // functor for operator ">"
1149 bool operator()(const Unit
* _Left
, const Unit
* _Right
) const
1151 return (MainTarget
->GetDistance(_Left
) < MainTarget
->GetDistance(_Right
));
1155 void Spell::SetTargetMap(uint32 i
,uint32 cur
,std::list
<Unit
*> &TagUnitMap
)
1158 if (m_spellInfo
->EffectRadiusIndex
[i
])
1159 radius
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
1161 radius
= GetSpellMaxRange(sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
));
1163 if(m_originalCaster
)
1164 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1165 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RADIUS
, radius
,this);
1167 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[i
];
1168 if(m_originalCaster
)
1169 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
1170 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
1172 uint32 unMaxTargets
= m_spellInfo
->MaxAffectedTargets
;
1175 case TARGET_TOTEM_EARTH
:
1176 case TARGET_TOTEM_WATER
:
1177 case TARGET_TOTEM_AIR
:
1178 case TARGET_TOTEM_FIRE
:
1181 case TARGET_DYNAMIC_OBJECT
:
1182 case TARGET_AREAEFFECT_CUSTOM
:
1183 case TARGET_AREAEFFECT_CUSTOM_2
:
1186 TagUnitMap
.push_back(m_caster
);
1189 case TARGET_RANDOM_ENEMY_CHAIN_IN_AREA
:
1191 m_targets
.m_targetMask
= 0;
1192 unMaxTargets
= EffectChainTarget
;
1193 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1195 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1197 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1200 std::list
<Unit
*> tempUnitMap
;
1203 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(m_caster
, m_caster
, max_range
);
1204 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(tempUnitMap
, u_check
);
1206 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1207 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1209 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1210 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1211 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1214 if(tempUnitMap
.empty())
1217 tempUnitMap
.sort(TargetDistanceOrder(m_caster
));
1219 //Now to get us a random target that's in the initial range of the spell
1221 std::list
<Unit
*>::iterator itr
= tempUnitMap
.begin();
1222 while(itr
!= tempUnitMap
.end() && (*itr
)->GetDistance(m_caster
) < radius
)
1228 itr
= tempUnitMap
.begin();
1229 std::advance(itr
, rand()%t
);
1230 Unit
*pUnitTarget
= *itr
;
1231 TagUnitMap
.push_back(pUnitTarget
);
1233 tempUnitMap
.erase(itr
);
1235 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1237 t
= unMaxTargets
- 1;
1238 Unit
*prev
= pUnitTarget
;
1239 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1241 while(t
&& next
!= tempUnitMap
.end() )
1243 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
1246 if(!prev
->IsWithinLOSInMap(*next
))
1253 TagUnitMap
.push_back(prev
);
1254 tempUnitMap
.erase(next
);
1255 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1256 next
= tempUnitMap
.begin();
1263 Pet
* tmpUnit
= m_caster
->GetPet();
1264 if (!tmpUnit
) break;
1265 TagUnitMap
.push_back(tmpUnit
);
1268 case TARGET_CHAIN_DAMAGE
:
1270 if (EffectChainTarget
<= 1)
1272 Unit
* pUnitTarget
= SelectMagnetTarget();
1274 TagUnitMap
.push_back(pUnitTarget
);
1278 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1282 unMaxTargets
= EffectChainTarget
;
1285 if(m_spellInfo
->DmgClass
==SPELL_DAMAGE_CLASS_MELEE
)
1286 max_range
= radius
; //
1288 //FIXME: This very like horrible hack and wrong for most spells
1289 max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1291 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1293 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1296 Unit
* originalCaster
= GetOriginalCaster();
1299 std::list
<Unit
*> tempUnitMap
;
1302 MaNGOS::AnyAoETargetUnitInObjectRangeCheck
u_check(pUnitTarget
, originalCaster
, max_range
);
1303 MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
> searcher(tempUnitMap
, u_check
);
1305 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, WorldTypeMapContainer
> world_unit_searcher(searcher
);
1306 TypeContainerVisitor
<MaNGOS::UnitListSearcher
<MaNGOS::AnyAoETargetUnitInObjectRangeCheck
>, GridTypeMapContainer
> grid_unit_searcher(searcher
);
1308 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1309 cell_lock
->Visit(cell_lock
, world_unit_searcher
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1310 cell_lock
->Visit(cell_lock
, grid_unit_searcher
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1313 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1315 if(tempUnitMap
.empty())
1318 if(*tempUnitMap
.begin() == pUnitTarget
)
1319 tempUnitMap
.erase(tempUnitMap
.begin());
1321 TagUnitMap
.push_back(pUnitTarget
);
1322 uint32 t
= unMaxTargets
- 1;
1323 Unit
*prev
= pUnitTarget
;
1324 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1326 while(t
&& next
!= tempUnitMap
.end() )
1328 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
1331 if(!prev
->IsWithinLOSInMap(*next
))
1338 TagUnitMap
.push_back(prev
);
1339 tempUnitMap
.erase(next
);
1340 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1341 next
= tempUnitMap
.begin();
1348 case TARGET_ALL_ENEMY_IN_AREA
:
1351 case TARGET_ALL_ENEMY_IN_AREA_INSTANT
:
1353 // targets the ground, not the units in the area
1354 if (m_spellInfo
->Effect
[i
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1356 CellPair
p(MaNGOS::ComputeCellPair(m_targets
.m_destX
, m_targets
.m_destY
));
1358 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1361 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1363 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_object_notifier(notifier
);
1364 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_object_notifier(notifier
);
1366 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1367 cell_lock
->Visit(cell_lock
, world_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1368 cell_lock
->Visit(cell_lock
, grid_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1370 // exclude caster (this can be important if this not original caster)
1371 TagUnitMap
.remove(m_caster
);
1374 case TARGET_DUELVSPLAYER_COORDINATES
:
1376 if(Unit
* currentTarget
= m_targets
.getUnitTarget())
1378 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1379 TagUnitMap
.push_back(currentTarget
);
1382 case TARGET_ALL_PARTY_AROUND_CASTER
:
1383 case TARGET_ALL_PARTY_AROUND_CASTER_2
:
1384 case TARGET_ALL_PARTY
:
1386 Player
*pTarget
= m_caster
->GetCharmerOrOwnerPlayerOrPlayerItself();
1387 Group
*pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1391 uint8 subgroup
= pTarget
->GetSubGroup();
1393 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1395 Player
* Target
= itr
->getSource();
1397 // IsHostileTo check duel and controlled by enemy
1398 if( Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
) )
1400 if( m_caster
->IsWithinDistInMap(Target
, radius
) )
1401 TagUnitMap
.push_back(Target
);
1403 if(Pet
* pet
= Target
->GetPet())
1404 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1405 TagUnitMap
.push_back(pet
);
1411 Unit
* ownerOrSelf
= pTarget
? pTarget
: m_caster
->GetCharmerOrOwnerOrSelf();
1412 if(ownerOrSelf
==m_caster
|| m_caster
->IsWithinDistInMap(ownerOrSelf
, radius
))
1413 TagUnitMap
.push_back(ownerOrSelf
);
1414 if(Pet
* pet
= ownerOrSelf
->GetPet())
1415 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1416 TagUnitMap
.push_back(pet
);
1419 case TARGET_RANDOM_RAID_MEMBER
:
1421 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1422 if(Player
* target
= ((Player
*)m_caster
)->GetNextRandomRaidMember(radius
))
1423 TagUnitMap
.push_back(target
);
1425 case TARGET_SINGLE_FRIEND
:
1426 case TARGET_SINGLE_FRIEND_2
:
1428 if(m_targets
.getUnitTarget())
1429 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1431 case TARGET_NONCOMBAT_PET
:
1433 if(Unit
* target
= m_targets
.getUnitTarget())
1434 if( target
->GetTypeId() == TYPEID_UNIT
&& ((Creature
*)target
)->isPet() && ((Pet
*)target
)->getPetType() == MINI_PET
)
1435 TagUnitMap
.push_back(target
);
1437 case TARGET_ALL_AROUND_CASTER
:
1439 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1441 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1444 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, PUSH_SELF_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1446 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_object_notifier(notifier
);
1447 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_object_notifier(notifier
);
1449 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1450 cell_lock
->Visit(cell_lock
, world_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1451 cell_lock
->Visit(cell_lock
, grid_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1453 case TARGET_ALL_FRIENDLY_UNITS_AROUND_CASTER
:
1455 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1457 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1460 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, PUSH_SELF_CENTER
,SPELL_TARGETS_FRIENDLY
);
1462 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_object_notifier(notifier
);
1463 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_object_notifier(notifier
);
1465 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1466 cell_lock
->Visit(cell_lock
, world_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1467 cell_lock
->Visit(cell_lock
, grid_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1469 case TARGET_ALL_FRIENDLY_UNITS_IN_AREA
:
1471 CellPair
p(MaNGOS::ComputeCellPair(m_targets
.m_destX
, m_targets
.m_destY
));
1473 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1476 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, PUSH_DEST_CENTER
,SPELL_TARGETS_FRIENDLY
);
1478 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_object_notifier(notifier
);
1479 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_object_notifier(notifier
);
1481 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1482 cell_lock
->Visit(cell_lock
, world_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1483 cell_lock
->Visit(cell_lock
, grid_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1485 // TARGET_SINGLE_PARTY means that the spells can only be casted on a party member and not on the caster (some sceals, fire shield from imp, etc..)
1486 case TARGET_SINGLE_PARTY
:
1488 Unit
*target
= m_targets
.getUnitTarget();
1489 // Thoses spells apparently can't be casted on the caster.
1490 if( target
&& target
!= m_caster
)
1492 // Can only be casted on group's members or its pets
1493 Group
*pGroup
= NULL
;
1495 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1496 Unit
*targetOwner
= target
->GetCharmerOrOwner();
1499 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1501 if( target
== owner
)
1503 TagUnitMap
.push_back(target
);
1506 pGroup
= ((Player
*)owner
)->GetGroup();
1509 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1511 if( targetOwner
== m_caster
&& target
->GetTypeId()==TYPEID_UNIT
&& ((Creature
*)target
)->isPet())
1513 TagUnitMap
.push_back(target
);
1516 pGroup
= ((Player
*)m_caster
)->GetGroup();
1521 // Our target can also be a player's pet who's grouped with us or our pet. But can't be controlled player
1524 if( targetOwner
->GetTypeId() == TYPEID_PLAYER
&&
1525 target
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)target
)->isPet()) &&
1526 target
->GetOwnerGUID()==targetOwner
->GetGUID() &&
1527 pGroup
->IsMember(((Player
*)targetOwner
)->GetGUID()))
1529 TagUnitMap
.push_back(target
);
1532 // 1Our target can be a player who is on our group
1533 else if (target
->GetTypeId() == TYPEID_PLAYER
&& pGroup
->IsMember(((Player
*)target
)->GetGUID()))
1535 TagUnitMap
.push_back(target
);
1540 case TARGET_GAMEOBJECT
:
1542 if(m_targets
.getGOTarget())
1543 AddGOTarget(m_targets
.getGOTarget(), i
);
1545 case TARGET_IN_FRONT_OF_CASTER
:
1547 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1549 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1552 bool inFront
= m_spellInfo
->SpellVisual
!= 3879;
1553 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, inFront
? PUSH_IN_FRONT
: PUSH_IN_BACK
,SPELL_TARGETS_AOE_DAMAGE
);
1555 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_object_notifier(notifier
);
1556 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_object_notifier(notifier
);
1558 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1559 cell_lock
->Visit(cell_lock
, world_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1560 cell_lock
->Visit(cell_lock
, grid_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1562 case TARGET_DUELVSPLAYER
:
1564 Unit
*target
= m_targets
.getUnitTarget();
1567 if(m_caster
->IsFriendlyTo(target
))
1569 TagUnitMap
.push_back(target
);
1573 Unit
* pUnitTarget
= SelectMagnetTarget();
1575 TagUnitMap
.push_back(pUnitTarget
);
1579 case TARGET_GAMEOBJECT_ITEM
:
1581 if(m_targets
.getGOTargetGUID())
1582 AddGOTarget(m_targets
.getGOTarget(), i
);
1583 else if(m_targets
.getItemTarget())
1584 AddItemTarget(m_targets
.getItemTarget(), i
);
1589 if(Unit
* owner
= m_caster
->GetCharmerOrOwner())
1590 TagUnitMap
.push_back(owner
);
1593 case TARGET_ALL_ENEMY_IN_AREA_CHANNELED
:
1595 // targets the ground, not the units in the area
1596 if (m_spellInfo
->Effect
[i
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
1598 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1600 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1603 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
, PUSH_DEST_CENTER
,SPELL_TARGETS_AOE_DAMAGE
);
1605 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_object_notifier(notifier
);
1606 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_object_notifier(notifier
);
1608 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1609 cell_lock
->Visit(cell_lock
, world_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1610 cell_lock
->Visit(cell_lock
, grid_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1615 if(m_spellInfo
->Effect
[i
] != SPELL_EFFECT_DUEL
)
1616 TagUnitMap
.push_back(m_caster
);
1618 case TARGET_SINGLE_ENEMY
:
1620 Unit
* pUnitTarget
= SelectMagnetTarget();
1622 TagUnitMap
.push_back(pUnitTarget
);
1624 case TARGET_AREAEFFECT_PARTY
:
1626 Unit
* owner
= m_caster
->GetCharmerOrOwner();
1627 Player
*pTarget
= NULL
;
1631 TagUnitMap
.push_back(m_caster
);
1632 if(owner
->GetTypeId() == TYPEID_PLAYER
)
1633 pTarget
= (Player
*)owner
;
1635 else if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
1637 if(Unit
* target
= m_targets
.getUnitTarget())
1639 if( target
->GetTypeId() != TYPEID_PLAYER
)
1641 if(((Creature
*)target
)->isPet())
1643 Unit
*targetOwner
= target
->GetOwner();
1644 if(targetOwner
->GetTypeId() == TYPEID_PLAYER
)
1645 pTarget
= (Player
*)targetOwner
;
1649 pTarget
= (Player
*)target
;
1653 Group
* pGroup
= pTarget
? pTarget
->GetGroup() : NULL
;
1657 uint8 subgroup
= pTarget
->GetSubGroup();
1659 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1661 Player
* Target
= itr
->getSource();
1663 // IsHostileTo check duel and controlled by enemy
1664 if(Target
&& Target
->GetSubGroup()==subgroup
&& !m_caster
->IsHostileTo(Target
))
1666 if( pTarget
->IsWithinDistInMap(Target
, radius
) )
1667 TagUnitMap
.push_back(Target
);
1669 if(Pet
* pet
= Target
->GetPet())
1670 if( pTarget
->IsWithinDistInMap(pet
, radius
) )
1671 TagUnitMap
.push_back(pet
);
1677 if(m_caster
->IsWithinDistInMap(owner
, radius
))
1678 TagUnitMap
.push_back(owner
);
1682 TagUnitMap
.push_back(pTarget
);
1684 if(Pet
* pet
= pTarget
->GetPet())
1685 if( m_caster
->IsWithinDistInMap(pet
, radius
) )
1686 TagUnitMap
.push_back(pet
);
1692 if(m_targets
.getUnitTarget())
1693 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1694 if(m_targets
.getItemTarget())
1695 AddItemTarget(m_targets
.getItemTarget(), i
);
1697 case TARGET_SELF_FISHING
:
1699 TagUnitMap
.push_back(m_caster
);
1701 case TARGET_CHAIN_HEAL
:
1703 Unit
* pUnitTarget
= m_targets
.getUnitTarget();
1707 if (EffectChainTarget
<= 1)
1708 TagUnitMap
.push_back(pUnitTarget
);
1711 unMaxTargets
= EffectChainTarget
;
1712 float max_range
= radius
+ unMaxTargets
* CHAIN_SPELL_JUMP_RADIUS
;
1714 std::list
<Unit
*> tempUnitMap
;
1717 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1719 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1722 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, tempUnitMap
, max_range
, PUSH_SELF_CENTER
, SPELL_TARGETS_FRIENDLY
);
1724 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_object_notifier(notifier
);
1725 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_object_notifier(notifier
);
1727 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1728 cell_lock
->Visit(cell_lock
, world_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1729 cell_lock
->Visit(cell_lock
, grid_object_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1733 if(m_caster
!= pUnitTarget
&& std::find(tempUnitMap
.begin(),tempUnitMap
.end(),m_caster
) == tempUnitMap
.end() )
1734 tempUnitMap
.push_front(m_caster
);
1736 tempUnitMap
.sort(TargetDistanceOrder(pUnitTarget
));
1738 if(tempUnitMap
.empty())
1741 if(*tempUnitMap
.begin() == pUnitTarget
)
1742 tempUnitMap
.erase(tempUnitMap
.begin());
1744 TagUnitMap
.push_back(pUnitTarget
);
1745 uint32 t
= unMaxTargets
- 1;
1746 Unit
*prev
= pUnitTarget
;
1747 std::list
<Unit
*>::iterator next
= tempUnitMap
.begin();
1749 while(t
&& next
!= tempUnitMap
.end() )
1751 if(prev
->GetDistance(*next
) > CHAIN_SPELL_JUMP_RADIUS
)
1754 if(!prev
->IsWithinLOSInMap(*next
))
1760 if((*next
)->GetHealth() == (*next
)->GetMaxHealth())
1762 next
= tempUnitMap
.erase(next
);
1767 TagUnitMap
.push_back(prev
);
1768 tempUnitMap
.erase(next
);
1769 tempUnitMap
.sort(TargetDistanceOrder(prev
));
1770 next
= tempUnitMap
.begin();
1776 case TARGET_CURRENT_ENEMY_COORDINATES
:
1778 Unit
* currentTarget
= m_targets
.getUnitTarget();
1781 TagUnitMap
.push_back(currentTarget
);
1782 m_targets
.setDestination(currentTarget
->GetPositionX(), currentTarget
->GetPositionY(), currentTarget
->GetPositionZ());
1783 if(m_spellInfo
->EffectImplicitTargetB
[i
]==TARGET_ALL_ENEMY_IN_AREA_INSTANT
)
1785 CellPair
p(MaNGOS::ComputeCellPair(currentTarget
->GetPositionX(), currentTarget
->GetPositionY()));
1787 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1789 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
,PUSH_TARGET_CENTER
, SPELL_TARGETS_AOE_DAMAGE
);
1790 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
1791 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
1792 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1793 cell_lock
->Visit(cell_lock
, world_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1794 cell_lock
->Visit(cell_lock
, grid_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1798 case TARGET_AREAEFFECT_PARTY_AND_CLASS
:
1800 Player
* targetPlayer
= m_targets
.getUnitTarget() && m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
1801 ? (Player
*)m_targets
.getUnitTarget() : NULL
;
1803 Group
* pGroup
= targetPlayer
? targetPlayer
->GetGroup() : NULL
;
1806 for(GroupReference
*itr
= pGroup
->GetFirstMember(); itr
!= NULL
; itr
= itr
->next())
1808 Player
* Target
= itr
->getSource();
1810 // IsHostileTo check duel and controlled by enemy
1811 if( Target
&& targetPlayer
->IsWithinDistInMap(Target
, radius
) &&
1812 targetPlayer
->getClass() == Target
->getClass() &&
1813 !m_caster
->IsHostileTo(Target
) )
1815 TagUnitMap
.push_back(Target
);
1819 else if(m_targets
.getUnitTarget())
1820 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1823 case TARGET_TABLE_X_Y_Z_COORDINATES
:
1825 SpellTargetPosition
const* st
= spellmgr
.GetSpellTargetPosition(m_spellInfo
->Id
);
1828 if (st
->target_mapId
== m_caster
->GetMapId())
1829 m_targets
.setDestination(st
->target_X
, st
->target_Y
, st
->target_Z
);
1831 // if B==TARGET_TABLE_X_Y_Z_COORDINATES then A already fill all required targets
1832 if (m_spellInfo
->EffectImplicitTargetB
[i
] && m_spellInfo
->EffectImplicitTargetB
[i
]!=TARGET_TABLE_X_Y_Z_COORDINATES
)
1834 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
1836 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
1839 SpellTargets targetB
= SPELL_TARGETS_AOE_DAMAGE
;
1840 // Select friendly targets for positive effect
1841 if (IsPositiveEffect(m_spellInfo
->Id
, i
))
1842 targetB
= SPELL_TARGETS_FRIENDLY
;
1844 MaNGOS::SpellNotifierCreatureAndPlayer
notifier(*this, TagUnitMap
, radius
,PUSH_DEST_CENTER
, targetB
);
1846 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, WorldTypeMapContainer
> world_notifier(notifier
);
1847 TypeContainerVisitor
<MaNGOS::SpellNotifierCreatureAndPlayer
, GridTypeMapContainer
> grid_notifier(notifier
);
1849 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
1850 cell_lock
->Visit(cell_lock
, world_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1851 cell_lock
->Visit(cell_lock
, grid_notifier
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
1855 sLog
.outError( "SPELL: unknown target coordinates for spell ID %u\n", m_spellInfo
->Id
);
1857 case TARGET_BEHIND_VICTIM
:
1859 Unit
*pTarget
= m_caster
->getVictim();
1860 if(!pTarget
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
1861 pTarget
= ObjectAccessor::GetUnit(*m_caster
, ((Player
*)m_caster
)->GetSelection());
1865 float _target_x
, _target_y
, _target_z
;
1866 pTarget
->GetClosePoint(_target_x
, _target_y
, _target_z
, m_caster
->GetObjectSize(), CONTACT_DISTANCE
, M_PI
);
1867 if(pTarget
->IsWithinLOS(_target_x
,_target_y
,_target_z
))
1868 m_targets
.setDestination(_target_x
, _target_y
, _target_z
);
1875 if (unMaxTargets
&& TagUnitMap
.size() > unMaxTargets
)
1877 // make sure one unit is always removed per iteration
1878 uint32 removed_utarget
= 0;
1879 for (std::list
<Unit
*>::iterator itr
= TagUnitMap
.begin(), next
; itr
!= TagUnitMap
.end(); itr
= next
)
1883 if (!*itr
) continue;
1884 if ((*itr
) == m_targets
.getUnitTarget())
1886 TagUnitMap
.erase(itr
);
1887 removed_utarget
= 1;
1891 // remove random units from the map
1892 while (TagUnitMap
.size() > unMaxTargets
- removed_utarget
)
1894 uint32 poz
= urand(0, TagUnitMap
.size()-1);
1895 for (std::list
<Unit
*>::iterator itr
= TagUnitMap
.begin(); itr
!= TagUnitMap
.end(); ++itr
, --poz
)
1897 if (!*itr
) continue;
1900 TagUnitMap
.erase(itr
);
1905 // the player's target will always be added to the map
1906 if (removed_utarget
&& m_targets
.getUnitTarget())
1907 TagUnitMap
.push_back(m_targets
.getUnitTarget());
1911 void Spell::prepare(SpellCastTargets
* targets
, Aura
* triggeredByAura
)
1913 m_targets
= *targets
;
1915 m_spellState
= SPELL_STATE_PREPARING
;
1917 m_castPositionX
= m_caster
->GetPositionX();
1918 m_castPositionY
= m_caster
->GetPositionY();
1919 m_castPositionZ
= m_caster
->GetPositionZ();
1920 m_castOrientation
= m_caster
->GetOrientation();
1923 m_triggeredByAuraSpell
= triggeredByAura
->GetSpellProto();
1925 // create and add update event for this spell
1926 SpellEvent
* Event
= new SpellEvent(this);
1927 m_caster
->m_Events
.AddEvent(Event
, m_caster
->m_Events
.CalculateTime(1));
1929 //Prevent casting at cast another spell (ServerSide check)
1930 if(m_caster
->IsNonMeleeSpellCasted(false, true) && m_cast_count
)
1932 SendCastResult(SPELL_FAILED_SPELL_IN_PROGRESS
);
1938 m_powerCost
= CalculatePowerCost();
1940 uint8 result
= CanCast(true);
1941 if(result
!= 0 && !IsAutoRepeat()) //always cast autorepeat dummy for triggering
1945 SendChannelUpdate(0);
1946 triggeredByAura
->SetAuraDuration(0);
1948 SendCastResult(result
);
1953 // calculate cast time (calculated after first CanCast check to prevent charge counting for first CanCast fail)
1954 m_casttime
= GetSpellCastTime(m_spellInfo
, this);
1956 // set timer base at cast time
1959 // stealth must be removed at cast starting (at show channel bar)
1960 // skip triggered spell (item equip spell casting and other not explicit character casts/item uses)
1961 if ( !m_IsTriggeredSpell
&& isSpellBreakStealth(m_spellInfo
) )
1963 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_MOD_STEALTH
);
1964 m_caster
->RemoveSpellsCausingAura(SPELL_AURA_FEIGN_DEATH
);
1967 if(m_IsTriggeredSpell
)
1971 m_caster
->SetCurrentCastedSpell( this );
1972 m_selfContainer
= &(m_caster
->m_currentSpells
[GetCurrentContainer()]);
1977 void Spell::cancel()
1979 if(m_spellState
== SPELL_STATE_FINISHED
)
1982 m_autoRepeat
= false;
1983 switch (m_spellState
)
1985 case SPELL_STATE_PREPARING
:
1986 case SPELL_STATE_DELAYED
:
1989 SendCastResult(SPELL_FAILED_INTERRUPTED
);
1992 case SPELL_STATE_CASTING
:
1994 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
1996 if( ihit
->missCondition
== SPELL_MISS_NONE
)
1998 Unit
* unit
= m_caster
->GetGUID()==(*ihit
).targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
1999 if( unit
&& unit
->isAlive() )
2000 unit
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2004 m_caster
->RemoveAurasDueToSpell(m_spellInfo
->Id
);
2005 SendChannelUpdate(0);
2007 SendCastResult(SPELL_FAILED_INTERRUPTED
);
2016 m_caster
->RemoveDynObject(m_spellInfo
->Id
);
2017 m_caster
->RemoveGameObject(m_spellInfo
->Id
,true);
2020 void Spell::cast(bool skipCheck
)
2022 uint8 castResult
= 0;
2024 // update pointers base at GUIDs to prevent access to non-existed already object
2027 // cancel at lost main target unit
2028 if(!m_targets
.getUnitTarget() && m_targets
.getUnitTargetGUID() && m_targets
.getUnitTargetGUID() != m_caster
->GetGUID())
2034 if(m_caster
->GetTypeId() != TYPEID_PLAYER
&& m_targets
.getUnitTarget() && m_targets
.getUnitTarget() != m_caster
)
2035 m_caster
->SetInFront(m_targets
.getUnitTarget());
2037 castResult
= CheckPower();
2040 SendCastResult(castResult
);
2045 // triggered cast called from Spell::prepare where it was already checked
2048 castResult
= CanCast(false);
2051 SendCastResult(castResult
);
2057 // Conflagrate - consumes immolate
2058 if ((m_spellInfo
->TargetAuraState
== AURA_STATE_IMMOLATE
) && m_targets
.getUnitTarget())
2060 // for caster applied auras only
2061 Unit::AuraList
const &mPeriodic
= m_targets
.getUnitTarget()->GetAurasByType(SPELL_AURA_PERIODIC_DAMAGE
);
2062 for(Unit::AuraList::const_iterator i
= mPeriodic
.begin(); i
!= mPeriodic
.end(); ++i
)
2064 if( (*i
)->GetSpellProto()->SpellFamilyName
== SPELLFAMILY_WARLOCK
&& ((*i
)->GetSpellProto()->SpellFamilyFlags
& 4) &&
2065 (*i
)->GetCasterGUID()==m_caster
->GetGUID() )
2067 m_targets
.getUnitTarget()->RemoveAura((*i
)->GetId(), (*i
)->GetEffIndex());
2073 // traded items have trade slot instead of guid in m_itemTargetGUID
2074 // set to real guid to be sent later to the client
2075 m_targets
.updateTradeSlotItem();
2078 SendSpellCooldown();
2081 TakeReagents(); // we must remove reagents before HandleEffects to allow place crafted item in same slot
2084 if(m_spellState
== SPELL_STATE_FINISHED
) // stop cast if spell marked as finish somewhere in Take*/FillTargetMap
2087 SendCastResult(castResult
);
2088 SendSpellGo(); // we must send smsg_spell_go packet before m_castItem delete in TakeCastItem()...
2090 // Pass cast spell event to handler (not send triggered by aura spells)
2091 if (m_spellInfo
->DmgClass
!= SPELL_DAMAGE_CLASS_MELEE
&& m_spellInfo
->DmgClass
!= SPELL_DAMAGE_CLASS_RANGED
&& !m_triggeredByAuraSpell
)
2093 m_caster
->ProcDamageAndSpell(m_targets
.getUnitTarget(), PROC_FLAG_CAST_SPELL
, PROC_FLAG_NONE
, 0, SPELL_SCHOOL_MASK_NONE
, m_spellInfo
, m_IsTriggeredSpell
);
2095 // update pointers base at GUIDs to prevent access to non-existed already object
2096 UpdatePointers(); // pointers can be invalidate at triggered spell casting
2099 // Okay, everything is prepared. Now we need to distinguish between immediate and evented delayed spells
2100 if (m_spellInfo
->speed
> 0.0f
)
2103 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2104 // in case delayed spell remove item at cast delay start
2107 // Okay, maps created, now prepare flags
2108 m_immediateHandled
= false;
2109 m_spellState
= SPELL_STATE_DELAYED
;
2114 // Immediate spell, no big deal
2119 void Spell::handle_immediate()
2121 // start channeling if applicable
2122 if(IsChanneledSpell(m_spellInfo
))
2124 m_spellState
= SPELL_STATE_CASTING
;
2125 SendChannelStart(GetSpellDuration(m_spellInfo
));
2128 // process immediate effects (items, ground, etc.) also initialize some variables
2129 _handle_immediate_phase();
2131 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2132 DoAllEffectOnTarget(&(*ihit
));
2134 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2135 DoAllEffectOnTarget(&(*ihit
));
2137 // spell is finished, perform some last features of the spell here
2138 _handle_finish_phase();
2140 // Remove used for cast item if need (it can be already NULL after TakeReagents call
2143 if(m_spellState
!= SPELL_STATE_CASTING
)
2144 finish(true); // successfully finish spell cast (not last in case autorepeat or channel spell)
2147 uint64
Spell::handle_delayed(uint64 t_offset
)
2149 uint64 next_time
= 0;
2151 if (!m_immediateHandled
)
2153 _handle_immediate_phase();
2154 m_immediateHandled
= true;
2157 // 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)
2158 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin(); ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2160 if (ihit
->processed
== false)
2162 if ( ihit
->timeDelay
<= t_offset
)
2163 DoAllEffectOnTarget(&(*ihit
));
2164 else if( next_time
== 0 || ihit
->timeDelay
< next_time
)
2165 next_time
= ihit
->timeDelay
;
2169 // now recheck gameobject targeting correctness
2170 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin(); ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
2172 if (ighit
->processed
== false)
2174 if ( ighit
->timeDelay
<= t_offset
)
2175 DoAllEffectOnTarget(&(*ighit
));
2176 else if( next_time
== 0 || ighit
->timeDelay
< next_time
)
2177 next_time
= ighit
->timeDelay
;
2180 // All targets passed - need finish phase
2183 // spell is finished, perform some last features of the spell here
2184 _handle_finish_phase();
2186 finish(true); // successfully finish spell cast
2188 // return zero, spell is finished now
2193 // spell is unfinished, return next execution time
2198 void Spell::_handle_immediate_phase()
2200 // handle some immediate features of the spell here
2201 HandleThreatSpells(m_spellInfo
->Id
);
2203 m_needSpellLog
= IsNeedSendToClient();
2204 for(uint32 j
= 0;j
<3;j
++)
2206 if(m_spellInfo
->Effect
[j
]==0)
2209 // apply Send Event effect to ground in case empty target lists
2210 if( m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SEND_EVENT
&& !HaveTargetsForEffect(j
) )
2212 HandleEffects(NULL
,NULL
,NULL
, j
);
2216 // Don't do spell log, if is school damage spell
2217 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_SCHOOL_DAMAGE
|| m_spellInfo
->Effect
[j
] == 0)
2218 m_needSpellLog
= false;
2220 uint32 EffectChainTarget
= m_spellInfo
->EffectChainTarget
[j
];
2221 if(m_originalCaster
)
2222 if(Player
* modOwner
= m_originalCaster
->GetSpellModOwner())
2223 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_JUMP_TARGETS
, EffectChainTarget
, this);
2225 // initialize multipliers
2226 m_damageMultipliers
[j
] = 1.0f
;
2227 if( (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_CHAIN_HEAL
) &&
2228 (EffectChainTarget
> 1) )
2229 m_applyMultiplierMask
|= 1 << j
;
2232 // initialize Diminishing Returns Data
2233 m_diminishLevel
= DIMINISHING_LEVEL_1
;
2234 m_diminishGroup
= DIMINISHING_NONE
;
2237 for(std::list
<ItemTargetInfo
>::iterator ihit
= m_UniqueItemInfo
.begin();ihit
!= m_UniqueItemInfo
.end();++ihit
)
2238 DoAllEffectOnTarget(&(*ihit
));
2241 for(uint32 j
= 0;j
<3;j
++)
2243 // persistent area auras target only the ground
2244 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_PERSISTENT_AREA_AURA
)
2245 HandleEffects(NULL
,NULL
,NULL
, j
);
2249 void Spell::_handle_finish_phase()
2256 void Spell::SendSpellCooldown()
2258 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
2261 Player
* _player
= (Player
*)m_caster
;
2262 // Add cooldown for max (disable spell)
2263 // Cooldown started on SendCooldownEvent call
2264 if (m_spellInfo
->Attributes
& SPELL_ATTR_DISABLED_WHILE_ACTIVE
)
2266 _player
->AddSpellCooldown(m_spellInfo
->Id
, 0, time(NULL
) - 1);
2270 // init cooldown values
2275 // some special item spells without correct cooldown in SpellInfo
2276 // cooldown information stored in item prototype
2277 // This used in same way in WorldSession::HandleItemQuerySingleOpcode data sending to client.
2281 ItemPrototype
const* proto
= m_CastItem
->GetProto();
2284 for(int idx
= 0; idx
< 5; ++idx
)
2286 if(proto
->Spells
[idx
].SpellId
== m_spellInfo
->Id
)
2288 cat
= proto
->Spells
[idx
].SpellCategory
;
2289 rec
= proto
->Spells
[idx
].SpellCooldown
;
2290 catrec
= proto
->Spells
[idx
].SpellCategoryCooldown
;
2297 // if no cooldown found above then base at DBC data
2298 if(rec
< 0 && catrec
< 0)
2300 cat
= m_spellInfo
->Category
;
2301 rec
= m_spellInfo
->RecoveryTime
;
2302 catrec
= m_spellInfo
->CategoryRecoveryTime
;
2305 // shoot spells used equipped item cooldown values already assigned in GetAttackTime(RANGED_ATTACK)
2306 // prevent 0 cooldowns set by another way
2307 if (rec
<= 0 && catrec
<= 0 && (cat
== 76 || cat
== 351))
2308 rec
= _player
->GetAttackTime(RANGED_ATTACK
);
2310 // Now we have cooldown data (if found any), time to apply mods
2312 _player
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COOLDOWN
, rec
, this);
2315 _player
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COOLDOWN
, catrec
, this);
2317 // replace negative cooldowns by 0
2318 if (rec
< 0) rec
= 0;
2319 if (catrec
< 0) catrec
= 0;
2321 // no cooldown after applying spell mods
2322 if( rec
== 0 && catrec
== 0)
2325 time_t curTime
= time(NULL
);
2327 time_t catrecTime
= catrec
? curTime
+catrec
/1000 : 0; // in secs
2328 time_t recTime
= rec
? curTime
+rec
/1000 : catrecTime
;// in secs
2330 // self spell cooldown
2332 _player
->AddSpellCooldown(m_spellInfo
->Id
, m_CastItem
? m_CastItem
->GetEntry() : 0, recTime
);
2337 SpellCategoryStore::const_iterator i_scstore
= sSpellCategoryStore
.find(cat
);
2338 if(i_scstore
!= sSpellCategoryStore
.end())
2340 for(SpellCategorySet::const_iterator i_scset
= i_scstore
->second
.begin(); i_scset
!= i_scstore
->second
.end(); ++i_scset
)
2342 if(*i_scset
== m_spellInfo
->Id
) // skip main spell, already handled above
2345 _player
->AddSpellCooldown(m_spellInfo
->Id
, m_CastItem
? m_CastItem
->GetEntry() : 0, catrecTime
);
2351 void Spell::update(uint32 difftime
)
2353 // update pointers based at it's GUIDs
2356 if(m_targets
.getUnitTargetGUID() && !m_targets
.getUnitTarget())
2362 // check if the player caster has moved before the spell finished
2363 if ((m_caster
->GetTypeId() == TYPEID_PLAYER
&& m_timer
!= 0) &&
2364 (m_castPositionX
!= m_caster
->GetPositionX() || m_castPositionY
!= m_caster
->GetPositionY() || m_castPositionZ
!= m_caster
->GetPositionZ()) &&
2365 (m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
|| !m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_FALLING
)))
2367 // always cancel for channeled spells
2368 if( m_spellState
== SPELL_STATE_CASTING
)
2370 // don't cancel for melee, autorepeat, triggered and instant spells
2371 else if(!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_IsTriggeredSpell
&& (m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_MOVEMENT
))
2375 switch(m_spellState
)
2377 case SPELL_STATE_PREPARING
:
2381 if(difftime
>= m_timer
)
2384 m_timer
-= difftime
;
2387 if(m_timer
== 0 && !IsNextMeleeSwingSpell() && !IsAutoRepeat())
2390 case SPELL_STATE_CASTING
:
2394 if( m_caster
->GetTypeId() == TYPEID_PLAYER
)
2396 // check if player has jumped before the channeling finished
2397 if(m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_JUMPING
))
2400 // check for incapacitating player states
2401 if( m_caster
->hasUnitState(UNIT_STAT_STUNNED
| UNIT_STAT_CONFUSED
))
2404 // check if player has turned if flag is set
2405 if( m_spellInfo
->ChannelInterruptFlags
& CHANNEL_FLAG_TURNING
&& m_castOrientation
!= m_caster
->GetOrientation() )
2409 // check if there are alive targets left
2410 if (!IsAliveUnitPresentInTargetList())
2412 SendChannelUpdate(0);
2416 if(difftime
>= m_timer
)
2419 m_timer
-= difftime
;
2424 SendChannelUpdate(0);
2426 // channeled spell processed independently for quest targeting
2427 // cast at creature (or GO) quest objectives update at successful cast channel finished
2428 // ignore autorepeat/melee casts for speed (not exist quest for spells (hm... )
2429 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsAutoRepeat() && !IsNextMeleeSwingSpell() )
2431 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2433 TargetInfo
* target
= &*ihit
;
2434 if(!IS_CREATURE_GUID(target
->targetGUID
))
2437 Unit
* unit
= m_caster
->GetGUID()==target
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
,target
->targetGUID
);
2441 ((Player
*)m_caster
)->CastedCreatureOrGO(unit
->GetEntry(),unit
->GetGUID(),m_spellInfo
->Id
);
2444 for(std::list
<GOTargetInfo
>::iterator ihit
= m_UniqueGOTargetInfo
.begin();ihit
!= m_UniqueGOTargetInfo
.end();++ihit
)
2446 GOTargetInfo
* target
= &*ihit
;
2448 GameObject
* go
= ObjectAccessor::GetGameObject(*m_caster
, target
->targetGUID
);
2452 ((Player
*)m_caster
)->CastedCreatureOrGO(go
->GetEntry(),go
->GetGUID(),m_spellInfo
->Id
);
2465 void Spell::finish(bool ok
)
2470 if(m_spellState
== SPELL_STATE_FINISHED
)
2473 m_spellState
= SPELL_STATE_FINISHED
;
2476 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2477 ((Player
*)m_caster
)->RemoveSpellMods(this);
2479 // other code related only to successfully finished spells
2483 //handle SPELL_AURA_ADD_TARGET_TRIGGER auras
2484 Unit::AuraList
const& targetTriggers
= m_caster
->GetAurasByType(SPELL_AURA_ADD_TARGET_TRIGGER
);
2485 for(Unit::AuraList::const_iterator i
= targetTriggers
.begin(); i
!= targetTriggers
.end(); ++i
)
2487 SpellEntry
const *auraSpellInfo
= (*i
)->GetSpellProto();
2488 uint32 auraSpellIdx
= (*i
)->GetEffIndex();
2489 if (IsAffectedBy(auraSpellInfo
, auraSpellIdx
))
2491 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2492 if( ihit
->effectMask
& (1<<auraSpellIdx
) )
2494 // check m_caster->GetGUID() let load auras at login and speedup most often case
2495 Unit
*unit
= m_caster
->GetGUID()== ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
2496 if (unit
&& unit
->isAlive())
2498 // Calculate chance at that moment (can be depend for example from combo points)
2499 int32 chance
= m_caster
->CalculateSpellDamage(auraSpellInfo
, auraSpellIdx
, (*i
)->GetBasePoints(),unit
);
2501 if(roll_chance_i(chance
))
2502 m_caster
->CastSpell(unit
, auraSpellInfo
->EffectTriggerSpell
[auraSpellIdx
], true, NULL
, (*i
));
2508 if (IsMeleeAttackResetSpell())
2510 m_caster
->resetAttackTimer(BASE_ATTACK
);
2511 if(m_caster
->haveOffhandWeapon())
2512 m_caster
->resetAttackTimer(OFF_ATTACK
);
2515 /*if (IsRangedAttackResetSpell())
2516 m_caster->resetAttackTimer(RANGED_ATTACK);*/
2518 // Clear combo at finish state
2519 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& NeedsComboPoints(m_spellInfo
))
2520 ((Player
*)m_caster
)->ClearComboPoints();
2522 // call triggered spell only at successful cast (after clear combo points -> for add some if need)
2523 if(!m_TriggerSpells
.empty())
2526 // Stop Attack for some spells
2527 if( m_spellInfo
->Attributes
& SPELL_ATTR_STOP_ATTACK_TARGET
)
2528 m_caster
->AttackStop();
2531 void Spell::SendCastResult(uint8 result
)
2533 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
2536 if(((Player
*)m_caster
)->GetSession()->PlayerLoading()) // don't send cast results at loading time
2541 WorldPacket
data(SMSG_CAST_FAILED
, (4+1+1));
2542 data
<< uint32(m_spellInfo
->Id
);
2543 data
<< uint8(result
); // problem
2544 data
<< uint8(m_cast_count
); // single cast or multi 2.3 (0/1)
2547 case SPELL_FAILED_REQUIRES_SPELL_FOCUS
:
2548 data
<< uint32(m_spellInfo
->RequiresSpellFocus
);
2550 case SPELL_FAILED_REQUIRES_AREA
:
2551 // hardcode areas limitation case
2552 if( m_spellInfo
->Id
==41618 || m_spellInfo
->Id
==41620 )
2553 data
<< uint32(3842);
2554 else if( m_spellInfo
->Id
==41617 || m_spellInfo
->Id
==41619 )
2555 data
<< uint32(3905);
2558 data
<< uint32(m_spellInfo
->AreaId
);
2560 case SPELL_FAILED_TOTEMS
:
2561 if(m_spellInfo
->Totem
[0])
2562 data
<< uint32(m_spellInfo
->Totem
[0]);
2563 if(m_spellInfo
->Totem
[1])
2564 data
<< uint32(m_spellInfo
->Totem
[1]);
2566 case SPELL_FAILED_TOTEM_CATEGORY
:
2567 if(m_spellInfo
->TotemCategory
[0])
2568 data
<< uint32(m_spellInfo
->TotemCategory
[0]);
2569 if(m_spellInfo
->TotemCategory
[1])
2570 data
<< uint32(m_spellInfo
->TotemCategory
[1]);
2572 case SPELL_FAILED_EQUIPPED_ITEM_CLASS
:
2573 data
<< uint32(m_spellInfo
->EquippedItemClass
);
2574 data
<< uint32(m_spellInfo
->EquippedItemSubClassMask
);
2575 data
<< uint32(m_spellInfo
->EquippedItemInventoryTypeMask
);
2578 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
2582 WorldPacket
data(SMSG_CLEAR_EXTRA_AURA_INFO
, (8+4));
2583 data
.append(m_caster
->GetPackGUID());
2584 data
<< uint32(m_spellInfo
->Id
);
2585 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
2589 void Spell::SendSpellStart()
2591 if(!IsNeedSendToClient())
2594 sLog
.outDebug("Sending SMSG_SPELL_START id=%u",m_spellInfo
->Id
);
2596 uint16 castFlags
= CAST_FLAG_UNKNOWN1
;
2598 castFlags
|= CAST_FLAG_AMMO
;
2601 if(!m_targets
.getUnitTarget())
2604 target
= m_targets
.getUnitTarget();
2606 WorldPacket
data(SMSG_SPELL_START
, (8+8+4+4+2));
2608 data
.append(m_CastItem
->GetPackGUID());
2610 data
.append(m_caster
->GetPackGUID());
2612 data
.append(m_caster
->GetPackGUID());
2613 data
<< uint32(m_spellInfo
->Id
);
2614 data
<< uint8(m_cast_count
); // single cast or multi 2.3 (0/1)
2615 data
<< uint16(castFlags
);
2616 data
<< uint32(m_timer
);
2618 m_targets
.write(&data
);
2620 if( castFlags
& CAST_FLAG_AMMO
)
2621 WriteAmmoToPacket(&data
);
2623 m_caster
->SendMessageToSet(&data
, true);
2626 void Spell::SendSpellGo()
2628 // not send invisible spell casting
2629 if(!IsNeedSendToClient())
2632 sLog
.outDebug("Sending SMSG_SPELL_GO id=%u",m_spellInfo
->Id
);
2635 if(!m_targets
.getUnitTarget())
2638 target
= m_targets
.getUnitTarget();
2640 uint16 castFlags
= CAST_FLAG_UNKNOWN3
;
2642 castFlags
|= CAST_FLAG_AMMO
;
2644 WorldPacket
data(SMSG_SPELL_GO
, 50); // guess size
2646 data
.append(m_CastItem
->GetPackGUID());
2648 data
.append(m_caster
->GetPackGUID());
2650 data
.append(m_caster
->GetPackGUID());
2651 data
<< uint32(m_spellInfo
->Id
);
2652 data
<< uint16(castFlags
);
2653 data
<< uint32(getMSTime()); // timestamp
2655 WriteSpellGoTargets(&data
);
2657 m_targets
.write(&data
);
2659 if( castFlags
& CAST_FLAG_AMMO
)
2660 WriteAmmoToPacket(&data
);
2662 m_caster
->SendMessageToSet(&data
, true);
2665 void Spell::WriteAmmoToPacket( WorldPacket
* data
)
2667 uint32 ammoInventoryType
= 0;
2668 uint32 ammoDisplayID
= 0;
2670 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2672 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack( RANGED_ATTACK
);
2675 ammoInventoryType
= pItem
->GetProto()->InventoryType
;
2676 if( ammoInventoryType
== INVTYPE_THROWN
)
2677 ammoDisplayID
= pItem
->GetProto()->DisplayInfoID
;
2680 uint32 ammoID
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
2683 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype( ammoID
);
2686 ammoDisplayID
= pProto
->DisplayInfoID
;
2687 ammoInventoryType
= pProto
->InventoryType
;
2690 else if(m_caster
->GetDummyAura(46699)) // Requires No Ammo
2692 ammoDisplayID
= 5996; // normal arrow
2693 ammoInventoryType
= INVTYPE_AMMO
;
2698 // TODO: implement selection ammo data based at ranged weapon stored in equipmodel/equipinfo/equipslot fields
2700 *data
<< uint32(ammoDisplayID
);
2701 *data
<< uint32(ammoInventoryType
);
2704 void Spell::WriteSpellGoTargets( WorldPacket
* data
)
2706 *data
<< (uint8
)m_countOfHit
;
2707 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2708 if ((*ihit
).missCondition
== SPELL_MISS_NONE
) // Add only hits
2709 *data
<< uint64(ihit
->targetGUID
);
2711 for(std::list
<GOTargetInfo
>::iterator ighit
= m_UniqueGOTargetInfo
.begin();ighit
!= m_UniqueGOTargetInfo
.end();++ighit
)
2712 *data
<< uint64(ighit
->targetGUID
); // Always hits
2714 *data
<< (uint8
)m_countOfMiss
;
2715 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
2717 if( ihit
->missCondition
!= SPELL_MISS_NONE
) // Add only miss
2719 *data
<< uint64(ihit
->targetGUID
);
2720 *data
<< uint8(ihit
->missCondition
);
2721 if( ihit
->missCondition
== SPELL_MISS_REFLECT
)
2722 *data
<< uint8(ihit
->reflectResult
);
2727 void Spell::SendLogExecute()
2729 Unit
*target
= m_targets
.getUnitTarget() ? m_targets
.getUnitTarget() : m_caster
;
2731 WorldPacket
data(SMSG_SPELLLOGEXECUTE
, (8+4+4+4+4+8));
2733 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
2734 data
.append(m_caster
->GetPackGUID());
2736 data
.append(target
->GetPackGUID());
2738 data
<< uint32(m_spellInfo
->Id
);
2740 data
<< uint32(count1
); // count1 (effect count?)
2741 for(uint32 i
= 0; i
< count1
; ++i
)
2743 data
<< uint32(m_spellInfo
->Effect
[0]); // spell effect?
2745 data
<< uint32(count2
); // count2 (target count?)
2746 for(uint32 j
= 0; j
< count2
; ++j
)
2748 switch(m_spellInfo
->Effect
[0])
2750 case SPELL_EFFECT_POWER_DRAIN
:
2751 if(Unit
*unit
= m_targets
.getUnitTarget())
2752 data
.append(unit
->GetPackGUID());
2759 case SPELL_EFFECT_ADD_EXTRA_ATTACKS
:
2760 if(Unit
*unit
= m_targets
.getUnitTarget())
2761 data
.append(unit
->GetPackGUID());
2764 data
<< uint32(0); // count?
2766 case SPELL_EFFECT_INTERRUPT_CAST
:
2767 if(Unit
*unit
= m_targets
.getUnitTarget())
2768 data
.append(unit
->GetPackGUID());
2771 data
<< uint32(0); // spellid
2773 case SPELL_EFFECT_DURABILITY_DAMAGE
:
2774 if(Unit
*unit
= m_targets
.getUnitTarget())
2775 data
.append(unit
->GetPackGUID());
2781 case SPELL_EFFECT_OPEN_LOCK
:
2782 case SPELL_EFFECT_OPEN_LOCK_ITEM
:
2783 if(Item
*item
= m_targets
.getItemTarget())
2784 data
.append(item
->GetPackGUID());
2788 case SPELL_EFFECT_CREATE_ITEM
:
2789 data
<< uint32(m_spellInfo
->EffectItemType
[0]);
2791 case SPELL_EFFECT_SUMMON
:
2792 case SPELL_EFFECT_SUMMON_WILD
:
2793 case SPELL_EFFECT_SUMMON_GUARDIAN
:
2794 case SPELL_EFFECT_TRANS_DOOR
:
2795 case SPELL_EFFECT_SUMMON_PET
:
2796 case SPELL_EFFECT_SUMMON_POSSESSED
:
2797 case SPELL_EFFECT_SUMMON_TOTEM
:
2798 case SPELL_EFFECT_SUMMON_OBJECT_WILD
:
2799 case SPELL_EFFECT_CREATE_HOUSE
:
2800 case SPELL_EFFECT_DUEL
:
2801 case SPELL_EFFECT_SUMMON_TOTEM_SLOT1
:
2802 case SPELL_EFFECT_SUMMON_TOTEM_SLOT2
:
2803 case SPELL_EFFECT_SUMMON_TOTEM_SLOT3
:
2804 case SPELL_EFFECT_SUMMON_TOTEM_SLOT4
:
2805 case SPELL_EFFECT_SUMMON_PHANTASM
:
2806 case SPELL_EFFECT_SUMMON_CRITTER
:
2807 case SPELL_EFFECT_SUMMON_OBJECT_SLOT1
:
2808 case SPELL_EFFECT_SUMMON_OBJECT_SLOT2
:
2809 case SPELL_EFFECT_SUMMON_OBJECT_SLOT3
:
2810 case SPELL_EFFECT_SUMMON_OBJECT_SLOT4
:
2811 case SPELL_EFFECT_SUMMON_DEMON
:
2812 case SPELL_EFFECT_150
:
2813 if(Unit
*unit
= m_targets
.getUnitTarget())
2814 data
.append(unit
->GetPackGUID());
2815 else if(m_targets
.getItemTargetGUID())
2816 data
.appendPackGUID(m_targets
.getItemTargetGUID());
2817 else if(GameObject
*go
= m_targets
.getGOTarget())
2818 data
.append(go
->GetPackGUID());
2820 data
<< uint8(0); // guid
2822 case SPELL_EFFECT_FEED_PET
:
2823 data
<< uint32(m_targets
.getItemTargetEntry());
2825 case SPELL_EFFECT_DISMISS_PET
:
2826 if(Unit
*unit
= m_targets
.getUnitTarget())
2827 data
.append(unit
->GetPackGUID());
2837 m_caster
->SendMessageToSet(&data
, true);
2840 void Spell::SendInterrupted(uint8 result
)
2842 WorldPacket
data(SMSG_SPELL_FAILURE
, (8+4+1));
2843 data
.append(m_caster
->GetPackGUID());
2844 data
<< m_spellInfo
->Id
;
2846 m_caster
->SendMessageToSet(&data
, true);
2848 data
.Initialize(SMSG_SPELL_FAILED_OTHER
, (8+4));
2849 data
.append(m_caster
->GetPackGUID());
2850 data
<< m_spellInfo
->Id
;
2851 m_caster
->SendMessageToSet(&data
, true);
2854 void Spell::SendChannelUpdate(uint32 time
)
2858 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
,0);
2859 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
,0);
2862 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
2865 WorldPacket
data( MSG_CHANNEL_UPDATE
, 8+4 );
2866 data
.append(m_caster
->GetPackGUID());
2869 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
2872 void Spell::SendChannelStart(uint32 duration
)
2874 WorldObject
* target
= NULL
;
2876 // select first not rsusted target from target list for _0_ effect
2877 if(!m_UniqueTargetInfo
.empty())
2879 for(std::list
<TargetInfo
>::iterator itr
= m_UniqueTargetInfo
.begin();itr
!= m_UniqueTargetInfo
.end();++itr
)
2881 if( (itr
->effectMask
& (1<<0)) && itr
->reflectResult
==SPELL_MISS_NONE
&& itr
->targetGUID
!= m_caster
->GetGUID())
2883 target
= ObjectAccessor::GetUnit(*m_caster
, itr
->targetGUID
);
2888 else if(!m_UniqueGOTargetInfo
.empty())
2890 for(std::list
<GOTargetInfo
>::iterator itr
= m_UniqueGOTargetInfo
.begin();itr
!= m_UniqueGOTargetInfo
.end();++itr
)
2892 if(itr
->effectMask
& (1<<0) )
2894 target
= ObjectAccessor::GetGameObject(*m_caster
, itr
->targetGUID
);
2900 if (m_caster
->GetTypeId() == TYPEID_PLAYER
)
2902 WorldPacket
data( MSG_CHANNEL_START
, (8+4+4) );
2903 data
.append(m_caster
->GetPackGUID());
2904 data
<< m_spellInfo
->Id
;
2907 ((Player
*)m_caster
)->GetSession()->SendPacket( &data
);
2912 m_caster
->SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT
, target
->GetGUID());
2913 m_caster
->SetUInt32Value(UNIT_CHANNEL_SPELL
, m_spellInfo
->Id
);
2916 void Spell::SendResurrectRequest(Player
* target
)
2918 WorldPacket
data(SMSG_RESURRECT_REQUEST
, (8+4+2+4));
2919 data
<< m_caster
->GetGUID();
2920 data
<< uint32(1) << uint16(0) << uint32(1);
2922 target
->GetSession()->SendPacket(&data
);
2925 void Spell::SendPlaySpellVisual(uint32 SpellID
)
2927 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
2930 WorldPacket
data(SMSG_PLAY_SPELL_VISUAL
, 12);
2931 data
<< m_caster
->GetGUID();
2933 ((Player
*)m_caster
)->GetSession()->SendPacket(&data
);
2936 void Spell::TakeCastItem()
2938 if(!m_CastItem
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
2941 // not remove cast item at triggered spell (equipping, weapon damage, etc)
2942 if(m_IsTriggeredSpell
)
2945 ItemPrototype
const *proto
= m_CastItem
->GetProto();
2949 // This code is to avoid a crash
2950 // I'm not sure, if this is really an error, but I guess every item needs a prototype
2951 sLog
.outError("Cast item has no item prototype highId=%d, lowId=%d",m_CastItem
->GetGUIDHigh(), m_CastItem
->GetGUIDLow());
2955 bool expendable
= false;
2956 bool withoutCharges
= false;
2958 for (int i
= 0; i
<5; i
++)
2960 if (proto
->Spells
[i
].SpellId
)
2962 // item has limited charges
2963 if (proto
->Spells
[i
].SpellCharges
)
2965 if (proto
->Spells
[i
].SpellCharges
< 0)
2968 int32 charges
= m_CastItem
->GetSpellCharges(i
);
2970 // item has charges left
2973 (charges
> 0) ? --charges
: ++charges
; // abs(charges) less at 1 after use
2974 if (proto
->Stackable
< 2)
2975 m_CastItem
->SetSpellCharges(i
, charges
);
2976 m_CastItem
->SetState(ITEM_CHANGED
, (Player
*)m_caster
);
2980 withoutCharges
= (charges
== 0);
2985 if (expendable
&& withoutCharges
)
2988 ((Player
*)m_caster
)->DestroyItemCount(m_CastItem
, count
, true);
2990 // prevent crash at access to deleted m_targets.getItemTarget
2991 if(m_CastItem
==m_targets
.getItemTarget())
2992 m_targets
.setItemTarget(NULL
);
2998 void Spell::TakePower()
3000 if(m_CastItem
|| m_triggeredByAuraSpell
)
3003 // health as power used
3004 if(m_spellInfo
->powerType
== POWER_HEALTH
)
3006 m_caster
->ModifyHealth( -(int32
)m_powerCost
);
3010 if(m_spellInfo
->powerType
>= MAX_POWERS
)
3012 sLog
.outError("Spell::TakePower: Unknown power type '%d'", m_spellInfo
->powerType
);
3016 Powers powerType
= Powers(m_spellInfo
->powerType
);
3018 m_caster
->ModifyPower(powerType
, -(int32
)m_powerCost
);
3020 // Set the five second timer
3021 if (powerType
== POWER_MANA
&& m_powerCost
> 0)
3022 m_caster
->SetLastManaUse(getMSTime());
3025 void Spell::TakeReagents()
3027 if(m_IsTriggeredSpell
) // reagents used in triggered spell removed by original spell or don't must be removed.
3030 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
3033 if (m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
&&
3034 m_caster
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PREPARATION
))
3037 Player
* p_caster
= (Player
*)m_caster
;
3039 for(uint32 x
=0;x
<8;x
++)
3041 if(m_spellInfo
->Reagent
[x
] <= 0)
3044 uint32 itemid
= m_spellInfo
->Reagent
[x
];
3045 uint32 itemcount
= m_spellInfo
->ReagentCount
[x
];
3047 // if CastItem is also spell reagent
3050 ItemPrototype
const *proto
= m_CastItem
->GetProto();
3051 if( proto
&& proto
->ItemId
== itemid
)
3053 for(int s
=0;s
<5;s
++)
3055 // CastItem will be used up and does not count as reagent
3056 int32 charges
= m_CastItem
->GetSpellCharges(s
);
3057 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
3068 // if getItemTarget is also spell reagent
3069 if (m_targets
.getItemTargetEntry()==itemid
)
3070 m_targets
.setItemTarget(NULL
);
3072 p_caster
->DestroyItemCount(itemid
, itemcount
, true);
3076 void Spell::HandleThreatSpells(uint32 spellId
)
3078 if(!m_targets
.getUnitTarget() || !spellId
)
3081 if(!m_targets
.getUnitTarget()->CanHaveThreatList())
3084 SpellThreatEntry
const *threatSpell
= sSpellThreatStore
.LookupEntry
<SpellThreatEntry
>(spellId
);
3088 m_targets
.getUnitTarget()->AddThreat(m_caster
, float(threatSpell
->threat
));
3090 DEBUG_LOG("Spell %u, rank %u, added an additional %i threat", spellId
, spellmgr
.GetSpellRank(spellId
), threatSpell
->threat
);
3093 void Spell::HandleEffects(Unit
*pUnitTarget
,Item
*pItemTarget
,GameObject
*pGOTarget
,uint32 i
, float DamageMultiplier
)
3095 unitTarget
= pUnitTarget
;
3096 itemTarget
= pItemTarget
;
3097 gameObjTarget
= pGOTarget
;
3099 uint8 eff
= m_spellInfo
->Effect
[i
];
3100 uint32 mechanic
= m_spellInfo
->EffectMechanic
[i
];
3102 damage
= int32(CalculateDamage((uint8
)i
,unitTarget
)*DamageMultiplier
);
3104 sLog
.outDebug( "Spell: Effect : %u", eff
);
3106 //Simply return. Do not display "immune" in red text on client
3107 if(unitTarget
&& unitTarget
->IsImmunedToSpellEffect(eff
, mechanic
))
3110 if(eff
<TOTAL_SPELL_EFFECTS
)
3112 //sLog.outDebug( "WORLD: Spell FX %d < TOTAL_SPELL_EFFECTS ", eff);
3113 (*this.*SpellEffects
[eff
])(i
);
3118 sLog.outDebug( "WORLD: Spell FX %d > TOTAL_SPELL_EFFECTS ", eff);
3120 EffectEnchantItemTmp(i);
3123 sLog.outError("SPELL: unknown effect %u spell id %u\n",
3124 eff, m_spellInfo->Id);
3130 void Spell::TriggerSpell()
3132 for(TriggerSpells::iterator si
=m_TriggerSpells
.begin(); si
!=m_TriggerSpells
.end(); ++si
)
3134 Spell
* spell
= new Spell(m_caster
, (*si
), true, m_originalCasterGUID
, this->m_selfContainer
);
3135 spell
->prepare(&m_targets
); // use original spell original targets
3139 uint8
Spell::CanCast(bool strict
)
3141 // check cooldowns to prevent cheating
3142 if(m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
3144 if(m_triggeredByAuraSpell
)
3145 return SPELL_FAILED_DONT_REPORT
;
3147 return SPELL_FAILED_NOT_READY
;
3150 // only allow triggered spells if at an ended battleground
3151 if( !m_IsTriggeredSpell
&& m_caster
->GetTypeId() == TYPEID_PLAYER
)
3152 if(BattleGround
* bg
= ((Player
*)m_caster
)->GetBattleGround())
3153 if(bg
->GetStatus() == STATUS_WAIT_LEAVE
)
3154 return SPELL_FAILED_DONT_REPORT
;
3156 // only check at first call, Stealth auras are already removed at second call
3157 // for now, ignore triggered spells
3158 if( strict
&& !m_IsTriggeredSpell
)
3160 // Cannot be used in this stance/form
3161 if(uint8 shapeError
= GetErrorAtShapeshiftedCast(m_spellInfo
, m_caster
->m_form
))
3164 if ((m_spellInfo
->Attributes
& SPELL_ATTR_ONLY_STEALTHED
) && !(m_caster
->HasStealthAura()))
3165 return SPELL_FAILED_ONLY_STEALTHED
;
3168 // caster state requirements
3169 if(m_spellInfo
->CasterAuraState
&& !m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraState
)))
3170 return SPELL_FAILED_CASTER_AURASTATE
;
3171 if(m_spellInfo
->CasterAuraStateNot
&& m_caster
->HasAuraState(AuraState(m_spellInfo
->CasterAuraStateNot
)))
3172 return SPELL_FAILED_CASTER_AURASTATE
;
3174 // cancel autorepeat spells if cast start when moving
3175 // (not wand currently autorepeat cast delayed to moving stop anyway in spell update code)
3176 if( m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->isMoving() )
3178 // skip stuck spell to allow use it in falling case and apply spell limitations at movement
3179 if( (!m_caster
->HasUnitMovementFlag(MOVEMENTFLAG_FALLING
) || m_spellInfo
->Effect
[0] != SPELL_EFFECT_STUCK
) &&
3180 (IsAutoRepeat() || (m_spellInfo
->AuraInterruptFlags
& AURA_INTERRUPT_FLAG_NOT_SEATED
) != 0) )
3181 return SPELL_FAILED_MOVING
;
3184 Unit
*target
= m_targets
.getUnitTarget();
3188 // target state requirements (not allowed state), apply to self also
3189 if(m_spellInfo
->TargetAuraStateNot
&& target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraStateNot
)))
3190 return SPELL_FAILED_TARGET_AURASTATE
;
3192 if(target
!= m_caster
)
3194 // target state requirements (apply to non-self only), to allow cast affects to self like Dirty Deeds
3195 if(m_spellInfo
->TargetAuraState
&& !target
->HasAuraState(AuraState(m_spellInfo
->TargetAuraState
)))
3196 return SPELL_FAILED_TARGET_AURASTATE
;
3198 // Not allow casting on flying player
3199 if (target
->isInFlight())
3200 return SPELL_FAILED_BAD_TARGETS
;
3202 if(VMAP::VMapFactory::checkSpellForLoS(m_spellInfo
->Id
) && !m_caster
->IsWithinLOSInMap(target
))
3203 return SPELL_FAILED_LINE_OF_SIGHT
;
3205 // auto selection spell rank implemented in WorldSession::HandleCastSpellOpcode
3206 // this case can be triggered if rank not found (too low-level target for first rank)
3207 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !IsPassiveSpell(m_spellInfo
->Id
) && !m_CastItem
)
3209 for(int i
=0;i
<3;i
++)
3211 if(IsPositiveEffect(m_spellInfo
->Id
, i
) && m_spellInfo
->Effect
[i
] == SPELL_EFFECT_APPLY_AURA
)
3212 if(target
->getLevel() + 10 < m_spellInfo
->spellLevel
)
3213 return SPELL_FAILED_LOWLEVEL
;
3218 // check pet presents
3219 for(int j
=0;j
<3;j
++)
3221 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_PET
)
3223 target
= m_caster
->GetPet();
3226 if(m_triggeredByAuraSpell
) // not report pet not existence for triggered spells
3227 return SPELL_FAILED_DONT_REPORT
;
3229 return SPELL_FAILED_NO_PET
;
3235 //check creature type
3236 //ignore self casts (including area casts when caster selected as target)
3237 if(target
!= m_caster
)
3239 if(!CheckTargetCreatureType(target
))
3241 if(target
->GetTypeId()==TYPEID_PLAYER
)
3242 return SPELL_FAILED_TARGET_IS_PLAYER
;
3244 return SPELL_FAILED_BAD_TARGETS
;
3248 // TODO: this check can be applied and for player to prevent cheating when IsPositiveSpell will return always correct result.
3249 // check target for pet/charmed casts (not self targeted), self targeted cast used for area effects and etc
3250 if(m_caster
!= target
&& m_caster
->GetTypeId()==TYPEID_UNIT
&& m_caster
->GetCharmerOrOwnerGUID())
3252 // check correctness positive/negative cast target (pet cast real check and cheating check)
3253 if(IsPositiveSpell(m_spellInfo
->Id
))
3255 if(m_caster
->IsHostileTo(target
))
3256 return SPELL_FAILED_BAD_TARGETS
;
3260 if(m_caster
->IsFriendlyTo(target
))
3261 return SPELL_FAILED_BAD_TARGETS
;
3265 if(IsPositiveSpell(m_spellInfo
->Id
))
3267 if(target
->IsImmunedToSpell(m_spellInfo
,false))
3268 return SPELL_FAILED_TARGET_AURASTATE
;
3271 //Must be behind the target.
3272 if( m_spellInfo
->AttributesEx2
== 0x100000 && (m_spellInfo
->AttributesEx
& 0x200) == 0x200 && target
->HasInArc(M_PI
, m_caster
) )
3275 return SPELL_FAILED_NOT_BEHIND
;
3278 //Target must be facing you.
3279 if((m_spellInfo
->Attributes
== 0x150010) && !target
->HasInArc(M_PI
, m_caster
) )
3282 return SPELL_FAILED_NOT_INFRONT
;
3285 // check if target is in combat
3286 if (target
!= m_caster
&& (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_NOT_IN_COMBAT_TARGET
) && target
->isInCombat())
3288 return SPELL_FAILED_TARGET_AFFECTING_COMBAT
;
3291 // Spell casted only on battleground
3292 if((m_spellInfo
->AttributesEx3
& SPELL_ATTR_EX3_BATTLEGROUND
) && m_caster
->GetTypeId()==TYPEID_PLAYER
)
3293 if(!((Player
*)m_caster
)->InBattleGround())
3294 return SPELL_FAILED_ONLY_BATTLEGROUNDS
;
3296 // do not allow spells to be cast in arenas
3297 // - with greater than 15 min CD without SPELL_ATTR_EX4_USABLE_IN_ARENA flag
3298 // - with SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA flag
3299 if( (m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_NOT_USABLE_IN_ARENA
) ||
3300 GetSpellRecoveryTime(m_spellInfo
) > 15 * MINUTE
* 1000 && !(m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_USABLE_IN_ARENA
) )
3301 if(MapEntry
const* mapEntry
= sMapStore
.LookupEntry(m_caster
->GetMapId()))
3302 if(mapEntry
->IsBattleArena())
3303 return SPELL_FAILED_NOT_IN_ARENA
;
3306 if(!IsSpellAllowedInLocation(m_spellInfo
,m_caster
->GetMapId(),m_caster
->GetZoneId(),m_caster
->GetAreaId()))
3307 return SPELL_FAILED_REQUIRES_AREA
;
3309 // not let players cast spells at mount (and let do it to creatures)
3310 if( m_caster
->IsMounted() && m_caster
->GetTypeId()==TYPEID_PLAYER
&& !m_IsTriggeredSpell
&&
3311 !IsPassiveSpell(m_spellInfo
->Id
) && !(m_spellInfo
->Attributes
& SPELL_ATTR_CASTABLE_WHILE_MOUNTED
) )
3313 if(m_caster
->isInFlight())
3314 return SPELL_FAILED_NOT_FLYING
;
3316 return SPELL_FAILED_NOT_MOUNTED
;
3319 // always (except passive spells) check items (focus object can be required for any type casts)
3320 if(!IsPassiveSpell(m_spellInfo
->Id
))
3321 if(uint8 castResult
= CheckItems())
3324 //ImpliciteTargetA-B = 38, If fact there is 0 Spell with ImpliciteTargetB=38
3325 if(m_UniqueTargetInfo
.empty()) // skip second canCast apply (for delayed spells for example)
3327 for(uint8 j
= 0; j
< 3; j
++)
3329 if( m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT
||
3330 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT
&& m_spellInfo
->EffectImplicitTargetA
[j
] != TARGET_SELF
||
3331 m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3332 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3336 SpellScriptTarget::const_iterator lower
= spellmgr
.GetBeginSpellScriptTarget(m_spellInfo
->Id
);
3337 SpellScriptTarget::const_iterator upper
= spellmgr
.GetEndSpellScriptTarget(m_spellInfo
->Id
);
3339 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
);
3341 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
3342 float range
= GetSpellMaxRange(srange
);
3344 Creature
* creatureScriptTarget
= NULL
;
3345 GameObject
* goScriptTarget
= NULL
;
3347 for(SpellScriptTarget::const_iterator i_spellST
= lower
; i_spellST
!= upper
; ++i_spellST
)
3349 switch(i_spellST
->second
.type
)
3351 case SPELL_TARGET_TYPE_GAMEOBJECT
:
3353 GameObject
* p_GameObject
= NULL
;
3355 if(i_spellST
->second
.targetEntry
)
3357 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
3359 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3361 MaNGOS::NearestGameObjectEntryInObjectRangeCheck
go_check(*m_caster
,i_spellST
->second
.targetEntry
,range
);
3362 MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
> checker(p_GameObject
,go_check
);
3364 TypeContainerVisitor
<MaNGOS::GameObjectLastSearcher
<MaNGOS::NearestGameObjectEntryInObjectRangeCheck
>, GridTypeMapContainer
> object_checker(checker
);
3365 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3366 cell_lock
->Visit(cell_lock
, object_checker
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
3370 // remember found target and range, next attempt will find more near target with another entry
3371 creatureScriptTarget
= NULL
;
3372 goScriptTarget
= p_GameObject
;
3373 range
= go_check
.GetLastRange();
3376 else if( focusObject
) //Focus Object
3378 float frange
= m_caster
->GetDistance(focusObject
);
3381 creatureScriptTarget
= NULL
;
3382 goScriptTarget
= focusObject
;
3388 case SPELL_TARGET_TYPE_CREATURE
:
3389 case SPELL_TARGET_TYPE_DEAD
:
3392 Creature
*p_Creature
= NULL
;
3394 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
3396 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
3397 cell
.SetNoCreate(); // Really don't know what is that???
3399 MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
u_check(*m_caster
,i_spellST
->second
.targetEntry
,i_spellST
->second
.type
!=SPELL_TARGET_TYPE_DEAD
,range
);
3400 MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
> searcher(p_Creature
, u_check
);
3402 TypeContainerVisitor
<MaNGOS::CreatureLastSearcher
<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck
>, GridTypeMapContainer
> grid_creature_searcher(searcher
);
3404 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
3405 cell_lock
->Visit(cell_lock
, grid_creature_searcher
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
3409 creatureScriptTarget
= p_Creature
;
3410 goScriptTarget
= NULL
;
3411 range
= u_check
.GetLastRange();
3418 if(creatureScriptTarget
)
3420 // store coordinates for TARGET_SCRIPT_COORDINATES
3421 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3422 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3424 m_targets
.setDestination(creatureScriptTarget
->GetPositionX(),creatureScriptTarget
->GetPositionY(),creatureScriptTarget
->GetPositionZ());
3426 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3427 AddUnitTarget(creatureScriptTarget
, j
);
3429 // store explicit target for TARGET_SCRIPT
3431 AddUnitTarget(creatureScriptTarget
, j
);
3433 else if(goScriptTarget
)
3435 // store coordinates for TARGET_SCRIPT_COORDINATES
3436 if (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
||
3437 m_spellInfo
->EffectImplicitTargetB
[j
] == TARGET_SCRIPT_COORDINATES
)
3439 m_targets
.setDestination(goScriptTarget
->GetPositionX(),goScriptTarget
->GetPositionY(),goScriptTarget
->GetPositionZ());
3441 if(m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_SCRIPT_COORDINATES
&& m_spellInfo
->EffectImplicitTargetB
[j
] == 0 && m_spellInfo
->Effect
[j
]!=SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3442 AddGOTarget(goScriptTarget
, j
);
3444 // store explicit target for TARGET_SCRIPT
3446 AddGOTarget(goScriptTarget
, j
);
3448 //Missing DB Entry or targets for this spellEffect.
3451 // not report target not existence for triggered spells
3452 if(m_triggeredByAuraSpell
|| m_IsTriggeredSpell
)
3453 return SPELL_FAILED_DONT_REPORT
;
3455 return SPELL_FAILED_BAD_TARGETS
;
3461 if(uint8 castResult
= CheckRange(strict
))
3465 if(uint8 castResult
= CheckPower())
3469 if(!m_triggeredByAuraSpell
) // triggered spell not affected by stun/etc
3470 if(uint8 castResult
= CheckCasterAuras())
3473 for (int i
= 0; i
< 3; i
++)
3475 // for effects of spells that have only one target
3476 switch(m_spellInfo
->Effect
[i
])
3478 case SPELL_EFFECT_DUMMY
:
3480 if(m_spellInfo
->SpellIconID
== 1648) // Execute
3482 if(!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
3483 return SPELL_FAILED_BAD_TARGETS
;
3485 else if (m_spellInfo
->Id
== 51582) // Rocket Boots Engaged
3487 if(m_caster
->IsInWater())
3488 return SPELL_FAILED_ONLY_ABOVEWATER
;
3490 else if(m_spellInfo
->SpellIconID
==156) // Holy Shock
3492 // spell different for friends and enemies
3493 // hart version required facing
3494 if(m_targets
.getUnitTarget() && !m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()) && !m_caster
->HasInArc( M_PI
, target
))
3495 return SPELL_FAILED_UNIT_NOT_INFRONT
;
3499 case SPELL_EFFECT_SCHOOL_DAMAGE
:
3502 if(m_spellInfo
->SpellVisual
== 7250)
3504 if (!m_targets
.getUnitTarget())
3505 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
3507 if(m_targets
.getUnitTarget()->GetHealth() > m_targets
.getUnitTarget()->GetMaxHealth()*0.2)
3508 return SPELL_FAILED_BAD_TARGETS
;
3512 case SPELL_EFFECT_TAMECREATURE
:
3514 if (!m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() == TYPEID_PLAYER
)
3515 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
3517 if (m_targets
.getUnitTarget()->getLevel() > m_caster
->getLevel())
3518 return SPELL_FAILED_HIGHLEVEL
;
3520 // use SMSG_PET_TAME_FAILURE?
3521 if (!((Creature
*)m_targets
.getUnitTarget())->GetCreatureInfo()->isTameable ())
3522 return SPELL_FAILED_BAD_TARGETS
;
3524 if(m_caster
->GetPetGUID())
3525 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
3527 if(m_caster
->GetCharmGUID())
3528 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
3532 case SPELL_EFFECT_LEARN_SPELL
:
3534 if(m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_PET
)
3537 Pet
* pet
= m_caster
->GetPet();
3540 return SPELL_FAILED_NO_PET
;
3542 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
3544 if(!learn_spellproto
)
3545 return SPELL_FAILED_NOT_KNOWN
;
3547 if(!pet
->CanTakeMoreActiveSpells(learn_spellproto
->Id
))
3548 return SPELL_FAILED_TOO_MANY_SKILLS
;
3550 if(m_spellInfo
->spellLevel
> pet
->getLevel())
3551 return SPELL_FAILED_LOWLEVEL
;
3553 if(!pet
->HasTPForSpell(learn_spellproto
->Id
))
3554 return SPELL_FAILED_TRAINING_POINTS
;
3558 case SPELL_EFFECT_LEARN_PET_SPELL
:
3560 Pet
* pet
= m_caster
->GetPet();
3563 return SPELL_FAILED_NO_PET
;
3565 SpellEntry
const *learn_spellproto
= sSpellStore
.LookupEntry(m_spellInfo
->EffectTriggerSpell
[i
]);
3567 if(!learn_spellproto
)
3568 return SPELL_FAILED_NOT_KNOWN
;
3570 if(!pet
->CanTakeMoreActiveSpells(learn_spellproto
->Id
))
3571 return SPELL_FAILED_TOO_MANY_SKILLS
;
3573 if(m_spellInfo
->spellLevel
> pet
->getLevel())
3574 return SPELL_FAILED_LOWLEVEL
;
3576 if(!pet
->HasTPForSpell(learn_spellproto
->Id
))
3577 return SPELL_FAILED_TRAINING_POINTS
;
3581 case SPELL_EFFECT_FEED_PET
:
3583 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getItemTarget() )
3584 return SPELL_FAILED_BAD_TARGETS
;
3586 Pet
* pet
= m_caster
->GetPet();
3589 return SPELL_FAILED_NO_PET
;
3591 if(!pet
->HaveInDiet(m_targets
.getItemTarget()->GetProto()))
3592 return SPELL_FAILED_WRONG_PET_FOOD
;
3594 if(!pet
->GetCurrentFoodBenefitLevel(m_targets
.getItemTarget()->GetProto()->ItemLevel
))
3595 return SPELL_FAILED_FOOD_LOWLEVEL
;
3597 if(m_caster
->isInCombat() || pet
->isInCombat())
3598 return SPELL_FAILED_AFFECTING_COMBAT
;
3602 case SPELL_EFFECT_POWER_BURN
:
3603 case SPELL_EFFECT_POWER_DRAIN
:
3605 // Can be area effect, Check only for players and not check if target - caster (spell can have multiply drain/burn effects)
3606 if(m_caster
->GetTypeId() == TYPEID_PLAYER
)
3607 if(Unit
* target
= m_targets
.getUnitTarget())
3608 if(target
!=m_caster
&& target
->getPowerType()!=m_spellInfo
->EffectMiscValue
[i
])
3609 return SPELL_FAILED_BAD_TARGETS
;
3612 case SPELL_EFFECT_CHARGE
:
3614 if (m_caster
->hasUnitState(UNIT_STAT_ROOT
))
3615 return SPELL_FAILED_ROOTED
;
3619 case SPELL_EFFECT_SKINNING
:
3621 if (m_caster
->GetTypeId() != TYPEID_PLAYER
|| !m_targets
.getUnitTarget() || m_targets
.getUnitTarget()->GetTypeId() != TYPEID_UNIT
)
3622 return SPELL_FAILED_BAD_TARGETS
;
3624 if( !(m_targets
.getUnitTarget()->GetUInt32Value(UNIT_FIELD_FLAGS
) & UNIT_FLAG_SKINNABLE
) )
3625 return SPELL_FAILED_TARGET_UNSKINNABLE
;
3627 Creature
* creature
= (Creature
*)m_targets
.getUnitTarget();
3628 if ( creature
->GetCreatureType() != CREATURE_TYPE_CRITTER
&& ( !creature
->lootForBody
|| !creature
->loot
.empty() ) )
3630 return SPELL_FAILED_TARGET_NOT_LOOTED
;
3633 uint32 skill
= creature
->GetCreatureInfo()->GetRequiredLootSkill();
3635 int32 skillValue
= ((Player
*)m_caster
)->GetSkillValue(skill
);
3636 int32 TargetLevel
= m_targets
.getUnitTarget()->getLevel();
3637 int32 ReqValue
= (skillValue
< 100 ? (TargetLevel
-10)*10 : TargetLevel
*5);
3638 if (ReqValue
> skillValue
)
3639 return SPELL_FAILED_LOW_CASTLEVEL
;
3641 // chance for fail at orange skinning attempt
3642 if( (m_selfContainer
&& (*m_selfContainer
) == this) &&
3643 skillValue
< sWorld
.GetConfigMaxSkillValue() &&
3644 (ReqValue
< 0 ? 0 : ReqValue
) > irand(skillValue
-25, skillValue
+37) )
3645 return SPELL_FAILED_TRY_AGAIN
;
3649 case SPELL_EFFECT_OPEN_LOCK_ITEM
:
3650 case SPELL_EFFECT_OPEN_LOCK
:
3652 if( m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT
&&
3653 m_spellInfo
->EffectImplicitTargetA
[i
] != TARGET_GAMEOBJECT_ITEM
)
3656 if( m_caster
->GetTypeId() != TYPEID_PLAYER
// only players can open locks, gather etc.
3657 // we need a go target in case of TARGET_GAMEOBJECT
3658 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT
&& !m_targets
.getGOTarget()
3659 // we need a go target, or an openable item target in case of TARGET_GAMEOBJECT_ITEM
3660 || m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_GAMEOBJECT_ITEM
&& !m_targets
.getGOTarget() &&
3661 (!m_targets
.getItemTarget() || !m_targets
.getItemTarget()->GetProto()->LockID
|| m_targets
.getItemTarget()->GetOwner() != m_caster
) )
3662 return SPELL_FAILED_BAD_TARGETS
;
3664 // In BattleGround players can use only flags and banners
3665 if( ((Player
*)m_caster
)->InBattleGround() &&
3666 !((Player
*)m_caster
)->isAllowUseBattleGroundObject() )
3667 return SPELL_FAILED_TRY_AGAIN
;
3669 // get the lock entry
3670 LockEntry
const *lockInfo
= NULL
;
3671 if (GameObject
* go
=m_targets
.getGOTarget())
3672 lockInfo
= sLockStore
.LookupEntry(go
->GetLockId());
3673 else if(Item
* itm
=m_targets
.getItemTarget())
3674 lockInfo
= sLockStore
.LookupEntry(itm
->GetProto()->LockID
);
3676 // check lock compatibility
3679 // check for lock - key pair (checked by client also, just prevent cheating
3680 bool ok_key
= false;
3681 for(int it
= 0; it
< 5; ++it
)
3683 switch(lockInfo
->keytype
[it
])
3689 if(lockInfo
->key
[it
])
3691 if(m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->key
[it
])
3696 case LOCK_KEY_SKILL
:
3698 if(uint32(m_spellInfo
->EffectMiscValue
[i
])!=lockInfo
->key
[it
])
3701 switch(lockInfo
->key
[it
])
3703 case LOCKTYPE_HERBALISM
:
3704 if(((Player
*)m_caster
)->HasSkill(SKILL_HERBALISM
))
3707 case LOCKTYPE_MINING
:
3708 if(((Player
*)m_caster
)->HasSkill(SKILL_MINING
))
3722 return SPELL_FAILED_BAD_TARGETS
;
3725 // chance for fail at orange mining/herb/LockPicking gathering attempt
3726 if (!m_selfContainer
|| ((*m_selfContainer
) != this))
3729 // get the skill value of the player
3730 int32 SkillValue
= 0;
3731 bool canFailAtMax
= true;
3732 if (m_spellInfo
->EffectMiscValue
[i
] == LOCKTYPE_HERBALISM
)
3734 SkillValue
= ((Player
*)m_caster
)->GetSkillValue(SKILL_HERBALISM
);
3735 canFailAtMax
= false;
3737 else if (m_spellInfo
->EffectMiscValue
[i
] == LOCKTYPE_MINING
)
3739 SkillValue
= ((Player
*)m_caster
)->GetSkillValue(SKILL_MINING
);
3740 canFailAtMax
= false;
3742 else if (m_spellInfo
->EffectMiscValue
[i
] == LOCKTYPE_PICKLOCK
)
3743 SkillValue
= ((Player
*)m_caster
)->GetSkillValue(SKILL_LOCKPICKING
);
3745 // castitem check: rogue using skeleton keys. the skill values should not be added in this case.
3749 // add the damage modifier from the spell casted (cheat lock / skeleton key etc.) (use m_currentBasePoints, CalculateDamage returns wrong value)
3750 SkillValue
+= m_currentBasePoints
[i
]+1;
3752 // get the required lock value
3756 // check for lock - key pair
3758 for(int it
= 0; it
< 5; ++it
)
3760 if(lockInfo
->keytype
[it
]==LOCK_KEY_ITEM
&& lockInfo
->key
[it
] && m_CastItem
&& m_CastItem
->GetEntry()==lockInfo
->key
[it
])
3762 // if so, we're good to go
3770 if (m_spellInfo
->EffectMiscValue
[i
] == LOCKTYPE_PICKLOCK
)
3771 ReqValue
= lockInfo
->requiredlockskill
;
3773 ReqValue
= lockInfo
->requiredminingskill
;
3776 // skill doesn't meet the required value
3777 if (ReqValue
> SkillValue
)
3778 return SPELL_FAILED_LOW_CASTLEVEL
;
3780 // chance for failure in orange gather / lockpick (gathering skill can't fail at maxskill)
3781 if((canFailAtMax
|| SkillValue
< sWorld
.GetConfigMaxSkillValue()) && ReqValue
> irand(SkillValue
-25, SkillValue
+37))
3782 return SPELL_FAILED_TRY_AGAIN
;
3786 case SPELL_EFFECT_SUMMON_DEAD_PET
:
3788 Creature
*pet
= m_caster
->GetPet();
3790 return SPELL_FAILED_NO_PET
;
3793 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
3797 // This is generic summon effect now and don't make this check for summon types similar
3798 // SPELL_EFFECT_SUMMON_CRITTER, SPELL_EFFECT_SUMMON_WILD or SPELL_EFFECT_SUMMON_GUARDIAN.
3799 // These won't show up in m_caster->GetPetGUID()
3800 case SPELL_EFFECT_SUMMON
:
3802 switch(m_spellInfo
->EffectMiscValueB
[i
])
3804 case SUMMON_TYPE_POSESSED
:
3805 case SUMMON_TYPE_POSESSED2
:
3806 case SUMMON_TYPE_DEMON
:
3807 case SUMMON_TYPE_SUMMON
:
3809 if(m_caster
->GetPetGUID())
3810 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
3812 if(m_caster
->GetCharmGUID())
3813 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
3819 // Don't make this check for SPELL_EFFECT_SUMMON_CRITTER, SPELL_EFFECT_SUMMON_WILD or SPELL_EFFECT_SUMMON_GUARDIAN.
3820 // These won't show up in m_caster->GetPetGUID()
3821 case SPELL_EFFECT_SUMMON_POSSESSED
:
3822 case SPELL_EFFECT_SUMMON_PHANTASM
:
3823 case SPELL_EFFECT_SUMMON_DEMON
:
3825 if(m_caster
->GetPetGUID())
3826 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
3828 if(m_caster
->GetCharmGUID())
3829 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
3833 case SPELL_EFFECT_SUMMON_PET
:
3835 if(m_caster
->GetPetGUID()) //let warlock do a replacement summon
3838 Pet
* pet
= ((Player
*)m_caster
)->GetPet();
3840 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& m_caster
->getClass()==CLASS_WARLOCK
)
3842 if (strict
) //starting cast, trigger pet stun (cast by pet so it doesn't attack player)
3843 pet
->CastSpell(pet
, 32752, true, NULL
, NULL
, pet
->GetGUID());
3846 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
3849 if(m_caster
->GetCharmGUID())
3850 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
3854 case SPELL_EFFECT_SUMMON_PLAYER
:
3856 if(m_caster
->GetTypeId()!=TYPEID_PLAYER
)
3857 return SPELL_FAILED_BAD_TARGETS
;
3858 if(!((Player
*)m_caster
)->GetSelection())
3859 return SPELL_FAILED_BAD_TARGETS
;
3861 Player
* target
= objmgr
.GetPlayer(((Player
*)m_caster
)->GetSelection());
3862 if( !target
|| ((Player
*)m_caster
)==target
|| !target
->IsInSameRaidWith((Player
*)m_caster
) )
3863 return SPELL_FAILED_BAD_TARGETS
;
3865 // check if our map is dungeon
3866 if( sMapStore
.LookupEntry(m_caster
->GetMapId())->IsDungeon() )
3868 InstanceTemplate
const* instance
= ObjectMgr::GetInstanceTemplate(m_caster
->GetMapId());
3870 return SPELL_FAILED_TARGET_NOT_IN_INSTANCE
;
3871 if ( instance
->levelMin
> target
->getLevel() )
3872 return SPELL_FAILED_LOWLEVEL
;
3873 if ( instance
->levelMax
&& instance
->levelMax
< target
->getLevel() )
3874 return SPELL_FAILED_HIGHLEVEL
;
3878 case SPELL_EFFECT_LEAP
:
3879 case SPELL_EFFECT_TELEPORT_UNITS_FACE_CASTER
:
3881 float dis
= GetSpellRadius(sSpellRadiusStore
.LookupEntry(m_spellInfo
->EffectRadiusIndex
[i
]));
3882 float fx
= m_caster
->GetPositionX() + dis
* cos(m_caster
->GetOrientation());
3883 float fy
= m_caster
->GetPositionY() + dis
* sin(m_caster
->GetOrientation());
3884 // teleport a bit above terrain level to avoid falling below it
3885 float fz
= MapManager::Instance().GetBaseMap(m_caster
->GetMapId())->GetHeight(fx
,fy
,m_caster
->GetPositionZ(),true);
3886 if(fz
<= INVALID_HEIGHT
) // note: this also will prevent use effect in instances without vmaps height enabled
3887 return SPELL_FAILED_TRY_AGAIN
;
3889 float caster_pos_z
= m_caster
->GetPositionZ();
3890 // Control the caster to not climb or drop when +-fz > 8
3891 if(!(fz
<=caster_pos_z
+8 && fz
>=caster_pos_z
-8))
3892 return SPELL_FAILED_TRY_AGAIN
;
3894 // not allow use this effect at battleground until battleground start
3895 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
3896 if(BattleGround
const *bg
= ((Player
*)m_caster
)->GetBattleGround())
3897 if(bg
->GetStatus() != STATUS_IN_PROGRESS
)
3898 return SPELL_FAILED_TRY_AGAIN
;
3901 case SPELL_EFFECT_STEAL_BENEFICIAL_BUFF
:
3903 if (m_targets
.getUnitTarget()==m_caster
)
3904 return SPELL_FAILED_BAD_TARGETS
;
3911 for (int i
= 0; i
< 3; i
++)
3913 switch(m_spellInfo
->EffectApplyAuraName
[i
])
3915 case SPELL_AURA_MOD_POSSESS
:
3916 case SPELL_AURA_MOD_CHARM
:
3918 if(m_caster
->GetPetGUID())
3919 return SPELL_FAILED_ALREADY_HAVE_SUMMON
;
3921 if(m_caster
->GetCharmGUID())
3922 return SPELL_FAILED_ALREADY_HAVE_CHARM
;
3924 if(m_caster
->GetCharmerGUID())
3925 return SPELL_FAILED_CHARMED
;
3927 if(!m_targets
.getUnitTarget())
3928 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
3930 if(m_targets
.getUnitTarget()->GetCharmerGUID())
3931 return SPELL_FAILED_CHARMED
;
3933 if(int32(m_targets
.getUnitTarget()->getLevel()) > CalculateDamage(i
,m_targets
.getUnitTarget()))
3934 return SPELL_FAILED_HIGHLEVEL
;
3936 case SPELL_AURA_MOUNTED
:
3938 if (m_caster
->IsInWater())
3939 return SPELL_FAILED_ONLY_ABOVEWATER
;
3941 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& ((Player
*)m_caster
)->GetTransport())
3942 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
3944 // Ignore map check if spell have AreaId. AreaId already checked and this prevent special mount spells
3945 if (m_caster
->GetTypeId()==TYPEID_PLAYER
&& !sMapStore
.LookupEntry(m_caster
->GetMapId())->IsMountAllowed() && !m_IsTriggeredSpell
&& !m_spellInfo
->AreaId
)
3946 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
3948 if (m_caster
->GetAreaId()==35)
3949 return SPELL_FAILED_NO_MOUNTS_ALLOWED
;
3951 ShapeshiftForm form
= m_caster
->m_form
;
3952 if( form
== FORM_CAT
|| form
== FORM_TREE
|| form
== FORM_TRAVEL
||
3953 form
== FORM_AQUA
|| form
== FORM_BEAR
|| form
== FORM_DIREBEAR
||
3954 form
== FORM_CREATUREBEAR
|| form
== FORM_GHOSTWOLF
|| form
== FORM_FLIGHT
||
3955 form
== FORM_FLIGHT_EPIC
|| form
== FORM_MOONKIN
)
3956 return SPELL_FAILED_NOT_SHAPESHIFT
;
3960 case SPELL_AURA_RANGED_ATTACK_POWER_ATTACKER_BONUS
:
3962 if(!m_targets
.getUnitTarget())
3963 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
3965 // can be casted at non-friendly unit or own pet/charm
3966 if(m_caster
->IsFriendlyTo(m_targets
.getUnitTarget()))
3967 return SPELL_FAILED_TARGET_FRIENDLY
;
3969 case SPELL_AURA_MOD_INCREASE_FLIGHT_SPEED
:
3970 case SPELL_AURA_FLY
:
3972 // not allow cast fly spells at old maps by players (all spells is self target)
3973 if(m_caster
->GetTypeId()==TYPEID_PLAYER
)
3975 if( !((Player
*)m_caster
)->isGameMaster() &&
3976 GetVirtualMapForMapAndZone(m_caster
->GetMapId(),m_caster
->GetZoneId()) != 530)
3977 return SPELL_FAILED_NOT_HERE
;
3980 case SPELL_AURA_PERIODIC_MANA_LEECH
:
3982 if (!m_targets
.getUnitTarget())
3983 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
3985 if (m_caster
->GetTypeId()!=TYPEID_PLAYER
|| m_CastItem
)
3988 if(m_targets
.getUnitTarget()->getPowerType()!=POWER_MANA
)
3989 return SPELL_FAILED_BAD_TARGETS
;
4000 int16
Spell::PetCanCast(Unit
* target
)
4002 if(!m_caster
->isAlive())
4003 return SPELL_FAILED_CASTER_DEAD
;
4005 if(m_caster
->IsNonMeleeSpellCasted(false)) //prevent spellcast interuption by another spellcast
4006 return SPELL_FAILED_SPELL_IN_PROGRESS
;
4007 if(m_caster
->isInCombat() && IsNonCombatSpell(m_spellInfo
))
4008 return SPELL_FAILED_AFFECTING_COMBAT
;
4010 if(m_caster
->GetTypeId()==TYPEID_UNIT
&& (((Creature
*)m_caster
)->isPet() || m_caster
->isCharmed()))
4012 //dead owner (pets still alive when owners ressed?)
4013 if(m_caster
->GetCharmerOrOwner() && !m_caster
->GetCharmerOrOwner()->isAlive())
4014 return SPELL_FAILED_CASTER_DEAD
;
4016 if(!target
&& m_targets
.getUnitTarget())
4017 target
= m_targets
.getUnitTarget();
4020 for(uint32 i
= 0;i
<3;i
++)
4022 if(m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CHAIN_DAMAGE
|| m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_FRIEND
|| m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_DUELVSPLAYER
|| m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_SINGLE_PARTY
|| m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_CURRENT_ENEMY_COORDINATES
)
4026 return SPELL_FAILED_BAD_IMPLICIT_TARGETS
;
4031 m_targets
.setUnitTarget(target
);
4033 Unit
* _target
= m_targets
.getUnitTarget();
4035 if(_target
) //for target dead/target not valid
4037 if(!_target
->isAlive())
4038 return SPELL_FAILED_BAD_TARGETS
;
4040 if(IsPositiveSpell(m_spellInfo
->Id
))
4042 if(m_caster
->IsHostileTo(_target
))
4043 return SPELL_FAILED_BAD_TARGETS
;
4047 bool duelvsplayertar
= false;
4048 for(int j
=0;j
<3;j
++)
4050 //TARGET_DUELVSPLAYER is positive AND negative
4051 duelvsplayertar
|= (m_spellInfo
->EffectImplicitTargetA
[j
] == TARGET_DUELVSPLAYER
);
4053 if(m_caster
->IsFriendlyTo(target
) && !duelvsplayertar
)
4055 return SPELL_FAILED_BAD_TARGETS
;
4060 if(((Creature
*)m_caster
)->HasSpellCooldown(m_spellInfo
->Id
))
4061 return SPELL_FAILED_NOT_READY
;
4064 uint16 result
= CanCast(true);
4068 return -1; //this allows to check spell fail 0, in combat
4071 uint8
Spell::CheckCasterAuras() const
4073 // Flag drop spells totally immuned to caster auras
4074 // FIXME: find more nice check for all totally immuned spells
4075 // AttributesEx3 & 0x10000000?
4076 if(m_spellInfo
->Id
==23336 || m_spellInfo
->Id
==23334 || m_spellInfo
->Id
==34991)
4079 uint8 school_immune
= 0;
4080 uint32 mechanic_immune
= 0;
4081 uint32 dispel_immune
= 0;
4083 //Check if the spell grants school or mechanic immunity.
4084 //We use bitmasks so the loop is done only once and not on every aura check below.
4085 if ( m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY
)
4087 for(int i
= 0;i
< 3; i
++)
4089 if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_SCHOOL_IMMUNITY
)
4090 school_immune
|= uint32(m_spellInfo
->EffectMiscValue
[i
]);
4091 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_MECHANIC_IMMUNITY
)
4092 mechanic_immune
|= 1 << uint32(m_spellInfo
->EffectMiscValue
[i
]);
4093 else if(m_spellInfo
->EffectApplyAuraName
[i
] == SPELL_AURA_DISPEL_IMMUNITY
)
4094 dispel_immune
|= GetDispellMask(DispelType(m_spellInfo
->EffectMiscValue
[i
]));
4096 //immune movement impairement and loss of control
4097 if(m_spellInfo
->Id
==(uint32
)42292)
4098 mechanic_immune
= IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK
;
4101 //Check whether the cast should be prevented by any state you might have.
4102 uint8 prevented_reason
= 0;
4103 // Have to check if there is a stun aura. Otherwise will have problems with ghost aura apply while logging out
4104 if(!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
) && m_caster
->HasAuraType(SPELL_AURA_MOD_STUN
))
4105 prevented_reason
= SPELL_FAILED_STUNNED
;
4106 else if(m_caster
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_CONFUSED
) && !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4107 prevented_reason
= SPELL_FAILED_CONFUSED
;
4108 else if(m_caster
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_FLEEING
) && !(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4109 prevented_reason
= SPELL_FAILED_FLEEING
;
4110 else if(m_caster
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_SILENCED
) && m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_SILENCE
)
4111 prevented_reason
= SPELL_FAILED_SILENCED
;
4112 else if(m_caster
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PACIFIED
) && m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_PACIFY
)
4113 prevented_reason
= SPELL_FAILED_PACIFIED
;
4115 // Attr must make flag drop spell totally immuned from all effects
4116 if(prevented_reason
)
4118 if(school_immune
|| mechanic_immune
|| dispel_immune
)
4120 //Checking auras is needed now, because you are prevented by some state but the spell grants immunity.
4121 Unit::AuraMap
const& auras
= m_caster
->GetAuras();
4122 for(Unit::AuraMap::const_iterator itr
= auras
.begin(); itr
!= auras
.end(); itr
++)
4126 if( GetSpellMechanicMask(itr
->second
->GetSpellProto(), itr
->second
->GetEffIndex()) & mechanic_immune
)
4128 if( GetSpellSchoolMask(itr
->second
->GetSpellProto()) & school_immune
)
4130 if( (1<<(itr
->second
->GetSpellProto()->Dispel
)) & dispel_immune
)
4133 //Make a second check for spell failed so the right SPELL_FAILED message is returned.
4134 //That is needed when your casting is prevented by multiple states and you are only immune to some of them.
4135 switch(itr
->second
->GetModifier()->m_auraname
)
4137 case SPELL_AURA_MOD_STUN
:
4138 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_STUNNED
))
4139 return SPELL_FAILED_STUNNED
;
4141 case SPELL_AURA_MOD_CONFUSE
:
4142 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_CONFUSED
))
4143 return SPELL_FAILED_CONFUSED
;
4145 case SPELL_AURA_MOD_FEAR
:
4146 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_USABLE_WHILE_FEARED
))
4147 return SPELL_FAILED_FLEEING
;
4149 case SPELL_AURA_MOD_SILENCE
:
4150 case SPELL_AURA_MOD_PACIFY
:
4151 case SPELL_AURA_MOD_PACIFY_SILENCE
:
4152 if( m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_PACIFY
)
4153 return SPELL_FAILED_PACIFIED
;
4154 else if ( m_spellInfo
->PreventionType
==SPELL_PREVENTION_TYPE_SILENCE
)
4155 return SPELL_FAILED_SILENCED
;
4161 //You are prevented from casting and the spell casted does not grant immunity. Return a failed error.
4163 return prevented_reason
;
4168 bool Spell::CanAutoCast(Unit
* target
)
4170 uint64 targetguid
= target
->GetGUID();
4172 for(uint32 j
= 0;j
<3;j
++)
4174 if(m_spellInfo
->Effect
[j
] == SPELL_EFFECT_APPLY_AURA
)
4176 if( m_spellInfo
->StackAmount
<= 1)
4178 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4183 if( target
->GetAuras().count(Unit::spellEffectPair(m_spellInfo
->Id
, j
)) >= m_spellInfo
->StackAmount
)
4187 else if ( IsAreaAuraEffect( m_spellInfo
->Effect
[j
] ))
4189 if( target
->HasAura(m_spellInfo
->Id
, j
) )
4194 int16 result
= PetCanCast(target
);
4196 if(result
== -1 || result
== SPELL_FAILED_UNIT_NOT_INFRONT
)
4199 //check if among target units, our WANTED target is as well (->only self cast spells return false)
4200 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
4201 if( ihit
->targetGUID
== targetguid
)
4204 return false; //target invalid
4207 uint8
Spell::CheckRange(bool strict
)
4211 // self cast doesn't need range checking -- also for Starshards fix
4212 if (m_spellInfo
->rangeIndex
== 1) return 0;
4214 if (strict
) //add radius of caster
4216 else //add radius of caster and ~5 yds "give"
4219 SpellRangeEntry
const* srange
= sSpellRangeStore
.LookupEntry(m_spellInfo
->rangeIndex
);
4220 float max_range
= GetSpellMaxRange(srange
) + range_mod
;
4221 float min_range
= GetSpellMinRange(srange
);
4223 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4224 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_RANGE
, max_range
, this);
4226 Unit
*target
= m_targets
.getUnitTarget();
4228 if(target
&& target
!= m_caster
)
4230 // distance from target center in checks
4231 float dist
= m_caster
->GetDistance(target
->GetPositionX(),target
->GetPositionY(),target
->GetPositionZ());
4232 if(dist
> max_range
)
4233 return SPELL_FAILED_OUT_OF_RANGE
; //0x5A;
4234 if(dist
< min_range
)
4235 return SPELL_FAILED_TOO_CLOSE
;
4236 if( m_caster
->GetTypeId() == TYPEID_PLAYER
&&
4237 (m_spellInfo
->FacingCasterFlags
& SPELL_FACING_FLAG_INFRONT
) && !m_caster
->HasInArc( M_PI
, target
) )
4238 return SPELL_FAILED_UNIT_NOT_INFRONT
;
4241 if(m_targets
.m_targetMask
== TARGET_FLAG_DEST_LOCATION
&& m_targets
.m_destX
!= 0 && m_targets
.m_destY
!= 0 && m_targets
.m_destZ
!= 0)
4243 float dist
= m_caster
->GetDistance(m_targets
.m_destX
, m_targets
.m_destY
, m_targets
.m_destZ
);
4244 if(dist
> max_range
)
4245 return SPELL_FAILED_OUT_OF_RANGE
;
4246 if(dist
< min_range
)
4247 return SPELL_FAILED_TOO_CLOSE
;
4253 int32
Spell::CalculatePowerCost()
4255 // item cast not used power
4259 // Spell drain all exist power on cast (Only paladin lay of Hands)
4260 if (m_spellInfo
->AttributesEx
& SPELL_ATTR_EX_DRAIN_ALL_POWER
)
4262 // If power type - health drain all
4263 if (m_spellInfo
->powerType
== POWER_HEALTH
)
4264 return m_caster
->GetHealth();
4265 // Else drain all power
4266 if (m_spellInfo
->powerType
< MAX_POWERS
)
4267 return m_caster
->GetPower(Powers(m_spellInfo
->powerType
));
4268 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4273 int32 powerCost
= m_spellInfo
->manaCost
;
4274 // PCT cost from total amount
4275 if (m_spellInfo
->ManaCostPercentage
)
4277 switch (m_spellInfo
->powerType
)
4279 // health as power used
4281 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateHealth() / 100;
4284 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetCreateMana() / 100;
4289 case POWER_HAPPINESS
:
4290 // case POWER_RUNES:
4291 powerCost
+= m_spellInfo
->ManaCostPercentage
* m_caster
->GetMaxPower(Powers(m_spellInfo
->powerType
)) / 100;
4294 sLog
.outError("Spell::CalculateManaCost: Unknown power type '%d' in spell %d", m_spellInfo
->powerType
, m_spellInfo
->Id
);
4298 SpellSchools school
= GetFirstSchoolInMask(m_spellSchoolMask
);
4299 // Flat mod from caster auras by spell school
4300 powerCost
+= m_caster
->GetInt32Value(UNIT_FIELD_POWER_COST_MODIFIER
+ school
);
4301 // Shiv - costs 20 + weaponSpeed*10 energy (apply only to non-triggered spell with energy cost)
4302 if ( m_spellInfo
->AttributesEx4
& SPELL_ATTR_EX4_SPELL_VS_EXTEND_COST
)
4303 powerCost
+= m_caster
->GetAttackTime(OFF_ATTACK
)/100;
4304 // Apply cost mod by spell
4305 if(Player
* modOwner
= m_caster
->GetSpellModOwner())
4306 modOwner
->ApplySpellMod(m_spellInfo
->Id
, SPELLMOD_COST
, powerCost
, this);
4308 if(m_spellInfo
->Attributes
& SPELL_ATTR_LEVEL_DAMAGE_CALCULATION
)
4309 powerCost
= int32(powerCost
/ (1.117f
* m_spellInfo
->spellLevel
/ m_caster
->getLevel() -0.1327f
));
4311 // PCT mod from user auras by school
4312 powerCost
= int32(powerCost
* (1.0f
+m_caster
->GetFloatValue(UNIT_FIELD_POWER_COST_MULTIPLIER
+school
)));
4318 uint8
Spell::CheckPower()
4320 // item cast not used power
4324 // health as power used - need check health amount
4325 if(m_spellInfo
->powerType
== POWER_HEALTH
)
4327 if(m_caster
->GetHealth() <= m_powerCost
)
4328 return SPELL_FAILED_CASTER_AURASTATE
;
4331 // Check valid power type
4332 if( m_spellInfo
->powerType
>= MAX_POWERS
)
4334 sLog
.outError("Spell::CheckMana: Unknown power type '%d'", m_spellInfo
->powerType
);
4335 return SPELL_FAILED_UNKNOWN
;
4337 // Check power amount
4338 Powers powerType
= Powers(m_spellInfo
->powerType
);
4339 if(m_caster
->GetPower(powerType
) < m_powerCost
)
4340 return SPELL_FAILED_NO_POWER
;
4345 uint8
Spell::CheckItems()
4347 if (m_caster
->GetTypeId() != TYPEID_PLAYER
)
4350 uint32 itemid
, itemcount
;
4351 Player
* p_caster
= (Player
*)m_caster
;
4355 itemid
= m_CastItem
->GetEntry();
4356 if( !p_caster
->HasItemCount(itemid
,1) )
4357 return SPELL_FAILED_ITEM_NOT_READY
;
4360 ItemPrototype
const *proto
= m_CastItem
->GetProto();
4362 return SPELL_FAILED_ITEM_NOT_READY
;
4364 for (int i
= 0; i
<5; i
++)
4366 if (proto
->Spells
[i
].SpellCharges
)
4368 if(m_CastItem
->GetSpellCharges(i
)==0)
4369 return SPELL_FAILED_NO_CHARGES_REMAIN
;
4373 uint32 ItemClass
= proto
->Class
;
4374 if (ItemClass
== ITEM_CLASS_CONSUMABLE
&& m_targets
.getUnitTarget())
4376 for (int i
= 0; i
< 3; i
++)
4378 // skip check, pet not required like checks, and for TARGET_PET m_targets.getUnitTarget() is not the real target but the caster
4379 if (m_spellInfo
->EffectImplicitTargetA
[i
] == TARGET_PET
)
4382 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_HEAL
)
4383 if (m_targets
.getUnitTarget()->GetHealth() == m_targets
.getUnitTarget()->GetMaxHealth())
4384 return (uint8
)SPELL_FAILED_ALREADY_AT_FULL_HEALTH
;
4386 // Mana Potion, Rage Potion, Thistle Tea(Rogue), ...
4387 if (m_spellInfo
->Effect
[i
] == SPELL_EFFECT_ENERGIZE
)
4389 if(m_spellInfo
->EffectMiscValue
[i
] < 0 || m_spellInfo
->EffectMiscValue
[i
] >= MAX_POWERS
)
4390 return (uint8
)SPELL_FAILED_ALREADY_AT_FULL_POWER
;
4392 Powers power
= Powers(m_spellInfo
->EffectMiscValue
[i
]);
4394 if (m_targets
.getUnitTarget()->GetPower(power
) == m_targets
.getUnitTarget()->GetMaxPower(power
))
4395 return (uint8
)SPELL_FAILED_ALREADY_AT_FULL_POWER
;
4402 if(m_targets
.getItemTargetGUID())
4404 if(m_caster
->GetTypeId() != TYPEID_PLAYER
)
4405 return SPELL_FAILED_BAD_TARGETS
;
4407 if(!m_targets
.getItemTarget())
4408 return SPELL_FAILED_ITEM_GONE
;
4410 if(!m_targets
.getItemTarget()->IsFitToSpellRequirements(m_spellInfo
))
4411 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
4413 // if not item target then required item must be equipped
4416 if(m_caster
->GetTypeId() == TYPEID_PLAYER
&& !((Player
*)m_caster
)->HasItemFitToSpellReqirements(m_spellInfo
))
4417 return SPELL_FAILED_EQUIPPED_ITEM_CLASS
;
4420 if(m_spellInfo
->RequiresSpellFocus
)
4422 CellPair
p(MaNGOS::ComputeCellPair(m_caster
->GetPositionX(), m_caster
->GetPositionY()));
4424 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
4426 GameObject
* ok
= NULL
;
4427 MaNGOS::GameObjectFocusCheck
go_check(m_caster
,m_spellInfo
->RequiresSpellFocus
);
4428 MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
> checker(ok
,go_check
);
4430 TypeContainerVisitor
<MaNGOS::GameObjectSearcher
<MaNGOS::GameObjectFocusCheck
>, GridTypeMapContainer
> object_checker(checker
);
4431 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
4432 cell_lock
->Visit(cell_lock
, object_checker
, *MapManager::Instance().GetMap(m_caster
->GetMapId(), m_caster
));
4435 return (uint8
)SPELL_FAILED_REQUIRES_SPELL_FOCUS
;
4437 focusObject
= ok
; // game object found in range
4440 if (!(m_spellInfo
->AttributesEx5
& SPELL_ATTR_EX5_NO_REAGENT_WHILE_PREP
&&
4441 m_caster
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_PREPARATION
)))
4443 for(uint32 i
=0;i
<8;i
++)
4445 if(m_spellInfo
->Reagent
[i
] <= 0)
4448 itemid
= m_spellInfo
->Reagent
[i
];
4449 itemcount
= m_spellInfo
->ReagentCount
[i
];
4451 // if CastItem is also spell reagent
4452 if( m_CastItem
&& m_CastItem
->GetEntry() == itemid
)
4454 ItemPrototype
const *proto
= m_CastItem
->GetProto();
4456 return SPELL_FAILED_ITEM_NOT_READY
;
4457 for(int s
=0;s
<5;s
++)
4459 // CastItem will be used up and does not count as reagent
4460 int32 charges
= m_CastItem
->GetSpellCharges(s
);
4461 if (proto
->Spells
[s
].SpellCharges
< 0 && abs(charges
) < 2)
4468 if( !p_caster
->HasItemCount(itemid
,itemcount
) )
4469 return (uint8
)SPELL_FAILED_ITEM_NOT_READY
; //0x54
4474 for(int i
=0;i
<2;++i
)
4476 if(m_spellInfo
->Totem
[i
] != 0)
4478 if( p_caster
->HasItemCount(m_spellInfo
->Totem
[i
],1) )
4487 return (uint8
)SPELL_FAILED_TOTEMS
; //0x7C
4489 //Check items for TotemCategory
4490 uint32 TotemCategory
= 2;
4491 for(int i
=0;i
<2;++i
)
4493 if(m_spellInfo
->TotemCategory
[i
] != 0)
4495 if( p_caster
->HasItemTotemCategory(m_spellInfo
->TotemCategory
[i
]) )
4504 if(TotemCategory
!= 0)
4505 return (uint8
)SPELL_FAILED_TOTEM_CATEGORY
; //0x7B
4507 for(int i
= 0; i
< 3; i
++)
4509 switch (m_spellInfo
->Effect
[i
])
4511 case SPELL_EFFECT_CREATE_ITEM
:
4513 if (!m_IsTriggeredSpell
&& m_spellInfo
->EffectItemType
[i
])
4515 ItemPosCountVec dest
;
4516 uint8 msg
= p_caster
->CanStoreNewItem(NULL_BAG
, NULL_SLOT
, dest
, m_spellInfo
->EffectItemType
[i
], 1 );
4517 if (msg
!= EQUIP_ERR_OK
)
4519 p_caster
->SendEquipError( msg
, NULL
, NULL
);
4520 return SPELL_FAILED_DONT_REPORT
;
4525 case SPELL_EFFECT_ENCHANT_ITEM
:
4527 Item
* targetItem
= m_targets
.getItemTarget();
4529 return SPELL_FAILED_ITEM_NOT_FOUND
;
4531 if( targetItem
->GetProto()->ItemLevel
< m_spellInfo
->baseLevel
)
4532 return SPELL_FAILED_LOWLEVEL
;
4533 // Not allow enchant in trade slot for some enchant type
4534 if( targetItem
->GetOwner() != m_caster
)
4536 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
4537 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
4539 return SPELL_FAILED_ERROR
;
4540 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
4541 return SPELL_FAILED_NOT_TRADEABLE
;
4545 case SPELL_EFFECT_ENCHANT_ITEM_TEMPORARY
:
4547 Item
*item
= m_targets
.getItemTarget();
4549 return SPELL_FAILED_ITEM_NOT_FOUND
;
4550 // Not allow enchant in trade slot for some enchant type
4551 if( item
->GetOwner() != m_caster
)
4553 uint32 enchant_id
= m_spellInfo
->EffectMiscValue
[i
];
4554 SpellItemEnchantmentEntry
const *pEnchant
= sSpellItemEnchantmentStore
.LookupEntry(enchant_id
);
4556 return SPELL_FAILED_ERROR
;
4557 if (pEnchant
->slot
& ENCHANTMENT_CAN_SOULBOUND
)
4558 return SPELL_FAILED_NOT_TRADEABLE
;
4562 case SPELL_EFFECT_ENCHANT_HELD_ITEM
:
4563 // check item existence in effect code (not output errors at offhand hold item effect to main hand for example
4565 case SPELL_EFFECT_DISENCHANT
:
4567 if(!m_targets
.getItemTarget())
4568 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
4570 // prevent disenchanting in trade slot
4571 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
4572 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
4574 ItemPrototype
const* itemProto
= m_targets
.getItemTarget()->GetProto();
4576 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
4578 uint32 item_quality
= itemProto
->Quality
;
4579 // 2.0.x addon: Check player enchanting level agains the item desenchanting requirements
4580 uint32 item_disenchantskilllevel
= itemProto
->RequiredDisenchantSkill
;
4581 if (item_disenchantskilllevel
== uint32(-1))
4582 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
4583 if (item_disenchantskilllevel
> p_caster
->GetSkillValue(SKILL_ENCHANTING
))
4584 return SPELL_FAILED_LOW_CASTLEVEL
;
4585 if(item_quality
> 4 || item_quality
< 2)
4586 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
4587 if(itemProto
->Class
!= ITEM_CLASS_WEAPON
&& itemProto
->Class
!= ITEM_CLASS_ARMOR
)
4588 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
4589 if (!itemProto
->DisenchantID
)
4590 return SPELL_FAILED_CANT_BE_DISENCHANTED
;
4593 case SPELL_EFFECT_PROSPECTING
:
4595 if(!m_targets
.getItemTarget())
4596 return SPELL_FAILED_CANT_BE_PROSPECTED
;
4597 //ensure item is a prospectable ore
4598 if(!(m_targets
.getItemTarget()->GetProto()->BagFamily
& BAG_FAMILY_MASK_MINING_SUPP
) || m_targets
.getItemTarget()->GetProto()->Class
!= ITEM_CLASS_TRADE_GOODS
)
4599 return SPELL_FAILED_CANT_BE_PROSPECTED
;
4600 //prevent prospecting in trade slot
4601 if( m_targets
.getItemTarget()->GetOwnerGUID() != m_caster
->GetGUID() )
4602 return SPELL_FAILED_CANT_BE_PROSPECTED
;
4603 //Check for enough skill in jewelcrafting
4604 uint32 item_prospectingskilllevel
= m_targets
.getItemTarget()->GetProto()->RequiredSkillRank
;
4605 if(item_prospectingskilllevel
>p_caster
->GetSkillValue(SKILL_JEWELCRAFTING
))
4606 return SPELL_FAILED_LOW_CASTLEVEL
;
4607 //make sure the player has the required ores in inventory
4608 if(m_targets
.getItemTarget()->GetCount() < 5)
4609 return SPELL_FAILED_PROSPECT_NEED_MORE
;
4611 if(!LootTemplates_Prospecting
.HaveLootFor(m_targets
.getItemTargetEntry()))
4612 return SPELL_FAILED_CANT_BE_PROSPECTED
;
4616 case SPELL_EFFECT_WEAPON_DAMAGE
:
4617 case SPELL_EFFECT_WEAPON_DAMAGE_NOSCHOOL
:
4619 if(m_caster
->GetTypeId() != TYPEID_PLAYER
) return SPELL_FAILED_TARGET_NOT_PLAYER
;
4620 if( m_attackType
!= RANGED_ATTACK
)
4622 Item
*pItem
= ((Player
*)m_caster
)->GetWeaponForAttack(m_attackType
);
4623 if(!pItem
|| pItem
->IsBroken())
4624 return SPELL_FAILED_EQUIPPED_ITEM
;
4626 switch(pItem
->GetProto()->SubClass
)
4628 case ITEM_SUBCLASS_WEAPON_THROWN
:
4630 uint32 ammo
= pItem
->GetEntry();
4631 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
4632 return SPELL_FAILED_NO_AMMO
;
4634 case ITEM_SUBCLASS_WEAPON_GUN
:
4635 case ITEM_SUBCLASS_WEAPON_BOW
:
4636 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
4638 uint32 ammo
= ((Player
*)m_caster
)->GetUInt32Value(PLAYER_AMMO_ID
);
4642 if(m_caster
->GetDummyAura(46699))
4643 break; // skip other checks
4645 return SPELL_FAILED_NO_AMMO
;
4648 ItemPrototype
const *ammoProto
= objmgr
.GetItemPrototype( ammo
);
4650 return SPELL_FAILED_NO_AMMO
;
4652 if(ammoProto
->Class
!= ITEM_CLASS_PROJECTILE
)
4653 return SPELL_FAILED_NO_AMMO
;
4655 // check ammo ws. weapon compatibility
4656 switch(pItem
->GetProto()->SubClass
)
4658 case ITEM_SUBCLASS_WEAPON_BOW
:
4659 case ITEM_SUBCLASS_WEAPON_CROSSBOW
:
4660 if(ammoProto
->SubClass
!=ITEM_SUBCLASS_ARROW
)
4661 return SPELL_FAILED_NO_AMMO
;
4663 case ITEM_SUBCLASS_WEAPON_GUN
:
4664 if(ammoProto
->SubClass
!=ITEM_SUBCLASS_BULLET
)
4665 return SPELL_FAILED_NO_AMMO
;
4668 return SPELL_FAILED_NO_AMMO
;
4671 if( !((Player
*)m_caster
)->HasItemCount( ammo
, 1 ) )
4672 return SPELL_FAILED_NO_AMMO
;
4674 case ITEM_SUBCLASS_WEAPON_WAND
:
4687 void Spell::Delayed()
4689 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
)
4692 if (m_spellState
== SPELL_STATE_DELAYED
)
4693 return; // spell is active and can't be time-backed
4695 // spells not loosing casting time ( slam, dynamites, bombs.. )
4696 if(!(m_spellInfo
->InterruptFlags
& SPELL_INTERRUPT_FLAG_DAMAGE
))
4699 //check resist chance
4700 int32 resistChance
= 100; //must be initialized to 100 for percent modifiers
4701 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
,SPELLMOD_NOT_LOSE_CASTING_TIME
,resistChance
, this);
4702 resistChance
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_RESIST_PUSHBACK
) - 100;
4703 if (roll_chance_i(resistChance
))
4706 int32 delaytime
= GetNextDelayAtDamageMsTime();
4708 if(int32(m_timer
) + delaytime
> m_casttime
)
4710 delaytime
= m_casttime
- m_timer
;
4711 m_timer
= m_casttime
;
4714 m_timer
+= delaytime
;
4716 sLog
.outDetail("Spell %u partially interrupted for (%d) ms at damage",m_spellInfo
->Id
,delaytime
);
4718 WorldPacket
data(SMSG_SPELL_DELAYED
, 8+4);
4719 data
.append(m_caster
->GetPackGUID());
4720 data
<< uint32(delaytime
);
4722 m_caster
->SendMessageToSet(&data
,true);
4725 void Spell::DelayedChannel()
4727 if(!m_caster
|| m_caster
->GetTypeId() != TYPEID_PLAYER
|| getState() != SPELL_STATE_CASTING
)
4730 //check resist chance
4731 int32 resistChance
= 100; //must be initialized to 100 for percent modifiers
4732 ((Player
*)m_caster
)->ApplySpellMod(m_spellInfo
->Id
,SPELLMOD_NOT_LOSE_CASTING_TIME
,resistChance
, this);
4733 resistChance
+= m_caster
->GetTotalAuraModifier(SPELL_AURA_RESIST_PUSHBACK
) - 100;
4734 if (roll_chance_i(resistChance
))
4737 int32 delaytime
= GetNextDelayAtDamageMsTime();
4739 if(int32(m_timer
) < delaytime
)
4741 delaytime
= m_timer
;
4745 m_timer
-= delaytime
;
4747 sLog
.outDebug("Spell %u partially interrupted for %i ms, new duration: %u ms", m_spellInfo
->Id
, delaytime
, m_timer
);
4749 for(std::list
<TargetInfo
>::iterator ihit
= m_UniqueTargetInfo
.begin();ihit
!= m_UniqueTargetInfo
.end();++ihit
)
4751 if ((*ihit
).missCondition
== SPELL_MISS_NONE
)
4753 Unit
* unit
= m_caster
->GetGUID()==ihit
->targetGUID
? m_caster
: ObjectAccessor::GetUnit(*m_caster
, ihit
->targetGUID
);
4756 for (int j
=0;j
<3;j
++)
4757 if( ihit
->effectMask
& (1<<j
) )
4758 unit
->DelayAura(m_spellInfo
->Id
, j
, delaytime
);
4764 for(int j
= 0; j
< 3; j
++)
4766 // partially interrupt persistent area auras
4767 DynamicObject
* dynObj
= m_caster
->GetDynObject(m_spellInfo
->Id
, j
);
4769 dynObj
->Delay(delaytime
);
4772 SendChannelUpdate(m_timer
);
4775 void Spell::UpdatePointers()
4777 if(m_originalCasterGUID
==m_caster
->GetGUID())
4778 m_originalCaster
= m_caster
;
4781 m_originalCaster
= ObjectAccessor::GetUnit(*m_caster
,m_originalCasterGUID
);
4782 if(m_originalCaster
&& !m_originalCaster
->IsInWorld()) m_originalCaster
= NULL
;
4785 m_targets
.Update(m_caster
);
4788 bool Spell::IsAffectedBy(SpellEntry
const *spellInfo
, uint32 effectId
)
4790 return spellmgr
.IsAffectedBySpell(m_spellInfo
,spellInfo
->Id
,effectId
,spellInfo
->EffectItemType
[effectId
]);
4793 bool Spell::CheckTargetCreatureType(Unit
* target
) const
4795 uint32 spellCreatureTargetMask
= m_spellInfo
->TargetCreatureType
;
4797 // Curse of Doom : not find another way to fix spell target check :/
4798 if(m_spellInfo
->SpellFamilyName
==SPELLFAMILY_WARLOCK
&& m_spellInfo
->SpellFamilyFlags
== 0x0200000000LL
)
4800 // not allow cast at player
4801 if(target
->GetTypeId()==TYPEID_PLAYER
)
4804 spellCreatureTargetMask
= 0x7FF;
4807 // Dismiss Pet and Taming Lesson skipped
4808 if(m_spellInfo
->Id
== 2641 || m_spellInfo
->Id
== 23356)
4809 spellCreatureTargetMask
= 0;
4811 if (spellCreatureTargetMask
)
4813 uint32 TargetCreatureType
= target
->GetCreatureTypeMask();
4815 return !TargetCreatureType
|| (spellCreatureTargetMask
& TargetCreatureType
);
4820 CurrentSpellTypes
Spell::GetCurrentContainer()
4822 if (IsNextMeleeSwingSpell())
4823 return(CURRENT_MELEE_SPELL
);
4824 else if (IsAutoRepeat())
4825 return(CURRENT_AUTOREPEAT_SPELL
);
4826 else if (IsChanneledSpell(m_spellInfo
))
4827 return(CURRENT_CHANNELED_SPELL
);
4829 return(CURRENT_GENERIC_SPELL
);
4832 bool Spell::CheckTarget( Unit
* target
, uint32 eff
, bool hitPhase
)
4834 // Check targets for creature type mask and remove not appropriate (skip explicit self target case, maybe need other explicit targets)
4835 if(m_spellInfo
->EffectImplicitTargetA
[eff
]!=TARGET_SELF
)
4837 if (!CheckTargetCreatureType(target
))
4841 // Check targets for not_selectable unit flag and remove
4842 // A player can cast spells on his pet (or other controlled unit) though in any state
4843 if (target
!= m_caster
&& target
->GetCharmerOrOwnerGUID() != m_caster
->GetGUID())
4845 // any unattackable target skipped
4846 if (target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NON_ATTACKABLE
))
4849 // unselectable targets skipped in all cases except TARGET_SCRIPT targeting
4850 // in case TARGET_SCRIPT target selected by server always and can't be cheated
4851 if( target
->HasFlag(UNIT_FIELD_FLAGS
, UNIT_FLAG_NOT_SELECTABLE
) &&
4852 m_spellInfo
->EffectImplicitTargetA
[eff
] != TARGET_SCRIPT
&&
4853 m_spellInfo
->EffectImplicitTargetB
[eff
] != TARGET_SCRIPT
)
4857 //Check player targets and remove if in GM mode or GM invisibility (for not self casting case)
4858 if( target
!= m_caster
&& target
->GetTypeId()==TYPEID_PLAYER
)
4860 if(((Player
*)target
)->GetVisibility()==VISIBILITY_OFF
)
4863 if(((Player
*)target
)->isGameMaster() && !IsPositiveSpell(m_spellInfo
->Id
))
4867 //Check targets for LOS visibility (except spells without range limitations )
4868 switch(m_spellInfo
->Effect
[eff
])
4870 case SPELL_EFFECT_SUMMON_PLAYER
: // from anywhere
4872 case SPELL_EFFECT_DUMMY
:
4873 if(m_spellInfo
->Id
!=20577) // Cannibalize
4876 case SPELL_EFFECT_RESURRECT_NEW
:
4877 // player far away, maybe his corpse near?
4878 if(target
!=m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
4880 if(!m_targets
.getCorpseTargetGUID())
4883 Corpse
*corpse
= ObjectAccessor::GetCorpse(*m_caster
,m_targets
.getCorpseTargetGUID());
4887 if(target
->GetGUID()!=corpse
->GetOwnerGUID())
4890 if(!corpse
->IsWithinLOSInMap(m_caster
))
4894 // all ok by some way or another, skip normal check
4896 default: // normal case
4897 if(target
!=m_caster
&& !target
->IsWithinLOSInMap(m_caster
))
4905 Unit
* Spell::SelectMagnetTarget()
4907 Unit
* target
= m_targets
.getUnitTarget();
4909 if(target
&& target
->HasAuraType(SPELL_AURA_SPELL_MAGNET
) && !(m_spellInfo
->Attributes
& 0x10))
4911 Unit::AuraList
const& magnetAuras
= target
->GetAurasByType(SPELL_AURA_SPELL_MAGNET
);
4912 for(Unit::AuraList::const_iterator itr
= magnetAuras
.begin(); itr
!= magnetAuras
.end(); ++itr
)
4914 if(Unit
* magnet
= (*itr
)->GetCaster())
4916 if(magnet
->IsWithinLOSInMap(m_caster
))
4919 m_targets
.setUnitTarget(target
);
4929 bool Spell::IsNeedSendToClient() const
4931 return m_spellInfo
->SpellVisual
!=0 || IsChanneledSpell(m_spellInfo
) ||
4932 m_spellInfo
->speed
> 0.0f
|| !m_triggeredByAuraSpell
&& !m_IsTriggeredSpell
;
4935 bool Spell::HaveTargetsForEffect( uint8 effect
) const
4937 for(std::list
<TargetInfo
>::const_iterator itr
= m_UniqueTargetInfo
.begin();itr
!= m_UniqueTargetInfo
.end();++itr
)
4938 if(itr
->effectMask
& (1<<effect
))
4941 for(std::list
<GOTargetInfo
>::const_iterator itr
= m_UniqueGOTargetInfo
.begin();itr
!= m_UniqueGOTargetInfo
.end();++itr
)
4942 if(itr
->effectMask
& (1<<effect
))
4945 for(std::list
<ItemTargetInfo
>::const_iterator itr
= m_UniqueItemInfo
.begin();itr
!= m_UniqueItemInfo
.end();++itr
)
4946 if(itr
->effectMask
& (1<<effect
))
4952 SpellEvent::SpellEvent(Spell
* spell
) : BasicEvent()
4957 SpellEvent::~SpellEvent()
4959 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
4962 if (m_Spell
->IsDeletable())
4968 sLog
.outError("~SpellEvent: %s %u tried to delete non-deletable spell %u. Was not deleted, causes memory leak.",
4969 (m_Spell
->GetCaster()->GetTypeId()==TYPEID_PLAYER
?"Player":"Creature"), m_Spell
->GetCaster()->GetGUIDLow(),m_Spell
->m_spellInfo
->Id
);
4973 bool SpellEvent::Execute(uint64 e_time
, uint32 p_time
)
4975 // update spell if it is not finished
4976 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)
4977 m_Spell
->update(p_time
);
4979 // check spell state to process
4980 switch (m_Spell
->getState())
4982 case SPELL_STATE_FINISHED
:
4984 // spell was finished, check deletable state
4985 if (m_Spell
->IsDeletable())
4987 // check, if we do have unfinished triggered spells
4989 return(true); // spell is deletable, finish event
4991 // event will be re-added automatically at the end of routine)
4994 case SPELL_STATE_CASTING
:
4996 // this spell is in channeled state, process it on the next update
4997 // event will be re-added automatically at the end of routine)
5000 case SPELL_STATE_DELAYED
:
5002 // first, check, if we have just started
5003 if (m_Spell
->GetDelayStart() != 0)
5005 // no, we aren't, do the typical update
5006 // check, if we have channeled spell on our hands
5007 if (IsChanneledSpell(m_Spell
->m_spellInfo
))
5009 // evented channeled spell is processed separately, casted once after delay, and not destroyed till finish
5010 // check, if we have casting anything else except this channeled spell and autorepeat
5011 if (m_Spell
->GetCaster()->IsNonMeleeSpellCasted(false, true, true))
5013 // another non-melee non-delayed spell is casted now, abort
5018 // do the action (pass spell to channeling state)
5019 m_Spell
->handle_immediate();
5021 // event will be re-added automatically at the end of routine)
5025 // run the spell handler and think about what we can do next
5026 uint64 t_offset
= e_time
- m_Spell
->GetDelayStart();
5027 uint64 n_offset
= m_Spell
->handle_delayed(t_offset
);
5030 // re-add us to the queue
5031 m_Spell
->GetCaster()->m_Events
.AddEvent(this, m_Spell
->GetDelayStart() + n_offset
, false);
5032 return(false); // event not complete
5035 // finish update event will be re-added automatically at the end of routine)
5040 // delaying had just started, record the moment
5041 m_Spell
->SetDelayStart(e_time
);
5042 // re-plan the event for the delay moment
5043 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ m_Spell
->GetDelayMoment(), false);
5044 return(false); // event not complete
5051 // event will be re-added automatically at the end of routine)
5055 // spell processing not complete, plan event on the next update interval
5056 m_Spell
->GetCaster()->m_Events
.AddEvent(this, e_time
+ 1, false);
5057 return(false); // event not complete
5060 void SpellEvent::Abort(uint64
/*e_time*/)
5062 // oops, the spell we try to do is aborted
5063 if (m_Spell
->getState() != SPELL_STATE_FINISHED
)