コード例 #1
0
        public static List <CachedDeck> ToCachedDecks(this List <HearthMirror.Objects.Deck> lstDecks)
        {
            List <CachedDeck> lstRet = new List <CachedDeck>();

            for (int i = 0; i < lstDecks.Count; i++)
            {
                HearthMirror.Objects.Deck deck = lstDecks[i];

                CachedDeck cachedDeck = new CachedDeck()
                {
                    Id          = deck.Id,
                    Name        = deck.Name,
                    Hero        = deck.Hero,
                    IsWild      = deck.IsWild,
                    Type        = deck.Type,
                    SeasonId    = deck.SeasonId,
                    CardBackId  = deck.CardBackId,
                    HeroPremium = deck.HeroPremium,
                    Cards       = deck.Cards.ToCachedCards()
                };

                lstRet.Add(cachedDeck);
            }

            return(lstRet);
        }
コード例 #2
0
ファイル: Deck.cs プロジェクト: becelot/dh-hdt-client
        /// <summary>
        /// Import the deck from a HearthMirror deck
        /// </summary>
        /// <param name="selectedDeck">The selected deck detected by HearthMirror</param>
        /// <returns>An instance of a deck that can be serialized</returns>
        private static Deck FromMirror(MirrorDeck selectedDeck)
        {
            Deck result = new Deck();

            // detect if an instance was provided
            if (selectedDeck == null)
            {
                throw new ArgumentException("No deck was provided");
            }

            try
            {
                // convert cards in selected deck to (dbfid, count) format
                selectedDeck.Cards.ForEach(card =>
                {
                    result.CardDbfIds.Add(HearthDb.Cards.All[card.Id].DbfId, card.Count);
                });
            }
            catch (Exception exc)
            {
                Log.Error(exc);
                throw new Exception("Exception while parsing the currently played deck");
            }

            // Extract the hero
            try
            {
                // Extract hero from mirror
                result.HeroDbfId = HearthDb.Cards.All[selectedDeck.Hero].DbfId;
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw new Exception("Could not parse the used hero");
            }

            // Extract deck name
            try
            {
                // Extract hero from mirror
                result.Name = selectedDeck.Name;
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw new Exception("Could not parse the name of the deck");
            }

            try
            {
                result.Format = selectedDeck.IsWild ? HearthDb.Enums.FormatType.FT_WILD : HearthDb.Enums.FormatType.FT_STANDARD;
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw new Exception("Could not parse deck format");
            }

            return(result);
        }
コード例 #3
0
        public ExistingDeck(Deck deck, HearthMirror.Objects.Deck newDeck)
        {
            Deck = deck;
            var tmp = new Deck {
                Cards = new ObservableCollection <Card>(newDeck.Cards.Select(x => new Card {
                    Id = x.Id, Count = x.Count
                }))
            };

            MatchingCards = 0;
            if (deck.HasVersions)
            {
                var counts = deck.VersionsIncludingSelf.Select(v => GetMatchingCards(tmp, deck.GetVersion(v)));
                if (counts.Any(c => c == 30))
                {
                    MatchingCards = 30;
                }
            }
            if (MatchingCards != 30)
            {
                MatchingCards = GetMatchingCards(tmp, deck);
            }
            NewVersion = MatchingCards == 30 ? new SerializableVersion(0, 0)
                                : (MatchingCards < 26 ? SerializableVersion.IncreaseMajor(deck.Version)
                                        : SerializableVersion.IncreaseMinor(deck.Version));
            ShouldBeNewDeck = MatchingCards < 15;
        }
