Пример #1
0
        //private void InitDraftHelperForHumanDraft(string set)
        //{
        //    RefreshCustomRatingsFromServer();
        //    ViewModel.SetMainWindowContext(WindowContext.Drafting);
        //    DraftHelperRunner.Set = set;
        //    ViewModel.DraftingVM.ResetDraftPicks(DraftHelperRunner.Set, true, Guid.NewGuid().ToString());
        //}

        private void SetCardsDraft(DraftPickProgress draftInfo, bool isHuman = false)
        {
            var cardPool = draftInfo?.DraftPack;

            if (cardPool == null)
            {
                return;
            }

            var collection = ViewModel.Collection.Cards
                             .Where(i => i.IdArena != 0)
                             .ToDictionary(i => i.IdArena, i => i.Amount);

            var draftingInfo = DraftHelper.GetDraftPicksForCards(
                cardPool,
                draftInfo.PickedCards,
                ViewModel.Config.LimitedRatingsSource,
                collection,
                RareDraftingInfo,
                ViewModel.DraftingVM.CustomRatingsBySetThenCardName);

            ViewModel.DraftingVM.SetCardsDraftBuffered(draftInfo, draftingInfo, isHuman);

            if (draftInfo.PickNumber == 0)
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() => DraftingControl.HideCardListWheeled()));
                ViewModel.DraftingVM.ShowCardListThatDidNotWheel = false;
            }
        }
        private void SetCardsDraft(DraftPickProgress draftInfo)
        {
            var cardPool = draftInfo?.DraftPack;

            if (cardPool == null)
            {
                return;
            }

            var draftingInfo = DraftHelper.GetDraftPicksForCards(
                MainWindowVM.Account.MtgaHelperUserId,
                cardPool,
                ConfigModel.ShowLimitedRatingsSource,
                MainWindowVM.Collection.Cards.Where(i => i.IdArena != 0).ToDictionary(i => i.IdArena, i => i.Amount),
                RareDraftingInfo);

            MainWindowVM.SetCardsDraftBuffered(draftInfo, draftingInfo);
        }
        internal void SetCardsDraftBuffered(DraftPickProgress draftProgress, ICollection <CardDraftPickWpf> ratingsInfo)
        {
            lock (lockCardsDraft)
            {
                // Manage the packs history, this is all for the "previously seen cards that didn't wheel" feature
                // (this if condition is only there to manage the case where the ratings source was changed, thus triggering an update here
                //  and we don't want that to affect the history)
                if (draftProgress.PackNumber != CurrentDraftPickProgress.PackNumber || draftProgress.PickNumber != CurrentDraftPickProgress.PickNumber)
                {
                    CardsThatDidntWheel = new int[0];

                    // Reset the progress history if it is a new draft
                    if (draftProgress.DraftId != default(string) && draftPicksHistory.Count > 0 && draftProgress.DraftId != draftPicksHistory[0].DraftId)
                    {
                        draftPicksHistory = new List <DraftPickProgress> {
                            draftProgress
                        };
                    }

                    // Try to find the original pack that wheeled to extract the cards that didn't wheel
                    var originalPack = draftPicksHistory.FirstOrDefault(i => i.PackNumber == draftProgress.PackNumber && i.PickNumber == draftProgress.PickNumber - POD_SIZE);
                    if (originalPack != null)
                    {
                        CardsThatDidntWheel = originalPack.DraftPack.Where(i => draftProgress.DraftPack.Contains(i) == false).ToArray();
                        var packFollowing = draftPicksHistory.FirstOrDefault(i => i.PackNumber == originalPack.PackNumber && i.PickNumber == originalPack.PickNumber + 1);
                        if (packFollowing != null)
                        {
                            CardChosenThatDidntWheel = Mapper.Map <Card>(packFollowing.PickedCards.Last()).name;
                        }
                    }

                    draftPicksHistory.Add(draftProgress);
                }

                draftInfoBuffered.DraftProgress      = draftProgress;
                draftInfoBuffered.CardsDraftBuffered = ratingsInfo;

                updateCardsDraftBuffered = true;
            }
        }
