Exemplo n.º 1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(ToyInd, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(ToyInd));

            yield return(Toils_Ingest.PickupIngestible(ToyInd, pawn));

            yield return(CarryToyToSpot(pawn, ToyInd));

            yield return(Toils_Ingest.FindAdjacentEatSurface(joySpot, ToyInd));

            var playWithToy = new Toil
            {
                tickAction = WaitTickAction()
            };

            playWithToy.AddFinishAction(() =>
            {
                JoyUtility.TryGainRecRoomThought(pawn);
                TalkToDoll();
            });
            playWithToy.defaultCompleteMode = ToilCompleteMode.Delay;
            playWithToy.defaultDuration     = job.def.joyDuration;
            playWithToy.handlingFacing      = true;
            yield return(playWithToy);
        }
Exemplo n.º 2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Goto.GotoThing(PuzzleBoxInd, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(PuzzleBoxInd));

            yield return(Toils_Ingest.PickupIngestible(PuzzleBoxInd, this.pawn));

            yield return(CarryPuzzleToSpot(pawn, PuzzleBoxInd));

            yield return(Toils_Ingest.FindAdjacentEatSurface(joySpot, PuzzleBoxInd));

            Toil puzzle;

            puzzle = new Toil();

            puzzle.tickAction = this.WaitTickAction();
            puzzle.AddFinishAction(() =>
            {
                JoyUtility.TryGainRecRoomThought(this.pawn);
                this.RollForLuck();
            });
            puzzle.defaultCompleteMode = ToilCompleteMode.Delay;
            puzzle.defaultDuration     = this.job.def.joyDuration;
            puzzle.handlingFacing      = true;
            yield return(puzzle);
        }
Exemplo n.º 3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            if (this.job.targetA.HasThing)
            {
                // ターゲットがThing=水アイテムを摂取する場合
                // 水が使用不可能になったらFail
                ToilFailConditions.FailOnDestroyedNullOrForbidden <JobDriver_DrinkWater>(this, WaterIndex);

                // 水を取得
                if (this.drinkingFromInventory)
                {
                    // 所持品から取り出す
                    yield return(Toils_Mizu.StartCarryFromInventory(WaterIndex));
                }
                else
                {
                    // 水の場所まで行く
                    yield return(Toils_Goto.Goto(WaterIndex, PathEndMode.OnCell));

                    // 水を拾う
                    yield return(Toils_Ingest.PickupIngestible(WaterIndex, this.pawn));
                }

                // 飲む場所を決めてそこへ移動
                yield return(Toils_Mizu.StartPathToDrinkSpot(WaterIndex));

                // 水を摂取
                yield return(Toils_Mizu.Drink(WaterIndex));

                // 水の摂取終了(心情、水分、アイテム個数の処理)
                yield return(Toils_Mizu.FinishDrink(WaterIndex));

                if (this.drinkingFromInventory && !this.TargetA.ThingDestroyed)
                {
                    // 所持品から取り出した&まだ残っている場合は所持品に戻す
                    yield return(Toils_Mizu.AddCarriedThingToInventory());
                }
            }
            else
            {
                // ターゲットがThingではない=水アイテムを摂取しない場合=水地形を利用する場合

                // 選んだ水地形が使用不可能or到達不可能になったらFail
                ToilFailConditions.FailOn <JobDriver_DrinkWater>(this, () =>
                {
                    return(this.job.targetA.Cell.IsForbidden(pawn) || !pawn.CanReach(this.job.targetA.Cell, PathEndMode.ClosestTouch, Danger.Deadly));
                });

                // 水地形まで移動
                yield return(Toils_Goto.GotoCell(WaterIndex, PathEndMode.OnCell));

                // 水地形から水分を摂取
                yield return(Toils_Mizu.DrinkTerrain(WaterIndex, BaseDrinkTicksFromTerrain));

                // 終了
                //yield return Toils_Mizu.FinishDrinkTerrain(WaterIndex);
            }
        }
