初步完成发电站换班任务

This commit is contained in:
MistEO
2021-09-11 14:48:18 +08:00
parent f2d36824f5
commit 9c3df883ef
6 changed files with 112 additions and 8 deletions

View File

@@ -315,9 +315,9 @@ bool asst::Assistance::start_infrast()
2) 如果没收获,使用基建默认大小的模板匹配
3. 进入宿舍把心情低于阈值的、心情没满但不在工作的都换下去使用InfrastDormTask
4. 根据用户设置按顺序进入制造站or贸易站使用ProcessTask
5. 制造站or贸易站进行换班使用InfrastStationTask
6. 根据用户设置使用无人机加速制造or贸易使用ProcessTaskTODO
7. 会客室线索处理、发电站换班、控制中枢换班同样需要根据用户设置决定顺序TODO
5. 制造站or贸易站进行换班使用InfrastStationTask
6. 根据用户设置使用无人机加速制造or贸易使用ProcessTask
7. 会客室线索处理、发电站换班、控制中枢、办公室换班同样需要根据用户设置决定顺序TODO
*/
// 1. 从任意界面进入基建使用ProcessTask
@@ -333,9 +333,7 @@ bool asst::Assistance::start_infrast()
// 返回基建的主界面
append_match_task(InfrastTaskCahin, { "InfrastBegin" });
// 5. 队制造站or贸易站进行换班使用InfrastStationTask
// 6. 根据用户设置使用无人机加速制造or贸易TODO
// 5. 对制造站or贸易站进行换班使用InfrastStationTask
// TODO这里需要根据用户设置是先制造站还是先贸易站或者是别的设施
// 从进入制造站,到设施列表的界面
@@ -354,9 +352,19 @@ bool asst::Assistance::start_infrast()
// 贸易站换班
m_tasks_deque.emplace_back(shift_task_ptr);
// 无人机加速贸易站
// 6. 根据用户设置使用无人机加速制造or贸易使用ProcessTask
// 对贸易站使用无人机加速
append_match_task(InfrastTaskCahin, { "UavAssist-Trade" });
// 返回基建的主界面
append_match_task(InfrastTaskCahin, { "InfrastBegin" });
// 7. 会客室线索处理、发电站换班、控制中枢、办公室换班同样需要根据用户设置决定顺序TODO
// 发电站换班
auto power_task_ptr = std::make_shared<InfrastPowerTask>(task_callback, (void*)this);
power_task_ptr->set_task_chain(InfrastTaskCahin);
m_tasks_deque.emplace_back(std::move(power_task_ptr));
// 全操作完之后,再返回基建的主界面
append_match_task(InfrastTaskCahin, { "InfrastBegin" });

View File

