Przeglądaj źródła

fix(Component): Attach ocr to the "prepare" button

ryland 2 lat temu
rodzic
commit
01d0cc0171

+ 5 - 0
tasks/Component/GeneralBattle/assets.py

@@ -120,6 +120,11 @@ 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_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")
 
 
 
 
+	# Ocr Rule Assets
+	# 准备 
+	O_BATTLE_PREPARE = RuleOcr(roi=(1122,546,92,51), area=(1122,546,92,51), mode="Single", method="Default", keyword="准备", name="battle_prepare")
+
+
 	# Swipe Rule Assets
 	# Swipe Rule Assets
 	# description 
 	# description 
 	S_BATTLE_RANDOM_LEFT = RuleSwipe(roi_front=(122,155,480,426), roi_back=(667,147,461,427), mode="default", name="battle_random_left")
 	S_BATTLE_RANDOM_LEFT = RuleSwipe(roi_front=(122,155,480,426), roi_back=(667,147,461,427), mode="default", name="battle_random_left")

+ 11 - 0
tasks/Component/GeneralBattle/gb/ocr.json

@@ -0,0 +1,11 @@
+[
+  {
+    "itemName": "battle_prepare",
+    "roiFront": "1122,546,92,51",
+    "roiBack": "1122,546,92,51",
+    "mode": "Single",
+    "method": "Default",
+    "keyword": "准备",
+    "description": "准备"
+  }
+]

+ 16 - 20
tasks/Component/GeneralBattle/general_battle.py

@@ -10,17 +10,15 @@ from tasks.Component.GeneralBattle.assets import GeneralBattleAssets
 from tasks.Component.GeneralBuff.config_buff import BuffClass
 from tasks.Component.GeneralBuff.config_buff import BuffClass
 from tasks.Component.GeneralBuff.general_buff import GeneralBuff
 from tasks.Component.GeneralBuff.general_buff import GeneralBuff
 
 
-
 from module.logger import logger
 from module.logger import logger
 
 
 
 
-
 class GeneralBattle(GeneralBuff, GeneralBattleAssets):
 class GeneralBattle(GeneralBuff, GeneralBattleAssets):
     """
     """
     使用这个通用的战斗必须要求这个任务的config有config_general_battle
     使用这个通用的战斗必须要求这个任务的config有config_general_battle
     """
     """
 
 
-    def run_general_battle(self, config: GeneralBattleConfig=None, buff: BuffClass or list[BuffClass]=None) -> bool:
+    def run_general_battle(self, config: GeneralBattleConfig = None, buff: BuffClass or list[BuffClass] = None) -> bool:
         """
         """
         运行脚本
         运行脚本
         :return:
         :return:
@@ -32,7 +30,6 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
         if config is None:
         if config is None:
             config = GeneralBattleConfig()
             config = GeneralBattleConfig()
 
 
-
         # 如果没有锁定队伍。那么可以根据配置设定队伍
         # 如果没有锁定队伍。那么可以根据配置设定队伍
         if not config.lock_team_enable:
         if not config.lock_team_enable:
             logger.info("Lock team is not enable")
             logger.info("Lock team is not enable")
@@ -46,11 +43,15 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
             # 点击准备按钮
             # 点击准备按钮
             self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
             self.wait_until_appear(self.I_PREPARE_HIGHLIGHT)
             self.wait_until_appear(self.I_BUFF)
             self.wait_until_appear(self.I_BUFF)
+            occur_prepare_button = False
             while 1:
             while 1:
                 self.screenshot()
                 self.screenshot()
                 if not self.appear(self.I_BUFF):
                 if not self.appear(self.I_BUFF):
                     break
                     break
                 if self.appear_then_click(self.I_PREPARE_HIGHLIGHT, interval=1.5):
                 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
                     continue
             logger.info("Click prepare ensure button")
             logger.info("Click prepare ensure button")
 
 
@@ -68,8 +69,7 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
         else:
         else:
             return False
             return False
 
 
-
-    def run_general_battle_back(self, config: GeneralBattleConfig=None) -> bool:
+    def run_general_battle_back(self, config: GeneralBattleConfig = None) -> bool:
         """
         """
         进入挑战然后直接返回
         进入挑战然后直接返回
         :param config:
         :param config:
