--- /dev/null
+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);
+ }
+
+}
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.