Beispiel #1
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn != null && pawn.Map != null && pawn.health != null && pawn.health.hediffSet != null && pawn.health.hediffSet.HasHediff(TorannMagicDefOf.TM_ChiHD) && !pawn.Drafted)
            {
                if (pawn.InBed() || HealthAIUtility.ShouldSeekMedicalRest(pawn) || !(pawn.GetPosture() == PawnPosture.Standing))
                {
                    return(null);
                }
                Need_Joy curJoy = pawn.needs.joy;
                if (curJoy == null)
                {
                    return(null);
                }
                if (curJoy.CurLevel >= .8f)
                {
                    return(null);
                }
                CompAbilityUserMight comp = pawn.GetComp <CompAbilityUserMight>();
                if (comp != null)
                {
                    MightPower mightPower = comp.MightData.MightPowersM.FirstOrDefault <MightPower>((MightPower x) => x.abilityDef == TorannMagicDefOf.TM_Meditate);

                    if (mightPower == null)
                    {
                        return(null);
                    }

                    if (!mightPower.AutoCast)
                    {
                        return(null);
                    }

                    Hediff      hediff  = pawn.health.hediffSet.GetFirstHediffOfDef(TorannMagicDefOf.TM_ChiHD);
                    PawnAbility ability = pawn.GetComp <CompAbilityUserMight>().AbilityData.Powers.FirstOrDefault((PawnAbility x) => x.Def == TorannMagicDefOf.TM_Meditate);

                    if (ability.CooldownTicksLeft > 0 || hediff.Severity >= 70)
                    {
                        return(null);
                    }

                    Building_Bed building_Bed = pawn.ownership.OwnedBed;
                    if (building_Bed != null)
                    {
                        if (building_Bed.GetRoom() != null && !building_Bed.GetRoom().PsychologicallyOutdoors)
                        {
                            List <IntVec3> roomCells = building_Bed.GetRoom().Cells.ToList();
                            for (int i = 0; i < roomCells.Count; i++)
                            {
                                if (roomCells[i].IsValid && roomCells[i].Walkable(pawn.Map) && roomCells[i].GetFirstBuilding(pawn.Map) == null)
                                {
                                    return(new Job(TorannMagicDefOf.JobDriver_TM_Meditate, roomCells[i]));
                                }
                            }
                        }
                    }
                    return(new Job(TorannMagicDefOf.JobDriver_TM_Meditate, pawn.Position));
                }
            }
            return(null);
        }
        public override float GetPriority(Pawn pawn)
        {
            if (pawn.health.hediffSet.HasNaturallyHealingInjury() || HealthAIUtility.ShouldSeekMedicalRest(pawn))
            {
                return(6);
            }

            if (pawn.needs?.rest == null)
            {
                Log.Message(pawn.Name.ToStringShort + " needs no rest...");
                return(0f);
            }
            float curLevel = pawn.needs.rest.CurLevel;

            int hourOfDay = GenLocalDate.HourOfDay(pawn);

            if (hourOfDay < 7 || hourOfDay > 21)
            {
                curLevel -= 0.2f;
            }

            if (curLevel < 0.35f)
            {
                return(6f);
            }

            if (curLevel > 0.4f)
            {
                return(0f);
            }
            return(1 - curLevel);
        }
Beispiel #3
0
 protected override bool Satisfied(Pawn pawn)
 {
     if (pawn.CurJob == null || !pawn.GetPosture().Laying() || (pawn.def.defName == "M7Mech" && !pawn.IsSurrogateAndroid()))
     {
         return(false);
     }
     if (!pawn.Downed)
     {
         if (RestUtility.DisturbancePreventsLyingDown(pawn))
         {
             return(false);
         }
         if (!pawn.CurJob.restUntilHealed || !HealthAIUtility.ShouldSeekMedicalRest(pawn))
         {
             if (!pawn.jobs.curDriver.asleep)
             {
                 return(false);
             }
             if (!pawn.CurJob.playerForced && RestUtility.TimetablePreventsLayDown(pawn))
             {
                 return(false);
             }
         }
     }
     return(true);
 }
 protected override bool Satisfied(Pawn pawn)
 {
     return(Settings.UseGasp && Settings.ApplyAnimals && pawn.AnimalOrWildMan() && !pawn.IsWildMan() &&
            pawn.Faction != null && pawn.Faction == Faction.OfPlayer && !pawn.Downed && !pawn.IsBurning() &&
            pawn.Awake() && !pawn.InMentalState && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Moving) &&
            !HealthAIUtility.ShouldSeekMedicalRest(pawn) && !BrrrGlobals.BrrrAnimalIsFollowing(pawn));
 }
        // RimWorld.SickPawnVisitUtility
        private static bool AboutToRecover(Pawn pawn)
        {
            if (pawn.Downed)
            {
                return(false);
            }

            if (!HealthAIUtility.ShouldSeekMedicalRestUrgent(pawn) && !HealthAIUtility.ShouldSeekMedicalRest(pawn))
            {
                return(true);
            }

            if (pawn.health.hediffSet.HasImmunizableNotImmuneHediff())
            {
                return(false);
            }

            float         num     = 0f;
            List <Hediff> hediffs = pawn.health.hediffSet.hediffs;

            for (int i = 0; i < hediffs.Count; i++)
            {
                Hediff_Injury hediff_Injury = hediffs[i] as Hediff_Injury;
                if (hediff_Injury != null && (hediff_Injury.CanHealFromTending() || hediff_Injury.CanHealNaturally() ||
                                              hediff_Injury.Bleeding))
                {
                    num += hediff_Injury.Severity;
                }
            }

            return(num < 8f * pawn.RaceProps.baseHealthScale);
        }
