public static void Postfix_DeliverOffSpring(ref Hero __result)
        {
            ZenDzeeRomanceHelper.ClearFakes();

            if (__result.Mother.IsNoble && __result.Father.IsNoble)
            {
                return;
            }

            FieldInfo _originCharacterInfo = typeof(CharacterObject).GetField("_originCharacter", BindingFlags.NonPublic | BindingFlags.Instance);

            if (_originCharacterInfo != null)
            {
                CharacterObject origin = null;
                if (__result.Mother.IsNoble)
                {
                    origin = __result.Mother.CharacterObject;
                }
                else if (__result.Father.IsNoble)
                {
                    origin = __result.Father.CharacterObject;
                }
                if (origin != null)
                {
                    _originCharacterInfo.SetValue(__result.CharacterObject, origin);
                }
            }
        }
        private static void OnPrisonerReleased(Hero hero, IFaction arg2, EndCaptivityDetail arg3)
        {
            if (hero == null)
            {
                return;
            }

            ZenDzeeRomanceHelper.EndLoverRomances(hero, ZenDzeeRomanceHelper.RomanceLevel_Prisoner);

            if (hero != Hero.MainHero &&
                !Hero.MainHero.IsPrisoner)
            {
                MenuContext currentMenuContext = Campaign.Current.CurrentMenuContext;
                if (currentMenuContext == null)
                {
                    return;
                }

                if (currentMenuContext.GameMenu.StringId == "zendzee_town_wait_menus" &&
                    ZenDzeeRomanceHelper.GetLover(Hero.MainHero, ZenDzeeRomanceHelper.RomanceLevel_Prisoner) == null)
                {
                    GameMenu.SwitchToMenu("town_wait_menus");
                }
            }
        }
        private static void OnDailyTickHero(Hero hero)
        {
            if (!hero.IsTemplate &&
                hero.IsNoble && hero.IsAlive && hero.IsActive &&
                hero.Clan != null &&
                hero.Clan != Clan.PlayerClan &&
                hero.Age >= ZenDzeeRomanceHelper.LoversAgeMin &&
                (!hero.IsFemale || hero.Age < ZenDzeeRomanceHelper.PregnancyAgeMax) &&
                (hero.Spouse == null ||
                 hero.Spouse.IsDead ||
                 (hero.Spouse.IsFemale && hero.Spouse.Age > ZenDzeeRomanceHelper.PregnancyAgeMax)) &&
                hero.Clan.Heroes.Count(h => h.IsAlive) < 6 &&
                hero.Children.Count(c => c.IsAlive && c.Clan == hero.Clan) == 0)
            {
                // Next day after birthday.
                if ((int)(hero.BirthDay.ElapsedDaysUntilNow - 1) % CampaignTime.DaysInYear == 0)
                {
                    Hero lover = ZenDzeeRomanceHelper.GetLover(hero);
                    if (lover == null)
                    {
                        // Find a lover. TODO maybe this should had random chance?
                        IEnumerable <Hero> list = hero.Clan.SupporterNotables;
                        if (list != null)
                        {
                            lover = GetSuitableLoverForHero(hero, list);
                            if (lover != null)
                            {
                                ChangeRomanticStateAction.Apply(hero, lover, (Romance.RomanceLevelEnum)ZenDzeeRomanceHelper.RomanceLevel_Lovers);
                                return;
                            }
                        }

                        if (hero.Age >= DesperateToFindSpouseAge && lover == null)
                        {
                            list = Hero.All.Where(h => h.IsWanderer &&
                                                  h.CurrentSettlement != null &&
                                                  h.CurrentSettlement.MapFaction == hero.MapFaction &&
                                                  h.Clan != Clan.PlayerClan &&
                                                  IsHeroSuitableLoverForHero(hero, h));

                            if (list != null)
                            {
                                lover = GetSuitableLoverForHero(hero, list);
                                if (lover != null)
                                {
                                    ChangeRomanticStateAction.Apply(hero, lover, (Romance.RomanceLevelEnum)ZenDzeeRomanceHelper.RomanceLevel_Lovers);
                                    return;
                                }
                            }
                        }

                        // Add here other romance options
                    }
                }
            }
        }
 private static bool IsHeroSuitableLoverForHero(Hero hero, Hero lover)
 {
     return(lover.IsFemale != hero.IsFemale &&
            !lover.IsTemplate &&
            lover.IsActive &&
            lover.IsAlive &&
            lover.Spouse == null &&
            lover.Age >= ZenDzeeRomanceHelper.LoversAgeMin &&
            (!lover.IsFemale || lover.Age < ZenDzeeRomanceHelper.PregnancyAgeMax) &&
            ZenDzeeRomanceHelper.GetLover(lover) == null);
 }
        private static void OnRomanticStateChanged(Hero hero1, Hero hero2, Romance.RomanceLevelEnum level)
        {
            if ((int)level == ZenDzeeRomanceHelper.RomanceLevel_Lovers)
            {
#if ENABLE_LOGS
                InformationManager.DisplayMessage(new InformationMessage(hero1.Name + " and " + hero2.Name + " started romance as lovers."));
#endif
            }
            else if (level == Romance.RomanceLevelEnum.Marriage)
            {
                ZenDzeeRomanceHelper.EndLoverRomances(hero1);
                ZenDzeeRomanceHelper.EndLoverRomances(hero2);
            }
        }
        private static void OnChildConceived(Hero mother)
        {
            if (mother.IsPrisoner && mother.StayingInSettlementOfNotable != null)
            {
                Hero captor = ZenDzeeRomanceHelper.GetLover(mother, ZenDzeeRomanceHelper.RomanceLevel_Prisoner);
                if (captor == null)
                {
                    InformationManager.DisplayMessage(new InformationMessage("ERROR: Captor is null: " + mother.Name));
                    return;
                }

                InformationManager.DisplayMessage(new InformationMessage(captor.Name + " impregnates prisoner " + mother.Name));
            }
        }
 public static void Prefix_DeliverOffSpring(ref Hero mother, ref Hero father, ref bool isOffspringFemale)
 {
     if (isOffspringFemale)
     {
         if (mother.IsWanderer || mother.IsNotable)
         {
             ZenDzeeRomanceHelper.FakeNoble(mother);
         }
     }
     else
     {
         if (father.IsWanderer || father.IsNotable)
         {
             ZenDzeeRomanceHelper.FakeNoble(father);
         }
     }
 }
        private static void LordLeavesAlonePrisoners(Settlement settlement, MobileParty captorParty)
        {
            Hero prisoner;

            while ((prisoner = settlement.HeroesWithoutParty.FirstOrDefault(p => PrisonerIsOwnedByHero(p, captorParty.LeaderHero))) != null)
            {
                prisoner.StayingInSettlementOfNotable = null;

                if (prisoner.IsHumanPlayerCharacter)
                {
                    GameMenu.SwitchToMenu("settlement_wait");
                }

#if ENABLE_LOGS
                InformationManager.DisplayMessage(new InformationMessage(captorParty.LeaderHero.Name + " leaves alone prisoner " + prisoner.Name));
#endif // ENABLE_LOGS

                ZenDzeeRomanceHelper.EndLoversRomance(captorParty.LeaderHero, prisoner, ZenDzeeRomanceHelper.RomanceLevel_Prisoner);
            }
        }
        public static void Prefix_DailyTickHero(ref Hero hero)
        {
            if (!hero.IsFemale || hero.IsDead || hero.Age < 18f || hero.IsPregnant)
            {
                return;
            }

            Settlement settlement = hero.CurrentSettlement;

            if (hero.IsHumanPlayerCharacter && !hero.IsPrisoner && hero.Spouse != null && hero.Spouse.CurrentSettlement == settlement)
            {
                return;
            }

            Hero lover;

            if (settlement != null)
            {
                lover = ZenDzeeRomanceHelper.GetLover(hero, ZenDzeeRomanceHelper.RomanceLevel_Prisoner);
                if (lover != null)
                {
                    ZenDzeeRomanceHelper.FakeSpouses(hero, lover);
                    return;
                }
            }

            lover = ZenDzeeRomanceHelper.GetLover(hero, ZenDzeeRomanceHelper.RomanceLevel_Lovers);
            if (lover != null)
            {
                if (lover.IsDead)
                {
                    ZenDzeeRomanceHelper.EndLoverRomances(lover);
                    return;
                }
                if (!lover.IsPrisoner)
                {
                    ZenDzeeRomanceHelper.FakeSpouses(hero, lover);
                    return;
                }
            }
        }
 private static void OnHeroKilled(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail actionDetail, bool showNotification)
 {
     ZenDzeeRomanceHelper.EndLoverRomances(victim);
 }
        private static void OnGameMenuOpened(MenuCallbackArgs menuCallbackArgs)
        {
            MenuContext menuContext = menuCallbackArgs.MenuContext;

            GameOverlays.MenuOverlayType menuOverlayType = Campaign.Current.GameMenuManager.GetMenuOverlayType(menuContext);

            if (menuOverlayType == GameOverlays.MenuOverlayType.SettlementWithCharacters)
            {
                Location lordshall = LocationComplex.Current.GetLocationWithId("lordshall");
                if (lordshall == null)
                {
                    return;
                }

                Settlement settlement = Hero.MainHero.CurrentSettlement;
                if (settlement == null)
                {
                    return;
                }

                IEnumerable <Hero> list = settlement.HeroesWithoutParty.Where(h => h.IsPrisoner);
                if (list == null)
                {
                    return;
                }

                foreach (Hero hero in list)
                {
                    Location current = LocationComplex.Current.GetLocationOfCharacter(hero);
                    if (current == lordshall)
                    {
                        continue;
                    }

                    if (current == null)
                    {
                        Tuple <string, Monster> actionSetAndMonster = new Tuple <string, Monster>("as_human_lady", Campaign.Current.HumanMonsterSettlement);
                        AgentData agentData = new AgentData(
                            new SimpleAgentOrigin(
                                hero.CharacterObject,
                                -1,
                                null,
                                default(UniqueTroopDescriptor))).Monster(actionSetAndMonster.Item2).NoHorses(true);
                        lordshall.AddCharacter(
                            new LocationCharacter(agentData,
                                                  new LocationCharacter.AddBehaviorsDelegate(SandBoxManager.Instance.AgentBehaviorManager.AddFixedCharacterBehaviors),
                                                  null,
                                                  true,
                                                  LocationCharacter.CharacterRelations.Neutral,
                                                  actionSetAndMonster.Item1,
                                                  true,
                                                  true,
                                                  null,
                                                  false,
                                                  false,
                                                  true));
                    }
                    else
                    {
                        LocationComplex.Current.ChangeLocation(LocationComplex.Current.GetLocationCharacterOfHero(hero),
                                                               current, lordshall);
                    }
                }
            }

            if (menuContext.GameMenu.StringId == "town_wait_menus")
            {
                if (ZenDzeeRomanceHelper.GetLover(Hero.MainHero, ZenDzeeRomanceHelper.RomanceLevel_Prisoner) != null)
                {
                    GameMenu.SwitchToMenu("zendzee_town_wait_menus");
                }
            }
        }
 public static void Postfix_DailyTickHero()
 {
     ZenDzeeRomanceHelper.ClearFakes();
 }