Esempio n. 1
0
        private BoardState GetBoardState()
        {
            if (Core.Game.PlayerEntity == null || Core.Game.OpponentEntity == null)
            {
                return(null);
            }


            var player   = Core.Game.Player;
            var opponent = Core.Game.Opponent;

            var deck         = DeckList.Instance.ActiveDeck;
            var games        = deck?.GetRelevantGames();
            var fullDeckList = new Dictionary <int, int>();

            if (DeckList.Instance.ActiveDeckVersion != null)
            {
                foreach (var card in DeckList.Instance.ActiveDeckVersion.Cards)
                {
                    fullDeckList[card.DbfIf] = card.Count;
                }
            }
            int FullCount(int dbfId) => fullDeckList == null ? 0 : fullDeckList.TryGetValue(dbfId, out var count) ? count : 0;

            var playerCardsDict = new List <int[]>();

            if (deck != null)
            {
                foreach (var card in player.GetPlayerCardList(false, false, false).Where(x => !x.Jousted))
                {
                    var inDeck = card.IsCreated ? 0 : FullCount(card.DbfIf);
                    playerCardsDict.Add(new[] { card.DbfIf, card.Count, inDeck });
                }
            }
            var format   = Core.Game.CurrentFormat ?? Format.Wild;
            var gameType = HearthDbConverter.GetBnetGameType(Core.Game.CurrentGameType, format);

            return(new BoardState
            {
                Player = new BoardStatePlayer
                {
                    Board = SortedDbfIds(player.Board.Where(x => x.IsMinion)),
                    Deck = new BoardStateDeck
                    {
                        Cards = playerCardsDict,
                        Name = deck?.Name,
                        Format = deck?.GuessFormatType() ?? FormatType.FT_UNKNOWN,
                        Hero = Database.GetHeroCardFromClass(deck?.Class)?.DbfIf ?? 0,
                        Wins = games?.Count(g => g.Result == GameResult.Win) ?? 0,
                        Losses = games?.Count(g => g.Result == GameResult.Loss) ?? 0,
                        Size = player.DeckCount
                    },
                    Secrets = SortedDbfIds(player.Secrets),
                    Hero = DbfId(Find(player, HeroId(Core.Game.PlayerEntity))),
                    Hand = new BoardStateHand
                    {
                        Cards = SortedDbfIds(player.Hand),
                        Size = player.HandCount
                    },
                    HeroPower = DbfId(FindHeroPower(player)),
                    Weapon = DbfId(Find(player, WeaponId(Core.Game.PlayerEntity))),
                    Quest = Quest(player.Quests.FirstOrDefault()),
                    Fatigue = Core.Game.PlayerEntity.GetTag(GameTag.FATIGUE)
                },
                Opponent = new BoardStatePlayer
                {
                    Board = SortedDbfIds(opponent.Board.Where(x => x.IsMinion)),
                    Deck = new BoardStateDeck
                    {
                        Size = opponent.DeckCount
                    },
                    Hand = new BoardStateHand
                    {
                        Size = opponent.HandCount
                    },
                    Hero = DbfId(Find(opponent, HeroId(Core.Game.OpponentEntity))),
                    HeroPower = DbfId(FindHeroPower(opponent)),
                    Weapon = DbfId(Find(opponent, WeaponId(Core.Game.OpponentEntity))),
                    Quest = Quest(opponent.Quests.FirstOrDefault()),
                    Fatigue = Core.Game.OpponentEntity.GetTag(GameTag.FATIGUE)
                },
                GameType = gameType,
                BobsBuddyOutput = gameType == BnetGameType.BGT_BATTLEGROUNDS ? GetBobsBuddyState() : null
            });
        }
        public static async Task <MessageDialogResult> ShowMissingCardsMessage(this MetroWindow window, Deck deck, bool exportDialog)
        {
            if (!deck.MissingCards.Any())
            {
                return(await window.ShowMessageAsync("No missing cards",
                                                     "No cards were missing when you last exported this deck. (or you have not recently exported this deck)",
                                                     Affirmative, new Settings { AffirmativeButtonText = "OK" }));
            }
            var message   = "You are missing the following cards:\n";
            var totalDust = 0;
            var sets      = new List <string>();

            foreach (var card in deck.MissingCards)
            {
                message += "\n• " + card.LocalizedName;
                if (card.Count == 2)
                {
                    message += " x2";
                }

                if (card.Set == HearthDbConverter.SetConverter(CardSet.NAXX))
                {
                    sets.Add("and the Naxxramas DLC ");
                }
                else if (card.Set == HearthDbConverter.SetConverter(CardSet.PROMO))
                {
                    sets.Add("and Promotion cards ");
                }
                else if (card.Set == HearthDbConverter.SetConverter(CardSet.HOF))
                {
                    sets.Add("and the Hall of Fame cards ");
                }
                else if (card.Set == HearthDbConverter.SetConverter(CardSet.BRM))
                {
                    sets.Add("and the Blackrock Mountain DLC ");
                }
                else if (card.Set == HearthDbConverter.SetConverter(CardSet.LOE))
                {
                    sets.Add("and the League of Explorers DLC ");
                }
                else if (card.Set == HearthDbConverter.SetConverter(CardSet.KARA))
                {
                    sets.Add("and the One Night in Karazhan DLC ");
                }
                else
                {
                    totalDust += card.DustCost * card.Count;
                }
            }
            message += $"\n\nYou need {totalDust} dust {string.Join("", sets.Distinct())}to craft the missing cards.";
            var style    = exportDialog ? AffirmativeAndNegative : Affirmative;
            var settings = new Settings {
                AffirmativeButtonText = "OK"
            };

            if (exportDialog)
            {
                settings.AffirmativeButtonText = "Export";
                settings.NegativeButtonText    = "Cancel";
                message += "\n\nExport anyway? (this will not craft the cards)";
            }
            return(await window.ShowMessageAsync("Missing cards", message, style, settings));
        }
