From b07cc3751f46d3bc848b7d1c3f5b350c7be084ee Mon Sep 17 00:00:00 2001 From: Shauren Date: Sat, 24 Sep 2011 23:30:11 +0200 Subject: 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 --- src/server/game/AI/CoreAI/UnitAI.cpp | 9 +++++++++ src/server/game/AI/CoreAI/UnitAI.h | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'src') 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 struct NonTankTargetSelector : public std::unary_function { 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 -- cgit v1.2.3