mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-17 18:01:26 +08:00
support control random delay
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <libloaderapi.h>
|
||||
#include <Windows.h>
|
||||
|
||||
namespace asst {
|
||||
|
||||
|
||||
@@ -27,18 +27,23 @@ namespace asst {
|
||||
}
|
||||
|
||||
enum class TaskType {
|
||||
Invalid,
|
||||
ClickSelf,
|
||||
ClickRect,
|
||||
ClickRand,
|
||||
DoNothing,
|
||||
Stop
|
||||
Invalid = 0,
|
||||
BasicClick = 1,
|
||||
DoNothing = 2,
|
||||
Stop = 4,
|
||||
ClickSelf = 8 | BasicClick,
|
||||
ClickRect = 16 | BasicClick,
|
||||
ClickRand = 32 | BasicClick
|
||||
};
|
||||
|
||||
static bool operator&(const TaskType& lhs, const TaskType& rhs)
|
||||
{
|
||||
return static_cast<std::underlying_type<TaskType>::type>(lhs) & static_cast<std::underlying_type<TaskType>::type>(rhs);
|
||||
}
|
||||
static std::ostream& operator<<(std::ostream& os, const TaskType& task)
|
||||
{
|
||||
static std::unordered_map<TaskType, std::string> _type_name = {
|
||||
{TaskType::Invalid, "Invalid"},
|
||||
{TaskType::BasicClick, "BasicClick"},
|
||||
{TaskType::ClickSelf, "ClickSelf"},
|
||||
{TaskType::ClickRect, "ClickRect"},
|
||||
{TaskType::ClickRand, "ClickRand"},
|
||||
@@ -116,8 +121,9 @@ namespace asst {
|
||||
};
|
||||
|
||||
struct Options {
|
||||
std::string delayType;
|
||||
int delayFixedTime = 0;
|
||||
bool cache = false;
|
||||
int identify_delay = 0;
|
||||
bool identify_cache = false;
|
||||
int control_delay_lower = 0;
|
||||
int control_delay_upper = 0;
|
||||
};
|
||||
}
|
||||
@@ -24,9 +24,7 @@ namespace asst {
|
||||
template <typename... Args>
|
||||
inline void log_trace(Args &&... args)
|
||||
{
|
||||
//#ifdef _DEBUG
|
||||
log("TRC", std::forward<Args>(args)...);
|
||||
//#endif
|
||||
}
|
||||
template <typename... Args>
|
||||
inline void log_info(Args &&... args)
|
||||
|
||||
@@ -19,7 +19,7 @@ Assistance::Assistance()
|
||||
{
|
||||
m_pIder->addImage(name, GetResourceDir() + info.filename);
|
||||
}
|
||||
m_pIder->setUseCache(Configer::m_options.cache);
|
||||
m_pIder->setUseCache(Configer::m_options.identify_cache);
|
||||
|
||||
m_working_thread = std::thread(workingProc, this);
|
||||
|
||||
@@ -85,7 +85,7 @@ std::optional<std::string> Assistance::setSimulator(const std::string& simulator
|
||||
|
||||
void Assistance::start(const std::string& task)
|
||||
{
|
||||
DebugTraceFunction;
|
||||
DebugTraceFunction;
|
||||
DebugTrace("Start |", task);
|
||||
|
||||
|
||||
@@ -164,17 +164,25 @@ void Assistance::workingProc(Assistance* pThis)
|
||||
if (task.pre_delay > 0) {
|
||||
DebugTrace("PreDelay", task.pre_delay);
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(task.pre_delay));
|
||||
auto cv_ret = pThis->m_condvar.wait_for(lock, std::chrono::milliseconds(task.pre_delay),
|
||||
bool cv_ret = pThis->m_condvar.wait_for(lock, std::chrono::milliseconds(task.pre_delay),
|
||||
[&]() -> bool { return !pThis->m_thread_running; });
|
||||
if (cv_ret == true) {
|
||||
continue;
|
||||
}
|
||||
if (cv_ret) { continue; }
|
||||
}
|
||||
|
||||
if (task.max_times != INT_MAX) {
|
||||
DebugTrace("CurTimes:", task.exec_times, "MaxTimes:", task.max_times);
|
||||
}
|
||||
if (task.exec_times < task.max_times) {
|
||||
if ((task.type & TaskType::BasicClick)
|
||||
&& Configer::m_options.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(Configer::m_options.control_delay_lower, Configer::m_options.control_delay_upper);
|
||||
int delay = rand_uni(rand_engine);
|
||||
DebugTraceInfo("Random Delay", delay, "ms");
|
||||
bool cv_ret = pThis->m_condvar.wait_for(lock, std::chrono::milliseconds(delay),
|
||||
[&]() -> bool { return !pThis->m_thread_running; });
|
||||
if (cv_ret) { continue; }
|
||||
}
|
||||
switch (task.type) {
|
||||
case TaskType::ClickRect:
|
||||
matched_rect = task.specific_area;
|
||||
@@ -206,9 +214,7 @@ void Assistance::workingProc(Assistance* pThis)
|
||||
// std::this_thread::sleep_for(std::chrono::milliseconds(task.rear_delay));
|
||||
auto cv_ret = pThis->m_condvar.wait_for(lock, std::chrono::milliseconds(task.rear_delay),
|
||||
[&]() -> bool { return !pThis->m_thread_running; });
|
||||
if (cv_ret == true) {
|
||||
continue;
|
||||
}
|
||||
if (cv_ret) { continue; }
|
||||
}
|
||||
pThis->m_next_tasks = Configer::m_tasks[matched_task].next;
|
||||
}
|
||||
@@ -227,7 +233,7 @@ void Assistance::workingProc(Assistance* pThis)
|
||||
DebugTrace("Next:", nexts_str);
|
||||
}
|
||||
pThis->m_condvar.wait_for(lock,
|
||||
std::chrono::milliseconds(Configer::m_options.delayFixedTime),
|
||||
std::chrono::milliseconds(Configer::m_options.identify_delay),
|
||||
[&]() -> bool { return !pThis->m_thread_running; });
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -41,9 +41,10 @@ bool Configer::reload()
|
||||
m_version = root["version"].as_string();
|
||||
|
||||
auto options_obj = root["options"].as_object();
|
||||
m_options.delayType = options_obj["delay"]["type"].as_string();
|
||||
m_options.delayFixedTime = options_obj["delay"]["fixedTime"].as_integer();
|
||||
m_options.cache = options_obj["cache"].as_boolean();
|
||||
m_options.identify_delay = options_obj["identifyDelay"].as_integer();
|
||||
m_options.identify_cache = options_obj["identifyCache"].as_boolean();
|
||||
m_options.control_delay_lower = options_obj["controlDelay"][0].as_integer();
|
||||
m_options.control_delay_upper = options_obj["controlDelay"][1].as_integer();
|
||||
|
||||
auto tasks_obj = root["tasks"].as_object();
|
||||
for (auto&& [name, task_json] : tasks_obj) {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <ctime>
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <WinUser.h>
|
||||
@@ -17,7 +17,7 @@ using namespace asst;
|
||||
WinMacro::WinMacro(const std::string& simulator_name, HandleType type)
|
||||
: m_simulator_name(simulator_name),
|
||||
m_handle_type(type),
|
||||
m_rand_engine(time(NULL))
|
||||
m_rand_engine(std::chrono::system_clock::now().time_since_epoch().count())
|
||||
{
|
||||
findHandle();
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ MuMu是个奇葩,它的所有的窗口句柄均不响应SendMessage鼠标消
|
||||
- [x] 基本图形化界面
|
||||
- [ ] 图形化界面进一步完善
|
||||
- [ ] 日志打印,错误提示
|
||||
- [ ] 使模拟器窗口不可见的按钮
|
||||
- [ ] 操作随机延时支持设置
|
||||
- [ ] 刷理智
|
||||
- [x] 支持剿灭
|
||||
- [x] 支持使模拟器窗口不可见
|
||||
@@ -93,7 +93,7 @@ MuMu是个奇葩,它的所有的窗口句柄均不响应SendMessage鼠标消
|
||||
- [x] 支持自动勾选代理指挥
|
||||
- [x] 支持刷指定次数
|
||||
- [x] 自动吃石头(根据设置,指定数量)
|
||||
- [ ] 操作随机延时
|
||||
- [x] 操作随机延时
|
||||
- [ ] 指定刷XX个某材料
|
||||
- [ ] 支持凌晨4点更新数据
|
||||
- [ ] 结束界面自动截图,可用于上传企鹅物流
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "Assistance.h"
|
||||
#include "Updater.h"
|
||||
|
||||
#include "Logger.hpp"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
{
|
||||
"version": "0.3",
|
||||
"version": "0.4",
|
||||
"options": {
|
||||
"delay": {
|
||||
"type": "fixedTime",
|
||||
"fixedTime": 1000
|
||||
},
|
||||
"cache": true
|
||||
"identifyCache": true,
|
||||
"identifyDelay": 1000,
|
||||
"controlDelay": [ 0, 0 ]
|
||||
},
|
||||
"handle": {
|
||||
"BlueStacks": {
|
||||
|
||||
Reference in New Issue
Block a user