From fc69dd5ddd19be2e10a77a7b9c0d55da87ea4f5a Mon Sep 17 00:00:00 2001 From: Alex Dcnh <140754794+Wishmaster117@users.noreply.github.com> Date: Thu, 25 Sep 2025 21:42:34 +0200 Subject: [PATCH] FIX Random Bot Guilds not initialising random emblem, colors, etc #1636 (#1650) * FIX Random Bot Guilds not initialising random emblem, colors, etc #1636 FIX Random Bot Guilds not initialising random emblem, colors, etc #1636 * Update RandomPlayerbotFactory.cpp * Add sql patch an remove FixEmptyGuildEmblems() function --- ...5_09_25_01_playerbots_guild_tabard_fix.sql | 8 +++ src/RandomPlayerbotFactory.cpp | 52 ++++++++++++++++--- src/strategy/actions/GuildCreateActions.cpp | 12 ++++- 3 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 data/sql/characters/updates/2025_09_25_01_playerbots_guild_tabard_fix.sql diff --git a/data/sql/characters/updates/2025_09_25_01_playerbots_guild_tabard_fix.sql b/data/sql/characters/updates/2025_09_25_01_playerbots_guild_tabard_fix.sql new file mode 100644 index 00000000..38c74691 --- /dev/null +++ b/data/sql/characters/updates/2025_09_25_01_playerbots_guild_tabard_fix.sql @@ -0,0 +1,8 @@ +UPDATE guild +SET + EmblemStyle = FLOOR(RAND() * 181), + EmblemColor = FLOOR(RAND() * 18), + BorderStyle = FLOOR(RAND() * 8), + BorderColor = FLOOR(RAND() * 18), + BackgroundColor = FLOOR(RAND() * 52) +WHERE EmblemStyle=0 AND EmblemColor=0 AND BorderStyle=0 AND BorderColor=0 AND BackgroundColor=0; \ No newline at end of file diff --git a/src/RandomPlayerbotFactory.cpp b/src/RandomPlayerbotFactory.cpp index 291d6825..94f6928e 100644 --- a/src/RandomPlayerbotFactory.cpp +++ b/src/RandomPlayerbotFactory.cpp @@ -15,6 +15,9 @@ #include "SharedDefines.h" #include "SocialMgr.h" #include "Timer.h" +#include "Guild.h" // EmblemInfo::SaveToDB +#include "Log.h" +#include "GuildMgr.h" std::map> RandomPlayerbotFactory::availableRaces; @@ -889,8 +892,10 @@ void RandomPlayerbotFactory::CreateRandomGuilds() availableLeaders.push_back(leader); } } - - for (; guildNumber < sPlayerbotAIConfig->randomBotGuildCount; ++guildNumber) + + // Create up to randomBotGuildCount by counting only EFFECTIVE creations + uint32 createdThisRun = 0; + for (; guildNumber < sPlayerbotAIConfig->randomBotGuildCount; /* ++guildNumber -> done only if creation */) { std::string const guildName = CreateRandomGuildName(); if (guildName.empty()) @@ -902,21 +907,29 @@ void RandomPlayerbotFactory::CreateRandomGuilds() if (availableLeaders.empty()) { LOG_ERROR("playerbots", "No leaders for random guilds available"); - continue; + break; // no more leaders: we can no longer progress without distorting the counter } uint32 index = urand(0, availableLeaders.size() - 1); ObjectGuid leader = availableLeaders[index]; + availableLeaders.erase(availableLeaders.begin() + index); // Removes the chosen leader to avoid re-selecting it repeatedly + Player* player = ObjectAccessor::FindPlayer(leader); if (!player) { LOG_ERROR("playerbots", "ObjectAccessor Cannot find player to set leader for guild {} . Skipped...", guildName.c_str()); + // we will try with other leaders in the next round (guildNumber is not incremented) continue; } if (player->GetGuildId()) + { + // leader already in guild -> we don't advance the counter, we move on to the next one continue; + } + + LOG_DEBUG("playerbots", "Creating guild name='{}' leader='{}'...", guildName.c_str(), player->GetName().c_str()); Guild* guild = new Guild(); if (!guild->Create(player, guildName)) @@ -929,6 +942,8 @@ void RandomPlayerbotFactory::CreateRandomGuilds() sGuildMgr->AddGuild(guild); + LOG_DEBUG("playerbots", "Guild created: id={} name='{}'", guild->GetId(), guildName.c_str()); + // create random emblem uint32 st, cl, br, bc, bg; bg = urand(0, 51); @@ -936,13 +951,38 @@ void RandomPlayerbotFactory::CreateRandomGuilds() cl = urand(0, 17); br = urand(0, 7); st = urand(0, 180); - EmblemInfo emblemInfo(st, cl, br, bc, bg); - guild->HandleSetEmblem(emblemInfo); + + LOG_DEBUG("playerbots", + "[TABARD] new guild id={} random -> style={}, color={}, borderStyle={}, borderColor={}, bgColor={}", + guild->GetId(), st, cl, br, bc, bg); + + // populate guild table with a random tabard design + CharacterDatabase.Execute( + "UPDATE guild SET EmblemStyle={}, EmblemColor={}, BorderStyle={}, BorderColor={}, BackgroundColor={} " + "WHERE guildid={}", + st, cl, br, bc, bg, guild->GetId()); + LOG_DEBUG("playerbots", "[TABARD] UPDATE done for guild id={}", guild->GetId()); + + // Immediate reading for log + if (QueryResult qr = CharacterDatabase.Query( + "SELECT EmblemStyle,EmblemColor,BorderStyle,BorderColor,BackgroundColor FROM guild WHERE guildid={}", + guild->GetId())) + { + Field* f = qr->Fetch(); + LOG_DEBUG("playerbots", + "[TABARD] DB check guild id={} => style={}, color={}, borderStyle={}, borderColor={}, bgColor={}", + guild->GetId(), f[0].Get(), f[1].Get(), f[2].Get(), f[3].Get(), f[4].Get()); + } sPlayerbotAIConfig->randomBotGuilds.push_back(guild->GetId()); + // The guild is only counted if it is actually created + ++guildNumber; + ++createdThisRun; } - LOG_INFO("playerbots", "{} random bot guilds available", guildNumber); + // Shows the true total and how many were created during this run + LOG_INFO("playerbots", "{} random bot guilds available (created this run: {})", + uint32(sPlayerbotAIConfig->randomBotGuilds.size()), createdThisRun); } std::string const RandomPlayerbotFactory::CreateRandomGuildName() diff --git a/src/strategy/actions/GuildCreateActions.cpp b/src/strategy/actions/GuildCreateActions.cpp index 57d22fc2..caa920c7 100644 --- a/src/strategy/actions/GuildCreateActions.cpp +++ b/src/strategy/actions/GuildCreateActions.cpp @@ -12,6 +12,7 @@ #include "Playerbots.h" #include "RandomPlayerbotFactory.h" #include "ServerFacade.h" +#include "SharedDefines.h" // GOLD bool BuyPetitionAction::Execute(Event event) { @@ -237,6 +238,15 @@ bool PetitionTurnInAction::Execute(Event event) if (bot->GetGuildId()) { + // Ensure that bot has at least 10g for HandleSetEmblem can be managed core side + // (EMBLEM_PRICE = 10 * GOLD in core) + static constexpr uint32 REQUIRED = 10 * GOLD; + uint32 have = bot->GetMoney(); // actual money earned by bot in copper + if (have < REQUIRED) + { + bot->ModifyMoney(int32(REQUIRED - have)); // add only the missing amount to bot to reach 10g + } + Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId()); uint32 st, cl, br, bc, bg; @@ -247,7 +257,7 @@ bool PetitionTurnInAction::Execute(Event event) st = urand(0, 180); EmblemInfo emblemInfo(st, cl, br, bc, bg); - guild->HandleSetEmblem(emblemInfo); + guild->HandleSetEmblem(emblemInfo); // official core handling // LANG_GUILD_VETERAN -> can invite guild->HandleSetRankInfo(2, GR_RIGHT_GCHATLISTEN | GR_RIGHT_GCHATSPEAK | GR_RIGHT_INVITE);