]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add wallbonk sound to BaseItem (#15689)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sun, 23 Apr 2023 17:42:09 +0000 (03:42 +1000)
committerGitHub <noreply@github.com>
Sun, 23 Apr 2023 17:42:09 +0000 (13:42 -0400)
Uses a chisel sound.

12 files changed:
Content.Server/Sound/EmitSoundSystem.cs
Content.Shared/Sound/Components/EmitSoundOnActivateComponent.cs
Content.Shared/Sound/Components/EmitSoundOnCollideComponent.cs [new file with mode: 0644]
Content.Shared/Sound/Components/EmitSoundOnDropComponent.cs
Content.Shared/Sound/Components/EmitSoundOnLandComponent.cs
Content.Shared/Sound/Components/EmitSoundOnPickupComponent.cs
Content.Shared/Sound/Components/EmitSoundOnThrowComponent.cs
Content.Shared/Sound/Components/EmitSoundOnUseComponent.cs
Content.Shared/Sound/SharedEmitSoundSystem.cs
Resources/Audio/Effects/licenses.txt
Resources/Audio/Effects/wall_bonk.ogg [new file with mode: 0644]
Resources/Prototypes/Entities/Objects/base_item.yml

index bc271a8351c691056ef264c4bca37b251c3ed24f..e4f9ebcb43669748e316d5084d87b4007e06cad2 100644 (file)
@@ -11,7 +11,9 @@ public sealed class EmitSoundSystem : SharedEmitSoundSystem
     public override void Update(float frameTime)
     {
         base.Update(frameTime);
-        foreach (var soundSpammer in EntityQuery<SpamEmitSoundComponent>())
+        var query = EntityQueryEnumerator<SpamEmitSoundComponent>();
+
+        while (query.MoveNext(out var uid, out var soundSpammer))
         {
             if (!soundSpammer.Enabled)
                 continue;
@@ -26,8 +28,8 @@ public sealed class EmitSoundSystem : SharedEmitSoundSystem
             if (Random.Prob(soundSpammer.PlayChance))
             {
                 if (soundSpammer.PopUp != null)
-                    Popup.PopupEntity(Loc.GetString(soundSpammer.PopUp), soundSpammer.Owner);
-                TryEmitSound(soundSpammer);
+                    Popup.PopupEntity(Loc.GetString(soundSpammer.PopUp), uid);
+                TryEmitSound(uid, soundSpammer);
             }
         }
     }
@@ -40,14 +42,14 @@ public sealed class EmitSoundSystem : SharedEmitSoundSystem
         SubscribeLocalEvent<EmitSoundOnUIOpenComponent, AfterActivatableUIOpenEvent>(HandleEmitSoundOnUIOpen);
     }
 
-    private void HandleEmitSoundOnUIOpen(EntityUid eUI, EmitSoundOnUIOpenComponent component, AfterActivatableUIOpenEvent args)
+    private void HandleEmitSoundOnUIOpen(EntityUid uid, EmitSoundOnUIOpenComponent component, AfterActivatableUIOpenEvent args)
     {
-        TryEmitSound(component, args.User);
+        TryEmitSound(uid, component, args.User);
     }
 
     private void HandleEmitSoundOnTrigger(EntityUid uid, EmitSoundOnTriggerComponent component, TriggerEvent args)
     {
-        TryEmitSound(component);
+        TryEmitSound(uid, component);
         args.Handled = true;
     }
 }
index 501195eb79fd7790c0da76c8541c2d0030634be3..5b5330a6d3c91541e087eaf7174eb4998f9dd0c6 100644 (file)
@@ -1,23 +1,22 @@
 using Robust.Shared.GameStates;
 
-namespace Content.Shared.Sound.Components
+namespace Content.Shared.Sound.Components;
+
+/// <summary>
+/// Simple sound emitter that emits sound on ActivateInWorld
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed class EmitSoundOnActivateComponent : BaseEmitSoundComponent
 {
     /// <summary>
-    /// Simple sound emitter that emits sound on ActivateInWorld
+    ///     Whether or not to mark an interaction as handled after playing the sound. Useful if this component is
+    ///     used to play sound for some other component with activation functionality.
     /// </summary>
-    [RegisterComponent, NetworkedComponent]
-    public sealed class EmitSoundOnActivateComponent : BaseEmitSoundComponent
-    {
-        /// <summary>
-        ///     Whether or not to mark an interaction as handled after playing the sound. Useful if this component is
-        ///     used to play sound for some other component with activation functionality.
-        /// </summary>
-        /// <remarks>
-        ///     If false, you should be confident that the interaction will also be handled by some other system, as
-        ///     otherwise this might enable sound spamming, as use-delays are only initiated if the interaction was
-        ///     handled.
-        /// </remarks>
-        [DataField("handle")]
-        public bool Handle = true;
-    }
+    /// <remarks>
+    ///     If false, you should be confident that the interaction will also be handled by some other system, as
+    ///     otherwise this might enable sound spamming, as use-delays are only initiated if the interaction was
+    ///     handled.
+    /// </remarks>
+    [DataField("handle")]
+    public bool Handle = true;
 }
