Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Звук сердцебиение в крите #1114

Merged
merged 9 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
ThereDrD0 marked this conversation as resolved.
Show resolved Hide resolved
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.
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
Loading