diff --git a/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/Assemblies/WulaFallenEmpire.dll index 9bb36975..c87a5671 100644 Binary files a/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/Documentation/EventSystem_Documentation.md b/Documentation/EventSystem_Documentation.md index d9014522..7d21f2c8 100644 --- a/Documentation/EventSystem_Documentation.md +++ b/Documentation/EventSystem_Documentation.md @@ -440,6 +440,14 @@ AcceptedOffer ``` +### `Condition_VariableNotEqual` +检查一个变量是否 **不等于** 一个特定值。 +```xml +
  • + QuestStage + 3 +
  • +``` ### `Condition_CompareVariable` (基类) 这是一个抽象基类,不应直接使用。以下所有比较条件(大于、小于等)都继承自这个基类,并共享其参数。 @@ -496,14 +504,4 @@ 2 ``` - -### `Condition_VariableNotEqual` -检查一个变量是否 **不等于** 一个特定值。 -```xml -
  • - QuestStage - 3 -
  • -``` - --- diff --git a/Source/WulaFallenEmpire/EventSystem/Condition.cs b/Source/WulaFallenEmpire/EventSystem/Condition.cs index 1ce61c9e..ba791517 100644 --- a/Source/WulaFallenEmpire/EventSystem/Condition.cs +++ b/Source/WulaFallenEmpire/EventSystem/Condition.cs @@ -16,12 +16,12 @@ namespace WulaFallenEmpire public override bool IsMet(out string reason) { - object variable = EventContext.GetVariable(name); - if (variable == null) + if (!EventContext.HasVariable(name)) { - reason = $"Variable '{name}' not set."; - return false; + EventContext.SetVariable(name, "0"); } + + object variable = EventContext.GetVariable(name); string compareValue = value; if (!string.IsNullOrEmpty(valueVariableName)) @@ -58,12 +58,12 @@ namespace WulaFallenEmpire public override bool IsMet(out string reason) { - float variable = EventContext.GetVariable(name, float.NaN); - if (float.IsNaN(variable)) + if (!EventContext.HasVariable(name)) { - reason = $"Variable '{name}' not set or not a number."; - return false; + EventContext.SetVariable(name, 0f); } + + float variable = EventContext.GetVariable(name); float compareValue = value; if (!string.IsNullOrEmpty(valueVariableName)) @@ -113,9 +113,42 @@ namespace WulaFallenEmpire protected override string GetOperatorString() => "<="; } - public class Condition_VariableNotEqual : Condition_CompareVariable + public class Condition_VariableNotEqual : Condition { - protected override bool Compare(float var1, float var2) => var1 != var2; - protected override string GetOperatorString() => "!="; + public string name; + public string value; + public string valueVariableName; + + public override bool IsMet(out string reason) + { + if (!EventContext.HasVariable(name)) + { + EventContext.SetVariable(name, "0"); + } + + object variable = EventContext.GetVariable(name); + + string compareValue = value; + if (!string.IsNullOrEmpty(valueVariableName)) + { + compareValue = EventContext.GetVariable(valueVariableName)?.ToString(); + if (compareValue == null) + { + reason = $"Comparison variable '{valueVariableName}' not set."; + return false; + } + } + + bool met = variable.ToString() != compareValue; + if (!met) + { + reason = $"Requires {name} != {compareValue} (Current: {variable})"; + } + else + { + reason = ""; + } + return met; + } } } diff --git a/Source/WulaFallenEmpire/EventSystem/Effect.cs b/Source/WulaFallenEmpire/EventSystem/Effect.cs index a3568502..43f58bad 100644 --- a/Source/WulaFallenEmpire/EventSystem/Effect.cs +++ b/Source/WulaFallenEmpire/EventSystem/Effect.cs @@ -153,6 +153,12 @@ namespace WulaFallenEmpire public override void Execute(Dialog_CustomDisplay dialog = null) { + // Only set the variable if it doesn't already exist. + if (EventContext.HasVariable(name)) + { + return; + } + // Try to parse as int, then float, otherwise keep as string if (int.TryParse(value, out int intValue)) {