public void Handle(string logLine, IHsGameState gameState, IGame game)
        {
            var match = HsLogReaderConstants.ExistingHeroRegex.Match(logLine);

            if (match.Success)
            {
                game.NewArenaDeck(match.Groups["id"].Value);
            }
            else
            {
                match = HsLogReaderConstants.ExistingCardRegex.Match(logLine);
                if (match.Success)
                {
                    game.NewArenaCard(match.Groups["id"].Value);
                }
                else
                {
                    match = HsLogReaderConstants.NewChoiceRegex.Match(logLine);
                    if (match.Success)
                    {
                        if (GameV2.GetHeroNameFromId(match.Groups["id"].Value, false) != null)
                        {
                            game.NewArenaDeck(match.Groups["id"].Value);
                        }
                        else
                        {
                            game.NewArenaCard(match.Groups["id"].Value);
                        }
                    }
                }
            }
        }
        public void Handle(string logLine, IHsGameState gameState)
        {
            if (HsLogReaderConstants.CardMovementRegex.IsMatch(logLine))
            {
                var match = HsLogReaderConstants.CardMovementRegex.Match(logLine);

                var id   = match.Groups["Id"].Value.Trim();
                var from = match.Groups["from"].Value.Trim();
                var to   = match.Groups["to"].Value.Trim();

                if (id.Contains("HERO") || (id.Contains("NAX") && id.Contains("_01")) || id.StartsWith("BRMA"))
                {
                    if (!from.Contains("PLAY"))
                    {
                        if (to.Contains("FRIENDLY"))
                        {
                            gameState.GameHandler.SetPlayerHero(GameV2.GetHeroNameFromId(id, false));
                        }
                        else if (to.Contains("OPPOSING"))
                        {
                            gameState.GameHandler.SetOpponentHero(GameV2.GetHeroNameFromId(id, false));
                        }
                    }
                }
            }
        }
        public void TestHeroSkins()
        {
            var Alleria = GameV2.GetHeroNameFromId("HERO_05a");

            Assert.AreEqual("Hunter", Alleria);

            var AlleriaPower = GameV2.GetCardFromId("DS1h_292_H1");

            Assert.AreEqual("Steady Shot", AlleriaPower.Name);
        }
        public void Handle(string logLine, IHsGameState gameState, IGame game)
        {
            var match = HsLogReaderConstants.ExistingHeroRegex.Match(logLine);

            if (match.Success)
            {
                game.NewArenaDeck(match.Groups["id"].Value);
            }
            else
            {
                match = HsLogReaderConstants.ExistingCardRegex.Match(logLine);
                if (match.Success)
                {
                    game.NewArenaCard(match.Groups["id"].Value);
                }
                else
                {
                    match = HsLogReaderConstants.NewChoiceRegex.Match(logLine);
                    if (match.Success)
                    {
                        if (GameV2.GetHeroNameFromId(match.Groups["id"].Value, false) != null)
                        {
                            game.NewArenaDeck(match.Groups["id"].Value);
                        }
                        else
                        {
                            var cardId = match.Groups["id"].Value;
                            var timeSinceLastChoice = DateTime.Now.Subtract(_lastChoice).Milliseconds;

                            if (_lastChoiceId == cardId && timeSinceLastChoice < 1000)
                            {
                                Logger.WriteLine(string.Format("Card with the same ID ({0}) was chosen less {1} ms ago. Ignoring.", cardId, timeSinceLastChoice));
                                return;
                            }

                            game.NewArenaCard(cardId);

                            _lastChoice   = DateTime.Now;
                            _lastChoiceId = cardId;
                        }
                    }
                }
            }
        }
        public static string SaveToDisk()
        {
            try
            {
                if (!Points.Any())
                {
                    return(null);
                }
                ResolveZonePos();
                ResolveCardIds();
                RemoveObsoletePlays();

                var player     = Points.Last().Data.First(x => x.IsPlayer);
                var opponent   = Points.Last().Data.First(x => x.HasTag(GAME_TAG.PLAYER_ID) && !x.IsPlayer);
                var playerHero =
                    Points.Last()
                    .Data.First(
                        x =>
                        !string.IsNullOrEmpty(x.CardId) && x.CardId.Contains("HERO") &&
                        x.IsControlledBy(player.GetTag(GAME_TAG.CONTROLLER)));
                var opponentHero =
                    Points.Last()
                    .Data.FirstOrDefault(
                        x =>
                        !string.IsNullOrEmpty(x.CardId) && x.CardId.Contains("HERO") &&
                        x.IsControlledBy(opponent.GetTag(GAME_TAG.CONTROLLER)));
                if (opponentHero == null)
                {
                    //adventure bosses
                    opponentHero =
                        Points.Last()
                        .Data.First(
                            x =>
                            !string.IsNullOrEmpty(x.CardId) &&
                            ((x.CardId.StartsWith("NAX") && x.CardId.Contains("_01")) || x.CardId.StartsWith("BRMA")) &&
                            GameV2.GetHeroNameFromId(x.CardId) != null);

                    ResolveOpponentName(GameV2.GetHeroNameFromId(opponentHero.CardId));
                }

                var fileName = string.Format("{0}({1}) vs {2}({3}) {4}", player.Name, GameV2.GetHeroNameFromId(playerHero.CardId), opponent.Name,
                                             GameV2.GetHeroNameFromId(opponentHero.CardId), DateTime.Now.ToString("HHmm-ddMMyy"));


                if (!Directory.Exists(Config.Instance.ReplayDir))
                {
                    Directory.CreateDirectory(Config.Instance.ReplayDir);
                }
                var path = Helper.GetValidFilePath(Config.Instance.ReplayDir, fileName, ".hdtreplay");
                using (var ms = new MemoryStream())
                {
                    using (var archive = new ZipArchive(ms, ZipArchiveMode.Create, true))
                    {
                        var json = archive.CreateEntry("replay.json");

                        using (var stream = json.Open())
                            using (var sw = new StreamWriter(stream))
                                sw.Write(JsonConvert.SerializeObject(Points));

                        if (Config.Instance.SaveHSLogIntoReplay)
                        {
                            var hsLog = archive.CreateEntry("output_log.txt");

                            using (var logStream = hsLog.Open())
                                using (var swLog = new StreamWriter(logStream))
                                    GameV2.HSLogLines.ForEach(swLog.WriteLine);
                        }
                    }

                    using (var fileStream = new FileStream(path, FileMode.Create))
                    {
                        ms.Seek(0, SeekOrigin.Begin);
                        ms.CopyTo(fileStream);
                    }
                }
                return(fileName + ".hdtreplay");
            }
            catch (Exception e)
            {
                Logger.WriteLine(e.ToString(), "ReplayMaker");
                return(null);
            }
        }