From 3dd92b7fd8ebfb7ef9343f9ee8f1f7df08daf1e3 Mon Sep 17 00:00:00 2001 From: SaW Date: Tue, 17 Dec 2024 23:31:38 +0100 Subject: [PATCH] Fix bots attacking others despite being in a prohibited zone - Issue 227 (#793) * Fix bots attacking despite being in a prohibited zone * Protect pets as well and move logic to not skip IsFriendlyTo * Fix prohibited typo * Update AttackAction.cpp --- src/strategy/actions/AttackAction.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/strategy/actions/AttackAction.cpp b/src/strategy/actions/AttackAction.cpp index 0ff90ba7..3600ce66 100644 --- a/src/strategy/actions/AttackAction.cpp +++ b/src/strategy/actions/AttackAction.cpp @@ -74,6 +74,7 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/) { return false; } + std::ostringstream msg; msg << target->GetName(); @@ -88,9 +89,11 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/) if (!bot->IsWithinLOSInMap(target)) { - msg << " is not on my sight"; + msg << " is not in my sight"; if (verbose) botAI->TellError(msg.str()); + + return false; } if (target->isDead()) @@ -102,6 +105,14 @@ bool AttackAction::Attack(Unit* target, bool with_pet /*true*/) return false; } + if (!bot->IsValidAttackTarget(target) && sPlayerbotAIConfig->IsInPvpProhibitedZone(bot->GetZoneId())) + { + if (verbose) + botAI->TellError("I cannot attack others in PvP prohibited zones"); + + return false; + } + // if (bot->IsMounted() && bot->IsWithinLOSInMap(target)) // { // WorldPacket emptyPacket;