[Command] Fix #killallnpcs from crashing (#2037)

This commit is contained in:
Chris Miles 2022-03-06 20:03:10 -08:00 committed by GitHub
parent 31ad0da811
commit 4e40d7eacc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,31 +8,22 @@ void command_killallnpcs(Client *c, const Seperator *sep)
} }
int killed_count = 0; int killed_count = 0;
for (auto& npc_entity : entity_list.GetNPCList()) {
auto entity_id = npc_entity.first; for (auto &e: entity_list.GetMobList()) {
if (!entity_id) { auto *entity = e.second;
if (!entity || !entity->IsNPC()) {
continue; continue;
} }
auto npc = npc_entity.second; std::string entity_name = str_tolower(entity->GetName());
if (!npc) { if ((!search_string.empty() && entity_name.find(search_string) == std::string::npos) ||
continue; !entity->IsAttackAllowed(c)) {
}
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;
} }
npc->Damage( entity->Damage(
c, c,
npc->GetHP(), entity->GetHP() + 1000,
SPELL_UNKNOWN, SPELL_UNKNOWN,
EQ::skills::SkillDragonPunch EQ::skills::SkillDragonPunch
); );
@ -49,26 +40,27 @@ void command_killallnpcs(Client *c, const Seperator *sep)
killed_count != 1 ? "s" : "", killed_count != 1 ? "s" : "",
( (
!search_string.empty() ? !search_string.empty() ?
fmt::format( fmt::format(
" that matched '{}'", " that matched '{}'",
search_string search_string
) : ) :
"" ""
) )
).c_str() ).c_str()
); );
} else { }
else {
c->Message( c->Message(
Chat::White, Chat::White,
fmt::format( fmt::format(
"There were no NPCs to kill{}.", "There were no NPCs to kill{}.",
( (
!search_string.empty() ? !search_string.empty() ?
fmt::format( fmt::format(
" that matched '{}'", " that matched '{}'",
search_string search_string
) : ) :
"" ""
) )
).c_str() ).c_str()
); );