2024-07-02 13:19:48 +00:00
|
|
|
|
using HarmonyLib;
|
2024-07-05 13:04:45 +00:00
|
|
|
|
using RimWorld;
|
2024-07-02 13:19:48 +00:00
|
|
|
|
using rjw;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Verse;
|
|
|
|
|
|
2024-07-04 07:19:34 +00:00
|
|
|
|
namespace RJW_Genes
|
2024-07-02 13:19:48 +00:00
|
|
|
|
{
|
|
|
|
|
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
|
|
|
|
|
public class Patch_AftersexUtility_TransferGeneticDiseases
|
|
|
|
|
{
|
|
|
|
|
|
2024-07-05 13:04:45 +00:00
|
|
|
|
public const int FACTION_GOODWILL_CHANGE = -2;
|
|
|
|
|
|
2024-07-02 13:19:48 +00:00
|
|
|
|
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
|
|
|
|
|
2024-07-04 07:19:34 +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-05 13:04:45 +00:00
|
|
|
|
HandleFactionGoodWillPenalties(infector, infected);
|
2024-07-02 13:19:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-05 13:04:45 +00:00
|
|
|
|
private static void HandleFactionGoodWillPenalties(Pawn actor, Pawn target)
|
|
|
|
|
{
|
|
|
|
|
if (
|
|
|
|
|
target.Faction != null && actor.Faction != null
|
|
|
|
|
&& target.Faction != actor.Faction
|
|
|
|
|
&& target.Faction != Faction.OfPlayer)
|
|
|
|
|
{
|
|
|
|
|
HistoryEventDef reason = DefDatabase<HistoryEventDef>.GetNamedSilentFail("rjw_genes_GoodwillChangedReason_spread_genetic_disease");
|
|
|
|
|
target.Faction.TryAffectGoodwillWith(actor.Faction, FACTION_GOODWILL_CHANGE, true, true, reason, target);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 13:19:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|