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