Beispiel #1
0
 static bool Prefix(ref bool __result, Toil ___toil, TargetIndex ___bedIndex)
 {
     if (___toil.actor.CurJob.GetTarget(___bedIndex).Thing is Building_BedMedPod bedMedPod)
     {
         // Add MedPod-specific fail conditions
         // - If the target bed is a MedPod AND
         // - If the pawn does not need to use the MedPod OR the MedPod has no power
         __result = !bedMedPod.powerComp.PowerOn || !MedPodHealthAIUtility.ShouldPawnSeekMedPod(___toil.actor);
         return(false); // Skip original code
     }
     return(true);      // Run original code
 }
Beispiel #2
0
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
        {
            if (myPawn.RaceProps.Humanlike && !ForPrisoners && Medical && !myPawn.Drafted && Faction == Faction.OfPlayer && RestUtility.CanUseBedEver(myPawn, def))
            {
                if (!MedPodHealthAIUtility.IsValidRaceForMedPod(myPawn, DisallowedRaces))
                {
                    yield return(new FloatMenuOption("UseMedicalBed".Translate() + " (" + "MedPod_FloatMenu_RaceNotAllowed".Translate(myPawn.def.label.CapitalizeFirst()) + ")", null));

                    yield break;
                }
                if (!MedPodHealthAIUtility.ShouldPawnSeekMedPod(myPawn, AlwaysTreatableHediffs, NeverTreatableHediffs))
                {
                    yield return(new FloatMenuOption("UseMedicalBed".Translate() + " (" + "NotInjured".Translate() + ")", null));

                    yield break;
                }
                if (MedPodHealthAIUtility.ShouldPawnSeekMedPod(myPawn, AlwaysTreatableHediffs, NeverTreatableHediffs) && !powerComp.PowerOn)
                {
                    yield return(new FloatMenuOption("UseMedicalBed".Translate() + " (" + "MedPod_FloatMenu_Unpowered".Translate() + ")", null));

                    yield break;
                }
                if (MedPodHealthAIUtility.ShouldPawnSeekMedPod(myPawn, AlwaysTreatableHediffs, NeverTreatableHediffs) && this.IsForbidden(myPawn))
                {
                    yield return(new FloatMenuOption("UseMedicalBed".Translate() + " (" + "ForbiddenLower".Translate() + ")", null));

                    yield break;
                }
                Action action = delegate
                {
                    if (!ForPrisoners && Medical && myPawn.CanReserveAndReach(this, PathEndMode.ClosestTouch, Danger.Deadly, SleepingSlotsCount, -1, null, ignoreOtherReservations: true))
                    {
                        if (myPawn.CurJobDef == JobDefOf.LayDown && myPawn.CurJob.GetTarget(TargetIndex.A).Thing == this)
                        {
                            myPawn.CurJob.restUntilHealed = true;
                        }
                        else
                        {
                            Job job = JobMaker.MakeJob(JobDefOf.LayDown, this);
                            job.restUntilHealed = true;
                            myPawn.jobs.TryTakeOrderedJob(job);
                        }
                        myPawn.mindState.ResetLastDisturbanceTick();
                    }
                };
                yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("UseMedicalBed".Translate(), action), myPawn, this, (AnyUnoccupiedSleepingSlot ? "ReservedBy" : "SomeoneElseSleeping").CapitalizeFirst()));
            }
        }
Beispiel #3
0
 static void Postfix(ref bool __result, Thing bedThing, Pawn sleeper)
 {
     if (bedThing is Building_BedMedPod bedMedPod && (!bedMedPod.powerComp.PowerOn || !MedPodHealthAIUtility.ShouldPawnSeekMedPod(sleeper) || !MedPodHealthAIUtility.IsValidRaceForMedPod(sleeper, bedMedPod.DisallowedRaces)))
     {
         __result = false;
     }
 }
