69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
// File: JobDrivers/JobDriver_OperateEquipmentIncubator.cs
|
|
using RimWorld;
|
|
using System.Collections.Generic;
|
|
using Verse;
|
|
using Verse.AI;
|
|
|
|
namespace ArachnaeSwarm
|
|
{
|
|
public class JobDriver_OperateEquipmentIncubator : JobDriver
|
|
{
|
|
private const int OperationDuration = 180;
|
|
|
|
private Building_EquipmentOotheca EquipmentOotheca => (Building_EquipmentOotheca)job.targetA.Thing;
|
|
|
|
public override bool TryMakePreToilReservations(bool errorOnFailed)
|
|
{
|
|
return pawn.Reserve(job.targetA, job, 1, -1, null, errorOnFailed);
|
|
}
|
|
|
|
protected override IEnumerable<Toil> MakeNewToils()
|
|
{
|
|
this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
|
|
this.FailOn(() => EquipmentOotheca == null);
|
|
|
|
yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell)
|
|
.FailOnSomeonePhysicallyInteracting(TargetIndex.A);
|
|
|
|
yield return Toils_General.WaitWith(TargetIndex.A, 10, true, true);
|
|
|
|
var operate = new Toil();
|
|
operate.initAction = () =>
|
|
{
|
|
EquipmentOotheca?.NotifyLarvaArrived(pawn);
|
|
};
|
|
operate.tickAction = () =>
|
|
{
|
|
pawn.rotationTracker.FaceCell(EquipmentOotheca.Position);
|
|
};
|
|
operate.defaultCompleteMode = ToilCompleteMode.Delay;
|
|
operate.defaultDuration = OperationDuration;
|
|
operate.WithProgressBar(TargetIndex.A, () =>
|
|
(float)(OperationDuration - operate.actor.jobs.curDriver.ticksLeftThisToil) / OperationDuration);
|
|
yield return operate;
|
|
|
|
yield return new Toil
|
|
{
|
|
initAction = () =>
|
|
{
|
|
if (EquipmentOotheca != null && pawn != null && pawn.def.defName == "ArachnaeBase_Race_Larva")
|
|
{
|
|
EquipmentOotheca.NotifyLarvaOperationComplete(pawn);
|
|
pawn.Destroy(DestroyMode.Vanish);
|
|
}
|
|
},
|
|
defaultCompleteMode = ToilCompleteMode.Instant
|
|
};
|
|
}
|
|
|
|
public override string GetReport()
|
|
{
|
|
if (EquipmentOotheca != null)
|
|
{
|
|
return "ARA_EquipmentIncubator.ActivatingOotheca".Translate();
|
|
}
|
|
return base.GetReport();
|
|
}
|
|
}
|
|
}
|