Skip to content

Commit 72ec523

Browse files
committed
Add self-trading program.
1 parent a6d480b commit 72ec523

File tree

11 files changed

+447
-9
lines changed

11 files changed

+447
-9
lines changed

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace PokemonAutomation{
2626
const bool IS_BETA_VERSION = true;
2727
const int PROGRAM_VERSION_MAJOR = 0;
2828
const int PROGRAM_VERSION_MINOR = 59;
29-
const int PROGRAM_VERSION_PATCH = 8;
29+
const int PROGRAM_VERSION_PATCH = 9;
3030

3131
const std::string PROGRAM_VERSION_BASE =
3232
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +

SerialPrograms/Source/PokemonLZA/PokemonLZA_Panels.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include "Programs/PokemonLZA_ClothingBuyer.h"
1515
#include "Programs/PokemonLZA_BerryBuyer.h"
1616

17+
// Trading
18+
#include "Programs/Trading/PokemonLZA_SelfBoxTrade.h"
19+
1720
// Farming
1821
#include "Programs/Farming/PokemonLZA_RestaurantFarmer.h"
1922
#include "Programs/Farming/PokemonLZA_JacintheInfiniteFarmer.h"
@@ -50,6 +53,9 @@ std::vector<PanelEntry> PanelListFactory::make_panels() const{
5053
ret.emplace_back("---- General ----");
5154
ret.emplace_back(make_single_switch_program<ClothingBuyer_Descriptor, ClothingBuyer>());
5255
ret.emplace_back(make_single_switch_program<BerryBuyer_Descriptor, BerryBuyer>());
56+
if (IS_BETA_VERSION){
57+
ret.emplace_back(make_multi_switch_program<SelfBoxTrade_Descriptor, SelfBoxTrade>());
58+
}
5359

5460
ret.emplace_back("---- Farming ----");
5561
ret.emplace_back(make_single_switch_program<RestaurantFarmer_Descriptor, RestaurantFarmer>());

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_BerryBuyer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ std::unique_ptr<StatsTracker> BerryBuyer_Descriptor::make_stats() const{
5454

5555
BerryBuyer::BerryBuyer()
5656
: BERRY_TYPE(
57-
"<b>Berry to Purchase:",
57+
"<b>Berry to Purchase:</b>",
5858
{
5959
{BerryType::POMEG, "pomeg", "Pomeg (HP)"},
6060
{BerryType::KELPSY, "kelpsy", "Kelpsy (Attack)"},

SerialPrograms/Source/PokemonLZA/Programs/PokemonLZA_BerryBuyer.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
#ifndef PokemonAutomation_PokemonLZA_BerryBuyer_H
88
#define PokemonAutomation_PokemonLZA_BerryBuyer_H
99

10-
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
10+
#include "Common/Cpp/Options/SimpleIntegerOption.h"
1111
#include "CommonFramework/Notifications/EventNotificationsTable.h"
12+
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1213
#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h"
13-
#include "Common/Cpp/Options/SimpleIntegerOption.h"
1414

1515
namespace PokemonAutomation{
1616
namespace NintendoSwitch{
1717
namespace PokemonLZA{
1818

19+
20+
1921
class BerryBuyer_Descriptor : public SingleSwitchProgramDescriptor{
2022
public:
2123
BerryBuyer_Descriptor();
@@ -24,6 +26,8 @@ class BerryBuyer_Descriptor : public SingleSwitchProgramDescriptor{
2426
virtual std::unique_ptr<StatsTracker> make_stats() const override;
2527
};
2628

29+
30+
2731
class BerryBuyer : public SingleSwitchProgramInstance{
2832
public:
2933
BerryBuyer();
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/* Self Box Trade
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#include "CommonFramework/Notifications/ProgramNotifications.h"
8+
#include "CommonFramework/ProgramStats/StatsTracking.h"
9+
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
10+
#include "Pokemon/Pokemon_Strings.h"
11+
#include "Pokemon/Inference/Pokemon_NameReader.h"
12+
#include "PokemonLZA_TradeRoutines.h"
13+
#include "PokemonLZA_SelfBoxTrade.h"
14+
15+
namespace PokemonAutomation{
16+
namespace NintendoSwitch{
17+
namespace PokemonLZA{
18+
19+
using namespace Pokemon;
20+
21+
22+
23+
24+
SelfBoxTrade_Descriptor::SelfBoxTrade_Descriptor()
25+
: MultiSwitchProgramDescriptor(
26+
"PokemonLZA:SelfBoxTrade",
27+
STRING_POKEMON + " LZA", "Self Box Trade",
28+
"Programs/PokemonLZA/SelfBoxTrade.html",
29+
"Trade boxes across two Switches.",
30+
ProgramControllerClass::StandardController_NoRestrictions,
31+
FeedbackType::REQUIRED,
32+
AllowCommandsWhenRunning::DISABLE_COMMANDS,
33+
2, 2, 2
34+
)
35+
{}
36+
37+
std::unique_ptr<StatsTracker> SelfBoxTrade_Descriptor::make_stats() const{
38+
return std::unique_ptr<StatsTracker>(new TradeStats());
39+
}
40+
41+
42+
43+
SelfBoxTrade::SelfBoxTrade()
44+
: LANGUAGE_LEFT(
45+
"<b>Game Language of Left Switch:</b>",
46+
Pokemon::PokemonNameReader::instance().languages(),
47+
LockMode::LOCK_WHILE_RUNNING,
48+
true
49+
)
50+
, LANGUAGE_RIGHT(
51+
"<b>Game Language of Right Switch:</b>",
52+
Pokemon::PokemonNameReader::instance().languages(),
53+
LockMode::LOCK_WHILE_RUNNING,
54+
true
55+
)
56+
, BOXES_TO_TRADE(
57+
"<b>Number of Boxes to Trade:</b>",
58+
LockMode::UNLOCK_WHILE_RUNNING,
59+
2, 0, 32
60+
)
61+
, START_ROW(
62+
"<b>Starting Row of 1st Box:</b>",
63+
LockMode::LOCK_WHILE_RUNNING,
64+
1, 1, 5
65+
)
66+
, START_COL(
67+
"<b>Starting Column of 1st Box:</b>",
68+
LockMode::LOCK_WHILE_RUNNING,
69+
1, 1, 6
70+
)
71+
#if 0
72+
, SKIP_TRADE_EVOLUTIONS(
73+
"<b>Skip Trade Evolutions:</b>",
74+
LockMode::UNLOCK_WHILE_RUNNING,
75+
true
76+
#endif
77+
, NOTIFICATION_STATUS_UPDATE("Status Update", true, false, std::chrono::seconds(3600))
78+
, NOTIFICATIONS({
79+
&NOTIFICATION_STATUS_UPDATE,
80+
&NOTIFICATION_PROGRAM_FINISH,
81+
&NOTIFICATION_ERROR_FATAL,
82+
})
83+
{
84+
PA_ADD_OPTION(LANGUAGE_LEFT);
85+
PA_ADD_OPTION(LANGUAGE_RIGHT);
86+
PA_ADD_OPTION(BOXES_TO_TRADE);
87+
PA_ADD_OPTION(START_ROW);
88+
PA_ADD_OPTION(START_COL);
89+
// PA_ADD_OPTION(SKIP_TRADE_EVOLUTIONS);
90+
PA_ADD_OPTION(NOTIFICATIONS);
91+
}
92+
void SelfBoxTrade::program(MultiSwitchProgramEnvironment& env, CancellableScope& scope){
93+
TradeStats& stats = env.current_stats<TradeStats>();
94+
env.update_stats();
95+
96+
uint8_t start_row = START_ROW - 1;
97+
uint8_t start_col = START_COL - 1;
98+
99+
for (uint8_t box = 0; box < BOXES_TO_TRADE; box++){
100+
if (box != 0){
101+
env.run_in_parallel(scope, [](ConsoleHandle& console, ProControllerContext& context){
102+
pbf_press_button(context, BUTTON_R, 60, 100);
103+
});
104+
}
105+
trade_current_box(env, scope, NOTIFICATION_STATUS_UPDATE, stats, start_row, start_col);
106+
start_row = 0;
107+
start_col = 0;
108+
}
109+
110+
env.update_stats();
111+
send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH);
112+
}
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
}
123+
}
124+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* Self Box Trade
2+
*
3+
* From: https://github.com/PokemonAutomation/
4+
*
5+
*/
6+
7+
#ifndef PokemonAutomation_PokemonLZA_SelfBoxTrade_H
8+
#define PokemonAutomation_PokemonLZA_SelfBoxTrade_H
9+
10+
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
11+
#include "Common/Cpp/Options/SimpleIntegerOption.h"
12+
#include "CommonFramework/Notifications/EventNotificationsTable.h"
13+
#include "CommonTools/Options/LanguageOCROption.h"
14+
#include "NintendoSwitch/NintendoSwitch_MultiSwitchProgram.h"
15+
16+
namespace PokemonAutomation{
17+
namespace NintendoSwitch{
18+
namespace PokemonLZA{
19+
20+
21+
22+
class SelfBoxTrade_Descriptor : public MultiSwitchProgramDescriptor{
23+
public:
24+
SelfBoxTrade_Descriptor();
25+
26+
virtual std::unique_ptr<StatsTracker> make_stats() const override;
27+
};
28+
29+
30+
31+
32+
33+
34+
35+
class SelfBoxTrade : public MultiSwitchProgramInstance{
36+
public:
37+
SelfBoxTrade();
38+
39+
virtual void program(MultiSwitchProgramEnvironment& env, CancellableScope& scope) override;
40+
41+
private:
42+
bool move_to_next(
43+
MultiSwitchProgramEnvironment& env, CancellableScope& scope,
44+
uint8_t& row, uint8_t& col
45+
);
46+
47+
private:
48+
OCR::LanguageOCROption LANGUAGE_LEFT;
49+
OCR::LanguageOCROption LANGUAGE_RIGHT;
50+
51+
SimpleIntegerOption<uint8_t> BOXES_TO_TRADE;
52+
53+
SimpleIntegerOption<uint8_t> START_ROW;
54+
SimpleIntegerOption<uint8_t> START_COL;
55+
56+
// BooleanCheckBoxOption SKIP_TRADE_EVOLUTIONS;
57+
58+
EventNotificationOption NOTIFICATION_STATUS_UPDATE;
59+
EventNotificationsOption NOTIFICATIONS;
60+
};
61+
62+
63+
64+
65+
66+
}
67+
}
68+
}
69+
#endif

0 commit comments

Comments
 (0)