diff --git a/Content.Shared/Sound/Components/EmitSoundOnCollideComponent.cs b/Content.Shared/Sound/Components/EmitSoundOnCollideComponent.cs
new file mode 100644 (file)
index 0000000..e800124
--- /dev/null
@@ -0,0 +1,22 @@
+using Robust.Shared.GameStates;
+using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
+
+namespace Content.Shared.Sound.Components;
+
+[RegisterComponent, NetworkedComponent]
+public sealed class EmitSoundOnCollideComponent : BaseEmitSoundComponent
+{
+    public static readonly TimeSpan CollideCooldown = TimeSpan.FromSeconds(0.2);
+
+    /// <summary>
+    /// Minimum velocity required for the sound to play.
+    /// </summary>
+    [ViewVariables(VVAccess.ReadWrite), DataField("minVelocity")]
+    public float MinimumVelocity = 0.25f;
+
+    /// <summary>
+    /// To avoid sound spam add a cooldown to it.
+    /// </summary>
+    [ViewVariables(VVAccess.ReadWrite), DataField("nextSound", customTypeSerializer:typeof(TimeOffsetSerializer))]
+    public TimeSpan NextSound;
+}
index 16a8e9995d63bf818954acadf42f2823df6d018d..d3c4206e9165126ab77d0f60f7592dfc2f99ccb7 100644 (file)
@@ -1,12 +1,11 @@
 using Robust.Shared.GameStates;
 
-namespace Content.Shared.Sound.Components
+namespace Content.Shared.Sound.Components;
+
+/// <summary>
+/// Simple sound emitter that emits sound on entity drop
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed class EmitSoundOnDropComponent : BaseEmitSoundComponent
 {
-    /// <summary>
-    /// Simple sound emitter that emits sound on entity drop
-    /// </summary>
-    [RegisterComponent, NetworkedComponent]
-    public sealed class EmitSoundOnDropComponent : BaseEmitSoundComponent
-    {
-    }
 }
index 8507d2d15efb683dd471d376d8d3a755241ec1b5..5bf3416bbefac848187fe7456d49993f705393cd 100644 (file)
@@ -1,12 +1,11 @@
 using Robust.Shared.GameStates;
 
-namespace Content.Shared.Sound.Components
+namespace Content.Shared.Sound.Components;
+
+/// <summary>
+/// Simple sound emitter that emits sound on LandEvent
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed class EmitSoundOnLandComponent : BaseEmitSoundComponent
 {
-    /// <summary>
-    /// Simple sound emitter that emits sound on LandEvent
-    /// </summary>
-    [RegisterComponent, NetworkedComponent]
-    public sealed class EmitSoundOnLandComponent : BaseEmitSoundComponent
-    {
-    }
 }
index 5fbb920f63e8bfac13a039c7652de29dece3741d..2b9cd96d055079970676dca87ec0fa167c701d7d 100644 (file)
@@ -1,12 +1,11 @@
 using Robust.Shared.GameStates;
 
-namespace Content.Shared.Sound.Components
+namespace Content.Shared.Sound.Components;
+
+/// <summary>
+/// Simple sound emitter that emits sound on entity pickup
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed class EmitSoundOnPickupComponent : BaseEmitSoundComponent
 {
-    /// <summary>
-    /// Simple sound emitter that emits sound on entity pickup
-    /// </summary>
-    [RegisterComponent, NetworkedComponent]
-    public sealed class EmitSoundOnPickupComponent : BaseEmitSoundComponent
-    {
-    }
 }
index d53d691e185965abdc9e7c0f3dac446224796d04..0b76e3305ed26720ace41a16459d5d2615304e55 100644 (file)
@@ -1,12 +1,11 @@
 using Robust.Shared.GameStates;
 