Exemplo n.º 4
0
        private IEnumerable <Toil> PrepareToIngestToils_ToolUser(Toil chewToil)
        {
            if (eatingFromInventory)
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, TargetIndex.A));
            }
            else
            {
                yield return(ReserveFoodIfWillIngestWholeStack());

                Toil gotoToPickup = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A);
                yield return(Toils_Jump.JumpIf(gotoToPickup, () => pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(TargetIndex.A));

                yield return(Toils_Jump.Jump(chewToil));

                yield return(gotoToPickup);

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, pawn));

                Toil reserveExtraFoodToCollect = Toils_Reserve.Reserve(TargetIndex.C);
                Toil findExtraFoodToCollect    = new Toil();
                findExtraFoodToCollect.initAction = delegate
                {
                    if (pawn.inventory.innerContainer.TotalStackCountOfDef(IngestibleSource.def) < job.takeExtraIngestibles)
                    {
                        Predicate <Thing> validator = (Thing x) => pawn.CanReserve(x) &&
                                                      !x.IsForbidden(pawn) && x.IsSociallyProper(pawn);
                        Thing thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map,
                                                                       ThingRequest.ForDef(IngestibleSource.def), PathEndMode.Touch,
                                                                       TraverseParms.For(pawn),
                                                                       12f, validator);
                        if (thing != null)
                        {
                            pawn.CurJob.SetTarget(TargetIndex.C, thing);
                            JumpToToil(reserveExtraFoodToCollect);
                        }
                    }
                };
                findExtraFoodToCollect.defaultCompleteMode = ToilCompleteMode.Instant;
                yield return(Toils_Jump.Jump(findExtraFoodToCollect));

                yield return(reserveExtraFoodToCollect);

                yield return(Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.Touch));

                yield return(Toils_Haul.TakeToInventory(TargetIndex.C,
                                                        () => job.takeExtraIngestibles - pawn.inventory.innerContainer.TotalStackCountOfDef(IngestibleSource.def)));

                yield return(findExtraFoodToCollect);
            }
            yield return(Toils_Ingest.CarryIngestibleToChewSpot(pawn, TargetIndex.A).FailOnDestroyedOrNull(TargetIndex.A));

            yield return(Toils_Ingest.FindAdjacentEatSurface(TargetIndex.B, TargetIndex.A));
        }
Exemplo n.º 5
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            List <Toil>   toilsList       = new List <Toil>();
            Building_Pyre pyre            = this.TargetThingA as Building_Pyre;
            bool          beerIsAvailable = false;

            if (this.pawn.Position.InHorDistOf(pyre.Position, Building_Pyre.partyAreaRadius) == false)
            {
                // Go around pyre.
                toilsList.Add(base.ToilGetWanderCell(pyre.Position));
                Find.PawnDestinationManager.ReserveDestinationFor(this.pawn, this.CurJob.targetB.Cell);
                toilsList.Add(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.OnCell));
                // Release cell (the pawn will either go grab a beer or move on the next job).
                toilsList.Add(base.ToilReleaseCell());
            }
            // Look for an available beer.
            List <Thing> list = Find.ListerThings.ThingsOfDef(ThingDefOf.Beer);

            if (list.Count > 0)
            {
                Predicate <Thing> validator = (Thing t) => pawn.CanReserve(t, 1) && !t.IsForbidden(pawn);
                Thing             beer      = GenClosest.ClosestThing_Global_Reachable(pyre.Position, list, PathEndMode.OnCell, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), Building_Pyre.beerSearchAreaRadius, validator, null);
                if (beer != null)
                {
                    beerIsAvailable = true;
                    this.CurJob.SetTarget(TargetIndex.A, beer);
                    //this.CurJob.targetA = beer;
                    this.CurJob.maxNumToCarry = 1;
                    toilsList.Add(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A));
                    toilsList.Add(Toils_Ingest.PickupIngestible(TargetIndex.A, this.pawn)); // TargetIndex.A becomes the carried beer.
                    toilsList.Add(Toils_Ingest.CarryIngestibleToChewSpot(this.pawn));
                    toilsList.Add(Toils_Ingest.FindAdjacentEatSurface(TargetIndex.B, TargetIndex.A));
                    // float durationMultiplier = 1f / this.pawn.GetStatValue(StatDefOf.EatingSpeed, true); // Don't use it so the job duration is nearly the same for all pawns.
                    float durationMultiplier = 1f;
                    toilsList.Add(Toils_Ingest.ChewIngestible(this.pawn, durationMultiplier, TargetIndex.A, TargetIndex.B).FailOn((Toil x) => !this.Food.Spawned && (this.pawn.carrier == null || this.pawn.carrier.CarriedThing != this.Food)));
                    toilsList.Add(Toils_Ingest.FinalizeIngest(this.pawn, TargetIndex.A));
                }
            }
            // Draw a mote.
            ThingDef moteDef = null;

            if (beerIsAvailable)
            {
                moteDef = Util_CampfireParty.Mote_BeerAvailable;
            }
            else
            {
                moteDef = Util_CampfireParty.Mote_BeerUnavailable;
            }
            MoteAttached moteAttached = (MoteAttached)ThingMaker.MakeThing(moteDef);

            moteAttached.AttachTo(this.pawn);
            GenSpawn.Spawn(moteAttached, this.pawn.Position);

            return(toilsList);
        }
