From 7cfa67ad49d22354dcf602ca28f4520f356681f2 Mon Sep 17 00:00:00 2001 From: holychowders Date: Sat, 15 May 2021 14:36:05 -0700 Subject: [PATCH] Guards now respond to villagers calling for help --- common/src/comp/agent.rs | 12 +- common/systems/src/beam.rs | 2 +- common/systems/src/controller.rs | 1 + common/systems/src/melee.rs | 8 +- common/systems/src/projectile.rs | 8 +- common/systems/src/shockwave.rs | 2 +- server/src/events/entity_manipulation.rs | 16 +- server/src/sys/agent.rs | 265 ++++++++++++----------- 8 files changed, 181 insertions(+), 133 deletions(-) diff --git a/common/src/comp/agent.rs b/common/src/comp/agent.rs index 07f23ab54a..f7fe32e86d 100644 --- a/common/src/comp/agent.rs +++ b/common/src/comp/agent.rs @@ -272,15 +272,23 @@ pub struct Sound { pub pos: Vec3, pub vol: f32, pub time: f64, + pub owner: Option, } impl Sound { - pub fn new(kind: SoundKind, pos: Vec3, vol: f32, time: f64) -> Self { + pub fn new( + kind: SoundKind, + pos: Vec3, + vol: f32, + time: f64, + owner: Option, + ) -> Self { Sound { kind, pos, vol, time, + owner, } } @@ -301,6 +309,8 @@ pub enum SoundKind { Beam, Shockwave, Utterance(UtteranceKind, Body), + // TODO: unify VillagerAlarm with Utterance + VillagerAlarm, } #[derive(Clone, Debug)] diff --git a/common/systems/src/beam.rs b/common/systems/src/beam.rs index c3373a3533..8bf62b323d 100644 --- a/common/systems/src/beam.rs +++ b/common/systems/src/beam.rs @@ -94,7 +94,7 @@ impl<'a> System<'a> for Sys { let mut rng = thread_rng(); if rng.gen_bool(0.005) { server_events.push(ServerEvent::Sound { - sound: Sound::new(SoundKind::Beam, pos.0, 7.0, time), + sound: Sound::new(SoundKind::Beam, pos.0, 7.0, time, Some(entity)), }); } diff --git a/common/systems/src/controller.rs b/common/systems/src/controller.rs index 7cc1e67e23..f157cc6c25 100644 --- a/common/systems/src/controller.rs +++ b/common/systems/src/controller.rs @@ -99,6 +99,7 @@ impl<'a> System<'a> for Sys { pos.0 + Vec3::unit_z() * body.eye_height(), 8.0, // TODO: Come up with a better way of determining this 1.0, + Some(entity), ); server_emitter.emit(ServerEvent::Sound { sound }); } diff --git a/common/systems/src/melee.rs b/common/systems/src/melee.rs index 20ac8b54a9..6f23eeabbc 100644 --- a/common/systems/src/melee.rs +++ b/common/systems/src/melee.rs @@ -70,7 +70,13 @@ impl<'a> System<'a> for Sys { continue; } server_emitter.emit(ServerEvent::Sound { - sound: Sound::new(SoundKind::Melee, pos.0, 3.0, read_data.time.0), + sound: Sound::new( + SoundKind::Melee, + pos.0, + 3.0, + read_data.time.0, + Some(attacker), + ), }); melee_attack.applied = true; diff --git a/common/systems/src/projectile.rs b/common/systems/src/projectile.rs index a1bab8cd96..d8430763b9 100644 --- a/common/systems/src/projectile.rs +++ b/common/systems/src/projectile.rs @@ -75,7 +75,13 @@ impl<'a> System<'a> for Sys { let mut rng = thread_rng(); if physics.on_surface().is_none() && rng.gen_bool(0.05) { server_emitter.emit(ServerEvent::Sound { - sound: Sound::new(SoundKind::Projectile, pos.0, 2.0, read_data.time.0), + sound: Sound::new( + SoundKind::Projectile, + pos.0, + 2.0, + read_data.time.0, + Some(entity), + ), }); } diff --git a/common/systems/src/shockwave.rs b/common/systems/src/shockwave.rs index 88c1aaaba0..0ec257b3ab 100644 --- a/common/systems/src/shockwave.rs +++ b/common/systems/src/shockwave.rs @@ -88,7 +88,7 @@ impl<'a> System<'a> for Sys { let mut rng = thread_rng(); if rng.gen_bool(0.05) { server_emitter.emit(ServerEvent::Sound { - sound: Sound::new(SoundKind::Shockwave, pos.0, 16.0, time), + sound: Sound::new(SoundKind::Shockwave, pos.0, 16.0, time, Some(entity)), }); } diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index 2cb6fe3fe0..0b8d97bced 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -692,10 +692,20 @@ pub fn handle_explosion(server: &Server, pos: Vec3, explosion: Explosion, o let ecs = &server.state.ecs(); let server_eventbus = ecs.read_resource::>(); let time = ecs.read_resource::