From be13e0e189e5fda47f53bb1a0c697db219d8677c Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Fri, 15 Sep 2023 00:06:45 +0800 Subject: [PATCH] equipmentPersistence --- conf/playerbots.conf.dist | 7 +++++++ src/PlayerbotAIConfig.cpp | 2 ++ src/PlayerbotAIConfig.h | 2 ++ src/PlayerbotFactory.cpp | 16 ++++++++++------ .../actions/AutoTeleportForLevelAction.cpp | 4 +++- 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index 44ac72c1..efce23da 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -623,6 +623,13 @@ AiPlayerbot.RandomBotRandomPassword = 0 # Set RandomBotMaxLevel bots to RandomBotMinLevel or not AiPlayerbot.DowngradeMaxLevelBot = 0 +# Enable/Disable bot equipments persistence (stop random initialization) after certain level (EquipmentPersistenceLevel) +# default: 0 (disable) +AiPlayerbot.EquipmentPersistence = 0 + +# default: 80 +AiPlayerbot.EquipmentPersistenceLevel = 80 + ################################################################################## # # # Database Stuff # diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index 0ccf397c..cc30d8f5 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -296,6 +296,8 @@ bool PlayerbotAIConfig::Initialize() disableRandomLevels = sConfigMgr->GetOption("AiPlayerbot.DisableRandomLevels", false); randomBotRandomPassword = sConfigMgr->GetOption("AiPlayerbot.RandomBotRandomPassword", true); downgradeMaxLevelBot = sConfigMgr->GetOption("AiPlayerbot.DowngradeMaxLevelBot", true); + equipmentPersistence = sConfigMgr->GetOption("AiPlayerbot.EquipmentPersistence", false); + equipmentPersistenceLevel = sConfigMgr->GetOption("AiPlayerbot.EquipmentPersistenceLevel", 80); playerbotsXPrate = sConfigMgr->GetOption("AiPlayerbot.KillXPRate", 1); botActiveAlone = sConfigMgr->GetOption("AiPlayerbot.BotActiveAlone", 10); randombotsWalkingRPG = sConfigMgr->GetOption("AiPlayerbot.RandombotsWalkingRPG", false); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index c7f04606..92368088 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -167,6 +167,8 @@ class PlayerbotAIConfig uint32 selfBotLevel; bool downgradeMaxLevelBot; + bool equipmentPersistence; + int32 equipmentPersistenceLevel; std::string const GetTimestampStr(); bool hasLog(std::string const fileName) { return std::find(allowedLogFiles.begin(), allowedLogFiles.end(), fileName) != allowedLogFiles.end(); }; bool openLog(std::string const fileName, char const* mode = "a"); diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 8424e3eb..689dbd15 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -130,7 +130,9 @@ void PlayerbotFactory::Randomize(bool incremental) { ResetQuests(); } - ClearAllItems(); + if (!sPlayerbotAIConfig->equipmentPersistence || level < sPlayerbotAIConfig->equipmentPersistenceLevel) { + ClearAllItems(); + } bot->SaveToDB(false, false); bot->GiveLevel(level); @@ -222,7 +224,9 @@ void PlayerbotFactory::Randomize(bool incremental) pmo = sPerformanceMonitor->start(PERF_MON_RNDBOT, "PlayerbotFactory_Equip"); LOG_INFO("playerbots", "Initializing equipmemt..."); - InitEquipment(incremental); + if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel) { + InitEquipment(incremental); + } // bot->SaveToDB(false, false); if (pmo) pmo->finish(); @@ -342,7 +346,9 @@ void PlayerbotFactory::Randomize(bool incremental) void PlayerbotFactory::Refresh() { // Prepare(); - InitEquipment(true); + if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel) { + InitEquipment(true); + } ClearInventory(); InitAmmo(); InitFood(); @@ -1153,9 +1159,7 @@ void Shuffle(std::vector& items) void PlayerbotFactory::InitEquipment(bool incremental) { - - // todo(yunfan): to be refactored, too much time overhead - std::map > items; + std::unordered_map > items; int tab = AiFactory::GetPlayerSpecTab(bot); uint32 blevel = bot->getLevel(); diff --git a/src/strategy/actions/AutoTeleportForLevelAction.cpp b/src/strategy/actions/AutoTeleportForLevelAction.cpp index a4ddad56..7ed7a832 100644 --- a/src/strategy/actions/AutoTeleportForLevelAction.cpp +++ b/src/strategy/actions/AutoTeleportForLevelAction.cpp @@ -20,6 +20,8 @@ void AutoTeleportForLevelAction::AutoUpgradeEquip() { return; } PlayerbotFactory factory(bot, bot->GetLevel(), ITEM_QUALITY_RARE); - factory.InitEquipment(true); + if (!sPlayerbotAIConfig->equipmentPersistence || bot->GetLevel() < sPlayerbotAIConfig->equipmentPersistenceLevel) { + factory.InitEquipment(true); + } factory.InitAmmo(); } \ No newline at end of file