[Commands] Cleanup #wpinfo Command. (#1866)

- Cleanup message and logic.
- Only display grid/waypoints if NPC has a grid.
This commit is contained in:
Kinglykrab 2021-12-04 21:53:29 -05:00 committed by GitHub
parent aa4536e1ef
commit 8ec4afe721
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 37 deletions

View File

@ -2,14 +2,25 @@
void command_wpinfo(Client *c, const Seperator *sep) void command_wpinfo(Client *c, const Seperator *sep)
{ {
Mob *t = c->GetTarget(); if (!c->GetTarget() || !c->GetTarget()->IsNPC()) {
c->Message(Chat::White, "You must target an NPC to use this command.");
if (t == nullptr || !t->IsNPC()) {
c->Message(Chat::White, "You must target an NPC to use this.");
return; return;
} }
NPC *n = t->CastToNPC(); auto target = c->GetTarget()->CastToNPC();
n->DisplayWaypointInfo(c);
if (!target->GetGrid()) {
c->Message(
Chat::White,
fmt::format(
"{} ({}) is not a part of any grid.",
target->GetCleanName(),
target->GetID()
).c_str()
);
return;
}
target->DisplayWaypointInfo(c);
} }

View File

@ -267,9 +267,9 @@ int Lua_NPC::GetMaxWp() {
return self->GetMaxWp(); return self->GetMaxWp();
} }
void Lua_NPC::DisplayWaypointInfo(Lua_Client to) { void Lua_NPC::DisplayWaypointInfo(Lua_Client client) {
Lua_Safe_Call_Void(); Lua_Safe_Call_Void();
self->DisplayWaypointInfo(to); self->DisplayWaypointInfo(client);
} }
void Lua_NPC::CalculateNewWaypoint() { void Lua_NPC::CalculateNewWaypoint() {

View File

@ -80,7 +80,7 @@ public:
void StartSwarmTimer(uint32 duration); void StartSwarmTimer(uint32 duration);
void DoClassAttacks(Lua_Mob target); void DoClassAttacks(Lua_Mob target);
int GetMaxWp(); int GetMaxWp();
void DisplayWaypointInfo(Lua_Client to); void DisplayWaypointInfo(Lua_Client client);
void CalculateNewWaypoint(); void CalculateNewWaypoint();
void AssignWaypoints(int grid); void AssignWaypoints(int grid);
void SetWaypointPause(); void SetWaypointPause();

View File

@ -327,7 +327,7 @@ public:
//waypoint crap //waypoint crap
int GetMaxWp() const { return max_wp; } int GetMaxWp() const { return max_wp; }
void DisplayWaypointInfo(Client *to); void DisplayWaypointInfo(Client *client);
void CalculateNewWaypoint(); void CalculateNewWaypoint();
void AssignWaypoints(int32 grid_id, int start_wp = 0); void AssignWaypoints(int32 grid_id, int start_wp = 0);
void SetWaypointPause(); void SetWaypointPause();

View File

@ -775,20 +775,23 @@ XS(XS_NPC_DisplayWaypointInfo); /* prototype to pass -Wmissing-prototypes */
XS(XS_NPC_DisplayWaypointInfo) { XS(XS_NPC_DisplayWaypointInfo) {
dXSARGS; dXSARGS;
if (items != 2) if (items != 2)
Perl_croak(aTHX_ "Usage: NPC::DisplayWaypointInfo(THIS, Client* target)"); // @categories Script Utility Perl_croak(aTHX_ "Usage: NPC::DisplayWaypointInfo(THIS, Client* client)"); // @categories Script Utility
{ {
NPC *THIS; NPC *THIS;
Client *to; Client *client;
VALIDATE_THIS_IS_NPC; VALIDATE_THIS_IS_NPC;
if (sv_derived_from(ST(1), "Client")) { if (sv_derived_from(ST(1), "Client")) {
IV tmp = SvIV((SV *) SvRV(ST(1))); IV tmp = SvIV((SV *) SvRV(ST(1)));
to = INT2PTR(Client *, tmp); client = INT2PTR(Client *, tmp);
} else } else {
Perl_croak(aTHX_ "to is not of type Client"); Perl_croak(aTHX_ "client is not of type Client");
if (to == nullptr) }
Perl_croak(aTHX_ "to is nullptr, avoiding crash.");
THIS->DisplayWaypointInfo(to); if (!client) {
Perl_croak(aTHX_ "client is nullptr, avoiding crash.");
}
THIS->DisplayWaypointInfo(client);
} }
XSRETURN_EMPTY; XSRETURN_EMPTY;
} }

View File

@ -76,26 +76,53 @@ void NPC::AI_SetRoambox(
roambox_min_delay = min_delay; roambox_min_delay = min_delay;
} }
void NPC::DisplayWaypointInfo(Client *c) { void NPC::DisplayWaypointInfo(Client *client) {
client->Message(
Chat::White,
fmt::format(
"Waypoint Info for {} ({}) | Grid: {} Waypoint: {} of {}",
GetCleanName(),
GetID(),
GetGrid(),
GetCurWp(),
GetMaxWp()
).c_str()
);
c->Message(Chat::White, "Mob is on grid %d, in spawn group %d, on waypoint %d/%d", client->Message(
GetGrid(), Chat::White,
GetSpawnGroupId(), fmt::format(
GetCurWp(), "Waypoint Info for {} ({}) | Spawn Group: {} Spawn Point: {}",
GetMaxWp()); GetCleanName(),
GetID(),
GetSpawnGroupId(),
GetSpawnPointID()
).c_str()
);
std::vector<wplist>::iterator cur, end; for (const auto& current_waypoint : Waypoints) {
cur = Waypoints.begin(); client->Message(
end = Waypoints.end(); Chat::White,
for (; cur != end; ++cur) { fmt::format(
c->Message(Chat::White, "Waypoint %d: (%.2f,%.2f,%.2f,%.2f) pause %d", "Waypoint {}{} | XYZ: {:.2f}, {:.2f}, {:.2f} Heading: {:.2f}{}",
cur->index, current_waypoint.index,
cur->x, current_waypoint.centerpoint ? " (Center)" : "",
cur->y, current_waypoint.x,
cur->z, current_waypoint.y,
cur->heading, current_waypoint.z,
cur->pause); current_waypoint.heading,
(
current_waypoint.pause ?
fmt::format(
"{} ({})",
ConvertSecondsToTime(current_waypoint.pause),
current_waypoint.pause
) :
""
)
).c_str()
);
} }
} }