Skip to content

Commit

Permalink
Alt login: Added the guild login criteria which will login bots that …
Browse files Browse the repository at this point in the history
…are in a guild of a online player first.
  • Loading branch information
mostlikely4r committed Dec 7, 2024
1 parent acce405 commit 6ef2b13
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion playerbot/PlayerbotAIConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bool PlayerbotAIConfig::Initialize()

loginBotsNearPlayerRange = config.GetIntDefault("AiPlayerbot.LoginBotsNearPlayerRange", 1000);

LoadListString<std::vector<std::string> >(config.GetStringDefault("AiPlayerbot.LoginCriteria", "classrace"), loginCriteria);
LoadListString<std::vector<std::string> >(config.GetStringDefault("AiPlayerbot.LoginCriteria", "guild,classrace"), loginCriteria);

for (uint32 level = 1; level <= DEFAULT_MAX_LEVEL; ++level)
{
Expand Down
42 changes: 32 additions & 10 deletions playerbot/PlayerbotLoginMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class PlayerbotLoginQueryHolder : public LoginQueryHolder
PlayerbotHolder* GetPlayerbotHolder() { return playerbotHolder; }
};

PlayerBotInfo::PlayerBotInfo(const uint32 account, const uint32 guid, const uint8 race, const uint8 cls, const uint32 level, const bool isNew, const WorldPosition& position) : account(account), guid(guid), race(race), cls(cls), level(level), isNew(isNew), position(position)
PlayerBotInfo::PlayerBotInfo(const uint32 account, const uint32 guid, const uint8 race, const uint8 cls, const uint32 level, const bool isNew, const WorldPosition& position, const uint32 guildId) : account(account), guid(guid), race(race), cls(cls), level(level), isNew(isNew), position(position), guildId(guildId)
{

holder = new PlayerbotLoginQueryHolder(&sRandomPlayerbotMgr, 0, account, guid);
Expand All @@ -45,6 +45,8 @@ PlayerBotInfo::PlayerBotInfo(const uint32 account, const uint32 guid, const uint
}
}

PlayerBotInfo::PlayerBotInfo(Player* player) : PlayerBotInfo(player->GetSession()->GetAccountId(), player->GetDbGuid(), player->getRace(), player->getClass(), player->GetLevel(), player->GetTotalPlayedTime() == 0, player, player->GetGuildId()) {};