-namespace Content.Shared.Sound.Components
+namespace Content.Shared.Sound.Components;
+
+/// <summary>
+/// Simple sound emitter that emits sound on ThrowEvent
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed class EmitSoundOnThrowComponent : BaseEmitSoundComponent
 {
-    /// <summary>
-    /// Simple sound emitter that emits sound on ThrowEvent
-    /// </summary>
-    [RegisterComponent, NetworkedComponent]
-    public sealed class EmitSoundOnThrowComponent : BaseEmitSoundComponent
-    {
-    }
 }
index 6a7b1e120e4fb1dc2d27fff2867c6737d0e844ee..5bb95a5c11fba1747d0e72775b3e45df209b871f 100644 (file)
@@ -1,23 +1,22 @@
 using Robust.Shared.GameStates;
 
-namespace Content.Shared.Sound.Components
+namespace Content.Shared.Sound.Components;
+
+/// <summary>
+/// Simple sound emitter that emits sound on UseInHand
+/// </summary>
+[RegisterComponent]
+public sealed class EmitSoundOnUseComponent : BaseEmitSoundComponent
 {
     /// <summary>
-    /// Simple sound emitter that emits sound on UseInHand
+    ///     Whether or not to mark an interaction as handled after playing the sound. Useful if this component is
+    ///     used to play sound for some other component with on-use functionality
     /// </summary>
-    [RegisterComponent]
-    public sealed class EmitSoundOnUseComponent : BaseEmitSoundComponent
-    {
-        /// <summary>
-        ///     Whether or not to mark an interaction as handled after playing the sound. Useful if this component is
-        ///     used to play sound for some other component with on-use functionality
-        /// </summary>
-        /// <remarks>
-        ///     If false, you should be confident that the interaction will also be handled by some other system, as
-        ///     otherwise this might enable sound spamming, as use-delays are only initiated if the interaction was
-        ///     handled.
-        /// </remarks>
-        [DataField("handle")]
-        public bool Handle = true;
-    }
+    /// <remarks>
+    ///     If false, you should be confident that the interaction will also be handled by some other system, as
+    ///     otherwise this might enable sound spamming, as use-delays are only initiated if the interaction was
+    ///     handled.
+    /// </remarks>
+    [DataField("handle")]
+    public bool Handle = true;
 }
index c7bf5cf137c16a346fc492311895f2c5f89d8e96..86433d4967311d4960de419c7dd5579fe9b63576 100644 (file)
@@ -8,104 +8,122 @@ using Content.Shared.Throwing;
 using JetBrains.Annotations;
 using Robust.Shared.Map;
 using Robust.Shared.Network;
+using Robust.Shared.Physics.Components;
+using Robust.Shared.Physics.Events;
 using Robust.Shared.Random;
+using Robust.Shared.Timing;
 
