فهرست منبع

Merge pull request #1412 from BluettDream/dev_generalbattle

fix(GeneralBattle)
huangrunheng 9 ماه پیش
والد
کامیت
12085a3994

+ 10 - 6
tasks/Component/GeneralBattle/assets.py

@@ -49,17 +49,17 @@ class GeneralBattleAssets:
 	# 预设组7 
 	C_PRESET_GROUP_7 = RuleClick(roi_front=(35,615,25,50), roi_back=(35,615,25,50), name="preset_group_7")
 	# 从左开始第一个绿标 
-	C_GREEN_LEFT_1 = RuleClick(roi_front=(128,433,90,150), roi_back=(128,433,90,150), name="green_left_1")
+	C_GREEN_LEFT_1 = RuleClick(roi_front=(183,506,125,108), roi_back=(183,506,125,108), name="green_left_1")
 	# 从左开始第二个绿标 
-	C_GREEN_LEFT_2 = RuleClick(roi_front=(371,385,81,145), roi_back=(371,385,81,145), name="green_left_2")
+	C_GREEN_LEFT_2 = RuleClick(roi_front=(407,474,100,100), roi_back=(407,474,100,100), name="green_left_2")
 	# 从左开始第三个绿标 
-	C_GREEN_LEFT_3 = RuleClick(roi_front=(586,328,100,76), roi_back=(586,328,100,76), name="green_left_3")
+	C_GREEN_LEFT_3 = RuleClick(roi_front=(608,446,64,44), roi_back=(608,446,64,44), name="green_left_3")
 	# 从左开始第四个绿标 
-	C_GREEN_LEFT_4 = RuleClick(roi_front=(817,379,77,133), roi_back=(817,379,77,133), name="green_left_4")
+	C_GREEN_LEFT_4 = RuleClick(roi_front=(769,475,81,98), roi_back=(769,475,81,98), name="green_left_4")
 	# 从左开始第五个绿标 
-	C_GREEN_LEFT_5 = RuleClick(roi_front=(1059,416,85,145), roi_back=(1059,416,85,145), name="green_left_5")
+	C_GREEN_LEFT_5 = RuleClick(roi_front=(932,473,132,108), roi_back=(932,473,132,108), name="green_left_5")
 	# 绿标阴阳师 
-	C_GREEN_MAIN = RuleClick(roi_front=(590,454,88,178), roi_back=(590,454,88,178), name="green_main")
+	C_GREEN_MAIN = RuleClick(roi_front=(565,555,104,81), roi_back=(565,555,104,81), name="green_main")
 	# 绿标点击 区域,默认为全屏,需要在代码中更新其区域 
 	C_GREEN_MARK_AREA = RuleClick(roi_front=(0,0,1280,720), roi_back=(0,0,1280,720), name="green_mark_area")
 	# 战斗的时候有一定的概率随机点击 
