99 lines
3.8 KiB
C#
99 lines
3.8 KiB
C#
using RimWorld;
|
||
using Verse;
|
||
|
||
namespace ArachnaeSwarm
|
||
{
|
||
public static class NecroticTransformationUtility
|
||
{
|
||
/// <summary>
|
||
/// 检查一个尸体是否可以被我们的逻辑转化为变异体。
|
||
/// 这是对原版 MutantUtility.CanResurrectAsShambler 的复制,但移除了对 canBecomeShambler 的检查。
|
||
/// </summary>
|
||
public static bool CanResurrect(Corpse corpse, bool ignoreIndoors = false)
|
||
{
|
||
if (corpse?.InnerPawn == null) return false;
|
||
if (!corpse.InnerPawn.RaceProps.IsFlesh) return false;
|
||
// 我们移除了对 corpse.InnerPawn.RaceProps.canBecomeShambler 的检查
|
||
if (corpse.InnerPawn.IsMutant) return false;
|
||
if (corpse is UnnaturalCorpse) return false;
|
||
|
||
Room room = corpse.PositionHeld.GetRoom(corpse.MapHeld);
|
||
if (room != null && !ignoreIndoors && corpse.PositionHeld.Roofed(corpse.MapHeld) && (room.ProperRoom || room.IsDoorway))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
if (!Find.Storyteller.difficulty.childShamblersAllowed && !corpse.InnerPawn.ageTracker.Adult)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
Hediff_DeathRefusal firstHediff = corpse.InnerPawn.health.hediffSet.GetFirstHediff<Hediff_DeathRefusal>();
|
||
if (firstHediff != null && (firstHediff.InProgress || firstHediff.UsesLeft > 0))
|
||
{
|
||
return false;
|
||
}
|
||
|
||
return true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将一个Pawn复活为指定的自定义变异体.
|
||
/// 这个方法是模仿原版 MutantUtility.ResurrectAsShambler,
|
||
/// 但允许传入一个自定义的 MutantDef.
|
||
/// </summary>
|
||
public static void ResurrectAsCustomMutant(Pawn pawn, MutantDef mutantDef, Faction faction = null, int lifespanTicks = -1)
|
||
{
|
||
if (pawn?.Corpse == null || mutantDef == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
RotStage rotStage = pawn.Corpse.GetRotStage();
|
||
|
||
// 创建并附加Pawn_MutantTracker,使用我们从XML传入的mutantDef
|
||
pawn.mutant = new Pawn_MutantTracker(pawn, mutantDef, rotStage);
|
||
|
||
// 添加变异体核心Hediff
|
||
Hediff hediff = pawn.health.AddHediff(mutantDef.hediff);
|
||
|
||
// 如果是我们自己的可配置变异体Hediff,则调用其上升动画
|
||
if (hediff is Hediff_ConfigurableMutant configurableMutant)
|
||
{
|
||
configurableMutant.StartRising(lifespanTicks);
|
||
}
|
||
|
||
// 设置生命周期
|
||
var disappearsComp = hediff.TryGetComp<HediffComp_DisappearsAndKills>();
|
||
if (disappearsComp != null)
|
||
{
|
||
if (lifespanTicks > 0)
|
||
{
|
||
disappearsComp.disappearsAfterTicks = lifespanTicks;
|
||
disappearsComp.ticksToDisappear = lifespanTicks;
|
||
}
|
||
else
|
||
{
|
||
disappearsComp.disabled = true;
|
||
}
|
||
}
|
||
|
||
// 如果没有提供派系,则尝试使用变异体定义的默认派系
|
||
if (faction == null && mutantDef.defaultFaction != null)
|
||
{
|
||
faction = Find.FactionManager.FirstFactionOfDef(mutantDef.defaultFaction);
|
||
}
|
||
|
||
// 设置派系
|
||
if (faction != null && pawn.Faction != faction)
|
||
{
|
||
pawn.SetFaction(faction);
|
||
}
|
||
|
||
// 移除 pawn.mutant.Turn(clearLord: true);
|
||
// Turn() 方法应该由 Hediff_Shambler.FinishRising() 在复活过程的最后阶段调用,
|
||
// 而不应该由我们在这里手动调用。
|
||
// Hediff_Shambler 的 StartRising() 会启动这个流程。
|
||
}
|
||
}
|
||
} |