mirror of
				https://github.com/vegapnk/RJW-Genes.git
				synced 2024-08-15 00:23:31 +00:00 
			
		
		
		
	Added the first genetic infector gene, stretcher, and docs for it
This commit is contained in:
		
							parent
							
								
									65ff62cbf9
								
							
						
					
					
						commit
						56f8c2b6b2
					
				
					 7 changed files with 167 additions and 4 deletions
				
			
		
							
								
								
									
										17
									
								
								Source/Genes/Diseases/Defs/GeneticInfectorExtension.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								Source/Genes/Diseases/Defs/GeneticInfectorExtension.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,17 @@
 | 
			
		|||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Verse;
 | 
			
		||||
 | 
			
		||||
namespace RJW_Genes
 | 
			
		||||
{
 | 
			
		||||
    public class GeneticInfectorExtension : DefModExtension
 | 
			
		||||
    {
 | 
			
		||||
        public float infectionChance;
 | 
			
		||||
 | 
			
		||||
        public List<string> infectionGenes;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -71,6 +71,31 @@ namespace RJW_Genes
 | 
			
		|||
            return new List<GeneDef>() { };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static List<GeneDef> GetGeneticInfectorGenes(Pawn pawn)
 | 
			
		||||
        {
 | 
			
		||||
            if (pawn != null && pawn.genes != null)
 | 
			
		||||
            {
 | 
			
		||||
                return pawn.genes
 | 
			
		||||
                    .GenesListForReading
 | 
			
		||||
                    .ConvertAll(gene => gene.def)
 | 
			
		||||
                    .Where(genedef => pawn.genes.HasActiveGene(genedef))
 | 
			
		||||
                    .Where(IsGeneticInfectorGene)
 | 
			
		||||
                    .ToList();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return new List<GeneDef>() { };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static List<GeneDef> LookupInfectionGeneDefs(GeneticInfectorExtension infectorExt)
 | 
			
		||||
        {
 | 
			
		||||
            if (infectorExt == null) new List<GeneDef>();
 | 
			
		||||
 | 
			
		||||
            return RimWorld.GeneUtility
 | 
			
		||||
                .GenesInOrder
 | 
			
		||||
                .Where(genedef => infectorExt.infectionGenes.Contains(genedef.defName))
 | 
			
		||||
                .ToList();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /// <summary>
 | 
			
		||||
        /// Checks if the performed sex was penetrative. 
 | 
			
		||||
        /// Condom check is not done here!
 | 
			
		||||
| 
						 | 
				
			
			@ -97,6 +122,13 @@ namespace RJW_Genes
 | 
			
		|||
            return diseaseExt != null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static bool IsGeneticInfectorGene(GeneDef geneDef)
 | 
			
		||||
        {
 | 
			
		||||
            if (geneDef == null) return false;
 | 
			
		||||
            GeneticInfectorExtension infectorExt = geneDef.GetModExtension<GeneticInfectorExtension>();
 | 
			
		||||
            return infectorExt != null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static float LookupDiseaseInfectionChance(GeneDef geneDef)
 | 
			
		||||
        {
 | 
			
		||||
            if (IsGeneticDiseaseGene(geneDef))
 | 
			
		||||
| 
						 | 
				
			
			@ -107,5 +139,7 @@ namespace RJW_Genes
 | 
			
		|||
            else
 | 
			
		||||
                return 0.0f;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -76,9 +76,11 @@
 | 
			
		|||
    <Compile Include="Genes\Cum\Patch_LikesCumflation.cs" />
 | 
			
		||||
    <Compile Include="Genes\Damage\Gene_Elasticity.cs" />
 | 
			
		||||
    <Compile Include="Genes\Diseases\Defs\GeneticDiseaseExtension.cs" />
 | 
			
		||||
    <Compile Include="Genes\Diseases\Defs\GeneticInfectorExtension.cs" />
 | 
			
		||||
    <Compile Include="Genes\Diseases\Defs\ImmunityAgainstGenesExtension.cs" />
 | 
			
		||||
    <Compile Include="Genes\Diseases\DiseaseHelper.cs" />
 | 
			
		||||
    <Compile Include="Genes\Diseases\Genes\Gene_FluctualSexualNeed.cs" />
 | 
			
		||||
    <Compile Include="Genes\Diseases\Patches\Patch_AfterSexUtility_ApplyGeneticInfectors.cs" />
 | 
			
		||||
    <Compile Include="Genes\Diseases\Patches\Patch_AftersexUtility_TransferGeneticDiseases.cs" />
 | 
			
		||||
    <Compile Include="Genes\Diseases\Patches\Patch_SecondaryRomanceChanceFactor_Gene_SizeBlinded.cs" />
 | 
			
		||||
    <Compile Include="Genes\Diseases\Thoughts\ThoughtWorker_SizeBlinded_Social.cs" />
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue