CatStation/Content.Server/SurveillanceCamera/Systems/SurveillanceCameraSpeakerSystem.cs
Eveloop 22a547c7c8
Use dependency injection for EntityQuery<T>s in Content.Server (#43566)
* Replace usages of EntityQuery with dependency injected ones in Content.Server

* Remove unused EntityQuery dependencies

* Restore CheckPressureAndFire override method

* Revert EntityQuery refactor changes to DisposalTubeSystem.cs & DisposableSystem.cs

* Infer Transform/Metadata directly instead of passing (#43479)

* Resolve RA0049, RA0051 errors (#43479)

* Resolve RA0049, RA0051 errors (#43479)

* Apply suggestions from code review

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>

---------

Co-authored-by: slarticodefast <161409025+slarticodefast@users.noreply.github.com>
2026-05-17 15:59:37 +00:00

58 lines
2.1 KiB
C#

using Content.Server.Chat.Systems;
using Content.Server.Speech;
using Content.Server.SurveillanceCamera.Systems;
using Content.Shared.Speech;
using Content.Shared.Chat;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Timing;
namespace Content.Server.SurveillanceCamera;
/// <summary>
/// This handles speech for surveillance camera monitors.
/// </summary>
public sealed partial class SurveillanceCameraSpeakerSystem : EntitySystem
{
[Dependency] private SharedAudioSystem _audioSystem = default!;
[Dependency] private SpeechSoundSystem _speechSound = default!;
[Dependency] private ChatSystem _chatSystem = default!;
[Dependency] private IGameTiming _gameTiming = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<SurveillanceCameraSpeakerComponent, SurveillanceCameraSpeechSendEvent>(OnSpeechSent);
}
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
// what is wrong with you?
if (time - component.LastSoundPlayed < cd
&& TryComp<SpeechComponent>(args.Speaker, out var speech))
{
var sound = _speechSound.GetSpeechSound((args.Speaker, speech), args.Message);
_audioSystem.PlayPvs(sound, uid);
component.LastSoundPlayed = time;
}
var nameEv = new TransformSpeakerNameEvent(args.Speaker, Name(args.Speaker));
RaiseLocalEvent(args.Speaker, nameEv);
var name = Loc.GetString("speech-name-relay", ("speaker", Name(uid)),
("originalName", nameEv.VoiceName));
// log to chat so people can identity the speaker/source, but avoid clogging ghost chat if there are many radios
_chatSystem.TrySendInGameICMessage(uid, args.Message, InGameICChatType.Speak, ChatTransmitRange.GhostRangeLimit, nameOverride: name);
}
}