-namespace Content.Shared.Sound
+namespace Content.Shared.Sound;
+
+/// <summary>
+/// Will play a sound on various events if the affected entity has a component derived from BaseEmitSoundComponent
+/// </summary>
+[UsedImplicitly]
+public abstract class SharedEmitSoundSystem : EntitySystem
 {
-    /// <summary>
-    /// Will play a sound on various events if the affected entity has a component derived from BaseEmitSoundComponent
-    /// </summary>
-    [UsedImplicitly]
-    public abstract class SharedEmitSoundSystem : EntitySystem
+    [Dependency] private readonly IGameTiming _timing = default!;
+    [Dependency] private readonly INetManager _netMan = default!;
+    [Dependency] private readonly IMapManager _mapManager = default!;
+    [Dependency] private readonly ITileDefinitionManager _tileDefMan = default!;
+    [Dependency] protected readonly IRobustRandom Random = default!;
+    [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
+    [Dependency] protected readonly SharedPopupSystem Popup = default!;
+
+    public override void Initialize()
     {
-        [Dependency] private readonly INetManager _netMan = default!;
-        [Dependency] private readonly IMapManager _mapManager = default!;
-        [Dependency] private readonly ITileDefinitionManager _tileDefMan = default!;
-        [Dependency] protected readonly IRobustRandom Random = default!;
-        [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
-        [Dependency] protected readonly SharedPopupSystem Popup = default!;
-
-        public override void Initialize()
-        {
-            base.Initialize();
-            SubscribeLocalEvent<EmitSoundOnSpawnComponent, ComponentInit>(HandleEmitSpawnOnInit);
-            SubscribeLocalEvent<EmitSoundOnLandComponent, LandEvent>(OnEmitSoundOnLand);
-            SubscribeLocalEvent<EmitSoundOnUseComponent, UseInHandEvent>(HandleEmitSoundOnUseInHand);
-            SubscribeLocalEvent<EmitSoundOnThrowComponent, ThrownEvent>(HandleEmitSoundOnThrown);
-            SubscribeLocalEvent<EmitSoundOnActivateComponent, ActivateInWorldEvent>(HandleEmitSoundOnActivateInWorld);
-            SubscribeLocalEvent<EmitSoundOnPickupComponent, GotEquippedHandEvent>(HandleEmitSoundOnPickup);
-            SubscribeLocalEvent<EmitSoundOnDropComponent, DroppedEvent>(HandleEmitSoundOnDrop);
-        }
+        base.Initialize();
+        SubscribeLocalEvent<EmitSoundOnSpawnComponent, ComponentInit>(OnEmitSpawnOnInit);
+        SubscribeLocalEvent<EmitSoundOnLandComponent, LandEvent>(OnEmitSoundOnLand);
+        SubscribeLocalEvent<EmitSoundOnUseComponent, UseInHandEvent>(OnEmitSoundOnUseInHand);
+        SubscribeLocalEvent<EmitSoundOnThrowComponent, ThrownEvent>(OnEmitSoundOnThrown);
+        SubscribeLocalEvent<EmitSoundOnActivateComponent, ActivateInWorldEvent>(OnEmitSoundOnActivateInWorld);
+        SubscribeLocalEvent<EmitSoundOnPickupComponent, GotEquippedHandEvent>(OnEmitSoundOnPickup);
+        SubscribeLocalEvent<EmitSoundOnDropComponent, DroppedEvent>(OnEmitSoundOnDrop);
+        SubscribeLocalEvent<EmitSoundOnCollideComponent, StartCollideEvent>(OnEmitSoundOnCollide);
+    }
 
-        private void HandleEmitSpawnOnInit(EntityUid uid, EmitSoundOnSpawnComponent component, ComponentInit args)
-        {
-            TryEmitSound(component, predict: false);
-        }
+    private void OnEmitSpawnOnInit(EntityUid uid, EmitSoundOnSpawnComponent component, ComponentInit args)
+    {
+        TryEmitSound(uid, component, predict: false);
+    }
 
-        private void OnEmitSoundOnLand(EntityUid uid, BaseEmitSoundComponent component, ref LandEvent args)
-        {
-            if (!TryComp<TransformComponent>(uid, out var xform) ||
-                !_mapManager.TryGetGrid(xform.GridUid, out var grid))
-                return;
+    private void OnEmitSoundOnLand(EntityUid uid, BaseEmitSoundComponent component, ref LandEvent args)
+    {
+        if (!TryComp<TransformComponent>(uid, out var xform) ||
+            !_mapManager.TryGetGrid(xform.GridUid, out var grid))
+            return;
 
-            var tile = grid.GetTileRef(xform.Coordinates);
+        var tile = grid.GetTileRef(xform.Coordinates);
 
-            // Handle maps being grids (we'll still emit the sound).
-            if (xform.GridUid != xform.MapUid && tile.IsSpace(_tileDefMan))
-                return;
+        // Handle maps being grids (we'll still emit the sound).
+        if (xform.GridUid != xform.MapUid && tile.IsSpace(_tileDefMan))
+            return;
 
-            // hand throwing not predicted sadly
-            TryEmitSound(component, args.User, false);
-        }
+        // hand throwing not predicted sadly
+        TryEmitSound(uid, component, args.User, false);
+    }
 
-        private void HandleEmitSoundOnUseInHand(EntityUid eUI, EmitSoundOnUseComponent component, UseInHandEvent args)
-        {
-            // Intentionally not checking whether the interaction has already been handled.
-            TryEmitSound(component, args.User);
+    private void OnEmitSoundOnUseInHand(EntityUid uid, EmitSoundOnUseComponent component, UseInHandEvent args)
+    {
+        // Intentionally not checking whether the interaction has already been handled.
+        TryEmitSound(uid, component, args.User);
 
-            if (component.Handle)
-                args.Handled = true;
-        }
+        if (component.Handle)
+            args.Handled = true;
+    }
 
-        private void HandleEmitSoundOnThrown(EntityUid eUI, BaseEmitSoundComponent component, ThrownEvent args)
-        {
-            TryEmitSound(component, args.User, false);
-        }
+    private void OnEmitSoundOnThrown(EntityUid uid, BaseEmitSoundComponent component, ThrownEvent args)
+    {
+        TryEmitSound(uid, component, args.User, false);
+    }
 
-        private void HandleEmitSoundOnActivateInWorld(EntityUid eUI, EmitSoundOnActivateComponent component, ActivateInWorldEvent args)
-        {
-            // Intentionally not checking whether the interaction has already been handled.
-            TryEmitSound(component, args.User);
+    private void OnEmitSoundOnActivateInWorld(EntityUid uid, EmitSoundOnActivateComponent component, ActivateInWorldEvent args)
+    {
+        // Intentionally not checking whether the interaction has already been handled.
+        TryEmitSound(uid, component, args.User);
 
-            if (component.Handle)
-                args.Handled = true;
-        }
+        if (component.Handle)
+            args.Handled = true;
+    }
+
+    private void OnEmitSoundOnPickup(EntityUid uid, EmitSoundOnPickupComponent component, GotEquippedHandEvent args)
+    {
+        TryEmitSound(uid, component, args.User);
+    }
+
+    private void OnEmitSoundOnDrop(EntityUid uid, EmitSoundOnDropComponent component, DroppedEvent args)
+    {
+        TryEmitSound(uid, component, args.User);
+    }
 
-        private void HandleEmitSoundOnPickup(EntityUid uid, EmitSoundOnPickupComponent component, GotEquippedHandEvent args)
+    protected void TryEmitSound(EntityUid uid, BaseEmitSoundComponent component, EntityUid? user=null, bool predict=true)
+    {
+        if (component.Sound == null)
+            return;
+
+        if (predict)
         {
-            TryEmitSound(component, args.User);
+            _audioSystem.PlayPredicted(component.Sound, uid, user);
         }
-
-        private void HandleEmitSoundOnDrop(EntityUid uid, EmitSoundOnDropComponent component, DroppedEvent args)
+        else if (_netMan.IsServer)
         {
-            TryEmitSound(component, args.User);
+            // don't predict sounds that client couldn't have played already
+            _audioSystem.PlayPvs(component.Sound, uid);
         }
+    }
 
-        protected void TryEmitSound(BaseEmitSoundComponent component, EntityUid? user=null, bool predict=true)
+    private void OnEmitSoundOnCollide(EntityUid uid, EmitSoundOnCollideComponent component, ref StartCollideEvent args)
+    {
+        if (!args.OurFixture.Hard ||
+            !args.OtherFixture.Hard ||
+            !TryComp<PhysicsComponent>(uid, out var physics) ||
+            physics.LinearVelocity.Length < component.MinimumVelocity ||
+            _timing.CurTime < component.NextSound)
         {
-            if (component.Sound == null)
-                return;
-
-            if (predict)
-            {
-                _audioSystem.PlayPredicted(component.Sound, component.Owner, user);
-            }
-            else if (_netMan.IsServer)
-            {
-                // don't predict sounds that client couldn't have played already
-                _audioSystem.PlayPvs(component.Sound, component.Owner);
-            }
+            return;
         }
+
+        component.NextSound = _timing.CurTime + EmitSoundOnCollideComponent.CollideCooldown;
+        TryEmitSound(uid, component, predict: false);
     }
 }
-
index 95d0d98f7092c795af7a2013a419308769a888c5..719cc77cd1f89b9391a27f96e8aed74db7b7664f 100644 (file)
@@ -50,4 +50,9 @@ box_deploy.ogg and chime.ogg taken from Citadel Station at commit: https://githu
    license: "Royalty free"
    copyright: "Sonniss.com - GDC 2016 - Game Audio Bundle - Levan Nadashvili - Soldier Footsteps - FS Concrete Soldier Crouch N02, mixed from stereo to mono"
 
+- files:
+      - "wall_bonk.ogg"
+  license: "Royalty free"
+  copyright: "Sonniss.com - GDC 2023 - Game Audio Bundle - 344 Audio - Nuts and Bolts"
+
 # Do not add to this list, I only did the above because yaml scheme validator doesn't like custom licenses.
diff --git a/Resources/Audio/Effects/wall_bonk.ogg b/Resources/Audio/Effects/wall_bonk.ogg
new file mode 100644 (file)
index 0000000..b1c5505
Binary files /dev/null and b/Resources/Audio/Effects/wall_bonk.ogg differ
index a9b70dd6622b7b8e3862853020a9cd09c4f2c06f..bd17cea8227d8cf35c8be6514844f7583fb8be14 100644 (file)
@@ -8,6 +8,11 @@
   - type: Clickable
   - type: InteractionOutline
   - type: MovedByPressure
+  - type: EmitSoundOnCollide
+    sound:
+      path: /Audio/Effects/wall_bonk.ogg
+      params:
+        volume: 2
   - type: EmitSoundOnLand
     sound:
       path: /Audio/Effects/drop.ogg