爽
This commit is contained in:
@@ -8,20 +8,23 @@ namespace WulaFallenEmpire
|
||||
public class CompAreaDamage : ThingComp
|
||||
{
|
||||
private int ticksUntilNextDamage;
|
||||
private bool enabled;
|
||||
|
||||
public CompProperties_AreaDamage Props => (CompProperties_AreaDamage)props;
|
||||
public bool Enabled => enabled;
|
||||
|
||||
public override void Initialize(CompProperties props)
|
||||
{
|
||||
base.Initialize(props);
|
||||
ticksUntilNextDamage = Props.damageIntervalTicks;
|
||||
enabled = Props.startEnabled;
|
||||
}
|
||||
|
||||
public override void CompTick()
|
||||
{
|
||||
base.CompTick();
|
||||
|
||||
if (!parent.Spawned)
|
||||
if (!parent.Spawned || !enabled)
|
||||
return;
|
||||
|
||||
ticksUntilNextDamage--;
|
||||
@@ -32,6 +35,16 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
}
|
||||
|
||||
public void Toggle()
|
||||
{
|
||||
enabled = !enabled;
|
||||
}
|
||||
|
||||
public void SetEnabled(bool newState)
|
||||
{
|
||||
enabled = newState;
|
||||
}
|
||||
|
||||
private void DoAreaDamage()
|
||||
{
|
||||
Map map = parent.Map;
|
||||
@@ -227,6 +240,50 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
base.PostExposeData();
|
||||
Scribe_Values.Look(ref ticksUntilNextDamage, "ticksUntilNextDamage", Props.damageIntervalTicks);
|
||||
Scribe_Values.Look(ref enabled, "enabled", Props.startEnabled);
|
||||
}
|
||||
|
||||
public override IEnumerable<Gizmo> CompGetGizmosExtra()
|
||||
{
|
||||
// 只有拥有者可以操作开关
|
||||
if (parent.Faction != null && parent.Faction != Faction.OfPlayer && !parent.Faction.IsPlayer)
|
||||
yield break;
|
||||
|
||||
// 创建切换开关的 Gizmo
|
||||
Command_Toggle toggleCommand = new Command_Toggle
|
||||
{
|
||||
defaultLabel = Props.toggleLabel.Translate(),
|
||||
defaultDesc = Props.toggleDescription.Translate(),
|
||||
icon = LoadToggleIcon(),
|
||||
isActive = () => enabled,
|
||||
toggleAction = () => Toggle()
|
||||
};
|
||||
|
||||
yield return toggleCommand;
|
||||
}
|
||||
|
||||
private Texture2D LoadToggleIcon()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Props.toggleIconPath))
|
||||
{
|
||||
return ContentFinder<Texture2D>.Get(Props.toggleIconPath, false);
|
||||
}
|
||||
|
||||
// 默认图标
|
||||
return TexCommand.DesirePower;
|
||||
}
|
||||
|
||||
public override string CompInspectStringExtra()
|
||||
{
|
||||
string baseString = base.CompInspectStringExtra();
|
||||
string statusText = enabled ?
|
||||
"AreaDamageEnabled".Translate() :
|
||||
"AreaDamageDisabled".Translate();
|
||||
|
||||
if (string.IsNullOrEmpty(baseString))
|
||||
return statusText;
|
||||
else
|
||||
return baseString + "\n" + statusText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,12 @@ namespace WulaFallenEmpire
|
||||
// 特殊效果
|
||||
public bool showDamageNumbers = false; // 显示伤害数值(调试用)
|
||||
|
||||
// 新增:开关设置
|
||||
public bool startEnabled = true; // 初始是否启用
|
||||
public string toggleLabel = "Toggle Area Damage"; // 开关标签
|
||||
public string toggleDescription = "Enable or disable the area damage effect"; // 开关描述
|
||||
public string toggleIconPath; // 开关图标路径
|
||||
|
||||
public CompProperties_AreaDamage()
|
||||
{
|
||||
compClass = typeof(CompAreaDamage);
|
||||
|
||||
Reference in New Issue
Block a user