mirror of
				https://github.com/vegapnk/RJW-Genes.git
				synced 2024-08-15 00:23:31 +00:00 
			
		
		
		
	Merge pull request #4 from Shabakur/main
New cleaner method to obtain racegroupdefs and bugfix in Patch_OrgasmRush
This commit is contained in:
		
						commit
						71a3b65c38
					
				
					 8 changed files with 80 additions and 168 deletions
				
			
		
										
											Binary file not shown.
										
									
								
							| 
						 | 
				
			
			@ -14,7 +14,7 @@ namespace RJW_BGS
 | 
			
		|||
    {
 | 
			
		||||
        static First()
 | 
			
		||||
        {
 | 
			
		||||
            RJWcopy.Racegroupdictbuilder();
 | 
			
		||||
            //RJWcopy.Racegroupdictbuilder();
 | 
			
		||||
            //Prints all found race dicts (debugging only)
 | 
			
		||||
            //logAllFoundRaceGroupGenes
 | 
			
		||||
            
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -42,8 +42,7 @@ namespace RJW_BGS
 | 
			
		|||
        public static List<GeneDef> SelectGenes(Pawn pawn)
 | 
			
		||||
        {
 | 
			
		||||
            List<GeneDef> genelist = new List<GeneDef>();
 | 
			
		||||
            PawnKindDef pawnKindDef = pawn.kindDef;
 | 
			
		||||
            RaceGeneDef raceGeneDef = RJWcopy.GetRaceGenDefInternal(pawnKindDef);
 | 
			
		||||
            RaceGeneDef raceGeneDef = RJWcopy.GetRaceGeneDefInternal(pawn);
 | 
			
		||||
            if (raceGeneDef != null)
 | 
			
		||||
            {
 | 
			
		||||
                foreach (BestialityGeneInheritanceDef gene in raceGeneDef.genes)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,6 +5,7 @@ using System.Text;
 | 
			
		|||
using System.Threading.Tasks;
 | 
			
		||||
using Verse;
 | 
			
		||||
using UnityEngine;
 | 
			
		||||
 | 
			
		||||
namespace RJW_Genes.Animal_Inheritance
 | 
			
		||||
{
 | 
			
		||||
    public class RJW_BGSSettings : ModSettings
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,157 +0,0 @@
 | 
			
		|||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using rjw;
 | 
			
		||||
using Verse;
 | 
			
		||||
using RimWorld;
 | 
			
		||||
 | 
			
		||||
namespace RJW_BGS
 | 
			
		||||
{
 | 
			
		||||
    internal class RJWcopy
 | 
			
		||||
    {
 | 
			
		||||
        //Code copied from rjw, as their code was internal and I need the dictionary to know which genes to add to the pawn
 | 
			
		||||
        public static void Racegroupdictbuilder()
 | 
			
		||||
        {
 | 
			
		||||
            foreach (PawnKindDef pawnKindDef2 in from pawnKindDef in DefDatabase<PawnKindDef>.AllDefs
 | 
			
		||||
                                                 where pawnKindDef.race.race != null
 | 
			
		||||
                                                 select pawnKindDef)
 | 
			
		||||
            {
 | 
			
		||||
                RaceGroupDef raceGroupDef = null;
 | 
			
		||||
				bool temp = TryGetRaceGroupDef(pawnKindDef2, out raceGroupDef);
 | 
			
		||||
            }
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public static bool TryGetRaceGroupDef(PawnKindDef pawnKindDef, out RaceGroupDef raceGroupDef)
 | 
			
		||||
		{
 | 
			
		||||
			
 | 
			
		||||
			if (RaceGroupByPawnKind.TryGetValue(pawnKindDef, out raceGroupDef))
 | 
			
		||||
			{
 | 
			
		||||
				return raceGroupDef != null;
 | 
			
		||||
			}
 | 
			
		||||
			raceGroupDef = GetRaceGroupDefInternal(pawnKindDef);
 | 
			
		||||
			RaceGroupByPawnKind.Add(pawnKindDef, raceGroupDef);
 | 
			
		||||
			return raceGroupDef != null;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		
 | 
			
		||||
		public static RaceGroupDef GetRaceGroupDefInternal(PawnKindDef kindDef)
 | 
			
		||||
		{
 | 
			
		||||
			string raceName = kindDef.race.defName;
 | 
			
		||||
			string pawnKindName = kindDef.defName;
 | 
			
		||||
			IEnumerable<RaceGroupDef> allDefs = DefDatabase<RaceGroupDef>.AllDefs;
 | 
			
		||||
			List<RaceGroupDef> pawnKindDefs = allDefs.Where(delegate (RaceGroupDef group)
 | 
			
		||||
			{
 | 
			
		||||
				List<string> pawnKindNames = group.pawnKindNames;
 | 
			
		||||
				return pawnKindNames != null && pawnKindNames.Contains(pawnKindName);
 | 
			
		||||
			}).ToList<RaceGroupDef>();
 | 
			
		||||
			List<RaceGroupDef> raceNameDefs = allDefs.Where(delegate (RaceGroupDef group)
 | 
			
		||||
			{
 | 
			
		||||
				List<string> raceNames = group.raceNames;
 | 
			
		||||
				return raceNames != null && raceNames.Contains(raceName);
 | 
			
		||||
			}).ToList<RaceGroupDef>();
 | 
			
		||||
 | 
			
		||||
			int availableDefs = pawnKindDefs.Count<RaceGroupDef>() + raceNameDefs.Count<RaceGroupDef>();
 | 
			
		||||
			if (availableDefs == 0)
 | 
			
		||||
			{
 | 
			
		||||
				//Exit Early
 | 
			
		||||
				return null;
 | 
			
		||||
			}
 | 
			
		||||
			if (availableDefs == 1)
 | 
			
		||||
			{
 | 
			
		||||
				return pawnKindDefs.Concat(raceNameDefs).Single<RaceGroupDef>();
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			RaceGroupDef result;
 | 
			
		||||
			if ((result = pawnKindDefs.FirstOrDefault((RaceGroupDef match) => !IsThisMod(match))) == null)
 | 
			
		||||
			{
 | 
			
		||||
				if ((result = raceNameDefs.FirstOrDefault((RaceGroupDef match) => !IsThisMod(match))) == null)
 | 
			
		||||
				{
 | 
			
		||||
					result = (pawnKindDefs.FirstOrDefault<RaceGroupDef>() ?? raceNameDefs.FirstOrDefault<RaceGroupDef>());
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			return result;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//slightly modified copy of code above so it also works for racegenedefs
 | 
			
		||||
		public static RaceGeneDef GetRaceGenDefInternal(PawnKindDef kindDef)
 | 
			
		||||
        {
 | 
			
		||||
			if (kindDef == null)
 | 
			
		||||
            {
 | 
			
		||||
				return null;
 | 
			
		||||
            }
 | 
			
		||||
			string raceName = kindDef.race.defName;
 | 
			
		||||
			string pawnKindName = kindDef.defName;
 | 
			
		||||
			RaceGroupDef raceGroupDef = GetRaceGroupDef(kindDef);
 | 
			
		||||
			IEnumerable<RaceGeneDef> allDefs = DefDatabase<RaceGeneDef>.AllDefs;
 | 
			
		||||
			Log.Message(allDefs.Count<RaceGeneDef>().ToString());
 | 
			
		||||
			List<RaceGeneDef> pawnKindDefs = allDefs.Where(delegate (RaceGeneDef group)
 | 
			
		||||
			{
 | 
			
		||||
				List<string> pawnKindNames = group.pawnKindNames;
 | 
			
		||||
				return pawnKindNames != null && pawnKindNames.Contains(pawnKindName);
 | 
			
		||||
			}).ToList<RaceGeneDef>();
 | 
			
		||||
			List<RaceGeneDef> raceKindDefs = allDefs.Where(delegate (RaceGeneDef group)
 | 
			
		||||
			{
 | 
			
		||||
				List<string> raceNames = group.raceNames;
 | 
			
		||||
				return raceNames != null && raceNames.Contains(raceName);
 | 
			
		||||
			}).ToList<RaceGeneDef>();
 | 
			
		||||
			List<RaceGeneDef> raceGroupDefs = new List<RaceGeneDef>();
 | 
			
		||||
			if (raceGroupDef != null)
 | 
			
		||||
			{
 | 
			
		||||
				/*
 | 
			
		||||
				// Log Messages for Debugging Only, prints the Genes found for this individual
 | 
			
		||||
				Log.Message("found a raceGroupDef");
 | 
			
		||||
				Log.Message(raceGroupDef.defName);
 | 
			
		||||
				foreach (RaceGeneDef rgd in allDefs)
 | 
			
		||||
                {
 | 
			
		||||
					Log.Message(rgd.defName);
 | 
			
		||||
                }
 | 
			
		||||
				*/
 | 
			
		||||
				raceGroupDefs = allDefs.Where(delegate (RaceGeneDef group)
 | 
			
		||||
				{
 | 
			
		||||
					String raceGroupDefName = group.raceGroup;
 | 
			
		||||
					return raceGroupDefName != null && raceGroupDefName == raceGroupDef.defName;
 | 
			
		||||
				}).ToList<RaceGeneDef>();
 | 
			
		||||
			}
 | 
			
		||||
			RaceGeneDef result = null;
 | 
			
		||||
			//First check if there is a matching pawnkinddef then race, then racegroup
 | 
			
		||||
			if (pawnKindDefs.Any())
 | 
			
		||||
			{
 | 
			
		||||
				result = pawnKindDefs.RandomElement();
 | 
			
		||||
			}
 | 
			
		||||
			else if (raceKindDefs.Any() && result == null)
 | 
			
		||||
			{
 | 
			
		||||
				result = raceKindDefs.RandomElement();
 | 
			
		||||
			}
 | 
			
		||||
			else if (raceGroupDefs.Any() && result == null)
 | 
			
		||||
			{
 | 
			
		||||
				result = raceGroupDefs.RandomElement();
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
            {
 | 
			
		||||
				result = null;
 | 
			
		||||
            }
 | 
			
		||||
			return result;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static RaceGroupDef GetRaceGroupDef(PawnKindDef kindDef)
 | 
			
		||||
        {
 | 
			
		||||
			RaceGroupDef raceGroupDef = null;
 | 
			
		||||
			bool temp = TryGetRaceGroupDef(kindDef, out raceGroupDef);
 | 
			
		||||
			return raceGroupDef;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static bool IsThisMod(Def def)
 | 
			
		||||
		{
 | 
			
		||||
			return LoadedModManager.RunningMods.Single((ModContentPack pack) => pack.Name == "RimJobWorld").AllDefs.Contains(def);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private static readonly IDictionary<PawnKindDef, RaceGroupDef> RaceGroupByPawnKind = new Dictionary<PawnKindDef, RaceGroupDef>();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
   
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										69
									
								
								Source/Animal_Inheritance/RaceGeneDef_Helper.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								Source/Animal_Inheritance/RaceGeneDef_Helper.cs
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,69 @@
 | 
			
		|||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using rjw;
 | 
			
		||||
using Verse;
 | 
			
		||||
using RimWorld;
 | 
			
		||||
 | 
			
		||||
namespace RJW_BGS
 | 
			
		||||
{
 | 
			
		||||
    internal class RJWcopy
 | 
			
		||||
    {
 | 
			
		||||
      	//code based on racegroupdefinternal which has a similar function
 | 
			
		||||
		public static RaceGeneDef GetRaceGeneDefInternal(Pawn pawn)
 | 
			
		||||
        {
 | 
			
		||||
			PawnKindDef kindDef = pawn.kindDef;
 | 
			
		||||
			if (kindDef == null)
 | 
			
		||||
            {
 | 
			
		||||
				return null;
 | 
			
		||||
            }
 | 
			
		||||
			string raceName = kindDef.race.defName;
 | 
			
		||||
			string pawnKindName = kindDef.defName;
 | 
			
		||||
			IEnumerable<RaceGeneDef> allDefs = DefDatabase<RaceGeneDef>.AllDefs;
 | 
			
		||||
			PawnData pawnData = SaveStorage.DataStore.GetPawnData(pawn);
 | 
			
		||||
			RaceGroupDef raceGroupDef = pawnData.RaceSupportDef;
 | 
			
		||||
			List<RaceGeneDef> pawnKindDefs = allDefs.Where(delegate (RaceGeneDef group)
 | 
			
		||||
			{
 | 
			
		||||
				List<string> pawnKindNames = group.pawnKindNames;
 | 
			
		||||
				return pawnKindNames != null && pawnKindNames.Contains(pawnKindName);
 | 
			
		||||
			}).ToList<RaceGeneDef>();
 | 
			
		||||
			List<RaceGeneDef> raceKindDefs = allDefs.Where(delegate (RaceGeneDef group)
 | 
			
		||||
			{
 | 
			
		||||
				List<string> raceNames = group.raceNames;
 | 
			
		||||
				return raceNames != null && raceNames.Contains(raceName);
 | 
			
		||||
			}).ToList<RaceGeneDef>();
 | 
			
		||||
			List<RaceGeneDef> raceGroupDefs = new List<RaceGeneDef>();
 | 
			
		||||
			if (raceGroupDef != null)
 | 
			
		||||
			{
 | 
			
		||||
				raceGroupDefs = allDefs.Where(delegate (RaceGeneDef group)
 | 
			
		||||
				{
 | 
			
		||||
					String raceGroupDefName = group.raceGroup;
 | 
			
		||||
					return raceGroupDefName != null && raceGroupDefName == raceGroupDef.defName;
 | 
			
		||||
				}).ToList<RaceGeneDef>();
 | 
			
		||||
			}
 | 
			
		||||
			RaceGeneDef result = null;
 | 
			
		||||
			//First check if there is a matching pawnkinddef then race, then racegroup
 | 
			
		||||
			if (pawnKindDefs.Any())
 | 
			
		||||
			{
 | 
			
		||||
				result = pawnKindDefs.RandomElement();
 | 
			
		||||
			}
 | 
			
		||||
			else if (raceKindDefs.Any() && result == null)
 | 
			
		||||
			{
 | 
			
		||||
				result = raceKindDefs.RandomElement();
 | 
			
		||||
			}
 | 
			
		||||
			else if (raceGroupDefs.Any() && result == null)
 | 
			
		||||
			{
 | 
			
		||||
				result = raceGroupDefs.RandomElement();
 | 
			
		||||
			}
 | 
			
		||||
			else
 | 
			
		||||
            {
 | 
			
		||||
				result = null;
 | 
			
		||||
            }
 | 
			
		||||
			return result;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		}
 | 
			
		||||
    } 
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -21,7 +21,7 @@ namespace RJW_Genes
 | 
			
		|||
			if (props.pawn == null || !props.hasPartner())
 | 
			
		||||
				return;
 | 
			
		||||
 | 
			
		||||
			if (props.pawn.genes.HasGene(GeneDefOf.rjw_genes_orgasm_rush))
 | 
			
		||||
			if (props.pawn.genes != null && props.pawn.genes.HasGene(GeneDefOf.rjw_genes_orgasm_rush))
 | 
			
		||||
            {
 | 
			
		||||
				props.pawn.needs.rest.CurLevel += REST_INCREASE;
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,7 +27,7 @@
 | 
			
		|||
      <Private>False</Private>
 | 
			
		||||
    </Reference>
 | 
			
		||||
    <Reference Include="Assembly-CSharp">
 | 
			
		||||
      <HintPath>..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
 | 
			
		||||
      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
 | 
			
		||||
      <Private>False</Private>
 | 
			
		||||
    </Reference>
 | 
			
		||||
    <Reference Include="LicentiaLabs">
 | 
			
		||||
| 
						 | 
				
			
			@ -35,7 +35,7 @@
 | 
			
		|||
      <Private>False</Private>
 | 
			
		||||
    </Reference>
 | 
			
		||||
    <Reference Include="RJW">
 | 
			
		||||
      <HintPath>..\..\rjw\1.4\Assemblies\RJW.dll</HintPath>
 | 
			
		||||
      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\rjw-master\1.4\Assemblies\RJW.dll</HintPath>
 | 
			
		||||
      <Private>False</Private>
 | 
			
		||||
    </Reference>
 | 
			
		||||
    <Reference Include="System" />
 | 
			
		||||
| 
						 | 
				
			
			@ -50,12 +50,12 @@
 | 
			
		|||
    <None Include="..\Common\Defs\Genes\GeneDefs_GenitaliaTypeEndogenes.xml" />
 | 
			
		||||
    <None Include="..\Common\Languages\**" />
 | 
			
		||||
    <None Include="..\Common\Patches\**" />
 | 
			
		||||
    <Reference Include="UnityEngine.CoreModule">
 | 
			
		||||
      <HintPath>..\..\..\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
 | 
			
		||||
    <Reference Include="UnityEngine">
 | 
			
		||||
      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.dll</HintPath>
 | 
			
		||||
      <Private>False</Private>
 | 
			
		||||
    </Reference>
 | 
			
		||||
    <Reference Include="UnityEngine.IMGUIModule">
 | 
			
		||||
      <HintPath>..\..\..\RimWorldWin64_Data\Managed\UnityEngine.IMGUIModule.dll</HintPath>
 | 
			
		||||
    <Reference Include="UnityEngine.CoreModule">
 | 
			
		||||
      <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\RimWorld\RimWorldWin64_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
 | 
			
		||||
      <Private>False</Private>
 | 
			
		||||
    </Reference>
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
| 
						 | 
				
			
			@ -67,7 +67,7 @@
 | 
			
		|||
    <Compile Include="Animal_Inheritance\PatchRJWHediffInsect_Egg.cs" />
 | 
			
		||||
    <Compile Include="Animal_Inheritance\PatchVanillaPregnancyUtility.cs" />
 | 
			
		||||
    <Compile Include="Animal_Inheritance\RaceGeneDef.cs" />
 | 
			
		||||
    <Compile Include="Animal_Inheritance\RJWcopies.cs" />
 | 
			
		||||
    <Compile Include="Animal_Inheritance\RaceGeneDef_Helper.cs" />
 | 
			
		||||
    <Compile Include="Animal_Inheritance\RJW_BGSSettings.cs" />
 | 
			
		||||
    <Compile Include="Animal_Inheritance\RJW_BGSSettingsController.cs" />
 | 
			
		||||
    <Compile Include="Animal_Inheritance\BestialityGeneInheritanceDef.cs" />
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue