public static bool OnIntervalPassed_Prefix(HediffGiver_RandomAgeCurved __instance, Pawn pawn, Hediff cause)
 {
     if (pawn == null)
     {
         return(true);
     }
     if (pawn.health.hediffSet.hediffs.Any(x => x.TryGetCompFast <HediffComp_RejuvTreatment>() != null))
     {
         float         increase        = 0f;
         List <Hediff> rejuvTreatments = pawn.health.hediffSet.hediffs.FindAll(x => x.TryGetCompFast <HediffComp_RejuvTreatment>() != null);
         foreach (Hediff hd in rejuvTreatments)
         {
             HediffComp_RejuvTreatment rejuvTreatment = hd.TryGetCompFast <HediffComp_RejuvTreatment>();
             increase += rejuvTreatment.LifeExpectancyIncrease;
         }
         if (increase != 0)
         {
             float x = (float)pawn.ageTracker.AgeBiologicalYears / (pawn.RaceProps.lifeExpectancy + increase);
             Rand.PushState();
             bool act = Rand.MTBEventOccurs(__instance.ageFractionMtbDaysCurve.Evaluate(x), 60000f, 60f);
             Rand.PopState();
             if (act)
             {
                 return(true);
             }
         }
     }
     return(true);
 }
示例#2
0
 public static IEnumerable <HediffGiver_Birthday> RandomHediffsToGainOnBirthday_RejuveTreatment_Postfix(IEnumerable <HediffGiver_Birthday> __result, Pawn pawn, int age)
 {
     if (__result.EnumerableNullOrEmpty())
     {
         yield break;
     }
     if (pawn != null)
     {
         if (rejuvTreatments == null)
         {
             rejuvTreatments = new List <HediffDef>();
             rejuvTreatments = DefDatabase <HediffDef> .AllDefsListForReading.FindAll(x => x.HasComp(typeof(HediffComp_RejuvTreatment)));
         }
         if (pawn.RaceProps.Humanlike && !rejuvTreatments.NullOrEmpty())
         {
             float         increase = 0f;
             List <Hediff> rejuvs   = pawn.health.hediffSet.hediffs.FindAll(x => rejuvTreatments.Contains(x.def));
             if (!rejuvs.NullOrEmpty())
             {
                 foreach (Hediff hd in rejuvs)
                 {
                     HediffComp_RejuvTreatment rejuvTreatment = hd.TryGetCompFast <HediffComp_RejuvTreatment>();
                     if (rejuvTreatment != null)
                     {
                         increase += rejuvTreatment.LifeExpectancyIncrease;
                     }
                 }
                 foreach (HediffGiver_Birthday item in RandomHediffsToGainOnBirthday(pawn.def, age, increase))
                 {
                     yield return(item);
                 }
                 yield break;
             }
         }
     }
     foreach (HediffGiver_Birthday item in __result)
     {
         yield return(item);
     }
     yield break;
 }