]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Landmine stepoff (#22962)
authorKISS <59531932+YuriyKiss@users.noreply.github.com>
Sun, 24 Mar 2024 05:33:45 +0000 (07:33 +0200)
committerGitHub <noreply@github.com>
Sun, 24 Mar 2024 05:33:45 +0000 (16:33 +1100)
* make landmine work on stepping off

* update methods naming

* made both step modes possible

* updated stepoff event raise to not interfere with game physics internals

* added comments

* figuring out how audiosystem works

* added beep sound effect, updated how stepoff trigger works to make it more consistent

* updated source in attributions.yml

* made stepoff working every time

* introduced suggested changes

* updated janitor's WetSignMine to have audio

* made cleaner events and bashing my head at OnEndCollide event raise

* inverted conditional where applicable

* review

---------

Co-authored-by: Yurii Kis <yurii.kis@smartteksas.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
13 files changed:
Content.Server/Ensnaring/EnsnareableSystem.Ensnaring.cs
Content.Server/Explosion/EntitySystems/TriggerSystem.cs
Content.Server/LandMines/LandMineComponent.cs
Content.Server/LandMines/LandMineSystem.cs
Content.Server/Tiles/LavaSystem.cs
Content.Shared/Chasm/ChasmSystem.cs
Content.Shared/Slippery/SlipperySystem.cs
Content.Shared/StepTrigger/Components/StepTriggerComponent.cs
Content.Shared/StepTrigger/Systems/StepTriggerSystem.cs
Resources/Audio/Effects/attributions.yml
Resources/Audio/Effects/beep_landmine.ogg [new file with mode: 0644]
Resources/Prototypes/Entities/Objects/Misc/land_mine.yml
Resources/Prototypes/Entities/Objects/Specific/Janitorial/janitor.yml

index 0c758141a195fee93768b17d2fc7b7e86cb40cba..105a8f9720de9f0264c7503e0f2369024e23d55f 100644 (file)
@@ -25,7 +25,7 @@ public sealed partial class EnsnareableSystem
     {
         SubscribeLocalEvent<EnsnaringComponent, ComponentRemove>(OnComponentRemove);
         SubscribeLocalEvent<EnsnaringComponent, StepTriggerAttemptEvent>(AttemptStepTrigger);
-        SubscribeLocalEvent<EnsnaringComponent, StepTriggeredEvent>(OnStepTrigger);
+        SubscribeLocalEvent<EnsnaringComponent, StepTriggeredOffEvent>(OnStepTrigger);
         SubscribeLocalEvent<EnsnaringComponent, ThrowDoHitEvent>(OnThrowHit);
         SubscribeLocalEvent<EnsnaringComponent, AttemptPacifiedThrowEvent>(OnAttemptPacifiedThrow);
     }
@@ -49,7 +49,7 @@ public sealed partial class EnsnareableSystem
         args.Continue = true;
     }
 
-    private void OnStepTrigger(EntityUid uid, EnsnaringComponent component, ref StepTriggeredEvent args)
+    private void OnStepTrigger(EntityUid uid, EnsnaringComponent component, ref StepTriggeredOffEvent args)
     {
         TryEnsnare(args.Tripper, uid, component);
     }
index 9b9a042641f17f5ae516b2063d27bf2cf1473cdc..e24de5a2f66fd2ab52d8d67d500c7046eac44753 100644 (file)
@@ -88,7 +88,7 @@ namespace Content.Server.Explosion.EntitySystems
             SubscribeLocalEvent<TriggerOnCollideComponent, StartCollideEvent>(OnTriggerCollide);
             SubscribeLocalEvent<TriggerOnActivateComponent, ActivateInWorldEvent>(OnActivate);
             SubscribeLocalEvent<TriggerImplantActionComponent, ActivateImplantEvent>(OnImplantTrigger);
-            SubscribeLocalEvent<TriggerOnStepTriggerComponent, StepTriggeredEvent>(OnStepTriggered);
+            SubscribeLocalEvent<TriggerOnStepTriggerComponent, StepTriggeredOffEvent>(OnStepTriggered);
             SubscribeLocalEvent<TriggerOnSlipComponent, SlipEvent>(OnSlipTriggered);
             SubscribeLocalEvent<TriggerWhenEmptyComponent, OnEmptyGunShotEvent>(OnEmptyTriggered);
 
@@ -228,7 +228,7 @@ namespace Content.Server.Explosion.EntitySystems
             args.Handled = Trigger(uid);
         }
 
-        private void OnStepTriggered(EntityUid uid, TriggerOnStepTriggerComponent component, ref StepTriggeredEvent args)
+        private void OnStepTriggered(EntityUid uid, TriggerOnStepTriggerComponent component, ref StepTriggeredOffEvent args)
         {
             Trigger(uid, args.Tripper);
         }
