mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 09:50:40 +08:00
Merge branch 'master' of https://github.com/MaaAssistantArknights/MaaAssistantArknights
This commit is contained in:
@@ -120,9 +120,9 @@ MAA 的意思是 MAA Assistant Arknights
|
||||
|
||||
### API
|
||||
|
||||
- [C 接口](https://github.com/MaaAssistantArknights/MaaAssistantArknights/blob/dev/include/AsstCaller.h)
|
||||
- [Python 接口](https://github.com/MaaAssistantArknights/MaaAssistantArknights/wiki/Python-%E6%8E%A5%E5%8F%A3)
|
||||
- [Golang 接口](https://github.com/MaaAssistantArknights/MaaAssistantArknights/wiki/Golang-%E6%8E%A5%E5%8F%A3)
|
||||
- [C 接口](include/AsstCaller.h):[集成示例](tools/TestCaller/main.cpp)
|
||||
- [Python 接口](src/Python/interface.py):[集成示例](src/Python/sample.py)
|
||||
- [Golang 接口](src/Golang/maa/):[集成示例](src/Golang/cli.go)(已停止维护 orz)
|
||||
- [回调消息协议](docs/回调消息协议.md)
|
||||
|
||||
## 声明
|
||||
|
||||
@@ -918,6 +918,26 @@
|
||||
255
|
||||
],
|
||||
"next": [
|
||||
"RecruitBeginLoading",
|
||||
"RecruitBegin"
|
||||
]
|
||||
},
|
||||
"RecruitBeginLoading": {
|
||||
"algorithm": "OcrDetect",
|
||||
"action": "doNothing",
|
||||
"text": [
|
||||
"正在提交",
|
||||
"反馈至神经"
|
||||
],
|
||||
"roi": [
|
||||
700,
|
||||
600,
|
||||
300,
|
||||
120
|
||||
],
|
||||
"next": [
|
||||
"RecruitBeginLoading",
|
||||
"Recruit",
|
||||
"RecruitBegin"
|
||||
]
|
||||
},
|
||||
@@ -932,6 +952,27 @@
|
||||
420
|
||||
],
|
||||
"next": [
|
||||
"RecruitFinishLoading",
|
||||
"RecruitFinish",
|
||||
"RecruitSkip",
|
||||
"RecruitSkipWithoutButton"
|
||||
]
|
||||
},
|
||||
"RecruitFinishLoading":{
|
||||
"algorithm": "OcrDetect",
|
||||
"action": "doNothing",
|
||||
"text": [
|
||||
"正在提交",
|
||||
"反馈至神经"
|
||||
],
|
||||
"roi": [
|
||||
700,
|
||||
600,
|
||||
300,
|
||||
120
|
||||
],
|
||||
"next": [
|
||||
"RecruitFinishLoading",
|
||||
"RecruitFinish",
|
||||
"RecruitSkip",
|
||||
"RecruitSkipWithoutButton"
|
||||
@@ -1711,6 +1752,17 @@
|
||||
"Stop"
|
||||
]
|
||||
},
|
||||
"RecruitCheckTimeUnreduced":{
|
||||
"action": "Stop",
|
||||
"template": "RecruitTimeReduce.png",
|
||||
"Doc": "检查时间是不是没有调整过",
|
||||
"roi": [
|
||||
350,
|
||||
150,
|
||||
200,
|
||||
150
|
||||
]
|
||||
},
|
||||
"RecruitConfirm": {
|
||||
"action": "clickSelf",
|
||||
"roi": [
|
||||
@@ -1720,6 +1772,25 @@
|
||||
80
|
||||
],
|
||||
"next": [
|
||||
"RecruitConfirmLoading",
|
||||
"RecruitFlag"
|
||||
]
|
||||
},
|
||||
"RecruitConfirmLoading":{
|
||||
"algorithm": "OcrDetect",
|
||||
"action": "doNothing",
|
||||
"text": [
|
||||
"正在提交",
|
||||
"反馈至神经"
|
||||
],
|
||||
"roi": [
|
||||
700,
|
||||
600,
|
||||
300,
|
||||
120
|
||||
],
|
||||
"next": [
|
||||
"RecruitConfirmLoading",
|
||||
"RecruitFlag"
|
||||
]
|
||||
},
|
||||
@@ -1925,6 +1996,27 @@
|
||||
150
|
||||
],
|
||||
"next": [
|
||||
"DroneConfirmLoading",
|
||||
"DeliverableOrder",
|
||||
"DroneAssist-Trade-Stop",
|
||||
"DroneAssistMfg"
|
||||
]
|
||||
},
|
||||
"DroneConfirmLoading": {
|
||||
"algorithm": "OcrDetect",
|
||||
"action": "doNothing",
|
||||
"text": [
|
||||
"正在提交",
|
||||
"反馈至神经"
|
||||
],
|
||||
"roi": [
|
||||
700,
|
||||
600,
|
||||
300,
|
||||
120
|
||||
],
|
||||
"next": [
|
||||
"DroneConfirmLoading",
|
||||
"DeliverableOrder",
|
||||
"DroneAssist-Trade-Stop",
|
||||
"DroneAssistMfg"
|
||||
@@ -3056,6 +3148,25 @@
|
||||
"ClueGiveTo1stConfirm"
|
||||
]
|
||||
},
|
||||
"ClueGiveLoading": {
|
||||
"algorithm": "OcrDetect",
|
||||
"action": "doNothing",
|
||||
"text": [
|
||||
"正在提交",
|
||||
"反馈至神经"
|
||||
],
|
||||
"roi": [
|
||||
700,
|
||||
600,
|
||||
300,
|
||||
120
|
||||
],
|
||||
"next": [
|
||||
"ClueGiveLoading",
|
||||
"SelectClue",
|
||||
"CloseSendClue"
|
||||
]
|
||||
},
|
||||
"ClueGiveTo1st": {
|
||||
"template": "ClusCanBeSent.png",
|
||||
"action": "doNothing",
|
||||
@@ -3084,6 +3195,7 @@
|
||||
160
|
||||
],
|
||||
"next": [
|
||||
"ClueGiveLoading",
|
||||
"SelectClue",
|
||||
"CloseSendClue"
|
||||
]
|
||||
@@ -3116,6 +3228,7 @@
|
||||
160
|
||||
],
|
||||
"next": [
|
||||
"ClueGiveLoading",
|
||||
"SelectClue",
|
||||
"CloseSendClue"
|
||||
]
|
||||
@@ -3148,6 +3261,7 @@
|
||||
160
|
||||
],
|
||||
"next": [
|
||||
"ClueGiveLoading",
|
||||
"SelectClue",
|
||||
"CloseSendClue"
|
||||
]
|
||||
@@ -3180,6 +3294,7 @@
|
||||
160
|
||||
],
|
||||
"next": [
|
||||
"ClueGiveLoading",
|
||||
"SelectClue",
|
||||
"CloseSendClue"
|
||||
]
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
#include "Resource.h"
|
||||
#include "OcrImageAnalyzer.h"
|
||||
#include "Controller.h"
|
||||
#include "RecruitImageAnalyzer.h"
|
||||
#include "ProcessTask.h"
|
||||
#include "RecruitTask.h"
|
||||
|
||||
@@ -108,32 +107,39 @@ bool asst::AutoRecruitTask::recruit_index(size_t index)
|
||||
|
||||
bool asst::AutoRecruitTask::calc_and_recruit()
|
||||
{
|
||||
RecruitTask recurit_task(m_callback, m_callback_arg, m_task_chain);
|
||||
recurit_task.set_retry_times(m_retry_times);
|
||||
recurit_task.set_param(m_select_level, true);
|
||||
RecruitTask recruit_task(m_callback, m_callback_arg, m_task_chain);
|
||||
recruit_task.set_retry_times(m_retry_times);
|
||||
recruit_task.set_param(m_select_level, true);
|
||||
|
||||
// 识别错误,放弃这个公招位,直接返回
|
||||
if (!recurit_task.run()) {
|
||||
if (!recruit_task.run()) {
|
||||
callback(AsstMsg::SubTaskError, basic_info());
|
||||
click_return_button();
|
||||
return true;
|
||||
}
|
||||
|
||||
int maybe_level = recurit_task.get_maybe_level();
|
||||
int maybe_level = recruit_task.get_maybe_level();
|
||||
if (need_exit()) {
|
||||
return false;
|
||||
}
|
||||
// 尝试刷新
|
||||
if (m_need_refresh && maybe_level == 3
|
||||
&& !recurit_task.get_has_special_tag()
|
||||
&& recurit_task.get_has_refresh()) {
|
||||
&& !recruit_task.get_has_special_tag()
|
||||
&& recruit_task.get_has_refresh()) {
|
||||
if (refresh()) {
|
||||
return calc_and_recruit();
|
||||
}
|
||||
}
|
||||
// 如果时间没调整过,那 tag 十有八九也没选,重新试一次
|
||||
// 造成时间没调的原因可见: https://github.com/MaaAssistantArknights/MaaAssistantArknights/pull/300#issuecomment-1073287984
|
||||
if (check_time_unreduced()) {
|
||||
return calc_and_recruit();
|
||||
}
|
||||
|
||||
if (need_exit()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (std::find(m_confirm_level.cbegin(), m_confirm_level.cend(), maybe_level) != m_confirm_level.cend()) {
|
||||
if (!confirm()) {
|
||||
return false;
|
||||
@@ -144,6 +150,12 @@ bool asst::AutoRecruitTask::calc_and_recruit()
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool asst::AutoRecruitTask::check_time_unreduced()
|
||||
{
|
||||
ProcessTask task(*this, {"RecruitCheckTimeUnreduced"});
|
||||
task.set_retry_times(1);
|
||||
return task.run();
|
||||
}
|
||||
|
||||
bool asst::AutoRecruitTask::check_recruit_home_page()
|
||||
{
|
||||
@@ -168,4 +180,4 @@ bool asst::AutoRecruitTask::refresh()
|
||||
{
|
||||
ProcessTask refresh_task(*this, { "RecruitRefresh" });
|
||||
return refresh_task.run();
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ namespace asst
|
||||
bool recruit_index(size_t index);
|
||||
bool calc_and_recruit();
|
||||
bool check_recruit_home_page();
|
||||
bool check_time_unreduced();
|
||||
bool recruit_now();
|
||||
bool confirm();
|
||||
bool refresh();
|
||||
|
||||
@@ -234,7 +234,7 @@ void asst::Controller::pipe_working_proc()
|
||||
m_cmd_queue.pop();
|
||||
cmd_queue_lock.unlock();
|
||||
// todo 判断命令是否执行成功
|
||||
call_command(cmd);
|
||||
call_command(cmd, 20 * 1000);
|
||||
++m_completed_id;
|
||||
}
|
||||
//else if (!m_thread_idle) { // 队列中没有任务,又不是闲置的时候,就去截图
|
||||
@@ -398,14 +398,22 @@ bool asst::Controller::try_capture(const EmulatorInfo & info, bool without_handl
|
||||
// }
|
||||
//}
|
||||
|
||||
std::optional<std::vector<unsigned char>> asst::Controller::call_command(const std::string & cmd)
|
||||
std::optional<std::vector<unsigned char>> asst::Controller::call_command(const std::string & cmd, int64_t timeout)
|
||||
{
|
||||
LogTraceFunction;
|
||||
|
||||
std::vector<uchar> pipe_data;
|
||||
|
||||
static std::mutex pipe_mutex;
|
||||
std::unique_lock<std::mutex> pipe_lock(pipe_mutex);
|
||||
|
||||
std::vector<uchar> pipe_data;
|
||||
auto start_time = std::chrono::steady_clock::now();
|
||||
auto check_timeout = [&]() -> bool {
|
||||
return timeout &&
|
||||
timeout < std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now() - start_time)
|
||||
.count();
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
PROCESS_INFORMATION process_info = { 0 }; // 进程信息结构体
|
||||
@@ -423,10 +431,12 @@ std::optional<std::vector<unsigned char>> asst::Controller::call_command(const s
|
||||
pipe_data.insert(pipe_data.end(), m_pipe_buffer.get(), m_pipe_buffer.get() + read_num);
|
||||
}
|
||||
}
|
||||
} while (::WaitForSingleObject(process_info.hProcess, 0) == WAIT_TIMEOUT);
|
||||
} while (::WaitForSingleObject(process_info.hProcess, 0) == WAIT_TIMEOUT && !check_timeout());
|
||||
|
||||
DWORD exit_ret = 255;
|
||||
::GetExitCodeProcess(process_info.hProcess, &exit_ret);
|
||||
if (!check_timeout()) {
|
||||
::GetExitCodeProcess(process_info.hProcess, &exit_ret);
|
||||
}
|
||||
|
||||
::CloseHandle(process_info.hProcess);
|
||||
::CloseHandle(process_info.hThread);
|
||||
@@ -462,7 +472,7 @@ std::optional<std::vector<unsigned char>> asst::Controller::call_command(const s
|
||||
pipe_data.insert(pipe_data.end(), m_pipe_buffer.get(), m_pipe_buffer.get() + read_num);
|
||||
read_num = read(m_pipe_out[PIPE_READ], m_pipe_buffer.get(), PipeBuffSize);
|
||||
};
|
||||
} while (::waitpid(m_child, &exit_ret, WNOHANG) == 0);
|
||||
} while (::waitpid(m_child, &exit_ret, WNOHANG) == 0 && !check_timeout());
|
||||
}
|
||||
else {
|
||||
// failed to create child process
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace asst
|
||||
bool connect_adb(const std::string& address);
|
||||
|
||||
void pipe_working_proc();
|
||||
std::optional<std::vector<unsigned char>> call_command(const std::string& cmd);
|
||||
std::optional<std::vector<unsigned char>> call_command(const std::string& cmd, int64_t timeout = 0);
|
||||
int push_cmd(const std::string& cmd);
|
||||
|
||||
using DecodeFunc = std::function<bool(const std::vector<uchar>&)>;
|
||||
|
||||
Reference in New Issue
Block a user