Эх сурвалжийг харах

feat(DemonEncounter): 逢魔之时增加今日挑战次数检测

lhye 2 сар өмнө
parent
commit
7b329e3eac

+ 2 - 0
tasks/DemonEncounter/assets.py

@@ -125,6 +125,8 @@ class DemonEncounterAssets:
 	# Ocr Rule Assets
 	# 计数已经开启多少的 
 	O_DE_COUNTER = RuleOcr(roi=(1204,685,48,34), area=(1204,685,48,34), mode="DigitCounter", method="Default", keyword="", name="de_counter")
+	# 现世逢魔顶部今日挑战次数X/1的最小识别区, 0/1表示已打过直接结束 
+	O_DE_CHALLENGE_COUNT = RuleOcr(roi=(680,68,75,36), area=(680,68,75,36), mode="Full", method="Default", keyword="", name="de_challenge_count")
 
 
 	# Click Rule Assets

+ 9 - 0
tasks/DemonEncounter/demon/ocr.json

@@ -7,5 +7,14 @@
     "method": "Default",
     "keyword": "",
     "description": "计数已经开启多少的"
+  },
+  {
+    "itemName": "de_challenge_count",
+    "roiFront": "680,68,75,36",
+    "roiBack": "680,68,75,36",
+    "mode": "Full",
+    "method": "Default",
+    "keyword": "",
+    "description": "现世逢魔顶部今日挑战次数X/1的最小识别区, 0/1表示已打过直接结束"
   }
 ]

+ 19 - 0
tasks/DemonEncounter/script_task.py

@@ -3,6 +3,7 @@
 # github https://github.com/runhey
 import time
 from time import sleep
+import re
 
 from enum import Enum
 from cached_property import cached_property
@@ -48,12 +49,30 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets, SwitchSoul):
             self.ui_goto(page_shikigami_records)
             self.checkout_soul()
         self.ui_goto(page_demon_encounter_realworld)
+        # 顶部"今日挑战次数:X/1"检测, 0/1表示今日已打过, 直接结束
+        if self.check_challenge_done():
+            logger.info('Challenge count 0/1, already challenged today')
+            self.set_next_run(task='DemonEncounter', success=True, finish=False)
+            raise TaskEnd('DemonEncounter')
         self.execute_lantern()
         self.execute_boss()
 
         self.set_next_run(task='DemonEncounter', success=True, finish=False)
         raise TaskEnd('DemonEncounter')
 
+    def check_challenge_done(self) -> bool:
+        """
+        OCR识别现世逢魔顶部"今日挑战次数:X/1"
+        :return: True表示0/1今日已打过
+        """
+        results = self.O_DE_CHALLENGE_COUNT.detect_and_ocr(self.device.image)
+        text = ''.join(r.ocr_text for r in results)
+        m = re.search(r'([01])\s*/\s*1', text)
+        if not m:
+            logger.warning(f'Challenge count not recognized: [{text}], continue by default')
+            return False
+        return m.group(1) == '0'
+
     def checkout_soul(self):
         """
         切换御魂