internal void <> m__0() { Pawn actor = this.layDown.actor; actor.pather.StopDead(); JobDriver curDriver = actor.jobs.curDriver; if (this.hasBed) { Building_Bed t = (Building_Bed)actor.CurJob.GetTarget(this.bedOrRestSpotIndex).Thing; if (!t.OccupiedRect().Contains(actor.Position)) { Log.Error("Can't start LayDown toil because pawn is not in the bed. pawn=" + actor, false); actor.jobs.EndCurrentJob(JobCondition.Errored, true); return; } actor.jobs.posture = PawnPosture.LayingInBed; } else { actor.jobs.posture = PawnPosture.LayingOnGroundNormal; } curDriver.asleep = false; if (actor.mindState.applyBedThoughtsTick == 0) { actor.mindState.applyBedThoughtsTick = Find.TickManager.TicksGame + Rand.Range(2500, 10000); actor.mindState.applyBedThoughtsOnLeave = false; } if (actor.ownership != null && actor.CurrentBed() != actor.ownership.OwnedBed) { ThoughtUtility.RemovePositiveBedroomThoughts(actor); } }
public static Toil LayDown(TargetIndex bedOrRestSpotIndex, bool hasBed, bool lookForOtherJobs, bool canSleep = true, bool gainRestAndHealth = true) { Toil layDown = new Toil(); layDown.initAction = delegate { Pawn actor = layDown.actor; actor.pather.StopDead(); JobDriver curDriver = actor.jobs.curDriver; if (hasBed) { Building_Bed t = (Building_Bed)actor.CurJob.GetTarget(bedOrRestSpotIndex).Thing; if (!t.OccupiedRect().Contains(actor.Position)) { Log.Error("Can't start LayDown toil because pawn is not in the bed. pawn=" + actor); actor.jobs.EndCurrentJob(JobCondition.Errored, true); return; } curDriver.layingDown = LayingDownState.LayingInBed; } else { curDriver.layingDown = LayingDownState.LayingSurface; } curDriver.asleep = false; if (actor.mindState.applyBedThoughtsTick == 0) { actor.mindState.applyBedThoughtsTick = Find.TickManager.TicksGame + Rand.Range(2500, 10000); actor.mindState.applyBedThoughtsOnLeave = false; } if (actor.ownership != null && actor.CurrentBed() != actor.ownership.OwnedBed) { ThoughtUtility.RemovePositiveBedroomThoughts(actor); } }; layDown.tickAction = delegate { Pawn actor = layDown.actor; Job curJob = actor.CurJob; JobDriver curDriver = actor.jobs.curDriver; Building_Bed building_Bed = (Building_Bed)curJob.GetTarget(bedOrRestSpotIndex).Thing; actor.GainComfortFromCellIfPossible(); if (!curDriver.asleep) { if (canSleep && ((actor.needs.rest != null && actor.needs.rest.CurLevel < RestUtility.FallAsleepMaxLevel(actor)) || curJob.forceSleep)) { curDriver.asleep = true; } } else if (!canSleep) { curDriver.asleep = false; } else if ((actor.needs.rest == null || actor.needs.rest.CurLevel >= RestUtility.WakeThreshold(actor)) && !curJob.forceSleep) { curDriver.asleep = false; } if (curDriver.asleep && gainRestAndHealth && actor.needs.rest != null) { float num; if (building_Bed != null && building_Bed.def.statBases.StatListContains(StatDefOf.BedRestEffectiveness)) { num = building_Bed.GetStatValue(StatDefOf.BedRestEffectiveness, true); } else { num = 0.8f; } float num2 = RestUtility.PawnHealthRestEffectivenessFactor(actor); num = 0.7f * num + 0.3f * num * num2; actor.needs.rest.TickResting(num); } if (actor.mindState.applyBedThoughtsTick != 0 && actor.mindState.applyBedThoughtsTick <= Find.TickManager.TicksGame) { Toils_LayDown.ApplyBedThoughts(actor); actor.mindState.applyBedThoughtsTick += 60000; actor.mindState.applyBedThoughtsOnLeave = true; } if (actor.IsHashIntervalTick(100) && !actor.Position.Fogged(actor.Map)) { if (curDriver.asleep) { MoteMaker.ThrowMetaIcon(actor.Position, actor.Map, ThingDefOf.Mote_SleepZ); } if (gainRestAndHealth && actor.health.hediffSet.GetNaturallyHealingInjuredParts().Any <BodyPartRecord>()) { MoteMaker.ThrowMetaIcon(actor.Position, actor.Map, ThingDefOf.Mote_HealingCross); } } if (actor.ownership != null && building_Bed != null && !building_Bed.Medical && !building_Bed.owners.Contains(actor)) { if (actor.Downed) { actor.Position = CellFinder.RandomClosewalkCellNear(actor.Position, actor.Map, 1, null); } actor.jobs.EndCurrentJob(JobCondition.Incompletable, true); return; } if (lookForOtherJobs && actor.IsHashIntervalTick(211)) { actor.jobs.CheckForJobOverride(); return; } }; layDown.defaultCompleteMode = ToilCompleteMode.Never; if (hasBed) { layDown.FailOnBedNoLongerUsable(bedOrRestSpotIndex); } layDown.AddFinishAction(delegate { Pawn actor = layDown.actor; JobDriver curDriver = actor.jobs.curDriver; if (actor.mindState.applyBedThoughtsOnLeave) { Toils_LayDown.ApplyBedThoughts(actor); } curDriver.layingDown = LayingDownState.NotLaying; curDriver.asleep = false; }); return(layDown); }
public static Toil LayDown(TargetIndex bedOrRestSpotIndex, bool hasBed, bool lookForOtherJobs, bool canSleep = true, bool gainRestAndHealth = true) { Toil layDown = new Toil(); layDown.initAction = delegate { Pawn actor3 = layDown.actor; actor3.pather.StopDead(); JobDriver curDriver3 = actor3.jobs.curDriver; if (hasBed) { if (!((Building_Bed)actor3.CurJob.GetTarget(bedOrRestSpotIndex).Thing).OccupiedRect().Contains(actor3.Position)) { Log.Error("Can't start LayDown toil because pawn is not in the bed. pawn=" + actor3); actor3.jobs.EndCurrentJob(JobCondition.Errored); return; } actor3.jobs.posture = PawnPosture.LayingInBed; } else { actor3.jobs.posture = PawnPosture.LayingOnGroundNormal; } curDriver3.asleep = false; if (actor3.mindState.applyBedThoughtsTick == 0) { actor3.mindState.applyBedThoughtsTick = Find.TickManager.TicksGame + Rand.Range(2500, 10000); actor3.mindState.applyBedThoughtsOnLeave = false; } if (actor3.ownership != null && actor3.CurrentBed() != actor3.ownership.OwnedBed) { ThoughtUtility.RemovePositiveBedroomThoughts(actor3); } actor3.GetComp <CompCanBeDormant>()?.ToSleep(); }; layDown.tickAction = delegate { Pawn actor2 = layDown.actor; Job curJob = actor2.CurJob; JobDriver curDriver2 = actor2.jobs.curDriver; Building_Bed building_Bed = (Building_Bed)curJob.GetTarget(bedOrRestSpotIndex).Thing; actor2.GainComfortFromCellIfPossible(); if (!curDriver2.asleep) { if (canSleep && ((actor2.needs.rest != null && actor2.needs.rest.CurLevel < RestUtility.FallAsleepMaxLevel(actor2)) || curJob.forceSleep)) { curDriver2.asleep = true; } } else if (!canSleep) { curDriver2.asleep = false; } else if ((actor2.needs.rest == null || actor2.needs.rest.CurLevel >= RestUtility.WakeThreshold(actor2)) && !curJob.forceSleep) { curDriver2.asleep = false; } if (curDriver2.asleep && gainRestAndHealth && actor2.needs.rest != null) { float restEffectiveness = (building_Bed == null || !building_Bed.def.statBases.StatListContains(StatDefOf.BedRestEffectiveness)) ? StatDefOf.BedRestEffectiveness.valueIfMissing : building_Bed.GetStatValue(StatDefOf.BedRestEffectiveness); actor2.needs.rest.TickResting(restEffectiveness); } if (actor2.mindState.applyBedThoughtsTick != 0 && actor2.mindState.applyBedThoughtsTick <= Find.TickManager.TicksGame) { ApplyBedThoughts(actor2); actor2.mindState.applyBedThoughtsTick += 60000; actor2.mindState.applyBedThoughtsOnLeave = true; } if (actor2.IsHashIntervalTick(100) && !actor2.Position.Fogged(actor2.Map)) { if (curDriver2.asleep) { MoteMaker.ThrowMetaIcon(actor2.Position, actor2.Map, ThingDefOf.Mote_SleepZ); } if (gainRestAndHealth && actor2.health.hediffSet.GetNaturallyHealingInjuredParts().Any()) { MoteMaker.ThrowMetaIcon(actor2.Position, actor2.Map, ThingDefOf.Mote_HealingCross); } } if (actor2.ownership != null && building_Bed != null && !building_Bed.Medical && !building_Bed.OwnersForReading.Contains(actor2)) { if (actor2.Downed) { actor2.Position = CellFinder.RandomClosewalkCellNear(actor2.Position, actor2.Map, 1); } actor2.jobs.EndCurrentJob(JobCondition.Incompletable); } else if (lookForOtherJobs && actor2.IsHashIntervalTick(211)) { actor2.jobs.CheckForJobOverride(); } }; layDown.defaultCompleteMode = ToilCompleteMode.Never; if (hasBed) { layDown.FailOnBedNoLongerUsable(bedOrRestSpotIndex); } layDown.AddFinishAction(delegate { Pawn actor = layDown.actor; JobDriver curDriver = actor.jobs.curDriver; if (actor.mindState.applyBedThoughtsOnLeave) { ApplyBedThoughts(actor); } curDriver.asleep = false; }); return(layDown); }