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));
            }
        }
示例#2
0
        internal static bool IsDrink(this JobDriver_SocialRelax obj)
        {
            if (!obj.pawn.CurJob.GetTarget(OptionalDrinkInd).HasThing)
            {
                return(false);
            }
            var thing = obj.pawn.CurJob.GetTarget(OptionalDrinkInd).Thing;

            return(thing.def.IsAlcohol());
        }
        internal static bool IsDrink(this JobDriver_SocialRelax obj)
        {
            var thing = obj.TargetThing(OptionalDrinkInd);

            if (thing == null)
            {
                return(false);
            }
            return(thing.def.IsAlcohol());
        }
        internal static bool IsDispenser(this JobDriver_SocialRelax obj)
        {
            var thing = obj.TargetThing(OptionalDrinkInd);

            if (thing == null)
            {
                return(false);
            }
            return(thing is Building_AutomatedFactory);
        }
示例#5
0
        internal static bool IsDispenser(this JobDriver_SocialRelax obj)
        {
            if (!obj.pawn.CurJob.GetTarget(OptionalDrinkInd).HasThing)
            {
                return(false);
            }
            var thing = obj.pawn.CurJob.GetTarget(OptionalDrinkInd).Thing;

            return(thing is Building_AutomatedFactory);
        }
示例#6
0
 static bool Prefix(ref IEnumerable <Toil> __result, JobDriver_SocialRelax __instance)
 {
     if (!Settings.social_relax_economy && !Settings.adv_cleaning_ingest)
     {
         return(true);
     }
     //
     __result = __instance._MakeToils();
     return(false);
 }
        private static IEnumerable <Toil> Postfix(IEnumerable <Toil> values, JobDriver_SocialRelax __instance)
        {
            if (!__instance.job.GetTarget(TargetIndex.C).HasThing)
            {
                foreach (Toil value in values)
                {
                    yield return(value);
                }
                yield break;
            }

            int numToilsBeforeGoto = 2;

            foreach (Toil toil in HeatMealInjector.InjectHeat(values, __instance, numToilsBeforeGoto, foodIndex: TargetIndex.C, finalLocation: TargetIndex.B))
            {
                yield return(toil);
            }
            yield break;
        }
示例#8
0
 internal static bool HasChair(this JobDriver_SocialRelax obj)
 {
     return(obj.pawn.CurJob.GetTarget(ChairOrSpotInd).HasThing);
 }
 internal static bool HasDrinkOrDispenser(this JobDriver_SocialRelax obj)
 {
     return(obj.TargetThing(OptionalDrinkInd) != null);
 }
 internal static Thing OccupyThing(this JobDriver_SocialRelax obj)
 {
     return(obj.TargetThing(ChairOrSpotInd));
 }
示例#11
0
 internal static IntVec3 OccupySpot(this JobDriver_SocialRelax obj)
 {
     return(obj.pawn.CurJob.GetTarget(ChairOrSpotInd).Cell);
 }
示例#12
0
 static IntVec3 ClosestGatherSpotParentCell(this JobDriver_SocialRelax driver)
 {
     return(driver.GatherSpotParent().OccupiedRect().ClosestCellTo(driver.pawn.Position));
 }
示例#13
0
 internal static Thing GatherSpotParent(this JobDriver_SocialRelax obj)
 {
     return(obj.pawn.CurJob.GetTarget(GatherSpotParentInd).Thing);
 }
示例#14
0
 static bool HasChair(this JobDriver_SocialRelax driver)
 {
     return(driver.job.GetTarget(TargetIndex.B).HasThing);
 }
示例#15
0
 internal static Thing OccupyThing(this JobDriver_SocialRelax obj)
 {
     return(obj.pawn.CurJob.GetTarget(ChairOrSpotInd).Thing);
 }
 internal static Thing Alcohol(this JobDriver_SocialRelax obj)
 {
     return(obj.TargetThing(OptionalDrinkInd));
 }
示例#17
0
 internal static Thing Alcohol(this JobDriver_SocialRelax obj)
 {
     return(obj.pawn.CurJob.GetTarget(OptionalDrinkInd).Thing);
 }
示例#18
0
 internal static bool HasDrinkOrDispenser(this JobDriver_SocialRelax obj)
 {
     return(obj.pawn.CurJob.GetTarget(OptionalDrinkInd).HasThing);
 }
 internal static Building_AutomatedFactory Dispenser(this JobDriver_SocialRelax obj)
 {
     return(obj.TargetThing(OptionalDrinkInd) as Building_AutomatedFactory);
 }
 internal static Thing GatherSpotParent(this JobDriver_SocialRelax obj)
 {
     return(obj.TargetThing(GatherSpotParentInd));
 }
 internal static IntVec3 ClosestGatherSpotParentCell(this JobDriver_SocialRelax obj)
 {
     return(obj.GatherSpotParent().OccupiedRect().ClosestCellTo(obj.pawn.Position));
 }
 internal static bool HasChair(this JobDriver_SocialRelax obj)
 {
     return(obj.TargetThing(ChairOrSpotInd) != null);
 }
示例#23
0
 static Thing GatherSpotParent(this JobDriver_SocialRelax driver)
 {
     return(driver.job.GetTarget(TargetIndex.A).Thing);
 }
 internal static IntVec3 OccupySpot(this JobDriver_SocialRelax obj)
 {
     return(obj.TargetCell(ChairOrSpotInd));
 }
示例#25
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;
        }
示例#26
0
 internal static Building_AutomatedFactory Dispenser(this JobDriver_SocialRelax obj)
 {
     return(obj.pawn.CurJob.GetTarget(OptionalDrinkInd).Thing as Building_AutomatedFactory);
 }