private static void AddExiledHero()
        {
            Hero            mainhero = Hero.MainHero;
            CharacterObject wanderer = (from x in CharacterObject.Templates
                                        where x.Occupation == Occupation.Wanderer && x.Culture.StringId == mainhero.Culture.StringId
                                        select x).GetRandomElementInefficiently <CharacterObject>();

            Equipment equipment = (from y in CharacterObject.All
                                   where y.Level > 20 && y.Culture.StringId == wanderer.Culture.StringId && !y.IsHero && y.Tier > 4
                                   select y).GetRandomElementInefficiently <CharacterObject>().Equipment;
            Equipment equipmentMC = (from z in CharacterObject.All
                                     where z.Tier == 4 && z.Culture.StringId == wanderer.Culture.StringId && !z.IsHero
                                     select z).GetRandomElementInefficiently <CharacterObject>().Equipment;
            Settlement randomElement = (from settlement in Settlement.All
                                        where settlement.Culture == wanderer.Culture && settlement.IsTown
                                        select settlement).GetRandomElementInefficiently <Settlement>();
            //wanderer.Equipment.FillFrom(equipment);
            Hero hero = HeroCreator.CreateSpecialHero(wanderer, randomElement, null, null, 33);

            Campaign.Current.GetCampaignBehavior <IHeroCreationCampaignBehavior>().DeriveSkillsFromTraits(hero, wanderer);
            GiveGoldAction.ApplyBetweenCharacters(null, hero, 4000, true);
            hero.BattleEquipment.FillFrom(equipment);
            mainhero.BattleEquipment.FillFrom(equipmentMC);
            hero.HasMet = true;
            hero.Clan   = randomElement.OwnerClan;
            hero.ChangeState(Hero.CharacterStates.Active);
            AddCompanionAction.Apply(Clan.PlayerClan, hero);
            AddHeroToPartyAction.Apply(hero, MobileParty.MainParty, true);
            CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
        }
        private static Hero DealNPC(CharacterObject target, CampaignGameStarter campaignGameStarter)
        {
            Hero hero = null;

            if (null != target)
            {
                CharacterObject character = CharacterObject.OneToOneConversationCharacter;
                hero = HeroCreator.CreateSpecialHero(character, null, Clan.PlayerClan, Clan.PlayerClan);
                // hero.StringId = "sms_npc_" + System.Enum.GetName(typeof(Occupation), character.Occupation) + hero.StringId;


                hero.ChangeState(Hero.CharacterStates.Active);
                hero.CacheLastSeenInformation(hero.HomeSettlement, true);
                hero.SyncLastSeenInformation();
                HeroInitPropertyUtils.InitHeroForNPC(hero);


                AddHeroToPartyAction.Apply(hero, MobileParty.MainParty, true);
                CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
                ConversationUtils.ChangeCurrentCharaObject(campaignGameStarter, hero);

                if (hero.Age > 30)
                {
                    hero.SetBirthDay(HeroHelper.GetRandomBirthDayForAge((float)22));
                }
            }
            return(hero);
        }
        private static void CSAddCompanion(int NoToAdd)
        {
            Hero mainhero = Hero.MainHero;

            for (int i = 0; i < NoToAdd; i++)
            {
                string          Locculture = CSCharCreationOption.CSOptionSettlement().Culture.StringId;
                CharacterObject wanderer   = (from x in CharacterObject.Templates
                                              where x.Occupation == Occupation.Wanderer && (x.Culture.StringId == mainhero.Culture.StringId || x.Culture.StringId == Locculture)
                                              select x).GetRandomElementInefficiently <CharacterObject>();
                Settlement randomElement = (from settlement in Settlement.All
                                            where settlement.Culture == wanderer.Culture && settlement.IsTown
                                            select settlement).GetRandomElementInefficiently <Settlement>();
                Hero hero = HeroCreator.CreateSpecialHero(wanderer, randomElement, null, null, 33);
                Campaign.Current.GetCampaignBehavior <IHeroCreationCampaignBehavior>().DeriveSkillsFromTraits(hero, wanderer);
                GiveGoldAction.ApplyBetweenCharacters(null, hero, 2000, true);
                CSSetEquip(hero, 4);
                hero.HasMet = true;
                hero.Clan   = randomElement.OwnerClan;
                hero.ChangeState(Hero.CharacterStates.Active);
                AddCompanionAction.Apply(Clan.PlayerClan, hero);
                AddHeroToPartyAction.Apply(hero, MobileParty.MainParty, true);
                CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
            }
        }
