private CultureObject GetCultureToSpawn()
        {
            List <IFaction> factionsAtWar = new List <IFaction>();

            foreach (IFaction faction in Campaign.Current.Factions)
            {
                if (Hero.MainHero.Clan.IsAtWarWith(faction) && !faction.IsBanditFaction)
                {
                    factionsAtWar.Add(faction);
                }
            }

            if (factionsAtWar.Count == 0)
            {
                // The player isn't at war with anyone, we'll spawn bandits.
                List <Settlement> hideouts       = Settlement.FindAll((s) => { return(s.IsHideout()); }).ToList();
                Settlement        closestHideout = hideouts.MinBy((s) => { return(MobileParty.MainParty.GetPosition().DistanceSquared(s.GetPosition())); });
                return(closestHideout.Culture);
            }
            else
            {
                // Pick one of the factions to spawn prisoners of
                return(RandomSelection <IFaction> .GetRandomElement(factionsAtWar).Culture);
            }
        }
Exemple #2
0
        public override void StartEvent()
        {
            if (Settings.GeneralSettings.DebugMode)
            {
                InformationManager.DisplayMessage(new InformationMessage($"Starting {this.RandomEventData.EventType}", RandomEventsSubmodule.textColor));
            }

            int realMaxTroopGain = Math.Min(MobileParty.MainParty.Party.PartySizeLimit - MobileParty.MainParty.MemberRoster.TotalHealthyCount, maxTroopGain);
            int numberToAdd      = MBRandom.RandomInt(minTroopGain, realMaxTroopGain);

            List <Settlement> settlements       = Settlement.FindAll((s) => { return(!s.IsHideout()); }).ToList();
            Settlement        closestSettlement = settlements.MinBy((s) => { return(MobileParty.MainParty.GetPosition().DistanceSquared(s.GetPosition())); });

            List <InquiryElement> inquiryElements = new List <InquiryElement>();

            inquiryElements.Add(new InquiryElement("a", "Accept", null));
            inquiryElements.Add(new InquiryElement("b", "Decline", null));

            MultiSelectionInquiryData msid = new MultiSelectionInquiryData(
                eventTitle,                                                                                                 // Title
                $"You come across {numberToAdd} troops that are eager for battle and glory. They want to join your ranks!", // Description
                inquiryElements,                                                                                            // Options
                false,                                                                                                      // Can close menu without selecting an option. Should always be false.
                1,                                                                                                          // Force a single option to be selected. Should usually be true
                "Okay",                                                                                                     // The text on the button that continues the event
                null,                                                                                                       // The text to display on the "cancel" button, shouldn't ever need it.
                (elements) =>                                                                                               // How to handle the selected option. Will only ever be a single element unless force single option is off.
            {
                if ((string)elements[0].Identifier == "a")
                {
                    MobileParty bandits = PartySetup.CreateBanditParty();
                    bandits.MemberRoster.Clear();
                    PartySetup.AddRandomCultureUnits(bandits, numberToAdd, closestSettlement.Culture);

                    MobileParty.MainParty.MemberRoster.Add(bandits.MemberRoster);

                    bandits.RemoveParty();
                }
                else if ((string)elements[0].Identifier == "b")
                {
                    InformationManager.ShowInquiry(new InquiryData(eventTitle, "Disappointed, the soldiers leave.", true, false, "Done", null, null, null), true);
                }
                else
                {
                    MessageBox.Show($"Error while selecting option for \"{this.RandomEventData.EventType}\"");
                }
            },
                null);                 // What to do on the "cancel" button, shouldn't ever need it.

            InformationManager.ShowMultiSelectionInquiry(msid, true);

            StopEvent();
        }
