public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
        {
            _003CGetFloatMenuOptions_003Ec__Iterator2 _003CGetFloatMenuOptions_003Ec__Iterator = (_003CGetFloatMenuOptions_003Ec__Iterator2) /*Error near IL_003a: stateMachine*/;

            if (!myPawn.RaceProps.Humanlike)
            {
                yield break;
            }
            if (this.ForPrisoners)
            {
                yield break;
            }
            if (!this.Medical)
            {
                yield break;
            }
            if (myPawn.Drafted)
            {
                yield break;
            }
            if (base.Faction != Faction.OfPlayer)
            {
                yield break;
            }
            if (!RestUtility.CanUseBedEver(myPawn, base.def))
            {
                yield break;
            }
            if (!HealthAIUtility.ShouldSeekMedicalRest(myPawn) && !HealthAIUtility.ShouldSeekMedicalRestUrgent(myPawn))
            {
                yield return(new FloatMenuOption("UseMedicalBed".Translate() + " (" + "NotInjured".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null));

                /*Error: Unable to find new state assignment for yield return*/;
            }
            Action sleep = delegate
            {
                if (!_003CGetFloatMenuOptions_003Ec__Iterator._0024this.ForPrisoners && _003CGetFloatMenuOptions_003Ec__Iterator._0024this.Medical && myPawn.CanReserveAndReach(_003CGetFloatMenuOptions_003Ec__Iterator._0024this, PathEndMode.ClosestTouch, Danger.Deadly, _003CGetFloatMenuOptions_003Ec__Iterator._0024this.SleepingSlotsCount, -1, null, true))
                {
                    Job job = new Job(JobDefOf.LayDown, _003CGetFloatMenuOptions_003Ec__Iterator._0024this);
                    job.restUntilHealed = true;
                    myPawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                    myPawn.mindState.ResetLastDisturbanceTick();
                }
            };

            if (this.AnyUnoccupiedSleepingSlot)
            {
                yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("UseMedicalBed".Translate(), sleep, MenuOptionPriority.Default, null, null, 0f, null, null), myPawn, this, "ReservedBy"));

                /*Error: Unable to find new state assignment for yield return*/;
            }
            yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("UseMedicalBed".Translate(), sleep, MenuOptionPriority.Default, null, null, 0f, null, null), myPawn, this, "SomeoneElseSleeping"));

            /*Error: Unable to find new state assignment for yield return*/;
        }
Exemple #2
0
 private TransferableOneWay BestBedFor(Pawn pawn)
 {
     for (int i = 0; i < tmpBeds.Count; i++)
     {
         Thing innerIfMinified = tmpBeds[i].AnyThing.GetInnerIfMinified();
         if (RestUtility.CanUseBedEver(pawn, innerIfMinified.def))
         {
             return(tmpBeds[i]);
         }
     }
     return(null);
 }
