private async Task DoEternatusEncounter(CancellationToken token) { while (!token.IsCancellationRequested && Config.NextRoutineType == PokeRoutineType.EncounterBot) { await SetStick(LEFT, 0, 20_000, 500, token).ConfigureAwait(false); await SetStick(LEFT, 0, 0, 1_000, token).ConfigureAwait(false); var pk = await ReadPokemon(RaidPokemonOffset, token).ConfigureAwait(false); if (pk.Species == 0) { Connection.Log("Invalid data detected. Restarting loop."); // add stuff for recovering continue; } encounterCount++; Connection.Log($"Encounter: {encounterCount}:{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}{Environment.NewLine}"); Counts.AddCompletedLegends(); if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, "legends", pk); } if (StopCondition(pk)) { Connection.Log("Result found! Stopping routine execution; restart the bot(s) to search again."); return; } Connection.Log("Resetting raid by restarting the game"); // Close out of the game await Click(HOME, 1_600, token).ConfigureAwait(false); await Click(X, 0_800, token).ConfigureAwait(false); await Click(A, 4_000, token).ConfigureAwait(false); // Closing software prompt Connection.Log("Closed out of the game!"); // Open game and select profile await Click(A, 1_000, token).ConfigureAwait(false); await Click(A, 1_000, token).ConfigureAwait(false); Connection.Log("Restarting the game!"); // Switch Logo lag, skip cutscene, game load screen await Task.Delay(14_000, token).ConfigureAwait(false); await Click(A, 1_000, token).ConfigureAwait(false); await Task.Delay(3_500, token).ConfigureAwait(false); Connection.Log("Back in the overworld!"); await ResetStick(token).ConfigureAwait(false); } }
private async Task <bool> HandleEncounter(PK8 pk, bool legends, CancellationToken token) { encounterCount++; Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}"); if (legends) { Counts.AddCompletedLegends(); } else { Counts.AddCompletedEncounters(); } if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, legends ? "legends" : "encounters", pk); } if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions)) { Log("Result found! Stopping routine execution; restart the bot(s) to search again."); if (Hub.Config.StopConditions.CaptureVideoClip) { await Task.Delay(Hub.Config.StopConditions.ExtraTimeWaitCaptureVideo, token).ConfigureAwait(false); await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false); } return(true); } return(false); }
private async Task <bool> HandleEncounter(PK8 pk, bool legends, CancellationToken token) { encounterCount++; //Star/Square Shiny Recognition var showdowntext = ShowdownParsing.GetShowdownText(pk); if (pk.IsShiny && pk.ShinyXor == 0) { showdowntext = showdowntext.Replace("Shiny: Yes", "Shiny: Square"); } else if (pk.IsShiny) { showdowntext = showdowntext.Replace("Shiny: Yes", "Shiny: Star"); } Log($"Encounter: {encounterCount}{Environment.NewLine}{Environment.NewLine}{showdowntext}{Environment.NewLine}{GetRibbonsList(pk)}{Environment.NewLine}"); if (legends) { Counts.AddCompletedLegends(); } else { Counts.AddCompletedEncounters(); } if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, legends ? "legends" : "encounters", pk); Counts.AddCompletedDumps(); } if (StopConditionSettings.EncounterFound(pk, DesiredMinIVs, DesiredMaxIVs, Hub.Config.StopConditions)) { if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag) && Hub.Config.SWSH_Encounter.EncounteringType != EncounterMode.LiveStatsChecking) { Log($"<@{Hub.Config.Discord.UserTag}> result found! Stopping routine execution; restart the bot(s) to search again."); } else if (Hub.Config.SWSH_Encounter.EncounteringType != EncounterMode.LiveStatsChecking) { Log("Result found!"); } if (Hub.Config.StopConditions.CaptureVideoClip) { await Task.Delay(Hub.Config.StopConditions.ExtraTimeWaitCaptureVideo, token).ConfigureAwait(false); await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false); } return(true); } return(false); }
private bool HandleEncounter(PK8 pk, bool legends) { encounterCount++; //Star/Square Shiny Recognition var showdowntext = ShowdownParsing.GetShowdownText(pk); if (pk.IsShiny && pk.ShinyXor == 0) { showdowntext = showdowntext.Replace("Shiny: Yes", "Shiny: Square"); } else if (pk.IsShiny) { showdowntext = showdowntext.Replace("Shiny: Yes", "Shiny: Star"); } Log($"Encounter: {encounterCount}{Environment.NewLine}{Environment.NewLine}{showdowntext}{Environment.NewLine}"); if (legends) { Counts.AddCompletedLegends(); } else { Counts.AddCompletedEncounters(); } if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, legends ? "legends" : "encounters", pk); Counts.AddCompletedDumps(); } if (StopConditionSettings.EncounterFound(pk, DesiredMinIVs, DesiredMaxIVs, Hub.Config.StopConditions)) { if (legends) { Log("Result found! Stopping routine execution; restart the bot(s) to search again."); } return(true); } return(false); }
private async Task <bool> HandleEncounter(PK8 pk, bool legends, CancellationToken token) { encounterCount++; Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownParsing.GetShowdownText(pk)}{Environment.NewLine}{(StopConditionSettings.HasMark(pk, out RibbonIndex mark) ? $"Mark: {mark.ToString().Replace("Mark", "")}{Environment.NewLine}" : "")}"); TradeExtensions.EncounterLogs(pk); if (legends) { Counts.AddCompletedLegends(); } else { Counts.AddCompletedEncounters(); } if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, legends ? "legends" : "encounters", pk); } if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions)) { Log(Hub.Config.StopConditions.CatchEncounter && (Hub.Config.Encounter.EncounteringType == EncounterMode.VerticalLine || Hub.Config.Encounter.EncounteringType == EncounterMode.HorizontalLine) ? "Result found! Attempting to catch..." : $"{(!Hub.Config.StopConditions.PingOnMatch.Equals(string.Empty) ? $"<@{Hub.Config.StopConditions.PingOnMatch}>\n" : "")}Result found! Stopping routine execution; restart the bot(s) to search again."); if (Hub.Config.StopConditions.CaptureVideoClip) { await Task.Delay(Hub.Config.StopConditions.ExtraTimeWaitCaptureVideo, token).ConfigureAwait(false); await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false); } if (Hub.Config.StopConditions.CatchEncounter && (Hub.Config.Encounter.EncounteringType == EncounterMode.VerticalLine || Hub.Config.Encounter.EncounteringType == EncounterMode.HorizontalLine)) { await CatchWildPokemon(pk, token).ConfigureAwait(false); } return(true); } return(false); }
private async Task <bool> HandleEncounter(PK8 pk, bool legends, CancellationToken token) { encounterCount++; Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}"); Counts.AddEncounteredSpecies(pk); if (legends) { Counts.AddCompletedLegends(); } else { Counts.AddCompletedEncounters(); } if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, legends ? "legends" : "encounters", pk); } if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions)) { Log(!Hub.Config.StopConditions.CatchEncounter || Hub.Config.Encounter.EncounteringType == EncounterMode.StrongSpawn ? $"{Ping}Result found! Stopping routine execution; restart the bot(s) to search again." : "Result found! Attempting to catch..."); if (Hub.Config.StopConditions.CaptureVideoClip) { await Task.Delay(Hub.Config.StopConditions.ExtraTimeWaitCaptureVideo).ConfigureAwait(false); await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false); } if (Hub.Config.StopConditions.CatchEncounter && (Hub.Config.Encounter.EncounteringType == EncounterMode.VerticalLine || Hub.Config.Encounter.EncounteringType == EncounterMode.HorizontalLine)) { await CatchWildPokemon(pk, token).ConfigureAwait(false); } return(true); } return(false); }
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; int j = 0; bool freeze = false; bool searchforshiny = Hub.Config.LGPE_OverworldScan.OnlyShiny; bool found = false; if (movementslist.Count > 0) { Log($"ATTENTION!{Environment.NewLine}Any wild encounter will broke the movement routine, resulting in the pg moving to unwanted places!{Environment.NewLine}" + $"----------------------------------------{Environment.NewLine}" + $"ATTENTION!\nUnexpected behaviour can occur if a shiny is detected while changing area. It his 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 = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(SpeciesComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0); 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 SwitchConnection.WriteBytesAbsoluteAsync(BitConverter.GetBytes((uint)Hub.Config.LGPE_OverworldScan.ChainSpecies), await ParsePointer(SpeciesComboPointer, token).ConfigureAwait(false), token).ConfigureAwait(false); speciescombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(SpeciesComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0); Log($"Current catch combo being now on {(speciescombo == 0 ? "None" : SpeciesName.GetSpeciesName((int)speciescombo, 2))}."); } } if (Hub.Config.LGPE_OverworldScan.ChainCount > 0) { catchcombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(CatchComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0); if (catchcombo < (uint)Hub.Config.LGPE_OverworldScan.ChainCount) { Log($"Current catch combo being {catchcombo}, incrementing to {Hub.Config.LGPE_OverworldScan.ChainCount}."); await SwitchConnection.WriteBytesAbsoluteAsync(BitConverter.GetBytes((uint)Hub.Config.LGPE_OverworldScan.ChainCount), await ParsePointer(CatchComboPointer, token).ConfigureAwait(false), token).ConfigureAwait(false); catchcombo = BitConverter.ToUInt16(await SwitchConnection.ReadBytesAbsoluteAsync(await ParsePointer(CatchComboPointer, token).ConfigureAwait(false), 2, token).ConfigureAwait(false), 0); Log($"Current catch combo being now {catchcombo}."); } } while (!token.IsCancellationRequested) { if (searchforshiny) { await LGZaksabeast(token, version).ConfigureAwait(false); } while (freeze == false && !token.IsCancellationRequested && !found) { if (await LGCountMilliseconds(Hub.Config, token).ConfigureAwait(false) > 0 || !searchforshiny) { //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(j)[2] || firstrun) { if (firstrun) { firstrun = false; } //Log($"Moved for {stopwatch.ElapsedMilliseconds}ms."); await ResetStick(token).ConfigureAwait(false); await SetStick(RIGHT, (short)(movementslist.ElementAt(j)[0]), (short)(movementslist.ElementAt(j)[1]), 0_001, token).ConfigureAwait(false); j++; if (j == movementslist.Count) { j = 0; } stopwatch.Restart(); } } //Check is inside an unwanted encounter if (await LGIsInCatchScreen(token).ConfigureAwait(false)) { await ResetStick(token).ConfigureAwait(false); Log($"Unwanted encounter detected!"); int y = 0; while (await LGIsInCatchScreen(token).ConfigureAwait(false) && !token.IsCancellationRequested) { y++; await Task.Delay(8_000, token).ConfigureAwait(false); if (y > 2) { await Click(B, 1_200, token).ConfigureAwait(false); } await Click(B, 1_200, token).ConfigureAwait(false); await Click(A, 1_000, token).ConfigureAwait(false); await Task.Delay(6_500, token).ConfigureAwait(false); } Log($"Exited wild encounter."); } //Check new spawns newspawn = BitConverter.ToUInt16(await Connection.ReadBytesAsync(LastSpawn1, 2, token).ConfigureAwait(false), 0); if (newspawn != prev) { if (newspawn != 0) { i++; if (IsPKLegendary((int)newspawn)) { Counts.AddCompletedLegends(); } else { Counts.AddCompletedEncounters(); } Log($"New spawn ({i}): {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; } } if (searchforshiny && !token.IsCancellationRequested) { Log("A Shiny has been detected."); } //Unfreeze to restart the routine, or log the Shiny species. await LGUnfreeze(token, version).ConfigureAwait(false); newspawn = BitConverter.ToUInt16(await Connection.ReadBytesAsync(LastSpawn1, 2, token).ConfigureAwait(false), 0); //Stop Conditions logic 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; } if (!found && !token.IsCancellationRequested) { freeze = false; Log($"Shiny {SpeciesName.GetSpeciesName((int)newspawn, 4)} is not the target, the routine will continue."); } else if (!token.IsCancellationRequested) { await ResetStick(token).ConfigureAwait(false); if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag)) { Log($"<@{Hub.Config.Discord.UserTag}> Shiny {SpeciesName.GetSpeciesName((int)newspawn, 4)} found!"); } else { Log($"Shiny {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); } }