diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index a077805d..bcb4ad11 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -96,6 +96,11 @@ AiPlayerbot.RandomBotAccountCount = 0 # To apply this, set the number to 1 and run the Worldserver. Once deletion is complete, if you would like to recreate randombots, set the number back to 0 and rerun the Worldserver. AiPlayerbot.DeleteRandomBotAccounts = 0 +# Disabled without real player +AiPlayerbot.DisabledWithoutRealPlayer = 0 +AiPlayerbot.DisabledWithoutRealPlayerLoginDelay = 30 +AiPlayerbot.DisabledWithoutRealPlayerLogoutDelay = 300 + #################################################################################################### ################################### diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index 225f97cb..15acf4f7 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -82,6 +82,8 @@ bool PlayerbotAIConfig::Initialize() sitDelay = sConfigMgr->GetOption("AiPlayerbot.SitDelay", 30000); returnDelay = sConfigMgr->GetOption("AiPlayerbot.ReturnDelay", 7000); lootDelay = sConfigMgr->GetOption("AiPlayerbot.LootDelay", 1000); + disabledWithoutRealPlayerLoginDelay = sConfigMgr->GetOption("AiPlayerbot.DisabledWithoutRealPlayerLoginDelay", 30); + disabledWithoutRealPlayerLogoutDelay = sConfigMgr->GetOption("AiPlayerbot.DisabledWithoutRealPlayerLogoutDelay", 300); farDistance = sConfigMgr->GetOption("AiPlayerbot.FarDistance", 20.0f); sightDistance = sConfigMgr->GetOption("AiPlayerbot.SightDistance", 75.0f); @@ -129,6 +131,7 @@ bool PlayerbotAIConfig::Initialize() allowAccountBots = sConfigMgr->GetOption("AiPlayerbot.AllowAccountBots", true); allowGuildBots = sConfigMgr->GetOption("AiPlayerbot.AllowGuildBots", true); allowTrustedAccountBots = sConfigMgr->GetOption("AiPlayerbot.AllowTrustedAccountBots", true); + disabledWithoutRealPlayer = sConfigMgr->GetOption("AiPlayerbot.DisabledWithoutRealPlayer", false); randomBotGuildNearby = sConfigMgr->GetOption("AiPlayerbot.RandomBotGuildNearby", false); randomBotInvitePlayer = sConfigMgr->GetOption("AiPlayerbot.RandomBotInvitePlayer", false); inviteChat = sConfigMgr->GetOption("AiPlayerbot.InviteChat", false); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index 17880ad5..e951e52d 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -55,6 +55,7 @@ public: bool IsInPvpProhibitedArea(uint32 id); bool enabled; + bool disabledWithoutRealPlayer; bool allowAccountBots, allowGuildBots, allowTrustedAccountBots; bool randomBotGuildNearby, randomBotInvitePlayer, inviteChat; uint32 globalCoolDown, reactDelay, maxWaitForMove, disableMoveSplinePath, maxMovementSearchTime, expireActionTime, @@ -99,6 +100,7 @@ public: uint32 minRandomBotPvpTime, maxRandomBotPvpTime; uint32 randomBotsPerInterval; uint32 minRandomBotsPriceChangeInterval, maxRandomBotsPriceChangeInterval; + uint32 disabledWithoutRealPlayerLoginDelay, disabledWithoutRealPlayerLogoutDelay; bool randomBotJoinLfg; // chat diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 4711ed03..5c9ce9f6 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -49,6 +49,7 @@ #include "UpdateTime.h" #include "World.h" #include "RandomPlayerbotFactory.h" +#include struct GuidClassRaceInfo { ObjectGuid::LowType guid; @@ -355,7 +356,43 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/) PERF_MON_TOTAL, onlineBotCount < maxAllowedBotCount ? "RandomPlayerbotMgr::Login" : "RandomPlayerbotMgr::UpdateAIInternal"); - if (availableBotCount < maxAllowedBotCount) + bool realPlayerIsLogged = false; + if (sPlayerbotAIConfig->disabledWithoutRealPlayer) + { + if (sWorldSessionMgr->GetActiveAndQueuedSessionCount() > 0) + { + RealPlayerLastTimeSeen = time(nullptr); + realPlayerIsLogged = true; + + if (DelayLoginBotsTimer == 0) + { + DelayLoginBotsTimer = time(nullptr) + sPlayerbotAIConfig->disabledWithoutRealPlayerLoginDelay; + } + } + else + { + if (DelayLoginBotsTimer) + { + DelayLoginBotsTimer = 0; + } + + if (RealPlayerLastTimeSeen != 0 && onlineBotCount > 0 && + time(nullptr) > RealPlayerLastTimeSeen + sPlayerbotAIConfig->disabledWithoutRealPlayerLogoutDelay) + { + LogoutAllBots(); + LOG_INFO("playerbots", + "Logout all bots due no real player session."); + } + } + + if (availableBotCount < maxAllowedBotCount && + (sPlayerbotAIConfig->disabledWithoutRealPlayer == false || + (realPlayerIsLogged && DelayLoginBotsTimer != 0 && time(nullptr) >= DelayLoginBotsTimer))) + { + AddRandomBots(); + } + } + else if (availableBotCount < maxAllowedBotCount) { AddRandomBots(); } @@ -391,7 +428,11 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/) } } uint32 updateBots = sPlayerbotAIConfig->randomBotsPerInterval * onlineBotFocus / 100; - uint32 maxNewBots = onlineBotCount < maxAllowedBotCount ? maxAllowedBotCount - onlineBotCount : 0; + uint32 maxNewBots = onlineBotCount < maxAllowedBotCount && + (sPlayerbotAIConfig->disabledWithoutRealPlayer == false || + (realPlayerIsLogged && DelayLoginBotsTimer != 0 && time(nullptr) >= DelayLoginBotsTimer)) + ? maxAllowedBotCount - onlineBotCount + : 0; uint32 loginBots = std::min(sPlayerbotAIConfig->randomBotsPerInterval - updateBots, maxNewBots); if (!availableBots.empty()) @@ -432,6 +473,8 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/) if (!loginBots) break; } + + DelayLoginBotsTimer = 0; } } diff --git a/src/RandomPlayerbotMgr.h b/src/RandomPlayerbotMgr.h index bd5b7cd4..f397276c 100644 --- a/src/RandomPlayerbotMgr.h +++ b/src/RandomPlayerbotMgr.h @@ -206,6 +206,8 @@ private: time_t BgCheckTimer; time_t LfgCheckTimer; time_t PlayersCheckTimer; + time_t RealPlayerLastTimeSeen = 0; + time_t DelayLoginBotsTimer; time_t printStatsTimer; uint32 AddRandomBots(); bool ProcessBot(uint32 bot);