@@ -117,8 +117,7 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
 
 
         return True
         return True
 
 
-
-    def exit_battle(self, skip_first: bool=False) -> bool:
+    def exit_battle(self, skip_first: bool = False) -> bool:
         """
         """
         在战斗的时候强制退出战斗
         在战斗的时候强制退出战斗
         :return:
         :return:
@@ -150,7 +149,6 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
 
 
         return True
         return True
 
 
-
     def battle_wait(self, random_click_swipt_enable: bool) -> bool:
     def battle_wait(self, random_click_swipt_enable: bool) -> bool:
         """
         """
         等待战斗结束 !!!
         等待战斗结束 !!!
@@ -221,15 +219,15 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
             self.screenshot()
             self.screenshot()
             # 如果出现领奖励
             # 如果出现领奖励
             action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
             action_click = random.choice([self.C_REWARD_1, self.C_REWARD_2, self.C_REWARD_3])
-            if self.appear_then_click(self.I_REWARD, action=action_click ,interval=1.5) or \
-                    self.appear_then_click(self.I_REWARD_GOLD, action=action_click ,interval=1.5):
+            if self.appear_then_click(self.I_REWARD, action=action_click, interval=1.5) or \
+                    self.appear_then_click(self.I_REWARD_GOLD, action=action_click, interval=1.5):
                 continue
                 continue
             if not self.appear(self.I_REWARD) and not self.appear(self.I_REWARD_GOLD):
             if not self.appear(self.I_REWARD) and not self.appear(self.I_REWARD_GOLD):
                 break
                 break
 
 
         return win
         return win
 
 
-    def green_mark(self, enable: bool=False, mark_mode: GreenMarkType=GreenMarkType.GREEN_MAIN):
+    def green_mark(self, enable: bool = False, mark_mode: GreenMarkType = GreenMarkType.GREEN_MAIN):
         """
         """
         绿标, 如果不使能就直接返回
         绿标, 如果不使能就直接返回
         :param enable:
         :param enable:
@@ -271,7 +269,7 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
             # 点击绿标
             # 点击绿标
             self.device.click(x, y)
             self.device.click(x, y)
 
 
-    def switch_preset_team(self, enable: bool=False, preset_group: int=1, preset_team: int=1):
+    def switch_preset_team(self, enable: bool = False, preset_group: int = 1, preset_team: int = 1):
         """
         """
         切换预设的队伍, 要求是在不锁定队伍时的情况下
         切换预设的队伍, 要求是在不锁定队伍时的情况下
         :param enable:
         :param enable:
@@ -368,9 +366,9 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
         if is_screenshot:
         if is_screenshot:
             self.screenshot()
             self.screenshot()
         if self.appear(self.I_FRIENDS) or \
         if self.appear(self.I_FRIENDS) or \
-                        self.appear(self.I_WIN) or \
-                        self.appear(self.I_FALSE) or \
-                        self.appear(self.I_REWARD):
+                self.appear(self.I_WIN) or \
+                self.appear(self.I_FALSE) or \
+                self.appear(self.I_REWARD):
             return True
             return True
         else:
         else:
             return False
             return False
@@ -443,7 +441,7 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
                 if self.appear_then_click(lock_image, interval=1):
                 if self.appear_then_click(lock_image, interval=1):
                     continue
                     continue
 
 
-    def check_buff(self, buff: BuffClass or list[BuffClass]=None):
+    def check_buff(self, buff: BuffClass or list[BuffClass] = None):
         """
         """
         检测是否开启buff
         检测是否开启buff
         :param buff:
         :param buff:
@@ -485,11 +483,9 @@ class GeneralBattle(GeneralBuff, GeneralBattleAssets):
 if __name__ == '__main__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config
     from module.device.device import Device
     from module.device.device import Device
+
     c = Config('oas1')
     c = Config('oas1')
     d = Device(c)
     d = Device(c)
     t = GeneralBattle(c, d)
     t = GeneralBattle(c, d)
 
 
     t.check_buff([BuffClass.EXP_50, BuffClass.GOLD_50])
     t.check_buff([BuffClass.EXP_50, BuffClass.GOLD_50])
-
-
-