Files
mod-playerbots/src/strategy/values/RtiTargetValue.cpp
Alex Dcnh 9971622093 Core - Fixe raid markers persists after target dead causes issue with bots running off (#1845)
This PR fixes #1833 where bots could keep chasing a raid target icon
(usually skull) across very large distances or even different maps after
the mark was set. It replaces the previous attempt with a simpler design
that keeps values generic and moves context logic into triggers/actions.

Changes

- RtiTargetValue now ignores RTI targets that are farther than
sPlayerbotAIConfig->sightDistance from the bot or the master (same map
only), while still using AttackersValue::IsValidTarget and LOS checks.
- AttackersValue is reverted to its original behavior (no special RTI +
IsInCombat logic).
- RTI triggers only react to "rti target" in combat, as suggested in
review (“that condition should be check in trigger…”).
- AttackRtiTargetAction keeps a small local fallback: if "rti target" is
null, it resolves the raid icon directly from the group so chat commands
like “attack rti target” still work, including out of combat.

Behavior

- Bots no longer run across the world to chase a stale skull far away
from the group.
- When the group comes back near the marked mob (within sight distance),
the skull is again used as a normal focus hint.
- Automatic RTI behavior is limited to combat via triggers, while
explicit chat commands still work out of combat.

Testing

- Marked a mob with skull, killed it, moved far away / changed zone,
then let it respawn: bots did not chase it from afar.
- In a normal dungeon/raid pack, bots still focus skull in combat.
- Passing near a previously marked mob: bots only react once it is back
within sight distance.

---------

Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
2025-12-23 20:42:29 +01:00

79 lines
2.4 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#include "RtiTargetValue.h"
#include "AttackersValue.h"
#include "Playerbots.h"
#include "ServerFacade.h"
int32 RtiTargetValue::GetRtiIndex(std::string const rti)
{
int32 index = -1;
if (rti == "star")
index = 0;
else if (rti == "circle")
index = 1;
else if (rti == "diamond")
index = 2;
else if (rti == "triangle")
index = 3;
else if (rti == "moon")
index = 4;
else if (rti == "square")
index = 5;
else if (rti == "cross")
index = 6;
else if (rti == "skull")
index = 7;
return index;
}
Unit* RtiTargetValue::Calculate()
{
Group* group = bot->GetGroup();
if (!group)
return nullptr;
std::string const rti = AI_VALUE(std::string, type);
int32 index = GetRtiIndex(rti);
if (index == -1)
return nullptr;
ObjectGuid guid = group->GetTargetIcon(index);
if (!guid)
return nullptr;
//////////////////////////////////////////////////////begin: delete below check
// Some units that need to be killed in battle are not on the list of attackers,
// such as the Kor'kron Battle-Mage in Icecrown Citadel.
// GuidVector attackers = context->GetValue<GuidVector >("attackers")->Get();
// if (find(attackers.begin(), attackers.end(), guid) == attackers.end())
// return nullptr;
//
//////////////////////////////////////////////////////end: delete below check
Unit* unit = botAI->GetUnit(guid);
if (!unit || unit->isDead() || !bot->IsWithinLOSInMap(unit) || !AttackersValue::IsValidTarget(unit, bot) ||
sServerFacade->IsDistanceGreaterThan(sServerFacade->GetDistance2d(bot, unit),
sPlayerbotAIConfig->sightDistance))
return nullptr;
// Also prevent chasing raid icon targets that are too far away from the master,
// even if they are technically visible to the bot.
if (Player* master = botAI->GetMaster())
{
if (master->IsInWorld() && master->GetMapId() == unit->GetMapId() &&
sServerFacade->IsDistanceGreaterThan(sServerFacade->GetDistance2d(master, unit),
sPlayerbotAIConfig->sightDistance))
return nullptr;
}
return unit;
}