Преглед изворни кода

Merge pull request #1775 from lhye/dev

feat(DemonEncounter): 逢魔之时增加今日挑战次数检测;fix(RichMan): 寮商店购买后先重新识别再滑动
huangrunheng пре 2 месеци
родитељ
комит
9eb3966aa6

+ 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):
         """
         切换御魂

+ 13 - 0
tasks/RichMan/guild.py

@@ -67,8 +67,10 @@ class Guild(Buy, GameUi, RichManAssets):
             *([(self.I_GUILD_SKIN, self._guild_skin_ticket)] if con.skin_ticket else []),
         ]
         items_all_done = False
+        swipe_no_progress = 0
         while 1:
             self.screenshot()
+            bought_this_round = False
             for item in items:
                 button, func = item
                 if not self.appear(button):
@@ -80,12 +82,23 @@ class Guild(Buy, GameUi, RichManAssets):
                     if item == items[-1]:
                         items_all_done = True
                     items.remove(item)
+                    bought_this_round = True
+                    swipe_no_progress = 0
                 except ButtonException as e:
                     logger.warning(f'Button {button.name} click failed')
                 break
             if items_all_done:
                 logger.info(f'All items have been purchased {items}')
                 break
+            # 刚购买成功: 先等待界面稳定并重新识别, 视野内还有商品就继续买, 不要急着滑动
+            if bought_this_round:
+                time.sleep(1)
+                continue
+            # 连续多次滑动都没有买到东西, 防止无限滑动触发点击保护
+            swipe_no_progress += 1
+            if swipe_no_progress >= 8:
+                logger.warning(f'Swipe {swipe_no_progress} times without buying, stop guild store')
+                break
             if self.swipe(self.S_GUILD_STORE, interval=1.5):
                 time.sleep(2)
                 continue