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
This commit is contained in:
Alex Dcnh
2025-09-25 21:42:34 +02:00
committed by GitHub
parent 0b74820f80
commit fc69dd5ddd
3 changed files with 65 additions and 7 deletions

View File

@@ -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;

View File

@@ -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<uint8, std::vector<uint8>> RandomPlayerbotFactory::availableRaces;
@@ -890,7 +893,9 @@ void RandomPlayerbotFactory::CreateRandomGuilds()
}
}
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);
sPlayerbotAIConfig->randomBotGuilds.push_back(guild->GetId());
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<uint8>(), f[1].Get<uint8>(), f[2].Get<uint8>(), f[3].Get<uint8>(), f[4].Get<uint8>());
}
LOG_INFO("playerbots", "{} random bot guilds available", guildNumber);
sPlayerbotAIConfig->randomBotGuilds.push_back(guild->GetId());
// The guild is only counted if it is actually created
++guildNumber;
++createdThisRun;
}
// 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()

View File

@@ -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);