Exemple #3
0
        public static bool IsValidBedFor(Thing bedThing, Pawn sleeper, Pawn traveler, bool sleeperWillBePrisoner, bool checkSocialProperness, bool allowMedBedEvenIfSetToNoCare = false, bool ignoreOtherReservations = false)
        {
            Building_Bed building_Bed = bedThing as Building_Bed;

            if (building_Bed == null)
            {
                return(false);
            }
            LocalTargetInfo target             = building_Bed;
            PathEndMode     peMode             = PathEndMode.OnCell;
            Danger          maxDanger          = Danger.Some;
            int             sleepingSlotsCount = building_Bed.SleepingSlotsCount;

            if (!traveler.CanReserveAndReach(target, peMode, maxDanger, sleepingSlotsCount, -1, null, ignoreOtherReservations))
            {
                return(false);
            }
            if (!RestUtility.CanUseBedEver(sleeper, building_Bed.def))
            {
                return(false);
            }
            if (!building_Bed.AnyUnoccupiedSleepingSlot && (!sleeper.InBed() || sleeper.CurrentBed() != building_Bed) && !building_Bed.AssignedPawns.Contains(sleeper))
            {
                return(false);
            }
            if (building_Bed.IsForbidden(traveler))
            {
                return(false);
            }
            if (checkSocialProperness && !building_Bed.IsSociallyProper(sleeper, sleeperWillBePrisoner, false))
            {
                return(false);
            }
            if (building_Bed.IsBurning())
            {
                return(false);
            }
            if (sleeperWillBePrisoner)
            {
                if (!building_Bed.ForPrisoners)
                {
                    return(false);
                }
                if (!building_Bed.Position.IsInPrisonCell(building_Bed.Map))
                {
                    return(false);
                }
            }
            else
            {
                if (building_Bed.Faction != traveler.Faction)
                {
                    return(false);
                }
                if (building_Bed.ForPrisoners)
                {
                    return(false);
                }
            }
            if (building_Bed.Medical)
            {
                if (!allowMedBedEvenIfSetToNoCare && !HealthAIUtility.ShouldEverReceiveMedicalCare(sleeper))
                {
                    return(false);
                }
                if (!HealthAIUtility.ShouldSeekMedicalRest(sleeper))
                {
                    return(false);
                }
            }
            else if (building_Bed.owners.Any <Pawn>() && !building_Bed.owners.Contains(sleeper))
            {
                if (sleeper.IsPrisoner || sleeperWillBePrisoner)
                {
                    if (!building_Bed.AnyUnownedSleepingSlot)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!RestUtility.IsAnyOwnerLovePartnerOf(building_Bed, sleeper))
                    {
                        return(false);
                    }
                    if (!building_Bed.AnyUnownedSleepingSlot)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Exemple #4
0
        public static Building_Bed FindBedFor(Pawn sleeper, Pawn traveler, bool sleeperWillBePrisoner, bool checkSocialProperness, bool ignoreOtherReservations = false)
        {
            if (HealthAIUtility.ShouldSeekMedicalRest(sleeper))
            {
                if (sleeper.InBed() && sleeper.CurrentBed().Medical)
                {
                    Building_Bed bedThing = sleeper.CurrentBed();
                    Pawn         pawn     = sleeper;
                    Pawn         pawn2    = traveler;
                    bool         flag     = sleeperWillBePrisoner;
                    bool         checkSocialProperness2 = checkSocialProperness;
                    bool         flag2 = ignoreOtherReservations;
                    if (RestUtility.IsValidBedFor(bedThing, pawn, pawn2, flag, checkSocialProperness2, false, flag2))
                    {
                        return(sleeper.CurrentBed());
                    }
                }
                for (int i = 0; i < RestUtility.bedDefsBestToWorst_Medical.Count; i++)
                {
                    ThingDef thingDef = RestUtility.bedDefsBestToWorst_Medical[i];
                    if (RestUtility.CanUseBedEver(sleeper, thingDef))
                    {
                        for (int j = 0; j < 2; j++)
                        {
                            Danger       maxDanger    = (j != 0) ? Danger.Deadly : Danger.None;
                            Building_Bed building_Bed = (Building_Bed)GenClosest.ClosestThingReachable(sleeper.Position, sleeper.Map, ThingRequest.ForDef(thingDef), PathEndMode.OnCell, TraverseParms.For(traveler, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, delegate(Thing b)
                            {
                                bool arg_92_0;
                                if (((Building_Bed)b).Medical && b.Position.GetDangerFor(sleeper, sleeper.Map) <= maxDanger)
                                {
                                    Pawn sleeper2  = sleeper;
                                    Pawn traveler2 = traveler;
                                    bool sleeperWillBePrisoner2   = sleeperWillBePrisoner;
                                    bool checkSocialProperness3   = checkSocialProperness;
                                    bool ignoreOtherReservations2 = ignoreOtherReservations;
                                    arg_92_0 = RestUtility.IsValidBedFor(b, sleeper2, traveler2, sleeperWillBePrisoner2, checkSocialProperness3, false, ignoreOtherReservations2);
                                }
                                else
                                {
                                    arg_92_0 = false;
                                }
                                return(arg_92_0);
                            }, null, 0, -1, false, RegionType.Set_Passable, false);
                            if (building_Bed != null)
                            {
                                return(building_Bed);
                            }
                        }
                    }
                }
            }
            if (sleeper.ownership != null && sleeper.ownership.OwnedBed != null)
            {
                Building_Bed bedThing = sleeper.ownership.OwnedBed;
                Pawn         pawn2    = sleeper;
                Pawn         pawn     = traveler;
                bool         flag2    = sleeperWillBePrisoner;
                bool         checkSocialProperness2 = checkSocialProperness;
                bool         flag = ignoreOtherReservations;
                if (RestUtility.IsValidBedFor(bedThing, pawn2, pawn, flag2, checkSocialProperness2, false, flag))
                {
                    return(sleeper.ownership.OwnedBed);
                }
            }
            DirectPawnRelation directPawnRelation = LovePartnerRelationUtility.ExistingMostLikedLovePartnerRel(sleeper, false);

            if (directPawnRelation != null)
            {
                Building_Bed ownedBed = directPawnRelation.otherPawn.ownership.OwnedBed;
                if (ownedBed != null)
                {
                    Building_Bed bedThing = ownedBed;
                    Pawn         pawn     = sleeper;
                    Pawn         pawn2    = traveler;
                    bool         flag     = sleeperWillBePrisoner;
                    bool         checkSocialProperness2 = checkSocialProperness;
                    bool         flag2 = ignoreOtherReservations;
                    if (RestUtility.IsValidBedFor(bedThing, pawn, pawn2, flag, checkSocialProperness2, false, flag2))
                    {
                        return(ownedBed);
                    }
                }
            }
            for (int k = 0; k < 2; k++)
            {
                Danger maxDanger = (k != 0) ? Danger.Deadly : Danger.None;
                for (int l = 0; l < RestUtility.bedDefsBestToWorst_RestEffectiveness.Count; l++)
                {
                    ThingDef thingDef2 = RestUtility.bedDefsBestToWorst_RestEffectiveness[l];
                    if (RestUtility.CanUseBedEver(sleeper, thingDef2))
                    {
                        Building_Bed building_Bed2 = (Building_Bed)GenClosest.ClosestThingReachable(sleeper.Position, sleeper.Map, ThingRequest.ForDef(thingDef2), PathEndMode.OnCell, TraverseParms.For(traveler, Danger.Deadly, TraverseMode.ByPawn, false), 9999f, delegate(Thing b)
                        {
                            bool arg_92_0;
                            if (!((Building_Bed)b).Medical && b.Position.GetDangerFor(sleeper, sleeper.Map) <= maxDanger)
                            {
                                Pawn sleeper2  = sleeper;
                                Pawn traveler2 = traveler;
                                bool sleeperWillBePrisoner2   = sleeperWillBePrisoner;
                                bool checkSocialProperness3   = checkSocialProperness;
                                bool ignoreOtherReservations2 = ignoreOtherReservations;
                                arg_92_0 = RestUtility.IsValidBedFor(b, sleeper2, traveler2, sleeperWillBePrisoner2, checkSocialProperness3, false, ignoreOtherReservations2);
                            }
                            else
                            {
                                arg_92_0 = false;
                            }
                            return(arg_92_0);
                        }, null, 0, -1, false, RegionType.Set_Passable, false);
                        if (building_Bed2 != null)
                        {
                            return(building_Bed2);
                        }
                    }
                }
            }
            return(null);
        }
Exemple #5
0
        private static void CreateSurgeryBill(Pawn medPawn, RecipeDef recipe, BodyPartRecord part)
        {
            Bill_Medical bill_Medical = new Bill_Medical(recipe);

            medPawn.BillStack.AddBill(bill_Medical);
            bill_Medical.Part = part;
            if (recipe.conceptLearned != null)
            {
                PlayerKnowledgeDatabase.KnowledgeDemonstrated(recipe.conceptLearned, KnowledgeAmount.Total);
            }
            Map map = medPawn.Map;

            if (!map.mapPawns.FreeColonists.Any((Pawn col) => recipe.PawnSatisfiesSkillRequirements(col)))
            {
                Bill.CreateNoPawnsWithSkillDialog(recipe);
            }
            if (!medPawn.InBed() && medPawn.RaceProps.IsFlesh)
            {
                if (medPawn.RaceProps.Humanlike)
                {
                    if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(medPawn, x.def) && ((Building_Bed)x).Medical))
                    {
                        Messages.Message("MessageNoMedicalBeds".Translate(), medPawn, MessageTypeDefOf.CautionInput, historical: false);
                    }
                }
                else if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(medPawn, x.def)))
                {
                    Messages.Message("MessageNoAnimalBeds".Translate(), medPawn, MessageTypeDefOf.CautionInput, historical: false);
                }
            }
            if (medPawn.Faction != null && !medPawn.Faction.Hidden && !medPawn.Faction.HostileTo(Faction.OfPlayer) && recipe.Worker.IsViolationOnPawn(medPawn, part, Faction.OfPlayer))
            {
                Messages.Message("MessageMedicalOperationWillAngerFaction".Translate(medPawn.FactionOrExtraMiniOrHomeFaction), medPawn, MessageTypeDefOf.CautionInput, historical: false);
            }
            ThingDef minRequiredMedicine = GetMinRequiredMedicine(recipe);

            if (minRequiredMedicine != null && medPawn.playerSettings != null && !medPawn.playerSettings.medCare.AllowsMedicine(minRequiredMedicine))
            {
                Messages.Message("MessageTooLowMedCare".Translate(minRequiredMedicine.label, medPawn.LabelShort, medPawn.playerSettings.medCare.GetLabel(), medPawn.Named("PAWN")), medPawn, MessageTypeDefOf.CautionInput, historical: false);
            }
            recipe.Worker.CheckForWarnings(medPawn);
        }
