Beispiel #1
0
        internal static IEnumerable <Toil> _PrepareToEatToils_Dispenser(this JobDriver_Ingest obj)
        {
            var foodSource = obj.TargetThing(FoodInd);
            var alcohol    = obj.TargetThing(AlcoholInd);

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

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

            if (foodSource is Building_NutrientPasteDispenser)
            {
                yield return(Toils_Ingest.TakeMealFromDispenser(FoodInd, obj.pawn));
            }
            else if (foodSource is Building_AutomatedFactory)
            {
                if (alcohol == null)
                {
                    yield return(Toils_FoodSynthesizer.TakeMealFromSynthesizer(FoodInd, obj.pawn));
                }
                else
                {
                    yield return(Toils_FoodSynthesizer.TakeAlcoholFromSynthesizer(AlcoholInd, obj.pawn));
                }
            }
            yield return(Toils_Ingest.CarryIngestibleToChewSpot(obj.pawn)
                         .FailOnDestroyedNullOrForbidden(FoodInd));

            yield return(Toils_Ingest.FindAdjacentEatSurface(TableCellInd, FoodInd));
        }
        internal static IEnumerable <Toil> _MakeNewToils(this JobDriver_SocialRelax obj)
        {
            obj.EndOnDespawnedOrNull(GatherSpotParentInd, JobCondition.Incompletable);

            if (obj.HasChair())
            {
                obj.EndOnDespawnedOrNull(ChairOrSpotInd, JobCondition.Incompletable);
            }
            yield return(Toils_Reserve.Reserve(ChairOrSpotInd, 1));

            if (obj.HasDrinkOrDispenser())
            {
                obj.FailOnDestroyedNullOrForbidden(OptionalDrinkInd);
                yield return(Toils_Reserve.Reserve(OptionalDrinkInd, 1));

                if (obj.IsDispenser())
                {
                    yield return(Toils_Goto.GotoThing(OptionalDrinkInd, PathEndMode.InteractionCell));

                    yield return(Toils_FoodSynthesizer.TakeAlcoholFromSynthesizer(OptionalDrinkInd, obj.pawn));
                }
                else
                {
                    yield return(Toils_Goto.GotoThing(OptionalDrinkInd, PathEndMode.OnCell));

                    yield return(Toils_Haul.StartCarryThing(OptionalDrinkInd));
                }
            }

            yield return(Toils_Goto.GotoCell(ChairOrSpotInd, PathEndMode.OnCell));

            var relax = new Toil()
            {
                defaultCompleteMode = ToilCompleteMode.Delay,
                defaultDuration     = obj.pawn.CurJob.def.joyDuration,
                tickAction          = () =>
                {
                    var pawnDrawer     = obj.pawn.GetPawnDrawTracker();
                    var pawnFaceTarget = obj.ClosestGatherSpotParentCell();
                    pawnDrawer.rotator.FaceCell(pawnFaceTarget);
                    obj.pawn.GainComfortFromCellIfPossible();
                    JoyUtility.JoyTickCheckEnd(obj.pawn, JoyTickFullJoyAction.GoToNextToil, 1f);
                }
            };

            relax.AddFinishAction(() =>
                                  JoyUtility.TryGainRecRoomThought(obj.pawn)
                                  );
            relax.socialMode = RandomSocialMode.SuperActive;
            yield return(relax);

            if (obj.IsDrink())
            {
                yield return(Toils_Ingest.FinalizeIngest(obj.pawn, OptionalDrinkInd));
            }
        }
        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;
            }));
        }