private void HandleNewText(string newText) { MainWindowVM.UnSetProblem(ProblemsFlags.LogFileNotFound); MainWindowVM.SizeOfLogToSend = FileMonitor.LogContentToSend.Length; ICollection <IMtgaOutputLogPartResult> messages; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(newText ?? ""))) { messages = Reader.ProcessIntoMessagesAsync("local", ms).Result; } void GoHome() { MainWindowVM.SetMainWindowContext(WindowContext.Home); } var mustUpload = false; foreach (IMtgaOutputLogPartResult msg in messages) { switch (msg) { case UnknownResult _: case IgnoredResult _: continue; case DetailedLoggingResult detLogRes: MainWindowVM.SetProblem(ProblemsFlags.DetailedLogsDisabled, detLogRes.IsDetailedLoggingDisabled); break; case IResultCardPool msgCardPool: { var isDrafting = true; if (msg is GetEventPlayerCourseV2Result playerCourse) { GetEventPlayerCourseV2Raw payload = playerCourse.Raw.payload; if (payload.CurrentEventState == "PreMatch") { // Clear the drafting window SetCardsDraft(new DraftPickProgress(new int[0])); } isDrafting = payload.InternalEventName.Contains("Draft") || payload.InternalEventName.Contains("Sealed"); } if (isDrafting) { // Refresh the drafting window to show whole card pool SetCardsDraft(new DraftPickProgress(msgCardPool.CardPool)); MainWindowVM.SetMainWindowContext(WindowContext.Drafting); } break; } case IResultDraftPick msgDraftPack when msgDraftPack.Raw.payload.draftPack != null: { // Refresh the drafting window to show the new picks var draftInfo = Mapper.Map <DraftPickProgress>(msgDraftPack.Raw.payload); SetCardsDraft(draftInfo); break; } case LogInfoRequestResult logInfoContainer: { var logInfo = JsonConvert.DeserializeObject <LogInfoRequestInnerRaw>(logInfoContainer.Raw.request); if ([email protected] == "DuelScene.EndOfMatchReport" || [email protected]("Client changed scenes to Home")) { //// Trigger to upload the stored log content //UploadLogFragment(); mustUpload = true; } // Change MainWindowContext Params prms = logInfo.@params; 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 != "deck builder") { GoHome(); } break; case "DuelScene.EndOfMatchReport": GoHome(); InGameTracker.Reset(); MainWindowVM.SetInMatchStateBuffered(InGameTracker.State); break; } break; } case StateChangedResult stateChanged: { if (msg.Part.Contains("\"new\":8}")) { GoHome(); } break; } //else if (msg is EventClaimPrizeResult claimPrize) //{ // // Clear the drafting window // SetCardsDraft(new int[0]); //} case MatchCreatedResult matchCreated: MainWindowVM.SetMainWindowContext(WindowContext.Playing); break; case GetPlayerInventoryResult _: case GetPlayerCardsResult _: case PostMatchUpdateResult _: case RankUpdatedResult _: case GetCombinedRankInfoResult _: case InventoryUpdatedResult _: mustUpload = true; break; } if (MainWindowVM.MainWindowContext == WindowContext.Playing) { InGameTracker.ProcessMessage(msg); MainWindowVM.SetInMatchStateBuffered(InGameTracker.State); } } if (mustUpload) { UploadLogFragment(); } }
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(); } }