AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
SpellTargetSelector Struct Reference

#include "UnitAI.h"

Inheritance diagram for SpellTargetSelector:
Acore::unary_function< Unit *, bool >

Public Member Functions

 SpellTargetSelector (Unit *caster, uint32 spellId)
 
bool operator() (Unit const *target) const
 

Private Attributes

Unit const * _caster
 
SpellInfo const * _spellInfo
 

Additional Inherited Members

- Public Types inherited from Acore::unary_function< Unit *, bool >
typedef Unitargument_type
 
typedef bool result_type
 

Detailed Description

Todo:
: Add more checks from Spell::CheckCast

Constructor & Destructor Documentation

◆ SpellTargetSelector()

SpellTargetSelector::SpellTargetSelector ( Unit caster,
uint32  spellId 
)
381 :
382 _caster(caster), _spellInfo(sSpellMgr->GetSpellForDifficultyFromSpell(sSpellMgr->GetSpellInfo(spellId), caster))
383{
385}
#define ASSERT
Definition: Errors.h:68
#define sSpellMgr
Definition: SpellMgr.h:825
SpellInfo const * _spellInfo
Definition: UnitAI.h:105
Unit const * _caster
Definition: UnitAI.h:104

References _spellInfo, and ASSERT.

Member Function Documentation

◆ operator()()

bool SpellTargetSelector::operator() ( Unit const *  target) const
388{
389 if (!target)
390 return false;
391
393 return false;
394
395 // copypasta from Spell::CheckRange
397 float max_range = _caster->GetSpellMaxRangeForTarget(target, _spellInfo);
398 float min_range = _caster->GetSpellMinRangeForTarget(target, _spellInfo);
399
400 if (target && target != _caster)
401 {
402 if (range_type == SPELL_RANGE_MELEE)
403 {
404 // Because of lag, we can not check too strictly here.
405 if (!_caster->IsWithinMeleeRange(target, max_range))
406 return false;
407 }
408 else if (!_caster->IsWithinCombatRange(target, max_range))
409 return false;
410
411 if (range_type == SPELL_RANGE_RANGED)
412 {
413 if (_caster->IsWithinMeleeRange(target))
414 return false;
415 }
416 else if (min_range && _caster->IsWithinCombatRange(target, min_range)) // skip this check if min_range = 0
417 return false;
418 }
419
420 return true;
421}
std::uint32_t uint32
Definition: Define.h:108
@ SPELL_RANGE_MELEE
Definition: Spell.h:89
@ SPELL_RANGE_RANGED
Definition: Spell.h:90
@ SPELL_CAST_OK
Definition: SharedDefines.h:1110
bool IsWithinCombatRange(Unit const *obj, float dist2compare) const
Definition: Unit.cpp:667
float GetSpellMinRangeForTarget(Unit const *target, SpellInfo const *spellInfo) const
Definition: Unit.cpp:15137
bool IsWithinMeleeRange(Unit const *obj, float dist=0.f) const
Definition: Unit.cpp:683
float GetSpellMaxRangeForTarget(Unit const *target, SpellInfo const *spellInfo) const
Definition: Unit.cpp:15117
SpellRangeEntry const * RangeEntry
Definition: SpellInfo.h:367
SpellCastResult CheckTarget(Unit const *caster, WorldObject const *target, bool implicit=true) const
Definition: SpellInfo.cpp:1744
uint32 Flags
Definition: DBCStructure.h:1797

References _caster, _spellInfo, SpellInfo::CheckTarget(), SpellRangeEntry::Flags, Unit::GetSpellMaxRangeForTarget(), Unit::GetSpellMinRangeForTarget(), Unit::IsWithinCombatRange(), Unit::IsWithinMeleeRange(), SpellInfo::RangeEntry, SPELL_CAST_OK, SPELL_RANGE_MELEE, and SPELL_RANGE_RANGED.

Member Data Documentation

◆ _caster

Unit const* SpellTargetSelector::_caster
private

Referenced by operator()().

◆ _spellInfo

SpellInfo const* SpellTargetSelector::_spellInfo
private

Referenced by operator()(), and SpellTargetSelector().