public static void CSGiveCastle(out Settlement Castle) { Castle = (from settlement in Settlement.All where settlement.Culture == Hero.MainHero.Culture && settlement.IsCastle select settlement).GetRandomElementInefficiently <Settlement>(); if (Castle == null) //Adding this for custom cultures that don't have any land to start { Castle = (from settlement in Settlement.All where settlement.IsCastle select settlement).GetRandomElementInefficiently <Settlement>(); } ChangeOwnerOfSettlementAction.ApplyByKingDecision(Hero.MainHero, Castle); if (CSCharCreationOption.CSLocationOption == 8) { MobileParty.MainParty.Position2D = Castle.GatePosition; MapState mapstate; mapstate = (GameStateManager.Current.ActiveState as MapState); mapstate.Handler.TeleportCameraToMainParty(); } }
private static void ConsiderFiefGiveAway(Clan clan) { if (clan == Clan.PlayerClan || clan.Kingdom == null || clan.Kingdom.RulingClan != clan) { return; } if (clan.Settlements == null || clan.Settlements.Count(s => s.IsFortification) < 2) { return; } Kingdom kingdom = clan.Kingdom; if (kingdom.UnresolvedDecisions.FirstOrDefault((KingdomDecision x) => x is SettlementClaimantDecision) != null) { return; } Clan bomzh = kingdom.Clans.FirstOrDefault(c => !c.IsUnderMercenaryService && c.Heroes.Count(h => h.IsAlive) > 0 && (c.Settlements == null || c.Settlements.Count() == 0)); if (bomzh == null) { return; } SettlementValueModel model = Campaign.Current.Models.SettlementValueModel; Settlement settlement = clan.Settlements .Where(s => s.IsFortification) .MaxBy(s => model.CalculateValueForFaction(s, kingdom)); ChangeOwnerOfSettlementAction.ApplyByKingDecision(bomzh.Leader, settlement); }
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); }
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);;; }