Skip to content
Closed
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 @@ -9,6 +9,7 @@
#include "Tests/ImageUnitTest.h"
#include "VideoGames/PokemonSV/Inference/PokemonSV_BlueberryPointsReader.h"
#include "VideoGames/PokemonSV/Options/PokemonSV_BBQuests.h"
#include "PokemonSV_BlueberryCatchPhoto.h"
#include "PokemonSV_BlueberryQuests.h"
#include "PokemonSV_BBQTests.h"

Expand Down Expand Up @@ -122,6 +123,79 @@
}


namespace{

// A catch quest, whether this attempt already battled, and whether a wild
// battle on the way back to Central Plaza should be caught instead of fled.
struct BBQCatchOnReturnScenario{
std::string name;
BBQuests quest;
bool battled_this_attempt = false;
bool expected_catch = false;
};

class Test_BBQCatchOnReturn : public UnitTest{
public:
Test_BBQCatchOnReturn(BBQCatchOnReturnScenario scenario)
: UnitTest("PokemonSV::BBQCatchOnReturn - " + scenario.name)
, m_scenario(std::move(scenario))
{}

virtual UnitTestResult run(Logger&, CancellableScope&) const override{
const bool got = catch_quest_catches_on_return(m_scenario.quest, m_scenario.battled_this_attempt);
if (got != m_scenario.expected_catch){
return std::string("Expected ") + (m_scenario.expected_catch ? "catch" : "flee")
+ ", got " + (got ? "catch" : "flee");
}
return true;
}

private:
const BBQCatchOnReturnScenario m_scenario;
};

}

Check failure on line 157 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace

static void add_tests_BBQCatchOnReturn(UnitTestDatabase& database){

Check warning on line 159 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health (advisory)

PokemonAutomation::NintendoSwitch::PokemonSV::add_tests_BBQCatchOnReturn( UnitTestDatabase & database): function_lines=38 (advisory above 25, limit 50)
using enum BBQuests;
const BBQCatchOnReturnScenario scenarios[] = {
{
// The target spawned late or not at all: any wild Pokemon completes the quest.
.name = "catch any without a battle catches",
.quest = catch_any,
.expected_catch = true,
},
{
// Already caught this attempt: fleeing is faster than a second catch.
.name = "catch any after a battle flees",
.quest = catch_any,
.battled_this_attempt = true,
},
{
// The type of a wild Pokemon is not read in battle.
.name = "catch normal without a battle flees",
.quest = catch_normal,
},
{
.name = "catch fire without a battle flees",
.quest = catch_fire,
},
{
.name = "catch psychic without a battle flees",
.quest = catch_psychic,
},
{
.name = "catch fighting after a battle flees",
.quest = catch_fighting,
.battled_this_attempt = true,
},
};
for (const BBQCatchOnReturnScenario& scenario : scenarios){
database.add<Test_BBQCatchOnReturn>(scenario);
}
}


void add_tests_BBQ(UnitTestDatabase& database){
database.add<Test_BBQuestsSlugs>();

Expand All @@ -134,6 +208,7 @@
database.add<Test_BlueberryPoints>("PokemonSV/BlueberryPoints/6740.png", 6740, 1280, 720);

add_tests_TeraEncounterAction(database);
add_tests_BBQCatchOnReturn(database);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Blueberry Catch Photo

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

View workflow job for this annotation

GitHub Actions / code-health

Code health

<file>: file_lines=1088, limit=1000, allowed 1057
*
* From: https://github.com/PokemonAutomation/
*
Expand Down Expand Up @@ -893,13 +893,18 @@
}
}

bool catch_quest_catches_on_return(BBQuests current_quest, bool battled_this_attempt){
return current_quest == BBQuests::catch_any && !battled_this_attempt;
}

void quest_catch(

Check failure on line 900 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::quest_catch( const ProgramInfo & info , ConsoleHandle & console , ProControllerContext & context , const BBQOption & BBQ_OPTIONS , BBQuests current_quest): function_lines=104, limit=50, allowed 77
const ProgramInfo& info,
ConsoleHandle& console, ProControllerContext& context,
const BBQOption& BBQ_OPTIONS,
BBQuests current_quest
){
EncounterWatcher encounter_watcher(console, COLOR_RED);
bool battle_menu_seen = false;

//Navigate to target and start battle
int ret = run_until<ProControllerContext>(
Expand All @@ -915,7 +920,11 @@
std::chrono::seconds(25),
{ battle_menu }
);
if (ret2 != 0){
if (ret2 == 0){
//encounter_watcher looks for the same battle menu. If this watcher
//sees it first, run_until() returns -1 even though a battle started.
battle_menu_seen = true;
}else{
console.log("Did not enter battle. Did target spawn?");
}
},
Expand All @@ -926,7 +935,8 @@
);
encounter_watcher.throw_if_no_sound();

