@@ -223,6 +223,11 @@ private async Task Overworld(SAV8SWSH sav, CancellationToken token)
223223 // Offsets are flickery so make sure we see it 3 times.
224224 for ( int i = 0 ; i < 3 ; i ++ )
225225 await ReadUntilChanged ( PokeDataOffsets . BattleMenuOffset , BattleMenuReady , 5_000 , 0_100 , true , token ) . ConfigureAwait ( false ) ;
226+
227+ var pk_enc = await ReadUntilPresent ( PokeDataOffsets . WildPokemonOffset , 2_000 , 0_200 , PokeDataOffsets . BoxFormatSlotSize , token ) . ConfigureAwait ( false ) ;
228+ if ( await HandleEncounter ( pk_enc , token ) . ConfigureAwait ( false ) )
229+ return ;
230+
226231 Log ( "Unwanted encounter started, running away..." ) ;
227232 await FleeToOverworld ( token ) . ConfigureAwait ( false ) ;
228233 // Extra delay to be sure we're fully out of the battle.
@@ -250,6 +255,9 @@ private async Task Overworld(SAV8SWSH sav, CancellationToken token)
250255 await ResetStick ( token ) . ConfigureAwait ( false ) ;
251256 for ( int i = 0 ; i < 3 ; i ++ )
252257 await ReadUntilChanged ( PokeDataOffsets . BattleMenuOffset , BattleMenuReady , 5_000 , 0_100 , true , token ) . ConfigureAwait ( false ) ;
258+ var pk_enc = await ReadUntilPresent ( PokeDataOffsets . WildPokemonOffset , 2_000 , 0_200 , PokeDataOffsets . BoxFormatSlotSize , token ) . ConfigureAwait ( false ) ;
259+ if ( await HandleEncounter ( pk_enc , token ) . ConfigureAwait ( false ) )
260+ return ;
253261 Log ( "Unwanted encounter started, running away..." ) ;
254262 await FleeToOverworld ( token ) . ConfigureAwait ( false ) ;
255263 await Task . Delay ( 0_250 , token ) . ConfigureAwait ( false ) ;
@@ -308,5 +316,34 @@ private async Task<bool> LogPKMs(PK8? pk, CancellationToken token)
308316
309317 return true ;
310318 }
319+
320+ protected async Task < bool > HandleEncounter ( PK8 ? pk , CancellationToken token )
321+ {
322+ if ( pk == null )
323+ return false ;
324+
325+ var print = ( Species ) pk . Species ;
326+ Log ( $ "Battle Encounter: { Hub . Config . StopConditions . GetPrintName ( pk ) } ") ;
327+
328+ if ( DumpSetting . Dump && ! string . IsNullOrEmpty ( DumpSetting . DumpFolder ) )
329+ DumpPokemon ( DumpSetting . DumpFolder , "encounters" , pk ) ;
330+
331+ if ( ! StopConditionSettings . EncounterFound ( pk , DesiredMinIVs , DesiredMaxIVs , Hub . Config . StopConditions , WantedNatures , UnwantedMarks ) )
332+ return false ;
333+
334+ if ( Hub . Config . StopConditions . CaptureVideoClip )
335+ {
336+ await Task . Delay ( Hub . Config . StopConditions . ExtraTimeWaitCaptureVideo , token ) . ConfigureAwait ( false ) ;
337+ await PressAndHold ( CAPTURE , 2_000 , 0 , token ) . ConfigureAwait ( false ) ;
338+ }
339+
340+ var msg = $ "Result found!\n { print } \n Stopping routine execution; restart the bot to search again.";
341+
342+ if ( ! string . IsNullOrWhiteSpace ( Hub . Config . StopConditions . MatchFoundEchoMention ) )
343+ msg = $ "{ Hub . Config . StopConditions . MatchFoundEchoMention } { msg } ";
344+ Log ( msg ) ;
345+
346+ return true ;
347+ }
311348 }
312349}
0 commit comments