Example #1
0
        // GET: Match
        public MatchlistDTO Get(string summonerId)
        {
            Match_V4 match_V4 = new Match_V4();
            var      match    = match_V4.GetMatchlistById(summonerId);

            return(match);
        }
Example #2
0
        // GET: MatchId
        public MatchDTO Get(long matchId)
        {
            Match_V4 match_V4 = new Match_V4();
            var      match    = match_V4.GetMatchListByMatchId(matchId);

            return(match);
        }
Example #3
0
        // Pego os historicos de partida
        private MatchDTO GetMatch(SummonerDTO summoner)
        {
            Match_V4 matchs   = new Match_V4(Constants.Region);
            var      mhistory = matchs.GetMatchHistoryByAccount(summoner.accountId, Constants.CurrentyChampionId);

            return(mhistory ?? new MatchDTO());
        }
Example #4
0
        public IActionResult ShowMore()
        {
            Summoner summ       = HttpContext.Session.GetSummoner();
            Summoner summoner   = _context.Summoners.Where(s => s.Id == summ.Id).FirstOrDefault();
            int?     matchIndex = HttpContext.Session.GetInt32("matchIndex");

            if (summoner == null)
            {
                return(RedirectToAction("Index"));
            }
            if (matchIndex == null)
            {
                matchIndex = 5;
            }


            // Get match list from DB
            MatchesResponse matches = _context.MatchesResponses.Where(r => r.SummonerID == summoner.Id).FirstOrDefault();

            matches.Matches = _context.Matches.Where(m => m.MatchesResponseID == matches.MatchesResponseID).OrderByDescending(m => m.Timestamp).ToList();

            // Setup new match list
            Match_V4        matchv4    = new Match_V4(summoner.Region);
            MatchesResponse newMatches = matchv4.GetMoreMatchesByAccountID(summoner.AccountId, (int)matchIndex);

            foreach (Matches match in newMatches.Matches)
            {
                MatchDTO matchDTO = matchv4.GetMatchByMatchID(match.GameID);
                MatchDB  matchDB  = matchDTO.ConvertMatchDTOToDBv2(_context);
                matchDB = _context.MatchesDB.Where(m => m.GameID == matchDB.GameID).FirstOrDefault();
                match.MatchesResponseID = matches.MatchesResponseID;
                match.MatchDB           = matchDB;
                matches.Matches.Add(match);
                foreach (PlayerInfoDB p in matchDB.PlayerInfos)
                {
                    if (p.SummonerID == summoner.Id)
                    {
                        summoner.Kills   += p.Kills;
                        summoner.Deaths  += p.Deaths;
                        summoner.Assists += p.Assists;
                    }
                }
            }
            summoner.KDA = ((summoner.Kills + summoner.Assists) / (float)Math.Max(summoner.Deaths, 1));
            _context.Summoners.Update(summoner);
            _context.SaveChanges();
            FindModel fm = new FindModel {
                Name = summoner.Name, Region = summoner.Region
            };

            return(RedirectToAction("Profile", fm));
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Summoner_V4 summoner_V4 = new Summoner_V4("BR1");

            var summoner = summoner_V4.GetSummonerByName(SummonerName.Text);

            Match_V4 match_V4 = new Match_V4("BR1");

//            var seila = match_V4.GetMatchByMatchId(1726239613);

            var position = GetPosition(summoner);

            var ChampMastery = new Champion_Mastery_V4("BR1");

            var championMasteryDTOs = ChampMastery.GetChampMasteryList(summoner.Id);

            var championsList = new ChampionsList.ChampionsList();

            lblTier.Content = String.Format("{0} {1}", position.Tier, position.Rank);

            var status = String.Format("{0} LP / {1}W {2}L", position.leaguePoints, position.Wins, position.Losses);

            float total = (position.Wins + position.Losses);

            int percentwin = Convert.ToInt32((position.Wins / total) * 100);

            lblPercentWin.Content = String.Format("Taxa de Vitória {0}%", percentwin);

            lblStatus.Content = status;

            lblName.Content = summoner.Name;

            var webBorder = new BitmapImage(new Uri("https://opgg-static.akamaized.net/images/borders2/" + position.Tier.ToLower() + ".png"));

            imgBorder.Source = webBorder;

            TierIcon.Source = new BitmapImage(new Uri(Environment.CurrentDirectory + "/TierIcons/" + position.Tier + ".png"));

            var webTier = new BitmapImage(new Uri("https://opgg-static.akamaized.net/images/profile_icons/profileIcon" + summoner.ProfileIconId + ".jpg"));

            ProfileIcon.Source = webTier;

            var webChampIcon1   = new BitmapImage(new Uri("https://opgg-static.akamaized.net/images/lol/champion/" + championsList.GetValue(championMasteryDTOs[0].championId) + ".png?image=w_45&v=1"));
            var webMasteryIcon1 = new BitmapImage(new Uri("https://www.masterypoints.com/assets/img/lol/mastery_icons/master" + championMasteryDTOs[0].championLevel + ".png?v=v8"));

            lblNameChamp1.Content     = championsList.GetValue(championMasteryDTOs[0].championId);
            lblMastery1.Content       = String.Format("Maestria {0}", championMasteryDTOs[0].championLevel);
            lblMasteryPoints1.Content = String.Format("{0} MP", championMasteryDTOs[0].championPoints);
            ChampIcon1.ImageSource    = webChampIcon1;
            MasteryIcon1.ImageSource  = webMasteryIcon1;

            var webChampIcon2   = new BitmapImage(new Uri("https://opgg-static.akamaized.net/images/lol/champion/" + championsList.GetValue(championMasteryDTOs[1].championId) + ".png?image=w_45&v=1"));
            var webMasteryIcon2 = new BitmapImage(new Uri("https://www.masterypoints.com/assets/img/lol/mastery_icons/master" + championMasteryDTOs[1].championLevel + ".png?v=v8"));

            lblNameChamp2.Content     = championsList.GetValue(championMasteryDTOs[1].championId);
            lblMastery2.Content       = String.Format("Maestria {0}", championMasteryDTOs[1].championLevel);
            lblMasteryPoints2.Content = String.Format("{0} MP", championMasteryDTOs[1].championPoints);
            ChampIcon2.ImageSource    = webChampIcon2;
            MasteryIcon2.ImageSource  = webMasteryIcon2;

            var webChampIcon3   = new BitmapImage(new Uri("https://opgg-static.akamaized.net/images/lol/champion/" + championsList.GetValue(championMasteryDTOs[2].championId) + ".png?image=w_45&v=1"));
            var webMasteryIcon3 = new BitmapImage(new Uri("https://www.masterypoints.com/assets/img/lol/mastery_icons/master" + championMasteryDTOs[2].championLevel + ".png?v=v8"));

            lblNameChamp3.Content     = championsList.GetValue(championMasteryDTOs[2].championId);
            lblMastery3.Content       = String.Format("Maestria {0}", championMasteryDTOs[2].championLevel);
            lblMasteryPoints3.Content = String.Format("{0} MP", championMasteryDTOs[2].championPoints);
            ChampIcon3.ImageSource    = webChampIcon3;
            MasteryIcon3.ImageSource  = webMasteryIcon3;

            var webChampIcon4   = new BitmapImage(new Uri("https://opgg-static.akamaized.net/images/lol/champion/" + championsList.GetValue(championMasteryDTOs[3].championId) + ".png?image=w_45&v=1"));
            var webMasteryIcon4 = new BitmapImage(new Uri("https://www.masterypoints.com/assets/img/lol/mastery_icons/master" + championMasteryDTOs[3].championLevel + ".png?v=v8"));

            lblNameChamp4.Content     = championsList.GetValue(championMasteryDTOs[3].championId);
            lblMastery4.Content       = String.Format("Maestria {0}", championMasteryDTOs[3].championLevel);
            lblMasteryPoints4.Content = String.Format("{0} MP", championMasteryDTOs[3].championPoints);
            ChampIcon4.ImageSource    = webChampIcon4;
            MasteryIcon4.ImageSource  = webMasteryIcon4;

            var webChampIcon5   = new BitmapImage(new Uri("https://opgg-static.akamaized.net/images/lol/champion/" + championsList.GetValue(championMasteryDTOs[4].championId) + ".png?image=w_45&v=1"));
            var webMasteryIcon5 = new BitmapImage(new Uri("https://www.masterypoints.com/assets/img/lol/mastery_icons/master" + championMasteryDTOs[4].championLevel + ".png?v=v8"));

            lblNameChamp5.Content     = championsList.GetValue(championMasteryDTOs[4].championId);
            lblMastery5.Content       = String.Format("Maestria {0}", championMasteryDTOs[4].championLevel);
            lblMasteryPoints5.Content = String.Format("{0} MP", championMasteryDTOs[4].championPoints);
            ChampIcon5.ImageSource    = webChampIcon5;
            MasteryIcon5.ImageSource  = webMasteryIcon5;
        }
