[Cleanup] quest::createBot() unnecessary check against nullptr (#3302)

# Notes
- We initialize this variable, so it can never be a nullptr.
This commit is contained in:
Alex King 2023-04-23 15:08:50 -04:00 committed by GitHub
parent 576f99f292
commit 8b1d64a043
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2595,57 +2595,55 @@ bool QuestManager::createBot(const char *name, const char *lastname, uint8 level
Bot* new_bot = new Bot(Bot::CreateDefaultNPCTypeStructForBot(name, lastname, level, race, botclass, gender), initiator); Bot* new_bot = new Bot(Bot::CreateDefaultNPCTypeStructForBot(name, lastname, level, race, botclass, gender), initiator);
if (new_bot) { if (!new_bot->IsValidRaceClassCombo()) {
if (!new_bot->IsValidRaceClassCombo()) { initiator->Message(Chat::White, "That Race/Class combination cannot be created.");
initiator->Message(Chat::White, "That Race/Class combination cannot be created."); return false;
return false; }
}
if (!new_bot->IsValidName()) { if (!new_bot->IsValidName()) {
initiator->Message( initiator->Message(
Chat::White, Chat::White,
fmt::format( fmt::format(
"{} has invalid characters. You can use only the A-Z, a-z and _ characters in a bot name.", "{} has invalid characters. You can use only the A-Z, a-z and _ characters in a bot name.",
new_bot->GetCleanName() new_bot->GetCleanName()
).c_str() ).c_str()
); );
return false; return false;
} }
// Now that all validation is complete, we can save our newly created bot // Now that all validation is complete, we can save our newly created bot
if (!new_bot->Save()) { if (!new_bot->Save()) {
initiator->Message( initiator->Message(
Chat::White, Chat::White,
fmt::format( fmt::format(
"Unable to save {} as a bot.", "Unable to save {} as a bot.",
new_bot->GetCleanName() new_bot->GetCleanName()
).c_str() ).c_str()
); );
} else { } else {
initiator->Message( initiator->Message(
Chat::White, Chat::White,
fmt::format( fmt::format(
"{} saved as bot ID {}.", "{} saved as bot ID {}.",
new_bot->GetCleanName(), new_bot->GetCleanName(),
new_bot->GetBotID() new_bot->GetBotID()
).c_str() ).c_str()
);
if (parse->PlayerHasQuestSub(EVENT_BOT_CREATE)) {
const auto &export_string = fmt::format(
"{} {} {} {} {}",
name,
new_bot->GetBotID(),
race,
botclass,
gender
); );
if (parse->PlayerHasQuestSub(EVENT_BOT_CREATE)) { parse->EventPlayer(EVENT_BOT_CREATE, initiator, export_string, 0);
const auto& export_string = fmt::format(
"{} {} {} {} {}",
name,
new_bot->GetBotID(),
race,
botclass,
gender
);
parse->EventPlayer(EVENT_BOT_CREATE, initiator, export_string, 0);
}
return true;
} }
return true;
} }
} }
return false; return false;