private void DoWork_ForceOwnerToSleep() { for (int i = 0; i < owners.Count; i++) { // preparation: stop all other jobs if (owners[i].jobs != null) { owners[i].jobs.StopAll(); } // Do Job with JobGiver -> Force owner to sleep JobGiver_GetRest getRest = new JobGiver_GetRest(); JobIssueParams jobParms = new JobIssueParams(); ThinkResult thinkResult = getRest.TryIssueJobPackage(owners[i], jobParms); owners[i].jobs.StartJob(thinkResult.Job); // Alternate: If you want to send the pawn somewhere... //// Do Job with JobDriver -> Call owner to bed //JobDriver_GotoTarget jobDriver = new JobDriver_GotoTarget(owner); //// Alternate: (JobDriver_GotoTarget)MakeDriver(owner, typeof(JobDriver_GotoTarget)); //jobDriver.TargetCell = Position; //jobDriver.StartJob(); } }
internal static RestCategory MinCategory(this JobGiver_GetRest _this) { if (_minCategory == null) { _minCategory = typeof(JobGiver_GetRest).GetField("minCategory", BindingFlags.Instance | BindingFlags.NonPublic); if (_minCategory == null) { Log.ErrorOnce("Unable to reflect JobGiver_GetRest.minCategory!", 0x12348765); } } return((RestCategory)_minCategory.GetValue(_this)); }
public static void LightsOut(List <Pawn> pawns) { foreach (var pawn in pawns) { if (!pawn.mindState.IsIdle && pawn.CurJobDef != JobDefOf.LayDown) { ThinkResult result = ThinkResult.NoJob; try { var joyGiver = new JobGiver_GetRest(); joyGiver.ResolveReferences(); result = joyGiver.TryIssueJobPackage(pawn, default(JobIssueParams)); } catch (Exception exception) { JobUtility.TryStartErrorRecoverJob(pawn, pawn.ToStringSafe() + " threw exception while determining job (main)", exception); } if (result.Job != null && result.Job.def != JobDefOf.GotoWander) { pawn.jobs.TryTakeOrderedJob(result.Job); } } } }
public override float GetPriority(Pawn pawn) { JobGiver_GetRest rester = pawn.thinker.GetMainTreeThinkNode <JobGiver_GetRest>(); return(8f - (rester?.GetPriority(pawn) ?? 0f)); }
internal static float _GetPriority(this JobGiver_GetRest j, Pawn pawn) { Need_Rest needRest = pawn.needs.rest; if (needRest == null || Find.TickManager.TicksGame < pawn.mindState.canSleepTick) { return(0.0f); } Lord lord = pawn.GetLord(); if (lord != null && !lord.CurLordToil.AllowSatisfyLongNeeds) { return(0.0f); } TimeAssignmentDef timeAssignmentDef; if (pawn.RaceProps.Humanlike) { timeAssignmentDef = pawn.timetable != null ? pawn.timetable.CurrentAssignment : TimeAssignmentDefOf.Anything; } else { int hourOfDay = GenDate.HourOfDay; timeAssignmentDef = hourOfDay < 7 || hourOfDay > 21 ? TimeAssignmentDefOf.Sleep : TimeAssignmentDefOf.Anything; } float curLevel = needRest.CurLevel; if (pawn.RaceProps.Humanlike && pawn.story.traits.HasTrait(TraitDefOfPsychology.Insomniac)) { if (timeAssignmentDef == TimeAssignmentDefOf.Anything) { return((double)curLevel < 0.15 ? 0.0000005f : 0.0f); } if (timeAssignmentDef == TimeAssignmentDefOf.Work) { return(0.0f); } if (timeAssignmentDef == TimeAssignmentDefOf.Joy) { return((double)curLevel < 0.15 ? 0.0000005f : 0.0f); } if (timeAssignmentDef != TimeAssignmentDefOf.Sleep) { throw new NotImplementedException(); } return((double)curLevel < 0.4 ? 0.0000005f : 0.0f); } if (timeAssignmentDef == TimeAssignmentDefOf.Anything) { return((double)curLevel < 0.300000011920929 ? 8f : 0.0f); } if (timeAssignmentDef == TimeAssignmentDefOf.Work) { return(0.0f); } if (timeAssignmentDef == TimeAssignmentDefOf.Joy) { return((double)curLevel < 0.300000011920929 ? 8f : 0.0f); } if (timeAssignmentDef != TimeAssignmentDefOf.Sleep) { throw new NotImplementedException(); } return((double)curLevel < 0.75 ? 8f : 0.0f); }
internal static float _GetPriority(this JobGiver_GetRest j, Pawn pawn) { Need_Rest rest = pawn.needs.rest; if (rest == null) { return(0f); } if (rest.CurCategory < j.MinCategory()) { return(0f); } if (Find.TickManager.TicksGame < pawn.mindState.canSleepTick) { return(0f); } Lord lord = pawn.GetLord(); if (lord != null && !lord.CurLordToil.AllowSatisfyLongNeeds) { return(0f); } TimeAssignmentDef timeAssignmentDef; if (pawn.RaceProps.Humanlike) { timeAssignmentDef = ((pawn.timetable != null) ? pawn.timetable.CurrentAssignment : TimeAssignmentDefOf.Anything); } else { int num = GenLocalDate.HourOfDay(pawn); if (num < 7 || num > 21) { timeAssignmentDef = TimeAssignmentDefOf.Sleep; } else { timeAssignmentDef = TimeAssignmentDefOf.Anything; } } float curLevel = rest.CurLevel; if (timeAssignmentDef == TimeAssignmentDefOf.Anything) { if (pawn.RaceProps.Humanlike && pawn.story.traits.HasTrait(TraitDefOfPsychology.Insomniac)) { if (curLevel < 0.3f) { return(1f); } return(0f); } else { if (curLevel < 0.3f) { return(8f); } return(0f); } } else { if (timeAssignmentDef == TimeAssignmentDefOf.Work) { return(0f); } if (timeAssignmentDef == TimeAssignmentDefOf.Joy) { if (pawn.RaceProps.Humanlike && pawn.story.traits.HasTrait(TraitDefOfPsychology.Insomniac)) { if (curLevel < 0.3f) { return(3f); } return(0f); } else { if (curLevel < 0.3f) { return(8f); } return(0f); } } else { if (timeAssignmentDef != TimeAssignmentDefOf.Sleep) { throw new NotImplementedException(); } if (pawn.RaceProps.Humanlike && pawn.story.traits.HasTrait(TraitDefOfPsychology.Insomniac)) { if (curLevel < 0.75f) { return(3f); } return(0f); } else { if (curLevel < 0.75f) { return(8f); } return(0f); } } } }