Skip to content

Commit

Permalink
NPCBots: New config: NpcBot.DisableInstances - disables certain ins…
Browse files Browse the repository at this point in the history
…tance map ids when NpcBot.Enable.Dungeon or/and NpcBot.Enable.Raid options are enabled
  • Loading branch information
trickerer committed Mar 17, 2024
1 parent e0c5c1f commit b491469
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/server/game/AI/NpcBots/botmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ float _mult_dmg_cryptlord;
float _bothk_rate_honor;
std::vector<float> _mult_dmg_levels;
BotBrackets _botwanderer_pct_level_brackets;
std::vector<uint32> _disabled_instance_maps;
std::vector<uint32> _enabled_wander_node_maps;

bool __firstload = true;
Expand Down Expand Up @@ -443,6 +444,27 @@ void BotMgr::LoadConfig(bool reload)
_desiredWanderingBotsCount = 0;
}

_disabled_instance_maps.clear();
std::string disabled_instance_maps = sConfigMgr->GetStringDefault("NpcBot.DisableInstances", "");
std::vector<std::string_view> toks4 = Trinity::Tokenize(disabled_instance_maps, ',', false);
for (decltype(toks4)::size_type i = 0; i != toks4.size(); ++i)
{
Optional<uint32> val = Trinity::StringTo<uint32>(toks4[i]);
if (val == std::nullopt)
{
TC_LOG_ERROR("server.loading", "NpcBot.DisableInstances contains invalid uint32 value '{}', skipped", toks4[i]);
continue;
}
uint32 uval = val.value_or(uint32(0));
MapEntry const* mapEntry = sMapStore.LookupEntry(uval);
if (!mapEntry || !mapEntry->IsDungeon())
{
TC_LOG_ERROR("server.loading", "NpcBot.DisableInstances contains invalid instance map id '{}', skipped", uval);
continue;
}
_disabled_instance_maps.push_back(uval);
}

//limits
RoundToInterval(_mult_dmg_physical, 0.1f, 10.f);
RoundToInterval(_mult_dmg_spell, 0.1f, 10.f);
Expand Down Expand Up @@ -967,6 +989,20 @@ void BotMgr::Update(uint32 diff)
}
}

bool BotMgr::IsMapAllowedForBots(Map const* map) const
{
if ((!_enableNpcBotsBGs && map->IsBattleground()) ||
(!_enableNpcBotsArenas && map->IsBattleArena()) ||
(!_enableNpcBotsDungeons && map->IsNonRaidDungeon()) ||
(!_enableNpcBotsRaids && map->IsRaid()))
return false;

if (map->IsDungeon() && !_disabled_instance_maps.empty() && std::find(_disabled_instance_maps.cbegin(), _disabled_instance_maps.cend(), map->GetId()) != _disabled_instance_maps.cend())
return false;

return true;
}

bool BotMgr::RestrictBots(Creature const* bot, bool add) const
{
if (!_owner->FindMap())
Expand All @@ -980,10 +1016,7 @@ bool BotMgr::RestrictBots(Creature const* bot, bool add) const

Map const* currMap = _owner->GetMap();

if ((!_enableNpcBotsBGs && currMap->IsBattleground()) ||
(!_enableNpcBotsArenas && currMap->IsBattleArena()) ||
(!_enableNpcBotsDungeons && currMap->IsNonRaidDungeon()) ||
(!_enableNpcBotsRaids && currMap->IsRaid()))
if (!IsMapAllowedForBots(currMap))
return true;

if (LimitBots(currMap))
Expand Down Expand Up @@ -1263,7 +1296,6 @@ void BotMgr::OnTeleportFar(uint32 mapId, float x, float y, float z, float ori)
for (BotMap::const_iterator itr = _bots.begin(); itr != _bots.end(); ++itr)
{
bot = itr->second;
ASSERT(bot, "BotMgr::OnTeleportFar(): bot does not exist!!!");

if (bot->IsTempBot())
continue;
Expand Down
1 change: 1 addition & 0 deletions src/server/game/AI/NpcBots/botmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class TC_GAME_API BotMgr
static bool IsWanderingWorldBot(Creature const* bot);
static bool IsBotContestedPvP(Creature const* bot);
static void SetBotContestedPvP(Creature const* bot);
bool IsMapAllowedForBots(Map const* map) const;
bool RestrictBots(Creature const* bot, bool add) const;
bool IsPartyInCombat() const;
bool HasBotClass(uint8 botclass) const;
Expand Down
9 changes: 9 additions & 0 deletions src/server/worldserver/worldserver.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4324,6 +4324,15 @@ NpcBot.Enable.BG = 0
NpcBot.Enable.Arena = 0
NpcBot.Enable.DungeonFinder = 1

#
# NpcBot.DisableInstances
# Description: When NpcBot.Enable.Dungeon or/and NpcBot.Enable.Raid options are set to 1
# excludes certain instance map ids, preventing bots from entering those maps
# Default: "" - (None)
# "509,531" - (Disable AQ20 and AQ40)

NpcBot.DisableInstances = ""

#
# NpcBot.Limit.Dungeon
# NpcBot.Limit.Raid
Expand Down

0 comments on commit b491469

Please sign in to comment.