rjw-genes/Source/Genes/Diseases/Patches/Patch_AftersexUtility_TransferGeneticDiseases.cs

57 lines
2 KiB
C#
Raw Normal View History

2024-07-02 13:19:48 +00:00
using HarmonyLib;
using rjw;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace RJW_Genes
2024-07-02 13:19:48 +00:00
{
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
public class Patch_AftersexUtility_TransferGeneticDiseases
{
public static void Postfix(SexProps props)
{
2024-07-03 08:14:05 +00:00
if (!RJW_Genes_Settings.rjw_genes_genetic_disease_spread) return;
2024-07-02 13:19:48 +00:00
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;
2024-07-03 08:14:05 +00:00
// Exit early if settings require penetrative sex, but this is not penetrative sex
2024-07-04 06:20:34 +00:00
if (!DiseaseHelper.IsPenetrativeSex(props) && RJW_Genes_Settings.rjw_genes_genetic_disease_spread_only_on_penetrative_sex) return;
2024-07-03 08:14:05 +00:00
//ModLog.Debug($"Firing Patch_TransferGeneticDiseases for {pawn} and {partner}");
2024-07-02 13:19:48 +00:00
TryTransferGeneticDiseases(pawn, partner, props);
TryTransferGeneticDiseases(partner, pawn, props);
}
private static void TryTransferGeneticDiseases(Pawn infector, Pawn infected, SexProps props)
{
2024-07-04 06:20:34 +00:00
foreach (GeneDef disease in DiseaseHelper.GetGeneticDiseaseGenes(infector)) {
2024-07-02 13:19:48 +00:00
ModLog.Debug($"Found genetic disease {disease} in {infector}, trying to infect {infected}");
2024-07-04 06:20:34 +00:00
if (DiseaseHelper.IsImmuneAgainstGeneticDisease(infected,disease))
2024-07-02 13:19:48 +00:00
continue;
2024-07-04 06:20:34 +00:00
if ((new Random()).NextDouble() <= DiseaseHelper.LookupDiseaseInfectionChance(disease))
2024-07-02 13:19:48 +00:00
{
2024-07-03 08:14:05 +00:00
infected.genes.AddGene(disease, !RJW_Genes_Settings.rjw_genes_genetic_disease_as_endogenes);
2024-07-02 13:19:48 +00:00
}
}
}
}
}