Пример #1
0
 /// <summary> Cretes a new preset from the given list of vehicles. </summary>
 /// <param name="nation"> The preset's nation. </param>
 /// <param name="mainBranch"> The preset's main branch. </param>
 /// <param name="battleRating"> The preset's battle rating. </param>
 /// <param name="vehicleList"> The vehicle list to use for initialization. </param>
 public Preset(ENation nation, EBranch mainBranch, string battleRating, IList <IVehicle> vehicleList)
     : base(vehicleList)
 {
     Nation       = nation;
     MainBranch   = mainBranch;
     BattleRating = battleRating;
 }
Пример #2
0
        public IDictionary <string, VehicleUsage> GetVehicleUsage(EBranch branch)
        {
            if (!IsLoaded)
            {
                return(new Dictionary <string, VehicleUsage>());
            }

            switch (branch)
            {
            case EBranch.Army:
                return(GetVehicleUsage(_armyTableXPath));

            case EBranch.Helicopters:
                return(GetVehicleUsage(_helicopterTableXPath));

            case EBranch.Aviation:
                return(GetVehicleUsage(_aircraftTableXPath));

            case EBranch.AllFleet:
                return(GetVehicleUsage(_fleetTableXPath));

            default:
                return(new Dictionary <string, VehicleUsage>());
            }
        }
        /// <summary> Maintains branch selection when switching between nations, unless the branch is not implemented in which case selection is reset to the first available branch. </summary>
        /// <param name="sender"> Not used. </param>
        /// <param name="routedEventArguments"> Event arguments. <see cref="SelectionChangedEventArgs"/> are expected. </param>
        private void OnTabChange(object sender, RoutedEventArgs routedEventArguments)
        {
            if (routedEventArguments.OriginalSource is TabControl && routedEventArguments is SelectionChangedEventArgs selectionChangedEventArguments && selectionChangedEventArguments.AddedItems.OfType <TabItem>().First() is TabItem newTabItem)
            {
                if (newTabItem.Tag is ENation selectedNation)
                {
                    _currentNation = selectedNation;

                    if (_currentBranch.IsValid())
                    {
                        var nationControl = _nationControls[_currentNation];
                        var branchTab     = nationControl.BranchTabs[_currentBranch];

                        if (branchTab.IsEnabled)
                        {
                            nationControl.TabControl.SelectedItem = branchTab;
                        }
                        else
                        {
                            nationControl.TabControl.SelectedItem = nationControl.BranchTabs.Values.First(branch => branch.IsEnabled);
                        }
                    }
                }
                if (newTabItem.Tag is EBranch selectedBranch)
                {
                    _currentBranch = selectedBranch;
                }
            }
        }
