mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-02-21 02:20:00 +01:00
Autocalc Accounts - take rotation into account (#971)
* Takes bot rotation into account and adjust accordingly when enabled as it requires to be higher than MaxRandomBots to function properly. * Correct default config to reflect that bots pool size for rotation should be higher than MaxRandomBots * Revert space at start of all lines.
This commit is contained in:
parent
dfcfe46865
commit
624e48068e
@ -507,8 +507,8 @@ AiPlayerbot.RandomBotAccountPrefix = "rndbot"
|
|||||||
# default: 0 (disable, the online bots are fixed)
|
# default: 0 (disable, the online bots are fixed)
|
||||||
AiPlayerbot.EnableRotation = 0
|
AiPlayerbot.EnableRotation = 0
|
||||||
|
|
||||||
# Bots pool size for rotation (should be less than MaxRandomBots)
|
# Bots pool size for rotation (should be higher than MaxRandomBots)
|
||||||
AiPlayerbot.RotationPoolSize = 20
|
AiPlayerbot.RotationPoolSize = 100
|
||||||
|
|
||||||
AiPlayerbot.RandomBotMinLevel = 1
|
AiPlayerbot.RandomBotMinLevel = 1
|
||||||
AiPlayerbot.RandomBotMaxLevel = 80
|
AiPlayerbot.RandomBotMaxLevel = 80
|
||||||
|
|||||||
@ -505,7 +505,7 @@ bool PlayerbotAIConfig::Initialize()
|
|||||||
limitGearExpansion = sConfigMgr->GetOption<int32>("AiPlayerbot.LimitGearExpansion", 1);
|
limitGearExpansion = sConfigMgr->GetOption<int32>("AiPlayerbot.LimitGearExpansion", 1);
|
||||||
randombotStartingLevel = sConfigMgr->GetOption<int32>("AiPlayerbot.RandombotStartingLevel", 5);
|
randombotStartingLevel = sConfigMgr->GetOption<int32>("AiPlayerbot.RandombotStartingLevel", 5);
|
||||||
enableRotation = sConfigMgr->GetOption<bool>("AiPlayerbot.EnableRotation", false);
|
enableRotation = sConfigMgr->GetOption<bool>("AiPlayerbot.EnableRotation", false);
|
||||||
rotationPoolSize = sConfigMgr->GetOption<int32>("AiPlayerbot.RotationPoolSize", 20);
|
rotationPoolSize = sConfigMgr->GetOption<int32>("AiPlayerbot.RotationPoolSize", 100);
|
||||||
gearscorecheck = sConfigMgr->GetOption<bool>("AiPlayerbot.GearScoreCheck", false);
|
gearscorecheck = sConfigMgr->GetOption<bool>("AiPlayerbot.GearScoreCheck", false);
|
||||||
randomBotPreQuests = sConfigMgr->GetOption<bool>("AiPlayerbot.PreQuests", true);
|
randomBotPreQuests = sConfigMgr->GetOption<bool>("AiPlayerbot.PreQuests", true);
|
||||||
|
|
||||||
|
|||||||
@ -1,26 +1,26 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it
|
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it
|
||||||
* and/or modify it under version 2 of the License, or (at your option), any later version.
|
* and/or modify it under version 2 of the License, or (at your option), any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "RandomPlayerbotFactory.h"
|
#include "RandomPlayerbotFactory.h"
|
||||||
|
|
||||||
#include "AccountMgr.h"
|
#include "AccountMgr.h"
|
||||||
#include "ArenaTeamMgr.h"
|
#include "ArenaTeamMgr.h"
|
||||||
#include "DatabaseEnv.h"
|
#include "DatabaseEnv.h"
|
||||||
#include "GuildMgr.h"
|
#include "GuildMgr.h"
|
||||||
#include "PlayerbotFactory.h"
|
#include "PlayerbotFactory.h"
|
||||||
#include "Playerbots.h"
|
#include "Playerbots.h"
|
||||||
#include "ScriptMgr.h"
|
#include "ScriptMgr.h"
|
||||||
#include "SharedDefines.h"
|
#include "SharedDefines.h"
|
||||||
#include "SocialMgr.h"
|
#include "SocialMgr.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
|
|
||||||
std::map<uint8, std::vector<uint8>> RandomPlayerbotFactory::availableRaces;
|
std::map<uint8, std::vector<uint8>> RandomPlayerbotFactory::availableRaces;
|
||||||
|
|
||||||
constexpr RandomPlayerbotFactory::NameRaceAndGender RandomPlayerbotFactory::CombineRaceAndGender(uint8 gender,
|
constexpr RandomPlayerbotFactory::NameRaceAndGender RandomPlayerbotFactory::CombineRaceAndGender(uint8 gender,
|
||||||
uint8 race)
|
uint8 race)
|
||||||
{
|
{
|
||||||
switch (race)
|
switch (race)
|
||||||
{
|
{
|
||||||
case RACE_HUMAN:
|
case RACE_HUMAN:
|
||||||
@ -47,10 +47,10 @@
|
|||||||
LOG_ERROR("playerbots", "The race with ID %d does not have a naming category", race);
|
LOG_ERROR("playerbots", "The race with ID %d does not have a naming category", race);
|
||||||
return static_cast<NameRaceAndGender>(static_cast<uint8>(NameRaceAndGender::GenericMale) + gender);
|
return static_cast<NameRaceAndGender>(static_cast<uint8>(NameRaceAndGender::GenericMale) + gender);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RandomPlayerbotFactory::RandomPlayerbotFactory(uint32 accountId) : accountId(accountId)
|
RandomPlayerbotFactory::RandomPlayerbotFactory(uint32 accountId) : accountId(accountId)
|
||||||
{
|
{
|
||||||
uint32 const expansion = sWorld->getIntConfig(CONFIG_EXPANSION);
|
uint32 const expansion = sWorld->getIntConfig(CONFIG_EXPANSION);
|
||||||
|
|
||||||
availableRaces[CLASS_WARRIOR].push_back(RACE_HUMAN);
|
availableRaces[CLASS_WARRIOR].push_back(RACE_HUMAN);
|
||||||
@ -151,10 +151,10 @@
|
|||||||
availableRaces[CLASS_DEATH_KNIGHT].push_back(RACE_GNOME);
|
availableRaces[CLASS_DEATH_KNIGHT].push_back(RACE_GNOME);
|
||||||
availableRaces[CLASS_DEATH_KNIGHT].push_back(RACE_DWARF);
|
availableRaces[CLASS_DEATH_KNIGHT].push_back(RACE_DWARF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Player* RandomPlayerbotFactory::CreateRandomBot(WorldSession* session, uint8 cls, std::unordered_map<NameRaceAndGender, std::vector<std::string>>& nameCache)
|
Player* RandomPlayerbotFactory::CreateRandomBot(WorldSession* session, uint8 cls, std::unordered_map<NameRaceAndGender, std::vector<std::string>>& nameCache)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("playerbots", "Creating new random bot for class {}", cls);
|
LOG_DEBUG("playerbots", "Creating new random bot for class {}", cls);
|
||||||
|
|
||||||
uint8 gender = rand() % 2 ? GENDER_MALE : GENDER_FEMALE;
|
uint8 gender = rand() % 2 ? GENDER_MALE : GENDER_FEMALE;
|
||||||
@ -259,10 +259,10 @@
|
|||||||
name.c_str(), race, cls);
|
name.c_str(), race, cls);
|
||||||
|
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const RandomPlayerbotFactory::CreateRandomBotName(NameRaceAndGender raceAndGender)
|
std::string const RandomPlayerbotFactory::CreateRandomBotName(NameRaceAndGender raceAndGender)
|
||||||
{
|
{
|
||||||
std::string botName = "";
|
std::string botName = "";
|
||||||
int tries = 3;
|
int tries = 3;
|
||||||
while (--tries)
|
while (--tries)
|
||||||
@ -391,19 +391,46 @@
|
|||||||
LOG_ERROR("playerbots", "Random name generation failed.");
|
LOG_ERROR("playerbots", "Random name generation failed.");
|
||||||
botName.clear();
|
botName.clear();
|
||||||
return std::move(botName);
|
return std::move(botName);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32 RandomPlayerbotFactory::CalculateTotalAccountCount()
|
||||||
|
{
|
||||||
|
// Calculates the total number of required accounts, either using the specified randomBotAccountCount
|
||||||
|
// or determining it dynamically based on the WOTLK condition, max random bots, rotation pool size,
|
||||||
|
// and additional class account pool size.
|
||||||
|
|
||||||
|
// Checks if randomBotAccountCount is set, otherwise calculate it dynamically.
|
||||||
|
if (sPlayerbotAIConfig->randomBotAccountCount > 0)
|
||||||
|
{
|
||||||
|
return sPlayerbotAIConfig->randomBotAccountCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RandomPlayerbotFactory::CreateRandomBots()
|
|
||||||
{
|
|
||||||
bool isWOTLK = sWorld->getIntConfig(CONFIG_EXPANSION) == EXPANSION_WRATH_OF_THE_LICH_KING;
|
bool isWOTLK = sWorld->getIntConfig(CONFIG_EXPANSION) == EXPANSION_WRATH_OF_THE_LICH_KING;
|
||||||
|
|
||||||
|
// Determine divisor based on WOTLK condition
|
||||||
|
int divisor = isWOTLK ? 10 : 9;
|
||||||
|
|
||||||
|
// Calculate max bots or rotation pool size
|
||||||
|
int maxBotsOrRotation = std::max(
|
||||||
|
sPlayerbotAIConfig->maxRandomBots,
|
||||||
|
sPlayerbotAIConfig->enableRotation ? sPlayerbotAIConfig->rotationPoolSize : 0
|
||||||
|
);
|
||||||
|
|
||||||
|
// Calculate base accounts, add class account pool size, and add 1 as a fixed offset
|
||||||
|
uint32 baseAccounts = maxBotsOrRotation / divisor;
|
||||||
|
return baseAccounts + sPlayerbotAIConfig->addClassAccountPoolSize + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RandomPlayerbotFactory::CreateRandomBots()
|
||||||
|
{
|
||||||
/* multi-thread here is meaningless? since the async db operations */
|
/* multi-thread here is meaningless? since the async db operations */
|
||||||
if (sPlayerbotAIConfig->deleteRandomBotAccounts)
|
if (sPlayerbotAIConfig->deleteRandomBotAccounts)
|
||||||
{
|
{
|
||||||
std::vector<uint32> botAccounts;
|
std::vector<uint32> botAccounts;
|
||||||
std::vector<uint32> botFriends;
|
std::vector<uint32> botFriends;
|
||||||
uint32 totalAccountCount = (sPlayerbotAIConfig->randomBotAccountCount != 0) ? sPlayerbotAIConfig->randomBotAccountCount
|
|
||||||
: (isWOTLK ? (sPlayerbotAIConfig->maxRandomBots / 10) : (sPlayerbotAIConfig->maxRandomBots / 9))
|
// Calculates the total number of required accounts.
|
||||||
+ sPlayerbotAIConfig->addClassAccountPoolSize + 1;
|
uint32 totalAccountCount = CalculateTotalAccountCount();
|
||||||
|
|
||||||
for (uint32 accountNumber = 0; accountNumber < totalAccountCount; ++accountNumber)
|
for (uint32 accountNumber = 0; accountNumber < totalAccountCount; ++accountNumber)
|
||||||
{
|
{
|
||||||
@ -446,9 +473,9 @@
|
|||||||
std::unordered_map<NameRaceAndGender, std::vector<std::string>> nameCache;
|
std::unordered_map<NameRaceAndGender, std::vector<std::string>> nameCache;
|
||||||
std::vector<std::future<void>> account_creations;
|
std::vector<std::future<void>> account_creations;
|
||||||
int account_creation = 0;
|
int account_creation = 0;
|
||||||
uint32 totalAccountCount = (sPlayerbotAIConfig->randomBotAccountCount != 0) ? sPlayerbotAIConfig->randomBotAccountCount
|
|
||||||
: (isWOTLK ? (sPlayerbotAIConfig->maxRandomBots / 10) : (sPlayerbotAIConfig->maxRandomBots / 9))
|
// Calculates the total number of required accounts.
|
||||||
+ sPlayerbotAIConfig->addClassAccountPoolSize + 1;
|
uint32 totalAccountCount = CalculateTotalAccountCount();
|
||||||
|
|
||||||
for (uint32 accountNumber = 0; accountNumber < totalAccountCount; ++accountNumber)
|
for (uint32 accountNumber = 0; accountNumber < totalAccountCount; ++accountNumber)
|
||||||
{
|
{
|
||||||
@ -612,10 +639,10 @@
|
|||||||
|
|
||||||
LOG_INFO("server.loading", ">> {} random bot accounts with {} characters available",
|
LOG_INFO("server.loading", ">> {} random bot accounts with {} characters available",
|
||||||
sPlayerbotAIConfig->randomBotAccounts.size(), totalRandomBotChars);
|
sPlayerbotAIConfig->randomBotAccounts.size(), totalRandomBotChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RandomPlayerbotFactory::CreateRandomGuilds()
|
void RandomPlayerbotFactory::CreateRandomGuilds()
|
||||||
{
|
{
|
||||||
std::vector<uint32> randomBots;
|
std::vector<uint32> randomBots;
|
||||||
|
|
||||||
PlayerbotsDatabasePreparedStatement* stmt = PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_SEL_RANDOM_BOTS_BOT);
|
PlayerbotsDatabasePreparedStatement* stmt = PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_SEL_RANDOM_BOTS_BOT);
|
||||||
@ -713,10 +740,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("playerbots", "{} random bot guilds available", guildNumber);
|
LOG_INFO("playerbots", "{} random bot guilds available", guildNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const RandomPlayerbotFactory::CreateRandomGuildName()
|
std::string const RandomPlayerbotFactory::CreateRandomGuildName()
|
||||||
{
|
{
|
||||||
std::string guildName = "";
|
std::string guildName = "";
|
||||||
|
|
||||||
QueryResult result = CharacterDatabase.Query("SELECT MAX(name_id) FROM playerbots_guild_names");
|
QueryResult result = CharacterDatabase.Query("SELECT MAX(name_id) FROM playerbots_guild_names");
|
||||||
@ -744,10 +771,10 @@
|
|||||||
guildName = fields[0].Get<std::string>();
|
guildName = fields[0].Get<std::string>();
|
||||||
|
|
||||||
return std::move(guildName);
|
return std::move(guildName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RandomPlayerbotFactory::CreateRandomArenaTeams(ArenaType type, uint32 count)
|
void RandomPlayerbotFactory::CreateRandomArenaTeams(ArenaType type, uint32 count)
|
||||||
{
|
{
|
||||||
std::vector<uint32> randomBots;
|
std::vector<uint32> randomBots;
|
||||||
|
|
||||||
PlayerbotsDatabasePreparedStatement* stmt = PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_SEL_RANDOM_BOTS_BOT);
|
PlayerbotsDatabasePreparedStatement* stmt = PlayerbotsDatabase.GetPreparedStatement(PLAYERBOTS_SEL_RANDOM_BOTS_BOT);
|
||||||
@ -855,10 +882,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("playerbots", "{} random bot {}vs{} arena teams available", arenaTeamNumber, type, type);
|
LOG_INFO("playerbots", "{} random bot {}vs{} arena teams available", arenaTeamNumber, type, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string const RandomPlayerbotFactory::CreateRandomArenaTeamName()
|
std::string const RandomPlayerbotFactory::CreateRandomArenaTeamName()
|
||||||
{
|
{
|
||||||
std::string arenaTeamName = "";
|
std::string arenaTeamName = "";
|
||||||
|
|
||||||
QueryResult result = CharacterDatabase.Query("SELECT MAX(name_id) FROM playerbots_arena_team_names");
|
QueryResult result = CharacterDatabase.Query("SELECT MAX(name_id) FROM playerbots_arena_team_names");
|
||||||
@ -887,4 +914,4 @@
|
|||||||
arenaTeamName = fields[0].Get<std::string>();
|
arenaTeamName = fields[0].Get<std::string>();
|
||||||
|
|
||||||
return std::move(arenaTeamName);
|
return std::move(arenaTeamName);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,6 +60,7 @@ private:
|
|||||||
static std::string const CreateRandomArenaTeamName();
|
static std::string const CreateRandomArenaTeamName();
|
||||||
|
|
||||||
uint32 accountId;
|
uint32 accountId;
|
||||||
|
static uint32 CalculateTotalAccountCount();
|
||||||
static std::map<uint8, std::vector<uint8>> availableRaces;
|
static std::map<uint8, std::vector<uint8>> availableRaces;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user