private void UpdateDeckList(Deck selected)
        {
            if (selected == null) return;

            ListViewDeck.Items.Clear();
            foreach (var card in selected.Cards)
            {
                ListViewDeck.Items.Add(card);
            }
            var cardsInDeck = selected.Cards.Sum(c => c.Count);

            SortCardCollection(ListViewDeck.Items);
            _config.LastDeck = selected.Name;
            _xmlManagerConfig.Save("config.xml", _config);
        }
 private void UseDeck(Deck selected)
 {
     if (selected == null)
         return;
     _hearthstone.SetPremadeDeck(selected.Cards);
     _overlay.Dispatcher.BeginInvoke(new Action(_overlay.SortViews));
     Dispatcher.BeginInvoke(new Action(() =>
         {
             _hearthstone.PlayerHandCount = 0;
             _hearthstone.EnemyCards.Clear();
             _hearthstone.EnemyHandCount = 0;
         }));
     _logReader.Reset(false);
 }
        private void BtnEditDeck_Click(object sender, RoutedEventArgs e)
        {
            if (ListboxDecks.SelectedIndex == -1) return;
            var selectedDeck = ListboxDecks.SelectedItem as Deck;
            if (selectedDeck == null) return;
            //move to new deck section with stuff preloaded
            if (_newContainsDeck)
            {
                //still contains deck, discard?
                var result = MessageBox.Show("New Deck Section still contains an unfinished deck. Discard?",
                                             "Found unfinished deck.", MessageBoxButton.YesNo,
                                             MessageBoxImage.Exclamation);
                if (result == MessageBoxResult.No)
                {
                    TabControlTracker.SelectedIndex = 1;
                    return;
                }
            }

            ClearNewDeckSection();
            _editingDeck = true;
            _newContainsDeck = true;
            _newDeck = (Deck) selectedDeck.Clone();
            ListViewNewDeck.ItemsSource = _newDeck.Cards;

            if (ComboBoxSelectClass.Items.Contains(_newDeck.Class))
                ComboBoxSelectClass.SelectedValue = _newDeck.Class;

            TextBoxDeckName.Text = _newDeck.Name;
            UpdateNewDeckHeader(true);
            UpdateDbListView();
            TabControlTracker.SelectedIndex = 1;
        }
        public MainWindow()
        {
            InitializeComponent();

            Helper.CheckForUpdates();

            //check for log config and create if not existing
            try
            {
                if (!File.Exists(_logConfigPath))
                {
                    File.Copy("Files/log.config", _logConfigPath);
                }
                else
                {
                    //update log.config if newer
                    var localFile = new FileInfo(_logConfigPath);
                    var file = new FileInfo("Files/log.config");
                    if (file.LastWriteTime > localFile.LastWriteTime)
                    {

                        File.Copy("Files/log.config", _logConfigPath, true);

                    }
                }
            }
            catch (UnauthorizedAccessException e)
            {
                MessageBox.Show(
                       e.Message + "\n\n" + e.InnerException +
                       "\n\n Please restart the tracker as administrator",
                       "Error writing log.config");
                Close();
                return;
            }
            catch (Exception e)
            {
                MessageBox.Show(
                       e.Message + "\n\n" + e.InnerException +
                       "\n\n What happend here? ",
                       "Error writing log.config");
                Close();
                return;
            }

            //load config
            _config = new Config();
            _xmlManagerConfig = new XmlManager<Config> {Type = typeof (Config)};
            try
            {
                _config = _xmlManagerConfig.Load("config.xml");
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    e.Message + "\n\n" + e.InnerException +
                    "\n\n If you don't know how to fix this, please overwrite config with the default one.",
                    "Error loading config.xml");
                Close();
                return;
            }

            //load saved decks
            if (!File.Exists("PlayerDecks.xml"))
            {
                //avoid overwriting decks file with new releases.
                using (var sr = new StreamWriter("PlayerDecks.xml", false))
                {
                    sr.WriteLine("<Decks></Decks>");
                }
            }
            _xmlManager = new XmlManager<Decks> {Type = typeof (Decks)};
            try
            {
                _deckList = _xmlManager.Load("PlayerDecks.xml");
            }
            catch (Exception e)
            {
                MessageBox.Show(
                    e.Message + "\n\n" + e.InnerException +
                    "\n\n If you don't know how to fix this, please delete PlayerDecks.xml (this will cause you to lose your decks).",
                    "Error loading PlayerDecks.xml");
                Close();
                return;
            }

            ListboxDecks.ItemsSource = _deckList.DecksList;

            //hearthstone, loads db etc
            _hearthstone = new Hearthstone();
            _newDeck = new Deck();
            ListViewNewDeck.ItemsSource = _newDeck.Cards;

            //create overlay
            _overlay = new OverlayWindow(_config, _hearthstone) {Topmost = true};
            _overlay.Show();

            _playerWindow = new PlayerWindow(_config, _hearthstone.PlayerDeck);
            _opponentWindow = new OpponentWindow(_config, _hearthstone.EnemyCards);

            LoadConfig();

            //find hs directory
            if (!File.Exists(_config.HearthstoneDirectory + @"\Hearthstone.exe"))
            {
                MessageBox.Show("Please specify your Hearthstone directory", "Hearthstone directory not found",
                                MessageBoxButton.OK);
                var dialog = new OpenFileDialog();
                dialog.Title = "Select Hearthstone.exe";
                dialog.DefaultExt = "Hearthstone.exe";
                dialog.Filter = "Hearthstone.exe|Hearthstone.exe";
                var result = dialog.ShowDialog();
                if (result != true)
                {
                    return;
                }
                _config.HearthstoneDirectory = Path.GetDirectoryName(dialog.FileName);
                _xmlManagerConfig.Save("config.xml", _config);
            }

            //log reader
            _logReader = new HsLogReader(_config.HearthstoneDirectory, _config.UpdateDelay);
            _logReader.CardMovement += LogReaderOnCardMovement;
            _logReader.GameStateChange += LogReaderOnGameStateChange;
            _logReader.Analyzing += LogReaderOnAnalyzing;

            UpdateDbListView();

            _updateThread = new Thread(Update);
            _updateThread.Start();
            ListboxDecks.SelectedItem =
                _deckList.DecksList.FirstOrDefault(d => d.Name != null && d.Name == _config.LastDeck);

            _initialized = true;

            UpdateDeckList(ListboxDecks.SelectedItem as Deck);
            UseDeck(ListboxDecks.SelectedItem as Deck);

            _logReader.Start();
        }
        private void BtnDeleteDeck_Click(object sender, RoutedEventArgs e)
        {
            var deck = new Deck();
            deck.Cards = new List<Card>();
            if (ComboBoxDecks.SelectedItem.ToString() == "Create New")
            {
                deck.Name = TextBoxDeckName.Text;
                ComboBoxDecks.Items.Add(deck.Name);
                _cardsInDeck = 0;
                ButtonUseDeck.Content = "Use Deck (" + (_cardsInDeck) + ")";
            }
            else
            {
                deck.Name = ComboBoxDecks.SelectedItem.ToString();
            }

            if (
                MessageBox.Show("Are you Sure?", "Delete " + deck.Name, MessageBoxButton.YesNo, MessageBoxImage.Asterisk) ==
                MessageBoxResult.Yes)
            {
                try
                {

                    _deckList.DecksList.Remove(
                        _deckList.DecksList.First(x => ComboBoxDecks.SelectedItem.ToString().Equals(x.Name)));
                    _xmlManager.Save("PlayerDecks.xml", _deckList);
                    ComboBoxDecks.SelectedIndex = 0;
                    ComboBoxDecks.Items.Remove(deck.Name);
                    _cardsInDeck = 0;
                    ButtonUseDeck.Content = "Use Deck (" + (_cardsInDeck) + ")";
                }
                catch (Exception)
                {
                    Console.WriteLine("Error deleting deck");
                }
            }
        }
        private void SaveDeck()
        {
            var deck = new Deck();
            deck.Cards = new List<Card>();
            if (ComboBoxDecks.SelectedItem.ToString() == "Create New")
            {
                deck.Name = TextBoxDeckName.Text;
                ComboBoxDecks.Items.Add(deck.Name);
            }
            else
            {
                deck.Name = ComboBoxDecks.SelectedItem.ToString();
                _deckList.DecksList.Remove(
                    _deckList.DecksList.First(x => ComboBoxDecks.SelectedItem.ToString().Equals(x.Name)));
            }
            foreach (var card in ListViewDeck.Items)
            {
                deck.Cards.Add((Card)card);
            }
            _deckList.DecksList.Add(deck);

            ComboBoxDecks.SelectedItem = deck.Name;
            _xmlManager.Save("PlayerDecks.xml", _deckList);
            BtnSaveDeck.Content = "Save";
        }
        public void SetDeck(Deck deck)
        {
            _deck = deck;
            if (deck == null)
            {
                TabControlCurrentOverall.SelectedIndex = 1;
                TabItemDeck.Visibility                = Collapsed;
                TabItemOverall.Visibility             = Collapsed;
                StackPanelUnassignedFilter.Visibility = Visible;
                return;
            }
            TabItemDeck.Visibility                = Visible;
            TabItemOverall.Visibility             = Visible;
            StackPanelUnassignedFilter.Visibility = TabControlCurrentOverall.SelectedIndex == 1 ? Visible : Collapsed;
            DataGridGames.Items.Clear();
            var filteredGames = FilterGames(deck.DeckStats.Games).ToList();
            var modified      = false;

            foreach (var game in filteredGames)
            {
                if (!game.VerifiedHeroes && VerifyHeroes(game))
                {
                    modified = true;
                }
                if (Config.Instance.StatsFilterOpponentHeroClass == HeroClassAll.All ||
                    game.OpponentHero == Config.Instance.StatsFilterOpponentHeroClass.ToString())
                {
                    DataGridGames.Items.Add(game);
                }
            }
            if (modified)
            {
                DeckStatsList.Save();
            }
            DataGridWinLoss.Items.Clear();
            DataGridWinLoss.Items.Add(new WinLoss(filteredGames, "%"));
            DataGridWinLoss.Items.Add(new WinLoss(filteredGames, "Win - Loss"));
            //current version
            var games = filteredGames.Where(g => g.BelongsToDeckVerion(deck)).ToList();

            DataGridWinLoss.Items.Add(new WinLoss(games, "%", deck.Version));
            DataGridWinLoss.Items.Add(new WinLoss(games, "Win - Loss", deck.Version));
            //prev versions
            foreach (var v in deck.Versions.OrderByDescending(d => d.Version))
            {
                games = filteredGames.Where(g => g.BelongsToDeckVerion(v)).ToList();
                DataGridWinLoss.Items.Add(new WinLoss(games, "%", v.Version));
                DataGridWinLoss.Items.Add(new WinLoss(games, "Win - Loss", v.Version));
            }

            var defaultStats = DefaultDeckStats.Instance.GetDeckStats(deck.Class) ?? new DeckStats();

            DataGridWinLossClass.Items.Clear();
            var allGames =
                DeckList.Instance.Decks.Where(d => d.GetClass == _deck.GetClass)
                .SelectMany(d => FilterGames(d.DeckStats.Games).Where(g => !g.IsClone))
                .Concat(FilterGames(defaultStats.Games))
                .ToList();

            DataGridWinLossClass.Items.Add(new WinLoss(allGames, "%"));
            DataGridWinLossClass.Items.Add(new WinLoss(allGames, "Win - Loss"));
            DataGridGames.Items.Refresh();
        }
 private bool MatchesTagFilters(Deck deck) => !Config.Instance.StatsOverallApplyTagFilters || Config.Instance.SelectedTags.Contains("All") ||
 deck.Tags.Any(tag => Config.Instance.SelectedTags.Contains(tag));
