Added two Genes for changing biological age by sex

This commit is contained in:
Vegapnk 2023-01-06 17:08:22 +01:00
parent 8e63e69385
commit 5ae3d0b13f
5 changed files with 114 additions and 0 deletions

View File

@ -10,4 +10,24 @@
<displayOrderInCategory>1</displayOrderInCategory>
</GeneDef>
<GeneDef>
<defName>rjw_genes_youth_fountain</defName>
<label>Youth Fountain</label>
<displayCategory>rjw_genes_special</displayCategory>
<description>Having sex with a carrier of this gene makes the partner slightly younger. (Partner stays adult)</description>
<biostatCpx>1</biostatCpx>
<iconPath>UI/Ideoligions/FireLeaves</iconPath>
<displayOrderInCategory>2</displayOrderInCategory>
</GeneDef>
<GeneDef>
<defName>rjw_genes_sex_age_drain</defName>
<label>Sexual Age Drain</label>
<displayCategory>rjw_genes_special</displayCategory>
<description>Having sex transfers some of the partners life-time to themselves. (Pawn stays adult)</description>
<biostatCpx>1</biostatCpx>
<iconPath>UI/Icons/ColonistBar/Idle</iconPath>
<displayOrderInCategory>3</displayOrderInCategory>
</GeneDef>
</Defs>

View File

@ -71,6 +71,8 @@ namespace RJW_Genes
// Special
public static readonly GeneDef rjw_genes_orgasm_rush;
public static readonly GeneDef rjw_genes_youth_fountain;
public static readonly GeneDef rjw_genes_sex_age_drain;
public static readonly HediffDef rjw_genes_orgasm_rush_hediff;

View File

@ -23,6 +23,24 @@ namespace RJW_Genes
return pawn.genes.HasGene(GeneDefOf.rjw_genes_insectincubator);
}
public static bool IsYouthFountain(Pawn pawn)
{
if (pawn.genes == null)
{
return false;
}
return pawn.genes.HasGene(GeneDefOf.rjw_genes_youth_fountain);
}
internal static bool IsAgeDrainer(Pawn pawn)
{
if (pawn.genes == null)
{
return false;
}
return pawn.genes.HasGene(GeneDefOf.rjw_genes_sex_age_drain);
}
public static bool IsInsectBreeder(Pawn pawn)
{
if (pawn.genes == null)

View File

@ -0,0 +1,38 @@
using HarmonyLib;
using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RJW_Genes.Genes.Special
{
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
public static class Patch_AgeDrain
{
const long AGE_TRANSFERED = 120000; // 120k == 2 days
// Comment Below in for debugging, changes years
// const long AGE_TRANSFERED = 6000000; // 6000k == 100 days
public static void Postfix(SexProps props)
{
if (props == null || props.pawn == null || props.partner == null || props.partner.IsAnimal() )
{
return;
}
if (GeneUtility.IsAgeDrainer(props.pawn))
{
var pawnAge = props.pawn.ageTracker.AgeBiologicalTicks;
var pawnMinAge = props.pawn.ageTracker.AdultMinAgeTicks;
// Make Partner older
props.partner.ageTracker.AgeBiologicalTicks += AGE_TRANSFERED;
// Make Pawn younger
props.pawn.ageTracker.AgeBiologicalTicks = Math.Max(pawnMinAge, pawnAge - AGE_TRANSFERED);
}
}
}
}

View File

@ -0,0 +1,36 @@
using HarmonyLib;
using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RJW_Genes.Genes.Special
{
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
public static class Patch_Youth_Fountain
{
const long AGE_REDUCTION = 60000; // 60k == 1 day
// Comment Below in for debugging
//const long AGE_REDUCTION = 6000000; // 6000k == 100 days
public static void Postfix(SexProps props)
{
if (props == null || props.pawn == null || props.partner == null || props.partner.IsAnimal())
{
return;
}
if (GeneUtility.IsYouthFountain(props.pawn))
{
var partnerAge = props.partner.ageTracker.AgeBiologicalTicks;
var minAge = props.partner.ageTracker.AdultMinAgeTicks;
props.partner.ageTracker.AgeBiologicalTicks = Math.Max(minAge, partnerAge - AGE_REDUCTION);
}
}
}
}