From eb268c7507789301cbbf4a32059e397bb3017234 Mon Sep 17 00:00:00 2001 From: Keleborn <22352763+Celandriel@users.noreply.github.com> Date: Fri, 24 Apr 2026 14:05:35 -0700 Subject: [PATCH] Init guilds on login. (#2325) ## Pull Request Description Guild solution to #2148 ## Feature Evaluation - Describe the **minimum logic** required to achieve the intended behavior. - Describe the **processing cost** when this logic executes across many bots. ## How to Test the Changes ## Impact Assessment - Does this change increase per-bot/per-tick processing or risk scaling poorly with thousands of bots? - - [ ] No, not at all - - [x] Minimal impact (**explain below**) - - [ ] Moderate impact (**explain below**) Minimal cost on bot login. - Does this change modify default bot behavior? - - [x] No - - [ ] Yes (**explain why**) - Does this change add new decision branches or increase maintenance complexity? - - [x] No - - [ ] Yes (**explain below**) ## AI Assistance Was AI assistance used while working on this change? - - [x] No - - [ ] Yes (**explain below**) ## Final Checklist - - [x] Stability is not compromised. - - [x] Performance impact is understood, tested, and acceptable. - - [x] Added logic complexity is justified and explained. - - [x] Any new bot dialogue lines are translated. - - [x] Documentation updated if needed (Conf comments, WiKi commands). ## Notes for Reviewers --- src/Bot/Factory/PlayerbotFactory.h | 2 +- src/Bot/RandomPlayerbotMgr.cpp | 7 +++++++ src/Mgr/Guild/PlayerbotGuildMgr.cpp | 11 ++++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/Bot/Factory/PlayerbotFactory.h b/src/Bot/Factory/PlayerbotFactory.h index 1962c0428..0e18e6b83 100644 --- a/src/Bot/Factory/PlayerbotFactory.h +++ b/src/Bot/Factory/PlayerbotFactory.h @@ -88,6 +88,7 @@ public: void InitKeyring(); void InitReputation(); void InitAttunementQuests(); + void InitGuild(); private: enum class ProfessionSpecializationSpell : uint32 @@ -199,7 +200,6 @@ private: void InitInventoryEquip(); void InitInventorySkill(); Item* StoreItem(uint32 itemId, uint32 count); - void InitGuild(); void InitArenaTeam(); void InitImmersive(); static void AddPrevQuests(uint32 questId, std::list& questIds); diff --git a/src/Bot/RandomPlayerbotMgr.cpp b/src/Bot/RandomPlayerbotMgr.cpp index 9e9150989..110a1942e 100644 --- a/src/Bot/RandomPlayerbotMgr.cpp +++ b/src/Bot/RandomPlayerbotMgr.cpp @@ -2532,6 +2532,13 @@ void RandomPlayerbotMgr::OnBotLoginInternal(Player* const bot) } } + // Run guild recovery/assignment at login to handle empty guild tables after restart. + if (sPlayerbotAIConfig.randomBotGuildCount > 0) + { + PlayerbotFactory factory(bot, bot->GetLevel()); + factory.InitGuild(); + } + if (sPlayerbotAIConfig.randomBotFixedLevel) { bot->SetPlayerFlag(PLAYER_FLAGS_NO_XP_GAIN); diff --git a/src/Mgr/Guild/PlayerbotGuildMgr.cpp b/src/Mgr/Guild/PlayerbotGuildMgr.cpp index 001a438cb..5dc1095de 100644 --- a/src/Mgr/Guild/PlayerbotGuildMgr.cpp +++ b/src/Mgr/Guild/PlayerbotGuildMgr.cpp @@ -150,13 +150,10 @@ void PlayerbotGuildMgr::OnGuildUpdate(Guild* guild) void PlayerbotGuildMgr::ResetGuildCache() { - for (auto it = _guildCache.begin(); it != _guildCache.end();) - { - GuildCache& cached = it->second; - cached.memberCount = 0; - cached.faction = 2; - cached.status = 0; - } + _guildCache.clear(); + + for (auto& nameEntry : _guildNames) + nameEntry.second = true; } void PlayerbotGuildMgr::LoadGuildNames()