Browse Source

fix(Restart): 识别 16+ 登录页并点击进入游戏

unknown 55 minutes ago
parent
commit
89160a62f4

+ 3 - 2
tasks/Component/SwitchAccount/login_account.py

@@ -9,6 +9,7 @@ from module.atom.ocr import RuleOcr
 from module.logger import logger
 from module.logger import logger
 from tasks.Component.SwitchAccount.assets import SwitchAccountAssets
 from tasks.Component.SwitchAccount.assets import SwitchAccountAssets
 from tasks.Component.SwitchAccount.switch_account_config import AccountInfo
 from tasks.Component.SwitchAccount.switch_account_config import AccountInfo
+from tasks.Restart.login_screen import LOGIN_SCREEN
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
 
 
 
 
@@ -153,7 +154,7 @@ class LoginAccount(BaseTask, SwitchAccountAssets):
                 return
                 return
             if self.appear_then_click(self.I_SA_SWITCH_ACCOUNT_BTN, interval=1.5):
             if self.appear_then_click(self.I_SA_SWITCH_ACCOUNT_BTN, interval=1.5):
                 continue
                 continue
-            if self.appear(self.I_CHECK_LOGIN_FORM):
+            if LOGIN_SCREEN.evaluate(self):
                 self.click(self.C_SA_LOGIN_FORM_USER_CENTER, 1.5)
                 self.click(self.C_SA_LOGIN_FORM_USER_CENTER, 1.5)
                 continue
                 continue
         return
         return
@@ -236,7 +237,7 @@ class LoginAccount(BaseTask, SwitchAccountAssets):
         """
         """
         self.screenshot()
         self.screenshot()
         #
         #
-        if not (self.appear(self.I_CHECK_LOGIN_FORM) or self.appear(self.I_SA_NETEASE_GAME_LOGO)):
+        if not (LOGIN_SCREEN.evaluate(self) or self.appear(self.I_SA_NETEASE_GAME_LOGO)):
             logger.error("Unknown Page,%s %s Login Failed", accountInfo.character, accountInfo.svr)
             logger.error("Unknown Page,%s %s Login Failed", accountInfo.character, accountInfo.svr)
             return False
             return False
 
 

+ 2 - 2
tasks/GameUi/default_pages.py

@@ -2,7 +2,6 @@ from __future__ import annotations
 
 
 from tasks.ActivityShikigami.assets import ActivityShikigamiAssets
 from tasks.ActivityShikigami.assets import ActivityShikigamiAssets
 from tasks.Component.GeneralInvite.assets import GeneralInviteAssets
 from tasks.Component.GeneralInvite.assets import GeneralInviteAssets
-from tasks.Component.SwitchAccount.assets import SwitchAccountAssets
 from tasks.Exploration.assets import ExplorationAssets
 from tasks.Exploration.assets import ExplorationAssets
 from tasks.GameUi.action import conditional_action, sequence
 from tasks.GameUi.action import conditional_action, sequence
 from tasks.Pets.assets import PetsAssets
 from tasks.Pets.assets import PetsAssets
@@ -21,6 +20,7 @@ from tasks.GameUi.matcher import any_of, all_of
 from tasks.GameUi.page_definition import Page
 from tasks.GameUi.page_definition import Page
 from tasks.KekkaiUtilize.assets import KekkaiUtilizeAssets
 from tasks.KekkaiUtilize.assets import KekkaiUtilizeAssets
 from tasks.Restart.assets import RestartAssets
 from tasks.Restart.assets import RestartAssets
+from tasks.Restart.login_screen import LOGIN_SCREEN
 from tasks.RyouToppa.assets import RyouToppaAssets
 from tasks.RyouToppa.assets import RyouToppaAssets
 from tasks.WeeklyTrifles.assets import WeeklyTriflesAssets
 from tasks.WeeklyTrifles.assets import WeeklyTriflesAssets
 
 
@@ -56,7 +56,7 @@ def handle_login_page(task) -> bool:
 
 
 
 
 # 登录页。
 # 登录页。
-page_login = Page(SwitchAccountAssets.I_CHECK_LOGIN_FORM, category="global")
+page_login = Page(LOGIN_SCREEN, category="global")
 page_login.add_enter_success_hooks(handle_login_page)
 page_login.add_enter_success_hooks(handle_login_page)
 
 
 # 庭院主页(此处通过提高阈值来处理部分探索章节会识别成原始庭院的问题, 后续有其他更好方法需改善)
 # 庭院主页(此处通过提高阈值来处理部分探索章节会识别成原始庭院的问题, 后续有其他更好方法需改善)

+ 2 - 0
tasks/Restart/assets.py

