* checkpoint * pt 2 * pt... i forgot * pt 4 * patch * More test fixes * optimization!!! * the REAL hand system * fix RetractableItemActionSystem.cs oversight * the review * test * remove test usage of body prototype * Update Content.IntegrationTests/Tests/Interaction/InteractionTest.cs Co-authored-by: Tayrtahn <tayrtahn@gmail.com> * hellcode * hellcode 2 * Minor cleanup * test * Chasing the last of the bugs * changes --------- Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using Content.Server.Hands.Systems;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.NPC.HTN.Preconditions;
|
|
|
|
/// <summary>
|
|
/// Returns true if the active hand entity has the specified components.
|
|
/// </summary>
|
|
public sealed partial class ActiveHandComponentPrecondition : HTNPrecondition
|
|
{
|
|
[Dependency] private readonly IEntityManager _entManager = default!;
|
|
|
|
[DataField("invert")]
|
|
public bool Invert;
|
|
|
|
[DataField("components", required: true)]
|
|
public ComponentRegistry Components = new();
|
|
|
|
public override bool IsMet(NPCBlackboard blackboard)
|
|
{
|
|
if (!blackboard.TryGetValue<EntityUid>(NPCBlackboard.Owner, out var owner, _entManager) ||
|
|
!blackboard.TryGetValue<string>(NPCBlackboard.ActiveHand, out var hand, _entManager))
|
|
{
|
|
return Invert;
|
|
}
|
|
|
|
if (!_entManager.System<HandsSystem>().TryGetHeldItem(owner, hand, out var entity))
|
|
return Invert;
|
|
|
|
foreach (var comp in Components)
|
|
{
|
|
var hasComp = _entManager.HasComponent(entity, comp.Value.Component.GetType());
|
|
|
|
if (!hasComp ||
|
|
Invert && hasComp)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|