mirror of
https://gitgud.io/Stardust3D/rjw-patch-autopsy.git
synced 2024-08-15 00:43:41 +00:00
prevent original method "TraverseBody" from executing and take over its work
This commit is contained in:
parent
30d8f148b9
commit
b674530677
6 changed files with 52 additions and 17 deletions
Binary file not shown.
Binary file not shown.
|
@ -49,9 +49,8 @@
|
|||
<HintPath>..\..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Autopsy, Version=4.1.1.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\__LocalCopy_Harvest Organs Post Mortem_-11-12\1.3\Assemblies\Autopsy.dll</HintPath>
|
||||
<Reference Include="Autopsy">
|
||||
<HintPath>..\..\..\RimwoldAutopsy\1.3\Assemblies\Autopsy.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="HugsLib">
|
||||
<HintPath>..\..\..\..\..\..\workshop\content\294100\818773962\Assemblies\HugsLib.dll</HintPath>
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace RJW_patch_Autopsy
|
|||
{
|
||||
public class Mod : ModBase
|
||||
{
|
||||
public override string ModIdentifier => "RJW Patch - Autopsy";
|
||||
public override string ModIdentifier => "Stardust3D.RJW.patch.Autopsy";
|
||||
|
||||
}
|
||||
}
|
|
@ -11,26 +11,62 @@ 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)
|
||||
[HarmonyPrefix]
|
||||
public static bool AddRjwParts(RecipeInfo recipeInfo, Corpse corpse, float skillChance, ref IEnumerable<Thing> __result)
|
||||
{
|
||||
var previousResult = __result.ToList();
|
||||
//Collect vanilla parts
|
||||
BodyPartRecord core = corpse.InnerPawn.RaceProps.body.corePart;
|
||||
List<BodyPartRecord> queue = new List<BodyPartRecord> { core };
|
||||
HediffSet hediffSet = corpse.InnerPawn.health.hediffSet;
|
||||
List<Thing> results = new List<Thing>();
|
||||
List<BodyPartRecord> damagedParts = new List<BodyPartRecord>();
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
BodyPartRecord 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 (BodyPartRecord part in damagedParts) NewMedicalRecipesUtility.DamageHarvested(corpse.InnerPawn, part);
|
||||
|
||||
//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;
|
||||
List<Hediff> rjwNaturalDiffs = (from x in corpse.InnerPawn.health.hediffSet.hediffs
|
||||
where x is Hediff_PartBaseNatural
|
||||
select x).ToList();
|
||||
List<Hediff> 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
|
||||
IEnumerable<Thing> rjwThings = rjwDiffs.Select(d => SexPartAdder.recipePartRemover(d));
|
||||
List<Thing> rjwNaturalThings = rjwNaturalDiffs.Select(d => SexPartAdder.recipePartRemover(d)).ToList();
|
||||
List<Thing> rjwArtificialThings = rjwArtificialDiffs.Select(d => SexPartAdder.recipePartRemover(d)).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.
|
||||
rjwThings.ToList().ForEach(t => { if (Rand.Chance(Math.Min(skillChance, recipeInfo.NaturalChance))) previousResult.Add(t); });
|
||||
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
|
||||
rjwDiffs.ToList().ForEach(d => corpse.InnerPawn.health.RemoveHediff(d));
|
||||
rjwNaturalDiffs.ToList().ForEach(d => corpse.InnerPawn.health.RemoveHediff(d));
|
||||
rjwArtificialDiffs.ToList().ForEach(d => corpse.InnerPawn.health.RemoveHediff(d));
|
||||
|
||||
__result = previousResult;
|
||||
if (results.Count() > recipeInfo.PartNumber)
|
||||
{
|
||||
Random random = new Random();
|
||||
__result = results.OrderBy(i => random.Next()).Take(recipeInfo.PartNumber);
|
||||
}
|
||||
else
|
||||
{
|
||||
__result = results;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ using System.Runtime.InteropServices;
|
|||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("RJW_patch_Autopsy")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2021")]
|
||||
[assembly: AssemblyCopyright("©2021 Stardust3D")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
|
|||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
[assembly: AssemblyVersion("1.0.1.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.1.0")]
|
Loading…
Reference in a new issue