Add sounds when inserting/missing into a disposal (#22077)

This commit is contained in:
zero
2023-12-02 11:19:32 -06:00
committed by GitHub
parent 008a541885
commit 68a71655d2
2 changed files with 30 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ using Content.Shared.Movement.Events;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Server.Audio;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
@@ -45,6 +46,7 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!; [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly AppearanceSystem _appearance = default!; [Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly AtmosphereSystem _atmosSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosSystem = default!;
[Dependency] private readonly AudioSystem _audioSystem = default!;
[Dependency] private readonly DisposalTubeSystem _disposalTubeSystem = default!; [Dependency] private readonly DisposalTubeSystem _disposalTubeSystem = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!; [Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!; [Dependency] private readonly PopupSystem _popupSystem = default!;
@@ -304,14 +306,24 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
/// </summary> /// </summary>
private void OnThrowCollide(EntityUid uid, SharedDisposalUnitComponent component, ThrowHitByEvent args) private void OnThrowCollide(EntityUid uid, SharedDisposalUnitComponent component, ThrowHitByEvent args)
{ {
if (!CanInsert(uid, component, args.Thrown) || var canInsert = CanInsert(uid, component, args.Thrown);
_robustRandom.NextDouble() > 0.75 || var randDouble = _robustRandom.NextDouble();
!component.Container.Insert(args.Thrown))
if (!canInsert || randDouble > 0.75)
{ {
_audioSystem.PlayPvs(component.MissSound, uid);
_popupSystem.PopupEntity(Loc.GetString("disposal-unit-thrown-missed"), uid); _popupSystem.PopupEntity(Loc.GetString("disposal-unit-thrown-missed"), uid);
return; return;
} }
var inserted = _containerSystem.Insert(args.Thrown, component.Container);
if (!inserted)
{
throw new InvalidOperationException("Container insertion failed but CanInsert returned true");
}
if (args.Component.Thrower != null) if (args.Component.Thrower != null)
_adminLogger.Add(LogType.Landed, LogImpact.Low, $"{ToPrettyString(args.Thrown)} thrown by {ToPrettyString(args.Component.Thrower.Value):player} landed in {ToPrettyString(uid)}"); _adminLogger.Add(LogType.Landed, LogImpact.Low, $"{ToPrettyString(args.Thrown)} thrown by {ToPrettyString(args.Component.Thrower.Value):player} landed in {ToPrettyString(uid)}");
@@ -786,6 +798,8 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
public void AfterInsert(EntityUid uid, SharedDisposalUnitComponent component, EntityUid inserted, EntityUid? user = null) public void AfterInsert(EntityUid uid, SharedDisposalUnitComponent component, EntityUid inserted, EntityUid? user = null)
{ {
_audioSystem.PlayPvs(component.InsertSound, uid);
if (!component.Container.Insert(inserted)) if (!component.Container.Insert(inserted))
return; return;

View File

@@ -17,6 +17,19 @@ public abstract partial class SharedDisposalUnitComponent : Component
[ViewVariables(VVAccess.ReadWrite), DataField("soundFlush")] [ViewVariables(VVAccess.ReadWrite), DataField("soundFlush")]
public SoundSpecifier? FlushSound = new SoundPathSpecifier("/Audio/Machines/disposalflush.ogg"); public SoundSpecifier? FlushSound = new SoundPathSpecifier("/Audio/Machines/disposalflush.ogg");
/// <summary>
/// Sound played when an object is inserted into the disposal unit.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("soundInsert")]
public SoundSpecifier? InsertSound = new SoundPathSpecifier("/Audio/Effects/trashbag1.ogg");
/// <summary>
/// Sound played when an item is thrown and misses the disposal unit.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("soundMiss")]
public SoundSpecifier? MissSound = new SoundPathSpecifier("/Audio/Effects/thudswoosh.ogg");
/// <summary> /// <summary>
/// State for this disposals unit. /// State for this disposals unit.
/// </summary> /// </summary>