Просмотр исходного кода

Merge pull request #1872 from LGG686/dev-f

调整真蛇计数逻辑
huangrunheng 1 месяц назад
Родитель
Сommit
17e7a3d355

+ 11 - 11
tasks/DemonEncounter/script_task.py

@@ -9,13 +9,13 @@ from cached_property import cached_property
 from datetime import datetime, timedelta
 
 from module.logger import logger
-from module.exception import TaskEnd
+from module.exception import GameStuckError, TaskEnd
 from module.base.timer import Timer
 
 from tasks.Component.SwitchSoul.switch_soul import SwitchSoul
 from tasks.DemonEncounter.config import BossType, DemonEncounter, convert_to_general_battle_config
 from tasks.GameUi.game_ui import GameUi
-from tasks.GameUi.page import page_demon_encounter, page_demon_encounter_realworld, page_shikigami_records
+from tasks.GameUi.page import page_town, page_demon_encounter_realworld, page_shikigami_records
 from tasks.DemonEncounter.assets import DemonEncounterAssets
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.Component.GeneralBattle.config_general_battle import GeneralBattleConfig
@@ -108,8 +108,8 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets, SwitchSoul):
                     self.appear_then_click(self.I_DE_LOCATION, interval=2)
                     time.sleep(1)
 
-                # 最多重新执行两轮“逢魔/极逢魔 -> 地图中央首领”的完整流程。
-                for search_attempt in range(1, 3):
+                # 最多重新执行三轮“逢魔/极逢魔 -> 地图中央首领”的完整流程。
+                for search_attempt in range(1, 4):
                     self.device.click_record_clear()
                     self.screenshot()
                     if self.appear(self.I_BOSS_FIRE) or self.appear(self.I_BEST_BOSS_FIRE):
@@ -121,14 +121,14 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets, SwitchSoul):
                     if not self.appear_then_click(search_button, interval=2):
                         raise GameStuckError(f'Cannot find {boss_name} search button')
                     logger.info(
-                        f'Finding {boss_name}, attempt {search_attempt}/2 '
+                        f'Finding {boss_name}, attempt {search_attempt}/3 '
                         f'(re-enter round {reenter_round}/3)...'
                     )
                     time.sleep(1)
 
-                    # 每轮点击地图中央框选的红色“集结”区域至多两次,
+                    # 每轮点击地图中央框选的红色“集结”区域至多三次,
                     # 每次等待集结挑战标志5秒。
-                    for center_attempt in range(1, 3):
+                    for center_attempt in range(1, 4):
                         self.click(self.C_DM_BOSS_CLICK, interval=2)
                         deadline = time.monotonic() + 5
                         while time.monotonic() < deadline:
@@ -136,13 +136,13 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets, SwitchSoul):
                             if self.appear(self.I_BOSS_FIRE) or self.appear(self.I_BEST_BOSS_FIRE):
                                 logger.info(
                                     f'{boss_name} gather appeared after center click '
-                                    f'{center_attempt}/2'
+                                    f'{center_attempt}/3'
                                 )
                                 return True
                             time.sleep(0.2)
                         logger.warning(
                             f'{boss_name} gather did not appear after center click '
-                            f'{center_attempt}/2'
+                            f'{center_attempt}/3'
                         )
 
                     # 本轮失败,返回逢魔地图,重新点击逢魔/极逢魔进行下一轮搜寻。
@@ -156,9 +156,9 @@ class ScriptTask(GameUi, GeneralBattle, DemonEncounterAssets, SwitchSoul):
                                 break
                             time.sleep(0.2)
 
-                # 2次搜索都没找到: 重进地图清状态, 最多3轮
+                # 3次搜索都没找到: 重进地图清状态, 最多3轮
                 logger.info(f'Boss not found, re-enter demon encounter map (round {reenter_round}/3)')
