@@ -83,6 +83,12 @@ GimmighoulChestFarmer::GimmighoulChestFarmer()
8383 " <b>Fix Time when Done:</b><br>Fix the time after the program finishes." ,
8484 LockMode::UNLOCK_WHILE_RUNNING, false
8585 )
86+ , ADDITIONAL_BATTLE_WAIT_TIME(
87+ " <b>Additional Battle Wait Time:</b><br>Increase this if you are timing out when entering battle." ,
88+ LockMode::LOCK_WHILE_RUNNING,
89+ TICKS_PER_SECOND,
90+ " 1250"
91+ )
8692 , NOTIFICATION_STATUS_UPDATE(" Status Update" , true , false , std::chrono::seconds(3600 ))
8793 , NOTIFICATIONS({
8894 &NOTIFICATION_STATUS_UPDATE,
@@ -94,11 +100,36 @@ GimmighoulChestFarmer::GimmighoulChestFarmer()
94100 PA_ADD_OPTION (START_LOCATION);
95101 PA_ADD_OPTION (GO_HOME_WHEN_DONE);
96102 PA_ADD_OPTION (FIX_TIME_WHEN_DONE);
103+ PA_ADD_OPTION (ADDITIONAL_BATTLE_WAIT_TIME);
97104 PA_ADD_OPTION (NOTIFICATIONS);
98105}
99106
107+ void GimmighoulChestFarmer::navigate_to_gimmi (SingleSwitchProgramEnvironment& env, BotBaseContext& context) {
108+ // Cursor is already in position
109+ fly_to_overworld_from_map (env.program_info (), env.console , context);
110+ pbf_move_left_joystick (context, 0 , 0 , 158 , 0 );
111+ pbf_press_button (context, BUTTON_L, 50 , 40 );
112+ pbf_move_left_joystick (context, 128 , 0 , 100 , 0 );
113+ // Climb ladder
114+ pbf_press_button (context, BUTTON_L, 50 , 40 );
115+ pbf_move_left_joystick (context, 128 , 0 , 2350 , 0 );
116+ pbf_press_button (context, BUTTON_L, 50 , 40 );
117+ pbf_wait (context, 100 );
118+ context.wait_for_all_requests ();
119+ // Walk into the wall
120+ pbf_move_left_joystick (context, 128 , 0 , 200 , 100 );
121+ context.wait_for_all_requests ();
122+ // Turn back
123+ pbf_move_left_joystick (context, 128 , 255 , 60 , 100 );
124+ context.wait_for_all_requests ();
125+ // Position toward chest
126+ pbf_move_left_joystick (context, 128 , 0 , 30 , 0 );
127+ context.wait_for_all_requests ();
128+ }
129+
100130void GimmighoulChestFarmer::program (SingleSwitchProgramEnvironment& env, BotBaseContext& context){
101131 assert_16_9_720p_min (env.logger (), env.console );
132+ GimmighoulChestFarmer_Descriptor::Stats& stats = env.current_stats <GimmighoulChestFarmer_Descriptor::Stats>();
102133
103134 if (START_LOCATION == StartLocation::FlyPoint){
104135 // Set starting position by flying - must fly to East Province (Area One) Watchtower, do not move from fly point
@@ -128,81 +159,37 @@ void GimmighoulChestFarmer::program(SingleSwitchProgramEnvironment& env, BotBase
128159 }
129160 // else assuming player is positioned correctly in front of the chest
130161
131- GimmighoulChestFarmer_Descriptor::Stats& stats = env.current_stats <GimmighoulChestFarmer_Descriptor::Stats>();
132162 uint32_t c = 0 ;
133163 while (c < PP){
134-
135164 // Press A to enter battle, assuming there is a chest
136165 env.log (" Fetch Attempts: " + tostr_u_commas (c));
137- pbf_mash_button (context, BUTTON_A, 90 );
166+ pbf_mash_button (context, BUTTON_A, 125 );
167+ pbf_wait (context, 125 ); // Wait extra to make sure the overworld map vanishes
168+ context.wait_for_all_requests ();
138169
139- // Wait for the battle to load then check for battle menu, if there isn't a battle menu then no chest
140- NormalBattleMenuWatcher battle_menu (COLOR_YELLOW );
141- int ret = wait_until (
170+ OverworldWatcher battleStarting (env. console , COLOR_RED);
171+ NormalBattleMenuWatcher battle_detected (COLOR_RED );
172+ int retOverworld = wait_until (
142173 env.console , context,
143- std::chrono::seconds (10 ),
144- { battle_menu }
174+ std::chrono::seconds (5 ),
175+ {battleStarting, battle_detected }
145176 );
146-
147- if (ret == 0 ){
148- // Attack using your first move
149- pbf_mash_button (context, BUTTON_A, 90 );
150- c++;
151- context.wait_for_all_requests ();
152- OverworldWatcher overworld (env.console , COLOR_RED);
153- int ret2 = wait_until (
177+ if (retOverworld != 0 ) {
178+ // Wait for the battle to load then check for battle menu, if there isn't a battle menu then no chest
179+ NormalBattleMenuWatcher battle_menu (COLOR_YELLOW);
180+ int ret = wait_until (
154181 env.console , context,
155- std::chrono::seconds (120 ),
156- { overworld }
157- );
158- if (ret2 != 0 ){
159- stats.errors ++;
160- env.update_stats ();
161- OperationFailedException::fire (
162- ErrorReport::SEND_ERROR_REPORT,
163- " Failed to return to Overworld after two minutes. Did your attack miss or fail to defeat Gimmighoul in one hit?" ,
164- env.console
165- );
166- }
167- stats.pokemon_fainted ++;
168- env.update_stats ();
169- send_program_status_notification (env, NOTIFICATION_STATUS_UPDATE);
170-
171- // Set starting position by flying - move map cursor
172- open_map_from_overworld (env.program_info (), env.console , context);
173- pbf_press_button (context, BUTTON_ZR, 50 , 40 );
174- pbf_move_left_joystick (context, 48 , 192 , 10 , 0 );
175- fly_to_overworld_from_map (env.program_info (), env.console , context);
176- pbf_move_left_joystick (context, 0 , 0 , 158 , 0 );
177- pbf_press_button (context, BUTTON_L, 50 , 40 );
178- pbf_move_left_joystick (context, 128 , 0 , 100 , 0 );
179- // Climb ladder
180- pbf_press_button (context, BUTTON_L, 50 , 40 );
181- pbf_move_left_joystick (context, 128 , 0 , 2350 , 0 );
182- pbf_press_button (context, BUTTON_L, 50 , 40 );
183- pbf_wait (context, 100 );
184- context.wait_for_all_requests ();
185- // Walk into the wall
186- pbf_move_left_joystick (context, 128 , 0 , 200 , 100 );
187- context.wait_for_all_requests ();
188- // Turn back
189- pbf_move_left_joystick (context, 128 , 255 , 60 , 100 );
190- context.wait_for_all_requests ();
191- // Position toward chest
192- pbf_move_left_joystick (context, 128 , 0 , 30 , 0 );
193- context.wait_for_all_requests ();
194-
195- // Check for tauros interrupt before pressing A - reset position if there was one
196- ret = wait_until (
197- env.console , context,
198- std::chrono::seconds (1 ),
182+ std::chrono::milliseconds (ADDITIONAL_BATTLE_WAIT_TIME * (1000 / TICKS_PER_SECOND)),
199183 { battle_menu }
200184 );
185+
201186 if (ret == 0 ){
187+ // Attack using your first move
202188 pbf_mash_button (context, BUTTON_A, 90 );
203189 c++;
204190 context.wait_for_all_requests ();
205- ret2 = wait_until (
191+ OverworldWatcher overworld (env.console , COLOR_RED);
192+ int ret2 = wait_until (
206193 env.console , context,
207194 std::chrono::seconds (120 ),
208195 { overworld }
@@ -212,37 +199,53 @@ void GimmighoulChestFarmer::program(SingleSwitchProgramEnvironment& env, BotBase
212199 env.update_stats ();
213200 OperationFailedException::fire (
214201 ErrorReport::SEND_ERROR_REPORT,
215- " Failed to return to Overworld after two minutes." ,
202+ " Failed to return to Overworld after two minutes. Did your attack miss or fail to defeat Gimmighoul in one hit? " ,
216203 env.console
217204 );
218205 }
219- // Don't move map cursor this time
220- open_map_from_overworld (env.program_info (), env.console , context);
221- fly_to_overworld_from_map (env.program_info (), env.console , context);
222- pbf_move_left_joystick (context, 0 , 0 , 158 , 0 );
223- pbf_press_button (context, BUTTON_L, 50 , 40 );
224- pbf_move_left_joystick (context, 128 , 0 , 100 , 0 );
225- // Climb ladder
226- pbf_press_button (context, BUTTON_L, 50 , 40 );
227- pbf_move_left_joystick (context, 128 , 0 , 2350 , 0 );
228- pbf_press_button (context, BUTTON_L, 50 , 40 );
229- pbf_wait (context, 100 );
230- context.wait_for_all_requests ();
231- // Walk into the wall
232- pbf_move_left_joystick (context, 128 , 0 , 200 , 100 );
233- context.wait_for_all_requests ();
234- // Turn back
235- pbf_move_left_joystick (context, 128 , 255 , 60 , 100 );
236- context.wait_for_all_requests ();
237- // Position toward chest
238- pbf_move_left_joystick (context, 128 , 0 , 30 , 0 );
239- context.wait_for_all_requests ();
240-
241- stats.wild_interrupts ++;
206+ stats.pokemon_fainted ++;
242207 env.update_stats ();
243208 send_program_status_notification (env, NOTIFICATION_STATUS_UPDATE);
244- }
245209
210+ // Set starting position by flying - move map cursor
211+ open_map_from_overworld (env.program_info (), env.console , context);
212+ pbf_press_button (context, BUTTON_ZR, 50 , 40 );
213+ pbf_move_left_joystick (context, 48 , 192 , 10 , 0 );
214+ navigate_to_gimmi (env, context);
215+
216+ // Check for tauros interrupt before pressing A - reset position if there was one
217+ ret = wait_until (
218+ env.console , context,
219+ std::chrono::seconds (1 ),
220+ { battle_menu }
221+ );
222+ if (ret == 0 ){
223+ pbf_mash_button (context, BUTTON_A, 90 );
224+ c++;
225+ context.wait_for_all_requests ();
226+ ret2 = wait_until (
227+ env.console , context,
228+ std::chrono::seconds (120 ),
229+ { overworld }
230+ );
231+ if (ret2 != 0 ){
232+ stats.errors ++;
233+ env.update_stats ();
234+ OperationFailedException::fire (
235+ ErrorReport::SEND_ERROR_REPORT,
236+ " Failed to return to Overworld after two minutes." ,
237+ env.console
238+ );
239+ }
240+ // Don't move map cursor this time
241+ open_map_from_overworld (env.program_info (), env.console , context);
242+ navigate_to_gimmi (env, context);
243+
244+ stats.wild_interrupts ++;
245+ env.update_stats ();
246+ send_program_status_notification (env, NOTIFICATION_STATUS_UPDATE);
247+ }
248+ }
246249 }
247250
248251 // Save the game
0 commit comments