]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Allow ai to understand if its handcuffed. (#30402)
authorIProduceWidgets <107586145+IProduceWidgets@users.noreply.github.com>
Fri, 2 Aug 2024 07:07:46 +0000 (03:07 -0400)
committerGitHub <noreply@github.com>
Fri, 2 Aug 2024 07:07:46 +0000 (17:07 +1000)
* allow ai to understand if its handcuffed.

* rerun tests they worky on local

* Contained here in, a string of expletives about flaky tests.

* on retrospect, default true is probably smorter.

* do reviews

* I forgor xml

* more xml

Content.Server/NPC/HTN/Preconditions/HandcuffedPrecondition.cs [new file with mode: 0644]
Content.Shared/Cuffs/SharedCuffableSystem.cs

diff --git a/Content.Server/NPC/HTN/Preconditions/HandcuffedPrecondition.cs b/Content.Server/NPC/HTN/Preconditions/HandcuffedPrecondition.cs
new file mode 100644 (file)
index 0000000..4a56eeb
--- /dev/null
@@ -0,0 +1,26 @@
+using Content.Server.Cuffs;
+using Content.Shared.Cuffs.Components;
+
+namespace Content.Server.NPC.HTN.Preconditions;
+
+public sealed partial class HandcuffedPrecondition : HTNPrecondition
+{
+    [Dependency] private readonly IEntityManager _entManager = default!;
+
+    [DataField]
+    public bool ReactOnlyWhenFullyCuffed = true;
+
+    public override bool IsMet(NPCBlackboard blackboard)
+    {
+        var cuffable = _entManager.System<CuffableSystem>();
+        var owner = blackboard.GetValue<EntityUid>(NPCBlackboard.Owner);
+
+        if (!_entManager.TryGetComponent<CuffableComponent>(owner, out var cuffComp))
+            return false;
+
+        var target = (owner, cuffComp);
+
+        return cuffable.IsCuffed(target, ReactOnlyWhenFullyCuffed);
+    }
+
+}
index 3bf6066f3388c1ad5657464226e5e67443c7722d..8889e0c9710a20fbf55f37850131dd32b46474ca 100644 (file)
@@ -521,6 +521,25 @@ namespace Content.Shared.Cuffs
             return true;
         }
 
+        /// <summary>
+        /// Checks if the target is handcuffed.
+        /// </summary>
+        /// <param name="requireFullyCuffed">when true, return false if the target is only partially cuffed (for things with more than 2 hands)</param>
+        /// <returns></returns>
+        public bool IsCuffed(Entity<CuffableComponent> target, bool requireFullyCuffed = true)
+        {
+            if (!TryComp<HandsComponent>(target, out var hands))
+                return false;
+
+            if (target.Comp.CuffedHandCount <= 0)
+                return false;
+
+            if (requireFullyCuffed && hands.Count > target.Comp.CuffedHandCount)
+                return false;
+
+            return true;
+        }
+
         /// <summary>
         /// Attempt to uncuff a cuffed entity. Can be called by the cuffed entity, or another entity trying to help uncuff them.
         /// If the uncuffing succeeds, the cuffs will drop on the floor.