[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;
continue; std::string entity_name = str_tolower(npc->GetName());
} if (
std::string entity_name = entity->GetName();
/**
* Filter by name
*/
if (search_string.length() > 0 && entity_name.find(search_string) == std::string::npos) {
continue;
}
bool is_not_attackable =
( (
entity->IsInvisible() || !search_string.empty() &&
!entity->IsAttackAllowed(c) || entity_name.find(search_string) == std::string::npos
entity->GetRace() == 127 || ) ||
entity->GetRace() == 240 !npc->IsAttackAllowed(c)
) {
continue;
}
npc->Damage(
c,
npc->GetHP(),
SPELL_UNKNOWN,
EQ::skills::SkillDragonPunch
); );
if (is_not_attackable) { killed_count++;
continue;
} }
entity->Damage(c, 1000000000, 0, EQ::skills::SkillDragonPunch); if (killed_count) {
c->Message(
count++; 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()
);
} }
c->Message(Chat::Yellow, "Killed (%i) npc(s)", count);
} }