Added the first genetic infector gene, stretcher, and docs for it

This commit is contained in:
Vegapnk 2024-07-04 09:19:34 +02:00
parent 65ff62cbf9
commit 56f8c2b6b2
7 changed files with 167 additions and 4 deletions

View file

@ -0,0 +1,57 @@
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);
}
}
}
}
}

View file

@ -7,7 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using Verse;
namespace RJW_Genes.Genes.Diseases.Patches
namespace RJW_Genes
{
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
public class Patch_AftersexUtility_TransferGeneticDiseases
@ -31,7 +31,7 @@ namespace RJW_Genes.Genes.Diseases.Patches
// 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;
ModLog.Debug($"Firing Patch_TransferGeneticDiseases for {pawn} and {partner}");
//ModLog.Debug($"Firing Patch_TransferGeneticDiseases for {pawn} and {partner}");
TryTransferGeneticDiseases(pawn, partner, props);
TryTransferGeneticDiseases(partner, pawn, props);
}