Merge branch 'specter/kill_npcs_additional_pet_argument' into 'master'

[#1251] /kill_npcs admin command does not kill player's pets now without additional argument

See merge request veloren/veloren!2819
This commit is contained in:
Joshua Barretto 2021-09-06 18:33:33 +00:00
commit 49ceb29240

View File

@ -55,6 +55,7 @@ use vek::*;
use wiring::{Circuit, Wire, WiringAction, WiringActionEffect, WiringElement};
use world::util::Sampler;
use common::comp::Alignment;
use tracing::{error, info, warn};
pub trait ChatCommandExt {
@ -617,7 +618,6 @@ fn handle_make_npc(
// Some would say it's a hack, some would say it's incomplete
// simulation. But this is what we do to avoid PvP between npc.
use comp::Alignment;
let npc_group = match alignment {
Alignment::Enemy => Some(comp::group::ENEMY),
Alignment::Npc | Alignment::Tame => Some(comp::group::NPC),
@ -1667,22 +1667,42 @@ fn handle_kill_npcs(
server: &mut Server,
client: EcsEntity,
_target: EcsEntity,
_args: Vec<String>,
args: Vec<String>,
_action: &ChatCommand,
) -> CmdResult<()> {
let kill_pets = if let Some(kill_option) = parse_args!(args, String) {
kill_option.contains("--also-pets")
} else {
false
};
let ecs = server.state.ecs();
let mut healths = ecs.write_storage::<comp::Health>();
let players = ecs.read_storage::<comp::Player>();
let alignments = ecs.read_storage::<comp::Alignment>();
let mut count = 0;
for (mut health, ()) in (&mut healths, !&players).join() {
count += 1;
health.set_to(0, comp::HealthSource::Command);
for (mut health, (), alignment) in (&mut healths, !&players, alignments.maybe()).join() {
let should_kill = kill_pets
|| if let Some(Alignment::Owned(owned)) = alignment {
ecs.entity_from_uid(owned.0)
.map_or(true, |owner| !players.contains(owner))
} else {
true
};
if should_kill {
count += 1;
health.set_to(0, comp::HealthSource::Command);
}
}
let text = if count > 0 {
format!("Destroyed {} NPCs.", count)
} else {
"No NPCs on server.".to_string()
};
server.notify_client(
client,
ServerGeneral::server_msg(ChatType::CommandInfo, text),