瀏覽代碼

Merge pull request #364 from ChengRanORZ/fixAreaBoss

Fix area boss
huangrunheng 2 年之前
父節點
當前提交
1c001ffdf3

+ 2 - 0
tasks/AreaBoss/assets.py

@@ -97,6 +97,8 @@ class AreaBossAssets:
 	I_AB_JI_FLOOR_LIST_CHECK = RuleImage(roi_front=(390,150,60,290), roi_back=(390,150,60,290), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_ji_floor_list_check.png")
 	I_AB_JI_FLOOR_LIST_CHECK = RuleImage(roi_front=(390,150,60,290), roi_back=(390,150,60,290), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_ji_floor_list_check.png")
 	# 极地鬼 一层 
 	# 极地鬼 一层 
 	I_AB_JI_FLOOR_ONE = RuleImage(roi_front=(390,150,60,290), roi_back=(390,150,60,290), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_ji_floor_one.png")
 	I_AB_JI_FLOOR_ONE = RuleImage(roi_front=(390,150,60,290), roi_back=(390,150,60,290), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_ji_floor_one.png")
+	# 小组内未取得名次 
+	I_AB_GROUP_RANK_NONE = RuleImage(roi_front=(890,415,95,85), roi_back=(890,415,95,85), threshold=0.8, method="Template matching", file="./tasks/AreaBoss/res/ab_rank_none.png")
 
 
 
 
 	# Ocr Rule Assets
 	# Ocr Rule Assets

二進制
tasks/AreaBoss/res/ab_rank_none.png


+ 10 - 1
tasks/AreaBoss/res/image.json

@@ -170,7 +170,7 @@
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "极地鬼 层数列表打开 标志"
     "description": "极地鬼 层数列表打开 标志"
   },
   },
-    {
+  {
     "itemName": "ab_ji_floor_one",
     "itemName": "ab_ji_floor_one",
     "imageName": "ab_ji_floor_one.png",
     "imageName": "ab_ji_floor_one.png",
     "roiFront": "390,150,60,290",
     "roiFront": "390,150,60,290",
@@ -178,5 +178,14 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "极地鬼 一层"
     "description": "极地鬼 一层"
+  },
+  {
+    "itemName": "ab_group_rank_none",
+    "imageName": "ab_rank_none.png",
+    "roiFront": "890,415,95,85",
+    "roiBack": "890,415,95,85",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "小组内未取得名次"
   }
   }
 ]
 ]

+ 55 - 18
tasks/AreaBoss/script_task.py

@@ -140,7 +140,15 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
         """
         """
         if not self.appear(self.I_AB_FILTER_OPENED):
         if not self.appear(self.I_AB_FILTER_OPENED):
             self.open_filter()
             self.open_filter()
-        self.ui_click(battle, self.I_AB_CLOSE_RED)
+
+        # 如果打不开鬼王详情界面,直接退出
+        if not self.open_boss_detail(battle, 3):
+            return False
+
+        # 如果已经打过该BOSS,直接跳过不打了
+        if self.is_group_ranked():
+            self.ui_click_until_disappear(self.I_AB_CLOSE_RED, interval=3)
+            return True
 
 
         if ultra:
         if ultra:
             if not self.get_difficulty():
             if not self.get_difficulty():
@@ -150,7 +158,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
                     if not self.start_fight():
                     if not self.start_fight():
                         logger.warning("you are so weakness!")
                         logger.warning("you are so weakness!")
                         self.wait_until_appear(self.I_AB_CLOSE_RED)
                         self.wait_until_appear(self.I_AB_CLOSE_RED)
-                        self.ui_click_until_disappear(self.I_AB_CLOSE_RED, interval=1)
+                        self.ui_click_until_disappear(self.I_AB_CLOSE_RED, interval=3)
                         return False
                         return False
                 # 切换到 极地鬼
                 # 切换到 极地鬼
                 self.switch_difficulty(True)
                 self.switch_difficulty(True)
@@ -208,22 +216,24 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
             if self.appear(_to):
             if self.appear(_to):
                 break
                 break
             if self.appear(_from):
             if self.appear(_from):
-                self.click(_from, interval=1)
+                self.click(_from, interval=3)
                 continue
                 continue
 
 
     def switch_to_floor_1(self):
     def switch_to_floor_1(self):
         """
         """
             更改层数为一层
             更改层数为一层
         """
         """
