存食物需求的ability

This commit is contained in:
2025-09-01 16:42:08 +08:00
parent 3203db0728
commit e58fac54f8
9 changed files with 212 additions and 57 deletions

View File

@@ -73,7 +73,9 @@
<Compile Include="JobDriver_Incubate.cs" />
<Compile Include="CompProperties_AbilitySprayLiquidMulti.cs" />
<Compile Include="CompAbilityEffect_SprayLiquidMulti.cs" />
<Compile Include="Building_Incubator.cs" />
<Compile Include="Hediffs\Hediff_CurseFlame.cs" />
<Compile Include="CompAbilityEffect_NeedCost.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@@ -0,0 +1,34 @@
using UnityEngine;
using Verse;
namespace ArachnaeSwarm
{
public class Building_Incubator : Building
{
public CompSpawnPawnFromList SpawnComp => GetComp<CompSpawnPawnFromList>();
public GraphicData hatchingGraphicData;
private Graphic hatchingGraphic;
public override void SpawnSetup(Map map, bool respawningAfterLoad)
{
base.SpawnSetup(map, respawningAfterLoad);
if (hatchingGraphicData != null)
{
hatchingGraphic = hatchingGraphicData.Graphic;
}
}
public override Graphic Graphic
{
get
{
if (SpawnComp != null && SpawnComp.IsHatching && hatchingGraphic != null)
{
return hatchingGraphic;
}
return base.Graphic;
}
}
}
}

View File

@@ -0,0 +1,54 @@
using RimWorld;
using RimWorld.Planet;
using Verse;
namespace ArachnaeSwarm
{
public class CompProperties_AbilityNeedCost : CompProperties_AbilityEffect
{
public NeedDef needDef;
public float needCost;
public string failMessage;
public CompProperties_AbilityNeedCost()
{
compClass = typeof(CompAbilityEffect_NeedCost);
}
}
public class CompAbilityEffect_NeedCost : CompAbilityEffect
{
public new CompProperties_AbilityNeedCost Props => (CompProperties_AbilityNeedCost)props;
public override bool GizmoDisabled(out string reason)
{
Pawn caster = parent.pawn;
if (caster != null && caster.needs != null)
{
if (caster.needs.TryGetNeed(Props.needDef, out Need need))
{
if (need.CurLevel < Props.needCost)
{
reason = Props.failMessage;
return true;
}
}
}
reason = null;
return false;
}
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest)
{
base.Apply(target, dest);
Pawn caster = parent.pawn;
if (caster != null && caster.needs != null)
{
if (caster.needs.TryGetNeed(Props.needDef, out Need need))
{
need.CurLevel -= Props.needCost;
}
}
}
}
}

View File

@@ -13,6 +13,7 @@ namespace ArachnaeSwarm
private int spawnUntilTick = -1;
private PawnKindDef spawningPawnKind;
private PawnKindDef selectedPawnKind;
public bool IsHatching => spawnUntilTick > 0;
public override IEnumerable<FloatMenuOption> CompFloatMenuOptions(Pawn selPawn)
{
@@ -40,6 +41,7 @@ namespace ArachnaeSwarm
}
}
public void StartIncubation()
{
spawningPawnKind = selectedPawnKind;
@@ -55,6 +57,8 @@ namespace ArachnaeSwarm
}
}
private void SpawnPawn(PawnKindDef pawnKind)
{
try
@@ -71,34 +75,38 @@ namespace ArachnaeSwarm
return;
}
Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(pawnKind, parent.Faction));
if (pawn == null)
int count = Props.spawnCount.RandomInRange;
for (int i = 0; i < count; i++)
{
Log.Error($"CompSpawnPawnFromList: Failed to generate pawn of kind {pawnKind.defName} for faction {parent.Faction?.Name ?? "null"}.");
return;
}
if (GenSpawn.Spawn(pawn, parent.Position, parent.Map) == null)
{
Log.Error($"CompSpawnPawnFromList: Failed to spawn pawn {pawn} at {parent.Position}.");
if (!pawn.Destroyed)
Pawn pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(pawnKind, parent.Faction));
if (pawn == null)
{
pawn.Destroy();
Log.Error($"CompSpawnPawnFromList: Failed to generate pawn of kind {pawnKind.defName} for faction {parent.Faction?.Name ?? "null"}.");
continue;
}
return;
}
if (Props.lordJob != null)
{
try
if (GenSpawn.Spawn(pawn, parent.Position, parent.Map) == null)
{
LordJob lordJobInstance = (LordJob)System.Activator.CreateInstance(Props.lordJob);
Lord lord = LordMaker.MakeNewLord(parent.Faction, lordJobInstance, parent.Map);
lord.AddPawn(pawn);
Log.Error($"CompSpawnPawnFromList: Failed to spawn pawn {pawn} at {parent.Position}.");
if (!pawn.Destroyed)
{
pawn.Destroy();
}
continue;
}
catch (System.Exception e)
if (Props.lordJob != null)
{
Log.Error($"CompSpawnPawnFromList: Error creating LordJob {Props.lordJob?.Name ?? "null"} or assigning pawn {pawn}. Exception: {e}");
try
{
LordJob lordJobInstance = (LordJob)System.Activator.CreateInstance(Props.lordJob);
Lord lord = LordMaker.MakeNewLord(parent.Faction, lordJobInstance, parent.Map);
lord.AddPawn(pawn);
}
catch (System.Exception e)
{
Log.Error($"CompSpawnPawnFromList: Error creating LordJob {Props.lordJob?.Name ?? "null"} or assigning pawn {pawn}. Exception: {e}");
}
}
}
@@ -114,6 +122,7 @@ namespace ArachnaeSwarm
}
}
public override string CompInspectStringExtra()
{
if (spawnUntilTick > 0)
@@ -136,6 +145,7 @@ namespace ArachnaeSwarm
base.PostExposeData();
Scribe_Values.Look(ref spawnUntilTick, "spawnUntilTick", -1);
Scribe_Defs.Look(ref spawningPawnKind, "spawningPawnKind");
Scribe_Defs.Look(ref selectedPawnKind, "selectedPawnKind");
}
}
}