public async Task <FormattedEmbedBuilder> BuildForRoleAsync(LeagueRole role) { FormattedEmbedBuilder message = new FormattedEmbedBuilder(); try { await this.LoadFromApi(); if (LeagueRole.All.Equals(role)) { foreach (LeagueRole leagueRole in LeagueRole.Values()) { this.AppendStatsOfRole(leagueRole, 3, message); } } else { this.AppendStatsOfRole(role, 6, message); } message.AppendTitle($"{XayahReaction.Clipboard} Winrates"); ChampionStatsDto first = this._championStats.ElementAtOrDefault(0); if (first != null) { message.AppendTitle($" for Patch {first.Patch}"); } message.AppendDescription("Short explanation of the table: `Position - Win % - Play %` - Name", AppendOption.Italic); } catch (NoApiResultException) { message = new FormattedEmbedBuilder() .AppendTitle($"{XayahReaction.Error} This didn't work") .AppendDescription("Apparently some random API refuses cooperation. Have some patience while I convince them again..."); } return(message); }
private string BuildChampionStats(ChampionStatsDto championStats, int position) { ChampionDto champion = this._championList.FirstOrDefault(x => x.Id.Equals(championStats.ChampionId)); if (champion != null) { return($"`{position.ToString("00", CultureInfo.InvariantCulture)} - {this.FormatPercentage(championStats.WinRate)} - " + $"{this.FormatPercentage(championStats.PlayRate)}` - {champion.Name}"); } return(string.Empty); }
private void AppendStatsOfRole(LeagueRole role, int entryCount, FormattedEmbedBuilder message) { List <ChampionStatsDto> roleStats = this._championStats.Where(x => x.Role.Equals(role.ApiRole)).ToList(); if (entryCount * 2 > roleStats.Count) { entryCount = (int)Math.Truncate(roleStats.Count / (decimal)2); } FormattedTextBuilder winrates = new FormattedTextBuilder(); for (int i = 0; i < entryCount && i < roleStats.Count; i++) { ChampionStatsDto topX = roleStats.ElementAt(i); string championLine = this.BuildChampionStats(topX, i + 1); if (i > 0) { winrates.AppendNewLine(); } winrates.Append(championLine); } if (roleStats.Count > entryCount * 2) { winrates.AppendNewLine(); } for (int i = roleStats.Count - entryCount; i >= 0 && i < roleStats.Count; i++) { ChampionStatsDto bottomX = roleStats.ElementAt(i); string championLine = this.BuildChampionStats(bottomX, i + 1); winrates.AppendNewLine().Append(championLine); } string resultText = winrates.ToString(); if (string.IsNullOrWhiteSpace(resultText)) { resultText = ". . ."; } message.AddField(role.Name, resultText, new AppendOption[] { AppendOption.Underscore }); }
internal ChampionStatistics(ChampionStatsDto dto) { HP = dto.Hp; HPRegeneration = dto.HpRegen; HPPerLevel = dto.HpPerLevel; HPRegenerationPerLevel = dto.HpRegenPerLevel; MP = dto.Mp; MPRegeneration = dto.MpRegen; MPPerLevel = dto.MpPerLevel; MPRegenerationPerLevel = dto.MpRegenPerLevel; MovementSpeed = dto.MoveSpeed; Armor = dto.Armor; ArmorPerLevel = dto.ArmorPerLevel; MagicResistance = dto.SpellBlock; MagicResistancePerLevel = dto.SpellBlockPerLevel; AttackRange = dto.AttackRange; CriticalRate = dto.Crit; CriticalRatePerLevel = dto.CritPerLevel; AttackDamage = dto.AttackDamage; AttackDamagePerLevel = dto.AttackDamagePerLevel; AttackSpeed = dto.AttackSpeed; AttackSpeedPerLevel = dto.AttackSpeedPerLevel; }