-        _Floor = ["壹星", "贰星", "叁星", "肆星", "伍星", "陆星", "柒星", "捌星", "玖星", "拾星"]
+        # _Floor = ["壹星", "贰星", "叁星", "肆星", "伍星", "陆星", "柒星", "捌星", "玖星", "拾星"]
         # 打开选择列表
         # 打开选择列表
-        self.ui_click(self.C_AB_JI_FLOOR_SELECTED, self.I_AB_JI_FLOOR_LIST_CHECK, interval=1)
+        self.ui_click(self.C_AB_JI_FLOOR_SELECTED, self.I_AB_JI_FLOOR_LIST_CHECK, interval=3)
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
             if self.appear(self.I_AB_JI_FLOOR_ONE):
             if self.appear(self.I_AB_JI_FLOOR_ONE):
                 self.click(self.I_AB_JI_FLOOR_ONE)
                 self.click(self.I_AB_JI_FLOOR_ONE)
                 break
                 break
             self.swipe(self.S_AB_FLOOR_DOWN, interval=1)
             self.swipe(self.S_AB_FLOOR_DOWN, interval=1)
+            # 等待滑动动画
+            self.wait_until_appear(self.I_AB_JI_FLOOR_ONE, False, 1)
 
 
     def fight_reward_boss(self):
     def fight_reward_boss(self):
         index = self.get_hot_in_reward()
         index = self.get_hot_in_reward()
@@ -231,7 +241,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
         # 滑动到最顶层
         # 滑动到最顶层
         if index < 3:
         if index < 3:
             logger.info("swipe to top")
             logger.info("swipe to top")
-            for i in range(3):
+            for i in range(random.randint(1, 3)):
                 self.swipe(self.S_AB_FILTER_DOWN)
                 self.swipe(self.S_AB_FILTER_DOWN)
         #
         #
         if index == 0:
         if index == 0:
@@ -241,7 +251,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
         elif index == 2:
         elif index == 2:
             return self.boss_fight(self.C_AB_BOSS_REWARD_PHOTO_3, True)
             return self.boss_fight(self.C_AB_BOSS_REWARD_PHOTO_3, True)
         # 保证滑动到最底部
         # 保证滑动到最底部
-        for i in range(3):
+        for i in range(random.randint(1, 3)):
             self.swipe(self.S_AB_FILTER_UP)
             self.swipe(self.S_AB_FILTER_UP)
         if index == 3:
         if index == 3:
             return self.boss_fight(self.C_AB_BOSS_REWARD_PHOTO_MINUS_2, True)
             return self.boss_fight(self.C_AB_BOSS_REWARD_PHOTO_MINUS_2, True)
@@ -273,6 +283,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
         self.open_filter()
         self.open_filter()
         for i in range(random.randint(1, 3)):
         for i in range(random.randint(1, 3)):
             self.swipe(self.S_AB_FILTER_UP)
             self.swipe(self.S_AB_FILTER_UP)
+        self.wait_until_appear(self.C_AB_BOSS_REWARD_PHOTO_MINUS_2, wait_time=1)
         num = self.get_num_challenge(self.C_AB_BOSS_REWARD_PHOTO_MINUS_2)
         num = self.get_num_challenge(self.C_AB_BOSS_REWARD_PHOTO_MINUS_2)
         lst.append(num)
         lst.append(num)
         self.ui_click_until_disappear(self.I_AB_CLOSE_RED)
         self.ui_click_until_disappear(self.I_AB_CLOSE_RED)
@@ -280,6 +291,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
         self.open_filter()
         self.open_filter()
         for i in range(random.randint(1, 3)):
         for i in range(random.randint(1, 3)):
             self.swipe(self.S_AB_FILTER_UP)
             self.swipe(self.S_AB_FILTER_UP)
+        self.wait_until_appear(self.C_AB_BOSS_REWARD_PHOTO_MINUS_1, wait_time=1)
         num = self.get_num_challenge(self.C_AB_BOSS_REWARD_PHOTO_MINUS_1)
         num = self.get_num_challenge(self.C_AB_BOSS_REWARD_PHOTO_MINUS_1)
         lst.append(num)
         lst.append(num)
         self.ui_click_until_disappear(self.I_AB_CLOSE_RED)
         self.ui_click_until_disappear(self.I_AB_CLOSE_RED)
@@ -301,20 +313,45 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, AreaBossAssets):
         @rtype:
         @rtype:
         """
         """
         # 如果鬼王不可挑战(未解锁),限制3次尝试打开鬼王详情界面
         # 如果鬼王不可挑战(未解锁),限制3次尝试打开鬼王详情界面
