mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-20 02:55:38 +08:00
feat.自动战斗新增支持费用增量字段,与击杀数是与的关系
This commit is contained in:
@@ -63,6 +63,7 @@
|
||||
|
||||
"cost_changes": 5, // 费用变化量,如果没达到就一直等待。可选,默认为 0,直接执行
|
||||
// 注意是从开始执行本 actions 开始计算的(即前一个 action 结束时的费用作为基准)
|
||||
// 另外仅在费用是两位数的时候识别的比较准,三位数的费用可能会识别错,不推荐使用
|
||||
// TODO: 其他条件
|
||||
// TODO: "condition_type": 0, // 执行条件间的关系,可选,默认 0
|
||||
// // 0 - 且; 1 - 或
|
||||
|
||||
@@ -4647,10 +4647,10 @@
|
||||
"algorithm": "OcrDetect",
|
||||
"text": [],
|
||||
"roi": [
|
||||
1197,
|
||||
492,
|
||||
1196,
|
||||
494,
|
||||
83,
|
||||
48
|
||||
44
|
||||
]
|
||||
},
|
||||
"BattleAutoSkillFlag": {
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace asst
|
||||
struct BattleAction // 操作
|
||||
{
|
||||
int kills = 0;
|
||||
int cost_changes = 0;
|
||||
BattleActionType type = BattleActionType::Deploy;
|
||||
std::string group_name; // 目标名,若 type >= SwitchSpeed, group_name 为空
|
||||
Point location;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "MultiMatchImageAnalyzer.h"
|
||||
#include "MatchImageAnalyzer.h"
|
||||
#include "OcrImageAnalyzer.h"
|
||||
#include "OcrWithPreprocessImageAnalyzer.h"
|
||||
#include "HashImageAnalyzer.h"
|
||||
#include "Logger.hpp"
|
||||
#include "TaskData.h"
|
||||
@@ -86,6 +87,11 @@ int asst::BattleImageAnalyzer::get_kills() const noexcept
|
||||
return m_kills;
|
||||
}
|
||||
|
||||
int asst::BattleImageAnalyzer::get_cost() const noexcept
|
||||
{
|
||||
return m_cost;
|
||||
}
|
||||
|
||||
void asst::BattleImageAnalyzer::clear() noexcept
|
||||
{
|
||||
m_opers.clear();
|
||||
@@ -468,14 +474,15 @@ bool asst::BattleImageAnalyzer::kills_analyze()
|
||||
|
||||
bool asst::BattleImageAnalyzer::cost_analyze()
|
||||
{
|
||||
OcrImageAnalyzer cost_analyzer(m_image);
|
||||
cost_analyzer.set_task_info("BattleKillsFlag");
|
||||
OcrWithPreprocessImageAnalyzer cost_analyzer(m_image);
|
||||
cost_analyzer.set_task_info("BattleCostData");
|
||||
cost_analyzer.set_replace(
|
||||
std::dynamic_pointer_cast<OcrTaskInfo>(Task.get("NumberOcrReplace"))->replace_map);
|
||||
|
||||
if (!cost_analyzer.analyze()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cost_analyzer.sort_result_by_score();
|
||||
std::string cost_str = cost_analyzer.get_result().front().text;
|
||||
|
||||
if (cost_str.empty() ||
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace asst
|
||||
const std::vector<Rect>& get_ready_skills() const noexcept;
|
||||
int get_hp() const noexcept;
|
||||
int get_kills() const noexcept;
|
||||
int get_cost() const noexcept;
|
||||
|
||||
void clear() noexcept;
|
||||
|
||||
|
||||
@@ -339,7 +339,6 @@ bool asst::BattleProcessTask::wait_condition(const BattleAction& action)
|
||||
}
|
||||
image = m_ctrler->get_image();
|
||||
BattleImageAnalyzer analyzer(image);
|
||||
|
||||
analyzer.set_target(BattleImageAnalyzer::Target::Kills);
|
||||
if (analyzer.analyze()) {
|
||||
m_kills = analyzer.get_kills();
|
||||
@@ -352,6 +351,29 @@ bool asst::BattleProcessTask::wait_condition(const BattleAction& action)
|
||||
std::this_thread::yield();
|
||||
}
|
||||
|
||||
if (action.cost_changes != 0) {
|
||||
int cost_base = -1;
|
||||
|
||||
while (true) {
|
||||
image = m_ctrler->get_image();
|
||||
BattleImageAnalyzer analyzer(image);
|
||||
analyzer.set_target(BattleImageAnalyzer::Target::Cost);
|
||||
if (analyzer.analyze()) {
|
||||
int cost = analyzer.get_cost();
|
||||
if (cost_base == -1) {
|
||||
cost_base = cost;
|
||||
continue;
|
||||
}
|
||||
if (cost >= cost_base + action.cost_changes) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
try_possible_skill(image);
|
||||
std::this_thread::yield();
|
||||
}
|
||||
}
|
||||
|
||||
// 部署干员还有额外等待费用够或 CD 转好
|
||||
if (action.type == BattleActionType::Deploy) {
|
||||
const std::string& name = m_group_to_oper_mapping[action.group_name].name;
|
||||
|
||||
@@ -90,6 +90,7 @@ bool asst::CopilotConfiger::parse(const json::value& json)
|
||||
action.type = BattleActionType::Deploy;
|
||||
}
|
||||
action.kills = action_info.get("kills", 0);
|
||||
action.cost_changes = action_info.get("cost_changes", 0);
|
||||
action.group_name = action_info.get("name", std::string());
|
||||
|
||||
action.location.x = action_info.get("location", 0, 0);
|
||||
|
||||
Reference in New Issue
Block a user