//
        // Static Methods
        //
        public static void GenerateRandomOldAgeInjuries(Pawn pawn, bool tryNotToKillPawn)
        {
            int num = 0;

            for (int i = 10; i < Mathf.Min(pawn.ageTracker.AgeBiologicalYears, 120); i += 10)
            {
                if (Rand.Value < 0.15f)
                {
                    num++;
                }
            }
            for (int j = 0; j < num; j++)
            {
                IEnumerable <BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined)
                                                      where x.depth == BodyPartDepth.Outside && !Mathf.Approximately(x.def.oldInjuryBaseChance, 0f) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(x)
                                                      select x;
                if (source.Any <BodyPartRecord>())
                {
                    BodyPartRecord bodyPartRecord      = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs);
                    DamageDef      dam                 = AgeInjuryUtility.RandomOldInjuryDamageType(bodyPartRecord.def.frostbiteVulnerability > 0f && pawn.RaceProps.ToolUser);
                    HediffDef      hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dam, pawn, bodyPartRecord);
                    if (bodyPartRecord.def.oldInjuryBaseChance > 0f && hediffDefFromDamage.CompPropsFor(typeof(HediffComp_GetsOld)) != null)
                    {
                        if (Rand.Chance(bodyPartRecord.def.amputateIfGeneratedInjuredChance))
                        {
                            Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, pawn, null);
                            hediff_MissingPart.lastInjury = hediffDefFromDamage;
                            hediff_MissingPart.TryGetComp <HediffComp_GetsOld>().IsOld = true;
                            pawn.health.AddHediff(hediff_MissingPart, bodyPartRecord, null);
                            if (pawn.RaceProps.Humanlike && (bodyPartRecord.def == BodyPartDefOf.LeftLeg || bodyPartRecord.def == BodyPartDefOf.RightLeg) && Rand.Chance(0.5f))
                            {
                                RecipeDefOf.InstallPegLeg.Worker.ApplyOnPawn(pawn, bodyPartRecord, null, AgeInjuryUtility.emptyIngredientsList, null);
                            }
                        }
                        else
                        {
                            Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null);
                            hediff_Injury.Severity = (float)Rand.RangeInclusive(2, 6);
                            hediff_Injury.TryGetComp <HediffComp_GetsOld>().IsOld = true;
                            pawn.health.AddHediff(hediff_Injury, bodyPartRecord, null);
                        }
                    }
                }
            }
            for (int k = 1; k < pawn.ageTracker.AgeBiologicalYears; k++)
            {
                foreach (HediffGiver_Birthday current in AgeInjuryUtility.RandomHediffsToGainOnBirthday(pawn, k))
                {
                    current.TryApplyAndSimulateSeverityChange(pawn, (float)k, tryNotToKillPawn);
                    if (pawn.Dead)
                    {
                        break;
                    }
                }
                if (pawn.Dead)
                {
                    break;
                }
            }
        }
Esempio n. 2
0
        // Token: 0x06004B87 RID: 19335 RVA: 0x00234638 File Offset: 0x00232A38
        private void ApplyDamageToPart(DamageInfo dinfo, Pawn pawn, DamageWorker.DamageResult result)
        {
            BodyPartRecord exactPartFromDamageInfo = this.GetExactPartFromDamageInfo(dinfo, pawn);

            if (exactPartFromDamageInfo == null)
            {
                return;
            }
            dinfo.SetHitPart(exactPartFromDamageInfo);
            float num  = dinfo.Amount;
            bool  flag = !dinfo.InstantPermanentInjury;
            bool  deflectedByMetalArmor = false;

            if (flag)
            {
                DamageDef def = dinfo.Def;
                num       = ArmorUtility.GetPostArmorDamage(pawn, num, dinfo.ArmorPenetrationInt, dinfo.HitPart, ref def, out deflectedByMetalArmor, out bool diminishedByMetalArmor);
                dinfo.Def = def;
                if (num < dinfo.Amount)
                {
                    result.diminished             = true;
                    result.diminishedByMetalArmor = diminishedByMetalArmor;
                }
            }
            if (num <= 0f)
            {
                result.AddPart(pawn, dinfo.HitPart);
                result.deflected             = true;
                result.deflectedByMetalArmor = deflectedByMetalArmor;
                return;
            }
            if (DamageWorker_CombiPin.IsHeadshot(dinfo, pawn))
            {
                result.headshot = true;
            }
            if (dinfo.InstantPermanentInjury)
            {
                HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, dinfo.HitPart);
                if (hediffDefFromDamage.CompPropsFor(typeof(HediffComp_GetsPermanent)) == null || dinfo.HitPart.def.permanentInjuryChanceFactor == 0f || pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(dinfo.HitPart))
                {
                    return;
                }
            }
            if (!dinfo.AllowDamagePropagation)
            {
                this.FinalizeAndAddInjury(pawn, num, dinfo, result);
                return;
            }
            this.ApplySpecialEffectsToPart(pawn, num, dinfo, result);
        }
