mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-19 02:23:01 +08:00
feat.将随机操作延迟的逻辑做到了全局
This commit is contained in:
@@ -436,8 +436,28 @@ asst::Point asst::Controller::rand_point_in_rect(const Rect& rect)
|
||||
return Point(x, y);
|
||||
}
|
||||
|
||||
void asst::Controller::random_delay() const
|
||||
{
|
||||
auto& opt = resource.cfg().get_options();
|
||||
if (opt.control_delay_upper != 0) {
|
||||
LogTraceFunction;
|
||||
static std::default_random_engine rand_engine(
|
||||
std::chrono::system_clock::now().time_since_epoch().count());
|
||||
static std::uniform_int_distribution<unsigned> rand_uni(
|
||||
opt.control_delay_lower,
|
||||
opt.control_delay_upper);
|
||||
|
||||
unsigned rand_delay = rand_uni(rand_engine);
|
||||
|
||||
log.trace("random_delay |", rand_delay, "ms");
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(rand_delay));
|
||||
}
|
||||
}
|
||||
|
||||
int asst::Controller::push_cmd(const std::string& cmd)
|
||||
{
|
||||
random_delay();
|
||||
|
||||
std::unique_lock<std::mutex> lock(m_cmd_queue_mutex);
|
||||
m_cmd_queue.emplace(cmd);
|
||||
m_cmd_condvar.notify_one();
|
||||
|
||||
@@ -67,6 +67,8 @@ namespace asst
|
||||
bool screencap();
|
||||
Point rand_point_in_rect(const Rect& rect);
|
||||
|
||||
void random_delay() const;
|
||||
|
||||
// 转换data中所有的crlf为lf:有些模拟器自带的adb,exec-out输出的\n,会被替换成\r\n,导致解码错误,所以这里转一下回来(点名批评mumu)
|
||||
static void convert_lf(std::vector<unsigned char>& data);
|
||||
|
||||
|
||||
@@ -179,38 +179,13 @@ bool ProcessTask::_run()
|
||||
return true;
|
||||
}
|
||||
|
||||
// 随机延时功能
|
||||
bool asst::ProcessTask::delay_random()
|
||||
{
|
||||
auto& opt = resource.cfg().get_options();
|
||||
if (opt.control_delay_upper != 0) {
|
||||
static std::default_random_engine rand_engine(
|
||||
std::chrono::system_clock::now().time_since_epoch().count());
|
||||
static std::uniform_int_distribution<unsigned> rand_uni(
|
||||
opt.control_delay_lower,
|
||||
opt.control_delay_upper);
|
||||
|
||||
unsigned rand_delay = rand_uni(rand_engine);
|
||||
|
||||
return sleep(rand_delay);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ProcessTask::exec_click_task(const Rect& matched_rect)
|
||||
{
|
||||
if (!delay_random()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ctrler.click(matched_rect);
|
||||
}
|
||||
|
||||
void asst::ProcessTask::exec_swipe_task(ProcessTaskAction action)
|
||||
{
|
||||
if (!delay_random()) {
|
||||
return;
|
||||
}
|
||||
const auto&& [width, height] = ctrler.get_scale_size();
|
||||
|
||||
const static Rect right_rect(width * 0.8,
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace asst
|
||||
|
||||
protected:
|
||||
virtual bool _run() override;
|
||||
bool delay_random();
|
||||
void exec_click_task(const Rect& matched_rect);
|
||||
void exec_swipe_task(ProcessTaskAction action);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user