Sfoglia il codice sorgente

fix(Exploration): 修复特定UP类型找怪提前退出及滑屏边缘检测问题

1. 修复 search_fail_timer 未启动即触发及与 swipe(interval=3) 时序冲突吞掉滑动指令导致误判滑到底退出的问题;
2. 将单屏找怪观察时间从 3.2s 缩短至 1.0s,并在滑屏后立即调用 is_swipe_unchanged 检测中上部背景(250,140,800,90)像素差,避开顶部跑马灯与右侧浮动鬼火干扰,到底即退;
3. 退出/切换探索场景时清理 swipe_background_right 点击历史记录,避免多轮翻找累计触发 GameTooManyClickError;
4. 修复 search_up_fight 在特定 UP 模式下未匹配到挑战图标时向下穿透到 UpType.ALL 的问题。
Vanity 1 mese fa
parent
commit
af6d1bcb8c
2 ha cambiato i file con 65 aggiunte e 18 eliminazioni
  1. 7 6
      tasks/Exploration/base.py
  2. 58 12
      tasks/Exploration/solo.py

+ 7 - 6
tasks/Exploration/base.py

@@ -58,9 +58,9 @@ 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)
+    def is_swipe_unchanged(self, before_image, after_image, threshold: float = 15) -> bool:
+        # 对比滑屏前后中上部背景区域(避开顶部跑马灯、下方小怪挑战图标及最右侧浮动鬼火),变化很小说明地图已滑到尽头。
+        swipe_check_roi = (250, 140, 800, 90)
         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)))
@@ -329,11 +329,11 @@ class BaseExploration(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, Replace
                     self.I_NORMAL_BATTLE_BUTTON.roi_front = roi_front
                     logger.info(f"Target locked: sword at {roi_front} (aligned with UP icon)")
                     return self.I_NORMAL_BATTLE_BUTTON
-            else:
-                # 没找到 UP 图标,返回 None 让外层逻辑去处理(滑动或退出)
-                return None
+            # 没找到 UP 图标或对应战斗图标,返回 None 让外层逻辑去处理(滑动或退出)
+            return None
 
         # 2. 如果是默认情况 (UpType.ALL),则只要有怪就打
+        self.I_NORMAL_BATTLE_BUTTON.roi_back = (0, 0, 1279, 719)
         if self.appear(self.I_NORMAL_BATTLE_BUTTON):
             return self.I_NORMAL_BATTLE_BUTTON
             
@@ -389,6 +389,7 @@ class BaseExploration(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, Replace
 
     def quit_explore(self):
         logger.info('Quit explore')
+        self.device.click_record_remove(self.S_SWIPE_BACKGROUND_RIGHT.name)
         boss_timer = Timer(15)
         boss_timer.start()
         # click_yellow_button = 0 #用于保证只点一次左上返回按钮,不要直接触发连点回到主界面

+ 58 - 12
tasks/Exploration/solo.py

@@ -62,7 +62,7 @@ class SoloExploration(BaseExploration):
 
     def run_solo(self):
         logger.hr('solo')
-        search_fail_timer = Timer(3.2)  # 这里设置的时间一定要大于S_SWIPE_BACKGROUND_RIGHT滑动的时间
+        search_fail_timer = Timer(1.0)
 
         while 1:
             self.screenshot()
@@ -70,6 +70,9 @@ class SoloExploration(BaseExploration):
             logger.info(f'[run_solo] Current scene: {scene.name}')  # TODO 2026.06.22 之后删掉这个刷屏的
             #
             if scene == Scene.WORLD:
+                search_fail_timer.clear()
+                self._match_end.refresh()
+                self.device.click_record_remove(self.S_SWIPE_BACKGROUND_RIGHT.name)
                 # 打开右边箭头
                 if not self.wait_world_stable():
                     continue
@@ -79,6 +82,9 @@ class SoloExploration(BaseExploration):
                 continue
             #
             elif scene == Scene.ENTRANCE:
+                search_fail_timer.clear()
+                self._match_end.refresh()
+                self.device.click_record_remove(self.S_SWIPE_BACKGROUND_RIGHT.name)
                 if self.check_exit():
                     break
                 self.ui_click(self.I_E_EXPLORATION_CLICK, stop=self.I_E_SETTINGS_BUTTON)
@@ -90,8 +96,12 @@ class SoloExploration(BaseExploration):
                         self.enter_settings_and_do_operations()
                     self.ui_click(self.I_E_AUTO_ROTATE_OFF, stop=self.I_E_AUTO_ROTATE_ON, timeout=5)
                     self.explore_init = True
+                    search_fail_timer.clear()
+                    self._match_end.refresh()
                     continue
                 if self._handle_treasure_box():
+                    search_fail_timer.clear()
+                    self._match_end.refresh()
                     continue
                 if (self.appear_then_click(self.I_UI_CONFIRM, interval=1)
                         or self.appear_then_click(self.I_UI_CONFIRM_SAMLL, interval=1)):
@@ -99,28 +109,39 @@ class SoloExploration(BaseExploration):
                 # 小纸人
                 if self.appear(self.I_BATTLE_REWARD):
                     if self.ui_get_reward(self.I_BATTLE_REWARD):
+                        search_fail_timer.clear()
+                        self._match_end.refresh()
                         continue
                 # boss
                 if self.appear(self.I_BOSS_BATTLE_BUTTON):
+                    search_fail_timer.clear()
+                    self._match_end.refresh()
                     if self.fire(self.I_BOSS_BATTLE_BUTTON):
                         logger.info(f'Boss battle, minions cnt {self.minions_cnt}')
                     continue
                 # 小怪
                 fight_button = self.search_up_fight()
                 if fight_button is not None:
+                    search_fail_timer.clear()
+                    self._match_end.refresh()
                     if self.fire(fight_button):
                         logger.info(f'Fight, minions cnt {self.minions_cnt}')
                     continue
                 # 向后拉,寻找怪
+                if not search_fail_timer.started():
+                    search_fail_timer.start()
+                    continue
                 if search_fail_timer.reached():
-                    search_fail_timer.reset()
-                    if self._match_end.stable(self.device.image, refresh_after_stable=True):
+                    before_image = self.device.image
+                    self.swipe(self.S_SWIPE_BACKGROUND_RIGHT)
+                    sleep(0.3)
+                    self.screenshot()
+                    if self.is_swipe_unchanged(before_image, self.device.image):
+                        search_fail_timer.clear()
                         self.quit_explore()
                         continue
-                    self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3)
+                    search_fail_timer.reset()
                     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)
