[Commands] Cleanup #scale Command. (#2591)

* [Commands] Cleanup #scale Command.

- Cleanup messages and logic.

* One line message.
This commit is contained in:
Alex King 2022-12-05 00:17:56 -05:00 committed by GitHub
parent ef42e00df8
commit 0455868f66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 134 additions and 86 deletions

View File

@ -270,7 +270,7 @@ int command_init(void)
command_add("roambox", "[Remove|Set] [Box Size] [Delay (Milliseconds)] - Remove or set an NPC's roambox size and delay", AccountStatus::GMMgmt, command_roambox) || command_add("roambox", "[Remove|Set] [Box Size] [Delay (Milliseconds)] - Remove or set an NPC's roambox size and delay", AccountStatus::GMMgmt, command_roambox) ||
command_add("rules", "(subcommand) - Manage server rules", AccountStatus::GMImpossible, command_rules) || command_add("rules", "(subcommand) - Manage server rules", AccountStatus::GMImpossible, command_rules) ||
command_add("save", "Force your player or player corpse target to be saved to the database", AccountStatus::Guide, command_save) || command_add("save", "Force your player or player corpse target to be saved to the database", AccountStatus::Guide, command_save) ||
command_add("scale", "Handles npc scaling", AccountStatus::GMLeadAdmin, command_scale) || command_add("scale", "Handles NPC scaling", AccountStatus::GMLeadAdmin, command_scale) ||
command_add("scribespell", "[Spell ID] - Scribe a spell by ID to your or your target's spell book.", AccountStatus::GMCoder, command_scribespell) || command_add("scribespell", "[Spell ID] - Scribe a spell by ID to your or your target's spell book.", AccountStatus::GMCoder, command_scribespell) ||
command_add("scribespells", "[Max level] [Min level] - Scribe all spells for you or your player target that are usable by them, up to level specified. (may freeze client for a few seconds)", AccountStatus::GMLeadAdmin, command_scribespells) || command_add("scribespells", "[Max level] [Min level] - Scribe all spells for you or your player target that are usable by them, up to level specified. (may freeze client for a few seconds)", AccountStatus::GMLeadAdmin, command_scribespells) ||
command_add("sendzonespawns", "Refresh spawn list for all clients in zone", AccountStatus::GMLeadAdmin, command_sendzonespawns) || command_add("sendzonespawns", "Refresh spawn list for all clients in zone", AccountStatus::GMLeadAdmin, command_sendzonespawns) ||

View File