if (ret >= 0){
bool battled = false;
if (ret >= 0 || battle_menu_seen){
console.log("Battle menu detected.");

bool is_shiny = (bool)encounter_watcher.shiny_screenshot();
Expand All @@ -936,10 +946,22 @@
throw ProgramFinishedException();
}else{
quest_catch_handle_battle(info, console, context, BBQ_OPTIONS, current_quest);
battled = true;
}
}

return_to_plaza(info, console, context);
while (true){
if (!catch_quest_catches_on_return(current_quest, battled)){
return_to_plaza(info, console, context);
break;
}
if (!return_to_plaza_unless_battle(info, console, context)){
break;
}
console.log("Battle on the way back to Central Plaza. Any wild Pokemon counts: catching it.");
quest_catch_handle_battle(info, console, context, BBQ_OPTIONS, current_quest);
battled = true;
}

//Day skip and attempt to respawn fixed encounters
pbf_press_button(context, BUTTON_HOME, 160ms, GameSettings::instance().GAME_TO_HOME_DELAY1);
Expand All @@ -948,6 +970,15 @@
pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
resume_game_from_home(console, context);

//Nothing to heal without a battle (return_to_plaza() flees with a Smoke Ball).
//The player is still on the Central Plaza fly point, where return_to_plaza()
//landed, so the central_to_* routes need no re-fly either.
if (!battled){
console.log("No battle this attempt. Skipping the Pokecenter heal.");
context.wait_for_all_requests();
return;
}

//Heal up and then reset position again.
OverworldWatcher done_healing(console.logger(), COLOR_BLUE);
pbf_move_left_joystick(context, {0, +1}, 800ms, 160ms);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ void quest_catch_handle_battle(
BBQuests current_quest
);

//Whether quest_catch() catches a wild battle that starts on the way back to Central Plaza
//instead of fleeing it. Any wild pokemon completes catch_any, so until this attempt has
//battled, the battle is a catch. Typed catch quests flee: the type is not read in battle.
bool catch_quest_catches_on_return(BBQuests current_quest, bool battled_this_attempt);

//Catch a pokemon
void quest_catch(
const ProgramInfo& info,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
namespace NintendoSwitch{
namespace PokemonSV{

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

// Returns true if it stopped at a wild battle's menu (only when stop_at_battle
// is set). Otherwise it flees each battle and returns false once at the plaza.
bool return_to_plaza_impl(

Check failure on line 30 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/PokemonSV_Terarium.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

PokemonAutomation::NintendoSwitch::PokemonSV::return_to_plaza_impl( const ProgramInfo & info , VideoStream & stream , ProControllerContext & context , bool stop_at_battle): function_lines=95, limit=50, allowed 50
const ProgramInfo& info, VideoStream& stream, ProControllerContext& context,
bool stop_at_battle
){
stream.log("Attempting to return to Central Plaza.");
//Modified version of handle_battles_and_back_to_pokecenter()
bool returned_to_pokecenter = false;
Expand Down Expand Up @@ -91,6 +98,9 @@
stream.log("Shiny detected!");
pbf_press_button(context, BUTTON_CAPTURE, 2000ms, 5000ms);
throw ProgramFinishedException();
}else if (stop_at_battle){
stream.log("Detected battle. Stopping at the battle menu.");
return true;
}else{
stream.log("Detected battle. Running from battle.");
try{
Expand All @@ -110,6 +120,17 @@
}
}
context.wait_for_all_requests();
return false;
}

}

Check failure on line 126 in SerialPrograms/Source/VideoGames/PokemonSV/Programs/PokemonSV_Terarium.cpp

View workflow job for this annotation

GitHub Actions / code-health

Code health

namespace-close: close this namespace with // namespace

void return_to_plaza(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
return_to_plaza_impl(info, stream, context, false);
}

bool return_to_plaza_unless_battle(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
return return_to_plaza_impl(info, stream, context, true);
}

void map_move_cursor_fly(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ namespace PokemonSV{
// Return to Central Plaza from anywhere in the terarium
void return_to_plaza(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context);

// Same as return_to_plaza(), but stops at the first wild battle instead of fleeing it.
// Returns true with the battle menu open, or false once at Central Plaza.
bool return_to_plaza_unless_battle(const ProgramInfo& info, VideoStream& stream, ProControllerContext& context);

// Open map from overworld, move cursor to fly location, and fly to location
void map_move_cursor_fly(
const ProgramInfo& info,
Expand Down
Loading