Draft for Genetic Diseases

This commit is contained in:
Vegapnk 2024-07-02 15:19:48 +02:00
parent 92e917f473
commit 3aa6fdaabd
8 changed files with 188 additions and 1 deletions

View file

@ -67,5 +67,11 @@
<displayPriorityInXenotype>8</displayPriorityInXenotype> <displayPriorityInXenotype>8</displayPriorityInXenotype>
</GeneCategoryDef> </GeneCategoryDef>
<GeneCategoryDef>
<defName>rjw_genes_diseases</defName>
<label>genetic STDs</label>
<displayPriorityInXenotype>22</displayPriorityInXenotype>
</GeneCategoryDef>
</Defs> </Defs>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<GeneDef>
<displayCategory>rjw_genes_diseases</displayCategory>
<defName>rjw_genes_genetic_disease_immunity</defName>
<displayOrderInCategory>1</displayOrderInCategory>
<label>genetic disease immunity</label>
<description>This gene makes the pawn immune against genetic STDs and other genes that imply negative side-effects. </description>
<biostatCpx>2</biostatCpx>
<biostatMet>-1</biostatMet>
<iconPath>UI/Icons/ColonistBar/Idle</iconPath>
<li MayRequire="OskarPotocki.VanillaFactionsExpanded.Core"
Class="VanillaGenesExpanded.GeneExtension">
<backgroundPathEndogenes>Genes/Icons/RJW_Genes_Endogene_Background</backgroundPathEndogenes>
<backgroundPathXenogenes>Genes/Icons/RJW_Genes_Xenogene_Background</backgroundPathXenogenes>
</li>
</GeneDef>
<GeneDef>
<displayCategory>rjw_genes_diseases</displayCategory>
<defName>rjw_genes_minor_vulnerability</defName>
<geneClass>RJW_Genes.DiseaseGene</geneClass>
<label>minor vulnerability</label>
<description>This gene makes the pawn more vulnerable, and a more attractive target for rape. </description>
<biostatCpx>2</biostatCpx>
<biostatMet>-1</biostatMet>
<iconPath>UI/Icons/ColonistBar/Idle</iconPath>
<displayOrderInCategory>3</displayOrderInCategory>
<modExtensions>
<li MayRequire="OskarPotocki.VanillaFactionsExpanded.Core"
Class="VanillaGenesExpanded.GeneExtension">
<backgroundPathEndogenes>Genes/Icons/RJW_Genes_Endogene_Background</backgroundPathEndogenes>
<backgroundPathXenogenes>Genes/Icons/RJW_Genes_Xenogene_Background</backgroundPathXenogenes>
</li>
<li Class="RJW_Genes.GeneticDiseaseExtension">
<infectionChance>1.0</infectionChance>
</li>
</modExtensions>
</GeneDef>
</Defs>

View file

@ -30,5 +30,12 @@ namespace RJW_Genes
Log.Warning($"[{ModId}] {message}"); Log.Warning($"[{ModId}] {message}");
} }
public static void Debug(string message)
{
if (RJW_Genes_Settings.rjw_genes_detailed_debug)
{
Log.Message($"[{ModId}][debug] {message}");
}
}
} }
} }

View file

@ -109,7 +109,7 @@ namespace RJW_Genes
public static readonly GeneDef rjw_genes_succubus_tail; public static readonly GeneDef rjw_genes_succubus_tail;
public static readonly GeneDef rjw_genes_succubus_wings; public static readonly GeneDef rjw_genes_succubus_wings;
//life force // Life force | Fertilin
public static readonly GeneDef rjw_genes_lifeforce; public static readonly GeneDef rjw_genes_lifeforce;
public static readonly GeneDef rjw_genes_pussyhealing; public static readonly GeneDef rjw_genes_pussyhealing;
public static readonly GeneDef rjw_genes_lifeforce_drain; public static readonly GeneDef rjw_genes_lifeforce_drain;
@ -121,6 +121,10 @@ namespace RJW_Genes
public static readonly GeneDef rjw_genes_cockeater; public static readonly GeneDef rjw_genes_cockeater;
public static readonly GeneDef rjw_genes_lifeforce_empath; public static readonly GeneDef rjw_genes_lifeforce_empath;
// Diseases
public static readonly GeneDef rjw_genes_genetic_disease_immunity;
public static readonly GeneDef rjw_genes_minor_vulnerability;
//Other Defs //Other Defs
public static readonly XenotypeDef rjw_genes_succubus; public static readonly XenotypeDef rjw_genes_succubus;
public static readonly DutyDef rjw_genes_flirt; public static readonly DutyDef rjw_genes_flirt;

