From de053ce8f3ad1a8a48ea8260bc471d430110c7fb Mon Sep 17 00:00:00 2001 From: nytmyr <53322305+nytmyr@users.noreply.github.com> Date: Wed, 8 Jan 2025 00:28:33 -0600 Subject: [PATCH] Add zero check for bot spawn limits If the spawn limit rule is set to 0 and spawn limit is set by bucket, if no class buckets are set, it defaults to the rule of 0 and renders the player unable to spawn bots. This adds a check where if the rule and class bucket are 0, it will check for the spawn limit bucket --- zone/bot_commands/bot.cpp | 12 +++++++++--- zone/client_bot.cpp | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/zone/bot_commands/bot.cpp b/zone/bot_commands/bot.cpp index 6678cb521..704e62863 100644 --- a/zone/bot_commands/bot.cpp +++ b/zone/bot_commands/bot.cpp @@ -983,6 +983,7 @@ void bot_command_spawn(Client *c, const Seperator *sep) } auto bot_character_level = c->GetBotRequiredLevel(); + if ( bot_character_level >= 0 && c->GetLevel() < bot_character_level && @@ -1009,8 +1010,9 @@ void bot_command_spawn(Client *c, const Seperator *sep) bot_spawn_limit >= 0 && spawned_bot_count >= bot_spawn_limit && !c->GetGM() - ) { + ) { std::string message; + if (bot_spawn_limit) { message = fmt::format( "You cannot have more than {} spawned bot{}.", @@ -1034,6 +1036,7 @@ void bot_command_spawn(Client *c, const Seperator *sep) uint32 bot_id = 0; uint8 bot_class = Class::None; + if (!database.botdb.LoadBotID(bot_name, bot_id, bot_class)) { c->Message( Chat::White, @@ -1052,7 +1055,7 @@ void bot_command_spawn(Client *c, const Seperator *sep) bot_spawn_limit_class >= 0 && spawned_bot_count_class >= bot_spawn_limit_class && !c->GetGM() - ) { + ) { std::string message; if (bot_spawn_limit_class) { @@ -1074,11 +1077,12 @@ void bot_command_spawn(Client *c, const Seperator *sep) } auto bot_character_level_class = c->GetBotRequiredLevel(bot_class); + if ( bot_character_level_class >= 0 && c->GetLevel() < bot_character_level_class && !c->GetGM() - ) { + ) { c->Message( Chat::White, fmt::format( @@ -1113,6 +1117,7 @@ void bot_command_spawn(Client *c, const Seperator *sep) } auto my_bot = Bot::LoadBot(bot_id); + if (!my_bot) { c->Message( Chat::White, @@ -1134,6 +1139,7 @@ void bot_command_spawn(Client *c, const Seperator *sep) bot_id ).c_str() ); + safe_delete(my_bot); return; } diff --git a/zone/client_bot.cpp b/zone/client_bot.cpp index 9d796cef1..2a4c5c0a8 100644 --- a/zone/client_bot.cpp +++ b/zone/client_bot.cpp @@ -88,8 +88,22 @@ int Client::GetBotSpawnLimit(uint8 class_id) ); auto bucket_value = GetBucket(bucket_name); + + if (class_id && !bot_spawn_limit && bucket_value.empty()) { + const auto new_bucket_name = "bot_spawn_limit"; + + bucket_value = GetBucket(new_bucket_name); + + if (!bucket_value.empty() && Strings::IsNumber(bucket_value)) { + bot_spawn_limit = Strings::ToInt(bucket_value); + + return bot_spawn_limit; + } + } + if (!bucket_value.empty() && Strings::IsNumber(bucket_value)) { bot_spawn_limit = Strings::ToInt(bucket_value); + return bot_spawn_limit; } @@ -101,6 +115,7 @@ int Client::GetBotSpawnLimit(uint8 class_id) ); auto results = database.QueryDatabase(query); // use 'database' for non-bot table calls + if (!results.Success() || !results.RowCount()) { return bot_spawn_limit; }