コード例 #4
0
        private void initGame()
        {
            // Init decks
            List <STC.Card> cardsInDeck = new List <STC.Card>();

            HearthMirror.Objects.Deck MirrorDeck = Core.Game.CurrentSelectedDeck;
            if (MirrorDeck != null)
            {
                MirrorDeck.Cards.ForEach(card =>
                {
                    for (var i = 0; i < card.Count; i++)
                    {
                        cardsInDeck.Add(STC.Cards.FromId(card.Id));
                    }
                });
            }

            List <STC.Card> UnknownDeck = new List <STC.Card>();

            for (int i = 0; i < 30; i++)
            {
                UnknownDeck.Add(new STC.Card()
                {
                    Id   = "Unknown",
                    Name = "Unknown",
                    Tags = new Dictionary <GameTag, int> {
                        [GameTag.CARDTYPE] = (int)CardType.MINION, [GameTag.COST] = 51
                    },
                });
            }

            // Init agent
            _agent = new Expectiminimax(cardsInDeck, Converter.GetCardClass(Core.Game.Player.Class), Strategy.Control);

            // Init game
            GameV2 gameV2 = Core.Game;

            _game = new STC.Game(
                new GameConfig()
            {
                StartPlayer      = gameV2.Player.HandCount == 3 ? 1 : 2,
                Player1Name      = gameV2.Player.Name,
                Player1HeroClass = Converter.GetCardClass(gameV2.Player.Class),
                Player1Deck      = cardsInDeck,
                Player2Name      = gameV2.Opponent.Name,
                Player2HeroClass = Converter.GetCardClass(gameV2.Opponent.Class),
                Player2Deck      = UnknownDeck,
                FillDecks        = false,
                Shuffle          = false,
                SkipMulligan     = false,
                AutoNextStep     = false,
                Logging          = false,
                History          = false,
                RandomController = _randomController
            });
            _game.StartGame();
            _game.BeginDraw();
            _game.BeginMulligan();
            Converter.SyncEntityIds(ref _entityIdMapping, _game, gameV2);
        }
コード例 #5
0
        /// <param name="deck">HearthMirror deck object</param>
        /// <param name="matches">Local decks with HsId OR 30 matching cards</param>
        /// <param name="localDecks">All local decks</param>
        public ImportedDeck(HearthMirror.Objects.Deck deck, List <Deck> matches, IList <Deck> localDecks)
        {
            Deck    = deck;
            matches = matches ?? new List <Deck>();
            var hero = Database.GetCardFromId(deck.Hero);

            if (string.IsNullOrEmpty(hero?.PlayerClass) || hero.Id == Database.UnknownCardId)
            {
                Log.Error("No hero found for id " + deck.Hero);
                return;
            }
            Class = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(hero.PlayerClass.ToLower());

            var localOptions = localDecks.Where(d => d.Class == Class && !d.Archived && !d.IsArenaDeck)
                               .Select(x => new ExistingDeck(x, deck));
            var matchesOptions = matches.Select(x => new ExistingDeck(x, deck)).ToList();
            var importOptions  = matchesOptions.Concat(localOptions)
                                 .GroupBy(x => new { x.Deck.DeckId, x.Deck.Version }).Select(g => g.First())
                                 .OrderByDescending(x => x.Deck.HsId == deck.Id)
                                 .ThenByDescending(x => x.MatchingCards)
                                 .ThenByDescending(x => x.Deck.LastPlayed);

            ImportOptions = New.Concat(importOptions);

            SelectedIndex = matchesOptions.Any(x => !x.ShouldBeNewDeck) ? 1 : 0;
        }
コード例 #6
0
 public Deck(DeckType type, HearthMirror.Objects.Deck deck)
 {
     Type   = type;
     Name   = deck.Name;
     DeckId = deck.Id;
     Cards  = CardSorting.Sort(deck.Cards.Select(x => new Card(x)));
     Class  = HearthDb.Cards.All.TryGetValue(deck.Hero, out var hero) ? hero.Class : CardClass.INVALID;
 }
コード例 #7
0
        public DeckListDialog(HearthMirror.Objects.Deck deck)
            : this()
        {
            Title = $"Dust Utility - {deck.Name}";

            m_lstCards = new List <Card>();

            Convert(deck);
        }
コード例 #8
0
        public static int GetCardCount(this HearthMirror.Objects.Deck deck)
        {
            int nRet = 0;

            for (int i = 0; i < deck.Cards.Count; i++)
            {
                nRet += deck.Cards[i].Count;
            }

            return(nRet);
        }
コード例 #9
0
        public ImportedDeck(HearthMirror.Objects.Deck deck, List <Deck> candidates)
        {
            Deck       = deck;
            candidates = candidates ?? new List <Deck>();
            var hero = HearthDb.Cards.All[deck.Hero];

            Class         = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(hero.Class.ToString().ToLower());
            ImportOptions =
                New.Concat(candidates.Concat(DeckList.Instance.Decks.Where(x => x.Class == Class && !x.Archived && !x.IsArenaDeck)).Distinct()
                           .Select(x => new ExistingDeck(x, deck)).OrderByDescending(x => x.MatchingCards).ThenByDescending(x => x.Deck.LastPlayed));
            SelectedIndex = candidates.Any() ? 1 : 0;
        }
