2024-01-31 20:07:06 +06:00
|
|
|
|
using Content.Shared.Mobs;
|
2023-05-01 15:05:43 +06:00
|
|
|
|
using Robust.Shared.Audio;
|
2024-01-13 12:24:00 +03:00
|
|
|
|
using Robust.Shared.Audio.Systems;
|
2024-01-17 19:34:15 +07:00
|
|
|
|
using Robust.Shared.Player;
|
2023-05-01 15:05:43 +06:00
|
|
|
|
|
2024-01-28 18:18:54 +07:00
|
|
|
|
namespace Content.Server._White.Other.DeathGasps;
|
2023-05-01 15:05:43 +06:00
|
|
|
|
|
|
|
|
|
|
public sealed class OnDeath : EntitySystem
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
2023-06-13 19:33:50 +00:00
|
|
|
|
SubscribeLocalEvent<DeathGaspsComponent, MobStateChangedEvent>(HandleDeathEvent);
|
|
|
|
|
|
SubscribeLocalEvent<DeathGaspsComponent, PlayerDetachedEvent>(OnDetach);
|
2023-05-01 15:05:43 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-13 12:24:00 +03:00
|
|
|
|
private readonly Dictionary<EntityUid, EntityUid> _playingStreams = new();
|
2024-07-02 12:55:25 +03:00
|
|
|
|
|
2023-05-01 15:05:43 +06:00
|
|
|
|
|
2023-06-13 19:33:50 +00:00
|
|
|
|
private void HandleDeathEvent(EntityUid uid, DeathGaspsComponent component, MobStateChangedEvent args)
|
2023-05-01 15:05:43 +06:00
|
|
|
|
{
|
|
|
|
|
|
//^.^
|
|
|
|
|
|
switch (args.NewMobState)
|
|
|
|
|
|
{
|
|
|
|
|
|
case MobState.Invalid:
|
|
|
|
|
|
StopPlayingStream(uid);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MobState.Alive:
|
|
|
|
|
|
StopPlayingStream(uid);
|
|
|
|
|
|
break;
|
|
|
|
|
|
case MobState.Critical:
|
2024-07-02 12:55:25 +03:00
|
|
|
|
PlayPlayingStream(uid, component);
|
2023-05-01 15:05:43 +06:00
|
|
|
|
break;
|
|
|
|
|
|
case MobState.Dead:
|
|
|
|
|
|
StopPlayingStream(uid);
|
2024-07-02 12:55:25 +03:00
|
|
|
|
PlayDeathSound(uid, component);
|
2023-05-01 15:05:43 +06:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-02 12:55:25 +03:00
|
|
|
|
private void PlayPlayingStream(EntityUid uid, DeathGaspsComponent component)
|
2023-05-01 15:05:43 +06:00
|
|
|
|
{
|
|
|
|
|
|
if (_playingStreams.TryGetValue(uid, out var currentStream))
|
|
|
|
|
|
{
|
2024-01-13 12:24:00 +03:00
|
|
|
|
_audio.Stop(currentStream);
|
2023-05-01 15:05:43 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-02 12:55:25 +03:00
|
|
|
|
var newStream = _audio.PlayEntity(component.HeartSounds, uid, uid, AudioParams.Default.WithLoop(true));
|
2024-01-31 15:08:17 +00:00
|
|
|
|
|
|
|
|
|
|
if (newStream.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
_playingStreams[uid] = newStream.Value.Entity;
|
|
|
|
|
|
}
|
2023-05-01 15:05:43 +06:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void StopPlayingStream(EntityUid uid)
|
|
|
|
|
|
{
|
2024-01-31 20:07:06 +06:00
|
|
|
|
if (!_playingStreams.TryGetValue(uid, out var currentStream))
|
|
|
|
|
|
return;
|
2023-05-01 15:05:43 +06:00
|
|
|
|
|
2024-01-31 20:07:06 +06:00
|
|
|
|
_audio.Stop(currentStream);
|
|
|
|
|
|
_playingStreams.Remove(uid);
|
2024-01-17 19:34:15 +07:00
|
|
|
|
}
|
2023-05-01 15:05:43 +06:00
|
|
|
|
|
2024-07-02 12:55:25 +03:00
|
|
|
|
private void PlayDeathSound(EntityUid uid, DeathGaspsComponent component)
|
2024-01-17 19:34:15 +07:00
|
|
|
|
{
|
2024-07-02 12:55:25 +03:00
|
|
|
|
if (component.CanOtherHearDeathSound)
|
|
|
|
|
|
_audio.PlayPvs(component.DeathSounds, uid, AudioParams.Default);
|
|
|
|
|
|
else
|
|
|
|
|
|
_audio.PlayEntity(component.DeathSounds, uid, uid, AudioParams.Default);
|
2024-01-17 19:34:15 +07:00
|
|
|
|
}
|
2023-05-01 15:05:43 +06:00
|
|
|
|
|
2023-06-13 19:33:50 +00:00
|
|
|
|
private void OnDetach(EntityUid uid, DeathGaspsComponent component, PlayerDetachedEvent args)
|
2024-01-17 19:34:15 +07:00
|
|
|
|
{
|
|
|
|
|
|
StopPlayingStream(args.Entity);
|
|
|
|
|
|
}
|
2023-05-01 15:05:43 +06:00
|
|
|
|
}
|