声音
This commit is contained in:
@@ -3,12 +3,12 @@ using RimWorld;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public abstract class Condition
|
||||
public abstract class ConditionBase
|
||||
{
|
||||
public abstract bool IsMet(out string reason);
|
||||
}
|
||||
|
||||
public class Condition_VariableEquals : Condition
|
||||
public class Condition_VariableEquals : ConditionBase
|
||||
{
|
||||
public string name;
|
||||
public string value;
|
||||
@@ -75,7 +75,7 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Condition_CompareVariable : Condition
|
||||
public abstract class Condition_CompareVariable : ConditionBase
|
||||
{
|
||||
public string name;
|
||||
public float value;
|
||||
@@ -145,7 +145,7 @@ namespace WulaFallenEmpire
|
||||
protected override string GetOperatorString() => "<=";
|
||||
}
|
||||
|
||||
public class Condition_VariableNotEqual : Condition
|
||||
public class Condition_VariableNotEqual : ConditionBase
|
||||
{
|
||||
public string name;
|
||||
public string value;
|
||||
@@ -213,7 +213,7 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
public class Condition_FactionExists : Condition
|
||||
public class Condition_FactionExists : ConditionBase
|
||||
{
|
||||
public FactionDef factionDef;
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public abstract class Condition
|
||||
{
|
||||
public abstract bool IsMet(out string reason);
|
||||
}
|
||||
|
||||
public class Condition_FlagExists : ConditionBase
|
||||
{
|
||||
public string flagName;
|
||||
|
||||
public override bool IsMet(out string reason)
|
||||
{
|
||||
if (string.IsNullOrEmpty(flagName))
|
||||
{
|
||||
reason = "Flag name is not specified.";
|
||||
return false;
|
||||
}
|
||||
|
||||
var eventVarManager = Find.World.GetComponent<EventVariableManager>();
|
||||
bool flagExists = eventVarManager.HasFlag(flagName);
|
||||
|
||||
if (!flagExists)
|
||||
{
|
||||
reason = $"Flag '{flagName}' does not exist or has expired.";
|
||||
}
|
||||
else
|
||||
{
|
||||
int remainingTicks = eventVarManager.GetFlagRemainingTicks(flagName);
|
||||
if (remainingTicks < 0)
|
||||
{
|
||||
reason = $"Flag '{flagName}' exists (permanent).";
|
||||
}
|
||||
else
|
||||
{
|
||||
reason = $"Flag '{flagName}' exists (expires in {remainingTicks} ticks).";
|
||||
}
|
||||
}
|
||||
|
||||
Log.Message($"[EventSystem] Condition_FlagExists check: Flag='{flagName}', Exists={flagExists}, Reason='{reason}'");
|
||||
return flagExists;
|
||||
}
|
||||
}
|
||||
|
||||
public class Condition_FlagNotExists : ConditionBase
|
||||
{
|
||||
public string flagName;
|
||||
|
||||
public override bool IsMet(out string reason)
|
||||
{
|
||||
if (string.IsNullOrEmpty(flagName))
|
||||
{
|
||||
reason = "Flag name is not specified.";
|
||||
return false;
|
||||
}
|
||||
|
||||
var eventVarManager = Find.World.GetComponent<EventVariableManager>();
|
||||
bool flagExists = eventVarManager.HasFlag(flagName);
|
||||
|
||||
if (flagExists)
|
||||
{
|
||||
int remainingTicks = eventVarManager.GetFlagRemainingTicks(flagName);
|
||||
if (remainingTicks < 0)
|
||||
{
|
||||
reason = $"Flag '{flagName}' exists (permanent).";
|
||||
}
|
||||
else
|
||||
{
|
||||
reason = $"Flag '{flagName}' exists (expires in {remainingTicks} ticks).";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
reason = $"Flag '{flagName}' does not exist.";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -572,7 +572,7 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
private bool AreConditionsMet(List<Condition> conditions, out string reason)
|
||||
private bool AreConditionsMet(List<ConditionBase> conditions, out string reason)
|
||||
{
|
||||
reason = "";
|
||||
if (conditions.NullOrEmpty())
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
private bool AreConditionsMet(List<Condition> conditions, out string reason)
|
||||
private bool AreConditionsMet(List<ConditionBase> conditions, out string reason)
|
||||
{
|
||||
reason = "";
|
||||
if (conditions.NullOrEmpty())
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
// 在 EffectBase.cs 中添加以下类
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class Effect_SetTimedFlag : EffectBase
|
||||
{
|
||||
public string flagName;
|
||||
public int durationTicks; // 持续时间(tick),负数表示永久
|
||||
|
||||
public override void Execute(Window dialog = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(flagName))
|
||||
{
|
||||
Log.Error("[WulaFallenEmpire] Effect_SetTimedFlag has a null or empty flagName.");
|
||||
return;
|
||||
}
|
||||
|
||||
var eventVarManager = Find.World.GetComponent<EventVariableManager>();
|
||||
eventVarManager.SetTimedFlag(flagName, durationTicks);
|
||||
|
||||
string durationInfo = durationTicks < 0 ? "permanent" : $"{durationTicks} ticks";
|
||||
Log.Message($"[EventSystem] Set timed flag '{flagName}' with duration: {durationInfo}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,7 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
[MustTranslate]
|
||||
public string label;
|
||||
public List<Condition> conditions;
|
||||
public List<ConditionBase> conditions;
|
||||
[MustTranslate]
|
||||
public string disabledReason;
|
||||
public bool hideWhenDisabled = true;
|
||||
@@ -102,7 +102,7 @@ namespace WulaFallenEmpire
|
||||
|
||||
public class ConditionalEffects
|
||||
{
|
||||
public List<Condition> conditions;
|
||||
public List<ConditionBase> conditions;
|
||||
public List<EffectBase> effects;
|
||||
public List<EffectBase> randomlistEffects;
|
||||
public List<LoopEffects> loopEffects;
|
||||
@@ -164,7 +164,7 @@ namespace WulaFallenEmpire
|
||||
|
||||
public class ConditionalDescription
|
||||
{
|
||||
public List<Condition> conditions;
|
||||
public List<ConditionBase> conditions;
|
||||
[MustTranslate]
|
||||
public string text;
|
||||
}
|
||||
|
||||
@@ -12,12 +12,17 @@ namespace WulaFallenEmpire
|
||||
private Dictionary<string, string> stringVars = new Dictionary<string, string>();
|
||||
private Dictionary<string, Pawn> pawnVars = new Dictionary<string, Pawn>();
|
||||
private Dictionary<string, List<Pawn>> pawnListVars = new Dictionary<string, List<Pawn>>();
|
||||
|
||||
// 新增:有时限的flag字典
|
||||
private Dictionary<string, int> timedFlags = new Dictionary<string, int>();
|
||||
|
||||
// 用于Scribe的辅助列表
|
||||
private List<string> pawnVarKeys;
|
||||
private List<Pawn> pawnVarValues;
|
||||
private List<string> pawnListVarKeys;
|
||||
private List<List<Pawn>> pawnListVarValues;
|
||||
private List<string> timedFlagKeys;
|
||||
private List<int> timedFlagValues;
|
||||
|
||||
// Required for WorldComponent
|
||||
public EventVariableManager(World world) : base(world)
|
||||
@@ -32,6 +37,7 @@ namespace WulaFallenEmpire
|
||||
Scribe_Collections.Look(ref stringVars, "stringVars", LookMode.Value, LookMode.Value);
|
||||
Scribe_Collections.Look(ref pawnVars, "pawnVars", LookMode.Value, LookMode.Reference, ref pawnVarKeys, ref pawnVarValues);
|
||||
Scribe_Collections.Look(ref pawnListVars, "pawnListVars", LookMode.Value, LookMode.Reference, ref pawnListVarKeys, ref pawnListVarValues);
|
||||
Scribe_Collections.Look(ref timedFlags, "timedFlags", LookMode.Value, LookMode.Value, ref timedFlagKeys, ref timedFlagValues);
|
||||
|
||||
// Ensure dictionaries are not null after loading
|
||||
if (Scribe.mode == LoadSaveMode.PostLoadInit)
|
||||
@@ -41,6 +47,43 @@ namespace WulaFallenEmpire
|
||||
stringVars ??= new Dictionary<string, string>();
|
||||
pawnVars ??= new Dictionary<string, Pawn>();
|
||||
pawnListVars ??= new Dictionary<string, List<Pawn>>();
|
||||
timedFlags ??= new Dictionary<string, int>();
|
||||
}
|
||||
}
|
||||
|
||||
public override void WorldComponentTick()
|
||||
{
|
||||
base.WorldComponentTick();
|
||||
|
||||
// 每60 tick检查一次过期flag
|
||||
if (Find.TickManager.TicksGame % 60 == 0)
|
||||
{
|
||||
CheckExpiredFlags();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查并清理过期的flag
|
||||
/// </summary>
|
||||
private void CheckExpiredFlags()
|
||||
{
|
||||
List<string> flagsToRemove = new List<string>();
|
||||
int currentTick = Find.TickManager.TicksGame;
|
||||
|
||||
foreach (var kvp in timedFlags)
|
||||
{
|
||||
// 如果flag的过期时间不为负数且小于当前tick,则标记为需要移除
|
||||
if (kvp.Value >= 0 && currentTick >= kvp.Value)
|
||||
{
|
||||
flagsToRemove.Add(kvp.Key);
|
||||
Log.Message($"[EventSystem] Flag '{kvp.Key}' expired and will be removed.");
|
||||
}
|
||||
}
|
||||
|
||||
// 移除过期的flag
|
||||
foreach (string flagName in flagsToRemove)
|
||||
{
|
||||
timedFlags.Remove(flagName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +124,80 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置有时限的flag
|
||||
/// </summary>
|
||||
/// <param name="flagName">flag名称</param>
|
||||
/// <param name="durationTicks">持续时间(tick),负数表示永久</param>
|
||||
public void SetTimedFlag(string flagName, int durationTicks)
|
||||
{
|
||||
if (string.IsNullOrEmpty(flagName)) return;
|
||||
|
||||
int expiryTick;
|
||||
if (durationTicks < 0)
|
||||
{
|
||||
// 负数表示永久flag
|
||||
expiryTick = -1;
|
||||
Log.Message($"[EventSystem] Setting permanent flag '{flagName}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 正数表示有时间限制的flag
|
||||
expiryTick = Find.TickManager.TicksGame + durationTicks;
|
||||
Log.Message($"[EventSystem] Setting timed flag '{flagName}' with duration {durationTicks} ticks (expires at tick {expiryTick}).");
|
||||
}
|
||||
|
||||
timedFlags[flagName] = expiryTick;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查flag是否存在且未过期
|
||||
/// </summary>
|
||||
public bool HasFlag(string flagName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(flagName)) return false;
|
||||
|
||||
if (timedFlags.TryGetValue(flagName, out int expiryTick))
|
||||
{
|
||||
if (expiryTick < 0)
|
||||
{
|
||||
// 永久flag
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 检查是否过期
|
||||
bool isActive = Find.TickManager.TicksGame < expiryTick;
|
||||
if (!isActive)
|
||||
{
|
||||
// 如果过期了,移除它
|
||||
timedFlags.Remove(flagName);
|
||||
Log.Message($"[EventSystem] Flag '{flagName}' has expired and was removed.");
|
||||
}
|
||||
return isActive;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取flag的剩余时间(tick)
|
||||
/// </summary>
|
||||
public int GetFlagRemainingTicks(string flagName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(flagName) || !timedFlags.TryGetValue(flagName, out int expiryTick))
|
||||
return 0;
|
||||
|
||||
if (expiryTick < 0)
|
||||
{
|
||||
// 永久flag
|
||||
return -1;
|
||||
}
|
||||
|
||||
int remaining = expiryTick - Find.TickManager.TicksGame;
|
||||
return remaining > 0 ? remaining : 0;
|
||||
}
|
||||
|
||||
public T GetVariable<T>(string name, T defaultValue = default)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return defaultValue;
|
||||
@@ -138,7 +255,8 @@ namespace WulaFallenEmpire
|
||||
floatVars.ContainsKey(name) ||
|
||||
stringVars.ContainsKey(name) ||
|
||||
pawnVars.ContainsKey(name) ||
|
||||
pawnListVars.ContainsKey(name);
|
||||
pawnListVars.ContainsKey(name) ||
|
||||
timedFlags.ContainsKey(name);
|
||||
}
|
||||
|
||||
public void ClearVariable(string name)
|
||||
@@ -152,6 +270,7 @@ namespace WulaFallenEmpire
|
||||
stringVars.Remove(name);
|
||||
pawnVars.Remove(name);
|
||||
pawnListVars.Remove(name);
|
||||
timedFlags.Remove(name);
|
||||
}
|
||||
|
||||
public void ClearAll()
|
||||
@@ -161,6 +280,7 @@ namespace WulaFallenEmpire
|
||||
stringVars.Clear();
|
||||
pawnVars.Clear();
|
||||
pawnListVars.Clear();
|
||||
timedFlags.Clear();
|
||||
}
|
||||
|
||||
public Dictionary<string, object> GetAllVariables()
|
||||
@@ -171,7 +291,8 @@ namespace WulaFallenEmpire
|
||||
foreach (var kvp in stringVars) allVars[kvp.Key] = kvp.Value;
|
||||
foreach (var kvp in pawnVars) allVars[kvp.Key] = kvp.Value;
|
||||
foreach (var kvp in pawnListVars) allVars[kvp.Key] = kvp.Value;
|
||||
foreach (var kvp in timedFlags) allVars[kvp.Key] = $"Flag (expires: {kvp.Value})";
|
||||
return allVars;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user