Exemplo n.º 1
0
        private async Task Skipper(CancellationToken token)
        {
            DexRecSpecies[] dex = Settings.DexRecConditions.SpeciesTargets;
            DexRecLoc       loc = Settings.DexRecConditions.LocationTarget;
            DexRecSpecies   species;
            uint            offset = DexRecMon;
            string          log    = string.Empty;

            bool empty = dex.All(x => x == DexRecSpecies.None) && loc == DexRecLoc.None;

            Log("Starting DaySkipping to update recommendations! Ensure that Date/Time Sync is ON, and that when the menu is open the cursor is hovered over the Pokédex!");
            if (empty)
            {
                Log("No target set, skipping indefinitely.. When you see a species or location you want, stop the bot.");
            }

            while (!token.IsCancellationRequested)
            {
                Log("DaySkipping to update recommendations!");
                await DaySkip(token).ConfigureAwait(false);

                await Task.Delay(0_500, token).ConfigureAwait(false);

                Log("Checking Pokédex for current recommendations.");
                await Click(X, 1_000, token).ConfigureAwait(false);
                await Click(A, 5_000, token).ConfigureAwait(false);

                ulong currentlocation = BitConverter.ToUInt64(await Connection.ReadBytesAsync(DexRecLocation, 8, token).ConfigureAwait(false), 0);
                int   s = 0;
                do
                {
                    byte[] currentspecies = await SwitchConnection.ReadBytesAsync(offset, 2, token).ConfigureAwait(false);

                    species = (DexRecSpecies)BitConverter.ToUInt16(currentspecies.Slice(0, 2), 0);
                    if (species != 0)
                    {
                        log += $"\n - {species}";
                    }

                    if (!empty)
                    {
                        for (int d = 0; d < dex.Length; d++)
                        {
                            if (dex[d] == DexRecSpecies.None)
                            {
                                break;
                            }

                            if (species == dex[d])
                            {
                                Log($"Recommended species found: {species}!");
                                _ = loc == DexRecLoc.None;
                                return;
                            }
                        }
                    }

                    offset += 0x20;
                    s++;
                } while (s < 4);

                Log($"Current location: {(DexRecLoc)currentlocation}\nCurrent species: {log}");
                offset = DexRecMon;
                log    = $"";

                if (loc != DexRecLoc.None)
                {
                    Log($"Searching for location: {loc}.");
                    if ((ulong)loc == currentlocation)
                    {
                        Log($"Recommendation matches target location: {loc}.");
                        _ = loc == DexRecLoc.None;
                        return;
                    }
                }

                while (!await IsOnOverworld(Hub.Config, token).ConfigureAwait(false))
                {
                    await Click(B, 0_500, token).ConfigureAwait(false);
                }
            }
        }