Bots: module update (raid tactics, group control, world-bot pool, riding, starter gear, combat fixes) (#71)

* Bots: module update (raid tactics, instance entry, world-bot and combat fixes)

* Bots: module update from the current build (follow-the-owner on drops, group-human instance entry, raid-ready and population fixes)

* Bots: group control, pool balance at every level, starter outfit for low world bots, riding tiers and mount fallback

* World bots: no quest hub for a bot that can take no quest there (#87)

* World bots: no quest hub for a bot that can take none there (ring spot instead); move_abandon logs why the bot did not move

* Starter outfit: wait while the bot casts or fights, and leave quivers and ammo out of the pieces that must be worn

* Bots: seven small cleanups of the bot rules (#88)

* Bots: one OwnerOrders struct holds the owner's orders (command, follow, stance, windows) and the cross-thread fields are now locked

* Bots: one pet attack order per combat tick; drop the warlock and hunter duplicates, new victim ordered at once and the same one every 3 s

* Raids: one script_names_target() test for the boss script's kill target, used by the raid dispatch and both generic pickers

* Bots: idle:rest sits a solo bot under 50% health that has nothing to eat

* Bots: remove the retail rotations of the nine vanilla classes (every spec is already overridden by the Classic rotation)

* Group: one movement_owned_elsewhere test for the follow, slot move and recall gates

* Bots: the threat drop spells and the 60/80 percent triggers live next to the other threat limits in ThreatLimits.h

* Trade: reagents of a recipe the bot knows, from the owner or a group mate, are a gift; trade line in the command guide (#89)
This commit is contained in:
Karrz1
2026-10-20 09:05:38 +08:00
committed by GitHub
parent 9680562527
commit 956aff2834
141 changed files with 4439 additions and 18558 deletions
@@ -1,4 +1,5 @@
#include "BotCommandParser.h"
#include "GroupControl.h"
#include "BotIntent.h"
#include "BotIntentEmitter.h"
#include "BotRegistry.h"
@@ -754,7 +755,7 @@ void ReportRaidRoster(Player* sender, Player* bot)
// a recognised value.
// Owner "distance <n>" / "follow distance <n>" (Playerbot.Behavior.DistanceOrder; the /fb Distance stepper): pins the bot's
// follow distance (BotAI::follow_distance, persisted with the squad state) and the formation spacing yards together, so
// the plain follow, the formation slots and the recall slack all agree. Clamped to 1..20 yards; the group's lowest-guid
// the plain follow, the formation slots and the recall slack all agree. Clamped to 2..20 yards; the group's lowest-guid
// bot whispers the confirmation. The spacing yards are memory only (as the spacing presets are); the addon re-sends
// the value on login. World thread. `rest` is the text after the verb.
bool OrderDistance(Player* sender, Player* bot, std::string const& rest)
@@ -764,7 +765,7 @@ bool OrderDistance(Player* sender, Player* bot, std::string const& rest)
return false;
float yd = 0.f;
try { yd = std::stof(rest); } catch (...) { return false; }
yd = std::clamp(yd, 1.0f, 20.0f);
yd = std::clamp(yd, 2.0f, 20.0f);
BotAI* ai = Services::Registry().ai(bot->GetGUID().GetCounter());
if (!ai) return true;
ai->set_follow_distance(yd);
@@ -1473,7 +1474,7 @@ bool OwnerWordOrder(Player* sender, Player* bot, std::string const& n)
if (bid != lowest)
return true;
}
say("Orders (whisper me, or say it in party / raid chat): follow, stay, come, summon, attack, flee, hold, resume, passive, defensive, aggressive.");
say("Orders (whisper me, or say it in party / raid chat): follow, stay, come, summon, attack, flee, hold, resume, passive, aggressive.");
say("Ask: who, stats, gear, quests, inv, money. Quests: accept [all], drop <quest>, turn in, share.");
say("Town and loot: sell grey, repair, loot / loot all. Raid: pull, pull back, fall back, rally here, formation <x>, spacing <x>, distance <n>, assign, rti.");
say("The whole verb index: 'commands'. Address several bots: all: / tank: / healer: / dps: / <class>: / <Name>: before the order.");
@@ -1607,23 +1608,12 @@ bool OwnerWordOrder(Player* sender, Player* bot, std::string const& n)
if (n == "summon")
{
auto refuse = [&](char const* why) { say(fmt::format("{}: can't be summoned, {}", me, why)); return true; };
if (!bot->IsAlive())
return refuse("I am dead - release or revive me first");
if (bot->IsInCombat())
return refuse("I am in combat");
if (sender->IsInCombat())
return refuse("you are in combat");
Map const* sm = sender->GetMap();
Map const* bm = bot->GetMap();
if (sm && sm->IsBattlegroundOrArena() && bot->GetMapId() != sender->GetMapId())
return refuse("you are in a battleground");
if (bm && bm->Instanceable() && bot->GetMapId() != sender->GetMapId())
return refuse("I am inside an instance - walk out first");
// Into the owner's instance only as a member of the owner's group (the door checks and their log are API::teleport_to's).
if (sm && sm->Instanceable() && bot->GetMapId() != sender->GetMapId() && !(bot->GetGroup() && bot->GetGroup() == sender->GetGroup()))
return refuse("you are inside an instance - invite me and walk in with the group");
Push(bot, TeleportToIntent{sender->GetMapId(), sender->GetPositionX(), sender->GetPositionY(),
sender->GetPositionZ(), sender->GetOrientation()});
// Wherever the bot is, inside the owner's instance too: it is put in the group, revived if dead elsewhere and ported to the owner
// (BotPopulationManager::BringToOwner logs every refusal as [summon]).
if (std::string const why = Services::Population().BringToOwner(sender, bot, "summon order"); !why.empty())
return refuse(why.c_str());
if (BotAI* ai = Services::Registry().ai(bid))
{
ai->enter_manual(BotAI::OwnerCommand::Follow, sender->GetGUID(), GameTime::GetGameTimeMS());
@@ -1636,7 +1626,7 @@ bool OwnerWordOrder(Player* sender, Player* bot, std::string const& n)
// Passive: the bot starts nothing (no autopilot pull, no assist on the owner's target) and defends itself and the group
// until attack / pull (a 15 s window) or aggressive. A fight already under way is not dropped. The stance is the panel's
// Aggressive / Passive toggle and stays on the bot until changed.
if (n == "passive")
if (n == "passive" || n == "defensive") // "defensive" is the retired third stance: it now means passive
{
if (BotAI* ai = Services::Registry().ai(bid))
{
@@ -1657,7 +1647,7 @@ bool OwnerWordOrder(Player* sender, Player* bot, std::string const& n)
{
if (ai->set_owner_stance(BotAI::OwnerStance::Aggressive))
TC_LOG_INFO("playerbot.v2", "[owner_order] {} <- {}: aggressive (attacks hostiles within {:.0f} yd of the owner)", me,
sender->GetName(), BotAI::kAggressiveRadiusYd);
sender->GetName(), Services::Config().behavior_aggressive_radius_yd());
// A Stay / Hold stays: aggressive changes the stance only (it used to cancel the Stay silently).
if (!ai->holding_position(GameTime::GetGameTimeMS()))
{
@@ -1665,24 +1655,9 @@ bool OwnerWordOrder(Player* sender, Player* bot, std::string const& n)
ai->release_owner_lead(false);
}
}
say(fmt::format("{}: aggressive, attacking anything hostile within {:.0f} yards of you", me, BotAI::kAggressiveRadiusYd));
say(fmt::format("{}: aggressive, attacking anything hostile within {:.0f} yards of you", me, Services::Config().behavior_aggressive_radius_yd()));
return true;
}
if (n == "defensive")
{
Push(bot, StopMovementIntent{/*clear_generators*/ true});
if (BotAI* ai = Services::Registry().ai(bid))
{
ai->enter_manual(BotAI::OwnerCommand::Hold, ObjectGuid::Empty, GameTime::GetGameTimeMS(), BotAI::kHoldPositionTtlMs);
// Defensive replaces an Aggressive stance (a Passive one already fights only what attacks); the Hold does the rest.
if (ai->owner_stance() == BotAI::OwnerStance::Aggressive)
ai->set_owner_stance(BotAI::OwnerStance::Auto);
ai->set_last_owner_name(sender->GetName());
}
say(me + ": defensive, holding here and fighting only what attacks");
return true;
}
// ---- invite (whispered: the bot invites its owner) --------------------------------------------------------------
if (n == "invite" && t_direct_whisper)
{
@@ -1875,6 +1850,26 @@ static void ConfirmWhisperOrder(Player* sender, Player* bot, std::string const&
Push(bot, WhisperIntent{sender->GetName(), std::move(text)});
}
bool BotCommandParser::ControlsForGroupOrder(Player const* sender, Player const* bot)
{
if (!sender || !bot || sender == bot || !sender->GetSession())
return false;
BotId const bot_id = bot->GetGUID().GetCounter();
if (Services::Owners().GetOwner(bot_id).account_id != 0)
return Services::Owners().IsOwner(bot_id, sender->GetSession()->GetAccountId(), sender->GetGUID().GetCounter());
Group const* g = bot->GetGroup();
if (!g || g != sender->GetGroup() || (sender->GetSession() && sender->GetSession()->IsBot()))
return false;
std::vector<GroupControl::Member<ObjectGuid>> members;
for (GroupReference const& itr : g->GetMembers())
{
Player const* m = itr.GetSource();
if (!m || m == bot) continue;
members.push_back({ m->GetGUID(), !(m->GetSession() && m->GetSession()->IsBot()) });
}
return GroupControl::ResolveController(g->GetLeaderGUID(), members) == sender->GetGUID();
}
bool BotCommandParser::DispatchSingle(Player* sender, Player* bot, std::string const& msg, char const* via)
{
if (!sender || !bot) return false;
@@ -2636,6 +2631,8 @@ bool BotCommandParser::DispatchSingleImpl(Player* sender, Player* bot, std::stri
if (BotAI* ai = Services::Registry().ai(bot->GetGUID().GetCounter()))
{
AutoAssignFormationSlot(bot, *ai);
ai->close_owner_order_window(); // a follow ends the attack / pull window: nothing it opened starts a fight again
Push(bot, PetSetCommandStateIntent{1}); // and the pet comes along instead of staying on its target
ai->enter_manual(BotAI::OwnerCommand::Follow, sender->GetGUID(),
GameTime::GetGameTimeMS());
ai->set_last_owner_name(sender->GetName());
@@ -2702,13 +2699,14 @@ bool BotCommandParser::DispatchSingleImpl(Player* sender, Player* bot, std::stri
}
if (cmd == "come" || cmd == "summon")
{
// Teleport the bot to the sender. The API guards against in-combat
// and casting bots — caller can re-issue when the bot reports back.
Push(bot, TeleportToIntent{sender->GetMapId(),
sender->GetPositionX(),
sender->GetPositionY(),
sender->GetPositionZ(),
sender->GetOrientation()});
// Bring the bot to the sender, in the open world or inside an instance (BotPopulationManager::BringToOwner: group, revive,
// door check, ring spot). A refusal is logged as [summon] and told to the sender, so no bot goes missing without a reason.
if (std::string const why = Services::Population().BringToOwner(sender, bot, "come"); !why.empty())
{
if (why != "in combat with you") // a bot in your own fight answers when it is over; no line per fighter
ChatHandler(sender->GetSession()).PSendSysMessage("%s cannot come: %s.", bot->GetName().c_str(), why.c_str());
return true;
}
// After /come the owner usually wants the bot to stay nearby —
// enter Follow manual mode so the bot doesn't immediately
// resume questing across the map.
@@ -2725,13 +2723,9 @@ bool BotCommandParser::DispatchSingleImpl(Player* sender, Player* bot, std::stri
// Teleport all registered group-mate bots to the sender. Each bot
// may individually refuse (in-combat / casting) — same gates as the
// single-bot variant. Bot dispatching the command is included.
TeleportToIntent tp{sender->GetMapId(),
sender->GetPositionX(),
sender->GetPositionY(),
sender->GetPositionZ(),
sender->GetOrientation()};
Push(bot, tp);
uint32 broadcast_count = 1;
uint32 broadcast_count = 0;
if (Services::Population().BringToOwner(sender, bot, "come all").empty())
++broadcast_count;
if (Group const* grp = bot->GetGroup())
{
for (GroupReference const& itr : grp->GetMembers())
@@ -2740,8 +2734,8 @@ bool BotCommandParser::DispatchSingleImpl(Player* sender, Player* bot, std::stri
if (!member || member == bot) continue;
const BotId mid = member->GetGUID().GetCounter();
if (!Services::Registry().has(mid)) continue;
Push(member, tp);
++broadcast_count;
if (Services::Population().BringToOwner(sender, member, "come all").empty())
++broadcast_count;
}
}
Push(bot, WhisperIntent{sender->GetName(),
@@ -4325,6 +4319,15 @@ bool BotCommandParser::DispatchSingleImpl(Player* sender, Player* bot, std::stri
if (cmd == "stop" || cmd == "passive" || cmd == "disengage")
{
Push(bot, StopAttackIntent{});
// Stop is stop for the pet too (a pet left on its target keeps pulling), and ends the attack / pull window and an engage order
// so nothing in the bot's rules starts the fight again.
Push(bot, PetSetCommandStateIntent{1});
if (BotAI* ai = Services::Registry().ai(bot->GetGUID().GetCounter()))
{
ai->close_owner_order_window();
if (ai->owner_command() == BotAI::OwnerCommand::Engage)
ai->exit_manual();
}
// /disengage clears manual mode entirely (vs /stop which is a
// single-shot break-combat). Cleanly returning to autonomous
// is the right semantic when the owner says "back off".
@@ -5901,7 +5904,7 @@ bool BotCommandParser::DispatchSingleImpl(Player* sender, Player* bot, std::stri
{
// "use <object name or entry>": the nearest matching game object within 30 y of the bot (an altar, brazier, lever, orb).
// The bot walks over, uses it once and stays there (idle:owner_use); "follow" releases it. A ritual such as the UBRS
// Blackrock Altar (3 users) completes once enough different players have used it: the owner plus ";Name:use altar" to two bots.
// Blackrock Altar (3 users) completes once enough different players have used it: the owner plus "Name use altar" in party chat to two bots.
// A selected game object still works for clients that can select one.
ObjectGuid selection = sender->GetTarget();
std::string want = parsed.tail; // lower case (Normalize)