暂存4
This commit is contained in:
@@ -12,6 +12,7 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
public string name;
|
||||
public string value;
|
||||
public string valueVariableName;
|
||||
|
||||
public override bool IsMet(out string reason)
|
||||
{
|
||||
@@ -22,11 +23,21 @@ namespace WulaFallenEmpire
|
||||
return false;
|
||||
}
|
||||
|
||||
// Simple string comparison for now. Can be expanded.
|
||||
bool met = variable.ToString() == value;
|
||||
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} = {value} (Current: {variable})";
|
||||
reason = $"Requires {name} = {compareValue} (Current: {variable})";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -35,25 +46,40 @@ namespace WulaFallenEmpire
|
||||
return met;
|
||||
}
|
||||
}
|
||||
|
||||
public class Condition_VariableGreaterThan : Condition
|
||||
|
||||
public abstract class Condition_CompareVariable : Condition
|
||||
{
|
||||
public string name;
|
||||
public float value;
|
||||
public string valueVariableName;
|
||||
|
||||
protected abstract bool Compare(float var1, float var2);
|
||||
protected abstract string GetOperatorString();
|
||||
|
||||
public override bool IsMet(out string reason)
|
||||
{
|
||||
float variable = EventContext.GetVariable<float>(name, float.MinValue);
|
||||
if (variable == float.MinValue)
|
||||
float variable = EventContext.GetVariable<float>(name, float.NaN);
|
||||
if (float.IsNaN(variable))
|
||||
{
|
||||
reason = $"Variable '{name}' not set.";
|
||||
reason = $"Variable '{name}' not set or not a number.";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool met = variable > value;
|
||||
float compareValue = value;
|
||||
if (!string.IsNullOrEmpty(valueVariableName))
|
||||
{
|
||||
compareValue = EventContext.GetVariable<float>(valueVariableName, float.NaN);
|
||||
if (float.IsNaN(compareValue))
|
||||
{
|
||||
reason = $"Comparison variable '{valueVariableName}' not set or not a number.";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool met = Compare(variable, compareValue);
|
||||
if (!met)
|
||||
{
|
||||
reason = $"Requires {name} > {value} (Current: {variable})";
|
||||
reason = $"Requires {name} {GetOperatorString()} {compareValue} (Current: {variable})";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -63,4 +89,27 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
public class Condition_VariableGreaterThan : Condition_CompareVariable
|
||||
{
|
||||
protected override bool Compare(float var1, float var2) => var1 > var2;
|
||||
protected override string GetOperatorString() => ">";
|
||||
}
|
||||
|
||||
public class Condition_VariableLessThan : Condition_CompareVariable
|
||||
{
|
||||
protected override bool Compare(float var1, float var2) => var1 < var2;
|
||||
protected override string GetOperatorString() => "<";
|
||||
}
|
||||
|
||||
public class Condition_VariableGreaterThanOrEqual : Condition_CompareVariable
|
||||
{
|
||||
protected override bool Compare(float var1, float var2) => var1 >= var2;
|
||||
protected override string GetOperatorString() => ">=";
|
||||
}
|
||||
|
||||
public class Condition_VariableLessThanOrEqual : Condition_CompareVariable
|
||||
{
|
||||
protected override bool Compare(float var1, float var2) => var1 <= var2;
|
||||
protected override string GetOperatorString() => "<=";
|
||||
}
|
||||
}
|
||||
|
||||
26
Source/WulaFallenEmpire/EventSystem/DebugActions.cs
Normal file
26
Source/WulaFallenEmpire/EventSystem/DebugActions.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
using LudeonTK;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public static class WulaDebugActions
|
||||
{
|
||||
[DebugAction("Wula Fallen Empire", "Open Custom UI...", actionType = DebugActionType.ToolMap, allowedGameStates = AllowedGameStates.Playing)]
|
||||
private static void OpenCustomUI()
|
||||
{
|
||||
List<DebugMenuOption> list = new List<DebugMenuOption>();
|
||||
foreach (CustomUIDef localDef in DefDatabase<CustomUIDef>.AllDefs)
|
||||
{
|
||||
// Capture the local variable for the lambda
|
||||
CustomUIDef currentDef = localDef;
|
||||
list.Add(new DebugMenuOption(currentDef.defName, DebugMenuOptionMode.Action, delegate
|
||||
{
|
||||
Find.WindowStack.Add(new Dialog_CustomDisplay(currentDef));
|
||||
}));
|
||||
}
|
||||
Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,8 +264,109 @@ namespace WulaFallenEmpire
|
||||
TaggedString finalText = letterText.Formatted(pawn.Named("PAWN")).AdjustedFor(pawn);
|
||||
PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref finalText, ref finalLabel, pawn);
|
||||
Find.LetterStack.ReceiveLetter(finalLabel, finalText, letterDef ?? LetterDefOf.PositiveEvent, pawn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum VariableOperation
|
||||
{
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide
|
||||
}
|
||||
|
||||
public class Effect_ModifyVariable : Effect
|
||||
{
|
||||
public string name;
|
||||
public float value;
|
||||
public VariableOperation operation;
|
||||
|
||||
public override void Execute(Dialog_CustomDisplay dialog)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
Log.Error("[WulaFallenEmpire] Effect_ModifyVariable has a null or empty name.");
|
||||
return;
|
||||
}
|
||||
|
||||
float currentValue = EventContext.GetVariable<float>(name, 0f);
|
||||
|
||||
switch (operation)
|
||||
{
|
||||
case VariableOperation.Add:
|
||||
currentValue += value;
|
||||
break;
|
||||
case VariableOperation.Subtract:
|
||||
currentValue -= value;
|
||||
break;
|
||||
case VariableOperation.Multiply:
|
||||
currentValue *= value;
|
||||
break;
|
||||
case VariableOperation.Divide:
|
||||
if (value != 0)
|
||||
{
|
||||
currentValue /= value;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error($"[WulaFallenEmpire] Effect_ModifyVariable tried to divide by zero for variable '{name}'.");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
EventContext.SetVariable(name, currentValue);
|
||||
}
|
||||
}
|
||||
|
||||
public class Effect_ClearVariable : Effect
|
||||
{
|
||||
public string name;
|
||||
|
||||
public override void Execute(Dialog_CustomDisplay dialog)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
Log.Error("[WulaFallenEmpire] Effect_ClearVariable has a null or empty name.");
|
||||
return;
|
||||
}
|
||||
EventContext.ClearVariable(name);
|
||||
}
|
||||
}
|
||||
|
||||
public class Effect_AddQuest : Effect
|
||||
{
|
||||
public QuestScriptDef quest;
|
||||
|
||||
public override void Execute(Dialog_CustomDisplay dialog)
|
||||
{
|
||||
if (quest == null)
|
||||
{
|
||||
Log.Error("[WulaFallenEmpire] Effect_AddQuest has a null quest Def.");
|
||||
return;
|
||||
}
|
||||
|
||||
Quest newQuest = Quest.MakeRaw();
|
||||
newQuest.root = quest;
|
||||
newQuest.id = Find.UniqueIDsManager.GetNextQuestID();
|
||||
Find.QuestManager.Add(newQuest);
|
||||
}
|
||||
}
|
||||
|
||||
public class Effect_FinishResearch : Effect
|
||||
{
|
||||
public ResearchProjectDef research;
|
||||
|
||||
public override void Execute(Dialog_CustomDisplay dialog)
|
||||
{
|
||||
if (research == null)
|
||||
{
|
||||
Log.Error("[WulaFallenEmpire] Effect_FinishResearch has a null research Def.");
|
||||
return;
|
||||
}
|
||||
|
||||
Find.ResearchManager.FinishProject(research);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,5 +48,17 @@ namespace WulaFallenEmpire
|
||||
variables.Clear();
|
||||
Log.Message("[EventContext] All variables cleared.");
|
||||
}
|
||||
|
||||
public static void ClearVariable(string name)
|
||||
{
|
||||
if (variables.Remove(name))
|
||||
{
|
||||
Log.Message($"[EventContext] Cleared variable '{name}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warning($"[EventContext] Tried to clear variable '{name}' but it was not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user