mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
Put IsValidAttackTarget check on both bots and their pets (#833)
* Prevent PetAttackAction on invalid targets * Prevent AttackAction on invalid targets in general
This commit is contained in:
@@ -75,6 +75,14 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!bot->IsValidAttackTarget(target))
|
||||||
|
{
|
||||||
|
if (verbose)
|
||||||
|
botAI->TellError("I cannot attack an invalid target");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::ostringstream msg;
|
std::ostringstream msg;
|
||||||
msg << target->GetName();
|
msg << target->GetName();
|
||||||
|
|
||||||
@@ -106,7 +114,7 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sPlayerbotAIConfig->IsInPvpProhibitedZone(bot->GetZoneId())
|
if (sPlayerbotAIConfig->IsInPvpProhibitedZone(bot->GetZoneId())
|
||||||
&& (target->IsPlayer() || target->IsPet() || !bot->IsValidAttackTarget(target)))
|
&& (target->IsPlayer() || target->IsPet()))
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose)
|
||||||
botAI->TellError("I cannot attack others in PvP prohibited zones");
|
botAI->TellError("I cannot attack others in PvP prohibited zones");
|
||||||
|
|||||||
@@ -67,11 +67,18 @@ bool PetAttackAction::Execute(Event event)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit* target = AI_VALUE(Unit*, "current target");
|
Unit* target = AI_VALUE(Unit*, "current target");
|
||||||
if (!target)
|
if (!target)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!bot->IsValidAttackTarget(target))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
pet->SetReactState(REACT_PASSIVE);
|
pet->SetReactState(REACT_PASSIVE);
|
||||||
pet->ClearUnitState(UNIT_STATE_FOLLOW);
|
pet->ClearUnitState(UNIT_STATE_FOLLOW);
|
||||||
pet->AttackStop();
|
pet->AttackStop();
|
||||||
@@ -85,4 +92,4 @@ bool PetAttackAction::Execute(Event event)
|
|||||||
|
|
||||||
pet->ToCreature()->AI()->AttackStart(target);
|
pet->ToCreature()->AI()->AttackStart(target);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user