Exemple #6
0
        private static FloatMenuOption GenerateSurgeryOption(Pawn pawn, Thing thingForMedBills, RecipeDef recipe, IEnumerable <ThingDef> missingIngredients, BodyPartRecord part = null)
        {
            string text = recipe.Worker.GetLabelWhenUsedOn(pawn, part);

            if (part != null && !recipe.hideBodyPartNames)
            {
                text = text + " (" + part.def.label + ")";
            }
            FloatMenuOption floatMenuOption;

            if (missingIngredients.Any())
            {
                text += " (";
                bool flag = true;
                foreach (ThingDef missingIngredient in missingIngredients)
                {
                    if (!flag)
                    {
                        text += ", ";
                    }
                    flag  = false;
                    text += "MissingMedicalBillIngredient".Translate(missingIngredient.label);
                }
                text           += ")";
                floatMenuOption = new FloatMenuOption(text, null, MenuOptionPriority.Default, null, null, 0f, null, null);
            }
            else
            {
                Action action = delegate
                {
                    Pawn pawn2 = thingForMedBills as Pawn;
                    if (pawn2 != null)
                    {
                        Bill_Medical bill_Medical = new Bill_Medical(recipe);
                        pawn2.BillStack.AddBill(bill_Medical);
                        bill_Medical.Part = part;
                        if (recipe.conceptLearned != null)
                        {
                            PlayerKnowledgeDatabase.KnowledgeDemonstrated(recipe.conceptLearned, KnowledgeAmount.Total);
                        }
                        Map map = thingForMedBills.Map;
                        if (!map.mapPawns.FreeColonists.Any((Pawn col) => recipe.PawnSatisfiesSkillRequirements(col)))
                        {
                            Bill.CreateNoPawnsWithSkillDialog(recipe);
                        }
                        if (!pawn2.InBed() && pawn2.RaceProps.IsFlesh)
                        {
                            if (pawn2.RaceProps.Humanlike)
                            {
                                if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(pawn, x.def) && ((Building_Bed)x).Medical))
                                {
                                    Messages.Message("MessageNoMedicalBeds".Translate(), pawn2, MessageTypeDefOf.CautionInput);
                                }
                            }
                            else if (!map.listerBuildings.allBuildingsColonist.Any((Building x) => x is Building_Bed && RestUtility.CanUseBedEver(pawn, x.def)))
                            {
                                Messages.Message("MessageNoAnimalBeds".Translate(), pawn2, MessageTypeDefOf.CautionInput);
                            }
                        }
                        if (pawn2.Faction != null && !pawn2.Faction.def.hidden && !pawn2.Faction.HostileTo(Faction.OfPlayer) && recipe.Worker.IsViolationOnPawn(pawn2, part, Faction.OfPlayer))
                        {
                            Messages.Message("MessageMedicalOperationWillAngerFaction".Translate(pawn2.Faction), pawn2, MessageTypeDefOf.CautionInput);
                        }
                        ThingDef minRequiredMedicine = HealthCardUtility.GetMinRequiredMedicine(recipe);
                        if (minRequiredMedicine != null && pawn2.playerSettings != null && !pawn2.playerSettings.medCare.AllowsMedicine(minRequiredMedicine))
                        {
                            Messages.Message("MessageTooLowMedCare".Translate(minRequiredMedicine.label, pawn2.LabelShort, pawn2.playerSettings.medCare.GetLabel()), pawn2, MessageTypeDefOf.CautionInput);
                        }
                    }
                };
                floatMenuOption = new FloatMenuOption(text, action, MenuOptionPriority.Default, null, null, 0f, null, null);
            }
            floatMenuOption.extraPartWidth = 29f;
            floatMenuOption.extraPartOnGUI = ((Rect rect) => Widgets.InfoCardButton((float)(rect.x + 5.0), (float)(rect.y + (rect.height - 24.0) / 2.0), recipe));
            return(floatMenuOption);
        }
