变量诸元
This commit is contained in:
@@ -16,12 +16,12 @@ namespace WulaFallenEmpire
|
||||
|
||||
public override bool IsMet(out string reason)
|
||||
{
|
||||
object variable = EventContext.GetVariable<object>(name);
|
||||
if (variable == null)
|
||||
if (!EventContext.HasVariable(name))
|
||||
{
|
||||
reason = $"Variable '{name}' not set.";
|
||||
return false;
|
||||
EventContext.SetVariable(name, "0");
|
||||
}
|
||||
|
||||
object variable = EventContext.GetVariable<object>(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<float>(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<float>(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<object>(name);
|
||||
|
||||
string compareValue = value;
|
||||
if (!string.IsNullOrEmpty(valueVariableName))
|
||||
{
|
||||
compareValue = EventContext.GetVariable<object>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user