Do the age adjustment for ovulation in FertilityByGenderAge instead of trying to patch RJW's StatWorker

This commit is contained in:
lutepickle 2023-12-05 16:08:55 -08:00
parent 02a96b957a
commit c254ce039a
5 changed files with 15 additions and 18 deletions

Binary file not shown.

View file

@ -319,7 +319,6 @@ namespace RJW_Menstruation
fertilityByAge.TransformValue(StatRequest.For(Pawn), ref factor);
if (factor <= 0.0f) return 0.0f; // Too young or too old
}
else part.TransformValue(StatRequest.For(Pawn), ref ovulationChance);
}
if (Pawn.HasQuirk(QuirkUtility.Quirks.Breeder)) ovulationChance *= 10.0f;
try

View file

@ -219,6 +219,16 @@ namespace RJW_Menstruation
}
}
[HarmonyPatch(typeof(StatPart_FertilityByGenderAge), "AgeFactor")]
public class AgeFactor_Patch
{
public static void Postfix(ref float __result, Pawn pawn)
{
if (pawn.GetMenstruationComps().Any(comp => comp.CalculatingOvulationChance))
__result = 1.0f;
}
}
//[HarmonyPatch(typeof(ChildcareUtility), nameof(ChildcareUtility.SuckleFromLactatingPawn))]
//public class GreedyConsume_Patch
//{

View file

@ -374,26 +374,13 @@ namespace RJW_Menstruation
}
}
[HarmonyPatch(typeof(PawnCapacityWorker_Fertility), nameof(PawnCapacityWorker_Fertility.CalculateCapacityLevel))]
public static class PawnCapacityWorker_Fertility_Patch
[HarmonyPatch(typeof(PawnCapacityWorker_Fertility), "CalculateAgeImpact")]
public static class PawnCapacityWorker_Fertility_Age_Patch
{
private static float GetFertilityStatOrOne(Thing thing, StatDef stat, bool applyPostProcess, int cacheStaleAfterTicks)
public static void Postfix(ref float __result, Pawn pawn)
{
Pawn pawn = (Pawn)thing;
if (pawn.GetMenstruationComps().Any(comp => comp.CalculatingOvulationChance))
return 1.0f;
else return thing.GetStatValue(stat, applyPostProcess, cacheStaleAfterTicks);
}
private static readonly MethodInfo GetStatValue = AccessTools.Method(typeof(StatExtension), "GetStatValue", new System.Type[] { typeof(Thing), typeof(StatDef), typeof(bool), typeof(int) });
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
if (GetStatValue?.ReturnType != typeof(float)) throw new System.InvalidOperationException("GetStatValue not found");
foreach (CodeInstruction instruction in instructions)
{
if (instruction.Calls(GetStatValue))
yield return CodeInstruction.Call(typeof(PawnCapacityWorker_Fertility_Patch), nameof(GetFertilityStatOrOne));
else yield return instruction;
}
__result = 1f;
}
}
}

View file

@ -1,6 +1,7 @@
Version 1.0.9.2
- Updated Traditional Chinese translation by Hydrogen.
- Fixed the no bleeding gene having positive metabolic efficiency instead of negative.
- Fixed ovulation chance not accounting for genes or precepts.
- Better handle wombs that are not in the genitals body part.
- Handle errors more gracefully when starting a pregnancy.
- Fix implanting multiple eggs in an animal when configured to use Biotech pregnancies.