Exemplo n.º 6
0
        internal static IEnumerable <Toil> _MakeNewToils(this JobDriver_FoodFeedPatient obj)
        {
            var foodThing = obj.TargetThing(FoodInd);
            var deliveree = (Pawn)obj.TargetThing(DelivereeInd);

            obj.FailOnDespawnedNullOrForbidden(DelivereeInd);
            obj.FailOn(() =>
            {
                return(!FoodUtility.ShouldBeFedBySomeone(deliveree));
            });

            yield return(Toils_Reserve.Reserve(DelivereeInd, 1));

            if (foodThing is Building)
            {
                yield return(Toils_Reserve.Reserve(FoodInd, 1));

                yield return(Toils_Goto.GotoThing(FoodInd, PathEndMode.InteractionCell).FailOnForbidden(FoodInd));

                if (foodThing is Building_NutrientPasteDispenser)
                {
                    yield return(Toils_Ingest.TakeMealFromDispenser(FoodInd, obj.pawn));
                }
                else if (foodThing is Building_AutomatedFactory)
                {
                    yield return(Toils_FoodSynthesizer.TakeMealFromSynthesizer(FoodInd, obj.pawn));
                }
                else // Unknown building
                {
                    throw new Exception("Food target for JobDriver_FoodDeliver is a building but not Building_NutrientPasteDispenser or Building_AutomatedFactory!");
                }
            }
            else if (
                (obj.pawn.inventory != null) &&
                (obj.pawn.inventory.Contains(foodThing))
                )
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(obj.pawn, FoodInd));
            }
            else
            {
                yield return(Toils_Reserve.Reserve(FoodInd, 1));

                yield return(Toils_Goto.GotoThing(FoodInd, PathEndMode.ClosestTouch).FailOnForbidden(FoodInd));

                yield return(Toils_Ingest.PickupIngestible(FoodInd, deliveree));
            }

            yield return(Toils_Goto.GotoThing(DelivereeInd, PathEndMode.Touch));

            yield return(Toils_Ingest.ChewIngestible(deliveree, FeedDurationMultiplier, FoodInd));

            yield return(Toils_Ingest.FinalizeIngest(deliveree, FoodInd));
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOn(() => PrisonerFoodReservation.isReserved(TargetA.Thing));
            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null));

            if (eatingFromInventory)
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(pawn, TargetIndex.A));
            }
            else if (usingNutrientPasteDispenser)
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell)
                             .FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, pawn));
            }
            else
            {
                yield return(Toils_Reserve.Reserve(TargetIndex.A, 1, -1, null));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch)
                             .FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, Deliveree));
            }
            var toil = new Toil();

            toil.initAction = delegate
            {
                var actor  = toil.actor;
                var curJob = actor.jobs.curJob;
                actor.pather.StartPath(curJob.targetC, PathEndMode.OnCell);
            };
            toil.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            toil.FailOnDestroyedNullOrForbidden(TargetIndex.B);
            toil.AddFailCondition(delegate
            {
                var pawn = (Pawn)toil.actor.jobs.curJob.targetB.Thing;
                return(!pawn.IsPrisonerOfColony || !pawn.guest.CanBeBroughtFood);
            });
            yield return(toil);

            yield return(new Toil
            {
                initAction = delegate
                {
                    Thing thing;
                    pawn.carryTracker.TryDropCarriedThing(toil.actor.jobs.curJob.targetC.Cell, ThingPlaceMode.Direct,
                                                          out thing, null);
                    PrisonerFoodReservation.reserve(thing, (Pawn)toil.actor.jobs.curJob.targetB.Thing);
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
        }
Exemplo n.º 8
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(this.ReserveFood());

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A));

            yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, this.pawn));

            Toil empty = new Toil();

            yield return(Toils_Jump.JumpIf(empty, delegate()
            {
                LocalTargetInfo food = this.job.GetTarget(TargetIndex.A);
                CompDFoodTemperature comp = food.Thing.TryGetComp <CompDFoodTemperature>();
                if (comp == null)
                {
                    return true;
                }
                if (comp.PropsTemp.likesHeat)
                {
                    return comp.curTemp >= comp.targetCookingTemp;
                }
                return comp.curTemp > 0;
            }));

            if (!HotMealsSettings.multipleHeat)
            {
                yield return(Toils_Reserve.Reserve(TargetIndex.C));

                yield return(Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.InteractionCell).FailOnDestroyedOrNull(TargetIndex.C));

                yield return(Toils_HeatMeal.HeatMeal().FailOnDespawnedNullOrForbiddenPlacedThings().FailOnCannotTouch(TargetIndex.C, PathEndMode.InteractionCell));

                yield return(Toils_Reserve.Release(TargetIndex.C));
            }
            else
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.Touch).FailOnDestroyedOrNull(TargetIndex.C));

                yield return(Toils_HeatMeal.HeatMeal().FailOnDespawnedNullOrForbiddenPlacedThings().FailOnCannotTouch(TargetIndex.C, PathEndMode.Touch));
            }
            yield return(empty);

            yield break;
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            if (this.pawn.inventory != null && this.pawn.inventory.Contains(base.TargetThingA))
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(this.pawn, TargetIndex.A));
            }
            else
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, this.pawn));
            }
            yield return(Toils_Ingest.ChewIngestible(this.pawn, 1f, TargetIndex.A));

            yield return(Toils_DrugIngest.FinalizeIngest(this.pawn, TargetIndex.A));

            yield break;
        }
        internal static IEnumerable <Toil> _MakeNewToils(this JobDriver_FoodFeedPatient obj)
        {
            Pawn deliveree = (Pawn)obj.pawn.CurJob.targetB.Thing;

            obj.FailOnDespawnedNullOrForbidden(TargetIndex.B);
            obj.FailOn(() =>
            {
                return(!FoodUtility.ShouldBeFedBySomeone(deliveree));
            });

            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1));

            var targetThingA = obj.TargetThingA();

            if (targetThingA is Building)
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell).FailOnForbidden(TargetIndex.A));

                if (targetThingA is Building_NutrientPasteDispenser)
                {
                    yield return(Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, obj.pawn));
                }
                if (targetThingA is Building_AutomatedFactory)
                {
                    yield return(Toils_FoodSynthesizer.TakeMealFromSynthesizer(TargetIndex.A, obj.pawn));
                }
            }
            else
            {
                yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnForbidden(TargetIndex.A));

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, deliveree));
            }

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.Touch));

            yield return(Toils_Ingest.ChewIngestible(deliveree, 1.5f, TargetIndex.A));

            yield return(Toils_Ingest.FinalizeIngest(deliveree, TargetIndex.A));
        }
