using System.Linq; using Content.Shared.EntityConditions; using Robust.Shared.Prototypes; namespace Content.Shared._DV.EntityConditions.Conditions; /// /// Reagent effect condition that depends on if the entity has a given component(s), potentially on a body part. /// /// public sealed partial class HasComponentsConditionSystem : EntityConditionSystem { [Dependency] private readonly EntityManager _ent = default!; protected override void Condition(Entity entity, ref EntityConditionEvent args) { var targetEntity = entity.Owner; if (!targetEntity.IsValid()) { args.Result = !args.Condition.ShouldHave; return; } var tested = args.Condition.ConsiderAll ? args.Condition.Components.Values.All(c => _ent.HasComponent(targetEntity, c.Component.GetType())) : args.Condition.Components.Values.Any(c => _ent.HasComponent(targetEntity, c.Component.GetType())); args.Result = tested ^ !args.Condition.ShouldHave; } } /// public sealed partial class HasComponentCondition : EntityConditionBase { /// /// The set of components that this condition cares about /// [DataField(required: true)] public ComponentRegistry Components; /// /// Whether or not the given components should be present /// [DataField] public bool ShouldHave = true; /// /// Whether the check is an existential or universal check /// [DataField] public bool ConsiderAll; /// /// The explanation displayed in the guidebook for this condition /// [DataField(required: true)] public LocId Explanation; public override string EntityConditionGuidebookText(IPrototypeManager prototype) => Loc.GetString(Explanation); }