孵化job
This commit is contained in:
Binary file not shown.
10
1.6/1.6/Defs/JobDefs/ARA_Jobs.xml
Normal file
10
1.6/1.6/Defs/JobDefs/ARA_Jobs.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Defs>
|
||||
|
||||
<JobDef>
|
||||
<defName>ARA_IncubateJob</defName>
|
||||
<driverClass>ArachnaeSwarm.JobDriver_Incubate</driverClass>
|
||||
<reportString>incubating TargetA.</reportString>
|
||||
</JobDef>
|
||||
|
||||
</Defs>
|
||||
@@ -2,5 +2,6 @@
|
||||
<LanguageData>
|
||||
|
||||
<ARA_Incubate>孵化 {0}</ARA_Incubate>
|
||||
<ARA_NeedsInteraction>未孵化,需要阿拉克涅女皇种交互</ARA_NeedsInteraction>
|
||||
|
||||
</LanguageData>
|
||||
@@ -70,6 +70,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="CompProperties_SpawnPawnFromList.cs" />
|
||||
<Compile Include="CompSpawnPawnFromList.cs" />
|
||||
<Compile Include="JobDriver_Incubate.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace ArachnaeSwarm
|
||||
public List<PawnKindDef> whitelist;
|
||||
public int delay = 0;
|
||||
public bool destroyOnSpawn = false;
|
||||
public IntRange spawnCount = new IntRange(1, 1);
|
||||
public Type lordJob;
|
||||
|
||||
public CompProperties_SpawnPawnFromList()
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
using RimWorld;
|
||||
using Verse.AI;
|
||||
using Verse.AI.Group;
|
||||
|
||||
namespace ArachnaeSwarm
|
||||
{
|
||||
public class CompSpawnPawnFromList : ThingComp
|
||||
{
|
||||
private CompProperties_SpawnPawnFromList Props => (CompProperties_SpawnPawnFromList)props;
|
||||
public CompProperties_SpawnPawnFromList Props => (CompProperties_SpawnPawnFromList)props;
|
||||
|
||||
private int spawnUntilTick = -1;
|
||||
private PawnKindDef spawningPawnKind;
|
||||
private PawnKindDef selectedPawnKind;
|
||||
|
||||
public override IEnumerable<FloatMenuOption> CompFloatMenuOptions(Pawn selPawn)
|
||||
{
|
||||
@@ -30,15 +32,17 @@ namespace ArachnaeSwarm
|
||||
{
|
||||
yield return new FloatMenuOption("ARA_Incubate".Translate(pawnKind.label), () =>
|
||||
{
|
||||
StartDelayedSpawn(pawnKind);
|
||||
Job job = JobMaker.MakeJob(DefDatabase<JobDef>.GetNamed("ARA_IncubateJob"), parent);
|
||||
selectedPawnKind = pawnKind;
|
||||
selPawn.jobs.TryTakeOrderedJob(job);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void StartDelayedSpawn(PawnKindDef pawnKind)
|
||||
public void StartIncubation()
|
||||
{
|
||||
spawningPawnKind = pawnKind;
|
||||
spawningPawnKind = selectedPawnKind;
|
||||
spawnUntilTick = Find.TickManager.TicksGame + Props.delay;
|
||||
}
|
||||
|
||||
@@ -115,9 +119,16 @@ namespace ArachnaeSwarm
|
||||
if (spawnUntilTick > 0)
|
||||
{
|
||||
int remainingTicks = spawnUntilTick - Find.TickManager.TicksGame;
|
||||
return $"Spawning in: {remainingTicks.ToStringTicksToPeriod()}";
|
||||
if (remainingTicks > 0)
|
||||
{
|
||||
return "Spawning {0} in: {1}".Translate(spawningPawnKind.label, remainingTicks.ToStringTicksToPeriod());
|
||||
}
|
||||
}
|
||||
return base.CompInspectStringExtra();
|
||||
else
|
||||
{
|
||||
return "ARA_NeedsInteraction".Translate();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public override void PostExposeData()
|
||||
|
||||
36
Source/ArachnaeSwarm/JobDriver_Incubate.cs
Normal file
36
Source/ArachnaeSwarm/JobDriver_Incubate.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
|
||||
namespace ArachnaeSwarm
|
||||
{
|
||||
public class JobDriver_Incubate : JobDriver
|
||||
{
|
||||
private const TargetIndex EggSacInd = TargetIndex.A;
|
||||
private const TargetIndex PawnKindInd = TargetIndex.B;
|
||||
|
||||
public override bool TryMakePreToilReservations(bool errorOnFailed)
|
||||
{
|
||||
return pawn.Reserve(job.GetTarget(EggSacInd), job, 1, -1, null, errorOnFailed);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Toil> MakeNewToils()
|
||||
{
|
||||
this.FailOnDespawnedNullOrForbidden(EggSacInd);
|
||||
|
||||
yield return Toils_Goto.GotoThing(EggSacInd, PathEndMode.Touch);
|
||||
|
||||
Toil incubate = new Toil();
|
||||
incubate.initAction = () =>
|
||||
{
|
||||
CompSpawnPawnFromList comp = job.GetTarget(EggSacInd).Thing.TryGetComp<CompSpawnPawnFromList>();
|
||||
if (comp != null)
|
||||
{
|
||||
comp.StartIncubation();
|
||||
}
|
||||
};
|
||||
incubate.defaultCompleteMode = ToilCompleteMode.Instant;
|
||||
yield return incubate;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user