/// <summary> /// Harmony postfix method for Hediff_PartBaseNatural.Tick and Hediff_PartBaseNatural.Tick. Applies organ contraction /// </summary> /// <param name="__instance"></param> public static void PartBase_Tick_Postfix(HediffWithComps __instance) { // Only runs once per 14 hours 40 minutes (to contract by 50% in 30 days) if (__instance.ageTicks % 36000 != 0) { return; } // Skip unspawned pawns if (!__instance.pawn.Spawned) { return; } // Only works for orifices if (!IsOrifice(__instance)) { return; } // Only contracts organs more than 0.5 in size if (__instance.Severity <= 0.5) { return; } // Contract the part by 1% __instance.Heal(0.01f); }
public void TrySealWounds() { IEnumerable <Hediff> enumerable = from hd in this.pawn.health.hediffSet.hediffs where hd.Bleeding select hd; bool flag = enumerable != null; if (flag && canHeal) { foreach (Hediff hediff in enumerable) { HediffWithComps hediffWithComps = hediff as HediffWithComps; bool flag2 = hediffWithComps != null; Rand.PushState(); float chance = Rand.Value; Rand.PopState(); if (flag2 && canHeal && chance < Props.sealWoundsChance) { HediffComp_TendDuration hediffComp_TendDuration = hediffWithComps.TryGetCompFast <HediffComp_TendDuration>(); hediffComp_TendDuration.tendQuality = 0f; hediffComp_TendDuration.tendTicksLeft = Find.TickManager.TicksGame; this.pawn.health.Notify_HediffChanged(hediff); } } } }
private static bool NeedUpdate(HediffWithComps hediff) { int id = hediff.loadID; int curTick = Find.TickManager.ticksGameInt; if (!LeaderHediffLastUpdate.ContainsKey(id)) { #if DEBUG Log.Message($"[EO-ColonyLeadership] new. update HediffLeader. pawn: {hediff.pawn.LabelCap}"); #endif LeaderHediffLastUpdate.Add(id, curTick); return(true); } if (Math.Abs(curTick - LeaderHediffLastUpdate[id]) >= UpdateDelay) { #if DEBUG Log.Message($"[EO-ColonyLeadership] update HediffLeader. pawn: {hediff.pawn.LabelCap}"); #endif LeaderHediffLastUpdate[id] = curTick; return(true); } return(false); }
public override bool OnHediffAdded(Pawn pawn, Hediff hediff) { //Replace bleeding with coolant loss. (Vampires Fix) if (hediff.def == RimWorld.HediffDefOf.BloodLoss) { HealthUtility.AdjustSeverity(pawn, HediffDefOf.ChjCoolantLoss, hediff.Severity); hediff.Severity = 0f; return(true); } //If it is not a injury, stop here. if (!(hediff is Hediff_Injury)) { return(false); } HediffWithComps hediffWithComps = hediff as HediffWithComps; if (hediffWithComps == null) { return(false); } hediffWithComps.comps.RemoveAll(hediffComp => hediffComp is HediffComp_Infecter); return(true); }
public void SpecialPostAdd(DamageInfo?dinfo) { base.CompPostPostAdd(dinfo); this.parent.pawn.health.RestorePart(this.parent.Part, this.parent, false); for (int i = 0; i < this.parent.Part.parts.Count; i++) { if (this.parent.Part.Index == 1) { Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, this.parent.pawn, null); hediff_MissingPart.IsFresh = true; hediff_MissingPart.lastInjury = HediffDefOf.SurgicalCut; hediff_MissingPart.Part = this.parent.Part.parts[i]; this.parent.pawn.health.hediffSet.AddDirect(hediff_MissingPart, null, null); } else if (this.Props.generateModule) { HediffWithComps hediff_BodyPartModule = (HediffWithComps)HediffMaker.MakeHediff(MSE_HediffDefOf.MSE_BodyPartModule, this.parent.pawn, null); hediff_BodyPartModule.Part = this.parent.Part.parts[i]; this.parent.pawn.health.hediffSet.AddDirect(hediff_BodyPartModule, null, null); } } MSE_VanillaExtender.HediffApplyHediffs(this.parent, this.parent.pawn, this.parent.Part); }
public static void Pawn_GizmosFromHediffComps(Pawn __instance, ref IEnumerable <Gizmo> __result) { if (__instance == null) { Log.Warning("HediffGizmosFromComps cannot access Apparel."); return; } if (__result == null) { Log.Warning("HediffGizmosFromComps creating new list."); return; } // Find all comps on the apparel. If any have gizmos, add them to the result returned from apparel already (typically empty set). List <Gizmo> l = new List <Gizmo>(__result); for (int o = 0; o < AdeptusHediffUtility.ShieldHediffs.Count; o++) { HediffWithComps item = __instance.health.hediffSet.GetFirstHediffOfDef(AdeptusHediffUtility.ShieldHediffs[o]) as HediffWithComps; if (item != null) { if (item.TryGetCompFast <HediffComp_Shield>() is HediffComp_Shield _Shield) { foreach (Gizmo gizmo in _Shield.GetShieldGizmos()) { l.Add(gizmo); } } } } __result = l; }
//https://github.com/Mehni/kNumbers/blob/fc9320b45bc0a8c41b2f2c67f68107fb89e84848/Numbers/PawnColumnWorkers/PawnColumnWorker_DiseaseProgression.cs#L152 private static float FindMostSevereHediffDelta(Pawn pawn) { IEnumerable <HediffWithComps> tmplist = pawn.health.hediffSet.hediffs.Where(x => x.Visible && x is HediffWithComps && !x.FullyImmune()).Cast <HediffWithComps>(); float delta = float.MinValue; HediffWithComps mostSevereHediff = null; foreach (HediffWithComps hediff in tmplist) { HediffComp_Immunizable hediffCompImmunizable = hediff.TryGetComp <HediffComp_Immunizable>(); if (hediffCompImmunizable == null) { continue; } if (hediffCompImmunizable.Immunity - hediff.Severity > delta) { delta = hediffCompImmunizable.Immunity - hediff.Severity; mostSevereHediff = hediff; } } return(delta); }
public override void PostIngested(Pawn ingester) { base.PostIngested(ingester); if (ingester.health.hediffSet.HasHediff(InfectionDefOf.MuscleParasites)) { HediffWithComps hediff = (HediffWithComps)ingester.health.hediffSet.GetFirstHediffOfDef(InfectionDefOf.MuscleParasites); hediff.comps.First(h => h is HediffComp_TendDuration).CompTended(1.25f, 0); } if (ingester.health.hediffSet.HasHediff(InfectionDefOf.GutWorms)) { HediffWithComps hediff = (HediffWithComps)ingester.health.hediffSet.GetFirstHediffOfDef(InfectionDefOf.GutWorms); hediff.comps.First(h => h is HediffComp_TendDuration).CompTended(1.25f, 0); } if (ingester.health.hediffSet.HasHediff(InfectionDefOf.FibrousMechanites)) { HediffWithComps hediff = (HediffWithComps)ingester.health.hediffSet.GetFirstHediffOfDef(InfectionDefOf.FibrousMechanites); HediffComp hediffComp = hediff.comps.First(h => h is HediffComp_Disappears); Traverse field = Traverse.Create(hediffComp).Field("ticksToDisappear"); int ticksToDisappear = field.GetValue <int>(); field.SetValue(ticksToDisappear - 180000); } if (ingester.health.hediffSet.HasHediff(InfectionDefOf.SensoryMechanites)) { HediffWithComps hediff = (HediffWithComps)ingester.health.hediffSet.GetFirstHediffOfDef(InfectionDefOf.SensoryMechanites); HediffComp hediffComp = hediff.comps.First(h => h is HediffComp_Disappears); Traverse field = Traverse.Create(hediffComp).Field("ticksToDisappear"); int ticksToDisappear = field.GetValue <int>(); field.SetValue(ticksToDisappear - 180000); } if (ingester.health.hediffSet.HasHediff(HediffDefOf.FoodPoisoning)) { ingester.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.FoodPoisoning).Heal(1); } }
private static List <Thing_withMeta> getCompsWithSeverity(Pawn p) { List <Thing_withMeta> twms = new List <Thing_withMeta>(); foreach (Hediff h in p.health.hediffSet.hediffs) { if (h.Visible && h is HediffWithComps) { HediffWithComps hwc = (HediffWithComps)h; foreach (HediffComp hc in hwc.comps) { if (hc is HediffComp_Immunizable) { HediffComp_Immunizable hci = (HediffComp_Immunizable)hc; if (hci.Immunity > 0 && hci.Immunity < 1) { float daysToImmune = (1 - hci.Immunity) / hci.Props.immunityPerDaySick; float daysToDeath = (1 - h.Severity) / hci.Props.severityPerDayNotImmune; float newQuant = daysToImmune - daysToDeath; twms.Add(new Thing_withMeta() { thing = p, meta = (new object[] { h.LabelBase, h.Severity, hci.Immunity, newQuant }) }); } } } } } return(twms); }
public void TryHealWounds() { IEnumerable <Hediff> enumerable = from hd in pawn.health.hediffSet.hediffs where !hd.IsTended() select hd; if (enumerable != null) { foreach (Hediff item in enumerable) { HediffWithComps val = item as HediffWithComps; if (val != null && val.TendableNow()) { if (val.Bleeding) { //Log.Message("TrySealWounds " + xxx.get_pawnname(pawn) + ", Bleeding " + item.Label); HediffComp_TendDuration val2 = HediffUtility.TryGetComp <HediffComp_TendDuration>(val); val2.tendQuality = 2f; val2.tendTicksLeft = Find.TickManager.TicksGame; pawn.health.Notify_HediffChanged(item); } // infections etc else // if (val.def.lethalSeverity > 0f) { //Log.Message("TryHeal " + xxx.get_pawnname(pawn) + ", infection(?) " + item.Label); HediffComp_TendDuration val2 = HediffUtility.TryGetComp <HediffComp_TendDuration>(val); val2.tendQuality = 2f; val2.tendTicksLeft = Find.TickManager.TicksGame; pawn.health.Notify_HediffChanged(item); } } } } }
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 PartSystem(HediffWithComps __instance, DamageInfo?dinfo) { HediffComp_PartModule partModule = __instance.TryGetComp <HediffComp_PartModule>(); if (partModule != null) { partModule.SpecialPostAdd(dinfo); } }
public override bool CanBeUsedBy(Pawn p, out string failReason) { bool selected = Find.Selector.SelectedObjects.Contains(p); if (p.health.hediffSet.HasHediff(YautjaDefOf.RRY_Hediff_BloodedUM)) { Hediff blooded = p.health.hediffSet.GetFirstHediffOfDef(YautjaDefOf.RRY_Hediff_BloodedUM); Comp_Yautja _Yautja = p.TryGetComp <Comp_Yautja>(); HediffWithComps hediff = (HediffWithComps)blooded; HediffComp_BloodedYautja comp = blooded.TryGetComp <HediffComp_BloodedYautja>(); /* * if (selected) Log.Message(string.Format("{0}", _Yautja.corpse)); * if (selected) Log.Message(string.Format("{0}", _Yautja.pawn.Corpse)); * if (selected) Log.Message(string.Format("{0}", _Yautja.pawn)); * if (selected) Log.Message(string.Format("{0}", _Yautja.MarkedhediffDef)); */ ThingDef def = _Yautja.pawn.Corpse.InnerPawn.kindDef.race; if (this.parent is Corpse corpse) { this.corpse = corpse; /* * Log.Message(string.Format("this.parent is Corpse corpse")); * Log.Message(string.Format("corpse.InnerPawn.kindDef.race: {0}, def: {1}", corpse.InnerPawn.kindDef.race, def)); */ if (corpse.InnerPawn.kindDef.race == def) { failReason = null; return(true); } else { failReason = "Wrong race"; return(false); } } else { failReason = "not a corpse"; return(false); } /* * if (YautjaBloodedUtility.bloodmatch(marked, (Corpse)this.parent)) * { * failReason = null; * return true; * } */ } else { failReason = "Doesnt need marking"; return(false); } }
// Token: 0x06004CA8 RID: 19624 RVA: 0x0023A458 File Offset: 0x00238858 public static bool FullyImmune(this Hediff hd) { HediffWithComps hediffWithComps = hd as HediffWithComps; if (hediffWithComps == null) { return(false); } HediffComp_Immunizable hediffComp_Immunizable = hediffWithComps.TryGetCompFast <HediffComp_Immunizable>(); return(hediffComp_Immunizable != null && hediffComp_Immunizable.FullyImmune); }
// Token: 0x06004CA7 RID: 19623 RVA: 0x0023A424 File Offset: 0x00238824 public static bool IsPermanent(this Hediff hd) { HediffWithComps hediffWithComps = hd as HediffWithComps; if (hediffWithComps == null) { return(false); } HediffComp_GetsPermanent hediffComp_GetsPermanent = hediffWithComps.TryGetCompFast <HediffComp_GetsPermanent>(); return(hediffComp_GetsPermanent != null && hediffComp_GetsPermanent.IsPermanent); }
// Token: 0x06004CA6 RID: 19622 RVA: 0x0023A3F0 File Offset: 0x002387F0 public static bool IsTended(this Hediff hd) { HediffWithComps hediffWithComps = hd as HediffWithComps; if (hediffWithComps == null) { return(false); } HediffComp_TendDuration hediffComp_TendDuration = hediffWithComps.TryGetCompFast <HediffComp_TendDuration>(); return(hediffComp_TendDuration != null && hediffComp_TendDuration.IsTended); }
public static void Postfix( HediffWithComps __instance ) { if (__instance.pawn is Pawn pawn && pawn.Spawned && pawn.TryGetComp <Comp_NightVision>() is Comp_NightVision comp ) { comp.CheckAndAddHediff(__instance, __instance.Part); } }
public static void Postfix(HediffWithComps __instance, ref float __result) { if (__result > 0) { // Check for stabilized comp HediffComp_Stabilize comp = __instance.TryGetComp <HediffComp_Stabilize>(); if (comp != null) { __result = __result * (comp.BleedModifier); } } }
internal static T GetHediffComp <T>(this HediffWithComps hediff) where T : HediffComp { var comps = hediff.comps; for (int i = 0, compCount = comps.Count; i < compCount; i++) { if (comps[i] is T comp) { return(comp); } } return(null); }
public float calcSeverityForHediff(HediffWithComps item) { float change = 0f; foreach (var comp in item.comps) { if (comp is HediffComp_SeverityPerDay sev) { sev.CompPostTick(ref change); } } return(change); }
public override void Effect(Pawn target) { CasterPawn.Drawer.Notify_DebugAffected(); MoteMaker.ThrowText(this.CasterPawn.DrawPos, this.CasterPawn.Map, AbilityUser.StringsToTranslate.AU_CastSuccess, -1f); HediffWithComps hediff = (HediffWithComps)HediffMaker.MakeHediff(VampDefOf.ROMV_MindReadingHediff, this.CasterPawn, null); if (hediff.TryGetComp <HediffComp_ReadMind>() is HediffComp_ReadMind rm) { rm.MindBeingRead = target; } hediff.Severity = 1.0f; this.CasterPawn.health.AddHediff(hediff, null, null); }
public void SpecialPostAdd(DamageInfo?dinfo) { base.CompPostPostAdd(dinfo); this.parent.pawn.health.RestorePart(this.parent.Part, this.parent, false); for (int i = 0; i < this.parent.Part.parts.Count; i++) { HediffWithComps hediff_BodyPartModule = (HediffWithComps)HediffMaker.MakeHediff(MSE_HediffDefOf.MSE_BodyPartModule, this.parent.pawn, null); hediff_BodyPartModule.Part = this.parent.Part.parts[i]; this.parent.pawn.health.hediffSet.AddDirect(hediff_BodyPartModule, null, null); } MSE_VanillaExtender.HediffApplyHediffs(this.parent, this.parent.pawn, this.parent.Part); }
public static void Impact_CanHit_Postfix(ref Projectile __instance, Thing thing, LocalTargetInfo ___intendedTarget, ref bool __result) { if (phaseHediffs == null) { // if (AMAMod.Dev) Log.Message("Projectile_CanHit_PhaseShifter_Patch phaseHediffs is null, Populating"); phaseHediffs = DefDatabase <HediffDef> .AllDefsListForReading.FindAll(x => x.HasComp(typeof(HediffComp_PhaseShifter))); // if (AMAMod.Dev) Log.Message("Projectile_CanHit_PhaseShifter_Patch phaseHediffs Populated: " + phaseHediffs.Count); } if (thing != null) { Pawn hitPawn = thing as Pawn; if (hitPawn != null) { for (int i = 0; i < phaseHediffs.Count; i++) { HediffWithComps item = hitPawn.health.hediffSet.GetFirstHediffOfDef(phaseHediffs[i]) as HediffWithComps; if (item != null) { List <Hediff> list = hitPawn.health.hediffSet.hediffs.FindAll(x => phaseHediffs.Contains(x.def)); foreach (Hediff hediff in list) { HediffComp_PhaseShifter _Shifter = hediff.TryGetCompFast <HediffComp_PhaseShifter>(); if (_Shifter != null) { if (_Shifter.phasedfor.Contains(__instance)) { __result = false; } else { if (!_Shifter.isPhasedIn) { _Shifter.phasedfor.Add(__instance); if (_Shifter.phasedNotifcationTick == 0) { MoteMaker.ThrowText(hitPawn.Position.ToVector3(), hitPawn.Map, "AdeptusMechanicus.Phased_Out".Translate(__instance.LabelCap, hitPawn.LabelShortCap), 3f); _Shifter.phasedNotifcationTick = _Shifter.Props.minPhasedNotifcation.SecondsToTicks(); } __result = false; } } } } } } } } }
public static bool CanBeStabilized(this Hediff diff) { HediffWithComps hediff = diff as HediffWithComps; if (hediff == null) { return(false); } if (hediff.BleedRate == 0f || hediff.IsTended() || hediff.IsPermanent()) { return(false); } HediffComp_Stabilize comp = hediff.TryGetComp <HediffComp_Stabilize>(); return(comp != null && !comp.Stabilized); }
public static bool IsOld(this Hediff hd) { HediffWithComps hediffWithComps = hd as HediffWithComps; if (hediffWithComps == null) { return(false); } HediffComp_GetsOld hediffComp_GetsOld = hediffWithComps.TryGetComp <HediffComp_GetsOld>(); if (hediffComp_GetsOld == null) { return(false); } return(hediffComp_GetsOld.IsOld); }
public bool HasAnyDisease(Pawn p) { foreach (Hediff h in p.health.hediffSet.hediffs) { HediffWithComps hwc = h as HediffWithComps; HediffComp_Immunizable hci = null; if (hwc != null) { hci = hwc.TryGetComp <HediffComp_Immunizable>(); } if (hci != null) { return(true); } } return(false); }
public override void ApplyOnPawn(Pawn pawn, BodyPartRecord part, Pawn billDoer, List <Thing> ingredients, Bill bill) { bool flag1 = pawn.health.hediffSet.hediffs.Any((Hediff d) => d.def.HasComp(typeof(HediffComp_PartModule)) && d.Part == part); bool flag2 = this.IsViolationOnPawn(pawn, part, Faction.OfPlayer); if (billDoer != null) { if (base.CheckSurgeryFail(billDoer, pawn, ingredients, part, bill)) { return; } TaleRecorder.RecordTale(TaleDefOf.DidSurgery, new object[] { billDoer, pawn }); MedicalRecipesUtility.SpawnNaturalPartIfClean(pawn, part, billDoer.Position, billDoer.Map); MedicalRecipesUtility.SpawnThingsFromHediffs(pawn, part, billDoer.Position, billDoer.Map); } if (flag1) { pawn.health.RestorePart(part, null, true); HediffWithComps hediff_BodyPartModule = (HediffWithComps)HediffMaker.MakeHediff(MSE_HediffDefOf.MSE_BodyPartModule, pawn, null); hediff_BodyPartModule.Part = part; pawn.health.hediffSet.AddDirect(hediff_BodyPartModule, null, null); } else { DamageDef surgicalCut = DamageDefOf.SurgicalCut; float amount = 99999f; float armorPenetration = 999f; pawn.TakeDamage(new DamageInfo(surgicalCut, amount, armorPenetration, -1f, null, part, null, DamageInfo.SourceCategory.ThingOrUnknown, null)); } if (flag2 && pawn.Faction != null && billDoer != null && billDoer.Faction != null) { Faction faction1 = pawn.Faction; Faction faction2 = billDoer.Faction; int goodwillChange = -20; string reason = "GoodwillChangedReason_RemovedBodyPart".Translate(part.LabelShort); GlobalTargetInfo?lookTarget = new GlobalTargetInfo?(pawn); faction1.TryAffectGoodwillWith(faction2, goodwillChange, true, true, reason, lookTarget); } }
private static List <Thing_withMeta> getCompsWithSeverity(Pawn p) { List <Thing_withMeta> twms = new List <Thing_withMeta>(); foreach (Hediff h in p.health.hediffSet.hediffs) { //if (h.Visible && h.def.defName != "Malnutrition" && h.def.defName != "BloodLoss") if (h.Visible && h.def.defName != "BloodLoss") { if (h.def.lethalSeverity > 0) { if (h is HediffWithComps) { HediffWithComps hwc = (HediffWithComps)h; bool compIsImmunizable = false; foreach (HediffComp hc in hwc.comps) { if (hc is HediffComp_Immunizable) { compIsImmunizable = true; } } if (!compIsImmunizable) { twms.Add(new Thing_withMeta() { thing = p, meta = (new object[] { h.LabelBase, h.Severity }) }); } } else { twms.Add(new Thing_withMeta() { thing = p, meta = (new object[] { h.LabelBase, h.Severity }) }); } } } } return(twms); }
public void TrySealWounds() { IEnumerable <Hediff> enumerable = from hd in this.pawn.health.hediffSet.hediffs where hd.TendableNow(false) select hd; if (enumerable != null) { foreach (Hediff hediff in enumerable) { HediffWithComps hediffWithComps = hediff as HediffWithComps; if (hediffWithComps != null) { HediffComp_TendDuration hediffComp_TendDuration = HediffUtility.TryGetComp <HediffComp_TendDuration>(hediffWithComps); hediffComp_TendDuration.tendQuality = 2f; hediffComp_TendDuration.tendTicksLeft = Find.TickManager.TicksGame; this.pawn.health.Notify_HediffChanged(hediff); } } } }
public override void Apply(LocalTargetInfo target, LocalTargetInfo dest) { Props.sound = SoundDefOf.PsycastPsychicEffect;//SoundDefOf.PsycastPsychicPulse; base.Apply(target, dest); if (target.Pawn == null) { return; } for (int i = 0; i < 10*MorePsycasts_Mod.settings.flash_heal_heal_amount; i++) { Hediff_Injury hediff_Injury = FindInjury(target.Pawn); if (hediff_Injury != null) { hediff_Injury.Heal(0.1f); HediffWithComps hediffWithComps = hediff_Injury as HediffWithComps; if (hediffWithComps != null) { hediffWithComps.TryGetComp<HediffComp_GetsPermanent>().Props.becomePermanentChanceFactor *= (float)MorePsycasts_Mod.settings.flash_heal_scar_chance; } } } //SoundDefOf.PsycastPsychicEffect.PlayOneShot(new TargetInfo(target.Cell, parent.pawn.Map)); }