Esempio n. 1
0
        private async void _parseTimer_Tick(object sender, object e)
        {
            _parseTimer.Stop();
            if (Warframe.WarframeIsRunning())
            {
                var text = await ScreenCapture.ParseTextAsync();

                var         hiddenPrimes        = new List <DisplayPrime>();
                List <Task> fetchPlatpriceTasks = new List <Task>();
                foreach (var p in PrimeItems)
                {
                    if (text.IndexOf(LocalizationManager.Localize(p.Prime.Name), StringComparison.InvariantCultureIgnoreCase) != -1)
                    {
                        p.Visible = true;
                        fetchPlatpriceTasks.Add(FetchPlatPriceTask(p));
                        fetchPlatpriceTasks.Add(FetchDucatValueTask(p));
                    }
                    else
                    {
                        hiddenPrimes.Add(p);
                    }
                }

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

                if (text.Contains(LocalizationManager.MissionSuccess) && _lastMissionComplete.AddMinutes(1) > DateTime.Now &&
                    PrimeItems.Count - hiddenPrimes.Count == 1)
                {
                    //Auto-record the selected reward if we detect a prime on the mission complete screen
                    _lastMissionComplete = DateTime.MinValue;
                    await Task.Run(() => PrimeItems.FirstOrDefault(p => p.Visible)?.AddCommand?.Execute());
                }

                if (text.Contains(LocalizationManager.SelectAReward) && PrimeItems.Count - hiddenPrimes.Count > 0)
                {
                    OnMissionComplete();
                }
                WarframeNotDetected = false;

                await Task.WhenAll(fetchPlatpriceTasks);
            }
            else
            {
                WarframeNotDetected = true;
            }
            _parseTimer.Start();
        }
Esempio n. 2
0
        private async void _parseTimer_Tick(object sender, object e)
        {
            _parseTimer.Stop();

            WarframeNotDetected = false;
            WarframeNotFocus    = false;

            List <DisplayPrime> hiddenPrimes     = new List <DisplayPrime>();
            List <Task>         fetchPricesTasks = new List <Task>();
            string text = string.Empty;

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

            try
            {
                text = await ScreenCapture.ParseTextAsync();

                text = await Task.Run(() => SpellCheckOCR(text));

                displayPrimes.Clear();

                foreach (var p in PrimeItems)
                {
                    if (text.IndexOf(LocalizationManager.Localize(p.Prime.Name), StringComparison.InvariantCultureIgnoreCase) != -1)
                    {
                        p.Visible = true;
                        displayPrimes.Add(p);
                        fetchPricesTasks.Add(FetchPlatPriceTask(p));
                        fetchPricesTasks.Add(FetchDucatPriceTask(p));
                    }
                    else
                    {
                        hiddenPrimes.Add(p);
                    }
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.Error.WriteLine("Error: " + ex.Message);
#endif
                _parseTimer.Start();
                return;
            }
            finally
            {
                if (!ShowAllPrimes)
                {
                    if (hiddenPrimes.Count < PrimeItems.Count)
                    {
                        //Only hide if we see at least one prime (let the old list persist until we need to refresh)
                        foreach (var p in hiddenPrimes)
                        {
                            p.Visible = false;
                        }
                    }
                }

                if (text.ToLower().Contains(LocalizationManager.MissionSuccess.ToLower()) && _lastMissionComplete.AddMinutes(1) > DateTime.Now &&
                    hiddenPrimes.Count < PrimeItems.Count)
                {
#if DEBUG
                    Console.WriteLine("Mission Success");
#endif
                    _lastMissionComplete = DateTime.MinValue;
                }

                if (text.ToLower().Contains(LocalizationManager.SelectAReward.ToLower()) && hiddenPrimes.Count < PrimeItems.Count)
                {
#if DEBUG
                    Console.WriteLine("Select a Reward");
#endif
                    OnMissionComplete();

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

                await Task.WhenAll(fetchPricesTasks);
            }

            _parseTimer.Start();
        }
        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();
            }
        }