mirror of
https://github.com/vegapnk/RJW-Genes.git
synced 2024-08-15 00:23:31 +00:00
57 lines
2.1 KiB
C#
57 lines
2.1 KiB
C#
using HarmonyLib;
|
|
using rjw;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.Remoting.Lifetime;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Verse;
|
|
|
|
namespace RJW_Genes
|
|
{
|
|
|
|
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
|
|
public class Patch_AfterSexUtility_ApplyGeneticInfectors
|
|
{
|
|
public static void Postfix(SexProps props)
|
|
{
|
|
if (props == null || props.pawn == null || props.partner == null) return;
|
|
|
|
Pawn pawn = props.pawn;
|
|
Pawn partner = props.partner;
|
|
|
|
if (pawn == partner) return;
|
|
if (pawn.IsAnimal() || partner.IsAnimal()) return;
|
|
if (pawn.genes == null || partner.genes == null) return;
|
|
// No Infections on Condom Use
|
|
if (props.usedCondom) return;
|
|
|
|
// Exit early if settings require penetrative sex, but this is not penetrative sex
|
|
if (!DiseaseHelper.IsPenetrativeSex(props) && RJW_Genes_Settings.rjw_genes_genetic_disease_spread_only_on_penetrative_sex) return;
|
|
|
|
TryApplyGeneticInfections(pawn, partner);
|
|
TryApplyGeneticInfections(partner, pawn);
|
|
}
|
|
|
|
private static void TryApplyGeneticInfections(Pawn infector, Pawn partner)
|
|
{
|
|
foreach (GeneDef infectorGeneDef in DiseaseHelper.GetGeneticInfectorGenes(infector))
|
|
{
|
|
GeneticInfectorExtension diseaseExt = infectorGeneDef.GetModExtension<GeneticInfectorExtension>();
|
|
if (diseaseExt == null) continue;
|
|
float application_chance = diseaseExt.infectionChance;
|
|
|
|
foreach (GeneDef diseaseGeneDef in DiseaseHelper.LookupInfectionGeneDefs(diseaseExt))
|
|
{
|
|
if (DiseaseHelper.IsImmuneAgainstGeneticDisease(partner, diseaseGeneDef))
|
|
continue;
|
|
|
|
if ((new Random()).NextDouble() < application_chance)
|
|
partner.genes.AddGene(diseaseGeneDef, !RJW_Genes_Settings.rjw_genes_genetic_disease_as_endogenes);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|