[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("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("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("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) ||

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);
}