Example #1
0
 public MissionAgentSpawnLogic(IMissionTroopSupplier[] suppliers, BattleSideEnum playerSide)
 {
     this._battleSize   = Math.Min(BannerlordConfig.GetRealBattleSize(), MissionAgentSpawnLogic.MaxNumberOfTroopsForMission);
     this._missionSides = new MissionAgentSpawnLogic.MissionSide[2];
     for (int index = 0; index < 2; ++index)
     {
         IMissionTroopSupplier supplier = suppliers[index];
         bool isPlayerSide = (BattleSideEnum)index == playerSide;
         this._missionSides[index] = new MissionAgentSpawnLogic.MissionSide((BattleSideEnum)index, supplier, isPlayerSide);
     }
     this._numberOfTroopsInTotal = new int[2];
     this._numberOfTroopsInQueueForReinforcement = new int[2];
     this._numberOfTroopsToSpawnPerSideFormation = new int[11];
     this._phases = new List <MissionAgentSpawnLogic.SpawnPhase> [2];
     for (int index = 0; index < 2; ++index)
     {
         this._phases[index] = new List <MissionAgentSpawnLogic.SpawnPhase>();
     }
 }
Example #2
0
 public static void SaveConfig() => BannerlordConfig.Save();
        public static void Initialize()
        {
            string str1 = Utilities.LoadConfigFile(nameof(BannerlordConfig));

            if (string.IsNullOrEmpty(str1))
            {
                BannerlordConfig.Save();
            }
            else
            {
                bool   flag     = false;
                string str2     = str1;
                char[] chArray1 = new char[1] {
                    '\n'
                };
                foreach (string str3 in str2.Split(chArray1))
                {
                    char[] chArray2 = new char[1] {
                        '='
                    };
                    string[]     strArray = str3.Split(chArray2);
                    PropertyInfo property = typeof(BannerlordConfig).GetProperty(strArray[0]);
                    if (property == (PropertyInfo)null)
                    {
                        flag = true;
                    }
                    else
                    {
                        string s = strArray[1];
                        try
                        {
                            if (property.PropertyType == typeof(string))
                            {
                                property.SetValue((object)null, (object)s);
                            }
                            else if (property.PropertyType == typeof(float))
                            {
                                float result;
                                if (float.TryParse(s, out result))
                                {
                                    property.SetValue((object)null, (object)result);
                                }
                                else
                                {
                                    flag = true;
                                }
                            }
                            else if (property.PropertyType == typeof(int))
                            {
                                int result;
                                if (int.TryParse(s, out result))
                                {
                                    BannerlordConfig.ConfigPropertyInt customAttribute = property.GetCustomAttribute <BannerlordConfig.ConfigPropertyInt>();
                                    if (customAttribute == null || customAttribute.IsValidValue(result))
                                    {
                                        property.SetValue((object)null, (object)result);
                                    }
                                    else
                                    {
                                        flag = true;
                                    }
                                }
                                else
                                {
                                    flag = true;
                                }
                            }
                            else if (property.PropertyType == typeof(bool))
                            {
                                bool result;
                                if (bool.TryParse(s, out result))
                                {
                                    property.SetValue((object)null, (object)result);
                                }
                                else
                                {
                                    flag = true;
                                }
                            }
                            else
                            {
                                flag = true;
                            }
                        }
                        catch
                        {
                            flag = true;
                        }
                    }
                }
                if (flag)
                {
                    BannerlordConfig.Save();
                }
                MBAPI.IMBBannerlordConfig.ValidateOptions();
            }
            MBTextManager.ChangeLanguage(BannerlordConfig.Language);
        }