Skip to content

Commit

Permalink
Fix: Prevents restarting game after PartyPK switch due.
Browse files Browse the repository at this point in the history
Improvement: Overworld recovery after PartyPK switch.
  • Loading branch information
bdawg1989 committed Aug 2, 2024
1 parent b73f1f4 commit d507913
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 25 deletions.
2 changes: 1 addition & 1 deletion SysBot.Pokemon/Helpers/NotRaidBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
84 changes: 60 additions & 24 deletions SysBot.Pokemon/SV/BotRaid/RotatingRaidBotSV.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -1685,21 +1688,43 @@ private async Task<int> PrepareForRaid(CancellationToken token)
}

Log("Preparing lobby...");
LobbyFiltersCategory settings = new();

if (!await ConnectToOnline(Hub.Config, token))
{
return 0;
}

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)
Expand All @@ -1716,27 +1741,38 @@ private async Task<int> 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<bool> 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)
Expand Down

0 comments on commit d507913

Please sign in to comment.