From 45e622d5c3c9a8aa2931214bb449b3a8d1c782d5 Mon Sep 17 00:00:00 2001 From: Luan Santos Date: Thu, 23 Nov 2023 11:51:12 -0800 Subject: [PATCH] fix: switch target when unreachable/untarggetable (#1890) --- src/creatures/monsters/monster.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index b2660933a27..0446addb0c6 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -773,7 +773,9 @@ void Monster::onThink(uint32_t interval) { } } else if (!targetList.empty()) { const bool attackedCreatureIsDisconnected = attackedCreature && attackedCreature->getPlayer() && attackedCreature->getPlayer()->isDisconnected(); - if (!attackedCreature || attackedCreatureIsDisconnected) { + const bool attackedCreatureIsUnattackable = attackedCreature && !canUseAttack(getPosition(), attackedCreature); + const bool attackedCreatureIsUnreachable = targetDistance <= 1 && attackedCreature && followCreature && !hasFollowPath; + if (!attackedCreature || attackedCreatureIsDisconnected || attackedCreatureIsUnattackable || attackedCreatureIsUnreachable) { if (!followCreature || !hasFollowPath || attackedCreatureIsDisconnected) { searchTarget(TARGETSEARCH_NEAREST); } else if (attackedCreature && isFleeing() && !canUseAttack(getPosition(), attackedCreature)) {