Esempio n. 3
0
        public static UploadMetaData Generate(GameMetaData gameMetaData, GameStats game)
        {
            var metaData = new UploadMetaData();
            var players  = GetPlayerInfo(game);

            if (players != null)
            {
                if (game.GameType == GameType.GT_BATTLEGROUNDS)
                {
                    metaData.Players = players;
                }
                else
                {
                    metaData.Player1 = players.FirstOrDefault(x => x.Id == 1);
                    metaData.Player2 = players.FirstOrDefault(x => x.Id == 2);
                }
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Address))
            {
                metaData.ServerIp = gameMetaData.ServerInfo.Address;
            }
            if (gameMetaData?.ServerInfo?.Port > 0)
            {
                metaData.ServerPort = gameMetaData.ServerInfo.Port.ToString();
            }
            if (gameMetaData?.ServerInfo?.GameHandle > 0)
            {
                metaData.GameHandle = gameMetaData.ServerInfo.GameHandle.ToString();
            }
            if (gameMetaData?.ServerInfo?.ClientHandle > 0)
            {
                metaData.ClientHandle = gameMetaData.ServerInfo.ClientHandle.ToString();
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.SpectatorPassword))
            {
                metaData.SpectatePassword = gameMetaData.ServerInfo.SpectatorPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.AuroraPassword))
            {
                metaData.AuroraPassword = gameMetaData.ServerInfo.AuroraPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Version))
            {
                metaData.ServerVersion = gameMetaData.ServerInfo.Version;
            }
            if (game?.StartTime > DateTime.MinValue)
            {
                metaData.MatchStart = game.StartTime.ToString("o");
            }
            if (game != null)
            {
                metaData.GameType = game.GameType != GameType.GT_UNKNOWN ? (int)HearthDbConverter.GetBnetGameType(game.GameType, game.Format) : (int)HearthDbConverter.GetGameType(game.GameMode, game.Format);
            }
            if (game?.Format != null)
            {
                metaData.Format = (int)HearthDbConverter.GetFormatType(game.Format);
            }
            metaData.SpectatorMode    = game?.GameMode == GameMode.Spectator;
            metaData.Reconnected      = gameMetaData?.Reconnected ?? false;
            metaData.Resumable        = gameMetaData?.ServerInfo?.Resumable ?? false;
            metaData.FriendlyPlayerId = game?.FriendlyPlayerId > 0 ? game.FriendlyPlayerId : (int?)null;
            var scenarioId = game?.ScenarioId ?? gameMetaData?.ServerInfo?.Mission;

            if (scenarioId > 0)
            {
                metaData.ScenarioId = scenarioId;
            }
            var build = gameMetaData?.HearthstoneBuild;

            if (build == null || build == 0)
            {
                build = game?.HearthstoneBuild;
            }
            if ((build == null || build == 0) && game != null)
            {
                build = BuildDates.GetByDate(game.StartTime);
            }
            if (build > 0)
            {
                metaData.HearthstoneBuild = build;
            }
            if (game?.BrawlSeasonId > 0)
            {
                metaData.BrawlSeason = game.BrawlSeasonId;
            }
            if (game?.RankedSeasonId > 0)
            {
                metaData.LadderSeason = game.RankedSeasonId;
            }
            if (gameMetaData?.TwitchVodData != null)
            {
                metaData.TwitchVod = gameMetaData.TwitchVodData;
            }
            if (game?.LeagueId > 0)
            {
                metaData.LeagueId = game.LeagueId;
            }
            return(metaData);
        }