コード例 #10
0
        public static int GetCraftingCost(this HearthMirror.Objects.Deck deck)
        {
            int nRet = 0;

            for (int i = 0; i < deck.Cards.Count; i++)
            {
                int nCost = deck.Cards[i].GetCraftingCost();

                nRet += nCost * deck.Cards[i].Count;
            }

            return(nRet);
        }
コード例 #11
0
        private void Convert(HearthMirror.Objects.Deck deck)
        {
            for (int i = 0; i < deck.Cards.Count; i++)
            {
                HearthDb.Card dbCard = HearthDb.Cards.Collectible[deck.Cards[i].Id];

                Card card = new Card(dbCard)
                {
                    Count = deck.Cards[i].Count
                };

                m_lstCards.Add(card);
            }
        }
コード例 #12
0
ファイル: ExistingDeck.cs プロジェクト: 66zjy/AllanHDT
        public ExistingDeck(Deck deck, HearthMirror.Objects.Deck newDeck)
        {
            Deck = deck;
            var tmp = new Deck {
                Cards = new ObservableCollection <Card>(newDeck.Cards.Select(x => new Card {
                    Id = x.Id, Count = x.Count
                }))
            };

            MatchingCards = 30 - (deck - tmp).Count(x => x.Count > 0);
            NewVersion    = MatchingCards == 30 ? new SerializableVersion(0, 0)
                                : (MatchingCards < 26 ? SerializableVersion.IncreaseMajor(deck.Version)
                                        : SerializableVersion.IncreaseMinor(deck.Version));
        }
コード例 #13
0
        public ImportedDeck(HearthMirror.Objects.Deck deck, List <Deck> candidates)
        {
            Deck       = deck;
            candidates = candidates ?? new List <Deck>();
            var hero = Database.GetCardFromId(deck.Hero);

            if (string.IsNullOrEmpty(hero?.PlayerClass) || hero.Id == Database.UnknownCardId)
            {
                Log.Error("No hero found for id " + deck.Hero);
                return;
            }
            Class         = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(hero.PlayerClass.ToLower());
            ImportOptions =
                New.Concat(candidates.Concat(DeckList.Instance.Decks.Where(x => x.Class == Class && !x.Archived && !x.IsArenaDeck)).Distinct()
                           .Select(x => new ExistingDeck(x, deck)).OrderByDescending(x => x.MatchingCards).ThenByDescending(x => x.Deck.LastPlayed));
            SelectedIndex = candidates.Any() ? 1 : 0;
        }
コード例 #14
0
        public static async void ShowNewArenaDeckMessageAsync(this MetroWindow window, HearthMirror.Objects.Deck deck)
        {
            if (_awaitingMainWindowOpen)
            {
                return;
            }
            _awaitingMainWindowOpen = true;

            if (window.WindowState == WindowState.Minimized)
            {
                Core.TrayIcon.ShowMessage("New arena deck detected!");
            }

            while (window.Visibility != Visibility.Visible || window.WindowState == WindowState.Minimized)
            {
                await Task.Delay(100);
            }

            var result = await window.ShowMessageAsync("New arena deck detected!",
                                                       "You can change this behaviour to \"auto save&import\" or \"manual\" in [options > tracker > importing]",
                                                       AffirmativeAndNegative, new Settings { AffirmativeButtonText = "Import", NegativeButtonText = "Cancel" });

            if (result == MessageDialogResult.Affirmative)
            {
                Log.Info("...saving new arena deck.");
                Core.MainWindow.ImportArenaDeck(deck);
            }
            else
            {
                Log.Info("...discarded by user.");
            }
            Core.Game.IgnoredArenaDecks.Add(deck.Id);
            _awaitingMainWindowOpen = false;
        }
コード例 #15
0
 public static HearthMirror.Objects.Card GetCard(this HearthMirror.Objects.Deck deck, string strId)
 {
     return(deck.Cards.Find(delegate(HearthMirror.Objects.Card c) { return string.CompareOrdinal(c.Id, strId) == 0; }));
 }
コード例 #16
0
 public static bool ContainsCard(this HearthMirror.Objects.Deck deck, string strId)
 {
     return(GetCard(deck, strId) != null);
 }