Ejemplo n.º 9
0
 public static string DeckToIdString(Deck deck)
 => deck.GetSelectedDeckVersion().Cards.Aggregate("", (current, card) => current + (card.Id + ":" + card.Count + ";"));
        public static async Task Export(Deck deck)
        {
            if (deck == null)
            {
                return;
            }

            var hsHandle = User32.GetHearthstoneWindow();

            if (!User32.IsHearthstoneInForeground())
            {
                //restore window and bring to foreground
                User32.ShowWindow(hsHandle, User32.SwRestore);
                User32.SetForegroundWindow(hsHandle);
                //wait it to actually be in foreground, else the rect might be wrong
                await Task.Delay(500);
            }
            if (!User32.IsHearthstoneInForeground())
            {
                MessageBox.Show("Can't find Heartstone window.");
                return;
            }

            var hsRect = User32.GetHearthstoneRect(false);
            var ratio  = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height);

            string oldClipboardContent = null;

            try
            {
                oldClipboardContent = Clipboard.GetText();
            }
            catch
            {
            }

            var searchBoxPos = new Point((int)(GetXPos(Config.Instance.ExportSearchBoxX, hsRect.Width, ratio)), (int)(Config.Instance.ExportSearchBoxY * hsRect.Height));
            var cardPosX     = GetXPos(Config.Instance.ExportCard1X, hsRect.Width, ratio);
            var card2PosX    = GetXPos(Config.Instance.ExportCard2X, hsRect.Width, ratio);
            var cardPosY     = Config.Instance.ExportCardsY * hsRect.Height;

            if (Config.Instance.ExportSetDeckName)
            {
                await SetDeckName(deck.Name, ratio, hsRect.Width, hsRect.Height, hsHandle);
            }

            await ClickAllCrystal(ratio, hsRect.Width, hsRect.Height, hsHandle);

            foreach (var card in deck.Cards)
            {
                await AddCardToDeck(card, searchBoxPos, cardPosX, card2PosX, cardPosY, hsRect.Height, hsHandle);
            }


            // Clear search field now all cards have been entered

            await ClickOnPoint(hsHandle, searchBoxPos);

            SendKeys.SendWait("{DELETE}");
            SendKeys.SendWait("{ENTER}");
            try
            {
                if (oldClipboardContent != null)
                {
                    Clipboard.SetText(oldClipboardContent);
                }
            }
            catch
            {
            }
        }
