From 10a45fcbdebb1ce3a6f22dd105251b8f3af4c45f Mon Sep 17 00:00:00 2001 From: SaW Date: Mon, 30 Dec 2024 19:21:38 +0100 Subject: [PATCH] Put IsValidAttackTarget check on both bots and their pets (#833) * Prevent PetAttackAction on invalid targets * Prevent AttackAction on invalid targets in general --- src/strategy/actions/AttackAction.cpp | 10 +++++++++- src/strategy/actions/GenericActions.cpp | 9 ++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/strategy/actions/AttackAction.cpp b/src/strategy/actions/AttackAction.cpp index 4be5da24..1473e85d 100644 --- a/src/strategy/actions/AttackAction.cpp +++ b/src/strategy/actions/AttackAction.cpp @@ -75,6 +75,14 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/) return false; } + if (!bot->IsValidAttackTarget(target)) + { + if (verbose) + botAI->TellError("I cannot attack an invalid target"); + + return false; + } + std::ostringstream msg; msg << target->GetName(); @@ -106,7 +114,7 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/) } if (sPlayerbotAIConfig->IsInPvpProhibitedZone(bot->GetZoneId()) - && (target->IsPlayer() || target->IsPet() || !bot->IsValidAttackTarget(target))) + && (target->IsPlayer() || target->IsPet())) { if (verbose) botAI->TellError("I cannot attack others in PvP prohibited zones"); diff --git a/src/strategy/actions/GenericActions.cpp b/src/strategy/actions/GenericActions.cpp index 84997212..2731fdd7 100644 --- a/src/strategy/actions/GenericActions.cpp +++ b/src/strategy/actions/GenericActions.cpp @@ -67,11 +67,18 @@ bool PetAttackAction::Execute(Event event) { return false; } + Unit* target = AI_VALUE(Unit*, "current target"); if (!target) { return false; } + + if (!bot->IsValidAttackTarget(target)) + { + return false; + } + pet->SetReactState(REACT_PASSIVE); pet->ClearUnitState(UNIT_STATE_FOLLOW); pet->AttackStop(); @@ -85,4 +92,4 @@ bool PetAttackAction::Execute(Event event) pet->ToCreature()->AI()->AttackStart(target); return true; -} \ No newline at end of file +}