示例#1
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(TargetIndex.A, JobCondition.Incompletable);
            if (HasChair)
            {
                this.EndOnDespawnedOrNull(TargetIndex.B, JobCondition.Incompletable);
            }
            if (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
            {
                pawn.rotationTracker.FaceCell(ClosestGatherSpotParentCell);
                pawn.GainComfortFromCellIfPossible();
                JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.GoToNextToil, 1f);

                if (pawn.IsHashIntervalTick(100))
                {
                    MoteMaker.ThrowMetaIcon(pawn.Position, pawn.Map, ThingDefOf.Mote_Note);
                }
            };
            chew.handlingFacing      = true;
            chew.defaultCompleteMode = ToilCompleteMode.Delay;
            chew.defaultDuration     = job.def.joyDuration;
            chew.AddFinishAction(delegate
            {
                JoyUtility.TryGainRecRoomThought(pawn);
            });
            chew.socialMode = RandomSocialMode.SuperActive;
            Toils_Ingest.AddIngestionEffects(chew, pawn, TargetIndex.C, TargetIndex.None);
            yield return(chew);

            if (HasDrink)
            {
                yield return(Toils_Ingest.FinalizeIngest(pawn, TargetIndex.C));
            }
            yield break;
        }
示例#2
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.EndOnDespawnedOrNull(GatherSpotParentInd);
            if (HasChair)
            {
                this.EndOnDespawnedOrNull(ChairOrSpotInd);
            }
            this.FailOnDestroyedNullOrForbidden(MateInd);
            yield return(Toils_Goto.GotoThing(MateInd, PathEndMode.OnCell)
                         .FailOnSomeonePhysicallyInteracting(MateInd));

            yield return(Toils_Haul.StartCarryThing(MateInd));

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

            var chew = new Toil {
                tickAction = delegate {
                    pawn.rotationTracker.FaceCell(ClosestGatherSpotParentCell);
                    pawn.GainComfortFromCellIfPossible();
                    JoyUtility.JoyTickCheckEnd(pawn, JoyTickFullJoyAction.GoToNextToil);
                },
                handlingFacing      = true,
                defaultCompleteMode = ToilCompleteMode.Delay,
                defaultDuration     = job.def.joyDuration,
                socialMode          = RandomSocialMode.SuperActive
            };

            chew.AddFinishAction(delegate {
                JoyUtility.TryGainRecRoomThought(pawn);
            });
            Toils_Ingest.AddIngestionEffects(chew, pawn, MateInd, TargetIndex.None);
            yield return(chew);

            Toil toilDrinkMate = new Toil();

            toilDrinkMate.initAction = () => {
                var ingester = pawn;
                var actor    = toilDrinkMate.actor;
                var curJob   = actor.jobs.curJob;
                var thing    = curJob.GetTarget(MateInd).Thing;
                if (ingester.needs.mood != null &&
                    thing.def.IsNutritionGivingIngestible &&
                    thing.def.ingestible.chairSearchRadius > 10.0)
                {
                    var room = ingester.GetRoom();
                    if (room != null)
                    {
                        var scoreStageIndex = RoomStatDefOf.Impressiveness.GetScoreStageIndex(room.GetStat(RoomStatDefOf.Impressiveness));
                        if (ThoughtDefOf.AteInImpressiveDiningRoom.stages[scoreStageIndex] != null)
                        {
                            ingester.needs.mood.thoughts.memories.TryGainMemory(ThoughtMaker.MakeThought(ThoughtDefOf.AteInImpressiveDiningRoom, scoreStageIndex));
                        }
                    }
                }

                var num2 = thing.Ingested(ingester, ingester.needs.food.NutritionWanted);
                if (!ingester.Dead)
                {
                    ingester.needs.food.CurLevel += num2;
                }
                ingester.records.AddTo(RecordDefOf.NutritionEaten, num2);
            };
            toilDrinkMate.defaultCompleteMode = ToilCompleteMode.Instant;
            yield return(toilDrinkMate);
        }
