Procházet zdrojové kódy

feat: Optimized the preparation page wait logic

Azure před 1 rokem
rodič
revize
ab8f8780aa
1 změnil soubory, kde provedl 9 přidání a 6 odebrání
  1. 9 6
      tasks/Component/GeneralBattle/general_battle.py

+ 9 - 6
tasks/Component/GeneralBattle/general_battle.py

@@ -6,6 +6,7 @@ import random
 from time import sleep
 from time import sleep
 
 
 import cv2
 import cv2
+from module.base.timer import Timer
 
 
 from module.base.utils import get_color, color_similar
 from module.base.utils import get_color, color_similar
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
@@ -53,14 +54,14 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
         """
         """
         # 用来判断是否已经做了相关配置
         # 用来判断是否已经做了相关配置
         conf = False
         conf = False
-        # 用于ui加载,防止还在加载过程中导致准备界面或战斗界面识别失败
-        while not self.is_in_battle():
-            logger.info('Wait to be in battle')
+        # 用于ui加载,防止还在加载过程中导致准备界面识别失败,最多等待2秒
+        wait_in_prepare_timer = Timer(2).start()
+        while not self.is_in_prepare() and not wait_in_prepare_timer.reached():
+            logger.info('Wait to enter the preparation page')
             time.sleep(0.2)
             time.sleep(0.2)
-        # 如果不在准备界面,那也没有战前了,想设置也设置不了,只能直接开始战斗
+        # 如果不在准备界面,想设置也设置不了,只能直接开始战斗
+        # 在准备界面则执行下列设置
         while self.is_in_prepare():
         while self.is_in_prepare():
-            # 照顾一下某些模拟器慢的
-            time.sleep(0.1)
             # 在准备界面,且没有配置过,则进行相关配置
             # 在准备界面,且没有配置过,则进行相关配置
             if not config.lock_team_enable and not conf:
             if not config.lock_team_enable and not conf:
                 logger.info("Lock team is not enable")
                 logger.info("Lock team is not enable")
@@ -74,6 +75,8 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
             # 已经配置完了,不管有没有锁定队伍,出现了准备都要点击
             # 已经配置完了,不管有没有锁定队伍,出现了准备都要点击
             if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
             if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
                 logger.info("Click prepare ensure button")
                 logger.info("Click prepare ensure button")
+            # 照顾一下某些模拟器慢的
+            time.sleep(0.1)
 
 
     def run_general_battle_back(self, config: GeneralBattleConfig = None, exit_four: bool = False) -> bool:
     def run_general_battle_back(self, config: GeneralBattleConfig = None, exit_four: bool = False) -> bool:
         """
         """