TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SpellTargetSelector Struct Reference

#include <UnitAI.h>

Public Member Functions

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

Private Attributes

Unit const_caster
 
SpellInfo const_spellInfo
 

Detailed Description

Todo:
Add more checks from Spell::CheckCast

Constructor & Destructor Documentation

SpellTargetSelector::SpellTargetSelector ( Unit caster,
uint32  spellId 
)
261  :
262  _caster(caster), _spellInfo(sSpellMgr->GetSpellInfo(spellId))
263 {
265 }
Unit const * _caster
Definition: UnitAI.h:100
#define sSpellMgr
Definition: SpellMgr.h:756
#define ASSERT
Definition: Errors.h:55
SpellInfo const * _spellInfo
Definition: UnitAI.h:101

Member Function Documentation

bool SpellTargetSelector::operator() ( Unit const target) const
268 {
269  if (!target)
270  return false;
271 
272  if (_spellInfo->CheckTarget(_caster, target) != SPELL_CAST_OK)
273  return false;
274 
275  // copypasta from Spell::CheckRange
276  uint32 range_type = _spellInfo->RangeEntry ? _spellInfo->RangeEntry->Flags : 0;
277  float max_range = _caster->GetSpellMaxRangeForTarget(target, _spellInfo);
278  float min_range = _caster->GetSpellMinRangeForTarget(target, _spellInfo);
279 
280 
281  if (target && target != _caster)
282  {
283  if (range_type == SPELL_RANGE_MELEE)
284  {
285  // Because of lag, we can not check too strictly here.
286  if (!_caster->IsWithinMeleeRange(target, max_range))
287  return false;
288  }
289  else if (!_caster->IsWithinCombatRange(target, max_range))
290  return false;
291 
292  if (range_type == SPELL_RANGE_RANGED)
293  {
294  if (_caster->IsWithinMeleeRange(target))
295  return false;
296  }
297  else if (min_range && _caster->IsWithinCombatRange(target, min_range)) // skip this check if min_range = 0
298  return false;
299  }
300 
301  return true;
302 }
bool IsWithinCombatRange(const Unit *obj, float dist2compare) const
Definition: Unit.cpp:492
float GetSpellMinRangeForTarget(Unit const *target, SpellInfo const *spellInfo) const
Definition: Unit.cpp:11239
uint32 Flags
Definition: DB2Structure.h:1280
Definition: Spell.h:114
Unit const * _caster
Definition: UnitAI.h:100
SpellCastResult CheckTarget(Unit const *caster, WorldObject const *target, bool implicit=true) const
Definition: SpellInfo.cpp:1875
SpellRangeEntry const * RangeEntry
Definition: SpellInfo.h:379
uint32_t uint32
Definition: Define.h:150
bool IsWithinMeleeRange(const Unit *obj, float dist=MELEE_RANGE) const
Definition: Unit.cpp:508
Definition: Spell.h:115
SpellInfo const * _spellInfo
Definition: UnitAI.h:101
float GetSpellMaxRangeForTarget(Unit const *target, SpellInfo const *spellInfo) const
Definition: Unit.cpp:11228
Definition: SharedDefines.h:1538

+ Here is the call graph for this function:

Member Data Documentation

Unit const* SpellTargetSelector::_caster
private
SpellInfo const* SpellTargetSelector::_spellInfo
private

The documentation for this struct was generated from the following files: