From e1d9b02583b5f786a47aab3b162fa7b1209e6a50 Mon Sep 17 00:00:00 2001 From: atrapalis <104009206+atrapalis@users.noreply.github.com> Date: Fri, 26 Jul 2024 18:31:04 +0100 Subject: [PATCH 1/2] feat(NpcBots/bot_ai): Changed ranged bots to run to a tank or to their master when they have aggro --- src/server/game/AI/NpcBots/bot_ai.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/server/game/AI/NpcBots/bot_ai.cpp b/src/server/game/AI/NpcBots/bot_ai.cpp index 492ae355c3da41..5791ab1360cd35 100644 --- a/src/server/game/AI/NpcBots/bot_ai.cpp +++ b/src/server/game/AI/NpcBots/bot_ai.cpp @@ -5430,7 +5430,24 @@ void bot_ai::CalculateAttackPos(Unit* target, Position& pos, bool& force) const force = true; return; } + + // Ranged bots that are being targeted should move towards a tank bot or towards the player + if (!IsTank(me) && HasRole(BOT_ROLE_RANGED) && target->GetVictim() == me) + { + // By default go to the master + Unit* moveTarget = master; + + // Look for a tank in the master's bots + BotMap const* map = master->GetBotMgr()->GetBotMap(); + for (BotMap::const_iterator itr = map->begin(); itr != map->end(); ++itr) + if (itr->second && (IsTank(itr->second) || IsOffTank(itr->second))) + moveTarget = itr->second; + pos.Relocate(moveTarget); + force = true; + return; + } + pos.Relocate(ppos); if (!me->IsWithinLOSInMap(target, VMAP::ModelIgnoreFlags::M2, LINEOFSIGHT_ALL_CHECKS)) force = true; From 35130d5bbaaa36e42caf8fada77c620941fa5015 Mon Sep 17 00:00:00 2001 From: atrapalis <104009206+atrapalis@users.noreply.github.com> Date: Sat, 27 Jul 2024 11:07:00 +0100 Subject: [PATCH 2/2] Tweaked the move position to be in a radius of +/- 1.5 from the target --- src/server/game/AI/NpcBots/bot_ai.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/server/game/AI/NpcBots/bot_ai.cpp b/src/server/game/AI/NpcBots/bot_ai.cpp index 5791ab1360cd35..f8e50b820a451c 100644 --- a/src/server/game/AI/NpcBots/bot_ai.cpp +++ b/src/server/game/AI/NpcBots/bot_ai.cpp @@ -5443,7 +5443,17 @@ void bot_ai::CalculateAttackPos(Unit* target, Position& pos, bool& force) const if (itr->second && (IsTank(itr->second) || IsOffTank(itr->second))) moveTarget = itr->second; - pos.Relocate(moveTarget); + // Decide if the bot needs to move + float thresholdDistance = 1.5f; + bool rangedBotNeedsToMove = std::abs(me->GetDistance(moveTarget)) > thresholdDistance; + if (rangedBotNeedsToMove) + { + // Randomise and adjust the bot's position + float randomModifier = irand(0, 1) ? 1.0f : -1.0f; + float absoluteAngle = me->GetAbsoluteAngle(moveTarget); + pos.Relocate(Position(moveTarget->GetPositionX() + randomModifier * thresholdDistance * std::cos(absoluteAngle), moveTarget->GetPositionY() + randomModifier * thresholdDistance * std::sin(absoluteAngle))); + } + force = true; return; }