コード例 #1
0
        private RiotSharp.Region ConvertRegion(Region region)
        {
            Guard.NotInvalidEnum(region, nameof(region));

            return this._regionMapping[region];
        }
コード例 #2
0
        private Participant ConvertParticipant(RiotSharp.CurrentGameEndpoint.Participant participant, Region region)
        {
            Guard.NotNull(participant, nameof(participant));
            Guard.NotInvalidEnum(region, nameof(region));

            return new Participant
            {
                IsBot = participant.Bot,
                SummonerId = participant.SummonerId,
                ProfileIconId = (int)participant.ProfileIconId,
                SummonerName = participant.SummonerName,
                ChampionId = participant.ChampionId,
                ChampionName = this.GetChampionList(region).Champions.FirstOrDefault(f => f.Value.Id == participant.ChampionId).Value?.Name,
                SummonerSpell1Id = participant.SummonuerSpell1,
                SummonerSpell1Name = this.GetSummonerSpells(region).SummonerSpells.FirstOrDefault(f => f.Value.Id == participant.SummonuerSpell1).Value?.Name,
                SummonerSpell2Id = participant.SummonerSpell2,
                SummonerSpell2Name = this.GetSummonerSpells(region).SummonerSpells.FirstOrDefault(f => f.Value.Id == participant.SummonerSpell2).Value?.Name,
            };
        }
コード例 #3
0
        private Platform ConvertRegionToPlatform(Region region)
        {
            Guard.NotInvalidEnum(region, nameof(region));

            return this._regionToPlatformMapping[region];
        }
コード例 #4
0
        private CurrentGame ConvertCurrentGame(RiotSharp.CurrentGameEndpoint.CurrentGame currentGame, Region region)
        {
            Guard.NotNull(currentGame, nameof(currentGame));
            Guard.NotInvalidEnum(region, nameof(region));

            return new CurrentGame
            {
                GameId = currentGame.GameId,
                GameQueueType = this.ConvertGameQueueType(currentGame.GameQueueType),
                GameType = this.ConvertGameType(currentGame.GameType),
                GameStartTime = currentGame.GameStartTime,
                BlueTeam = new Team
                {
                    Participants = currentGame.Participants
                        .Where(f => f.TeamId == 100)
                        .Select(f => this.ConvertParticipant(f, region))
                        .ToList(),
                    BannedChampions = currentGame.BannedChampions
                        .Where(f => f.TeamId == 100)
                        .Select(f => this.ConvertBannedChampion(f, region))
                        .ToList()
                },
                PurpleTeam = new Team
                {
                    Participants = currentGame.Participants
                        .Where(f => f.TeamId == 200)
                        .Select(f => this.ConvertParticipant(f, region))
                        .ToList(),
                    BannedChampions = currentGame.BannedChampions
                        .Where(f => f.TeamId == 200)
                        .Select(f => this.ConvertBannedChampion(f, region))
                        .ToList()
                },
                GameMode = this.ConvertGameMode(currentGame.GameMode),
                MapType = this.ConvertMapType(currentGame.MapType),
                Region = region
            };
        }
コード例 #5
0
        private BannedChampion ConvertBannedChampion(RiotSharp.CurrentGameEndpoint.BannedChampion bannedChampion, Region region)
        {
            Guard.NotNull(bannedChampion, nameof(bannedChampion));
            Guard.NotInvalidEnum(region, nameof(region));

            return new BannedChampion
            {
                ChampionId = bannedChampion.ChampionId,
                ChampionName = this.GetChampionList(region).Champions.FirstOrDefault(f => f.Value.Id == bannedChampion.ChampionId).Value?.Name,
                PickTurn = bannedChampion.PickTurn
            };
        }
コード例 #6
0
        private ChampionListStatic GetChampionList(Region region)
        {
            Guard.NotInvalidEnum(region, nameof(region));

            return this._cachedChampions.GetOrAdd(region, f => this._staticApi.GetChampions(this.ConvertRegion(f), ChampionData.info));
        }
コード例 #7
0
        private SummonerSpellListStatic GetSummonerSpells(Region region)
        {
            Guard.NotInvalidEnum(region, nameof(region));

            return this._cachedSummonerSpells.GetOrAdd(region, f => this._staticApi.GetSummonerSpells(this.ConvertRegion(f), SummonerSpellData.image));
        }
コード例 #8
0
        public async Task<PlayedMatch> GetMatch(Region region, long matchId)
        {
            Guard.NotInvalidEnum(region, nameof(region));
            Guard.NotZeroOrNegative(matchId , nameof(matchId));

            MatchDetail match = await this._api.GetMatchAsync(this.ConvertRegion(region), matchId, includeTimeline: true);
            return this.ConvertPlayedMatch(match);
        }
コード例 #9
0
        public async Task<List<long>>  GetMatchHistory(Region region, long summonerId, DateTime? latestCheckedMatchTimeStamp)
        {
            Guard.NotInvalidEnum(region, nameof(region));
            Guard.NotZeroOrNegative(summonerId, nameof(summonerId));

            latestCheckedMatchTimeStamp = latestCheckedMatchTimeStamp?.AddSeconds(1);

            var matchList = await this._api.GetMatchListAsync(
                this.ConvertRegion(region),
                summonerId,
                seasons: new List<Season>() {Season.Season2016},
                beginTime: latestCheckedMatchTimeStamp);

            if (matchList.Matches == null)
                return new List<long>();

            return matchList.Matches
                .Select(f => f.MatchID)
                .OrderBy(f => f)
                .ToList();
        }
コード例 #10
0
        public async Task<CurrentGame> GetCurrentGameAsync(Region region, long riotSummonerId)
        {
            Guard.NotInvalidEnum(region, nameof(region));
            Guard.NotZeroOrNegative(riotSummonerId, nameof(riotSummonerId));

            try
            {
                var result = await this._api.GetCurrentGameAsync(this.ConvertRegionToPlatform(region), riotSummonerId);

                if (result == null)
                    return null;

                return this.ConvertCurrentGame(result, region);
            }
            catch (RiotSharpException e) when (e.Message.StartsWith("404"))
            {
                return null;
            }
        }
コード例 #11
0
        public async Task<IList<Summoner>> GetSummonersAsync(Region region, IList<long> riotSummonerIds)
        {
            Guard.NotInvalidEnum(region, nameof(region));
            Guard.NotNullOrEmpty(riotSummonerIds, nameof(riotSummonerIds));

            var summoners = await this._api.GetSummonersAsync(this.ConvertRegion(region), riotSummonerIds.Select(f => (int)f).ToList());
            return summoners.Select(this.ConvertSummoner).ToList();
        }
コード例 #12
0
        public async Task<Summoner> GetSummonerAsync(Region region, string name)
        {
            Guard.NotInvalidEnum(region, nameof(region));
            Guard.NotNullOrWhiteSpace(name, nameof(name));

            try
            {
                var result = await this._api.GetSummonerAsync(this.ConvertRegion(region), name);

                if (result == null)
                    return null;

                return this.ConvertSummoner(result);
            }
            catch (RiotSharpException e) when (e.Message.StartsWith("404"))
            {
                return null;
            }
        }