@@ -113,6 +113,8 @@ class RestartAssets:
 	I_LOGIN_YELLOW_CLOSE = RuleImage(roi_front=(29,17,46,44), roi_back=(0,0,94,86), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_yellow_close.png")
 	I_LOGIN_YELLOW_CLOSE = RuleImage(roi_front=(29,17,46,44), roi_back=(0,0,94,86), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_yellow_close.png")
 	# 用于判断是否出现登录选区的 
 	# 用于判断是否出现登录选区的 
 	I_LOGIN_8 = RuleImage(roi_front=(178,572,53,60), roi_back=(1,547,241,105), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_8.png")
 	I_LOGIN_8 = RuleImage(roi_front=(178,572,53,60), roi_back=(1,547,241,105), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_8.png")
+	# 登录页左下角的 16+ 适龄提示
+	I_LOGIN_16 = RuleImage(roi_front=(13,564,53,70), roi_back=(1,547,241,105), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_16.png")
 	# 指定角色进入游戏,默认第一个 
 	# 指定角色进入游戏,默认第一个 
 	I_LOGIN_SPECIFIC_SERVE = RuleImage(roi_front=(0,0,120,120), roi_back=(0,0,120,120), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_specific_serve.png")
 	I_LOGIN_SPECIFIC_SERVE = RuleImage(roi_front=(0,0,120,120), roi_back=(0,0,120,120), threshold=0.8, method="Template matching", file="./tasks/Restart/login/login_login_specific_serve.png")
 	# 下载插画 
 	# 下载插画 

+ 3 - 4
tasks/Restart/login.py

@@ -6,6 +6,7 @@ from module.base.timer import Timer
 from module.exception import RequestHumanTakeover, GameTooManyClickError, GameStuckError
 from module.exception import RequestHumanTakeover, GameTooManyClickError, GameStuckError
 from module.logger import logger
 from module.logger import logger
 from tasks.Restart.assets import RestartAssets
 from tasks.Restart.assets import RestartAssets
+from tasks.Restart.login_screen import LOGIN_SCREEN
 from tasks.GameUi.assets import GameUiAssets
 from tasks.GameUi.assets import GameUiAssets
 from tasks.Component.GeneralBuff.assets import GeneralBuffAssets
 from tasks.Component.GeneralBuff.assets import GeneralBuffAssets
 from tasks.base_task import BaseTask
 from tasks.base_task import BaseTask
@@ -159,16 +160,14 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
                 logger.warning('Appear create account')
                 logger.warning('Appear create account')
                 raise GameStuckError('Appear create account')
                 raise GameStuckError('Appear create account')
 
 
-            # 点击“进入游戏”速度过快会进入区服设置,同时需在检测I_LOGIN_8之前检测,因为新服图标会让I_LOGIN_8向右偏移导致永远无法检测成功
-            # 同时修复了点击位置(之前是点击I_CHARACTARS而不是左边的区域)
+            # 先退出区服设置,再在下一帧识别「进入游戏」。
             if self.appear(self.I_CHARACTARS, interval=1):
             if self.appear(self.I_CHARACTARS, interval=1):
                 logger.info('误入区服设置')
                 logger.info('误入区服设置')
                 # https://github.com/runhey/OnmyojiAutoScript/issues/585
                 # https://github.com/runhey/OnmyojiAutoScript/issues/585
                 self.device.click(x=106, y=535)
                 self.device.click(x=106, y=535)
                 continue
                 continue
                 
                 
-            # 点击’进入游戏‘
-            if not self.appear(self.I_LOGIN_8):
+            if not LOGIN_SCREEN.evaluate(self):
                 continue
                 continue
             
             
             # 登录体验服时,点击“进入游戏”速度过快,可能会出现体验服的弹窗
             # 登录体验服时,点击“进入游戏”速度过快,可能会出现体验服的弹窗

+ 9 - 0
tasks/Restart/login/image.json

@@ -53,6 +53,15 @@
     "threshold": 0.8,
     "threshold": 0.8,
     "description": "用于判断是否出现登录选区的"
     "description": "用于判断是否出现登录选区的"
   },
   },
+  {
+    "itemName": "login_16",
+    "imageName": "login_login_16.png",
+    "roiFront": "13,564,53,70",
+    "roiBack": "1,547,241,105",
+    "method": "Template matching",
+    "threshold": 0.8,
+    "description": "登录页左下角的 16+ 适龄提示"
+  },
   {
   {
     "itemName": "login_specific_serve",
     "itemName": "login_specific_serve",
     "imageName": "login_login_specific_serve.png",
     "imageName": "login_login_specific_serve.png",

BIN
tasks/Restart/login/login_login_16.png


+ 11 - 0
tasks/Restart/login_screen.py

@@ -0,0 +1,11 @@
+from tasks.Component.SwitchAccount.assets import SwitchAccountAssets
+from tasks.GameUi.matcher import any_of
+from tasks.Restart.assets import RestartAssets
+
+
+# 旧版 8+ 标识有两种裁剪,重启、导航和切换账号共用这组登录页标识。
+LOGIN_SCREEN = any_of(
+    RestartAssets.I_LOGIN_16,
+    RestartAssets.I_LOGIN_8,
+    SwitchAccountAssets.I_CHECK_LOGIN_FORM,
+)

+ 18 - 0
tests/tasks/Restart/test_login.py

@@ -121,6 +121,24 @@ def test_direct_courtyard_entry_does_not_wait_for_character_selection(monkeypatc
     assert task.now - task.clicks[0][2] < 3
     assert task.now - task.clicks[0][2] < 3
 
 
 
 
+def test_16_plus_login_clicks_only_when_the_button_is_visible(monkeypatch):
+    def next_screen(task):
+        if task.clicks:
+            return task.courtyard()
+        if task.frames == 1:
+            return [task.O_LOGIN_ENTER_GAME_ORIGIN]
+        if task.frames == 2:
+            return [task.I_LOGIN_16]
+        return [task.I_LOGIN_16, task.O_LOGIN_ENTER_GAME_ORIGIN]
+
+    task = LoginReplay(monkeypatch, next_screen)
+
+    assert task._app_handle_login() is True
+    assert [(name, frame) for name, frame, _ in task.clicks] == [
+        (task.O_LOGIN_ENTER_GAME_ORIGIN.name, 3),
+    ]
+
+
 def test_character_selection_is_handled_after_enter_game(monkeypatch):
 def test_character_selection_is_handled_after_enter_game(monkeypatch):
     def next_screen(task):
     def next_screen(task):
         clicked = [click[0] for click in task.clicks]
         clicked = [click[0] for click in task.clicks]