Ejemplo n.º 11
0
        private static async Task <Deck> ImportArenaValue(string url)
        {
            try
            {
                var deck = new Deck {
                    Name = "Arena " + DateTime.Now.ToString("dd-MM hh:mm")
                };

                const string baseUrl = @"http://www.arenavalue.com/deckpopout.php?id=";
                var          newUrl  = baseUrl + url.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();


                HtmlNodeCollection nodes = null;
                using (var wb = new WebBrowser())
                {
                    var done = false;
                    wb.Navigate(newUrl + "#" + DateTime.Now.Ticks);
                    wb.DocumentCompleted += (sender, args) => done = true;

                    while (!done)
                    {
                        await Task.Delay(50);
                    }

                    for (var i = 0; i < 20; i++)
                    {
                        var doc = new HtmlDocument();
                        doc.Load(wb.DocumentStream);
                        if ((nodes = doc.DocumentNode.SelectNodes("//*[@id='deck']/div[@class='deck screenshot']")) != null)
                        {
                            try
                            {
                                if (nodes.Sum(x => int.Parse(x.Attributes["data-count"].Value)) == 30)
                                {
                                    break;
                                }
                            }
                            catch
                            {
                            }
                        }
                        await Task.Delay(500);
                    }
                }

                if (nodes == null)
                {
                    return(null);
                }

                foreach (var node in nodes)
                {
                    var cardId = node.Attributes["data-original"].Value;
                    int count;
                    int.TryParse(node.Attributes["data-count"].Value, out count);
                    var card = Game.GetCardFromId(cardId);
                    card.Count = count;
                    deck.Cards.Add(card);

                    if (string.IsNullOrEmpty(deck.Class) && card.GetPlayerClass != "Neutral")
                    {
                        deck.Class = card.PlayerClass;
                    }
                }

                return(deck);
            }
            catch (Exception e)
            {
                Logger.WriteLine(e.Message + "\n" + e.StackTrace);
                return(null);
            }
        }