Exemple #4
0
        public void DailyTick()
        {
            if (this._sneaker == null || this._sneaker.IsDead)
            {
                Settlement randomSettlement = Settlement.All.Where(obj => obj.IsTown).GetRandomElement();

                CultureObject culture = randomSettlement.Culture;

                CharacterObject co = CharacterObject.CreateFrom(culture.FemaleBeggar, true);
                CharacterObject characterObject = MBObjectManager.Instance.CreateObject <CharacterObject>();
                characterObject.Culture = co.Culture;
                characterObject.Age     = (float)MBRandom.RandomInt(22, 30);
                characterObject.DefaultFormationGroup   = co.DefaultFormationGroup;
                characterObject.StaticBodyPropertiesMin = co.StaticBodyPropertiesMin;
                characterObject.StaticBodyPropertiesMax = co.StaticBodyPropertiesMax;
                characterObject.IsFemale  = true;
                characterObject.Level     = co.Level;
                characterObject.HairTags  = co.HairTags;
                characterObject.BeardTags = co.BeardTags;
                characterObject.InitializeEquipmentsOnLoad(co.AllEquipments.ToList <Equipment>());
                characterObject.Name = co.Name;

                this._sneaker      = HeroCreator.CreateSpecialHero(characterObject, randomSettlement);
                this._sneaker.Name = new TextObject("\"偷袭者\"" + this._sneaker.Name.ToString(), null);
                HeroInitPropertyUtils.InitAttributeAndFouse(this._sneaker);
                HeroInitPropertyUtils.FillBattleEquipment(this._sneaker);

                randomSettlement = Hero.MainHero.CurrentSettlement;
                if (null != randomSettlement && randomSettlement.IsTown)
                {
                    CharacterChangeLocation(this._sneaker, this._sneaker.CurrentSettlement, randomSettlement);
                    InformationManager.DisplayMessage(new InformationMessage(this._sneaker.Name.ToString() + " 出现在" + randomSettlement.Name, Colors.Blue));
                }
            }
        }
        // Token: 0x0600001D RID: 29 RVA: 0x00003474 File Offset: 0x00001674
        public void CreateCompanion(CharacterObject companionTemplate)
        {
            bool flag = companionTemplate == null;

            if (!flag)
            {
                Settlement settlement3 = (from settlement in Settlement.All
                                          where settlement.Culture == companionTemplate.Culture && settlement.IsTown
                                          select settlement).GetRandomElement <Settlement>();
                List <Settlement> list = new List <Settlement>();
                foreach (Settlement settlement4 in Settlement.All)
                {
                    bool flag2 = settlement4.IsVillage && Campaign.Current.Models.MapDistanceModel.GetDistance(settlement4, settlement3) < 30f;
                    if (flag2)
                    {
                        list.Add(settlement4);
                    }
                }
                settlement3 = ((list.Any <Settlement>() ? list.GetRandomElement <Settlement>().Village.Bound : settlement3) ?? Settlement.All.GetRandomElement <Settlement>());
                Hero hero = HeroCreator.CreateSpecialHero(companionTemplate, settlement3, null, null, Campaign.Current.Models.AgeModel.HeroComesOfAge + 5 + MBRandom.RandomInt(27));
                Campaign.Current.GetCampaignBehavior <IHeroCreationCampaignBehavior>().DeriveSkillsFromTraits(hero, companionTemplate);
                CharacterObject template = hero.Template;
                bool            flag3    = ((template != null) ? template.HeroObject : null) != null && hero.Template.HeroObject.Clan != null && hero.Template.HeroObject.Clan.IsMinorFaction;
                if (flag3)
                {
                    hero.SupporterOf = hero.Template.HeroObject.Clan;
                }
                else
                {
                    hero.SupporterOf = HeroHelper.GetRandomClanForNotable(hero);
                }
                CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
                this._companions.Add(hero);
            }
        }
        public Hero CreateRandomLeader(Clan clan, BaseSettlementInfo settlementInfo)
        {
            var templateBase = clan.Leader.CharacterObject;

            var characterTemplate = CharacterObject.Templates.Where(go => go.Culture == clan.Culture && (go.Occupation == Occupation.Lord || go.Occupation == Occupation.Lady)).GetRandomElement();

            characterTemplate.InitializeEquipmentsOnLoad(templateBase.AllEquipments.ToList());

            foreach (var attribute in CharacterAttributes.All)
            {
                characterTemplate.SetAttributeValue(attribute.AttributeEnum, 255);
            }

            foreach (var skill in SkillObject.All)
            {
                characterTemplate.SetSkillValue(skill, 255);
            }

            characterTemplate.SetSkillValue(SkillObject.GetSkill(13), 1000);

            var hero = HeroCreator.CreateSpecialHero(characterTemplate, settlementInfo.Settlement);

            hero.IsNoble            = true;
            hero.IsMinorFactionHero = false;

            foreach (var perk in PerkObject.All)
            {
                hero.SetPerkValue(perk, true);
            }

            hero.ChangeState(Hero.CharacterStates.Active);

            Get(hero.CharacterObject).IsCustomCharacter = true;
            return(hero);
        }
        public static void DealLordForClan(Hero hero)
        {
            Clan clan = hero.Clan;

            if (clan.Leader == hero)
            {
                List <Hero> others = clan.Heroes.Where((obj) => (obj != hero && obj.IsAlive)).ToList();
                if (others.Count() > 0)
                {
                    Hero target = others.GetRandomElement();
                    ChangeClanLeaderAction.ApplyWithSelectedNewLeader(clan, target);

                    TextObject textObject = GameTexts.FindText("sue_more_spouses_clan_leave", null);
                    StringHelpers.SetCharacterProperties("SUE_HERO", hero.CharacterObject, null, textObject);
                    InformationManager.AddQuickInformation(textObject, 0, null, "event:/ui/notification/quest_finished");

                    textObject = GameTexts.FindText("sue_more_spouses_clan_change", null);
                    StringHelpers.SetCharacterProperties("SUE_HERO", target.CharacterObject, null, textObject);
                    InformationManager.AddQuickInformation(textObject, 0, null, "event:/ui/notification/quest_finished");
                }
                else
                {
                    List <Settlement> settlements = clan.Settlements.ToList();
                    settlements.ForEach((settlement) => ChangeOwnerOfSettlementAction.ApplyByDestroyClan(settlement, Hero.MainHero));
                    List <Hero> deadHeros = clan.Heroes.Where((obj) => (obj != hero && obj.IsDead)).ToList();
                    Hero        target    = null;
                    if (deadHeros.Count > 0)
                    {
                        target = deadHeros.GetRandomElement();
                        clan.SetLeader(target);
                    }
                    else
                    {
                        CharacterObject character = CharacterObject.FindFirst(obj => obj.Culture == hero.Culture && obj.Occupation == Occupation.Lord);
                        target = HeroCreator.CreateSpecialHero(character, hero.HomeSettlement, null, null, -1);
                        target.ChangeState(CharacterStates.Dead);
                        target.Clan = clan;
                        CampaignEventDispatcher.Instance.OnHeroCreated(target, false);
                        clan.SetLeader(target);
                    }

                    if (null != GameComponent.CampaignEventDispatcher())
                    {
                        GameComponent.CampaignEventDispatcher().OnClanLeaderChanged(hero, target);
                    }
                    DestroyClanAction.Apply(clan);
                    dealKindomLeader(clan, hero);
                }
            }
            hero.Clan = Clan.PlayerClan;
        }
        public static Hero CreateNewBandit(Game game)
        {
            CultureObject banditCulture = null;

            // Search for Vagabond Culture
            banditCulture = MBObjectManager.Instance.GetObjectTypeList <CultureObject>().FirstOrDefault(x => x.IsMainCulture && x.GetName().ToString() == "Vagabond");
            if (banditCulture != default(CultureObject))
            {
                // If its not found use default culture. Normally thats null culture
                InformationManager.DisplayMessage(new InformationMessage("DEFAULT CULTURE USED"));
            }

            CustomClan clan = new CustomClan("Bandit Clan", "Bandits", banditCulture); // creates custom clan, initializes it in custom clans constructor
                                                                                       //clan.AddClan(game); // Still causes Crashes

            //hero = game.ObjectManager.RegisterPresumedObject<Hero>(new Hero()); // Causes crashes, I don't think I can do this

            // CharacterObject lord creates a character object that a hero can be made from.
            // Currently it uses the Occupation.Wanderer template, we will need to make new template for thsi
            CharacterObject lord = (from x in CharacterObject.Templates
                                    where x.Occupation == Occupation.Wanderer
                                    select x).GetRandomElement <CharacterObject>();

            // changes the lords name
            lord.Name = new TextObject("Bandit Lord Test", null);

            // Changes the lords culture
            lord.Culture = banditCulture;

            // creates a hero from the characterObject template.
            // TODO Change clan add to HeroCreator field
            Hero hero = HeroCreator.CreateSpecialHero(lord, null, null, null, -1);

            //GiveGoldAction.ApplyBetweenCharacters(null, hero, 20000, true); // add later
            hero.Clan = clan.getClan(); // gives the hero the new clan

            // initializes and creates a kingdom using my custom kingdom class
            CustomKingdom kingdom = new CustomKingdom("Vagabond Kingdom", "Vagabond", banditCulture);

            // makes heroes clan join the faction
            hero.Clan.ClanJoinFaction(kingdom.getKingdom());

            //hero.ChangeState(Hero.CharacterStates.Active); // not sure what this does
            //AddCompanionAction.Apply(Clan.PlayerClan, hero); // Adds this hero to players clan
            //AddHeroToPartyAction.Apply(hero, MobileParty.MainParty, true); // use this to test if method works
            //CampaignEventDispatcher.Instance.OnHeroCreated(hero, false); // I believe this crashes
            return(hero);
        }