Exemplo n.º 11
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            // 水が使用不可能になったらFail
            ToilFailConditions.FailOnDestroyedNullOrForbidden <JobDriver_WaterDeliver>(this, WaterIndex);

            if (!this.pawn.CanReserveAndReach(this.TargetA, PathEndMode.Touch, Danger.Deadly, 1, this.job.count))
            {
                // 水を予約できなかったら終了
                this.pawn.jobs.EndCurrentJob(JobCondition.Incompletable);
                yield break;
            }

            // 予約する
            if (!this.pawn.Map.reservationManager.ReservedBy(this.TargetA.Thing, pawn))
            {
                yield return(Toils_Reserve.Reserve(WaterIndex, 1, this.job.count, null));
            }

            if (this.drinkingFromInventory)
            {
                // 水を持ち物から取り出す
                yield return(Toils_Mizu.StartCarryFromInventory(WaterIndex));
            }
            else
            {
                // 水の場所まで行く
                yield return(Toils_Goto.Goto(WaterIndex, PathEndMode.OnCell));

                // 水を拾う
                yield return(Toils_Ingest.PickupIngestible(WaterIndex, this.pawn));
            }

            // スポットまで移動する
            yield return(Toils_Goto.GotoCell(this.TargetC.Cell, PathEndMode.OnCell));

            // 置いて囚人に予約させる
            yield return(Toils_Mizu.DropCarriedThing(PrisonerIndex, DropSpotIndex));
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            // ターゲットがThing=水アイテムを摂取する場合

            // 水(食事)が使用不可能になったらFail
            ToilFailConditions.FailOnDestroyedNullOrForbidden(this, WaterIndex);
            ToilFailConditions.FailOn(this, () =>
            {
                if (this.Patient == null)
                {
                    return(true);
                }

                // 患者がベッドに入ってなかったらFail
                if (!this.Patient.InBed())
                {
                    return(true);
                }

                // 到達不能になっていたらFail
                if (!this.pawn.CanReach(this.Patient, PathEndMode.ClosestTouch, Danger.Deadly))
                {
                    return(true);
                }

                return(false);
            });

            // 水が予約出来ない状態なら中断
            if (!ReservationUtility.CanReserveAndReach(this.pawn, this.TargetA, PathEndMode.Touch, Danger.Deadly, 1, this.job.count, null, false))
            {
                this.GetActor().jobs.EndCurrentJob(JobCondition.Incompletable);
                yield break;
            }

            // 水を予約する
            if (!this.pawn.Map.reservationManager.ReservedBy(this.TargetA.Thing, pawn))
            {
                yield return(Toils_Reserve.Reserve(WaterIndex, 1, this.job.count, null));
            }

            if (this.getItemFromInventory)
            {
                // 水を持ち物から取り出す
                yield return(Toils_Mizu.StartCarryFromInventory(WaterIndex));
            }
            else
            {
                // 水の場所まで行く
                yield return(Toils_Goto.Goto(WaterIndex, PathEndMode.OnCell));

                // 水を拾う
                yield return(Toils_Ingest.PickupIngestible(WaterIndex, this.pawn));
            }

            // 患者のもとへ移動
            yield return(Toils_Goto.Goto(PatientIndex, PathEndMode.Touch));

            // 水を飲ませる
            yield return(Toils_Mizu.FeedToPatient(WaterIndex, PatientIndex));

            // 水の摂取終了(心情、食事の処理)
            yield return(Toils_Mizu.FinishDrinkPatient(WaterIndex, PatientIndex));

            if (this.getItemFromInventory && !this.TargetA.ThingDestroyed)
            {
                // 所持品から取り出した&まだ残っている場合は所持品に戻す
                yield return(Toils_Mizu.AddCarriedThingToInventory());
            }
        }
