Example #1
0
        private static EncounterCount ReadCounts(InventoryPouch pouch)
        {
            var counts = new EncounterCount();

            foreach (var ball in pouch.Items)
            {
                counts.SetCount(ball.Index, ball.Count);
            }
            return(counts);
        }
Example #2
0
        public async Task SetLastUsedBall(Ball ball, CancellationToken token)
        {
            if (ball >= Ball.Fast && ball <= Ball.Beast)
            {
                var apriData = BitConverter.GetBytes(EncounterCount.BallIndex((int)ball));
                await Connection.WriteBytesAsync(apriData, LastUsedBallOffset, token).ConfigureAwait(false);

                return;
            }

            var data = BitConverter.GetBytes((int)ball);
            await Connection.WriteBytesAsync(data, LastUsedBallOffset, token).ConfigureAwait(false);
        }
Example #3
0
        private async Task CheckPokeBallCount(CancellationToken token)
        {
            if (Hub.Config.StopConditions.CatchEncounter)
            {
                Log("Checking Poké Ball count...");
                pouchData = await Connection.ReadBytesAsync(PokeBallOffset, 116, Config.ConnectionType, token).ConfigureAwait(false);

                var counts = EncounterCount.GetBallCounts(pouchData);
                catchCount = counts.PossibleCatches(Ball.Master);

                if (catchCount == 0)
                {
                    Log("Insufficient Master Ball count. Please obtain at least one before starting.");
                    return;
                }
            }
        }
Example #4
0
        private async Task WalkInLine(CancellationToken token)
        {
            if (hub.Config.Encounter.CatchEncounter && !hub.Config.Encounter.StrongSpawn)
            {
                Log("Checking Poké Ball count...");
                pouchData = await Connection.ReadBytesAsync(PokeBallOffset, 116, token).ConfigureAwait(false);

                var counts = EncounterCount.GetBallCounts(pouchData);
                catchCount = counts.PossibleCatches(Ball.Master);

                if (catchCount == 0)
                {
                    Log("Insufficient Master Balls. Please obtain at least one before starting.");
                    return;
                }
            }

            while (!token.IsCancellationRequested)
            {
                if (hub.Config.Encounter.StrongSpawn)
                {
                    await StrongSpawn(token).ConfigureAwait(false);
                }

                var attempts = await StepUntilEncounter(token).ConfigureAwait(false);

                if (attempts < 0) // aborted
                {
                    continue;
                }

                Log($"Encounter found after {attempts} attempts! Checking details...");

                // Reset stick while we wait for the encounter to load.
                await ResetStick(token).ConfigureAwait(false);

                var pk = await ReadPokemon(WildPokemonOffset, token).ConfigureAwait(false);

                if (pk.Species == 0)
                {
                    Log("Invalid data detected. Restarting loop.");

                    // Flee and continue looping.
                    while (await IsInBattle(token).ConfigureAwait(false))
                    {
                        await FleeToOverworld(token).ConfigureAwait(false);
                    }
                    continue;
                }

                encounterCount++;
                Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}");
                Counts.AddCompletedEncounters();
                Counts.AddEncounteredSpecies(pk);

                if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
                {
                    DumpPokemon(DumpSetting.DumpFolder, "encounters", pk);
                }

                // Offsets are flickery so make sure we see it 3 times.
                for (int i = 0; i < 3; i++)
                {
                    await ReadUntilChanged(BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false);
                }

                if (StopCondition(pk))
                {
                    if (hub.Config.CaptureVideoClip)
                    {
                        await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false);
                    }

                    if (hub.Config.Encounter.CatchEncounter && !hub.Config.Encounter.StrongSpawn)
                    {
                        await SetLastUsedBall(Ball.Master, token).ConfigureAwait(false);

                        Log($"Result found! Attempting to catch...");
                        await CatchWildPokemon(pk, token).ConfigureAwait(false);

                        if (!hub.Config.Encounter.InjectPokeBalls && encounterCount != 0 && encounterCount % catchCount == 0)
                        {
                            return;
                        }

                        await WalkInLine(token).ConfigureAwait(false);
                    }

                    Log($"{Ping}Result found! Stopping routine execution; restart the bot(s) to search again.");
                    return;
                }

                Log("Running away...");
                while (await IsInBattle(token).ConfigureAwait(false) && !hub.Config.Encounter.StrongSpawn)
                {
                    await FleeToOverworld(token).ConfigureAwait(false);
                }
            }
        }