/// <summary> /// Behavior Duplicate found In PregnancyCampaignBehavior /// </summary> /// <param name="pregnancy"></param> private void CheckOffspringsToDeliver(Pregnancy pregnancy) { try { if (!pregnancy.Mother.IsAlive) { pregnancy.AlreadyOccured = true; return; } CalculatePregnancyWeight(pregnancy); if (pregnancy.DueDate.IsFuture) { return; } PregnancyModel pregnancyModel = Campaign.Current.Models.PregnancyModel; Hero mother = pregnancy.Mother; bool flag = MBRandom.RandomFloat <= pregnancyModel.DeliveringTwinsProbability; List <Hero> aliveOffsprings = new List <Hero>(); int num = flag ? 2 : 1; int stillbornCount = 0; for (int i = 0; i < 1; i++) { if (MBRandom.RandomFloat > pregnancyModel.StillbirthProbability) { bool isOffspringFemale = MBRandom.RandomFloat <= pregnancyModel.DeliveringFemaleOffspringProbability; try { Hero item = DeliverOffSpring(pregnancy.Mother, pregnancy.Father, isOffspringFemale, 0); aliveOffsprings.Add(item); } catch (Exception e) { CECustomHandler.ForceLogToFile("Bad pregnancy " + (isOffspringFemale ? "Female" : "Male")); CECustomHandler.ForceLogToFile(e.Message + " : " + e); Hero item = HeroCreator.DeliverOffSpring(pregnancy.Mother, pregnancy.Father, !isOffspringFemale, null, 0); aliveOffsprings.Add(item); } } else { if (mother == Hero.MainHero) { TextObject textObject = new TextObject("{=pw4cUPEn}{MOTHER.LINK} has delivered stillborn."); StringHelpers.SetCharacterProperties("MOTHER", mother.CharacterObject, textObject); InformationManager.DisplayMessage(new InformationMessage(textObject.ToString())); } stillbornCount++; } } if (mother == Hero.MainHero || pregnancy.Father == Hero.MainHero) { TextObject textObject = mother == Hero.MainHero ? new TextObject("{=oIA9lkpc}You have given birth to {DELIVERED_CHILDREN}.") : new TextObject("{=CEEVENTS1092}Your captive {MOTHER.NAME} has given birth to {DELIVERED_CHILDREN}."); switch (stillbornCount) { case 2: textObject.SetTextVariable("DELIVERED_CHILDREN", new TextObject("{=Sn9a1Aba}two stillborn babies")); break; case 1 when aliveOffsprings.Count == 0: textObject.SetTextVariable("DELIVERED_CHILDREN", new TextObject("{=qWLq2y84}a stillborn baby")); break; case 1 when aliveOffsprings.Count == 1: textObject.SetTextVariable("DELIVERED_CHILDREN", new TextObject("{=CEEVENTS1168}one healthy and one stillborn baby")); break; case 0 when aliveOffsprings.Count == 1: textObject.SetTextVariable("DELIVERED_CHILDREN", new TextObject("{=CEEVENTS1169}a healthy baby")); break; case 0 when aliveOffsprings.Count == 2: textObject.SetTextVariable("DELIVERED_CHILDREN", new TextObject("{=CEEVENTS1170}two healthy babies")); break; } StringHelpers.SetCharacterProperties("MOTHER", mother.CharacterObject, textObject); InformationManager.AddQuickInformation(textObject); } if (mother.IsHumanPlayerCharacter || pregnancy.Father == Hero.MainHero) { for (int i = 0; i < stillbornCount; i++) { ChildbirthLogEntry childbirthLogEntry = new ChildbirthLogEntry(mother, null); LogEntry.AddLogEntry(childbirthLogEntry); Campaign.Current.CampaignInformationManager.NewMapNoticeAdded(new ChildBornMapNotification(null, childbirthLogEntry.GetEncyclopediaText())); } foreach (Hero newbornHero in aliveOffsprings) { ChildbirthLogEntry childbirthLogEntry2 = new ChildbirthLogEntry(mother, newbornHero); LogEntry.AddLogEntry(childbirthLogEntry2); Campaign.Current.CampaignInformationManager.NewMapNoticeAdded(new ChildBornMapNotification(newbornHero, childbirthLogEntry2.GetEncyclopediaText())); } } mother.IsPregnant = false; pregnancy.AlreadyOccured = true; ChangeWeight(pregnancy.Mother, 0, MBRandom.RandomFloatRanged(0.4025f, 0.6025f)); } catch (Exception e) { CECustomHandler.ForceLogToFile("Bad pregnancy"); CECustomHandler.ForceLogToFile(e.Message + " : " + e); TextObject textObject = new TextObject("{=CEEVENTS1008}Error: bad pregnancy in CE pregnancy list"); InformationManager.DisplayMessage(new InformationMessage(textObject.ToString(), Colors.Black)); pregnancy.AlreadyOccured = true; } }
/// <summary> /// Behavior Duplicate found In PregnancyCampaignBehavior /// </summary> /// <param name="mother"></param> /// <param name="father"></param> /// <param name="isOffspringFemale"></param> /// <param name="age"></param> /// <returns></returns> private Hero DeliverOffSpring(Hero mother, Hero father, bool isOffspringFemale, int age = 1) { CharacterObject characterObject = isOffspringFemale ? mother.CharacterObject : father.CharacterObject; characterObject.Culture = mother.Culture; // Reflection One MethodInfo mi = typeof(HeroCreator).GetMethod("CreateNewHero", BindingFlags.NonPublic | BindingFlags.Static); if (mi == null) { return(HeroCreator.DeliverOffSpring(mother, father, isOffspringFemale, null, 0)); } Hero hero = (Hero)mi.Invoke(null, new object[] { characterObject, age }); // For Wanderer Pregnancy hero.SetBirthDay(CampaignTime.Now); int becomeChildAge = Campaign.Current.Models.AgeModel.BecomeChildAge; CharacterObject characterObject2 = CharacterObject.ChildTemplates.FirstOrDefault((CharacterObject t) => t.Culture == mother.Culture && t.Age <= becomeChildAge && t.IsFemale == isOffspringFemale && t.Occupation == Occupation.Lord); if (characterObject2 != null) { Equipment equipment = characterObject2.FirstCivilianEquipment.Clone(false); Equipment equipment2 = new Equipment(false); // TaleWorld's Bug if (hero.BattleEquipment == null) { PropertyInfo fi = hero.GetType().GetProperty("BattleEquipment", BindingFlags.Instance | BindingFlags.Public); if (fi != null) { fi.SetValue(hero, new Equipment(false)); } } if (hero.CivilianEquipment == null) { PropertyInfo fi = hero.GetType().GetProperty("CivilianEquipment", BindingFlags.Instance | BindingFlags.Public); if (fi != null) { fi.SetValue(hero, new Equipment(true)); } } equipment2.FillFrom(equipment, false); EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, equipment); EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, equipment2); } hero.FirstName = NameGenerator.Current.GenerateHeroFirstName(hero, true); hero.CharacterObject.Name = hero.FirstName; // Reflection Two mi = hero.HeroDeveloper.GetType().GetMethod("CheckInitialLevel", BindingFlags.NonPublic | BindingFlags.Instance); if (mi != null) { mi.Invoke(hero.HeroDeveloper, new object[] { }); } Campaign.Current.GetCampaignBehavior <IHeroCreationCampaignBehavior>().DeriveSkillsFromTraits(hero, characterObject); hero.CharacterObject.IsFemale = isOffspringFemale; if (hero.CharacterObject.Occupation != Occupation.Lord) { PropertyInfo fi = hero.CharacterObject.GetType().GetProperty("Occupation", BindingFlags.Instance | BindingFlags.Public); if (fi != null) { fi.SetValue(hero.CharacterObject, Occupation.Lord); } } BodyProperties bodyPropertiesMin = mother.CharacterObject.GetBodyPropertiesMin(false); BodyProperties bodyPropertiesMin2 = father.CharacterObject.GetBodyPropertiesMin(false); int seed = isOffspringFemale ? mother.CharacterObject.GetDefaultFaceSeed(1) : father.CharacterObject.GetDefaultFaceSeed(1); string hairTags = isOffspringFemale ? mother.CharacterObject.HairTags : father.CharacterObject.HairTags; string tattooTags = isOffspringFemale ? mother.CharacterObject.TattooTags : father.CharacterObject.TattooTags; PropertyInfo pi = hero.GetType().GetProperty("StaticBodyProperties", BindingFlags.Instance | BindingFlags.NonPublic); StaticBodyProperties staticBody = BodyProperties.GetRandomBodyProperties(isOffspringFemale, bodyPropertiesMin, bodyPropertiesMin2, 1, seed, hairTags, father.CharacterObject.BeardTags, tattooTags).StaticProperties; if (pi != null) { pi.SetValue(hero, staticBody); } hero.Mother = mother; hero.Father = father; // Reflection Two MethodInfo mi2 = typeof(HeroCreator).GetMethod("DecideBornSettlement", BindingFlags.NonPublic | BindingFlags.Static); if (mi == null) { return(HeroCreator.DeliverOffSpring(mother, father, isOffspringFemale, null, 0)); } hero.BornSettlement = (Settlement)mi2.Invoke(null, new object[] { hero }); hero.IsNoble = true; if (mother == Hero.MainHero || father == Hero.MainHero) { hero.HasMet = true; hero.Clan = Clan.PlayerClan; } else { hero.Clan = father.Clan; } CampaignEventDispatcher.Instance.OnHeroCreated(hero, true); return(hero); }