public FossilBot(PokeBotState cfg, PokeTradeHub <PK8> hub) : base(cfg) { Hub = hub; Counts = Hub.Counts; DumpSetting = Hub.Config.Folder; DesiredIVs = StopConditionSettings.InitializeTargetIVs(Hub); }
public Letsgo(PokeBotState cfg, PokeTradeHub <PK8> hub) : base(cfg) { Hub = hub; Counts = Hub.Counts; DumpSetting = Hub.Config.Folder; StopConditionSettings.InitializeTargetIVs(Hub, out DesiredMinIVs, out DesiredMaxIVs); }
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).ConfigureAwait(false); await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false); } return(true); } return(false); }
private static int[] ReadTargetIVs(StopConditionSettings settings, bool min) { int[] targetIVs = new int[6]; string[] splitIVs = min ? settings.TargetMinIVs.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries) : settings.TargetMaxIVs.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); // Only accept up to 6 values. Fill it in with default values if they don't provide 6. // Anything that isn't an integer will be a wild card. for (int i = 0; i < 6 && i < splitIVs.Length; i++) { if (i < splitIVs.Length) { var str = splitIVs[i]; if (int.TryParse(str, out var val)) { targetIVs[i] = val; continue; } } targetIVs[i] = min ? 0 : 31; } return(targetIVs); }
public static bool EncounterFound(PK8 pk, int[] targetIVs, StopConditionSettings settings) { // Match Nature and Species if they were specified. if (settings.StopOnSpecies != Species.None && settings.StopOnSpecies != (Species)pk.Species) { return(false); } if (settings.TargetNature != Nature.Random && settings.TargetNature != (Nature)pk.Nature) { return(false); } if (settings.MarkOnly && !HasMark(pk)) { return(false); } if (settings.ShinyTarget != TargetShinyType.DisableOption) { bool shinymatch = settings.ShinyTarget switch { TargetShinyType.AnyShiny => pk.IsShiny, TargetShinyType.NonShiny => !pk.IsShiny, TargetShinyType.StarOnly => pk.IsShiny && pk.ShinyXor != 0, TargetShinyType.SquareOnly => pk.ShinyXor == 0, TargetShinyType.DisableOption => true, _ => throw new ArgumentException(nameof(TargetShinyType)), }; // If we only needed to match one of the criteria and it shinymatch'd, return true. // If we needed to match both criteria and it didn't shinymatch, return false. if (!settings.MatchShinyAndIV && shinymatch) { return(true); } if (settings.MatchShinyAndIV && !shinymatch) { return(false); } } int[] pkIVList = PKX.ReorderSpeedLast(pk.IVs); for (int i = 0; i < 6; i++) { // Match all 0's. if (targetIVs[i] == 0 && pkIVList[i] != 0) { return(false); } // Wild cards should be -1, so they will always be less than the Pokemon's IVs. if (targetIVs[i] > pkIVList[i]) { return(false); } } return(true); }
protected EncounterBot(PokeBotState cfg, PokeTradeHub <PK8> hub) : base(cfg) { Hub = hub; Settings = Hub.Config.Encounter; DumpSetting = Hub.Config.Folder; StopConditionSettings.InitializeTargetIVs(Hub, out DesiredMinIVs, out DesiredMaxIVs); StopConditionSettings.ReadUnwantedMarks(Hub.Config.StopConditions, out UnwantedMarks); }
public EggBot(PokeBotConfig cfg, PokeTradeHub <PK8> hub) : base(cfg) { Hub = hub; Counts = Hub.Counts; DumpSetting = Hub.Config.Folder; DesiredIVs = StopConditionSettings.InitializeTargetIVs(Hub); Ping = !Hub.Config.StopConditions.PingOnMatch.Equals(string.Empty) ? $"<@{Hub.Config.StopConditions.PingOnMatch}>\n" : ""; }
private async Task <bool> LogPKMs(PK8 pk, bool legends, CancellationToken token) { encounterCount++; string text = ""; if (Hub.Config.StopConditions.StopOnSpecies != 0 && pk.Species == (int)Hub.Config.StopConditions.StopOnSpecies) { _ = $"Scan {encounterCount}:\n{ShowdownParsing.GetShowdownText(pk)}"; if (pk.IsShiny && pk.ShinyXor == 0) { _ = text.Replace("Shiny: Yes", "Shiny: Square"); } else if (pk.IsShiny) { _ = text.Replace("Shiny: Yes", "Shiny: Star"); } _ = $"{text}\n{GetRibbonsList(pk)}"; } else { _ = $"Scan {encounterCount}: {(pk.IsShiny ? "Shiny " : "")}{pk.Nickname}."; } Log($"Scan: {text}"); if (legends) { Counts.AddSWSHLegendaryScans(); } else { Counts.AddSWSHOverworldScans(); } if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, legends ? "OverworldLegends" : "OverworldEncounters", pk); } if (StopConditionSettings.EncounterFound(pk, DesiredMinIVs, DesiredMaxIVs, Hub.Config.StopConditions)) { if (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag)) { Log($"<@{Hub.Config.Discord.UserTag}> result found! Stopping routine execution; restart the bot(s) to search again."); } else { 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 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 (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions)) { 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); } }
public static bool EncounterFound(PK8 pk, int[] targetIVs, StopConditionSettings settings) { if (settings.ShinyTarget != TargetShinyType.DisableOption) { if (settings.ShinyTarget == TargetShinyType.NonShiny && pk.IsShiny) { return(false); } if (settings.ShinyTarget != TargetShinyType.NonShiny && !pk.IsShiny) { return(false); } if (settings.ShinyTarget == TargetShinyType.StarOnly && pk.ShinyXor == 0) { return(false); } if (settings.ShinyTarget == TargetShinyType.SquareOnly && pk.ShinyXor != 0) { return(false); } } // Match Nature and Species if they were specified. if (settings.StopOnSpecies != Species.None && settings.StopOnSpecies != (Species)pk.Species) { return(false); } if (settings.TargetNature != Nature.Random && settings.TargetNature != (Nature)pk.Nature) { return(false); } if (settings.MarkOnly && !HasMark(pk)) { return(false); } int[] pkIVList = PKX.ReorderSpeedLast(pk.IVs); for (int i = 0; i < 6; i++) { // Match all 0's. if (targetIVs[i] == 0 && pk.IVs[i] != 0) { return(false); } // Wild cards should be -1, so they will always be less than the Pokemon's IVs. if (targetIVs[i] > pkIVList[i]) { return(false); } } return(true); }
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); }
public static bool EncounterFound(PKM pk, int[] targetminIVs, int[] targetmaxIVs, StopConditionSettings settings) { // Match Nature and Species if they were specified. if (settings.StopOnSpecies != Species.None && settings.StopOnSpecies != (Species)pk.Species) { return(false); } if (settings.TargetNature != Nature.Random && settings.TargetNature != (Nature)pk.Nature) { return(false); } //If target is Any Mark then do the standard routine otherwise check for a specific Marker if (pk is PK8) { PK8 pk8 = new PK8(pk.Data); if ((settings.MarkTarget == MarkIndex.Any && !HasMark(pk8, settings.MarkTarget, false)) || (settings.MarkTarget != MarkIndex.None && settings.MarkTarget != MarkIndex.Any && !HasMark(pk8, settings.MarkTarget, true))) { return(false); } } if (settings.ShinyTarget != TargetShinyType.DisableOption) { bool shinymatch = settings.ShinyTarget switch { TargetShinyType.AnyShiny => pk.IsShiny, TargetShinyType.NonShiny => !pk.IsShiny, TargetShinyType.StarOnly => pk.IsShiny && pk.ShinyXor != 0, TargetShinyType.SquareOnly => pk.ShinyXor == 0, TargetShinyType.DisableOption => true, _ => throw new ArgumentException(nameof(TargetShinyType)), }; // If we only needed to match one of the criteria and it shinymatch'd, return true. // If we needed to match both criteria and it didn't shinymatch, return false. if (!settings.MatchShinyAndIV && shinymatch) { return(true); } if (settings.MatchShinyAndIV && !shinymatch) { return(false); } } int[] pkIVList = PKX.ReorderSpeedLast(pk.IVs); for (int i = 0; i < 6; i++) { // Match all 0's. if (targetminIVs[i] > pkIVList[i] || targetmaxIVs[i] < pkIVList[i]) { return(false); } } return(true); }
public static bool EncounterFound <T>(T pk, int[] targetminIVs, int[] targetmaxIVs, StopConditionSettings settings, IReadOnlyList <string>?marklist) where T : PKM { // Match Nature and Species if they were specified. if (settings.StopOnSpecies != Species.None && settings.StopOnSpecies != (Species)pk.Species) { return(false); } if (settings.StopOnForm.HasValue && settings.StopOnForm != pk.Form) { return(false); } if (settings.TargetNature != Nature.Random && settings.TargetNature != (Nature)pk.Nature) { return(false); } // Return if it doesn't have a mark or it has an unwanted mark. var unmarked = pk is IRibbonIndex m && !HasMark(m); var unwanted = marklist is not null && pk is IRibbonIndex m2 && settings.IsUnwantedMark(GetMarkName(m2), marklist); if (settings.MarkOnly && (unmarked || unwanted)) { return(false); } if (settings.ShinyTarget != TargetShinyType.DisableOption) { bool shinymatch = settings.ShinyTarget switch { TargetShinyType.AnyShiny => pk.IsShiny, TargetShinyType.NonShiny => !pk.IsShiny, TargetShinyType.StarOnly => pk.IsShiny && pk.ShinyXor != 0, TargetShinyType.SquareOnly => pk.ShinyXor == 0, TargetShinyType.DisableOption => true, _ => throw new ArgumentException(nameof(TargetShinyType)), }; // If we only needed to match one of the criteria and it shinymatch'd, return true. // If we needed to match both criteria and it didn't shinymatch, return false. if (!settings.MatchShinyAndIV && shinymatch) { return(true); } if (settings.MatchShinyAndIV && !shinymatch) { return(false); } } int[] pkIVList = pk.IVs; PKX.ReorderSpeedLast(pkIVList); for (int i = 0; i < 6; i++) { if (targetminIVs[i] > pkIVList[i] || targetmaxIVs[i] < pkIVList[i]) { return(false); } } return(true); }
public static void ReadUnwantedMarks(StopConditionSettings settings, out IReadOnlyList <string> marks) => marks = settings.UnwantedMarks.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();
public override async Task MainLoop(CancellationToken token) { Log("Identifying trainer data of the host console."); await IdentifyTrainer(token).ConfigureAwait(false); Log("Checking item counts..."); var pouchData = await Connection.ReadBytesAsync(ItemTreasureAddress, 80, token).ConfigureAwait(false); var counts = FossilCount.GetFossilCounts(pouchData); int reviveCount = counts.PossibleRevives(Hub.Config.SWSH_Fossil.Species); if (reviveCount == 0) { Log("Insufficient fossil pieces. Please obtain at least one of each required fossil piece first."); return; } Log("Starting main FossilBot loop."); Config.IterateNextRoutine(); while (!token.IsCancellationRequested && Config.NextRoutineType == PokeRoutineType.SWSH_FossilBot) { if (encounterCount != 0 && encounterCount % reviveCount == 0) { Log($"Ran out of fossils to revive {Hub.Config.SWSH_Fossil.Species}."); Log("Restarting the game to restore the puch data."); await CloseGame(Hub.Config, token).ConfigureAwait(false); await StartGame(Hub.Config, token).ConfigureAwait(false); } await ReviveFossil(counts, token).ConfigureAwait(false); Log("Fossil revived. Checking details..."); var pk = await ReadUntilPresent(await ParsePointer(PokeGift, token), 2_000, 0_200, token).ConfigureAwait(false); if (pk == null) { Log("RAM may be shifted, please restart the game and the bot."); } else { encounterCount++; Log($"Encounter: {encounterCount}:{Environment.NewLine}{ShowdownParsing.GetShowdownText(pk)}{Environment.NewLine}"); if (DumpSetting.Dump) { DumpPokemon(DumpSetting.DumpFolder, "fossil", pk); } Counts.AddCompletedFossils(); if (StopConditionSettings.EncounterFound(pk, DesiredMinIVs, DesiredMaxIVs, Hub.Config.StopConditions)) { 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); } Log("Result found! Stopping routine execution; restart the bot(s) to search again."); await DetachController(token).ConfigureAwait(false); return; } while (!await IsOnOverworld(Hub.Config, token).ConfigureAwait(false)) { await Click(B, 0_200, token).ConfigureAwait(false); } } } }
public override async Task MainLoop(CancellationToken token) { Log("Identifying trainer data of the host console."); await IdentifyTrainer(token).ConfigureAwait(false); Log("Checking item counts..."); var pouchData = await Connection.ReadBytesAsync(ItemTreasureAddress, 80, token).ConfigureAwait(false); var counts = FossilCount.GetFossilCounts(pouchData); int reviveCount = counts.PossibleRevives(Hub.Config.Fossil.Species); if (reviveCount == 0) { Log("Insufficient fossil pieces. Please obtain at least one of each required fossil piece first."); return; } Config.IterateNextRoutine(); while (!token.IsCancellationRequested && Config.NextRoutineType == PokeRoutineType.FossilBot) { await ReviveFossil(counts, token).ConfigureAwait(false); Log("Fossil revived. Checking details..."); var pk = await ReadUntilPresent(await ParsePointer(giftpoke, token), 2_000, 0_200, token).ConfigureAwait(false); if (pk == null) { Log("RAM probably shifted."); continue; } encounterCount++; string 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}{Environment.NewLine}"); if (DumpSetting.Dump) { DumpPokemon(DumpSetting.DumpFolder, "fossil", pk); } Counts.AddCompletedFossils(); if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions)) { 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 (!String.IsNullOrEmpty(Hub.Config.Discord.UserTag)) { Log($"<@{Hub.Config.Discord.UserTag}> Result found! Stopping routine execution; restart the bot(s) to search again."); } else { Log("Result found! Stopping routine execution; restart the bot(s) to search again."); } await DetachController(token).ConfigureAwait(false); return; } else { await CloseGame(Hub.Config, token).ConfigureAwait(false); await StartGame(Hub.Config, token).ConfigureAwait(false); } } }
// return true if breaking loop protected async Task <bool> HandleEncounter(PK8 pk, CancellationToken token) { encounterCount++; var print = Hub.Config.StopConditions.GetPrintName(pk); Log($"Encounter: {encounterCount}{Environment.NewLine}{print}{Environment.NewLine}"); var legendary = Legal.Legends.Contains(pk.Species) || Legal.SubLegends.Contains(pk.Species); if (legendary) { Settings.AddCompletedLegends(); } else { Settings.AddCompletedEncounters(); } if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, legendary ? "legends" : "encounters", pk); } if (!StopConditionSettings.EncounterFound(pk, DesiredMinIVs, DesiredMaxIVs, Hub.Config.StopConditions, UnwantedMarks)) { return(false); } if (Hub.Config.StopConditions.CaptureVideoClip) { await Task.Delay(Hub.Config.StopConditions.ExtraTimeWaitCaptureVideo, token).ConfigureAwait(false); await PressAndHold(CAPTURE, 2_000, 0, token).ConfigureAwait(false); } var mode = Settings.ContinueAfterMatch; var msg = $"Result found!\n{print}\n" + mode switch { ContinueAfterMatch.Continue => "Continuing...", ContinueAfterMatch.PauseWaitAcknowledge => "Waiting for instructions to continue.", ContinueAfterMatch.StopExit => "Stopping routine execution; restart the bot to search again.", _ => throw new ArgumentOutOfRangeException(), }; if (!string.IsNullOrWhiteSpace(Hub.Config.StopConditions.MatchFoundEchoMention)) { msg = $"{Hub.Config.StopConditions.MatchFoundEchoMention} {msg}"; } EchoUtil.Echo(msg); Log(msg); if (mode == ContinueAfterMatch.StopExit) { return(true); } if (mode == ContinueAfterMatch.Continue) { return(false); } IsWaiting = true; while (IsWaiting) { await Task.Delay(1_000, token).ConfigureAwait(false); } return(false); }
private async Task WalkInLine(CancellationToken token) { if (Hub.Config.StopConditions.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 (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions)) { 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.StrongSpawn) { await SetLastUsedBall(Ball.Master, token).ConfigureAwait(false); Log($"{Ping}Result found! Attempting to catch..."); await CatchWildPokemon(pk, token).ConfigureAwait(false); if (!Hub.Config.StopConditions.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); } } }
private async Task WalkInLine(CancellationToken token) { while (!token.IsCancellationRequested) { 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(); 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 (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).ConfigureAwait(false); await PressAndHold(CAPTURE, 2_000, 1_000, token).ConfigureAwait(false); } return; } Log("Running away..."); while (await IsInBattle(token).ConfigureAwait(false)) { await FleeToOverworld(token).ConfigureAwait(false); } } }
public CurryBot(PokeBotState cfg, PokeTradeHub <PK8> hub) : base(cfg, hub) { Settings = Hub.Config.Curry; StopSettings = Hub.Config.StopConditions; }
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("Checking item counts..."); var pouchData = await Connection.ReadBytesAsync(ItemTreasureAddress, 80, Config.ConnectionType, token).ConfigureAwait(false); var counts = FossilCount.GetFossilCounts(pouchData); int reviveCount = counts.PossibleRevives(Hub.Config.Fossil.Species); if (reviveCount == 0) { Log("Insufficient fossil pieces. Please obtain at least one of each required fossil piece first."); return; } Log("Starting main FossilBot loop."); Config.IterateNextRoutine(); while (!token.IsCancellationRequested && Config.NextRoutineType == PokeRoutineType.FossilBot) { if (encounterCount != 0 && encounterCount % reviveCount == 0) { Log($"Ran out of fossils to revive {Hub.Config.Fossil.Species}."); if (Hub.Config.Fossil.InjectWhenEmpty) { Log("Restoring original pouch data."); await Connection.WriteBytesAsync(pouchData, ItemTreasureAddress, Config.ConnectionType, token).ConfigureAwait(false); await Task.Delay(500, token).ConfigureAwait(false); } else { Log("Restart the game and the bot(s) or set \"Inject Fossils\" to True in the config."); return; } } await ReviveFossil(counts, token).ConfigureAwait(false); Log("Fossil revived. Checking details..."); var pk = await ReadBoxPokemon(InjectBox, InjectSlot, token).ConfigureAwait(false); if (pk.Species == 0 || !pk.ChecksumValid) { Log("Invalid data detected in destination slot. Restarting loop."); continue; } encounterCount++; Log($"Encounter: {encounterCount}:{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}{Environment.NewLine}"); if (DumpSetting.Dump) { DumpPokemon(DumpSetting.DumpFolder, "fossil", pk); } Counts.AddCompletedFossils(); Counts.AddEncounteredSpecies(pk); if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions)) { 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.Fossil.ContinueAfterMatch) { Log($"{Ping}Result found! Continuing to collect more fossils."); } else { Log($"{Ping}Result found! Stopping routine execution; restart the bot(s) to search again."); await DetachController(token).ConfigureAwait(false); return; } } Log("Clearing destination slot."); await SetBoxPokemon(Blank, InjectBox, InjectSlot, 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 }
private async Task DoDogEncounter(CancellationToken token) { while (!token.IsCancellationRequested) { Log("Looking for a new dog..."); // At the start of each loop, an A press is needed to exit out of a prompt. await Click(A, 0_500, token).ConfigureAwait(false); await SetStick(LEFT, 0, 30000, 1_000, token).ConfigureAwait(false); // Encounters Zacian/Zamazenta await Click(A, 0_600, token).ConfigureAwait(false); // Cutscene loads await Click(A, 2_600, token).ConfigureAwait(false); // Click through all the menus. while (!await IsInBattle(token).ConfigureAwait(false)) { await Click(A, 1_000, token).ConfigureAwait(false); } Log("Encounter started! Checking details..."); var pk = await ReadPokemon(LegendaryPokemonOffset, token).ConfigureAwait(false); if (pk.Species == 0) { Log("Invalid data detected. Restarting loop."); continue; } encounterCount++; Log($"Encounter: {encounterCount}{Environment.NewLine}{ShowdownSet.GetShowdownText(pk)}{Environment.NewLine}"); Counts.AddCompletedLegends(); if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder)) { DumpPokemon(DumpSetting.DumpFolder, "legends", pk); } if (StopConditionSettings.EncounterFound(pk, DesiredIVs, Hub.Config.StopConditions)) { Log("Result found! Stopping routine execution; restart the bot(s) to search again."); return; } // Get rid of any stick stuff left over so we can flee properly. await ResetStick(token).ConfigureAwait(false); // Wait for the entire cutscene. await Task.Delay(15_000, token).ConfigureAwait(false); // 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); } Log("Running away..."); while (await IsInBattle(token).ConfigureAwait(false)) { await FleeToOverworld(token).ConfigureAwait(false); } // Extra delay to be sure we're fully out of the battle. await Task.Delay(0_250, token).ConfigureAwait(false); } }