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));
        }
Exemple #2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            // ツールまで移動
            yield return(Toils_Goto.GotoThing(ToolInd, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(ToolInd));

            // ツールを手に取る
            yield return(Toils_Haul.StartCarryThing(ToolInd));

            // ターゲットが水やり対象として不適になっていたらリストから外す
            Toil initExtractTargetFromQueue = Toils_Mizu.ClearConditionSatisfiedTargets(WateringInd, (lti) =>
            {
                var mapComp = this.Map.GetComponent <MapComponent_Watering>();
                return(mapComp.Get(this.Map.cellIndices.CellToIndex(lti.Cell)) > 0);
            });

            yield return(initExtractTargetFromQueue);

            yield return(Toils_JobTransforms.SucceedOnNoTargetInQueue(WateringInd));

            // ターゲットキューから次のターゲットを取り出す
            yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(WateringInd, true));

            // ターゲットの元へ移動
            yield return(Toils_Goto.GotoCell(WateringInd, PathEndMode.Touch));

            // 作業中
            Toil workToil = new Toil();

            workToil.initAction = delegate
            {
                // 必要工数の計算
                this.ticksLeftThisToil = WorkingTicks;
            };
            // 細々とした設定
            workToil.defaultCompleteMode = ToilCompleteMode.Delay;
            workToil.WithProgressBar(WateringInd, () => 1f - (float)this.ticksLeftThisToil / WorkingTicks, true, -0.5f);
            workToil.PlaySustainerOrSound(() => SoundDefOf.Interact_CleanFilth);
            yield return(workToil);

            // 作業終了
            var finishToil = new Toil();

            finishToil.initAction = () =>
            {
                // 水やり更新
                var mapComp = this.Map.GetComponent <MapComponent_Watering>();
                mapComp.Set(this.Map.cellIndices.CellToIndex(WateringPos), MapComponent_Watering.MaxWateringValue);
                this.Map.mapDrawer.SectionAt(WateringPos).dirtyFlags = MapMeshFlag.Terrain;

                // ツールから水を減らす
                var compTool = Tool.GetComp <CompWaterTool>();
                compTool.StoredWaterVolume -= ConsumeWaterVolume;
            };
            finishToil.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(finishToil);

            // 最初に戻る
            yield return(Toils_Jump.JumpIf(initExtractTargetFromQueue, () =>
            {
                return this.pawn.jobs.curJob.GetTargetQueue(WateringInd).Count > 0;
            }));

            // ツールを片付ける場所を決める
            yield return(Toils_Mizu.TryFindStoreCell(ToolInd, ToolPlaceInd));

            // 倉庫まで移動
            yield return(Toils_Goto.GotoCell(ToolPlaceInd, PathEndMode.Touch));

            // 倉庫に置く
            yield return(Toils_Haul.PlaceHauledThingInCell(ToolPlaceInd, null, true));
        }