45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Verse;
|
|
using RimWorld;
|
|
|
|
namespace ArachnaeSwarm
|
|
{
|
|
public class CompHediffGiver : ThingComp
|
|
{
|
|
public CompProperties_HediffGiver Props => (CompProperties_HediffGiver)this.props;
|
|
|
|
public override void PostSpawnSetup(bool respawningAfterLoad)
|
|
{
|
|
base.PostSpawnSetup(respawningAfterLoad);
|
|
|
|
// 只有当thing是pawn时才添加hediff
|
|
if (this.parent is Pawn pawn)
|
|
{
|
|
AddHediffsToPawn(pawn);
|
|
}
|
|
}
|
|
|
|
private void AddHediffsToPawn(Pawn pawn)
|
|
{
|
|
// 检查是否有hediff列表
|
|
if (Props.hediffs == null || Props.hediffs.Count == 0)
|
|
return;
|
|
|
|
// 检查概率
|
|
if (Props.addChance < 1.0f && Rand.Value > Props.addChance)
|
|
return;
|
|
|
|
// 为每个hediff添加到pawn
|
|
foreach (HediffDef hediffDef in Props.hediffs)
|
|
{
|
|
// 检查是否允许重复添加
|
|
if (!Props.allowDuplicates && pawn.health.hediffSet.HasHediff(hediffDef))
|
|
continue;
|
|
|
|
// 添加hediff
|
|
pawn.health.AddHediff(hediffDef);
|
|
}
|
|
}
|
|
}
|
|
} |