Skip to content

Commit

Permalink
NPCBots: Add NpcBot.WanderingBots.MaxItemLevel.Levels config param …
Browse files Browse the repository at this point in the history
…to restrict maximum item level generated for wandering bots per level bracket

(cherry picked from commit 1e1130d4799c56be2433f0f9c66a163e72ccaccd)

# Conflicts:
#	src/server/worldserver/worldserver.conf.dist
  • Loading branch information
trickerer committed Nov 8, 2024
1 parent eef5d63 commit 8181aac
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/server/apps/worldserver/worldserver.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4944,6 +4944,18 @@ NpcBot.WanderingBots.Continents.Maps = 0,1,530,571

NpcBot.WanderingBots.Continents.XPGain = 1.0

#
# NpcBot.WanderingBots.MaxItemLevel.Levels
# Description: Maximum item ilevel to generate for wandering bots per level bracket:
# 0-9, 10-19, 20,29, ... , 70-79, 80+.
# Note: If item generation attempt fails becuse of item ilevel restriction
# the item will be generated again with this restriction ignored
# Example: 0,0,0,0,0,0,0,0,200 makes level 80+ wandering bots only generate
# items of ilevel 200 or less
# Default: 0,0,0,0,0,0,0,0,0

NpcBot.WanderingBots.MaxItemLevel.Levels = 0,0,0,0,0,0,0,0,0

#
# NpcBot.WanderingBots.BG.Enable
# Description: Allow wandering bots generation for Battlegrounds.
Expand Down
15 changes: 11 additions & 4 deletions src/server/game/AI/NpcBots/botdatamgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2166,11 +2166,18 @@ Item* BotDataMgr::GenerateWanderingBotItem(uint8 slot, uint8 botclass, uint8 lev
{
ItemIdVector validVec;
validVec.reserve(itemIdVec->size());
for (uint32 iid : *itemIdVec)
uint32 maxItemLevel = BotMgr::GetBotWandererMaxItemLevel(level);
for (uint32 maxLvl : { maxItemLevel, static_cast<decltype(maxItemLevel)>(0) })
{
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(iid);
if (check(proto))
validVec.push_back(iid);
if (!validVec.empty())
break;

for (uint32 iid : *itemIdVec)
{
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(iid);
if ((!maxLvl || proto->ItemLevel <= maxLvl) && check(proto))
validVec.push_back(iid);
}
}

if (!validVec.empty())
Expand Down
18 changes: 18 additions & 0 deletions src/server/game/AI/NpcBots/botmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ std::vector<float> _mult_hp_levels;
std::vector<float> _mult_mp_levels;
LvlBrackets _max_npcbots;
PctBrackets _botwanderer_pct_level_brackets;
ItemLvlBrackets _botwanderer_itemlvl_level_brackets;
std::vector<uint32> _disabled_instance_maps;
std::vector<uint32> _enabled_wander_node_maps;

Expand Down Expand Up @@ -599,6 +600,19 @@ void BotMgr::LoadConfig(bool reload)
_disabled_instance_maps.push_back(uval);
}

_botwanderer_itemlvl_level_brackets = {};
std::string itemlevel_by_levels = sConfigMgr->GetStringDefault("NpcBot.WanderingBots.MaxItemLevel.Levels", "0,0,0,0,0,0,0,0,0");
std::vector<std::string_view> tok8 = Bcore::Tokenize(itemlevel_by_levels, ',', false);
ASSERT(tok8.size() == BracketsCount, "NpcBot.WanderingBots.MaxItemLevel.Levels must have exactly %u values", uint32(BracketsCount));
for (decltype(tok8)::size_type i = 0; i != tok8.size(); ++i)
{
Optional<uint32> val = Bcore::StringTo<uint32>(tok8[i]);
if (val == std::nullopt)
BOT_LOG_ERROR("server.loading", "NpcBot.WanderingBots.MaxItemLevel.Levels contains invalid uint32 value '{}', set to default", tok8[i]);
uint32 uval = val.value_or(uint32(0));
_botwanderer_itemlvl_level_brackets[i] = uval;
}

//limits
_mountLevel100 = std::max<uint8>(_mountLevel100, _mountLevel60);
RoundToInterval(_mult_dmg_physical, 0.1f, 10.f);
Expand Down Expand Up @@ -3117,6 +3131,10 @@ PctBrackets BotMgr::GetBotWandererLevelBrackets()
{
return _botwanderer_pct_level_brackets;
}
uint32 BotMgr::GetBotWandererMaxItemLevel(uint8 level)
{
return _botwanderer_itemlvl_level_brackets[std::min<size_t>(BracketsCount - 1, level / 10)];
}
float BotMgr::GetBotDamageModByClass(uint8 botclass)
{
switch (botclass)
Expand Down
2 changes: 2 additions & 0 deletions src/server/game/AI/NpcBots/botmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ template<typename U>
using BotBrackets = std::array<U, BracketsCount>;
typedef BotBrackets<uint8> LvlBrackets;
typedef BotBrackets<uint32> PctBrackets;
typedef BotBrackets<uint32> ItemLvlBrackets;

class AC_GAME_API BotMgr
{
Expand Down Expand Up @@ -174,6 +175,7 @@ class AC_GAME_API BotMgr
static float GetBotWandererSpeedMod();
static float GetBotWandererXPGainMod();
static PctBrackets GetBotWandererLevelBrackets();
static uint32 GetBotWandererMaxItemLevel(uint8 level);
static float GetBotDamageModByClass(uint8 botclass);
static float GetBotDamageModByLevel(uint8 botlevel);
static float GetBotHealingModByLevel(uint8 botlevel);
Expand Down

0 comments on commit 8181aac

Please sign in to comment.