-                self.goto_page(page_demon_encounter)
+                self.goto_page(page_town)
                 self.goto_page(page_demon_encounter_realworld)
 
             raise GameStuckError(

+ 8 - 0
tasks/Exploration/assets.py

@@ -68,6 +68,10 @@ class ExplorationAssets:
 	C_CLICK_ROTATE_4 = RuleClick(roi_front=(921,590,21,21), roi_back=(921,590,21,21), name="click_rotate_4")
 	# 随机点 
 	C_SAFE_RANDOM = RuleClick(roi_front=(0,0,111,12), roi_back=(0,0,111,12), name="safe_random")
+	# 探索大地图 · 主线 tab 标题("章"字锚点)点击区域 
+	C_CLICK_MAIN_TITLE = RuleClick(roi_front=(1070,174,77,28), roi_back=(1070,174,77,28), name="click_main_title")
+	# 探索大地图 · 玩法 tab 标题("御魂"标题锚点)点击区域 
+	C_CLICK_PALY_TITLE = RuleClick(roi_front=(1178,172,77,28), roi_back=(1178,172,77,28), name="click_paly_title")
 
 
 	# Image Rule Assets
@@ -127,6 +131,10 @@ class ExplorationAssets:
 	I_EXP_ARROW_LEFT = RuleImage(roi_front=(1244,115,18,26), roi_back=(1178,78,100,100), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_exp_arrow_left.png")
 	# 战斗中的队友标识 
 	I_TEAM_EMOJI_FIGHT = RuleImage(roi_front=(38,405,37,37), roi_back=(18,386,74,75), threshold=0.8, method="Template matching", file="./tasks/Exploration/res/res_team_emoji_fight.png")
+	# 探索大地图 · 主线 tab 标题锚点("章"字,仅主线 tab 命中,玩法 tab 不命中) 
+	I_CHECK_MAIN_TITLE = RuleImage(roi_front=(1150,457,32,32), roi_back=(1069,222,113,336), threshold=0.85, method="Template matching", file="./tasks/Exploration/res/res_check_main_title.png")
+	# 探索大地图 · 玩法 tab 标题锚点("御魂"标题,仅玩法 tab 命中,主线 tab 不命中) 
+	I_CHECK_PLAY_TITLE = RuleImage(roi_front=(1073,214,40,32), roi_back=(1065,210,190,316), threshold=0.85, method="Template matching", file="./tasks/Exploration/res/res_check_play_title.png")
 
 
 	# Long Click Rule Assets

+ 10 - 3
tasks/Exploration/base.py

@@ -16,7 +16,8 @@ from tasks.Exploration.assets import ExplorationAssets
 from tasks.Exploration.config import ChooseRarity, AutoRotate, AttackNumber, UpType
 from tasks.Component.GeneralBattle.general_battle import GeneralBattle
 from tasks.GameUi.game_ui import GameUi
-from tasks.GameUi.page import page_exploration, page_shikigami_records, page_main
+from tasks.GameUi.page import page_shikigami_records, page_main
+import tasks.Exploration.page as pages
 from tasks.RealmRaid.script_task import ScriptTask as RealmRaidScriptTask
 from tasks.Utils.config_enum import ShikigamiClass
 
@@ -112,8 +113,9 @@ class BaseExploration(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, Replace
                 self.exp_100()
             self.close_buff()
 
-        # 探索页面
-        self.goto_page(page_exploration)
+        # 探索页面(大地图始终处于主线/玩法 tab 之一,裸 page_exploration 永远被 prio 60 的 tab 页遮蔽、
+        # 无法作为当前页抵达,故直接进入主线 tab)
+        self.goto_page(pages.page_mainline)
 
     def post_process(self):
         self.wait_until_stable(self.I_UI_BACK_RED)
@@ -133,6 +135,11 @@ class BaseExploration(GameUi, GeneralBattle, GeneralRoom, GeneralInvite, Replace
 
     # 打开指定的章节:
     def open_expect_level(self):
+        # 选关依赖主线 tab 右侧的章节列表(I_E_EXPLORATION_CLICK + 章节名 OCR)。
+        # 探索大地图常驻「主线/玩法」之一,若停在玩法 tab 不选回主线,右边会是御魂/今日掉落等模块名,
+        # I_E_EXPLORATION_CLICK 不出现、OCR 交集为空 → 一直滑屏卡死。故进选关前无条件确保主线 tab。
+        self.goto_page(pages.page_mainline)
+
         swipeCount = 0
         while 1:
             # 探索的 config

+ 44 - 0
tasks/Exploration/page.py

@@ -0,0 +1,44 @@
+from tasks.Exploration.assets import ExplorationAssets
+from tasks.GameUi.assets import GameUiAssets
+from tasks.GameUi.page import all_of, page_exploration
+from tasks.GameUi.page_definition import Page
+
+
+def inherit_transitions(source: Page, *targets: Page) -> None:
+    """把 source 的全部出边复制给 targets(tab 页继承大地图出口,动作与 tab 状态无关)。
+
+    跳过目标页自身(自环防护),若目标页已有到同一目的地的边则不重复添加。
+    """
+    for target in targets:
+        for transition in source.transitions:
+            if transition.destination == target:
+                continue
+            if any(item.destination == transition.destination for item in target.transitions):
+                continue
+            target.connect(
+                transition.destination,
+                transition.action,
+                cost=transition.cost,
+                on_enter_success=transition.on_enter_success,
+                on_enter_failure=transition.on_enter_failure,
+                on_leave_success=transition.on_leave_success,
+                on_leave_failure=transition.on_leave_failure,
+            )
+
+
+# 探索大地图 · 主线 tab("章"字锚点,优先级高于 page_exploration 的兜底识别)
+page_mainline = Page(all_of(GameUiAssets.I_CHECK_EXPLORATION, ExplorationAssets.I_CHECK_MAIN_TITLE), priority=60)
+# 探索大地图 · 玩法 tab("御魂"标题锚点)
+page_gameplay = Page(all_of(GameUiAssets.I_CHECK_EXPLORATION, ExplorationAssets.I_CHECK_PLAY_TITLE), priority=60)
+
+# 大地图 tab 互切(固定坐标点击,幂等)
+page_mainline.connect(page_gameplay, ExplorationAssets.C_CLICK_PALY_TITLE, key="page_mainline->page_gameplay")
+page_gameplay.connect(page_mainline, ExplorationAssets.C_CLICK_MAIN_TITLE, key="page_gameplay->page_mainline")
+
+# 大地图通用态 -> tab 桥接边:page_exploration 是入口桥 + 导航缓存页,
+# tab 页必须从这里可达才能从庭院方向进入,也保证 tab 页能切回通用态。
+page_exploration.connect(page_mainline, ExplorationAssets.C_CLICK_MAIN_TITLE, key="page_exploration->page_mainline")
+page_exploration.connect(page_gameplay, ExplorationAssets.C_CLICK_PALY_TITLE, key="page_exploration->page_gameplay")
+
+# tab 页继承大地图全部出口(回庭院、各区域入口等),此后 page_exploration 新增出边自动跟随
+inherit_transitions(page_exploration, page_mainline, page_gameplay)

+ 12 - 0
tasks/Exploration/res/click.json

@@ -52,5 +52,17 @@
     "roiFront": "0,0,111,12",
     "roiBack": "0,0,111,12",
     "description": "随机点"
+  },
+  {
+    "itemName": "click_main_title",
+    "roiFront": "1070,174,77,28",
+    "roiBack": "1070,174,77,28",
+    "description": "点击探索大地图主线tab标题"
+  },
+  {
+    "itemName": "click_paly_title",
+    "roiFront": "1178,172,77,28",
+    "roiBack": "1178,172,77,28",
+    "description": "点击探索大地图玩法tab标题"
   }
 ]

+ 18 - 0
tasks/Exploration/res/image.json

@@ -250,5 +250,23 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "探索章节切换文件夹图标(移植自mine)"
+  },
+  {
+    "itemName": "check_main_title",
+    "imageName": "res_check_main_title.png",
+    "roiFront": "1150,457,32,32",
+    "roiBack": "1069,222,113,336",
+    "method": "Template matching",
+    "threshold": 0.85,
+    "description": "探索大地图主线tab标题锚点(章字)"
+  },
+  {
+    "itemName": "check_play_title",
+    "imageName": "res_check_play_title.png",
+    "roiFront": "1073,214,40,32",
+    "roiBack": "1065,210,190,316",
+    "method": "Template matching",
+    "threshold": 0.85,
+    "description": "探索大地图玩法tab标题锚点(御魂)"
   }
 ]