Esempio n. 3
0
        public static IEnumerable <StatDrawEntry> DrugAddictionStats(CompProperties_Drug comp, StatRequest req, int displayOffset = 0)
        {
            ThingDef thingDef = (ThingDef)req.Def;
            var      category = DefDatabase <StatCategoryDef> .GetNamed("DrugAddiction");

            HediffDef addictionHediff = comp.chemical?.addictionHediff;
            NeedDef   addictionNeed   = addictionHediff?.causesNeed;
            HediffCompProperties_SeverityPerDay addictionSeverityComp =
                (HediffCompProperties_SeverityPerDay)addictionHediff?.CompPropsFor(typeof(HediffComp_SeverityPerDay))
            ;

            // Addictiveness
            yield return(new StatDrawEntry(
                             category:    category,
                             label:       "Addictiveness".Translate(),
                             reportText:  "Stat_Thing_Drug_Addictiveness_Desc".Translate(),
                             valueString: comp.addictiveness.ToStringPercent(),
                             displayPriorityWithinCategory: displayOffset + 99
                             ));

            if (addictionSeverityComp != null)
            {
                // Addiction decay per day
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_AddictionDecay_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_AddictionDecay_Desc".Translate(),
                                 valueString: addictionSeverityComp.severityPerDay.ToStringPercent(),
                                 displayPriorityWithinCategory: displayOffset + 98
                                 ));

                // Time to shake addiction
                float daysToShakeAddiction = addictionHediff.initialSeverity / addictionSeverityComp.severityPerDay * -1;
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_TimeToShakeAddiction_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_TimeToShakeAddiction_Desc".Translate(),
                                 valueString: ToStringDaysToPeriod(daysToShakeAddiction),
                                 displayPriorityWithinCategory: displayOffset + 98
                                 ));
            }

            if (addictionHediff != null)
            {
                yield return(FindHediffRisks(addictionHediff, "AddictionRisks", category, displayOffset));
            }
        }
        //
        // Static Methods
        //
        public static void GenerateRandomOldAgeInjuries(Pawn pawn, bool tryNotToKillPawn)
        {
            int num = 0;

            for (int i = 10; i < pawn.ageTracker.AgeBiologicalYears; i += 10)
            {
                if (Rand.Value < 0.15)
                {
                    num++;
                }
            }
            for (int j = 0; j < num; j++)
            {
                DamageDef dam  = AgeInjuryUtility.RandomOldInjuryDamageType();
                int       num2 = Rand.RangeInclusive(2, 6);
                IEnumerable <BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined)
                                                      where x.depth == BodyPartDepth.Outside && !Mathf.Approximately(x.def.oldInjuryBaseChance, 0) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(x)
                                                      select x;
                if (source.Any <BodyPartRecord>())
                {
                    BodyPartRecord bodyPartRecord      = source.RandomElementByWeight((BodyPartRecord x) => x.absoluteFleshCoverage);
                    HediffDef      hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dam, pawn, bodyPartRecord);
                    if (bodyPartRecord.def.oldInjuryBaseChance > 0 && hediffDefFromDamage.CompPropsFor(typeof(HediffComp_GetsOld)) != null)
                    {
                        Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null);
                        hediff_Injury.Severity = (float)num2;
                        hediff_Injury.TryGetComp <HediffComp_GetsOld>().IsOld = true;
                        pawn.health.AddHediff(hediff_Injury, bodyPartRecord, null);
                    }
                }
            }
            for (int k = 1; k < pawn.ageTracker.AgeBiologicalYears; k++)
            {
                foreach (HediffGiver_Birthday current in AgeInjuryUtility.RandomHediffsToGainOnBirthday(pawn, k))
                {
                    current.TryApplyAndSimulateSeverityChange(pawn, (float)k, tryNotToKillPawn);
                }
            }
        }
