Пример #1
0
        private async Task Overworld(CancellationToken token, bool birds = false)
        {
            GameVersion version = await LGWhichGameVersion(token).ConfigureAwait(false);

            List <int[]> movementslist = ParseMovements();
            bool         firstrun      = movementslist.Count > 0;
            Stopwatch    stopwatch     = new Stopwatch();
            uint         prev          = 0;
            uint         newspawn;
            uint         catchcombo;
            uint         speciescombo;
            int          i              = 0;
            bool         freeze         = false;
            bool         searchforshiny = Hub.Config.LGPE_OverworldScan.OnlyShiny;
            bool         found;

            if (movementslist.Count > 0)
            {
                Log($"{Environment.NewLine}----------------------------------------{Environment.NewLine}" +
                    $"ATTENTION{Environment.NewLine}Any wild battles will broke the movement routine, resulting in the pg moving to unwanted areas!{Environment.NewLine}" +
                    $"----------------------------------------{Environment.NewLine}" +
                    $"ATTENTION{Environment.NewLine}Unexpected behaviour can occur if a Pokémon is detected while changing area. It is higlhy recommended to avoid that.{Environment.NewLine}" +
                    $"-----------------------------------------{Environment.NewLine}");
            }

            //Catch combo to increment spawn quality and shiny rate (Thanks to Lincoln-LM for the offsets)
            if ((int)Hub.Config.LGPE_OverworldScan.ChainSpecies > 0)
            {
                speciescombo = await LGReadSpeciesCombo(token).ConfigureAwait(false);

                if ((speciescombo != (uint)Hub.Config.LGPE_OverworldScan.ChainSpecies) && (Hub.Config.LGPE_OverworldScan.ChainSpecies != 0))
                {
                    Log($"Current catch combo being on {(speciescombo == 0 ? "None" : SpeciesName.GetSpeciesName((int)speciescombo, 2))}, changing to {Hub.Config.LGPE_OverworldScan.ChainSpecies}.");
                    await LGEditSpeciesCombo((uint)Hub.Config.LGPE_OverworldScan.ChainSpecies, token).ConfigureAwait(false);

                    speciescombo = await LGReadSpeciesCombo(token).ConfigureAwait(false);

                    Log($"Current catch combo being now on {(speciescombo == 0 ? "None" : SpeciesName.GetSpeciesName((int)speciescombo, 2))}.");
                }
            }

            if (Hub.Config.LGPE_OverworldScan.ChainCount > 0)
            {
                catchcombo = await LGReadComboCount(token).ConfigureAwait(false);

                if (catchcombo < (uint)Hub.Config.LGPE_OverworldScan.ChainCount)
                {
                    Log($"Current catch combo being {catchcombo}, incrementing to {Hub.Config.LGPE_OverworldScan.ChainCount}.");
                    await LGEditComboCount((uint)Hub.Config.LGPE_OverworldScan.ChainCount, token).ConfigureAwait(false);

                    catchcombo = await LGReadComboCount(token).ConfigureAwait(false);

                    Log($"Current catch combo being now {catchcombo}.");
                }
            }

            //Main Loop
            while (!token.IsCancellationRequested)
            {
                if (searchforshiny)
                {
                    await LGZaksabeast(token, version).ConfigureAwait(false);
                }

                //Main Loop
                while (!freeze && !token.IsCancellationRequested)
                {
                    if (await LGCountMilliseconds(Hub.Config, token).ConfigureAwait(false) > 0 || !searchforshiny)
                    {
                        //Force the Fortune Teller Nature value, value is reset at the end of the day
                        if (Hub.Config.LGPE_OverworldScan.SetFortuneTellerNature != Nature.Random && !await LGIsNatureTellerEnabled(token).ConfigureAwait(false))
                        {
                            await LGEnableNatureTeller(token).ConfigureAwait(false);
                            await LGEditWildNature(Hub.Config.LGPE_OverworldScan.SetFortuneTellerNature, token).ConfigureAwait(false);

                            Log($"Fortune Teller enabled, Nature set to {await LGReadWildNature(token).ConfigureAwait(false)}.");
                        }

                        //PG Movements. The routine need to continue and check the overworld spawns, cannot be stuck at changing stick position.
                        if (movementslist.Count > 0)
                        {
                            if (stopwatch.ElapsedMilliseconds >= movementslist.ElementAt(i)[2] || firstrun)
                            {
                                if (firstrun)
                                {
                                    firstrun = false;
                                }
                                await ResetStick(token).ConfigureAwait(false);
                                await SetStick(RIGHT, (short)(movementslist.ElementAt(i)[0]), (short)(movementslist.ElementAt(i)[1]), 0_001, token).ConfigureAwait(false);

                                i++;
                                if (i == movementslist.Count)
                                {
                                    i = 0;
                                }
                                stopwatch.Restart();
                            }
                        }

                        //Check is inside an unwanted encounter
                        if (await LGIsInCatchScreen(token).ConfigureAwait(false))
                        {
                            await EscapeWildEncounter(token).ConfigureAwait(false);
                        }

                        //Check new spawns
                        newspawn = BitConverter.ToUInt16(await Connection.ReadBytesAsync(LastSpawn, 2, token).ConfigureAwait(false), 0);
                        if (newspawn != prev)
                        {
                            if (newspawn != 0)
                            {
                                encounterCount++;
                                if (IsPKLegendary((int)newspawn))
                                {
                                    Counts.AddLGPELegendaryScans();
                                }
                                else
                                {
                                    Counts.AddLGPEOverworldScans();
                                }
                                Log($"New spawn ({encounterCount}): {newspawn} {SpeciesName.GetSpeciesName((int)newspawn, 4)}");
                            }
                            prev = newspawn;
                            if (!searchforshiny &&
                                ((!birds && (int)newspawn == (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies) ||
                                 (!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies == 0) ||
                                 (birds && ((int)newspawn == 144 || (int)newspawn == 145 || (int)newspawn == 146))))
                            {
                                await Click(X, 1_000, token).ConfigureAwait(false);
                                await Click(HOME, 1_000, token).ConfigureAwait(false);

                                if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag))
                                {
                                    Log($"<@{Hub.Config.Discord.UserTag}> stop conditions met, restart the bot(s) to search again.");
                                }
                                else
                                {
                                    Log("Stop conditions met, restart the bot(s) to search again.");
                                }
                                return;
                            }
                        }
                    }
                    else if (searchforshiny)
                    {
                        freeze = true;
                    }
                }

                await LGUnfreeze(token, version).ConfigureAwait(false);

                freeze   = false;
                newspawn = BitConverter.ToUInt16(await Connection.ReadBytesAsync(LastSpawn, 2, token).ConfigureAwait(false), 0);

                //Stop Conditions
                if (birds && ((int)newspawn == 144 || (int)newspawn == 145 || (int)newspawn == 146) && !token.IsCancellationRequested)
                {
                    found = true;
                }
                else if ((!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies > 0 && (int)newspawn == (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies) ||
                         (!birds && (int)Hub.Config.LGPE_OverworldScan.StopOnSpecies == 0))
                {
                    found = true;
                }
                else
                {
                    found = false;
                }

                encounterCount++;
                if (IsPKLegendary((int)newspawn))
                {
                    Counts.AddLGPELegendaryScans();
                }
                else
                {
                    Counts.AddLGPEOverworldScans();
                }

                if (!found && !token.IsCancellationRequested)
                {
                    Log($"New spawn ({encounterCount}): {newspawn} Shiny {SpeciesName.GetSpeciesName((int)newspawn, 4)}");
                }
                else if (found && !token.IsCancellationRequested)
                {
                    await ResetStick(token).ConfigureAwait(false);

                    if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag))
                    {
                        Log($"<@{Hub.Config.Discord.UserTag}> Shiny Target {SpeciesName.GetSpeciesName((int)newspawn, 4)} found!");
                    }
                    else
                    {
                        Log($"Shiny Target {SpeciesName.GetSpeciesName((int)newspawn, 4)} found!");
                    }
                    await Click(X, 1_000, token).ConfigureAwait(false);
                    await Click(HOME, 1_000, token).ConfigureAwait(false);

                    return;
                }
            }
            await ResetStick(token).ConfigureAwait(false);

            if (searchforshiny)
            {
                await LGUnfreeze(token, version).ConfigureAwait(false);
            }
        }