diff --git a/common/systems/src/beam.rs b/common/systems/src/beam.rs index 8bf62b323d..2edddbce28 100644 --- a/common/systems/src/beam.rs +++ b/common/systems/src/beam.rs @@ -91,10 +91,14 @@ impl<'a> System<'a> for Sys { }; let end_time = creation_time + beam_segment.duration.as_secs_f64(); + let beam_owner = beam_segment + .owner + .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); + 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, Some(entity)), + sound: Sound::new(SoundKind::Beam, pos.0, 7.0, time, beam_owner), }); } @@ -119,10 +123,6 @@ impl<'a> System<'a> for Sys { (beam_segment.speed * (time_since_creation - frame_time)).max(0.0); let frame_end_dist = (beam_segment.speed * time_since_creation).max(frame_start_dist); - let beam_owner = beam_segment - .owner - .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); - // Group to ignore collisions with // Might make this more nuanced if beams are used for non damage effects let group = beam_owner.and_then(|e| read_data.groups.get(e)); diff --git a/common/systems/src/projectile.rs b/common/systems/src/projectile.rs index d8430763b9..4d6d27ec22 100644 --- a/common/systems/src/projectile.rs +++ b/common/systems/src/projectile.rs @@ -72,6 +72,10 @@ impl<'a> System<'a> for Sys { ) .join() { + let projectile_owner = projectile + .owner + .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); + let mut rng = thread_rng(); if physics.on_surface().is_none() && rng.gen_bool(0.05) { server_emitter.emit(ServerEvent::Sound { @@ -89,12 +93,10 @@ impl<'a> System<'a> for Sys { // Hit entity for other in physics.touch_entities.iter().copied() { - let same_group = projectile - .owner + let same_group = projectile_owner // Note: somewhat inefficient since we do the lookup for every touching // entity, but if we pull this out of the loop we would want to do it only // if there is at least one touching entity - .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())) .and_then(|e| read_data.groups.get(e)) .map_or(false, |owner_group| Some(owner_group) == read_data.uid_allocator diff --git a/common/systems/src/shockwave.rs b/common/systems/src/shockwave.rs index 0ec257b3ab..ac5aa752e3 100644 --- a/common/systems/src/shockwave.rs +++ b/common/systems/src/shockwave.rs @@ -85,10 +85,14 @@ impl<'a> System<'a> for Sys { let end_time = creation_time + shockwave.duration.as_secs_f64(); + let shockwave_owner = shockwave + .owner + .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); + 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, Some(entity)), + sound: Sound::new(SoundKind::Shockwave, pos.0, 16.0, time, shockwave_owner), }); } @@ -120,10 +124,6 @@ impl<'a> System<'a> for Sys { end: frame_end_dist, }; - let shockwave_owner = shockwave - .owner - .and_then(|uid| read_data.uid_allocator.retrieve_entity_internal(uid.into())); - // Group to ignore collisions with // Might make this more nuanced if shockwaves are used for non damage effects let group = shockwave_owner.and_then(|e| read_data.groups.get(e));