Exemplo n.º 1
0
        public void AddCardTransfer(CardForTurn c)
        {
            if (CardTransfersByTurn.Count == 0)
            {
                FirstTurn = c.Player == PlayerEnum.Me ? FirstTurnEnum.Play : FirstTurnEnum.Draw;
            }

            if (CardTransfersByTurn.ContainsKey(c.Turn) == false)
            {
                CardTransfersByTurn.Add(c.Turn, new List <CardForTurn>());
            }

            CardTransfersByTurn[c.Turn].Add(c);
        }
Exemplo n.º 2
0
        public void AddResult(IMtgaOutputLogPartResult r)
        {
            //if (r.MatchId == "c84b04f4-16da-4abe-9968-4b7866176847") Debugger.Break();

            try
            {
                if (r is IgnoredResult || r is IgnoredMatchResult || r is UnknownResult || r is UnknownMatchResult)
                {
                    return;
                }

                //else if (r is MtgaOutputLogPartResultBase<string> resultNoJson)
                //{
                //    if (resultNoJson.Raw.Contains("MatchCompleted -> Disconnected"))
                //    {
                //        EndCurrentMatch();
                //    }
                //}

                else if (r is ITagMatchResult)
                {
                    //if (configApp.IsFeatureEnabled(ConfigAppFeatureEnum.ParseMatches) == false)
                    //    return;

                    if (r is MatchCreatedResult mc)
                    {
                        CreateMatch(mc);
                    }
                    //else if (r is DuelSceneGameStopResult gameStop)
                    else if (r is GameStateMessageResult gsm && gsm.Raw.gameStateMessage?.gameInfo?.stage == "GameStage_GameOver")
                    {
                        var winningTeamId = gsm.Raw.gameStateMessage.gameInfo.results.First().winningTeamId;
                        UpdateGame(winningTeamId);
                    }
                    //else if (r is DuelSceneSideboardingStopResult)
                    else if (r is ClientToMatchResult <PayloadEnterSideboardingReq> )
                    {
                        EndCurrentGame();
                        //CreateGame()
                    }
                    else if (r is MatchGameRoomStateChangedEventResult roomChanged)
                    {
                        if (roomChanged.Raw.gameRoomInfo.gameRoomConfig.reservedPlayers != null)
                        {
                            var opponentInfo = roomChanged.Raw.gameRoomInfo.gameRoomConfig.reservedPlayers.First(i => i.playerName != MyScreenName);
                            lastOpponentSystemId      = opponentInfo.systemSeatId;
                            OpponentNameWithTagNumber = opponentInfo.playerName;
                            CreateGame(roomChanged.LogDateTime, opponentInfo.systemSeatId, null);
                            //currentGameProgress.DeckUsed.Name = currentMatch.DeckUsed.Name;
                        }

                        if (roomChanged.Raw.gameRoomInfo.finalMatchResult != null)
                        {
                            EndCurrentMatch(roomChanged.Raw.gameRoomInfo.finalMatchResult);
                        }
                    }
                    else if (r is IntermissionReqResult intermission)
                    {
                        if (intermission.Raw.intermissionReq.result.reason == "ResultReason_Concede")
                        {
                            //currentGameProgress.Outcome = (intermission.Raw.intermissionReq.result.winningTeamId == currentGameProgress.systemSeatId) ? GameOutcomeEnum.Victory : GameOutcomeEnum.Defeat;
                            //EndCurrentGame();

                            var c = new CardForTurn
                            {
                                CardGrpId = default(int),
                                Player    = intermission.Raw.intermissionReq.result.winningTeamId == currentGameProgress.systemSeatId ? PlayerEnum.Opponent : PlayerEnum.Me,
                                Turn      = currentGameProgress.CurrentTurn,
                                Action    = CardForTurnEnum.Conceded,
                            };
                            currentGameProgress.AddCardTransfer(c);
                        }
                        else if (intermission.Raw.intermissionReq.result.reason == "ResultReason_Game" &&
                                 intermission.Raw.intermissionReq.result.result == "ResultType_Draw")
                        {
                            currentGameProgress.Outcome = GameOutcomeEnum.Draw;
                        }
                    }
                    else
                    {
                        UpdateMatch(r);
                    }
                }
                else if (r is AuthenticateResponseResult authenticateResponse)
                {
                    MyScreenName = authenticateResponse.Raw.authenticateResponse.screenName;
                    if (currentMatch != null)
                    {
                        currentMatch.StartDateTime = authenticateResponse.LogDateTime;
                    }
                }
                else
                {
                    AddResultLobby(r);
                }
            }
        void AnalyzeSingleZoneTransfer(ZoneTransfer zt)
        {
            var gameObject = gsm.Raw.gameStateMessage.gameObjects?.FirstOrDefault(i => i.instanceId == zt.instanceId);
            //if (gameObject != null)
            {
                var playerId = currentGameProgress.GetPlayerFromId(zt.instanceId);
                if (playerId == PlayerEnum.Unknown)
                {
                    // Cannot retrace the ids changes to the original card...probably because of summarized messages

                    if (gameObject != null)
                    {
                        if (gameObject.ownerSeatId == gameObject.controllerSeatId)
                        {
                            playerId = gameObject.ownerSeatId == gameObject.controllerSeatId ? (
                                gameObject.ownerSeatId == currentGameProgress.systemSeatId ? PlayerEnum.Me : PlayerEnum.Opponent
                                ) : PlayerEnum.Unknown;
                        }
                        else
                        {
                            //System.Diagnostics.Debugger.Break();
                            //Log.Error("OUTPUTLOG {outputLogError}. User {userId}, Match id {matchId}",
                            //    "Unknown zone transfer",

                            //    JsonConvert.SerializeObject(gsm));
                            Errors.Add(new OutputLogError(OutputLogErrorType.UnknownZoneTransfer, gsm.Timestamp));
                            return;
                        }
                    }
                    else
                    {
                        if (zt.zone_src.Player == zt.zone_dest.Player)
                        {
                            playerId = zt.zone_dest.Player;
                        }
                        else
                        {
                            //System.Diagnostics.Debugger.Break();
                            //Log
                            playerId = zt.zone_dest.Player;
                        }
                    }
                }

                var c = new CardForTurn
                {
                    CardGrpId = gameObject?.grpId ?? default(int),
                    Player    = playerId,
                    Turn      = currentGameProgress.CurrentTurn,
                };

                if (zt.zone_src.Name == "ZoneType_Library" && zt.zone_dest.Name == "ZoneType_Hand")
                {
                    c.Action = CardForTurnEnum.Drew;
                }
                else if (zt.zone_src.Name == "ZoneType_Hand" && (zt.zone_dest.Name == "ZoneType_Battlefield" || zt.zone_dest.Name == "ZoneType_Stack"))
                {
                    c.Action = CardForTurnEnum.Played;
                }
                else if (zt.zone_src.Name == "ZoneType_Hand" && zt.zone_dest.Name == "ZoneType_Graveyard")
                {
                    c.Action = CardForTurnEnum.Discarded;
                }

                else if (zt.zone_src.Name == "ZoneType_Library" && zt.zone_dest.Name == "ZoneType_Battlefield")
                {
                    c.Action = CardForTurnEnum.FromLibraryToBattlefield;
                }
                else if (zt.zone_src.Name == "ZoneType_Library" && zt.zone_dest.Name == "ZoneType_Exile")
                {
                    c.Action = CardForTurnEnum.FromLibraryToExile;
                }
                else if (zt.zone_src.Name == "ZoneType_Library" && zt.zone_dest.Name == "ZoneType_Graveyard")
                {
                    c.Action = CardForTurnEnum.FromLibraryToGraveyard;
                }

                else if (zt.zone_src.Name == "ZoneType_Battlefield" && (zt.zone_dest.Name == "ZoneType_Graveyard" || zt.zone_dest.Name == "ZoneType_Exile"))
                {
                    c.Action = CardForTurnEnum.PermanentRemoved;
                }

                else if (zt.zone_src.Name == "ZoneType_Stack" && (zt.zone_dest.Name == "ZoneType_Battlefield" || zt.zone_dest.Name == "ZoneType_Graveyard"))
                {
                    c.Action = CardForTurnEnum.SpellResolved;
                }

                else if (zt.zone_src.Name == "ZoneType_Graveyard" && zt.zone_dest.Name == "ZoneType_Battlefield")
                {
                    c.Action = CardForTurnEnum.FromGraveyardToBattlefield;
                }
                else if (zt.zone_src.Name == "ZoneType_Graveyard" && zt.zone_dest.Name == "ZoneType_Hand")
                {
                    c.Action = CardForTurnEnum.FromGraveyardToHand;
                }
                else if (zt.zone_src.Name == "ZoneType_Graveyard" && zt.zone_dest.Name == "ZoneType_Stack")
                {
                    c.Action = CardForTurnEnum.FromGraveyardToStack;
                }
                else if (zt.zone_src.Name == "ZoneType_Graveyard" && zt.zone_dest.Name == "ZoneType_Exile")
                {
                    c.Action = CardForTurnEnum.FromGraveyardToExile;
                }

                else if (zt.zone_src.Name == "ZoneType_Exile" && zt.zone_dest.Name == "ZoneType_Stack")
                {
                    c.Action = CardForTurnEnum.FromExileToStack;
                }
                else if (zt.zone_src.Name == "ZoneType_Exile" && zt.zone_dest.Name == "ZoneType_Battlefield")
                {
                    c.Action = CardForTurnEnum.FromExileToBattlefield;
                }
                else if (zt.zone_src.Name == "ZoneType_Exile" && zt.zone_dest.Name == "ZoneType_Hand")
                {
                    c.Action = CardForTurnEnum.FromExileToHand;
                }

                if (c.Player == 0 /* || c.Turn == 14*/)
                {
                    //System.Diagnostics.Debugger.Break();
                    Errors.Add(new OutputLogError(OutputLogErrorType.PlayerZero, gsm.Timestamp));
                    return;
                }

                /*if (c.Action == CardForTurnEnum.Unknown)
                 * {
                 *  Errors.Add(new OutputLogError(OutputLogErrorType.CardForTurnUnknown, gsm.Timestamp));
                 *  return;
                 * }
                 * else*/
                if (c.Action == CardForTurnEnum.Drew || c.Action == CardForTurnEnum.Played || c.Action == CardForTurnEnum.Discarded)
                {
                    if (dictAllCards.ContainsKey(c.CardGrpId))
                    {
                        currentGameProgress.AddCardTransfer(c);
                    }
                }
            }
            //else
            //if (gameObject == null)
            //{
            //    System.Diagnostics.Debugger.Break();
            //}
        }