Просмотр исходного кода

Merge pull request #293 from ChengRanORZ/fixAreaBoss

修复因 OCR失败/默认筛选框中没有鬼王可挑战 等原因导致的 筛选按钮 频繁点击 卡死问题
huangrunheng 2 лет назад
Родитель
Сommit
884900dfd8

+ 13 - 2
tasks/AreaBoss/assets.py

@@ -10,6 +10,13 @@ from module.atom.list import RuleList
 class AreaBossAssets: 
 
 
+	# Click Rule Assets
+	# 热门按钮 
+	C_AB_FAMOUS_BTN = RuleClick(roi_front=(1190,220,50,120), roi_back=(1190,220,50,120), name="ab_famous_btn")
+	# 收藏按钮 
+	C_AB_COLLECTION_BTN = RuleClick(roi_front=(1190,580,50,120), roi_back=(1190,580,50,120), name="ab_collection_btn")
+
+
 	# Image Rule Assets
 	# 探索图标 
 	I_EXPLORE = RuleImage(roi_front=(758,122,66,77), roi_back=(339,104,836,120), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_explore.png")
@@ -31,6 +38,10 @@ class AreaBossAssets:
 	I_CLOSE_RED = RuleImage(roi_front=(1190,24,37,38), roi_back=(1190,24,37,38), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_close_red.png")
 	# 红色关闭 
 	I_AB_CLOSE_RED = RuleImage(roi_front=(1194,24,38,37), roi_back=(1194,24,38,37), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/res_ab_close_red.png")
+	# 筛选中 选中收藏标识 
+	I_AB_FILTER_TITLE_COLLECTION = RuleImage(roi_front=(940,110,170,70), roi_back=(940,110,170,70), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_filter_title_collection.png")
+	# 筛选界面打开标识 
+	I_AB_FILTER_OPENED = RuleImage(roi_front=(840,110,130,70), roi_back=(840,110,130,70), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_filter_opened.png")
 
 
 	# Ocr Rule Assets
@@ -39,8 +50,8 @@ class AreaBossAssets:
 	# 我的收藏 
 	O_AB_MY_COLLECT = RuleOcr(roi=(949,124,129,53), area=(949,124,129,53), mode="Single", method="Default", keyword="我的收藏", name="ab_my_collect")
 	# 热门 
-	O_AB_FAMOUS = RuleOcr(roi=(1188,181,78,82), area=(1188,181,78,82), mode="Single", method="Default", keyword="热门", name="ab_famous")
+	O_AB_FAMOUS = RuleOcr(roi=(1190,220,50,120), area=(1190,220,50,120), mode="Single", method="Default", keyword="热门", name="ab_famous")
 	# 收藏 
-	O_AB_COLLECTING = RuleOcr(roi=(1163,522,88,100), area=(1163,522,88,100), mode="Single", method="Default", keyword="收藏", name="ab_collecting")
+	O_AB_COLLECTING = RuleOcr(roi=(1190,580,50,120), area=(1190,580,50,120), mode="Single", method="Default", keyword="收藏", name="ab_collecting")
 
 

+ 14 - 0
tasks/AreaBoss/click.json

@@ -0,0 +1,14 @@
+[
+  {
+    "itemName": "ab_famous_btn",
+    "roiFront": "1190,220,50,120",
+    "roiBack": "1190,220,50,120",
+    "description": "热门按钮"
+  },
+  {
+    "itemName": "ab_collection_btn",
+    "roiFront": "1190,580,50,120",
+    "roiBack": "1190,580,50,120",
+    "description": "收藏按钮"
+  }
+]

BIN
tasks/AreaBoss/res/ab_filter_opened.png


BIN
tasks/AreaBoss/res/ab_filter_title_collection.png


+ 18 - 0
tasks/AreaBoss/res/image.json

@@ -88,5 +88,23 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "红色关闭"
+  },
+  {
+    "itemName": "ab_filter_title_collection",
+    "imageName": "ab_filter_title_collection.png",
+    "roiFront": "940,110,170,70",
+    "roiBack":  "940,110,170,70",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "筛选中 选中收藏标识"
+  },
+  {
+    "itemName": "ab_filter_opened",
+    "imageName": "ab_filter_opened.png",
+    "roiFront": "840,110,130,70",
+    "roiBack":  "840,110,130,70",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "筛选界面打开标识"
   }
 ]

+ 4 - 4
tasks/AreaBoss/res/ocr.json

@@ -19,8 +19,8 @@
   },
   {
     "itemName": "ab_famous",
-    "roiFront": "1188,181,78,82",
-    "roiBack": "1188,181,78,82",
+    "roiFront": "1190,220,50,120",
+    "roiBack": "1190,220,50,120",
     "mode": "Single",
     "method": "Default",
     "keyword": "热门",
@@ -28,8 +28,8 @@
   },
   {
     "itemName": "ab_collecting",
-    "roiFront": "1163,522,88,100",
-    "roiBack": "1163,522,88,100",
+    "roiFront": "1190,580,50,120",
+    "roiBack": "1190,580,50,120",
     "mode": "Single",
     "method": "Default",
     "keyword": "收藏",

+ 16 - 7
tasks/AreaBoss/script_task.py

@@ -3,6 +3,7 @@
 # github https://github.com/runhey
 import time
 
+import cv2
 from tasks.base_task import BaseTask
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.GameUi.game_ui import GameUi
@@ -71,26 +72,33 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
             if self.appear(self.I_CHECK_MAIN, threshold=0.6):
                 break
 
-    def boss(self, battle: RuleImage, collect: bool=False):
-        def switch_collect():
+    def boss(self, battle: RuleImage, collect: bool = False):
+        def switch2mycollect():
             while 1:
                 self.screenshot()
-                if self.ocr_appear(self.O_AB_MY_COLLECT):
+                if self.appear(self.I_AB_FILTER_TITLE_COLLECTION):
                     break
-                if self.ocr_appear_click(self.O_AB_COLLECTING, interval=1):
+                if self.appear(self.I_AB_FILTER_OPENED):
+                    self.click(self.C_AB_COLLECTION_BTN, 1.5)
                     continue
 
         # 点击右上角的鬼王选择
         logger.info("Script filter")
         while 1:
             self.screenshot()
-            if self.appear(self.I_BATTLE_1) or self.appear(self.I_BATTLE_2) or self.appear(self.I_BATTLE_3):
+            # 如果筛选界面已经打开 点击热门按钮
+            if self.appear(self.I_AB_FILTER_OPENED):
+                self.click(self.C_AB_FAMOUS_BTN)
                 break
-            if self.appear_then_click(self.I_FILTER, interval=2):
+            if self.appear_then_click(self.I_FILTER, interval=3):
                 continue
 
         if collect:
-            switch_collect()
+            switch2mycollect()
+        # 页面没有可挑战的BOSS
+        if not (self.appear(self.I_BATTLE_1) or self.appear(self.I_BATTLE_2) or self.appear(self.I_BATTLE_3)):
+            logger.error("There is no boss could be challenged")
+            return
         # 点击第几个鬼王
         logger.info(f'Script area boss {battle}')
         self.ui_click(battle, self.I_AB_CLOSE_RED)
@@ -109,6 +117,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
         self.wait_until_appear(self.I_AB_CLOSE_RED)
         self.ui_click(self.I_AB_CLOSE_RED, self.I_FILTER)
 
+
 if __name__ == '__main__':
     from module.config.config import Config
     from module.device.device import Device