Files
ArachnaeSwarm/Source/ArachnaeSwarm/Abilities/ARA_DestroyOwnBodyPart/CompAbilityEffect_DestroyOwnBodyPart.cs
2025-09-28 17:28:11 +08:00

63 lines
1.9 KiB
C#

using RimWorld;
using System.Collections.Generic;
using System.Linq;
using Verse;
namespace ArachnaeSwarm
{
public class CompAbilityEffect_DestroyOwnBodyPart : CompAbilityEffect
{
public new CompProperties_AbilityDestroyOwnBodyPart Props => (CompProperties_AbilityDestroyOwnBodyPart)props;
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
Pawn caster = parent.pawn;
if (caster == null || caster.Dead)
return;
// 获取要破坏的身体部位
List<BodyPartRecord> partsToDestroy = GetBodyPartsToDestroy(caster);
if (partsToDestroy.Count == 0)
return;
// 对每个部位执行破坏
foreach (BodyPartRecord part in partsToDestroy)
{
DestroyBodyPart(caster, part);
}
}
// 获取要破坏的身体部位列表
private List<BodyPartRecord> GetBodyPartsToDestroy(Pawn pawn)
{
List<BodyPartRecord> validParts = new List<BodyPartRecord>();
// 获取指定的身体部位
foreach (BodyPartDef partDef in Props.bodyPartsToDestroy)
{
var parts = pawn.RaceProps.body.GetPartsWithDef(partDef);
foreach (BodyPartRecord part in parts)
{
// 检查部位是否已经缺失
if (!pawn.health.hediffSet.PartIsMissing(part))
{
validParts.Add(part);
}
}
}
return validParts;
}
// 实际执行身体部位的破坏
private void DestroyBodyPart(Pawn pawn, BodyPartRecord part)
{
// 直接添加缺失部位hediff
pawn.health.AddHediff(HediffDefOf.MissingBodyPart, part);
}
}
}