diff --git a/resource/tasks.json b/resource/tasks.json index 0957ae85a5..d2fe093851 100644 --- a/resource/tasks.json +++ b/resource/tasks.json @@ -8340,9 +8340,8 @@ "BattleOperRoleTank": {}, "BattleOperRoleWarrior": {}, "BattleOperRoleDrone": {}, - "BattleOperCostRange": { - "algorithm": "Hash", - "hash": [], + "BattleOperCost": { + "template": "empty.png", "rectMove": [ -10, 12, diff --git a/src/MaaCore/Vision/Battle/BattlefieldMatcher.cpp b/src/MaaCore/Vision/Battle/BattlefieldMatcher.cpp index 78e6d074a3..80ad86911c 100644 --- a/src/MaaCore/Vision/Battle/BattlefieldMatcher.cpp +++ b/src/MaaCore/Vision/Battle/BattlefieldMatcher.cpp @@ -90,6 +90,7 @@ std::vector BattlefieldMatcher::deployment_analyze() con const Rect& avlb_move = Task.get("BattleOperAvailable")->rect_move; const Rect& cooling_move = Task.get("BattleOperCooling")->rect_move; const Rect& avatar_move = Task.get("BattleOperAvatar")->rect_move; + const Rect& cost_move = Task.get("BattleOperCost")->rect_move; std::vector oper_result; size_t index = 0; @@ -128,6 +129,9 @@ std::vector BattlefieldMatcher::deployment_analyze() con Log.error("oper is available, but with cooling"); } + Rect cost_rect = correct_rect(flag_res.rect.move(cost_move), m_image); + oper.cost = oper_cost_analyze(cost_rect); + oper.index = index++; oper_result.emplace_back(std::move(oper)); @@ -205,8 +209,20 @@ bool BattlefieldMatcher::oper_cooling_analyze(const Rect& roi) const int BattlefieldMatcher::oper_cost_analyze(const Rect& roi) const { - std::ignore = roi; - return 0; + int cost = -1; + RegionOCRer cost_analyzer(m_image, roi); + cost_analyzer.set_replace(Task.get("NumberOcrReplace")->replace_map); + cost_analyzer.set_use_char_model(true); + cost_analyzer.set_bin_threshold(80, 255); + if (!cost_analyzer.analyze()) { + Log.warn("oper cost analyze failed"); + return cost; + } + if (!utils::chars_to_number(cost_analyzer.get_result().text, cost)) { + Log.warn("oper cost convert failed, str:", cost_analyzer.get_result().text); + return cost; + } + return cost; } bool BattlefieldMatcher::oper_available_analyze(const Rect& roi) const