This commit is contained in:
2025-07-22 19:07:21 +08:00
parent 4f524845a9
commit 15494e8a8e
26 changed files with 318 additions and 963 deletions

View File

@@ -0,0 +1,65 @@
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
}
}
}