]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add Ability to stop sound when MobState is Dead (#26905)
authorGreaseMonk <1354802+GreaseMonk@users.noreply.github.com>
Sun, 14 Apr 2024 03:12:38 +0000 (05:12 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Apr 2024 03:12:38 +0000 (13:12 +1000)
* Add stopsWhenEntityDead to sound components

* Convert component

* Review

* Fix dupe sub

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Content.Server/Audio/AmbientSoundSystem.cs
Content.Server/Sound/EmitSoundSystem.cs
Content.Shared/Audio/SharedAmbientSoundSystem.cs
Content.Shared/Audio/SoundWhileAliveComponent.cs [new file with mode: 0644]
Content.Shared/Sound/SharedEmitSoundSystem.cs

index 53a03be2aa297cefb4d31e45aacadb82cff84539..e78970d1243df3b5215c13855e7d3dc56545100b 100644 (file)
@@ -1,6 +1,7 @@
 using Content.Server.Power.Components;
 using Content.Server.Power.EntitySystems;
 using Content.Shared.Audio;
+using Content.Shared.Mobs;
 
 namespace Content.Server.Audio;
 
index 5b9620990eb72f738035f9c07a121604b0010f5a..fc10d951e76f3559abb445c89b5bf1fe7f67ba01 100644 (file)
@@ -40,7 +40,6 @@ public sealed class EmitSoundSystem : SharedEmitSoundSystem
 
         SubscribeLocalEvent<EmitSoundOnTriggerComponent, TriggerEvent>(HandleEmitSoundOnTrigger);
         SubscribeLocalEvent<EmitSoundOnUIOpenComponent, AfterActivatableUIOpenEvent>(HandleEmitSoundOnUIOpen);
-
         SubscribeLocalEvent<SpamEmitSoundComponent, MapInitEvent>(HandleSpamEmitSoundMapInit);
     }
 
index 5f17261825c3638ec5a4ff39d2d2772d7361a228..0a52b7c58e2dbeb5fbd098b514f09750a7334fde 100644 (file)
@@ -1,3 +1,4 @@
+using Content.Shared.Mobs;
 using Robust.Shared.Audio;
 using Robust.Shared.GameStates;
 
@@ -12,6 +13,7 @@ public abstract class SharedAmbientSoundSystem : EntitySystem
         base.Initialize();
         SubscribeLocalEvent<AmbientSoundComponent, ComponentGetState>(GetCompState);
         SubscribeLocalEvent<AmbientSoundComponent, ComponentHandleState>(HandleCompState);
+
         _query = GetEntityQuery<AmbientSoundComponent>();
     }
 
diff --git a/Content.Shared/Audio/SoundWhileAliveComponent.cs b/Content.Shared/Audio/SoundWhileAliveComponent.cs
new file mode 100644 (file)
index 0000000..977d937
--- /dev/null
@@ -0,0 +1,10 @@
+using Content.Shared.Sound.Components;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Audio;
+
+/// <summary>
+/// Toggles <see cref="AmbientSoundComponent"/> and <see cref="SpamEmitSoundComponent"/> off when this entity's MobState isn't Alive.
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class SoundWhileAliveComponent : Component;
index 329626964ef6a07783444fa28517367d5184b8b0..a9a50698d7d5cf12a4f051091df25769c7350053 100644 (file)
@@ -1,7 +1,10 @@
+using Content.Shared.Audio;
 using Content.Shared.Hands;
+using Content.Shared.Hands.Components;
 using Content.Shared.Interaction;
 using Content.Shared.Interaction.Events;
 using Content.Shared.Maps;
+using Content.Shared.Mobs;
 using Content.Shared.Popups;
 using Content.Shared.Sound.Components;
 using Content.Shared.Throwing;
@@ -28,7 +31,8 @@ public abstract class SharedEmitSoundSystem : EntitySystem
     [Dependency] private readonly INetManager _netMan = default!;
     [Dependency] private readonly ITileDefinitionManager _tileDefMan = default!;
     [Dependency] protected readonly IRobustRandom Random = default!;
-    [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
+    [Dependency] private   readonly SharedAmbientSoundSystem _ambient = default!;
+    [Dependency] private   readonly SharedAudioSystem _audioSystem = default!;
     [Dependency] protected readonly SharedPopupSystem Popup = default!;
 
     public override void Initialize()
@@ -44,6 +48,20 @@ public abstract class SharedEmitSoundSystem : EntitySystem
         SubscribeLocalEvent<EmitSoundOnInteractUsingComponent, InteractUsingEvent>(OnEmitSoundOnInteractUsing);
 
         SubscribeLocalEvent<EmitSoundOnCollideComponent, StartCollideEvent>(OnEmitSoundOnCollide);
+
+        SubscribeLocalEvent<SoundWhileAliveComponent, MobStateChangedEvent>(OnMobState);
+    }
+
+    private void OnMobState(Entity<SoundWhileAliveComponent> entity, ref MobStateChangedEvent args)
+    {
+        // Disable this component rather than removing it because it can be brought back to life.
+        if (TryComp<SpamEmitSoundComponent>(entity, out var comp))
+        {
+            comp.Enabled = args.NewMobState == MobState.Alive;
+            Dirty(entity.Owner, comp);
+        }
+
+        _ambient.SetAmbience(entity.Owner, args.NewMobState != MobState.Dead);
     }
 
     private void OnEmitSpawnOnInit(EntityUid uid, EmitSoundOnSpawnComponent component, MapInitEvent args)