public static Toil JumpIfOutsideMopArea(this Toil toil, TargetIndex ind, Toil jumpToil) { return(toil.JumpIf(delegate { var target = toil.actor.jobs.curJob.GetTarget(ind); IntVec3 pos = (target.HasThing) ? target.Thing.Position : target.Cell; return !toil.actor.Map.areaManager.Mop()[pos]; }, jumpToil)); }
protected override IEnumerable <Toil> MakeNewToils() { // モップまで移動 yield return(Toils_Goto.GotoThing(MopInd, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(MopInd)); // モップを手に取る yield return(Toils_Haul.StartCarryThing(MopInd)); // ターゲットが掃除対象として不適になっていたらリストから外す // Thing系にしか使えない var initExtractTargetFromQueue = Toils_Mizu.ClearConditionSatisfiedTargets( MoppingInd, lti => lti.Cell.GetFirstThing(pawn.Map, MizuDef.Thing_MoppedThing) != null); yield return(initExtractTargetFromQueue); yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(MoppingInd)); // ターゲットキューから次のターゲットを取り出す yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(MoppingInd)); // ターゲットの元へ移動 yield return(Toils_Goto.GotoCell(MoppingInd, PathEndMode.Touch).JumpIf( () => { var target = pawn.jobs.curJob.GetTarget(MoppingInd); if (target.HasThing) { return true; } return target.Cell.GetFirstThing(pawn.Map, MizuDef.Thing_MoppedThing) != null; }, initExtractTargetFromQueue).JumpIfOutsideMopArea(MoppingInd, initExtractTargetFromQueue)); // モップ掛け作業中 var mopToil = new Toil { initAction = delegate { // 必要工数の計算 ticksLeftThisToil = MoppingTicks; }, // 細々とした設定 defaultCompleteMode = ToilCompleteMode.Delay }; mopToil.WithProgressBar(MoppingInd, () => 1f - ((float)ticksLeftThisToil / MoppingTicks), true); mopToil.PlaySustainerOrSound(() => SoundDefOf.Interact_CleanFilth); // 掃除中に条件が変更されたら最初に戻る mopToil.JumpIf( () => { var target = pawn.jobs.curJob.GetTarget(MoppingInd); if (target.HasThing) { return(true); } return(target.Cell.GetFirstThing(pawn.Map, MizuDef.Thing_MoppedThing) != null); }, initExtractTargetFromQueue); mopToil.JumpIfOutsideMopArea(MoppingInd, initExtractTargetFromQueue); yield return(mopToil); // モップ掛け終了 var finishToil = new Toil { initAction = () => { // モップオブジェクト生成 var moppedThing = ThingMaker.MakeThing(MizuDef.Thing_MoppedThing); GenSpawn.Spawn(moppedThing, MoppingPos, mopToil.actor.Map); // モップから水を減らす var compTool = Mop.GetComp <CompWaterTool>(); compTool.StoredWaterVolume -= ConsumeWaterVolume; }, defaultCompleteMode = ToilCompleteMode.Instant }; yield return(finishToil); // 最初に戻る yield return(Toils_Jump.JumpIf( initExtractTargetFromQueue, () => pawn.jobs.curJob.GetTargetQueue(MoppingInd).Count > 0)); // モップを片付ける場所を決める yield return(Toils_Mizu.TryFindStoreCell(MopInd, MopPlaceInd)); // Toil startCarryToil = new Toil(); // startCarryToil.initAction = () => // { // var actor = startCarryToil.actor; // var curJob = actor.jobs.curJob; // IntVec3 c; // if (StoreUtility.TryFindBestBetterStoreCellFor(Mop, actor, actor.Map, StoragePriority.Unstored, actor.Faction, out c)) // { // curJob.targetC = c; // curJob.count = 99999; // return; // } // }; // startCarryToil.defaultCompleteMode = ToilCompleteMode.Instant; // yield return startCarryToil; // 倉庫まで移動 yield return(Toils_Goto.GotoCell(MopPlaceInd, PathEndMode.Touch)); // 倉庫に置く yield return(Toils_Haul.PlaceHauledThingInCell(MopPlaceInd, null, true)); }
protected override IEnumerable <Toil> MakeNewToils() { rotateToFace = Facing; AddEndCondition(delegate { if (ExecutionerPawn == null) { return(JobCondition.Incompletable); } if (ExecutionerPawn.CurJob == null) { return(JobCondition.Incompletable); } if (ExecutionerPawn.CurJob.def == CultsDefOf.Cults_ReflectOnResult) { return(JobCondition.Succeeded); } if (ExecutionerPawn.CurJob.def != CultsDefOf.Cults_HoldSacrifice) { return(JobCondition.Incompletable); } return(JobCondition.Ongoing); }); this.EndOnDespawnedOrNull(Spot); this.EndOnDespawnedOrNull(Build); yield return(Toils_Reserve.Reserve(Spot)); //Toil 1: Go to the locations Toil gotoExecutioner; if (TargetC.HasThing) { gotoExecutioner = Toils_Goto.GotoThing(Spot, PathEndMode.OnCell); } else { gotoExecutioner = Toils_Goto.GotoCell(Spot, PathEndMode.OnCell); } yield return(gotoExecutioner); //Toil 2: 'Attend' var altarToil = new Toil { defaultCompleteMode = ToilCompleteMode.Delay, defaultDuration = CultUtility.ritualDuration }; altarToil.AddPreTickAction(() => { pawn.GainComfortFromCellIfPossible(); pawn.rotationTracker.FaceCell(TargetB.Cell); if (report == "") { report = "Cults_AttendingSacrifice".Translate(); } if (ExecutionerPawn != null) { if (ExecutionerPawn.CurJob != null) { if (ExecutionerPawn.CurJob.def != CultsDefOf.Cults_HoldSacrifice) { ReadyForNextToil(); } } } }); altarToil.JumpIf(() => ExecutionerPawn.CurJob.def == CultsDefOf.Cults_HoldSacrifice, altarToil); yield return(altarToil); //ToDo -- Add random Ia! Ia! yield return(new Toil { initAction = delegate { //Do something? Ia ia! }, defaultCompleteMode = ToilCompleteMode.Instant }); //Toil 3 Reflect on worship var reflectingTime = new Toil { defaultCompleteMode = ToilCompleteMode.Delay, defaultDuration = CultUtility.reflectDuration }; reflectingTime.AddPreTickAction(() => report = "Cults_ReflectingOnSacrifice".Translate()); yield return(reflectingTime); //Toil 3 Reset the altar and clear variables. yield return(new Toil { initAction = delegate { if (Altar != null) { if (Altar.currentSacrificeState != Building_SacrificialAltar.SacrificeState.finished) { Altar.ChangeState(Building_SacrificialAltar.State.sacrificing, Building_SacrificialAltar.SacrificeState.finished); } } }, defaultCompleteMode = ToilCompleteMode.Instant }); AddFinishAction(() => { //When the ritual is finished -- then let's give the thoughts /* * if (Altar.currentSacrificeState == Building_SacrificialAltar.SacrificeState.finished) * { * if (this.pawn == null) return; * if (Altar.sacrifice != null) * { * CultUtility.AttendSacrificeTickCheckEnd(this.pawn, Altar.sacrifice); * } * else * { * CultUtility.AttendSacrificeTickCheckEnd(this.pawn, null); * } * } */ if (TargetC.Cell.GetEdifice(pawn.Map) != null) { if (pawn.Map.reservationManager.ReservedBy(TargetC.Cell.GetEdifice(pawn.Map), pawn)) { pawn.ClearAllReservations(); // this.pawn.Map.reservationManager.Release(this.TargetC.Cell.GetEdifice(this.pawn.Map), pawn); } } else { if (pawn.Map.reservationManager.ReservedBy(TargetC.Cell.GetEdifice(pawn.Map), pawn)) { pawn.ClearAllReservations(); //this.pawn.Map.reservationManager.Release(this.job.targetC.Cell, this.pawn); } } }); }