[Commands] Cleanup #save Command. (#2136)

- Cleanup messages and logic.
This commit is contained in:
Kinglykrab 2022-05-06 19:50:19 -04:00 committed by GitHub
parent e2bfa44df0
commit bf7c1252f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,31 +3,38 @@
void command_save(Client *c, const Seperator *sep) void command_save(Client *c, const Seperator *sep)
{ {
if (c->GetTarget() == 0) { if (
c->Message(Chat::White, "Error: no target"); !c->GetTarget() ||
(
c->GetTarget() &&
!c->GetTarget()->IsClient() &&
!c->GetTarget()->IsPlayerCorpse()
)
) {
c->Message(Chat::White, "You must target a player or player corpse to use this command.");
return;
} }
else if (c->GetTarget()->IsClient()) {
if (c->GetTarget()->CastToClient()->Save(2)) { if (c->GetTarget()->IsClient()) {
c->Message(Chat::White, "%s successfully saved.", c->GetTarget()->GetName());
}
else {
c->Message(Chat::White, "Manual save for %s failed.", c->GetTarget()->GetName());
}
}
else if (c->GetTarget()->IsPlayerCorpse()) {
if (c->GetTarget()->CastToMob()->Save()) {
c->Message( c->Message(
Chat::White, Chat::White,
"%s successfully saved. (dbid=%u)", fmt::format(
c->GetTarget()->GetName(), "{} ({}) {} saved.",
c->GetTarget()->CastToCorpse()->GetCorpseDBID()); c->GetTarget()->GetCleanName(),
} c->GetTarget()->GetID(),
else { c->GetTarget()->CastToClient()->Save(2) ? "successfully" : "failed to be"
c->Message(Chat::White, "Manual save for %s failed.", c->GetTarget()->GetName()); ).c_str()
} );
} } else if (c->GetTarget()->IsPlayerCorpse()) {
else { c->Message(
c->Message(Chat::White, "Error: target not a Client/PlayerCorpse"); Chat::White,
fmt::format(
"{} ({}) {} saved.",
c->GetTarget()->GetCleanName(),
c->GetTarget()->CastToCorpse()->GetCorpseDBID(),
c->GetTarget()->CastToMob()->Save() ? "successfully" : "failed to be"
).c_str()
);
} }
} }