Example #1
0
        private static Hediff FindNonInjuryMiscBadHediff([NotNull] Pawn pawn, bool onlyIfCanKill)
        {
            Hediff        hediff  = null;
            var           num     = 1f;
            List <Hediff> hediffs = pawn.health.hediffSet.hediffs;

            foreach (Hediff h in hediffs)
            {
                if (!h.Visible || !h.def.isBad || !h.def.everCurableByItem || h is Hediff_Injury || h is Hediff_MissingPart || h is Hediff_Addiction ||
                    h is Hediff_AddedPart || (onlyIfCanKill && !CanEverKill(h)) || !CompatRegistry.IsHealable(h))
                {
                    continue;
                }

                if (h.def == HediffDefOf.BloodLoss || h.def == HediffDefOf.Malnutrition)
                {
                    continue;
                }

                float coverage = h.Part?.coverageAbsWithChildren ?? 999f;

                if (hediff != null && coverage <= num)
                {
                    continue;
                }

                hediff = h;
                num    = coverage;
            }

            return(hediff);
        }
Example #2
0
        private static Hediff FindMostBleedingHediff([NotNull] Pawn pawn)
        {
            var           num     = 0f;
            Hediff        hediff  = null;
            List <Hediff> hediffs = pawn.health.hediffSet.hediffs;

            foreach (Hediff h in hediffs)
            {
                if (!h.Visible || !h.def.everCurableByItem || !CompatRegistry.IsHealable(h))
                {
                    continue;
                }

                float bleedRate = h.BleedRate;

                if (bleedRate <= 0f || (bleedRate <= num && hediff != null))
                {
                    continue;
                }

                num    = bleedRate;
                hediff = h;
            }

            return(hediff);
        }
Example #3
0
        private static Hediff FindLifeThreateningHediff([NotNull] Pawn pawn)
        {
            Hediff        hediff  = null;
            float         num     = -1f;
            List <Hediff> hediffs = pawn.health.hediffSet.hediffs;

            foreach (Hediff h in hediffs)
            {
                if (!h.Visible || !h.def.everCurableByItem || h.FullyImmune() || !CompatRegistry.IsHealable(h))
                {
                    continue;
                }

                bool lifeThreatening = h.CurStage?.lifeThreatening ?? false;
                bool lethal          = h.def.lethalSeverity >= 0f && h.Severity / h.def.lethalSeverity >= 0.8f;

                if (!lifeThreatening && !lethal)
                {
                    continue;
                }

                float coverage = h.Part?.coverageAbsWithChildren ?? 999f;

                if (hediff != null && coverage <= num)
                {
                    continue;
                }

                hediff = h;
                num    = coverage;
            }

            return(hediff);
        }
Example #4
0
        private static Hediff FindImmunizableHediffWhichCanKill([NotNull] Pawn pawn)
        {
            Hediff        hediff  = null;
            float         num     = -1f;
            List <Hediff> hediffs = pawn.health.hediffSet.hediffs;

            foreach (Hediff h in hediffs)
            {
                if (!h.Visible || !h.def.everCurableByItem || h.TryGetComp <HediffComp_Immunizable>() == null || h.FullyImmune() || !CanEverKill(h) ||
                    !CompatRegistry.IsHealable(h))
                {
                    continue;
                }

                float severity = h.Severity;

                if (hediff != null && severity <= num)
                {
                    continue;
                }

                hediff = h;
                num    = severity;
            }

            return(hediff);
        }
Example #5
0
        private static Hediff_Addiction FindAddiction([NotNull] Pawn pawn)
        {
            List <Hediff> hediffs = pawn.health.hediffSet.hediffs;

            foreach (Hediff hediff in hediffs)
            {
                if (hediff is Hediff_Addiction {
                    Visible: true
                } a&& a.def.everCurableByItem && CompatRegistry.IsHealable(hediff))
                {
                    return(a);
                }
            }

            return(null);
        }
Example #6
0
        private static Hediff_Injury FindInjury([NotNull] Pawn pawn, [CanBeNull] IReadOnlyCollection <BodyPartRecord> allowedBodyParts = null)
        {
            Hediff_Injury injury  = null;
            List <Hediff> hediffs = pawn.health.hediffSet.hediffs;

            foreach (Hediff h in hediffs)
            {
                if (h is Hediff_Injury {
                    Visible: true
                } h2&& h2.def.everCurableByItem && (allowedBodyParts == null || allowedBodyParts.Contains(h2.Part)) &&
                    (injury == null || h2.Severity > injury.Severity) && CompatRegistry.IsHealable(h))
                {
                    injury = h2;
                }
            }

            return(injury);
        }
Example #7
0
        private static BodyPartRecord FindBiggestMissingBodyPart([NotNull] Pawn pawn, float minCoverage = 0f)
        {
            BodyPartRecord record = null;

            foreach (Hediff_MissingPart missing in pawn.health.hediffSet.GetMissingPartsCommonAncestors())
            {
                if (missing.Part.coverageAbsWithChildren >= minCoverage && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(missing.Part) &&
                    (record == null || missing.Part.coverageAbsWithChildren > record.coverageAbsWithChildren) && CompatRegistry.IsHealable(missing))
                {
                    record = missing.Part;
                }
            }

            return(record);
        }