public static void Postfix(Thing __instance, Pawn ingester) { float sugarValue = __instance.def.statBases.GetStatValueFromList(StatDefOf.Nutrition, 0f) * randomFactor.RandomInRange; HealHypoglycaemia(ref sugarValue, ingester.health.hediffSet.GetFirstHediffOfDef(TypeGetter.HediffDef(EHediffDef.Hypoglycaemia))); if (!ingester.health.hediffSet.HasHediff(TypeGetter.HediffDef(EHediffDef.Diabetes))) { return; } if (sugarValue <= 0f) { return; } HediffDef hediffDef = TypeGetter.HediffDef(EHediffDef.Hyperglycaemia); Hediff hediff = ingester.health.hediffSet.GetFirstHediffOfDef(hediffDef); if (hediff == null) { hediff = HediffMaker.MakeHediff(hediffDef, ingester); ingester.health.AddHediff(hediff); } hediff.Severity += sugarValue; }
private int GetTotalDiabetics(Map map) { int total = 0; foreach (Pawn pawn in map.mapPawns.FreeColonistsAndPrisoners) { if (pawn.health.hediffSet.HasHediff(TypeGetter.HediffDef(EHediffDef.Diabetes))) { total++; } } return(total); }
public override float GetPriority(Pawn pawn) { if (!DiabetesUtility.HasIrregularBloodSugar(pawn)) { return 0f; } Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(TypeGetter.HediffDef(EHediffDef.Hypoglycaemia)); if (hediff == null) { hediff = pawn.health.hediffSet.GetFirstHediffOfDef(TypeGetter.HediffDef(EHediffDef.Hyperglycaemia)); } if (!hediff.CurStage.becomeVisible) { return 0f; } return Mathf.Lerp(1.0f, 10f, hediff.Severity / 0.8f); }
protected override Job TryGiveJob(Pawn pawn) { if (!DiabetesUtility.HasIrregularBloodSugar(pawn)) { return(null); } Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(TypeGetter.HediffDef(EHediffDef.Hypoglycaemia)); Thing thing; float value; JobDef jobDef; if (hediff == null) { hediff = pawn.health.hediffSet.GetFirstHediffOfDef(TypeGetter.HediffDef(EHediffDef.Hyperglycaemia)); thing = DiabetesUtility.FindNextInsulin(pawn); value = DiabetesUtility.InsulinValue; jobDef = TypeGetter.JobDef(EJobDef.LowerBloodSugar); } else { ThingDef thingDef; FoodUtility.TryFindBestFoodSourceFor(pawn, pawn, true, out thing, out thingDef); if (thing.def != thingDef) { return(null); } value = thingDef.ingestible.CachedNutrition * Nutrition_Patch.randomFactor.Average; jobDef = JobDefOf.Ingest; } if (!hediff.CurStage.becomeVisible) { return(null); } if (thing == null) { return(null); } Job job = JobMaker.MakeJob(jobDef); job.targetA = thing; job.count = DiabetesUtility.NumToIngest(thing, hediff, value); return(job); }
public override void CompPostTick(ref float severityAdjustment) { Hediff insulinHigh = Pawn.health.hediffSet.GetFirstHediffOfDef(TypeGetter.HediffDef(EHediffDef.InsulinHigh)); base.CompPostTick(ref severityAdjustment); severityAdjustment = Math.Max(severityAdjustment, -insulinHigh.Severity); if (severityAdjustment == 0f) { return; } Hediff hediff = this.Pawn.health.hediffSet.GetFirstHediffOfDef(TypeGetter.HediffDef(EHediffDef.Hyperglycaemia)); if (hediff == null) { hediff = this.Pawn.health.hediffSet.GetFirstHediffOfDef(TypeGetter.HediffDef(EHediffDef.Hypoglycaemia)); if (hediff == null) { hediff = HediffMaker.MakeHediff(TypeGetter.HediffDef(EHediffDef.Hypoglycaemia), this.Pawn); this.Pawn.health.AddHediff(hediff); } hediff.Severity += Mathf.Abs(severityAdjustment); } else { if (!Pawn.health.hediffSet.HasHediff(TypeGetter.HediffDef(EHediffDef.Diabetes))) { return; } if (hediff.Severity >= Mathf.Abs(severityAdjustment)) { hediff.Severity += severityAdjustment; } else { Hediff newHediff = HediffMaker.MakeHediff(TypeGetter.HediffDef(EHediffDef.Hypoglycaemia), this.Pawn); newHediff.Severity = Mathf.Abs(severityAdjustment) - hediff.Severity; hediff.Severity = 0f; this.Pawn.health.AddHediff(newHediff); } } }
public static bool HasIrregularBloodSugar(Pawn pawn) { HediffSet set = pawn.health.hediffSet; if (set.HasHediff(TypeGetter.HediffDef(EHediffDef.Hypoglycaemia))) { return(true); } if (set.HasHediff(TypeGetter.HediffDef(EHediffDef.Hyperglycaemia))) { if (set.HasHediff(TypeGetter.HediffDef(EHediffDef.InsulinHigh))) { return(false); } if (set.HasHediff(TypeGetter.HediffDef(EHediffDef.AdvancedInsulinPump))) { return(false); } return(true); } return(false); }