Exemple #9
0
        private Clan CreateRebellionClan(SettlementInfo info)
        {
            Clan clan = MBObjectManager.Instance.CreateObject <Clan>(info.Settlement.Name.ToString() + "_rebels_" + MBRandom.RandomInt(100000).ToString());
            Hero hero = HeroCreator.CreateSpecialHero(CreateLordCharacter(info.OriginalCulture), info.Settlement, clan, clan, 30);

            TextObject name  = new TextObject(hero.Name.ToString());
            int        value = MBMath.ClampInt(1, DefaultTraits.Commander.MinValue, DefaultTraits.Commander.MaxValue);

            hero.SetTraitLevel(DefaultTraits.Commander, value);
            hero.ChangeState(Hero.CharacterStates.Active);
            hero.Initialize();
            clan.InitializeClan(name, name, info.OriginalCulture, Banner.CreateRandomClanBanner(MBRandom.RandomInt(100000)));
            hero.Clan = clan;
            clan.SetLeader(hero);
            clan.IsUnderMercenaryService = false;
            var kingdom = FormRebelKingdom(clan, info.Settlement, info.CurrentFaction);

            kingdom.ReactivateKingdom();
            DeclareWarAction.Apply(kingdom, info.CurrentFaction);
            clan.ClanJoinFaction(kingdom);
            kingdom.RulingClan = clan;
            return(clan);
        }
Exemple #10
0
        public static Hero?SpawnNoble(Clan clan, int ageMin, int ageMax = -1, bool isFemale = false)
        {
            var templateSeq = Hero.All.Where(h =>
                                             h.IsNoble &&
                                             h.CharacterObject.Occupation == Occupation.Lord &&
                                             (isFemale && h.IsFemale || !isFemale && !h.IsFemale));

            var template = templateSeq.Where(h => h.Culture == clan.Culture).GetRandomElement() ?? templateSeq.GetRandomElement();

            if (template is null)
            {
                return(null);
            }

            ageMax = ageMax <= ageMin ? -1 : ageMax;
            int age = ageMax < 0 ? ageMin : MBRandom.RandomInt(ageMin, ageMax);

            var hero = HeroCreator.CreateSpecialHero(template.CharacterObject,
                                                     bornSettlement: clan.HomeSettlement,
                                                     faction: clan,
                                                     supporterOfClan: clan,
                                                     age: age);

            // Our own, exact age assignment:
            // FIXME: Will need update in e1.5.5
            hero.BirthDay            = CampaignTime.Now - CampaignTime.Years(age);
            hero.CharacterObject.Age = hero.Age; // Get it into the BasicCharacterObject.Age property as well

            // Attributes
            for (var attr = CharacterAttributesEnum.First; attr < CharacterAttributesEnum.End; ++attr)
            {
                hero.SetAttributeValue(attr, MBRandom.RandomInt(6, 7));
            }

            // Skills: levels & focus point minimums
            foreach (var skillObj in Game.Current.SkillList)
            {
                var curSkill = hero.GetSkillValue(skillObj);
                var curFocus = hero.HeroDeveloper.GetFocus(skillObj);

                int minSkill = MBRandom.RandomInt(75, 110);
                int minFocus = minSkill > 95 ? 4 : MBRandom.RandomInt(2, 3);

                if (curSkill < minSkill)
                {
                    hero.HeroDeveloper.ChangeSkillLevel(skillObj, minSkill - curSkill, false);
                }

                if (curFocus < minFocus)
                {
                    hero.HeroDeveloper.AddFocus(skillObj, minFocus - curFocus, false);
                }
            }

            // TODO:
            // - morph StaticBodyParameters a bit, in a way that doesn't result in ogres
            // - equip them with a culture-appropriate horse and horse harness
            // - ensure they have some decent equipment (maybe pick a template soldier from each culture)

            hero.Name    = hero.FirstName;
            hero.IsNoble = true;
            hero.ChangeState(Hero.CharacterStates.Active);
            CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
            return(hero);
        }
Exemple #11
0
        public void DailyTickFixClanLeader()
        {
            //玩家家族领导人修正, 玩家家族领导人不是玩家时,将会修改成玩家
            if (Clan.PlayerClan.Leader != Hero.MainHero)
            {
                Clan.PlayerClan.SetLeader(Hero.MainHero);
                InformationManager.DisplayMessage(new InformationMessage("MoreSpouses: player clan leader fix"));
            }

            //家族领导人的家族不是该家族时,将会把领导人修改成该家族的人员
            IEnumerable <Clan> clans = Clan.All.ToList().Where(obj => obj.IsEliminated && (null != obj.Leader && obj.Leader.Clan != obj));

            if (clans.Count() > 0)
            {
                for (int i = 0; i < clans.Count(); i++)
                {
                    Clan current = clans.ElementAt(i);

                    if (null != current.Leader && null != current.Leader.Clan && current.Leader.Clan != current)
                    {
                        Hero        sourc      = current.Leader;
                        List <Hero> otherHeros = current.Heroes.Where((obj) => (obj != sourc)).ToList();
                        Hero        target     = null;
                        if (otherHeros.Count > 0)
                        {
                            target = otherHeros.GetRandomElement();
                            current.SetLeader(target);
                        }
                        else
                        {
                            CharacterObject character = CharacterObject.FindFirst(obj => obj.Culture == current.Culture && obj.Occupation == Occupation.Lord);
                            target = HeroCreator.CreateSpecialHero(character, sourc.HomeSettlement, null, null, -1);
                            target.ChangeState(CharacterStates.Dead);
                            target.Clan = current;
                            CampaignEventDispatcher.Instance.OnHeroCreated(target, false);
                            current.SetLeader(target);
                        }

                        if (null != GameComponent.CampaignEventDispatcher())
                        {
                            GameComponent.CampaignEventDispatcher().OnClanLeaderChanged(sourc, target);
                        }

                        InformationManager.DisplayMessage(new InformationMessage("MoreSpouses: " + current.Name + " clan leader fix"));
                    }
                }
            }

            //修正国王领导
            IEnumerable <Kingdom> kingdoms = Kingdom.All.ToList().Where(obj => obj.RulingClan == Clan.PlayerClan && (!obj.Clans.Contains(Clan.PlayerClan)));

            if (kingdoms.Count() > 0)
            {
                for (int i = 0; i < kingdoms.Count(); i++)
                {
                    Kingdom            current    = kingdoms.ElementAt(i);
                    IEnumerable <Clan> aliveClans = current.Clans.Where(obj => !obj.IsEliminated);
                    if (aliveClans.Count() > 0)
                    {
                        current.RulingClan = aliveClans.ToList().GetRandomElement();
                    }
                    else
                    {
                        current.RulingClan = current.Clans.GetRandomElement();
                    }

                    InformationManager.DisplayMessage(new InformationMessage("MoreSpouses: " + current.Name + " kingdom leader fix"));
                }
            }

            //修正玩家部队拥有者不是玩家
            if (null != MobileParty.MainParty && null != MobileParty.MainParty.Party && null != MobileParty.MainParty.Party.Owner &&
                MobileParty.MainParty.Party.Owner != Hero.MainHero)
            {
                MobileParty.MainParty.Party.Owner = Hero.MainHero;
            }
        }
