[Commands] Cleanup #spawnfix Command. (#2143)

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

View File

@ -2,38 +2,67 @@
void command_spawnfix(Client* c, const Seperator* sep) void command_spawnfix(Client* c, const Seperator* sep)
{ {
Mob *target_mob = c->GetTarget(); if (!c->GetTarget() || !c->GetTarget()->IsNPC()) {
if (!target_mob || !target_mob->IsNPC()) { c->Message(Chat::White, "You must target an NPC to use this command.");
c->Message(Chat::White, "Error: #spawnfix: Need an NPC target.");
return; return;
} }
Spawn2 *s2 = target_mob->CastToNPC()->respawn2; auto target = c->GetTarget()->CastToNPC();
auto spawn2 = target->respawn2;
if (!s2) { if (!spawn2) {
c->Message( c->Message(Chat::White, "Failed to fix spawn, the spawn must not exist in the database.");
Chat::White,
"#spawnfix FAILED -- cannot determine which spawn entry in the database this mob came from."
);
return; return;
} }
std::string query = StringFormat( auto client_x = c->GetX();
"UPDATE spawn2 SET x = '%f', y = '%f', z = '%f', heading = '%f' WHERE id = '%i'", auto client_y = c->GetY();
c->GetX(), auto client_z = target->GetFixedZ(c->GetPosition());
c->GetY(), auto client_heading = c->GetHeading();
target_mob->GetFixedZ(c->GetPosition()),
c->GetHeading(), auto query = fmt::format(
s2->GetID() "UPDATE spawn2 SET x = {:.2f}, y = {:.2f}, z = {:.2f}, heading = {:.2f} WHERE id = {}",
client_x,
client_y,
client_z,
client_heading,
spawn2->GetID()
); );
auto results = content_db.QueryDatabase(query); auto results = content_db.QueryDatabase(query);
if (!results.Success()) {
c->Message(Chat::Red, "Update failed! MySQL gave the following error:"); if (!results.Success() || !results.RowsAffected()) {
c->Message(Chat::Red, results.ErrorMessage().c_str()); c->Message(Chat::White, "Failed to fix spawn.");
return; return;
} }
c->Message(Chat::White, "Updating coordinates successful."); c->Message(
target_mob->Depop(false); Chat::White,
fmt::format(
"Updated Spawn | NPC: {}",
target->GetCleanName()
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"Updated Spawn | NPC ID: {} Spawn2 ID: {}",
target->GetNPCTypeID(),
spawn2->GetID()
).c_str()
);
c->Message(
Chat::White,
fmt::format(
"Updated Spawn | Coordinates: {:.2f}, {:.2f}, {:.2f}, {:.2f}",
client_x,
client_y,
client_z,
client_heading
).c_str()
);
target->Depop(false);
} }