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 UnityEngine;
|
|
|
|
|
using Verse;
|
2023-01-06 16:08:22 +00:00
|
|
|
|
|
|
|
|
|
namespace RJW_Genes.Genes.Special
|
|
|
|
|
{
|
|
|
|
|
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
|
|
|
|
|
public static class Patch_AgeDrain
|
|
|
|
|
{
|
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-01-06 16:08:22 +00:00
|
|
|
|
|
2023-05-10 18:57:49 +00:00
|
|
|
|
const long AGE_TRANSFERED_FALLBACK = 120000; // 120k == 2 days
|
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;
|
|
|
|
|
}
|
2023-05-10 18:57:49 +00:00
|
|
|
|
|
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
|
|
|
|
Pawn pawn = props.pawn;
|
|
|
|
|
Pawn partner = props.partner;
|
|
|
|
|
|
|
|
|
|
if (GeneUtility.IsAgeDrainer(pawn) && !GeneUtility.IsAgeDrainer(partner))
|
|
|
|
|
{
|
|
|
|
|
TransferAge(pawn, partner);
|
|
|
|
|
}
|
|
|
|
|
else if (GeneUtility.IsAgeDrainer(partner) && !GeneUtility.IsAgeDrainer(pawn))
|
2023-01-06 16:08:22 +00:00
|
|
|
|
{
|
2023-05-10 18:57:49 +00:00
|
|
|
|
TransferAge(partner,pawn);
|
2023-01-06 16:08:22 +00:00
|
|
|
|
}
|
2023-05-10 18:57:49 +00:00
|
|
|
|
else if (GeneUtility.IsAgeDrainer(partner) && GeneUtility.IsAgeDrainer(pawn) && RJW_Genes_Settings.rjw_genes_detailed_debug)
|
|
|
|
|
{
|
|
|
|
|
ModLog.Message($"[Sexual Age Drainer] both {pawn} and {partner} are sexual-age-drainers - nothing happens.");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-06 16:08:22 +00:00
|
|
|
|
|
2023-05-10 18:57:49 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Transfers age from the giver to the receiver.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="receiver">The pawn that will receive biological-Age-Ticks, and becomes younger if they are not already young. </param>
|
|
|
|
|
/// <param name="giver">The pawn that will be giving biological-Age-Ticks. This pawn is always aged, even if the other pawn is too young.</param>
|
|
|
|
|
private static void TransferAge(Pawn receiver, Pawn giver)
|
|
|
|
|
{
|
|
|
|
|
AgeTransferExtension transferExt = GeneDefOf.rjw_genes_sex_age_drain.GetModExtension<AgeTransferExtension>();
|
|
|
|
|
long age_transfered = transferExt?.ageTickChange ?? AGE_TRANSFERED_FALLBACK;
|
|
|
|
|
long minimum_age = transferExt?.minAgeInYears * 60 * 60000 + 1 ?? MINIMUM_AGE_FALLBACK;
|
|
|
|
|
|
|
|
|
|
var pawnAge = receiver.ageTracker.AgeBiologicalTicks;
|
|
|
|
|
|
|
|
|
|
if (RJW_Genes_Settings.rjw_genes_detailed_debug)
|
|
|
|
|
ModLog.Message($"[Sexual Age Drainer] {receiver} is aging {giver} by {age_transfered} ({Math.Round(age_transfered / 60000.0, 2)} days)");
|
|
|
|
|
|
|
|
|
|
// Giver ALWAYS ages
|
|
|
|
|
giver.ageTracker.AgeBiologicalTicks += age_transfered;
|
|
|
|
|
|
|
|
|
|
// Make Receiver younger if they are older than minimum age
|
|
|
|
|
if (pawnAge - age_transfered > minimum_age)
|
|
|
|
|
receiver.ageTracker.AgeBiologicalTicks = Math.Max(minimum_age, (pawnAge - age_transfered));
|
|
|
|
|
else {
|
|
|
|
|
if (RJW_Genes_Settings.rjw_genes_detailed_debug)
|
|
|
|
|
ModLog.Message($"[Sexual Age Drainer] {receiver} was too young ({receiver.ageTracker.AgeBiologicalYears}), and remains unchanged.");
|
|
|
|
|
}
|
2024-07-05 13:04:45 +00:00
|
|
|
|
|
2024-07-05 13:20:09 +00:00
|
|
|
|
FactionUtility.HandleFactionGoodWillPenalties(receiver, giver, "rjw_genes_GoodwillChangedReason_aged_pawn_with_sex_gene",FACTION_GOODWILL_CHANGE);
|
2024-07-05 13:04:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 16:08:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|