Exemple #7
0
 public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
 {
     if (myPawn.RaceProps.Humanlike && !this.ForPrisoners && this.Medical && !myPawn.Drafted && base.Faction == Faction.OfPlayer && RestUtility.CanUseBedEver(myPawn, this.def))
     {
         if (!HealthAIUtility.ShouldSeekMedicalRest(myPawn) && !HealthAIUtility.ShouldSeekMedicalRestUrgent(myPawn))
         {
             yield return(new FloatMenuOption("UseMedicalBed".Translate() + " (" + "NotInjured".Translate() + ")", null, MenuOptionPriority.Default, null, null, 0f, null, null));
         }
         else
         {
             Action sleep = delegate
             {
                 if (!this.$this.ForPrisoners && this.$this.Medical && myPawn.CanReserveAndReach(this.$this, PathEndMode.ClosestTouch, Danger.Deadly, this.$this.SleepingSlotsCount, -1, null, true))
                 {
                     Job job = new Job(JobDefOf.LayDown, this.$this);
                     job.restUntilHealed = true;
                     myPawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                     myPawn.mindState.ResetLastDisturbanceTick();
                 }
             };
             if (this.AnyUnoccupiedSleepingSlot)
             {
                 yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("UseMedicalBed".Translate(), sleep, MenuOptionPriority.Default, null, null, 0f, null, null), myPawn, this, "ReservedBy"));
             }
             else
             {
                 yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("UseMedicalBed".Translate(), sleep, MenuOptionPriority.Default, null, null, 0f, null, null), myPawn, this, "SomeoneElseSleeping"));
             }
         }
     }
 }