Exemplo n.º 13
0
        static IEnumerable <Toil> prepToils(JobDriver_Ingest driver, Toil chewToil)
        {
            if ((bool)LeatingFromInventory.GetValue(driver))
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(driver.pawn, TargetIndex.A));
            }
            else
            {
                yield return((Toil)LReserveFood.Invoke(driver, new object[] { }));

                Toil gotoToPickup = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A);
                yield return(Toils_Jump.JumpIf(gotoToPickup, () => driver.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(TargetIndex.A));

                yield return(Toils_Jump.Jump(chewToil));

                yield return(gotoToPickup);

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, driver.pawn));

                gotoToPickup = null;
            }
            if (driver.job.takeExtraIngestibles > 0)
            {
                foreach (Toil toil in (IEnumerable <Toil>)LTakeExtraIngestibles.Invoke(driver, new object[] { }))
                {
                    yield return(toil);
                }
            }
            if (!driver.pawn.Drafted)
            {
                yield return(reserveChewSpot(driver.pawn, TargetIndex.A, TargetIndex.B));

                Toil gotospot = gotoSpot(TargetIndex.B).FailOnDestroyedOrNull(TargetIndex.A);

                if (!Utility.IncapableOfCleaning(driver.pawn))
                {
                    TargetIndex filthListIndex = TargetIndex.B;
                    TargetIndex progIndex      = TargetIndex.A;
                    Toil        FilthList      = new Toil();
                    FilthList.initAction = delegate()
                    {
                        Job curJob = FilthList.actor.jobs.curJob;
                        //
                        if (curJob.GetTargetQueue(filthListIndex).NullOrEmpty())
                        {
                            LocalTargetInfo A = curJob.GetTarget(filthListIndex);
                            if (!A.HasThing)
                            {
                                return;
                            }
                            IEnumerable <Filth> l = Utility.SelectAllFilth(FilthList.actor, A, Settings.adv_clean_num);
                            Utility.AddFilthToQueue(curJob, filthListIndex, l, FilthList.actor);
                            FilthList.actor.ReserveAsManyAsPossible(curJob.GetTargetQueue(filthListIndex), curJob);
                            curJob.GetTargetQueue(filthListIndex).Add(A);
                        }
                    };

                    yield return(FilthList);

                    yield return(Toils_Jump.JumpIf(gotospot, () => driver.job.GetTargetQueue(filthListIndex).NullOrEmpty()));

                    Toil nextTarget = Toils_JobTransforms.ExtractNextTargetFromQueue(filthListIndex, true);
                    yield return(nextTarget);

                    yield return(Toils_Jump.JumpIf(gotospot, () => driver.job.GetTargetQueue(filthListIndex).NullOrEmpty()));

                    yield return(Toils_Goto.GotoThing(filthListIndex, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(filthListIndex, nextTarget).JumpIfOutsideHomeArea(filthListIndex, nextTarget));

                    //
                    if (driver.job.GetTargetQueue(progIndex).Count == 0)
                    {
                        driver.job.GetTargetQueue(progIndex).Add(new IntVec3(0, 0, 0));
                    }
                    //
                    Toil clean = new Toil();
                    clean.initAction = delegate()
                    {
                        Filth filth   = clean.actor.jobs.curJob.GetTarget(filthListIndex).Thing as Filth;
                        var   progQue = clean.actor.jobs.curJob.GetTargetQueue(progIndex);
                        progQue[0] = new IntVec3(0, 0, (int)filth.def.filth.cleaningWorkToReduceThickness * filth.thickness);
                    };
                    clean.tickAction = delegate()
                    {
                        Filth   filth   = clean.actor.jobs.curJob.GetTarget(filthListIndex).Thing as Filth;
                        var     progQue = clean.actor.jobs.curJob.GetTargetQueue(progIndex);
                        IntVec3 iv      = progQue[0].Cell;
                        iv.x += 1;
                        iv.y += 1;
                        if (iv.x > filth.def.filth.cleaningWorkToReduceThickness)
                        {
                            filth.ThinFilth();
                            iv.x = 0;
                            if (filth.Destroyed)
                            {
                                clean.actor.records.Increment(RecordDefOf.MessesCleaned);
                                driver.ReadyForNextToil();
                                return;
                            }
                        }
                        progQue[0] = iv;
                    };
                    clean.defaultCompleteMode = ToilCompleteMode.Never;
                    clean.WithEffect(EffecterDefOf.Clean, filthListIndex);
                    clean.WithProgressBar(filthListIndex,
                                          delegate()
                    {
                        var q        = driver.job.GetTargetQueue(progIndex)[0];
                        float result = (float)q.Cell.y / q.Cell.z;
                        return(result);
                    }
                                          , true, -0.5f);
                    clean.PlaySustainerOrSound(() => SoundDefOf.Interact_CleanFilth);
                    clean.JumpIfDespawnedOrNullOrForbidden(filthListIndex, nextTarget);
                    clean.JumpIfOutsideHomeArea(filthListIndex, nextTarget);
                    clean.FailOnDestroyedOrNull(TargetIndex.A);
                    yield return(clean);

                    yield return(Toils_Jump.Jump(nextTarget));
                }
                yield return(gotospot);
            }
            yield return(Toils_Ingest.FindAdjacentEatSurface(TargetIndex.B, TargetIndex.A));

            yield break;
        }
        internal static IEnumerable <Toil> _MakeNewToils(this JobDriver_FoodDeliver obj)
        {
            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1));

            var targetThingA = obj.TargetThingA();

            if (targetThingA is Building)
            {
                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell));

                if (targetThingA is Building_NutrientPasteDispenser)
                {
                    yield return(Toils_Ingest.TakeMealFromDispenser(TargetIndex.A, obj.pawn));
                }
                if (targetThingA is Building_AutomatedFactory)
                {
                    yield return(Toils_FoodSynthesizer.TakeMealFromSynthesizer(TargetIndex.A, obj.pawn));
                }
            }
            else
            {
                var deliveree = (Pawn)obj.pawn.CurJob.targetB.Thing;
                yield return(Toils_Reserve.Reserve(TargetIndex.A, 1));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch));

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, deliveree));
            }

            var pathToTarget = new Toil();

            pathToTarget.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            pathToTarget.initAction          = new Action(() =>
            {
                Pawn pawn = obj.pawn;
                Job job   = pawn.jobs.curJob;
                pawn.pather.StartPath(job.targetC, PathEndMode.OnCell);
            }
                                                          );
            pathToTarget.FailOnDestroyedNullOrForbidden(TargetIndex.B);
            pathToTarget.AddFailCondition(() =>
            {
                Pawn pawn = (Pawn)obj.pawn.jobs.curJob.targetB.Thing;
                return
                ((pawn.Downed) ||
                 (!pawn.IsPrisonerOfColony) ||
                 (!pawn.guest.ShouldBeBroughtFood));
            });
            yield return(pathToTarget);

            var dropFoodAtTarget = new Toil();

            dropFoodAtTarget.initAction = new Action(() =>
            {
                Thing resultingThing;
                obj.pawn.carrier.TryDropCarriedThing(obj.pawn.jobs.curJob.targetC.Cell, ThingPlaceMode.Direct, out resultingThing);
            }
                                                     );
            dropFoodAtTarget.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(dropFoodAtTarget);
        }
