TrinityCore
Loading...
Searching...
No Matches
SpellTargetSelector Struct Reference

#include <UnitAICommon.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::SpellTargetSelector ( Unit caster,
uint32  spellId 
)
67 :
68 _caster(caster), _spellInfo(sSpellMgr->GetSpellInfo(spellId, caster->GetMap()->GetDifficultyID()))
69{
71}
#define ASSERT
Definition: Errors.h:68
#define sSpellMgr
Definition: SpellMgr.h:824
Difficulty GetDifficultyID() const
Definition: Map.h:307
Map * GetMap() const
Definition: Object.h:611
SpellInfo const * _spellInfo
Definition: UnitAICommon.h:76
Unit const * _caster
Definition: UnitAICommon.h:75

Member Function Documentation

◆ operator()()

bool SpellTargetSelector::operator() ( Unit const *  target) const
74{
75 if (!target)
76 return false;
77
79 return false;
80
81 // copypasta from Spell::CheckRange
82 float minRange = 0.0f;
83 float maxRange = 0.0f;
84 float rangeMod = 0.0f;
86 {
88 {
89 rangeMod = _caster->GetCombatReach() + 4.0f / 3.0f;
90 rangeMod += target->GetCombatReach();
91
92 rangeMod = std::max(rangeMod, NOMINAL_MELEE_RANGE);
93 }
94 else
95 {
96 float meleeRange = 0.0f;
98 {
99 meleeRange = _caster->GetCombatReach() + 4.0f / 3.0f;
100 meleeRange += target->GetCombatReach();
101
102 meleeRange = std::max(meleeRange, NOMINAL_MELEE_RANGE);
103 }
104
105 minRange = _caster->GetSpellMinRangeForTarget(target, _spellInfo) + meleeRange;
106 maxRange = _caster->GetSpellMaxRangeForTarget(target, _spellInfo);
107
108 rangeMod = _caster->GetCombatReach();
109 rangeMod += target->GetCombatReach();
110
111 if (minRange > 0.0f && !(_spellInfo->RangeEntry->Flags & SPELL_RANGE_RANGED))
112 minRange += rangeMod;
113 }
114
115 if (_caster->isMoving() && target->isMoving() && !_caster->IsWalking() && !target->IsWalking() &&
116 (_spellInfo->RangeEntry->Flags & SPELL_RANGE_MELEE || target->GetTypeId() == TYPEID_PLAYER))
117 rangeMod += 8.0f / 3.0f;
118 }
119
120 maxRange += rangeMod;
121
122 minRange *= minRange;
123 maxRange *= maxRange;
124
125 if (target != _caster)
126 {
127 if (_caster->GetExactDistSq(target) > maxRange)
128 return false;
129
130 if (minRange > 0.0f && _caster->GetExactDistSq(target) < minRange)
131 return false;
132 }
133
134 return true;
135}
#define NOMINAL_MELEE_RANGE
Definition: ObjectDefines.h:42
@ TYPEID_PLAYER
Definition: ObjectGuid.h:39
@ SPELL_CAST_OK
Definition: SharedDefines.h:1762
@ SPELL_RANGE_MELEE
Definition: Spell.h:151
@ SPELL_RANGE_RANGED
Definition: Spell.h:152
SpellRangeEntry const * RangeEntry
Definition: SpellInfo.h:388
SpellCastResult CheckTarget(WorldObject const *caster, WorldObject const *target, bool implicit=true) const
Definition: SpellInfo.cpp:2136
float GetCombatReach() const override
Definition: Unit.h:804
bool isMoving() const
Definition: Unit.h:1825
bool IsWalking() const
Definition: Unit.h:1225
float GetSpellMinRangeForTarget(Unit const *target, SpellInfo const *spellInfo) const
Definition: Object.cpp:2274
float GetSpellMaxRangeForTarget(Unit const *target, SpellInfo const *spellInfo) const
Definition: Object.cpp:2260
float GetExactDistSq(float x, float y, float z) const
Definition: Position.h:111
uint8 Flags
Definition: DB2Structure.h:3657
+ Here is the call graph for this function:

Member Data Documentation

◆ _caster

Unit const* SpellTargetSelector::_caster
private

◆ _spellInfo

SpellInfo const* SpellTargetSelector::_spellInfo
private

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