Beispiel #1
0
        public static SimDescription MakeDescendant(SimDescription dad, SimDescription mom, SimDescription robotDad, SimDescription robotMom,
                                                    CASAgeGenderFlags age, CASAgeGenderFlags gender, float averageMood, Random pregoRandom, bool interactive, bool updateGenealogy,
                                                    bool setName, WorldName homeWorld, bool plantSimBaby, Pregnancy.BabyCustomizeData customizeData)
        {
            if (robotDad == null && robotMom == null)
            {
                Common.DebugNotify("CommonSurrogatePregnancy.MakeDescendant" + Common.NewLine + " - Fail: Robot Parnets Null");
                return(null);
            }

            SimBuilder simBuilder = new SimBuilder();

            simBuilder.Age            = age;
            simBuilder.Gender         = gender;
            simBuilder.Species        = CASAgeGenderFlags.Human;
            simBuilder.TextureSize    = 1024u;
            simBuilder.UseCompression = true;
            List <SimDescription> list = new List <SimDescription>();

            if (mom != null)
            {
                list.Add(mom);
            }

            if (dad != null)
            {
                list.Add(dad);
            }

            float alienDNAPercentage = SimDescription.GetAlienDNAPercentage(dad, mom, true);

            SimDescription[] array = list.ToArray();
            bool             flag  = alienDNAPercentage >= SimDescription.kMinAlienDNAPercentToBeAlien;

            if (plantSimBaby)
            {
                float skinToneIndex = OccultPlantSim.kBaseGreenSkinIndex + RandomUtil.GetFloat(1f - OccultPlantSim.kBaseGreenSkinIndex);
                simBuilder.SkinTone      = new ResourceKey(2751605866008866797uL, 55867754u, 0u);
                simBuilder.SkinToneIndex = skinToneIndex;
            }
            else
            {
                Genetics.InheritSkinColor(simBuilder, array, pregoRandom, homeWorld);
            }

            if (customizeData.IsBabyCustomized)
            {
                CASPart mPart = customizeData.EyeColorPreset.mPart;

                if (simBuilder.AddPart(mPart))
                {
                    string mPresetString = customizeData.EyeColorPreset.mPresetString;

                    if (!string.IsNullOrEmpty(mPresetString))
                    {
                        OutfitUtils.ApplyPresetStringToPart(simBuilder, mPart, mPresetString);
                    }
                }
            }
            else
            {
                Genetics.InheritEyeColor(simBuilder, array, pregoRandom);
            }

            Genetics.InheritFacialBlends(simBuilder, array, pregoRandom);
            ResourceKey geneticHairstyleKey = Genetics.InheritHairStyle(gender, dad, mom, pregoRandom, flag);

            Genetics.InheritBodyShape(simBuilder, array, pregoRandom);
            bool  flag2 = pregoRandom.Next(0, 2) == 0;
            float num   = (float)pregoRandom.NextDouble() * 100f;

            Color[] array2;

            if (customizeData.IsBabyCustomized)
            {
                array2 = new Color[10];

                for (int i = 0; i < 4; i++)
                {
                    array2[i]     = customizeData.HairColor[i];
                    array2[i + 5] = customizeData.HairColor[i];
                }

                array2[4] = customizeData.HairColor[0];
                array2[9] = customizeData.HairColor[0];
            }
            else if (age == CASAgeGenderFlags.Elder)
            {
                array2 = Genetics.GetRandomElderHairColor();
            }
            else
            {
                array2 = Genetics.InheritHairColor(simBuilder, array, pregoRandom);
            }

            SimDescription baby = Genetics.MakeSim(simBuilder, CASAgeGenderFlags.Baby, gender, simBuilder.SkinTone, simBuilder.SkinToneIndex, array2, homeWorld, 4294967295u, false);

            if (baby == null)
            {
                return(null);
            }

            baby.SetAlienDNAPercentage(alienDNAPercentage);
            baby.GeneticHairstyleKey = geneticHairstyleKey;
            bool flag3 = false;

            if (num < Genetics.kInheritMomHiddenBodyHairStyleChance)
            {
                flag3 |= Genetics.InheritBodyHairstyle(baby, mom);
            }

            if (!flag3 || num < Genetics.kInheritDadBodyHairStyleChance + Genetics.kInheritMomHiddenBodyHairStyleChance)
            {
                Genetics.InheritBodyHairstyle(baby, dad);
            }

            if (customizeData.IsBabyCustomized)
            {
                Genetics.TraitOutcome traitOutcome = Genetics.AssignTraits(baby, dad, mom, false, averageMood, pregoRandom);
                List <TraitNames>     list2        = new List <TraitNames>();
                List <Trait>          list3        = new List <Trait>();

                foreach (Trait current in baby.TraitManager.List)
                {
                    if (!current.IsVisible)
                    {
                        list3.Add(current);
                    }
                }

                baby.TraitManager.RemoveAllElements();

                if (customizeData.CurrentTraits != null)
                {
                    foreach (ITraitEntryInfo current2 in customizeData.CurrentTraits)
                    {
                        baby.TraitManager.AddElement((TraitNames)current2.TraitGuid);
                    }

                    if (customizeData.CurrentTraits.Count != 2)
                    {
                        baby.TraitManager.AddRandomTrait(2 - customizeData.CurrentTraits.Count);
                    }

                    foreach (Trait current3 in list3)
                    {
                        baby.TraitManager.AddHiddenElement((TraitNames)current3.TraitGuid);
                    }
                }

                foreach (Trait current4 in baby.TraitManager.List)
                {
                    if (current4.IsVisible)
                    {
                        list2.Add((TraitNames)current4.TraitGuid);
                    }
                }

                if (interactive)
                {
                    bool   isFemale   = baby.IsFemale;
                    string titleText  = Localization.LocalizeString(baby.IsFemale, "Gameplay/CAS/Genetics:MakeBabyTitle", new object[0]);
                    string promptText = null;

                    switch (traitOutcome)
                    {
                    case Genetics.TraitOutcome.Horrible:
                    {
                        string entryKey = "Gameplay/CAS/Genetics:MakeBabyDescTwoTraitsHorrible";
                        promptText = Localization.LocalizeString(baby.IsFemale, entryKey, new object[]
                            {
                                robotMom == null ? mom : robotMom,
                                baby.TraitManager.GetElement((ulong)list2[0]).TraitName(baby.IsFemale),
                                baby.TraitManager.GetElement((ulong)list2[1]).TraitName(baby.IsFemale)
                            });
                        break;
                    }

                    case Genetics.TraitOutcome.Bad:
                    {
                        string entryKey = "Gameplay/CAS/Genetics:MakeBabyDescTwoTraitsBad";
                        promptText = Localization.LocalizeString(baby.IsFemale, entryKey, new object[]
                            {
                                robotMom == null ? mom : robotMom,
                                baby.TraitManager.GetElement((ulong)list2[0]).TraitName(baby.IsFemale),
                                baby.TraitManager.GetElement((ulong)list2[1]).TraitName(baby.IsFemale)
                            });
                        break;
                    }

                    case Genetics.TraitOutcome.Average:
                    {
                        string entryKey = "Gameplay/CAS/Genetics:MakeBabyDescTwoTraits";
                        promptText = Localization.LocalizeString(baby.IsFemale, entryKey, new object[]
                            {
                                robotMom == null ? mom : robotMom,
                                baby.TraitManager.GetElement((ulong)list2[0]).TraitName(baby.IsFemale),
                                baby.TraitManager.GetElement((ulong)list2[1]).TraitName(baby.IsFemale)
                            });
                        break;
                    }

                    case Genetics.TraitOutcome.Good:
                    {
                        string entryKey = "Gameplay/CAS/Genetics:MakeBabyDescOneTraits";
                        promptText = Localization.LocalizeString(baby.IsFemale, entryKey, new object[]
                            {
                                robotMom == null ? mom : robotMom,
                                baby.TraitManager.GetElement((ulong)list2[0]).TraitName(baby.IsFemale)
                            });
                        break;
                    }

                    case Genetics.TraitOutcome.Excellent:
                    {
                        string entryKey = "Gameplay/CAS/Genetics:MakeBabyDesc";
                        promptText = Localization.LocalizeString(baby.IsFemale, entryKey, new object[]
                            {
                                robotMom == null ? mom : robotMom,
                            });
                        break;
                    }
                    }

                    while (string.IsNullOrEmpty(baby.FirstName))
                    {
                        baby.FirstName = StringInputDialog.Show(titleText, promptText, "", CASBasics.GetMaxNameLength(), StringInputDialog.Validation.SimNameText);
                    }
                }
            }
            else
            {
                Genetics.AssignTraits(baby, dad, mom, interactive, averageMood, pregoRandom);
            }

            if (setName)
            {
                baby.LastName = array[0].LastName;

                if (!interactive)
                {
                    baby.FirstName = SimUtils.GetRandomGivenName(baby.IsMale, homeWorld);
                }
            }

            baby.CelebrityManager.SetBabyLevel(Genetics.AssignBabyCelebrityLevel(dad, mom));

            if (updateGenealogy)
            {
                if (robotDad != null && robotMom == null)
                {
                    if (robotDad.Genealogy != null)
                    {
                        robotDad.Genealogy.AddChild(baby.Genealogy);
                    }

                    if (mom != null && mom.Genealogy != null)
                    {
                        mom.Genealogy.AddChild(baby.Genealogy);
                    }
                }
                else if (robotMom != null && robotDad == null)
                {
                    if (robotMom.Genealogy != null)
                    {
                        robotMom.Genealogy.AddChild(baby.Genealogy);
                    }

                    if (dad != null && dad.Genealogy != null)
                    {
                        dad.Genealogy.AddChild(baby.Genealogy);
                    }
                }
                else
                {
                    if (robotDad.Genealogy != null)
                    {
                        robotDad.Genealogy.AddChild(baby.Genealogy);
                    }

                    if (robotMom.Genealogy != null)
                    {
                        robotMom.Genealogy.AddChild(baby.Genealogy);
                    }
                }
            }

            OccultTypes occultTypes = OccultTypes.None;

            if (flag2)
            {
                if (mom != null)
                {
                    CASSupernaturalData supernaturalData = mom.SupernaturalData;

                    if (supernaturalData != null)
                    {
                        occultTypes = supernaturalData.OccultType;
                    }
                }
            }
            else if (dad != null)
            {
                CASSupernaturalData supernaturalData2 = dad.SupernaturalData;

                if (supernaturalData2 != null)
                {
                    occultTypes = supernaturalData2.OccultType;
                }
            }

            if (plantSimBaby)
            {
                occultTypes = OccultTypes.PlantSim;
            }

            if (!OccultManager.DoesOccultTransferToOffspring(occultTypes))
            {
                occultTypes = OccultTypes.None;
            }

            if (RandomUtil.CoinFlip())
            {
                if (occultTypes == OccultTypes.Fairy)
                {
                    baby.AddSupernaturalData(OccultTypes.Fairy);
                    CASFairyData fairyData = baby.SupernaturalData as CASFairyData;

                    if (fairyData != null)
                    {
                        Vector3   wingColor;
                        WingTypes wingType;
                        Genetics.InheritWings(baby, mom, dad, pregoRandom, out wingColor, out wingType);
                        fairyData.WingType  = wingType;
                        fairyData.WingColor = wingColor;
                    }
                }

                if (occultTypes != OccultTypes.None)
                {
                    baby.OccultManager.AddOccultType(occultTypes, false, false, false);
                }
            }

            return(baby);
        }