Core/AI: Fix a crash in UnitAI

This commit is contained in:
Spp-
2011-08-30 13:44:14 +02:00
parent d498a5b68f
commit fcf58e7062

View File

@@ -42,22 +42,26 @@ void UnitAI::DoMeleeAttackIfReady()
if (me->HasUnitState(UNIT_STAT_CASTING)) if (me->HasUnitState(UNIT_STAT_CASTING))
return; return;
Unit *victim = me->getVictim();
if (!victim || !victim->IsInWorld())
return;
//Make sure our attack is ready and we aren't currently casting before checking distance //Make sure our attack is ready and we aren't currently casting before checking distance
if (me->isAttackReady()) if (me->isAttackReady())
{ {
//If we are within range melee the target //If we are within range melee the target
if (me->IsWithinMeleeRange(me->getVictim())) if (me->IsWithinMeleeRange(victim))
{ {
me->AttackerStateUpdate(me->getVictim()); me->AttackerStateUpdate(victim);
me->resetAttackTimer(); me->resetAttackTimer();
} }
} }
if (me->haveOffhandWeapon() && me->isAttackReady(OFF_ATTACK)) if (me->haveOffhandWeapon() && me->isAttackReady(OFF_ATTACK))
{ {
//If we are within range melee the target //If we are within range melee the target
if (me->IsWithinMeleeRange(me->getVictim())) if (me->IsWithinMeleeRange(victim))
{ {
me->AttackerStateUpdate(me->getVictim(), OFF_ATTACK); me->AttackerStateUpdate(victim, OFF_ATTACK);
me->resetAttackTimer(OFF_ATTACK); me->resetAttackTimer(OFF_ATTACK);
} }
} }