mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-08 12:27:33 +08:00
Fix: Catch server hot fix and restart game immediately
- Pretty Timer print
This commit is contained in:
parent
db169546a9
commit
6702ec234a
2
alas.py
2
alas.py
@ -57,7 +57,7 @@ class AzurLaneAutoScript:
|
||||
self.config.task_call('Restart')
|
||||
return True
|
||||
except (GameStuckError, GameTooManyClickError) as e:
|
||||
logger.warning(e)
|
||||
logger.error(e)
|
||||
self.save_error_log()
|
||||
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')
|
||||
|
@ -12,6 +12,7 @@ def timer(function):
|
||||
t1 = time.time()
|
||||
print('%s: %s s' % (function.__name__, str(round(t1 - t0, 10))))
|
||||
return result
|
||||
|
||||
return function_timer
|
||||
|
||||
|
||||
@ -106,7 +107,10 @@ class Timer:
|
||||
Returns:
|
||||
float
|
||||
"""
|
||||
return time.time() - self._current
|
||||
if self.started():
|
||||
return time.time() - self._current
|
||||
else:
|
||||
return 0.
|
||||
|
||||
def reached(self):
|
||||
"""
|
||||
@ -145,4 +149,9 @@ class Timer:
|
||||
|
||||
def show(self):
|
||||
from module.logger import logger
|
||||
logger.info('%s s' % str(self.current()))
|
||||
logger.info(str(self))
|
||||
|
||||
def __str__(self):
|
||||
return f'Timer(limit={round(self.current(), 3)}/{self.limit}, count={self._reach_count}/{self.count})'
|
||||
|
||||
__repr__ = __str__
|
||||
|
@ -7,7 +7,7 @@ from module.device.app_control import AppControl
|
||||
from module.device.control import Control
|
||||
from module.device.screenshot import Screenshot
|
||||
from module.exception import (GameStuckError, GameTooManyClickError,
|
||||
RequestHumanTakeover)
|
||||
GameNotRunningError, RequestHumanTakeover)
|
||||
from module.handler.assets import GET_MISSION
|
||||
from module.logger import logger
|
||||
|
||||
@ -85,7 +85,10 @@ class Device(Screenshot, Control, AppControl):
|
||||
logger.warning(f'Waiting for {self.detect_record}')
|
||||
self.stuck_record_clear()
|
||||
|
||||
raise GameStuckError(f'Wait too long')
|
||||
if self.app_is_running():
|
||||
raise GameStuckError(f'Wait too long')
|
||||
else:
|
||||
raise GameNotRunningError('Game died')
|
||||
|
||||
def handle_control_check(self, button):
|
||||
self.stuck_record_clear()
|
||||
|
@ -4,6 +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.handler.assets import *
|
||||
from module.logger import logger
|
||||
|
||||
@ -103,6 +104,8 @@ class InfoHandler(ModuleBase):
|
||||
def popup_interval_clear(self):
|
||||
self.interval_clear([POPUP_CANCEL, POPUP_CONFIRM])
|
||||
|
||||
_hot_fix_check_wait = Timer(6)
|
||||
|
||||
def handle_urgent_commission(self, drop=None):
|
||||
"""
|
||||
Args:
|
||||
@ -118,6 +121,18 @@ class InfoHandler(ModuleBase):
|
||||
self.handle_info_bar()
|
||||
drop.add(self.device.image)
|
||||
self.device.click(GET_MISSION)
|
||||
self._hot_fix_check_wait.reset()
|
||||
|
||||
# Check game client existence after 3s to 6s
|
||||
# Hot fixes will kill AL if you clicked the confirm button
|
||||
if self._hot_fix_check_wait.reached():
|
||||
self._hot_fix_check_wait.clear()
|
||||
if self._hot_fix_check_wait.started() and 3 <= self._hot_fix_check_wait.current() <= 6:
|
||||
if not self.device.app_is_running():
|
||||
logger.warning('Detected hot fixes from game server, game died')
|
||||
raise GameNotRunningError
|
||||
self._hot_fix_check_wait.clear()
|
||||
|
||||
return appear
|
||||
|
||||
def handle_combat_low_emotion(self):
|
||||
|
Loading…
Reference in New Issue
Block a user