public static float CalculateLimbEfficiency(HediffSet diffSet, BodyPartTagDef limbCoreTag, BodyPartTagDef limbSegmentTag, BodyPartTagDef limbDigitTag, float appendageWeight, out float functionalPercentage, List <CapacityImpactor> impactors) { BodyDef body = diffSet.pawn.RaceProps.body; float totalEfficiency = 0f; int partCount = 0; int functionalPartCount = 0; foreach (BodyPartRecord item in body.GetPartsWithTag(limbCoreTag)) { float partEfficiency = CalculateImmediatePartEfficiencyAndRecord(diffSet, item, impactors); foreach (BodyPartRecord connectedPart in item.GetConnectedParts(limbSegmentTag)) { partEfficiency *= CalculateImmediatePartEfficiencyAndRecord(diffSet, connectedPart, impactors); } if (item.HasChildParts(limbDigitTag)) { partEfficiency = Mathf.Lerp(partEfficiency, partEfficiency * item.GetChildParts(limbDigitTag).Average((BodyPartRecord digitPart) => CalculateImmediatePartEfficiencyAndRecord(diffSet, digitPart, impactors)), appendageWeight); } totalEfficiency += partEfficiency; partCount++; if (partEfficiency > 0f) { functionalPartCount++; } } if (partCount == 0) { functionalPercentage = 0f; return(0f); } functionalPercentage = (float)functionalPartCount / (float)partCount; return(totalEfficiency / (float)partCount); }
public static void DamageUntilDead(Pawn p) { HediffSet hediffSet = p.health.hediffSet; int num = 0; while (!p.Dead && num < 200 && HealthUtility.HittablePartsViolence(hediffSet).Any <BodyPartRecord>()) { num++; BodyPartRecord bodyPartRecord = HealthUtility.HittablePartsViolence(hediffSet).RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); int num2 = Rand.RangeInclusive(8, 25); DamageDef damageDef; if (bodyPartRecord.depth == BodyPartDepth.Outside) { damageDef = HealthUtility.RandomViolenceDamageType(); } else { damageDef = DamageDefOf.Blunt; } DamageDef def = damageDef; float amount = (float)num2; float armorPenetration = 999f; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(def, amount, armorPenetration, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown, null); p.TakeDamage(dinfo); } if (!p.Dead) { Log.Error(p + " not killed during GiveInjuriesToKill", false); } }
public static float CalculateTagEfficiency(HediffSet diffSet, string tag, float maximum = 3.40282347E+38f, List <CapacityImpactor> impactors = null) { BodyDef body = diffSet.pawn.RaceProps.body; float num = 0f; int num2 = 0; List <CapacityImpactor> list = null; foreach (BodyPartRecord item in body.GetPartsWithTag(tag)) { BodyPartRecord part = item; List <CapacityImpactor> impactors2 = list; float num3 = PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); if (impactors != null && num3 != 1.0 && list == null) { list = new List <CapacityImpactor>(); part = item; impactors2 = list; PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); } num += num3; num2++; } if (num2 == 0) { return(1f); } float num4 = num / (float)num2; float num5 = Mathf.Min(num4, maximum); if (impactors != null && list != null && (maximum != 1.0 || num4 <= 1.0 || num5 == 1.0)) { impactors.AddRange(list); } return(num5); }
public static float CalculateNaturalPartsAverageEfficiency(HediffSet diffSet, BodyPartGroupDef bodyPartGroup) { float num = 0f; int num2 = 0; IEnumerable <BodyPartRecord> enumerable = from x in diffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null) where x.groups.Contains(bodyPartGroup) select x; foreach (BodyPartRecord part in enumerable) { if (!diffSet.PartOrAnyAncestorHasDirectlyAddedParts(part)) { num += PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, null); } num2++; } float result; if (num2 == 0 || num < 0f) { result = 0f; } else { result = num / (float)num2; } return(result); }
public static float CalculateLimbEfficiency(HediffSet diffSet, BodyPartTagDef limbCoreTag, BodyPartTagDef limbSegmentTag, BodyPartTagDef limbDigitTag, float appendageWeight, out float functionalPercentage, List <CapacityImpactor> impactors) { BodyDef body = diffSet.pawn.RaceProps.body; float num = 0f; int num2 = 0; int num3 = 0; foreach (BodyPartRecord item in body.GetPartsWithTag(limbCoreTag)) { float num4 = CalculateImmediatePartEfficiencyAndRecord(diffSet, item, impactors); foreach (BodyPartRecord connectedPart in item.GetConnectedParts(limbSegmentTag)) { num4 *= CalculateImmediatePartEfficiencyAndRecord(diffSet, connectedPart, impactors); } if (item.HasChildParts(limbDigitTag)) { num4 = Mathf.Lerp(num4, num4 * item.GetChildParts(limbDigitTag).Average((BodyPartRecord digitPart) => CalculateImmediatePartEfficiencyAndRecord(diffSet, digitPart, impactors)), appendageWeight); } num += num4; num2++; if (num4 > 0f) { num3++; } } if (num2 == 0) { functionalPercentage = 0f; return(0f); } functionalPercentage = (float)num3 / (float)num2; return(num / (float)num2); }
public static float CalculateCapacityLevel(HediffSet diffSet, PawnCapacityDef capacity, List <PawnCapacityUtility.CapacityImpactor> impactors = null) { float result; if (capacity.zeroIfCannotBeAwake && !diffSet.pawn.health.capacities.CanBeAwake) { if (impactors != null) { impactors.Add(new PawnCapacityUtility.CapacityImpactorCapacity { capacity = PawnCapacityDefOf.Consciousness }); } result = 0f; } else { float num = capacity.Worker.CalculateCapacityLevel(diffSet, impactors); if (num > 0f && capacity.minValue <= 0f) { float num2 = 99999f; float num3 = 1f; for (int i = 0; i < diffSet.hediffs.Count; i++) { Hediff hediff = diffSet.hediffs[i]; List <PawnCapacityModifier> capMods = hediff.CapMods; if (capMods != null) { for (int j = 0; j < capMods.Count; j++) { PawnCapacityModifier pawnCapacityModifier = capMods[j]; if (pawnCapacityModifier.capacity == capacity) { num += pawnCapacityModifier.offset; num3 *= pawnCapacityModifier.postFactor; if (pawnCapacityModifier.setMax < num2) { num2 = pawnCapacityModifier.setMax; } if (impactors != null) { impactors.Add(new PawnCapacityUtility.CapacityImpactorHediff { hediff = hediff }); } } } } } num *= num3; num = Mathf.Min(num, num2); } num = Mathf.Max(num, capacity.minValue); num = GenMath.RoundedHundredth(num); result = num; } return(result); }
public static float CalculateImmediatePartEfficiencyAndRecord(HediffSet diffSet, BodyPartRecord part, List <CapacityImpactor> impactors = null) { if (diffSet.AncestorHasDirectlyAddedParts(part)) { return(1f); } return(CalculatePartEfficiency(diffSet, part, ignoreAddedParts: false, impactors)); }
public bool IsSkinCovered(BodyPartRecord part, HediffSet body) { if (body.PartOrAnyAncestorHasDirectlyAddedParts(part)) { return(false); } return(skinCovered); }
public static float CalculateCapacityLevel(HediffSet diffSet, PawnCapacityDef capacity, List <CapacityImpactor> impactors = null, bool forTradePrice = false) { if (capacity.zeroIfCannotBeAwake && !diffSet.pawn.health.capacities.CanBeAwake) { impactors?.Add(new CapacityImpactorCapacity { capacity = PawnCapacityDefOf.Consciousness }); return(0f); } float num = capacity.Worker.CalculateCapacityLevel(diffSet, impactors); if (num > 0f) { float num2 = 99999f; float num3 = 1f; for (int i = 0; i < diffSet.hediffs.Count; i++) { Hediff hediff = diffSet.hediffs[i]; if (forTradePrice && !hediff.def.priceImpact) { continue; } List <PawnCapacityModifier> capMods = hediff.CapMods; if (capMods == null) { continue; } for (int j = 0; j < capMods.Count; j++) { PawnCapacityModifier pawnCapacityModifier = capMods[j]; if (pawnCapacityModifier.capacity == capacity) { num += pawnCapacityModifier.offset; float num4 = pawnCapacityModifier.postFactor; if (hediff.CurStage != null && hediff.CurStage.capacityFactorEffectMultiplier != null) { num4 = StatWorker.ScaleFactor(num4, hediff.pawn.GetStatValue(hediff.CurStage.capacityFactorEffectMultiplier)); } num3 *= num4; float num5 = pawnCapacityModifier.EvaluateSetMax(diffSet.pawn); if (num5 < num2) { num2 = num5; } impactors?.Add(new CapacityImpactorHediff { hediff = hediff }); } } } num *= num3; num = Mathf.Min(num, num2); } num = Mathf.Max(num, capacity.minValue); return(GenMath.RoundedHundredth(num)); }
public Pawn_HealthTracker(Pawn pawn) { this.pawn = pawn; this.hediffSet = new HediffSet(pawn); this.capacities = new PawnCapacitiesHandler(pawn); this.summaryHealth = new SummaryHealthHandler(pawn); this.surgeryBills = new BillStack(pawn); this.immunity = new ImmunityHandler(pawn); }
public override void OnIntervalPassed(Pawn pawn, Hediff cause) { float ambientTemperature = pawn.AmbientTemperature; FloatRange floatRange = pawn.ComfortableTemperatureRange(); FloatRange floatRange2 = pawn.SafeTemperatureRange(); HediffSet hediffSet = pawn.health.hediffSet; Hediff firstHediffOfDef = hediffSet.GetFirstHediffOfDef(this.hediff, false); if (ambientTemperature > floatRange2.max) { float num = ambientTemperature - floatRange2.max; num = HediffGiver_Heat.TemperatureOverageAdjustmentCurve.Evaluate(num); float num2 = num * 6.45E-05f; num2 = Mathf.Max(num2, 0.000375f); HealthUtility.AdjustSeverity(pawn, this.hediff, num2); } else if (firstHediffOfDef != null && ambientTemperature < floatRange.max) { float num3 = firstHediffOfDef.Severity * 0.027f; num3 = Mathf.Clamp(num3, 0.0015f, 0.015f); firstHediffOfDef.Severity -= num3; } if (pawn.Dead) { return; } if (pawn.IsNestedHashIntervalTick(60, 420)) { float num4 = floatRange.max + 150f; if (ambientTemperature > num4) { float num5 = ambientTemperature - num4; num5 = HediffGiver_Heat.TemperatureOverageAdjustmentCurve.Evaluate(num5); int num6 = Mathf.Max(GenMath.RoundRandom(num5 * 0.06f), 3); DamageInfo dinfo = new DamageInfo(DamageDefOf.Burn, (float)num6, 0f, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown, null); dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside); pawn.TakeDamage(dinfo); if (pawn.Faction == Faction.OfPlayer) { Find.TickManager.slower.SignalForceNormalSpeed(); if (MessagesRepeatAvoider.MessageShowAllowed("PawnBeingBurned", 60f)) { Messages.Message("MessagePawnBeingBurned".Translate(new object[] { pawn.LabelShort }).CapitalizeFirst(), pawn, MessageTypeDefOf.ThreatSmall, true); } } Lord lord = pawn.GetLord(); if (lord != null) { lord.ReceiveMemo(HediffGiver_Heat.MemoPawnBurnedByAir); } } } }
public Pawn_HealthTracker(Pawn pawn) { this.pawn = pawn; this.hediffSet = new HediffSet(pawn); this.capacities = new PawnCapacitiesHandler(pawn); this.summaryHealth = new SummaryHealthHandler(pawn); this.surgeryBills = new BillStack(pawn); this.immunity = new ImmunityHandler(pawn); this.beCarriedByCaravanIfSick = pawn.RaceProps.Humanlike; }
public static void DamageUntilDowned(Pawn p) { if (p.health.Downed) { return; } HediffSet hediffSet = p.health.hediffSet; p.health.forceIncap = true; IEnumerable <BodyPartRecord> source = from x in HealthUtility.HittablePartsViolence(hediffSet) where !p.health.hediffSet.hediffs.Any((Hediff y) => y.Part == x && y.CurStage != null && y.CurStage.partEfficiencyOffset < 0f) select x; int num = 0; while (num < 300 && !p.Downed && source.Any <BodyPartRecord>()) { num++; BodyPartRecord bodyPartRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); int num2 = Mathf.RoundToInt(hediffSet.GetPartHealth(bodyPartRecord)) - 3; if (num2 >= 8) { DamageDef damageDef; if (bodyPartRecord.depth == BodyPartDepth.Outside) { damageDef = HealthUtility.RandomViolenceDamageType(); } else { damageDef = DamageDefOf.Blunt; } int num3 = Rand.RangeInclusive(Mathf.RoundToInt((float)num2 * 0.65f), num2); HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(damageDef, p, bodyPartRecord); if (!p.health.WouldDieAfterAddingHediff(hediffDefFromDamage, bodyPartRecord, (float)num3)) { DamageDef def = damageDef; int amount = num3; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(def, amount, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown); dinfo.SetAllowDamagePropagation(false); p.TakeDamage(dinfo); } } } if (p.Dead) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(p + " died during GiveInjuriesToForceDowned"); for (int i = 0; i < p.health.hediffSet.hediffs.Count; i++) { stringBuilder.AppendLine(" -" + p.health.hediffSet.hediffs[i].ToString()); } Log.Error(stringBuilder.ToString()); } p.health.forceIncap = false; }
public override void OnIntervalPassed(Pawn pawn, Hediff cause) { float ambientTemperature = pawn.AmbientTemperature; FloatRange floatRange = pawn.ComfortableTemperatureRange(); FloatRange floatRange2 = pawn.SafeTemperatureRange(); HediffSet hediffSet = pawn.health.hediffSet; HediffDef hediffDef = (pawn.RaceProps.FleshType != FleshTypeDefOf.Insectoid) ? this.hediff : this.hediffInsectoid; Hediff firstHediffOfDef = hediffSet.GetFirstHediffOfDef(hediffDef, false); if (ambientTemperature < floatRange2.min) { float num = Mathf.Abs(ambientTemperature - floatRange2.min); float num2 = num * 6.45E-05f; num2 = Mathf.Max(num2, 0.00075f); HealthUtility.AdjustSeverity(pawn, hediffDef, num2); if (pawn.Dead) { return; } } if (firstHediffOfDef != null) { if (ambientTemperature > floatRange.min) { float num3 = firstHediffOfDef.Severity * 0.027f; num3 = Mathf.Clamp(num3, 0.0015f, 0.015f); firstHediffOfDef.Severity -= num3; } else if (pawn.RaceProps.FleshType != FleshTypeDefOf.Insectoid) { if (ambientTemperature < 0f && firstHediffOfDef.Severity > 0.37f) { float num4 = 0.025f * firstHediffOfDef.Severity; if (Rand.Value < num4) { BodyPartRecord bodyPartRecord; if ((from x in pawn.RaceProps.body.AllPartsVulnerableToFrostbite where !hediffSet.PartIsMissing(x) select x).TryRandomElementByWeight((BodyPartRecord x) => x.def.frostbiteVulnerability, out bodyPartRecord)) { int num5 = Mathf.CeilToInt((float)bodyPartRecord.def.hitPoints * 0.5f); DamageDef frostbite = DamageDefOf.Frostbite; float amount = (float)num5; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(frostbite, amount, 0f, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown, null); pawn.TakeDamage(dinfo); } } } } } }
protected float CalculateCapacityAndRecord(HediffSet diffSet, PawnCapacityDef capacity, List <PawnCapacityUtility.CapacityImpactor> impactors) { float level = diffSet.pawn.health.capacities.GetLevel(capacity); if (impactors != null && level != 1.0) { impactors.Add(new PawnCapacityUtility.CapacityImpactorCapacity { capacity = capacity }); } return(level); }
public static float CalculateTagEfficiency(HediffSet diffSet, BodyPartTagDef tag, float maximum = 3.40282347E+38f, FloatRange lerp = default(FloatRange), List <PawnCapacityUtility.CapacityImpactor> impactors = null, float bestPartEfficiencySpecialWeight = -1f) { BodyDef body = diffSet.pawn.RaceProps.body; float num = 0f; int num2 = 0; float num3 = 0f; List <PawnCapacityUtility.CapacityImpactor> list = null; foreach (BodyPartRecord current in body.GetPartsWithTag(tag)) { BodyPartRecord part = current; List <PawnCapacityUtility.CapacityImpactor> impactors2 = list; float num4 = PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); if (impactors != null && num4 != 1f && list == null) { list = new List <PawnCapacityUtility.CapacityImpactor>(); part = current; impactors2 = list; PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); } num += num4; num3 = Mathf.Max(num3, num4); num2++; } if (num2 == 0) { return(1f); } float num5; if (bestPartEfficiencySpecialWeight >= 0f && num2 >= 2) { num5 = num3 * bestPartEfficiencySpecialWeight + (num - num3) / (float)(num2 - 1) * (1f - bestPartEfficiencySpecialWeight); } else { num5 = num / (float)num2; } float num6 = num5; if (lerp != default(FloatRange)) { num6 = lerp.LerpThroughRange(num6); } num6 = Mathf.Min(num6, maximum); if (impactors != null && list != null && (maximum != 1f || num5 <= 1f || num6 == 1f)) { impactors.AddRange(list); } return(num6); }
public static int CountAddedAndImplantedParts(this HediffSet hs) { int num = 0; List <Hediff> hediffs = hs.hediffs; for (int i = 0; i < hediffs.Count; i++) { if (hediffs[i].def.countsAsAddedPartOrImplant) { num++; } } return(num); }
public static int CountAddedParts(this HediffSet hs) { int num = 0; List <Hediff> hediffs = hs.hediffs; for (int i = 0; i < hediffs.Count; i++) { if (hediffs[i] is Hediff_AddedPart) { num++; } } return(num); }
public override void OnIntervalPassed(Pawn pawn, Hediff cause) { HediffSet hediffSet = pawn.health.hediffSet; bool flag = hediffSet.BleedRateTotal >= 0.1f; if (flag) { HealthUtility.AdjustSeverity(pawn, this.hediff, hediffSet.BleedRateTotal * 0.001f); } else { HealthUtility.AdjustSeverity(pawn, this.hediff, -0.00033333333f); } }
public static float CalculateImmediatePartEfficiencyAndRecord(HediffSet diffSet, BodyPartRecord part, List <PawnCapacityUtility.CapacityImpactor> impactors = null) { float result; if (diffSet.AncestorHasDirectlyAddedParts(part)) { result = 1f; } else { result = PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors); } return(result); }
public override void OnIntervalPassed(Pawn pawn, Hediff cause) { float ambientTemperature = pawn.AmbientTemperature; FloatRange floatRange = pawn.ComfortableTemperatureRange(); FloatRange floatRange2 = pawn.SafeTemperatureRange(); HediffSet hediffSet = pawn.health.hediffSet; Hediff firstHediffOfDef = hediffSet.GetFirstHediffOfDef(base.hediff, false); if (ambientTemperature > floatRange2.max) { float x = ambientTemperature - floatRange2.max; x = HediffGiver_Heat.TemperatureOverageAdjustmentCurve.Evaluate(x); float a = (float)(x * 6.44999963697046E-05); a = Mathf.Max(a, 0.000375f); HealthUtility.AdjustSeverity(pawn, base.hediff, a); } else if (firstHediffOfDef != null && ambientTemperature < floatRange.max) { float value = (float)(firstHediffOfDef.Severity * 0.027000000700354576); value = Mathf.Clamp(value, 0.0015f, 0.015f); firstHediffOfDef.Severity -= value; } if (!pawn.Dead && pawn.IsNestedHashIntervalTick(60, 420)) { float num = (float)(floatRange.max + 150.0); if (ambientTemperature > num) { float x2 = ambientTemperature - num; x2 = HediffGiver_Heat.TemperatureOverageAdjustmentCurve.Evaluate(x2); int amount = Mathf.Max(GenMath.RoundRandom((float)(x2 * 0.059999998658895493)), 3); DamageInfo dinfo = new DamageInfo(DamageDefOf.Burn, amount, -1f, null, null, null, DamageInfo.SourceCategory.ThingOrUnknown); dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside); pawn.TakeDamage(dinfo); if (pawn.Faction == Faction.OfPlayer) { Find.TickManager.slower.SignalForceNormalSpeed(); if (MessagesRepeatAvoider.MessageShowAllowed("PawnBeingBurned", 60f)) { Messages.Message("MessagePawnBeingBurned".Translate(pawn.LabelShort).CapitalizeFirst(), pawn, MessageTypeDefOf.ThreatSmall); } } Lord lord = pawn.GetLord(); if (lord != null) { lord.ReceiveMemo(HediffGiver_Heat.MemoPawnBurnedByAir); } } } }
public static void DamageUntilDowned(Pawn p, bool allowBleedingWounds = true) { if (!p.health.Downed) { HediffSet hediffSet = p.health.hediffSet; p.health.forceIncap = true; IEnumerable <BodyPartRecord> source = from x in HittablePartsViolence(hediffSet) where !p.health.hediffSet.hediffs.Any((Hediff y) => y.Part == x && y.CurStage != null && y.CurStage.partEfficiencyOffset < 0f) select x; int num = 0; while (num < 300 && !p.Downed && source.Any()) { num++; BodyPartRecord bodyPartRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); int num2 = Mathf.RoundToInt(hediffSet.GetPartHealth(bodyPartRecord)) - 3; if (num2 >= 8) { DamageDef damageDef = (bodyPartRecord.depth != BodyPartDepth.Outside) ? DamageDefOf.Blunt : ((allowBleedingWounds || !(bodyPartRecord.def.bleedRate > 0f)) ? RandomViolenceDamageType() : DamageDefOf.Blunt); int num3 = Rand.RangeInclusive(Mathf.RoundToInt((float)num2 * 0.65f), num2); HediffDef hediffDefFromDamage = GetHediffDefFromDamage(damageDef, p, bodyPartRecord); if (!p.health.WouldDieAfterAddingHediff(hediffDefFromDamage, bodyPartRecord, (float)num3)) { DamageDef def = damageDef; float amount = (float)num3; float armorPenetration = 999f; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(def, amount, armorPenetration, -1f, null, hitPart); dinfo.SetAllowDamagePropagation(val: false); p.TakeDamage(dinfo); } } } if (p.Dead) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(p + " died during GiveInjuriesToForceDowned"); for (int i = 0; i < p.health.hediffSet.hediffs.Count; i++) { stringBuilder.AppendLine(" -" + p.health.hediffSet.hediffs[i].ToString()); } Log.Error(stringBuilder.ToString()); } p.health.forceIncap = false; } }
public static float CalculateTagEfficiency(HediffSet diffSet, BodyPartTagDef tag, float maximum = 3.40282347E+38f, FloatRange lerp = default(FloatRange), List <PawnCapacityUtility.CapacityImpactor> impactors = null) { BodyDef body = diffSet.pawn.RaceProps.body; float num = 0f; int num2 = 0; List <PawnCapacityUtility.CapacityImpactor> list = null; foreach (BodyPartRecord bodyPartRecord in body.GetPartsWithTag(tag)) { BodyPartRecord part = bodyPartRecord; List <PawnCapacityUtility.CapacityImpactor> impactors2 = list; float num3 = PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); if (impactors != null && num3 != 1f && list == null) { list = new List <PawnCapacityUtility.CapacityImpactor>(); part = bodyPartRecord; impactors2 = list; PawnCapacityUtility.CalculatePartEfficiency(diffSet, part, false, impactors2); } num += num3; num2++; } float result; if (num2 == 0) { result = 1f; } else { float num4 = num / (float)num2; float num5 = num4; if (lerp != default(FloatRange)) { num5 = lerp.LerpThroughRange(num5); } num5 = Mathf.Min(num5, maximum); if (impactors != null && list != null && (maximum != 1f || num4 <= 1f || num5 == 1f)) { impactors.AddRange(list); } result = num5; } return(result); }
public override void OnIntervalPassed(Pawn pawn, Hediff cause) { float ambientTemperature = pawn.AmbientTemperature; FloatRange floatRange = pawn.ComfortableTemperatureRange(); FloatRange floatRange2 = pawn.SafeTemperatureRange(); HediffSet hediffSet = pawn.health.hediffSet; Hediff firstHediffOfDef = hediffSet.GetFirstHediffOfDef(hediff); if (ambientTemperature > floatRange2.max) { float x = ambientTemperature - floatRange2.max; x = TemperatureOverageAdjustmentCurve.Evaluate(x); float a = x * 6.45E-05f; a = Mathf.Max(a, 0.000375f); HealthUtility.AdjustSeverity(pawn, hediff, a); } else if (firstHediffOfDef != null && ambientTemperature < floatRange.max) { float value = firstHediffOfDef.Severity * 0.027f; value = Mathf.Clamp(value, 0.0015f, 0.015f); firstHediffOfDef.Severity -= value; } if (!pawn.Dead && pawn.IsNestedHashIntervalTick(60, 420)) { float num = floatRange.max + 150f; if (ambientTemperature > num) { float x2 = ambientTemperature - num; x2 = TemperatureOverageAdjustmentCurve.Evaluate(x2); int num2 = Mathf.Max(GenMath.RoundRandom(x2 * 0.06f), 3); DamageInfo dinfo = new DamageInfo(DamageDefOf.Burn, (float)num2); dinfo.SetBodyRegion(BodyPartHeight.Undefined, BodyPartDepth.Outside); pawn.TakeDamage(dinfo); if (pawn.Faction == Faction.OfPlayer) { Find.TickManager.slower.SignalForceNormalSpeed(); if (MessagesRepeatAvoider.MessageShowAllowed("PawnBeingBurned", 60f)) { Messages.Message("MessagePawnBeingBurned".Translate(pawn.LabelShort, pawn).CapitalizeFirst(), pawn, MessageTypeDefOf.ThreatSmall); } } pawn.GetLord()?.ReceiveMemo(MemoPawnBurnedByAir); } } }
public override void OnIntervalPassed(Pawn pawn, Hediff cause) { float ambientTemperature = pawn.AmbientTemperature; FloatRange floatRange = pawn.ComfortableTemperatureRange(); FloatRange floatRange2 = pawn.SafeTemperatureRange(); HediffSet hediffSet = pawn.health.hediffSet; Hediff firstHediffOfDef = hediffSet.GetFirstHediffOfDef(base.hediff, false); if (ambientTemperature < floatRange2.min) { float num = Mathf.Abs(ambientTemperature - floatRange2.min); float a = (float)(num * 6.44999963697046E-05); a = Mathf.Max(a, 0.00075f); HealthUtility.AdjustSeverity(pawn, base.hediff, a); if (pawn.Dead) { return; } } if (firstHediffOfDef != null) { if (ambientTemperature > floatRange.min) { float value = (float)(firstHediffOfDef.Severity * 0.027000000700354576); value = Mathf.Clamp(value, 0.0015f, 0.015f); firstHediffOfDef.Severity -= value; } else if (ambientTemperature < 0.0 && firstHediffOfDef.Severity > 0.37000000476837158) { float num2 = (float)(0.02500000037252903 * firstHediffOfDef.Severity); BodyPartRecord bodyPartRecord = default(BodyPartRecord); if (Rand.Value < num2 && (from x in pawn.RaceProps.body.AllPartsVulnerableToFrostbite where !hediffSet.PartIsMissing(x) select x).TryRandomElementByWeight <BodyPartRecord>((Func <BodyPartRecord, float>)((BodyPartRecord x) => x.def.frostbiteVulnerability), out bodyPartRecord)) { int num3 = Mathf.CeilToInt((float)((float)bodyPartRecord.def.hitPoints * 0.5)); DamageDef frostbite = DamageDefOf.Frostbite; int amount = num3; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(frostbite, amount, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown); pawn.TakeDamage(dinfo); } } } }
public static void DamageUntilDead(Pawn p) { HediffSet hediffSet = p.health.hediffSet; int num = 0; while (!p.Dead && num < 200 && HittablePartsViolence(hediffSet).Any()) { num++; BodyPartRecord bodyPartRecord = HittablePartsViolence(hediffSet).RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); int num2 = Rand.RangeInclusive(8, 25); DamageDef def = (bodyPartRecord.depth != BodyPartDepth.Outside) ? DamageDefOf.Blunt : RandomViolenceDamageType(); DamageInfo dinfo = new DamageInfo(def, num2, 999f, -1f, null, bodyPartRecord); p.TakeDamage(dinfo); } if (!p.Dead) { Log.Error(p + " not killed during GiveInjuriesToKill"); } }
public static float CalculateTagEfficiency(HediffSet diffSet, BodyPartTagDef tag, float maximum = float.MaxValue, FloatRange lerp = default(FloatRange), List <CapacityImpactor> impactors = null, float bestPartEfficiencySpecialWeight = -1f) { BodyDef body = diffSet.pawn.RaceProps.body; float totalEfficiency = 0f; int partCount = 0; float bestPartEfficiency = 0f; List <CapacityImpactor> list = null; foreach (BodyPartRecord item in body.GetPartsWithTag(tag)) { BodyPartRecord part = item; List <CapacityImpactor> impactors2 = list; float partEfficiency = CalculatePartEfficiency(diffSet, part, ignoreAddedParts: false, impactors2); if (impactors != null && partEfficiency != 1f && list == null) { list = new List <CapacityImpactor>(); part = item; impactors2 = list; CalculatePartEfficiency(diffSet, part, ignoreAddedParts: false, impactors2); } totalEfficiency += partEfficiency; bestPartEfficiency = Mathf.Max(bestPartEfficiency, partEfficiency); partCount++; } if (partCount == 0) { return(1f); } float weightedEfficiency = (!(bestPartEfficiencySpecialWeight >= 0f) || partCount < 2) ? (totalEfficiency / (float)partCount) : (bestPartEfficiency * bestPartEfficiencySpecialWeight + (totalEfficiency - bestPartEfficiency) / (float)(partCount - 1) * (1f - bestPartEfficiencySpecialWeight)); float num6 = weightedEfficiency; if (lerp != default(FloatRange)) { num6 = lerp.LerpThroughRange(num6); } num6 = Mathf.Min(num6, maximum); if (impactors != null && list != null && (maximum != 1f || weightedEfficiency <= 1f || num6 == 1f)) { impactors.AddRange(list); } return(num6); }
public static float CalculateNaturalPartsAverageEfficiency(HediffSet diffSet, BodyPartGroupDef bodyPartGroup) { float num = 0f; int num2 = 0; foreach (BodyPartRecord item in from x in diffSet.GetNotMissingParts() where x.groups.Contains(bodyPartGroup) select x) { if (!diffSet.PartOrAnyAncestorHasDirectlyAddedParts(item)) { num += CalculatePartEfficiency(diffSet, item); } num2++; } if (num2 == 0 || num < 0f) { return(0f); } return(num / (float)num2); }
public override void OnIntervalPassed(Pawn pawn, Hediff cause) { float ambientTemperature = pawn.AmbientTemperature; FloatRange floatRange = pawn.ComfortableTemperatureRange(); FloatRange floatRange2 = pawn.SafeTemperatureRange(); HediffSet hediffSet = pawn.health.hediffSet; HediffDef hediffDef = ((pawn.RaceProps.FleshType == FleshTypeDefOf.Insectoid) ? hediffInsectoid : hediff); Hediff firstHediffOfDef = hediffSet.GetFirstHediffOfDef(hediffDef); if (ambientTemperature < floatRange2.min) { float a = Mathf.Abs(ambientTemperature - floatRange2.min) * 6.45E-05f; a = Mathf.Max(a, 0.00075f); HealthUtility.AdjustSeverity(pawn, hediffDef, a); if (pawn.Dead) { return; } } if (firstHediffOfDef == null) { return; } if (ambientTemperature > floatRange.min) { float value = firstHediffOfDef.Severity * 0.027f; value = Mathf.Clamp(value, 0.0015f, 0.015f); firstHediffOfDef.Severity -= value; } else if (pawn.RaceProps.FleshType != FleshTypeDefOf.Insectoid && ambientTemperature < 0f && firstHediffOfDef.Severity > 0.37f) { float num = 0.025f * firstHediffOfDef.Severity; if (Rand.Value < num && pawn.RaceProps.body.AllPartsVulnerableToFrostbite.Where((BodyPartRecord x) => !hediffSet.PartIsMissing(x)).TryRandomElementByWeight((BodyPartRecord x) => x.def.frostbiteVulnerability, out var result)) { int num2 = Mathf.CeilToInt((float)result.def.hitPoints * 0.5f); DamageInfo dinfo = new DamageInfo(DamageDefOf.Frostbite, num2, 0f, -1f, null, result); pawn.TakeDamage(dinfo); } } }
public static float CalculateNaturalPartsAverageEfficiency(HediffSet diffSet, BodyPartGroupDef bodyPartGroup) { float num = 0f; int num2 = 0; IEnumerable <BodyPartRecord> enumerable = from x in diffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined) where x.groups.Contains(bodyPartGroup) select x; foreach (BodyPartRecord item in enumerable) { if (!diffSet.PartOrAnyAncestorHasDirectlyAddedParts(item)) { num += PawnCapacityUtility.CalculatePartEfficiency(diffSet, item, false, null); } num2++; } if (num2 != 0 && !(num < 0.0)) { return(num / (float)num2); } return(0f); }