[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);
if (new_bot) {
if (!new_bot->IsValidRaceClassCombo()) {
initiator->Message(Chat::White, "That Race/Class combination cannot be created.");
return false;
}
if (!new_bot->IsValidRaceClassCombo()) {
initiator->Message(Chat::White, "That Race/Class combination cannot be created.");
return false;
}
if (!new_bot->IsValidName()) {
initiator->Message(
Chat::White,
fmt::format(
"{} has invalid characters. You can use only the A-Z, a-z and _ characters in a bot name.",
new_bot->GetCleanName()
).c_str()
);
return false;
}
if (!new_bot->IsValidName()) {
initiator->Message(
Chat::White,
fmt::format(
"{} has invalid characters. You can use only the A-Z, a-z and _ characters in a bot name.",
new_bot->GetCleanName()
).c_str()
);
return false;
}
// Now that all validation is complete, we can save our newly created bot
if (!new_bot->Save()) {
initiator->Message(
Chat::White,
fmt::format(
"Unable to save {} as a bot.",
new_bot->GetCleanName()
).c_str()
);
} else {
initiator->Message(
Chat::White,
fmt::format(
"{} saved as bot ID {}.",
new_bot->GetCleanName(),
new_bot->GetBotID()
).c_str()
// Now that all validation is complete, we can save our newly created bot
if (!new_bot->Save()) {
initiator->Message(
Chat::White,
fmt::format(
"Unable to save {} as a bot.",
new_bot->GetCleanName()
).c_str()
);
} else {
initiator->Message(
Chat::White,
fmt::format(
"{} saved as bot ID {}.",
new_bot->GetCleanName(),
new_bot->GetBotID()
).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)) {
const auto& export_string = fmt::format(
"{} {} {} {} {}",
name,
new_bot->GetBotID(),
race,
botclass,
gender
);
parse->EventPlayer(EVENT_BOT_CREATE, initiator, export_string, 0);
}
return true;
parse->EventPlayer(EVENT_BOT_CREATE, initiator, export_string, 0);
}
return true;
}
}
return false;