91 lines
3.3 KiB
C#
91 lines
3.3 KiB
C#
using RimWorld;
|
|
using Verse;
|
|
|
|
namespace ArachnaeSwarm
|
|
{
|
|
public class CompProperties_TemperatureRuinableDamage : CompProperties
|
|
{
|
|
public float minSafeTemperature;
|
|
public float maxSafeTemperature = 100f;
|
|
public float progressPerDegreePerTick = 1E-05f; // 修改参数名以匹配标准调用方式
|
|
public float damagePerTick = 1f; // 每tick造成的伤害值
|
|
public float recoveryRate = 0.001f; // 温度恢复正常时的恢复速率
|
|
|
|
public CompProperties_TemperatureRuinableDamage()
|
|
{
|
|
compClass = typeof(CompTemperatureRuinableDamage);
|
|
}
|
|
}
|
|
|
|
public class CompTemperatureRuinableDamage : ThingComp
|
|
{
|
|
private float ruinedPercent; // 修改变量名以匹配标准
|
|
private bool isRuined; // 修改变量名以匹配标准
|
|
|
|
public CompProperties_TemperatureRuinableDamage Props => (CompProperties_TemperatureRuinableDamage)props;
|
|
|
|
public override void CompTick()
|
|
{
|
|
base.CompTick();
|
|
if (parent.AmbientTemperature < Props.minSafeTemperature || parent.AmbientTemperature > Props.maxSafeTemperature)
|
|
{
|
|
float tempDelta = 0f;
|
|
if (parent.AmbientTemperature < Props.minSafeTemperature)
|
|
{
|
|
tempDelta = Props.minSafeTemperature - parent.AmbientTemperature;
|
|
}
|
|
else if (parent.AmbientTemperature > Props.maxSafeTemperature)
|
|
{
|
|
tempDelta = parent.AmbientTemperature - Props.maxSafeTemperature;
|
|
}
|
|
|
|
// 累积损坏进度
|
|
ruinedPercent += tempDelta * Props.progressPerDegreePerTick;
|
|
|
|
// 只有在已损坏的情况下才每tick造成持续伤害
|
|
if (isRuined)
|
|
{
|
|
parent.TakeDamage(new DamageInfo(DamageDefOf.Deterioration, Props.damagePerTick));
|
|
}
|
|
|
|
// 标记为已受损
|
|
isRuined = true;
|
|
}
|
|
else
|
|
{
|
|
// 当温度恢复正常时,逐渐减少损坏进度而不是重置
|
|
if (isRuined && ruinedPercent > 0f)
|
|
{
|
|
ruinedPercent -= Props.recoveryRate;
|
|
if (ruinedPercent <= 0f)
|
|
{
|
|
ruinedPercent = 0f;
|
|
isRuined = false;
|
|
}
|
|
}
|
|
|
|
// 即使温度正常,如果已损坏也要继续造成伤害直到恢复
|
|
if (isRuined)
|
|
{
|
|
parent.TakeDamage(new DamageInfo(DamageDefOf.Deterioration, Props.damagePerTick));
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void PostExposeData()
|
|
{
|
|
base.PostExposeData();
|
|
Scribe_Values.Look(ref ruinedPercent, "ruinedPercent", 0f);
|
|
Scribe_Values.Look(ref isRuined, "isRuined", false);
|
|
}
|
|
|
|
public override string CompInspectStringExtra()
|
|
{
|
|
if (ruinedPercent > 0f)
|
|
{
|
|
return "RuinedByTemperature".Translate() + ": " + ruinedPercent.ToStringPercent();
|
|
}
|
|
return base.CompInspectStringExtra();
|
|
}
|
|
}
|
|
} |