]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add blacklist support for steptriggers (#14354)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 6 Mar 2023 19:11:27 +0000 (06:11 +1100)
committerGitHub <noreply@github.com>
Mon, 6 Mar 2023 19:11:27 +0000 (11:11 -0800)
Content.Shared/StepTrigger/Components/StepTriggerComponent.cs
Content.Shared/StepTrigger/Systems/StepTriggerSystem.cs
Resources/Prototypes/Entities/Structures/catwalk.yml
Resources/Prototypes/Entities/Tiles/lava.yml
Resources/Prototypes/tags.yml

index 0e0e48f25d547c843e5fb3572602c43616454221..4fe47093799240f3ee91807d7e372b0f0b9a9a94 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Shared.StepTrigger.Systems;
+using Content.Shared.Whitelist;
 using Robust.Shared.GameStates;
 using Robust.Shared.Serialization;
 
@@ -39,6 +40,12 @@ public sealed class StepTriggerComponent : Component
     /// </summary>
     [DataField("requiredTriggeredSpeed")]
     public float RequiredTriggerSpeed = 3.5f;
+
+    /// <summary>
+    /// If any entities occupy the blacklist on the same tile then steptrigger won't work.
+    /// </summary>
+    [DataField("blacklist")]
+    public EntityWhitelist? Blacklist;
 }
 
 [RegisterComponent]
index b6398ca21db6204fa5ac2bca579a8c877c297434..44274e0d7cee151f02713505b0282ca13e533f21 100644 (file)
@@ -1,6 +1,8 @@
 using Content.Shared.StepTrigger.Components;
+using Content.Shared.Tag;
 using Robust.Shared.Collections;
 using Robust.Shared.GameStates;
+using Robust.Shared.Map.Components;
 using Robust.Shared.Physics;
 using Robust.Shared.Physics.Components;
 using Robust.Shared.Physics.Events;
@@ -37,20 +39,38 @@ public sealed class StepTriggerSystem : EntitySystem
         var query = GetEntityQuery<PhysicsComponent>();
         var enumerator = EntityQueryEnumerator<StepTriggerActiveComponent, StepTriggerComponent, TransformComponent>();
 
-        while (enumerator.MoveNext(out var active, out var trigger, out var transform))
+        while (enumerator.MoveNext(out var uid, out var active, out var trigger, out var transform))
         {
-            if (!Update(trigger, transform, query))
+            if (!Update(uid, trigger, transform, query))
                 continue;
 
-            RemCompDeferred(trigger.Owner, active);
+            RemCompDeferred(uid, active);
         }
     }
 
-    private bool Update(StepTriggerComponent component, TransformComponent transform, EntityQuery<PhysicsComponent> query)
+    private bool Update(EntityUid uid, StepTriggerComponent component, TransformComponent transform, EntityQuery<PhysicsComponent> query)
     {
         if (!component.Active ||
             component.Colliding.Count == 0)
+        {
             return true;
+        }
+
+        if (component.Blacklist != null && TryComp<MapGridComponent>(transform.GridUid, out var grid))
+        {
+            var anch = grid.GetAnchoredEntitiesEnumerator(grid.LocalToTile(transform.Coordinates));
+
+            while (anch.MoveNext(out var ent))
+            {
+                if (ent == uid)
+                    continue;
+
+                if (component.Blacklist.IsValid(ent.Value, EntityManager) == true)
+                {
+                    return false;
+                }
+            }
+        }
 
         foreach (var otherUid in component.Colliding)
         {
index 16b13946ef4ce5726424cd3f3b80764081865ff2..3fbe08dd644803aa5ab3f3f8eb1386534f380b20 100644 (file)
@@ -22,6 +22,9 @@
   - type: FootstepModifier
     footstepSoundCollection:
       collection: FootstepCatwalk
+  - type: Tag
+    tags:
+      - Catwalk
   - type: Construction
     graph: Catwalk
     node: Catwalk
index 5d17c23692d5a7e5085fe1ad9e45549f9957b314..40eac1a75113f68edee768b231d961692dac4f9e 100644 (file)
@@ -9,6 +9,9 @@
   - type: StepTrigger
     requiredTriggeredSpeed: 0
     intersectRatio: 0.1
+    blacklist:
+      tags:
+        - Catwalk
   - type: Lava
   - type: Transform
     anchored: true
index 5e353bf8fd9a4bbbaf41e4fbc9ce5febb6ed7482..312d1a197edb501217db20470e842555bdf0593c 100644 (file)
 - type: Tag
   id: CartridgeRocket
 
+# Allows you to walk over tile entities such as lava without steptrigger
+- type: Tag
+  id: Catwalk
+
 - type: Tag
   id: Cigarette