@ -3,134 +3,182 @@
void command_scale(Client *c, const Seperator *sep) void command_scale(Client *c, const Seperator *sep)
{ {
if (sep->argnum == 0) { auto arguments = sep->argnum;
c->Message(Chat::Yellow, "# Usage # "); if (!arguments) {
c->Message(Chat::Yellow, "#scale [static/dynamic] (With targeted NPC)"); c->Message(Chat::White, "Usage: #scale [Scale Type] - Must target an NPC");
c->Message(Chat::Yellow, "#scale [npc_name_search] [static/dynamic] (To make zone-wide changes)"); c->Message(Chat::White, "Usage: #scale [Search Criteria] [Scale Type] - Zone-wide Changes");
c->Message(Chat::Yellow, "#scale all [static/dynamic]"); c->Message(Chat::White, "Usage: #scale all [Scale Type] - Scale every NPC in the zone");
c->Message(Chat::White, "Note: Scale Type can be \"dynamic\" or \"static\".");
return; return;
} }
/** if (c->GetTarget() && c->GetTarget()->IsNPC() && arguments < 2) {
* Targeted changes auto n = c->GetTarget()->CastToNPC();
*/
if (c->GetTarget() && c->GetTarget()->IsNPC() && sep->argnum < 2) {
NPC *npc = c->GetTarget()->CastToNPC();
bool apply_status = false; bool apply_status = false;
if (strcasecmp(sep->arg[1], "dynamic") == 0) {
c->Message(Chat::Yellow, "Applying global base scaling to npc dynamically (All stats set to zeroes)..."); bool is_dynamic = !strcasecmp(sep->arg[1], "dynamic");
apply_status = npc_scale_manager->ApplyGlobalBaseScalingToNPCDynamically(npc); bool is_static = !strcasecmp(sep->arg[1], "static");
}
else if (strcasecmp(sep->arg[1], "static") == 0) { if (is_dynamic || is_static) {
c->Message(Chat::Yellow, "Applying global base scaling to npc statically (Copying base stats onto NPC)..."); c->Message(
apply_status = npc_scale_manager->ApplyGlobalBaseScalingToNPCStatically(npc); Chat::White,
} fmt::format(
else { "Applying global base scaling to {} {}ally, all stats set to zeroes.",
c->GetTargetDescription(n),
sep->arg[1]
).c_str()
);
if (is_dynamic) {
apply_status = npc_scale_manager->ApplyGlobalBaseScalingToNPCDynamically(n);
} else {
apply_status = npc_scale_manager->ApplyGlobalBaseScalingToNPCStatically(n);
}
} else {
c->Message(Chat::White, "Usage: #scale [Scale Type] - Must target an NPC");
c->Message(Chat::White, "Usage: #scale [Search Criteria] [Scale Type] - Zone-wide Changes");
c->Message(Chat::White, "Usage: #scale all [Scale Type] - Scale every NPC in the zone");
c->Message(Chat::White, "Note: Scale Type can be \"dynamic\" or \"static\".");
return; return;
} }
if (apply_status) { if (apply_status) {
c->Message(Chat::Yellow, "Applied to NPC '%s' successfully!", npc->GetName());
}
else {
c->Message( c->Message(
Chat::Yellow, "Failed to load scaling data from the database " Chat::White,
"for this npc / type, see 'NPCScaling' log for more info" fmt::format(
"Applied global base scaling to {} {}ally successfully.",
c->GetTargetDescription(n),
sep->arg[1]
).c_str()
);
} else {
c->Message(
Chat::White,
fmt::format(
"Failed to load scaling data from the database for {}, see 'NPCScaling' log for more info.",
c->GetTargetDescription(n)
).c_str()
); );
} }
} } else if (c->GetTarget() && arguments < 2) {
else if (c->GetTarget() && sep->argnum < 2) { c->Message(Chat::White, "You must target an NPC to use targeted scaling!");
c->Message(Chat::Yellow, "Target must be an npc!");
} }
/** if (arguments > 1) {
* Zonewide
*/
if (sep->argnum > 1) {
std::string scale_type; std::string scale_type;
if (strcasecmp(sep->arg[2], "dynamic") == 0) {
scale_type = "dynamic";
}
else if (strcasecmp(sep->arg[2], "static") == 0) {
scale_type = "static";
}
if (scale_type.length() <= 0) { bool is_all = !strcasecmp(sep->arg[1], "all");
c->Message( bool is_dynamic = !strcasecmp(sep->arg[2], "dynamic");
Chat::Yellow, bool is_static = !strcasecmp(sep->arg[2], "static");
"You must first set if you intend on using static versus dynamic for these changes"
); bool is_apply = arguments == 3 && !strcasecmp(sep->arg[3], "apply");
c->Message(Chat::Yellow, "#scale [npc_name_search] [static/dynamic]");
c->Message(Chat::Yellow, "#scale all [static/dynamic]"); if (is_dynamic) {
scale_type = "dynamic";
} else if (is_static) {
scale_type = "static";
} else {
c->Message(Chat::White, "Usage: #scale [Scale Type] - Must target an NPC");
c->Message(Chat::White, "Usage: #scale [Search Criteria] [Scale Type] - Zone-wide Changes");
c->Message(Chat::White, "Usage: #scale all [Scale Type] - Scale every NPC in the zone");
c->Message(Chat::White, "Note: Scale Type can be \"dynamic\" or \"static\".");
return; return;
} }
std::string search_string = sep->arg[1]; const std::string search_string = sep->arg[1];
auto &entity_list_search = entity_list.GetNPCList(); const auto& l = entity_list.GetNPCList();
int found_count = 0; auto found_count = 0;
for (auto &itr : entity_list_search) { auto found_number = 1;
NPC *entity = itr.second;
std::string entity_name = entity->GetName(); for (const auto &e : l) {
auto n = e.second;
/** std::string entity_name = n->GetName();
* Filter by name
*/ if (
if (search_string.length() > 0 && entity_name.find(search_string) == std::string::npos && !search_string.empty() &&
strcasecmp(sep->arg[1], "all") != 0) { !Strings::Contains(entity_name, search_string) &&
!is_all
) {
continue; continue;
} }
std::string status = "(Searching)"; std::string status = "(Searching)";
if (strcasecmp(sep->arg[3], "apply") == 0) { if (is_apply) {
status = "(Applying)"; status = "(Applying)";
if (strcasecmp(sep->arg[2], "dynamic") == 0) { if (is_dynamic) {
npc_scale_manager->ApplyGlobalBaseScalingToNPCDynamically(entity); npc_scale_manager->ApplyGlobalBaseScalingToNPCDynamically(n);
} } else if (is_static) {
if (strcasecmp(sep->arg[2], "static") == 0) { npc_scale_manager->ApplyGlobalBaseScalingToNPCStatically(n);
npc_scale_manager->ApplyGlobalBaseScalingToNPCStatically(entity);
} }
} }
c->Message( c->Message(
15, Chat::White,
"| ID %5d | %s | x %.0f | y %0.f | z %.0f | DBID %u %s", fmt::format(
entity->GetID(), "Entity {} | Name: {} | NPC ID: {} | Position: {:.2f}, {:.2f}, {:.2f}, {:.2f} {}",
entity->GetName(), found_number,
entity->GetX(), c->GetTargetDescription(n),
entity->GetY(), n->GetNPCTypeID(),
entity->GetZ(), n->GetX(),
entity->GetNPCTypeID(), n->GetY(),
status.c_str() n->GetZ(),
n->GetHeading(),
status
).c_str()
); );
found_count++; found_count++;
found_number++;
} }
if (strcasecmp(sep->arg[3], "apply") == 0) { if (is_apply) {
c->Message(Chat::Yellow, "%s scaling applied against (%i) NPC's", sep->arg[2], found_count); c->Message(
} Chat::White,
else { fmt::format(
"{} scaling applied against {} NPC{}.",
std::string saylink = StringFormat( Strings::UcFirst(sep->arg[2]),
"#scale %s %s apply", found_count,
sep->arg[1], found_count != 1 ? "s" : ""
sep->arg[2] ).c_str()
);
} else {
c->Message(
Chat::White,
fmt::format(
"Found {} NPC{}{}.",
found_count,
found_count != 1 ? "s" : "",
(
is_all ?
"" :
fmt::format(
" matching '{}'",
search_string
)
)
).c_str()
); );
c->Message(Chat::Yellow, "Found (%i) NPC's that match this search...", found_count);
c->Message( c->Message(
Chat::Yellow, "To apply these changes, click <%s> or type %s", Chat::White,
Saylink::Silent(saylink, "Apply").c_str(), fmt::format(
saylink.c_str() "Would you like to {} these changes?",
Saylink::Silent(
fmt::format(
"#scale {} {} apply",
sep->arg[1],
sep->arg[2]
),
"apply"
)
).c_str()
); );
} }
} }
} }