]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Nuke Music start adjusted for duration (#25946)
authorErrant <35878406+Errant-4@users.noreply.github.com>
Tue, 12 Mar 2024 18:50:34 +0000 (19:50 +0100)
committerGitHub <noreply@github.com>
Tue, 12 Mar 2024 18:50:34 +0000 (14:50 -0400)
The exact time when the Nuke Music starts is now derived from the music's duration

Content.Server/Audio/ServerGlobalSoundSystem.cs
Content.Server/Nuke/NukeSystem.cs

index df8771df8d866e593b352e61ff0ba9cb031db413..3d30be8eeaecf4f48810a1e90954f0e01d9042ff 100644 (file)
@@ -1,6 +1,7 @@
 using Content.Server.Station.Systems;
 using Content.Shared.Audio;
 using Robust.Shared.Audio;
+using Robust.Shared.Audio.Systems;
 using Robust.Shared.Console;
 using Robust.Shared.Player;
 
@@ -10,6 +11,7 @@ public sealed class ServerGlobalSoundSystem : SharedGlobalSoundSystem
 {
     [Dependency] private readonly IConsoleHost _conHost = default!;
     [Dependency] private readonly StationSystem _stationSystem = default!;
+    [Dependency] private readonly SharedAudioSystem _audio = default!;
 
     public override void Shutdown()
     {
@@ -49,10 +51,14 @@ public sealed class ServerGlobalSoundSystem : SharedGlobalSoundSystem
     }
 
     public void DispatchStationEventMusic(EntityUid source, SoundSpecifier sound, StationEventMusicType type)
+    {
+        DispatchStationEventMusic(source, _audio.GetSound(sound), type);
+    }
+
+    public void DispatchStationEventMusic(EntityUid source, string sound, StationEventMusicType type)
     {
         var audio = AudioParams.Default.WithVolume(-8);
-        var soundFile = sound.GetSound();
-        var msg = new StationEventMusicEvent(soundFile, type, audio);
+        var msg = new StationEventMusicEvent(sound, type, audio);
 
         var filter = GetStationAndPvs(source);
         RaiseNetworkEvent(msg, filter);
index 652852ece288d3514d22de5067903f9201cf72a2..d6767cd2de8af9b29dcd1fba53cc66cf737c38dc 100644 (file)
@@ -46,7 +46,8 @@ public sealed class NukeSystem : EntitySystem
     /// <summary>
     ///     Used to calculate when the nuke song should start playing for maximum kino with the nuke sfx
     /// </summary>
-    private const float NukeSongLength = 60f + 51.6f;
+    private float _nukeSongLength;
+    private string _selectedNukeSong = String.Empty;
 
     /// <summary>
     ///     Time to leave between the nuke song and the nuke alarm playing.
@@ -292,9 +293,9 @@ public sealed class NukeSystem : EntitySystem
 
         // Start playing the nuke event song so that it ends a couple seconds before the alert sound
         // should play
-        if (nuke.RemainingTime <= NukeSongLength + nuke.AlertSoundTime + NukeSongBuffer && !nuke.PlayedNukeSong)
+        if (nuke.RemainingTime <= _nukeSongLength + nuke.AlertSoundTime + NukeSongBuffer && !nuke.PlayedNukeSong && !string.IsNullOrEmpty(_selectedNukeSong))
         {
-            _sound.DispatchStationEventMusic(uid, nuke.ArmMusic, StationEventMusicType.Nuke);
+            _sound.DispatchStationEventMusic(uid, _selectedNukeSong, StationEventMusicType.Nuke);
             nuke.PlayedNukeSong = true;
         }
 
@@ -457,6 +458,9 @@ public sealed class NukeSystem : EntitySystem
         var y = (int) pos.Y;
         var posText = $"({x}, {y})";
 
+        // We are collapsing the randomness here, otherwise we would get separate random song picks for checking duration and when actually playing the song afterwards
+        _selectedNukeSong = _audio.GetSound(component.ArmMusic);
+
         // warn a crew
         var announcement = Loc.GetString("nuke-component-announcement-armed",
             ("time", (int) component.RemainingTime), ("position", posText));
@@ -464,6 +468,7 @@ public sealed class NukeSystem : EntitySystem
         _chatSystem.DispatchStationAnnouncement(stationUid ?? uid, announcement, sender, false, null, Color.Red);
 
         _sound.PlayGlobalOnStation(uid, _audio.GetSound(component.ArmSound));
+        _nukeSongLength = (float) _audio.GetAudioLength(_selectedNukeSong).TotalSeconds;
 
         // turn on the spinny light
         _pointLight.SetEnabled(uid, true);