Surveillance camera listening/speaking (#11640)
This commit is contained in:
@@ -243,7 +243,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem
|
|||||||
/// <param name="alarmable"></param>
|
/// <param name="alarmable"></param>
|
||||||
public void Reset(EntityUid uid, AtmosAlarmableComponent? alarmable = null, TagComponent? tags = null)
|
public void Reset(EntityUid uid, AtmosAlarmableComponent? alarmable = null, TagComponent? tags = null)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref alarmable, ref tags) || alarmable.LastAlarmState == AtmosAlarmType.Normal)
|
if (!Resolve(uid, ref alarmable, ref tags, false) || alarmable.LastAlarmState == AtmosAlarmType.Normal)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -285,7 +285,7 @@ public sealed class AtmosAlarmableSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
alarm = null;
|
alarm = null;
|
||||||
|
|
||||||
if (!Resolve(uid, ref alarmable))
|
if (!Resolve(uid, ref alarmable, false))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ public sealed class AtmosMonitorSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
if (!monitor.NetEnabled) return;
|
if (!monitor.NetEnabled) return;
|
||||||
|
|
||||||
if (!Resolve(monitor.Owner, ref tags))
|
if (!Resolve(monitor.Owner, ref tags, false))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
using Content.Server.Radio.Components;
|
||||||
|
using Content.Shared.Interaction;
|
||||||
|
using Content.Shared.Radio;
|
||||||
|
using Content.Shared.Whitelist;
|
||||||
|
|
||||||
|
namespace Content.Server.SurveillanceCamera;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Component that allows surveillance cameras to listen to the local
|
||||||
|
/// environment. All surveillance camera monitors have speakers for this.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent]
|
||||||
|
[ComponentReference(typeof(IListen))]
|
||||||
|
public sealed class SurveillanceCameraMicrophoneComponent : Component, IListen
|
||||||
|
{
|
||||||
|
public bool Enabled { get; set; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Components that the microphone checks for to avoid transmitting
|
||||||
|
/// messages from these entities over the surveillance camera.
|
||||||
|
/// Used to avoid things like feedback loops, or radio spam.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("blacklist")]
|
||||||
|
public EntityWhitelist BlacklistedComponents { get; } = new();
|
||||||
|
|
||||||
|
// TODO: Once IListen is removed, **REMOVE THIS**
|
||||||
|
|
||||||
|
private SurveillanceCameraMicrophoneSystem? _microphoneSystem;
|
||||||
|
protected override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
_microphoneSystem = EntitySystem.Get<SurveillanceCameraMicrophoneSystem>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int ListenRange { get; } = 10;
|
||||||
|
public bool CanListen(string message, EntityUid source, RadioChannelPrototype? channelPrototype)
|
||||||
|
{
|
||||||
|
return _microphoneSystem != null
|
||||||
|
&& _microphoneSystem.CanListen(Owner, source, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Listen(string message, EntityUid speaker, RadioChannelPrototype? channel)
|
||||||
|
{
|
||||||
|
_microphoneSystem?.RelayEntityMessage(Owner, speaker, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
namespace Content.Server.SurveillanceCamera;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This allows surveillance cameras to speak, if the camera in question
|
||||||
|
/// has a microphone that listens to speech.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent]
|
||||||
|
public sealed class SurveillanceCameraSpeakerComponent : Component
|
||||||
|
{
|
||||||
|
// mostly copied from Speech
|
||||||
|
[DataField("speechEnabled")] public bool SpeechEnabled = true;
|
||||||
|
|
||||||
|
[ViewVariables] public float SpeechSoundCooldown = 0.5f;
|
||||||
|
|
||||||
|
[ViewVariables] public readonly Queue<string> LastSpokenNames = new();
|
||||||
|
|
||||||
|
public TimeSpan LastSoundPlayed = TimeSpan.Zero;
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
using Content.Shared.IdentityManagement;
|
||||||
|
using Content.Shared.Interaction;
|
||||||
|
|
||||||
|
namespace Content.Server.SurveillanceCamera;
|
||||||
|
|
||||||
|
public sealed class SurveillanceCameraMicrophoneSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private SharedInteractionSystem _interactionSystem = default!;
|
||||||
|
|
||||||
|
public bool CanListen(EntityUid source, EntityUid speaker, SurveillanceCameraMicrophoneComponent? microphone = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(source, ref microphone))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return microphone.Enabled
|
||||||
|
&& !microphone.BlacklistedComponents.IsValid(speaker)
|
||||||
|
&& _interactionSystem.InRangeUnobstructed(source, speaker, range: microphone.ListenRange);
|
||||||
|
}
|
||||||
|
public void RelayEntityMessage(EntityUid source, EntityUid speaker, string message, SurveillanceCameraComponent? camera = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(source, ref camera))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ev = new SurveillanceCameraSpeechSendEvent(speaker, message);
|
||||||
|
|
||||||
|
foreach (var monitor in camera.ActiveMonitors)
|
||||||
|
{
|
||||||
|
RaiseLocalEvent(monitor, ev);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class SurveillanceCameraSpeechSendEvent : EntityEventArgs
|
||||||
|
{
|
||||||
|
public EntityUid Speaker { get; }
|
||||||
|
public string Message { get; }
|
||||||
|
|
||||||
|
public SurveillanceCameraSpeechSendEvent(EntityUid speaker, string message)
|
||||||
|
{
|
||||||
|
Speaker = speaker;
|
||||||
|
Message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,13 +1,18 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Content.Server.Chat.Systems;
|
||||||
using Content.Server.DeviceNetwork;
|
using Content.Server.DeviceNetwork;
|
||||||
using Content.Server.DeviceNetwork.Systems;
|
using Content.Server.DeviceNetwork.Systems;
|
||||||
using Content.Server.Power.Components;
|
using Content.Server.Power.Components;
|
||||||
using Content.Server.UserInterface;
|
using Content.Server.UserInterface;
|
||||||
using Content.Server.Wires;
|
using Content.Server.Wires;
|
||||||
using Content.Shared.Interaction;
|
using Content.Shared.Interaction;
|
||||||
|
using Content.Shared.Speech;
|
||||||
using Content.Shared.SurveillanceCamera;
|
using Content.Shared.SurveillanceCamera;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
namespace Content.Server.SurveillanceCamera;
|
namespace Content.Server.SurveillanceCamera;
|
||||||
|
|
||||||
@@ -370,8 +375,7 @@ public sealed class SurveillanceCameraMonitorSystem : EntitySystem
|
|||||||
|
|
||||||
if (monitor.ActiveCamera != null)
|
if (monitor.ActiveCamera != null)
|
||||||
{
|
{
|
||||||
EntityUid? monitorUid = monitor.Viewers.Count == 0 ? uid : null;
|
_surveillanceCameras.RemoveActiveViewer(monitor.ActiveCamera.Value, player);
|
||||||
_surveillanceCameras.RemoveActiveViewer(monitor.ActiveCamera.Value, player, monitorUid);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
using Content.Server.Chat.Systems;
|
||||||
|
using Content.Shared.Speech;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
using Robust.Shared.Random;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
|
||||||
|
namespace Content.Server.SurveillanceCamera;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This handles speech for surveillance camera monitors.
|
||||||
|
/// </summary>
|
||||||
|
public sealed class SurveillanceCameraSpeakerSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly SharedAudioSystem _audioSystem = default!;
|
||||||
|
[Dependency] private readonly ChatSystem _chatSystem = default!;
|
||||||
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
[Dependency] private readonly IRobustRandom _random = default!;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
SubscribeLocalEvent<SurveillanceCameraSpeakerComponent, SurveillanceCameraSpeechSendEvent>(OnSpeechSent);
|
||||||
|
SubscribeLocalEvent<SurveillanceCameraSpeakerComponent, TransformSpeakerNameEvent>(OnTransformSpeech);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnSpeechSent(EntityUid uid, SurveillanceCameraSpeakerComponent component,
|
||||||
|
SurveillanceCameraSpeechSendEvent args)
|
||||||
|
{
|
||||||
|
if (!component.SpeechEnabled)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var time = _gameTiming.CurTime;
|
||||||
|
var cd = TimeSpan.FromSeconds(component.SpeechSoundCooldown);
|
||||||
|
|
||||||
|
// this part's mostly copied from speech
|
||||||
|
if (time - component.LastSoundPlayed < cd
|
||||||
|
&& TryComp<SharedSpeechComponent>(args.Speaker, out var speech)
|
||||||
|
&& speech.SpeechSounds != null
|
||||||
|
&& _prototypeManager.TryIndex(speech.SpeechSounds, out SpeechSoundsPrototype? speechProto))
|
||||||
|
{
|
||||||
|
var sound = args.Message[^1] switch
|
||||||
|
{
|
||||||
|
'?' => speechProto.AskSound,
|
||||||
|
'!' => speechProto.ExclaimSound,
|
||||||
|
_ => speechProto.SaySound
|
||||||
|
};
|
||||||
|
|
||||||
|
var uppercase = 0;
|
||||||
|
for (var i = 0; i < args.Message.Length; i++)
|
||||||
|
{
|
||||||
|
if (char.IsUpper(args.Message[i]))
|
||||||
|
{
|
||||||
|
uppercase++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uppercase > args.Message.Length / 2)
|
||||||
|
{
|
||||||
|
sound = speechProto.ExclaimSound;
|
||||||
|
}
|
||||||
|
|
||||||
|
var scale = (float) _random.NextGaussian(1, speechProto.Variation);
|
||||||
|
var param = speech.AudioParams.WithPitchScale(scale);
|
||||||
|
_audioSystem.PlayPvs(sound, uid, param);
|
||||||
|
|
||||||
|
component.LastSoundPlayed = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
var nameEv = new TransformSpeakerNameEvent(args.Speaker, Name(args.Speaker));
|
||||||
|
RaiseLocalEvent(args.Speaker, nameEv);
|
||||||
|
component.LastSpokenNames.Enqueue(nameEv.Name);
|
||||||
|
|
||||||
|
_chatSystem.TrySendInGameICMessage(uid, args.Message, InGameICChatType.Speak, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTransformSpeech(EntityUid uid, SurveillanceCameraSpeakerComponent component,
|
||||||
|
TransformSpeakerNameEvent args)
|
||||||
|
{
|
||||||
|
args.Name = Loc.GetString("surveillance-camera-microphone-message", ("speaker", Name(uid)),
|
||||||
|
("originalName", component.LastSpokenNames.Dequeue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
surveillance-camera-microphone-message = {$speaker} ({$originalName})
|
||||||
@@ -10,3 +10,4 @@ surveillance-camera-monitor-ui-no-subnets = No Subnets
|
|||||||
|
|
||||||
surveillance-camera-setup = Setup
|
surveillance-camera-setup = Setup
|
||||||
surveillance-camera-setup-ui-set = Set
|
surveillance-camera-setup-ui-set = Set
|
||||||
|
|
||||||
|
|||||||
@@ -674,7 +674,10 @@
|
|||||||
- type: WirelessNetworkConnection
|
- type: WirelessNetworkConnection
|
||||||
range: 200
|
range: 200
|
||||||
- type: DeviceNetworkRequiresPower
|
- type: DeviceNetworkRequiresPower
|
||||||
|
- type: Speech
|
||||||
|
- type: SurveillanceCameraSpeaker
|
||||||
- type: SurveillanceCameraMonitor
|
- type: SurveillanceCameraMonitor
|
||||||
|
speechEnabled: true
|
||||||
- type: ActivatableUI
|
- type: ActivatableUI
|
||||||
key: enum.SurveillanceCameraMonitorUiKey.Key
|
key: enum.SurveillanceCameraMonitorUiKey.Key
|
||||||
- type: ActivatableUIRequiresPower
|
- type: ActivatableUIRequiresPower
|
||||||
|
|||||||
@@ -22,6 +22,11 @@
|
|||||||
density: 80
|
density: 80
|
||||||
mask:
|
mask:
|
||||||
- MachineMask
|
- MachineMask
|
||||||
|
- type: SurveillanceCameraMicrophone
|
||||||
|
blacklist:
|
||||||
|
components:
|
||||||
|
- SurveillanceCamera
|
||||||
|
- SurveillanceCameraMonitor
|
||||||
- type: UserInterface
|
- type: UserInterface
|
||||||
interfaces:
|
interfaces:
|
||||||
- key: enum.SurveillanceCameraSetupUiKey.Camera
|
- key: enum.SurveillanceCameraSetupUiKey.Camera
|
||||||
|
|||||||
@@ -159,6 +159,8 @@
|
|||||||
- type: WirelessNetworkConnection
|
- type: WirelessNetworkConnection
|
||||||
range: 200
|
range: 200
|
||||||
- type: DeviceNetworkRequiresPower
|
- type: DeviceNetworkRequiresPower
|
||||||
|
- type: Speech
|
||||||
|
- type: SurveillanceCameraSpeaker
|
||||||
- type: SurveillanceCameraMonitor
|
- type: SurveillanceCameraMonitor
|
||||||
- type: ActivatableUI
|
- type: ActivatableUI
|
||||||
key: enum.SurveillanceCameraMonitorUiKey.Key
|
key: enum.SurveillanceCameraMonitorUiKey.Key
|
||||||
|
|||||||
Reference in New Issue
Block a user