diff options
| author | Shauren <shauren.trinity@gmail.com> | 2011-09-24 23:30:11 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2011-09-24 23:30:11 +0200 |
| commit | b07cc3751f46d3bc848b7d1c3f5b350c7be084ee (patch) | |
| tree | 5fff40470eb880fc295e141715a220d7eda2b275 /src | |
| parent | da0229da8f6c22d71729bed54ab608b0b805112e (diff) | |
Core/Scripts: Added NULL checks to new target selectors, threat references aren't guaranteed to be valid always, also added (default true) player typeid check to NonTankTargetSelector
Diffstat (limited to 'src')
| -rwxr-xr-x | src/server/game/AI/CoreAI/UnitAI.cpp | 9 | ||||
| -rwxr-xr-x | src/server/game/AI/CoreAI/UnitAI.h | 3 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp index 82b0f5c7125..e11be0612a2 100755 --- a/src/server/game/AI/CoreAI/UnitAI.cpp +++ b/src/server/game/AI/CoreAI/UnitAI.cpp @@ -255,6 +255,9 @@ SpellTargetSelector::SpellTargetSelector(Unit* caster, uint32 spellId) : bool SpellTargetSelector::operator()(Unit const* target) const { + if (!target) + return false; + if (_spellInfo->CheckTarget(_caster, target) != SPELL_CAST_OK) return false; @@ -289,5 +292,11 @@ bool SpellTargetSelector::operator()(Unit const* target) const bool NonTankTargetSelector::operator()(Unit const* target) const { + if (!target) + return false; + + if (_playerOnly && target->GetTypeId() != TYPEID_PLAYER) + return false; + return target != _source->getVictim(); } diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h index bd6a9b37b5a..8485559c7fa 100755 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -116,11 +116,12 @@ struct SpellTargetSelector : public std::unary_function<Unit*, bool> struct NonTankTargetSelector : public std::unary_function<Unit*, bool> { public: - explicit NonTankTargetSelector(Creature* source) : _source(source) { } + NonTankTargetSelector(Creature* source, bool playerOnly = true) : _source(source), _playerOnly(playerOnly) { } bool operator()(Unit const* target) const; private: Creature const* _source; + bool _playerOnly; }; class UnitAI |
