// // 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; } } }
// // 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); } } }