Skip to content

Commit

Permalink
Log wild encounter in SwSh overworld routine
Browse files Browse the repository at this point in the history
  • Loading branch information
Manu098vm committed Sep 19, 2022
1 parent faf62c1 commit b737da2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions SysBot.Pokemon/SWSH/BotOverworld/BotOverworld.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ private async Task Overworld(SAV8SWSH sav, CancellationToken token)
// Offsets are flickery so make sure we see it 3 times.
for (int i = 0; i < 3; i++)
await ReadUntilChanged(PokeDataOffsets.BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false);

var pk_enc = await ReadUntilPresent(PokeDataOffsets.WildPokemonOffset, 2_000, 0_200, PokeDataOffsets.BoxFormatSlotSize, token).ConfigureAwait(false);
if (await HandleEncounter(pk_enc, token).ConfigureAwait(false))
return;

Log("Unwanted encounter started, running away...");
await FleeToOverworld(token).ConfigureAwait(false);
// Extra delay to be sure we're fully out of the battle.
Expand Down Expand Up @@ -250,6 +255,9 @@ private async Task Overworld(SAV8SWSH sav, CancellationToken token)
await ResetStick(token).ConfigureAwait(false);
for (int i = 0; i < 3; i++)
await ReadUntilChanged(PokeDataOffsets.BattleMenuOffset, BattleMenuReady, 5_000, 0_100, true, token).ConfigureAwait(false);
var pk_enc = await ReadUntilPresent(PokeDataOffsets.WildPokemonOffset, 2_000, 0_200, PokeDataOffsets.BoxFormatSlotSize, token).ConfigureAwait(false);
if (await HandleEncounter(pk_enc, token).ConfigureAwait(false))
return;
Log("Unwanted encounter started, running away...");
await FleeToOverworld(token).ConfigureAwait(false);
await Task.Delay(0_250, token).ConfigureAwait(false);
Expand Down Expand Up @@ -308,5 +316,34 @@ private async Task<bool> LogPKMs(PK8? pk, CancellationToken token)

return true;
}

protected async Task<bool> HandleEncounter(PK8? pk, CancellationToken token)
{
if (pk == null)
return false;

var print = (Species)pk.Species;
Log($"Battle Encounter: {Hub.Config.StopConditions.GetPrintName(pk)}");

if (DumpSetting.Dump && !string.IsNullOrEmpty(DumpSetting.DumpFolder))
DumpPokemon(DumpSetting.DumpFolder, "encounters", pk);

if (!StopConditionSettings.EncounterFound(pk, DesiredMinIVs, DesiredMaxIVs, Hub.Config.StopConditions, WantedNatures, 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 msg = $"Result found!\n{print}\nStopping routine execution; restart the bot to search again.";

if (!string.IsNullOrWhiteSpace(Hub.Config.StopConditions.MatchFoundEchoMention))
msg = $"{Hub.Config.StopConditions.MatchFoundEchoMention} {msg}";
Log(msg);

return true;
}
}
}

0 comments on commit b737da2

Please sign in to comment.