index 63e1e4b99f0925a84ef050f06580daaaaef4ca18..1c4ba06691a6fc9135a4a20e527c8a918506ec2a 100644 (file)
@@ -1,6 +1,13 @@
-namespace Content.Server.LandMines;
+using Robust.Shared.Audio;
+
+namespace Content.Server.LandMines;
 
 [RegisterComponent]
 public sealed partial class LandMineComponent : Component
 {
+    /// <summary>
+    /// Trigger sound effect when stepping onto landmine
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public SoundSpecifier? Sound;
 }
index 78c48ef99ec51d3dc930b2e470008048ed04cdc6..22dedb93375921f8b92762cdc84715bae61ddfe0 100644 (file)
@@ -1,43 +1,43 @@
-using Content.Server.Explosion.EntitySystems;
+using Content.Server.Explosion.EntitySystems;
 using Content.Shared.Popups;
-using Content.Shared.StepTrigger;
 using Content.Shared.StepTrigger.Systems;
-using Robust.Shared.Player;
+using Robust.Shared.Audio;
+using Robust.Shared.Audio.Systems;
 
 namespace Content.Server.LandMines;
 
 public sealed class LandMineSystem : EntitySystem
 {
+    [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
     [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
     [Dependency] private readonly TriggerSystem _trigger = default!;
 
-
     public override void Initialize()
     {
-        SubscribeLocalEvent<LandMineComponent, StepTriggeredEvent>(HandleTriggered);
-        SubscribeLocalEvent<LandMineComponent, StepTriggerAttemptEvent>(HandleTriggerAttempt);
+        SubscribeLocalEvent<LandMineComponent, StepTriggeredOnEvent>(HandleStepOnTriggered);
+        SubscribeLocalEvent<LandMineComponent, StepTriggeredOffEvent>(HandleStepOffTriggered);
+
+        SubscribeLocalEvent<LandMineComponent, StepTriggerAttemptEvent>(HandleStepTriggerAttempt);
     }
 
-    private static void HandleTriggerAttempt(
-        EntityUid uid,
-        LandMineComponent component,
-        ref StepTriggerAttemptEvent args)
+    private void HandleStepOnTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredOnEvent args)
     {
-        args.Continue = true;
+        _popupSystem.PopupCoordinates(
+            Loc.GetString("land-mine-triggered", ("mine", uid)),
+            Transform(uid).Coordinates,
+            args.Tripper,
+            PopupType.LargeCaution);
+
+        _audioSystem.PlayPvs(component.Sound, uid);
     }
 
-    private void HandleTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredEvent args)
+    private void HandleStepOffTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredOffEvent args)
     {
-        // This doesn't use TriggerOnStepTrigger since we don't want to display the popup if nothing happens
-        // and I didn't feel like making an `AfterTrigger` event
-        if (_trigger.Trigger(uid, args.Tripper))
-        {
-            _popupSystem.PopupCoordinates(
-                Loc.GetString("land-mine-triggered", ("mine", uid)),
-                Transform(uid).Coordinates,
-                args.Tripper,
-                PopupType.LargeCaution);
-        }
+        _trigger.Trigger(uid, args.Tripper);
     }
-}
 
+    private static void HandleStepTriggerAttempt(EntityUid uid, LandMineComponent component, ref StepTriggerAttemptEvent args)
+    {
+        args.Continue = true;
+    }
+}
index 7aee0b65010a01695d9c3eadc901612b8f03b729..51bd6f8475faa120b3e65eac0c018a3dd0e9bddf 100644 (file)
@@ -11,7 +11,7 @@ public sealed class LavaSystem : EntitySystem
     public override void Initialize()
     {
         base.Initialize();
-        SubscribeLocalEvent<LavaComponent, StepTriggeredEvent>(OnLavaStepTriggered);
+        SubscribeLocalEvent<LavaComponent, StepTriggeredOffEvent>(OnLavaStepTriggered);
         SubscribeLocalEvent<LavaComponent, StepTriggerAttemptEvent>(OnLavaStepTriggerAttempt);
     }
 
@@ -23,7 +23,7 @@ public sealed class LavaSystem : EntitySystem
         args.Continue = true;
     }
 
