mirror of
https://github.com/mod-playerbots/mod-playerbots
synced 2025-11-29 15:58:20 +08:00
* 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:
@@ -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;
|
||||||
@@ -15,6 +15,9 @@
|
|||||||
#include "SharedDefines.h"
|
#include "SharedDefines.h"
|
||||||
#include "SocialMgr.h"
|
#include "SocialMgr.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
#include "Guild.h" // EmblemInfo::SaveToDB
|
||||||
|
#include "Log.h"
|
||||||
|
#include "GuildMgr.h"
|
||||||
|
|
||||||
std::map<uint8, std::vector<uint8>> RandomPlayerbotFactory::availableRaces;
|
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();
|
std::string const guildName = CreateRandomGuildName();
|
||||||
if (guildName.empty())
|
if (guildName.empty())
|
||||||
@@ -902,21 +907,29 @@ void RandomPlayerbotFactory::CreateRandomGuilds()
|
|||||||
if (availableLeaders.empty())
|
if (availableLeaders.empty())
|
||||||
{
|
{
|
||||||
LOG_ERROR("playerbots", "No leaders for random guilds available");
|
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);
|
uint32 index = urand(0, availableLeaders.size() - 1);
|
||||||
ObjectGuid leader = availableLeaders[index];
|
ObjectGuid leader = availableLeaders[index];
|
||||||
|
availableLeaders.erase(availableLeaders.begin() + index); // Removes the chosen leader to avoid re-selecting it repeatedly
|
||||||
|
|
||||||
Player* player = ObjectAccessor::FindPlayer(leader);
|
Player* player = ObjectAccessor::FindPlayer(leader);
|
||||||
if (!player)
|
if (!player)
|
||||||
{
|
{
|
||||||
LOG_ERROR("playerbots", "ObjectAccessor Cannot find player to set leader for guild {} . Skipped...",
|
LOG_ERROR("playerbots", "ObjectAccessor Cannot find player to set leader for guild {} . Skipped...",
|
||||||
guildName.c_str());
|
guildName.c_str());
|
||||||
|
// we will try with other leaders in the next round (guildNumber is not incremented)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player->GetGuildId())
|
if (player->GetGuildId())
|
||||||
|
{
|
||||||
|
// leader already in guild -> we don't advance the counter, we move on to the next one
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DEBUG("playerbots", "Creating guild name='{}' leader='{}'...", guildName.c_str(), player->GetName().c_str());
|
||||||
|
|
||||||
Guild* guild = new Guild();
|
Guild* guild = new Guild();
|
||||||
if (!guild->Create(player, guildName))
|
if (!guild->Create(player, guildName))
|
||||||
@@ -929,6 +942,8 @@ void RandomPlayerbotFactory::CreateRandomGuilds()
|
|||||||
|
|
||||||
sGuildMgr->AddGuild(guild);
|
sGuildMgr->AddGuild(guild);
|
||||||
|
|
||||||
|
LOG_DEBUG("playerbots", "Guild created: id={} name='{}'", guild->GetId(), guildName.c_str());
|
||||||
|
|
||||||
// create random emblem
|
// create random emblem
|
||||||
uint32 st, cl, br, bc, bg;
|
uint32 st, cl, br, bc, bg;
|
||||||
bg = urand(0, 51);
|
bg = urand(0, 51);
|
||||||
@@ -936,13 +951,38 @@ void RandomPlayerbotFactory::CreateRandomGuilds()
|
|||||||
cl = urand(0, 17);
|
cl = urand(0, 17);
|
||||||
br = urand(0, 7);
|
br = urand(0, 7);
|
||||||
st = urand(0, 180);
|
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()
|
std::string const RandomPlayerbotFactory::CreateRandomGuildName()
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "Playerbots.h"
|
#include "Playerbots.h"
|
||||||
#include "RandomPlayerbotFactory.h"
|
#include "RandomPlayerbotFactory.h"
|
||||||
#include "ServerFacade.h"
|
#include "ServerFacade.h"
|
||||||
|
#include "SharedDefines.h" // GOLD
|
||||||
|
|
||||||
bool BuyPetitionAction::Execute(Event event)
|
bool BuyPetitionAction::Execute(Event event)
|
||||||
{
|
{
|
||||||
@@ -237,6 +238,15 @@ bool PetitionTurnInAction::Execute(Event event)
|
|||||||
|
|
||||||
if (bot->GetGuildId())
|
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());
|
Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId());
|
||||||
|
|
||||||
uint32 st, cl, br, bc, bg;
|
uint32 st, cl, br, bc, bg;
|
||||||
@@ -247,7 +257,7 @@ bool PetitionTurnInAction::Execute(Event event)
|
|||||||
st = urand(0, 180);
|
st = urand(0, 180);
|
||||||
EmblemInfo emblemInfo(st, cl, br, bc, bg);
|
EmblemInfo emblemInfo(st, cl, br, bc, bg);
|
||||||
|
|
||||||
guild->HandleSetEmblem(emblemInfo);
|
guild->HandleSetEmblem(emblemInfo); // official core handling
|
||||||
|
|
||||||
// LANG_GUILD_VETERAN -> can invite
|
// LANG_GUILD_VETERAN -> can invite
|
||||||
guild->HandleSetRankInfo(2, GR_RIGHT_GCHATLISTEN | GR_RIGHT_GCHATSPEAK | GR_RIGHT_INVITE);
|
guild->HandleSetRankInfo(2, GR_RIGHT_GCHATLISTEN | GR_RIGHT_GCHATSPEAK | GR_RIGHT_INVITE);
|
||||||
|
|||||||
Reference in New Issue
Block a user