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 { public class RaceGeneDef_Helper { //code based on racegroupdefinternal which has a similar function public static RaceGeneDef GetRaceGeneDefInternal(Pawn pawn) { List 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 ValidRaceGeneDefs(Pawn pawn) { PawnKindDef kindDef = pawn.kindDef; if (kindDef == null) { return null; } string raceName = kindDef.race.defName; string pawnKindName = kindDef.defName; PawnData pawnData = SaveStorage.DataStore.GetPawnData(pawn); RaceGroupDef raceGroupDef = pawnData.RaceSupportDef; IEnumerable allDefs = DefDatabase.AllDefs; List pawnKindDefs = allDefs.Where(delegate (RaceGeneDef group) { List pawnKindNames = group.pawnKindNames; return pawnKindNames != null && pawnKindNames.Contains(pawnKindName); }).ToList(); if (pawnKindDefs.Count() > 0) return pawnKindDefs; List raceKindDefs = allDefs.Where(delegate (RaceGeneDef group) { List raceNames = group.raceNames; return raceNames != null && raceNames.Contains(raceName); }).ToList(); if (raceKindDefs.Count() > 0) return raceKindDefs; List raceGroupDefs = new List(); if (raceGroupDef != null) { raceGroupDefs = allDefs.Where(delegate (RaceGeneDef group) { String raceGroupDefName = group.raceGroup; return raceGroupDefName != null && raceGroupDefName == raceGroupDef.defName; }).ToList(); } if (raceGroupDefs.Count() > 0) return raceGroupDefs; return new List(); } } }