@@ -27,7 +27,7 @@ public BotOverworld7B(PokeBotState cfg, PokeBotHub<PK8> hub) : base(cfg)
27
27
public override async Task MainLoop ( CancellationToken token )
28
28
{
29
29
Log ( "Identifying trainer data of the host console." ) ;
30
- var sav = await IdentifyTrainer ( token ) . ConfigureAwait ( false ) ;
30
+ await IdentifyTrainer ( token ) . ConfigureAwait ( false ) ;
31
31
await InitializeHardware ( Settings , token ) . ConfigureAwait ( false ) ;
32
32
33
33
try
@@ -65,11 +65,10 @@ private async Task Overworld(CancellationToken token, bool birds = false)
65
65
var i = 0 ;
66
66
var freeze = false ;
67
67
var searchforshiny = Settings . OnlyShiny ;
68
- uint newspawn ;
68
+ int newspawn ;
69
69
uint catchcombo ;
70
70
uint speciescombo ;
71
71
bool found ;
72
- int lastSpawn ;
73
72
74
73
if ( movementslist . Count > 0 )
75
74
Log ( $ "{ Environment . NewLine } ----------------------------------------{ Environment . NewLine } " +
@@ -151,36 +150,40 @@ private async Task Overworld(CancellationToken token, bool birds = false)
151
150
152
151
//Check if inside an unwanted encounter
153
152
if ( await IsInCatchScreen ( token ) . ConfigureAwait ( false ) )
154
- await FleeToOverworld ( token ) . ConfigureAwait ( false ) ;
155
-
156
- //Check new spawns
157
- newspawn = BitConverter . ToUInt16 ( await Connection . ReadBytesAsync ( LastSpawn , 2 , token ) . ConfigureAwait ( false ) , 0 ) ;
158
- if ( newspawn != 0 )
159
153
{
160
- //Count and log the LastSpawn
161
- encounterCount ++ ;
162
- Settings . AddCompletedScans ( ) ;
163
- lastSpawn = ( int ) newspawn ;
164
- var msg = $ "New spawn ({ encounterCount } ): { lastSpawn } { SpeciesName . GetSpeciesName ( ( int ) lastSpawn , 4 ) } ";
165
- Log ( msg ) ;
166
-
167
- //Set the LastSpawn to 0, so we can account multiple consecutive spawns of the same species. Thanks Anubis for the suggestion!
154
+ await FleeToOverworld ( token ) . ConfigureAwait ( false ) ;
155
+ //The encounter changes the LastSpawn value.
168
156
await Connection . WriteBytesAsync ( new byte [ ] { 0x0 , 0x0 } , LastSpawn , token ) . ConfigureAwait ( false ) ;
169
-
170
- if ( ! searchforshiny &&
171
- ( ( ! birds && lastSpawn == ( int ) Settings . StopOnSpecies ) ||
172
- ( ! birds && ( int ) Settings . StopOnSpecies == 0 ) ||
173
- ( birds && ( lastSpawn == 144 || lastSpawn == 145 || lastSpawn == 146 ) ) ) )
157
+ }
158
+ else
159
+ {
160
+ //Check new spawns
161
+ newspawn = BitConverter . ToUInt16 ( await Connection . ReadBytesAsync ( LastSpawn , 2 , token ) . ConfigureAwait ( false ) , 0 ) ;
162
+ if ( newspawn != 0 )
174
163
{
175
- await Click ( X , 1_000 , token ) . ConfigureAwait ( false ) ;
176
- await Click ( HOME , 1_000 , token ) . ConfigureAwait ( false ) ;
177
-
178
- msg = "Stop conditions met, restart the bot(s) to search again." ;
179
- if ( ! string . IsNullOrWhiteSpace ( Hub . Config . StopConditions . MatchFoundEchoMention ) )
180
- msg = $ "{ Hub . Config . StopConditions . MatchFoundEchoMention } { msg } ";
181
- Log ( msg ) ;
182
-
183
- return ;
164
+ //Count and log the LastSpawn
165
+ encounterCount ++ ;
166
+ Settings . AddCompletedScans ( ) ;
167
+ Log ( $ "New spawn ({ encounterCount } ): { newspawn } { SpeciesName . GetSpeciesName ( newspawn , 4 ) } ") ;
168
+
169
+ //Set the LastSpawn to 0, so we can account multiple consecutive spawns of the same species. Thanks Anubis for the suggestion!
170
+ await Connection . WriteBytesAsync ( new byte [ ] { 0x0 , 0x0 } , LastSpawn , token ) . ConfigureAwait ( false ) ;
171
+
172
+ if ( ! searchforshiny &&
173
+ ( ( ! birds && newspawn == ( int ) Settings . StopOnSpecies ) ||
174
+ ( ! birds && ( int ) Settings . StopOnSpecies == 0 ) ||
175
+ ( birds && ( newspawn == 144 || newspawn == 145 || newspawn == 146 ) ) ) )
176
+ {
177
+ await Click ( X , 1_000 , token ) . ConfigureAwait ( false ) ;
178
+ await Click ( HOME , 1_000 , token ) . ConfigureAwait ( false ) ;
179
+
180
+ var msg = "Stop conditions met, restart the bot(s) to search again." ;
181
+ if ( ! string . IsNullOrWhiteSpace ( Hub . Config . StopConditions . MatchFoundEchoMention ) )
182
+ msg = $ "{ Hub . Config . StopConditions . MatchFoundEchoMention } { msg } ";
183
+ Log ( msg ) ;
184
+
185
+ return ;
186
+ }
184
187
}
185
188
}
186
189
}
@@ -190,13 +193,12 @@ private async Task Overworld(CancellationToken token, bool birds = false)
190
193
191
194
await Unfreeze ( token , version ) . ConfigureAwait ( false ) ;
192
195
freeze = false ;
193
- await Task . Delay ( 0_500 , token ) . ConfigureAwait ( false ) ;
194
- newspawn = BitConverter . ToUInt16 ( await Connection . ReadBytesAsync ( LastSpawn , 2 , token ) . ConfigureAwait ( false ) , 0 ) ;
196
+ newspawn = BitConverter . ToUInt16 ( await Connection . ReadBytesAsync ( LastSpawn_r , 2 , token ) . ConfigureAwait ( false ) , 0 ) ;
195
197
196
198
//Stop Conditions
197
- if ( birds && ( ( int ) newspawn == 144 || ( int ) newspawn == 145 || ( int ) newspawn == 146 ) && ! token . IsCancellationRequested )
199
+ if ( birds && ( newspawn == 144 || newspawn == 145 || newspawn == 146 ) && ! token . IsCancellationRequested )
198
200
found = true ;
199
- else if ( ( ! birds && ( int ) Settings . StopOnSpecies > 0 && ( int ) newspawn == ( int ) Settings . StopOnSpecies ) ||
201
+ else if ( ( ! birds && ( int ) Settings . StopOnSpecies > 0 && newspawn == ( int ) Settings . StopOnSpecies ) ||
200
202
( ! birds && ( int ) Settings . StopOnSpecies == 0 ) )
201
203
found = true ;
202
204
else
@@ -317,17 +319,10 @@ private async Task FleeToOverworld(CancellationToken token)
317
319
{
318
320
await ResetStick ( token ) . ConfigureAwait ( false ) ;
319
321
Log ( $ "Unwanted encounter detected!") ;
320
- int i = 0 ;
321
- while ( await IsInCatchScreen ( token ) . ConfigureAwait ( false ) && ! token . IsCancellationRequested )
322
- {
323
- i ++ ;
324
- await Task . Delay ( 8_000 , token ) . ConfigureAwait ( false ) ;
325
- if ( i > 2 )
326
- await Click ( B , 1_200 , token ) . ConfigureAwait ( false ) ;
322
+ while ( ! await IsInConfirmDialog ( token ) . ConfigureAwait ( false ) && ! token . IsCancellationRequested )
327
323
await Click ( B , 1_200 , token ) . ConfigureAwait ( false ) ;
328
- await Click ( A , 1_000 , token ) . ConfigureAwait ( false ) ;
329
- await Task . Delay ( 6_500 , token ) . ConfigureAwait ( false ) ;
330
- }
324
+ await Click ( A , 1_000 , token ) . ConfigureAwait ( false ) ;
325
+ while ( await IsInCatchScreen ( token ) . ConfigureAwait ( false ) && ! token . IsCancellationRequested ) { }
331
326
Log ( $ "Exited wild encounter.") ;
332
327
}
333
328
}
0 commit comments