@@ -8,6 +8,7 @@
#include "Identify.h"
#include "Configer.h"
#include "InfrastConfiger.h"
#include "Logger.hpp"
using namespace asst;
@@ -20,6 +21,8 @@ asst::InfrastAbstractTask::InfrastAbstractTask(AsstCallback callback, void* call
bool asst::InfrastAbstractTask::swipe_to_the_left()
{
DebugTraceFunction;
constexpr int SwipeTimes = 5;
m_swipe_duration = 100;
@@ -40,24 +43,32 @@ bool asst::InfrastAbstractTask::swipe_to_the_left()
bool asst::InfrastAbstractTask::click_clear_button()
{
DebugTraceFunction;
const static Rect ClearButtonRect(430, 655, 150, 40);
return m_controller_ptr->click(ClearButtonRect);
}
bool asst::InfrastAbstractTask::click_confirm_button()
{
DebugTraceFunction;
const static Rect ConfirmButtonRect(1105, 655, 150, 40);
return m_controller_ptr->click(ConfirmButtonRect);
}
bool asst::InfrastAbstractTask::click_return_button()
{
DebugTraceFunction;
const static Rect ConfirmButtonRect(20, 20, 135, 35);
return m_controller_ptr->click(ConfirmButtonRect);
}
bool asst::InfrastAbstractTask::swipe(bool reverse)
{
DebugTraceFunction;
//#ifndef LOG_TRACE
bool ret = true;
if (!reverse) {
@@ -81,6 +92,8 @@ std::vector<TextArea> asst::InfrastAbstractTask::detect_operators_name(
std::string>& feature_cond,
std::unordered_set<std::string>& feature_whatever)
{
DebugTraceFunction;
// 裁剪出来干员名的一个长条形图片,没必要把整张图片送去识别
int cropped_height = image.rows * m_cropped_height_ratio;
int cropped_upper_y = image.rows * m_cropped_upper_y_ratio;
@@ -247,6 +260,8 @@ std::vector<TextArea> asst::InfrastAbstractTask::detect_operators_name(
bool asst::InfrastAbstractTask::enter_station(const std::vector<std::string>& templ_names, int index, double threshold)
{
DebugTraceFunction;
cv::Mat image = m_controller_ptr->get_image();
std::vector<asst::Identify::FindImageResult> max_score_reslut;
@@ -284,3 +299,11 @@ bool asst::InfrastAbstractTask::enter_station(const std::vector<std::string>& te
return false;
}
bool asst::InfrastAbstractTask::click_first_operator()
{
DebugTraceFunction;
const static Rect FirstOperatorRect(420, 80, 125, 270);
return m_controller_ptr->click(FirstOperatorRect);
}

View File

@@ -22,6 +22,7 @@ namespace asst {
std::unordered_map<std::string, std::string>& feature_cond,
std::unordered_set<std::string>& feature_whatever);
virtual bool enter_station(const std::vector<std::string>& templ_names, int index, double threshold = 0.8);
virtual bool click_first_operator();
constexpr static int SwipeExtraDelayDefault = 1000;
constexpr static int SwipeDurationDefault = 2000;

View File

@@ -2,6 +2,7 @@
#include "WinMacro.h"
#include "Identify.h"
#include "Configer.h"
bool asst::InfrastPowerTask::run()
{
@@ -12,11 +13,77 @@ bool asst::InfrastPowerTask::run()
return false;
}
bool is_the_left = false;
for (int i = 0; i != PowerNum; ++i) {
enter_station({ "Power", "PowerMini"}, i);
sleep(1000);
if (enter_operator_selection()) {
if (is_the_left) {
select_operators(false);
}
else {
select_operators(true);
is_the_left = true;
}
}
sleep(1000);
click_return_button();
sleep(1000);
}
return true;
}
}
bool asst::InfrastPowerTask::enter_operator_selection()
{
// 有这些文字之一就说明“进驻信息”这个按钮已经点开了
static const std::vector<std::string> info_opened_flags = {
GbkToUtf8("当前房间入住信息"),
GbkToUtf8("进驻人数"),
GbkToUtf8("清空")
};
std::vector<TextArea> ocr_result = ocr_detect();
bool is_info_opened =
std::find_first_of(
ocr_result.cbegin(), ocr_result.cend(),
info_opened_flags.cbegin(), info_opened_flags.cend(),
[](const TextArea& lhs, const std::string& rhs)
-> bool { return lhs.text == rhs; })
!= ocr_result.cend();
static const std::string station_info = GbkToUtf8("进驻信息");
// 如果“进驻信息”窗口没点开,那就点开
if (!is_info_opened) {
auto station_info_iter = std::find_if(ocr_result.cbegin(), ocr_result.cend(),
[](const TextArea& textarea) -> bool {
return textarea.text == station_info;
});
m_controller_ptr->click(station_info_iter->rect);
sleep(1000);
}
cv::Mat image = m_controller_ptr->get_image();
auto goin_result = m_identify_ptr->find_image(image, "GoIn");
// 如果找到了GoIn“进驻”按钮进点进去准备选择干员
if (goin_result.score > Configer::TemplThresholdDefault) {
m_controller_ptr->click(goin_result.rect);
sleep(1000);
return true;
}
else {
return false; // 否则说明这个发电站是有人在的,不用换班
}
}
int asst::InfrastPowerTask::select_operators(bool need_to_the_left)
{
if (need_to_the_left) {
swipe_to_the_left();
}
// 发电站干员不用做识别,直接选择第一个即可
click_first_operator();
click_confirm_button();
return 1;
}

View File

@@ -14,5 +14,10 @@ namespace asst {
protected:
constexpr static int PowerNum = 3; // 发电站数量
// 进入当前发电站的干员选择界面
bool enter_operator_selection();
// 选择干员返回本次选择了几个干员DuckType发电站固定返回 1
int select_operators(bool need_to_the_left = false);
};
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB