Skip to content

Commit f8184e4

Browse files
committed
Fix let's go kill.
1 parent 5a95acf commit f8184e4

File tree

4 files changed

+36
-13
lines changed

4 files changed

+36
-13
lines changed

SerialPrograms/Source/CommonTools/Audio/AudioPerSpectrumDetectorBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class AudioPerSpectrumDetectorBase : public AudioInferenceCallback{
6666
DetectedCallback detected_callback = nullptr
6767
);
6868

69-
void set_detected_callback(DetectedCallback detected_callback);
69+
virtual void set_detected_callback(DetectedCallback detected_callback);
7070

7171
WallClock last_detection() const{
7272
return m_last_timestamp;

SerialPrograms/Source/PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,17 @@ LetsGoKillSoundDetector::LetsGoKillSoundDetector(Logger& logger, DetectedCallbac
218218
"LetsGoKillSoundDetector",
219219
"Let's Go Kill Sound",
220220
COLOR_RED,
221-
[this, callback = std::move(detected_callback)](float error_coefficient){
221+
[this](float error_coefficient){
222222
m_last_detected = current_time();
223-
return callback != nullptr ? callback(error_coefficient) : false;
223+
return m_detected_callback != nullptr ? m_detected_callback(error_coefficient) : false;
224224
}
225225
)
226+
, m_detected_callback(std::move(detected_callback))
226227
, m_last_detected(WallClock::min())
227228
{}
229+
void LetsGoKillSoundDetector::set_detected_callback(DetectedCallback detected_callback){
230+
m_detected_callback = std::move(detected_callback);
231+
}
228232
float LetsGoKillSoundDetector::get_score_threshold() const{
229233
return (float)GameSettings::instance().LETS_GO_KILL_SOUND_THRESHOLD;
230234
}

SerialPrograms/Source/PokemonSV/Inference/Overworld/PokemonSV_LetsGoKillDetector.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class LetsGoKillSoundDetector : public AudioPerSpectrumDetectorBase{
6464
public:
6565
LetsGoKillSoundDetector(Logger& logger, DetectedCallback detected_callback = nullptr);
6666

67+
virtual void set_detected_callback(DetectedCallback detected_callback) override;
68+
6769
virtual float get_score_threshold() const override;
6870

6971
WallClock last_kill() const{
@@ -74,6 +76,7 @@ class LetsGoKillSoundDetector : public AudioPerSpectrumDetectorBase{
7476
virtual std::unique_ptr<SpectrogramMatcher> build_spectrogram_matcher(size_t sample_rate) override;
7577

7678
private:
79+
DetectedCallback m_detected_callback;
7780
std::atomic<WallClock> m_last_detected;
7881
};
7982

SerialPrograms/Source/PokemonSV/Programs/ShinyHunting/PokemonSV_LetsGoTools.cpp

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@
55
*/
66

77
#include <algorithm>
8+
#include "Common/Cpp/PrettyPrint.h"
89
#include "CommonFramework/Logging/Logger.h"
910
#include "CommonFramework/Exceptions/ProgramFinishedException.h"
10-
#include "CommonFramework/Exceptions/OperationFailedException.h"
11-
#include "CommonFramework/Exceptions/FatalProgramException.h"
11+
//#include "CommonFramework/Exceptions/OperationFailedException.h"
12+
//#include "CommonFramework/Exceptions/FatalProgramException.h"
1213
#include "CommonFramework/Tools/ProgramEnvironment.h"
1314
#include "CommonTools/Async/InferenceRoutines.h"
1415
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h"
15-
#include "Pokemon/Pokemon_Notification.h"
16-
#include "PokemonSV/Options/PokemonSV_EncounterBotCommon.h"
16+
//#include "Pokemon/Pokemon_Notification.h"
17+
//#include "PokemonSV/Options/PokemonSV_EncounterBotCommon.h"
1718
#include "PokemonSV/Inference/PokemonSV_SweatBubbleDetector.h"
1819
#include "PokemonSV/Programs/Battles/PokemonSV_Battles.h"
19-
#include "PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.h"
20+
//#include "PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.h"
2021
#include "PokemonSV_LetsGoTools.h"
2122

2223
//#include <iostream>
@@ -195,34 +196,49 @@ bool use_lets_go_to_clear_in_front(
195196
if (ret == 0){
196197
if (throw_ball_if_bubble){
197198
stream.log("Detected sweat bubble. Throwing ball...");
198-
pbf_mash_button(context, BUTTON_ZR, 5 * TICKS_PER_SECOND);
199+
pbf_mash_button(context, BUTTON_ZR, 5000ms);
199200
}else{
200201
stream.log("Detected sweat bubble. Will not throw ball.");
201202
}
202203
}else{
203204
stream.log("Did not detect sweat bubble.");
204205
}
205206

206-
WallClock last_kill = tracker.last_kill();
207207
context.wait_for_all_requests();
208208
std::chrono::seconds timeout(6);
209209
while (true){
210+
// cout << "last kill: " << last_kill << endl;
210211
if (command){
211212
// cout << "running command..." << endl;
212213
command(context);
213214
context.wait_for_all_requests();
214215
command = nullptr;
215216
}else{
216217
// cout << "Waiting out... " << timeout.count() << " seconds" << endl;
217-
context.wait_until(last_kill + timeout);
218+
context.wait_until(tracker.last_kill() + timeout);
218219
}
219220
// timeout = std::chrono::seconds(3);
220-
if (last_kill == tracker.last_kill()){
221+
222+
WallClock now = current_time();
223+
WallClock last_kill_time = tracker.last_kill();
224+
WallDuration last_kill;
225+
if (last_kill_time == WallClock::min()){
226+
stream.log("Last Kill: Never");
227+
last_kill = WallDuration::max();
228+
}else{
229+
last_kill = now - last_kill_time;
230+
stream.log(
231+
"Last Kill: " +
232+
tostr_fixed(std::chrono::duration_cast<Milliseconds>(last_kill).count() / 1000., 3) +
233+
" seconds ago"
234+
);
235+
}
236+
237+
if (last_kill > timeout){
221238
// cout << "no kill" << endl;
222239
break;
223240
}
224241
// cout << "found kill" << endl;
225-
last_kill = tracker.last_kill();
226242
}
227243
stream.log("Nothing left to clear...");
228244
tracker.throw_if_no_sound();

0 commit comments

Comments
 (0)