Exemple #12
0
        // modified from 1.5.8 copy
        public static Hero CreateBanditHero(Clan mostPrevalent, MobileParty mobileParty)
        {
            var settlement = Hideouts.GetRandomElement();
            var num1       = 0;

            foreach (var characterObject in Source)
            {
                var num2 = characterObject.GetTraitLevel(DefaultTraits.Frequency) * 10;
                num1 += num2 > 0 ? num2 : 100;
            }

            if (!Source.Any())
            {
                return(null);
            }
            CharacterObject characterObject1 = null;
            var             num3             = 1 + (int)(settlement.Random.GetValueNormalized(settlement.Notables.Count) * (double)(num1 - 1));

            foreach (var characterObject2 in Source)
            {
                var num2 = characterObject2.GetTraitLevel(DefaultTraits.Frequency) * 10;
                num3 -= num2 > 0 ? num2 : 100;
                if (num3 < 0)
                {
                    characterObject1 = characterObject2;
                    break;
                }
            }

            var specialHero = HeroCreator.CreateSpecialHero(characterObject1, settlement);

            specialHero.SupporterOf = Clan.BanditFactions.ToList().GetRandomElement();
            Traverse.Create(typeof(HeroCreator)).Method("AddRandomVarianceToTraits", specialHero).GetValue();
            // 1.4.3b doesn't have these wired up really, but I patched prisoners with it... kinda
            specialHero.NeverBecomePrisoner = true;
            specialHero.AlwaysDie           = true;
            var partyStrength = Traverse.Create(mobileParty.Party).Method("CalculateStrength").GetValue <float>();

            specialHero.Gold = Convert.ToInt32(partyStrength * GoldMap[Globals.Settings.GoldReward]);
            //var hideout = Hideouts.Where(x => x.MapFaction != CampaignData.NeutralFaction).GetRandomElement();
            // home has to be set to a hideout to make party aggressive (see PartyBase.MapFaction)
            // 1.4.3b changed this now we also have to set ActualClan
            specialHero.Clan = mostPrevalent;
            // why is this not accessed?
            // ReSharper disable once NotAccessedVariable
            var lastSeenPlace = Traverse.Create(specialHero).Field <Hero.HeroLastSeenInformation>("_lastSeenInformationKnownToPlayer").Value;

            lastSeenPlace.LastSeenPlace = settlement;
            EquipmentHelper.AssignHeroEquipmentFromEquipment(specialHero, BanditEquipment.GetRandomElement());
            Traverse.Create(specialHero).Field("_homeSettlement").SetValue(settlement);
            Traverse.Create(specialHero.Clan).Field("_warParties").Method("Add", mobileParty).GetValue();
            mobileParty.MemberRoster.AddToCounts(specialHero.CharacterObject, 1, false, 0, 0, true, 0);
            if (Globals.Settings.CanTrain)
            {
                specialHero.SetSkillValue(Leadership, 150);
                specialHero.SetPerkValue(VeteransRespect, true);
            }

            MBObjectManager.Instance.RegisterObject(specialHero);
            return(specialHero);
        }