Exemplo n.º 15
0
        static IEnumerable <Toil> prepToils(JobDriver_Ingest driver, Toil chewToil)
        {
            if ((bool)LeatingFromInventory.GetValue(driver))
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(driver.pawn, TargetIndex.A));
            }
            else
            {
                yield return((Toil)LReserveFood.Invoke(driver, new object[] { }));

                Toil gotoToPickup = Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.A);
                yield return(Toils_Jump.JumpIf(gotoToPickup, () => driver.pawn.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation)));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOnDespawnedNullOrForbidden(TargetIndex.A));

                yield return(Toils_Jump.Jump(chewToil));

                yield return(gotoToPickup);

                yield return(Toils_Ingest.PickupIngestible(TargetIndex.A, driver.pawn));

                gotoToPickup = null;
            }
            if (driver.job.takeExtraIngestibles > 0)
            {
                foreach (Toil toil in (IEnumerable <Toil>)LTakeExtraIngestibles.Invoke(driver, new object[] { }))
                {
                    yield return(toil);
                }
            }
            if (!driver.pawn.Drafted)
            {
                yield return(reserveChewSpot(TargetIndex.A, TargetIndex.B));

                Toil gotospot = gotoSpot(TargetIndex.B).FailOnDestroyedOrNull(TargetIndex.A);

                if (!Utility.IncapableOfCleaning(driver.pawn))
                {
                    TargetIndex filthListIndex = TargetIndex.B;
                    TargetIndex progListIndex  = TargetIndex.A;
                    Toil        FilthList      = makeFilthListToil(filthListIndex);
                    yield return(FilthList);

                    yield return(Toils_Jump.JumpIf(gotospot, () => driver.job.GetTargetQueue(filthListIndex).NullOrEmpty()));

                    Toil nextTarget = Toils_JobTransforms.ExtractNextTargetFromQueue(filthListIndex, true);
                    yield return(nextTarget);

                    yield return(Toils_Jump.JumpIf(gotospot, () => driver.job.GetTargetQueue(filthListIndex).NullOrEmpty()));

                    yield return(Toils_Goto.GotoThing(filthListIndex, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(filthListIndex, nextTarget).JumpIfOutsideHomeArea(filthListIndex, nextTarget));

                    //
                    if (driver.job.GetTargetQueue(progListIndex).Count == 0)
                    {
                        driver.job.GetTargetQueue(progListIndex).Add(new IntVec3(0, 0, 0));
                    }
                    //
                    Toil clean = makeCleanToil(progListIndex, filthListIndex, nextTarget);
                    yield return(clean);

                    yield return(Toils_Jump.Jump(nextTarget));
                }
                yield return(gotospot);
            }
            yield return(Toils_Ingest.FindAdjacentEatSurface(TargetIndex.B, TargetIndex.A));

            yield break;
        }
        internal static IEnumerable <Toil> _MakeNewToils(this JobDriver_Ingest obj)
        {
            if (obj.IsDispenser())
            {
                yield return(Toils_Goto.GotoThing(FoodOrDispenserInd, PathEndMode.InteractionCell).FailOnDespawnedNullOrForbidden(FoodOrDispenserInd));

                if (obj.Alcohol() == null)
                {
                    // Meals
                    if (obj.Dispenser() is Building_NutrientPasteDispenser)
                    {
                        yield return(Toils_Ingest.TakeMealFromDispenser(FoodOrDispenserInd, obj.pawn));
                    }
                    if (obj.Dispenser() is Building_AutomatedFactory)
                    {
                        yield return(Toils_FoodSynthesizer.TakeMealFromSynthesizer(FoodOrDispenserInd, obj.pawn));
                    }
                }
                else
                {
                    // Alcohol
                    if (obj.Dispenser() is Building_AutomatedFactory)
                    {
                        yield return(Toils_FoodSynthesizer.TakeAlcoholFromSynthesizer(FoodOrDispenserInd, obj.pawn));
                    }
                }
                yield return(Toils_Ingest.CarryIngestibleToChewSpot(obj.pawn).FailOnDestroyedNullOrForbidden(FoodOrDispenserInd));

                yield return(Toils_Ingest.FindAdjacentEatSurface(TableCellInd, FoodOrDispenserInd));
            }
            else if (obj.pawn.RaceProps.ToolUser)
            {
                if (obj.pawn.CurJob.eatFromInventory)
                {
                    var dropIfNeeded = new Toil();
                    dropIfNeeded.initAction = new Action(() =>
                    {
                        Pawn pawn            = obj.pawn;
                        Thing resultingThing = obj.Food();
                        Thing thing          = resultingThing;
                        if (
                            (pawn.inventory == null) ||
                            (!pawn.inventory.container.Contains(resultingThing))
                            )
                        {
                            return;
                        }
                        int count = Mathf.Min(resultingThing.stackCount, pawn.CurJob.maxNumToCarry);
                        if (!pawn.inventory.container.TryDrop(resultingThing, pawn.Position, ThingPlaceMode.Near, count, out resultingThing))
                        {
                            Verse.Log.Error(pawn + " could not drop their food to eat it.");
                            obj.EndJobWith(JobCondition.Errored);
                        }
                        else
                        {
                            if (resultingThing == thing)
                            {
                                return;
                            }
                            pawn.CurJob.SetTarget(FoodOrDispenserInd, (TargetInfo)resultingThing);
                        }
                    });

                    yield return(dropIfNeeded);
                }
                yield return(obj.ReserveFoodIfWillEatWholeStack());

                yield return(Toils_Goto.GotoThing(FoodOrDispenserInd, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(FoodOrDispenserInd));

                yield return(Toils_Ingest.PickupIngestible(FoodOrDispenserInd, obj.pawn));

                yield return(Toils_Ingest.CarryIngestibleToChewSpot(obj.pawn).FailOnDestroyedNullOrForbidden(FoodOrDispenserInd));

                yield return(Toils_Ingest.FindAdjacentEatSurface(TableCellInd, FoodOrDispenserInd));
            }
            else // Non-Tool User
            {
                yield return(obj.ReserveFoodIfWillEatWholeStack());

                yield return(Toils_Goto.GotoThing(FoodOrDispenserInd, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(FoodOrDispenserInd));
            }

            var durationMultiplier = 1f / obj.pawn.GetStatValue(StatDefOf.EatingSpeed, true);
            var chew = Toils_Ingest.ChewIngestible(obj.pawn, durationMultiplier, FoodOrDispenserInd, TableCellInd).FailOn(() =>
            {
                if (!obj.Food().Spawned)
                {
                    return((obj.pawn.carrier == null ? 0 : (obj.pawn.carrier.CarriedThing == obj.Food() ? 1 : 0)) == 0);
                }
                return(false);
            });

            yield return(chew);

            yield return(Toils_Ingest.FinalizeIngest(obj.pawn, FoodOrDispenserInd));

            yield return(Toils_Jump.JumpIf(chew, () =>
            {
                if (obj.Food() is Corpse)
                {
                    return (double)obj.pawn.needs.food.CurLevelPercentage < JobDriver_Ingest.EatCorpseBodyPartsUntilFoodLevelPct;
                }
                return false;
            }));
        }
Exemplo n.º 17
0
        internal static IEnumerable <Toil> _MakeNewToils(this JobDriver_FoodDeliver obj)
        {
            var foodThing = obj.TargetThing(FoodInd);
            var deliveree = (Pawn)obj.TargetThing(DelivereeInd);
            var dropCell  = obj.TargetCell(DeliverToInd);

            yield return(Toils_Reserve.Reserve(DelivereeInd, 1));

            if (foodThing is Building)
            {
                yield return(Toils_Reserve.Reserve(FoodInd, 1));

                yield return(Toils_Goto.GotoThing(FoodInd, PathEndMode.InteractionCell).FailOnForbidden(FoodInd));

                if (foodThing is Building_NutrientPasteDispenser)
                {
                    yield return(Toils_Ingest.TakeMealFromDispenser(FoodInd, obj.pawn));
                }
                else if (foodThing is Building_AutomatedFactory)
                {
                    yield return(Toils_FoodSynthesizer.TakeMealFromSynthesizer(FoodInd, obj.pawn));
                }
                else // Unknown building
                {
                    throw new Exception("Food target for JobDriver_FoodDeliver is a building but not Building_NutrientPasteDispenser or Building_AutomatedFactory!");
                }
            }
            else if (
                (obj.pawn.inventory != null) &&
                (obj.pawn.inventory.Contains(foodThing))
                )
            {
                yield return(Toils_Misc.TakeItemFromInventoryToCarrier(obj.pawn, FoodInd));
            }
            else
            {
                yield return(Toils_Reserve.Reserve(FoodInd, 1));

                yield return(Toils_Goto.GotoThing(FoodInd, PathEndMode.ClosestTouch));

                yield return(Toils_Ingest.PickupIngestible(FoodInd, deliveree));
            }

            var pathToTarget = new Toil();

            pathToTarget.defaultCompleteMode = ToilCompleteMode.PatherArrival;
            pathToTarget.initAction          = new Action(() =>
            {
                var pawn = obj.pawn;
                var job  = pawn.jobs.curJob;
                pawn.pather.StartPath(job.targetC, PathEndMode.OnCell);
            }
                                                          );
            pathToTarget.FailOnDestroyedNullOrForbidden(DelivereeInd);
            pathToTarget.AddFailCondition(() =>
            {
                return
                ((deliveree.Downed) ||
                 (!deliveree.IsPrisonerOfColony) ||
                 (!deliveree.guest.ShouldBeBroughtFood));
            });
            yield return(pathToTarget);

            var dropFoodAtTarget = new Toil();

            dropFoodAtTarget.initAction = new Action(() =>
            {
                Thing resultingThing;
                obj.pawn.carrier.TryDropCarriedThing(dropCell, ThingPlaceMode.Direct, out resultingThing);
            }
                                                     );
            dropFoodAtTarget.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(dropFoodAtTarget);
        }