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

fix(GeneralBattle): Add timeout guard to preset ensure loop to prevent infinite loop #1667

neptine 4 месяцев назад
Родитель
Сommit
b40b9f6389
1 измененных файлов с 5 добавлено и 1 удалено
  1. 5 1
      tasks/Component/GeneralBattle/general_battle.py

+ 5 - 1
tasks/Component/GeneralBattle/general_battle.py

@@ -398,13 +398,17 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
 
 
         # 点击预设确认
         # 点击预设确认
         self.wait_until_appear(self.I_PRESET_ENSURE, wait_time=1)
         self.wait_until_appear(self.I_PRESET_ENSURE, wait_time=1)
+        click_timer = Timer(10).start()
         while 1:
         while 1:
             self.screenshot()
             self.screenshot()
+            if click_timer.reached():
+                logger.warning("Switch preset failure")
             if not self.appear(self.I_PRESET_ENSURE):
             if not self.appear(self.I_PRESET_ENSURE):
                 break
                 break
-            if self.appear_then_click(self.I_PRESET_ENSURE, threshold=0.8, interval=0.2):
+            if self.appear_then_click(self.I_PRESET_ENSURE, threshold=0.8, interval=1):
                 continue
                 continue
         logger.info("Click preset ensure")
         logger.info("Click preset ensure")
+        return None
 
 
     def random_click_swipt(self):
     def random_click_swipt(self):
         if 0 <= random.randint(0, 500) <= 3:  # 百分之4的概率
         if 0 <= random.randint(0, 500) <= 3:  # 百分之4的概率