Example #1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(TargetIndex.A, JobCondition.Incompletable);
            if (this.HasChair)
            {
                this.EndOnDespawnedOrNull(TargetIndex.B, JobCondition.Incompletable);
            }
            if (this.HasDrink)
            {
                this.FailOnDestroyedNullOrForbidden(TargetIndex.C);
                yield return(Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell).FailOnSomeonePhysicallyInteracting(TargetIndex.C));

                yield return(Toils_Haul.StartCarryThing(TargetIndex.C, false, false, false));
            }
            yield return(Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.OnCell));

            Toil chew = new Toil();

            chew.tickAction = delegate()
            {
                this.pawn.rotationTracker.FaceCell(this.ClosestGatherSpotParentCell);
                this.pawn.GainComfortFromCellIfPossible();
                JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.GoToNextToil, 1f, null);
            };
            chew.handlingFacing      = true;
            chew.defaultCompleteMode = ToilCompleteMode.Delay;
            chew.defaultDuration     = this.job.def.joyDuration;
            chew.AddFinishAction(delegate
            {
                JoyUtility.TryGainRecRoomThought(this.pawn);
            });
            chew.socialMode = RandomSocialMode.SuperActive;
            Toils_Ingest.AddIngestionEffects(chew, this.pawn, TargetIndex.C, TargetIndex.None);
            yield return(chew);

            if (this.HasDrink)
            {
                yield return(Toils_Ingest.FinalizeIngest(this.pawn, TargetIndex.C));
            }
            yield break;
        }
        public static Toil ChewIngestible(Pawn chewer, float durationMultiplier, TargetIndex ingestibleInd, TargetIndex eatSurfaceInd = TargetIndex.None)
        {
            Toil toil = new Toil();

            toil.initAction = delegate()
            {
                Pawn  actor = toil.actor;
                Thing thing = actor.CurJob.GetTarget(ingestibleInd).Thing;
                if (!thing.IngestibleNow)
                {
                    chewer.jobs.EndCurrentJob(JobCondition.Incompletable, true);
                }
                else
                {
                    actor.jobs.curDriver.ticksLeftThisToil = Mathf.RoundToInt((float)thing.def.ingestible.baseIngestTicks * durationMultiplier);
                    if (thing.Spawned)
                    {
                        thing.Map.physicalInteractionReservationManager.Reserve(chewer, actor.CurJob, thing);
                    }
                }
            };
            toil.tickAction = delegate()
            {
                if (chewer != toil.actor)
                {
                    toil.actor.rotationTracker.FaceCell(chewer.Position);
                }
                else
                {
                    Thing thing = toil.actor.CurJob.GetTarget(ingestibleInd).Thing;
                    if (thing != null && thing.Spawned)
                    {
                        toil.actor.rotationTracker.FaceCell(thing.Position);
                    }
                    else if (eatSurfaceInd != TargetIndex.None && toil.actor.CurJob.GetTarget(eatSurfaceInd).IsValid)
                    {
                        toil.actor.rotationTracker.FaceCell(toil.actor.CurJob.GetTarget(eatSurfaceInd).Cell);
                    }
                }
                toil.actor.GainComfortFromCellIfPossible();
            };
            toil.WithProgressBar(ingestibleInd, delegate
            {
                Pawn actor  = toil.actor;
                Thing thing = actor.CurJob.GetTarget(ingestibleInd).Thing;
                float result;
                if (thing == null)
                {
                    result = 1f;
                }
                else
                {
                    result = 1f - (float)toil.actor.jobs.curDriver.ticksLeftThisToil / Mathf.Round((float)thing.def.ingestible.baseIngestTicks * durationMultiplier);
                }
                return(result);
            }, false, -0.5f);
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.FailOnDestroyedOrNull(ingestibleInd);
            toil.AddFinishAction(delegate
            {
                if (chewer != null)
                {
                    if (chewer.CurJob != null)
                    {
                        Thing thing = chewer.CurJob.GetTarget(ingestibleInd).Thing;
                        if (thing != null)
                        {
                            if (chewer.Map.physicalInteractionReservationManager.IsReservedBy(chewer, thing))
                            {
                                chewer.Map.physicalInteractionReservationManager.Release(chewer, toil.actor.CurJob, thing);
                            }
                        }
                    }
                }
            });
            toil.handlingFacing = true;
            Toils_Ingest.AddIngestionEffects(toil, chewer, ingestibleInd, eatSurfaceInd);
            return(toil);
        }
Example #3
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.EndOnDespawnedOrNull(TargetIndex.A, JobCondition.Incompletable);
                    if (base.HasChair)
                    {
                        this.EndOnDespawnedOrNull(TargetIndex.B, JobCondition.Incompletable);
                    }
                    if (base.HasDrink)
                    {
                        this.FailOnDestroyedNullOrForbidden(TargetIndex.C);
                        this.$current = Toils_Goto.GotoThing(TargetIndex.C, PathEndMode.OnCell).FailOnSomeonePhysicallyInteracting(TargetIndex.C);
                        if (!this.$disposing)
                        {
                            this.$PC = 1;
                        }
                        return(true);
                    }
                    break;

                case 1u:
                    this.$current = Toils_Haul.StartCarryThing(TargetIndex.C, false, false, false);
                    if (!this.$disposing)
                    {
                        this.$PC = 2;
                    }
                    return(true);

                case 2u:
                    break;

                case 3u:
                    chew            = new Toil();
                    chew.tickAction = delegate()
                    {
                        this.pawn.rotationTracker.FaceCell(base.ClosestGatherSpotParentCell);
                        this.pawn.GainComfortFromCellIfPossible();
                        JoyUtility.JoyTickCheckEnd(this.pawn, JoyTickFullJoyAction.GoToNextToil, 1f, null);
                    };
                    chew.handlingFacing      = true;
                    chew.defaultCompleteMode = ToilCompleteMode.Delay;
                    chew.defaultDuration     = this.job.def.joyDuration;
                    chew.AddFinishAction(delegate
                    {
                        JoyUtility.TryGainRecRoomThought(this.pawn);
                    });
                    chew.socialMode = RandomSocialMode.SuperActive;
                    Toils_Ingest.AddIngestionEffects(chew, this.pawn, TargetIndex.C, TargetIndex.None);
                    this.$current = chew;
                    if (!this.$disposing)
                    {
                        this.$PC = 4;
                    }
                    return(true);

                case 4u:
                    if (base.HasDrink)
                    {
                        this.$current = Toils_Ingest.FinalizeIngest(this.pawn, TargetIndex.C);
                        if (!this.$disposing)
                        {
                            this.$PC = 5;
                        }
                        return(true);
                    }
                    goto IL_1D6;

                case 5u:
                    goto IL_1D6;

                default:
                    return(false);
                }
                this.$current = Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.OnCell);
                if (!this.$disposing)
                {
                    this.$PC = 3;
                }
                return(true);

IL_1D6:
                this.$PC = -1;
                return(false);
            }