diff --git a/common/src/cmd.rs b/common/src/cmd.rs index 644eaf3e4e..94e025e300 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -695,8 +695,9 @@ impl ServerChatCommand { Some(Moderator), ), ServerChatCommand::RtsimNpc => cmd( - vec![Any("query", Required)], - "List rtsim NPCs that fit a given query (e.g: simulated,merchant)", + vec![Any("query", Required), Integer("max number", 20, Optional)], + "List rtsim NPCs that fit a given query (e.g: simulated,merchant) in order of \ + distance", Some(Moderator), ), ServerChatCommand::RtsimPurge => cmd( diff --git a/common/systems/tests/character_state.rs b/common/systems/tests/character_state.rs index 8f1dcbf58f..fbfe672b00 100644 --- a/common/systems/tests/character_state.rs +++ b/common/systems/tests/character_state.rs @@ -2,8 +2,8 @@ mod tests { use common::{ comp::{ - item::MaterialStatManifest, skills::GeneralSkill, tool::AbilityMap, CharacterState, - Controller, Energy, Ori, PhysicsState, Poise, Pos, Skill, Stats, Vel, + item::MaterialStatManifest, skills::GeneralSkill, tool::AbilityMap, CharacterActivity, + CharacterState, Controller, Energy, Ori, PhysicsState, Poise, Pos, Skill, Stats, Vel, }, resources::{DeltaTime, GameMode, Time}, shared_server_config::ServerConstants, @@ -53,6 +53,7 @@ mod tests { .ecs_mut() .create_entity() .with(CharacterState::Idle(common::states::idle::Data::default())) + .with(CharacterActivity::default()) .with(Pos(Vec3::zero())) .with(Vel::default()) .with(ori) @@ -116,8 +117,12 @@ mod tests { for i in 0..TESTCASES { if let Some(e) = entities[i] { let result = Dir::from(*results.get(e).expect("Ori missing")); - assert!(result.abs_diff_eq(&testcases[i].1, 0.0005)); - // println!("{:?}", result); + assert!( + result.abs_diff_eq(&testcases[i].1, 0.0005), + "{:?} != {:?}", + result, + testcases[i].1 + ); } } } diff --git a/common/systems/tests/phys/basic.rs b/common/systems/tests/phys/basic.rs index dbeab553ea..1c21dce260 100644 --- a/common/systems/tests/phys/basic.rs +++ b/common/systems/tests/phys/basic.rs @@ -128,11 +128,11 @@ fn fall_dt_speed_diff() -> Result<(), Box> { assert_relative_eq!(svel.0.z, -4.9847627, epsilon = EPSILON); assert_relative_eq!(fpos.0.x, 16.0); assert_relative_eq!(fpos.0.y, 16.0); - assert_relative_eq!(fpos.0.z, 264.25073, epsilon = EPSILON); + assert_relative_eq!(fpos.0.z, 264.25067, epsilon = EPSILON); assert_relative_eq!(fvel.0.z, -4.9930925, epsilon = EPSILON); // Diff after 200ms - assert_relative_eq!((spos.0.z - fpos.0.z).abs(), 0.2253418, epsilon = EPSILON); + assert_relative_eq!((spos.0.z - fpos.0.z).abs(), 0.22540283, epsilon = EPSILON); assert_relative_eq!((svel.0.z - fvel.0.z).abs(), 0.008329868, epsilon = EPSILON); Ok(()) diff --git a/common/systems/tests/phys/utils.rs b/common/systems/tests/phys/utils.rs index 0fd4f08515..b8b4c0fb33 100644 --- a/common/systems/tests/phys/utils.rs +++ b/common/systems/tests/phys/utils.rs @@ -3,8 +3,8 @@ use common::{ inventory::item::MaterialStatManifest, skills::{GeneralSkill, Skill}, tool::AbilityMap, - Auras, Buffs, CharacterState, Collider, Combo, Controller, Energy, Health, Ori, Pos, Stats, - Vel, + Auras, Buffs, CharacterActivity, CharacterState, Collider, Combo, Controller, Energy, + Health, Ori, Pos, Stats, Vel, }, resources::{DeltaTime, GameMode, Time}, shared_server_config::ServerConstants, @@ -123,6 +123,7 @@ pub fn create_player(state: &mut State) -> Entity { .with(body) .with(Controller::default()) .with(CharacterState::default()) + .with(CharacterActivity::default()) .with(Buffs::default()) .with(Combo::default()) .with(Auras::default()) diff --git a/rtsim/src/data/npc.rs b/rtsim/src/data/npc.rs index 98c31d0839..fbefd49a47 100644 --- a/rtsim/src/data/npc.rs +++ b/rtsim/src/data/npc.rs @@ -226,6 +226,7 @@ impl Npc { // Clear reports that have been forgotten self.known_reports .retain(|report| reports.contains_key(*report)); + // TODO: Limit number of reports // TODO: Clear old inbox items } } diff --git a/rtsim/src/data/report.rs b/rtsim/src/data/report.rs index ce1f0a2824..127c0c6653 100644 --- a/rtsim/src/data/report.rs +++ b/rtsim/src/data/report.rs @@ -58,6 +58,7 @@ impl Reports { // Forget reports that are too old self.reports .retain(|_, report| (current_time.0 - report.at.0).max(0.0) < report.remember_for()); + // TODO: Limit global number of reports } } diff --git a/rtsim/src/data/site.rs b/rtsim/src/data/site.rs index 44d55eb9b4..9f02d41a92 100644 --- a/rtsim/src/data/site.rs +++ b/rtsim/src/data/site.rs @@ -51,6 +51,7 @@ impl Site { // Clear reports that have been forgotten self.known_reports .retain(|report| reports.contains_key(*report)); + // TODO: Limit number of reports } } diff --git a/server/src/cmd.rs b/server/src/cmd.rs index a44944a88b..04616f7966 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1268,12 +1268,12 @@ fn handle_rtsim_info( fn handle_rtsim_npc( server: &mut Server, client: EcsEntity, - _target: EcsEntity, + target: EcsEntity, args: Vec, action: &ServerChatCommand, ) -> CmdResult<()> { use crate::rtsim::RtSim; - if let Some(query) = parse_cmd_args!(args, String) { + if let (Some(query), count) = parse_cmd_args!(args, String, u32) { let terms = query .split(',') .map(|s| s.trim().to_lowercase()) @@ -1281,7 +1281,7 @@ fn handle_rtsim_npc( let rtsim = server.state.ecs().read_resource::(); let data = rtsim.state().data(); - let npcs = data + let mut npcs = data .npcs .values() .enumerate() @@ -1294,20 +1294,28 @@ fn handle_rtsim_npc( format!("{:?}", npc.mode), format!("{}", idx), ]; - terms - .iter() - .all(|term| tags.iter().any(|tag| term.eq_ignore_ascii_case(tag.trim()))) + terms.iter().all(|term| { + term == "" || tags.iter().any(|tag| term.eq_ignore_ascii_case(tag.trim())) + }) }) .collect::>(); + if let Ok(pos) = position(server, target, "target") { + npcs.sort_by_key(|(_, npc)| (npc.wpos.distance_squared(pos.0) * 10.0) as u64); + } let mut info = String::new(); let _ = writeln!(&mut info, "-- NPCs matching [{}] --", terms.join(", ")); - for (idx, _) in &npcs { + for (idx, _) in npcs.iter().take(count.unwrap_or(!0) as usize) { let _ = write!(&mut info, "{}, ", idx); } let _ = writeln!(&mut info); - let _ = writeln!(&mut info, "Matched {} NPCs.", npcs.len()); + let _ = writeln!( + &mut info, + "Showing {}/{} matching NPCs.", + count.unwrap_or(npcs.len() as u32), + npcs.len() + ); server.notify_client( client,