3 using System.Collections.Generic;
16 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"Optional second tag. Can be used if the target must have two different tags.")]
22 [
Serialize(-1,
IsPropertySaveable.Yes, description:
"Minimum number of matching entities for the check to succeed. If omitted or negative, there is no minimum amount.")]
25 [
Serialize(-1,
IsPropertySaveable.Yes, description:
"Maximum number of matching entities for the check to succeed. If omitted or negative, there is no maximum amount.")]
28 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"Tag of some other entities to compare the number of targets to. E.g. you could compare the number of entities tagged as \"discoveredhull\" to entities tagged as \"anyhull\". The minimum/maximum amount of entities there must be relative to the other entities is configured using MinPercentageRelativeToTarget and MaxPercentageRelativeToTarget.")]
31 [
Serialize(-1.0f,
IsPropertySaveable.Yes, description:
"Minimum amount of targets, as a percentage of the number of entities tagged with CompareToTarget. E.g. you could compare the number of entities tagged as \"discoveredhull\" to entities tagged as \"anyhull\" to require 50% of hulls to be discovered.")]
34 [
Serialize(-1.0f,
IsPropertySaveable.Yes, description:
"Maximum amount of targets, as a percentage of the number of entities tagged with CompareToTarget. E.g. you could compare the number of entities tagged as \"floodedhull\" to entities tagged as \"anyhull\" to require less than 50% of hulls to be flooded.")]
37 private readonly IReadOnlyList<PropertyConditional> conditionals;
41 var conditionalList =
new List<PropertyConditional>();
46 conditionals = conditionalList;
50 int amount = element.GetAttributeInt(
"amount", -1);
57 DebugConsole.ThrowError($
"Error in event \"{ParentEvent.Prefab.Identifier}\". {MinAmount} is larger than {MaxAmount} in {nameof(CountTargetsAction)}.",
58 contentPackage: element.ContentPackage);
65 DebugConsole.ThrowError($
"Error in event \"{ParentEvent.Prefab.Identifier}\". Comparing to another target, but neither {nameof(MinPercentageRelativeToTarget)} or {nameof(MaxPercentageRelativeToTarget)} is set.",
66 contentPackage: element.ContentPackage);
82 potentialTargets = potentialTargets.Where(t =>
83 (t is
Item it && hulls.Contains(it.CurrentHull)) ||
84 (t is
Character c && hulls.Contains(c.CurrentHull)));
87 if (conditionals.Any())
89 potentialTargets = potentialTargets.Where(t => conditionals.Any(c => c.Matches(t as
ISerializableEntity)));
92 int targetCount = potentialTargets.Count();
102 float percentage = MathUtils.Percentage(targetCount, compareToTargetCount);
111 return $
"{ToolBox.GetDebugSymbol(HasBeenDetermined())} {nameof(CountTargetsAction)} -> (TargetTag: {TargetTag.ColorizeObject()}, " +
112 $
"Succeeded: {succeeded.ColorizeObject()})";
IEnumerable< ContentXElement > GetChildElements(string name)
Check whether there's at least / at most some number of entities matching some specific criteria.
float MinPercentageRelativeToTarget
override string ToDebugString()
Rich test to display in debugdraw
Identifier CompareToTarget
float MaxPercentageRelativeToTarget
override? bool DetermineSuccess()
CountTargetsAction(ScriptedEvent parentEvent, ContentXElement element)
Identifier SecondRequiredTargetTag
readonly ScriptedEvent ParentEvent
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)