feat: 添加循环效果和随机效果到事件系统
添加了循环效果和随机效果到事件系统,允许更复杂的事件逻辑。
This commit is contained in:
Binary file not shown.
79
1.6/1.6/Defs/EventDefs/EventDef_Examples_Loop.xml
Normal file
79
1.6/1.6/Defs/EventDefs/EventDef_Examples_Loop.xml
Normal file
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Defs>
|
||||
|
||||
<WulaFallenEmpire.EventDef>
|
||||
<defName>WULA_Example_Loop</defName>
|
||||
<characterName>循环大师</characterName>
|
||||
<description>这是一个演示循环效果列表功能的事件。
|
||||
|
||||
首先,设置一个循环次数,然后看看会发生什么!</description>
|
||||
<options>
|
||||
<li>
|
||||
<label>设置循环次数为 3</label>
|
||||
<optionEffects>
|
||||
<li Class="WulaFallenEmpire.ConditionalEffects">
|
||||
<effects>
|
||||
<li Class="WulaFallenEmpire.Effect_SetVariable">
|
||||
<name>LoopCount</name>
|
||||
<value>3</value>
|
||||
</li>
|
||||
<li Class="WulaFallenEmpire.Effect_ShowMessage">
|
||||
<message>变量 'LoopCount' 已被设置为 3。</message>
|
||||
<messageTypeDef>PositiveEvent</messageTypeDef>
|
||||
</li>
|
||||
</effects>
|
||||
</li>
|
||||
</optionEffects>
|
||||
</li>
|
||||
<li>
|
||||
<label>执行循环(使用变量)</label>
|
||||
<optionEffects>
|
||||
<li Class="WulaFallenEmpire.ConditionalEffects">
|
||||
<loopEffects>
|
||||
<li Class="WulaFallenEmpire.LoopEffects">
|
||||
<countVariableName>LoopCount</countVariableName>
|
||||
<!-- 如果LoopCount变量不存在,将默认执行1次 -->
|
||||
<count>1</count>
|
||||
<effects>
|
||||
<li Class="WulaFallenEmpire.Effect_GiveThing">
|
||||
<thingDef>Silver</thingDef>
|
||||
<count>10</count>
|
||||
</li>
|
||||
</effects>
|
||||
</li>
|
||||
</loopEffects>
|
||||
</li>
|
||||
</optionEffects>
|
||||
</li>
|
||||
<li>
|
||||
<label>执行循环(固定次数)</label>
|
||||
<optionEffects>
|
||||
<li Class="WulaFallenEmpire.ConditionalEffects">
|
||||
<loopEffects>
|
||||
<li Class="WulaFallenEmpire.LoopEffects">
|
||||
<count>5</count>
|
||||
<effects>
|
||||
<li Class="WulaFallenEmpire.Effect_GiveThing">
|
||||
<thingDef>Steel</thingDef>
|
||||
<count>20</count>
|
||||
</li>
|
||||
</effects>
|
||||
</li>
|
||||
</loopEffects>
|
||||
</li>
|
||||
</optionEffects>
|
||||
</li>
|
||||
<li>
|
||||
<label>关闭</label>
|
||||
<optionEffects>
|
||||
<li Class="WulaFallenEmpire.ConditionalEffects">
|
||||
<effects>
|
||||
<li Class="WulaFallenEmpire.Effect_CloseDialog" />
|
||||
</effects>
|
||||
</li>
|
||||
</optionEffects>
|
||||
</li>
|
||||
</options>
|
||||
</WulaFallenEmpire.EventDef>
|
||||
|
||||
</Defs>
|
||||
56
1.6/1.6/Defs/EventDefs/EventDef_Examples_RandomList.xml
Normal file
56
1.6/1.6/Defs/EventDefs/EventDef_Examples_RandomList.xml
Normal file
@@ -0,0 +1,56 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Defs>
|
||||
|
||||
<WulaFallenEmpire.EventDef>
|
||||
<defName>WULA_Example_RandomList</defName>
|
||||
<characterName>系统管理员</characterName>
|
||||
<description>这是一个演示随机效果列表功能的事件。
|
||||
|
||||
点击下面的选项,你会看到一条固定消息,然后会随机获得一件物品。</description>
|
||||
<options>
|
||||
<li>
|
||||
<label>试一试!</label>
|
||||
<optionEffects>
|
||||
<li Class="WulaFallenEmpire.ConditionalEffects">
|
||||
<!-- 这个列表中的效果会全部执行 -->
|
||||
<effects>
|
||||
<li Class="WulaFallenEmpire.Effect_ShowMessage">
|
||||
<message>你总是会看到这条消息!</message>
|
||||
<messageTypeDef>PositiveEvent</messageTypeDef>
|
||||
</li>
|
||||
</effects>
|
||||
<!-- 系统会从这个列表中根据权重随机选择一个执行 -->
|
||||
<randomlistEffects>
|
||||
<li Class="WulaFallenEmpire.Effect_GiveThing">
|
||||
<thingDef>Silver</thingDef>
|
||||
<count>100</count>
|
||||
<weight>3.0</weight> <!-- 获得白银的权重更高 -->
|
||||
</li>
|
||||
<li Class="WulaFallenEmpire.Effect_GiveThing">
|
||||
<thingDef>Gold</thingDef>
|
||||
<count>10</count>
|
||||
<weight>1.0</weight> <!-- 获得黄金的权重较低 -->
|
||||
</li>
|
||||
<li Class="WulaFallenEmpire.Effect_GiveThing">
|
||||
<thingDef>ComponentIndustrial</thingDef>
|
||||
<count>5</count>
|
||||
<weight>1.5</weight> <!-- 获得零件的权重居中 -->
|
||||
</li>
|
||||
</randomlistEffects>
|
||||
</li>
|
||||
</optionEffects>
|
||||
</li>
|
||||
<li>
|
||||
<label>关闭</label>
|
||||
<optionEffects>
|
||||
<li Class="WulaFallenEmpire.ConditionalEffects">
|
||||
<effects>
|
||||
<li Class="WulaFallenEmpire.Effect_CloseDialog" />
|
||||
</effects>
|
||||
</li>
|
||||
</optionEffects>
|
||||
</li>
|
||||
</options>
|
||||
</WulaFallenEmpire.EventDef>
|
||||
|
||||
</Defs>
|
||||
@@ -216,13 +216,7 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
if (AreConditionsMet(ce.conditions, out _))
|
||||
{
|
||||
if (!ce.effects.NullOrEmpty())
|
||||
{
|
||||
foreach (var effect in ce.effects)
|
||||
{
|
||||
effect.Execute(this);
|
||||
}
|
||||
}
|
||||
ce.Execute(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
public abstract class Effect
|
||||
{
|
||||
public float weight = 1.0f;
|
||||
public abstract void Execute(Dialog_CustomDisplay dialog = null);
|
||||
}
|
||||
|
||||
@@ -50,13 +51,7 @@ namespace WulaFallenEmpire
|
||||
string reason;
|
||||
if (AreConditionsMet(conditionalEffect.conditions, out reason))
|
||||
{
|
||||
if (!conditionalEffect.effects.NullOrEmpty())
|
||||
{
|
||||
foreach (var effect in conditionalEffect.effects)
|
||||
{
|
||||
effect.Execute(null);
|
||||
}
|
||||
}
|
||||
conditionalEffect.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
|
||||
@@ -68,10 +69,73 @@ namespace WulaFallenEmpire
|
||||
public bool hideWhenDisabled = false;
|
||||
}
|
||||
|
||||
public class LoopEffects
|
||||
{
|
||||
public int count = 1;
|
||||
public string countVariableName;
|
||||
public List<Effect> effects;
|
||||
}
|
||||
|
||||
public class ConditionalEffects
|
||||
{
|
||||
public List<Condition> conditions;
|
||||
public List<Effect> effects;
|
||||
public List<Effect> randomlistEffects;
|
||||
public List<LoopEffects> loopEffects;
|
||||
|
||||
public void Execute(Dialog_CustomDisplay dialog)
|
||||
{
|
||||
// Execute all standard effects
|
||||
if (!effects.NullOrEmpty())
|
||||
{
|
||||
foreach (var effect in effects)
|
||||
{
|
||||
effect.Execute(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
// Execute one random effect from the random list
|
||||
if (!randomlistEffects.NullOrEmpty())
|
||||
{
|
||||
float totalWeight = randomlistEffects.Sum(e => e.weight);
|
||||
float randomPoint = Rand.Value * totalWeight;
|
||||
|
||||
foreach (var effect in randomlistEffects)
|
||||
{
|
||||
if (randomPoint < effect.weight)
|
||||
{
|
||||
effect.Execute(dialog);
|
||||
break;
|
||||
}
|
||||
randomPoint -= effect.weight;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute looped effects
|
||||
if (!loopEffects.NullOrEmpty())
|
||||
{
|
||||
var eventVarManager = Find.World.GetComponent<EventVariableManager>();
|
||||
foreach (var loop in loopEffects)
|
||||
{
|
||||
int loopCount = loop.count;
|
||||
if (!loop.countVariableName.NullOrEmpty() && eventVarManager.HasVariable(loop.countVariableName))
|
||||
{
|
||||
loopCount = eventVarManager.GetVariable<int>(loop.countVariableName);
|
||||
}
|
||||
|
||||
for (int i = 0; i < loopCount; i++)
|
||||
{
|
||||
if (!loop.effects.NullOrEmpty())
|
||||
{
|
||||
foreach (var effect in loop.effects)
|
||||
{
|
||||
effect.Execute(dialog);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ConditionalDescription
|
||||
|
||||
@@ -36,13 +36,7 @@ namespace WulaFallenEmpire
|
||||
string reason;
|
||||
if (AreConditionsMet(conditionalEffect.conditions, out reason))
|
||||
{
|
||||
if (!conditionalEffect.effects.NullOrEmpty())
|
||||
{
|
||||
foreach (var effect in conditionalEffect.effects)
|
||||
{
|
||||
effect.Execute(null);
|
||||
}
|
||||
}
|
||||
conditionalEffect.Execute(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user