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

Merge pull request #1704 from musJinx/fix-explor

Fix-team-explor
huangrunheng 3 месяцев назад
Родитель
Сommit
be644738bc

+ 4 - 2
tasks/Exploration/assets.py

@@ -110,9 +110,9 @@ class ExplorationAssets:
 	# description 
 	I_E_EXIT_CONFIRM = RuleImage(roi_front=(694,380,163,49), roi_back=(694,380,163,49), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_e_exit_confirm.png")
 	# 宝箱 
-	I_TREASURE_BOX_CLICK = RuleImage(roi_front=(34,386,47,37), roi_back=(2,130,135,406), threshold=0.65, method="Template matching", file="./tasks/Exploration/res/res_treasure_box_click.png")
+	I_TREASURE_BOX_CLICK = RuleImage(roi_front=(31,543,27,24), roi_back=(11,520,378,65), threshold=0.65, method="Template matching", file="./tasks/Exploration/res/res_treasure_box_click.png")
 	# 困28滚动到最后 
-	I_SWIPE_END = RuleImage(roi_front=(994,234,119,100), roi_back=(968,196,311,165), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_swipe_end.png")
+	I_SWIPE_END = RuleImage(roi_front=(1213,79,66,265), roi_back=(1213,79,66,265), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_swipe_end.png")
 	# 队伍的表情标志 
 	I_TEAM_EMOJI = RuleImage(roi_front=(36,437,44,46), roi_back=(4,407,100,100), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_team_emoji.png")
 	# 组队按钮 
@@ -123,6 +123,8 @@ class ExplorationAssets:
 	I_EXP_ARROW_RIGHT = RuleImage(roi_front=(1240,117,24,21), roi_back=(1178,74,100,100), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_exp_arrow_right.png")
 	# 箭头,打开 
 	I_EXP_ARROW_LEFT = RuleImage(roi_front=(1244,115,18,26), roi_back=(1178,78,100,100), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_exp_arrow_left.png")
+	# 战斗中的队友标识 
+	I_TEAM_EMOJI_FIGHT = RuleImage(roi_front=(38,405,37,37), roi_back=(18,386,74,75), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_team_emoji_fight.png")
 
 
 	# Long Click Rule Assets

+ 9 - 1
tasks/Exploration/base.py

@@ -57,6 +57,15 @@ class BaseExploration(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, Replace
     def _match_end(self):
         return RuleAnimate(self.I_SWIPE_END)
 
+    def is_swipe_unchanged(self, before_image, after_image, threshold: float = 20) -> bool:
+        # 对比滑屏前后同一块区域,变化很小说明地图大概率没有移动,已经滑到尽头。
+        swipe_check_roi = (1216, 86, 64, 225)
+        before = self.I_SWIPE_END.corp(before_image, swipe_check_roi)
+        after = self.I_SWIPE_END.corp(after_image, swipe_check_roi)
+        diff = np.mean(np.abs(before.astype(np.int16) - after.astype(np.int16)))
+        logger.info(f'Swipe end area diff: {diff:.2f}')
+        return diff <= threshold
+
     def get_current_scene(self, reuse_screenshot: bool = True) -> Scene:
         if not reuse_screenshot:
             self.screenshot()
@@ -464,4 +473,3 @@ if __name__ == "__main__":
         print(t.get_current_scene())
     from PIL import Image
     # Image.fromarray(t.device.image.astype(np.uint8)).show()
-

+ 13 - 4
tasks/Exploration/res/image.json

@@ -173,8 +173,8 @@
   {
     "itemName": "treasure_box_click",
     "imageName": "res_treasure_box_click.png",
-    "roiFront": "34,386,47,37",
-    "roiBack": "2,130,135,406",
+    "roiFront": "31,543,27,24",
+    "roiBack": "11,520,378,65",
     "method": "Template matching",
     "threshold": 0.65,
     "description": "宝箱"
@@ -182,8 +182,8 @@
   {
     "itemName": "swipe_end",
     "imageName": "res_swipe_end.png",
-    "roiFront": "994,234,119,100",
-    "roiBack": "968,196,311,165",
+    "roiFront": "1213,79,66,265",
+    "roiBack": "1213,79,66,265",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "困28滚动到最后"
@@ -232,5 +232,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "箭头,打开"
+  },
+  {
+    "itemName": "team_emoji_fight",
+    "imageName": "res_team_emoji_fight.png",
+    "roiFront": "38,405,37,37",
+    "roiBack": "18,386,74,75",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "战斗中的队友标识"
   }
 ]

BIN
tasks/Exploration/res/res_swipe_end.png


BIN
tasks/Exploration/res/res_team_emoji_fight.png


BIN
tasks/Exploration/res/res_treasure_box_click.png


+ 72 - 80
tasks/Exploration/solo.py

@@ -9,12 +9,14 @@ from module.base.timer import Timer
 
 from tasks.Component.GeneralInvite.config_invite import InviteConfig, InviteNumber, FindMode
 from tasks.Exploration.base import BaseExploration, UpType, Scene
-from tasks.Exploration.config import ChooseRarity, AutoRotate, UserStatus, ExplorationLevel
+from tasks.Exploration.config import ChooseRarity, AutoRotate, UserStatus
 
 
 class SoloExploration(BaseExploration):
     INVITE_FLAG_OFF = (157, 109, 83)
     INVITE_FLAG_ON = (227, 193, 153)
+    INVITE_TIMEOUT = 20
+    FRIEND_LEAVE_TIMEOUT = 3
     explore_init = False
 
     @cached_property
@@ -28,9 +30,38 @@ class SoloExploration(BaseExploration):
             default_invite=False
         )
 
+    def _handle_treasure_box(self) -> bool:
+        if self.appear(self.I_TREASURE_BOX_CLICK):
+            logger.info('Treasure box appear, get it.')
+            self.ui_click_until_disappear(self.I_TREASURE_BOX_CLICK)
+            return True
+        return False
+
+    def _check_mate_leave(self, friend_leave_timer: Timer) -> bool:
+
+        if self.appear(self.I_TEAM_EMOJI) or self.appear(self.I_TEAM_EMOJI_FIGHT):
+            # 再次出现则重新计时,进入对局标志消失
+            if friend_leave_timer.started():
+                logger.warning('Team emoji appear again, clear friend_leave_timer')
+                friend_leave_timer.clear()
+            return False
+
+        logger.warning('Team emoji not appear')
+        if not friend_leave_timer.started():
+            logger.warning('Mate leave, start timer')
+            friend_leave_timer.start()
+            return False
+        if not friend_leave_timer.reached():
+            return False
+
+        logger.warning('Mate leave timer reached')
+        logger.warning('Exit team')
+        self.quit_explore()
+        return True
+
     def run_solo(self):
         logger.hr('solo')
-        search_fail_cnt = 0
+        search_fail_timer = Timer(3.2)  # 这里设置的时间一定要大于S_SWIPE_BACKGROUND_RIGHT滑动的时间
 
         while 1:
             self.screenshot()
@@ -41,10 +72,6 @@ class SoloExploration(BaseExploration):
                 # 打开右边箭头
                 if not self.wait_world_stable():
                     continue
-                if self.appear(self.I_TREASURE_BOX_CLICK):
-                    # 宝箱
-                    logger.info('Treasure box appear, get it.')
-                    self.ui_click_until_disappear(self.I_TREASURE_BOX_CLICK)
                 if self.check_exit():
                     break
                 self.open_expect_level()
@@ -63,6 +90,8 @@ class SoloExploration(BaseExploration):
                     self.ui_click(self.I_E_AUTO_ROTATE_OFF, stop=self.I_E_AUTO_ROTATE_ON)
                     self.explore_init = True
                     continue
+                if self._handle_treasure_box():
+                    continue
                 # 小纸人
                 if self.appear(self.I_BATTLE_REWARD):
                     if self.ui_get_reward(self.I_BATTLE_REWARD):
@@ -79,17 +108,15 @@ class SoloExploration(BaseExploration):
                         logger.info(f'Fight, minions cnt {self.minions_cnt}')
                     continue
                 # 向后拉,寻找怪
-                if search_fail_cnt >= 4:
-                    search_fail_cnt = 0
-                    if (self._config.exploration_config.exploration_level == ExplorationLevel.EXPLORATION_28\
-                        and self.appear(self.I_SWIPE_END))\
-                            or self._match_end.stable(self.device.image, refresh_after_stable=True):
+                if search_fail_timer.reached():
+                    search_fail_timer.reset()
+                    if self._match_end.stable(self.device.image, refresh_after_stable=True):
                         self.quit_explore()
                         continue
-                    if self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3):
-                        continue
-                else:
-                    search_fail_cnt += 1
+                    self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3)
+                    continue
+                if not search_fail_timer.started():
+                    search_fail_timer.start()
             #
             elif scene == Scene.BATTLE_PREPARE or scene == Scene.BATTLE_FIGHTING:
                 self.check_take_over_battle(is_screenshot=False, config=self._config.general_battle_config)
@@ -98,8 +125,8 @@ class SoloExploration(BaseExploration):
 
     def run_leader(self):
         logger.hr('leader')
-        search_fail_cnt = 0
-        friend_leave_timer = Timer(10)
+        search_fail_timer = Timer(3.2)  # 这里设置的时间一定要大于S_SWIPE_BACKGROUND_RIGHT滑动的时间
+        friend_leave_timer = Timer(self.FRIEND_LEAVE_TIMEOUT)
 
         while 1:
             self.screenshot()
@@ -110,22 +137,6 @@ class SoloExploration(BaseExploration):
                 # 打开右边箭头
                 if not self.wait_world_stable():
                     continue
-                if self.appear(self.I_TREASURE_BOX_CLICK):
-                    # 宝箱
-                    logger.info('Treasure box appear, get it.')
-                    self.wait_until_stable(self.I_UI_CANCEL, timer=Timer(0.6, 1))
-                    while 1:
-                        self.screenshot()
-                        if self.appear(self.I_REWARD):
-                            self.ui_click_until_disappear(self.I_REWARD)
-                            logger.info('Get reward.')
-                            break
-                        if self.ui_reward_appear_click():
-                            continue
-                        if self.appear_then_click(self.I_UI_CANCEL, interval=0.8):
-                            continue
-                        if self.appear_then_click(self.I_TREASURE_BOX_CLICK, interval=1):
-                            continue
                 if self.check_exit():
                     self.wait_until_stable(self.I_UI_CANCEL, timer=Timer(0.6, 2))
                     if self.appear(self.I_UI_CANCEL):
@@ -149,10 +160,11 @@ class SoloExploration(BaseExploration):
                         continue
                     if self.appear_then_click(self.I_ENSURE_PRIVATE_FALSE_2, interval=0.5):
                         continue
-                    if self.appear_then_click(self.I_EXP_CREATE_TEAM, interval=1):
-                        continue
+                    # 创建在组队前,组队蒙层后概率会被误识别
                     if self.appear_then_click(self.I_EXP_CREATE_ENSURE, interval=2):
                         continue
+                    if self.appear_then_click(self.I_EXP_CREATE_TEAM, interval=1):
+                        continue
             #
             elif scene == Scene.TEAM:
                 self.wait_until_stable(self.I_ADD_2, timer=Timer(0.8, 1))
@@ -180,27 +192,17 @@ class SoloExploration(BaseExploration):
                     if self._config.exploration_config.auto_rotate == AutoRotate.yes:
                         self.enter_settings_and_do_operations()
                     self.ui_click(self.I_E_AUTO_ROTATE_OFF, stop=self.I_E_AUTO_ROTATE_ON)
-                    friend_leave_timer = Timer(10)
                     self.explore_init = True
                     continue
+                if self._handle_treasure_box():
+                    continue
                 # 小纸人
                 if self.appear(self.I_BATTLE_REWARD):
                     if self.ui_get_reward(self.I_BATTLE_REWARD):
                         continue
                 # 中途有人跑路
-                if not self.appear(self.I_TEAM_EMOJI):
-                    if not friend_leave_timer.started():
-                        logger.warning('Mate leave, start timer')
-                        friend_leave_timer = Timer(10)
-                        friend_leave_timer.start()
-                    elif friend_leave_timer.started() and friend_leave_timer.reached():
-                        logger.warning('Mate leave timer reached')
-                        logger.warning('Exit team')
-                        self.quit_explore()
-                        continue
-                else:
-                    logger.warning('Team emoji appear again, clear friend_leave_timer')
-                    friend_leave_timer = Timer(10)
+                if self._check_mate_leave(friend_leave_timer):
+                    continue
                 # boss
                 if self.appear(self.I_BOSS_BATTLE_BUTTON):
                     if self.fire(self.I_BOSS_BATTLE_BUTTON):
@@ -213,17 +215,15 @@ class SoloExploration(BaseExploration):
                         logger.info(f'Fight, minions cnt {self.minions_cnt}')
                     continue
                 # 向后拉,寻找怪
-                if search_fail_cnt >= 4:
-                    search_fail_cnt = 0
-                    if (self._config.exploration_config.exploration_level == ExplorationLevel.EXPLORATION_28\
-                        and self.appear(self.I_SWIPE_END))\
-                            or self._match_end.stable(self.device.image, refresh_after_stable=True):
+                if search_fail_timer.reached():
+                    search_fail_timer.reset()
+                    if self._match_end.stable(self.device.image, refresh_after_stable=True):
                         self.quit_explore()
                         continue
-                    if self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=4.5):
-                        continue
-                else:
-                    search_fail_cnt += 1
+                    self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3)
+                    continue
+                if not search_fail_timer.started():
+                    search_fail_timer.start()
             #
             elif scene == Scene.BATTLE_PREPARE or scene == Scene.BATTLE_FIGHTING:
                 self.check_take_over_battle(is_screenshot=False, config=self._config.general_battle_config)
@@ -233,7 +233,7 @@ class SoloExploration(BaseExploration):
     def run_member(self):
         logger.hr('member')
         wait_timer = Timer(50)
-        friend_leave_timer = Timer(10)
+        friend_leave_timer = Timer(self.FRIEND_LEAVE_TIMEOUT)
 
         while 1:
             self.screenshot()
@@ -244,14 +244,12 @@ class SoloExploration(BaseExploration):
                 # 打开右边箭头
                 if not self.wait_world_stable():
                     continue
-                if self.appear(self.I_TREASURE_BOX_CLICK):
-                    # 宝箱
-                    logger.info('Treasure box appear, get it.')
-                    self.ui_click_until_disappear(self.I_TREASURE_BOX_CLICK)
                 if self.check_exit():
                     break
                 if self.check_then_accept():
-                    pass
+                    # 接受邀请后清掉计时器
+                    wait_timer.clear()
+                    continue
                 if wait_timer.started() and wait_timer.reached():
                     logger.warning('Wait timer reached')
                     break
@@ -271,27 +269,16 @@ class SoloExploration(BaseExploration):
                     self.ui_click(self.I_E_AUTO_ROTATE_OFF, stop=self.I_E_AUTO_ROTATE_ON)
                     self.explore_init = True
                     continue
+                if self._handle_treasure_box():
+                    continue
                 # 小纸人
                 if self.appear(self.I_BATTLE_REWARD):
                     if self.ui_get_reward(self.I_BATTLE_REWARD):
                         continue
                 #
-                if not self.appear(self.I_TEAM_EMOJI):
-                    logger.warning('Team emoji not appear')
-                    if not friend_leave_timer.started():
-                        logger.warning('Mate leave, start timer')
-                        friend_leave_timer = Timer(10)
-                        friend_leave_timer.start()
-                    elif friend_leave_timer.started() and friend_leave_timer.reached():
-                        logger.warning('Mate leave timer reached')
-                        logger.warning('Exit team')
-                        self.quit_explore()
-                        wait_timer = Timer(50)
-                        wait_timer.start()
-                        continue
-                else:
-                    logger.warning('Team emoji appear again, clear friend_leave_timer')
-                    friend_leave_timer = Timer(10)
+                if self._check_mate_leave(friend_leave_timer):
+                    wait_timer.reset()
+                    continue
             #
             elif scene == Scene.BATTLE_PREPARE or scene == Scene.BATTLE_FIGHTING:
                 logger.info('[run_member] Handling scene: BATTLE')
@@ -312,6 +299,11 @@ class SoloExploration(BaseExploration):
                 continue
             if self.appear_then_click(self.I_ADD_5_4, interval=1):
                 continue
+            # 避免中途队友进来邀请死循环
+            if not self.appear(self.I_ADD_2) or not self.appear(self.I_ADD_5_4):
+                # 可能刚好点到人,点一下空地方
+                self.device.click(x=370, y=480, control_name='exploration_invite_friend_prevent')
+                return True
 
         friend_class = []
         class_ocr = [self.O_F_LIST_1, self.O_F_LIST_2, self.O_F_LIST_3, self.O_F_LIST_4]