Exemplo n.º 1
0
        private async void ParseTimerTick(object sender, object e)
        {
            List <DisplayPrime> notDetectedPrimePartsList = new List <DisplayPrime>();
            List <Task>         fetchTasks = new List <Task>();
            string text = string.Empty;

            parseTimer.Stop();

            WarframeNotDetected = false;
            WarframeNotFocus    = false;

            if (!Warframe.WarframeIsRunning())
            {
                WarframeNotDetected = true;
                WarframeProcess     = null;
                parseTimer.Start();
                return;
            }
            if (SkipNotFocus && !IsOnFocus())
            {
                WarframeNotFocus = true;
                parseTimer.Start();
                return;
            }

            try
            {
                text = await ScreenCapture.ParseTextAsync();

                text = text.ToLower(new System.Globalization.CultureInfo("en-US"));

                //Only use spellcheck if using English
                if (LocalizationManager.Language.ToLower(new System.Globalization.CultureInfo("en-US")) == "english")
                {
                    text = await Task.Run(() => SpellCheckOCR(text));
                }

                detectedPrimePartsList.Clear();

                foreach (var part in AllPrimePartsList)
                {
                    if (text.IndexOf(LocalizationManager.Localize(part.Prime.Name), StringComparison.InvariantCultureIgnoreCase) != -1)
                    {
                        part.Visible = true;
                        detectedPrimePartsList.Add(part);
                        fetchTasks.Add(FetchPlatTask(part));
                        fetchTasks.Add(FetchDucatTask(part));
                    }
                    else
                    {
                        notDetectedPrimePartsList.Add(part);
                    }
                }

                if (!ShowAllPrimes)
                {
                    if (notDetectedPrimePartsList.Count < AllPrimePartsList.Count)
                    {
                        //Only hide if we see at least one prime (let the old list persist until we need to refresh)
                        foreach (var part in notDetectedPrimePartsList)
                        {
                            part.Visible = false;
                        }
                    }
                }

                if (text.Contains(LocalizationManager.MissionSuccess.ToLower(new System.Globalization.CultureInfo("en-US"))) &&
                    lastMissionCompleteTime + TimeSpan.FromMinutes(1.0) > DateTime.Now &&
                    notDetectedPrimePartsList.Count < AllPrimePartsList.Count)
                {
#if DEBUG
                    Console.WriteLine("Mission Success");
#endif
                    OnMissionComplete();
                }

                if (text.Contains(LocalizationManager.SelectAReward.ToLower(new System.Globalization.CultureInfo("en-US"))) &&
                    notDetectedPrimePartsList.Count < AllPrimePartsList.Count)
                {
#if DEBUG
                    Console.WriteLine("Select a Reward");
#endif

                    if (RenderOverlay && !backgroundWorker.IsBusy)
                    {
                        StartRenderOverlayPrimes();
                        backgroundWorker.RunWorkerAsync();
                    }
                }
                else if (backgroundWorker.IsBusy)
                {
                    backgroundWorker.CancelAsync();
                }

                await Task.WhenAll(fetchTasks).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.Error.WriteLine("Error: " + ex.Message);
#endif
            }
            finally
            {
                parseTimer.Start();
            }
        }