Browse Source

Merge pull request #1131 from runhey/dev

Automated PR 2025.10.09
huangrunheng 1 year ago
parent
commit
babefd2873

+ 1 - 1
module/device/device.py

@@ -29,7 +29,7 @@ class Device(Platform, Screenshot, Control, AppControl):
     click_record = deque(maxlen=15)
     stuck_timer = Timer(60, count=60).start()
     stuck_timer_long = Timer(300, count=300).start()
-    stuck_long_wait_list = ['BATTLE_STATUS_S', 'PAUSE', 'LOGIN_CHECK']
+    stuck_long_wait_list = ['BATTLE_STATUS_S', 'PAUSE', 'LOGIN_CHECK', 'PREPARE_BEFORE_BATTLE']
 
     def __init__(self, *args, **kwargs):
         for trial in range(4):

+ 3 - 3
module/ocr/base_ocr.py

@@ -191,9 +191,9 @@ class BaseCor:
                 continue
             result.ocr_text = self.after_process(result.ocr_text)
             results.append(result)
-            if logDisplay:
-                logger.attr(name='%s %ss' % (self.name, float2str(time.time() - start_time)),
-                            text=str([result.ocr_text for result in results]))
+        if logDisplay:
+            logger.attr(name='%s %ss' % (self.name, float2str(time.time() - start_time)),
+                        text=str([result.ocr_text for result in results]))
         return results
 
     def match(self, result: str, included: bool=False) -> bool:

+ 45 - 49
tasks/Component/GeneralBattle/general_battle.py

@@ -6,6 +6,7 @@ import random
 from time import sleep
 
 import cv2
+from module.base.timer import Timer
 
 from module.base.utils import get_color, color_similar
 from tasks.base_task import BaseTask
@@ -28,52 +29,60 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
         运行脚本
         :return:
         """
-        # 本人选择的策略是只要进来了就算一次,不管是不是打完了
         logger.hr("General battle start", 2)
-        self.current_count += 1
-        logger.info(f"Current count: {self.current_count}")
         if config is None:
             config = GeneralBattleConfig()
-
-        # 如果没有锁定队伍。那么可以根据配置设定队伍
-        if not config.lock_team_enable:
-            logger.info("Lock team is not enable")
-            # 如果更换队伍
-            if self.current_count == 1:
-                self.switch_preset_team(config.preset_enable, config.preset_group, config.preset_team)
-
-            # 打开buff
-            self.check_buff(buff)
-
-            # 点击准备按钮
-            self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
-            self.wait_until_appear(self.I_BUFF)
-            occur_prepare_button = False
-            while 1:
-                self.screenshot()
-                if not self.appear(self.I_BUFF):
-                    break
-                if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
-                    occur_prepare_button = True
-                    continue
-                # if occur_prepare_button and self.ocr_appear_click(self.O_BATTLE_PREPARE, interval=2):
-                #     continue
-            logger.info("Click prepare ensure button")
-
-            # 照顾一下某些模拟器慢的
-            time.sleep(0.1)
-
+        # 本人选择的策略是只要进来了就算一次,不管是不是打完了
+        # 战斗统计
+        self.current_count += 1
+        logger.info(f"Current count: {self.current_count}")
+        # 战前设置
+        self.battle_before(buff, config)
         # 绿标
-        self.wait_until_disappear(self.I_BUFF)
         if self.is_in_battle(False):
             self.green_mark(config.green_enable, config.green_mark)
-
+        # 战中设置
         win = self.battle_wait(config.random_click_swipt_enable)
         if win:
             return True
         else:
             return False
 
+    def battle_before(self, buff, config):
+        """
+        战斗前设置
+        """
+        # 用于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.5)
+        confed = False
+        need_battle_timer = Timer(2)
+        # 如果不在准备界面,想设置也设置不了,只能直接开始战斗
+        while self.is_in_prepare():
+            # 配置了锁定阵容则启动超时器
+            if config.lock_team_enable and not need_battle_timer.started():
+                need_battle_timer.start()
+            # 在准备界面,且没有锁定阵容,则进行相关配置
+            if not config.lock_team_enable and not confed:
+                logger.info("Lock team is not enable")
+                # 第一次进则切换预设
+                if self.current_count == 1:
+                    self.switch_preset_team(config.preset_enable, config.preset_group, config.preset_team)
+                # 判断是否开启buff并开启
+                self.check_and_open_buff(buff)
+                # 配置过了不再配置
+                confed = True
+            # 如果锁定了阵容且超过2秒还在准备界面,则点击准备
+            if config.lock_team_enable and need_battle_timer.reached():
+                self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5)
+            # 没有锁定阵容且配置完成则直接点击准备
+            if not config.lock_team_enable and confed:
+                self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5)
+            # 照顾一下某些模拟器慢的
+            time.sleep(0.2)
+
     def run_general_battle_back(self, config: GeneralBattleConfig = None, exit_four: bool = False) -> bool:
         """
         进入挑战然后直接返回
@@ -454,20 +463,7 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
         if not self.is_in_battle():
             return None
 
-        if self.is_in_prepare(False):
-            while 1:
-                self.screenshot()
-                if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
-                    continue
-                if not self.appear(self.I_BUFF):
-                    break
-
-            # 被接管的战斗,只有准备阶段才可以点绿标。
-            # 因为如果是战斗中,无法保证点击的时候是否出现动画
-            self.wait_until_disappear(self.I_BUFF)
-            self.green_mark(config.green_enable, config.green_mark)
-
-        return self.battle_wait(config.random_click_swipt_enable)
+        return self.run_general_battle(config=config)
 
     def check_lock(self, enable: bool, lock_image, unlock_image):
         """
@@ -494,7 +490,7 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
                 if self.appear_then_click(lock_image, interval=1):
                     continue
 
-    def check_buff(self, buff: BuffClass or list[BuffClass] = None):
+    def check_and_open_buff(self, buff: BuffClass or list[BuffClass] = None):
         """
         检测是否开启buff
         :param buff:

BIN
tasks/Component/GeneralInvite/gi/gi_i_accept_jy.png


+ 3 - 1
tasks/FrogBoss/script_task.py

@@ -256,7 +256,9 @@ class ScriptTask(RightActivity, FrogBossAssets, GeneralBattleAssets):
             {"name": "Mico林木森", "id": "b6b5bc8277e34f69aeca018db0081397"},
             {"name": "查查尔", "id": "d9dc2a75497c4a91b2db1e909a36544d"},
             {"name": "CC南浔", "id": "74db771d92a54c28ae3e98d19aa565a3"},
-            {"name": "冰七喜Den", "id": "e498e524252041e29999b38e57c4df1d"}
+            {"name": "冰七喜Den", "id": "e498e524252041e29999b38e57c4df1d"},
+            {"name": "行水姑娘", "id": "30b0c2923faa483f95572c324a5bc910"},
+            {"name": "更慕林", "id": "e32aedbdd8da46a5b5b497a16c4b7658"}
             # ... 可以添加更多 uid
         ]
 

+ 2 - 0
tasks/RyouToppa/script_task.py

@@ -159,6 +159,8 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, RyouToppaAssets):
         area_index = 0
         success = True
         while 1:
+            # 设置长任务标志,用来寻找寮突可进攻的目标
+            self.device.stuck_record_add('PREPARE_BEFORE_BATTLE')
             if not self.has_ticket():
                 logger.info("We have no chance to attack. Try again after 1 hour.")
                 success = False