Core/PetAI: Fixed a crash in PetAI::CanAttack

Closes #8660
This commit is contained in:
Subv
2012-12-14 11:06:56 -05:00
parent 36c3e46fdb
commit 4b1e65d057
+6 -2
View File
@@ -550,10 +550,14 @@ bool PetAI::CanAttack(Unit* target)
return (me->IsWithinMeleeRange(target) || me->GetCharmInfo()->IsCommandAttack());
// Pets attacking something (or chasing) should only switch targets if owner tells them to
if (me->getVictim() && (me->getVictim() != target))
if (me->getVictim() && me->getVictim() != target)
{
// Check if our owner selected this target and clicked "attack"
Unit* ownerTarget = me->GetCharmerOrOwner()->ToPlayer()->GetSelectedUnit();
Unit* ownerTarget = NULL;
if (Player* owner = me->GetCharmerOrOwner()->ToPlayer())
ownerTarget = owner->GetSelectedUnit();
else
ownerTarget = me->GetCharmerOrOwner()->getVictim();
if (ownerTarget && me->GetCharmInfo()->IsCommandAttack())
return (target->GetGUID() == ownerTarget->GetGUID());