Skip to content

Commit 0e059f2

Browse files
committed
handle shiny battle
1 parent 618e07b commit 0e059f2

File tree

3 files changed

+63
-9
lines changed

3 files changed

+63
-9
lines changed

SerialPrograms/Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class BattleArrowDetector : public StaticScreenDetector{
2828
Don't know what changes for a double battle.
2929
*/
3030
//Arrow bounces back and forth.
31-
BattleArrowDetector(Color color, const ImageFloatBox& box = {0.546, 0.863, 0.045, 0.068}); //Wild battle.
31+
BattleArrowDetector(Color color, const ImageFloatBox& box);
3232

3333
virtual void make_overlays(VideoOverlaySet& items) const override;
3434
virtual bool detect(const ImageViewRGB32& screen) const override;
@@ -39,8 +39,8 @@ class BattleArrowDetector : public StaticScreenDetector{
3939
};
4040
class BattleArrowWatcher : public DetectorToFinder<BattleArrowDetector>{
4141
public:
42-
BattleArrowWatcher(Color color = COLOR_RED)
43-
: DetectorToFinder("BattleArrowWatcher", std::chrono::milliseconds(100), color)
42+
BattleArrowWatcher(Color color = COLOR_RED, ImageFloatBox box = {0.546, 0.863, 0.045, 0.068})
43+
: DetectorToFinder("BattleArrowWatcher", std::chrono::milliseconds(100), color, box)
4444
{}
4545
};
4646

SerialPrograms/Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.cpp

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ LegendaryReset::LegendaryReset()
8181
PA_ADD_OPTION(NOTIFICATIONS);
8282
}
8383

84-
bool LegendaryReset::run_battle(SingleSwitchProgramEnvironment& env, JoyconContext& context){
84+
bool LegendaryReset::run_encounter(SingleSwitchProgramEnvironment& env, JoyconContext& context){
8585
float shiny_coefficient = 1.0;
8686
ShinySoundDetector shiny_detector(env.logger(), [&](float error_coefficient) -> bool{
8787
shiny_coefficient = error_coefficient;
8888
return true;
8989
});
90-
BattleArrowWatcher battle_started(COLOR_YELLOW);
90+
BattleArrowWatcher battle_started(COLOR_YELLOW, {0.546, 0.863, 0.045, 0.068});
9191

9292
env.log("Starting battle.");
9393
switch (TARGET) {
@@ -146,14 +146,15 @@ void LegendaryReset::program(SingleSwitchProgramEnvironment& env, CancellableSco
146146
147147
Settings:
148148
Text Speed fast
149-
Skip cutscene option?
149+
Skip cutscene On
150+
Skip move animation On
150151
151152
Mewtwo, Articuno, Zapdos, Moltres, Snorlax, Electrode(?)
152153
Don't do it on the first Snorlax, otherwise have to sit through fuji tutorial
153154
*/
154155

155156
while (true) {
156-
bool encounter_battle = run_battle(env, context);
157+
bool encounter_battle = run_encounter(env, context);
157158
if (encounter_battle) {
158159
stats.shinies++;
159160
env.update_stats();
@@ -174,6 +175,59 @@ void LegendaryReset::program(SingleSwitchProgramEnvironment& env, CancellableSco
174175
stats.resets++;
175176
env.update_stats();
176177
}
178+
//Shiny found, complete the battle
179+
WallClock start = current_time();
180+
BattleArrowWatcher catching_started(COLOR_RED, {0.005, 0.662, 0.049, 0.069});
181+
int res = run_until<JoyconContext>(
182+
env.console, context,
183+
[&](JoyconContext& context) {
184+
while(true){
185+
if (current_time() - start > std::chrono::minutes(5)){
186+
env.log("Timed out during battle after 5 minutes.", COLOR_RED);
187+
OperationFailedException::fire(
188+
ErrorReport::SEND_ERROR_REPORT,
189+
"Timed out during battle after 5 minutes.",
190+
env.console
191+
);
192+
}
193+
BattleArrowWatcher battle_menu(COLOR_YELLOW, {0.546, 0.863, 0.045, 0.068});
194+
context.wait_for_all_requests();
195+
196+
int ret = wait_until(
197+
env.console, context,
198+
std::chrono::seconds(30),
199+
{ battle_menu }
200+
);
201+
switch (ret){
202+
case 0:
203+
env.log("Detected battle menu. Mashing A to attack.");
204+
pbf_mash_button(context, BUTTON_A, 3000ms);
205+
context.wait_for_all_requests();
206+
break;
207+
default:
208+
env.log("Timed out during battle. Stuck, crashed, or took more than 30 seconds for a turn.", COLOR_RED);
209+
OperationFailedException::fire(
210+
ErrorReport::SEND_ERROR_REPORT,
211+
"Timed out during battle. Stuck, crashed, or took more than 30 seconds for a turn.",
212+
env.console
213+
);
214+
}
215+
}
216+
},
217+
{{catching_started}}
218+
);
219+
switch (res){
220+
case 0:
221+
env.log("Catching menu detected.");
222+
break;
223+
default:
224+
OperationFailedException::fire(
225+
ErrorReport::SEND_ERROR_REPORT,
226+
"Failed to detect catching menu.",
227+
env.console
228+
);
229+
break;
230+
}
177231

178232
if (GO_HOME_WHEN_DONE) {
179233
pbf_press_button(context, BUTTON_HOME, 200ms, 1000ms);

SerialPrograms/Source/PokemonLGPE/Programs/ShinyHunting/PokemonLGPE_LegendaryReset.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class LegendaryReset : public SingleSwitchProgramInstance{
3030
virtual void program(SingleSwitchProgramEnvironment& env, CancellableScope& scope) override;
3131

3232
private:
33-
bool run_battle(SingleSwitchProgramEnvironment& env, JoyconContext& context);
33+
bool run_encounter(SingleSwitchProgramEnvironment& env, JoyconContext& context);
3434

3535
enum class Target{
3636
mewtwo,
3737
snorlax,
38-
snorlax2,
38+
//snorlax2,
3939
};
4040
EnumDropdownOption<Target> TARGET;
4141

0 commit comments

Comments
 (0)