22 [
Serialize(
null,
IsPropertySaveable.Yes, description:
"Depending on the operation, the value you want to set the metadata to, multiply it with, or add to it.")]
23 public string Value {
get;
set; } =
null!;
25 [
Serialize(
"",
IsPropertySaveable.Yes, description:
"Identifier of the metadata to set. Can be any arbitrary identifier, e.g. itemscollected, my_custom_event_state, specialnpckilled...")]
28 private bool isFinished;
39 public override void Update(
float deltaTime)
41 if (isFinished) {
return; }
54 if (metadata ==
null) {
return; }
56 object currentValue = metadata.GetValue(identifier);
58 float? originalValue = ConvertValueToFloat(currentValue ?? 0);
59 float? newValue = ConvertValueToFloat(value);
61 if ((originalValue ==
null || newValue ==
null) && operation !=
OperationType.Set)
63 DebugConsole.ThrowError($
"Tried to perform numeric operations to a non number via SetDataAction (Existing: {currentValue?.GetType()}, New: {value.GetType()})");
70 metadata.SetValue(identifier, value);
73 metadata.SetValue(identifier, originalValue + newValue ?? 0);
76 metadata.SetValue(identifier, originalValue * newValue ?? 0);
81 private static float? ConvertValueToFloat(
object value)
83 if (value is
float || value is
int)
85 return (
float?) Convert.ChangeType(value, typeof(
float));
93 if (
bool.TryParse(value, out
bool b))
98 if (
float.TryParse(value, out
float f))
108 return $
"{ToolBox.GetDebugSymbol(isFinished)} {nameof(SetDataAction)} -> (Identifier: {Identifier.ColorizeObject()}, Value: {ConvertXMLValue(Value).ColorizeObject()}, Operation: {Operation.ColorizeObject()})";
static GameSession?? GameSession
Sets a campaign metadata value. The metadata can be any arbitrary data you want to save: for example,...
override void Update(float deltaTime)
static object ConvertXMLValue(string value)
SetDataAction(ScriptedEvent parentEvent, ContentXElement element)
override bool IsFinished(ref string goTo)
Has the action finished.
static void PerformOperation(CampaignMetadata metadata, Identifier identifier, object value, OperationType operation)
override string ToDebugString()
Rich test to display in debugdraw