示例#1
0
        private void LoadLeagueNames()
        {
            // Get all main league from API, loop through array containing
            // league ID's and add them to comboBox

            var leagueDataResult = ApiDataHandler.GetLeagueData();

            leagueName_comboBox.Items.Clear();

            for (int i = 0; i < leagueDataResult.Count; i++)
            {
                leagueName_comboBox.Items.Add(leagueDataResult[i].Id);
            }
        }
示例#2
0
        private void GetDataButton_Click(object sender, RoutedEventArgs e)
        {
            // Get data from Player IGN textBox
            string playerIGN = playerIGN_textbox.Text;

            // Get data from Player league comboBox
            string leagueName = Convert.ToString(leagueName_comboBox.SelectedItem);

            if (string.IsNullOrWhiteSpace(playerIGN) || playerIGN.StartsWith(" "))
            {
                MessageBox.Show("Please check your Player IGN");
            }
            else if (string.IsNullOrWhiteSpace(leagueName))
            {
                MessageBox.Show("Please check your League field");
            }
            else
            {
                // Adding player characters to clear comboBox
                playerCharacters_comboBox.Items.Clear();

                var currentPlayer = ApiDataHandler.GetPlayerData(playerIGN, leagueName);
                for (int i = 0; i < currentPlayer.Entries.Count(); i++)
                {
                    if (currentPlayer.Entries[i].Dead == true)
                    {
                        playerCharacters_comboBox.Items.Add($"{currentPlayer.Entries[i].Character.Name} ({currentPlayer.Entries[i].Character.Class}) DEAD");
                    }
                    else
                    {
                        playerCharacters_comboBox.Items.Add($"{currentPlayer.Entries[i].Character.Name} ({currentPlayer.Entries[i].Character.Class})");
                    }
                }

                // After receiving player characters, allow user to select character and start tracking

                playerCharacters_comboBox.IsEnabled = true;
                startTrackingButton.IsEnabled       = true;
            }
        }
示例#3
0
        public void ProcessData(string _playerIGN, string _leagueName, int _playerCharacter)
        {
            // API request
            var currentPlayer = ApiDataHandler.GetPlayerData(_playerIGN, _leagueName);

            // Player class
            string playerClass = currentPlayer.Entries[_playerCharacter].Character.Class;

            // Player selected character
            string playerCharacter = currentPlayer.Entries[_playerCharacter].Character.Name;

            // Player league
            string playerLeague = _leagueName;

            // Player global rank
            int playerGlobalRank = currentPlayer.Entries[_playerCharacter].Rank;

            // Player class rank
            const int maxLimit        = 200;
            int       _offset         = 0;
            int       playerClassRank = 0;

            //// Checking players class above selected player, if they are playing same class , add it to counter (playerClassRank)

            //void checkPlayerClassRank(int globalRank)
            //{
            //    if (globalRank <= maxLimit)
            //    {
            //        var playersAbove = ApiDataHandler.GetPlayersAboveData(playerLeague, globalRank, _offset);

            //        for (int i = 0; i < globalRank; i++)
            //        {
            //            if (playersAbove.Entries[i].Character.Class == currentPlayer.Entries[_playerCharacter].Character.Class)
            //            {
            //                playerClassRank++;
            //            }
            //        }
            //    }
            //    else if (globalRank > maxLimit)
            //    {
            //        var playersAbove = ApiDataHandler.GetPlayersAboveData(playerLeague, maxLimit, _offset);
            //        _offset += 200;
            //        globalRank -= 200;

            //        for (int i = 0; i < 200; i++)
            //        {
            //            if (playersAbove.Entries[i].Character.Class == currentPlayer.Entries[_playerCharacter].Character.Class)
            //            {
            //                playerClassRank++;
            //            }
            //        }

            //        checkPlayerClassRank(globalRank);
            //    }
            //}

            //checkPlayerClassRank(playerGlobalRank);

            // Player level
            int playerLevel = currentPlayer.Entries[_playerCharacter].Character.Level;

            // Player experience
            double playerExperience = currentPlayer.Entries[_playerCharacter].Character.Experience;

            //Player % exp , rounded to two decimal places
            double gainedExp, expToGain, playerPercentageExperience;

            if (playerLevel != 100)
            {
                gainedExp = playerExperience - ExperienceTable.level[playerLevel - 1];
                expToGain = ExperienceTable.level[playerLevel] - ExperienceTable.level[playerLevel - 1];

                playerPercentageExperience = Math.Round(gainedExp * 100 / expToGain, 2);
            }
            else
            {
                playerPercentageExperience = 100;
            }

            // Player exp compared to player above/behind
            // Calculating player offset -> 1.playerAbove 2.currentPlayer 3.playerBehind
            // Subtracting currentPlayer exp from player above/behind
            int offset;

            switch (currentPlayer.Entries[_playerCharacter].Rank)
            {
            case 1:
            case 2:
                offset = 0;
                break;

            case 3:
                offset = 1;
                break;

            default:
                offset = currentPlayer.Entries[_playerCharacter].Rank - 2;
                break;
            }

            var playerBehindAndAbove = ApiDataHandler.GetDataOfPlayerAboveAndBehind(_leagueName, offset);

            // If player rank equals one there is only player behind, it means that entries will contain only two object instead of default 3.
            double playerBehindExp;

            // SelectedPlayer[0] -> PlayerBehind[1]

            if (playerGlobalRank == 1)
            {
                playerBehindExp = playerExperience - playerBehindAndAbove.Entries[1].Character.Experience;
            }

            // PlayerAbove[0] -> SelectedPlayer[1] -> PlayerBehind[2]

            else
            {
                playerBehindExp = playerExperience - playerBehindAndAbove.Entries[2].Character.Experience;
            }

            // Set playerAboveExp to 0 if player rank equals 1 because there's no player above.
            double playerAboveExp;

            if (currentPlayer.Entries[_playerCharacter].Rank == 1)
            {
                playerAboveExp = 0;
            }
            else
            {
                playerAboveExp = currentPlayer.Entries[_playerCharacter].Character.Experience - playerBehindAndAbove.Entries[0].Character.Experience;
            }

            TrackerInterface trackerInterface = new TrackerInterface
                                                (
                playerClass,
                playerCharacter,
                playerLeague,
                playerGlobalRank,
                playerClassRank,
                playerLevel,
                playerExperience,
                playerPercentageExperience,
                playerAboveExp,
                playerBehindExp
                                                );

            trackerInterface.Show();
        }