Ejemplo n.º 1
0
        private void InitializeClan(Hero leader, string origin)
        {
            Clan newClan = MBObjectManager.Instance.CreateObject <Clan>();

            try
            {
                newClan.Culture = leader.Culture;

                TextObject name = new TextObject("{=!}{CLAN_NAME}");

                origin = origin.Replace(" Castle", "");

                name.SetTextVariable("CLAN_NAME", leader.Name + " of " + origin);

                newClan.AddRenown(900, false);

                newClan.SetLeader(leader);

                leader.Clan = newClan;

                newClan.InitializeClan(name,
                                       name,
                                       leader.Culture,
                                       Banner.CreateRandomClanBanner(leader.StringId.GetDeterministicHashCode()));
            }
            catch (Exception e)
            {
                Log.Info("Exception in InitializeClan");
                Log.Error(e);
            }
        }
Ejemplo n.º 2
0
        public void CreateVassal()
        {
            //Settlement settlement = GetCandidateSettlements().FirstOrDefault<Settlement>();
            if (targetSettlement == null)
            {
                return;
            }
            Hero hero = Hero.OneToOneConversationHero;

            if (hero == null)
            {
                return;
            }
            Kingdom kingdom = Hero.MainHero.MapFaction as Kingdom;

            if (kingdom == null)
            {
                return;
            }

            CultureObject culture  = targetSettlement.Culture;
            TextObject    clanName = NameGenerator.Current.GenerateClanName(culture, targetSettlement);
            string        str      = Guid.NewGuid().ToString().Replace("-", "");

            if (null == hero.LastSeenPlace)
            {
                hero.CacheLastSeenInformation(hero.HomeSettlement, true);
                hero.SyncLastSeenInformation();
            }
            //RemoveCompanionAction.ApplyByFire(Hero.MainHero.Clan, hero);
            //for  1.4.3 200815
            HeroOperation.DealApplyByFire(Hero.MainHero.Clan, hero);

            HeroOperation.SetOccupationToLord(hero);
            hero.ChangeState(Hero.CharacterStates.Active);
            Clan   clan   = TaleWorlds.ObjectSystem.MBObjectManager.Instance.CreateObject <Clan>("sue_clan_" + str);
            Banner banner = Banner.CreateRandomClanBanner(-1);

            clan.InitializeClan(clanName, clanName, culture, banner);
            clan.SetLeader(hero);

            //clan.Tier = 5; 修改家族等级
            FieldInfo fieldInfoId = clan.GetType().GetField("_tier", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

            if (null != fieldInfoId)
            {
                fieldInfoId.SetValue(clan, selectClanTier);
            }
            //增加一些影响力
            clan.AddRenown(50 * selectClanTier, true);


            hero.Clan        = clan;
            hero.CompanionOf = null;
            hero.IsNoble     = true;
            hero.SetTraitLevel(DefaultTraits.Commander, 1);

            MobileParty mobileParty = clan.CreateNewMobileParty(hero);

            mobileParty.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
            mobileParty.ItemRoster.AddToCounts(DefaultItems.Meat, 5);

            ChangeOwnerOfSettlementAction.ApplyByKingDecision(hero, targetSettlement);
            clan.UpdateHomeSettlement(targetSettlement);


            int takeMoney = TakeMoneyByTier(selectClanTier);

            if (targetSpouse != null)
            {
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, hero, takeMoney / 2, false);
            }
            else
            {
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, hero, takeMoney, false);
            }

            //关系处理
            //新晋家族关系增加
            int shipIncreate = ShipIncreateByTier(selectClanTier);

            ChangeRelationAction.ApplyPlayerRelation(hero, shipIncreate, true, true);
            if (targetSpouse != null)
            {
                ChangeRelationAction.ApplyPlayerRelation(targetSpouse, shipIncreate, true, true);
            }

            //以前家族关系减低,
            int     shipReduce = ShipReduceByTier(selectClanTier);
            Kingdom kindom     = Hero.MainHero.MapFaction as Kingdom;

            if (null != kindom && shipReduce > 0)
            {
                kindom.Clans.ToList().ForEach((obj) =>
                {
                    if (obj != Clan.PlayerClan)
                    {
                        ChangeRelationAction.ApplyPlayerRelation(obj.Leader, shipReduce * -1, true, true);
                    }
                }
                                              );
            }

            if (targetSpouse != null)
            {
                targetSpouse.Spouse = hero;
                InformationManager.AddQuickInformation(new TextObject($"{hero.Name} marry with {targetSpouse.Name}"), 0, null, "event:/ui/notification/quest_finished");

                HeroOperation.DealApplyByFire(Hero.MainHero.Clan, targetSpouse);
                //RemoveCompanionAction.ApplyByFire(Hero.MainHero.Clan, targetSpouse);

                targetSpouse.ChangeState(Hero.CharacterStates.Active);
                targetSpouse.IsNoble = true;
                HeroOperation.SetOccupationToLord(targetSpouse);
                targetSpouse.CompanionOf = null;
                targetSpouse.Clan        = clan;
                targetSpouse.SetTraitLevel(DefaultTraits.Commander, 1);
                //AddCompanionAction.Apply(clan, targetSpouse);

                MobileParty targetSpouseMobileParty = clan.CreateNewMobileParty(targetSpouse);

                targetSpouseMobileParty.ItemRoster.AddToCounts(DefaultItems.Grain, 10);
                targetSpouseMobileParty.ItemRoster.AddToCounts(DefaultItems.Meat, 5);
                GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, targetSpouse, takeMoney / 2, false);
            }

            // 他们孩子处理
            if (isTogetherWithThireChildren)
            {
                DealTheirChildren(hero, clan);
            }


            //加入王国
            ChangeKingdomAction.ApplyByJoinToKingdom(clan, kingdom, true);
        }