Skip to content

Commit 09b0fa2

Browse files
committed
Reduce chance of false positive detection of rewards menu.
1 parent 039c23b commit 09b0fa2

File tree

4 files changed

+102
-1
lines changed

4 files changed

+102
-1
lines changed

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,8 @@ file(GLOB MAIN_SOURCES
15771577
Source/PokemonSV/Inference/Battles/PokemonSV_StartBattleYellowBar.h
15781578
Source/PokemonSV/Inference/Battles/PokemonSV_TeraBattleMenus.cpp
15791579
Source/PokemonSV/Inference/Battles/PokemonSV_TeraBattleMenus.h
1580+
Source/PokemonSV/Inference/Battles/PokemonSV_TeraRewardsMenu.cpp
1581+
Source/PokemonSV/Inference/Battles/PokemonSV_TeraRewardsMenu.h
15801582
Source/PokemonSV/Inference/Boxes/PokemonSV_BoxDetection.cpp
15811583
Source/PokemonSV/Inference/Boxes/PokemonSV_BoxDetection.h
15821584
Source/PokemonSV/Inference/Boxes/PokemonSV_BoxEggDetector.cpp
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* Tera Rewards Menu
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "PokemonSV_TeraRewardsMenu.h"
8+
9+
namespace PokemonAutomation{
10+
namespace NintendoSwitch{
11+
namespace PokemonSV{
12+
13+
14+
15+
TeraRewardsMenuDetector::TeraRewardsMenuDetector(Color color)
16+
: m_color(color)
17+
, m_next_button(
18+
COLOR_CYAN,
19+
WhiteButton::ButtonA,
20+
{0.8, 0.93, 0.2, 0.07}
21+
)
22+
, m_arrow(color, GradientArrowType::RIGHT, {0, 0, 1, 1})
23+
{}
24+
void TeraRewardsMenuDetector::make_overlays(VideoOverlaySet& items) const{
25+
m_next_button.make_overlays(items);
26+
m_arrow.make_overlays(items);
27+
}
28+
bool TeraRewardsMenuDetector::detect(const ImageViewRGB32& screen){
29+
if (!m_next_button.detect(screen)){
30+
return false;
31+
}
32+
if (m_arrow.detect(screen)){
33+
return false;
34+
}
35+
return true;
36+
}
37+
38+
39+
40+
41+
}
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* Tera Rewards Menu
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonSV_TeraRewardsMenu_H
8+
#define PokemonAutomation_PokemonSV_TeraRewardsMenu_H
9+
10+
#include "CommonTools/VisualDetector.h"
11+
#include "PokemonSV/Inference/PokemonSV_WhiteButtonDetector.h"
12+
#include "PokemonSV/Inference/Dialogs/PokemonSV_GradientArrowDetector.h"
13+
14+
namespace PokemonAutomation{
15+
namespace NintendoSwitch{
16+
namespace PokemonSV{
17+
18+
19+
class TeraRewardsMenuDetector : public StaticScreenDetector{
20+
public:
21+
TeraRewardsMenuDetector(Color color = COLOR_RED);
22+
23+
virtual void make_overlays(VideoOverlaySet& items) const override;
24+
virtual bool detect(const ImageViewRGB32& screen) override;
25+
26+
protected:
27+
Color m_color;
28+
WhiteButtonDetector m_next_button;
29+
GradientArrowDetector m_arrow;
30+
};
31+
class TeraRewardsMenuWatcher : public DetectorToFinder<TeraRewardsMenuDetector>{
32+
public:
33+
TeraRewardsMenuWatcher(Color color, std::chrono::milliseconds duration)
34+
: DetectorToFinder("TeraRewardsMenuWatcher", duration, color)
35+
{}
36+
};
37+
38+
39+
40+
}
41+
}
42+
}
43+
#endif

SerialPrograms/Source/PokemonSV/Programs/TeraRaids/PokemonSV_TeraBattler.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
1212
#include "PokemonSV/Inference/Battles/PokemonSV_NormalBattleMenus.h"
1313
#include "PokemonSV/Inference/Battles/PokemonSV_TeraBattleMenus.h"
14+
#include "PokemonSV/Inference/Battles/PokemonSV_TeraRewardsMenu.h"
1415
#include "PokemonSV/Inference/Overworld/PokemonSV_OverworldDetector.h"
1516
#include "PokemonSV_TeraBattler.h"
1617

@@ -213,6 +214,16 @@ bool run_tera_battle(
213214
CheerSelectWatcher cheer_select_menu(COLOR_YELLOW);
214215
MoveSelectWatcher move_select_menu(COLOR_YELLOW);
215216
TargetSelectWatcher target_select_menu(COLOR_CYAN);
217+
TeraRewardsMenuWatcher rewards_menu(
218+
COLOR_BLUE,
219+
// This can false positive against the back (B) button while in the
220+
// lobby. So don't trigger this unless we see the battle menu first.
221+
// At the same time, there's a possibility that we miss the battle
222+
// menu if the raid is won before it even loads. And this can only
223+
// happen if the raid was uncatchable to begin with.
224+
std::chrono::seconds(battle_menu_seen ? 5 : 180)
225+
);
226+
#if 0
216227
WhiteButtonWatcher next_button(
217228
COLOR_CYAN,
218229
WhiteButton::ButtonA,
@@ -225,6 +236,7 @@ bool run_tera_battle(
225236
// happen if the raid was uncatchable to begin with.
226237
std::chrono::seconds(battle_menu_seen ? 5 : 180)
227238
);
239+
#endif
228240
TeraCatchWatcher catch_menu(COLOR_BLUE);
229241
OverworldWatcher overworld(stream.logger(), COLOR_GREEN);
230242
context.wait_for_all_requests();
@@ -241,7 +253,8 @@ bool run_tera_battle(
241253
cheer_select_menu,
242254
move_select_menu,
243255
target_select_menu,
244-
next_button,
256+
// next_button,
257+
rewards_menu,
245258
catch_menu,
246259
overworld,
247260
}

0 commit comments

Comments
 (0)