-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add: crit heartbeat sound * fix: fix strange things happening on second crit * add: disable option for children in prototypes * add: shitty implementation of health-relative pitch scale * clean up * review requested changes * review requested changes * changes 2
- Loading branch information
Showing
4 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Content.Server/_Sunrise/CritHeartbeat/CritHeartbeatComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
Content.Server/_Sunrise/CritHeartbeat/CritHeartbeatSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters