2023-01-06 16:08:22 +00:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using rjw;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-05-10 18:57:49 +00:00
|
|
|
|
using Verse;
|
2023-01-06 16:08:22 +00:00
|
|
|
|
|
|
|
|
|
namespace RJW_Genes.Genes.Special
|
|
|
|
|
{
|
|
|
|
|
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
|
|
|
|
|
public static class Patch_Youth_Fountain
|
|
|
|
|
{
|
2023-03-24 09:53:58 +00:00
|
|
|
|
/**
|
|
|
|
|
* Update Issue #26:
|
|
|
|
|
* There are options that a 16 yo pawn and a 16 yo pawn have sex,
|
2023-04-06 06:24:00 +00:00
|
|
|
|
* or there are races that have a different age-limits.
|
|
|
|
|
* I am not sure how I feel about this, but as some people that I consider "normal" asked me about this I changed it as requested in #26 and #28
|
2023-03-24 09:53:58 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2023-05-10 18:57:49 +00:00
|
|
|
|
const long AGE_REDUCTION_FALLBACK = 60000; // 60k == 1 day
|
2023-03-24 09:53:58 +00:00
|
|
|
|
// 18 Years * 60 Days / Year * 60k Ticks/Day + 1 for safety
|
2023-05-10 18:57:49 +00:00
|
|
|
|
const long MINIMUM_AGE_FALLBACK = 18 * 60 * 60000 + 1;
|
2023-01-06 16:08:22 +00:00
|
|
|
|
|
|
|
|
|
public static void Postfix(SexProps props)
|
|
|
|
|
{
|
|
|
|
|
if (props == null || props.pawn == null || props.partner == null || props.partner.IsAnimal())
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 18:57:49 +00:00
|
|
|
|
if (GeneUtility.IsYouthFountain(props.pawn))
|
|
|
|
|
{
|
|
|
|
|
ChangeAgeForPawn(props.partner, props.pawn);
|
|
|
|
|
}
|
|
|
|
|
if (GeneUtility.IsYouthFountain(props.partner))
|
|
|
|
|
{
|
|
|
|
|
ChangeAgeForPawn(props.pawn,props.partner);
|
2023-01-06 16:08:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 18:57:49 +00:00
|
|
|
|
private static void ChangeAgeForPawn(Pawn ToYouth, Pawn YouthingPawn)
|
|
|
|
|
{
|
|
|
|
|
AgeTransferExtension transferExt = GeneDefOf.rjw_genes_youth_fountain.GetModExtension<AgeTransferExtension>();
|
|
|
|
|
long age_reduction = transferExt?.ageTickChange ?? AGE_REDUCTION_FALLBACK;
|
|
|
|
|
long minimum_age = transferExt?.minAgeInYears * 60 * 60000 + 1 ?? MINIMUM_AGE_FALLBACK;
|
|
|
|
|
|
|
|
|
|
var partnerAge = ToYouth.ageTracker.AgeBiologicalTicks;
|
|
|
|
|
|
|
|
|
|
if (RJW_Genes_Settings.rjw_genes_detailed_debug)
|
|
|
|
|
ModLog.Message($"Firing Youth Fountain - {YouthingPawn} is youthing {ToYouth} by {age_reduction} ({Math.Round(age_reduction / 60000.0, 2)} days)");
|
|
|
|
|
|
|
|
|
|
if (partnerAge - age_reduction > minimum_age) {
|
|
|
|
|
ToYouth.ageTracker.AgeBiologicalTicks = Math.Max(minimum_age, partnerAge - age_reduction);
|
|
|
|
|
}
|
|
|
|
|
else if (RJW_Genes_Settings.rjw_genes_detailed_debug)
|
|
|
|
|
ModLog.Message($"[Youth Fountain] {ToYouth} was too young ({ToYouth.ageTracker.AgeBiologicalYears}), and remains unchanged.");
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 16:08:22 +00:00
|
|
|
|
}
|
2023-01-07 15:51:34 +00:00
|
|
|
|
|
2023-01-06 16:08:22 +00:00
|
|
|
|
}
|