diff --git a/alas.py b/alas.py index 5017727ea..8055a7b22 100644 --- a/alas.py +++ b/alas.py @@ -8,6 +8,7 @@ import inflection from cached_property import cached_property from module.base.decorator import del_cached_property +from module.base.resource import release_resources from module.config.config import AzurLaneConfig, TaskEnd from module.config.deep import deep_get, deep_set from module.exception import * @@ -21,7 +22,7 @@ class AzurLaneAutoScript: AutoRestart_Enabled = False AutoRestart_AttemptsToRestart = 0 AutoRestart_NotifyWhenAutoRestart = False - + OtherLoginCount = 0 def __init__(self, config_name='alas'): logger.hr('Start', level=0) self.config_name = config_name @@ -76,6 +77,23 @@ class AzurLaneAutoScript: logger.exception(e) exit(1) + def handle_otherlogin(self): + self.OtherLoginCount += 1 + logger.warning(f'OtherLogin_Count: {self.OtherLoginCount}') + # self.device.app_stop() + release_resources() + self.device.release_during_wait() + # 将Optimization_otherLoginTime字符串转换为列表 + wait_times = [int(t) for t in self.config.Optimization_otherLoginTime.split(',')] + # 根据计数选择等待时间,如果计数超过列表长度,使用最后一个值 + index = min(self.OtherLoginCount - 1, len(wait_times) - 1) + wait_time = wait_times[index] + logger.warning(f'Waiting for {wait_time} minutes before restarting') + self.device.sleep(60 * wait_time) + logger.warning("======OtherLogin_Sleep Over,now restart======") + self.config.task_call('Restart') + self.device.sleep(10) + def run(self, command, skip_first_screenshot=False): self.AutoRestart_Enabled = deep_get(self.config.data, "Restart.AutoRestart.Enabled") self.AutoRestart_NotifyWhenAutoRestart = deep_get(self.config.data, "Restart.AutoRestart.NotifyWhenAutoRestart") @@ -93,15 +111,19 @@ class AzurLaneAutoScript: logger.warning(e) self.config.task_call('Restart') return False + except OtherLogin as e: + logger.error(e) + self.handle_otherlogin() + return False except (GameStuckError, GameTooManyClickError) as e: logger.error(e) self.save_error_log() from module.handler.info_handler import InfoHandler info_handler = InfoHandler(config=self.config,device=self.device) - if info_handler.handle_urgent_commission(): - logger.warning("======OtherLogin_Sleep Over,now restart======") - self.config.task_call('Restart') - self.device.sleep(10) + try: + info_handler.handle_urgent_commission() + except OtherLogin: + self.handle_otherlogin() return False logger.warning(f'Game stuck, {self.device.package} will be restarted in 10 seconds') logger.warning('If you are playing by hand, please stop Alas') diff --git a/config/template.json b/config/template.json index b61eead43..408c79144 100644 --- a/config/template.json +++ b/config/template.json @@ -97,7 +97,8 @@ "ScreenshotInterval": 0.3, "CombatScreenshotInterval": 1.0, "TaskHoardingDuration": 0, - "WhenTaskQueueEmpty": "goto_main" + "WhenTaskQueueEmpty": "goto_main", + "otherLoginTime": "15,30,60" }, "DropRecord": { "SaveFolder": "./screenshots", diff --git a/module/config/argument/args.json b/module/config/argument/args.json index 9566bdc4e..a44965973 100644 --- a/module/config/argument/args.json +++ b/module/config/argument/args.json @@ -429,6 +429,10 @@ "goto_main", "close_game" ] + }, + "otherLoginTime": { + "type": "textarea", + "value": "15,30,60" } }, "DropRecord": { diff --git a/module/config/argument/argument.yaml b/module/config/argument/argument.yaml index 36807bb65..edd6fe5a6 100644 --- a/module/config/argument/argument.yaml +++ b/module/config/argument/argument.yaml @@ -151,6 +151,9 @@ Optimization: WhenTaskQueueEmpty: value: goto_main option: [ stay_there, goto_main, close_game ] + otherLoginTime: + value: 15,30,60 + type: textarea DropRecord: SaveFolder: ./screenshots AzurStatsID: null diff --git a/module/config/config_generated.py b/module/config/config_generated.py index a4a865681..a5957277f 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -110,6 +110,7 @@ class GeneratedConfig: Optimization_CombatScreenshotInterval = 1.0 Optimization_TaskHoardingDuration = 0 Optimization_WhenTaskQueueEmpty = 'goto_main' # stay_there, goto_main, close_game + Optimization_otherLoginTime = '15,30,60' # Group `DropRecord` DropRecord_SaveFolder = './screenshots' diff --git a/module/config/i18n/en-US.json b/module/config/i18n/en-US.json index 9e17574f1..1ccd48185 100644 --- a/module/config/i18n/en-US.json +++ b/module/config/i18n/en-US.json @@ -779,6 +779,10 @@ "stay_there": "Stay There", "goto_main": "Goto Main Page", "close_game": "Close Game" + }, + "otherLoginTime": { + "name": "Remote Login Wait Time", + "help": "Waiting time (minutes) when another device login is detected, a comma-separated list of numbers, each login detection will use the next value in sequence. Example: 15,30,60" } }, "DropRecord": { diff --git a/module/config/i18n/ja-JP.json b/module/config/i18n/ja-JP.json index ec879d243..e303a1054 100644 --- a/module/config/i18n/ja-JP.json +++ b/module/config/i18n/ja-JP.json @@ -779,6 +779,10 @@ "stay_there": "stay_there", "goto_main": "goto_main", "close_game": "close_game" + }, + "otherLoginTime": { + "name": "Optimization.otherLoginTime.name", + "help": "Optimization.otherLoginTime.help" } }, "DropRecord": { diff --git a/module/config/i18n/zh-CN.json b/module/config/i18n/zh-CN.json index 790e6bd35..55af9bd11 100644 --- a/module/config/i18n/zh-CN.json +++ b/module/config/i18n/zh-CN.json @@ -779,6 +779,10 @@ "stay_there": "停在原处", "goto_main": "前往主界面", "close_game": "关闭游戏" + }, + "otherLoginTime": { + "name": "异地登录等待时间", + "help": "检测到其他设备登录时等待的时间(分钟),逗号分隔的数字列表,每次检测到登录会按顺序使用下一个值。例如: 15,30,60" } }, "DropRecord": { diff --git a/module/config/i18n/zh-TW.json b/module/config/i18n/zh-TW.json index 44c3b0d51..b42bfd79e 100644 --- a/module/config/i18n/zh-TW.json +++ b/module/config/i18n/zh-TW.json @@ -779,6 +779,10 @@ "stay_there": "停在原處", "goto_main": "前往主界面", "close_game": "關閉遊戲" + }, + "otherLoginTime": { + "name": "Optimization.otherLoginTime.name", + "help": "Optimization.otherLoginTime.help" } }, "DropRecord": { diff --git a/module/exception.py b/module/exception.py index e0d3ecf39..c2e7248ba 100644 --- a/module/exception.py +++ b/module/exception.py @@ -61,3 +61,5 @@ class RequestHumanTakeover(Exception): # Request human takeover # Alas is unable to handle such error, probably because of wrong settings. pass +class OtherLogin(Exception): + pass \ No newline at end of file diff --git a/module/handler/info_handler.py b/module/handler/info_handler.py index d8cc5f78d..dbcb12388 100644 --- a/module/handler/info_handler.py +++ b/module/handler/info_handler.py @@ -4,7 +4,7 @@ from module.base.base import ModuleBase from module.base.button import Button from module.base.timer import Timer from module.base.utils import * -from module.exception import GameNotRunningError +from module.exception import GameNotRunningError, OtherLogin from module.handler.assets import * from module.logger import logger from module.os_handler.assets import CLICK_SAFE_AREA as OS_CLICK_SAFE_AREA @@ -34,7 +34,6 @@ class InfoHandler(ModuleBase): """ Info bar """ - def info_bar_count(self): """ Detect info bar by the blue lines on the top of it. @@ -171,15 +170,8 @@ class InfoHandler(ModuleBase): self._hot_fix_check_wait.reset() return False if appear2 or appear3: - from module.base.resource import release_resources logger.warning('Other login in') - logger.warning('Other login in') - logger.warning('Other login in') - self.device.app_stop() - release_resources() - self.device.release_during_wait() - self.device.sleep(60*15) - return True + raise OtherLogin # Check game client existence after 3s to 6s # Hot fixes will kill AL if you clicked the confirm button diff --git a/module/map/camera.py b/module/map/camera.py index 5ede63a4e..51b647f18 100644 --- a/module/map/camera.py +++ b/module/map/camera.py @@ -141,6 +141,8 @@ class Camera(MapOperation): self.ensure_no_story(skip_first_screenshot=False) return False elif self.appear(GET_MISSION, offset=(20, 20)): + logger.warning('GET_MISSION in UPDATE_VIEW') + self.handle_urgent_commission() logger.warning('Perspective error caused by GET_MISSION') self.device.click(GET_MISSION) return False