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