eqemu-server/zone/gm_commands/titlesuffix.cpp
Kinglykrab 0e96099b3d
[Titles] Cleanup titles, title suffix, and last name methods. (#2174)
* [Titles] Cleanup titles, title suffix, and last name methods.
- Use strings instead of const chars*.
- Add optional parameter to SetAATitle in Lua so you can save to the database similar to Perl.
- Cleanup #lastname command.
- Cleanup #title command.
- Cleanup #titlesuffix command.

* Update npc.cpp
2022-05-19 20:15:44 -04:00

59 lines
1.2 KiB
C++
Executable File

#include "../client.h"
#include "../titles.h"
void command_titlesuffix(Client *c, const Seperator *sep)
{
int arguments = sep->argnum;
if (!arguments) {
c->Message(
Chat::White,
"Usage: #titlesuffix [Remove|Title] [Save (0 = False, 1 = True)]"
);
return;
}
bool is_remove = !strcasecmp(sep->arg[1], "remove");
std::string suffix = is_remove ? "" : sep->arg[1];
bool save_suffix = sep->IsNumber(2) ? atobool(sep->arg[2]) : false;
auto target = c;
if (c->GetTarget() && c->GetTarget()->IsClient()) {
target = c->GetTarget()->CastToClient();
}
if (suffix.size() > 31) {
c->Message(Chat::White, "Title suffix must be 31 characters or less.");
return;
}
if (!suffix.empty()) {
find_replace(suffix, "_", " ");
}
if (!save_suffix || is_remove) {
target->SetTitleSuffix(suffix);
} else if (save_suffix) {
title_manager.CreateNewPlayerSuffix(target, suffix);
}
target->Save();
c->Message(
Chat::White,
fmt::format(
"Title suffix has been {}{} for {}{}",
is_remove ? "removed" : "changed",
!is_remove && save_suffix ? " and saved" : "",
c->GetTargetDescription(target),
(
is_remove ?
"." :
fmt::format(
" to '{}'.",
suffix
)
)
).c_str()
);
}