Files
WulaFallenEmpireRW/Source/WulaFallenEmpire/HediffComp_WulaCharging.cs
2025-07-22 19:07:21 +08:00

66 lines
2.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Verse;
using RimWorld;
namespace WulaFallenEmpire
{
public class HediffCompProperties_WulaCharging : HediffCompProperties
{
public float energyPerTick = 0.001f; // 每tick补充的能量量
public int durationTicks = 600; // 持续时间例如600ticks = 10秒
public HediffCompProperties_WulaCharging()
{
this.compClass = typeof(HediffComp_WulaCharging);
}
}
public class HediffComp_WulaCharging : HediffComp
{
public HediffCompProperties_WulaCharging Props => (HediffCompProperties_WulaCharging)this.props;
private int ticksPassed = 0;
private Thing sourceThing; // 新增字段,用于存储能量核心物品
public void SetSourceThing(Thing thing)
{
this.sourceThing = thing;
}
public override void CompPostTick(ref float severityAdjustment)
{
base.CompPostTick(ref severityAdjustment);
ticksPassed++;
if (ticksPassed >= Props.durationTicks)
{
// 持续时间结束移除Hediff
this.parent.pawn.health.RemoveHediff(this.parent);
return;
}
Need_WulaEnergy energyNeed = this.parent.pawn.needs.TryGetNeed<Need_WulaEnergy>();
if (energyNeed != null)
{
// 从sourceThing的ThingDefExtension_EnergySource获取能量量
ThingDefExtension_EnergySource ext = sourceThing?.def.GetModExtension<ThingDefExtension_EnergySource>();
if (ext != null)
{
energyNeed.CurLevel += ext.energyAmount / Props.durationTicks; // 将总能量量分摊到每个tick
}
else
{
// 如果没有找到能量来源扩展则使用默认的energyPerTick
energyNeed.CurLevel += Props.energyPerTick;
}
}
}
public override void CompExposeData()
{
base.CompExposeData();
Scribe_Values.Look(ref ticksPassed, "ticksPassed", 0);
Scribe_References.Look(ref sourceThing, "sourceThing"); // 保存sourceThing
}
}
}