From 2a094e879257e00c55cae45d6e142a32e7f4202c Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Wed, 5 Apr 2023 10:09:19 -0400 Subject: [PATCH] [Cleanup] Use variable for c->GetTarget() instead of calling multiple times in bot_command.cpp (#3254) # Notes - Calling multiple times is less performant than using a variable. --- zone/bot_command.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/zone/bot_command.cpp b/zone/bot_command.cpp index fcaa37b10..224a7bd0a 100644 --- a/zone/bot_command.cpp +++ b/zone/bot_command.cpp @@ -2526,9 +2526,17 @@ void bot_command_apply_poison(Client *c, const Seperator *sep) } Bot *my_rogue_bot = nullptr; - if (c->GetTarget() && c->GetTarget()->IsBot() && c->GetTarget()->CastToBot()->GetBotOwnerCharacterID() == c->CharacterID() && c->GetTarget()->CastToBot()->GetClass() == ROGUE) { - my_rogue_bot = c->GetTarget()->CastToBot(); + auto t = c->GetTarget(); + + if ( + t && + t->IsBot() && + t->CastToBot()->GetBotOwnerCharacterID() == c->CharacterID() && + t->GetClass() == ROGUE + ) { + my_rogue_bot = t->CastToBot(); } + if (!my_rogue_bot) { c->Message(Chat::White, "You must target a rogue bot that you own to use this command!"); @@ -6402,13 +6410,14 @@ void bot_subcommand_bot_report(Client *c, const Seperator *sep) std::string ab_type_arg = sep->arg[1]; if (ab_type_arg.empty()) { - if (c->GetTarget()) { - if (c->GetTarget()->IsClient() && c->GetTarget()->CastToClient() == c) + auto t = c->GetTarget(); + if (t && t->IsClient()) { + if (t->CastToClient() == c) { ab_type_arg = "ownergroup"; - else if (c->GetTarget()->IsClient() && c->GetTarget()->CastToClient() != c) + } else { ab_type_arg = "targetgroup"; - } - else { + } + } else { ab_type_arg = "spawned"; } }