]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add sounds when inserting/missing into a disposal (#22077)
authorzero <hello@enumerate.dev>
Sat, 2 Dec 2023 17:19:32 +0000 (11:19 -0600)
committerGitHub <noreply@github.com>
Sat, 2 Dec 2023 17:19:32 +0000 (12:19 -0500)
Content.Server/Disposal/Unit/EntitySystems/DisposalUnitSystem.cs
Content.Shared/Disposal/Components/SharedDisposalUnitComponent.cs

index 5408a1f521ae361d44b3ffe850d58ed52dec40b8..659566ca4319d8a3df969a84d7c2c9f97d45902a 100644 (file)
@@ -26,6 +26,7 @@ using Content.Shared.Movement.Events;
 using Content.Shared.Popups;
 using Content.Shared.Throwing;
 using Content.Shared.Verbs;
+using Robust.Server.Audio;
 using Robust.Server.GameObjects;
 using Robust.Shared.Containers;
 using Robust.Shared.GameStates;
@@ -45,6 +46,7 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
     [Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
     [Dependency] private readonly AppearanceSystem _appearance = default!;
     [Dependency] private readonly AtmosphereSystem _atmosSystem = default!;
+    [Dependency] private readonly AudioSystem _audioSystem = default!;
     [Dependency] private readonly DisposalTubeSystem _disposalTubeSystem = default!;
     [Dependency] private readonly EntityLookupSystem _lookup = default!;
     [Dependency] private readonly PopupSystem _popupSystem = default!;
@@ -304,14 +306,24 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
     /// </summary>
     private void OnThrowCollide(EntityUid uid, SharedDisposalUnitComponent component, ThrowHitByEvent args)
     {
-        if (!CanInsert(uid, component, args.Thrown) ||
-            _robustRandom.NextDouble() > 0.75 ||
-            !component.Container.Insert(args.Thrown))
+        var canInsert = CanInsert(uid, component, args.Thrown);
+        var randDouble = _robustRandom.NextDouble();
+
+        if (!canInsert || randDouble > 0.75)
         {
+            _audioSystem.PlayPvs(component.MissSound, uid);
+
             _popupSystem.PopupEntity(Loc.GetString("disposal-unit-thrown-missed"), uid);
             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)
             _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)
     {
+        _audioSystem.PlayPvs(component.InsertSound, uid);
+
         if (!component.Container.Insert(inserted))
             return;
 
index e1b78de5cd33026b1aa067a87941a32c99f8f28b..72586be1ec624922b784ff4d84f1bfa5619a8640 100644 (file)
@@ -17,6 +17,19 @@ public abstract partial class SharedDisposalUnitComponent : Component
     [ViewVariables(VVAccess.ReadWrite), DataField("soundFlush")]
     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>
     /// State for this disposals unit.
     /// </summary>