Skip to content

Commit

Permalink
fix compnsating for the Transformed Cards are marked as Gift bug
Browse files Browse the repository at this point in the history
  • Loading branch information
icetbr committed Jan 11, 2021
1 parent 080c430 commit b17186f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
32 changes: 24 additions & 8 deletions Advisor/Advisor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
Expand All @@ -17,6 +17,7 @@
using Hearthstone_Deck_Tracker.Utility.Logging;
using MahApps.Metro.Controls;
using CoreAPI = Hearthstone_Deck_Tracker.API.Core;
using Newtonsoft.Json;

namespace HDT.Plugins.Advisor
{
Expand All @@ -26,6 +27,7 @@ internal class Advisor
private static Flyout _notificationFlyout;
private readonly AdvisorOverlay _advisorOverlay;
private Guid _currentArchetypeDeckGuid;
private IList<Card> opponentCardList;

public Advisor(AdvisorOverlay overlay)
{
Expand Down Expand Up @@ -141,6 +143,7 @@ internal async void GameStart()
_advisorOverlay.Update(new List<Card>(), true);
_currentArchetypeDeckGuid = Guid.Empty;

opponentCardList = new List<Card>();
UpdateCardList();
_advisorOverlay.Show();
}
Expand Down Expand Up @@ -210,7 +213,20 @@ internal async void UpdateCardList()
}

// Get opponent's cards list (all yet revealed cards)
IList<Card> opponentCardlist = Core.Game.Opponent.OpponentCardList.Where(x => !x.IsCreated).ToList();
IList<Card> newOpponentCardlist = Core.Game.Opponent.OpponentCardList.Where(x => !x.IsCreated).ToList();
foreach (var card in newOpponentCardlist)
{
if (!opponentCardList.Contains(card))
{
opponentCardList.Add(card);
}
else
{
var foundCard = opponentCardList.FirstOrDefault(x => x.Id == card.Id || x.Id.Equals(card.Id));
if (foundCard == null) continue;
foundCard.Count = card.Count;
}
}

// If opponent's class is unknown yet or we have no imported archetype decks in the database, return empty card list
if (CoreAPI.Game.Opponent.Class == "" || !ArchetypeDecks.Any())
Expand All @@ -225,7 +241,7 @@ internal async void UpdateCardList()
IDictionary<Deck, float> dict = ArchetypeDecks
.Where(d => d.Class == CoreAPI.Game.Opponent.Class && !(d.IsWildDeck && CoreAPI.Game.CurrentFormat == Format.Standard))
.Distinct()
.ToDictionary(d => d, d => d.Similarity(opponentCardlist));
.ToDictionary(d => d, d => d.Similarity(opponentCardList));

// Get highest similarity value
// Some unreproducable bug threw an exception here. System.InvalidOperationException: Sequence contains no elements @ IEnumerable.Max() => should be fixed by DefaultIfEmpty() now!
Expand All @@ -249,8 +265,8 @@ internal async void UpdateCardList()
if (Settings.Default.ShowAbsoluteSimilarity)
{
// Count how many cards from opponent deck are in matched deck
var matchingCards = matchedDeck.Key.CountMatchingCards(opponentCardlist);
_advisorOverlay.LblArchetype.Text = $"{matchedDeck.Key.Name} ({matchingCards}/{matchedDeck.Key.CountUnion(opponentCardlist)})";
var matchingCards = matchedDeck.Key.CountMatchingCards(opponentCardList);
_advisorOverlay.LblArchetype.Text = $"{matchedDeck.Key.Name} ({matchingCards}/{matchedDeck.Key.CountUnion(opponentCardList)})";
}
else
{
Expand All @@ -263,7 +279,7 @@ internal async void UpdateCardList()

var predictedCards = ((Deck) deck.Clone()).Cards.ToList();

foreach (var card in opponentCardlist)
foreach (var card in opponentCardList)
{
// Remove already played opponent cards from predicted archetype deck. But don't remove revealed jousted cards, because they were only seen and not played yet.
if (predictedCards.Contains(card))
Expand Down Expand Up @@ -328,7 +344,7 @@ internal async void UpdateCardList()
// If no archetype deck matches more than MinimumSimilarity clear the list and show the best match percentage
_advisorOverlay.LblArchetype.Text = $"Best match: {Math.Round(maxSim * 100, 2)}%";
_advisorOverlay.LblStats.Text = "";
_advisorOverlay.Update(Settings.Default.ShowNonMatchingCards ? opponentCardlist.ToList() : new List<Card>(), _currentArchetypeDeckGuid != Guid.Empty);
_advisorOverlay.Update(Settings.Default.ShowNonMatchingCards ? opponentCardList.ToList() : new List<Card>(), _currentArchetypeDeckGuid != Guid.Empty);
_currentArchetypeDeckGuid = Guid.Empty;
}
}
Expand Down Expand Up @@ -434,7 +450,7 @@ public static void OpenWebsite()
{
try
{
Process.Start("https://github.com/kimsey0/Advisor");
Process.Start("https://github.com/icetbr/Advisor");
}
catch (Exception e)
{
Expand Down
4 changes: 2 additions & 2 deletions Advisor/AdvisorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public void OnUpdate()
{
}

public Version Version => new Version(1, 2, 0);
public Version Version => new Version(1, 3, 0);

public async Task CheckForUpdate()
{
var latest = await Github.CheckForUpdate("kimsey0", "Advisor", Version);
var latest = await Github.CheckForUpdate("icetbr", "Advisor", Version);
if (latest != null)
{
Advisor.Notify("Plugin update available", $"[DOWNLOAD]({latest.HtmlUrl}) Advisor {latest.TagName}", 0,
Expand Down
4 changes: 2 additions & 2 deletions Advisor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]

0 comments on commit b17186f

Please sign in to comment.