uint32 PlayerBotInfo::GetLevel() const
{
if (!isNew || sPlayerbotAIConfig.disableRandomLevels)
Expand All @@ -61,14 +63,15 @@ uint32 PlayerBotInfo::GetLevel() const

bool PlayerBotInfo::IsFarFromPlayer(const LoginSpace& space) const
{
if (space.playerLocations.empty())
return false;
if (space.realPlayerInfos.empty())
return true;

if (isNew && sPlayerbotAIConfig.instantRandomize) //We do not know where the bot will be teleported to on randomisation.
return false;

for (auto& p : space.playerLocations)
for (auto& player : space.realPlayerInfos)
{
WorldPosition p(player.position);
if (p.mapid == position.mapid && p.sqDistance(position) < sPlayerbotAIConfig.loginBotsNearPlayerRange * sPlayerbotAIConfig.loginBotsNearPlayerRange)
{
return false;
Expand All @@ -78,6 +81,22 @@ bool PlayerBotInfo::IsFarFromPlayer(const LoginSpace& space) const
return true;
}

bool PlayerBotInfo::IsInPlayerGuild(const LoginSpace& space) const
{
if (space.realPlayerInfos.empty())
return false;

for (auto& player : space.realPlayerInfos)
{
if (player.guildId == guildId)
{
return true;
}
}

return false;
}

bool PlayerBotInfo::SendHolder()
{
if (holderState == HolderState::HOLDER_SENT)
Expand Down Expand Up @@ -325,7 +344,7 @@ void PlayerBotLoginMgr::LoadBotsFromDb()

sLog.outDebug("PlayerbotLoginMgr: %d accounts found.", uint32(accounts.size()));

result = CharacterDatabase.PQuery("SELECT account, guid, race, class, level, totaltime, map, position_x, position_y, position_z, orientation FROM characters");
result = CharacterDatabase.PQuery("SELECT account, guid, race, class, level, totaltime, map, position_x, position_y, position_z, orientation, (SELECT guildid FROM guild_member m WHERE m.guid = c.guid) guildId FROM characters c");

do
{
Expand All @@ -341,7 +360,8 @@ void PlayerBotLoginMgr::LoadBotsFromDb()
uint32 level = fields[4].GetUInt32();
bool isNew = sPlayerbotAIConfig.instantRandomize ? (fields[5].GetUInt32() == 0) : level == 1;
WorldPosition position(fields[6].GetFloat(), fields[7].GetFloat(), fields[8].GetFloat(), fields[9].GetFloat(), fields[10].GetFloat());
botPool.insert(std::make_pair(guid, PlayerBotInfo(account, guid, race, cls, level, isNew, position)));;
uint32 guildId = fields[11].GetUInt32();
botPool.insert(std::make_pair(guid, PlayerBotInfo(account, guid, race, cls, level, isNew, position, guildId)));;
} while (result->NextRow());

sLog.outDebug("PlayerbotLoginMgr: %d bots found.", uint32(botPool.size()));
Expand Down Expand Up @@ -389,12 +409,12 @@ void PlayerBotLoginMgr::Update()

void PlayerBotLoginMgr::SetPlayerLocations(std::map<uint32, Player*> players)
{
std::vector<WorldPosition> positions;
std::vector<PlayerBotInfo> realPlayers;
for (auto& [guid, player] : players)
positions.push_back(player);
realPlayers.push_back(player);

playerMutex.lock();
playerLocations = positions;
realPlayerInfos = realPlayers;
playerMutex.unlock();
}

Expand Down Expand Up @@ -513,6 +533,8 @@ LoginCriteria PlayerBotLoginMgr::GetLoginCriteria(const uint8 attempt) const
ADD_CRITERIA(LEVEL, space.classRaceBucket[info.GetLevel()] <= 0);
if (configCriteria[i] == "range")
ADD_CRITERIA(RANGE, info.IsFarFromPlayer(space));
if (configCriteria[i] == "guild")
ADD_CRITERIA(GUILD, !info.IsInPlayerGuild(space));
}

return criteria;
Expand All @@ -523,7 +545,7 @@ void PlayerBotLoginMgr::FillLoginSpace(LoginSpace& space, FillStep step)
space.totalSpace = GetMaxOnlineBotCount();
space.currentSpace = GetMaxOnlineBotCount();
playerMutex.lock();
space.playerLocations = playerLocations;
space.realPlayerInfos = realPlayerInfos;
playerMutex.unlock();

for (uint32 level = 1; level <= GetMaxLevel(); ++level)
Expand Down
12 changes: 9 additions & 3 deletions playerbot/PlayerbotLoginMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct LoginSpace
int32 totalSpace;
int32 classRaceBucket[MAX_CLASSES][MAX_RACES];
int32 levelBucket[DEFAULT_MAX_LEVEL + 1];
std::vector<WorldPosition> playerLocations;
std::vector<PlayerBotInfo> realPlayerInfos;
};

enum class HolderState : uint8
Expand Down Expand Up @@ -43,6 +43,7 @@ enum class LoginCriterionFailType : uint8
CLASSRACE = 6,
LEVEL = 7,
RANGE = 8,
GUILD = 9,
LOGIN_OK = 10
};

Expand All @@ -55,21 +56,25 @@ static const std::unordered_map<LoginCriterionFailType, std::string> failName =
,{LoginCriterionFailType::CLASSRACE, "CLASSRACE"}
,{LoginCriterionFailType::LEVEL, "LEVEL"}
,{LoginCriterionFailType::RANGE , "RANGE"}
,{LoginCriterionFailType::GUILD , "GUILD"}
,{LoginCriterionFailType::LOGIN_OK, "LOGIN_OK"} };

typedef std::vector <std::pair<LoginCriterionFailType, std::function<bool(const PlayerBotInfo&, const LoginSpace&)>>> LoginCriteria;