BIN
tasks/Exploration/res/res_check_main_title.png


BIN
tasks/Exploration/res/res_check_play_title.png


+ 4 - 3
tasks/GameUi/navigator.py

@@ -766,7 +766,7 @@ class GameUi(BaseTask, GameUiAssets):
         return True
 
     def goto_page(self, destination: Page, confirm_wait: float = 0, skip_first_screenshot: bool = True,
-                  timeout: int = 30) -> bool | None:
+                  timeout: int = 30, *, accepted_pages: tuple[Page, ...] = ()) -> bool | None:
         """导航到目标页面。
 
         Args:
@@ -774,6 +774,7 @@ class GameUi(BaseTask, GameUiAssets):
             confirm_wait: 到达目标页面后额外等待的确认时间。
             skip_first_screenshot: 是否复用当前截图。
             timeout: 无有效进展超时时间,单位秒。
+            accepted_pages: 可直接继续任务的其他页面,识别到后无需转往目标页。
 
         Returns:
             是否成功到达目标页面。
@@ -824,9 +825,9 @@ class GameUi(BaseTask, GameUiAssets):
                 last_detected_page_key = current.key
                 reset_repeated_transition_failures()
 
-            if current == destination:
+            if current == destination or any(current.key == page.key for page in accepted_pages):
                 # current 来自 _refresh_current_page,其返回已是两帧稳定确认的结果,无需再次 confirm。
-                return self._finalize_arrival(destination, confirm_wait, start_time)
+                return self._finalize_arrival(current, confirm_wait, start_time)
 
             path = self._build_path(current, destination)
             if not path:

+ 2 - 5
tasks/TrueOrochi/assets.py

@@ -58,10 +58,7 @@ class TrueOrochiAssets:
 	I_ST_CREATE_ROOM = RuleImage(roi_front=(528,482,223,62), roi_back=(528,482,223,62), threshold=0.8, method="Template matching", file="./tasks/TrueOrochi/st/st_st_create_room.png")
 	# 头像框 
 	I_ST_FRAME = RuleImage(roi_front=(571,442,135,65), roi_back=(571,442,135,65), threshold=0.8, method="Template matching", file="./tasks/TrueOrochi/st/st_st_frame.png")
-
-
-	# Ocr Rule Assets
-	# 本周剩余奖励次数 
-	O_TIMES = RuleOcr(roi=(461,388,40,26), area=(461,388,40,26), mode="DigitCounter", method="Default", keyword="", name="times")
+	# 玩法tab八岐大蛇模块,在场说明本周还有次数 
+	I_ST_MODULE = RuleImage(roi_front=(1111,322,84,22), roi_back=(1068,210,191,313), threshold=0.85, method="Template matching", file="./tasks/TrueOrochi/st/st_module.png")
 
 

+ 0 - 1
tasks/TrueOrochi/config.py

@@ -30,7 +30,6 @@ class TrueOrochiConfig(BaseModel):
     find_true_orochi: bool = Field(default=True, description='find_true_orochi_help')
     # green_enable: bool = Field(default=False, description='green_enable_help')
     # green_mark_type: GreenMarkType = Field(default=GreenMarkType.LEFT_1, description='green_mark_type_help')
-    current_success: int = Field(default=0, description='current_success_help')
 
 class TrueOrochi(ConfigBase):
     scheduler: TrueOrochiScheduler = Field(default_factory=TrueOrochiScheduler)

+ 12 - 35
tasks/TrueOrochi/script_task.py

@@ -2,7 +2,7 @@
 # @author runhey
 # github https://github.com/runhey
 from time import sleep
-from datetime import datetime, time
+from datetime import datetime
 
 from module.logger import logger
 from module.exception import TaskEnd, GameStuckError
@@ -16,6 +16,7 @@ from tasks.Orochi.script_task import ScriptTask as OrochiScriptTask
 from tasks.Orochi.config import Layer
 from tasks.Orochi.page import page_orochi
 from tasks.GameUi.page import page_main, page_shikigami_records
+from tasks.Exploration.page import page_gameplay
 from tasks.TrueOrochi.assets import TrueOrochiAssets
 
 
@@ -25,9 +26,10 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
     
         conf = self.config.true_orochi.true_orochi_config
 
-        if conf.current_success >= 2:
-            # 超过两次就说明这周打完了没有必要再打了
-            logger.warning('This week is full')
+        # 玩法tab的八岐大蛇模块在场说明本周还有次数,消失说明本周已打完
+        self.goto_page(page_gameplay)
+        if not self.appear(self.I_ST_MODULE):
+            logger.warning('True orochi module absent, no attempts left this week')
             self.check_times(True)
             raise TaskEnd('TrueOrochi')
 
@@ -91,7 +93,7 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
         # 检查是否还有真蛇入口,支持存储两次
         self.goto_page(page_orochi)
         sleep(0.5)
-        if conf.current_success < 2 and self.check_true_orochi(True):
+        if self.check_true_orochi(True):
             battle = True
             logger.info('Find another true orochi entry, continue')
             self.run_true_orochi_battle()
@@ -110,13 +112,6 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
             if self.appear_then_click(self.I_UI_CONFIRM, interval=1):
                 continue
             if self.appear_then_click(self.I_ST_FIRE, interval=4):
-                # 修正已经挑战的次数, 注意这个是战斗开始之前的次数
-                current, current_success, total = self.O_TIMES.ocr(self.device.image)
-                if current_success < 0 or current_success > 2:
-                    continue
-                logger.info(f'current: {current}, current_success: {current_success}, total: {total}')
-                conf.current_success = current_success
-                self.config.save()
                 continue
             if self.appear_then_click(self.I_FIND_TS, interval=1):
                 continue
@@ -192,31 +187,13 @@ class ScriptTask(OrochiScriptTask, TrueOrochiAssets):
 
     def check_times(self, battle: bool):
         """