Beispiel #6
0
 public static bool WorkTime(Pawn pawn)
 {
     if (pawn.needs == null || pawn.needs.food == null || pawn.needs.rest == null)
     {
         return(false);
     }
     if (pawn.timetable == null)
     {
         return(true);
     }
     if (pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Work)
     {
         return(true);
     }
     if (pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Anything)
     {
         if (HealthAIUtility.ShouldSeekMedicalRest(pawn) ||
             pawn.health.hediffSet.HasTemperatureInjury(TemperatureInjuryStage.Serious) ||
             pawn.needs.food.CurCategory > HungerCategory.Hungry ||
             pawn.needs.rest.CurCategory != RestCategory.Rested)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #7
0
        /*
         * public static Building_HackingTable HackingTable(this Pawn pawn)
         * {
         *  List<Thing> thingList = pawn.Position.GetThingList(pawn.Map);
         *  Building_HackingTable hackingTable = null;
         *  for (int i = 0; i < thingList.Count; i++)
         *  {
         *      hackingTable = (thingList[i] as Building_HackingTable);
         *      if (hackingTable != null)
         *      {
         *          break;
         *      }
         *  }
         *  if (hackingTable == null)
         *  {
         *      return null;
         *  }
         *  if(hackingTable.GetCurOccupant(0) == pawn)
         *  {
         *      return hackingTable;
         *  }
         *  return null;
         * }
         */
        /*
         * public static bool OnHackingTable(this Pawn pawn)
         * {
         *  if(pawn.HackingTable() != null)
         *  {
         *      return true;
         *  }
         *  return false;
         * }
         */

        public static void FailOnPlatformNoLongerUsable(this Toil toil, TargetIndex bedIndex)
        {
            toil.FailOnDespawnedOrNull(bedIndex);
            toil.FailOn(() => ((Building_Bed)toil.actor.CurJob.GetTarget(bedIndex).Thing).IsBurning());
            toil.FailOn(() => !HealthAIUtility.ShouldSeekMedicalRest(toil.actor) && !HealthAIUtility.ShouldSeekMedicalRestUrgent(toil.actor) && ((Building_Bed)toil.actor.CurJob.GetTarget(bedIndex).Thing).Medical);
            toil.FailOn(() => toil.actor.IsColonist && !toil.actor.CurJob.ignoreForbidden && !toil.actor.Downed && toil.actor.CurJob.GetTarget(bedIndex).Thing.IsForbidden(toil.actor));
        }
Beispiel #8
0
        public static bool PrisonLabor_WorkTimePrefix(Pawn pawn, ref bool __result)
        {
            if (pawn != null && pawn.IsAndroidTier())
            {
                if (pawn.timetable == null)
                {
                    __result = true;
                }
                else if (pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Work)
                {
                    __result = true;
                }
                else if (pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Anything)
                {
                    if (HealthAIUtility.ShouldSeekMedicalRest(pawn) ||
                        pawn.health.hediffSet.HasTemperatureInjury(TemperatureInjuryStage.Serious) ||
                        pawn.needs.food.CurCategory > HungerCategory.Hungry)
                    {
                        __result = false;
                    }
                    else
                    {
                        __result = true;
                    }
                }
                else
                {
                    __result = false;
                }

                return(false);
            }

            return(true);
        }
        public static bool WorkTime(Pawn pawn)
        {
/*            if (pawn.needs == null || pawn.needs.food == null || pawn.needs.rest == null)
 *              return false;*/
            if (pawn.timetable == null)
            {
                return(true);
            }
            if (pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Work)
            {
                return(true);
            }
            if (pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Anything)
            {
                if (HealthAIUtility.ShouldSeekMedicalRest(pawn) ||
                    pawn.health.hediffSet.HasTemperatureInjury(TemperatureInjuryStage.Serious) ||
                    CheckFoodNeed(pawn) ||
                    CheckRestNeed(pawn))
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            return(false);
        }
        // Token: 0x0600004F RID: 79 RVA: 0x000044B4 File Offset: 0x000026B4
        public static bool CompatPatch_ShouldMeasureTimeNow(bool __result, ref Pawn pawn)
        {
            bool flag = pawn == null;
            bool result;

            if (flag)
            {
                result = true;
            }
            else
            {
                Pawn pawn2 = pawn;
                bool flag2 = ((pawn2 != null) ? pawn2.needs.TryGetNeed(NeedDefOf.Rest) : null) != null;
                bool flag3 = !flag2;
                if (flag3)
                {
                    if (pawn.InBed())
                    {
                        if (!HealthAIUtility.ShouldSeekMedicalRestUrgent(pawn))
                        {
                            bool flag4 = HealthAIUtility.ShouldSeekMedicalRest(pawn) && pawn.CurJob.restUntilHealed;
                        }
                    }
                    result = false;
                }
                else
                {
                    result = true;
                }
            }
            return(result);
        }
            public static void Postfix(Pawn sleeper, Thing bedThing, ref bool __result, bool sleeperWillBePrisoner)
            {
                if (!__result)
                {
                    return;
                }
                switch (bedThing)
                {
                // guest bed
                case Building_GuestBed guestBed:
                    if (!sleeper.IsGuest())
                    {
                        __result = false;
                    }
                    break;

                // normal bed
                case Building_Bed bed:
                    if (sleeper.IsGuest())
                    {
                        __result = HealthAIUtility.ShouldSeekMedicalRest(sleeper) || sleeper.health.hediffSet.HasNaturallyHealingInjury() || sleeperWillBePrisoner;
                    }
                    break;
                }
            }
Beispiel #12
0
 public static bool WorkTime(Pawn pawn)
 {
     if (pawn.timetable == null)
     {
         return(true);
     }
     if (pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Work)
     {
         return(true);
     }
     if (pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Anything)
     {
         if (HealthAIUtility.ShouldSeekMedicalRest(pawn) ||
             pawn.needs.food.CurCategory > HungerCategory.Hungry ||
             pawn.needs.rest.CurCategory != RestCategory.Rested)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #13
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            if (pawn.AnimalOrWildMan())
            {
                return(null);
            }

            if (!pawn.IsColonist)
            {
                return(null);
            }

            if (pawn.Drafted)
            {
                return(null);
            }

            if (pawn.Downed)
            {
                return(null);
            }

            if (HealthAIUtility.ShouldSeekMedicalRest(pawn))
            {
                return(null);
            }

            CompMilkableHumanoid compMilk = pawn.TryGetComp <CompMilkableHumanoid>();

            if (compMilk == null)
            {
                return(null);
            }

            if (!compMilk.ActiveAndCanBeMilked)
            {
                return(null);
            }

            if (!compMilk.MilkProps.canMilkThemselves)
            {
                return(null);
            }

            Pawn lover = LovePartnerRelationUtility.ExistingLovePartner(pawn);

            if (lover != null)
            {
                if (pawn.Faction == lover.Faction)
                {
                    if (!lover.Drafted && !lover.Downed && !HealthAIUtility.ShouldSeekMedicalRest(lover))
                    {
                        return(null);
                    }
                }
            }

            return(new Job(MilkyDefOf.MilkySelf));
        }
 protected override bool Satisfied(Pawn pawn)
 {
     if (pawn.Downed || HealthAIUtility.ShouldSeekMedicalRest(pawn) || pawn.IsBurning())
     {
         return(false);
     }
     return(true);
 }
        // Token: 0x0600002D RID: 45 RVA: 0x00002758 File Offset: 0x00000958
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParm)
        {
            bool        flag = !HealthAIUtility.ShouldSeekMedicalRest(pawn);
            ThinkResult result;

            if (flag)
            {
                result = ThinkResult.NoJob;
            }
            else
            {
                bool flag2 = !HealthAIUtility.ShouldBeTendedNowByPlayer(pawn);
                if (flag2)
                {
                    result = ThinkResult.NoJob;
                }
                else
                {
                    bool flag3 = !GenCollection.Any <Apparel>(pawn.apparel.WornApparel, (Apparel x) => x.def.defName.Contains("RRY_Equipment_HunterGauntlet"));
                    if (flag3)
                    {
                        result = ThinkResult.NoJob;
                    }
                    else
                    {
                        Thing thing = RestUtility.FindPatientBedFor(pawn);
                        bool  flag4 = thing == null;
                        if (flag4)
                        {
                            result = ThinkResult.NoJob;
                        }
                        else
                        {
                            Thing thing2 = null;
                            bool  flag5  = Medicine.GetMedicineCountToFullyHeal(pawn) > 0;
                            if (flag5)
                            {
                                thing2 = HealthAIUtility.FindBestMedicine(pawn, pawn);
                            }
                            bool flag6 = thing2 != null;
                            Job  job;
                            if (flag6)
                            {
                                job = new Job(YautjaDefOf.RRY_Yautja_TendSelf, thing, thing2);
                            }
                            else
                            {
                                job = new Job(YautjaDefOf.RRY_Yautja_TendSelf, thing);
                            }
                            result = new ThinkResult(job, this, null, false);
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #16
0
 protected override bool Satisfied(Pawn pawn)
 {
     return((pawn.IsColonistPlayerControlled && pawn.health.capacities.CapableOf(PawnCapacityDefOf.Moving)) &&
            !pawn.Downed &&
            !pawn.IsBurning() &&
            !pawn.InMentalState &&
            !pawn.Drafted &&
            pawn.Awake() &&
            !HealthAIUtility.ShouldSeekMedicalRest(pawn));
 }
Beispiel #17
0
 private static void Postfix(ref bool __result, Pawn pawn)
 {
     if (__result || pawn is null)
     {
         return;
     }
     if (pawn.FindCage(null) != null)
     {
         __result = pawn.GetPosture() != PawnPosture.Standing && HealthAIUtility.ShouldSeekMedicalRest(pawn) &&
                    (pawn.HostFaction == null || pawn.HostFaction == Faction.OfPlayer && (pawn.guest?.CanBeBroughtFood ?? true));
     }
 }
Beispiel #18
0
        // Token: 0x0600000B RID: 11 RVA: 0x0000278C File Offset: 0x0000098C
        internal static bool NearThingEffects(Thing thing, Pawn pawn)
        {
            var def = thing.def;

            if (ProximityGet.GetProxRoomOnly(def))
            {
                // Func def changed, this used to be GetRoom
                var room  = thing.Position.GetRoomOrAdjacent(thing.Map);
                var room2 = pawn?.Position.GetRoomOrAdjacent(thing.Map);
                if (room != null && room2 != null && room != room2)
                {
                    return(false);
                }
            }

            if (pawn != null && pawn.IsColonist && !ProximityGet.GetProxColonist(def))
            {
                return(false);
            }

            if (pawn != null && pawn.Drafted && !ProximityGet.GetProxDrafted(def))
            {
                return(false);
            }

            if (!ProximityGet.GetProxComposMentis(def))
            {
                return(pawn != null && (!pawn.RaceProps.IsMechanoid || ProximityGet.GetProxMechanoid(def)) &&
                       (pawn.RaceProps.FleshType.defName != "Insectoid" || ProximityGet.GetProxInsectoid(def)) &&
                       (!pawn.AnimalOrWildMan() || ProximityGet.GetProxAnimal(def)) &&
                       (!pawn.IsPrisoner || ProximityGet.GetProxPrisoner(def)) &&
                       (pawn.Faction == thing.Faction || GetEffectsOutsider(thing, pawn)) &&
                       (ProximityGet.GetProxEquipped(def) == null || GetPawnHasEquipment(thing, pawn)));
            }

            if (pawn != null && (pawn.Downed || pawn.InMentalState || pawn.IsBurning() ||
                                 HealthAIUtility.ShouldSeekMedicalRest(pawn)))
            {
                return(false);
            }

            if (!pawn.Awake())
            {
                return(false);
            }

            return(pawn != null && (!pawn.RaceProps.IsMechanoid || ProximityGet.GetProxMechanoid(def)) &&
                   (pawn.RaceProps.FleshType.defName != "Insectoid" || ProximityGet.GetProxInsectoid(def)) &&
                   (!pawn.AnimalOrWildMan() || ProximityGet.GetProxAnimal(def)) &&
                   (!pawn.IsPrisoner || ProximityGet.GetProxPrisoner(def)) &&
                   (pawn.Faction == thing.Faction || GetEffectsOutsider(thing, pawn)) &&
                   (ProximityGet.GetProxEquipped(def) == null || GetPawnHasEquipment(thing, pawn)));
        }
Beispiel #19
0
        private float GetChangePoints()
        {
            if (pawn.IsPrisoner && pawn.IsPrisonerOfColony)
            {
                if (pawn.GetRoomGroup() != null)
                {
                    var value = InspirationTracker.GetInsiprationValue(pawn, true);

                    if (PrisonLaborUtility.LaborEnabled(pawn))
                    {
                        if (IsPrisonerWorking)
                        {
                            value -= BGP.Laziness_LazyRate;
                            if (HealthAIUtility.ShouldSeekMedicalRest(pawn))
                            {
                                value -= BGP.Laziness_HealthRate;
                            }
                            if (pawn.needs.food != null)
                            {
                                //warforged
                                value -= (int)pawn.needs.food.CurCategory * BGP.Laziness_HungryRate;
                            }
                            // Some pawns have no rest need (e.g. Pawns with Circadian Half Cycler or androids from other mods)
                            if (pawn.needs.rest != null)
                            {
                                value -= (int)pawn.needs.rest.CurCategory * BGP.Laziness_TiredRate;
                            }
                        }
                        else if (pawn.timetable != null && pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Joy)
                        {
                            value += BGP.Laziness_JoyRate;
                        }
                    }

                    _GUIChangeArrow = value.CompareTo(0.0f);
                    return(value);
                }
                else
                {
                    _GUIChangeArrow = 0;
                    return(0.0f);
                }
            }
            else
            {
                _GUIChangeArrow = 1;
                return(+0.01f);
            }
        }
Beispiel #20
0
        public void Update(RimworldTime time)
        {
            var hoursPassed = (time.Year - _updateTime.Year) * 60 * 24 + (time.Day - _updateTime.Day) * 24 + time.Hour -
                              _updateTime.Hour;

            _updateTime.Day  = time.Day;
            _updateTime.Hour = time.Hour;
            if (Prefs.DevMode && Settings.VerboseLogging)
            {
                Log.Message(
                    $"----- Work Manager: Updating cache for {Pawn.LabelShort} (hours passed = {hoursPassed})... -----");
            }
            IsCapable    = !Pawn.Dead && !Pawn.Downed && !Pawn.InMentalState;
            IsRecovering = IsCapable && Settings.RecoveringPawnsUnfitForWork &&
                           HealthAIUtility.ShouldSeekMedicalRest(Pawn);
            IsManaged = WorkManager.GetPawnEnabled(Pawn);
            WorkPriorities.Clear();
            _managedWorkTypes.Clear();
            var workTypes = DefDatabase <WorkTypeDef> .AllDefsListForReading.Where(w => w.visible);

            foreach (var workType in workTypes)
            {
                WorkPriorities.Add(workType, IsManagedWork(workType) ? 0 : Pawn.workSettings.GetPriority(workType));
            }
            if (!IsCapable)
            {
                return;
            }
            if (hoursPassed >= 24)
            {
                DisabledWorkTypes.Clear();
                BadWorkTypes.Clear();
            }
            if (hoursPassed >= 6)
            {
                if (Settings.UsePawnLearningRateThresholds)
                {
                    _skillLearningRates.Clear();
                    foreach (var skill in DefDatabase <SkillDef> .AllDefsListForReading)
                    {
                        _skillLearningRates.Add(skill, Pawn.skills.GetSkill(skill).LearnRateFactor());
                    }
                }
                _workSkillLearningRates.Clear();
                _workSkillLevels.Clear();
            }
        }
Beispiel #21
0
        protected virtual bool HasSufficientColonists(Map map)
        {
            var list = map.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer);
            int num  = 0;

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].IsFreeColonist && !HealthAIUtility.ShouldSeekMedicalRest(list[i]))
                {
                    if (++num >= MinCapableColonists)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #22
0
        static bool Prefix(Pawn sleeper, Pawn traveler, ref Building_Bed __result)
        {
            /*
             * if (sleeper.RaceProps.Animal && (__result is Building_MechanoidPlatform || __result is Building_HackingTable))
             * {
             *  return false;
             * }
             */

            if (!sleeper.RaceProps.IsMechanoid || !sleeper.IsHacked())
            {
                return(true);
            }

            if (HealthAIUtility.ShouldSeekMedicalRest(sleeper))
            {
                if (!sleeper.IsHacked())
                {
                    if (sleeper.OnHackingTable())
                    {
                        __result = sleeper.CurrentBed();
                        return(false);
                    }
                    else
                    {
                        __result = Utilities.GetAvailableHackingTable(traveler, sleeper);
                        return(false);
                    }
                }
                else
                {
                    if (sleeper.OnBaseMechanoidPlatform())
                    {
                        __result = sleeper.CurrentBed();
                        return(false);
                    }
                    else
                    {
                        __result = Utilities.GetAvailableMechanoidPlatform(traveler, sleeper);
                        return(false);
                    }
                }
            }
            return(true);
        }
Beispiel #23
0
        protected virtual bool HasSufficientColonists(Map map)
        {
            var list = map.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer);
            var num  = 0;

            foreach (var pawn in list)
            {
                if (pawn.IsFreeColonist && !HealthAIUtility.ShouldSeekMedicalRest(pawn))
                {
                    if (++num >= MinCapableColonists)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #24
0
        private static bool AtLeast2HealthyColonists(Map map)
        {
            List <Pawn> pawnList         = map.mapPawns.SpawnedPawnsInFaction(faction: Faction.OfPlayer);
            int         healthyColonists = 0;

            foreach (Pawn pawn in pawnList)
            {
                if (pawn.IsFreeColonist && !HealthAIUtility.ShouldSeekMedicalRest(pawn: pawn))
                {
                    healthyColonists++;
                    if (healthyColonists >= 2)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #25
0
        private float GetChangePoints()
        {
            if (pawn.IsPrisoner && pawn.IsPrisonerOfColony)
            {
                if (pawn.GetRoomGroup() != null)
                {
                    var value = InspirationTracker.GetInsiprationValue(pawn, true);

                    if (PrisonLaborUtility.LaborEnabled(pawn))
                    {
                        if (IsPrisonerWorking)
                        {
                            value -= BGP.Laziness_LazyRate;
                            if (HealthAIUtility.ShouldSeekMedicalRest(pawn))
                            {
                                value -= BGP.Laziness_HealthRate;
                            }
                            value -= (int)pawn.needs.food.CurCategory * BGP.Laziness_HungryRate;
                            value -= (int)pawn.needs.rest.CurCategory * BGP.Laziness_TiredRate;
                        }
                        else if (pawn.timetable != null && pawn.timetable.CurrentAssignment == TimeAssignmentDefOf.Joy)
                        {
                            value += BGP.Laziness_JoyRate;
                        }
                    }

                    _GUIChangeArrow = value.CompareTo(0.0f);
                    return(value);
                }
                else
                {
                    _GUIChangeArrow = 0;
                    return(0.0f);
                }
            }
            else
            {
                _GUIChangeArrow = 1;
                return(+0.01f);
            }
        }
Beispiel #26
0
        static bool Prefix(Pawn sleeper, Pawn traveler, ref Building_Bed __result)
        {
            if (!sleeper.IsHacked())
            {
                return(true);
            }

            if (HealthAIUtility.ShouldSeekMedicalRest(sleeper))
            {
                if (sleeper.OnBaseMechanoidPlatform())
                {
                    __result = sleeper.CurrentBed();
                    return(false);
                }
                else
                {
                    __result = Utilities.GetAvailableMechanoidPlatform(traveler, sleeper);
                    return(false);
                }
            }
            return(true);
        }
Beispiel #27
0
 protected override Job TryGiveJob(Pawn pawn)
 {
     if (pawn.InMentalState)
     {
         return(null);
     }
     if (pawn.Map == null)
     {
         return(null);
     }
     if (HealthAIUtility.ShouldSeekMedicalRest(pawn))
     {
         return(null);
     }
     if (RestUtility.DisturbancePreventsLyingDown(pawn))
     {
         return(null);
     }
     if (pawn.CurJobDef != null && pawn.CurJobDef == VFEV_DefOf.VFEV_HypothermiaResponse)
     {
         return(null);
     }
     if (!pawn.health.hediffSet.HasHediff(HediffDefOf.Hypothermia, false))
     {
         return(null);
     }
     if (pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.Hypothermia, false) is Hediff hediffHypothermia && hediffHypothermia != null && hediffHypothermia.Severity >= 0.35f)
     {
         Building_Bed bed = this.FindFurBedFor(pawn, pawn, false, true);
         if (bed != null)
         {
             return(new Job(VFEV_DefOf.VFEV_HypothermiaResponse, bed));
         }
     }
     return(null);
 }
        private bool AtLeast2HealthyColonists(Map map)
        {
            List <Pawn> list = map.mapPawns.SpawnedPawnsInFaction(Faction.OfPlayer);
            int         num  = 0;
            bool        result;

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].IsFreeColonist)
                {
                    if (!HealthAIUtility.ShouldSeekMedicalRest(list[i]))
                    {
                        num++;
                        if (num >= 2)
                        {
                            result = true;
                            return(result);
                        }
                    }
                }
            }
            result = false;
            return(result);
        }
Beispiel #29
0
        // Token: 0x06000067 RID: 103 RVA: 0x000043C0 File Offset: 0x000025C0
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParm)
        {
            ThinkResult result;

            if (!Controller.Settings.EquippingDone)
            {
                result = ThinkResult.NoJob;
            }
            else
            {
                var IsFW = pawn.IsColonistPlayerControlled &&
                           pawn.workSettings.WorkIsActive(FWWorkTypeDef.PelFireWarden) &&
                           !pawn.story.traits.HasTrait(TraitDefOf.Pyromaniac);
                if (!IsFW)
                {
                    result = ThinkResult.NoJob;
                }
                else
                {
                    var FWHasGear     = false;
                    var TargetGearDef = "N";
                    if (FWResearch.FireExt.IsFinished)
                    {
                        if (!FWGotFE(pawn))
                        {
                            if (pawn.story.traits.HasTrait(TraitDefOf.Brawler))
                            {
                                if (!Controller.Settings.BrawlerNotOK)
                                {
                                    TargetGearDef = FEDefName;
                                }
                                else if (!FWGotFB(pawn))
                                {
                                    TargetGearDef = FBDefName;
                                }
                                else
                                {
                                    FWHasGear = true;
                                }
                            }
                            else
                            {
                                TargetGearDef = FEDefName;
                            }
                        }
                        else
                        {
                            FWHasGear = true;
                        }
                    }
                    else if (FWResearch.FireBeater.IsFinished)
                    {
                        if (!FWGotFB(pawn))
                        {
                            TargetGearDef = FBDefName;
                        }
                        else
                        {
                            FWHasGear = true;
                        }
                    }

                    if (FWHasGear)
                    {
                        result = ThinkResult.NoJob;
                    }
                    else
                    {
                        var IsFightingFires = pawn.CurJob != null && pawn.CurJob.targetA != null &&
                                              pawn.CurJob.targetA.HasThing &&
                                              pawn.CurJob.targetA.Thing.def == ThingDefOf.Fire;
                        var IsAlreadyEquipping = pawn.CurJob != null && pawn.CurJobDef == FWEquipJobs.FWEquipping;
                        if (IsFightingFires || IsAlreadyEquipping)
                        {
                            result = ThinkResult.NoJob;
                        }
                        else
                        {
                            var IsHomeFire = false;
                            var list       = pawn.Map.listerThings.ThingsOfDef(ThingDefOf.Fire);
                            foreach (var thing in list)
                            {
                                if (!pawn.Map.areaManager.Home[thing.Position] || thing.Position.Fogged(thing.Map))
                                {
                                    continue;
                                }

                                IsHomeFire = true;
                                break;
                            }

                            if (IsHomeFire)
                            {
                                result = ThinkResult.NoJob;
                            }
                            else if (pawn.Drafted || HealthAIUtility.ShouldSeekMedicalRest(pawn) || pawn.IsBurning())
                            {
                                result = ThinkResult.NoJob;
                            }
                            else
                            {
                                var FWSearchRange = (float)Controller.Settings.SearchRange;
                                if (FWSearchRange < 25f)
                                {
                                    FWSearchRange = 25f;
                                }

                                if (FWSearchRange > 75f)
                                {
                                    FWSearchRange = 75f;
                                }

                                var FElist =
                                    pawn.Map.listerThings.ThingsOfDef(DefDatabase <ThingDef> .GetNamed(FEDefName));
                                var FBlist =
                                    pawn.Map.listerThings.ThingsOfDef(DefDatabase <ThingDef> .GetNamed(FBDefName));
                                var traverseParams = TraverseParms.For(pawn);

                                bool ValidatorFe(Thing t)
                                {
                                    return(!t.IsForbidden(pawn) && pawn.CanReserve(t) &&
                                           !FWFoamUtility.ReplaceFEFoam(t) && FWFoamUtility.HasFEFoam(t));
                                }

                                bool ValidatorFb(Thing t)
                                {
                                    return(!t.IsForbidden(pawn) && pawn.CanReserve(t));
                                }

                                Thing ThingToGrab = null;
                                if (TargetGearDef != "N")
                                {
                                    if (TargetGearDef == FEDefName)
                                    {
                                        if (!FWGotFE(pawn))
                                        {
                                            ThingToGrab = GenClosest.ClosestThing_Global_Reachable(pawn.Position,
                                                                                                   pawn.Map, FElist, PathEndMode.OnCell, traverseParams, FWSearchRange,
                                                                                                   ValidatorFe);
                                        }

                                        if (ThingToGrab == null && !FWGotFB(pawn))
                                        {
                                            ThingToGrab = GenClosest.ClosestThing_Global_Reachable(pawn.Position,
                                                                                                   pawn.Map, FBlist, PathEndMode.OnCell, traverseParams, FWSearchRange,
                                                                                                   ValidatorFb);
                                        }
                                    }
                                    else if (!FWGotFB(pawn))
                                    {
                                        ThingToGrab = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map,
                                                                                               FBlist, PathEndMode.OnCell, traverseParams, FWSearchRange, ValidatorFb);
                                    }
                                }

                                if (ThingToGrab != null &&
                                    pawn.inventory.innerContainer.CanAcceptAnyOf(ThingToGrab, false))
                                {
                                    return(new ThinkResult(new Job(FWEquipJobs.FWEquipping, ThingToGrab), this));
                                }

                                result = ThinkResult.NoJob;
                            }
                        }
                    }
                }
            }

            return(result);
        }
 public void HealthTick()
 {
     if (!this.Dead)
     {
         for (int i = this.hediffSet.hediffs.Count - 1; i >= 0; i--)
         {
             Hediff hediff = this.hediffSet.hediffs[i];
             try
             {
                 hediff.Tick();
                 hediff.PostTick();
             }
             catch (Exception ex)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Exception ticking hediff ",
                     hediff.ToStringSafe <Hediff>(),
                     " for pawn ",
                     this.pawn.ToStringSafe <Pawn>(),
                     ". Removing hediff... Exception: ",
                     ex
                 }), false);
                 try
                 {
                     this.RemoveHediff(hediff);
                 }
                 catch (Exception arg)
                 {
                     Log.Error("Error while removing hediff: " + arg, false);
                 }
             }
         }
         bool flag = false;
         for (int j = this.hediffSet.hediffs.Count - 1; j >= 0; j--)
         {
             Hediff hediff2 = this.hediffSet.hediffs[j];
             if (hediff2.ShouldRemove)
             {
                 this.hediffSet.hediffs.RemoveAt(j);
                 hediff2.PostRemoved();
                 flag = true;
             }
         }
         if (flag)
         {
             this.Notify_HediffChanged(null);
         }
         if (!this.Dead)
         {
             this.immunity.ImmunityHandlerTick();
             if (this.pawn.RaceProps.IsFlesh && this.pawn.IsHashIntervalTick(600) && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
             {
                 bool flag2 = false;
                 if (this.hediffSet.HasNaturallyHealingInjury())
                 {
                     float num = 8f;
                     if (this.pawn.GetPosture() != PawnPosture.Standing)
                     {
                         num += 4f;
                         Building_Bed building_Bed = this.pawn.CurrentBed();
                         if (building_Bed != null)
                         {
                             num += building_Bed.def.building.bed_healPerDay;
                         }
                     }
                     Hediff_Injury hediff_Injury = (from x in this.hediffSet.GetHediffs <Hediff_Injury>()
                                                    where x.CanHealNaturally()
                                                    select x).RandomElement <Hediff_Injury>();
                     hediff_Injury.Heal(num * this.pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (this.hediffSet.HasTendedAndHealingInjury() && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
                 {
                     Hediff_Injury hediff_Injury2 = (from x in this.hediffSet.GetHediffs <Hediff_Injury>()
                                                     where x.CanHealFromTending()
                                                     select x).RandomElement <Hediff_Injury>();
                     float tendQuality = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                     float num2        = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                     hediff_Injury2.Heal(22f * num2 * this.pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (flag2 && !this.HasHediffsNeedingTendByPlayer(false) && !HealthAIUtility.ShouldSeekMedicalRest(this.pawn) && !this.hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(this.pawn))
                 {
                     Messages.Message("MessageFullyHealed".Translate(new object[]
                     {
                         this.pawn.LabelCap
                     }), this.pawn, MessageTypeDefOf.PositiveEvent, true);
                 }
             }
             if (this.pawn.RaceProps.IsFlesh && this.hediffSet.BleedRateTotal >= 0.1f)
             {
                 float num3 = this.hediffSet.BleedRateTotal * this.pawn.BodySize;
                 if (this.pawn.GetPosture() == PawnPosture.Standing)
                 {
                     num3 *= 0.004f;
                 }
                 else
                 {
                     num3 *= 0.0004f;
                 }
                 if (Rand.Value < num3)
                 {
                     this.DropBloodFilth();
                 }
             }
             if (this.pawn.IsHashIntervalTick(60))
             {
                 List <HediffGiverSetDef> hediffGiverSets = this.pawn.RaceProps.hediffGiverSets;
                 if (hediffGiverSets != null)
                 {
                     for (int k = 0; k < hediffGiverSets.Count; k++)
                     {
                         List <HediffGiver> hediffGivers = hediffGiverSets[k].hediffGivers;
                         for (int l = 0; l < hediffGivers.Count; l++)
                         {
                             hediffGivers[l].OnIntervalPassed(this.pawn, null);
                             if (this.pawn.Dead)
                             {
                                 return;
                             }
                         }
                     }
                 }
                 if (this.pawn.story != null)
                 {
                     List <Trait> allTraits = this.pawn.story.traits.allTraits;
                     for (int m = 0; m < allTraits.Count; m++)
                     {
                         TraitDegreeData currentData = allTraits[m].CurrentData;
                         if (currentData.randomDiseaseMtbDays > 0f && Rand.MTBEventOccurs(currentData.randomDiseaseMtbDays, 60000f, 60f))
                         {
                             BiomeDef biome;
                             if (this.pawn.Tile != -1)
                             {
                                 biome = Find.WorldGrid[this.pawn.Tile].biome;
                             }
                             else
                             {
                                 biome = DefDatabase <BiomeDef> .GetRandom();
                             }
                             IncidentDef incidentDef = (from d in DefDatabase <IncidentDef> .AllDefs
                                                        where d.category == IncidentCategoryDefOf.DiseaseHuman
                                                        select d).RandomElementByWeightWithFallback((IncidentDef d) => biome.CommonalityOfDisease(d), null);
                             if (incidentDef != null)
                             {
                                 ((IncidentWorker_Disease)incidentDef.Worker).ApplyToPawns(Gen.YieldSingle <Pawn>(this.pawn));
                             }
                         }
                     }
                 }
             }
         }
     }
 }