酸爆种和土豆雷

This commit is contained in:
2025-09-12 16:16:21 +08:00
parent 5c32da8634
commit ba9c515b3f
10 changed files with 116 additions and 19 deletions

View File

@@ -196,6 +196,7 @@
<Compile Include="HediffGiver_RandomWithSeverity.cs" />
<Compile Include="CompHunterExplosion.cs" />
<Compile Include="CompProperties_HunterExplosion.cs" />
<Compile Include="TrapReleaseRandomExtension.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="Morphable\CompProperties_Morphable.cs" />

View File

@@ -2,22 +2,72 @@ using System.Collections.Generic;
using Verse;
using Verse.Sound;
using RimWorld;
using System.Linq;
namespace ArachnaeSwarm;
public class Building_TrapReleaseRandom : Building_TrapReleaseEntity
{
// XML-assignable: number of pawns to spawn
public int countToSpawn = 1;
private TrapReleaseRandomExtension extension;
// XML-assignable: list of PawnKindDefs to choose from randomly when spawning
public List<PawnKindDef> pawnKinds = new List<PawnKindDef>();
private TrapReleaseRandomExtension Extension
{
get
{
if (extension == null)
{
extension = def.GetModExtension<TrapReleaseRandomExtension>();
}
return extension;
}
}
protected override int CountToSpawn => countToSpawn;
protected override int CountToSpawn => Extension?.countToSpawn ?? 1;
protected override PawnKindDef PawnToSpawn => (pawnKinds == null || pawnKinds.Count == 0) ? PawnKindDefOf.Drone_Hunter : pawnKinds.RandomElement();
protected override PawnKindDef PawnToSpawn
{
get
{
if (Extension == null || Extension.pawnKinds.NullOrEmpty())
{
return PawnKindDefOf.Drone_Hunter;
}
return Extension.pawnKinds.RandomElement();
}
}
public override void SpawnSetup(Map map, bool respawningAfterLoad)
{
if (this.Faction == null)
{
this.SetFaction(Faction.OfPlayer);
}
base.SpawnSetup(map, respawningAfterLoad);
}
// Ensure spawned pawns use the building's faction when possible; otherwise spawn as wild (null faction)
protected override void Tick()
{
if (!base.Spawned || base.IsStunned || !this.IsHashIntervalTick(60))
{
return;
}
float radius = (Extension != null) ? Extension.detectionRadius : 20f;
Map map = base.Map;
IEnumerable<Pawn> enumerable = map.mapPawns.AllPawnsSpawned.Where((Pawn x) => !x.IsPsychologicallyInvisible() && x.HostileTo(this) && x.Position.DistanceTo(base.Position) <= radius);
IntVec3 position = base.Position;
foreach (Pawn item in enumerable)
{
if ((base.Faction != Faction.OfPlayer || (!item.IsPrisoner && !item.Downed)) && GenSight.LineOfSight(position, item.Position, map))
{
Spring(item);
break;
}
}
}
protected override void SpringSub(Pawn p)
{
if (base.Spawned)

View File

@@ -0,0 +1,12 @@
using System.Collections.Generic;
using Verse;
namespace ArachnaeSwarm
{
public class TrapReleaseRandomExtension : DefModExtension
{
public int countToSpawn = 1;
public List<PawnKindDef> pawnKinds = new List<PawnKindDef>();
public float detectionRadius = 20f;
}
}