diff --git a/src/modules/PlayerbotV2/Bot/Raid/README.md b/src/modules/PlayerbotV2/Bot/Raid/README.md index e2f0bf28d5..4da9126abe 100644 --- a/src/modules/PlayerbotV2/Bot/Raid/README.md +++ b/src/modules/PlayerbotV2/Bot/Raid/README.md @@ -24,6 +24,9 @@ Port of Karrz's raid10-revamp ike3 raid logic (Karrz1/wow-1.12, src/game/PlayerB - Hooks outside this folder: BotSnapshot.h (field + reset), BotSnapshotBuilder.cpp (copy), PlayerbotV2.cpp (Update call), State_InCombat.cpp (dispatch), 4 raid DungeonScripts (one call each), BotSnapshotView.cpp (no-AoE clamp), core PlayerbotAPI.cpp (pet_attack / pet_cast drive a possessed creature when the bot has no pet). +- `RaidCallouts.h`: bots say their new decision in raid chat like players ("Living Bomb on me, running out", "taunting + Flamegor", "Polymorph on X, don't break it", "spread out"), from the change-only decision log at the end of `Brain::Update`. + No model; rate limited per bot and per raid; Russian readers get the catalog lines. `Playerbot.Raid.Callouts` (default 1). - Config: `Playerbot.Raid.Enable` (default 1). Log: `[raid] : ...` lines at WARN on channel playerbot.v2.raid (shows with Logger.playerbot.v2=3), one per changed decision. diff --git a/src/modules/PlayerbotV2/Bot/Raid/RaidBrain.cpp b/src/modules/PlayerbotV2/Bot/Raid/RaidBrain.cpp index 406619f6f3..44ccd43abd 100644 --- a/src/modules/PlayerbotV2/Bot/Raid/RaidBrain.cpp +++ b/src/modules/PlayerbotV2/Bot/Raid/RaidBrain.cpp @@ -10,6 +10,7 @@ #include "Api/BotLanguage.h" #include "DispelWorth.h" #include "RaidBrainInternal.h" +#include "RaidCallouts.h" #include "RaidEncounters.h" #include "RaidGeometry.h" #include "RaidReadiness.h" @@ -4580,6 +4581,66 @@ void EndQuietPulls(uint32_t now_ms) } } +// Raid callouts (RaidCallouts.h): the bot says its new decision in raid chat, the way a player types "bomb on me, running out". +CalloutGate g_callouts; + +std::string SpellNameOf(uint32_t spellId) +{ + SpellInfo const* info = spellId ? sSpellMgr->GetSpellInfo(spellId, DIFFICULTY_NONE) : nullptr; + char const* name = info && info->SpellName ? info->SpellName->Str[LOCALE_enUS] : nullptr; + return name ? std::string(name) : std::string(); +} + +void SayCallout(Player* bot, RaidOrder const& o, uint32_t now_ms) +{ + Group* group = bot->GetGroup(); + if (!group || !bot->IsAlive()) + return; + // Only a group with a real player in it reads raid chat; a bot-only group stays quiet. + bool human = false; + for (GroupReference const& ref : group->GetMembers()) + if (Player const* m = ref.GetSource(); m && !Services::Lifecycle().is_bot(m->GetGUID().GetCounter())) + { + human = true; + break; + } + if (!human) + return; + + CalloutFacts f; + f.move_reason = o.move && o.move_reason ? o.move_reason : ""; + f.hold_rotation = o.hold_rotation; + f.use_object = !o.use_object.IsEmpty(); + if (o.cast_kind == RaidOrder::CastKind::Taunt || o.cast_kind == RaidOrder::CastKind::CrowdControl) + { + Unit const* target = o.cast_target.IsEmpty() ? nullptr : ObjectAccessor::GetUnit(*bot, o.cast_target); + if (target) + f.target = target->GetName(); + f.spell = SpellNameOf(o.cast_spell); + f.taunt = o.cast_kind == RaidOrder::CastKind::Taunt; + if (o.cast_kind == RaidOrder::CastKind::CrowdControl) + if (SpellInfo const* info = sSpellMgr->GetSpellInfo(o.cast_spell, DIFFICULTY_NONE)) + f.long_cc = info->GetMaxDuration() >= 15000; + } + if (f.move_reason == "carrier run") + if (RaidRules const* rules = RulesForMap(bot->GetMapId())) + for (CarrierRun const& rule : rules->carrierRun) + if (bot->HasAura(rule.aura)) + { + f.carried = SpellNameOf(rule.aura); + break; + } + + Callout const c = PickCallout(f); + if (!g_callouts.Allow(group->GetGUID().GetCounter(), bot->GetGUID().GetCounter(), c.kind, c.group_wide, now_ms)) + return; + ChatMsg type = group->isRaidGroup() + ? (group->IsLeader(bot->GetGUID()) ? CHAT_MSG_RAID_LEADER : CHAT_MSG_RAID) + : (group->IsLeader(bot->GetGUID()) ? CHAT_MSG_PARTY_LEADER : CHAT_MSG_PARTY); + BotLanguage::GroupChat(bot, group, type, c.text, group->isRaidGroup() ? -1 : group->GetMemberGroup(bot->GetGUID())); + TC_LOG_INFO("playerbot.v2.raid", "[raid_callout] {}: {}", bot->GetName(), c.text); +} + } // namespace // [release] (playtest, MC 2026-10-08: "A member of your group is in combat" blocks Release Spirit, which worked in the morning): while a human of @@ -5128,11 +5189,17 @@ void Brain::Update(uint32_t now_ms) std::string& last = lastSignature[guidLow]; if (s != last && !s.empty()) if (Player* p = ObjectAccessor::FindConnectedPlayer(ObjectGuid::Create(guidLow))) + { TC_LOG_WARN("playerbot.v2.raid", "[raid] {}: {}", p->GetName(), s); + if (Services::Config().raid_callouts_enabled()) + SayCallout(p, o, now_ms); + } last = s; } if (lastSignature.size() > 2 * next.size() + 64) lastSignature.clear(); + if (g_callouts.Tracked() > 256) + g_callouts.Prune(now_ms); EndQuietPulls(now_ms); orders_.swap(next); diff --git a/src/modules/PlayerbotV2/Bot/Raid/RaidCallouts.h b/src/modules/PlayerbotV2/Bot/Raid/RaidCallouts.h new file mode 100644 index 0000000000..2eda8831ba --- /dev/null +++ b/src/modules/PlayerbotV2/Bot/Raid/RaidCallouts.h @@ -0,0 +1,149 @@ +// RaidCallouts - bots say what they are doing in raid chat, the way players do ("Living Bomb on me, running out", "taunting +// Flamegor", "Polymorph on Flamewaker Healer, don't break it", "spread out"). +// +// No model: the line comes from the raid brain's own decision (RaidOrder), at the moment that decision changes. The text is +// English and is translated per reader where it leaves the server (BotLanguage::GroupChat and the Russian catalog). +// +// This header is the pure part (which line for which decision, and how often a bot or a raid may speak) so it can be unit +// tested; RaidBrain.cpp resolves the names and sends. +// +// Playerbot.Raid.Callouts 1 0 = the bots stay quiet in raid chat + +#pragma once + +#include +#include +#include +#include +#include +#include + +namespace Playerbot::Raid { + +enum class CalloutKind : uint8_t +{ + None = 0, + WipeRetreat, // the raid is lost: one bot calls the run back + CarrierRun, // the bot carries a bomb aura and runs out + IceBlock, // the bot hides behind an ice block for a breath + Spread, // the raid has to spread: one bot calls it + HeiganDance, // Heigan's dance starts: one bot calls it + TakeOrb, // the bot takes Razorgore's Orb of Domination + HoldHeals, // a healing priest stops for Nefarian's priest call + Taunt, // the bot taunts a boss or an add + CrowdControl, // the bot polymorphs, banishes or shackles an add for a long time + Count +}; + +// What the bot was just told to do (a changed raid order), with the names already resolved by the caller. +struct CalloutFacts +{ + std::string_view move_reason; // RaidOrder::move_reason, empty when the bot has no move + bool taunt = false; // its elected cast is a taunt + bool long_cc = false; // its elected cast is crowd control that lasts 15 s or more + bool hold_rotation = false; + bool use_object = false; + std::string spell; // the elected spell's name (taunt, crowd control) + std::string target; // the elected cast's target name + std::string carried; // carrier run: the name of the aura the bot carries +}; + +struct Callout +{ + CalloutKind kind = CalloutKind::None; + std::string text; + bool group_wide = false; // a call for the whole raid: one bot says it, not every bot that got the order +}; + +// The one line for this decision, the most urgent first. kind None = nothing worth saying. +inline Callout PickCallout(CalloutFacts const& f) +{ + std::string_view const m = f.move_reason; + if (m == "wipe retreat") + return { CalloutKind::WipeRetreat, "wipe, run back to the entrance", true }; + if (m == "carrier run") + return { CalloutKind::CarrierRun, (f.carried.empty() ? std::string("bomb") : f.carried) + " on me, running out", false }; + if (m == "hide behind ice block") + return { CalloutKind::IceBlock, "hiding behind an ice block", false }; + if (m == "spread") + return { CalloutKind::Spread, "spread out", true }; + if (m == "heigan dance" || m == "heigan eruption") + return { CalloutKind::HeiganDance, "dance time, follow the safe side", true }; + if (f.use_object || m.substr(0, 4) == "orb:") + return { CalloutKind::TakeOrb, "taking the orb", false }; + if (f.hold_rotation) + return { CalloutKind::HoldHeals, "priest call, not healing", false }; + if (f.taunt && !f.target.empty()) + return { CalloutKind::Taunt, "taunting " + f.target, false }; + if (f.long_cc && !f.spell.empty() && !f.target.empty()) + return { CalloutKind::CrowdControl, f.spell + " on " + f.target + ", don't break it", false }; + return {}; +} + +// How often the bots may speak, so raid chat reads like players and not like a log: +// * the same bot, the same kind of line: once per kSameKindMs (a re-sheep a few seconds later stays quiet); +// * the same bot, any line: once per kBotGapMs; +// * a group-wide call (spread, wipe, dance): once per kGroupWideMs for the whole raid, whichever bot says it; +// * the whole raid: kGroupGapMs between two lines, at most kWindowMax lines in kWindowMs. +class CalloutGate +{ +public: + static constexpr uint32_t kSameKindMs = 20000; + static constexpr uint32_t kBotGapMs = 6000; + static constexpr uint32_t kGroupWideMs = 45000; + static constexpr uint32_t kGroupGapMs = 2000; + static constexpr uint32_t kWindowMs = 20000; + static constexpr uint32_t kWindowMax = 5; + + // True when the line may be said now; it is then counted as said. + bool Allow(uint64_t group, uint64_t bot, CalloutKind kind, bool group_wide, uint32_t now) + { + if (kind == CalloutKind::None) + return false; + GroupState& g = groups_[group]; + while (!g.said.empty() && now - g.said.front() >= kWindowMs) + g.said.pop_front(); + if (!g.said.empty() && now - g.said.back() < kGroupGapMs) + return false; + if (g.said.size() >= kWindowMax) + return false; + size_t const k = static_cast(kind); + if (group_wide && g.wide[k] && now - g.wide[k] < kGroupWideMs) + return false; + BotState& b = bots_[bot]; + if (b.last && now - b.last < kBotGapMs) + return false; + if (b.kind[k] && now - b.kind[k] < kSameKindMs) + return false; + + uint32_t const stamp = now ? now : 1u; + g.said.push_back(stamp); + g.last = stamp; + if (group_wide) + g.wide[k] = stamp; + b.last = stamp; + b.kind[k] = stamp; + return true; + } + + // Drops what no longer limits anything (call now and then). + void Prune(uint32_t now) + { + uint32_t const keep = kGroupWideMs > kSameKindMs ? kGroupWideMs : kSameKindMs; + for (auto it = bots_.begin(); it != bots_.end();) + it = now - it->second.last >= keep ? bots_.erase(it) : std::next(it); + for (auto it = groups_.begin(); it != groups_.end();) + it = now - it->second.last >= keep ? groups_.erase(it) : std::next(it); + } + + size_t Tracked() const { return bots_.size() + groups_.size(); } + +private: + static constexpr size_t kKinds = static_cast(CalloutKind::Count); + struct BotState { uint32_t last = 0; uint32_t kind[kKinds] = {}; }; + struct GroupState { std::deque said; uint32_t last = 0; uint32_t wide[kKinds] = {}; }; + std::unordered_map bots_; + std::unordered_map groups_; +}; + +} // namespace Playerbot::Raid diff --git a/src/modules/PlayerbotV2/Util/BotLocaleRu.cpp b/src/modules/PlayerbotV2/Util/BotLocaleRu.cpp index 08a8702f6e..2e042239cb 100644 --- a/src/modules/PlayerbotV2/Util/BotLocaleRu.cpp +++ b/src/modules/PlayerbotV2/Util/BotLocaleRu.cpp @@ -780,6 +780,16 @@ std::vector const& RussianEntries() { "sorry, the invite didn't go through", "извините, приглашение не прошло" }, { "sure! invite to <{}> sent, welcome :)", "конечно! приглашение в <{}> отправлено, добро пожаловать :)" }, { "i can't invite myself, so {} sent you the invite to <{}>", "у меня нет права приглашать, поэтому {} отправляет вам приглашение в <{}>" }, + // ---- raid callouts (Bot/Raid/RaidCallouts.h): spell and creature names stay as the server has them ----------------------- + { "wipe, run back to the entrance", "вайп, бегите ко входу" }, + { "{} on me, running out", "{} на мне, отбегаю" }, + { "hiding behind an ice block", "прячусь за ледяную глыбу" }, + { "spread out", "расходимся" }, + { "dance time, follow the safe side", "танцуем, держитесь безопасной стороны" }, + { "taking the orb", "беру сферу" }, + { "priest call, not healing", "зов жрецов, не лечу" }, + { "taunting {}", "провоцирую {}" }, + { "{} on {}, don't break it", "{} на {}, не сбивайте" }, // ---- arena (.bot arena, the arena ready line) ------------------------------------------------------------------------ { "Your arena is ready. Enter: click Enter at the minimap or type .bot arena enter. Leave: type .bot arena leave.", "Ваша арена готова. Войти: нажмите «Войти» у миникарты или введите .bot arena enter. Отказаться: введите .bot arena leave." }, { "No arena is ready for you yet.", "Для вас пока нет готовой арены." }, diff --git a/src/modules/PlayerbotV2/Util/ConfigReader.cpp b/src/modules/PlayerbotV2/Util/ConfigReader.cpp index 3833557140..f5c1a87040 100644 --- a/src/modules/PlayerbotV2/Util/ConfigReader.cpp +++ b/src/modules/PlayerbotV2/Util/ConfigReader.cpp @@ -78,6 +78,7 @@ void ConfigReader::apply_from_loaded_config() raid_enabled_ = c.GetBoolDefault("Playerbot.Raid.Enable", true, true); boss_warnings_enabled_ = c.GetBoolDefault("Playerbot.Raid.BossWarnings", true, true); + raid_callouts_enabled_ = c.GetBoolDefault("Playerbot.Raid.Callouts", true, true); raid_auto_accept_rez_ = c.GetBoolDefault("Playerbot.Raid.AutoAcceptOwnerRez", true, true); housing_enabled_ = c.GetBoolDefault("Playerbot.Housing.Enabled", false, true); diff --git a/src/modules/PlayerbotV2/Util/ConfigReader.h b/src/modules/PlayerbotV2/Util/ConfigReader.h index 0cd4554032..06cf66d681 100644 --- a/src/modules/PlayerbotV2/Util/ConfigReader.h +++ b/src/modules/PlayerbotV2/Util/ConfigReader.h @@ -56,6 +56,7 @@ public: // Raid brain (Bot/Raid): read once per config load, not per tick. bool raid_enabled() const { return raid_enabled_; } bool boss_warnings_enabled() const { return boss_warnings_enabled_; } + bool raid_callouts_enabled() const { return raid_callouts_enabled_; } bool raid_auto_accept_rez() const { return raid_auto_accept_rez_; } // Housing @@ -606,6 +607,7 @@ private: bool raid_enabled_ = true; bool boss_warnings_enabled_ = true; + bool raid_callouts_enabled_ = true; bool raid_auto_accept_rez_ = true; bool housing_enabled_ = true; diff --git a/src/modules/PlayerbotV2/conf/playerbot.conf.dist b/src/modules/PlayerbotV2/conf/playerbot.conf.dist index bf0c2a1721..bb3a8f2e4a 100644 --- a/src/modules/PlayerbotV2/conf/playerbot.conf.dist +++ b/src/modules/PlayerbotV2/conf/playerbot.conf.dist @@ -568,6 +568,11 @@ Playerbot.Raid.Enable = 1 # "Shazzrah is casting Arcane Explosion"), sent as a boss emote. Molten Core bosses. 0 turns them off. Playerbot.Raid.BossWarnings = 1 +# Bots say what they do in raid chat, like players: "Living Bomb on me, running out", "taunting Flamegor", +# "Polymorph on Flamewaker Healer, don't break it", "spread out", "wipe, run back to the entrance". No model is used, the +# lines come from the raid rules, and they are rate limited (a few lines a minute). 0 turns them off. +Playerbot.Raid.Callouts = 1 + # A resurrection a bot casts on you is accepted for you after 3 s without an answer (the 70205 client shows no accept popup). Playerbot.Raid.AutoAcceptOwnerRez = 1 diff --git a/tests/game/ClassicBossWarnings.cpp b/tests/game/ClassicBossWarnings.cpp index dc14491db1..a61f485f2e 100644 --- a/tests/game/ClassicBossWarnings.cpp +++ b/tests/game/ClassicBossWarnings.cpp @@ -18,6 +18,7 @@ #include "tc_catch2.h" #include "../../src/modules/PlayerbotV2/Bot/Raid/BossWarningData_MC.h" +#include "../../src/modules/PlayerbotV2/Bot/Raid/RaidCallouts.h" using namespace Playerbot::Raid; @@ -131,3 +132,84 @@ TEST_CASE("Molten Core table is sane", "[ClassicBossWarnings]") magmadarPanic = magmadarPanic || (r.boss == 11982 && r.spell == 19408); CHECK(magmadarPanic); } + +TEST_CASE("Raid callout: the line for each decision", "[ClassicBossWarnings]") +{ + CalloutFacts f; + f.move_reason = "carrier run"; + f.carried = "Living Bomb"; + Callout c = PickCallout(f); + CHECK(c.kind == CalloutKind::CarrierRun); + CHECK(c.text == "Living Bomb on me, running out"); + CHECK_FALSE(c.group_wide); + + f.carried.clear(); + CHECK(PickCallout(f).text == "bomb on me, running out"); + + CalloutFacts spread; + spread.move_reason = "spread"; + CHECK(PickCallout(spread).text == "spread out"); + CHECK(PickCallout(spread).group_wide); + + CalloutFacts wipe; + wipe.move_reason = "wipe retreat"; + wipe.taunt = true; + wipe.target = "Ragnaros"; + CHECK(PickCallout(wipe).kind == CalloutKind::WipeRetreat); // the most urgent line wins + + CalloutFacts taunt; + taunt.taunt = true; + taunt.target = "Flamegor"; + CHECK(PickCallout(taunt).text == "taunting Flamegor"); + taunt.target.clear(); + CHECK(PickCallout(taunt).kind == CalloutKind::None); // no name, nothing to say + + CalloutFacts cc; + cc.spell = "Polymorph"; + cc.target = "Flamewaker Healer"; + CHECK(PickCallout(cc).kind == CalloutKind::None); // a short stun is not called + cc.long_cc = true; + CHECK(PickCallout(cc).text == "Polymorph on Flamewaker Healer, don't break it"); + + CalloutFacts orb; + orb.move_reason = "orb: walk to the Orb of Domination"; + CHECK(PickCallout(orb).text == "taking the orb"); + + CalloutFacts quiet; + quiet.move_reason = "leave hazard"; // every few seconds in a fight: not worth a line + CHECK(PickCallout(quiet).kind == CalloutKind::None); + quiet.move_reason = "role position"; + CHECK(PickCallout(quiet).kind == CalloutKind::None); +} + +TEST_CASE("Raid callout: rate limits per bot and per raid", "[ClassicBossWarnings]") +{ + CalloutGate g; + uint32_t t = 100000; + CHECK(g.Allow(1, 10, CalloutKind::Taunt, false, t)); + CHECK_FALSE(g.Allow(1, 10, CalloutKind::CarrierRun, false, t + 3000)); // same bot, too soon + CHECK_FALSE(g.Allow(1, 11, CalloutKind::Taunt, false, t + 1000)); // the raid just heard a line + CHECK(g.Allow(1, 11, CalloutKind::Taunt, false, t + CalloutGate::kGroupGapMs)); // another bot, after the gap + CHECK(g.Allow(1, 10, CalloutKind::CarrierRun, false, t + CalloutGate::kBotGapMs)); // same bot, another line, later + CHECK_FALSE(g.Allow(1, 10, CalloutKind::Taunt, false, t + CalloutGate::kBotGapMs * 2)); // same line again within kSameKindMs + CHECK(g.Allow(1, 10, CalloutKind::Taunt, false, t + CalloutGate::kSameKindMs)); + CHECK(g.Allow(2, 10, CalloutKind::None, false, t) == false); + + // A group-wide call is said once for the whole raid. + CalloutGate w; + CHECK(w.Allow(5, 1, CalloutKind::Spread, true, t)); + CHECK_FALSE(w.Allow(5, 2, CalloutKind::Spread, true, t + 10000)); + CHECK(w.Allow(6, 2, CalloutKind::Spread, true, t + 10000)); // another raid + CHECK(w.Allow(5, 3, CalloutKind::Spread, true, t + CalloutGate::kGroupWideMs)); + + // At most kWindowMax lines in kWindowMs for one raid, however many bots. + CalloutGate cap; + uint32_t said = 0; + for (uint64_t bot = 1; bot <= 10; ++bot) + said += cap.Allow(9, bot, CalloutKind::Taunt, false, t + uint32_t(bot) * CalloutGate::kGroupGapMs); + CHECK(said == CalloutGate::kWindowMax); + + // Prune forgets the old state. + cap.Prune(t + 200000); + CHECK(cap.Tracked() == 0); +} diff --git a/tests/game/ClassicBotLocale.cpp b/tests/game/ClassicBotLocale.cpp index 88b74b3612..99d41c3956 100644 --- a/tests/game/ClassicBotLocale.cpp +++ b/tests/game/ClassicBotLocale.cpp @@ -118,6 +118,15 @@ TEST_CASE("BotLocale: the add-on's structured whispers are never translated", "[ CHECK(Translate(Lang::Ru, "ASSIGN|END|3") == "ASSIGN|END|3"); } +TEST_CASE("BotLocale: raid callouts", "[BotLocale]") +{ + CHECK(Translate(Lang::Ru, "Living Bomb on me, running out") == "Living Bomb на мне, отбегаю"); + CHECK(Translate(Lang::Ru, "taunting Flamegor") == "провоцирую Flamegor"); + CHECK(Translate(Lang::Ru, "Polymorph on Flamewaker Healer, don't break it") == "Polymorph на Flamewaker Healer, не сбивайте"); + CHECK(Translate(Lang::Ru, "spread out") == "расходимся"); + CHECK(Translate(Lang::Ru, "wipe, run back to the entrance") == "вайп, бегите ко входу"); +} + TEST_CASE("BotLocale: unknown lines come back in English", "[BotLocale]") { CHECK(Translate(Lang::Ru, "Perf: ticks=5 emit=3") == "Perf: ticks=5 emit=3");