示例#3
0
        static IEnumerable <Toil> _MakeToils(this JobDriver_SocialRelax driver)
        {
            //driver.EndOnDespawnedOrNull(TargetIndex.A, JobCondition.Incompletable);
            driver.AddEndCondition(delegate
            {
                LocalTargetInfo target = driver.GetActor().jobs.curJob.GetTarget(TargetIndex.A);
                Thing thing            = target.Thing;
                if (thing == null && target.IsValid || thing is Filth)
                {
                    return(JobCondition.Ongoing);
                }
                if (thing == null || !thing.Spawned || thing.Map != driver.GetActor().Map)
                {
                    return(JobCondition.Incompletable);
                }
                return(JobCondition.Ongoing);
            });

            if (driver.HasChair())
            {
                driver.EndOnDespawnedOrNull(TargetIndex.B, JobCondition.Incompletable);
            }
            if (driver.HasDrink())
            {
                driver.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));
            }

            //cleaning patch
            Toil GoToRelaxPlace = Toils_Goto.GotoCell(TargetIndex.B, PathEndMode.OnCell);

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

                yield return(Toils_Jump.JumpIf(GoToRelaxPlace, () => driver.job.GetTargetQueue(TargetIndex.A).NullOrEmpty()));

                Toil CleanFilthList = Toils_JobTransforms.ClearDespawnedNullOrForbiddenQueuedTargets(TargetIndex.A, null);
                yield return(CleanFilthList);

                yield return(Toils_JobTransforms.ExtractNextTargetFromQueue(TargetIndex.A, true));

                yield return(Toils_Jump.JumpIf(GoToRelaxPlace, () => driver.job.GetTargetQueue(TargetIndex.A).NullOrEmpty()));

                yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, CleanFilthList).JumpIfOutsideHomeArea(TargetIndex.A, CleanFilthList));

                //
                driver.job.GetTargetQueue(TargetIndex.B).Add(new IntVec3(0, 0, 0));
                Toil clean = new Toil();
                clean.initAction = delegate()
                {
                    Filth filth   = clean.actor.jobs.curJob.GetTarget(TargetIndex.A).Thing as Filth;
                    var   progQue = clean.actor.jobs.curJob.GetTargetQueue(TargetIndex.B);
                    progQue[0] = new IntVec3(0, 0, (int)filth.def.filth.cleaningWorkToReduceThickness * filth.thickness);
                };
                clean.tickAction = delegate()
                {
                    Filth   filth   = clean.actor.jobs.curJob.GetTarget(TargetIndex.A).Thing as Filth;
                    var     progQue = clean.actor.jobs.curJob.GetTargetQueue(TargetIndex.B);
                    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, TargetIndex.A);
                clean.WithProgressBar(TargetIndex.A,
                                      delegate()
                {
                    var q        = driver.job.GetTargetQueue(TargetIndex.B)[0];
                    float result = (float)q.Cell.y / q.Cell.z;
                    return(result);
                }
                                      , true, -0.5f);
                clean.PlaySustainerOrSound(() => SoundDefOf.Interact_CleanFilth);
                clean.JumpIfDespawnedOrNullOrForbidden(TargetIndex.A, CleanFilthList);
                clean.JumpIfOutsideHomeArea(TargetIndex.A, CleanFilthList);
                yield return(clean);

                yield return(Toils_Jump.Jump(CleanFilthList));
            }

            yield return(GoToRelaxPlace);

            //
            float    joyoffset;
            ThingDef def = driver.job.GetTarget(TargetIndex.C).HasThing ? driver.job.GetTarget(TargetIndex.C).Thing.def : null;

            if (Settings.social_relax_economy && def != null && def.IsIngestible)
            {
                joyoffset = def.ingestible.joy * driver.pawn.needs.joy.tolerances.JoyFactorFromTolerance(def.ingestible.JoyKind);
                //minimum amount of time for action to perform
                float baseoffset = Mathf.Max(0.36f / 2500f * def.ingestible.baseIngestTicks, 0.36f / 2500f * 60f * 4f);
                float expected   = 1f - driver.pawn.needs.joy.CurLevel - joyoffset;
                if (expected < baseoffset)
                {
                    float expected2 = 1f - driver.pawn.needs.joy.CurLevel - baseoffset;
                    if (expected2 < 0f)
                    {
                        joyoffset = 0f;
                    }
                    else if (expected2 < baseoffset)
                    {
                        joyoffset = baseoffset - expected2;
                    }
                    else
                    {
                        joyoffset += expected - baseoffset;
                    }
                }
            }
            else
            {
                joyoffset = 0f;
            }

            Toil toil = new Toil();

            toil.tickAction = delegate()
            {
                driver.pawn.rotationTracker.FaceCell(driver.ClosestGatherSpotParentCell());
                driver.pawn.GainComfortFromCellIfPossible(false);
                JoyTickCheckEndOffset(driver.pawn, joyoffset, JoyTickFullJoyAction.GoToNextToil);
            };
            toil.handlingFacing      = true;
            toil.defaultCompleteMode = ToilCompleteMode.Delay;
            toil.defaultDuration     = driver.job.def.joyDuration;
            toil.AddFinishAction(delegate
            {
                JoyUtility.TryGainRecRoomThought(driver.pawn);
            });
            toil.socialMode = RandomSocialMode.SuperActive;
            Toils_Ingest.AddIngestionEffects(toil, driver.pawn, TargetIndex.C, TargetIndex.None);
            yield return(toil);

            if (driver.HasDrink())
            {
                yield return(Toils_Ingest.FinalizeIngest(driver.pawn, TargetIndex.C));
            }
            yield break;
        }