-        后续的次数和时间设置
-        :param battle: 本次是否挑战了真蛇
-        :param current_success: 这周的成功次数
+        根据是否有战斗结果设置下次运行时间
+        :param battle:
         :return:
         """
-        now = datetime.now()
-        now_year, now_week_number, now_weekday = now.isocalendar()
-        if battle:
-            # 只有真正打过才加一次数
-            logger.info('Add current_success by 1')
-            self.config.true_orochi.true_orochi_config.current_success += 1
-            self.config.true_orochi.true_orochi_config.current_success = min(2, self.config.true_orochi.true_orochi_config.current_success)
-            next_run = now + self.config.true_orochi.scheduler.success_interval
-        else:
-            logger.info('Battle skipped or not found True Orochi')
-            next_run = now + self.config.true_orochi.scheduler.failure_interval
-        next_run_year, next_run_week_number, next_run_weekday = next_run.isocalendar()
-        # 如果下次运行的时间是下一周,那么就重置成功次数
-        if now_week_number != next_run_week_number:
-            logger.info('Reset current_success')
-            self.config.true_orochi.true_orochi_config.current_success = 0
-
-        self.config.save()
-        self.set_next_run(task='TrueOrochi', target=next_run)
-        # self.set_next_run('TrueOrochi', finish=True, success=True)
+        interval = self.config.true_orochi.scheduler.success_interval if battle \
+            else self.config.true_orochi.scheduler.failure_interval
+        self.set_next_run(task='TrueOrochi', target=datetime.now() + interval)
 
     def run_true_orochi(self) -> bool:
         pass

+ 9 - 0
tasks/TrueOrochi/st/image.json

@@ -124,5 +124,14 @@
     "method": "Template matching",
     "threshold": 0.8,
     "description": "头像框"
+  },
+  {
+    "itemName": "st_module",
+    "imageName": "st_module.png",
+    "roiFront": "1111,322,84,22",
+    "roiBack": "1068,210,191,313",
+    "method": "Template matching",
+    "threshold": 0.85,
+    "description": "玩法tab八岐大蛇模块,在场说明本周还有次数"
   }
 ]

+ 0 - 11
tasks/TrueOrochi/st/ocr.json

@@ -1,11 +0,0 @@
-[
-  {
-    "itemName": "times",
-    "roiFront": "461,388,40,26",
-    "roiBack": "461,388,40,26",
-    "mode": "DigitCounter",
-    "method": "Default",
-    "keyword": "",
-    "description": "本周剩余奖励次数"
-  }
-]

BIN
tasks/TrueOrochi/st/st_module.png