Browse Source

fix(BondlingFairyland): Switch mitama separately before search and capture #1715

neptine 3 months ago
parent
commit
fe7f8e1cc9

+ 35 - 1
tasks/BondlingFairyland/script_task.py

@@ -290,6 +290,8 @@ class ScriptTask(GameUi, GeneralInvite, GeneralRoom, BondlingBattle, SwitchSoul,
                     elif bondling_config.bondling_search_enable and bondling_config.user_status == UserStatus.ALONE:
                     elif bondling_config.bondling_search_enable and bondling_config.user_status == UserStatus.ALONE:
                         if self.run_search(bondling_config, limit_cnt=random.randint(5, 20)):
                         if self.run_search(bondling_config, limit_cnt=random.randint(5, 20)):
                             logger.info('Bondling search finish, try to run catch')
                             logger.info('Bondling search finish, try to run catch')
+                            # 切御魂
+                            self._switch_soul_capture()
                             continue
                             continue
                         else:
                         else:
                             break  # 时间到了或次数到了直接退出
                             break  # 时间到了或次数到了直接退出
@@ -368,6 +370,7 @@ class ScriptTask(GameUi, GeneralInvite, GeneralRoom, BondlingBattle, SwitchSoul,
         (4) 打满对应limit_cnt次, (探查界面)返回True
         (4) 打满对应limit_cnt次, (探查界面)返回True
         """
         """
         self.lock_team()
         self.lock_team()
+        self._switch_soul_search()
         while 1:
         while 1:
             # 检查是不是在探查界面,
             # 检查是不是在探查界面,
             if not self.in_search_ui(screenshot=True):
             if not self.in_search_ui(screenshot=True):
@@ -816,6 +819,37 @@ class ScriptTask(GameUi, GeneralInvite, GeneralRoom, BondlingBattle, SwitchSoul,
             type_str, (group, team) = bondling_switch_soul.get_switch_by_name('search_switch')
             type_str, (group, team) = bondling_switch_soul.get_switch_by_name('search_switch')
             do_switch_soul(type_str, group, team)
             do_switch_soul(type_str, group, team)
 
 
+    def _switch_soul_to(self, ts, g, te):
+        def _do_switch_soul(ts: str, g: str | int, te: str | int):
+            if ts is None:
+                raise ValueError(f'Invalid switch soul config on {self.config.bondling_fairyland.bondling_config.bondling_stone_class.value}')
+            if ts == 'int':
+                self.run_switch_soul((g, te))
+            if ts == 'str':
+                self.run_switch_soul_by_name(g, te)
+
+        if ts is None:
+            logger.warning('Switch soul preset not configured, skip')
+            return
+
+        self.goto_shikigami_records(self.I_GOTO_SHIKIGAMI_COMMON)
+        _do_switch_soul(ts, g, te)
+        self.exit_shikigami_records()
+
+
+    def _switch_soul_search(self):
+        logger.info("切换御魂-探查")
+        if not self.config.bondling_fairyland.bondling_switch_soul.enable: return
+        ts, (g, te) = self.config.bondling_fairyland.bondling_switch_soul.get_switch_by_name('search_switch')
+        self._switch_soul_to(ts, g, te)
+
+    def _switch_soul_capture(self):
+        logger.info("切换御魂-捕获")
+        cong = self.config.bondling_fairyland
+        if not cong.bondling_switch_soul.enable: return
+        ts, (g, te) = cong.bondling_switch_soul.get_switch_by_enum(cong.bondling_config.bondling_stone_class)
+        self._switch_soul_to(ts, g, te)
+
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
     from module.config.config import Config
     from module.config.config import Config
@@ -824,7 +858,7 @@ if __name__ == '__main__':
     config = Config('oas1')
     config = Config('oas1')
     device = Device(config)
     device = Device(config)
     t = ScriptTask(config, device)
     t = ScriptTask(config, device)
-    # t.run()
+    t.run()
     t.ui_get_current_page()
     t.ui_get_current_page()
     t.ui_goto(page_bondling_fairyland)
     t.ui_goto(page_bondling_fairyland)
     # image = task.screenshot()
     # image = task.screenshot()

+ 2 - 0
tasks/Component/SwitchSoul/assets.py

@@ -66,6 +66,8 @@ class SwitchSoulAssets:
 	I_SOU_CLICK_PRESENT = RuleImage(roi_front=(978,304,25,26), roi_back=(965,142,48,480), threshold=0.9, method="Template matching", file="./tasks/Component/SwitchSoul/ss/ss_sou_click_present.png")
 	I_SOU_CLICK_PRESENT = RuleImage(roi_front=(978,304,25,26), roi_back=(965,142,48,480), threshold=0.9, method="Template matching", file="./tasks/Component/SwitchSoul/ss/ss_sou_click_present.png")
 	# 误触点到式神检查 
 	# 误触点到式神检查 
 	I_CHECK_BLOCK = RuleImage(roi_front=(572,408,137,49), roi_back=(572,408,137,49), threshold=0.8, method="Template matching", file="./tasks/Component/SwitchSoul/ss/ss_check_block.png")
 	I_CHECK_BLOCK = RuleImage(roi_front=(572,408,137,49), roi_back=(572,408,137,49), threshold=0.8, method="Template matching", file="./tasks/Component/SwitchSoul/ss/ss_check_block.png")
+	# 通用进入式神录 
+	I_GOTO_SHIKIGAMI_COMMON = RuleImage(roi_front=(1037,567,36,36), roi_back=(617,503,487,134), threshold=0.8, method="Template matching", file="./tasks/Component/SwitchSoul/ss/ss_goto_shikigami_common.png")
 
 
 
 
 	# Ocr Rule Assets
 	# Ocr Rule Assets

+ 9 - 0
tasks/Component/SwitchSoul/ss/image.json

@@ -160,5 +160,14 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "误触点到式神检查"
     "description": "误触点到式神检查"
+  },
+  {
+    "itemName": "goto_shikigami_common",
+    "imageName": "ss_goto_shikigami_common.png",
+    "roiFront": "1037,567,36,36",
+    "roiBack": "617,503,487,134",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "通用进入式神录"
   }
   }
 ]
 ]

