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); }
public override float Apply(DamageInfo dinfo, Thing victim) { if (victim is ProjectJedi.PawnGhost) { Messages.Message("PJ_ForceGhostResisted".Translate(), MessageSound.Negative); return(0f); } Pawn pawn = victim as Pawn; if (pawn != null) { DamageInfo newDinfo = new DamageInfo(dinfo); BodyPartRecord neckRecord = pawn.def.race.body.AllParts.FirstOrDefault((BodyPartRecord x) => x.def.label == "neck"); if (!pawn.health.hediffSet.GetHediffs <Hediff_MissingPart>().Any((Hediff_MissingPart x) => x.Part == neckRecord)) { newDinfo.SetForcedHitPart(neckRecord); } else { BodyPartRecord lungRecord = pawn.def.race.body.AllParts.FirstOrDefault((BodyPartRecord x) => x.def.tags.First((string s) => s == "BreathingSource" || s == "BreathingPathway") != null); if (!pawn.health.hediffSet.GetHediffs <Hediff_MissingPart>().Any((Hediff_MissingPart x) => x.Part == lungRecord)) { newDinfo.SetForcedHitPart(lungRecord); } } DamageWorker_AddInjury newWorker = new DamageWorker_AddInjury(); return(newWorker.Apply(newDinfo, victim)); } return(0f); }
public static void FinalizeAndAddInjuryPostfix(DamageWorker_AddInjury __instance, Pawn pawn, Hediff_Injury injury, DamageInfo dinfo, DamageWorker.DamageResult result) { if (pawn != null) { if (injury != null) { Comp_NecronOG _Necron = pawn.TryGetCompFast <Comp_NecronOG>(); if (_Necron != null) { DamageInfo dInfo = dinfo; DamageDef damageDef = dinfo.Def; float AP = dinfo.ArmorPenetrationInt; float AV = (pawn.kindDef.race.statBases.GetStatValueFromList(dinfo.Def.armorCategory.armorRatingStat, 0f)); bool healable = AP < AV; if (healable) { _Necron.healableHediffs.Add(injury); } else { _Necron.unhealableHediffs.Add(injury); } // Log.Message(string.Format("{1} got a {2} AP: {7} on its {3} AV:{6}, healable: {0}, total Healable: {5}, Unhealable: {4}", healable, pawn.Label, injury.Label, injury.Part, _Necron.unhealableHediffs.Count, _Necron.healableHediffs.Count, AV, AP)); } } } }
//public class DamageWorker_AddInjury : DamageWorker public static void HulkDmgFixFinalizeAndAddInjury(DamageWorker_AddInjury __instance, Pawn pawn, ref Hediff_Injury injury, ref DamageInfo dinfo, ref DamageWorker.DamageResult result) { if (dinfo.Amount > 0 && pawn.TryGetComp <CompHulk>() is CompHulk ww && ww.IsHulk && ww.CurrentHulkForm != null) { if (dinfo.Instigator is Pawn a && ShouldModifyDamage(a)) { if (a?.equipment?.Primary is ThingWithComps b && !b.IsSilverTreated()) { int math = (int)(dinfo.Amount) - (int)(dinfo.Amount * (ww.CurrentHulkForm.DmgImmunity)); //10% damage. Decimated damage. dinfo.SetAmount(math); injury.Severity = math; //Log.Message(dinfo.Amount.ToString()); } } } }
private static void TryRegeneratePart(Pawn pawn, Building_BaseMechanoidPlatform platform) { Hediff_MissingPart hediff = FindBiggestMissingBodyPart(pawn); if (hediff == null || pawn.health.hediffSet.HasHediff(WTH_DefOf.WTH_RegeneratedPart)) { return; } pawn.health.RemoveHediff(hediff); float partHealth = hediff.Part.def.GetMaxHealth(pawn); float fuelNeeded = Math.Min(4f, partHealth / 5f);//body parts with less health need less parts to regenerate, capped at 4. platform.refuelableComp.ConsumeFuel(fuelNeeded); //Hediff_Injury injury = new Hediff_Injury(); DamageWorker_AddInjury addInjury = new DamageWorker_AddInjury(); addInjury.Apply(new DamageInfo(WTH_DefOf.WTH_RegeneratedPartDamage, hediff.Part.def.GetMaxHealth(pawn) - 1, 0, -1, pawn, hediff.Part), pawn); }
// Verse.DamageWorker_AddInjury public static void FinalizeAndAddInjury_PostFix(DamageWorker_AddInjury __instance, Pawn pawn, Hediff_Injury injury, DamageInfo dinfo) { CompVehicle compPilotable = pawn.GetComp <CompVehicle>(); if (compPilotable != null) { List <Pawn> affectedPawns = new List <Pawn>(); if (compPilotable.handlers != null && compPilotable.handlers.Count > 0) { foreach (VehicleHandlerGroup group in compPilotable.handlers) { if (group.OccupiedParts != null && (group.handlers != null && group.handlers.Count > 0)) { if (group.OccupiedParts.Contains(injury.Part)) { affectedPawns.AddRange(group.handlers); } } } } //Attack the seatholder if (affectedPawns != null && affectedPawns.Count > 0) { DamageInfo newDamageInfo = new DamageInfo(dinfo); float criticalBonus = 0f; if (Rand.Value < compPilotable.Props.seatHitCriticalHitChance) { criticalBonus = dinfo.Amount * 2; } float newDamFloat = (dinfo.Amount * compPilotable.Props.seatHitDamageFactor) + criticalBonus; newDamageInfo.SetAmount((int)newDamFloat); affectedPawns.RandomElement <Pawn>().TakeDamage(newDamageInfo); } } }
// Verse.DamageWorker_AddInjury public static void FinalizeAndAddInjury_PostFix(DamageWorker_AddInjury __instance, Pawn pawn, Hediff_Injury injury, DamageInfo dinfo) { CompPilotable compPilotable = pawn.GetComp <CompPilotable>(); if (compPilotable != null) { List <Pawn> affectedPawns = new List <Pawn>(); //Pilot check. List <BodyPartRecord> pilotParts = compPilotable.PilotParts; if (pilotParts != null && pilotParts.Count > 0) { if (pilotParts.Contains(injury.Part)) { if (compPilotable.pilots != null && compPilotable.pilots.Count > 0) { affectedPawns.AddRange(compPilotable.pilots); } } } //Gunner check. List <BodyPartRecord> gunnerParts = compPilotable.GunnerParts; if (gunnerParts != null && gunnerParts.Count > 0) { if (gunnerParts.Contains(injury.Part)) { if (compPilotable.gunners != null && compPilotable.gunners.Count > 0) { affectedPawns.AddRange(compPilotable.gunners); } } } //Crew check. List <BodyPartRecord> crewParts = compPilotable.CrewParts; if (crewParts != null && crewParts.Count > 0) { if (crewParts.Contains(injury.Part)) { if (compPilotable.crew != null && compPilotable.crew.Count > 0) { affectedPawns.AddRange(compPilotable.crew); } } } //Passenger check. List <BodyPartRecord> passengerParts = compPilotable.PassengerParts; if (passengerParts != null && passengerParts.Count > 0) { if (passengerParts.Contains(injury.Part)) { if (compPilotable.passengers != null && compPilotable.passengers.Count > 0) { affectedPawns.AddRange(compPilotable.passengers); } } } //Attack the seatholder if (affectedPawns != null && affectedPawns.Count > 0) { affectedPawns.RandomElement <Pawn>().TakeDamage(new DamageInfo(dinfo)); } } }
public static bool CalculatePartEfficiency(ref float __result, HediffSet diffSet, BodyPartRecord part, bool ignoreAddedParts = false, List <CapacityImpactor> impactors = null) { BodyPartRecord rec; for (rec = part.parent; rec != null; rec = rec.parent) { if (diffSet.HasDirectlyAddedPartFor(rec)) { Hediff_AddedPart hediff_AddedPart = (from x in diffSet.GetHediffs <Hediff_AddedPart>() where x.Part == rec select x).First(); impactors?.Add(new CapacityImpactorHediff { hediff = hediff_AddedPart }); __result = hediff_AddedPart.def.addedPartProps.partEfficiency; return(false); } } if (part.parent != null && diffSet.PartIsMissing(part.parent)) { __result = 0f; return(false); } float num = 1f; if (!ignoreAddedParts) { for (int i = 0; i < diffSet.hediffs.Count; i++) { Hediff_AddedPart hediff_AddedPart2 = diffSet.hediffs[i] as Hediff_AddedPart; if (hediff_AddedPart2 != null && hediff_AddedPart2.Part == part) { num *= hediff_AddedPart2.def.addedPartProps.partEfficiency; if (hediff_AddedPart2.def.addedPartProps.partEfficiency != 1f) { impactors?.Add(new CapacityImpactorHediff { hediff = hediff_AddedPart2 }); } } } } float b = -1f; float num2 = 0f; bool flag = false; for (int j = 0; j < diffSet.hediffs.Count; j++) { Hediff hediff1 = diffSet.hediffs[j]; if (hediff1 != null && hediff1.Part == part && hediff1.CurStage != null) { HediffStage curStage = hediff1.CurStage; num2 += curStage.partEfficiencyOffset; flag |= curStage.partIgnoreMissingHP; if (curStage.partEfficiencyOffset != 0f && curStage.becomeVisible) { impactors?.Add(new CapacityImpactorHediff { hediff = hediff1 }); } } } if (!flag) { float num3 = diffSet.GetPartHealth(part) / part.def.GetMaxHealth(diffSet.pawn); if (num3 != 1f) { if (DamageWorker_AddInjury.ShouldReduceDamageToPreservePart(part)) { num3 = Mathf.InverseLerp(0.1f, 1f, num3); } impactors?.Add(new CapacityImpactorBodyPartHealth { bodyPart = part }); num *= num3; } } num += num2; if (num > 0.0001f) { num = Mathf.Max(num, b); } __result = Mathf.Max(num, 0f); return(false); }