View file

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace RJW_Genes
{
public class GeneticDiseaseExtension : DefModExtension
{
/// <summary>
/// The chance for this gene to spread upon (finished) sex.
/// </summary>
public float infectionChance;
}
}

View file

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Verse;
namespace RJW_Genes
{
public class DiseaseGene : Gene
{
}
}

View file

@ -0,0 +1,86 @@
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.Genes.Diseases.Patches
{
[HarmonyPatch(typeof(SexUtility), "Aftersex")]
public class Patch_AftersexUtility_TransferGeneticDiseases
{
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;
ModLog.Debug($"Firing Patch_TransferGeneticDiseases for {pawn} and {partner}");
TryTransferGeneticDiseases(pawn, partner, props);
TryTransferGeneticDiseases(partner, pawn, props);
}
private static void TryTransferGeneticDiseases(Pawn infector, Pawn infected, SexProps props)
{
if (infected.genes.HasActiveGene(GeneDefOf.rjw_genes_genetic_disease_immunity))
{
ModLog.Debug($"{infected} is immune to genetic diseases");
return;
}
foreach (GeneDef disease in GetGeneticDiseaseGenes(infector)) {
ModLog.Debug($"Found genetic disease {disease} in {infector}, trying to infect {infected}");
if (infected.genes.HasActiveGene(disease))
continue;
if ((new Random()).NextDouble() <= LookupDiseaseInfectionChance(disease))
{
infected.genes.AddGene(disease, false);
}
}
}
private static List<GeneDef> GetGeneticDiseaseGenes(Pawn pawn)
{
if (pawn != null && pawn.genes != null)
{
return pawn.genes
.GenesListForReading
.ConvertAll(gene => gene.def)
.Where(genedef => pawn.genes.HasActiveGene(genedef))
.Where(IsGeneticDiseaseGene)
.ToList();
}
return new List<GeneDef>() { };
}
private static bool IsGeneticDiseaseGene(GeneDef geneDef)
{
return geneDef.geneClass.FullName.Contains("DiseaseGene");
}
private static float LookupDiseaseInfectionChance(GeneDef geneDef)
{
if (IsGeneticDiseaseGene(geneDef))
{
GeneticDiseaseExtension diseaseExt = geneDef.GetModExtension<GeneticDiseaseExtension>();
return diseaseExt != null ? diseaseExt.infectionChance : 0.0f;
}
else
return 0.0f;
}
}
}

View file

@ -74,6 +74,9 @@
<Compile Include="Genes\Breeding\Genes\Gene_InsectIncubator.cs" /> <Compile Include="Genes\Breeding\Genes\Gene_InsectIncubator.cs" />
<Compile Include="Genes\Cum\Patch_LikesCumflation.cs" /> <Compile Include="Genes\Cum\Patch_LikesCumflation.cs" />
<Compile Include="Genes\Damage\Gene_Elasticity.cs" /> <Compile Include="Genes\Damage\Gene_Elasticity.cs" />
<Compile Include="Genes\Diseases\Defs\GeneticDiseaseExtension.cs" />
<Compile Include="Genes\Diseases\Genes\DiseaseGene.cs" />
<Compile Include="Genes\Diseases\Patches\Patch_AftersexUtility_TransferGeneticDiseases.cs" />
<Compile Include="Genes\Life_Force\Events\SuccubusVisit\IncidentWorker_SuccubusVisit.cs" /> <Compile Include="Genes\Life_Force\Events\SuccubusVisit\IncidentWorker_SuccubusVisit.cs" />
<Compile Include="Genes\Life_Force\Events\SuccubusVisit\LordJob_SuccubusVisit.cs" /> <Compile Include="Genes\Life_Force\Events\SuccubusVisit\LordJob_SuccubusVisit.cs" />
<Compile Include="Genes\Life_Force\Interactions\SuccubusTailjob\DomSuccubusTailCustomRequirementHandler.cs" /> <Compile Include="Genes\Life_Force\Interactions\SuccubusTailjob\DomSuccubusTailCustomRequirementHandler.cs" />