-    private void OnLavaStepTriggered(EntityUid uid, LavaComponent component, ref StepTriggeredEvent args)
+    private void OnLavaStepTriggered(EntityUid uid, LavaComponent component, ref StepTriggeredOffEvent args)
     {
         var otherUid = args.Tripper;
 
index 51299557dbd3f2cf967ffef355f880471518c401..86b8d4fc4d778c6a563c467d2c3bc828391bd4d4 100644 (file)
@@ -24,7 +24,7 @@ public sealed class ChasmSystem : EntitySystem
     {
         base.Initialize();
 
-        SubscribeLocalEvent<ChasmComponent, StepTriggeredEvent>(OnStepTriggered);
+        SubscribeLocalEvent<ChasmComponent, StepTriggeredOffEvent>(OnStepTriggered);
         SubscribeLocalEvent<ChasmComponent, StepTriggerAttemptEvent>(OnStepTriggerAttempt);
         SubscribeLocalEvent<ChasmFallingComponent, UpdateCanMoveEvent>(OnUpdateCanMove);
     }
@@ -47,7 +47,7 @@ public sealed class ChasmSystem : EntitySystem
         }
     }
 
-    private void OnStepTriggered(EntityUid uid, ChasmComponent component, ref StepTriggeredEvent args)
+    private void OnStepTriggered(EntityUid uid, ChasmComponent component, ref StepTriggeredOffEvent args)
     {
         // already doomed
         if (HasComp<ChasmFallingComponent>(args.Tripper))
index d20495cfa6c0603e21280950edf71f43fd5139cf..ff8b597a0d58590a21de27e3c98b216bdf942a9a 100644 (file)
@@ -31,14 +31,14 @@ public sealed class SlipperySystem : EntitySystem
         base.Initialize();
 
         SubscribeLocalEvent<SlipperyComponent, StepTriggerAttemptEvent>(HandleAttemptCollide);
-        SubscribeLocalEvent<SlipperyComponent, StepTriggeredEvent>(HandleStepTrigger);
+        SubscribeLocalEvent<SlipperyComponent, StepTriggeredOffEvent>(HandleStepTrigger);
         SubscribeLocalEvent<NoSlipComponent, SlipAttemptEvent>(OnNoSlipAttempt);
         SubscribeLocalEvent<ThrownItemComponent, SlipCausingAttemptEvent>(OnThrownSlipAttempt);
         // as long as slip-resistant mice are never added, this should be fine (otherwise a mouse-hat will transfer it's power to the wearer).
         SubscribeLocalEvent<NoSlipComponent, InventoryRelayedEvent<SlipAttemptEvent>>((e, c, ev) => OnNoSlipAttempt(e, c, ev.Args));
     }
 
-    private void HandleStepTrigger(EntityUid uid, SlipperyComponent component, ref StepTriggeredEvent args)
+    private void HandleStepTrigger(EntityUid uid, SlipperyComponent component, ref StepTriggeredOffEvent args)
     {
         TrySlip(uid, component, args.Tripper);
     }
index f4731bf46abd12c885bc6605950dc6b8e3c8463a..b8483d021a4a71919fdff37968951094412c55af 100644 (file)
@@ -49,8 +49,14 @@ public sealed partial class StepTriggerComponent : Component
     ///     If this is true, steptrigger will still occur on entities that are in air / weightless. They do not
     ///     by default.
     /// </summary>
-    [DataField]
+    [DataField, AutoNetworkedField]
     public bool IgnoreWeightless;
+
+    /// <summary>
+    /// Does this have separate "StepOn" and "StepOff" triggers.
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool StepOn = false;
 }
 
 [RegisterComponent]
