coffees-rjw-ideology-addons/CRIALactation/Source/JobDrivers/JobDriver_MassageBreasts.cs

81 lines
2.7 KiB
C#

using Milk;
using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
using RimWorld;
using Verse.AI;
namespace CRIALactation
{
public class JobDriver_MassageBreasts : JobDriver
{
private readonly float WorkTotal = 300f;
public override bool TryMakePreToilReservations(bool errorOnFailed)
{
LocalTargetInfo Target = job.GetTarget(TargetIndex.A);
return pawn.Reserve(Target, job, 1, -1, null, errorOnFailed);
}
protected override IEnumerable<Toil> MakeNewToils()
{
this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);
Toil massage = new Toil();
massage.FailOnDespawnedOrNull(TargetIndex.A);
massage.FailOnAggroMentalStateAndHostile(TargetIndex.A);
massage.initAction = delegate
{
Pawn p = job.GetTarget(TargetIndex.A).Thing as Pawn;
pawn.pather.StopDead();
PawnUtility.ForceWait(p, 15000, null, true);
};
massage.tickAction = delegate ()
{
pawn.skills.Learn(SkillDefOf.Animals, 0.13f, false);
massageProgress += pawn.GetStatValue(StatDefOf.AnimalGatherSpeed, true);
};
massage.AddEndCondition(delegate
{
Pawn p = job.GetTarget(TargetIndex.A).Thing as Pawn;
if (massageProgress >= WorkTotal)
{
p.TryGetComp<CompInduceLactation>().MassageBreasts();
return JobCondition.Succeeded;
}
if (!(p.TryGetComp<CompInduceLactation>().isActive && p.TryGetComp<CompInduceLactation>().CanMassage))
{
return JobCondition.Incompletable;
}
return JobCondition.Ongoing;
});
massage.AddFinishAction(delegate {
Pawn pawn = this.job.GetTarget(TargetIndex.A).Thing as Pawn;
if (pawn != null && pawn.CurJobDef == JobDefOf.Wait_MaintainPosture)
{
pawn.jobs.EndCurrentJob(JobCondition.InterruptForced, true, true);
}
});
massage.defaultCompleteMode = ToilCompleteMode.Never;
massage.WithProgressBar(TargetIndex.A, () => massageProgress / WorkTotal);
massage.activeSkill = (() => SkillDefOf.Animals);
yield return massage;
yield break;
}
float massageProgress = 0f;
}
}