Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
VigersRay committed Jan 15, 2025
2 parents d86ad2b + 5c9923f commit 6858313
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Content.Server/_Sunrise/CritHeartbeat/CritHeartbeatComponent.cs
Original file line number Diff line number Diff line change
@@ -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");

/// <summary>
/// Чтобы выключать это для наследников в прототипах
/// </summary>
[DataField]
public bool Enabled = true;

public EntityUid? AudioStream;
}
45 changes: 45 additions & 0 deletions Content.Server/_Sunrise/CritHeartbeat/CritHeartbeatSystem.cs
Original file line number Diff line number Diff line change
@@ -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<CritHeartbeatComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<CritHeartbeatComponent, DamageChangedEvent>(OnDamage);
}

private void OnMobStateChanged(Entity<CritHeartbeatComponent> 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<CritHeartbeatComponent> 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;
}
}
Binary file added Resources/Audio/_Sunrise/Effects/heartbeat.ogg
Binary file not shown.
9 changes: 9 additions & 0 deletions Resources/Changelog/ChangelogSunrise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions Resources/Prototypes/Entities/Mobs/Species/base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 6858313

Please sign in to comment.