index ede39b2aa97ab5e59210a2fd24638c4e74c7f5c8..b4ac2cde75637207c55849a64c22d9a4c492596b 100644 (file)
@@ -11,6 +11,7 @@ public sealed class StepTriggerSystem : EntitySystem
 {
     [Dependency] private readonly EntityLookupSystem _entityLookup = default!;
     [Dependency] private readonly SharedGravitySystem _gravity = default!;
+    [Dependency] private readonly SharedMapSystem _map = default!;
 
     public override void Initialize()
     {
@@ -40,7 +41,9 @@ public sealed class StepTriggerSystem : EntitySystem
         while (enumerator.MoveNext(out var uid, out var active, out var trigger, out var transform))
         {
             if (!Update(uid, trigger, transform, query))
+            {
                 continue;
+            }
 
             RemCompDeferred(uid, active);
         }
@@ -56,7 +59,8 @@ public sealed class StepTriggerSystem : EntitySystem
 
         if (component.Blacklist != null && TryComp<MapGridComponent>(transform.GridUid, out var grid))
         {
-            var anch = grid.GetAnchoredEntitiesEnumerator(grid.LocalToTile(transform.Coordinates));
+            var positon = _map.LocalToTile(uid, grid, transform.Coordinates);
+            var anch = _map.GetAnchoredEntitiesEnumerator(uid, grid, positon);
 
             while (anch.MoveNext(out var ent))
             {
@@ -109,8 +113,16 @@ public sealed class StepTriggerSystem : EntitySystem
             return;
         }
 
-        var ev = new StepTriggeredEvent { Source = uid, Tripper = otherUid };
-        RaiseLocalEvent(uid, ref ev, true);
+        if (component.StepOn)
+        {
+            var evStep = new StepTriggeredOnEvent(uid, otherUid);
+            RaiseLocalEvent(uid, ref evStep);
+        }
+        else
+        {
+            var evStep = new StepTriggeredOffEvent(uid, otherUid);
+            RaiseLocalEvent(uid, ref evStep);
+        }
 
         component.CurrentlySteppedOn.Add(otherUid);
         Dirty(uid, component);
@@ -130,7 +142,7 @@ public sealed class StepTriggerSystem : EntitySystem
 
         var msg = new StepTriggerAttemptEvent { Source = uid, Tripper = otherUid };
 
-        RaiseLocalEvent(uid, ref msg, true);
+        RaiseLocalEvent(uid, ref msg);
 
         return msg.Continue && !msg.Cancelled;
     }
@@ -163,6 +175,12 @@ public sealed class StepTriggerSystem : EntitySystem
         component.CurrentlySteppedOn.Remove(otherUid);
         Dirty(uid, component);
 
+        if (component.StepOn)
+        {
+            var evStepOff = new StepTriggeredOffEvent(uid, otherUid);
+            RaiseLocalEvent(uid, ref evStepOff);
+        }
+
         if (component.Colliding.Count == 0)
         {
             RemCompDeferred<StepTriggerActiveComponent>(uid);
@@ -230,9 +248,14 @@ public struct StepTriggerAttemptEvent
     public bool Cancelled;
 }
 
+/// <summary>
+/// Raised when an entity stands on a steptrigger initially (assuming it has both on and off states).
+/// </summary>
 [ByRefEvent]
-public struct StepTriggeredEvent
-{
-    public EntityUid Source;
-    public EntityUid Tripper;
-}
+public readonly record struct StepTriggeredOnEvent(EntityUid Source, EntityUid Tripper);
+
+/// <summary>
+/// Raised when an entity leaves a steptrigger if it has on and off states OR when an entity intersects a steptrigger.
+/// </summary>
+[ByRefEvent]
+public readonly record struct StepTriggeredOffEvent(EntityUid Source, EntityUid Tripper);
index a5f91ef10c68fececcbb40b721756bf953419a9a..4d2ba44925dcefbb9fe0ba43480ead4d286b4328 100644 (file)
   copyright: TGStation at 3df5d3b42bfb6b3b5adba1067ab41f83816255bb
   license: CC-BY-SA-3.0
   source: https://github.com/tgstation/tgstation/blob/3df5d3b42bfb6b3b5adba1067ab41f83816255bb/sound/misc/server-ready.ogg
+
+- files: [beep_landmine.ogg]
+  copyright: '"beep_landmine.ogg" by kaktuscsc of Discord for SS14'
+  license: "CC-BY-SA-3.0"
+  source: https://github.com/YuriyKiss/space-station-14/commit/971a135a9c83aed46e967aac9302ab5b35562b5f
diff --git a/Resources/Audio/Effects/beep_landmine.ogg b/Resources/Audio/Effects/beep_landmine.ogg
new file mode 100644 (file)
index 0000000..48bc5e2
Binary files /dev/null and b/Resources/Audio/Effects/beep_landmine.ogg differ
index 9088edc81599eb944a51bd15f3d8c5004614c0f5..a3e3485bc652ba245c313a3d8cb558a78ccf02a7 100644 (file)
       - !type:DoActsBehavior
         acts: [ "Destruction" ]
   - type: LandMine
-  - type: TriggerOnStepTrigger
+    sound:
+        path: /Audio/Effects/beep_landmine.ogg
+        params:
+            maxDistance: 10
   - type: StepTrigger
     requiredTriggeredSpeed: 0
+    stepOn: true
 
 - type: entity
   name: kick mine
@@ -57,7 +61,6 @@
   - type: Construction
     graph: ModularMineGraph
     node: emptyCase
-  - type: LandMine
 
 - type: entity
   name: explosive mine
@@ -71,4 +74,3 @@
     intensitySlope: 3
     totalIntensity: 120 # about a ~4 tile radius
     canCreateVacuum: false
-  - type: DeleteOnTrigger
index 8d3c83e3e1e3fab2d80373ac066df40491adc573..2ddb21b9e6cb73f26539bac54742ef4a2e6d5009 100644 (file)
   - type: StepTrigger
     intersectRatio: 0.2
     requiredTriggeredSpeed: 0
+    stepOn: true
   - type: CollisionWake
     enabled: false
   - type: Physics
         mask:
         - ItemMask
   - type: LandMine
+    sound:
+      path: /Audio/Effects/beep_landmine.ogg
+      params:
+        maxDistance: 10
   - type: ExplodeOnTrigger
   - type: Explosive
     explosionType: HardBomb  # normally Default and max 5 total 60