Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NpcBots/bot_ai): Change ranged bots to run to a tank or to their master when they have aggro #7

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/server/game/AI/NpcBots/bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5430,7 +5430,34 @@ 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)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsOffTank() check is redundant here, off-tank bot automatically has tanking role enabled

moveTarget = itr->second;

// 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;
}

pos.Relocate(ppos);
if (!me->IsWithinLOSInMap(target, VMAP::ModelIgnoreFlags::M2, LINEOFSIGHT_ALL_CHECKS))
force = true;
Expand Down
Loading