Пример #1
0
        private GameStart GetGameStart(BoardState boardState)
        {
            var format     = Core.Game.CurrentFormat ?? Format.Wild;
            var gameType   = HearthDbConverter.GetBnetGameType(Core.Game.CurrentGameType, format);
            var player     = Core.Game.MatchInfo?.LocalPlayer;
            var rank       = format == Format.Standard ? player?.StandardRank : player?.WildRank;
            var legendRank = format == Format.Standard ? player?.Standard.LegendRank : player?.Wild.LegendRank;

            return(new GameStart
            {
                Deck = boardState.Player.Deck,
                GameType = gameType,
                Rank = rank ?? 0,
                LegendRank = legendRank ?? 0
            });
        }
Пример #2
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
            });
        }
Пример #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);
        }
Пример #4
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);
        }
Пример #5
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,
            });
        }