private CustomBattleData PrepareBattleData()
        {
            BasicCharacterObject selectedCharacter1 = this.PlayerSide.SelectedCharacter;
            BasicCharacterObject selectedCharacter2 = this.EnemySide.SelectedCharacter;
            int  armySize1        = this.PlayerSide.CompositionGroup.ArmySize;
            int  armySize2        = this.EnemySide.CompositionGroup.ArmySize;
            bool isPlayerAttacker = this.GameTypeSelectionGroup.SelectedPlayerSide == CustomBattlePlayerSide.Attacker;
            bool flag             = this.GameTypeSelectionGroup.SelectedPlayerType == CustomBattlePlayerType.Commander;
            BasicCharacterObject playerSideGeneralCharacter = (BasicCharacterObject)null;

            if (!flag)
            {
                List <BasicCharacterObject> list = CustomBattleData.Characters.ToList <BasicCharacterObject>();
                list.Remove(selectedCharacter1);
                list.Remove(selectedCharacter2);
                playerSideGeneralCharacter = list.GetRandomElement <BasicCharacterObject>();
                --armySize1;
            }
            int[] troopCounts1 = CustomBattleMenuVM.CustomBattleHelper.GetTroopCounts(armySize1, this.PlayerSide.CompositionGroup);
            ArmyCompositionGroupVM compositionGroup = this.EnemySide.CompositionGroup;

            int[] troopCounts2 = CustomBattleMenuVM.CustomBattleHelper.GetTroopCounts(armySize2, compositionGroup);
            List <BasicCharacterObject>[] troopSelections1 = CustomBattleMenuVM.CustomBattleHelper.GetTroopSelections(this.PlayerSide.CompositionGroup);
            List <BasicCharacterObject>[] troopSelections2 = CustomBattleMenuVM.CustomBattleHelper.GetTroopSelections(this.EnemySide.CompositionGroup);
            BasicCultureObject            selectedFaction1 = this.PlayerSide.SelectedFaction;
            BasicCultureObject            selectedFaction2 = this.EnemySide.SelectedFaction;

            CustomBattleCombatant[] customBattleParties = this._customBattleState.GetCustomBattleParties(selectedCharacter1, playerSideGeneralCharacter, selectedCharacter2, selectedFaction1, troopCounts1, troopSelections1, selectedFaction2, troopCounts2, troopSelections2, isPlayerAttacker);
            CustomBattleData        customBattleData    = new CustomBattleData();

            customBattleData.GameType                   = this.GameTypeSelectionGroup.SelectedGameType;
            customBattleData.SceneId                    = this.MapSelectionGroup.SelectedMapId;
            customBattleData.PlayerCharacter            = selectedCharacter1;
            customBattleData.PlayerParty                = customBattleParties[0];
            customBattleData.EnemyParty                 = customBattleParties[1];
            customBattleData.IsPlayerGeneral            = flag;
            customBattleData.PlayerSideGeneralCharacter = playerSideGeneralCharacter;
            customBattleData.SeasonId                   = this.MapSelectionGroup.SelectedSeasonId;
            customBattleData.SceneLevel                 = "";
            customBattleData.TimeOfDay                  = (float)this.MapSelectionGroup.SelectedTimeOfDay;
            if (customBattleData.GameType == CustomBattleGameType.Siege)
            {
                Dictionary <SiegeEngineType, int> machineCounts1 = new Dictionary <SiegeEngineType, int>();
                Dictionary <SiegeEngineType, int> machineCounts2 = new Dictionary <SiegeEngineType, int>();
                CustomBattleMenuVM.CustomBattleHelper.FillSiegeMachineCounts(machineCounts1, this._attackerMeleeMachines);
                CustomBattleMenuVM.CustomBattleHelper.FillSiegeMachineCounts(machineCounts1, this._attackerRangedMachines);
                CustomBattleMenuVM.CustomBattleHelper.FillSiegeMachineCounts(machineCounts2, this._defenderMachines);
                float[] hitpointPercentages = CustomBattleMenuVM.CustomBattleHelper.GetWallHitpointPercentages(this.MapSelectionGroup.SelectedWallBreachedCount);
                customBattleData.AttackerMachines        = machineCounts1;
                customBattleData.DefenderMachines        = machineCounts2;
                customBattleData.WallHitpointPercentages = hitpointPercentages;
                customBattleData.HasAnySiegeTower        = this._attackerMeleeMachines.Any <CustomBattleSiegeMachineVM>((Func <CustomBattleSiegeMachineVM, bool>)(mm => mm.SiegeEngineType == DefaultSiegeEngineTypes.SiegeTower));
                customBattleData.IsPlayerAttacker        = isPlayerAttacker;
                customBattleData.SceneUpgradeLevel       = this.MapSelectionGroup.SelectedSceneLevel;
                customBattleData.IsSallyOut     = this.MapSelectionGroup.IsSallyOutSelected;
                customBattleData.IsReliefAttack = false;
            }
            return(customBattleData);
        }
        private void UpdateSliders(int value, int changedSliderIndex)
        {
            this.updatingSliders = true;
            bool[] enabledArray = new bool[4]
            {
                !this.IsArmyComposition1Enabled,
                !this.IsArmyComposition2Enabled,
                !this.IsArmyComposition3Enabled,
                !this.IsArmyComposition4Enabled
            };
            int[] array = new int[4]
            {
                this._values[0],
                this._values[1],
                this._values[2],
                this._values[3]
            };
            int[] numArray = new int[4]
            {
                this._values[0],
                this._values[1],
                this._values[2],
                this._values[3]
            };
            int num1 = ((IEnumerable <bool>)enabledArray).Count <bool>((Func <bool, bool>)(s => s));

            if (enabledArray[changedSliderIndex])
            {
                --num1;
            }
            if (num1 > 0)
            {
                int num2 = ArmyCompositionGroupVM.SumOfValues(array, enabledArray);
                if (value >= num2)
                {
                    value = num2;
                }
                int num3 = value - array[changedSliderIndex];
                if (num3 != 0)
                {
                    int num4 = ArmyCompositionGroupVM.SumOfValues(array, enabledArray, changedSliderIndex);
                    int num5 = num4 - num3;
                    if (num5 > 0)
                    {
                        int num6 = 0;
                        numArray[changedSliderIndex] = value;
                        for (int index = 0; index < enabledArray.Length; ++index)
                        {
                            if (changedSliderIndex != index && enabledArray[index] && array[index] != 0)
                            {
                                int num7 = MathF.Round((float)array[index] / (float)num4 * (float)num5);
                                num6           += num7;
                                numArray[index] = num7;
                            }
                        }
                        int num8 = num5 - num6;
                        if (num8 != 0)
                        {
                            int num7 = 0;
                            for (int index = 0; index < enabledArray.Length; ++index)
                            {
                                if (enabledArray[index] && index != changedSliderIndex && (0 < array[index] + num8 && 100 > array[index] + num8))
                                {
                                    ++num7;
                                }
                            }
                            for (int index = 0; index < enabledArray.Length; ++index)
                            {
                                if (enabledArray[index] && index != changedSliderIndex && (0 < array[index] + num8 && 100 > array[index] + num8))
                                {
                                    int num9 = (int)Math.Round((double)num8 / (double)num7);
                                    numArray[index] += num9;
                                    num8            -= num9;
                                }
                            }
                            if (num8 != 0)
                            {
                                for (int index = 0; index < enabledArray.Length; ++index)
                                {
                                    if (enabledArray[index] && index != changedSliderIndex && (0 <= array[index] + num8 && 100 >= array[index] + num8))
                                    {
                                        numArray[index] += num8;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        numArray[changedSliderIndex] = value;
                        for (int index = 0; index < enabledArray.Length; ++index)
                        {
                            if (changedSliderIndex != index && enabledArray[index])
                            {
                                numArray[index] = 0;
                            }
                        }
                    }
                }
            }
            this.SetArmyCompositionValue(0, numArray[0]);
            this.SetArmyCompositionValue(1, numArray[1]);
            this.SetArmyCompositionValue(2, numArray[2]);
            this.SetArmyCompositionValue(3, numArray[3]);
            this.updatingSliders = false;
        }