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 @@ -41,12 +41,13 @@ namespace PokemonSV{




// spam A button to choose the first move
// throw exception if wipeout or if your lead faints.
void run_battle_press_A(
VideoStream& stream,
ProControllerContext& context,
BattleStopCondition stop_condition,
std::vector<CallbackEnum> enum_optional_callbacks,
std::unordered_set<CallbackEnum> enum_optional_callbacks,
bool detect_wipeout
){
int16_t num_times_seen_overworld = 0;
Expand All @@ -61,9 +62,15 @@ void run_battle_press_A(
MoveSelectWatcher move_select_menu(COLOR_YELLOW);

std::vector<PeriodicInferenceCallback> callbacks;
std::vector<CallbackEnum> enum_all_callbacks;
// mandatory callbacks: Battle, Overworld, Advance Dialog, Swap menu, Move select
std::vector<CallbackEnum> enum_all_callbacks{CallbackEnum::BATTLE, CallbackEnum::OVERWORLD, CallbackEnum::ADVANCE_DIALOG, CallbackEnum::SWAP_MENU, CallbackEnum::MOVE_SELECT}; // mandatory callbacks
enum_all_callbacks.insert(enum_all_callbacks.end(), enum_optional_callbacks.begin(), enum_optional_callbacks.end()); // append the mandatory and optional callback vectors together
// optional callbacks: DIALOG_ARROW, NEXT_POKEMON

// merge the mandatory and optional callbacks as a set, to avoid duplicates. then convert to vector
std::unordered_set<CallbackEnum> enum_all_callbacks_set{CallbackEnum::BATTLE, CallbackEnum::OVERWORLD, CallbackEnum::ADVANCE_DIALOG, CallbackEnum::SWAP_MENU, CallbackEnum::MOVE_SELECT}; // mandatory callbacks
enum_all_callbacks_set.insert(enum_optional_callbacks.begin(), enum_optional_callbacks.end()); // append the mandatory and optional callback sets together
enum_all_callbacks.assign(enum_all_callbacks_set.begin(), enum_all_callbacks_set.end());

for (const CallbackEnum& enum_callback : enum_all_callbacks){
switch(enum_callback){
case CallbackEnum::ADVANCE_DIALOG:
Expand All @@ -78,10 +85,10 @@ void run_battle_press_A(
case CallbackEnum::BATTLE:
callbacks.emplace_back(battle);
break;
case CallbackEnum::GRADIENT_ARROW:
case CallbackEnum::NEXT_POKEMON: // to detect the "next pokemon" prompt.
callbacks.emplace_back(next_pokemon);
break;
case CallbackEnum::SWAP_MENU:
case CallbackEnum::SWAP_MENU: // detecting Swap Menu implies your lead fainted.
callbacks.emplace_back(fainted);
break;
case CallbackEnum::MOVE_SELECT:
Expand Down Expand Up @@ -159,7 +166,7 @@ void run_battle_press_A(
stream.log("run_battle_press_A: Detected dialog arrow.");
pbf_press_button(context, BUTTON_A, 20, 105);
break;
case CallbackEnum::GRADIENT_ARROW:
case CallbackEnum::NEXT_POKEMON:
stream.log("run_battle_press_A: Detected prompt for bringing in next pokemon. Keep current pokemon.");
pbf_mash_button(context, BUTTON_B, 100);
break;
Expand All @@ -176,6 +183,27 @@ void run_battle_press_A(
}
}

void run_trainer_battle_press_A(
VideoStream& stream,
ProControllerContext& context,
BattleStopCondition stop_condition,
std::unordered_set<CallbackEnum> enum_optional_callbacks,
bool detect_wipeout
){
enum_optional_callbacks.insert(CallbackEnum::NEXT_POKEMON); // always check for the "Next pokemon" prompt when in trainer battles
run_battle_press_A(stream, context, stop_condition, enum_optional_callbacks, detect_wipeout);
}

void run_wild_battle_press_A(
VideoStream& stream,
ProControllerContext& context,
BattleStopCondition stop_condition,
std::unordered_set<CallbackEnum> enum_optional_callbacks,
bool detect_wipeout
){
run_battle_press_A(stream, context, stop_condition, enum_optional_callbacks, detect_wipeout);
}

void select_top_move(VideoStream& stream, ProControllerContext& context, size_t consecutive_move_select){
if (consecutive_move_select > 3){
// to handle case where move is disabled/out of PP/taunted
Expand Down Expand Up @@ -471,7 +499,7 @@ void overworld_navigation(
return;
}

run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD, {}, detect_wipeout);
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD, {}, detect_wipeout);
if (auto_heal){
auto_heal_from_menu_or_overworld(info, stream, context, 0, true);
}
Expand Down Expand Up @@ -743,7 +771,7 @@ void handle_unexpected_battles(
action(info, stream, context);
return;
}catch (UnexpectedBattleException&){
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
}
}
}
Expand Down Expand Up @@ -943,7 +971,7 @@ bool is_ride_active(const ProgramInfo& info, VideoStream& stream, ProControllerC
return is_ride_active;

}catch(UnexpectedBattleException&){
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
}
}

Expand Down Expand Up @@ -1072,7 +1100,7 @@ void realign_player_from_landmark(
return;

}catch (UnexpectedBattleException&){
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
}catch (OperationFailedException&){
// reset to overworld if failed to center on the pokecenter, and re-try
leave_phone_to_overworld(info, stream, context);
Expand Down Expand Up @@ -1154,7 +1182,7 @@ void move_cursor_towards_flypoint_and_go_there(
return;

}catch (UnexpectedBattleException&){
run_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
run_wild_battle_press_A(stream, context, BattleStopCondition::STOP_OVERWORLD);
}catch (OperationFailedException&){
// reset to overworld if failed to center on the pokecenter, and re-try
leave_phone_to_overworld(info, stream, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define PokemonAutomation_PokemonSV_AutoStoryTools_H

#include <functional>
#include <unordered_set>
#include "CommonFramework/Language.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ProgramStats/StatsTracking.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ enum class CallbackEnum{
BATTLE,
TUTORIAL,
BLACK_DIALOG_BOX,
GRADIENT_ARROW,
NEXT_POKEMON,
SWAP_MENU,
MOVE_SELECT,
};
Expand Down Expand Up @@ -117,13 +118,25 @@ class AutoStory_Segment {
AutoStoryOptions options) const = 0;
};

// spam A button to choose the first move
// throw exception if wipeout.
void run_battle_press_A(
// spam A button to choose the first move for trainer battles
// detect_wipeout: can be false if you have multiple pokemon in your party, since an exception will be thrown if your lead faints.
// throw exception if wipeout or if your lead faints.
void run_trainer_battle_press_A(
VideoStream& stream,
ProControllerContext& context,
BattleStopCondition stop_condition,
std::vector<CallbackEnum> optional_callbacks = {},
std::unordered_set<CallbackEnum> enum_optional_callbacks = {},
bool detect_wipeout = false
);

// spam A button to choose the first move for wild battles
// detect_wipeout: can be false if you have multiple pokemon in your party, since an exception will be thrown if your lead faints.
// throw exception if wipeout or if your lead faints.
void run_wild_battle_press_A(
VideoStream& stream,
ProControllerContext& context,
BattleStopCondition stop_condition,
std::unordered_set<CallbackEnum> enum_optional_callbacks = {},
bool detect_wipeout = false
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ void checkpoint_06(
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60,
{CallbackEnum::WHITE_A_BUTTON, CallbackEnum::TUTORIAL, CallbackEnum::BATTLE});

// can die in catch tutorial, and the story will continue
env.console.log("run_battle_press_A: Battle Lechonk in catch tutorial. Stop when detect dialog.");
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
// can die in catch tutorial, and the story will continue. so need to detect wipeout
env.console.log("Battle Lechonk in catch tutorial. Stop when detect dialog.");
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);

env.console.log("clear_dialog: Talk with Nemona to finish catch tutorial. Stop when detect overworld.");
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ void checkpoint_13(
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60,
{CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW, CallbackEnum::BATTLE});

env.console.log("run_battle_press_A: Battle with Nemona at Mesagoza gate. Stop when detect dialog.");
// story continues even if you lose
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
env.console.log("Battle with Nemona at Mesagoza gate. Stop when detect dialog.");
// story continues even if you lose, no need to detect wipeout
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);

env.console.log("clear_dialog: Talk with Nemona within Mesagoza. Stop when detect overworld.");
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60,
Expand Down Expand Up @@ -146,15 +146,15 @@ void checkpoint_14(
env.console.log("clear_dialog: Talk with Team Star at the top of the stairs. Stop when detect battle.");
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::PROMPT_DIALOG, CallbackEnum::BATTLE, CallbackEnum::DIALOG_ARROW});
// run battle until dialog
env.console.log("run_battle_press_A: Battle with Team Star grunt 1. Stop when detect dialog.");
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {}, true);
env.console.log("Battle with Team Star grunt 1. Stop when detect dialog.");
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {}, true); // need to detect wipeouts, since you need to win, and you likely only have 1 pokemon
// clear dialog until battle, with prompt, white button, tutorial, battle
env.console.log("clear_dialog: Talk with Team Star and Nemona. Receive Tera orb. Stop when detect battle.");
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60,
{CallbackEnum::PROMPT_DIALOG, CallbackEnum::WHITE_A_BUTTON, CallbackEnum::TUTORIAL, CallbackEnum::BATTLE, CallbackEnum::DIALOG_ARROW});
// run battle until dialog
env.console.log("run_battle_press_A: Battle with Team Star grunt 2. Stop when detect dialog.");
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {}, true);
env.console.log("Battle with Team Star grunt 2. Stop when detect dialog.");
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {}, true); // need to detect wipeouts, since you need to win, and you likely only have 1 pokemon
// clear dialog until overworld
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60, {CallbackEnum::OVERWORLD});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ void checkpoint_25(
direction.change_direction(env.program_info(), env.console, context, 1.485);
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10, 128, 20);
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::DIALOG_ARROW});
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
env.console.log("Battle Olive Roll NPC 1.");
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
mash_button_till_overworld(env.console, context, BUTTON_A);