-        numTry = 0
-        while numTry < 3:
-            self.screenshot()
-            if self.appear(self.I_AB_CLOSE_RED):
-                break
-            if self.click(click_area, interval=2):
-                numTry += 1
-        if numTry >= 3:
+        if not self.open_boss_detail(click_area, 3):
+            logger.info("%s unavailable", str(click_area))
             return 0
             return 0
         return self.O_AB_NUM_OF_CHALLENGE.ocr_digit(self.device.image)
         return self.O_AB_NUM_OF_CHALLENGE.ocr_digit(self.device.image)
 
 
+    def open_boss_detail(self, battle: RuleImage, try_num: int = 3) -> bool:
+        """
+            打开鬼王详情界面
+        @param battle:
+        @type battle:
+        @param try_num: 重试次数
+        @type try_num:
+        @return:    True        打开成功
+                    False       打开失败
+        @rtype:
+        """
+        try_num = 3 if try_num <= 0 else try_num
+
+        while try_num > 0:
+            self.click(battle, interval=3)
+            if self.wait_until_appear(self.I_AB_CLOSE_RED, wait_time=3):
+                break
+            try_num -= 1
+        # 打开鬼王详情界面失败,直接返回
+        self.screenshot()
+        if self.appear(self.I_AB_CLOSE_RED):
+            return True
+        return False
+
+    def is_group_ranked(self):
+        """
+            判断该鬼王是否已经获取到小组排名
+        """
+        return not self.appear(self.I_AB_GROUP_RANK_NONE)
+        pass
+
     def open_filter(self):
     def open_filter(self):
         logger.info("openFilter")
         logger.info("openFilter")
-        self.ui_click(self.I_FILTER, self.I_AB_FILTER_OPENED, interval=1)
+        self.ui_click(self.I_FILTER, self.I_AB_FILTER_OPENED, interval=3)
 
 
     def switch_to_collect(self):
     def switch_to_collect(self):
         while 1:
         while 1:
@@ -348,10 +385,10 @@ if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config
     from module.device.device import Device
     from module.device.device import Device
 
 
-    c = Config('oas2')
+    c = Config('oas1')
     d = Device(c)
     d = Device(c)
     t = ScriptTask(c, d)
     t = ScriptTask(c, d)
-    time.sleep(3)
+    # time.sleep(3)
     # t.switchFloor2One()
     # t.switchFloor2One()
     # t.switch2Level60()
     # t.switch2Level60()
     t.run()
     t.run()

+ 1 - 1
tasks/GameUi/assets.py

@@ -71,7 +71,7 @@ class GameUiAssets:
 	# description 
 	# description 
 	I_CHECK_SECRET_ZONES = RuleImage(roi_front=(1145,592,110,119), roi_back=(1145,592,110,119), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_secret_zones.png")
 	I_CHECK_SECRET_ZONES = RuleImage(roi_front=(1145,592,110,119), roi_back=(1145,592,110,119), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_secret_zones.png")
 	# description 
 	# description 
-	I_CHECK_AREA_BOSS = RuleImage(roi_front=(1176,505,65,62), roi_back=(1159,487,101,106), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_area_boss.png")
+	I_CHECK_AREA_BOSS = RuleImage(roi_front=(20,320,150,130), roi_back=(20,320,150,130), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_area_boss.png")
 	# description 
 	# description 
 	I_CHECK_HEIAN_KITAN = RuleImage(roi_front=(27,48,47,39), roi_back=(27,48,47,39), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_heian_kitan.png")
 	I_CHECK_HEIAN_KITAN = RuleImage(roi_front=(27,48,47,39), roi_back=(27,48,47,39), threshold=0.8, method="Template matching", file="./tasks/GameUi/page/page_check_heian_kitan.png")
 	# description 
 	# description 

二進制
tasks/GameUi/page/page_check_area_boss.png


+ 2 - 2
tasks/GameUi/page/page_img.json

@@ -182,8 +182,8 @@
   {
   {
     "itemName": "check_area_boss",
     "itemName": "check_area_boss",
     "imageName": "page_check_area_boss.png",
     "imageName": "page_check_area_boss.png",
-    "roiFront": "1176,505,65,62",
-    "roiBack": "1159,487,101,106",
+    "roiFront": "20,320,150,130",
+    "roiBack": "20,320,150,130",
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "description"
     "description": "description"