Skip to content

Commit 33d530f

Browse files
author
Gin
committed
Revert "cleanup again"
This reverts commit 11cfbf4. At Zone 4, NPC outside gate that can talk to. So we cannot mash A again to ensure we are outside zone
1 parent 1d29532 commit 33d530f

File tree

4 files changed

+63
-30
lines changed

4 files changed

+63
-30
lines changed

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_BasicNavigation.cpp

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -424,25 +424,20 @@ double get_angle_between_facing_directions(double dir1, double dir2){
424424
return angle;
425425
}
426426

427-
void leave_zone_gate(ConsoleHandle& console, ProControllerContext& context){
427+
bool leave_zone_gate(ConsoleHandle& console, ProControllerContext& context){
428428
console.log("Leaving zone gate");
429429

430-
auto mash_A_to_leave = [&](int seconds) -> int{
431-
OverworldPartySelectionWatcher overworld_watcher(COLOR_WHITE, &console.overlay());
432-
pbf_mash_button(context, BUTTON_A, 1s);
433-
context.wait_for_all_requests();
434-
int ret = wait_until(
435-
console, context,
436-
std::chrono::seconds(seconds),
437-
{overworld_watcher}
438-
);
439-
pbf_wait(context, 100ms); // after leaving the gate, the game needs this long time to give back control
440-
context.wait_for_all_requests();
441-
return ret;
442-
};
443-
444430
WallClock start_time = current_time();
445-
mash_A_to_leave(40); // // wait 40 sec in case day/night change happens
431+
OverworldPartySelectionWatcher overworld_watcher(COLOR_WHITE, &console.overlay());
432+
pbf_mash_button(context, BUTTON_A, 1s);
433+
context.wait_for_all_requests();
434+
wait_until(
435+
console, context,
436+
std::chrono::seconds(40), // wait this long in case day/night change happens
437+
{overworld_watcher}
438+
);
439+
pbf_wait(context, 100ms); // after leaving the gate, the game needs this long time to give back control
440+
context.wait_for_all_requests();
446441
WallClock end_time = current_time();
447442

448443
const auto duration = end_time - start_time;
@@ -457,19 +452,11 @@ void leave_zone_gate(ConsoleHandle& console, ProControllerContext& context){
457452
// In this case, there is no day/night change. We are sure we are outside the wild zone
458453
// (unless some angry Garchomp or Drilbur used Dig and escaped wild zone containment... We don't
459454
// consider this case for now)
460-
return;
455+
return true;
461456
}
462457

463458
console.log("Leaving zone function took " + std::to_string(second_count) + " sec. Day/night change happened");
464-
int ret = mash_A_to_leave(15);
465-
if (ret != 0){
466-
OperationFailedException::fire(
467-
ErrorReport::SEND_ERROR_REPORT,
468-
"leave_zone_gate(): Unable to leave zone gate after day/night change",
469-
console
470-
);
471-
}
472-
return;
459+
return false;
473460
}
474461

475462

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,15 @@ double get_facing_direction(ConsoleHandle& console, ProControllerContext& contex
9797
double get_angle_between_facing_directions(double dir1, double dir2);
9898

9999
// While at the gate in the zone, mash A to leave the zone. If day/night changes while
100-
// leaving, it will wait until the change is done to leave the zone again.
101-
void leave_zone_gate(ConsoleHandle& console, ProControllerContext& context);
100+
// leaving, it will wait until the change is done.
101+
// Return true if there is no day/night change.
102+
// Return false if day/night change happens. In this case, we don't know if the player
103+
// character is still inside the zone or not.
104+
// Note:
105+
// We don't want to mash A after a day/night change to ensure we leave the zone because
106+
// at Wild Zone 4 there are talkable npcs outside the gate. Button A appears on them.
107+
// If the program mashes A after leaving the zone, it will stuck talking to the npcs.
108+
bool leave_zone_gate(ConsoleHandle& console, ProControllerContext& context);
102109

103110
// Run towards a wild zone until either button A is detected at specified box region,
104111
// or day/night change happens. If day/night changes, it will wait until the transition

SerialPrograms/Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneCafe.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,11 @@ void do_one_cafe_trip(
220220

221221
// Found button A, so we are at the entrance.
222222
// Mash A to leave Zone.
223-
leave_zone_gate(env.console, context);
223+
if (!leave_zone_gate(env.console, context)){
224+
// day/night change happens while leaving
225+
// Try leave again
226+
leave_zone_gate(env.console, context);
227+
}
224228
shiny_sound_handler.process_pending(context);
225229

226230
// do a fast travel back to cafe

SerialPrograms/Source/PokemonLZA/Programs/ShinyHunting/PokemonLZA_WildZoneEntrance.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,45 @@ void leave_zone_and_reset_spawns(
362362

363363
std::string extra_eror_msg = " This is after leaving zone.";
364364

365-
leave_zone_gate(env.console, context);
365+
// Due to day/night change may eating the mashing button A sequence, we may still be inside the zone!
366+
// We need to check if we can fast travel
367+
if (leave_zone_gate(env.console, context)){
368+
shiny_sound_handler.process_pending(context);
369+
// Do a fast travel outside the gate to reset spawns
370+
fast_travel_outside_zone(env, context, wild_zone, to_max_zoom_level_on_map, std::move(extra_eror_msg));
371+
return;
372+
}
366373

374+
// there is a day/night change while leaving the zone. We don't know if we are still inside the zone.
375+
//
376+
// We can't call leave_zone_gate() again because at Wild Zone 4 there are npcs outside the gate that can
377+
// press A to talk to. If the program can get stuck into talking to the npc.
378+
379+
FastTravelState travel_status = open_map_and_fly_in_place(env.console, context, to_max_zoom_level_on_map);
380+
if (travel_status == FastTravelState::SUCCESS){
381+
// We can fast travel and we fast traveled. This means we were inside the gate but now safe.
382+
env.log("We fast traveled. We were inside the gate but now safe for next trip");
383+
return;
384+
}else if(travel_status == FastTravelState::NOT_AT_FLY_SPOT){
385+
env.log("We cannot fast travel in place. We left zone successfully");
386+
// we cannot fast travel at current location. So we have left the zone!
387+
// Fast travel to the zone gate to reset spawn
388+
const bool map_already_opened = true;
389+
fast_travel_outside_zone(env, context, wild_zone, to_max_zoom_level_on_map,
390+
std::move(extra_eror_msg), map_already_opened);
391+
return;
392+
}
393+
// We cannot fast travel: we are still being chased by wild pokemon
394+
env.log("We cannot fast travel. Still chased by pokemon");
395+
396+
// Mash B to close map and return to overworld
397+
map_to_overworld(env.console, context);
398+
// Mash A to leave zone gate
399+
env.log("Mashing A again to leave zone");
400+
leave_zone_gate(env.console, context);
367401
shiny_sound_handler.process_pending(context);
368402
// Do a fast travel outside the gate to reset spawns
403+
env.log("Finally, we should have left the zone");
369404
fast_travel_outside_zone(env, context, wild_zone, to_max_zoom_level_on_map, std::move(extra_eror_msg));
370405
}
371406

0 commit comments

Comments
 (0)