2023-01-06 16:08:22 +00:00
|
|
|
|
using HarmonyLib;
|
2024-07-05 13:04:45 +00:00
|
|
|
|
using RimWorld;
|
2023-01-06 16:08:22 +00:00
|
|
|
|
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
|
|
|
|
|
2024-07-05 13:04:45 +00:00
|
|
|
|
const int FACTION_GOODWILL_CHANGE = 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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-26 15:49:08 +00:00
|
|
|
|
if (props.pawn == props.partner || props.sexType == xxx.rjwSextype.Masturbation || props.sexType == xxx.rjwSextype.None)
|
|
|
|
|
{
|
|
|
|
|
// This case was reported but is a bit strange, I hardened it after reports in #99
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-10 18:57:49 +00:00
|
|
|
|
if (GeneUtility.IsYouthFountain(props.pawn))
|
|
|
|
|
{
|
|
|
|
|
ChangeAgeForPawn(props.partner, props.pawn);
|
2024-07-05 13:04:45 +00:00
|
|
|
|
HandleFactionGoodWillPenalties(props.pawn, props.partner);
|
2023-05-10 18:57:49 +00:00
|
|
|
|
}
|
|
|
|
|
if (GeneUtility.IsYouthFountain(props.partner))
|
|
|
|
|
{
|
|
|
|
|
ChangeAgeForPawn(props.pawn,props.partner);
|
2024-07-05 13:04:45 +00:00
|
|
|
|
HandleFactionGoodWillPenalties(props.partner, props.pawn);
|
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.");
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-05 13:04:45 +00:00
|
|
|
|
|
|
|
|
|
private static void HandleFactionGoodWillPenalties(Pawn actor, Pawn target)
|
|
|
|
|
{
|
|
|
|
|
if (
|
|
|
|
|
target.Faction != null && actor.Faction != null
|
|
|
|
|
&& target.Faction != actor.Faction
|
|
|
|
|
&& target.Faction != Faction.OfPlayer)
|
|
|
|
|
{
|
|
|
|
|
HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_youthed_pawn_with_sex_gene");
|
|
|
|
|
target.Faction.TryAffectGoodwillWith(actor.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, target);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-06 16:08:22 +00:00
|
|
|
|
}
|
2023-01-07 15:51:34 +00:00
|
|
|
|
|
2023-01-06 16:08:22 +00:00
|
|
|
|
}
|