Exemple #13
0
        public static Hero?SpawnNoble(Clan clan, int ageMin, int ageMax = -1, bool isFemale = false)
        {
            // Select a main template hero, which must be a Lord
#if STABLE
            var mainTemplateSeq = Hero.All
#else
            var mainTemplateSeq = Hero.AllAliveHeroes.Concat(Hero.DeadOrDisabledHeroes)
#endif
                                  .Where(h => h.IsNoble &&
                                         h.CharacterObject.Occupation == Occupation.Lord &&
                                         h.IsFemale == isFemale);

            var mainTemplate = mainTemplateSeq.Where(h => h.Culture == clan.Culture).RandomPick()
                               ?? mainTemplateSeq.RandomPick();

            if (mainTemplate is null)
            {
                return(null); // If we couldn't find a single one, we're screwed. Luckily this is basically a never-condition in any working setup.
            }
            // Select a different auxiliary template to use for cross-pollination of randomized facial appearance, if possible.
            // The auxiliary template doesn't need to be a proper Lord.

#if STABLE
            var auxTemplateSeq = Hero.All
#else
            var auxTemplateSeq = Hero.AllAliveHeroes.Concat(Hero.DeadOrDisabledHeroes)
#endif
                                 .Where(h => h.IsNoble && h != mainTemplate);

            var auxTemplate = auxTemplateSeq.Where(h => h.Culture == clan.Culture && h.IsFemale != isFemale).RandomPick()
                              ?? auxTemplateSeq.Where(h => h.Culture == clan.Culture).RandomPick()
                              ?? auxTemplateSeq.RandomPick()
                              ?? mainTemplate;

            // Nail down that intended age
            ageMax = ageMax <= ageMin ? -1 : ageMax;
            int age = ageMax < 0 ? ageMin : MBRandom.RandomInt(ageMin, ageMax);

            // The juice: come to life!
            var hero = HeroCreator.CreateSpecialHero(mainTemplate.CharacterObject,
                                                     bornSettlement: clan.HomeSettlement,
                                                     faction: clan,
                                                     supporterOfClan: clan,
                                                     age: age);

#if STABLE
            hero.Name = hero.FirstName;
#else
            hero.SetName(hero.FirstName);
#endif
            hero.IsNoble = true;

            // Randomize face/body parameters by simulating a cross between our main template
            // and our auxiliary template (might be same sex) + random mutation thrown into the mix
            RandomizeSpawnedNobleAppearance(hero, mainTemplate, auxTemplate);

            // Set attributes & skills & focus points

            // Currently I just ballpark skills and attributes such that they'll be decent but not beyond
            // the learning limit for the character. No special methodology here.

            // Attributes

#if STABLE
            for (var attr = CharacterAttributesEnum.First; attr < CharacterAttributesEnum.End; ++attr)
            {
                hero.SetAttributeValue(attr, MBRandom.RandomInt(6, 8));
            }
#else
            foreach (var attr in Attributes.All)
            {
                if (hero.GetAttributeValue(attr) < 4)
                {
                    hero.HeroDeveloper.AddAttribute(attr, 7, false);
                }
            }
#endif

            // Skills: level & focus point minimums
            const int MinRidingSkill = 100;

#if STABLE
            foreach (var skillObj in Game.Current.SkillList)
#else
            foreach (var skillObj in Skills.All)
#endif
            {
                var curSkill = hero.GetSkillValue(skillObj);
                var curFocus = hero.HeroDeveloper.GetFocus(skillObj);

                var(min, max) = (80, 160);

                if (skillObj == DefaultSkills.Riding)
                {
                    min = MinRidingSkill;
                }

                int minSkill = MBRandom.RandomInt(min, max);
                int minFocus = minSkill >= 120 ? 5 : minSkill >= 95 ? MBRandom.RandomInt(3, 4) : MBRandom.RandomInt(2, 4);

                if (curSkill < minSkill)
                {
                    hero.HeroDeveloper.ChangeSkillLevel(skillObj, minSkill - curSkill, false);
                }

                if (curFocus < minFocus)
                {
                    hero.HeroDeveloper.AddFocus(skillObj, minFocus - curFocus, false);
                }
            }
        public void SpawnTheHero(SpawnHero[] variables, PartyBase party)
        {
            foreach (SpawnHero heroVariables in variables)
            {
                try
                {
                    bool isFemale = heroVariables.Gender != null && heroVariables.Gender.ToLower() == "female";

                    string culture = null;
                    if (heroVariables.Culture != null)
                    {
                        switch (heroVariables.Culture.ToLower())
                        {
                        case "player":
                            culture = Hero.MainHero.Culture.StringId;
                            break;

                        case "captor":
                            culture = party.Culture.StringId;
                            break;

                        default:
                            culture = heroVariables.Culture;
                            break;
                        }
                    }
                    else
                    {
                        culture = heroVariables.Culture;
                    }

                    CharacterObject wanderer = (from x in CharacterObject.Templates
                                                where x.Occupation == Occupation.Wanderer && (culture == null || x.Culture != null && x.Culture.StringId == culture.ToLower()) && (heroVariables.Gender == null || x.IsFemale == isFemale)
                                                select x).GetRandomElementInefficiently();
                    Settlement randomElement = (from settlement in Settlement.All
                                                where settlement.Culture == wanderer.Culture && settlement.IsTown
                                                select settlement).GetRandomElementInefficiently();

                    Hero hero = HeroCreator.CreateSpecialHero(wanderer, randomElement, Clan.BanditFactions.GetRandomElementInefficiently(), null, -1);

                    GiveGoldAction.ApplyBetweenCharacters(null, hero, 20000, true);
                    hero.HasMet = true;
                    hero.ChangeState(Hero.CharacterStates.Active);
                    if (heroVariables.Clan != null)
                    {
                        switch (heroVariables.Clan.ToLower())
                        {
                        case "captor":
                            AddCompanionAction.Apply(party.Owner.Clan, hero);
                            break;

                        case "player":
                            AddCompanionAction.Apply(Clan.PlayerClan, hero);
                            break;

                        default:
                            break;
                        }
                    }

                    try
                    {
                        int level = 0;
                        int xp    = 0;

                        if (heroVariables.SkillsToLevel != null)
                        {
                            foreach (SkillToLevel skillToLevel in heroVariables.SkillsToLevel)
                            {
                                if (!string.IsNullOrWhiteSpace(skillToLevel.ByLevel))
                                {
                                    level = new CEVariablesLoader().GetIntFromXML(skillToLevel.ByLevel);
                                }
                                else if (!string.IsNullOrWhiteSpace(skillToLevel.ByXP))
                                {
                                    xp = new CEVariablesLoader().GetIntFromXML(skillToLevel.ByXP);
                                }

                                new Dynamics().SkillModifier(hero, skillToLevel.Id, level, xp, !skillToLevel.HideNotification, skillToLevel.Color);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        CECustomHandler.ForceLogToFile("Failed to level spawning Hero" + e);
                    }

                    if (heroVariables.Ref == "Prisoner" || heroVariables.Ref == "prisoner")
                    {
                        TakePrisonerAction.Apply(party, hero);
                    }
                    else
                    {
                        if (!party.IsMobile)
                        {
                            AddHeroToPartyAction.Apply(hero, party.Settlement.Party.MobileParty, true);
                        }
                        else
                        {
                            AddHeroToPartyAction.Apply(hero, party.MobileParty, true);
                        }
                    }

                    CampaignEventDispatcher.Instance.OnHeroCreated(hero, false);
                }
                catch (Exception e)
                {
                    CECustomHandler.ForceLogToFile("Failed to SpawnTheHero : " + e);
                }
            }
        }
        // Captor / Captive Version
        public void CaptivityImpregnationChance(Hero targetHero, int modifier = 0, bool forcePreg = false, bool lord = true, Hero captorHero = null)
        {
            ScoresCalculation scoresCalculation = new ScoresCalculation();


            if (targetHero != null && targetHero.IsFemale && !targetHero.IsPregnant && !CECampaignBehavior.CheckIfPregnancyExists(targetHero))
            {
                if (CESettings.Instance != null && IsHeroAgeSuitableForPregnancy(targetHero) && CESettings.Instance.PregnancyToggle)
                {
                    if (!CESettings.Instance.UsePregnancyModifiers)
                    {
                        modifier = 0;
                    }

                    if (MBRandom.Random.Next(100)
                        >= (CESettings.Instance.AttractivenessSkill
                            ? scoresCalculation.AttractivenessScore(targetHero) / 20 + modifier
                            : CESettings.Instance.PregnancyChance + modifier))
                    {
                        return;
                    }

                    Hero randomSoldier;

                    if (captorHero != null)
                    {
                        if (!captorHero.IsFemale)
                        {
                            randomSoldier = captorHero;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else if (lord && CECampaignBehavior.ExtraProps.Owner != null)
                    {
                        randomSoldier = CECampaignBehavior.ExtraProps.Owner;
                    }
                    else if (lord && targetHero.PartyBelongedToAsPrisoner != null && targetHero.PartyBelongedToAsPrisoner.IsMobile && targetHero.PartyBelongedToAsPrisoner.MobileParty?.LeaderHero != null && !targetHero.PartyBelongedToAsPrisoner.MobileParty.LeaderHero.IsFemale)
                    {
                        randomSoldier = targetHero.PartyBelongedToAsPrisoner.MobileParty.LeaderHero;
                    }
                    else if (targetHero.PartyBelongedToAsPrisoner != null && targetHero.PartyBelongedToAsPrisoner.IsMobile && targetHero.PartyBelongedToAsPrisoner.MobileParty != null)
                    {
                        IEnumerable <TroopRosterElement> maleMembers         = targetHero.PartyBelongedToAsPrisoner.MobileParty.MemberRoster.GetTroopRoster().Where(characterObject => characterObject.Character.IsFemale == false);
                        List <TroopRosterElement>        troopRosterElements = maleMembers.ToList();

                        if (!troopRosterElements.Any())
                        {
                            return;
                        }

                        CharacterObject m = troopRosterElements.GetRandomElement().Character;
                        randomSoldier = HeroCreator.CreateSpecialHero(m, targetHero.PartyBelongedToAsPrisoner.MobileParty.HomeSettlement, CampaignData.NeutralFaction, CampaignData.NeutralFaction, MBRandom.Random.Next(20) + 20);
                    }
                    else if (targetHero.PartyBelongedToAsPrisoner != null && targetHero.PartyBelongedToAsPrisoner.IsSettlement && targetHero.PartyBelongedToAsPrisoner.Settlement.Party != null && !targetHero.PartyBelongedToAsPrisoner.Settlement.Party.MemberRoster.GetTroopRoster().IsEmpty())
                    {
                        Settlement playerCaptor = targetHero.PartyBelongedToAsPrisoner.Settlement;
                        IEnumerable <TroopRosterElement> maleMembers         = playerCaptor.Party.MemberRoster.GetTroopRoster().Where(characterObject => characterObject.Character.IsFemale == false);
                        List <TroopRosterElement>        troopRosterElements = maleMembers.ToList();

                        if (!troopRosterElements.Any())
                        {
                            return;
                        }

                        CharacterObject m = troopRosterElements.GetRandomElement().Character;
                        randomSoldier = HeroCreator.CreateSpecialHero(m, playerCaptor, CampaignData.NeutralFaction, CampaignData.NeutralFaction, MBRandom.Random.Next(20) + 20);
                    }
                    else
                    {
                        CharacterObject m = CharacterObject.Templates.Where(characterObject => characterObject.IsFemale == false && characterObject.Occupation == Occupation.Outlaw).GetRandomElementInefficiently();
                        randomSoldier = HeroCreator.CreateSpecialHero(m, SettlementHelper.FindRandomSettlement(x => x.IsTown && x.Culture == m.Culture), CampaignData.NeutralFaction, CampaignData.NeutralFaction, MBRandom.Random.Next(20) + 20);
                    }

                    TextObject textObject3 = GameTexts.FindText("str_CE_impregnated");
                    textObject3.SetTextVariable("HERO", targetHero.Name);
                    textObject3.SetTextVariable("SPOUSE", randomSoldier.Name);
                    InformationManager.DisplayMessage(new InformationMessage(textObject3.ToString(), Colors.Magenta));

                    CEHelper.spouseOne = randomSoldier;
                    CEHelper.spouseTwo = targetHero;
                    MakePregnantAction.Apply(targetHero);
                    CEHelper.spouseOne = CEHelper.spouseTwo = null;

                    //RelationsModifier(randomSoldier, 50, targetHero);
                }
                else if (forcePreg)
                {
                    CharacterObject m             = CharacterObject.Templates.Where(characterObject => characterObject.IsFemale == false).GetRandomElementInefficiently();
                    Hero            randomSoldier = HeroCreator.CreateSpecialHero(m, targetHero.BornSettlement, CampaignData.NeutralFaction, CampaignData.NeutralFaction, MBRandom.Random.Next(20) + 20);
                    CEHelper.spouseOne = randomSoldier;
                    CEHelper.spouseTwo = targetHero;
                    MakePregnantAction.Apply(targetHero);
                    CEHelper.spouseOne = CEHelper.spouseTwo = null;
                    TextObject textObject4 = new TextObject("{PLAYER_HERO} forced impregnated by {PLAYER_SPOUSE}.");
                    textObject4.SetTextVariable("PLAYER_HERO", targetHero.Name);
                    textObject4.SetTextVariable("PLAYER_SPOUSE", randomSoldier.Name);
                    InformationManager.DisplayMessage(new InformationMessage(textObject4.ToString(), Colors.Magenta));
                }
            }
            else if (targetHero != null && !targetHero.IsFemale)
            {
                if (CESettings.Instance != null && !CESettings.Instance.PregnancyToggle)
                {
                    return;
                }
                if (CESettings.Instance != null && !CESettings.Instance.UsePregnancyModifiers)
                {
                    modifier = 0;
                }

                if (CESettings.Instance != null &&
                    MBRandom.Random.Next(100)
                    >= (CESettings.Instance.AttractivenessSkill
                        ? scoresCalculation.AttractivenessScore(targetHero) / 20 + modifier
                        : CESettings.Instance.PregnancyChance + modifier))
                {
                    return;
                }

                Hero randomSoldier = null;

                if (captorHero != null)
                {
                    randomSoldier = captorHero;
                    if (!(randomSoldier.IsFemale && !randomSoldier.IsPregnant && !CECampaignBehavior.CheckIfPregnancyExists(randomSoldier)))
                    {
                        return;
                    }
                }
                else if (lord && targetHero.PartyBelongedToAsPrisoner != null && targetHero.PartyBelongedToAsPrisoner.IsMobile && targetHero.PartyBelongedToAsPrisoner.MobileParty?.LeaderHero != null)
                {
                    randomSoldier = targetHero.PartyBelongedToAsPrisoner.MobileParty.LeaderHero;
                    if (!(randomSoldier.IsFemale && !randomSoldier.IsPregnant && !CECampaignBehavior.CheckIfPregnancyExists(randomSoldier)))
                    {
                        return;
                    }
                }
                else if (targetHero.PartyBelongedToAsPrisoner != null && targetHero.PartyBelongedToAsPrisoner.IsMobile && targetHero.PartyBelongedToAsPrisoner.MobileParty != null)
                {
                    IEnumerable <TroopRosterElement> femaleMembers       = targetHero.PartyBelongedToAsPrisoner.MobileParty.MemberRoster.GetTroopRoster().Where(characterObject => characterObject.Character.IsFemale);
                    List <TroopRosterElement>        troopRosterElements = femaleMembers.ToList();

                    if (!troopRosterElements.Any())
                    {
                        return;
                    }

                    do
                    {
                        CharacterObject m = troopRosterElements.GetRandomElement().Character;
                        randomSoldier = HeroCreator.CreateSpecialHero(m, targetHero.PartyBelongedToAsPrisoner.MobileParty.HomeSettlement, CampaignData.NeutralFaction, CampaignData.NeutralFaction, MBRandom.Random.Next(15) + 18);
                    } while (!IsHeroAgeSuitableForPregnancy(randomSoldier));
                }
                else if (targetHero.PartyBelongedToAsPrisoner != null && targetHero.PartyBelongedToAsPrisoner.IsSettlement && targetHero.PartyBelongedToAsPrisoner.Settlement.Party != null && !targetHero.PartyBelongedToAsPrisoner.Settlement.Party.MemberRoster.GetTroopRoster().IsEmpty())
                {
                    Settlement playerCaptor = targetHero.PartyBelongedToAsPrisoner.Settlement;
                    IEnumerable <TroopRosterElement> femaleMembers       = playerCaptor.Party.MemberRoster.GetTroopRoster().Where(characterObject => characterObject.Character.IsFemale);
                    List <TroopRosterElement>        troopRosterElements = femaleMembers.ToList();

                    if (!troopRosterElements.Any())
                    {
                        return;
                    }

                    do
                    {
                        CharacterObject m = troopRosterElements.GetRandomElement().Character;
                        if (targetHero.PartyBelongedToAsPrisoner.MobileParty != null)
                        {
                            randomSoldier = HeroCreator.CreateSpecialHero(m, targetHero.PartyBelongedToAsPrisoner.MobileParty.HomeSettlement, CampaignData.NeutralFaction, CampaignData.NeutralFaction, MBRandom.Random.Next(15) + 18);
                        }
                    } while (!IsHeroAgeSuitableForPregnancy(randomSoldier));
                }
                else
                {
                    CharacterObject m = CharacterObject.Templates.Where(characterObject => characterObject.IsFemale && characterObject.IsRegular).GetRandomElementInefficiently();
                    randomSoldier = HeroCreator.CreateSpecialHero(m, SettlementHelper.FindRandomSettlement(x => x.IsTown && x.Culture == m.Culture), CampaignData.NeutralFaction, CampaignData.NeutralFaction, MBRandom.Random.Next(15) + 18);
                }

                TextObject textObject3 = GameTexts.FindText("str_CE_impregnated");

                if (randomSoldier != null)
                {
                    textObject3.SetTextVariable("HERO", randomSoldier.Name);
                    textObject3.SetTextVariable("SPOUSE", targetHero.Name);
                    InformationManager.DisplayMessage(new InformationMessage(textObject3.ToString(), Colors.Magenta));

                    CEHelper.spouseOne = randomSoldier;
                }

                CEHelper.spouseTwo = targetHero;
                MakePregnantAction.Apply(randomSoldier);
                CEHelper.spouseOne = CEHelper.spouseTwo = null;

                //RelationsModifier(randomSoldier, 50, targetHero);
            }
        }
Exemple #16
0
        private static Hero CreateRandomLeader(Clan clan, Settlement origin)
        {
            Hero specialHero = null;

            try
            {
                CharacterObject templateBase = clan.Leader.CharacterObject;

                CharacterObject template = CharacterObject.Templates.Where(x =>
                                                                           origin.Culture == x.Culture &&
                                                                           x.Occupation == Occupation.Lord ||
                                                                           x.Occupation == Occupation.Lady).GetRandomElement();

                template.InitializeEquipmentsOnLoad(templateBase.AllEquipments.ToList());

                specialHero = HeroCreator.CreateSpecialHero(template,
                                                            origin, clan, null, -1);

                specialHero.StringId = Campaign.Current.Heroes[Campaign.Current.Heroes.Count - 1].StringId +
                                       Rand.Next(int.MaxValue);

                specialHero.Name = NameGenerator.Current.GenerateHeroFirstName(specialHero, true);

                //TextObject encyclopediaText = new TextObject("{=!}{RULER} has stretched their borders too thin. Usurper {REBEL} from {SETTLEMENT} is taking advantage of it.");
                //encyclopediaText.SetTextVariable("REBEL", specialHero.Name);
                //encyclopediaText.SetTextVariable("SETTLEMENT", origin.Name);
                //encyclopediaText.SetTextVariable("RULER", clan.Kingdom.Leader.Name);

                //specialHero.EncyclopediaText = encyclopediaText;

                specialHero.ChangeState(Hero.CharacterStates.NotSpawned);

                specialHero.IsMinorFactionHero = false;

                specialHero.IsNoble = true;

                specialHero.BornSettlement = origin;

                specialHero.UpdateHomeSettlement();

                specialHero.AddSkillXp(SkillObject.GetSkill(0), Rand.Next(80000, 500000));                 // One Handed
                specialHero.AddSkillXp(SkillObject.GetSkill(2), Rand.Next(80000, 500000));                 // Pole Arm
                specialHero.AddSkillXp(SkillObject.GetSkill(6), Rand.Next(80000, 500000));                 // Riding
                specialHero.AddSkillXp(SkillObject.GetSkill(7), Rand.Next(80000, 500000));                 // Athletics
                specialHero.AddSkillXp(SkillObject.GetSkill(9), Rand.Next(80000, 500000));                 // Tactics
                specialHero.AddSkillXp(SkillObject.GetSkill(13), Rand.Next(80000, 500000));                // Leadership
                specialHero.AddSkillXp(SkillObject.GetSkill(15), Rand.Next(80000, 500000));                // Steward
                specialHero.AddSkillXp(SkillObject.GetSkill(17), Rand.Next(80000, 500000));                // Engineering

                specialHero.ChangeState(Hero.CharacterStates.Active);

                specialHero.Gold += 100000;

                MBObjectManager.Instance.RegisterObject(specialHero);
            }
            catch (Exception e)
            {
                Log.Info("Exception when trying to create new Hero");
                Log.Error(e);
            }

            return(specialHero);
        }
Exemple #17
0
        private void conversation_adopt_child_on_consequence()
        {
            // Similar system from Recruit Everyone
            if (_notAdoptableAgents is not null)
            {
                _notAdoptableAgents.Add(_agent);
            }
            Agent           agent     = (Agent)Campaign.Current.ConversationManager.OneToOneConversationAgent;
            CharacterObject character = CharacterObject.OneToOneConversationCharacter;

            // Add a bit of the DeliverOffspring method into the mix
            Hero            hero            = HeroCreator.CreateSpecialHero(character, Settlement.CurrentSettlement, null, null, (int)agent.Age);
            int             becomeChildAge  = Campaign.Current.Models.AgeModel.BecomeChildAge;
            CharacterObject characterObject = CharacterObject.ChildTemplates.FirstOrDefault((CharacterObject t) => t.Culture == character.Culture && t.Age <= becomeChildAge && t.IsFemale == character.IsFemale && t.Occupation == Occupation.Lord);

            if (characterObject is not null)
            {
                Equipment equipment  = characterObject.FirstCivilianEquipment.Clone(false);
                Equipment equipment2 = new(false);
                equipment2.FillFrom(equipment, false);
                EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, equipment);
                EquipmentHelper.AssignHeroEquipmentFromEquipment(hero, equipment2);
            }
            MAHelper.OccupationToLord(hero.CharacterObject);
            hero.Clan = Clan.PlayerClan;
            AccessTools.Method(typeof(HeroDeveloper), "CheckInitialLevel").Invoke(hero.HeroDeveloper, null);
            hero.CharacterObject.IsFemale = character.IsFemale;
            BodyProperties bodyPropertiesValue = agent.BodyPropertiesValue;

            AccessTools.Property(typeof(Hero), "StaticBodyProperties").SetValue(hero, bodyPropertiesValue.StaticProperties);
            // Selects player as the parent
            if (Hero.MainHero.IsFemale)
            {
                hero.Mother = Hero.MainHero;
            }
            else
            {
                hero.Father = Hero.MainHero;
            }
            hero.IsNoble = true;
            hero.HasMet  = true;

            // Too much work to try and implement the log

            /*
             * CharacterAdoptedLogEntry characterAdoptedLogEntry = new(hero, Hero.MainHero);
             * Campaign.Current.CampaignInformationManager.NewMapNoticeAdded(new AdoptionMapNotification(hero, Hero.MainHero, characterAdoptedLogEntry.GetEncyclopediaText()));
             */

            // Cool idea. Might put this into Recruit Everyone, too!
            AccessTools.Field(typeof(Agent), "_name").SetValue(agent, hero.Name);
            OnHeroAdopted(Hero.MainHero, hero);
            // Follows you! I like this feature :3
            Campaign.Current.ConversationManager.ConversationEndOneShot += FollowMainAgent;

            int heroComesOfAge = Campaign.Current.Models.AgeModel.HeroComesOfAge;
            var instance       = Traverse.Create <CampaignEventDispatcher>().Property("Instance").GetValue <CampaignEventDispatcher>();

            if (hero.Age > becomeChildAge || (hero.Age == becomeChildAge && hero.BirthDay.GetDayOfYear < CampaignTime.Now.GetDayOfYear))
            {
                // CampaignEventDispatcher.Instance.OnHeroGrowsOutOfInfancy(hero);
                Traverse.Create(instance).Method("OnHeroGrowsOutOfInfancy", new Type[] { typeof(Hero) }).GetValue(new object[] { hero });
            }
            if (hero.Age > heroComesOfAge || (hero.Age == heroComesOfAge && hero.BirthDay.GetDayOfYear < CampaignTime.Now.GetDayOfYear))
            {
                // CampaignEventDispatcher.Instance.OnHeroComesOfAge(hero);
                Traverse.Create(instance).Method("OnHeroComesOfAge", new Type[] { typeof(Hero) }).GetValue(new object[] { hero });
            }
        }
Exemple #18
0
        private void CastleAbandonSettlementMenuOption(CampaignGameStarter campaignGameStarter)
        {
            campaignGameStarter.AddGameMenuOption("ruler_castle_menu", "ruler_castle_abandon", "Abandon Rulership of Castle", (GameMenuOption.OnConditionDelegate)(args =>
            {
                args.optionLeaveType = GameMenuOption.LeaveType.Manage;
                if (Settlement.CurrentSettlement.OwnerClan.Kingdom != null && Settlement.CurrentSettlement.OwnerClan.Kingdom.Leader != Hero.MainHero)
                {
                    args.Tooltip   = new TextObject("You must be the faction leader to abandon a settlement");
                    args.IsEnabled = false;
                }

                args.Tooltip = new TextObject("A minor noble will take control of the settlement");

                return(true);
            }), (GameMenuOption.OnConsequenceDelegate)(args => {
                InformationManager.ShowInquiry(new InquiryData("Abandon Castle", "Are you sure you want to abandon this castle?", true, true, "Yes", "No", (Action)(() => {
                    List <CharacterObject> source = new List <CharacterObject>();
                    CultureObject culture = Settlement.CurrentSettlement.Culture;
                    foreach (CharacterObject characterObject in CharacterObject.Templates.Where <CharacterObject>((Func <CharacterObject, bool>)(x => x.Occupation == Occupation.Lord)).ToList <CharacterObject>())
                    {
                        if (characterObject.Culture == culture)
                        {
                            source.Add(characterObject);
                        }
                    }
                    CharacterObject template = source[rng.Next(0, source.Count - 1)];
                    Hero NewHero = HeroCreator.CreateSpecialHero(template, Settlement.CurrentSettlement, null, Hero.MainHero.Clan, rng.Next(25, 30));
                    NewHero.ChangeState(Hero.CharacterStates.Active);
                    HeroCreationCampaignBehavior herocreationbehavior = new HeroCreationCampaignBehavior();
                    herocreationbehavior.DeriveSkillsFromTraits(NewHero, template);

                    List <CharacterObject> source2 = new List <CharacterObject>();
                    foreach (CharacterObject characterObject in CharacterObject.Templates.Where <CharacterObject>((Func <CharacterObject, bool>)(x => x.Occupation == Occupation.Lord)).ToList <CharacterObject>())
                    {
                        if (characterObject.Culture == culture)
                        {
                            source2.Add(characterObject);
                        }
                    }
                    CharacterObject template2 = source2[rng.Next(0, source2.Count - 1)];
                    template2.IsFemale = true;
                    Hero NewHero2 = HeroCreator.CreateSpecialHero(template2, Settlement.CurrentSettlement, null, Hero.MainHero.Clan, rng.Next(25, 30));
                    NewHero2.ChangeState(Hero.CharacterStates.Active);
                    herocreationbehavior.DeriveSkillsFromTraits(NewHero2, template2);
                    template2.IsFemale = false;

                    Clan clan = MBObjectManager.Instance.CreateObject <Clan>();
                    Banner ClanBanner = Banner.CreateRandomClanBanner();
                    TextObject clanName = culture.ClanNameList[rng.Next(0, culture.ClanNameList.Count)];
                    clan.InitializeClan(clanName, clanName, culture, ClanBanner);
                    clan.SetLeader(NewHero);
                    FieldInfo field = clan.GetType().GetField("_tier", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    if ((FieldInfo)null != field)
                    {
                        field.SetValue((object)clan, rng.Next(2, 4));
                    }

                    NewHero.Clan = clan;
                    NewHero.IsNoble = true;
                    MobileParty newMobileParty1 = clan.CreateNewMobileParty(NewHero);
                    newMobileParty1.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
                    newMobileParty1.ItemRoster.AddToCounts(DefaultItems.Meat, 5);

                    NewHero2.Clan = clan;
                    NewHero2.IsNoble = true;
                    MobileParty newMobileParty2 = clan.CreateNewMobileParty(NewHero2);
                    newMobileParty2.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
                    newMobileParty2.ItemRoster.AddToCounts(DefaultItems.Meat, 5);

                    ChangeOwnerOfSettlementAction.ApplyByKingDecision(NewHero, Settlement.CurrentSettlement);
                    clan.UpdateHomeSettlement(Settlement.CurrentSettlement);

                    MarriageAction.Apply(NewHero, NewHero2);
                    ChangeRelationAction.ApplyPlayerRelation(NewHero, 40);
                }), (Action)(() => {
                    GameMenu.SwitchToMenu("castle");
                })), true);
            }), index: 1);;;
        }