From d5079133dc0b2f07b0204502f7a2f0edf9f85a60 Mon Sep 17 00:00:00 2001 From: Gengar <80122551+bdawg1989@users.noreply.github.com> Date: Fri, 2 Aug 2024 08:38:31 -0500 Subject: [PATCH] Fix: Prevents restarting game after PartyPK switch due. Improvement: Overworld recovery after PartyPK switch. --- SysBot.Pokemon/Helpers/NotRaidBot.cs | 2 +- .../SV/BotRaid/RotatingRaidBotSV.cs | 84 +++++++++++++------ 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/SysBot.Pokemon/Helpers/NotRaidBot.cs b/SysBot.Pokemon/Helpers/NotRaidBot.cs index 329b2a5..235e597 100644 --- a/SysBot.Pokemon/Helpers/NotRaidBot.cs +++ b/SysBot.Pokemon/Helpers/NotRaidBot.cs @@ -2,7 +2,7 @@ { public static class NotRaidBot { - public const string Version = "v8.1.5"; + public const string Version = "v8.1.6"; public const string Repo = "https://github.com/bdawg1989/NotRaidBot"; public const string ConfigPath = "config.json"; } diff --git a/SysBot.Pokemon/SV/BotRaid/RotatingRaidBotSV.cs b/SysBot.Pokemon/SV/BotRaid/RotatingRaidBotSV.cs index 94b3789..a36748a 100644 --- a/SysBot.Pokemon/SV/BotRaid/RotatingRaidBotSV.cs +++ b/SysBot.Pokemon/SV/BotRaid/RotatingRaidBotSV.cs @@ -371,19 +371,22 @@ private async Task InnerLoop(CancellationToken token) await SwitchConnection.WriteBytesAbsoluteAsync(new byte[32], TeraNIDOffsets[0], token).ConfigureAwait(false); // Connect online and enter den. - int prepareResult = await PrepareForRaid(token).ConfigureAwait(false); + int prepareResult; + do + { + prepareResult = await PrepareForRaid(token).ConfigureAwait(false); + if (prepareResult == 0) + { + Log("Failed to prepare the raid, rebooting the game."); + await ReOpenGame(Hub.Config, token).ConfigureAwait(false); + } + } while (prepareResult == 0); + if (prepareResult == 2) { // Seed was injected, restart the loop continue; } - else if (prepareResult == 0) - { - // Preparation failed, reboot the game - Log("Failed to prepare the raid, rebooting the game."); - await ReOpenGame(Hub.Config, token).ConfigureAwait(false); - continue; - } // Wait until we're in lobby. if (!await GetLobbyReady(false, token).ConfigureAwait(false)) @@ -1685,7 +1688,6 @@ private async Task PrepareForRaid(CancellationToken token) } Log("Preparing lobby..."); - LobbyFiltersCategory settings = new(); if (!await ConnectToOnline(Hub.Config, token)) { @@ -1693,13 +1695,36 @@ private async Task PrepareForRaid(CancellationToken token) } await Task.Delay(0_500, token).ConfigureAwait(false); + await SwitchPartyPokemon(token).ConfigureAwait(false); + await Task.Delay(1_500, token).ConfigureAwait(false); + + if (!await IsOnOverworld(OverworldOffset, token).ConfigureAwait(false)) + return 0; + + await Click(A, 3_000, token).ConfigureAwait(false); + await Click(A, 3_000, token).ConfigureAwait(false); + + if (!Settings.ActiveRaids[RotationCount].IsCoded || (Settings.ActiveRaids[RotationCount].IsCoded && EmptyRaid == Settings.LobbyOptions.EmptyRaidLimit && Settings.LobbyOptions.LobbyMethod == LobbyMethodOptions.OpenLobby)) + { + if (Settings.ActiveRaids[RotationCount].IsCoded && EmptyRaid == Settings.LobbyOptions.EmptyRaidLimit && Settings.LobbyOptions.LobbyMethod == LobbyMethodOptions.OpenLobby) + Log($"We had {Settings.LobbyOptions.EmptyRaidLimit} empty raids.. Opening this raid to all!"); + await Click(DDOWN, 1_000, token).ConfigureAwait(false); + } + + await Click(A, 4_000, token).ConfigureAwait(false); + return 1; + } + + private async Task SwitchPartyPokemon(CancellationToken token) + { + LobbyFiltersCategory settings = new(); var len = string.Empty; foreach (var l in Settings.ActiveRaids[RotationCount].PartyPK) len += l; if (len.Length > 1 && EmptyRaid == 0) { Log("Preparing PartyPK. Sit tight."); - await Task.Delay(2_500 + settings.ExtraTimeLobbyDisband, token).ConfigureAwait(false); + await Task.Delay(2_500 + settings.ExtraTimePartyPK, token).ConfigureAwait(false); await SetCurrentBox(0, token).ConfigureAwait(false); var res = string.Join("\n", Settings.ActiveRaids[RotationCount].PartyPK); if (res.Length > 4096) @@ -1716,27 +1741,38 @@ private async Task PrepareForRaid(CancellationToken token) await Click(Y, 0_500, token).ConfigureAwait(false); await Click(DLEFT, 0_800, token).ConfigureAwait(false); await Click(Y, 0_500, token).ConfigureAwait(false); - for (int i = 0; i < 2; i++) - await Click(B, 1_500, token).ConfigureAwait(false); + await RecoverToOverworld(token).ConfigureAwait(false); Log("PartyPK switch successful."); } - await Task.Delay(1_500, token).ConfigureAwait(false); - - if (!await IsOnOverworld(OverworldOffset, token).ConfigureAwait(false)) - return 0; + } - await Click(A, 3_000, token).ConfigureAwait(false); - await Click(A, 3_000, token).ConfigureAwait(false); + private async Task RecoverToOverworld(CancellationToken token) + { + if (await IsOnOverworld(OverworldOffset, token).ConfigureAwait(false)) + return true; - if (!Settings.ActiveRaids[RotationCount].IsCoded || (Settings.ActiveRaids[RotationCount].IsCoded && EmptyRaid == Settings.LobbyOptions.EmptyRaidLimit && Settings.LobbyOptions.LobbyMethod == LobbyMethodOptions.OpenLobby)) + var attempts = 0; + while (!await IsOnOverworld(OverworldOffset, token).ConfigureAwait(false)) { - if (Settings.ActiveRaids[RotationCount].IsCoded && EmptyRaid == Settings.LobbyOptions.EmptyRaidLimit && Settings.LobbyOptions.LobbyMethod == LobbyMethodOptions.OpenLobby) - Log($"We had {Settings.LobbyOptions.EmptyRaidLimit} empty raids.. Opening this raid to all!"); - await Click(DDOWN, 1_000, token).ConfigureAwait(false); + attempts++; + if (attempts >= 30) + break; + for (int i = 0; i < 20; i++) + { + await Click(B, 1_000, token).ConfigureAwait(false); + if (await IsOnOverworld(OverworldOffset, token).ConfigureAwait(false)) + return true; + } } - await Click(A, 4_000, token).ConfigureAwait(false); - return 1; + // We didn't make it for some reason. + if (!await IsOnOverworld(OverworldOffset, token).ConfigureAwait(false)) + { + Log("Failed to recover to overworld, rebooting the game."); + await ReOpenGame(Hub.Config, token).ConfigureAwait(false); + } + await Task.Delay(1_000, token).ConfigureAwait(false); + return true; } private async Task RollBackHour(CancellationToken token)