2 using System.Collections.Generic;
3 using System.Collections.Immutable;
21 private ImmutableArray<PropertyConditional> Conditionals {
get; }
23 [Serialize(
"",
IsPropertySaveable.Yes, description:
"A tag to apply to the hull the target is currently in when the check succeeds, as well as all the hulls linked to it.")]
26 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"A tag to apply to the hull the target is currently in when the check succeeds.")]
33 DebugConsole.LogError($
"CheckConditionalAction error: {GetEventDebugName()} uses a CheckConditionalAction with no target tag! This will cause the check to automatically succeed.",
37 if (conditionalElements.None())
44 var conditionalList =
new List<PropertyConditional>();
49 Conditionals = conditionalList.ToImmutableArray();
52 if (Conditionals.None())
54 DebugConsole.LogError($
"CheckConditionalAction error: {GetEventDebugName()} uses a CheckConditionalAction with no valid PropertyConditional! This will cause the check to automatically succeed.",
58 static bool IsConditionalAttribute(XAttribute attribute)
60 var nameAsIdentifier = attribute.NameAsIdentifier();
71 IEnumerable<ISerializableEntity> targets =
null;
79 DebugConsole.LogError($
"{nameof(CheckConditionalAction)} error: {GetEventDebugName()} uses a {nameof(CheckConditionalAction)} but no valid target was found for tag \"{TargetTag}\"! This will cause the check to automatically succeed.",
83 if (targets.None() || Conditionals.None())
85 foreach (var target
in targets)
94 foreach (var target
in targets)
96 if (ConditionalsMatch(target))
110 return Conditionals.All(c => ConditionalMatches(target, c));
114 return Conditionals.Any(c => ConditionalMatches(target, c));
118 private static bool ConditionalMatches(ISerializableEntity target, PropertyConditional conditional)
120 if (target is Item item)
122 if (!conditional.TargetItemComponent.IsNullOrEmpty() &&
123 item.Components.None(ic => ic.Name == conditional.TargetItemComponent))
127 return item.ConditionalMatches(conditional);
129 return conditional.Matches(target);
Checks whether an arbitrary condition is met. The conditionals work the same way as they do in Status...
override? bool DetermineSuccess()
Identifier ApplyTagToHull
Identifier ApplyTagToLinkedHulls
PropertyConditional.LogicalOperatorType LogicalOperator
CheckConditionalAction(ScriptedEvent parentEvent, ContentXElement element)
IEnumerable< ContentXElement > GetChildElements(string name)
readonly ScriptedEvent ParentEvent
void ApplyTagsToHulls(Entity entity, Identifier hullTag, Identifier linkedHullTag)
ContentPackage? ContentPackage
Conditionals are used by some in-game mechanics to require one or more conditions to be met for those...
static IEnumerable< PropertyConditional > FromXElement(ContentXElement element, Predicate< XAttribute >? predicate=null)
IEnumerable< Entity > GetTargets(Identifier tag)