Esempio n. 4
0
        private void UpdateDbListView()
        {
            if (_newDeck == null)
            {
                return;
            }
            var    selectedClass = _newDeck.Class;
            string selectedNeutral;
            int    selectedManaCost;
            string selectedSet;

            try
            {
                selectedNeutral = MenuFilterType.Items.Cast <RadioButton>().First(x => x.IsChecked.HasValue && x.IsChecked.Value).Name.Substring(15);
            }
            catch (Exception)
            {
                selectedNeutral = "All";
            }
            try
            {
                if (!int.TryParse(MenuFilterMana.Items.Cast <RadioButton>().First(x => x.IsChecked.HasValue && x.IsChecked.Value).Content.ToString().Substring(0, 1),
                                  out selectedManaCost))
                {
                    selectedManaCost = -1;
                }
            }
            catch (Exception)
            {
                selectedManaCost = -1;
            }
            try
            {
                int value;
                int.TryParse(MenuFilterSet.Items.Cast <RadioButton>().First(x => x.IsChecked.HasValue && x.IsChecked.Value).Name.Substring(14), out value);
                selectedSet = value > 0 ? HearthDbConverter.SetConverter((CardSet)value) : "All";
            }
            catch (Exception)
            {
                selectedSet = "All";
            }
            if (selectedClass == "Select a Class")
            {
                ListViewDB.Items.Clear();
            }
            else
            {
                ListViewDB.Items.Clear();

                var formattedInput = Helper.RemoveDiacritics(TextBoxDBFilter.Text.ToLowerInvariant(), true);
                var words          = formattedInput.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var card in Database.GetActualCards())
                {
                    var cardName = Helper.RemoveDiacritics(card.LocalizedName.ToLowerInvariant(), true);
                    if (!Config.Instance.UseFullTextSearch && !cardName.Contains(formattedInput) &&
                        card.AlternativeNames.All(x => x == null || !Helper.RemoveDiacritics(x.ToLowerInvariant(), true).Contains(formattedInput)) &&
                        (!string.IsNullOrEmpty(card.RaceOrType) && formattedInput != card.RaceOrType.ToLowerInvariant()))
                    {
                        continue;
                    }
                    if (Config.Instance.UseFullTextSearch &&
                        words.Any(
                            w =>
                            !cardName.Contains(w) && !(!string.IsNullOrEmpty(card.Text) && card.Text.ToLowerInvariant().Contains(w)) &&
                            card.AlternativeNames.All(x => x == null || !Helper.RemoveDiacritics(x.ToLowerInvariant(), true).Contains(formattedInput)) &&
                            card.AlternativeTexts.All(x => x == null || !x.ToLowerInvariant().Contains(formattedInput)) &&
                            (!string.IsNullOrEmpty(card.RaceOrType) && w != card.RaceOrType.ToLowerInvariant()) &&
                            (w != card.Rarity.ToString().ToLowerInvariant())))
                    {
                        continue;
                    }

                    // mana filter
                    if (selectedManaCost > -1 && ((selectedManaCost < 9 || card.Cost < 9) && (selectedManaCost != card.Cost)))
                    {
                        continue;
                    }
                    if (selectedSet != "All" && !string.Equals(selectedSet, card.Set, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }
                    if (!_newDeck.IsArenaDeck && !_newDeck.IsBrawlDeck && !(CheckBoxIncludeWild.IsChecked ?? true) && Helper.WildOnlySets.Contains(card.Set))
                    {
                        continue;
                    }
                    switch (selectedNeutral)
                    {
                    case "All":
                        if (card.GetPlayerClass == selectedClass || card.GetPlayerClass == "Neutral")
                        {
                            ListViewDB.Items.Add(card);
                        }
                        break;

                    case "Class":
                        if (card.GetPlayerClass == selectedClass)
                        {
                            ListViewDB.Items.Add(card);
                        }
                        break;

                    case "Neutral":
                        if (card.GetPlayerClass == "Neutral")
                        {
                            ListViewDB.Items.Add(card);
                        }
                        break;
                    }
                }

                Helper.SortCardCollection(ListViewDB.Items, Config.Instance.CardSortingClassFirst);
            }
        }
        public static void UpdateDungeonRunDeck(DungeonInfo info, bool isPVPDR)
        {
            if (!Config.Instance.DungeonAutoImport)
            {
                return;
            }

            var isNewPVPDR = isPVPDR && !info.RunActive && info.SelectedLoadoutTreasureDbId > 0;

            Log.Info($"Found dungeon run deck Set={(CardSet)info.CardSet}, PVPDR={isPVPDR} (new={isNewPVPDR})");

            var allCards = info.DbfIds?.ToList() ?? new List <int>();

            // New PVPDR runs have all non-loadout cards in the DbfIds. We still add the picked loadout below.
            // So we don't want to replace allCards with baseDeck, as backDeck is empty, and we don't want to add
            // any loot or treasure, as these will be the ones from a previous run, if they exist.
            if (!isNewPVPDR)
            {
                var baseDeck = info.SelectedDeck ?? new List <int>();
                if (baseDeck.All(x => allCards.Contains(x)))
                {
                    if (info.PlayerChosenLoot > 0)
                    {
                        var loot   = new[] { info.LootA, info.LootB, info.LootC };
                        var chosen = loot[info.PlayerChosenLoot - 1];
                        for (var i = 1; i < chosen.Count; i++)
                        {
                            allCards.Add(chosen[i]);
                        }
                    }
                    if (info.PlayerChosenTreasure > 0)
                    {
                        allCards.Add(info.Treasure[info.PlayerChosenTreasure - 1]);
                    }
                }
                else
                {
                    allCards = baseDeck;
                }
            }

            var cards = allCards.GroupBy(x => x).Select(x =>
            {
                var card = Database.GetCardFromDbfId(x.Key, false);
                if (card == null)
                {
                    return(null);
                }
                card.Count = x.Count();
                return(card);
            }).Where(x => x != null).ToList();

            var loadoutCardId = info.LoadoutCardId;
            var loadout       = loadoutCardId != null?Database.GetCardFromId(loadoutCardId) : null;

            if (loadout != null && !allCards.Contains(loadout.DbfIf))
            {
                cards.Add(loadout);
            }

            if (!Config.Instance.DungeonRunIncludePassiveCards)
            {
                cards.RemoveAll(c => !c.Collectible && c.HideStats);
            }

            var cardSet = (CardSet)info.CardSet;

            string playerClass = null;

            if (cardSet == CardSet.ULDUM && loadout != null)
            {
                playerClass = DungeonRun.GetUldumHeroPlayerClass(loadout.PlayerClass);
            }
            else if (isPVPDR)
            {
                playerClass = HearthDbConverter.ConvertClass((CardClass)(info.HeroClass != 0 ? info.HeroClass : info.HeroCardClass));
            }
            else
            {
                if (allCards.Count == 10)
                {
                    playerClass = allCards.Select(x => Database.GetCardFromDbfId(x).PlayerClass).FirstOrDefault(x => x != null)?.ToUpperInvariant();
                }
                if (playerClass == null)
                {
                    playerClass = ((CardClass)info.HeroCardClass).ToString().ToUpperInvariant();
                }
            }

            var deck = DeckList.Instance.Decks.FirstOrDefault(x => (!isPVPDR && x.IsDungeonDeck || isPVPDR && x.IsDuelsDeck) && x.Class.ToUpperInvariant() == playerClass.ToUpperInvariant() &&
                                                              x.Cards.All(e => cards.Any(c => c.Id == e.Id && c.Count >= e.Count)) &&
                                                              !(x.IsDungeonRunCompleted ?? false) &&
                                                              !(x.IsDuelsRunCompleted ?? false));
            var baseDbfids = isPVPDR ? info.DbfIds : info.SelectedDeck;

            if (deck == null && (deck = CreateDungeonDeck(playerClass, cardSet, isPVPDR, baseDbfids, loadout)) == null)
            {
                Log.Info($"No existing deck - can't find default deck for {playerClass}");
                return;
            }
            if (!info.RunActive && (cardSet == CardSet.ULDUM || cardSet == CardSet.DALARAN))
            {
                Log.Info($"Inactive run for Set={cardSet.ToString()} - this is a new run");
                return;
            }
            if (cards.All(c => deck.Cards.Any(e => c.Id == e.Id && c.Count == e.Count)))
            {
                Log.Info("No new cards");
                return;
            }
            deck.Cards.Clear();
            Helper.SortCardCollection(cards, false);
            foreach (var card in cards)
            {
                deck.Cards.Add(card);
            }
            deck.LastEdited = DateTime.Now;
            DeckList.Save();
            Core.UpdatePlayerCards(true);
            Log.Info("Updated dungeon run deck");
        }
