Пример #1
0
            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();
            }
Пример #2
0
            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))));
            }
Пример #3
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);
        }