rjw-patch-autopsy/Source/RJW_patch_Autopsy/Patches/NewMedicalRecipesUtilityPatch.cs

37 lines
1.3 KiB
C#
Raw Normal View History

2021-12-11 19:18:21 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using Verse;
using rjw;
using Autopsy;
using HarmonyLib;
namespace RJW_patch_Autopsy
{
[HarmonyPatch(typeof(NewMedicalRecipesUtility), "TraverseBody")]
public static class NewMedicalRecipesUtilityPatch
{
[HarmonyPostfix]
public static void AddRjwParts(RecipeInfo recipeInfo, Corpse corpse, float skillChance, ref IEnumerable<Thing> __result)
{
var previousResult = __result.ToList();
//Collect rjw rediffs
IEnumerable<Hediff> rjwDiffs = from x in corpse.InnerPawn.health.hediffSet.hediffs
where x is Hediff_PartBaseNatural || x is Hediff_PartBaseArtifical
select x;
//Collect parts from hediffs rjw's surgery methods
IEnumerable<Thing> rjwThings = rjwDiffs.Select(d => SexPartAdder.recipePartRemover(d));
//Simulate success chance scaled with skill etc.
rjwThings.ToList().ForEach(t => { if (Rand.Chance(Math.Min(skillChance, recipeInfo.NaturalChance))) previousResult.Add(t); });
//Remove all parts that were tried to harves from the corpse
rjwDiffs.ToList().ForEach(d => corpse.InnerPawn.health.RemoveHediff(d));
__result = previousResult;
}
}
}