From: GreaseMonk <1354802+GreaseMonk@users.noreply.github.com> Date: Sun, 14 Apr 2024 03:12:38 +0000 (+0200) Subject: Add Ability to stop sound when MobState is Dead (#26905) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=da618d791a48efacebe441eee9398c0d1c571ec8;p=space-station-14.git Add Ability to stop sound when MobState is Dead (#26905) * Add stopsWhenEntityDead to sound components * Convert component * Review * Fix dupe sub --------- Co-authored-by: metalgearsloth --- diff --git a/Content.Server/Audio/AmbientSoundSystem.cs b/Content.Server/Audio/AmbientSoundSystem.cs index 53a03be2aa..e78970d124 100644 --- a/Content.Server/Audio/AmbientSoundSystem.cs +++ b/Content.Server/Audio/AmbientSoundSystem.cs @@ -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; diff --git a/Content.Server/Sound/EmitSoundSystem.cs b/Content.Server/Sound/EmitSoundSystem.cs index 5b9620990e..fc10d951e7 100644 --- a/Content.Server/Sound/EmitSoundSystem.cs +++ b/Content.Server/Sound/EmitSoundSystem.cs @@ -40,7 +40,6 @@ public sealed class EmitSoundSystem : SharedEmitSoundSystem SubscribeLocalEvent(HandleEmitSoundOnTrigger); SubscribeLocalEvent(HandleEmitSoundOnUIOpen); - SubscribeLocalEvent(HandleSpamEmitSoundMapInit); } diff --git a/Content.Shared/Audio/SharedAmbientSoundSystem.cs b/Content.Shared/Audio/SharedAmbientSoundSystem.cs index 5f17261825..0a52b7c58e 100644 --- a/Content.Shared/Audio/SharedAmbientSoundSystem.cs +++ b/Content.Shared/Audio/SharedAmbientSoundSystem.cs @@ -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(GetCompState); SubscribeLocalEvent(HandleCompState); + _query = GetEntityQuery(); } diff --git a/Content.Shared/Audio/SoundWhileAliveComponent.cs b/Content.Shared/Audio/SoundWhileAliveComponent.cs new file mode 100644 index 0000000000..977d9372ce --- /dev/null +++ b/Content.Shared/Audio/SoundWhileAliveComponent.cs @@ -0,0 +1,10 @@ +using Content.Shared.Sound.Components; +using Robust.Shared.GameStates; + +namespace Content.Shared.Audio; + +/// +/// Toggles and off when this entity's MobState isn't Alive. +/// +[RegisterComponent, NetworkedComponent] +public sealed partial class SoundWhileAliveComponent : Component; diff --git a/Content.Shared/Sound/SharedEmitSoundSystem.cs b/Content.Shared/Sound/SharedEmitSoundSystem.cs index 329626964e..a9a50698d7 100644 --- a/Content.Shared/Sound/SharedEmitSoundSystem.cs +++ b/Content.Shared/Sound/SharedEmitSoundSystem.cs @@ -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(OnEmitSoundOnInteractUsing); SubscribeLocalEvent(OnEmitSoundOnCollide); + + SubscribeLocalEvent(OnMobState); + } + + private void OnMobState(Entity entity, ref MobStateChangedEvent args) + { + // Disable this component rather than removing it because it can be brought back to life. + if (TryComp(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)