@@ -129,7 +150,7 @@ class SoloExploration(BaseExploration):
 
     def run_leader(self):
         logger.hr('leader')
-        search_fail_timer = Timer(3.2)  # 这里设置的时间一定要大于S_SWIPE_BACKGROUND_RIGHT滑动的时间
+        search_fail_timer = Timer(1.0)
         friend_leave_timer = Timer(self.FRIEND_LEAVE_TIMEOUT)
 
         while 1:
@@ -137,6 +158,9 @@ class SoloExploration(BaseExploration):
             scene = self.get_current_scene()
             # 探索大世界
             if scene == Scene.WORLD:
+                search_fail_timer.clear()
+                self._match_end.refresh()
+                self.device.click_record_remove(self.S_SWIPE_BACKGROUND_RIGHT.name)
                 # 打开右边箭头
                 if not self.wait_world_stable():
                     continue
@@ -155,6 +179,9 @@ class SoloExploration(BaseExploration):
 
             # 邀请好友, 非常有可能是后面邀请好友,然后直接跳到组队了
             elif scene == Scene.ENTRANCE:
+                search_fail_timer.clear()
+                self._match_end.refresh()
+                self.device.click_record_remove(self.S_SWIPE_BACKGROUND_RIGHT.name)
                 while 1:
                     self.screenshot()
                     if self.is_in_room():
@@ -170,6 +197,8 @@ class SoloExploration(BaseExploration):
                         continue
             #
             elif scene == Scene.TEAM:
+                search_fail_timer.clear()
+                self._match_end.refresh()
                 self.wait_until_stable(self.I_ADD_2, timer=Timer(0.8, 1))
                 if self.appear(self.I_FIRE, threshold=0.8) and not self.appear(self.I_ADD_2):
                     self.ui_click_until_disappear(self.I_FIRE, interval=1)
@@ -196,37 +225,54 @@ class SoloExploration(BaseExploration):
                         self.enter_settings_and_do_operations()
                     self.ui_click(self.I_E_AUTO_ROTATE_OFF, stop=self.I_E_AUTO_ROTATE_ON)
                     self.explore_init = True
+                    search_fail_timer.clear()
+                    self._match_end.refresh()
                     continue
                 if self._handle_treasure_box():
+                    search_fail_timer.clear()
+                    self._match_end.refresh()
                     continue
                 # 小纸人
                 if self.appear(self.I_BATTLE_REWARD):
                     if self.ui_get_reward(self.I_BATTLE_REWARD):
+                        search_fail_timer.clear()
+                        self._match_end.refresh()
                         continue
                 # 中途有人跑路
                 if self._check_mate_leave(friend_leave_timer):
+                    search_fail_timer.clear()
+                    self._match_end.refresh()
                     continue
                 # boss
                 if self.appear(self.I_BOSS_BATTLE_BUTTON):
+                    search_fail_timer.clear()
+                    self._match_end.refresh()
                     if self.fire(self.I_BOSS_BATTLE_BUTTON):
                         logger.info(f'Boss battle, minions cnt {self.minions_cnt}')
                     continue
                 # 小怪
                 fight_button = self.search_up_fight()
                 if fight_button is not None:
+                    search_fail_timer.clear()
+                    self._match_end.refresh()
                     if self.fire(fight_button):
                         logger.info(f'Fight, minions cnt {self.minions_cnt}')
                     continue
                 # 向后拉,寻找怪
+                if not search_fail_timer.started():
+                    search_fail_timer.start()
+                    continue
                 if search_fail_timer.reached():
-                    search_fail_timer.reset()
-                    if self._match_end.stable(self.device.image, refresh_after_stable=True):
+                    before_image = self.device.image
+                    self.swipe(self.S_SWIPE_BACKGROUND_RIGHT)
+                    sleep(0.3)
+                    self.screenshot()
+                    if self.is_swipe_unchanged(before_image, self.device.image):
+                        search_fail_timer.clear()
                         self.quit_explore()
                         continue
-                    self.swipe(self.S_SWIPE_BACKGROUND_RIGHT, interval=3)
+                    search_fail_timer.reset()
                     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)