SurveillanceCameraSpeakerSystem.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using Content.Server.Chat.Systems;
  2. using Content.Server.Speech;
  3. using Content.Shared.Speech;
  4. using Content.Shared.Chat;
  5. using Robust.Shared.Audio.Systems;
  6. using Robust.Shared.Timing;
  7. namespace Content.Server.SurveillanceCamera;
  8. /// <summary>
  9. /// This handles speech for surveillance camera monitors.
  10. /// </summary>
  11. public sealed class SurveillanceCameraSpeakerSystem : EntitySystem
  12. {
  13. [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
  14. [Dependency] private readonly SpeechSoundSystem _speechSound = default!;
  15. [Dependency] private readonly ChatSystem _chatSystem = default!;
  16. [Dependency] private readonly IGameTiming _gameTiming = default!;
  17. /// <inheritdoc/>
  18. public override void Initialize()
  19. {
  20. SubscribeLocalEvent<SurveillanceCameraSpeakerComponent, SurveillanceCameraSpeechSendEvent>(OnSpeechSent);
  21. }
  22. private void OnSpeechSent(EntityUid uid, SurveillanceCameraSpeakerComponent component,
  23. SurveillanceCameraSpeechSendEvent args)
  24. {
  25. if (!component.SpeechEnabled)
  26. {
  27. return;
  28. }
  29. var time = _gameTiming.CurTime;
  30. var cd = TimeSpan.FromSeconds(component.SpeechSoundCooldown);
  31. // this part's mostly copied from speech
  32. // what is wrong with you?
  33. if (time - component.LastSoundPlayed < cd
  34. && TryComp<SpeechComponent>(args.Speaker, out var speech))
  35. {
  36. var sound = _speechSound.GetSpeechSound((args.Speaker, speech), args.Message);
  37. _audioSystem.PlayPvs(sound, uid);
  38. component.LastSoundPlayed = time;
  39. }
  40. var nameEv = new TransformSpeakerNameEvent(args.Speaker, Name(args.Speaker));
  41. RaiseLocalEvent(args.Speaker, nameEv);
  42. var name = Loc.GetString("speech-name-relay", ("speaker", Name(uid)),
  43. ("originalName", nameEv.VoiceName));
  44. // log to chat so people can identity the speaker/source, but avoid clogging ghost chat if there are many radios
  45. _chatSystem.TrySendInGameICMessage(uid, args.Message, InGameICChatType.Speak, ChatTransmitRange.GhostRangeLimit, nameOverride: name);
  46. }
  47. }