public static void HealInjuryRandom(Pawn pawn, float amount) { BodyPartRecord part; if (!pawn.health.hediffSet.GetInjuredParts().TryRandomElement(out part)) { return; } Hediff_Injury hediff_Injury = null; foreach (Hediff_Injury current in from x in pawn.health.hediffSet.GetHediffs <Hediff_Injury>() where x.Part == part select x) { if (!current.IsOld()) { if (hediff_Injury == null || current.Severity > hediff_Injury.Severity) { hediff_Injury = current; } } } if (hediff_Injury != null) { hediff_Injury.Heal(amount); } }
private void CalculatePermanentInjuryDamageThreshold(Pawn pawn, Hediff_Injury injury) { HediffCompProperties_GetsPermanent hediffCompProperties_GetsPermanent = injury.def.CompProps <HediffCompProperties_GetsPermanent>(); if (hediffCompProperties_GetsPermanent != null) { if (!injury.Part.def.IsSolid(injury.Part, pawn.health.hediffSet.hediffs) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(injury.Part) && !injury.IsPermanent() && injury.Part.def.permanentInjuryBaseChance >= 1E-05f) { bool isDelicate = injury.Part.def.IsDelicate; if ((Rand.Value <= injury.Part.def.permanentInjuryBaseChance * hediffCompProperties_GetsPermanent.becomePermanentChance && injury.Severity >= injury.Part.def.GetMaxHealth(pawn) * 0.25f && injury.Severity >= 7f) || isDelicate) { HediffComp_GetsPermanent hediffComp_GetsPermanent = injury.TryGetComp <HediffComp_GetsPermanent>(); float num = 1f; float num2 = injury.Severity / 2f; if (num <= num2) { hediffComp_GetsPermanent.permanentDamageThreshold = Rand.Range(num, num2); } if (isDelicate) { hediffComp_GetsPermanent.permanentDamageThreshold = injury.Severity; hediffComp_GetsPermanent.IsPermanent = true; } } } } }
private void CalculateOldInjuryDamageThreshold(Pawn pawn, Hediff_Injury injury) { HediffCompProperties_GetsOld hediffCompProperties_GetsOld = injury.def.CompProps <HediffCompProperties_GetsOld>(); if (hediffCompProperties_GetsOld != null && !injury.Part.def.IsSolid(injury.Part, pawn.health.hediffSet.hediffs) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(injury.Part) && !injury.IsOld() && !(injury.Part.def.oldInjuryBaseChance < 9.9999997473787516E-06)) { bool isDelicate = injury.Part.def.IsDelicate; if ((!(Rand.Value <= injury.Part.def.oldInjuryBaseChance * hediffCompProperties_GetsOld.becomeOldChance) || !(injury.Severity >= injury.Part.def.GetMaxHealth(pawn) * 0.25) || !(injury.Severity >= 7.0)) && !isDelicate) { return; } HediffComp_GetsOld hediffComp_GetsOld = injury.TryGetComp <HediffComp_GetsOld>(); float num = 1f; float num2 = (float)(injury.Severity / 2.0); if (num <= num2) { hediffComp_GetsOld.oldDamageThreshold = Rand.Range(num, num2); } if (isDelicate) { hediffComp_GetsOld.oldDamageThreshold = injury.Severity; hediffComp_GetsOld.IsOld = true; } } }
private void CalculateOldInjuryDamageThreshold(Pawn pawn, Hediff_Injury injury) { HediffCompProperties_GetsOld hediffCompProperties_GetsOld = injury.def.CompProps <HediffCompProperties_GetsOld>(); if (hediffCompProperties_GetsOld == null) { return; } if (injury.Part.def.IsSolid(injury.Part, pawn.health.hediffSet.hediffs) || pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(injury.Part) || injury.IsOld() || injury.Part.def.oldInjuryBaseChance < 1E-05f) { return; } bool isDelicate = injury.Part.def.IsDelicate; if ((Rand.Value <= injury.Part.def.oldInjuryBaseChance * hediffCompProperties_GetsOld.becomeOldChance && injury.Severity >= injury.Part.def.GetMaxHealth(pawn) * 0.25f && injury.Severity >= 7f) || isDelicate) { HediffComp_GetsOld hediffComp_GetsOld = injury.TryGetComp <HediffComp_GetsOld>(); float num = 1f; float num2 = injury.Severity / 2f; if (num <= num2) { hediffComp_GetsOld.oldDamageThreshold = Rand.Range(num, num2); } if (isDelicate) { hediffComp_GetsOld.oldDamageThreshold = injury.Severity; hediffComp_GetsOld.IsOld = true; } } }
protected float FinalizeAndAddInjury(Pawn pawn, float totalDamage, DamageInfo dinfo, DamageWorker.DamageResult result) { if (pawn.health.hediffSet.PartIsMissing(dinfo.HitPart)) { return(0f); } HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, dinfo.HitPart); Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null); hediff_Injury.Part = dinfo.HitPart; hediff_Injury.source = dinfo.Weapon; hediff_Injury.sourceBodyPartGroup = dinfo.WeaponBodyPartGroup; hediff_Injury.sourceHediffDef = dinfo.WeaponLinkedHediff; hediff_Injury.Severity = totalDamage; if (dinfo.InstantPermanentInjury) { HediffComp_GetsPermanent hediffComp_GetsPermanent = hediff_Injury.TryGetComp <HediffComp_GetsPermanent>(); if (hediffComp_GetsPermanent != null) { hediffComp_GetsPermanent.IsPermanent = true; } else { Log.Error(string.Concat(new object[] { "Tried to create instant permanent injury on Hediff without a GetsPermanent comp: ", hediffDefFromDamage, " on ", pawn }), false); } } return(this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, result)); }
public static void HealNonPermanentInjuriesAndRestoreLegs(Pawn p) { if (!p.Dead) { tmpHediffs.Clear(); tmpHediffs.AddRange(p.health.hediffSet.hediffs); for (int i = 0; i < tmpHediffs.Count; i++) { Hediff_Injury hediff_Injury = tmpHediffs[i] as Hediff_Injury; if (hediff_Injury != null && !hediff_Injury.IsPermanent()) { p.health.RemoveHediff(hediff_Injury); } else { Hediff_MissingPart hediff_MissingPart = tmpHediffs[i] as Hediff_MissingPart; if (hediff_MissingPart != null && hediff_MissingPart.Part.def.tags.Contains(BodyPartTagDefOf.MovingLimbCore) && (hediff_MissingPart.Part.parent == null || p.health.hediffSet.GetNotMissingParts().Contains(hediff_MissingPart.Part.parent))) { p.health.RestorePart(hediff_MissingPart.Part); } } } tmpHediffs.Clear(); } }
public float GetPartHealth(BodyPartRecord part) { if (part == null) { return(0f); } float num = part.def.GetMaxHealth(this.pawn); for (int i = 0; i < this.hediffs.Count; i++) { if (this.hediffs[i] is Hediff_MissingPart && this.hediffs[i].Part == part) { return(0f); } if (this.hediffs[i].Part == part) { Hediff_Injury hediff_Injury = this.hediffs[i] as Hediff_Injury; if (hediff_Injury != null) { num -= hediff_Injury.Severity; } } } if (num < 0f) { num = 0f; } return((float)Mathf.RoundToInt(num)); }
public static void HealNonPermanentInjuriesAndRestoreLegs(Pawn p) { if (p.Dead) { return; } HealthUtility.tmpHediffs.Clear(); HealthUtility.tmpHediffs.AddRange(p.health.hediffSet.hediffs); for (int i = 0; i < HealthUtility.tmpHediffs.Count; i++) { Hediff_Injury hediff_Injury = HealthUtility.tmpHediffs[i] as Hediff_Injury; if (hediff_Injury != null && !hediff_Injury.IsPermanent()) { p.health.RemoveHediff(hediff_Injury); } else { Hediff_MissingPart hediff_MissingPart = HealthUtility.tmpHediffs[i] as Hediff_MissingPart; if (hediff_MissingPart != null && hediff_MissingPart.Part.def.tags.Contains(BodyPartTagDefOf.MovingLimbCore) && (hediff_MissingPart.Part.parent == null || p.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null).Contains(hediff_MissingPart.Part.parent))) { p.health.RestorePart(hediff_MissingPart.Part, null, true); } } } HealthUtility.tmpHediffs.Clear(); }
private void CheckDuplicateDamageToOuterParts(DamageInfo dinfo, Pawn pawn, float totalDamage, DamageWorker.DamageResult result) { if (!dinfo.AllowDamagePropagation) { return; } if (dinfo.Def.harmAllLayersUntilOutside && dinfo.HitPart.depth == BodyPartDepth.Inside) { BodyPartRecord parent = dinfo.HitPart.parent; do { if (pawn.health.hediffSet.GetPartHealth(parent) != 0f && parent.coverageAbs > 0f) { HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, parent); Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null); hediff_Injury.Part = parent; hediff_Injury.source = dinfo.Weapon; hediff_Injury.sourceBodyPartGroup = dinfo.WeaponBodyPartGroup; hediff_Injury.Severity = totalDamage; if (hediff_Injury.Severity <= 0f) { hediff_Injury.Severity = 1f; } this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, result); } if (parent.depth == BodyPartDepth.Outside) { break; } parent = parent.parent; }while (parent != null); } }
protected float FinalizeAndAddInjury(Pawn pawn, float totalDamage, DamageInfo dinfo, ref DamageResult result) { if (pawn.health.hediffSet.PartIsMissing(dinfo.HitPart)) { return(0f); } HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, dinfo.HitPart); Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null); hediff_Injury.Part = dinfo.HitPart; hediff_Injury.source = dinfo.Weapon; hediff_Injury.sourceBodyPartGroup = dinfo.WeaponBodyPartGroup; hediff_Injury.sourceHediffDef = dinfo.WeaponLinkedHediff; hediff_Injury.Severity = totalDamage; if (dinfo.InstantOldInjury) { HediffComp_GetsOld hediffComp_GetsOld = hediff_Injury.TryGetComp <HediffComp_GetsOld>(); if (hediffComp_GetsOld != null) { hediffComp_GetsOld.IsOld = true; } else { Log.Error("Tried to create instant old injury on Hediff without a GetsOld comp: " + hediffDefFromDamage + " on " + pawn); } } return(this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, ref result)); }
public float GetPartHealth(BodyPartRecord part) { if (part == null) { return(0f); } float num = part.def.GetMaxHealth(pawn); for (int i = 0; i < hediffs.Count; i++) { if (hediffs[i] is Hediff_MissingPart && hediffs[i].Part == part) { return(0f); } if (hediffs[i].Part == part) { Hediff_Injury hediff_Injury = hediffs[i] as Hediff_Injury; if (hediff_Injury != null) { num -= hediff_Injury.Severity; } } } num = Mathf.Max(num, 0f); if (!part.def.destroyableByDamage) { num = Mathf.Max(num, 1f); } return((float)Mathf.RoundToInt(num)); }
public static void DamageLegsUntilIncapableOfMoving(Pawn p) { HediffDef def = Rand.Element <HediffDef>(HediffDefOf.Scratch, HediffDefOf.Bruise, HediffDefOf.Bite, HediffDefOf.Cut); int num = 0; while (p.health.capacities.CapableOf(PawnCapacityDefOf.Moving) && num < 300) { num++; IEnumerable <BodyPartRecord> source = from x in p.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined) where x.def.tags.Contains("MovingLimbCore") && p.health.hediffSet.GetPartHealth(x) >= 2f select x; if (!source.Any <BodyPartRecord>()) { break; } BodyPartRecord bodyPartRecord = source.RandomElement <BodyPartRecord>(); float maxHealth = bodyPartRecord.def.GetMaxHealth(p); float partHealth = p.health.hediffSet.GetPartHealth(bodyPartRecord); int min = Mathf.Clamp(Mathf.RoundToInt(maxHealth * 0.12f), 1, (int)partHealth - 1); int max = Mathf.Clamp(Mathf.RoundToInt(maxHealth * 0.27f), 1, (int)partHealth - 1); int num2 = Rand.RangeInclusive(min, max); if (p.health.WouldDieAfterAddingHediff(def, bodyPartRecord, (float)num2)) { break; } Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(def, p, bodyPartRecord); hediff_Injury.Severity = (float)num2; p.health.AddHediff(hediff_Injury, null, null); } }
protected float FinalizeAndAddInjury(Pawn pawn, Hediff_Injury injury, DamageInfo dinfo, DamageResult result) { injury.TryGetComp <HediffComp_GetsPermanent>()?.PreFinalizeInjury(); float partHealth = pawn.health.hediffSet.GetPartHealth(injury.Part); if (pawn.IsColonist && !dinfo.IgnoreInstantKillProtection && dinfo.Def.ExternalViolenceFor(pawn) && !Rand.Chance(Find.Storyteller.difficultyValues.allowInstantKillChance)) { float num = ((injury.def.lethalSeverity > 0f) ? (injury.def.lethalSeverity * 1.1f) : 1f); float min = 1f; float max = Mathf.Min(injury.Severity, partHealth); for (int i = 0; i < 7; i++) { if (!pawn.health.WouldDieAfterAddingHediff(injury)) { break; } float num2 = Mathf.Clamp(partHealth - num, min, max); if (DebugViewSettings.logCauseOfDeath) { Log.Message($"CauseOfDeath: attempt to prevent death for {pawn.Name} on {injury.Part.Label} attempt:{i + 1} severity:{injury.Severity}->{num2} part health:{partHealth}"); } injury.Severity = num2; num *= 2f; min = 0f; } } pawn.health.AddHediff(injury, null, dinfo, result); float num3 = Mathf.Min(injury.Severity, partHealth); result.totalDamageDealt += num3; result.wounded = true; result.AddPart(pawn, injury.Part); result.AddHediff(injury); return(num3); }
public static bool CanHealFromTending(this Hediff_Injury hd) { if (hd.IsTended()) { return(!hd.IsPermanent()); } return(false); }
public override bool TryMergeWith(Hediff other) { Hediff_Injury hediff_Injury = other as Hediff_Injury; if (hediff_Injury == null || hediff_Injury.def != def || hediff_Injury.Part != base.Part || hediff_Injury.IsTended() || hediff_Injury.IsPermanent() || this.IsTended() || this.IsPermanent() || !def.injuryProps.canMerge) { return false; } return base.TryMergeWith(other); }
public override bool TryMergeWith(Hediff other) { Hediff_Injury hediff_Injury = other as Hediff_Injury; if (hediff_Injury != null && hediff_Injury.def == base.def && hediff_Injury.Part == base.Part && !hediff_Injury.IsTended() && !hediff_Injury.IsOld() && !this.IsTended() && !this.IsOld() && base.def.injuryProps.canMerge) { return(base.TryMergeWith(other)); } return(false); }
protected float FinalizeAndAddInjury(Pawn pawn, Hediff_Injury injury, DamageInfo dinfo, ref DamageResult result) { this.CalculateOldInjuryDamageThreshold(pawn, injury); pawn.health.AddHediff(injury, null, dinfo); float num = Mathf.Min(injury.Severity, pawn.health.hediffSet.GetPartHealth(injury.Part)); result.totalDamageDealt += num; result.wounded = true; result.AddPart(pawn, injury.Part); return(num); }
public IEnumerable <Hediff_Injury> GetInjuriesTendable() { for (int i = 0; i < this.hediffs.Count; i++) { Hediff_Injury inj = this.hediffs[i] as Hediff_Injury; if (inj != null && inj.TendableNow) { yield return(inj); } } }
protected float FinalizeAndAddInjury(Pawn pawn, Hediff_Injury injury, DamageInfo dinfo, DamageResult result) { injury.TryGetComp <HediffComp_GetsPermanent>()?.PreFinalizeInjury(); pawn.health.AddHediff(injury, null, dinfo, result); float num = Mathf.Min(injury.Severity, pawn.health.hediffSet.GetPartHealth(injury.Part)); result.totalDamageDealt += num; result.wounded = true; result.AddPart(pawn, injury.Part); result.AddHediff(injury); return(num); }
public bool HasNaturallyHealingInjury() { for (int i = 0; i < hediffs.Count; i++) { Hediff_Injury hediff_Injury = hediffs[i] as Hediff_Injury; if (hediff_Injury != null && hediff_Injury.CanHealNaturally()) { return(true); } } return(false); }
public bool HasTendedAndHealingInjury() { for (int i = 0; i < hediffs.Count; i++) { Hediff_Injury hediff_Injury = hediffs[i] as Hediff_Injury; if (hediff_Injury != null && hediff_Injury.CanHealFromTending() && hediff_Injury.Severity > 0f) { return(true); } } return(false); }
public bool HasTendableInjury() { for (int i = 0; i < hediffs.Count; i++) { Hediff_Injury hediff_Injury = hediffs[i] as Hediff_Injury; if (hediff_Injury != null && hediff_Injury.TendableNow()) { return(true); } } return(false); }
public IEnumerable <BodyPartRecord> GetNaturallyHealingInjuredParts() { foreach (BodyPartRecord part in this.GetInjuredParts()) { for (int i = 0; i < this.hediffs.Count; i++) { Hediff_Injury injury = this.hediffs[i] as Hediff_Injury; if (injury != null && this.hediffs[i].Part == part && injury.CanHealNaturally()) { yield return(part); } } } }
public static string GetGeneralConditionLabel(Pawn pawn, bool shortVersion = false) { string result; if (pawn.health.Dead) { result = "Dead".Translate(); } else if (!pawn.health.capacities.CanBeAwake) { result = "Unconscious".Translate(); } else if (pawn.health.InPainShock) { result = ((!shortVersion || !"PainShockShort".CanTranslate()) ? "PainShock".Translate() : "PainShockShort".Translate()); } else if (pawn.Downed) { result = "Incapacitated".Translate(); } else { bool flag = false; for (int i = 0; i < pawn.health.hediffSet.hediffs.Count; i++) { Hediff_Injury hediff_Injury = pawn.health.hediffSet.hediffs[i] as Hediff_Injury; if (hediff_Injury != null) { if (!hediff_Injury.IsPermanent()) { flag = true; } } } if (flag) { result = "Injured".Translate(); } else if (pawn.health.hediffSet.PainTotal > 0.3f) { result = "InPain".Translate(); } else { result = "Healthy".Translate(); } } return(result); }
public IEnumerable <Hediff_Injury> GetInjuriesTendable() { int i = 0; while (i < hediffs.Count) { Hediff_Injury hediff_Injury = hediffs[i] as Hediff_Injury; if (hediff_Injury != null && hediff_Injury.TendableNow()) { yield return(hediff_Injury); } int num = i + 1; i = num; } }
public IEnumerable <BodyPartRecord> GetNaturallyHealingInjuredParts() { foreach (BodyPartRecord injuredPart in GetInjuredParts()) { for (int i = 0; i < hediffs.Count; i++) { Hediff_Injury hediff_Injury = hediffs[i] as Hediff_Injury; if (hediff_Injury != null && hediffs[i].Part == injuredPart && hediff_Injury.CanHealNaturally()) { yield return(injuredPart); break; } } } }
public IEnumerable <BodyPartRecord> GetNaturallyHealingInjuredParts() { foreach (BodyPartRecord injuredPart in GetInjuredParts()) { for (int i = 0; i < hediffs.Count; i++) { Hediff_Injury injury = hediffs[i] as Hediff_Injury; if (injury != null && hediffs[i].Part == injuredPart && injury.CanHealNaturally()) { yield return(injuredPart); /*Error: Unable to find new state assignment for yield return*/; } } } yield break; IL_0155: /*Error near IL_0156: Unexpected return in MoveNext()*/; }
public static void HealInjuryRandom(Pawn pawn, float amount) { BodyPartRecord part; if (pawn.health.hediffSet.GetInjuredParts().TryRandomElement <BodyPartRecord>(out part)) { Hediff_Injury hediff_Injury = null; foreach (Hediff_Injury item in from x in pawn.health.hediffSet.GetHediffs <Hediff_Injury>() where x.Part == part select x) { if (!item.IsOld() && (hediff_Injury == null || item.Severity > hediff_Injury.Severity)) { hediff_Injury = item; } } if (hediff_Injury != null) { hediff_Injury.Heal(amount); } } }
public static string GetGeneralConditionLabel(Pawn pawn, bool shortVersion = false) { if (pawn.health.Dead) { return("Dead".Translate()); } if (!pawn.health.capacities.CanBeAwake) { return("Unconscious".Translate()); } if (pawn.health.InPainShock) { return((!shortVersion || !"PainShockShort".CanTranslate()) ? "PainShock".Translate() : "PainShockShort".Translate()); } if (pawn.Downed) { return("Incapacitated".Translate()); } bool flag = false; for (int i = 0; i < pawn.health.hediffSet.hediffs.Count; i++) { Hediff_Injury hediff_Injury = pawn.health.hediffSet.hediffs[i] as Hediff_Injury; if (hediff_Injury != null && !hediff_Injury.IsOld()) { flag = true; } } if (flag) { return("Injured".Translate()); } if (pawn.health.hediffSet.PainTotal > 0.30000001192092896) { return("InPain".Translate()); } return("Healthy".Translate()); }
private static bool <HealthTick> m__6(Hediff_Injury x) { return(x.CanHealFromTending()); }