+using Content.Shared.Mobs;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
base.Initialize();
SubscribeLocalEvent<AmbientSoundComponent, ComponentGetState>(GetCompState);
SubscribeLocalEvent<AmbientSoundComponent, ComponentHandleState>(HandleCompState);
+
_query = GetEntityQuery<AmbientSoundComponent>();
}
--- /dev/null
+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;
+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;
[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()
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)