Пример #4
0
 /// <summary> Cretes a new preset from the given list of vehicles. </summary>
 /// <param name="nation"> The preset's nation. </param>
 /// <param name="gameMode"> The preset's game mode. </param>
 /// <param name="mainBranch"> The preset's main branch. </param>
 /// <param name="economicRank"> The preset's <see cref="IVehicle.EconomicRank"/>. </param>
 /// <param name="battleRating"> The preset's battle rating. </param>
 /// <param name="vehicleList"> The vehicle list to use for initialisation. </param>
 public Preset(EGameMode gameMode, ENation nation, EBranch mainBranch, int economicRank, string battleRating, IList <IVehicle> vehicleList)
     : base(vehicleList)
 {
     GameMode     = gameMode;
     Nation       = nation;
     MainBranch   = mainBranch;
     EconomicRank = economicRank;
     BattleRating = battleRating;
     Branches     = this.Select(vehicle => vehicle.Branch).Distinct();
 }
 public static int GetSingleDigitCode(this EBranch branch)
 {
     return(branch switch
     {
         EBranch.Army => 1,
         EBranch.Helicopters => 2,
         EBranch.Aviation => 3,
         EBranch.BluewaterFleet => 4,
         EBranch.CoastalFleet => 5,
         _ => - 1,
     });
 /// <summary> Returns the enumeration item representing selection of all vehicle types under the given branch. </summary>
 /// <param name="branch"> The branch whose vehicle classes to get. </param>
 /// <returns></returns>
 public static EVehicleClass GetAllVehicleClassesItem(this EBranch branch) =>
 branch.CastTo <int>().CastTo <EVehicleClass>();
 /// <summary> Returns vehicle classes which belong to the branch. </summary>
 /// <param name="branch"> The branch whose vehicle classes to get. </param>
 /// <param name="selectOnlyValidItems"> Whether to select only valid items. </param>
 /// <returns></returns>
 public static IEnumerable <EVehicleClass> GetVehicleClasses(this EBranch branch, bool selectOnlyValidItems = true) =>
 typeof(EVehicleClass)
 .GetEnumerationItems <EVehicleClass>()
 .Where(vehicleClass => vehicleClass.GetBranch() == branch && (!selectOnlyValidItems || vehicleClass.IsValid()))
 ;
 /// <summary> Checks whether the branch is valid. </summary>
 /// <param name="branch"> The branch to check. </param>
 /// <returns></returns>
 public static bool IsValid(this EBranch branch) =>
 branch.EnumerationItemValueIsPositive();
 /// <summary> Initialises class properties. </summary>
 /// <param name="deserializedTags"> Vehicle tags deserialized from JSON data to select subclasses from. </param>
 /// <param name="vehiclePerformanceData"> Vehicle performance data to initialise this instance with. </param>
 /// <param name="branch"> The vehicle branch for which to select subclasses. </param>
 private void InitialiseProperties(VehicleTagsDeserializedFromJson deserializedTags, VehiclePerformanceData vehiclePerformanceData, EBranch branch)
 {
     if (branch == EBranch.Army)
     {
         IsWheeled = vehiclePerformanceData.MoveType.Contains("wheeled");
         CanScout  = deserializedTags.CanScout;
     }
     InitialiseIndex();
 }
 /// <summary> Creates a new filter specification with the given parameters. </summary>
 /// <param name="branch"> The branch. </param>
 /// <param name="vehicleClasses"> Vehicle classes in the branch. </param>
 public BranchSpecification(EBranch branch, IEnumerable <EVehicleClass> vehicleClasses)
 {
     Branch         = branch;
     VehicleClasses = vehicleClasses;
 }
        /// <summary> Selects valid economic ranks from <paramref name="enabledEconomicRanks"/> based on <paramref name="economicRanksWithVehicles"/></summary>
        /// <param name="enabledEconomicRanks"> Economic ranks enabled via GUI (as battle ratings). </param>
        /// <param name="economicRanksWithVehicles"> Economic ranks that have vehicles after application of previous filters. </param>
        /// <param name="getFormattedBattleRating"> A function to get a formatted battle rating from an economic rank. </param>
        /// <param name="nation"> The nation. </param>
        /// <param name="mainBranch"> The main branch. </param>
        /// <returns></returns>
        private IEnumerable <int> GetEconomicRanks(IEnumerable <int> enabledEconomicRanks, IEnumerable <int> economicRanksWithVehicles, Func <int, string> getFormattedBattleRating, ENation nation, EBranch mainBranch)
        {
            var validEconomicRanks = enabledEconomicRanks.Intersect(economicRanksWithVehicles);

            if (validEconomicRanks.IsEmpty())
            {
                var minimumBattleRating = getFormattedBattleRating(enabledEconomicRanks.Min());
                var maximumBattleRating = getFormattedBattleRating(enabledEconomicRanks.Max());

                LogWarn(EOrganizationLogMessage.NoVehiclesAvailableForSelectedBattleRatings.Format(minimumBattleRating, maximumBattleRating, mainBranch, nation));
                return(null);
            }
            return(validEconomicRanks);
        }
 /// <summary> Creates a new nation-branch pair. </summary>
 /// <param name="nation"> The nation. </param>
 /// <param name="branch"> The branch. </param>
 public NationBranchPair(ENation nation, EBranch branch)
 {
     Nation = nation;
     Branch = branch;
 }
 public static IEnumerable <EVehicleBranchTag> GetVehicleBranchTags(this EBranch branch, bool selectOnlyValidItems = true) =>
 typeof(EVehicleBranchTag)
 .GetEnumerationItems <EVehicleBranchTag>()
 .Where(vehicleClass => EVehicleBranchTagExtensions.GetBranch(vehicleClass) == branch && (!selectOnlyValidItems || vehicleClass.IsValid()));
Пример #14
0
 public BranchCountryPair(EBranch branch, ECountry country)
 {
     Branch  = branch;
     Country = country;
 }
 public BranchClassPair(EBranch branch, EVehicleClass vehicleClass)
 {
     Branch = branch;
     Class  = vehicleClass;
 }
Пример #16
0
 /// <summary> Checks whether the given <paramref name="branch"/> has any <see cref="EVehicleClass"/> items enabled or not. </summary>
 /// <param name="branch"> The branch to check. </param>
 /// <returns></returns>
 public bool BranchHasVehicleClassesEnabled(EBranch branch) =>
 EnabledVehicleClassesByBranches.TryGetValue(branch, out var vehicleClasses) && vehicleClasses.Any();
        /// <summary> Selects the nation specification from <paramref name="specification"/> based on previously selected <paramref name="mainBranch"/> and <paramref name="availableNations"/>. </summary>
        /// <param name="specification"> The search specification. </param>
        /// <param name="mainBranch"> The main vehicle branch. </param>
        /// <param name="availableNations"> Nations available after filtering with vehicle classes. </param>
        /// <returns></returns>
        private NationSpecification SelectNationSpecification(Specification specification, EBranch mainBranch, IEnumerable <ENation> availableNations)
        {
            var nationSpecificationsWithValidBranches = specification.NationSpecifications.Values.Where(nationSpecification => nationSpecification.Branches.Contains(mainBranch));

            if (nationSpecificationsWithValidBranches.IsEmpty())
            {
                LogWarn(EOrganizationLogMessage.NationsHaveNoBranch.Format(specification.NationSpecifications.Values.Select(nationSpecification => nationSpecification.Nation).StringJoin(ESeparator.CommaAndSpace), mainBranch));
                return(null);
            }

            var nationSpecification = _randomiser.GetRandom(nationSpecificationsWithValidBranches.Where(nationSpecification => nationSpecification.Nation.IsIn(availableNations)));

            if (nationSpecification is null)
            {
                LogWarn(EOrganizationLogMessage.NoVehiclesAvailableFor.Format(availableNations.StringJoin(ESeparator.CommaAndSpace)));
            }

            return(nationSpecification);
        }
Пример #18
0
 /// <summary> Displays a message that no vehicles suit the criteria with additional information. </summary>
 /// <param name="nation"> The nation. </param>
 /// <param name="mainBranch"> The branch. </param>
 public void ShowNoVehicles(ENation nation, EBranch mainBranch) => Owner.ShowNoVehicles(nation, mainBranch);
        /// <summary> Generates a vehicle type composition for a preset. </summary>
        /// <param name="gameMode"> The game mode to generate preset composition for. </param>
        /// <param name="allowedBranches"> Branches allowed in the composition. </param>
        /// <param name="crewSlotAmount"> The amount of available crew slots. </param>
        /// <param name="mainBranch"> The branch whose vehicles serve as the core of a preset. </param>
        /// <returns></returns>
        private IDictionary <EBranch, int> GetPresetComposition(EGameMode gameMode, IEnumerable <EBranch> allowedBranches, int crewSlotAmount, EBranch mainBranch)
        {
            var presetComposition = new Dictionary <EBranch, int>();

            void setAll(EBranch branch) => presetComposition.Add(branch, crewSlotAmount);
            void setQuarter(EBranch branch) => presetComposition.Add(branch, Convert.ToInt32(Math.Ceiling(crewSlotAmount * 0.25)));
            void setOneThird(EBranch branch) => presetComposition.Add(branch, Convert.ToInt32(Math.Ceiling(crewSlotAmount / 3.0)));
            void setTwoThirds(EBranch branch) => presetComposition.Add(branch, Convert.ToInt32(Math.Ceiling(crewSlotAmount * 2.0 / 3.0)));
            void setThreeQuarters(EBranch branch) => presetComposition.Add(branch, Convert.ToInt32(Math.Ceiling(crewSlotAmount * 0.75)));
            void setHalf(EBranch branch) => presetComposition.Add(branch, Convert.ToInt32(Math.Ceiling(crewSlotAmount * 0.5)));
            void setRemaining(EBranch branch, params EBranch[] otherBranches) => presetComposition.Add(branch, crewSlotAmount - otherBranches.Sum(branch => presetComposition[branch]));
Пример #20
0
 /// <summary> Focuses on a research tree by given parameters. </summary>
 /// <param name="nation"> The nation whose <paramref name="branch"/> to put into focus. </param>
 /// <param name="branch"> The branch to put into focus. </param>
 public void FocusResearchTree(ENation nation, EBranch branch) => Owner.FocusResearchTree(nation, branch);
Пример #21
0
 /// <summary> Initialises class properties. </summary>
 /// <param name="deserializedTags"> Vehicle tags deserialized from JSON data to select subclasses from. </param>
 /// <param name="branch"> The vehicle branch for which to select subclasses. </param>
 private void InitialiseProperties(VehicleTagsDeserializedFromJson deserializedTags, EBranch branch)
 {
     if (branch == EBranch.Aviation)
     {
         IsNavalAircraft = deserializedTags.IsNavalAircraft;
         IsHydroplane    = deserializedTags.IsHydroplane;
         IsTorpedoBomber = deserializedTags.CanCarryTorpedoes;
     }
     InitialiseIndex();
 }
 public static bool IsValid(this EBranch branch) =>
 branch.CastTo <int>() > EInteger.Number.Nine && !branch.ToString().StartsWith(EWord.All);