public override float GetPriority(Pawn pawn)
        {
            Pawn_PsychicEntropyTracker psychicEntropy = pawn.psychicEntropy;
            bool flag = pawn.HasPsylink && psychicEntropy != null && psychicEntropy.CurrentPsyfocus <Mathf.Min(psychicEntropy.TargetPsyfocus, 0.95f) && psychicEntropy.PsychicSensitivity> float.Epsilon;

            if (!ValidatePawnState(pawn))
            {
                return(0f);
            }
            if (pawn.timetable?.CurrentAssignment == TimeAssignmentDefOf.Meditate)
            {
                return(9f);
            }
            if (pawn.CurrentBed() == null)
            {
                if (pawn.timetable?.CurrentAssignment == TimeAssignmentDefOf.Anything && flag)
                {
                    return(7.1f);
                }
            }
            else if (flag && pawn.health.hediffSet.PainTotal <= 0.3f && pawn.CurrentBed() != null)
            {
                return(6f);
            }
            return(0f);
        }
Пример #2
0
        public PsychicEntropyGizmo(Pawn_PsychicEntropyTracker tracker)
        {
            this.tracker = tracker;
            order        = -100f;
            LimitedTex   = ContentFinder <Texture2D> .Get("UI/Icons/EntropyLimit/Limited");

            UnlimitedTex = ContentFinder <Texture2D> .Get("UI/Icons/EntropyLimit/Unlimited");
        }
Пример #3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            Toil meditate = new Toil
            {
                socialMode = RandomSocialMode.Off
            };

            if (FromBed)
            {
                this.KeepLyingDown(TargetIndex.B);
                meditate = Toils_LayDown.LayDown(TargetIndex.B, job.GetTarget(TargetIndex.B).Thing is Building_Bed, lookForOtherJobs: false, canSleep: false);
            }
            else
            {
                yield return(Toils_Goto.GotoCell(TargetIndex.A, PathEndMode.OnCell));

                meditate.initAction = delegate
                {
                    LocalTargetInfo target = job.GetTarget(TargetIndex.C);
                    if (target.IsValid)
                    {
                        faceDir = target.Cell - pawn.Position;
                    }
                    else
                    {
                        faceDir = (job.def.faceDir.IsValid ? job.def.faceDir : Rot4.Random).FacingCell;
                    }
                };
                if (Focus != null)
                {
                    meditate.FailOnDespawnedNullOrForbidden(TargetIndex.C);
                    if (pawn.HasPsylink && Focus.Thing != null)
                    {
                        meditate.FailOn(() => Focus.Thing.GetStatValueForPawn(StatDefOf.MeditationFocusStrength, pawn) < float.Epsilon);
                    }
                }
                meditate.handlingFacing = true;
            }
            meditate.defaultCompleteMode = ToilCompleteMode.Delay;
            meditate.defaultDuration     = job.def.joyDuration;
            meditate.FailOn(() => !MeditationUtility.CanMeditateNow(pawn) || !MeditationUtility.SafeEnvironmentalConditions(pawn, base.TargetLocA, base.Map));
            meditate.AddPreTickAction(delegate
            {
                bool flag = pawn.GetTimeAssignment() == TimeAssignmentDefOf.Meditate;
                if (job.ignoreJoyTimeAssignment)
                {
                    Pawn_PsychicEntropyTracker psychicEntropy = pawn.psychicEntropy;
                    if (!flag && psychicEntropy.TargetPsyfocus < psychicEntropy.CurrentPsyfocus && (psychicEntropy.TargetPsyfocus < job.psyfocusTargetLast || job.wasOnMeditationTimeAssignment))
                    {
                        EndJobWith(JobCondition.InterruptForced);
                        return;
                    }
                    job.psyfocusTargetLast            = psychicEntropy.TargetPsyfocus;
                    job.wasOnMeditationTimeAssignment = flag;
                }
                if (faceDir.IsValid && !FromBed)
                {
                    pawn.rotationTracker.FaceCell(pawn.Position + faceDir);
                }
                MeditationTick();
                if (ModLister.RoyaltyInstalled && MeditationFocusDefOf.Natural.CanPawnUse(pawn))
                {
                    int num = GenRadial.NumCellsInRadius(MeditationUtility.FocusObjectSearchRadius);
                    for (int i = 0; i < num; i++)
                    {
                        IntVec3 c = pawn.Position + GenRadial.RadialPattern[i];
                        if (c.InBounds(pawn.Map))
                        {
                            Plant plant = c.GetPlant(pawn.Map);
                            if (plant != null && plant.def == ThingDefOf.Plant_TreeAnima)
                            {
                                plant.TryGetComp <CompSpawnSubplant>()?.AddProgress_NewTmp(AnimaTreeSubplantProgressPerTick);
                            }
                        }
                    }
                }
            });
            yield return(meditate);
        }