[Commands] Cleanup #flags Command. (#1783)

- Cleanup message and logic.
This commit is contained in:
Kinglykrab 2021-11-21 10:03:08 -05:00 committed by GitHub
parent dfe43ce189
commit 7154d5b841
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 19 deletions

View File

@ -2,15 +2,16 @@
void command_flags(Client *c, const Seperator *sep) void command_flags(Client *c, const Seperator *sep)
{ {
Client *t = c; Client *target = c;
if (c->Admin() >= minStatusToSeeOthersZoneFlags) { if (
Mob *tgt = c->GetTarget(); c->GetTarget() &&
if (tgt != nullptr && tgt->IsClient()) { c->GetTarget()->IsClient() &&
t = tgt->CastToClient(); c->Admin() >= minStatusToSeeOthersZoneFlags
} ) {
target = c->GetTarget()->CastToClient();
} }
t->SendZoneFlagInfo(c); target->SendZoneFlagInfo(c);
} }

View File

@ -1043,21 +1043,31 @@ bool Client::HasZoneFlag(uint32 zone_id) const {
void Client::SendZoneFlagInfo(Client *to) const { void Client::SendZoneFlagInfo(Client *to) const {
if(zone_flags.empty()) { if(zone_flags.empty()) {
to->Message(Chat::White, "%s has no zone flags.", GetName()); to->Message(
Chat::White,
fmt::format(
"{} {} no Zone Flags.",
to == this ? "You" : GetName(),
to == this ? "have" : "has"
).c_str()
);
return; return;
} }
std::set<uint32>::const_iterator cur, end; to->Message(
cur = zone_flags.begin(); Chat::White,
end = zone_flags.end(); fmt::format(
char empty[1] = { '\0' }; "{} {} the following Flags:",
to == this ? "You" : GetName(),
to == this ? "have" : "has"
).c_str()
);
to->Message(Chat::White, "Flags for %s:", GetName()); int flag_count = 0;
for (const auto& zone_id : zone_flags) {
for(; cur != end; ++cur) { int flag_number = (flag_count + 1);
uint32 zone_id = *cur;
const char* zone_short_name = ZoneName(zone_id); const char* zone_short_name = ZoneName(zone_id);
std::string zone_long_name = zone_store.GetZoneLongName(zone_id); std::string zone_long_name = ZoneLongName(zone_id);
float safe_x, safe_y, safe_z, safe_heading; float safe_x, safe_y, safe_z, safe_heading;
int16 min_status = AccountStatus::Player; int16 min_status = AccountStatus::Player;
uint8 min_level = 0; uint8 min_level = 0;
@ -1073,11 +1083,32 @@ void Client::SendZoneFlagInfo(Client *to) const {
&min_level, &min_level,
flag_name flag_name
)) { )) {
strcpy(flag_name, "(ERROR GETTING NAME)"); strcpy(flag_name, "ERROR");
} }
to->Message(Chat::White, "Has Flag %s for zone %s (%d,%s)", flag_name, zone_long_name.c_str(), zone_id, zone_short_name); to->Message(
Chat::White,
fmt::format(
"Zone Flag {} | Zone ID: {} Zone Name: {} ({}) Flag Name: {}",
flag_number,
zone_id,
zone_long_name,
zone_short_name,
flag_name
).c_str()
);
flag_count++;
} }
to->Message(
Chat::White,
fmt::format(
"{} {} {} Zone Flags.",
to == this ? "You" : GetName(),
to == this ? "have" : "has",
flag_count
).c_str()
);
} }
bool Client::CanBeInZone() { bool Client::CanBeInZone() {