1
0

ServerGlobalSoundSystem.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using Content.Server.Station.Systems;
  2. using Content.Shared.Audio;
  3. using Robust.Shared.Audio;
  4. using Robust.Shared.Audio.Systems;
  5. using Robust.Shared.Console;
  6. using Robust.Shared.Player;
  7. namespace Content.Server.Audio;
  8. public sealed class ServerGlobalSoundSystem : SharedGlobalSoundSystem
  9. {
  10. [Dependency] private readonly IConsoleHost _conHost = default!;
  11. [Dependency] private readonly StationSystem _stationSystem = default!;
  12. [Dependency] private readonly SharedAudioSystem _audio = default!;
  13. public override void Shutdown()
  14. {
  15. base.Shutdown();
  16. _conHost.UnregisterCommand("playglobalsound");
  17. }
  18. public void PlayAdminGlobal(Filter playerFilter, ResolvedSoundSpecifier specifier, AudioParams? audioParams = null, bool replay = true)
  19. {
  20. var msg = new AdminSoundEvent(specifier, audioParams);
  21. RaiseNetworkEvent(msg, playerFilter, recordReplay: replay);
  22. }
  23. private Filter GetStationAndPvs(EntityUid source)
  24. {
  25. var stationFilter = _stationSystem.GetInOwningStation(source);
  26. stationFilter.AddPlayersByPvs(source, entityManager: EntityManager);
  27. return stationFilter;
  28. }
  29. public void PlayGlobalOnStation(EntityUid source, ResolvedSoundSpecifier specifier, AudioParams? audioParams = null)
  30. {
  31. var msg = new GameGlobalSoundEvent(specifier, audioParams);
  32. var filter = GetStationAndPvs(source);
  33. RaiseNetworkEvent(msg, filter);
  34. }
  35. public void StopStationEventMusic(EntityUid source, StationEventMusicType type)
  36. {
  37. // TODO REPLAYS
  38. // these start & stop events are gonna be a PITA
  39. // theres probably some nice way of handling them. Maybe it just needs dedicated replay data (in which case these events should NOT get recorded).
  40. var msg = new StopStationEventMusic(type);
  41. var filter = GetStationAndPvs(source);
  42. RaiseNetworkEvent(msg, filter);
  43. }
  44. public void DispatchStationEventMusic(EntityUid source, SoundSpecifier sound, StationEventMusicType type)
  45. {
  46. DispatchStationEventMusic(source, _audio.ResolveSound(sound), type);
  47. }
  48. public void DispatchStationEventMusic(EntityUid source, ResolvedSoundSpecifier specifier, StationEventMusicType type)
  49. {
  50. var audio = AudioParams.Default.WithVolume(-8);
  51. var msg = new StationEventMusicEvent(specifier, type, audio);
  52. var filter = GetStationAndPvs(source);
  53. RaiseNetworkEvent(msg, filter);
  54. }
  55. }