mirror of
https://gitgud.io/Stardust3D/rjw-patch-autopsy.git
synced 2024-08-15 00:43:41 +00:00
83 lines
No EOL
3.4 KiB
C#
83 lines
No EOL
3.4 KiB
C#
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
|
|
{
|
|
[HarmonyPrefix]
|
|
public static bool AddRjwParts(RecipeInfo recipeInfo, Corpse corpse, float skillChance,
|
|
ref IEnumerable<Thing> __result)
|
|
{
|
|
//Collect vanilla parts
|
|
var core = corpse.InnerPawn.RaceProps.body.corePart;
|
|
var queue = new List<BodyPartRecord> {core};
|
|
var hediffSet = corpse.InnerPawn.health.hediffSet;
|
|
var results = new List<Thing>();
|
|
var damagedParts = new List<BodyPartRecord>();
|
|
while (queue.Count > 0)
|
|
{
|
|
var part = queue.First();
|
|
queue.Remove(part);
|
|
//Drop parts and bionics that are higher on the body tree.
|
|
if (NewMedicalRecipesUtility.TryGetParts(corpse, recipeInfo, part, skillChance, ref results,
|
|
ref damagedParts) && core != part)
|
|
continue;
|
|
queue.AddRange(part.parts.Where(x => !hediffSet.PartIsMissing(x)));
|
|
}
|
|
|
|
foreach (var part in damagedParts)
|
|
NewMedicalRecipesUtility.DamageHarvested(corpse.InnerPawn, part);
|
|
|
|
//Collect rjw rediffs
|
|
var rjwNaturalDiffs = (from x in corpse.InnerPawn.health.hediffSet.hediffs
|
|
where x is Hediff_PartBaseNatural
|
|
select x).ToList();
|
|
var rjwArtificialDiffs = (from x in corpse.InnerPawn.health.hediffSet.hediffs
|
|
where x is Hediff_PartBaseArtifical
|
|
select x).ToList();
|
|
|
|
//Log.Message(String.Format("Collected {0} natural and {1} artifical hediffs", rjwNaturalDiffs.Count(), rjwArtificialDiffs.Count()));
|
|
|
|
//Collect parts from hediffs rjw's surgery methods
|
|
var rjwNaturalThings = rjwNaturalDiffs.Select(SexPartAdder.recipePartRemover).ToList();
|
|
var rjwArtificialThings =
|
|
rjwArtificialDiffs.Select(SexPartAdder.recipePartRemover).ToList();
|
|
|
|
//Log.Message(String.Format("Collected {0} things from {1} natural and {2} things from {3} artifical hediffs",
|
|
//rjwArtificialThings.Count(), rjwNaturalDiffs.Count(), rjwArtificialThings.Count(), rjwArtificialDiffs.Count()));
|
|
|
|
//Simulate success chance scaled with skill etc.
|
|
rjwNaturalThings.ToList().ForEach(t =>
|
|
{
|
|
if (Rand.Chance(Math.Min(skillChance, recipeInfo.NaturalChance))) results.Add(t);
|
|
});
|
|
rjwArtificialThings.ToList().ForEach(t =>
|
|
{
|
|
if (Rand.Chance(Math.Min(skillChance, recipeInfo.BionicChance))) results.Add(t);
|
|
});
|
|
|
|
//Remove all parts that were tried to harves from the corpse
|
|
rjwNaturalDiffs.ToList().ForEach(d => corpse.InnerPawn.health.RemoveHediff(d));
|
|
rjwArtificialDiffs.ToList().ForEach(d => corpse.InnerPawn.health.RemoveHediff(d));
|
|
|
|
if (results.Count() > recipeInfo.PartNumber)
|
|
{
|
|
var random = new Random();
|
|
__result = results.OrderBy(i => random.Next()).Take(recipeInfo.PartNumber);
|
|
}
|
|
else
|
|
{
|
|
__result = results;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
} |