public static void NewClanAllocateForHero(Hero hero, Clan clan) { if (hero.Clan == Clan.PlayerClan) { DealApplyByFire(Hero.MainHero.Clan, hero); SetOccupationToLord(hero); hero.Clan = clan; hero.CompanionOf = null; hero.ChangeState(Hero.CharacterStates.Active); hero.IsNoble = true; if (hero.Age >= Campaign.Current.Models.AgeModel.HeroComesOfAge && hero.PartyBelongedTo == null) { MobileParty chilrenMobileParty = clan.CreateNewMobileParty(hero); chilrenMobileParty.ItemRoster.AddToCounts(DefaultItems.Grain, 10); chilrenMobileParty.ItemRoster.AddToCounts(DefaultItems.Meat, 5); } GiveGoldAction.ApplyBetweenCharacters(Hero.MainHero, hero, 2000, false); } }
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 static bool Prefix(Settlement settlement) { bool hadPlayerSupport = false; List <Hero> NotablesSupportingReveolt = new List <Hero>(); if (settlement.IsVillage) { return(true); } Town town = settlement.Town; foreach (var pair in NotableBehavior.RebelliousNotables) { if (town.Settlement.Notables.Contains(pair.Key)) { if (town.MapFaction == pair.Value) { hadPlayerSupport = true; NotablesSupportingReveolt.Add(pair.Key); } } foreach (Village village in town.Villages) { if (village.Settlement.Notables.Contains(pair.Key)) { hadPlayerSupport = true; NotablesSupportingReveolt.Add(pair.Key); } } } if (hadPlayerSupport) { InformationManager.ShowInquiry(new InquiryData("Rebellion", "Your supporters have started an uprising in " + settlement.Town.Name.ToString() + ". Do you want to take direct control of the settlement or let them elect their own leader? Taking control of the settlement will lead to a war with the previous owners", true, true, "take it", "let them decide", (Action)(() => { DeclareWarAction.ApplyDeclareWarOverSettlement(settlement.MapFaction, Hero.MainHero.MapFaction); ChangeOwnerOfSettlementAction.ApplyByRebellion(Hero.MainHero, settlement); }), (Action)(() => { Random rng = new Random(); Hero newLeader = NotablesSupportingReveolt[rng.Next(0, NotablesSupportingReveolt.Count - 1)]; FieldInfo field2 = newLeader.GetType().GetField("Occupation", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if ((FieldInfo)null != field2) { field2.SetValue((object)newLeader, Occupation.Lord); } Clan clan = MBObjectManager.Instance.CreateObject <Clan>(); Banner ClanBanner = Banner.CreateRandomClanBanner(); TextObject clanName = newLeader.Culture.ClanNameList[rng.Next(0, newLeader.Culture.ClanNameList.Count)]; clan.InitializeClan(clanName, clanName, newLeader.Culture, ClanBanner); clan.SetLeader(newLeader); FieldInfo field = clan.GetType().GetField("_tier", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if ((FieldInfo)null != field) { field.SetValue((object)clan, rng.Next(2, 4)); } newLeader.Clan = clan; newLeader.IsNoble = true; MobileParty newMobileParty1 = clan.CreateNewMobileParty(newLeader); newMobileParty1.ItemRoster.AddToCounts(DefaultItems.Grain, 10); newMobileParty1.ItemRoster.AddToCounts(DefaultItems.Meat, 5); List <Equipment> Lordgear = new List <Equipment>(); foreach (Hero hero in Campaign.Current.Heroes) { if (hero.Culture == newLeader.Culture && hero.IsNoble && hero.IsFemale == newLeader.IsFemale) { Lordgear.Add(hero.BattleEquipment); } } EquipmentHelper.AssignHeroEquipmentFromEquipment(newLeader, Lordgear[rng.Next(0, Lordgear.Count - 1)]); clan.UpdateHomeSettlement(settlement); ChangeRelationAction.ApplyRelationChangeBetweenHeroes(newLeader, settlement.OwnerClan.Leader, -200); if (settlement.OwnerClan.Leader != settlement.MapFaction.Leader) { ChangeRelationAction.ApplyRelationChangeBetweenHeroes(newLeader, settlement.MapFaction.Leader, -200); } DeclareWarAction.Apply(settlement.MapFaction, newLeader.MapFaction); ChangeOwnerOfSettlementAction.ApplyByRebellion(newLeader, settlement); }))); return(false); } else { return(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);;; }