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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user