Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ArenaHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<DependentUpon>ValueOverlay.xaml</DependentUpon>
</Compile>
<Compile Include="Detection.cs" />
<Compile Include="HeroWinRate.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="Plugins.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
62 changes: 62 additions & 0 deletions HeroWinRate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Linq;

namespace ArenaHelper
{
/// <summary>
/// Provides hero win rate information in arena mode. Information is requesting from HSReplay
/// </summary>
public class HeroWinRate
{
private const string HSReplyPerformanceSummaryUrl = "https://hsreplay.net/api/v1/analytics/query/player_class_performance_summary";
private const int ArenaGameType = 3;

private Dictionary<string, double> heroWinRateDictionary;

/// <summary>
/// Search for win rate by hero class
/// </summary>
/// <param name="heroClass">Hero class</param>
/// <returns>Win rate of specified hero</returns>
public string GetWinRateAsString(string heroClass)
{
if (heroWinRateDictionary == null)
{
FillWinRateDictionary();
}

return string.Format("{0:0.0}%", heroWinRateDictionary[heroClass.ToLower()]);
}

private void FillWinRateDictionary()
{
WebRequest request = WebRequest.Create(HSReplyPerformanceSummaryUrl);

using (WebResponse response = request.GetResponse())
{
if ((response as HttpWebResponse).StatusCode != HttpStatusCode.OK)
{
throw new System.Exception("Can't get information about hero win rate");
}

using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
string responseBody = reader.ReadToEnd();
dynamic responseObject = JObject.Parse(responseBody);

heroWinRateDictionary = new Dictionary<string, double>();
foreach (var heroWinRateDataPair in responseObject.series.data)
{
JArray winRateData = heroWinRateDataPair.Value;
dynamic arenaWinRateData = winRateData.First(data => (data as dynamic).game_type == ArenaGameType);
JValue winRate = arenaWinRateData.win_rate;
heroWinRateDictionary[heroWinRateDataPair.Name.ToLower()] = (double)winRate.Value;
}
}
}
}
}
}
10 changes: 5 additions & 5 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.IO;
Expand All @@ -14,11 +13,8 @@
using System.Diagnostics;
using System.Threading;
using Newtonsoft.Json;
using System.Runtime.InteropServices;
using MahApps.Metro.Controls.Dialogs;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Converters;
using Hearthstone_Deck_Tracker.Utility;
using Hearthstone_Deck_Tracker.Utility.Logging;
using HearthMirror;

Expand Down Expand Up @@ -1148,7 +1144,7 @@ private void SetState(PluginState newstate)
}
else if (newstate == PluginState.SearchBigHero)
{
ShowOverlay(false);
ShowOverlay(true);
arenawindow.DetectedHeroesWarning.Text = "";
arenawindow.DetectingPanel.Visibility = System.Windows.Visibility.Hidden;
arenawindow.ConfigureHeroPanel.Visibility = System.Windows.Visibility.Hidden;
Expand Down Expand Up @@ -1916,9 +1912,13 @@ private void UpdateDetectedHeroes()
return;

// All heroes detected, show them
var heroWinRate = new HeroWinRate();
SetHeroControl(arenawindow.Hero0, arenadata.detectedheroes[0]);
SetValueText(0, heroWinRate.GetWinRateAsString(arenadata.detectedheroes[0]));
SetHeroControl(arenawindow.Hero1, arenadata.detectedheroes[1]);
SetValueText(1, heroWinRate.GetWinRateAsString(arenadata.detectedheroes[1]));
SetHeroControl(arenawindow.Hero2, arenadata.detectedheroes[2]);
SetValueText(2, heroWinRate.GetWinRateAsString(arenadata.detectedheroes[2]));

// Update window
arenawindow.Update();
Expand Down