[Commands] Cleanup #killallnpcs Command. (#1797)

- Cleanup message and logic.
This commit is contained in:
Kinglykrab 2021-11-21 10:11:47 -05:00 committed by GitHub
parent 80f15ed04a
commit 446c5d90ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,42 +4,65 @@ void command_killallnpcs(Client *c, const Seperator *sep)
{ {
std::string search_string; std::string search_string;
if (sep->arg[1]) { if (sep->arg[1]) {
search_string = sep->arg[1]; search_string = str_tolower(sep->arg[1]);
} }
int count = 0; int killed_count = 0;
for (auto &itr : entity_list.GetMobList()) { for (auto& npc_entity : entity_list.GetNPCList()) {
Mob *entity = itr.second; auto entity_id = npc_entity.first;
if (!entity->IsNPC()) { auto npc = npc_entity.second;
std::string entity_name = str_tolower(npc->GetName());
if (
(
!search_string.empty() &&
entity_name.find(search_string) == std::string::npos
) ||
!npc->IsAttackAllowed(c)
) {
continue; continue;
} }
std::string entity_name = entity->GetName(); npc->Damage(
c,
npc->GetHP(),
SPELL_UNKNOWN,
EQ::skills::SkillDragonPunch
);
/** killed_count++;
* Filter by name
*/
if (search_string.length() > 0 && entity_name.find(search_string) == std::string::npos) {
continue;
}
bool is_not_attackable =
(
entity->IsInvisible() ||
!entity->IsAttackAllowed(c) ||
entity->GetRace() == 127 ||
entity->GetRace() == 240
);
if (is_not_attackable) {
continue;
}
entity->Damage(c, 1000000000, 0, EQ::skills::SkillDragonPunch);
count++;
} }
c->Message(Chat::Yellow, "Killed (%i) npc(s)", count); if (killed_count) {
c->Message(
Chat::White,
fmt::format(
"Killed {} NPC{}{}.",
killed_count,
killed_count != 1 ? "s" : "",
(
!search_string.empty() ?
fmt::format(
" that matched '{}'",
search_string
) :
""
)
).c_str()
);
} else {
c->Message(
Chat::White,
fmt::format(
"There were no NPCs to kill{}.",
(
!search_string.empty() ?
fmt::format(
" that matched '{}'",
search_string
) :
""
)
).c_str()
);
}
} }