rjw-genes/Source/Genes/Special/Patches/Patch_OrgasmRush.cs

66 lines
2 KiB
C#
Raw Normal View History

2022-12-19 10:25:27 +00:00
using HarmonyLib;
using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2023-01-06 08:45:03 +00:00
using Verse;
2022-12-19 10:25:27 +00:00
namespace RJW_Genes
{
[HarmonyPatch(typeof(SexUtility), nameof(SexUtility.SatisfyPersonal))]
public static class Patch_OrgasmRush
{
private const float REST_INCREASE = 0.05f;
2023-01-06 08:45:03 +00:00
private const float ORGASMS_NEEDED_FOR_SUPERCHARGE = 3.0f;
2022-12-19 10:25:27 +00:00
public static void Postfix(SexProps props)
{
// ShortCuts: Exit Early if Pawn or Partner are null (can happen with Masturbation or other nieche-cases)
if (props == null || props.pawn == null || !props.hasPartner())
return;
// Exit for Animals - Animals can't get or trigger Orgasm Rushes. Fixes #15
if (props.pawn.IsAnimal() || props.partner.IsAnimal())
2022-12-19 10:25:27 +00:00
return;
2024-05-26 15:45:00 +00:00
if (props.pawn.genes != null && props.pawn.genes.HasActiveGene(GeneDefOf.rjw_genes_orgasm_rush))
2022-12-19 10:25:27 +00:00
{
2023-01-06 08:45:03 +00:00
// Pump up Wake-Ness
if (props.pawn.needs.rest != null)
props.pawn.needs.rest.CurLevel += REST_INCREASE;
// Add or Update Hediff for Orgasm Rush
Hediff rush = GetOrgasmRushHediff(props.pawn);
float added_severity = props.orgasms / ORGASMS_NEEDED_FOR_SUPERCHARGE;
rush.Severity += added_severity;
// Severity should be capped to 1 by the XML logic
}
}
/// <summary>
/// Helps to get the Orgasm Rush Hediff of a Pawn. If it does not exist, one is added.
/// </summary>
/// <param name="orgasmed">The pawn that had the orgasm, for which a hediff is looked up or created.</param>
/// <returns></returns>
public static Hediff GetOrgasmRushHediff(Pawn orgasmed)
{
2023-01-15 20:14:26 +00:00
Hediff orgasmRushHediff = orgasmed.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.rjw_genes_orgasm_rush_hediff);
2023-01-06 08:45:03 +00:00
if (orgasmRushHediff == null)
{
2023-01-15 20:14:26 +00:00
orgasmRushHediff = HediffMaker.MakeHediff(HediffDefOf.rjw_genes_orgasm_rush_hediff, orgasmed);
2023-01-06 08:45:03 +00:00
orgasmRushHediff.Severity = 0;
orgasmed.health.AddHediff(orgasmRushHediff);
}
return orgasmRushHediff;
2022-12-19 10:25:27 +00:00
}
}
2023-01-06 08:45:03 +00:00
2022-12-19 10:25:27 +00:00
}