diff --git a/Content.Server/_Sunrise/CritHeartbeat/CritHeartbeatComponent.cs b/Content.Server/_Sunrise/CritHeartbeat/CritHeartbeatComponent.cs new file mode 100644 index 00000000000..b4a62e87a6d --- /dev/null +++ b/Content.Server/_Sunrise/CritHeartbeat/CritHeartbeatComponent.cs @@ -0,0 +1,18 @@ +using Robust.Shared.Audio; + +namespace Content.Server._Sunrise.CritHeartbeat; + +[RegisterComponent] +public sealed partial class CritHeartbeatComponent : Component +{ + [DataField] + public SoundSpecifier HeartbeatSound = new SoundPathSpecifier("/Audio/_Sunrise/Effects/heartbeat.ogg"); + + /// + /// Чтобы выключать это для наследников в прототипах + /// + [DataField] + public bool Enabled = true; + + public EntityUid? AudioStream; +} diff --git a/Content.Server/_Sunrise/CritHeartbeat/CritHeartbeatSystem.cs b/Content.Server/_Sunrise/CritHeartbeat/CritHeartbeatSystem.cs new file mode 100644 index 00000000000..dfa89d66846 --- /dev/null +++ b/Content.Server/_Sunrise/CritHeartbeat/CritHeartbeatSystem.cs @@ -0,0 +1,45 @@ +using Content.Shared.Damage; +using Content.Shared.Mobs; +using Robust.Server.Audio; +using Robust.Shared.Audio; + +namespace Content.Server._Sunrise.CritHeartbeat; + +public sealed class CritHeartbeatSystem : EntitySystem +{ + [Dependency] private readonly AudioSystem _audio = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnMobStateChanged); + SubscribeLocalEvent(OnDamage); + } + + private void OnMobStateChanged(Entity ent, ref MobStateChangedEvent args) + { + if (!ent.Comp.Enabled) + return; + + ent.Comp.AudioStream = args.NewMobState == MobState.Critical + ? _audio.PlayEntity(ent.Comp.HeartbeatSound, ent, ent)?.Entity + : _audio.Stop(ent.Comp.AudioStream); + } + + private void OnDamage(Entity ent, ref DamageChangedEvent args) + { + if (!ent.Comp.Enabled) + return; + + if (!Exists(ent.Comp.AudioStream)) + return; + + var pitch = Math.Min(1, 100 / args.Damageable.TotalDamage.Float()); + + // Потому что игра говно, тут нельзя изменять аудиопарамс уже существующего звука. Поэтому я пересоздаю его заново + // Это приводит к проигрыванию звука через неравномерные промежутки времени, но зато работает и не очень заметно + _audio.Stop(ent.Comp.AudioStream); + ent.Comp.AudioStream = _audio.PlayEntity(ent.Comp.HeartbeatSound, ent, ent, AudioParams.Default.WithPitchScale(pitch))?.Entity; + } +} diff --git a/Resources/Audio/_Sunrise/Effects/heartbeat.ogg b/Resources/Audio/_Sunrise/Effects/heartbeat.ogg new file mode 100644 index 00000000000..288bc882613 Binary files /dev/null and b/Resources/Audio/_Sunrise/Effects/heartbeat.ogg differ diff --git a/Resources/Changelog/ChangelogSunrise.yml b/Resources/Changelog/ChangelogSunrise.yml index 057f7a35e35..9a02eddbca3 100644 --- a/Resources/Changelog/ChangelogSunrise.yml +++ b/Resources/Changelog/ChangelogSunrise.yml @@ -10594,3 +10594,12 @@ id: 733 time: '2025-01-14T17:11:14.0000000+00:00' url: https://github.com/space-sunrise/space-station-14/pull/1113 +- author: ThereDrD + changes: + - message: "\u0414\u043E\u0431\u0430\u0432\u043B\u0435\u043D \u0437\u0432\u0443\u043A\ + \ \u0441\u0435\u0440\u0434\u0446\u0435\u0431\u0438\u0435\u043D\u0438\u044F \u0432\ + \ \u043A\u0440\u0438\u0442\u0435" + type: Add + id: 734 + time: '2025-01-15T15:26:33.0000000+00:00' + url: https://github.com/space-sunrise/space-station-14/pull/1114 diff --git a/Resources/Prototypes/Entities/Mobs/Species/base.yml b/Resources/Prototypes/Entities/Mobs/Species/base.yml index 1da01fcde1e..a1114c20e41 100644 --- a/Resources/Prototypes/Entities/Mobs/Species/base.yml +++ b/Resources/Prototypes/Entities/Mobs/Species/base.yml @@ -261,6 +261,12 @@ - type: Carriable - type: CanEscapeInventory - type: Mood + - type: CritHeartbeat + heartbeatSound: + path: /Audio/_Sunrise/Effects/heartbeat.ogg + params: + volume: -3 + loop: True # Sunrise-End - type: Barotrauma damage: