Sfoglia il codice sorgente

Merge pull request #2006 from leovefy/fix/wanted-quests-ocr

fix(WantedQuests): 悬赏地点数量识别失败时收紧区域重试
huangrunheng 1 settimana fa
parent
commit
358aaa6893
1 ha cambiato i file con 16 aggiunte e 5 eliminazioni
  1. 16 5
      tasks/WantedQuests/script_task.py

+ 16 - 5
tasks/WantedQuests/script_task.py

@@ -1,6 +1,7 @@
 # This Python file uses the following encoding: utf-8
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # @author runhey
 # github https://github.com/runhey
 # github https://github.com/runhey
+from copy import copy
 from datetime import timedelta, time, datetime
 from datetime import timedelta, time, datetime
 from time import sleep
 from time import sleep
 from typing import List
 from typing import List
@@ -23,6 +24,19 @@ from tasks.WantedQuests.config import CooperationType, CooperationSelectMask
 from tasks.WantedQuests.explore import WQExplore, ExploreWantedBoss
 from tasks.WantedQuests.explore import WQExplore, ExploreWantedBoss
 
 
 
 
+def _read_location_info(rule: RuleOcr, image):‘、
+    # https://github.com/runhey/OnmyojiAutoScript/pull/2006
+    pattern = r"^(.*?)[((]?数量[::]\s*(\d+)[))]"
+    match = re.match(pattern, rule.ocr(image))
+    if match and match.group(1):
+        return match
+    # 数量可能被单行 OCR 漏读;只收紧上下留白,保留完整地点名。
+    retry = copy(rule)
+    x, y, w, h = rule.roi
+    retry.roi = [x, y + 7, w, h - 14]
+    return re.match(pattern, retry.ocr(image))
+
+
 class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
 class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
     want_strategy_excluding: list[list] = []  # 不需要执行的
     want_strategy_excluding: list[list] = []  # 不需要执行的
     # 追踪界面(显示"前往"按钮的界面,左上角位置,神秘任务不好使)显示以下名称时,任务不再执行
     # 追踪界面(显示"前往"按钮的界面,左上角位置,神秘任务不好使)显示以下名称时,任务不再执行
@@ -269,11 +283,8 @@ class ScriptTask(WQExplore, SecretScriptTask, WantedQuestsAssets):
             # ,荒川之怒·壹,4,前往按钮,function
             # ,荒川之怒·壹,4,前往按钮,function
             result = [-1, '', -1, GOTO_BUTTON[index], self.challenge, '']
             result = [-1, '', -1, GOTO_BUTTON[index], self.challenge, '']
             type_wq = OCR_WQ_TYPE[index].ocr(self.device.image)
             type_wq = OCR_WQ_TYPE[index].ocr(self.device.image)
-            info_wq_1 = OCR_WQ_INFO[index].ocr(self.device.image)
-            info_wq_1 = info_wq_1.replace(':', ':').replace('(', '(').replace(')', ')')
-            info_wq_1 = info_wq_1.replace(':', ':')
-            match = re.match(r"^(.*?)[((]?数量[::]\s*(\d+)[))]", info_wq_1)
-            if not match:
+            match = _read_location_info(OCR_WQ_INFO[index], self.device.image)
+            if not match or not match.group(1):
                 return None
                 return None
             wq_destination = match.group(1)
             wq_destination = match.group(1)
             wq_number = int(match.group(2))
             wq_number = int(match.group(2))