Ejemplo n.º 12
0
        public static Deck ParseCardString(string cards, bool localizedNames = false)
        {
            try
            {
                var deck  = new Deck();
                var lines = cards.Split('\n');
                foreach (var line in lines)
                {
                    var   count    = 1;
                    var   cardName = line.Trim();
                    Match match    = null;
                    if (_cardLineRegexCountFirst.IsMatch(cardName))
                    {
                        match = _cardLineRegexCountFirst.Match(cardName);
                    }
                    else if (_cardLineRegexCountLast.IsMatch(cardName))
                    {
                        match = _cardLineRegexCountLast.Match(cardName);
                    }
                    else if (_cardLineRegexCountLast2.IsMatch(cardName))
                    {
                        match = _cardLineRegexCountLast2.Match(cardName);
                    }
                    if (match != null)
                    {
                        var tmpCount = match.Groups["count"];
                        if (tmpCount.Success)
                        {
                            count = int.Parse(tmpCount.Value);
                        }
                        cardName = match.Groups["cardname"].Value.Trim();
                    }

                    var card = Database.GetCardFromName(cardName, localizedNames);
                    if (card == null || string.IsNullOrEmpty(card.Name))
                    {
                        continue;
                    }
                    card.Count = count;

                    if (string.IsNullOrEmpty(deck.Class) && card.PlayerClass != "Neutral")
                    {
                        deck.Class = card.PlayerClass;
                    }

                    if (deck.Cards.Contains(card))
                    {
                        var deckCard = deck.Cards.First(c => c.Equals(card));
                        deck.Cards.Remove(deckCard);
                        deckCard.Count += count;
                        deck.Cards.Add(deckCard);
                    }
                    else
                    {
                        deck.Cards.Add(card);
                    }
                }
                return(deck);
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Error parsing card string: " + ex, "Import");
                return(null);
            }
        }
        private void ListboxPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems == null || e.AddedItems.Count == 0)
            {
                return;
            }
            if (!_initialized)
            {
                return;
            }
            ChangedSelection = true;
            var selectedClass = e.AddedItems[0] as HsClass;

            if (selectedClass != null)
            {
                if (_inClassSelect)
                {
                    ShowAll = selectedClass.Name == "All";

                    _selectedClass = selectedClass;

                    ListboxPicker.Items.Clear();
                    ListboxPicker.Items.Add(new HsClass("Back"));

                    if (ShowAll)
                    {
                        foreach (var d in _hsClasses.SelectMany(hsc => hsc.Decks))
                        {
                            if (DeckMatchesSelectedTags(d))
                            {
                                ListboxPicker.Items.Add(d);
                            }
                        }
                    }
                    else
                    {
                        foreach (var d in selectedClass.Decks)
                        {
                            if (DeckMatchesSelectedTags(d))
                            {
                                ListboxPicker.Items.Add(d);
                            }
                        }
                    }
                    _inClassSelect = false;
                    SortDecks();
                }
                else if (selectedClass.Name == "Back")
                {
                    _selectedClass = null;
                    ListboxPicker.Items.Clear();
                    ListboxPicker.Items.Add(new HsClass("All"));
                    foreach (var hsClass in _hsClasses)
                    {
                        ListboxPicker.Items.Add(hsClass);
                    }
                    _inClassSelect = true;
                }
            }
            else
            {
                var newSelectedDeck = e.AddedItems[0] as Deck;
                if (newSelectedDeck == null)
                {
                    ChangedSelection = false;
                    return;
                }

                if (Equals(newSelectedDeck, SelectedDeck))
                {
                    ChangedSelection = false;
                    return;
                }

                if (OnSelectedDeckChanged != null)
                {
                    OnSelectedDeckChanged(this, newSelectedDeck);
                }
                if (SelectedDeck != null)
                {
                    SelectedDeck.IsSelectedInGui = false;
                }
                newSelectedDeck.IsSelectedInGui = true;
                ListboxPicker.Items.Refresh();


                SelectedDeck = newSelectedDeck;
            }
            ChangedSelection = false;
        }