Beispiel #4
0
            static bool Prefix(Toil ___layDown, TargetIndex ___bedOrRestSpotIndex)
            {
                Pawn         patientPawn  = ___layDown.actor;
                Job          curJob       = patientPawn.CurJob;
                JobDriver    curDriver    = patientPawn.jobs.curDriver;
                Building_Bed building_Bed = (Building_Bed)curJob.GetTarget(___bedOrRestSpotIndex).Thing;

                patientPawn.GainComfortFromCellIfPossible();

                if (building_Bed is Building_BedMedPod bedMedPod && bedMedPod.powerComp.PowerOn && MedPodHealthAIUtility.ShouldPawnSeekMedPod(patientPawn))
                {
                    // Keep pawn asleep in MedPod as long as they need to use it
                    curDriver.asleep = true;
                    return(false); // Skip original code
                }

                return(true);  // Run original code
            }
Beispiel #5
0
 static void Postfix(ref bool __result, Thing bedThing, Pawn sleeper)
 {
     if (bedThing is Building_BedMedPod bedMedPod && (!bedMedPod.powerComp.PowerOn || bedMedPod.IsForbidden(sleeper) || !MedPodHealthAIUtility.ShouldPawnSeekMedPod(sleeper, bedMedPod.AlwaysTreatableHediffs, bedMedPod.NeverTreatableHediffs) || MedPodHealthAIUtility.HasUsageBlockingHediffs(sleeper, bedMedPod.UsageBlockingHediffs) || !MedPodHealthAIUtility.IsValidRaceForMedPod(sleeper, bedMedPod.DisallowedRaces) || bedMedPod.Aborted))
     {
         __result = false;
     }
 }
Beispiel #6
0
            static bool Prefix(Toil ___layDown, TargetIndex ___bedOrRestSpotIndex)
            {
                Pawn         patientPawn  = ___layDown.actor;
                Job          curJob       = patientPawn.CurJob;
                JobDriver    curDriver    = patientPawn.jobs.curDriver;
                Building_Bed building_Bed = (Building_Bed)curJob.GetTarget(___bedOrRestSpotIndex).Thing;

                patientPawn.GainComfortFromCellIfPossible();

                if (building_Bed is Building_BedMedPod bedMedPod && bedMedPod.powerComp.PowerOn && bedMedPod.IsForbidden(patientPawn) && MedPodHealthAIUtility.ShouldPawnSeekMedPod(patientPawn, bedMedPod.AlwaysTreatableHediffs, bedMedPod.NeverTreatableHediffs) && !bedMedPod.Aborted)
                {
                    // Keep pawn asleep in MedPod as long as they need to use it
                    curDriver.asleep = true;

                    // Fulfil pawn's rest need while they are asleep in MedPod if they're not rest immune (e.g. Circadian Half-Cycler)
                    if (patientPawn.needs.rest != null)
                    {
                        float restEffectiveness = !building_Bed.def.statBases.StatListContains(StatDefOf.BedRestEffectiveness) ? StatDefOf.BedRestEffectiveness.valueIfMissing : building_Bed.GetStatValue(StatDefOf.BedRestEffectiveness);
                        patientPawn.needs.rest.TickResting(restEffectiveness);
                    }
                    return(false); // Skip original code
                }
                return(true);      // Run original code
            }
Beispiel #7
0
 static bool Prefix(ref bool __result, Toil ___toil, TargetIndex ___bedIndex)
 {
     // Add MedPod-specific fail conditions if the target bed is a MedPod
     if (___toil.actor.CurJob.GetTarget(___bedIndex).Thing is Building_BedMedPod bedMedPod)
     {
         // - If the MedPod has no power OR
         // - If the MedPod is forbidden
         // - If the pawn does not need to use the MedPod OR
         // - If the treatment cycle was aborted
         __result = !bedMedPod.powerComp.PowerOn || bedMedPod.IsForbidden(___toil.actor) || !MedPodHealthAIUtility.ShouldPawnSeekMedPod(___toil.actor, bedMedPod.AlwaysTreatableHediffs, bedMedPod.NeverTreatableHediffs) || bedMedPod.Aborted;
         return(false); // Skip original code
     }
     return(true);      // Run original code
 }