This commit is contained in:
2026-02-27 17:32:08 +08:00
parent 305c7b122f
commit 5d2f824140
11 changed files with 1090 additions and 94 deletions

View File

@@ -0,0 +1,62 @@
// CompBuildToPawn_SimpleDelay.cs
using RimWorld;
using System.Collections.Generic;
using Verse;
namespace WulaFallenEmpire
{
public class CompBuildToPawn : ThingComp
{
public CompProperties_BuildToPawn Props => (CompProperties_BuildToPawn)props;
private bool shouldSpawn = false;
private int delayCounter = 0;
public override void PostSpawnSetup(bool respawningAfterLoad)
{
base.PostSpawnSetup(respawningAfterLoad);
// 跳过存档加载和蓝图/框架
if (respawningAfterLoad || parent.def.IsBlueprint || parent.def.IsFrame)
return;
// 延迟一帧
shouldSpawn = true;
delayCounter = 0;
}
public override void CompTick()
{
base.CompTick();
if (shouldSpawn && delayCounter >= 1) // 延迟一帧后执行
{
if (Props.pawnKindDef != null && parent != null && !parent.Destroyed && parent.Map != null)
{
// 生成Pawn
for (int i = 0; i < Props.spawnCount; i++)
{
Pawn pawn = PawnGenerator.GeneratePawn(Props.pawnKindDef);
if (Props.inheritFaction)
pawn.SetFaction(parent.Faction, null);
GenSpawn.Spawn(pawn, parent.Position, parent.Map, WipeMode.Vanish);
if (Props.initDrafted && pawn.drafter!=null)
pawn.drafter.Drafted = true;
}
if (Props.destroyBuilding)
// 摧毁建筑
parent.Destroy();
}
shouldSpawn = false;
}
else if (shouldSpawn)
{
delayCounter++;
}
}
}
}

View File

@@ -0,0 +1,20 @@
// CompProperties_BuildToPawn.cs
using RimWorld;
using Verse;
namespace WulaFallenEmpire
{
public class CompProperties_BuildToPawn : CompProperties
{
public PawnKindDef pawnKindDef; // 要生成的Pawn种类
public int spawnCount = 1; // 生成数量默认为1
public bool inheritFaction = true; // 是否继承建筑的派系
public bool destroyBuilding = false; // 是否销毁建筑
public bool initDrafted = false; // 是否生成时直接设为征召
public CompProperties_BuildToPawn()
{
this.compClass = typeof(CompBuildToPawn);
}
}
}