class PlayerBotInfo
{
public:
PlayerBotInfo(const uint32 account, const uint32 guid, const uint8 race, const uint8 cls, const uint32 level, const bool isNew, const WorldPosition& position);
PlayerBotInfo(const uint32 account, const uint32 guid, const uint8 race, const uint8 cls, const uint32 level, const bool isNew, const WorldPosition& position, const uint32 guildId);

PlayerBotInfo(Player* player);

ObjectGuid GetGuid() const { return ObjectGuid(HIGHGUID_PLAYER, guid); }
uint32 GetId() const { return guid; }
uint8 GetRace() const { return race; }
uint8 GetClass() const { return cls; }
uint32 GetLevel() const;
bool IsFarFromPlayer(const LoginSpace& space) const;
bool IsInPlayerGuild(const LoginSpace& space) const;
LoginState GetLoginState() const { return loginState; }

bool SendHolder();
Expand Down Expand Up @@ -97,6 +102,7 @@ class PlayerBotInfo
uint32 level;
bool isNew = false;
WorldPosition position;
uint32 guildId;

SqlQueryHolder* holder;
HolderState holderState = HolderState::HOLDER_EMPTY;
Expand Down Expand Up @@ -137,7 +143,7 @@ class PlayerBotLoginMgr
bool showSpace = false;

std::mutex playerMutex;
std::vector<WorldPosition> playerLocations;
std::vector<PlayerBotInfo> realPlayerInfos;

std::mutex loginMutex;
std::queue<PlayerBotInfo*> loginQueue;
Expand Down
4 changes: 2 additions & 2 deletions playerbot/aiplayerbot.conf.dist.in
Original file line number Diff line number Diff line change
Expand Up @@ -985,9 +985,9 @@ AiPlayerbot.PerfMonEnabled = 0

# Enable the alternative asynchronous login system.
# AiPlayerbot.AsyncBotLogin = 0
# The login criteria to apply when trying to log in bots. options: range,classrace,level
# The login criteria to apply when trying to log in bots. options: range,classrace,level,guild
# When trying to reach max bots it will drop the last criteria first. So if classrace,level only reaches 800/1000 bots it will try to get to 1000 only looking at classrace.
# AiPlayerbot.LoginCriteria = classrace
# AiPlayerbot.LoginCriteria = guild,classrace
# When bots are logged in that do not fully match all criteria selected it will do so up to xxx spaces below the maximum. Bots that suddenly match all the criteria will then have room to use this to log in.
# AiPlayerbot.FreeRoomForNonSpareBots = 0

Expand Down
4 changes: 2 additions & 2 deletions playerbot/aiplayerbot.conf.dist.in.tbc
Original file line number Diff line number Diff line change
Expand Up @@ -1004,9 +1004,9 @@ AiPlayerbot.PerfMonEnabled = 0

# Enable the alternative asynchronous login system.
# AiPlayerbot.AsyncBotLogin = 0
# The login criteria to apply when trying to log in bots. options: range,classrace,level
# The login criteria to apply when trying to log in bots. options: range,classrace,level,guild
# When trying to reach max bots it will drop the last criteria first. So if classrace,level only reaches 800/1000 bots it will try to get to 1000 only looking at classrace.
# AiPlayerbot.LoginCriteria = classrace
# AiPlayerbot.LoginCriteria = guild,classrace
# When bots are logged in that do not fully match all criteria selected it will do so up to xxx spaces below the maximum. Bots that suddenly match all the criteria will then have room to use this to log in.
# AiPlayerbot.FreeRoomForNonSpareBots = 0

Expand Down
4 changes: 2 additions & 2 deletions playerbot/aiplayerbot.conf.dist.in.wotlk
Original file line number Diff line number Diff line change
Expand Up @@ -944,9 +944,9 @@ AiPlayerbot.PerfMonEnabled = 0

# Enable the alternative asynchronous login system.
# AiPlayerbot.AsyncBotLogin = 0
# The login criteria to apply when trying to log in bots. options: range,classrace,level
# The login criteria to apply when trying to log in bots. options: range,classrace,level,guild
# When trying to reach max bots it will drop the last criteria first. So if classrace,level only reaches 800/1000 bots it will try to get to 1000 only looking at classrace.
# AiPlayerbot.LoginCriteria = classrace
# AiPlayerbot.LoginCriteria = guild,classrace
# When bots are logged in that do not fully match all criteria selected it will do so up to xxx spaces below the maximum. Bots that suddenly match all the criteria will then have room to use this to log in.
# AiPlayerbot.FreeRoomForNonSpareBots = 0

Expand Down

0 comments on commit 6ef2b13

Please sign in to comment.