Esempio n. 6
0
        public static UploadMetaData Generate(GameMetaData gameMetaData, GameStats game)
        {
            var metaData = new UploadMetaData();
            var players  = GetPlayerInfo(game);

            if (players != null)
            {
                if (game.GameMode == GameMode.Battlegrounds || game.GameMode == GameMode.Mercenaries)
                {
                    metaData.Players = players;
                }
                else
                {
                    metaData.Player1 = players.FirstOrDefault(x => x.Id == 1);
                    metaData.Player2 = players.FirstOrDefault(x => x.Id == 2);
                }
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Address))
            {
                metaData.ServerIp = gameMetaData.ServerInfo.Address;
            }
            if (gameMetaData?.ServerInfo?.Port > 0)
            {
                metaData.ServerPort = gameMetaData.ServerInfo.Port.ToString();
            }
            if (gameMetaData?.ServerInfo?.GameHandle > 0)
            {
                metaData.GameHandle = gameMetaData.ServerInfo.GameHandle.ToString();
            }
            if (gameMetaData?.ServerInfo?.ClientHandle > 0)
            {
                metaData.ClientHandle = gameMetaData.ServerInfo.ClientHandle.ToString();
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.SpectatorPassword))
            {
                metaData.SpectatePassword = gameMetaData.ServerInfo.SpectatorPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.AuroraPassword))
            {
                metaData.AuroraPassword = gameMetaData.ServerInfo.AuroraPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Version))
            {
                metaData.ServerVersion = gameMetaData.ServerInfo.Version;
            }
            if (game?.StartTime > DateTime.MinValue)
            {
                metaData.MatchStart = game.StartTime.ToString("o");
            }
            if (game != null)
            {
                metaData.GameType = (int)HearthDbConverter.GetBnetGameType(game.GameType, game.Format);
            }
            if (game?.Format != null)
            {
                metaData.Format = (int)HearthDbConverter.GetFormatType(game.Format);
            }
            metaData.SpectatorMode    = game?.GameMode == GameMode.Spectator;
            metaData.Reconnected      = gameMetaData?.Reconnected ?? false;
            metaData.Resumable        = gameMetaData?.ServerInfo?.Resumable ?? false;
            metaData.FriendlyPlayerId = game?.FriendlyPlayerId > 0 ? game.FriendlyPlayerId : (int?)null;
            var scenarioId = game?.ScenarioId ?? gameMetaData?.ServerInfo?.Mission;

            if (scenarioId > 0)
            {
                metaData.ScenarioId = scenarioId;
            }
            var build = gameMetaData?.HearthstoneBuild;

            if (build == null || build == 0)
            {
                build = game?.HearthstoneBuild;
            }
            if ((build == null || build == 0) && game != null)
            {
                build = BuildDates.GetByDate(game.StartTime);
            }
            if (build > 0)
            {
                metaData.HearthstoneBuild = build;
            }
            if (game?.BrawlSeasonId > 0)
            {
                metaData.BrawlSeason = game.BrawlSeasonId;
            }
            if (game?.RankedSeasonId > 0)
            {
                metaData.LadderSeason = game.RankedSeasonId;
            }
            if (gameMetaData?.TwitchVodData != null)
            {
                metaData.TwitchVod = gameMetaData.TwitchVodData;
            }
            if (game?.LeagueId > 0)
            {
                metaData.LeagueId = game.LeagueId;
            }
            if (game?.GameMode == GameMode.Battlegrounds)
            {
                metaData.BattlegroundsRaces = game.BattlegroundsRaces?.Cast <int>().OrderBy(x => x).ToArray();
            }
            if (game?.GameMode == GameMode.Mercenaries)
            {
                if (game?.MercenariesBountyRunRewards?.Count > 0)
                {
                    metaData.MercenariesRewards = game.MercenariesBountyRunRewards
                                                  .Select(x => new UploadMetaData.MercenaryReward()
                    {
                        Id = x.Id, Coins = x.Coins
                    })
                                                  .ToList();
                }
                if (!string.IsNullOrEmpty(game?.MercenariesBountyRunId))
                {
                    metaData.MercenariesBountyRunId             = game.MercenariesBountyRunId;
                    metaData.MercenariesBountyRunTurnsTaken     = game.MercenariesBountyRunTurnsTaken;
                    metaData.MercenariesBountyRunCompletedNodes = game.MercenariesBountyRunCompletedNodes;
                }
            }
            return(metaData);
        }
