15 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"The condition that must be met for the check to succeed. Uses the same formatting as conditionals (for example, \"gt 5.2\", \"true\", \"lt 10\".)")]
18 [
Serialize(
false,
IsPropertySaveable.Yes,
"Forces the comparison to use string instead of attempting to parse it as a boolean or a float first. Use this if you know the value is a string.")]
21 [
Serialize(
false,
IsPropertySaveable.Yes,
"Performs the comparison against a metadata by identifier instead of a constant value. Meaning that you could for example check whether the value of \"progress_of_some_event\" is larger than \"progress_of_some_other_event\".")]
36 DebugConsole.ThrowError($
"Error in scripted event \"{parentEvent.Prefab.Identifier}\". CheckDataAction with no condition set ({element}).",
49 DebugConsole.ThrowError($
"Error in scripted event \"{parentDebugString}\". CheckDataAction with no condition set ({element}).",
67 DebugConsole.ThrowError($
"{Condition} is invalid, it should start with an operator followed by a boolean or a floating point value.",
74 object? metadata1 = campaignMode.CampaignMetadata.GetValue(
Identifier);
75 object? metadata2 = campaignMode.CampaignMetadata.GetValue(value.ToIdentifier());
77 if (metadata1 ==
null || metadata2 ==
null)
91 case bool bool1 when metadata2 is
bool bool2:
92 return CompareBool(bool1, bool2) ??
false;
93 case float float1 when metadata2 is
float float2:
98 if (metadata1 is
string string1 && metadata2 is
string string2)
100 return CompareString(string1, string2) ??
false;
108 bool? tryBoolean = TryBoolean(campaignMode, value);
109 if (tryBoolean !=
null) {
return tryBoolean; }
111 bool? tryFloat = TryFloat(campaignMode, value);
112 if (tryFloat !=
null) {
return tryFloat; }
115 bool? tryString = TryString(campaignMode, value);
116 if (tryString !=
null) {
return tryString; }
121 private bool? TryBoolean(
CampaignMode campaignMode,
string value)
123 if (
bool.TryParse(value, out
bool b))
125 return CompareBool(
GetBool(campaignMode), b);
128 DebugConsole.Log($
"{value} != bool");
132 private bool? CompareBool(
bool val1,
bool val2)
138 case PropertyConditional.ComparisonOperatorType.Equals:
140 case PropertyConditional.ComparisonOperatorType.NotEquals:
143 DebugConsole.Log($
"Only \"Equals\" and \"Not equals\" operators are allowed for a boolean (was {Operator} for {val2}).");
148 private bool? TryFloat(CampaignMode campaignMode,
string value)
150 if (
float.TryParse(value, out
float f))
152 return PropertyConditional.CompareFloat(
GetFloat(campaignMode), f,
Operator);
155 DebugConsole.Log($
"{value} != float");
159 private bool? TryString(CampaignMode campaignMode,
string value)
161 return CompareString(GetString(campaignMode), value);
164 private bool? CompareString(
string val1,
string val2)
168 bool equals =
string.Equals(val1, val2, StringComparison.OrdinalIgnoreCase);
171 case PropertyConditional.ComparisonOperatorType.Equals:
173 case PropertyConditional.ComparisonOperatorType.NotEquals:
176 DebugConsole.Log($
"Only \"Equals\" and \"Not equals\" operators are allowed for a string (was {Operator} for {val2}).");
198 string condition =
"?";
201 condition = $
"{value1.ColorizeObject()} {Operator.ColorizeObject()} {value2.ColorizeObject()}";
205 condition = $
"{Identifier} {Condition}".ColorizeObject();
208 return $
"{ToolBox.GetDebugSymbol(succeeded.HasValue)} {nameof(CheckDataAction)} -> (Data: {Identifier.ColorizeObject()}, Success: {succeeded.ColorizeObject()}, Expression: {condition})";
readonly CampaignMetadata CampaignMetadata
Can be used to check arbitrary campaign metadata set using SetDataAction.
override string ToDebugString()
Rich test to display in debugdraw
virtual float GetFloat(CampaignMode campaignMode)
bool CheckAgainstMetadata
PropertyConditional.ComparisonOperatorType Operator
CheckDataAction(ScriptedEvent parentEvent, ContentXElement element)
CheckDataAction(ContentXElement element, string parentDebugString)
override? bool DetermineSuccess()
virtual bool GetBool(CampaignMode campaignMode)
string? GetAttributeString(string key, string? def)
readonly ScriptedEvent ParentEvent
static GameSession?? GameSession
Conditionals are used by some in-game mechanics to require one or more conditions to be met for those...
ComparisonOperatorType
There are several ways to compare properties to values. The comparison operator to use can be specifi...
static bool CompareFloat(float val1, float val2, ComparisonOperatorType op)