Fix Crash in FoS.

Fixes issue #1566.

+ add support of minimum distance criteria in SelectTarget.

--HG--
branch : trunk
This commit is contained in:
Trazom62
2010-04-10 13:52:33 +02:00
parent 4a8bf5900d
commit 9d3c7c4ab0
2 changed files with 23 additions and 10 deletions
+16 -5
View File
@@ -83,23 +83,34 @@ bool UnitAI::DoSpellAttackIfReady(uint32 spell)
} }
// default predicate function to select target based on distance, player and/or aura criteria // default predicate function to select target based on distance, player and/or aura criteria
struct DefaultTargetSelector : public std::unary_function<Unit *, bool> { struct DefaultTargetSelector : public std::unary_function<Unit *, bool>
{
const Unit *me; const Unit *me;
float m_dist; float m_dist;
bool m_playerOnly; bool m_playerOnly;
int32 m_aura; int32 m_aura;
// pUnit: the reference unit // pUnit: the reference unit
// dist: if 0: ignored, if not 0: maximum distance to the reference unit // dist: if 0: ignored, if > 0: maximum distance to the reference unit, if < 0: minimum distance to the reference unit
// playerOnly: self explaining // playerOnly: self explaining
// aura: if 0: ignored, if > 0: the target shall have the aura, if < 0, the target shall NOT have the aura // aura: if 0: ignored, if > 0: the target shall have the aura, if < 0, the target shall NOT have the aura
DefaultTargetSelector(const Unit *pUnit, float dist, bool playerOnly, int32 aura) : me(pUnit), m_dist(dist), m_playerOnly(playerOnly), m_aura(aura) {} DefaultTargetSelector(const Unit *pUnit, float dist, bool playerOnly, int32 aura) : me(pUnit), m_dist(dist), m_playerOnly(playerOnly), m_aura(aura) {}
bool operator() (const Unit *pTarget) { bool operator() (const Unit *pTarget)
if (m_playerOnly && (!pTarget || pTarget->GetTypeId() != TYPEID_PLAYER)) {
if (!me)
return false; return false;
if (m_dist && (!me || !pTarget || !me->IsWithinCombatRange(pTarget, m_dist))) if (!pTarget)
return false;
if (m_playerOnly && (pTarget->GetTypeId() != TYPEID_PLAYER))
return false;
if (m_dist > 0.0f && !me->IsWithinCombatRange(pTarget, m_dist))
return false;
if (m_dist < 0.0f && me->IsWithinCombatRange(pTarget, -m_dist))
return false; return false;
if (m_aura) if (m_aura)
@@ -114,14 +114,16 @@ struct boss_bronjahmAI : public ScriptedAI
// Cast aura spell on all players farther than 10y // Cast aura spell on all players farther than 10y
void ApplySoulStorm() void ApplySoulStorm()
{ {
const std::list<HostileReference*>& threatlist = m_creature->getThreatManager().getThreatList(); std::list<Unit*> targetList;
if (threatlist.empty())
SelectTargetList(targetList, 100, SELECT_TARGET_TOPAGGRO, -10.0f);
if (targetList.empty())
return; return;
for (std::list<HostileReference*>::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr) for (std::list<Unit *>::const_iterator itr = targetList.begin(); itr != targetList.end(); ++itr)
{ {
Unit* pUnit = Unit::GetUnit(*m_creature, (*itr)->getUnitGuid()); Unit* pUnit = (*itr);
if (pUnit && pUnit->isAlive() && pUnit->GetDistance(m_creature) > 10.0f) if (pUnit && pUnit->isAlive())
m_creature->CastSpell(pUnit, DUNGEON_MODE(SPELL_SOULSTORM_AURA,H_SPELL_SOULSTORM_AURA), true); m_creature->CastSpell(pUnit, DUNGEON_MODE(SPELL_SOULSTORM_AURA,H_SPELL_SOULSTORM_AURA), true);
} }
} }