public bool CompatibleWithPart(BodyPartRecord part, HediffSet hediffSet) { return((this.whitelist == null || (from h in hediffSet.hediffs // no white list or there is a whitelisted hediff where h.Part == part where this.whitelist.Contains(h.def) select h).Any()) && !(this.whitelist == null && onlyOnNatural && hediffSet.HasDirectlyAddedPartFor(part))); }
public static bool AddDirect(HediffSet __instance, Hediff hediff, DamageInfo?dinfo = null, DamageWorker.DamageResult damageResult = null) { if (hediff.def == null) { Log.Error("Tried to add health diff with null def. Canceling."); return(false); } if (hediff.Part != null && !__instance.GetNotMissingParts().Contains(hediff.Part)) { Log.Error("Tried to add health diff to missing part " + hediff.Part); return(false); } hediff.ageTicks = 0; hediff.pawn = __instance.pawn; bool flag = false; for (int i = 0; i < __instance.hediffs.Count; i++) { if (__instance.hediffs[i].TryMergeWith(hediff)) { flag = true; } } if (!flag) { lock (__instance) { //List<Hediff> newHediffs = new List<Hediff>(__instance.hediffs) { hediff }; //__instance.hediffs = newHediffs; __instance.hediffs.Add(hediff); } hediff.PostAdd(dinfo); if (__instance.pawn.needs != null && __instance.pawn.needs.mood != null) { __instance.pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty(); } } bool flag2 = hediff is Hediff_MissingPart; if (!(hediff is Hediff_MissingPart) && hediff.Part != null && hediff.Part != __instance.pawn.RaceProps.body.corePart && __instance.GetPartHealth(hediff.Part) == 0f && hediff.Part != __instance.pawn.RaceProps.body.corePart) { bool flag3 = __instance.HasDirectlyAddedPartFor(hediff.Part); Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, __instance.pawn); hediff_MissingPart.IsFresh = !flag3; hediff_MissingPart.lastInjury = hediff.def; __instance.pawn.health.AddHediff(hediff_MissingPart, hediff.Part, dinfo); damageResult?.AddHediff(hediff_MissingPart); if (flag3) { if (dinfo.HasValue) { hediff_MissingPart.lastInjury = HealthUtility.GetHediffDefFromDamage(dinfo.Value.Def, __instance.pawn, hediff.Part); } else { hediff_MissingPart.lastInjury = null; } } flag2 = true; } __instance.DirtyCache(); if (flag2 && __instance.pawn.apparel != null) { __instance.pawn.apparel.Notify_LostBodyPart(); } if (hediff.def.causesNeed != null && !__instance.pawn.Dead) { __instance.pawn.needs.AddOrRemoveNeedsAsAppropriate(); } return(false); }
public static bool CalculatePartEfficiency(ref float __result, HediffSet diffSet, BodyPartRecord part, bool ignoreAddedParts = false, List <CapacityImpactor> impactors = null) { BodyPartRecord rec; for (rec = part.parent; rec != null; rec = rec.parent) { if (diffSet.HasDirectlyAddedPartFor(rec)) { Hediff_AddedPart hediff_AddedPart = (from x in diffSet.GetHediffs <Hediff_AddedPart>() where x.Part == rec select x).First(); impactors?.Add(new CapacityImpactorHediff { hediff = hediff_AddedPart }); __result = hediff_AddedPart.def.addedPartProps.partEfficiency; return(false); } } if (part.parent != null && diffSet.PartIsMissing(part.parent)) { __result = 0f; return(false); } float num = 1f; if (!ignoreAddedParts) { for (int i = 0; i < diffSet.hediffs.Count; i++) { Hediff_AddedPart hediff_AddedPart2 = diffSet.hediffs[i] as Hediff_AddedPart; if (hediff_AddedPart2 != null && hediff_AddedPart2.Part == part) { num *= hediff_AddedPart2.def.addedPartProps.partEfficiency; if (hediff_AddedPart2.def.addedPartProps.partEfficiency != 1f) { impactors?.Add(new CapacityImpactorHediff { hediff = hediff_AddedPart2 }); } } } } float b = -1f; float num2 = 0f; bool flag = false; for (int j = 0; j < diffSet.hediffs.Count; j++) { Hediff hediff1 = diffSet.hediffs[j]; if (hediff1 != null && hediff1.Part == part && hediff1.CurStage != null) { HediffStage curStage = hediff1.CurStage; num2 += curStage.partEfficiencyOffset; flag |= curStage.partIgnoreMissingHP; if (curStage.partEfficiencyOffset != 0f && curStage.becomeVisible) { impactors?.Add(new CapacityImpactorHediff { hediff = hediff1 }); } } } if (!flag) { float num3 = diffSet.GetPartHealth(part) / part.def.GetMaxHealth(diffSet.pawn); if (num3 != 1f) { if (DamageWorker_AddInjury.ShouldReduceDamageToPreservePart(part)) { num3 = Mathf.InverseLerp(0.1f, 1f, num3); } impactors?.Add(new CapacityImpactorBodyPartHealth { bodyPart = part }); num *= num3; } } num += num2; if (num > 0.0001f) { num = Mathf.Max(num, b); } __result = Mathf.Max(num, 0f); return(false); }