Exemple #3
0
        private static void GoToSettlementByString(string name)
        {
            var matches = Settlement.FindAll(x =>
                                             x.Name.ToLower().ToString().StartsWith(name)).ToList();

            if (matches.Count == 0)
            {
                return;
            }

            // prefer an exact match over a substring
            var settlement = matches.Any(x => x.ToString().Length == name.Length)
                ? matches.First(x => x.ToString().Length == name.Length)
                : matches.OrderByDescending(x => x.ToString().Length).First();

            SetCameraToSettlement(settlement.StringId);
        }
Exemple #4
0
        public static MobileParty CreateBanditParty(string cultureObjectID = null, string partyName = null)
        {
            MobileParty banditParty = null;

            try
            {
                List <Settlement> hideouts       = Settlement.FindAll((s) => { return(s.IsHideout()); }).ToList();
                Settlement        closestHideout = hideouts.MinBy((s) => { return(MobileParty.MainParty.GetPosition().DistanceSquared(s.GetPosition())); });

                CultureObject banditCultureObject = null;
                if (cultureObjectID != null)
                {
                    banditCultureObject = MBObjectManager.Instance.GetObject <CultureObject>(cultureObjectID);
                }
                else
                {
                    banditCultureObject = closestHideout.Culture;
                }

                if (partyName == null)
                {
                    partyName = $"{banditCultureObject.Name} (Random Event)";
                }

                PartyTemplateObject partyTemplate = MBObjectManager.Instance.GetObject <PartyTemplateObject>($"{banditCultureObject.StringId}_template");
                banditParty = MBObjectManager.Instance.CreateObject <MobileParty>($"randomevent_{banditCultureObject.StringId}_{MBRandom.RandomInt(int.MaxValue)}");
                TextObject partyNameTextObject = new TextObject(partyName, null);
                Clan       banditClan          = Clan.BanditFactions.FirstOrDefault(clan => clan.StringId == banditCultureObject.StringId);
                banditParty.InitializeMobileParty(partyTemplate, MobileParty.MainParty.Position2D, 0.2f, 0.1f);
                banditParty.SetCustomName(partyNameTextObject);

                banditParty.HomeSettlement = closestHideout;
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error while trying to create a mobile bandit party :\n\n {ex.Message} \n\n { ex.StackTrace}");
            }

            return(banditParty);
        }
Exemple #5
0
 private void ExitChangeCultureMenu()
 {
     if (this._cultureChangerProperties.CurrentCulture != null)
     {
         // change culture to the choosen one
         this._cultureChangerProperties.Settlement.Culture = this._cultureChangerProperties.CurrentCulture;
         // change bound settlement as well
         if (this._cultureChangerProperties.Settlement.BoundVillages.Count > 0)
         {
             foreach (Village element in this._cultureChangerProperties.Settlement.BoundVillages)
             {
                 Settlement settlement = Settlement.FindAll(delegate(Settlement s) {
                     if (s.Name.ToString() == element.Name.ToString())
                     {
                         return(true);
                     }
                     return(false);
                 }).First();
                 if (settlement == null)
                 {
                     InformationManager.DisplayMessage(new InformationMessage("[Error] Could not find bound settlement :" + element.Name.ToString()));
                     continue;
                 }
                 else
                 {
                     InformationManager.DisplayMessage(new InformationMessage(
                                                           String.Format("Culture of {0} changed to {1}", element.Name.ToString(), this._cultureChangerProperties.CurrentCultureName)
                                                           ));
                 }
                 settlement.Culture = this._cultureChangerProperties.Settlement.Culture;
             }
         }
         InformationManager.DisplayMessage(new InformationMessage(
                                               String.Format("Culture of {0} changed to {1}", this._cultureChangerProperties.Settlement.Name.ToString(), this._cultureChangerProperties.CurrentCultureName)
                                               ));
     }
     ScreenManager.PopScreen();
 }
            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))));
            }
Exemple #7
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();
            }
Exemple #8
0
        public static Settlement RandcultureSettlement()
        {
            //var result;

            return(Settlement.FindAll((Settlement x) => x.IsTown).GetRandomElement <Settlement>());
        }