public Militia(MobileParty mobileParty, TroopRoster party, TroopRoster prisoners) { Banner = Banners.GetRandomElement(); BannerKey = Banner.Serialize(); Spawn(mobileParty, party, prisoners); TrainMilitia(); PartyMilitiaMap.Add(MobileParty, this); LogMilitiaFormed(MobileParty); }
private void Spawn(Vec2 position, TroopRoster party, TroopRoster prisoners) { var partyClan = GetMostPrevalent(party) ?? Clan.BanditFactions.First(); MobileParty = ModBanditMilitiaPartyComponent.CreateBanditParty(partyClan); MobileParty.InitializeMobilePartyAroundPosition(party, prisoners, position, 0); PartyMilitiaMap.Add(MobileParty, this); PartyImageMap.Add(MobileParty, new ImageIdentifierVM(Banner)); var leaderHero = MobileParty.MemberRoster.GetTroopRoster().ToListQ()[0].Character.HeroObject; MobileParty.PartyComponent.ChangePartyLeader(leaderHero); Hero = MobileParty.LeaderHero; Hero.Gold = Convert.ToInt32(MobileParty.Party.TotalStrength * Globals.GoldMap[Globals.Settings.GoldReward.SelectedValue]); if (MobileParty.ActualClan.Leader is null) { MobileParty.ActualClan.SetLeader(Hero); } if (MobileParty.MemberRoster.GetTroopRoster().Any(t => t.Character.IsMounted)) { var mount = Mounts.GetRandomElement(); Hero.BattleEquipment[10] = new EquipmentElement(mount); if (mount.HorseComponent.Monster.MonsterUsage == "camel") { Hero.BattleEquipment[11] = new EquipmentElement(Saddles.Where(saddle => saddle.Name.ToString().ToLower().Contains("camel")).ToList().GetRandomElement()); } else { Hero.BattleEquipment[11] = new EquipmentElement(Saddles.Where(saddle => !saddle.Name.ToString().ToLower().Contains("camel")).ToList().GetRandomElement()); } } var getLocalizedText = AccessTools.Method(typeof(MBTextManager), "GetLocalizedText"); Name = (string)getLocalizedText.Invoke(null, new object[] { $"{Possess(Hero.FirstName.ToString())} Bandit Militia" }); MobileParty.SetCustomName(new TextObject(Name)); MobileParty.LeaderHero.StringId += "Bandit_Militia"; MobileParty.ShouldJoinPlayerBattles = true; var tracker = Globals.MobilePartyTrackerVM?.Trackers?.FirstOrDefault(t => t.TrackedParty == MobileParty); if (Globals.Settings.Trackers && tracker is null && MobileParty.MemberRoster.TotalManCount >= Globals.Settings.TrackedSizeMinimum) { tracker = new MobilePartyTrackItemVM(MobileParty, MapScreen.Instance.MapCamera, null); Globals.MobilePartyTrackerVM?.Trackers?.Add(tracker); }
private static void Postfix() { Mod.Log("MapScreen.OnInitialize"); //Mod.Log("Clans:"); //Clan.All.Do(x => Mod.Log($"Name: {x.Name} MapFaction: {x.MapFaction} Culture: {x.Culture}")); //Mod.Log("Bandit Clans:"); //Clan.BanditFactions.Do(x => Mod.Log($"Name: {x.Name} MapFaction: {x.MapFaction} Culture: {x.Culture}")); HeroCreatorCopy.VeteransRespect = PerkObject.All.First(x => x.StringId == "LeadershipVeteransRespect"); HeroCreatorCopy.Leadership = SkillObject.All.First(x => x.StringId == "Leadership"); EquipmentItems.Clear(); PopulateItems(); Recruits = CharacterObject.All.Where(x => x.Level == 11 && x.Occupation == Occupation.Soldier && !x.StringId.StartsWith("regular_fighter") && !x.StringId.StartsWith("veteran_borrowed_troop") && !x.StringId.EndsWith("_tier_1") && !x.StringId.Contains("_militia_") && !x.StringId.Equals("sturgian_warrior_son") && !x.StringId.Equals("khuzait_noble_son") && !x.StringId.Equals("imperial_vigla_recruit") && !x.StringId.Equals("battanian_highborn_youth") && !x.StringId.Equals("vlandian_squire") && !x.StringId.Equals("aserai_youth") && !x.StringId.Equals("poacher")); // used for armour foreach (ItemObject.ItemTypeEnum value in Enum.GetValues(typeof(ItemObject.ItemTypeEnum))) { ItemTypes[value] = Items.FindAll(x => x.Type == value && x.Value >= 1000 && x.Value <= Globals.Settings.MaxItemValue * Variance).ToList(); } // front-load BanditEquipment.Clear(); for (var i = 0; i < 500; i++) { BanditEquipment.Add(BuildViableEquipmentSet()); } PartyMilitiaMap.Clear(); Hideouts = Settlement.FindAll(x => x.IsHideout()).ToList(); var militias = MobileParty.All.Where(x => x != null && x.StringId.StartsWith("Bandit_Militia")).ToList(); for (var i = 0; i < militias.Count; i++) { var militia = militias[i]; if (militia.LeaderHero == null) { Mod.Log("Leaderless militia found and removed."); Trash(militia); } else { var recreatedMilitia = new Militia(militia); PartyMilitiaMap.Add(recreatedMilitia.MobileParty, recreatedMilitia); } } Mod.Log($"Militias: {militias.Count} (registered {PartyMilitiaMap.Count})"); // 1.5.8 is dropping the militia settlements at some point, I haven't figured out where ReHome(); DailyCalculations(); // have to patch it late because of its static constructor (type initialization exception) Mod.harmony.Patch( AccessTools.Method(typeof(EncounterGameMenuBehavior), "game_menu_encounter_on_init"), new HarmonyMethod(AccessTools.Method(typeof(Helper), nameof(FixMapEventFuckery)))); }
private static void Postfix() { Mod.Log("MapScreen.OnInitialize"); MinSplitSize = Globals.Settings.MinPartySize * 2; EquipmentItems.Clear(); PopulateItems(); // 1.7 changed CreateHeroAtOccupation to only fish from this: NotableAndWandererTemplates // this has no effect on 1.6.5 since the property doesn't exist var characterObjects = CharacterObject.All.Where(x => x.Occupation is Occupation.Bandit && x.Name.Contains("Boss")).ToList().GetReadOnlyList(); foreach (var clan in Clan.BanditFactions) { Traverse.Create(clan.Culture).Property <IReadOnlyList <CharacterObject> >("NotableAndWandererTemplates").Value = characterObjects; } var filter = new List <string> { "regular_fighter", "veteran_borrowed_troop", }; Recruits = CharacterObject.All.Where(c => c.Level == 11 && c.Occupation == Occupation.Soldier && !filter.Contains(c.StringId) && !c.StringId.EndsWith("_tier_1")); // used for armour foreach (ItemObject.ItemTypeEnum value in Enum.GetValues(typeof(ItemObject.ItemTypeEnum))) { ItemTypes[value] = Items.All.Where(x => x.Type == value && x.Value >= 1000 && x.Value <= Globals.Settings.MaxItemValue).ToList(); } // front-load BanditEquipment.Clear(); for (var i = 0; i < 1000; i++) { BanditEquipment.Add(BuildViableEquipmentSet()); } PartyMilitiaMap.Clear(); Hideouts = Settlement.FindAll(x => x.IsHideout).ToList(); // considers leaderless militias var militias = MobileParty.All.Where(m => m.LeaderHero is not null && m.StringId.StartsWith("Bandit_Militia")).ToList(); for (var i = 0; i < militias.Count; i++) { var militia = militias[i]; var recreatedMilitia = new Militia(militia); SetMilitiaPatrol(recreatedMilitia.MobileParty); PartyMilitiaMap.Add(recreatedMilitia.MobileParty, recreatedMilitia); } DoPowerCalculations(true); FlushMilitiaCharacterObjects(); // 1.6 is dropping the militia settlements at some point, I haven't figured out where ReHome(); Mod.Log($"Militias: {militias.Count} (registered {PartyMilitiaMap.Count})"); RunLateManualPatches(); }