Raid: a raid leader bot who reacts to mistakes, and wipe banter

In a raid or party with a real player, one bot leads the chat (the group
leader if that is a bot, else an assistant bot, else the first bot) and
reacts the way a real raid leader does:

- standing in fire or another bad area ("Karrz GET OUT OF IT"),
- a cast nobody kicked ("NOBODY KICKED Shadow Bolt??"),
- a broken crowd control, named when the server saw who hit it,
- an extra pull ("WHO PULLED THAT. adds on Brok").

After a wipe one or two other bots answer: blame, excuses, "my bad" (the
one who died first speaks for himself). The kill gets a "gg".

Playerbot.Raid.Banter: 0 off, 1 mild (teasing, the default), 2 harsh (a
leader who freaks out at every mishap). Game mistakes only, in good fun:
never about the person, never a slur. Rate limited per raid: one line every
20 s (10 s on harsh), the same mistake once in 45 s, the same raider once
in 90 s. In a party of 15 or fewer with PartyBanter on, the wipe and kill
lines stay the companions' own.

No model needed: every line has a fixed form, mild and harsh, with Russian
for Russian clients. With the bot bridge answering chat, a new raid_line
event asks the program for the line in the bot's own words; an answer not
back within 2.5 s is dropped and the fixed line is said, so the raid never
waits. The example program answers it with the main model only, a short
prompt and a few tokens, and its filter still removes slurs whatever the
realm's swearing setting.

(cherry picked from commit d7681e0a2d91d5186d6849804be2a31b874330b8)
This commit is contained in:
Karrz1
2026-11-11 23:44:07 +00:00
parent a7feec8180
commit 8d2d35a955
14 changed files with 899 additions and 4 deletions
+71 -1
View File
@@ -131,7 +131,10 @@ uint32 g_bad_lines = 0;
uint32 g_last_bad_warn_ms = 0;
struct ChatAsk { BotId bot = 0; std::string sender; ObjectGuid sender_guid; bool sender_is_bot = false; std::string channel; uint32 asked_ms = 0;
uint64 talk_key = 0; // a bot-to-bot talk line (AskTalk), kept for TakeTalk
std::vector<BotId> group; }; // a group order (AskGroupOrder): the other bots that take the answer's action too
std::vector<BotId> group; // a group order (AskGroupOrder): the other bots that take the answer's action too
uint32 deadline_ms = 0; }; // a raid line (AskRaidLine): an answer at or after this time is dropped (the fixed line was said)
// Raid lines the program answered in time (AskRaidLine / RaidLineAnswered), by event id.
std::unordered_set<uint64> g_raid_answered;
// The group's part of a group order: each other bot runs the answer's action a moment after the first (HandleGroupFollowups).
struct GroupFollowup { BotId bot = 0; ChatAsk ask; Reply reply; uint32 read_ms = 0, due_ms = 0; };
std::vector<GroupFollowup> g_group_followups;
@@ -1786,6 +1789,13 @@ void HandleReplies(ConfigReader::BridgeConfig const& cfg, uint32 now_ms)
continue;
}
ask = it->second;
if (ask.deadline_ms && int32(now_ms - ask.deadline_ms) >= 0)
{
// A raid line that came too late: the caller said its fixed line at the deadline.
TC_LOG_INFO("playerbot.v2", "[bridge] raid line {} came {} ms late, dropped", r.reply_to, now_ms - ask.deadline_ms);
g_chat.erase(it);
continue;
}
bot = ask.bot;
if (Player* p = FindBot(bot))
bot_name = p->GetName();
@@ -1841,6 +1851,12 @@ void HandleReplies(ConfigReader::BridgeConfig const& cfg, uint32 now_ms)
to = ask.sender;
}
}
if (!text.empty() && ask.deadline_ms)
{
if (g_raid_answered.size() > 512)
g_raid_answered.clear();
g_raid_answered.insert(r.reply_to);
}
if (!text.empty())
{
g_last_line_ms[bot] = now_ms;
@@ -2539,6 +2555,60 @@ bool BotBridge::AskTalk(Player* bot, std::string const& scene, std::string const
return true;
}
uint64 BotBridge::AskRaidLine(Player* bot, std::string const& what, std::string const& detail, std::string const& example,
std::string const& mood, std::string const& role, uint32 delay_ms, uint32 wait_ms)
{
if (!ChatOn() || !bot || !bot->GetGroup())
return 0;
uint32 const now_ms = GameTime::GetGameTimeMS();
// Players come first: while two of their lines wait for an answer, the fixed line is said.
std::size_t waiting = 0;
for (auto const& kv : g_chat)
if (!kv.second.talk_key && !kv.second.deadline_ms && !kv.second.sender_is_bot && !kv.second.sender.empty() &&
now_ms - kv.second.asked_ms < 20000)
++waiting;
if (waiting >= 2)
return 0;
Group const* group = bot->GetGroup();
std::string const channel = group->isRaidGroup() ? "raid" : "party";
// The language most of the group's real players read (one line goes to all of them).
std::array<uint32, TOTAL_LOCALES> count{};
for (GroupReference const& ref : group->GetMembers())
if (Player const* m = ref.GetSource(); m && m->GetSession() && !Services::Registry().has(m->GetGUID().GetCounter()))
if (LocaleConstant const l = m->GetSession()->GetSessionDbcLocale(); l < TOTAL_LOCALES)
++count[l];
std::size_t best = 0;
for (std::size_t l = 0; l < count.size(); ++l)
if (count[l] > count[best])
best = l;
Event e;
e.type = "raid_line";
FillBot(e, bot, 0);
e.fields.emplace_back("what", what);
e.fields.emplace_back("detail", detail);
e.fields.emplace_back("example", example);
e.fields.emplace_back("mood", mood);
e.fields.emplace_back("role", role);
e.fields.emplace_back("channel", channel);
e.fields.emplace_back("locale", best < TOTAL_LOCALES ? localeNames[best] : "enUS");
e.numbers.emplace_back("delay_ms", delay_ms);
e.numbers.emplace_back("wait_ms", wait_ms);
if (Services::Config().bridge().swearing)
e.numbers.emplace_back("swearing", 1);
Write(e);
if (g_chat.size() > 2048)
g_chat.clear();
ChatAsk ask{ bot->GetGUID().GetCounter(), std::string(), ObjectGuid::Empty, true, channel, now_ms };
ask.deadline_ms = now_ms + wait_ms;
g_chat[e.id] = std::move(ask);
return e.id;
}
bool BotBridge::RaidLineAnswered(uint64 id)
{
return id && g_raid_answered.erase(id) > 0;
}
bool BotBridge::QueueGreet(BotId bot, ObjectGuid player)
{
if (!bot || player.IsEmpty() || !g_talk_on.load(std::memory_order_relaxed))