Browse Source

refactor(Dokan): 优化道馆内自动换御魂逻辑

- 新增道馆内式神录的识别图像和相关配置
- 修改自动换御魂的执行时机和流程
- 优化道馆场景下的状态处理和操作逻辑
- 调整任务调度时间设置逻辑
ChengRanORZ 1 năm trước cách đây
mục cha
commit
ba69c80ab3

+ 2 - 0
tasks/Dokan/assets.py

@@ -42,6 +42,8 @@ class DokanAssets:
 	I_RYOU_DOKAN_ACTIVATED = RuleImage(roi_front=(0,150,200,400), roi_back=(0,150,200,400), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_activated.png")
 	I_RYOU_DOKAN_ACTIVATED = RuleImage(roi_front=(0,150,200,400), roi_back=(0,150,200,400), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_activated.png")
 	# 是否已经成功进入道馆,上面中间的“道馆突破”文字 
 	# 是否已经成功进入道馆,上面中间的“道馆突破”文字 
 	I_RYOU_DOKAN_CHECK = RuleImage(roi_front=(567,15,144,42), roi_back=(567,15,144,42), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_check.png")
 	I_RYOU_DOKAN_CHECK = RuleImage(roi_front=(567,15,144,42), roi_back=(567,15,144,42), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_check.png")
+	# 道馆内式神录 
+	I_RYOU_DOKAN_SHIKIGAMI = RuleImage(roi_front=(960,580,140,120), roi_back=(960,580,140,120), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_shikigami.png")
 	# 优先攻击选项 
 	# 优先攻击选项 
 	I_RYOU_DOKAN_ATTACK_PRIORITY = RuleImage(roi_front=(666,672,58,25), roi_back=(666,672,58,25), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_priority.png")
 	I_RYOU_DOKAN_ATTACK_PRIORITY = RuleImage(roi_front=(666,672,58,25), roi_back=(666,672,58,25), threshold=0.8, method="Template matching", file="./tasks/Dokan/res/res_ryou_dokan_priority.png")
 	# 优先攻击: 见习 
 	# 优先攻击: 见习 

+ 11 - 1
tasks/Dokan/res/image.json

@@ -35,6 +35,15 @@
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "是否已经成功进入道馆,上面中间的“道馆突破”文字"
     "description": "是否已经成功进入道馆,上面中间的“道馆突破”文字"
   },
   },
+  {
+    "itemName": "ryou_dokan_shikigami",
+    "imageName": "res_ryou_dokan_shikigami.png",
+    "roiFront": "960,580,140,120",
+    "roiBack": "960,580,140,120",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "道馆内式神录"
+  },
   {
   {
     "itemName": "ryou_dokan_attack_priority",
     "itemName": "ryou_dokan_attack_priority",
     "imageName": "res_ryou_dokan_priority.png",
     "imageName": "res_ryou_dokan_priority.png",
@@ -403,7 +412,8 @@
     "method": "Template matching",
     "method": "Template matching",
     "threshold": 0.9,
     "threshold": 0.9,
     "description": "今日道馆已挑战成功"
     "description": "今日道馆已挑战成功"
-  },{
+  },
+  {
     "itemName": "ryou_dokan_remain_attack_count_zero",
     "itemName": "ryou_dokan_remain_attack_count_zero",
     "imageName": "res_ryou_dokan_remain_attack_count_zero.png",
     "imageName": "res_ryou_dokan_remain_attack_count_zero.png",
     "roiFront": "650,610,110,80",
     "roiFront": "650,610,110,80",

BIN
tasks/Dokan/res/res_ryou_dokan_shikigami.png


+ 34 - 11
tasks/Dokan/script_task.py

@@ -40,6 +40,7 @@ class ScriptTask(ExtendGreenMark, GameUi, SwitchSoul, DokanSceneDetector):
     attack_priority_selected: bool = False
     attack_priority_selected: bool = False
     team_switched: bool = False
     team_switched: bool = False
     green_mark_done: bool = False
     green_mark_done: bool = False
+    switch_soul_done: bool = False
 
 
     @cached_property
     @cached_property
     def _attack_priorities(self) -> list:
     def _attack_priorities(self) -> list:
@@ -66,15 +67,15 @@ class ScriptTask(ExtendGreenMark, GameUi, SwitchSoul, DokanSceneDetector):
                 self.next_run(True)
                 self.next_run(True)
                 return
                 return
 
 
-        # 自动换御魂
-        if cfg.switch_soul_config.enable:
-            self.ui_get_current_page()
-            self.ui_goto(page_shikigami_records)
-            self.run_switch_soul(cfg.switch_soul_config.switch_group_team)
-        if cfg.switch_soul_config.enable_switch_by_name:
-            self.ui_get_current_page()
-            self.ui_goto(page_shikigami_records)
-            self.run_switch_soul_by_name(cfg.switch_soul_config.group_name, cfg.switch_soul_config.team_name)
+        # # 自动换御魂
+        # if cfg.switch_soul_config.enable:
+        #     self.ui_get_current_page()
+        #     self.ui_goto(page_shikigami_records)
+        #     self.run_switch_soul(cfg.switch_soul_config.switch_group_team)
+        # if cfg.switch_soul_config.enable_switch_by_name:
+        #     self.ui_get_current_page()
+        #     self.ui_goto(page_shikigami_records)
+        #     self.run_switch_soul_by_name(cfg.switch_soul_config.group_name, cfg.switch_soul_config.team_name)
 
 
         # 初始化相关动态参数,从配置文件读取相关记录,如果没有当天的记录则设置为默认值
         # 初始化相关动态参数,从配置文件读取相关记录,如果没有当天的记录则设置为默认值
         cfg.attack_count_config.init_attack_count(callback=self.config.save)
         cfg.attack_count_config.init_attack_count(callback=self.config.save)
@@ -146,6 +147,8 @@ class ScriptTask(ExtendGreenMark, GameUi, SwitchSoul, DokanSceneDetector):
                     self.dokan_choose_attack_priority(attack_priority=attack_priority)
                     self.dokan_choose_attack_priority(attack_priority=attack_priority)
                     self.attack_priority_selected = True
                     self.attack_priority_selected = True
                     continue
                     continue
+                self.switch_soul_in_dokan()
+
                 self.device.click_record_clear()
                 self.device.click_record_clear()
                 self.device.stuck_record_clear()
                 self.device.stuck_record_clear()
                 sleep(2)
                 sleep(2)
@@ -153,6 +156,8 @@ class ScriptTask(ExtendGreenMark, GameUi, SwitchSoul, DokanSceneDetector):
             # 场景状态:等待馆主战开始
             # 场景状态:等待馆主战开始
             if current_scene == DokanScene.RYOU_DOKAN_SCENE_BOSS_WAITING:
             if current_scene == DokanScene.RYOU_DOKAN_SCENE_BOSS_WAITING:
                 logger.debug(f"Ryou DOKAN boss battle waiting...")
                 logger.debug(f"Ryou DOKAN boss battle waiting...")
+                self.switch_soul_in_dokan()
+
                 self.device.stuck_record_clear()
                 self.device.stuck_record_clear()
                 if cfg.dokan_config.try_start_dokan and cfg.attack_count_config.attack_dokan_master_count() == 0:
                 if cfg.dokan_config.try_start_dokan and cfg.attack_count_config.attack_dokan_master_count() == 0:
                     # 有权限且当前道馆突破 不再打馆主,直接放弃突破
                     # 有权限且当前道馆突破 不再打馆主,直接放弃突破
@@ -235,6 +240,8 @@ class ScriptTask(ExtendGreenMark, GameUi, SwitchSoul, DokanSceneDetector):
                 continue
                 continue
             # 场景状态:如果CD中,开始加油
             # 场景状态:如果CD中,开始加油
             if current_scene == DokanScene.RYOU_DOKAN_SCENE_CD:
             if current_scene == DokanScene.RYOU_DOKAN_SCENE_CD:
+                self.switch_soul_in_dokan()
+
                 self.device.stuck_record_clear()
                 self.device.stuck_record_clear()
                 logger.info(f"Fail CD: start cheering={cfg.dokan_config.dokan_auto_cheering_while_cd}..")
                 logger.info(f"Fail CD: start cheering={cfg.dokan_config.dokan_auto_cheering_while_cd}..")
                 if cfg.dokan_config.dokan_auto_cheering_while_cd:
                 if cfg.dokan_config.dokan_auto_cheering_while_cd:
@@ -829,6 +836,22 @@ class ScriptTask(ExtendGreenMark, GameUi, SwitchSoul, DokanSceneDetector):
             if self.appear(self.I_RYOU_DOKAN_FAILED_VOTE_KEEP_BOUNTY):
             if self.appear(self.I_RYOU_DOKAN_FAILED_VOTE_KEEP_BOUNTY):
                 self.ui_click_until_disappear(self.I_RYOU_DOKAN_FAILED_VOTE_KEEP_BOUNTY)
                 self.ui_click_until_disappear(self.I_RYOU_DOKAN_FAILED_VOTE_KEEP_BOUNTY)
 
 
+    def switch_soul_in_dokan(self):
+        if self.switch_soul_done:
+            return
+        self.ui_click_until_disappear(self.I_RYOU_DOKAN_SHIKIGAMI, interval=2)
+
+        if self.config.dokan.switch_soul_config.enable:
+            self.run_switch_soul(self.config.dokan.switch_soul_config.switch_group_team)
+        if self.config.dokan.switch_soul_config.enable_switch_by_name:
+            self.run_switch_soul_by_name(self.config.dokan.switch_soul_config.group_name,
+                                         self.config.dokan.switch_soul_config.team_name)
+
+        self.switch_soul_done = True
+        # back to dokan
+        from tasks.GameUi.assets import GameUiAssets as gua
+        self.ui_click_until_disappear(gua.I_BACK_Y, interval=2)
+
     def next_run(self, skip_today=False, is_dokan_activated=False):
     def next_run(self, skip_today=False, is_dokan_activated=False):
         """
         """
             设置下次运行时间
             设置下次运行时间
@@ -859,11 +882,11 @@ class ScriptTask(ExtendGreenMark, GameUi, SwitchSoul, DokanSceneDetector):
         # 检测当前时间,如果在服务器时间左右[-1,2]范围内,则认为当前时间可能进行道馆,执行失败逻辑;否则直接设置时间
         # 检测当前时间,如果在服务器时间左右[-1,2]范围内,则认为当前时间可能进行道馆,执行失败逻辑;否则直接设置时间
         now = datetime.now()
         now = datetime.now()
         ser_time: Time = self.config.dokan.scheduler.server_update
         ser_time: Time = self.config.dokan.scheduler.server_update
-        if now.hour >= ser_time.hour - 1:
+        if now.hour < ser_time.hour or (now.hour == ser_time.hour and now.minute < ser_time.minute):
             # 在服务器时间之前,直接设定到服务器时间
             # 在服务器时间之前,直接设定到服务器时间
             self.set_next_run(task="Dokan", server=False,
             self.set_next_run(task="Dokan", server=False,
                               target=now.replace(hour=ser_time.hour, minute=ser_time.minute, second=ser_time.second))
                               target=now.replace(hour=ser_time.hour, minute=ser_time.minute, second=ser_time.second))
-        elif now.hour <= ser_time.hour + 2:
+        elif now.hour >= ser_time.hour + 2:
             # 在服务器时间之后,当作已经打过,设定到明天
             # 在服务器时间之后,当作已经打过,设定到明天
             self.set_next_run(task="Dokan", finish=True, success=True, server=True)
             self.set_next_run(task="Dokan", finish=True, success=True, server=True)
         else:
         else: