mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
perf: 按照 reviews 意见修改 ProcessTask
把 max_times 的计算拉出来做个函数
This commit is contained in:
@@ -135,24 +135,7 @@ bool ProcessTask::_run()
|
||||
|
||||
int& exec_times = m_exec_times[cur_name];
|
||||
|
||||
int max_times = m_cur_task_ptr->max_times;
|
||||
TimesLimitType limit_type = TimesLimitType::Pre;
|
||||
{
|
||||
std::string cur_base_name = cur_name;
|
||||
while (true) {
|
||||
if (auto iter = m_times_limit.find(cur_base_name); iter != m_times_limit.cend()) {
|
||||
max_times = iter->second.times;
|
||||
limit_type = iter->second.type;
|
||||
break;
|
||||
}
|
||||
if (size_t at_pos = cur_base_name.find('@'); at_pos == std::string::npos) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
cur_base_name = cur_base_name.substr(at_pos + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
auto [max_times, limit_type] = calc_time_limit();
|
||||
|
||||
if (limit_type == TimesLimitType::Pre && exec_times >= max_times) {
|
||||
info["what"] = "ExceededLimit";
|
||||
@@ -299,6 +282,21 @@ bool asst::ProcessTask::on_run_fails()
|
||||
return run();
|
||||
}
|
||||
|
||||
std::pair<int, asst::ProcessTask::TimesLimitType> asst::ProcessTask::calc_time_limit() const
|
||||
{
|
||||
// eg. "C@B@A" 的 max_times 取 "C@B@A", "B@A", "A" 中有 max_times 定义的最靠前者
|
||||
for (std::string cur_base_name = m_cur_task_ptr->name;;) {
|
||||
if (auto iter = m_times_limit.find(cur_base_name); iter != m_times_limit.cend()) {
|
||||
return { iter->second.times, iter->second.type };
|
||||
}
|
||||
size_t at_pos = cur_base_name.find('@');
|
||||
if (at_pos == std::string::npos) {
|
||||
return { m_cur_task_ptr->max_times, TimesLimitType::Pre };
|
||||
}
|
||||
cur_base_name = cur_base_name.substr(at_pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
json::value asst::ProcessTask::basic_info() const
|
||||
{
|
||||
return AbstractTask::basic_info() |
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace asst
|
||||
{
|
||||
// 流程任务,按照配置文件里的设置的流程运行
|
||||
class ProcessTask : public AbstractTask
|
||||
class ProcessTask final : public AbstractTask
|
||||
{
|
||||
public:
|
||||
enum class TimesLimitType
|
||||
@@ -40,6 +40,7 @@ namespace asst
|
||||
virtual bool on_run_fails() override;
|
||||
virtual json::value basic_info() const override;
|
||||
|
||||
std::pair<int, TimesLimitType> calc_time_limit() const;
|
||||
void exec_click_task(const Rect& matched_rect);
|
||||
void exec_swipe_task(ProcessTaskAction action);
|
||||
void exec_slowly_swipe_task(ProcessTaskAction action);
|
||||
|
||||
Reference in New Issue
Block a user