Esempio n. 7
0
 public Card GetCardForFormat(Format?format) => GetCardForFormat(HearthDbConverter.GetFormatType(format));
Esempio n. 8
0
        public static UploadMetaData Generate(string[] log, GameMetaData gameMetaData, GameStats game)
        {
            var metaData   = new UploadMetaData();
            var playerInfo = GetPlayerInfo(log, game);

            if (playerInfo != null)
            {
                metaData.Player1 = playerInfo.Player1;
                metaData.Player2 = playerInfo.Player2;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Address))
            {
                metaData.ServerIp = gameMetaData.ServerInfo.Address;
            }
            if (gameMetaData?.ServerInfo?.Port > 0)
            {
                metaData.ServerPort = gameMetaData.ServerInfo.Port.ToString();
            }
            if (gameMetaData?.ServerInfo?.GameHandle > 0)
            {
                metaData.GameHandle = gameMetaData.ServerInfo.GameHandle.ToString();
            }
            if (gameMetaData?.ServerInfo?.ClientHandle > 0)
            {
                metaData.ClientHandle = gameMetaData.ServerInfo.ClientHandle.ToString();
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.SpectatorPassword))
            {
                metaData.SpectatePassword = gameMetaData.ServerInfo.SpectatorPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.AuroraPassword))
            {
                metaData.AuroraPassword = gameMetaData.ServerInfo.AuroraPassword;
            }
            if (!string.IsNullOrEmpty(gameMetaData?.ServerInfo?.Version))
            {
                metaData.ServerVersion = gameMetaData.ServerInfo.Version;
            }
            if (game?.StartTime > DateTime.MinValue)
            {
                metaData.MatchStart = game.StartTime.ToString("o");
            }
            if (game != null)
            {
                metaData.GameType = game.GameType != GameType.GT_UNKNOWN ? (int)HearthDbConverter.GetBnetGameType(game.GameType, game.Format) : (int)HearthDbConverter.GetGameType(game.GameMode, game.Format);
            }
            if (game?.Format != null)
            {
                metaData.Format = (int)HearthDbConverter.GetFormatType(game.Format);
            }
            metaData.SpectatorMode    = game?.GameMode == GameMode.Spectator;
            metaData.Reconnected      = gameMetaData?.Reconnected ?? false;
            metaData.Resumable        = gameMetaData?.ServerInfo?.Resumable ?? false;
            metaData.FriendlyPlayerId = game?.FriendlyPlayerId > 0 ? game.FriendlyPlayerId : (playerInfo?.FriendlyPlayerId > 0 ? playerInfo?.FriendlyPlayerId : null);
            var scenarioId = game?.ScenarioId ?? gameMetaData?.ServerInfo?.Mission;

            if (scenarioId > 0)
            {
                metaData.ScenarioId = scenarioId;
            }
            var build = gameMetaData?.HearthstoneBuild ?? game?.HearthstoneBuild ?? (game != null ? BuildDates.GetByDate(game.StartTime) : null);

            if (build > 0)
            {
                metaData.HearthstoneBuild = build;
            }
            if (game?.BrawlSeasonId > 0)
            {
                metaData.BrawlSeason = game.BrawlSeasonId;
            }
            if (game?.RankedSeasonId > 0)
            {
                metaData.LadderSeason = game.RankedSeasonId;
            }
            return(metaData);
        }
        private BoardState GetBoardState()
        {
            if (Core.Game.PlayerEntity == null || Core.Game.OpponentEntity == null)
            {
                return(null);
            }

            int ZonePosition(Entity e) => e.GetTag(GameTag.ZONE_POSITION);
            int DbfId(Entity e) => e?.Card.DbfIf ?? 0;

            int[] SortedDbfIds(IEnumerable <Entity> entities) => entities.OrderBy(ZonePosition).Select(DbfId).ToArray();
            int HeroId(Entity playerEntity) => playerEntity.GetTag(GameTag.HERO_ENTITY);
            int WeaponId(Entity playerEntity) => playerEntity.GetTag(GameTag.WEAPON);
            Entity Find(Player p, int entityId) => p.PlayerEntities.FirstOrDefault(x => x.Id == entityId);
            Entity FindHeroPower(Player p) => p.PlayerEntities.FirstOrDefault(x => x.IsHeroPower && x.IsInPlay);

            BoardStateQuest Quest(Entity questEntity)
            {
                if (questEntity == null)
                {
                    return(null);
                }
                return(new BoardStateQuest
                {
                    DbfId = questEntity.Card.DbfIf,
                    Progress = questEntity.GetTag(GameTag.QUEST_PROGRESS),
                    Total = questEntity.GetTag(GameTag.QUEST_PROGRESS_TOTAL)
                });
            }

            var player   = Core.Game.Player;
            var opponent = Core.Game.Opponent;

            var deck         = DeckList.Instance.ActiveDeck;
            var games        = deck?.GetRelevantGames();
            var fullDeckList = new Dictionary <int, int>();

            if (DeckList.Instance.ActiveDeckVersion != null)
            {
                foreach (var card in DeckList.Instance.ActiveDeckVersion.Cards)
                {
                    fullDeckList[card.DbfIf] = card.Count;
                }
            }
            int FullCount(int dbfId) => fullDeckList == null ? 0 : fullDeckList.TryGetValue(dbfId, out var count) ? count : 0;

            var playerCardsDict = new List <int[]>();

            if (deck != null)
            {
                foreach (var card in player.GetPlayerCardList(false, false, false).Where(x => !x.Jousted))
                {
                    var inDeck = card.IsCreated ? 0 : FullCount(card.DbfIf);
                    playerCardsDict.Add(new [] { card.DbfIf, card.Count, inDeck });
                }
            }
            var format   = Core.Game.CurrentFormat ?? Format.Wild;
            var gameType = HearthDbConverter.GetBnetGameType(Core.Game.CurrentGameType, format);

            return(new BoardState
            {
                Player = new BoardStatePlayer
                {
                    Board = SortedDbfIds(player.Board.Where(x => x.IsMinion)),
                    Deck = new BoardStateDeck
                    {
                        Cards = playerCardsDict,
                        Name = deck?.Name,
                        Format = (deck?.IsWildDeck ?? false) ? FormatType.FT_WILD : FormatType.FT_STANDARD,
                        Hero = Database.GetHeroCardFromClass(deck?.Class)?.DbfIf ?? 0,
                        Wins = games?.Count(g => g.Result == GameResult.Win) ?? 0,
                        Losses = games?.Count(g => g.Result == GameResult.Loss) ?? 0,
                        Size = player.DeckCount
                    },
                    Secrets = SortedDbfIds(player.Secrets),
                    Hero = DbfId(Find(player, HeroId(Core.Game.PlayerEntity))),
                    Hand = new BoardStateHand
                    {
                        Cards = SortedDbfIds(player.Hand),
                        Size = player.HandCount
                    },
                    HeroPower = DbfId(FindHeroPower(player)),
                    Weapon = DbfId(Find(player, WeaponId(Core.Game.PlayerEntity))),
                    Quest = Quest(player.Quests.FirstOrDefault()),
                    Fatigue = Core.Game.PlayerEntity.GetTag(GameTag.FATIGUE)
                },
                Opponent = new BoardStatePlayer
                {
                    Board = SortedDbfIds(opponent.Board.Where(x => x.IsMinion)),
                    Deck = new BoardStateDeck
                    {
                        Size = opponent.DeckCount
                    },
                    Hand = new BoardStateHand
                    {
                        Size = opponent.HandCount
                    },
                    Hero = DbfId(Find(opponent, HeroId(Core.Game.OpponentEntity))),
                    HeroPower = DbfId(FindHeroPower(opponent)),
                    Weapon = DbfId(Find(opponent, WeaponId(Core.Game.OpponentEntity))),
                    Quest = Quest(opponent.Quests.FirstOrDefault()),
                    Fatigue = Core.Game.OpponentEntity.GetTag(GameTag.FATIGUE)
                },
                GameType = gameType,
            });
        }
        private void Update(int tier, IEnumerable <Race> availableRaces)
        {
            if (ActiveTier == tier)
            {
                return;
            }
            ActiveTier = tier;
            foreach (var item in _tierIcons)
            {
                item.Active = tier == item.Tier;
            }
            if (tier < 1 || tier > 6)
            {
                for (var i = 0; i < 6; i++)
                {
                    _tierIcons[i].SetFaded(false);
                }
                Groups.Clear();
                UnavailableTypes.UnavailableTypesVisibility = System.Windows.Visibility.Collapsed;
                return;
            }
            for (var i = 0; i < 6; i++)
            {
                _tierIcons[i].SetFaded(i != tier - 1);
            }

            var resort = false;

            var unavailableRaces = string.Join(", ", _db.Value.Races.Where(x => !availableRaces.Contains(x) && x != Race.INVALID && x != Race.ALL).Select(x => HearthDbConverter.RaceConverter(x)));

            UnavailableTypes.UnavailableTypesVisibility = System.Windows.Visibility.Visible;
            UnavailableTypes.UnavailableRacesText       = unavailableRaces;

            foreach (var race in _db.Value.Races)
            {
                var title = race == Race.INVALID ? "Other" : HearthDbConverter.RaceConverter(race);

                var cards = _db.Value.GetCards(tier, race).ToList();

                if (race == Race.MURLOC)
                {
                    cards = cards.Where(x => x.Id != NonBgMurlocTidehunterCardId).ToList();
                }
                if (race == Race.INVALID)
                {
                    cards.AddRange(GetUnavailableRaceCards(availableRaces).Where(x => x.TechLevel == tier));
                }
                if (cards.Count == 0)
                {
                    Groups.FirstOrDefault(x => x.Title == title)?.Hide();
                }
                else
                {
                    if (race == Race.ALL || race == Race.INVALID || availableRaces.Contains(race))
                    {
                        resort |= AddOrUpdateBgCardGroup(title, cards);
                    }
                }
            }

            if (resort)
            {
                var items = Groups.ToList()
                            .OrderBy(x => string.IsNullOrEmpty(x.Title) || x.Title == "Other")
                            .ThenBy(x => x.Title);
                foreach (var item in items)
                {
                    Groups.Remove(item);
                    Groups.Add(item);
                }
            }
        }
