Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1575,12 +1575,13 @@ int grass_spin(ConsoleHandle& console, ProControllerContext& context, bool leftr

context.wait_for_all_requests();
console.log("Starting grass spin.");
WallClock deadline = current_time() + timeout;

const size_t spins = (size_t)(timeout / 366ms);

int ret = run_until<ProControllerContext>(
console, context,
[leftright, deadline](ProControllerContext& context){
while (current_time() < deadline){
[leftright, spins](ProControllerContext& context){
for (size_t c = 0; c < spins; c++){
if (leftright){
pbf_move_left_joystick(context, {+1, 0}, 33ms, 150ms);
pbf_move_left_joystick(context, {-1, 0}, 33ms, 150ms);
Expand All @@ -1597,7 +1598,17 @@ int grass_spin(ConsoleHandle& console, ProControllerContext& context, bool leftr
return -1;
}

bool encounter_shiny = handle_encounter(console, context, true);
bool encounter_shiny;
try{
encounter_shiny = handle_encounter(console, context, true);
}catch (OperationFailedException&){
// check to see if it was a false positive
if (!in_overworld(console, context)){
throw;
}
console.log("grass_spin(): No battle started. Still in the overworld.", COLOR_RED);
return -1;
}
return encounter_shiny ? 1 : 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ void heal_at_pokecenter(ConsoleHandle& console, ProControllerContext& context);
// Can be used to alternate left/right and up/down. It is important that the player is not facing
// the same direction as the first thumbstick press.
// returns -1 if no encounter is triggered, 0 if a non-shiny is encounter, and 1 if a shiny is encountered
// A spin that stops without starting a battle also returns -1, as long as the player is still in the overworld.
int grass_spin(ConsoleHandle& console, ProControllerContext& context, bool leftright, Seconds timeout = 60s);

// Trigger encounters by fishing with a registered rod. The player must be facing water.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ int encounter_roamer(

context.wait_for_all_requests();
pbf_move_left_joystick(context, {0, +1}, 200ms, 800ms);
int ret = grass_spin(console, context, true, 5s);
int ret = grass_spin(console, context, true, 8s);
if (ret < 0){
attempts++;
pbf_move_left_joystick(context, {0, -1}, 200ms, 800ms);
Expand Down
Loading