Skip to content
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Blueberry Quests

Check failure on line 1 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

<file>: file_lines=1366, limit=1000, allowed 1322
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -438,9 +438,19 @@
return quest_completed;
}

void quest_make_tm(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){

Check failure on line 441 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::quest_make_tm( const ProgramInfo & info , VideoStream & stream , ProControllerContext & context): function_lines=124, limit=50, allowed 80
stream.log("Quest: Make TM");

//The index of the last craftable TM in this program run. The machine opens on the first
//TM, and the craftable one moves only a few places between quests as materials run out,
//so starting there saves walking past the same uncraftable TMs (~2.5 s each) every time.
static WallClock last_tm_run = WallClock::min();
static int last_tm_index = 0;
if (last_tm_run != info.start_time){
last_tm_run = info.start_time;
last_tm_index = 0;
}

//Mount and then dismount in case you're crouched
pbf_press_button(context, BUTTON_PLUS, 160ms, 840ms);
pbf_press_button(context, BUTTON_PLUS, 160ms, 840ms);
Expand Down Expand Up @@ -469,28 +479,62 @@
if (enter_machine == 0){
stream.log("TM machine entered. Finding TM to make.");

int make_tm = run_until<ProControllerContext>(
stream, context,
[&](ProControllerContext& context){
for (int i = 0; i < 229; i++){ //229 is max number of TMs
//click on tm
pbf_press_button(context, BUTTON_A, 160ms, 400ms);
pbf_wait(context, 800ms);
context.wait_for_all_requests();

//not craftable, close and move on to next
int make_tm = -1;
if (last_tm_index > 0){
stream.log("Trying TM " + std::to_string(last_tm_index + 1) + " first, the last one made.");
make_tm = run_until<ProControllerContext>(
stream, context,
[&](ProControllerContext& context){
for (int i = 0; i < last_tm_index; i++){
pbf_press_dpad(context, DPAD_RIGHT, 160ms, 160ms);
}
pbf_press_button(context, BUTTON_A, 160ms, 400ms);
pbf_press_dpad(context, DPAD_RIGHT, 160ms, 160ms);
pbf_wait(context, 800ms);
context.wait_for_all_requests();
},
{{ makeTM }}
);
context.wait_for_all_requests();
if (make_tm != 0){
stream.log("Not craftable. Scanning from the first TM.");
pbf_press_button(context, BUTTON_A, 160ms, 400ms);
for (int i = 0; i < last_tm_index; i++){
pbf_press_dpad(context, DPAD_LEFT, 160ms, 160ms);
}
},
{{ makeTM }}
);
context.wait_for_all_requests();
pbf_wait(context, 800ms);
context.wait_for_all_requests();
}
}

if (make_tm != 0){
int tm_index = 0;
make_tm = run_until<ProControllerContext>(
stream, context,
[&](ProControllerContext& context){
for (int i = 0; i < 229; i++){ //229 is max number of TMs
//click on tm
tm_index = i;
pbf_press_button(context, BUTTON_A, 160ms, 400ms);
pbf_wait(context, 800ms);
context.wait_for_all_requests();

//not craftable, close and move on to next
pbf_press_button(context, BUTTON_A, 160ms, 400ms);
pbf_press_dpad(context, DPAD_RIGHT, 160ms, 160ms);
pbf_wait(context, 800ms);
context.wait_for_all_requests();
}
},
{{ makeTM }}
);
context.wait_for_all_requests();
if (make_tm == 0){
last_tm_index = tm_index;
}
}

if (make_tm == 0){
stream.log("Craftable TM found. Making TM");
stream.log("Craftable TM found. Making TM " + std::to_string(last_tm_index + 1) + ".");

pbf_mash_button(context, BUTTON_A, 1760ms);
context.wait_for_all_requests();
Expand Down
Loading