mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Made /rtsim_npc order NPCs by distance
This commit is contained in:
parent
70538dae66
commit
326aa3f8ff
@ -695,8 +695,9 @@ impl ServerChatCommand {
|
|||||||
Some(Moderator),
|
Some(Moderator),
|
||||||
),
|
),
|
||||||
ServerChatCommand::RtsimNpc => cmd(
|
ServerChatCommand::RtsimNpc => cmd(
|
||||||
vec![Any("query", Required)],
|
vec![Any("query", Required), Integer("max number", 20, Optional)],
|
||||||
"List rtsim NPCs that fit a given query (e.g: simulated,merchant)",
|
"List rtsim NPCs that fit a given query (e.g: simulated,merchant) in order of \
|
||||||
|
distance",
|
||||||
Some(Moderator),
|
Some(Moderator),
|
||||||
),
|
),
|
||||||
ServerChatCommand::RtsimPurge => cmd(
|
ServerChatCommand::RtsimPurge => cmd(
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
mod tests {
|
mod tests {
|
||||||
use common::{
|
use common::{
|
||||||
comp::{
|
comp::{
|
||||||
item::MaterialStatManifest, skills::GeneralSkill, tool::AbilityMap, CharacterState,
|
item::MaterialStatManifest, skills::GeneralSkill, tool::AbilityMap, CharacterActivity,
|
||||||
Controller, Energy, Ori, PhysicsState, Poise, Pos, Skill, Stats, Vel,
|
CharacterState, Controller, Energy, Ori, PhysicsState, Poise, Pos, Skill, Stats, Vel,
|
||||||
},
|
},
|
||||||
resources::{DeltaTime, GameMode, Time},
|
resources::{DeltaTime, GameMode, Time},
|
||||||
shared_server_config::ServerConstants,
|
shared_server_config::ServerConstants,
|
||||||
@ -53,6 +53,7 @@ mod tests {
|
|||||||
.ecs_mut()
|
.ecs_mut()
|
||||||
.create_entity()
|
.create_entity()
|
||||||
.with(CharacterState::Idle(common::states::idle::Data::default()))
|
.with(CharacterState::Idle(common::states::idle::Data::default()))
|
||||||
|
.with(CharacterActivity::default())
|
||||||
.with(Pos(Vec3::zero()))
|
.with(Pos(Vec3::zero()))
|
||||||
.with(Vel::default())
|
.with(Vel::default())
|
||||||
.with(ori)
|
.with(ori)
|
||||||
@ -116,8 +117,12 @@ mod tests {
|
|||||||
for i in 0..TESTCASES {
|
for i in 0..TESTCASES {
|
||||||
if let Some(e) = entities[i] {
|
if let Some(e) = entities[i] {
|
||||||
let result = Dir::from(*results.get(e).expect("Ori missing"));
|
let result = Dir::from(*results.get(e).expect("Ori missing"));
|
||||||
assert!(result.abs_diff_eq(&testcases[i].1, 0.0005));
|
assert!(
|
||||||
// println!("{:?}", result);
|
result.abs_diff_eq(&testcases[i].1, 0.0005),
|
||||||
|
"{:?} != {:?}",
|
||||||
|
result,
|
||||||
|
testcases[i].1
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,11 +128,11 @@ fn fall_dt_speed_diff() -> Result<(), Box<dyn Error>> {
|
|||||||
assert_relative_eq!(svel.0.z, -4.9847627, epsilon = EPSILON);
|
assert_relative_eq!(svel.0.z, -4.9847627, epsilon = EPSILON);
|
||||||
assert_relative_eq!(fpos.0.x, 16.0);
|
assert_relative_eq!(fpos.0.x, 16.0);
|
||||||
assert_relative_eq!(fpos.0.y, 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);
|
assert_relative_eq!(fvel.0.z, -4.9930925, epsilon = EPSILON);
|
||||||
|
|
||||||
// Diff after 200ms
|
// 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);
|
assert_relative_eq!((svel.0.z - fvel.0.z).abs(), 0.008329868, epsilon = EPSILON);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -3,8 +3,8 @@ use common::{
|
|||||||
inventory::item::MaterialStatManifest,
|
inventory::item::MaterialStatManifest,
|
||||||
skills::{GeneralSkill, Skill},
|
skills::{GeneralSkill, Skill},
|
||||||
tool::AbilityMap,
|
tool::AbilityMap,
|
||||||
Auras, Buffs, CharacterState, Collider, Combo, Controller, Energy, Health, Ori, Pos, Stats,
|
Auras, Buffs, CharacterActivity, CharacterState, Collider, Combo, Controller, Energy,
|
||||||
Vel,
|
Health, Ori, Pos, Stats, Vel,
|
||||||
},
|
},
|
||||||
resources::{DeltaTime, GameMode, Time},
|
resources::{DeltaTime, GameMode, Time},
|
||||||
shared_server_config::ServerConstants,
|
shared_server_config::ServerConstants,
|
||||||
@ -123,6 +123,7 @@ pub fn create_player(state: &mut State) -> Entity {
|
|||||||
.with(body)
|
.with(body)
|
||||||
.with(Controller::default())
|
.with(Controller::default())
|
||||||
.with(CharacterState::default())
|
.with(CharacterState::default())
|
||||||
|
.with(CharacterActivity::default())
|
||||||
.with(Buffs::default())
|
.with(Buffs::default())
|
||||||
.with(Combo::default())
|
.with(Combo::default())
|
||||||
.with(Auras::default())
|
.with(Auras::default())
|
||||||
|
@ -226,6 +226,7 @@ impl Npc {
|
|||||||
// Clear reports that have been forgotten
|
// Clear reports that have been forgotten
|
||||||
self.known_reports
|
self.known_reports
|
||||||
.retain(|report| reports.contains_key(*report));
|
.retain(|report| reports.contains_key(*report));
|
||||||
|
// TODO: Limit number of reports
|
||||||
// TODO: Clear old inbox items
|
// TODO: Clear old inbox items
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,7 @@ impl Reports {
|
|||||||
// Forget reports that are too old
|
// Forget reports that are too old
|
||||||
self.reports
|
self.reports
|
||||||
.retain(|_, report| (current_time.0 - report.at.0).max(0.0) < report.remember_for());
|
.retain(|_, report| (current_time.0 - report.at.0).max(0.0) < report.remember_for());
|
||||||
|
// TODO: Limit global number of reports
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ impl Site {
|
|||||||
// Clear reports that have been forgotten
|
// Clear reports that have been forgotten
|
||||||
self.known_reports
|
self.known_reports
|
||||||
.retain(|report| reports.contains_key(*report));
|
.retain(|report| reports.contains_key(*report));
|
||||||
|
// TODO: Limit number of reports
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1268,12 +1268,12 @@ fn handle_rtsim_info(
|
|||||||
fn handle_rtsim_npc(
|
fn handle_rtsim_npc(
|
||||||
server: &mut Server,
|
server: &mut Server,
|
||||||
client: EcsEntity,
|
client: EcsEntity,
|
||||||
_target: EcsEntity,
|
target: EcsEntity,
|
||||||
args: Vec<String>,
|
args: Vec<String>,
|
||||||
action: &ServerChatCommand,
|
action: &ServerChatCommand,
|
||||||
) -> CmdResult<()> {
|
) -> CmdResult<()> {
|
||||||
use crate::rtsim::RtSim;
|
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
|
let terms = query
|
||||||
.split(',')
|
.split(',')
|
||||||
.map(|s| s.trim().to_lowercase())
|
.map(|s| s.trim().to_lowercase())
|
||||||
@ -1281,7 +1281,7 @@ fn handle_rtsim_npc(
|
|||||||
|
|
||||||
let rtsim = server.state.ecs().read_resource::<RtSim>();
|
let rtsim = server.state.ecs().read_resource::<RtSim>();
|
||||||
let data = rtsim.state().data();
|
let data = rtsim.state().data();
|
||||||
let npcs = data
|
let mut npcs = data
|
||||||
.npcs
|
.npcs
|
||||||
.values()
|
.values()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
@ -1294,20 +1294,28 @@ fn handle_rtsim_npc(
|
|||||||
format!("{:?}", npc.mode),
|
format!("{:?}", npc.mode),
|
||||||
format!("{}", idx),
|
format!("{}", idx),
|
||||||
];
|
];
|
||||||
terms
|
terms.iter().all(|term| {
|
||||||
.iter()
|
term == "" || tags.iter().any(|tag| term.eq_ignore_ascii_case(tag.trim()))
|
||||||
.all(|term| tags.iter().any(|tag| term.eq_ignore_ascii_case(tag.trim())))
|
})
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
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 mut info = String::new();
|
||||||
|
|
||||||
let _ = writeln!(&mut info, "-- NPCs matching [{}] --", terms.join(", "));
|
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 _ = write!(&mut info, "{}, ", idx);
|
||||||
}
|
}
|
||||||
let _ = writeln!(&mut info);
|
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(
|
server.notify_client(
|
||||||
client,
|
client,
|
||||||
|
Loading…
Reference in New Issue
Block a user