protected override async Task MainLoop(CancellationToken token) { Log("Identifying trainer data of the host console."); await IdentifyTrainer(token).ConfigureAwait(false); var originalTextSpeed = await EnsureTextSpeedFast(token).ConfigureAwait(false); await SetCurrentBox(0, token).ConfigureAwait(false); Log("Checking destination slot..."); var existing = await GetBoxSlotQuality(InjectBox, InjectSlot, token).ConfigureAwait(false); if (existing.Quality != SlotQuality.Overwritable) { PrintBadSlotMessage(existing); return; } Log("Starting main EggBot loop."); Config.IterateNextRoutine(); var blank = new PK8(); while (!token.IsCancellationRequested && Config.NextRoutineType == PokeRoutineType.EggFetch) { // Walk a step left, then right => check if egg was generated on this attempt. // Repeat until an egg is generated. var attempts = await StepUntilEgg(token).ConfigureAwait(false); if (attempts < 0) // aborted { continue; } Log($"Egg available after {attempts} attempts! Clearing destination slot."); await SetBoxPokemon(blank, InjectBox, InjectSlot, token).ConfigureAwait(false); for (int i = 0; i < 4; i++) { await Click(A, 0_400, token).ConfigureAwait(false); } // Safe to mash B from here until we get out of all menus. Currentscreen becomes 0xFFFFFFFF. while (!await IsOnOverworldFossil(token).ConfigureAwait(false)) { await Click(B, 0_400, token).ConfigureAwait(false); } Log("Egg received. Checking details."); var pk = await ReadBoxPokemon(InjectBox, InjectSlot, token).ConfigureAwait(false); if (pk.Species == 0) { Log("Invalid data detected in destination slot. Restarting loop."); continue; } encounterCount++; Log($"Encounter: {encounterCount}:{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}{Environment.NewLine}"); Counts.AddCompletedEggs(); if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, "egg", pk); } if (StopCondition(pk)) { if (ContinueGettingEggs) { Log("Result found! Continuing to collect more eggs."); continue; } Log("Result found! Stopping routine execution; restart the bot(s) to search again."); return; } } // If aborting the sequence, we might have the stick set at some position. Clear it just in case. await SetStick(LEFT, 0, 0, 0, CancellationToken.None).ConfigureAwait(false); // reset await SetTextSpeed(originalTextSpeed, token).ConfigureAwait(false); }
protected override async Task MainLoop(CancellationToken token) { Log("Identifying trainer data of the host console."); await IdentifyTrainer(token).ConfigureAwait(false); await SetCurrentBox(0, token).ConfigureAwait(false); var existing = await ReadBoxPokemon(InjectBox, InjectSlot, token).ConfigureAwait(false); if (existing.Species != 0 && existing.ChecksumValid) { Log("Destination slot is occupied! Dumping the Pokémon found there..."); DumpPokemon(DumpSetting.DumpFolder, "saved", existing); } Log("Clearing destination slot to start the bot."); await SetBoxPokemon(Blank, InjectBox, InjectSlot, token).ConfigureAwait(false); Log("Starting main EggBot loop."); Config.IterateNextRoutine(); while (!token.IsCancellationRequested && Config.NextRoutineType == PokeRoutineType.EggFetch) { // Walk a step left, then right => check if egg was generated on this attempt. // Repeat until an egg is generated. var attempts = await StepUntilEgg(token).ConfigureAwait(false); if (attempts < 0) // aborted { continue; } Log($"Egg available after {attempts} attempts! Clearing destination slot."); await SetBoxPokemon(Blank, InjectBox, InjectSlot, token).ConfigureAwait(false); for (int i = 0; i < 6; i++) { await Click(A, 0_400, token).ConfigureAwait(false); } // Safe to mash B from here until we get out of all menus. while (!await IsOnOverworld(Hub.Config, token).ConfigureAwait(false)) { await Click(B, 0_400, token).ConfigureAwait(false); } Log("Egg received. Checking details."); var pk = await ReadBoxPokemon(InjectBox, InjectSlot, token).ConfigureAwait(false); if (pk.Species == 0) { Log("Invalid data detected in destination slot. Restarting loop."); continue; } encounterCount++; Log($"Encounter: {encounterCount}:{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}"); Counts.AddCompletedEggs(); Counts.AddEncounteredSpecies(pk); if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, "egg", pk); } if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions)) { if (Hub.Config.Egg.ContinueAfterMatch) { Log($"{Ping}Result found! Continuing to collect more eggs."); continue; } Log($"{Ping}Result found! Stopping routine execution; restart the bot(s) to search again."); await DetachController(token).ConfigureAwait(false); return; } } // If aborting the sequence, we might have the stick set at some position. Clear it just in case. await SetStick(LEFT, 0, 0, 0, CancellationToken.None).ConfigureAwait(false); // reset }
protected override async Task MainLoop(CancellationToken token) { Connection.Log("Identifying trainer data of the host console."); await IdentifyTrainer(token).ConfigureAwait(false); Connection.Log("Checking destination slot for eggs to see if anything is in the slot..."); var existing = await GetBoxSlotQuality(InjectBox, InjectSlot, token).ConfigureAwait(false); if (existing.Quality != SlotQuality.Overwritable) { PrintBadSlotMessage(existing); return; } Connection.Log("Starting main EggBot loop."); var blank = new PK8(); while (!token.IsCancellationRequested && Config.NextRoutineType == PokeRoutineType.EggFetch) { // Walk a step left, then right => check if egg was generated on this attempt. // Repeat until an egg is generated. var attempts = await StepUntilEgg(token).ConfigureAwait(false); if (attempts < 0) // aborted { continue; } Connection.Log($"Egg available after {attempts} attempts! Clearing destination slot."); await SetBoxPokemon(blank, InjectBox, InjectSlot, token).ConfigureAwait(false); for (int i = 0; i < 4; i++) { await Click(A, 500, token).ConfigureAwait(false); } await Task.Delay(4000, token).ConfigureAwait(false); await Click(A, 1850, token).ConfigureAwait(false); await Click(A, 1850, token).ConfigureAwait(false); await Click(A, 450, token).ConfigureAwait(false); Connection.Log("Egg received. Checking details."); var pk = await ReadBoxPokemon(InjectBox, InjectSlot, token).ConfigureAwait(false); if (pk.Species == 0) { Connection.Log("Invalid data detected in destination slot. Restarting loop."); continue; } Connection.Log($"Encounter: {encounterCount}:{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}{Environment.NewLine}"); Counts.AddCompletedEggs(); if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, pk); } encounterCount++; if (!StopCondition(pk)) { continue; } Connection.Log("Result found! Stopping routine execution; re-start the bot(s) to search again."); break; } // If aborting the sequence, we might have the stick set at some position. Clear it just in case. await SetStick(LEFT, 0, 0, 0, CancellationToken.None).ConfigureAwait(false); // reset }