public static bool CacheMissingPartsCommonAncestors(HediffSet __instance) { if (__instance.cachedMissingPartsCommonAncestors == null) { __instance.cachedMissingPartsCommonAncestors = new List <Hediff_MissingPart>(); } else { __instance.cachedMissingPartsCommonAncestors.Clear(); } missingPartsCommonAncestorsQueue.Clear(); missingPartsCommonAncestorsQueue.Enqueue(__instance.pawn.def.race.body.corePart); while (missingPartsCommonAncestorsQueue.Count != 0) { BodyPartRecord node = missingPartsCommonAncestorsQueue.Dequeue(); if (!__instance.PartOrAnyAncestorHasDirectlyAddedParts(node)) { Hediff_MissingPart hediffMissingPart = __instance.GetHediffs <Hediff_MissingPart>().Where <Hediff_MissingPart>((Func <Hediff_MissingPart, bool>)(x => x.Part == node)).FirstOrDefault <Hediff_MissingPart>(); if (hediffMissingPart != null) { __instance.cachedMissingPartsCommonAncestors.Add(hediffMissingPart); } else { for (int index = 0; index < node.parts.Count; ++index) { missingPartsCommonAncestorsQueue.Enqueue(node.parts[index]); } } } } return(false); }
public static bool PartShouldBeIgnored(this HediffSet set, BodyPartRecord bodyPart) { if (bodyPart != null && bodyPart.parent != null) { var modExt = set.GetHediffs <Hediff_AddedPart>() .FirstOrDefault(h => h.Part == bodyPart.parent)? // added part on parent bodypartrecord .def.GetModExtension <IgnoreSubParts>(); return ((modExt != null && modExt.ignoredSubParts.Contains(bodyPart.def)) || set.PartShouldBeIgnored(bodyPart.parent)); } return(false); }
public static bool CacheMissingPartsCommonAncestors(HediffSet __instance) { if (cachedMissingPartsCommonAncestors(__instance) == null) { cachedMissingPartsCommonAncestors(__instance) = new List <Hediff_MissingPart>(); } lock (cachedMissingPartsCommonAncestors(__instance)) { cachedMissingPartsCommonAncestors(__instance).Clear(); missingPartsCommonAncestorsQueue(__instance).Clear(); missingPartsCommonAncestorsQueue(__instance).Enqueue(__instance.pawn.def.race.body.corePart); while (missingPartsCommonAncestorsQueue(__instance).Count != 0) { BodyPartRecord node = missingPartsCommonAncestorsQueue(__instance).Dequeue(); if (node != null) { if (__instance.PartOrAnyAncestorHasDirectlyAddedParts(node)) { continue; } Hediff_MissingPart hediff_MissingPart = (from x in __instance.GetHediffs <Hediff_MissingPart>() where x.Part == node select x).FirstOrDefault(); if (hediff_MissingPart != null) { cachedMissingPartsCommonAncestors(__instance).Add(hediff_MissingPart); continue; } for (int i = 0; i < node.parts.Count; i++) { lock (missingPartsCommonAncestorsQueue(__instance)) { missingPartsCommonAncestorsQueue(__instance).Enqueue(node.parts[i]); } } } } } 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); }