Fixed and improved prioritization of racegenedefs

Added an priority option to xml which decides the racegenedef to choose if an animal is present in multiple racegenedefs (under the same variable (racegroups, racenames or kinddefs
This commit is contained in:
Shabakur 2022-12-22 19:04:56 +01:00
parent cc43a5a5aa
commit 8a7138106a
4 changed files with 26 additions and 27 deletions

Binary file not shown.

View file

@ -42,7 +42,7 @@ namespace RJW_BGS
public static List<GeneDef> SelectGenes(Pawn pawn)
{
List<GeneDef> genelist = new List<GeneDef>();
RaceGeneDef raceGeneDef = RJWcopy.GetRaceGeneDefInternal(pawn);
RaceGeneDef raceGeneDef = RaceGeneDef_Helper.GetRaceGeneDefInternal(pawn);
if (raceGeneDef != null)
{
foreach (BestialityGeneInheritanceDef gene in raceGeneDef.genes)

View file

@ -10,7 +10,7 @@ namespace RJW_BGS
{
public class RaceGeneDef : Def
{
public int priority;
public String raceGroup;
public List<string> raceNames;
public List<string> pawnKindNames;

View file

@ -9,31 +9,48 @@ using RimWorld;
namespace RJW_BGS
{
internal class RJWcopy
public class RaceGeneDef_Helper
{
//code based on racegroupdefinternal which has a similar function
public static RaceGeneDef GetRaceGeneDefInternal(Pawn pawn)
{
List<RaceGeneDef> Valids = ValidRaceGeneDefs(pawn);
if (Valids.Count > 0)
{
RaceGeneDef result = Valids.MaxBy(r => r.priority);
return result;
}
return null;
//First check if there is a matching pawnkinddef then race, then racegroup
}
public static List<RaceGeneDef> ValidRaceGeneDefs(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;
IEnumerable<RaceGeneDef> allDefs = DefDatabase<RaceGeneDef>.AllDefs;
List<RaceGeneDef> pawnKindDefs = allDefs.Where(delegate (RaceGeneDef group)
{
List<string> pawnKindNames = group.pawnKindNames;
return pawnKindNames != null && pawnKindNames.Contains(pawnKindName);
}).ToList<RaceGeneDef>();
if (pawnKindDefs.Count() > 0)
return pawnKindDefs;
List<RaceGeneDef> raceKindDefs = allDefs.Where(delegate (RaceGeneDef group)
{
List<string> raceNames = group.raceNames;
return raceNames != null && raceNames.Contains(raceName);
}).ToList<RaceGeneDef>();
if (raceKindDefs.Count() > 0)
return raceKindDefs;
List<RaceGeneDef> raceGroupDefs = new List<RaceGeneDef>();
if (raceGroupDef != null)
{
@ -43,27 +60,9 @@ namespace RJW_BGS
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;
if (raceGroupDefs.Count() > 0)
return raceGroupDefs;
return new List<RaceGeneDef>();
}
}
}