mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-09 06:07:40 +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')
|
self.config.task_call('Restart')
|
||||||
return True
|
return True
|
||||||
except (GameStuckError, GameTooManyClickError) as e:
|
except (GameStuckError, GameTooManyClickError) as e:
|
||||||
logger.warning(e)
|
logger.error(e)
|
||||||
self.save_error_log()
|
self.save_error_log()
|
||||||
logger.warning(f'Game stuck, {self.device.package} will be restarted in 10 seconds')
|
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')
|
logger.warning('If you are playing by hand, please stop Alas')
|
||||||
|
@ -12,6 +12,7 @@ def timer(function):
|
|||||||
t1 = time.time()
|
t1 = time.time()
|
||||||
print('%s: %s s' % (function.__name__, str(round(t1 - t0, 10))))
|
print('%s: %s s' % (function.__name__, str(round(t1 - t0, 10))))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
return function_timer
|
return function_timer
|
||||||
|
|
||||||
|
|
||||||
@ -106,7 +107,10 @@ class Timer:
|
|||||||
Returns:
|
Returns:
|
||||||
float
|
float
|
||||||
"""
|
"""
|
||||||
return time.time() - self._current
|
if self.started():
|
||||||
|
return time.time() - self._current
|
||||||
|
else:
|
||||||
|
return 0.
|
||||||
|
|
||||||
def reached(self):
|
def reached(self):
|
||||||
"""
|
"""
|
||||||
@ -145,4 +149,9 @@ class Timer:
|
|||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
from module.logger import logger
|
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.control import Control
|
||||||
from module.device.screenshot import Screenshot
|
from module.device.screenshot import Screenshot
|
||||||
from module.exception import (GameStuckError, GameTooManyClickError,
|
from module.exception import (GameStuckError, GameTooManyClickError,
|
||||||
RequestHumanTakeover)
|
GameNotRunningError, RequestHumanTakeover)
|
||||||
from module.handler.assets import GET_MISSION
|
from module.handler.assets import GET_MISSION
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
|
|
||||||
@ -85,7 +85,10 @@ class Device(Screenshot, Control, AppControl):
|
|||||||
logger.warning(f'Waiting for {self.detect_record}')
|
logger.warning(f'Waiting for {self.detect_record}')
|
||||||
self.stuck_record_clear()
|
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):
|
def handle_control_check(self, button):
|
||||||
self.stuck_record_clear()
|
self.stuck_record_clear()
|
||||||
|
@ -4,6 +4,7 @@ from module.base.base import ModuleBase
|
|||||||
from module.base.button import Button
|
from module.base.button import Button
|
||||||
from module.base.timer import Timer
|
from module.base.timer import Timer
|
||||||
from module.base.utils import *
|
from module.base.utils import *
|
||||||
|
from module.exception import GameNotRunningError
|
||||||
from module.handler.assets import *
|
from module.handler.assets import *
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
|
|
||||||
@ -103,6 +104,8 @@ class InfoHandler(ModuleBase):
|
|||||||
def popup_interval_clear(self):
|
def popup_interval_clear(self):
|
||||||
self.interval_clear([POPUP_CANCEL, POPUP_CONFIRM])
|
self.interval_clear([POPUP_CANCEL, POPUP_CONFIRM])
|
||||||
|
|
||||||
|
_hot_fix_check_wait = Timer(6)
|
||||||
|
|
||||||
def handle_urgent_commission(self, drop=None):
|
def handle_urgent_commission(self, drop=None):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
@ -118,6 +121,18 @@ class InfoHandler(ModuleBase):
|
|||||||
self.handle_info_bar()
|
self.handle_info_bar()
|
||||||
drop.add(self.device.image)
|
drop.add(self.device.image)
|
||||||
self.device.click(GET_MISSION)
|
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
|
return appear
|
||||||
|
|
||||||
def handle_combat_low_emotion(self):
|
def handle_combat_low_emotion(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user