mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 02:55:38 +08:00
perf: 自动战斗自定义添加干员编队时按职业选择
This commit is contained in:
@@ -145,7 +145,6 @@ bool asst::CopilotTask::set_params(const json::value& params)
|
|||||||
m_formation_task_ptr->set_enable(with_formation && navigate_name.find("TR") == std::string::npos);
|
m_formation_task_ptr->set_enable(with_formation && navigate_name.find("TR") == std::string::npos);
|
||||||
m_formation_task_ptr->set_select_formation(select_formation);
|
m_formation_task_ptr->set_select_formation(select_formation);
|
||||||
m_formation_task_ptr->set_add_trust(add_trust);
|
m_formation_task_ptr->set_add_trust(add_trust);
|
||||||
m_formation_task_ptr->set_add_user_additional(add_user_additional);
|
|
||||||
m_formation_task_ptr->set_support_unit_name(std::move(support_unit_name));
|
m_formation_task_ptr->set_support_unit_name(std::move(support_unit_name));
|
||||||
|
|
||||||
if (auto opt = params.find<json::array>("user_additional"); add_user_additional && opt) {
|
if (auto opt = params.find<json::array>("user_additional"); add_user_additional && opt) {
|
||||||
|
|||||||
@@ -22,11 +22,6 @@ void asst::BattleFormationTask::set_support_unit_name(std::string name)
|
|||||||
m_support_unit_name = std::move(name);
|
m_support_unit_name = std::move(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void asst::BattleFormationTask::set_add_user_additional(bool add_user_additional)
|
|
||||||
{
|
|
||||||
m_add_user_additional = add_user_additional;
|
|
||||||
}
|
|
||||||
|
|
||||||
void asst::BattleFormationTask::set_user_additional(std::vector<std::pair<std::string, int>> user_additional)
|
void asst::BattleFormationTask::set_user_additional(std::vector<std::pair<std::string, int>> user_additional)
|
||||||
{
|
{
|
||||||
m_user_additional = std::move(user_additional);
|
m_user_additional = std::move(user_additional);
|
||||||
@@ -42,7 +37,7 @@ void asst::BattleFormationTask::set_select_formation(int index)
|
|||||||
m_select_formation_index = index;
|
m_select_formation_index = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<std::unordered_map<std::string, std::string>>asst::BattleFormationTask::get_opers_in_formation() const
|
std::shared_ptr<std::unordered_map<std::string, std::string>> asst::BattleFormationTask::get_opers_in_formation() const
|
||||||
{
|
{
|
||||||
return m_opers_in_formation;
|
return m_opers_in_formation;
|
||||||
}
|
}
|
||||||
@@ -72,18 +67,19 @@ bool asst::BattleFormationTask::_run()
|
|||||||
for (auto& [role, oper_groups] : m_formation) {
|
for (auto& [role, oper_groups] : m_formation) {
|
||||||
add_formation(role, oper_groups, missing_operators);
|
add_formation(role, oper_groups, missing_operators);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!missing_operators.empty()) {
|
if (!missing_operators.empty()) {
|
||||||
if (missing_operators.size() == 1) {
|
if (missing_operators.size() == 1) {
|
||||||
// TODO: 自动借助战?
|
// TODO: 自动借助战?
|
||||||
}
|
}
|
||||||
|
|
||||||
report_missing_operators(missing_operators);
|
report_missing_operators(missing_operators);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_add_user_additional) {
|
// 对于有在干员组中存在的自定干员,无法提前得知是否成功编入,故不提前加入编队
|
||||||
|
if (!m_user_additional.empty()) {
|
||||||
auto limit = 12 - m_size_of_operators_in_formation;
|
auto limit = 12 - m_size_of_operators_in_formation;
|
||||||
for (const auto& [name, skill] : m_user_additional) {
|
for (const auto& [name, skill] : m_user_additional) {
|
||||||
if (m_opers_in_formation->contains(name)) {
|
if (m_opers_in_formation->contains(name)) {
|
||||||
@@ -96,9 +92,11 @@ bool asst::BattleFormationTask::_run()
|
|||||||
oper.name = name;
|
oper.name = name;
|
||||||
oper.skill = skill;
|
oper.skill = skill;
|
||||||
std::vector<asst::battle::OperUsage> usage { std::move(oper) };
|
std::vector<asst::battle::OperUsage> usage { std::move(oper) };
|
||||||
m_user_formation.emplace_back(name, std::move(usage));
|
m_user_formation[BattleData.get_role(name)].emplace_back(name, std::move(usage));
|
||||||
|
}
|
||||||
|
for (auto& [role, oper_groups] : m_user_formation) {
|
||||||
|
add_formation(role, oper_groups, missing_operators);
|
||||||
}
|
}
|
||||||
add_formation(battle::Role::Unknown, m_user_formation, missing_operators);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_additional();
|
add_additional();
|
||||||
@@ -117,7 +115,10 @@ bool asst::BattleFormationTask::_run()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool asst::BattleFormationTask::add_formation(battle::Role role, std::vector<OperGroup> oper_group, std::vector<OperGroup>& missing)
|
bool asst::BattleFormationTask::add_formation(
|
||||||
|
battle::Role role,
|
||||||
|
std::vector<OperGroup> oper_group,
|
||||||
|
std::vector<OperGroup>& missing)
|
||||||
{
|
{
|
||||||
LogTraceFunction;
|
LogTraceFunction;
|
||||||
|
|
||||||
@@ -145,7 +146,7 @@ bool asst::BattleFormationTask::add_formation(battle::Role role, std::vector<Ope
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (overall_swipe_times == m_missing_retry_times) {
|
if (overall_swipe_times == m_missing_retry_times) {
|
||||||
missing.insert(missing.end(), oper_group.begin(), oper_group.end());
|
missing.insert(missing.end(), oper_group.begin(), oper_group.end());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,9 +225,8 @@ bool asst::BattleFormationTask::add_trust_operators()
|
|||||||
ProcessTask(*this, { "BattleQuickFormationFilter-Trust" }).run();
|
ProcessTask(*this, { "BattleQuickFormationFilter-Trust" }).run();
|
||||||
ProcessTask(*this, { "BattleQuickFormationFilterClose" }).run();
|
ProcessTask(*this, { "BattleQuickFormationFilterClose" }).run();
|
||||||
// 检查特关是否开启
|
// 检查特关是否开启
|
||||||
ProcessTask(*this, {
|
ProcessTask(*this, { "BattleQuickFormationFilter-PinUnactivated", "BattleQuickFormationFilter-PinActivated" })
|
||||||
"BattleQuickFormationFilter-PinUnactivated", "BattleQuickFormationFilter-PinActivated"
|
.run();
|
||||||
}).run();
|
|
||||||
|
|
||||||
// 重置职业选择,保证处于最左
|
// 重置职业选择,保证处于最左
|
||||||
click_role_table(battle::Role::Caster);
|
click_role_table(battle::Role::Caster);
|
||||||
@@ -431,7 +431,9 @@ bool asst::BattleFormationTask::click_role_table(battle::Role role)
|
|||||||
tasks = { "BattleQuickFormationRole-All", "BattleQuickFormationRole-All-OCR" };
|
tasks = { "BattleQuickFormationRole-All", "BattleQuickFormationRole-All-OCR" };
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
tasks = { "BattleQuickFormationRole-" + role_iter->second, "BattleQuickFormationRole-All", "BattleQuickFormationRole-All-OCR"};
|
tasks = { "BattleQuickFormationRole-" + role_iter->second,
|
||||||
|
"BattleQuickFormationRole-All",
|
||||||
|
"BattleQuickFormationRole-All-OCR" };
|
||||||
}
|
}
|
||||||
return ProcessTask(*this, tasks).set_retry_times(0).run();
|
return ProcessTask(*this, tasks).set_retry_times(0).run();
|
||||||
}
|
}
|
||||||
@@ -475,7 +477,8 @@ bool asst::BattleFormationTask::select_formation(int select_index)
|
|||||||
// 第二组是名字最左边和最右边的一块区域
|
// 第二组是名字最左边和最右边的一块区域
|
||||||
// 右边比左边窄,暂定为左边 10*58
|
// 右边比左边窄,暂定为左边 10*58
|
||||||
|
|
||||||
static const std::vector<std::string> select_formation_task = { "BattleSelectFormation1", "BattleSelectFormation2",
|
static const std::vector<std::string> select_formation_task = { "BattleSelectFormation1",
|
||||||
|
"BattleSelectFormation2",
|
||||||
"BattleSelectFormation3",
|
"BattleSelectFormation3",
|
||||||
"BattleSelectFormation4" };
|
"BattleSelectFormation4" };
|
||||||
|
|
||||||
|
|||||||
@@ -7,80 +7,81 @@
|
|||||||
|
|
||||||
namespace asst
|
namespace asst
|
||||||
{
|
{
|
||||||
class BattleFormationTask : public AbstractTask
|
class BattleFormationTask : public AbstractTask
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
using AbstractTask::AbstractTask;
|
||||||
|
virtual ~BattleFormationTask() override = default;
|
||||||
|
|
||||||
|
enum class Filter
|
||||||
{
|
{
|
||||||
public:
|
None,
|
||||||
using AbstractTask::AbstractTask;
|
Trust,
|
||||||
virtual ~BattleFormationTask() override = default;
|
Cost,
|
||||||
|
|
||||||
enum class Filter
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Trust,
|
|
||||||
Cost,
|
|
||||||
};
|
|
||||||
struct AdditionalFormation
|
|
||||||
{
|
|
||||||
Filter filter = Filter::None;
|
|
||||||
bool double_click_filter = true;
|
|
||||||
battle::RoleCounts role_counts;
|
|
||||||
};
|
|
||||||
void append_additional_formation(AdditionalFormation formation);
|
|
||||||
|
|
||||||
void set_support_unit_name(std::string name);
|
|
||||||
// 是否追加自定干员
|
|
||||||
void set_add_user_additional(bool add_user_additional);
|
|
||||||
// 设置追加自定干员列表
|
|
||||||
void set_user_additional(std::vector<std::pair<std::string, int>> user_additional);
|
|
||||||
// 是否追加低信赖干员
|
|
||||||
void set_add_trust(bool add_trust);
|
|
||||||
// 设置对指定编队自动编队
|
|
||||||
void set_select_formation(int index);
|
|
||||||
std::shared_ptr<std::unordered_map<std::string, std::string>> get_opers_in_formation() const;
|
|
||||||
|
|
||||||
enum class DataResource
|
|
||||||
{
|
|
||||||
Copilot,
|
|
||||||
SSSCopilot,
|
|
||||||
};
|
|
||||||
void set_data_resource(DataResource resource);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
using OperGroup = std::pair<std::string, std::vector<asst::battle::OperUsage>>;
|
|
||||||
|
|
||||||
virtual bool _run() override;
|
|
||||||
bool add_formation(battle::Role role, std::vector<OperGroup> oper_group, std::vector<OperGroup>& missing);
|
|
||||||
// 追加附加干员(按部署费用等小分类)
|
|
||||||
bool add_additional();
|
|
||||||
// 补充刷信赖的干员,从最小的开始
|
|
||||||
bool add_trust_operators();
|
|
||||||
bool enter_selection_page();
|
|
||||||
bool select_opers_in_cur_page(std::vector<OperGroup>& groups);
|
|
||||||
void swipe_page();
|
|
||||||
void swipe_to_the_left(int times = 2);
|
|
||||||
bool confirm_selection();
|
|
||||||
bool click_role_table(battle::Role role);
|
|
||||||
bool parse_formation();
|
|
||||||
bool select_formation(int select_index);
|
|
||||||
bool select_random_support_unit();
|
|
||||||
void report_missing_operators(std::vector<OperGroup>& groups);
|
|
||||||
|
|
||||||
std::vector<asst::TemplDetOCRer::Result> analyzer_opers();
|
|
||||||
|
|
||||||
std::string m_stage_name;
|
|
||||||
std::unordered_map<battle::Role, std::vector<OperGroup>> m_formation;
|
|
||||||
std::vector<OperGroup> m_user_formation;
|
|
||||||
int m_size_of_operators_in_formation = 0; // 编队中干员个数
|
|
||||||
std::shared_ptr<std::unordered_map<std::string, std::string>> m_opers_in_formation =
|
|
||||||
std::make_shared<std::unordered_map<std::string, std::string>>(); // 编队中的干员名称-所属组名
|
|
||||||
bool m_add_trust = false; // 是否需要追加信赖干员
|
|
||||||
bool m_add_user_additional = false; // 补用户自定义干员
|
|
||||||
std::vector<std::pair<std::string, int>> m_user_additional; // 追加干员表,从头往后加
|
|
||||||
std::string m_support_unit_name;
|
|
||||||
DataResource m_data_resource = DataResource::Copilot;
|
|
||||||
std::vector<AdditionalFormation> m_additional;
|
|
||||||
std::string m_last_oper_name;
|
|
||||||
int m_select_formation_index = 0;
|
|
||||||
int m_missing_retry_times = 1; // 识别不到干员的重试次数
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AdditionalFormation
|
||||||
|
{
|
||||||
|
Filter filter = Filter::None;
|
||||||
|
bool double_click_filter = true;
|
||||||
|
battle::RoleCounts role_counts;
|
||||||
|
};
|
||||||
|
|
||||||
|
void append_additional_formation(AdditionalFormation formation);
|
||||||
|
|
||||||
|
void set_support_unit_name(std::string name);
|
||||||
|
// 是否追加自定干员
|
||||||
|
void set_add_user_additional(bool add_user_additional);
|
||||||
|
// 设置追加自定干员列表
|
||||||
|
void set_user_additional(std::vector<std::pair<std::string, int>> user_additional);
|
||||||
|
// 是否追加低信赖干员
|
||||||
|
void set_add_trust(bool add_trust);
|
||||||
|
// 设置对指定编队自动编队
|
||||||
|
void set_select_formation(int index);
|
||||||
|
std::shared_ptr<std::unordered_map<std::string, std::string>> get_opers_in_formation() const;
|
||||||
|
|
||||||
|
enum class DataResource
|
||||||
|
{
|
||||||
|
Copilot,
|
||||||
|
SSSCopilot,
|
||||||
|
};
|
||||||
|
void set_data_resource(DataResource resource);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
using OperGroup = std::pair<std::string, std::vector<asst::battle::OperUsage>>;
|
||||||
|
|
||||||
|
virtual bool _run() override;
|
||||||
|
bool add_formation(battle::Role role, std::vector<OperGroup> oper_group, std::vector<OperGroup>& missing);
|
||||||
|
// 追加附加干员(按部署费用等小分类)
|
||||||
|
bool add_additional();
|
||||||
|
// 补充刷信赖的干员,从最小的开始
|
||||||
|
bool add_trust_operators();
|
||||||
|
bool enter_selection_page();
|
||||||
|
bool select_opers_in_cur_page(std::vector<OperGroup>& groups);
|
||||||
|
void swipe_page();
|
||||||
|
void swipe_to_the_left(int times = 2);
|
||||||
|
bool confirm_selection();
|
||||||
|
bool click_role_table(battle::Role role);
|
||||||
|
bool parse_formation();
|
||||||
|
bool select_formation(int select_index);
|
||||||
|
bool select_random_support_unit();
|
||||||
|
void report_missing_operators(std::vector<OperGroup>& groups);
|
||||||
|
|
||||||
|
std::vector<asst::TemplDetOCRer::Result> analyzer_opers();
|
||||||
|
|
||||||
|
std::string m_stage_name;
|
||||||
|
std::unordered_map<battle::Role, std::vector<OperGroup>> m_formation;
|
||||||
|
std::unordered_map<battle::Role, std::vector<OperGroup>> m_user_formation;
|
||||||
|
int m_size_of_operators_in_formation = 0; // 编队中干员个数
|
||||||
|
std::shared_ptr<std::unordered_map<std::string, std::string>> m_opers_in_formation =
|
||||||
|
std::make_shared<std::unordered_map<std::string, std::string>>(); // 编队中的干员名称-所属组名
|
||||||
|
bool m_add_trust = false; // 是否需要追加信赖干员
|
||||||
|
std::vector<std::pair<std::string, int>> m_user_additional; // 追加干员表,从头往后加
|
||||||
|
std::string m_support_unit_name;
|
||||||
|
DataResource m_data_resource = DataResource::Copilot;
|
||||||
|
std::vector<AdditionalFormation> m_additional;
|
||||||
|
std::string m_last_oper_name;
|
||||||
|
int m_select_formation_index = 0;
|
||||||
|
int m_missing_retry_times = 1; // 识别不到干员的重试次数
|
||||||
|
};
|
||||||
} // namespace asst
|
} // namespace asst
|
||||||
|
|||||||
Reference in New Issue
Block a user