[Commands] Cleanup #push Command. (#2114)

- Cleanup messages and logic.
This commit is contained in:
Kinglykrab 2022-05-06 20:38:15 -04:00 committed by GitHub
parent 78d44440eb
commit 6bbd1e94c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 21 deletions

View File

@ -278,7 +278,7 @@ int command_init(void)
command_add("pf", "- Display additional mob coordinate and wandering data", AccountStatus::Player, command_pf) || command_add("pf", "- Display additional mob coordinate and wandering data", AccountStatus::Player, command_pf) ||
command_add("picklock", "Analog for ldon pick lock for the newer clients since we still don't have it working.", AccountStatus::Player, command_picklock) || command_add("picklock", "Analog for ldon pick lock for the newer clients since we still don't have it working.", AccountStatus::Player, command_picklock) ||
command_add("profanity", "Manage censored language.", AccountStatus::GMLeadAdmin, command_profanity) || command_add("profanity", "Manage censored language.", AccountStatus::GMLeadAdmin, command_profanity) ||
command_add("push", "Lets you do spell push", AccountStatus::GMLeadAdmin, command_push) || command_add("push", "[Back Push] [Up Push] - Lets you do spell push on an NPC", AccountStatus::GMLeadAdmin, command_push) ||
command_add("proximity", "Shows NPC proximity", AccountStatus::GMLeadAdmin, command_proximity) || command_add("proximity", "Shows NPC proximity", AccountStatus::GMLeadAdmin, command_proximity) ||
command_add("pvp", "[On|Off] - Set you or your player target's PVP status", AccountStatus::GMAdmin, command_pvp) || command_add("pvp", "[On|Off] - Set you or your player target's PVP status", AccountStatus::GMAdmin, command_pvp) ||
command_add("qglobal", "[On|Off|View] - Toggles quest global functionality for your NPC target", AccountStatus::GMAdmin, command_qglobal) || command_add("qglobal", "[On|Off|View] - Toggles quest global functionality for your NPC target", AccountStatus::GMAdmin, command_qglobal) ||

View File

@ -5,31 +5,39 @@ extern FastMath g_Math;
void command_push(Client *c, const Seperator *sep) void command_push(Client *c, const Seperator *sep)
{ {
Mob *t = c; int arguments = sep->argnum;
if (c->GetTarget() != nullptr) { if (!arguments || !sep->IsNumber(1)) {
t = c->GetTarget(); c->Message(Chat::White, "Usage: #push [Back Push] [Up Push]");
}
if (!sep->arg[1] || !sep->IsNumber(1)) {
c->Message(Chat::White, "ERROR: Must provide at least a push back.");
return; return;
} }
float back = atof(sep->arg[1]); if (!c->GetTarget() || !c->GetTarget()->IsNPC()) {
float up = 0.0f; c->Message(Chat::White, "You must target an NPC to use this command.");
return;
if (sep->arg[2] && sep->IsNumber(2)) {
up = atof(sep->arg[2]);
} }
if (t->IsNPC()) { auto target = c->GetTarget();
t->IncDeltaX(back * g_Math.FastSin(c->GetHeading())); auto back = std::stof(sep->arg[1]);
t->IncDeltaY(back * g_Math.FastCos(c->GetHeading())); auto up = 0.0f;
t->IncDeltaZ(up);
t->SetForcedMovement(6); if (arguments == 2 && sep->IsNumber(2)) {
} up = std::stof(sep->arg[2]);
else if (t->IsClient()) {
// TODO: send packet to push
} }
c->Message(
Chat::White,
fmt::format(
"Pushing {} ({}) with a push back of {:.2f} and a push up of {:.2f}.",
target->GetCleanName(),
target->GetID(),
back,
up
).c_str()
);
target->IncDeltaX(back * g_Math.FastSin(c->GetHeading()));
target->IncDeltaY(back * g_Math.FastCos(c->GetHeading()));
target->IncDeltaZ(up);
target->SetForcedMovement(6);
} }