|
@@ -11,6 +11,10 @@ from tasks.Component.GeneralBuff.assets import GeneralBuffAssets
|
|
|
from tasks.base_task import BaseTask
|
|
from tasks.base_task import BaseTask
|
|
|
import time
|
|
import time
|
|
|
|
|
|
|
|
|
|
+# 登录期间 MPay 弹窗「关掉又重弹」的容忍上限,超过说明回车已走不出去,交 Restart 重建
|
|
|
|
|
+DESKTOP_MPAY_CLOSE_LIMIT = 5
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
|
|
class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
|
|
|
character: str
|
|
character: str
|
|
|
|
|
|
|
@@ -31,8 +35,33 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
|
|
|
confirm_timer = Timer(1.5, count=2).start()
|
|
confirm_timer = Timer(1.5, count=2).start()
|
|
|
orientation_timer = Timer(10)
|
|
orientation_timer = Timer(10)
|
|
|
login_success = False
|
|
login_success = False
|
|
|
|
|
+ # 本次登录已处理过的 MPay 弹窗次数,用于给「关掉又重弹」封顶
|
|
|
|
|
+ popup_handled = 0
|
|
|
|
|
+
|
|
|
|
|
+ def handle_desktop_login_popup() -> bool:
|
|
|
|
|
+ """登录期间处理 MPay 弹窗,返回是否刚关闭了弹窗。
|
|
|
|
|
+
|
|
|
|
|
+ MPay 是独立顶层窗口,主窗口截图识别不到,只能按 HWND 枚举检查。
|
|
|
|
|
+ """
|
|
|
|
|
+ nonlocal popup_handled
|
|
|
|
|
+ if not self.device.is_desktop or not self.device.find_desktop_login_popup():
|
|
|
|
|
+ return False
|
|
|
|
|
+ popup_handled += 1
|
|
|
|
|
+ if popup_handled > DESKTOP_MPAY_CLOSE_LIMIT:
|
|
|
|
|
+ raise GameStuckError(
|
|
|
|
|
+ f'Desktop MPay login popup reappeared more than {DESKTOP_MPAY_CLOSE_LIMIT} times')
|
|
|
|
|
+ if not self.device.desktop_confirm_login_popup():
|
|
|
|
|
+ # 弹窗可能恰好在确认函数最后一次枚举后自行关闭,重新确认避免误判卡死
|
|
|
|
|
+ if not self.device.find_desktop_login_popup():
|
|
|
|
|
+ return True
|
|
|
|
|
+ # 弹窗仍存活时不能继续识别页面,否则 MPay 会被当成未知页面
|
|
|
|
|
+ raise GameStuckError('Desktop MPay login popup cannot be closed')
|
|
|
|
|
+ return True
|
|
|
|
|
|
|
|
while 1:
|
|
while 1:
|
|
|
|
|
+ # MPay 可能在启动后、重登时或登录中途反复出现,每轮都要处理
|
|
|
|
|
+ if handle_desktop_login_popup():
|
|
|
|
|
+ continue
|
|
|
# Watch device rotation
|
|
# Watch device rotation
|
|
|
if not login_success and orientation_timer.reached():
|
|
if not login_success and orientation_timer.reached():
|
|
|
# Screen may rotate after starting an app
|
|
# Screen may rotate after starting an app
|
|
@@ -40,6 +69,9 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
|
|
|
orientation_timer.reset()
|
|
orientation_timer.reset()
|
|
|
|
|
|
|
|
self.device.screenshot()
|
|
self.device.screenshot()
|
|
|
|
|
+ # 截图与窗口枚举有竞态,截图后再查一次,避免刚出现的 MPay 进入图像识别
|
|
|
|
|
+ if handle_desktop_login_popup():
|
|
|
|
|
+ continue
|
|
|
# https://github.com/runhey/OnmyojiAutoScript/pull/1761
|
|
# https://github.com/runhey/OnmyojiAutoScript/pull/1761
|
|
|
if not self.device.check_screen_size_sample():
|
|
if not self.device.check_screen_size_sample():
|
|
|
continue
|
|
continue
|
|
@@ -152,6 +184,9 @@ class LoginHandler(BaseTask, RestartAssets, GameUiAssets, GeneralBuffAssets):
|
|
|
self.device.click_record_clear()
|
|
self.device.click_record_clear()
|
|
|
try:
|
|
try:
|
|
|
self._app_handle_login()
|
|
self._app_handle_login()
|
|
|
|
|
+ # 桌面:登录成功后标记登录态,app_is_running 才会判定为已在游戏中
|
|
|
|
|
+ if self.device.is_desktop:
|
|
|
|
|
+ self.device.desktop_mark_logged_in()
|
|
|
if self.config.restart.harvest_config.enable:
|
|
if self.config.restart.harvest_config.enable:
|
|
|
self.harvest()
|
|
self.harvest()
|
|
|
return True
|
|
return True
|