Exemplo n.º 1
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);
        }