Esempio n. 5
0
        public static IEnumerable <StatDrawEntry> DrugToleranceStats(CompProperties_Drug comp, StatRequest req, int displayOffset = 0)
        {
            ThingDef thingDef = (ThingDef)req.Def;
            var      category = DefDatabase <StatCategoryDef> .GetNamed("DrugTolerance");

            HediffDef toleranceHediff = comp.chemical?.toleranceHediff;
            IngestionOutcomeDoer_GiveHediff     toleranceOutcomeDoer  = null;
            HediffCompProperties_SeverityPerDay toleranceSeverityComp = null;

            if (toleranceHediff != null)
            {
                toleranceOutcomeDoer = (IngestionOutcomeDoer_GiveHediff)thingDef.ingestible.outcomeDoers.FirstOrFallback(
                    iod => iod is IngestionOutcomeDoer_GiveHediff iod_gh &&
                    iod_gh.hediffDef != null && iod_gh.hediffDef == toleranceHediff
                    );
                toleranceSeverityComp = (HediffCompProperties_SeverityPerDay)toleranceHediff.CompPropsFor(typeof(HediffComp_SeverityPerDay));

                yield return(FindHediffRisks(toleranceHediff, "ToleranceRisks", category, displayOffset));
            }

            if (toleranceOutcomeDoer != null)
            {
                // Tolerance for using
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_ToleranceForUsing_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_ToleranceForUsing_Desc".Translate(),
                                 valueString: toleranceOutcomeDoer.severity.ToStringPercent(),
                                 displayPriorityWithinCategory: displayOffset + 98
                                 ));

                // [Reflection] toleranceOutcomeDoer.divideByBodySize
                FieldInfo divideByBodySizeField = AccessTools.Field(typeof(IngestionOutcomeDoer_GiveHediff), "divideByBodySize");
                bool      divideByBodySize      = (bool)divideByBodySizeField.GetValue(toleranceOutcomeDoer);

                // Severity affected by body size
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_SeverityUsesBodySize_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_SeverityUsesBodySize_Desc".Translate(),
                                 valueString: divideByBodySize.ToStringYesNo(),
                                 displayPriorityWithinCategory: displayOffset + 97
                                 ));
            }

            // Minimum tolerance to addict
            yield return(new StatDrawEntry(
                             category:    category,
                             label:       "Stat_Thing_Drug_MinToleranceToAddict_Name".Translate(),
                             reportText:  "Stat_Thing_Drug_MinToleranceToAddict_Desc".Translate(),
                             valueString: comp.minToleranceToAddict.ToStringPercent(),
                             displayPriorityWithinCategory: displayOffset + 96
                             ));

            if (comp.minToleranceToAddict == 0f)
            {
                drugNotSafe = true;
            }

            // Tolerance decay per day
            if (toleranceSeverityComp != null)
            {
                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_ToleranceDecay_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_ToleranceDecay_Desc".Translate(),
                                 valueString: toleranceSeverityComp.severityPerDay.ToStringPercent(),
                                 displayPriorityWithinCategory: displayOffset + 95
                                 ));
            }

            // Doses before addiction
            if (toleranceOutcomeDoer != null)
            {
                float dosesBeforeAddiction = comp.minToleranceToAddict / toleranceOutcomeDoer.severity;
                if (dosesBeforeAddiction <= 1f)
                {
                    dosesBeforeAddiction = 0;                              // cannot take partial doses
                }
                drugNotSafe = drugNotSafe != null ?
                              ((bool)drugNotSafe || dosesBeforeAddiction == 0f) :
                              dosesBeforeAddiction == 0f
                ;

                yield return(new StatDrawEntry(
                                 category:    category,
                                 label:       "Stat_Thing_Drug_DosagesBeforeAddiction_Name".Translate(),
                                 reportText:  "Stat_Thing_Drug_DosagesBeforeAddiction_Desc".Translate(),
                                 valueString: dosesBeforeAddiction.ToStringDecimalIfSmall(),
                                 displayPriorityWithinCategory: displayOffset + 94
                                 ));

                if (toleranceSeverityComp != null)
                {
                    daysPerSafeDoseAddiction = toleranceOutcomeDoer.severity / toleranceSeverityComp.severityPerDay * -1;
                }
            }
        }