This commit is contained in:
2026-02-25 12:00:37 +08:00
parent 5195d05045
commit 2fd290da9e
17 changed files with 1005 additions and 171 deletions

View File

@@ -0,0 +1,23 @@
using RimWorld;
using System.Collections.Generic;
using Verse;
namespace WulaFallenEmpire
{
public class HediffCompProperties_GiveHediffsInRangeToRace : HediffCompProperties
{
public float range;
public TargetingParameters targetingParameters;
public HediffDef hediff;
public ThingDef mote;
public bool hideMoteWhenNotDrafted;
public float initialSeverity = 1f;
public bool onlyPawnsInSameFaction = true;
public List<ThingDef> targetRaces; // 新增:可配置的目标种族列表
public HediffCompProperties_GiveHediffsInRangeToRace()
{
compClass = typeof(HediffComp_GiveHediffsInRangeToRace);
}
}
}

View File

@@ -0,0 +1,63 @@
using RimWorld;
using System.Collections.Generic;
using UnityEngine;
using Verse;
namespace WulaFallenEmpire
{
public class HediffComp_GiveHediffsInRangeToRace : HediffComp
{
private Mote mote;
public HediffCompProperties_GiveHediffsInRangeToRace Props => (HediffCompProperties_GiveHediffsInRangeToRace)props;
public override void CompPostTick(ref float severityAdjustment)
{
if (!parent.pawn.Awake() || parent.pawn.health == null || parent.pawn.health.InPainShock || !parent.pawn.Spawned)
{
return;
}
if (!Props.hideMoteWhenNotDrafted || parent.pawn.Drafted)
{
if (Props.mote != null && (mote == null || mote.Destroyed))
{
mote = MoteMaker.MakeAttachedOverlay(parent.pawn, Props.mote, Vector3.zero);
}
if (mote != null)
{
mote.Maintain();
}
}
IReadOnlyList<Pawn> pawns = ((!Props.onlyPawnsInSameFaction || parent.pawn.Faction == null) ? parent.pawn.Map.mapPawns.AllPawnsSpawned : parent.pawn.Map.mapPawns.SpawnedPawnsInFaction(parent.pawn.Faction));
foreach (Pawn pawn in pawns)
{
// 修改点检查种族是否在我们的目标列表中如果列表为空或null则不进行任何操作
if ((Props.targetRaces.NullOrEmpty() || !Props.targetRaces.Contains(pawn.def)) || pawn.Dead || pawn.health == null || pawn == parent.pawn || !(pawn.Position.DistanceTo(parent.pawn.Position) <= Props.range) || !Props.targetingParameters.CanTarget(pawn))
{
continue;
}
Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(Props.hediff);
if (hediff == null)
{
hediff = pawn.health.AddHediff(Props.hediff, pawn.health.hediffSet.GetBrain());
hediff.Severity = Props.initialSeverity;
HediffComp_Link hediffComp_Link = hediff.TryGetComp<HediffComp_Link>();
if (hediffComp_Link != null)
{
hediffComp_Link.drawConnection = true;
hediffComp_Link.other = parent.pawn;
}
}
HediffComp_Disappears hediffComp_Disappears = hediff.TryGetComp<HediffComp_Disappears>();
if (hediffComp_Disappears == null)
{
WulaLog.Debug("HediffComp_GiveHediffsInRangeToRace has a hediff in props which does not have a HediffComp_Disappears");
}
else
{
hediffComp_Disappears.ticksToDisappear = 5;
}
}
}
}
}