Example #6
0
        public IActionResult Profile(FindModel fm)
        {
            // TODO: Add option to select region
            // Currently just using NA region, since that's what I am on.

            Champion_Mastery_V4 championMastery = new Champion_Mastery_V4("na1");
            Match_V4            matchv4         = new Match_V4("na1");


            // Get summoner info
            Summoner summoner = _context.Summoners.Where(s => s.Name == fm.Name).SingleOrDefault();

            if (summoner == null)
            {
                Summoner_V4 summonerv4 = new Summoner_V4("na1");
                summoner        = summonerv4.GetSummonerByName(fm.Name);
                summoner.Region = fm.Region;
                _context.Summoners.Add(summoner);
                _context.SaveChanges();
                summoner = _context.Summoners.Where(s => s.Name == fm.Name).SingleOrDefault();
            }
            // Get list of masteries by summoner id
            List <ChampionMastery> masteries = championMastery.GetChampionMasteryById(summoner.Id);
            // List will be top 3 champs by mastery
            ChampionInfo list = new ChampionInfo();

            // Get top 3 champs by mastery
            for (int i = 0; i < 3; i++)
            {
                foreach (KeyValuePair <string, Champion> champ in _allChamps.Data)
                {
                    if (champ.Value.Key == masteries[i].ChampionID.ToString())
                    {
                        champ.Value.Rank = i;
                        list.Champions.Add(champ.Key, champ.Value);
                        break;
                    }
                }
            }
            // Get matchlist by account id
            MatchesResponse matches = _context.MatchesResponses.Where(r => r.SummonerID == summoner.Id).FirstOrDefault();

            if (matches == null)
            {
                int k, d, a;
                k                  = d = a = 0;
                matches            = matchv4.GetMatchesByAccountID(summoner.AccountId);
                matches.SummonerID = summoner.Id;
                foreach (Matches match in matches.Matches)
                {
                    MatchDB matchDB = _context.MatchesDB.Where(m => m.GameID == long.Parse(match.GameID)).FirstOrDefault();
                    if (matchDB == null)
                    {
                        MatchDTO matchDTO = matchv4.GetMatchByMatchID(match.GameID);
                        matchDB = matchDTO.ConvertMatchDTOToDBv2(_context);
                    }
                    else
                    {
                        matchDB.PlayerInfos = _context.PlayerInfoDBs.Where(p => p.GameID == matchDB.GameID).OrderBy(p => p.ParticipantID).ToList();
                        matchDB.Teams       = _context.TeamStatsDBs.Where(t => t.GameID == matchDB.GameID).OrderBy(t => t.TeamID).ToList();
                    }

                    match.MatchDB = matchDB;
                    foreach (PlayerInfoDB p in matchDB.PlayerInfos)
                    {
                        if (p.SummonerID == summoner.Id)
                        {
                            k += p.Kills;
                            d += p.Deaths;
                            a += p.Assists;
                        }
                    }
                }
                summoner.Kills   = k;
                summoner.Deaths  = d;
                summoner.Assists = a;
                summoner.KDA     = ((k + a) / (float)d);
                _context.Summoners.Update(summoner);
                _context.MatchesResponses.Add(matches);
                _context.SaveChanges();
            }
            else
            {
                matches.Matches = _context.Matches.Where(m => m.MatchesResponseID == matches.MatchesResponseID).OrderByDescending(m => m.Timestamp).ToList();
                foreach (Matches match in matches.Matches)
                {
                    MatchDB matchDB = _context.MatchesDB.Where(m => m.GameID == long.Parse(match.GameID)).FirstOrDefault();
                    matchDB.Teams       = _context.TeamStatsDBs.Where(t => t.GameID == matchDB.GameID).OrderBy(t => t.TeamID).ToList();
                    matchDB.PlayerInfos = _context.PlayerInfoDBs.Where(p => p.GameID == matchDB.GameID).OrderBy(p => p.ParticipantID).ToList();

                    match.MatchDB = matchDB;
                }
            }

            Dictionary <int, string> championIDs = new Dictionary <int, string>();

            foreach (Champion c in _allChamps.Data.Values)
            {
                championIDs.Add(int.Parse(c.Key), c.Id);
            }
            ViewModelProfile viewModel = new ViewModelProfile {
                Summoner    = summoner,
                Masteries   = masteries,
                ChampionIDs = championIDs,
                Info        = list,
                Matchlist   = matches
            };

            HttpContext.Session.SetInt32("matchIndex", matches.Matches.Count);
            HttpContext.Session.SetSummoner(summoner);
            return(View(viewModel));
        }