From 36038a1707747b06f82e26471895f795a0dab99d Mon Sep 17 00:00:00 2001 From: IProduceWidgets <107586145+IProduceWidgets@users.noreply.github.com> Date: Fri, 2 Aug 2024 03:07:46 -0400 Subject: [PATCH] Allow ai to understand if its handcuffed. (#30402) * 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 --- .../Preconditions/HandcuffedPrecondition.cs | 26 +++++++++++++++++++ Content.Shared/Cuffs/SharedCuffableSystem.cs | 19 ++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 Content.Server/NPC/HTN/Preconditions/HandcuffedPrecondition.cs diff --git a/Content.Server/NPC/HTN/Preconditions/HandcuffedPrecondition.cs b/Content.Server/NPC/HTN/Preconditions/HandcuffedPrecondition.cs new file mode 100644 index 0000000000..4a56eeb953 --- /dev/null +++ b/Content.Server/NPC/HTN/Preconditions/HandcuffedPrecondition.cs @@ -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(); + var owner = blackboard.GetValue(NPCBlackboard.Owner); + + if (!_entManager.TryGetComponent(owner, out var cuffComp)) + return false; + + var target = (owner, cuffComp); + + return cuffable.IsCuffed(target, ReactOnlyWhenFullyCuffed); + } + +} diff --git a/Content.Shared/Cuffs/SharedCuffableSystem.cs b/Content.Shared/Cuffs/SharedCuffableSystem.cs index 3bf6066f33..8889e0c971 100644 --- a/Content.Shared/Cuffs/SharedCuffableSystem.cs +++ b/Content.Shared/Cuffs/SharedCuffableSystem.cs @@ -521,6 +521,25 @@ namespace Content.Shared.Cuffs return true; } + /// + /// Checks if the target is handcuffed. + /// + /// when true, return false if the target is only partially cuffed (for things with more than 2 hands) + /// + public bool IsCuffed(Entity target, bool requireFullyCuffed = true) + { + if (!TryComp(target, out var hands)) + return false; + + if (target.Comp.CuffedHandCount <= 0) + return false; + + if (requireFullyCuffed && hands.Count > target.Comp.CuffedHandCount) + return false; + + return true; + } + /// /// 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. -- 2.52.0