@@ -142,6 +142,10 @@ class GeneralBattleAssets:
 	I_GREED_GHOST = RuleImage(roi_front=(56,40,45,45), roi_back=(56,40,45,45), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_greed_ghost.png")
 	# 确认按钮 
 	I_CONFIRM = RuleImage(roi_front=(732,383,83,43), roi_back=(330,228,615,286), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_confirm.png")
+	# 关闭御魂不一致提示弹窗 
+	I_CONFIRM_CLOSE_DIFF_SOUL = RuleImage(roi_front=(571,404,135,54), roi_back=(517,374,226,112), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_confirm_close_diff_soul.png")
+	# 禁用御魂不一致提示7天 
+	I_DISABLE_7DAYS_DIFF_SOUL = RuleImage(roi_front=(547,342,27,36), roi_back=(524,325,70,71), threshold=0.8, method="Template matching", file="./tasks/Component/GeneralBattle/gb/gb_disable_7days_diff_soul.png")
 
 
 	# Ocr Rule Assets

+ 12 - 12
tasks/Component/GeneralBattle/gb/click.json

@@ -67,38 +67,38 @@
   },
   {
     "itemName": "green_left_1",
-    "roiFront": "128,433,90,150",
-    "roiBack": "128,433,90,150",
+    "roiFront": "183,506,125,108",
+    "roiBack": "183,506,125,108",
     "description": "从左开始第一个绿标"
   },
   {
     "itemName": "green_left_2",
-    "roiFront": "371,385,81,145",
-    "roiBack": "371,385,81,145",
+    "roiFront": "407,474,100,100",
+    "roiBack": "407,474,100,100",
     "description": "从左开始第二个绿标"
   },
   {
     "itemName": "green_left_3",
-    "roiFront": "586,328,100,76",
-    "roiBack": "586,328,100,76",
+    "roiFront": "608,446,64,44",
+    "roiBack": "608,446,64,44",
     "description": "从左开始第三个绿标"
   },
   {
     "itemName": "green_left_4",
-    "roiFront": "817,379,77,133",
-    "roiBack": "817,379,77,133",
+    "roiFront": "769,475,81,98",
+    "roiBack": "769,475,81,98",
     "description": "从左开始第四个绿标"
   },
   {
     "itemName": "green_left_5",
-    "roiFront": "1059,416,85,145",
-    "roiBack": "1059,416,85,145",
+    "roiFront": "932,473,132,108",
+    "roiBack": "932,473,132,108",
     "description": "从左开始第五个绿标"
   },
   {
     "itemName": "green_main",
-    "roiFront": "590,454,88,178",
-    "roiBack": "590,454,88,178",
+    "roiFront": "565,555,104,81",
+    "roiBack": "565,555,104,81",
     "description": "绿标阴阳师"
   },
   {

BIN
tasks/Component/GeneralBattle/gb/gb_confirm_close_diff_soul.png


BIN
tasks/Component/GeneralBattle/gb/gb_disable_7days_diff_soul.png


+ 18 - 0
tasks/Component/GeneralBattle/gb/img_supplement.json

@@ -16,5 +16,23 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "确认按钮"
+  },
+  {
+    "itemName": "confirm_close_diff_soul",
+    "imageName": "gb_confirm_close_diff_soul.png",
+    "roiFront": "571,404,135,54",
+    "roiBack": "517,374,226,112",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "关闭御魂不一致提示弹窗"
+  },
+  {
+    "itemName": "disable_7days_diff_soul",
+    "imageName": "gb_disable_7days_diff_soul.png",
+    "roiFront": "547,342,27,36",
+    "roiBack": "524,325,70,71",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "禁用御魂不一致提示7天"
   }
 ]

+ 26 - 32
tasks/Component/GeneralBattle/general_battle.py

@@ -48,40 +48,34 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
         else:
             return False
 
-    def battle_before(self, buff, config):
+    def battle_before(self, buff: BuffClass | list[BuffClass], config: GeneralBattleConfig, timeout: float = 5) -> bool:
+        """战斗前设置
+        :return: True:进入战斗或点击了准备按钮且识别不到准备按钮了 False:超过timeout s还没有进入战斗且没有点击过准备
         """
-        战斗前设置
-        """
-        # 用于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)
+        timeout_timer = Timer(timeout).start()
         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)
+        while not timeout_timer.reached():
+            self.screenshot()
+            if self.is_in_real_battle(False):  # 战斗阶段
+                return True
+            if self.appear_then_click(self.I_DISABLE_7DAYS_DIFF_SOUL, interval=0.6):  # 关闭御魂不一致提示
+                continue
+            if self.appear_then_click(self.I_CONFIRM_CLOSE_DIFF_SOUL, interval=0.6):  # 确认关闭御魂不一致提示
+                continue
+            if self.is_in_prepare(False):  # 战斗准备阶段
+                if not getattr(config, 'lock_team_enable', False):  # 没有锁定阵容
+                    if self.current_count == 1 and not confed:  # 第一次战斗且是本次第一次配置
+                        self.switch_preset_team(config.preset_enable, config.preset_group, config.preset_team)
+                        self.check_and_open_buff(buff)
+                        confed = True
+                # 点击准备(锁定阵容自动点准备,不锁定阵容前面也已经配置完毕需要点准备)
+                if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=0.8):
+                    continue
+                continue
+            # 未知界面, 既不是准备界面也不是战斗界面
+            logger.info('Wait for preparation page')
+            sleep(random.uniform(0.4, 0.8))
+        return False
 
     def run_general_battle_back(self, config: GeneralBattleConfig = None, exit_four: bool = False) -> bool:
         """