变量诸元
This commit is contained in:
Binary file not shown.
@@ -440,6 +440,14 @@
|
||||
<value>AcceptedOffer</value>
|
||||
</li>
|
||||
```
|
||||
### `Condition_VariableNotEqual`
|
||||
检查一个变量是否 **不等于** 一个特定值。
|
||||
```xml
|
||||
<li Class="WulaFallenEmpire.Condition_VariableNotEqual">
|
||||
<name>QuestStage</name>
|
||||
<value>3</value>
|
||||
</li>
|
||||
```
|
||||
|
||||
### `Condition_CompareVariable` (基类)
|
||||
这是一个抽象基类,不应直接使用。以下所有比较条件(大于、小于等)都继承自这个基类,并共享其参数。
|
||||
@@ -496,14 +504,4 @@
|
||||
<value>2</value>
|
||||
</li>
|
||||
```
|
||||
|
||||
### `Condition_VariableNotEqual`
|
||||
检查一个变量是否 **不等于** 一个特定值。
|
||||
```xml
|
||||
<li Class="WulaFallenEmpire.Condition_VariableNotEqual">
|
||||
<name>QuestStage</name>
|
||||
<value>3</value>
|
||||
</li>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -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