feat: 肉鸽支持重新编队

This commit is contained in:
MistEO
2022-07-21 23:58:41 +08:00
parent 9ee81133f9
commit 2124d9022b
6 changed files with 122 additions and 7 deletions

View File

@@ -6962,6 +6962,50 @@
],
"rearDelay": 2000
},
"Roguelike1QuickFormationDelay": {
"algorithm": "JustReturn",
"action": "DoNothing",
"rearDelay": 100
},
"Roguelike1QuickFormationClearAndReselect": {
"action": "ClickSelf",
"roi": [
821,
608,
139,
112
],
"next": [
"Roguelike1QuickFormationClearAndReselect-Confirm"
]
},
"Roguelike1QuickFormationClearAndReselect-Confirm": {
"template": "Roguelike1FormationConfirm.png",
"roi": [
1015,
601,
265,
119
],
"next": [
"Roguelike1QuickFormationClearAndReselect-Formation"
]
},
"Roguelike1QuickFormationClearAndReselect-Formation": {
"template": "Roguelike1QuickFormation.png",
"action": "ClickSelf",
"roi": [
817,
0,
402,
146
],
"next": [
"Roguelike1QuickFormationClearAndReselect-Formation",
"Stop"
],
"rearDelay": 2000
},
"Roguelike1FormationOper": {
"cache": false,
"roi": [

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -7,6 +7,8 @@
bool asst::RoguelikeFormationImageAnalyzer::analyze()
{
m_result.clear();
MultiMatchImageAnalyzer opers_analyzer(m_image);
opers_analyzer.set_task_info("Roguelike1FormationOper");

View File

@@ -25,10 +25,6 @@ namespace asst
{
AbstractImageAnalyzer::set_roi(roi);
}
virtual void set_image(const cv::Mat image, const Rect& roi)
{
AbstractImageAnalyzer::set_image(image, roi);
}
bool selected_analyze(const Rect& roi);

View File

@@ -4,6 +4,7 @@
#include "Controller.h"
#include "TaskData.h"
#include "ProcessTask.h"
#include "Logger.hpp"
bool asst::RoguelikeFormationTaskPlugin::verify(AsstMsg msg, const json::value& details) const
{
@@ -23,17 +24,83 @@ bool asst::RoguelikeFormationTaskPlugin::verify(AsstMsg msg, const json::value&
bool asst::RoguelikeFormationTaskPlugin::_run()
{
RoguelikeFormationImageAnalyzer formation_analyzer(m_ctrler->get_image());
if (!formation_analyzer.analyze()) {
return false;
}
size_t pre_selected = 0;
size_t select_count = 0;
for (const auto& oper : formation_analyzer.get_result()) {
if (oper.selected) {
++pre_selected;
continue;
}
m_ctrler->click(oper.rect);
++select_count;
}
Log.info(__FUNCTION__, "pre_selected: ", pre_selected, " select: ", select_count);
// 以下情况清空重选(游戏会自动排序)
// 1. 这一页选满 8 个了
// 2. select 有值但是重新识别后发现总的选择数量并没有增加说明上面的click都没生效
bool reselect = false;
if (pre_selected == MaxNumOfOperPerPage) {
reselect = true;
}
if (!reselect && select_count != 0) {
sleep(Task.get("Roguelike1QuickFormationDelay")->rear_delay);
formation_analyzer.set_image(m_ctrler->get_image());
if (!formation_analyzer.analyze()) {
Log.warn("RoguelikeFormationImageAnalyzer re analyze failed");
return true;
}
auto& new_result = formation_analyzer.get_result();
size_t new_selected_count = std::count_if(new_result.cbegin(), new_result.cend(),
[](const auto& oper) { return oper.selected; });
// 说明 select_count 计数没生效,即都没点上
if (new_selected_count == pre_selected) {
reselect = true;
}
}
if (reselect) {
clear_and_reselect();
}
return true;
}
void asst::RoguelikeFormationTaskPlugin::clear_and_reselect()
{
// 清空并退出游戏会自动按等级重新排序
ProcessTask(*this, { "Roguelike1QuickFormationClearAndReselect" }).run();
size_t select_count = analyze_and_select();
// 说明第二页还有
if (select_count == MaxNumOfOperPerPage) {
ProcessTask(*this, { "SlowlySwipeToTheRight" }).run();
analyze_and_select();
// 应该不可能还有第三页吧,不管了
}
}
size_t asst::RoguelikeFormationTaskPlugin::analyze_and_select()
{
RoguelikeFormationImageAnalyzer formation_analyzer(m_ctrler->get_image());
if (!formation_analyzer.analyze()) {
return false;
}
size_t select_count = 0;
for (const auto& oper : formation_analyzer.get_result()) {
if (oper.selected) {
continue;
}
m_ctrler->click(oper.rect);
++select_count;
}
return true;
return select_count;
}

View File

@@ -6,6 +6,9 @@ namespace asst
// 集成战略模式快捷编队任务
class RoguelikeFormationTaskPlugin : public AbstractTaskPlugin
{
public:
static constexpr size_t MaxNumOfOperPerPage = 8;
public:
using AbstractTaskPlugin::AbstractTaskPlugin;
virtual ~RoguelikeFormationTaskPlugin() = default;
@@ -14,5 +17,8 @@ namespace asst
protected:
virtual bool _run() override;
void clear_and_reselect();
size_t analyze_and_select();
};
}