public static float CalculatePartEfficiency(HediffSet diffSet, BodyPartRecord part, bool ignoreAddedParts = false, List <PawnCapacityUtility.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 <Hediff_AddedPart>(); if (impactors != null) { impactors.Add(new PawnCapacityUtility.CapacityImpactorHediff { hediff = hediff_AddedPart }); } return(hediff_AddedPart.def.addedPartProps.partEfficiency); } } if (part.parent != null && diffSet.PartIsMissing(part.parent)) { return(0f); } 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 != null) { impactors.Add(new PawnCapacityUtility.CapacityImpactorHediff { hediff = hediff_AddedPart2 }); } } } } float b = -1f; float num2 = 0f; bool flag = false; for (int j = 0; j < diffSet.hediffs.Count; j++) { if (diffSet.hediffs[j].Part == part && diffSet.hediffs[j].CurStage != null) { HediffStage curStage = diffSet.hediffs[j].CurStage; num2 += curStage.partEfficiencyOffset; flag |= curStage.partIgnoreMissingHP; if (curStage.partEfficiencyOffset != 0f && curStage.becomeVisible && impactors != null) { impactors.Add(new PawnCapacityUtility.CapacityImpactorHediff { hediff = diffSet.hediffs[j] }); } } } 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); } if (impactors != null) { impactors.Add(new PawnCapacityUtility.CapacityImpactorBodyPartHealth { bodyPart = part }); } num *= num3; } } num += num2; if (num > 0.0001f) { num = Mathf.Max(num, b); } return(Mathf.Max(num, 0f)); }
public static IEnumerable <StatDrawEntry> SpecialDisplayStats(HediffStage stage, Hediff instance) { if (instance != null && instance.Bleeding) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "BleedingRate".Translate(), instance.BleedRate.ToStringPercent() + "/" + "LetterDay".Translate(), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } float painOffsetToDisplay = 0f; if (instance != null) { painOffsetToDisplay = instance.PainOffset; } else if (stage != null) { painOffsetToDisplay = stage.painOffset; } if (painOffsetToDisplay != 0f) { if (painOffsetToDisplay > 0f && painOffsetToDisplay < 0.01f) { painOffsetToDisplay = 0.01f; } if (painOffsetToDisplay < 0f && painOffsetToDisplay > -0.01f) { painOffsetToDisplay = -0.01f; } yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "Pain".Translate(), (painOffsetToDisplay * 100f).ToString("+###0;-###0") + "%", 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } float painFactorToDisplay = 1f; if (instance != null) { painFactorToDisplay = instance.PainFactor; } else if (stage != null) { painFactorToDisplay = stage.painFactor; } if (painFactorToDisplay != 1f) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "Pain".Translate(), "x" + painFactorToDisplay.ToStringPercent(), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } if (stage != null && stage.partEfficiencyOffset != 0f) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "PartEfficiency".Translate(), stage.partEfficiencyOffset.ToStringByStyle(ToStringStyle.PercentZero, ToStringNumberSense.Offset), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } List <PawnCapacityModifier> capModsToDisplay = null; if (instance != null) { capModsToDisplay = instance.CapMods; } else if (stage != null) { capModsToDisplay = stage.capMods; } if (capModsToDisplay != null) { for (int j = 0; j < capModsToDisplay.Count; j++) { if (capModsToDisplay[j].offset != 0f) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, capModsToDisplay[j].capacity.GetLabelFor(isFlesh: true, isHumanlike: true).CapitalizeFirst(), (capModsToDisplay[j].offset * 100f).ToString("+#;-#") + "%", 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } if (capModsToDisplay[j].postFactor != 1f) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, capModsToDisplay[j].capacity.GetLabelFor(isFlesh: true, isHumanlike: true).CapitalizeFirst(), "x" + capModsToDisplay[j].postFactor.ToStringPercent(), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } if (capModsToDisplay[j].SetMaxDefined) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, capModsToDisplay[j].capacity.GetLabelFor(isFlesh: true, isHumanlike: true).CapitalizeFirst(), "max".Translate() + " " + capModsToDisplay[j].setMax.ToStringPercent(), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } } } if (stage != null) { if (stage.AffectsMemory || stage.AffectsSocialInteractions) { StringBuilder affectsSb = new StringBuilder(); if (stage.AffectsMemory) { if (affectsSb.Length != 0) { affectsSb.Append(", "); } affectsSb.Append("MemoryLower".Translate()); } if (stage.AffectsSocialInteractions) { if (affectsSb.Length != 0) { affectsSb.Append(", "); } affectsSb.Append("SocialInteractionsLower".Translate()); } yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "Affects".Translate(), affectsSb.ToString(), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } if (stage.hungerRateFactor != 1f) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "HungerRate".Translate(), "x" + stage.hungerRateFactor.ToStringPercent(), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } if (stage.hungerRateFactorOffset != 0f) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "HungerRate".Translate(), stage.hungerRateFactorOffset.ToStringSign() + stage.hungerRateFactorOffset.ToStringPercent(), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } if (stage.restFallFactor != 1f) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "Tiredness".Translate(), "x" + stage.restFallFactor.ToStringPercent(), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } if (stage.restFallFactorOffset != 0f) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "Tiredness".Translate(), stage.restFallFactorOffset.ToStringSign() + stage.restFallFactorOffset.ToStringPercent(), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } if (stage.makeImmuneTo != null) { yield return(new StatDrawEntry(StatCategoryDefOf.Basics, "PreventsInfection".Translate(), (from im in stage.makeImmuneTo select im.label).ToCommaList().CapitalizeFirst(), 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } if (stage.statOffsets != null) { int i = 0; if (i < stage.statOffsets.Count) { StatModifier sm = stage.statOffsets[i]; yield return(new StatDrawEntry(StatCategoryDefOf.Basics, sm.stat.LabelCap, sm.ValueToStringAsOffset, 0, string.Empty)); /*Error: Unable to find new state assignment for yield return*/; } } } }