// Token: 0x06004B8B RID: 19339 RVA: 0x00234924 File Offset: 0x00232D24 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); } }
// // Static Methods // public static void GenerateRandomOldAgeInjuries(Pawn pawn, bool tryNotToKillPawn) { int num = 0; for (int i = 10; i < Mathf.Min(pawn.ageTracker.AgeBiologicalYears, 120); i += 10) { if (Rand.Value < 0.15f) { num++; } } for (int j = 0; j < num; j++) { IEnumerable <BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined) where x.depth == BodyPartDepth.Outside && !Mathf.Approximately(x.def.oldInjuryBaseChance, 0f) && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(x) select x; if (source.Any <BodyPartRecord>()) { BodyPartRecord bodyPartRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); DamageDef dam = AgeInjuryUtility.RandomOldInjuryDamageType(bodyPartRecord.def.frostbiteVulnerability > 0f && pawn.RaceProps.ToolUser); HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dam, pawn, bodyPartRecord); if (bodyPartRecord.def.oldInjuryBaseChance > 0f && hediffDefFromDamage.CompPropsFor(typeof(HediffComp_GetsOld)) != null) { if (Rand.Chance(bodyPartRecord.def.amputateIfGeneratedInjuredChance)) { Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, pawn, null); hediff_MissingPart.lastInjury = hediffDefFromDamage; hediff_MissingPart.TryGetComp <HediffComp_GetsOld>().IsOld = true; pawn.health.AddHediff(hediff_MissingPart, bodyPartRecord, null); if (pawn.RaceProps.Humanlike && (bodyPartRecord.def == BodyPartDefOf.LeftLeg || bodyPartRecord.def == BodyPartDefOf.RightLeg) && Rand.Chance(0.5f)) { RecipeDefOf.InstallPegLeg.Worker.ApplyOnPawn(pawn, bodyPartRecord, null, AgeInjuryUtility.emptyIngredientsList, null); } } else { Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null); hediff_Injury.Severity = (float)Rand.RangeInclusive(2, 6); hediff_Injury.TryGetComp <HediffComp_GetsOld>().IsOld = true; pawn.health.AddHediff(hediff_Injury, bodyPartRecord, null); } } } } for (int k = 1; k < pawn.ageTracker.AgeBiologicalYears; k++) { foreach (HediffGiver_Birthday current in AgeInjuryUtility.RandomHediffsToGainOnBirthday(pawn, k)) { current.TryApplyAndSimulateSeverityChange(pawn, (float)k, tryNotToKillPawn); if (pawn.Dead) { break; } } if (pawn.Dead) { break; } } }
static void Prefix(ref Hediff_Injury __instance, ref bool __result) { if (__instance.pawn.def.race.FleshType.defName == "BETAFlesh") { __result = __instance.ageTicks >= AgeTicksToStopBleeding(__instance) / 3; } }
protected void InitializeTooltip() { StringBuilder stringBuilder = new StringBuilder(); if (hediff.Part != null) { stringBuilder.Append(hediff.Part.def.LabelCap + ": "); stringBuilder.Append(" " + hediff.pawn.health.hediffSet.GetPartHealth(hediff.Part).ToString() + " / " + hediff.Part.def.GetMaxHealth(hediff.pawn).ToString()); } else { stringBuilder.Append("WholeBody".Translate()); } stringBuilder.AppendLine(); stringBuilder.AppendLine("------------------"); Hediff_Injury hediff_Injury = hediff as Hediff_Injury; string damageLabel = hediff.SeverityLabel; if (!hediff.Label.NullOrEmpty() || !damageLabel.NullOrEmpty() || !hediff.CapMods.NullOrEmpty <PawnCapacityModifier>()) { stringBuilder.Append(hediff.LabelCap); if (!damageLabel.NullOrEmpty()) { stringBuilder.Append(": " + damageLabel); } stringBuilder.AppendLine(); string tipStringExtra = hediff.TipStringExtra; if (!tipStringExtra.NullOrEmpty()) { stringBuilder.AppendLine(tipStringExtra.TrimEndNewlines().Indented()); } } tooltip = stringBuilder.ToString(); }
//public class DamageWorker_AddInjury : DamageWorker public static void WerewolfDmgFixFinalizeAndAddInjury(Pawn pawn, ref Hediff_Injury injury, ref DamageInfo dinfo) { if (!(dinfo.Amount > 0) || pawn.TryGetComp <CompWerewolf>() is not { } ww || !ww.IsWerewolf || ww.CurrentWerewolfForm == null) { return; } if (dinfo.Instigator is not Pawn a || !ShouldModifyDamage(a)) { return; } if (a.equipment?.Primary is not { } b || b.IsSilverTreated()) { return; } var math = (int)dinfo.Amount - (int)(dinfo.Amount * ww.CurrentWerewolfForm.DmgImmunity); //10% damage. Decimated damage. dinfo.SetAmount(math); injury.Severity = math; //Log.Message(dinfo.Amount.ToString()); }
private static bool AboutToRecover(Pawn pawn) { if (pawn.Downed) { return(false); } if (!HealthAIUtility.ShouldSeekMedicalRestUrgent(pawn) && !HealthAIUtility.ShouldSeekMedicalRest(pawn)) { return(true); } if (pawn.health.hediffSet.HasTendedImmunizableNotImmuneHediff()) { return(false); } float num = 0f; List <Hediff> hediffs = pawn.health.hediffSet.hediffs; 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.CanHealNaturally() || hediff_Injury.Bleeding)) { num += hediff_Injury.Severity; } } return(num < 8.0 * pawn.RaceProps.baseHealthScale); }
private void CalculateOldInjuryDamageThreshold(Pawn pawn, Hediff_Injury injury) { HediffCompProperties hediffCompProperties = injury.def.CompPropsFor(typeof(HediffComp_GetsOld)); if (hediffCompProperties == 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.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; } } }
private void CalculateOldInjuryDamageThreshold(Pawn pawn, Hediff_Injury injury) { HediffComp_GetsOld comp = injury.TryGetComp <HediffComp_GetsOld>(); if (comp == null) { return; } // No permanent injuries on solid parts, prosthetics or injuries that are already old if (injury.Part.def.IsSolid(injury.Part, pawn.health.hediffSet.hediffs) || pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(injury.Part) || injury.IsOld()) { return; } // Delicate parts get old instantly if (injury.Part.def.IsDelicate) { comp.oldDamageThreshold = injury.Severity; comp.IsOld = true; } // Check if injury is at least 10% of part health and make a random roll else if (injury.Severity >= injury.Part.def.GetMaxHealth(pawn) * 0.1f && injury.Severity > 1) { float getOldChance = injury.Part.def.oldInjuryBaseChance * comp.Props.becomeOldChance * Mathf.Pow((injury.Severity / injury.Part.def.GetMaxHealth(pawn)), 2); if (Rand.Value < getOldChance) { comp.oldDamageThreshold = Rand.Range(1, injury.Severity); } } }
public void TryHealWounds() { IEnumerable <Hediff> enumerable = from hd in this.pawn.health.hediffSet.hediffs where !hd.IsPermanent() && hd.def.isBad && hd is Hediff_Injury select hd; bool flag = enumerable != null; if (flag && canHeal) { foreach (Hediff hediff in enumerable) { Hediff_Injury Injury = hediff as Hediff_Injury; bool flag2 = Injury != null; Rand.PushState(); float chance = Rand.Value; Rand.PopState(); if (flag2 && canHeal && chance < Props.healFreshChance) { float num = Injury.Severity * 0.001f; Injury.Heal(num); // Log.Message(string.Format("num = {0}",num)); if (Props.useFood) { pawn.needs.food.CurLevel -= num; } if (Props.useRest) { pawn.needs.rest.CurLevel -= num; } // Traverse.Create(hediff_Injury).Property(name: "BleedRate").SetValue(hediff_Injury.BleedRate*0.95); } } } }
// Token: 0x06004378 RID: 17272 RVA: 0x001E8A2C File Offset: 0x001E6E2C public override bool OnHediffAdded(Pawn pawn, Hediff hediff) { if (hediff is Hediff_Injury && !pawn.health.hediffSet.PartIsMissing(hediff.Part.parent) && !pawn.health.hediffSet.PartIsMissing(hediff.Part)) { Hediff_Injury injury = hediff as Hediff_Injury; //float oldChance = injury.def.chanceToCauseNoPain; //injury.def.chanceToCauseNoPain = 70000f; injury.PostMake(); injury.ageTicks = 70000000; //injury.def.chanceToCauseNoPain = oldChance; } else if (hediff is Hediff_MissingPart && !pawn.health.hediffSet.PartIsMissing(hediff.Part.parent)) { Hediff_MissingPart missing = hediff as Hediff_MissingPart; //float oldChance = missing.def.chanceToCauseNoPain; //missing.def.chanceToCauseNoPain = 70000f; missing.PostMake(); missing.ageTicks = 70000000; //missing.def.chanceToCauseNoPain = oldChance; } if (pawn.health.Downed && !pawn.health.InPainShock) { DamageInfo info = new DamageInfo(DamageDefOf.Rotting, 17f, 0f, 0f, null, pawn.health.hediffSet.GetBrain()); pawn.Kill(info); } return(false); }
private static Hediff_Injury FindInjury(Pawn pawn, IEnumerable <BodyPartRecord> allowedBodyParts = null) { Hediff_Injury hediffInjury = null; var hediffs = pawn.health.hediffSet.hediffs; foreach (var hediff in hediffs) { if (hediff is not Hediff_Injury { Visible: true } hediffInjury2 || !hediffInjury2.def.everCurableByItem) { continue; } if (allowedBodyParts != null && !allowedBodyParts.Contains(hediffInjury2.Part)) { continue; } if (hediffInjury == null || hediffInjury2.Severity > hediffInjury.Severity) { hediffInjury = hediffInjury2; } } return(hediffInjury); }
public static void Postfix(WeatherManager __instance, Map map) { if (map.weatherManager.curWeather.defName == "LotRW_HealingRainWD") { if (Find.TickManager.TicksGame % 10 == 0) { Pawn pawn = map.mapPawns.AllPawnsSpawned.RandomElement(); if (!pawn.Position.Roofed(map)) { IEnumerable <Hediff_Injury> injuries = pawn.health.hediffSet.GetHediffs <Hediff_Injury>(); if (injuries != null && injuries.Count() > 0) { Hediff_Injury injury = injuries.RandomElement(); if (injury.CanHealNaturally() && !injury.IsPermanent()) { injury.Heal(Rand.Range(.2f, 2f)); if (Rand.Chance(.5f)) { EffectMaker.MakeEffect(ThingDef.Named("Mote_HealingWaves"), pawn.DrawPos, map, Rand.Range(.4f, .6f), 180, 1f, 0); } else { EffectMaker.MakeEffect(ThingDef.Named("Mote_HealingWaves"), pawn.DrawPos, map, Rand.Range(.4f, .6f), 180, 1f, 0, 180, .1f, .02f, .19f, false); } } } } } } }
// Verse.Hediff_Injury public static void get_VampBleedRate(Hediff_Injury __instance, ref float __result) { if (__instance.pawn is Pawn p && p.IsVampire()) { __result = 0f; } }
private static int AgeTicksToStopBleeding(Hediff_Injury __instance) { int num = 90000; float t = Mathf.Clamp(Mathf.InverseLerp(1f, 30f, __instance.Severity), 0f, 1f); return(num + Mathf.RoundToInt(Mathf.Lerp(0f, 90000f, t))); }
public virtual void Repair(Building_RepairStation repairStation) { List <Hediff_Injury> allInjuries = health.hediffSet.GetHediffs <Hediff_Injury>().ToList(); List <Hediff_MissingPart> allMissingParts = health.hediffSet.GetHediffs <Hediff_MissingPart>().ToList(); float num = Rand.Value; if ((allInjuries.Count == 0 || num > 0.6) && allMissingParts.Count > 0 && repairStation != null && repairStation.HasEnoughOf(repairStation.Def.repairThingDef, repairStation.Def.repairCostAmount)) { Hediff_MissingPart hediff = allMissingParts.RandomElement(); if (repairStation.TakeSomeOf(repairStation.Def.repairThingDef, repairStation.Def.repairCostAmount)) { health.hediffSet.RestorePart(hediff.Part.HighestMissingPart(this)); } } else if (allInjuries.Count > 0) { Hediff_Injury hediff = allInjuries.RandomElement(); if (hediff.def.injuryProps.fullyHealableOnlyByTreatment) { HediffComp_Treatable treatable = hediff.TryGetComp <HediffComp_Treatable>(); if (treatable != null && !treatable.treatedWithMedicine) { treatable.NewlyTreated(1f, ThingDefOf.Medicine); } } hediff.DirectHeal(repairStation.Def.repairAmount); } }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { float num = pawn.health.hediffSet.hediffs.Count; for (int i = 0; (float)i < num; i++) { if (!GenCollection.TryRandomElement <BodyPartRecord>(pawn.health.hediffSet.GetInjuredParts(), out part)) { break; } Hediff_Injury val = null; foreach (Hediff_Injury item in from x in pawn.health.hediffSet.GetHediffs <Hediff_Injury>() where x.Part == part select x) { if (val != null) { ((Hediff)val).Heal(2000f); if (val != null) { pawn.health.RemoveHediff((Hediff)(object)val); } } } pawn.health.AddHediff(WPVehicleHediffDefOf.WPVehicleReboot, (BodyPartRecord)null, (DamageInfo?)null, (DamageResult)null); } }
static bool Prefix(DamageWorker_AddInjury __instance, DamageInfo dinfo, Pawn pawn, float totalDamage, DamageWorker.DamageResult result) { var hitPart = dinfo.HitPart; if (hitPart.IsInGroup(CE_BodyPartGroupDefOf.OutsideSquishy)) { var parent = hitPart.parent; if (parent != null) { dinfo.SetHitPart(parent); if (pawn.health.hediffSet.GetPartHealth(parent) != 0f && parent.coverageAbs > 0f) { Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, parent), 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; } FinalizeAndAddInjury.Invoke(__instance, new object[] { pawn, hediff_Injury, dinfo, result }); } } } return(true); }
// Token: 0x06004BC8 RID: 19400 RVA: 0x0023675C File Offset: 0x00234B5C public static void HealNonPermanentInjuriesAndRestoreLegs(Pawn p) { if (p.Dead) { return; } HealthShardTendUtility.tmpHediffs.Clear(); HealthShardTendUtility.tmpHediffs.AddRange(p.health.hediffSet.hediffs); for (int i = 0; i < HealthShardTendUtility.tmpHediffs.Count; i++) { Hediff_Injury hediff_Injury = HealthShardTendUtility.tmpHediffs[i] as Hediff_Injury; if (hediff_Injury != null && !hediff_Injury.IsPermanent()) { p.health.RemoveHediff(hediff_Injury); } else { Hediff_MissingPart hediff_MissingPart = HealthShardTendUtility.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); } } } HealthShardTendUtility.tmpHediffs.Clear(); }
public static void CleanBite(Pawn actor, Pawn victim) { HediffWithComps fangs = actor.GetVampFangs(); string dmgLabel; float dmgAmount; DamageDef dmgDef; RulePackDef dmgRules; if (fangs != null && TryGetFangsDmgInfo(fangs, out dmgLabel, out dmgAmount, out dmgDef, out dmgRules)) { Hediff_Injury neckInjury = (Hediff_Injury)victim.health.hediffSet.hediffs.FirstOrDefault(x => x is Hediff_Injury y && !y.IsPermanent() && y?.Part?.def == BodyPartDefOf.Neck); if (neckInjury == null) { neckInjury = (Hediff_Injury)victim.health.hediffSet.hediffs.FirstOrDefault(x => x is Hediff_Injury y && !y.IsPermanent()); } if (neckInjury != null) { neckInjury.Heal((int)neckInjury.Severity + 1); Find.BattleLog.Add( new BattleLogEntry_StateTransition(victim, RulePackDef.Named("ROMV_BiteCleaned"), actor, null, null) ); if (victim.IsGhoul() && victim?.VampComp()?.ThrallData?.BondStage == BondStage.Thrall) { TryRemoveHarmedMemory(actor, victim); } else if (!victim.health.capacities.CanBeAwake) { TryRemoveHarmedMemory(actor, victim); } } } }
private static void HealToStanding(Pawn pawn, BodyPartRecord part) { bool shouldStop = false; float extraHealth = 100f; //TODO: no magic number; extraHealth *= pawn.HealthScale; float healPerIteration = 10f; float totalExtraHealed = 0f; int guard = 0; while (totalExtraHealed <= extraHealth && guard < 1000) { Hediff_Injury hediff_Injury = pawn.health.hediffSet.GetHediffs <Hediff_Injury>().Where(new Func <Hediff_Injury, bool>(HediffUtility.CanHealNaturally)).RandomElement <Hediff_Injury>(); if (hediff_Injury == null || !pawn.Downed) { shouldStop = true; } hediff_Injury.Heal(healPerIteration); if (shouldStop) { totalExtraHealed += healPerIteration; } guard++; } pawn.jobs.EndCurrentJob(JobCondition.InterruptForced); if (pawn.GetLord() == null || pawn.GetLord().LordJob == null) { LordMaker.MakeNewLord(Faction.OfPlayer, new LordJob_SearchAndDestroy(), pawn.Map, new List <Pawn> { pawn }); } Find.LetterStack.ReceiveLetter("WTH_Letter_HealedToStanding_Label".Translate(), "WTH_Letter_HealedToStanding_Description".Translate(), LetterDefOf.ThreatBig, pawn); }
// Token: 0x06004B89 RID: 19337 RVA: 0x002347B4 File Offset: 0x00232BB4 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 PostFix(Hediff_Injury __instance, ref float __result) { if (__result > 0) { // Scales it down by (Real HP : Displayed HP) __result = __result * __instance.Part.def.GetRawMaxHealth(__instance.pawn) / __instance.Part.def.GetMaxHealth(__instance.pawn, __instance.Part); } }
private static bool Prefix(Hediff_Injury __instance, ref float amount) { if (__instance.pawn.def is RaceAddonThingDef thingDef) { amount *= thingDef.raceAddonSettings.healthSetting.healingFactor; } return(true); }
// Self healing //private int timerRepairDamage = 0; private void TryHealDamagedBodyPartOfRobot(X2_AIRobot robot) { //timerRepairDamage--; //if (timerRepairDamage > 0) // return; //timerRepairDamage = 300; if (robot == null || !Verse.Gen.IsHashIntervalTick(robot, 300)) { return; } IEnumerable <Hediff_Injury> hediff_injuries = (from x in robot.health.hediffSet.GetHediffs <Hediff_Injury>() where x.CanHealFromTending() || x.CanHealNaturally() select x); // Apply Treated, but not healing! if (robot.health.HasHediffsNeedingTend(false)) { float quality = (Rand.Value); int batchPosition = 0; foreach (Hediff_Injury injury in from x in robot.health.hediffSet.GetInjuriesTendable() orderby x.Severity descending select x) { injury.Tended(quality, batchPosition); batchPosition++; if (batchPosition >= 1) { break; } } } // Apply healing if (hediff_injuries != null && hediff_injuries.Count() > 0) { Hediff_Injury hediff_Injury2 = hediff_injuries.RandomElement(); float tendQuality = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality; float num2 = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality)); ////hediff_Injury2.Heal(22f * num2 * robot.HealthScale * 0.01f); -> At quality 0.5 --> 0.066 healed. //Log.Error("Calculation: " + (GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality)).ToString())); //Log.Error("Healing: " + (22f * num2 * robot.HealthScale * 0.1f).ToString()); //Log.Error("PRE:" + hediff_Injury2.Severity.ToString()); //hediff_Injury2.Heal(1f); hediff_Injury2.Heal(22f * num2 * robot.HealthScale * 0.1f * 0.5f); //Log.Error("POST:" + hediff_Injury2.Severity.ToString()); // Throw Healing Mote MoteMaker.ThrowMetaIcon(this.Position, this.Map, ThingDefOf.Mote_HealingCross); } }
private void SetRecallHediffs() { comp.recallHediffList = new List <Hediff>(); comp.recallHediffList.Clear(); comp.recallInjuriesList = new List <Hediff_Injury>(); comp.recallInjuriesList.Clear(); for (int i = 0; i < this.CasterPawn.health.hediffSet.hediffs.Count; i++) { if (!this.CasterPawn.health.hediffSet.hediffs[i].IsPermanent() && this.CasterPawn.health.hediffSet.hediffs[i].def != TorannMagicDefOf.TM_MagicUserHD && !this.CasterPawn.health.hediffSet.hediffs[i].def.defName.Contains("TM_HediffEnchantment") && !this.CasterPawn.health.hediffSet.hediffs[i].def.defName.Contains("TM_Artifact") && this.CasterPawn.health.hediffSet.hediffs[i].def != TorannMagicDefOf.TM_MightUserHD && this.CasterPawn.health.hediffSet.hediffs[i].def != TorannMagicDefOf.TM_BloodHD && this.CasterPawn.health.hediffSet.hediffs[i].def != TorannMagicDefOf.TM_ChiHD && this.CasterPawn.health.hediffSet.hediffs[i].def != TorannMagicDefOf.TM_PsionicHD) { if (this.CasterPawn.health.hediffSet.hediffs[i] is Hediff_Injury) { Hediff_Injury rhd = this.CasterPawn.health.hediffSet.hediffs[i] as Hediff_Injury; Hediff_Injury hediff = new Hediff_Injury(); //hediff = TM_Calc.Clone<Hediff>(this.CasterPawn.health.hediffSet.hediffs[i]); hediff.def = rhd.def; hediff.Part = rhd.Part; Traverse.Create(root: hediff).Field(name: "visible").SetValue(rhd.Visible); Traverse.Create(root: hediff).Field(name: "severityInt").SetValue(rhd.Severity); //hediff.Severity = rhd.Severity; hediff.ageTicks = rhd.ageTicks; comp.recallInjuriesList.Add(hediff); } else if (this.CasterPawn.health.hediffSet.hediffs[i] is Hediff_MissingPart || this.CasterPawn.health.hediffSet.hediffs[i] is Hediff_AddedPart || this.CasterPawn.health.hediffSet.hediffs[i].def.defName == "PsychicAmplifier") { //do nothing } else if (this.CasterPawn.health.hediffSet.hediffs[i] is Hediff_Addiction) { //Hediff_Addiction rhd = this.CasterPawn.health.hediffSet.hediffs[i] as Hediff_Addiction; } else if (this.CasterPawn.health.hediffSet.hediffs[i].def.defName == "LuciferiumHigh") { //do nothing } else { Hediff rhd = this.CasterPawn.health.hediffSet.hediffs[i]; //Log.Message("sev def is " + rhd.def.defName); Hediff hediff = new Hediff(); //hediff = TM_Calc.Clone<Hediff>(this.CasterPawn.health.hediffSet.hediffs[i]); hediff.def = rhd.def; hediff.Part = rhd.Part; Traverse.Create(root: hediff).Field(name: "visible").SetValue(rhd.Visible); Traverse.Create(root: hediff).Field(name: "severityInt").SetValue(rhd.Severity); hediff.Severity = rhd.Severity; hediff.ageTicks = rhd.ageTicks; comp.recallHediffList.Add(hediff); } //Log.Message("adding " + this.CasterPawn.health.hediffSet.hediffs[i].def + " at severity " + this.CasterPawn.health.hediffSet.hediffs[i].Severity); } } //Log.Message("hediffs set"); }
public static void GetOptimalHediffsToTendWithSingleTreatment(Pawn patient, bool usingMedicine, List <Hediff> outHediffsToTend, List <Hediff> tendableHediffsInTendPriorityOrder = null) { outHediffsToTend.Clear(); TendUtility.tmpHediffs.Clear(); if (tendableHediffsInTendPriorityOrder != null) { TendUtility.tmpHediffs.AddRange(tendableHediffsInTendPriorityOrder); } else { List <Hediff> hediffs = patient.health.hediffSet.hediffs; for (int i = 0; i < hediffs.Count; i++) { if (hediffs[i].TendableNow) { TendUtility.tmpHediffs.Add(hediffs[i]); } } TendUtility.SortByTendPriority(TendUtility.tmpHediffs); } if (TendUtility.tmpHediffs.Any()) { Hediff hediff = TendUtility.tmpHediffs[0]; outHediffsToTend.Add(hediff); HediffCompProperties_TendDuration hediffCompProperties_TendDuration = hediff.def.CompProps <HediffCompProperties_TendDuration>(); if (hediffCompProperties_TendDuration != null && hediffCompProperties_TendDuration.tendAllAtOnce) { for (int j = 0; j < TendUtility.tmpHediffs.Count; j++) { if (TendUtility.tmpHediffs[j] != hediff && TendUtility.tmpHediffs[j].def == hediff.def) { outHediffsToTend.Add(TendUtility.tmpHediffs[j]); } } } else if (hediff is Hediff_Injury && usingMedicine) { float num = hediff.Severity; for (int k = 0; k < TendUtility.tmpHediffs.Count; k++) { if (TendUtility.tmpHediffs[k] != hediff) { Hediff_Injury hediff_Injury = TendUtility.tmpHediffs[k] as Hediff_Injury; if (hediff_Injury != null) { float severity = hediff_Injury.Severity; if (num + severity <= 20.0) { num += severity; outHediffsToTend.Add(hediff_Injury); } } } } } TendUtility.tmpHediffs.Clear(); } }
/// <summary> /// Boats can not be tended, and thus don't heal. They must be repaired instead /// </summary> /// <param name="hd"></param> /// <param name="__result"></param> /// <returns></returns> public static bool VehiclesDontHealTended(Hediff_Injury hd, ref bool __result) { if (hd.pawn is VehiclePawn) { __result = false; return(false); } return(true); }
static bool Prefix(Hediff_Injury __instance, ref DamageInfo?dinfo) { if (__instance.comps != null) { for (int i = 0; i < __instance.comps.Count; i++) { __instance.comps[i].CompPostPostAdd(dinfo); } } return(false); }
public static void DamagePart(Pawn p, int damage, BodyPartRecord part) { HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(DamageDefOf.SurgicalCut, p, part); Hediff_Injury injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, p, part); injury.Severity = damage; p.health.AddHediff(injury, part, new DamageInfo(DamageDefOf.SurgicalCut, damage, 999f, -1f, null, part)); GenLeaving.DropFilthDueToDamage(p, damage); }
public static void Prefix(Hediff_Injury __instance, ref float amount) { if (__instance.def == HediffDefOf.Burn) { var skin = __instance.pawn.health.hediffSet.GetFirstHediffOfDef(HML_DefOf.HRM_SyntheticSkin); if (skin != null) { amount *= 2f; } } }
private void CalculateOldInjuryDamageThreshold(Pawn pawn, Hediff_Injury injury) { HediffCompProperties hediffCompProperties = injury.def.CompPropsFor(typeof(HediffComp_GetsOld)); if (hediffCompProperties == 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 flag = injury.Part.def.oldInjuryBaseChance >= 0.8f; if ((Rand.Value <= injury.Part.def.oldInjuryBaseChance * hediffCompProperties.becomeOldChance && injury.Severity >= injury.Part.def.GetMaxHealth(pawn) * 0.25f && injury.Severity >= 7f) || flag) { 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 (flag) { hediffComp_GetsOld.oldDamageThreshold = injury.Severity; hediffComp_GetsOld.isOld = true; } } }
private void CheckDuplicateDamageToOuterParts(DamageInfo dinfo, Pawn pawn, Hediff_Injury injury, bool involveArmor, ref DamageWorker_AddInjuryCR.LocalInjuryResult result) { if (!dinfo.AllowDamagePropagation) { return; } if (dinfo.Def.harmAllLayersUntilOutside && injury.Part.depth == BodyPartDepth.Inside) { BodyPartRecord parent = injury.Part.parent; do { if (pawn.health.hediffSet.GetPartHealth(parent) != 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 = injury.source; hediff_Injury.sourceBodyPartGroup = injury.sourceBodyPartGroup; hediff_Injury.Severity = (float)dinfo.Amount; if (involveArmor) { hediff_Injury.Severity = (float)Utility.GetAfterArmorDamage(pawn, dinfo.Amount, parent, dinfo); } if (hediff_Injury.Severity <= 0f) { hediff_Injury.Severity = 1f; } result.lastHitPart = hediff_Injury.Part; this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, ref result); } if (parent.depth == BodyPartDepth.Outside) { break; } parent = parent.parent; } while (parent != null); } }
private void CheckPropagateDamageToInnerSolidParts(DamageInfo dinfo, Pawn pawn, Hediff_Injury injury, bool involveArmor, ref DamageWorker_AddInjuryCR.LocalInjuryResult result) { if (!dinfo.AllowDamagePropagation) { return; } if (Rand.Value >= HealthTunings.ChanceToAdditionallyDamageInnerSolidPart) { return; } if (dinfo.Def.hasChanceToAdditionallyDamageInnerSolidParts && !injury.Part.def.IsSolid(injury.Part, pawn.health.hediffSet.hediffs) && injury.Part.depth == BodyPartDepth.Outside) { IEnumerable<BodyPartRecord> source = from x in pawn.health.hediffSet.GetNotMissingParts(null, null) where x.parent == injury.Part && x.def.IsSolid(x, pawn.health.hediffSet.hediffs) && x.depth == BodyPartDepth.Inside select x; BodyPartRecord part; if (source.TryRandomElementByWeight((BodyPartRecord x) => x.absoluteFleshCoverage, out part)) { HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, part); Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(hediffDefFromDamage, pawn, null); hediff_Injury.Part = part; hediff_Injury.source = injury.source; hediff_Injury.sourceBodyPartGroup = injury.sourceBodyPartGroup; hediff_Injury.Severity = (float)(dinfo.Amount / 2); if (involveArmor) { hediff_Injury.Severity = (float)Utility.GetAfterArmorDamage(pawn, dinfo.Amount / 2, part, dinfo); } if (hediff_Injury.Severity <= 0f) { return; } result.lastHitPart = hediff_Injury.Part; this.FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, ref result); } } }
private void FinalizeAndAddInjury(Pawn pawn, Hediff_Injury injury, DamageInfo dinfo, ref DamageWorker_AddInjuryCR.LocalInjuryResult result) { this.CalculateOldInjuryDamageThreshold(pawn, injury); result.totalDamageDealt += injury.Severity; pawn.health.AddHediff(injury, null, new DamageInfo?(dinfo)); }
private static bool IsHeadshot(DamageInfo dinfo, Hediff_Injury injury, Pawn pawn) { return !dinfo.InstantOldInjury && injury.Part.groups.Contains(BodyPartGroupDefOf.FullHead) && dinfo.Def == DamageDefOf.Bullet; }