BIN
tasks/Component/SwitchSoul/ss/ss_goto_shikigami_common.png


+ 30 - 14
tasks/Component/SwitchSoul/switch_soul.py

@@ -8,11 +8,14 @@ from module.atom.click import RuleClick
 from module.atom.long_click import RuleLongClick
 from module.atom.long_click import RuleLongClick
 from module.atom.ocr import RuleOcr
 from module.atom.ocr import RuleOcr
 from module.base.timer import Timer
 from module.base.timer import Timer
+from module.logger import logger
+
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
+from tasks.GameUi.assets import GameUiAssets
 from tasks.Component.GeneralInvite.assets import GeneralInviteAssets
 from tasks.Component.GeneralInvite.assets import GeneralInviteAssets
 from tasks.Component.GeneralInvite.config_invite import InviteConfig, InviteNumber, FindMode
 from tasks.Component.GeneralInvite.config_invite import InviteConfig, InviteNumber, FindMode
 from tasks.Component.SwitchSoul.assets import SwitchSoulAssets
 from tasks.Component.SwitchSoul.assets import SwitchSoulAssets
-from module.logger import logger
+
 
 
 
 
 def switch_parser(switch_str: str) -> tuple:
 def switch_parser(switch_str: str) -> tuple:
@@ -24,6 +27,32 @@ def switch_parser(switch_str: str) -> tuple:
 
 
 class SwitchSoul(BaseTask, SwitchSoulAssets):
 class SwitchSoul(BaseTask, SwitchSoulAssets):
 
 
+    def goto_shikigami_records(self, button):
+        """
+        进入式神录
+        """
+        while 1:
+            self.screenshot()
+            if self.appear(GameUiAssets.I_CHECK_RECORDS):
+                break
+            if self.appear_then_click(button, interval=1.5):
+                continue
+        logger.info('Entry shikigami records')
+
+    def exit_shikigami_records(self) -> None:
+        """
+        退出式神录的界面
+        :return:
+        """
+        while 1:
+            self.screenshot()
+            if not self.appear(self.I_SOU_CHECK_IN):
+                break
+            if self.appear_then_click(self.I_RECORD_SOUL_BACK, interval=3.5):
+                continue
+        logger.info('Exit shikigami records')
+
+
     def run_switch_soul(self, target: tuple | list[tuple] | str):
     def run_switch_soul(self, target: tuple | list[tuple] | str):
         """
         """
         保证在式神录的界面
         保证在式神录的界面
@@ -153,19 +182,6 @@ class SwitchSoul(BaseTask, SwitchSoulAssets):
             team = int(team)
             team = int(team)
             self.switch_soul_one(group, team)
             self.switch_soul_one(group, team)
 
 
-    def exit_shikigami_records(self) -> None:
-        """
-        退出式神录的界面
-        :return:
-        """
-        while 1:
-            self.screenshot()
-            if not self.appear(self.I_SOU_CHECK_IN):
-                break
-            if self.appear_then_click(self.I_RECORD_SOUL_BACK, interval=3.5):
-                continue
-        logger.info('Exit shikigami records')
-
     def run_switch_soul_by_name(self, groupName, teamName):
     def run_switch_soul_by_name(self, groupName, teamName):
         """
         """
         保证在式神录的界面
         保证在式神录的界面