using RJW_Genes; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Verse; namespace RJW_BGS { public class VGEHybridUtility { /// /// All VGE-Hybrids that can result from Bestiality - these are drawn from the existing XML-Defs. /// public static List SupportedHybridRaces { get{return DefDatabase.AllDefs.SelectMany(def => def.PossibleHybridChildKindDefs).Distinct().ToList();} } /// /// All Animals that can produce VGE Hybrids - these are drawn from the existing XML-Defs. /// public static List SupportedInitialAnimalRaces { get { return DefDatabase.AllDefs.SelectMany(def => def.SupportedParentKindDefs).Distinct().ToList(); } } /// /// Returns a possible Hybrid KindDef for a given Animal. /// Null if there is none. /// Random one if there are multiple. /// /// The animal fathering the baby /// KindDef for Hybrid originated from Parent Animal. Null on None, Not-Supported or Error. Random one from multiple. public static PawnKindDef LookupPossiblyOffspringHybrid(PawnKindDef Parent) { if (Parent == null) return null; if (!SupportedInitialAnimalRaces.Contains(Parent)) return null; else { return DefDatabase.AllDefs .Where(def => def.SupportedParentKindDefs.Contains(Parent)) .SelectMany(def => def.PossibleHybridChildKindDefs) .Distinct() .RandomElementWithFallback(null); // Man I am a true Java Developer } } /// /// Small Method for debugging - I used it mostly on game-startup to see if reading all Defs worked fine. /// Introduced after the VGE-Hybridization Rework from #116 /// public static void LogAllFoundVGEHybridDefinitions() { IEnumerable defs = DefDatabase.AllDefs; var parents = defs.SelectMany(def => def.SupportedParentKindDefs).Distinct(); var offsprings = defs.SelectMany(def => def.PossibleHybridChildKindDefs).Distinct(); RJW_Genes.ModLog.Debug($"Found {defs.Count()} VGEHybridOffspringDefs, covering {parents.Count()} distinct possible parent-animals and {offsprings.Count()} distinct possible hybrid-children."); } } }