Exemple #8
0
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
        {
            _003CGetFloatMenuOptions_003Ec__Iterator2 _003CGetFloatMenuOptions_003Ec__Iterator = (_003CGetFloatMenuOptions_003Ec__Iterator2) /*Error near IL_0036: stateMachine*/;

            if (myPawn.RaceProps.Humanlike && !ForPrisoners && Medical && !myPawn.Drafted && base.Faction == Faction.OfPlayer && RestUtility.CanUseBedEver(myPawn, def))
            {
                if (!HealthAIUtility.ShouldSeekMedicalRest(myPawn) && !HealthAIUtility.ShouldSeekMedicalRestUrgent(myPawn))
                {
                    yield return(new FloatMenuOption("UseMedicalBed".Translate() + " (" + "NotInjured".Translate() + ")", null));

                    /*Error: Unable to find new state assignment for yield return*/;
                }
                yield return(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(action: delegate
                {
                    if (!_003CGetFloatMenuOptions_003Ec__Iterator._0024this.ForPrisoners && _003CGetFloatMenuOptions_003Ec__Iterator._0024this.Medical && myPawn.CanReserveAndReach(_003CGetFloatMenuOptions_003Ec__Iterator._0024this, PathEndMode.ClosestTouch, Danger.Deadly, _003CGetFloatMenuOptions_003Ec__Iterator._0024this.SleepingSlotsCount, -1, null, ignoreOtherReservations: true))
                    {
                        if (myPawn.CurJobDef == JobDefOf.LayDown && myPawn.CurJob.GetTarget(TargetIndex.A).Thing == _003CGetFloatMenuOptions_003Ec__Iterator._0024this)
                        {
                            myPawn.CurJob.restUntilHealed = true;
                        }
                        else
                        {
                            Job job = new Job(JobDefOf.LayDown, _003CGetFloatMenuOptions_003Ec__Iterator._0024this)
                            {
                                restUntilHealed = true
                            };
                            myPawn.jobs.TryTakeOrderedJob(job);
                        }
                        myPawn.mindState.ResetLastDisturbanceTick();
                    }
                }, label: "UseMedicalBed".Translate()), myPawn, this, (!AnyUnoccupiedSleepingSlot) ? "SomeoneElseSleeping" : "ReservedBy"));

                /*Error: Unable to find new state assignment for yield return*/;
            }
        }
        public override IEnumerable <FloatMenuOption> GetFloatMenuOptions(Pawn myPawn)
        {
            if (!myPawn.RaceProps.Humanlike || ForPrisoners || !Medical || myPawn.Drafted || base.Faction != Faction.OfPlayer || !RestUtility.CanUseBedEver(myPawn, def))
            {
                yield break;
            }
            if (!HealthAIUtility.ShouldSeekMedicalRest(myPawn) && !HealthAIUtility.ShouldSeekMedicalRestUrgent(myPawn))
            {
                yield return(new FloatMenuOption("UseMedicalBed".Translate() + " (" + "NotInjured".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()));
        }