fix spawn command placement to be random to improve AI responsivity and not spawn directly on player

This commit is contained in:
Jessie Mancer 2019-07-21 18:22:13 +00:00 committed by Joshua Barretto
parent cac780c5b9
commit 4893ab5c2a
3 changed files with 12 additions and 3 deletions

1
Cargo.lock generated
View File

@ -2766,6 +2766,7 @@ version = "0.2.0"
dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
"ron 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"scan_fmt 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -16,4 +16,5 @@ lazy_static = "1.3.0"
scan_fmt = "0.1.3"
ron = "0.5.1"
serde = "1.0"
serde_derive = "1.0"
serde_derive = "1.0"
rand = "0.5.6"

View File

@ -9,6 +9,7 @@ use common::{
npc::{get_npc_name, NpcKind},
state::TimeOfDay,
};
use rand::Rng;
use specs::{Builder, Entity as EcsEntity, Join};
use vek::*;
@ -314,12 +315,18 @@ fn handle_spawn(server: &mut Server, entity: EcsEntity, args: String, action: &C
match (opt_agent, opt_id, opt_amount) {
(Some(agent), Some(id), Some(amount)) => {
match server.state.read_component_cloned::<comp::Pos>(entity) {
Some(mut pos) => {
pos.0.x += 1.0; // Temp fix TODO: Solve NaN issue with positions of pets
Some(pos) => {
for _ in 0..amount {
let vel = Vec3::new(
rand::thread_rng().gen_range(-2.0, 3.0),
rand::thread_rng().gen_range(-2.0, 3.0),
10.0,
);
let body = kind_to_body(id);
server
.create_npc(pos, get_npc_name(id), body)
.with(comp::Vel(vel))
.with(agent)
.build();
}