Esempio n. 11
0
        public static Deck Import(string cards, bool localizedNames = false)
        {
            CardClass[] AvailableClasses(Card x)
            {
                var card = HearthDb.Cards.GetFromDbfId(x.DbfIf);

                switch ((MultiClassGroup)card.Entity.GetTag(GameTag.MULTI_CLASS_GROUP))
                {
                case MultiClassGroup.GRIMY_GOONS:
                    return(new[] { CardClass.WARRIOR, CardClass.HUNTER, CardClass.PALADIN });

                case MultiClassGroup.JADE_LOTUS:
                    return(new[] { CardClass.ROGUE, CardClass.DRUID, CardClass.SHAMAN });

                case MultiClassGroup.KABAL:
                    return(new[] { CardClass.MAGE, CardClass.PRIEST, CardClass.WARLOCK });

                case MultiClassGroup.PALADIN_PRIEST:
                    return(new[] { CardClass.PALADIN, CardClass.PRIEST });

                case MultiClassGroup.PRIEST_WARLOCK:
                    return(new[] { CardClass.PRIEST, CardClass.WARLOCK });

                case MultiClassGroup.WARLOCK_DEMONHUNTER:
                    return(new[] { CardClass.WARLOCK, CardClass.DEMONHUNTER });

                case MultiClassGroup.HUNTER_DEMONHUNTER:
                    return(new[] { CardClass.HUNTER, CardClass.DEMONHUNTER });

                case MultiClassGroup.DRUID_HUNTER:
                    return(new[] { CardClass.DRUID, CardClass.HUNTER });

                case MultiClassGroup.DRUID_SHAMAN:
                    return(new[] { CardClass.DRUID, CardClass.SHAMAN });

                case MultiClassGroup.MAGE_SHAMAN:
                    return(new[] { CardClass.MAGE, CardClass.SHAMAN });

                case MultiClassGroup.MAGE_ROGUE:
                    return(new[] { CardClass.MAGE, CardClass.ROGUE });

                case MultiClassGroup.ROGUE_WARRIOR:
                    return(new[] { CardClass.ROGUE, CardClass.WARRIOR });

                case MultiClassGroup.PALADIN_WARRIOR:
                    return(new[] { CardClass.PALADIN, CardClass.WARRIOR });

                default:
                    return(new[] { card.Class });
                }
            }

            try
            {
                var deck  = new Deck();
                var lines = cards.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
                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);
                    }
                    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.Replace("’", "'"), localizedNames);
                    if (string.IsNullOrEmpty(card?.Name) || card.Id == Database.UnknownCardId)
                    {
                        continue;
                    }
                    card.Count = count;

                    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);
                    }
                }
                var deckClass = deck.Cards
                                .Where(x => x.DbfIf != 0)
                                .Select(AvailableClasses)
                                .Where(x => x.Length > 1 || x[0] != CardClass.NEUTRAL)
                                .Aggregate((a, b) => a.Concat(b).GroupBy(x => x).Where(x => x.Count() > 1).Select(x => x.Key).ToArray());
                if (deckClass.Length > 1)
                {
                    Log.Warn("Could not identify a class for this deck. Found multiple potential classes: " + string.Join(", ", deckClass.Select(HearthDbConverter.ConvertClass)));
                    return(null);
                }
                else if (deckClass.Length == 0)
                {
                    Log.Warn("Could not identify a class for this deck. Found conflicting classes.");
                    return(null);
                }
                else
                {
                    deck.Class = HearthDbConverter.ConvertClass(deckClass[0]);
                    return(deck);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(null);
            }
        }