Geiger counters can now be heard by everyone nearby (#30463)

* haha geiger counter go brrrrrrr

* move hardcoded values to datafields

* syntax cleanup
This commit is contained in:
Errant
2025-04-17 13:24:47 +02:00
committed by GitHub
parent f46bb301fb
commit 9b1a7dea1d
3 changed files with 59 additions and 39 deletions

View File

@@ -8,6 +8,7 @@ using Content.Shared.Radiation.Systems;
using Robust.Server.Audio;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Player;
namespace Content.Server.Radiation.Systems;
@@ -155,16 +156,17 @@ public sealed class GeigerSystem : SharedGeigerSystem
if (!component.Sounds.TryGetValue(component.DangerLevel, out var sounds))
return;
if (component.User == null)
return;
if (!_player.TryGetSessionByEntity(component.User.Value, out var session))
return;
var sound = _audio.ResolveSound(sounds);
var param = sounds.Params.WithLoop(true).WithVolume(-4f);
var param = sounds.Params.WithLoop(true).WithVolume(component.Volume);
component.Stream = _audio.PlayGlobal(sound, session, param)?.Entity;
if (component.BroadcastAudio)
{
// For some reason PlayPvs sounds quieter even at distance 0, so we need to boost the volume a bit for consistency
param = sounds.Params.WithLoop(true).WithVolume(component.Volume + 1.5f).WithMaxDistance(component.BroadcastRange);
component.Stream = _audio.PlayPvs(sound, uid, param)?.Entity;
}
else if(component.User is not null && _player.TryGetSessionByEntity(component.User.Value, out var session))
component.Stream = _audio.PlayGlobal(sound, session, param)?.Entity;
}
public static GeigerDangerLevel RadsToLevel(float rads)

View File

@@ -83,6 +83,24 @@ public sealed partial class GeigerComponent : Component
/// Played only for current user.
/// </summary>
public EntityUid? Stream;
/// <summary>
/// Mark true if the audio should be heard by everyone around the device
/// </summary>
[DataField]
public bool BroadcastAudio = false;
/// <summary>
/// The distance within which the broadcast tone can be heard.
/// </summary>
[DataField]
public float BroadcastRange = 4f;
/// <summary>
/// The volume of the warning tone.
/// </summary>
[DataField]
public float Volume = -4f;
}
[Serializable, NetSerializable]

View File

@@ -4,34 +4,34 @@
name: Geiger counter
description: A handheld device used for detecting and measuring radiation pulses.
components:
- type: Sprite
sprite: Objects/Tools/geiger.rsi
layers:
- state: geiger_base
- state: geiger_on_idle
map: ["enum.GeigerLayers.Screen"]
shader: unshaded
visible: false
- type: Item
sprite: Objects/Tools/geiger.rsi
- type: Geiger
showControl: true
showExamine: true
- type: Appearance
- type: GenericVisualizer
visuals:
enum.GeigerVisuals.IsEnabled:
GeigerLayers.Screen:
True: { visible: True }
False: { visible: False }
enum.GeigerVisuals.DangerLevel:
GeigerLayers.Screen:
None: {state: geiger_on_idle}
Low: {state: geiger_on_low}
Med: {state: geiger_on_med}
High: {state: geiger_on_high}
Extreme: {state: geiger_on_ext}
- type: PhysicalComposition
materialComposition:
Plastic: 100
- type: Sprite
sprite: Objects/Tools/geiger.rsi
layers:
- state: geiger_base
- state: geiger_on_idle
map: ["enum.GeigerLayers.Screen"]
shader: unshaded
visible: false
- type: Item
sprite: Objects/Tools/geiger.rsi
- type: Geiger
showControl: true
showExamine: true
broadcastAudio: true
- type: Appearance
- type: GenericVisualizer
visuals:
enum.GeigerVisuals.IsEnabled:
GeigerLayers.Screen:
True: { visible: True }
False: { visible: False }
enum.GeigerVisuals.DangerLevel:
GeigerLayers.Screen:
None: {state: geiger_on_idle}
Low: {state: geiger_on_low}
Med: {state: geiger_on_med}
High: {state: geiger_on_high}
Extreme: {state: geiger_on_ext}
- type: PhysicalComposition
materialComposition:
Plastic: 100