// section 6
Expand All @@ -200,7 +201,8 @@ void checkpoint_25(
direction.change_direction(env.program_info(), env.console, context, 4.275);
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10, 128, 20);
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::DIALOG_ARROW});
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
env.console.log("Battle Olive Roll NPC 2.");
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
mash_button_till_overworld(env.console, context, BUTTON_A);

// section 10. leave Olive roll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ void checkpoint_28(
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});

// battle Katy
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW}, true);
env.console.log("Battle Grass Gym.");
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
mash_button_till_overworld(env.console, context, BUTTON_A, 360);

// leave gym building
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,12 @@ void checkpoint_30(

}

run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
env.console.log("Battle Bombirdier Titan phase 1.");
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 30, {CallbackEnum::BATTLE});
// round 2 of battle
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW});
env.console.log("Battle Bombirdier Titan phase 2.");
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW});
// get ride upgrade
mash_button_till_overworld(env.console, context, BUTTON_A);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ void checkpoint_32(

// battle team star grunts
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
env.console.log("Battle Team star grunt.");
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
clear_dialog(env.console, context, ClearDialogMode::STOP_OVERWORLD, 60, {CallbackEnum::OVERWORLD, CallbackEnum::BLACK_DIALOG_BOX});


Expand Down Expand Up @@ -253,7 +254,8 @@ void checkpoint_33(
);
}
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::DIALOG_ARROW});
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {}, true);
env.console.log("Battle the Team Star (Dark) boss.");
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
mash_button_till_overworld(env.console, context, BUTTON_A, 360);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ void checkpoint_37(
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_ONLY, 20);

clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW});
env.console.log("Battle Kofu's assistant.");
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
mash_button_till_overworld(env.console, context, BUTTON_A, 360);


Expand Down Expand Up @@ -170,7 +171,8 @@ void checkpoint_38(
// talk to reception. Battle Kofu
walk_forward_until_dialog(env.program_info(), env.console, context, NavigationMovementMode::DIRECTIONAL_SPAM_A, 10);
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::PROMPT_DIALOG, CallbackEnum::DIALOG_ARROW});
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::GRADIENT_ARROW}, true);
env.console.log("Battle Water Gym.");
run_trainer_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG);
mash_button_till_overworld(env.console, context, BUTTON_A, 360);

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ void checkpoint_39(

// battle the titan phase 1
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE, CallbackEnum::BLACK_DIALOG_BOX});
run_battle_press_A(env.console, context, BattleStopCondition::STOP_OVERWORLD);
env.console.log("Battle Great Tusk/Iron Treads Titan phase 1.");
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_OVERWORLD);

// section 5
realign_player_from_landmark(
Expand All @@ -225,7 +226,8 @@ void checkpoint_39(

// battle the titan phase 2
clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 60, {CallbackEnum::BATTLE});
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW});
env.console.log("Battle Great Tusk/Iron Treads Titan phase 2.");
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW});
mash_button_till_overworld(env.console, context, BUTTON_A, 360);

break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ void checkpoint_41(


// battle Klawf phase 1
run_battle_press_A(env.console, context, BattleStopCondition::STOP_OVERWORLD);
env.console.log("Battle Klawf Titan phase 1.");
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_OVERWORLD);
do_action_and_monitor_for_battles(env.program_info(), env.console, context,
[&](const ProgramInfo& info, VideoStream& stream, ProControllerContext& context){
direction.change_direction(env.program_info(), env.console, context, 2.83);
Expand All @@ -240,7 +241,8 @@ void checkpoint_41(

clear_dialog(env.console, context, ClearDialogMode::STOP_BATTLE, 30, {CallbackEnum::BATTLE});
// Klawf battle phase 2
run_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW});
env.console.log("Battle Klawf Titan phase 1.");
run_wild_battle_press_A(env.console, context, BattleStopCondition::STOP_DIALOG, {CallbackEnum::DIALOG_ARROW});
// get ride upgrade
mash_button_till_overworld(env.console, context, BUTTON_A);

Expand Down
Loading