Beispiel #1
0
        public static bool TryGetRaceGroupDef(Pawn pawn, out RaceGroupDef raceGroupDef)
        {
            var raceName     = pawn.kindDef.race.defName;
            var pawnKindName = pawn.kindDef.defName;
            var groups       = DefDatabase <RaceGroupDef> .AllDefs;

            // Not sure searching by pawnKindName is a good idea but it is needed to reproduce previous functionality 100%.
            raceGroupDef = groups.FirstOrDefault(group => group.pawnKindNames?.Contains(pawnKindName) ?? false)
                           ?? groups.FirstOrDefault(group => group.raceNames?.Contains(raceName) ?? false);
            return(raceGroupDef != null);
        }
Beispiel #2
0
        public static bool TryChooseRacePartDef(RaceGroupDef raceGroupDef, SexPartType sexPartType, out RacePartDef racePartDef)
        {
            var partNames = raceGroupDef.GetRacePartDefNames(sexPartType);

            if (partNames == null)
            {
                // Missing list, so nothing was chosen.
                racePartDef = null;
                return(false);
            }
            else if (!partNames.Any())
            {
                // Empty list, so "no part" was chosen.
                racePartDef = RacePartDef.None;
                return(true);
            }

            var chances    = raceGroupDef.GetChances(sexPartType);
            var hasChances = chances != null && chances.Count() > 0;

            if (hasChances && chances.Count() != partNames.Count())
            {
                // No need for this to be runtime, should probably be a config error in RaceGroupDef.
                Log.Error($"[RJW] RaceGroupDef named {raceGroupDef.defName} has {partNames.Count()} parts but {chances.Count()} chances for {sexPartType}.");
                racePartDef = null;
                return(false);
            }

            string partName;

            if (hasChances)
            {
                var indexes = partNames.Select((x, i) => i);
                partName = partNames[indexes.RandomElementByWeight(i => chances[i])];
            }
            else
            {
                partName = partNames.RandomElement();
            }

            racePartDef = DefDatabase <RacePartDef> .GetNamedSilentFail(partName);

            if (racePartDef == null)
            {
                Log.Error($"[RJW] Could not find a RacePartDef named {partName} referenced by RaceGroupDef named {raceGroupDef.defName}.");
                return(false);
            }
            else
            {
                return(true);
            }
        }
 public static bool TryGetRaceGroupDef(Pawn pawn, out RaceGroupDef raceGroupDef)
 {
     if (RaceGroupByPawnKind.TryGetValue(pawn.kindDef, out raceGroupDef))
     {
         return(raceGroupDef != null);
     }
     else
     {
         raceGroupDef = GetRaceGroupDefInternal(pawn);
         RaceGroupByPawnKind.Add(pawn.kindDef, raceGroupDef);
         return(raceGroupDef != null);
     }
 }
Beispiel #4
0
        public static List <float> GetPartsChances(RaceGroupDef raceGroupDef, SexPartType sexPartType)
        {
            switch (sexPartType)
            {
            case SexPartType.Anus:
                return(raceGroupDef.chanceanuses);

            case SexPartType.FemaleBreast:
                return(raceGroupDef.chancefemaleBreasts);

            case SexPartType.FemaleGenital:
                return(raceGroupDef.chancefemaleGenitals);

            case SexPartType.MaleBreast:
                return(raceGroupDef.chancemaleBreasts);

            case SexPartType.MaleGenital:
                return(raceGroupDef.chancemaleGenitals);

            default:
                throw new ApplicationException($"Unrecognized sexPartType: {sexPartType}");
            }
        }