Пример #4
0
        private void HandleNewText(string newText)
        {
            ViewModel.SetProblem(ProblemsFlags.LogFileNotFound, false);
            ViewModel.SizeOfLogToSend = FileMonitor.LogContentToSend.Length;

            ICollection <IMtgaOutputLogPartResult> messages;

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(newText ?? "")))
            {
                messages = Reader.ProcessIntoMessagesAsync("local", ms).Result;
            }

            void GoHome()
            {
                ViewModel.SetMainWindowContext(WindowContext.Home);
            }

            var mustUpload = false;

            foreach (IMtgaOutputLogPartResult msg in messages)
            {
                switch (msg)
                {
                case UnknownResult _:
                case IgnoredResult _:
                    continue;

                case DetailedLoggingResult detLogRes:
                    ViewModel.SetProblem(ProblemsFlags.DetailedLogsDisabled, detLogRes.IsDetailedLoggingDisabled);
                    break;

                case IResultCardPool msgCardPool:
                {
                    var isLimitedCardPool = true;
                    if (msg is GetEventPlayerCourseV2Result playerCourse)
                    {
                        // Set the set drafted for the Human DraftHelper
                        string set        = null;
                        var    regexMatch = Regex.Match(playerCourse.Raw.payload.InternalEventName, "(?:Draft|Sealed)_(.*?)_");
                        if (regexMatch.Success)
                        {
                            //DraftHelperRunner.Set = regexMatch.Groups[1].Value;
                            set = regexMatch.Groups[1].Value;
                        }

                        GetEventPlayerCourseV2Raw payload = playerCourse.Raw.payload;
                        if (payload.CurrentEventState == "PreMatch")
                        {
                            RefreshCustomRatingsFromServer();
                            ViewModel.DraftingVM.ResetDraftPicks(set, false);
                            //ViewModel.DraftingVM.ResetDraftPicks(DraftHelperRunner.Set, false);
                            ////// TO SIMULATE HUMAN DRAFTING FROM A QUICKDRAFT LOG
                            ////MainWindowVM.DraftingVM.ResetDraftPicks(DraftHelperRunner.Set, true, Guid.NewGuid().ToString());
                        }

                        isLimitedCardPool = payload.InternalEventName.Contains("Draft") || payload.InternalEventName.Contains("Sealed");
                    }

                    if (isLimitedCardPool)
                    {
                        ViewModel.CheckAndDownloadThumbnails(msgCardPool.CardPool);

                        // Refresh the drafting window to show whole card pool
                        ViewModel.DraftingVM.ShowGlobalMTGAHelperSays = false;
                        SetCardsDraft(new DraftPickProgress(msgCardPool.CardPool));
                        ViewModel.SetMainWindowContext(WindowContext.Drafting);
                    }

                    break;
                }

                case IResultDraftPick msgDraftPack when msgDraftPack.Raw.payload.draftPack != null:
                {
                    ViewModel.SetMainWindowContext(WindowContext.Drafting);

                    // Refresh the drafting window to show the new picks
                    ViewModel.DraftingVM.ShowGlobalMTGAHelperSays = true;
                    var draftInfo = mapper.Map <DraftPickProgress>(msgDraftPack.Raw.payload);
                    SetCardsDraft(draftInfo);
                    //// TO SIMULATE HUMAN DRAFTING FROM A QUICKDRAFT LOG
                    //SetCardsDraft(draftInfo, true);
                    break;
                }

                case LogInfoRequestResult logInfoContainer:
                {
                    var prms = logInfoContainer.RequestParams;
                    if (prms.messageName == "DuelScene.EndOfMatchReport" || prms.humanContext.Contains("Client changed scenes to Home"))
                    {
                        //// Trigger to upload the stored log content
                        //UploadLogFragment();
                        mustUpload = true;
                    }

                    // Change MainWindowContext
                    switch (prms.messageName)
                    {
                    case "Client.SceneChange":
                        dynamic context = prms.payloadObject.context?.ToString();               // SceneChange_PayloadObject
                        if (prms.humanContext.Contains("Client changed scene") &&
                            context.Contains("Draft") == false &&
                            context.Contains("Opening sealed boosters") == false &&
                            context.Contains("Sealed") == false &&
                            context != "deck builder")
                        {
                            GoHome();
                        }
                        break;

                    case "DuelScene.EndOfMatchReport":
                        GoHome();
                        InGameTracker.Reset();
                        ViewModel.SetInMatchStateBuffered(InGameTracker.State);
                        break;
                    }

                    break;
                }

                case StateChangedResult stateChanged:
                {
                    if (stateChanged.SignifiesMatchEnd)
                    {
                        GoHome();
                    }
                    break;
                }

                case GetActiveEventsV2Result getActiveEvents:
                    GoHome();
                    break;

                case MatchCreatedResult _:
                    ViewModel.SetMainWindowContext(WindowContext.Playing);
                    break;

                case ConnectRespResult connectResp:
                    var distinctCards = connectResp.Raw.connectResp.deckMessage.deckCards.Union(connectResp.Raw.connectResp.deckMessage.sideboardCards ?? new List <int>()).Distinct().ToArray();
                    ViewModel.CheckAndDownloadThumbnails(distinctCards);
                    ViewModel.SetMainWindowContext(WindowContext.Playing);
                    break;

                case JoinPodmakingResult joinPodmaking:
                    var txt   = joinPodmaking.RequestParams.queueId;
                    var match = Regex.Match(txt, @"Draft_(.*?)_\d+");
                    if (match.Success)
                    {
                        var set = match.Groups[2].Value;

                        //InitDraftHelperForHumanDraft(set);
                        RefreshCustomRatingsFromServer();
                        ViewModel.DraftingVM.ResetDraftPicks(set, false);
                    }
                    break;

                //case MakeHumanDraftPickResult humanDraftPick:
                //    ViewModel.SetMainWindowContext(WindowContext.Drafting);
                //    var cardId = humanDraftPick.RequestParams.cardId;
                //    DraftingControl.PickCard(cardId);
                //    break;

                case DraftNotifyResult draftNotify:
                    ViewModel.SetMainWindowContext(WindowContext.Drafting);

                    // Refresh the drafting window to show the new picks
                    ViewModel.DraftingVM.ShowGlobalMTGAHelperSays = true;
                    var info = new DraftPickProgress
                    {
                        DraftId    = draftNotify.Raw.draftId.ToString(),
                        PackNumber = draftNotify.Raw.SelfPack - 1,
                        PickNumber = draftNotify.Raw.SelfPick - 1,
                        DraftPack  = draftNotify.Raw.PackCards.Split(',').Select(i => int.Parse(i.Trim())).ToList(),
                    };
                    SetCardsDraft(info);
                    break;

                case GetPlayerInventoryResult _:
                case GetPlayerCardsResult _:
                case PostMatchUpdateResult _:
                //case RankUpdatedResult _:
                case GetCombinedRankInfoResult _:
                    mustUpload = true;
                    break;

                case InventoryUpdatedResult inventoryUpdated:
                    mustUpload = true;

                    var aetherizedCards = inventoryUpdated.Raw.payload.updates.LastOrDefault()?.aetherizedCards;
                    if (aetherizedCards != null && aetherizedCards.Any())
                    {
                        lastCardsAetherized = aetherizedCards.Select(i => i.grpId).ToArray();
                    }

                    break;

                case SceneChangeResult sceneChange:
                    if (sceneChange.Raw.toSceneName == "SealedBoosterOpen")
                    {
                        // Refresh the drafting window to show whole card pool
                        ViewModel.DraftingVM.ShowGlobalMTGAHelperSays = false;
                        SetCardsDraft(new DraftPickProgress(lastCardsAetherized));
                        ViewModel.SetMainWindowContext(WindowContext.Drafting);
                    }
                    break;
                }

                if (ViewModel.Context == WindowContext.Playing)
                {
                    InGameTracker.ProcessMessage(msg);
                    ViewModel.SetInMatchStateBuffered(InGameTracker.State);
                }
            }

            if (mustUpload)
            {
                //if (ViewModel.DraftingVM.DraftProgressHuman?.PickedCards?.Count >= 42)
                //{
                //    Log.Information("Must upload human draft:{NewLine}{humanDraft}", JsonConvert.SerializeObject(ViewModel.DraftingVM.DraftPicksHistory));
                //}

                UploadLogFragment();
            }
        }
Пример #5
0
        //internal void SetMainWindowContext(string newText, int logContentSize)
        //{
        //    SizeOfLogToSend = logContentSize;

        //    if (MainWindowContext != MainWindowContextEnum.Welcome)
        //    {
        //        if (newText.Contains("<== Draft.MakePick") || newText.Contains("<== Draft.DraftStatus"))
        //            MainWindowContext = MainWindowContextEnum.Drafting;
        //        //else if (newText.Contains("Client.SceneChange") || newText.Contains("Draft.Complete"))
        //        //    IsDrafting = false;

        //        if (newText.Contains("Event.MatchCreated"))
        //            MainWindowContext = MainWindowContextEnum.Playing;
        //        else if (newText.Contains("DuelScene.EndOfMatchReport"))
        //            MainWindowContext = MainWindowContextEnum.Home;
        //    }

        //    RaisePropertyChangedEvent(nameof(MainWindowContext));
        //}

        internal void SetCardsDraftBuffered(DraftPickProgress draftProgress, ICollection <CardDraftPickWpf> ratingsInfo)
        {
            DraftingVM.SetCardsDraftBuffered(draftProgress, ratingsInfo);
        }