瀏覽代碼

feat(DemonEncounter): 添加封魔boss进入按钮及wait_and_click函数

- 添加 I_DE_BOSS_ENTER 图片规则 (994,485,106,30)
- 在点灯笼后、执行boss前添加 wait_and_click(I_DE_BOSS_ENTER)
- 新增 wait_and_click 函数:等待目标出现并点击
- 更新 image.json 添加 de_boss_enter 配置
lhye 6 月之前
父節點
當前提交
1549ad3898

+ 4 - 2
tasks/DemonEncounter/assets.py

@@ -71,9 +71,11 @@ class DemonEncounterAssets:
 
 
 	# Image Rule Assets
-	# 红色达摩 
+	# 红色达摩
 	I_DE_RED_DHARMA = RuleImage(roi_front=(1216,215,32,33), roi_back=(1209,208,51,50), threshold=0.7, method="Template matching", file="./tasks/DemonEncounter/demon/demon_de_red_dharma.png")
-	# 点击右下角的寻找封魔 
+	# description
+	I_DE_BOSS_ENTER = RuleImage(roi_front=(994,485,106,30), roi_back=(994,485,106,30), threshold=0.8, method="Template matching", file="./tasks/DemonEncounter/demon/demon_de_boss_enter.png")
+	# 点击右下角的寻找封魔
 	I_DE_FIND = RuleImage(roi_front=(1136,593,100,100), roi_back=(1136,593,100,100), threshold=0.8, method="Template matching", file="./tasks/DemonEncounter/demon/demon_de_find.png")
 	# 点击首领 
 	I_DE_BOSS = RuleImage(roi_front=(1001,645,45,45), roi_back=(1001,645,45,45), threshold=0.8, method="Template matching", file="./tasks/DemonEncounter/demon/demon_de_boss.png")

二進制
tasks/DemonEncounter/demon/demon_de_boss_enter.png


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

@@ -8,6 +8,15 @@
     "threshold": 0.7,
     "description": "红色达摩"
   },
+  {
+    "itemName": "de_boss_enter",
+    "imageName": "demon_de_boss_enter.png",
+    "roiFront": "994,485,106,30",
+    "roiBack": "994,485,106,30",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "进入boss"
+  },
   {
     "itemName": "de_find",
     "imageName": "demon_de_find.png",

+ 20 - 0
tasks/DemonEncounter/script_task.py

@@ -49,6 +49,7 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets, SwitchSoul):
             self.checkout_soul()
         self.ui_goto(page_demon_encounter)
         self.execute_lantern()
+        self.wait_and_click(self.I_DE_BOSS_ENTER)
         self.execute_boss()
 
         self.set_next_run(task='DemonEncounter', success=True, finish=False)
@@ -544,6 +545,25 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets, SwitchSoul):
         boss_name = BossType(datetime.now().weekday()).name
         return getattr(self.conf.best_demon_boss_config, f'best_demon_{boss_name}_select', False)
 
+    def wait_and_click(self, target) -> bool:
+        """
+        等待目标出现并点击,然后返回True
+        :param target: 图片规则
+        :return: 点击成功返回True
+        """
+        from module.base.timer import Timer
+        from module.exception import TaskEnd
+        timeout = 60
+        timer = Timer(timeout)
+        timer.start()
+        while not timer.reached():
+            self.screenshot()
+            if self.appear(target):
+                if self.appear_then_click(target, interval=1):
+                    return True
+        logger.warning(f'wait_and_click {target.name} timeout')
+        return False
+
 
 if __name__ == '__main__':
     from module.config.config import Config