1
0
mirror of https://gitee.com/sui-feng-cb/AzurLaneAutoScript1 synced 2026-04-15 17:02:26 +08:00

Merge pull request #1466 from LmeSzinc/bug_fix

Bug fix
This commit is contained in:
LmeSzinc
2022-08-01 00:50:00 +08:00
committed by GitHub
9 changed files with 83 additions and 30 deletions

View File

@@ -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')

View File

@@ -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__

View File

@@ -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()

View File

@@ -197,10 +197,9 @@ def remove_shell_warning(s):
str, bytes: str, bytes:
""" """
if isinstance(s, bytes): if isinstance(s, bytes):
s = remove_prefix(s, b'WARNING: linker: [vdso]: unused DT entry: type 0x70000001 arg 0x0\n') return re.sub(b'^WARNING.+\n', b'', s)
elif isinstance(s, str): elif isinstance(s, str):
s = remove_prefix(s, 'WARNING: linker: [vdso]: unused DT entry: type 0x70000001 arg 0x0\n') return re.sub('^WARNING.+\n', '', s)
return s return s

View File

@@ -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):

View File

@@ -342,7 +342,8 @@ class OSFleet(OSCamera, Combat, Fleet, OSAsh):
self.update_os() self.update_os()
current = self.view.backend.homo_loca current = self.view.backend.homo_loca
logger.attr('homo_loca', current) logger.attr('homo_loca', current)
if record is None or (current is not None and np.linalg.norm(np.subtract(current, record)) < 3): # Max known distance is 4.48px, homo_loca between ( 56, 60) and ( 52, 58)
if record is None or (current is not None and np.linalg.norm(np.subtract(current, record)) < 5.5):
if confirm_timer.reached(): if confirm_timer.reached():
break break
else: else:

View File

@@ -582,7 +582,7 @@ class ResearchSelector(UI):
@Config.when(SERVER=None) @Config.when(SERVER=None)
def research_detect(self): def research_detect(self):
timeout = Timer(3, count=3).start() timeout = Timer(5, count=5).start()
while 1: while 1:
projects = research_detect(self.device.image) projects = research_detect(self.device.image)

View File

@@ -438,26 +438,44 @@ class RewardResearch(ResearchSelector, ResearchQueue):
bool: If success bool: If success
""" """
logger.hr('Receive 6th research', level=2) logger.hr('Receive 6th research', level=2)
# Check if it's finished
if self.research_has_finished(): timeout = Timer(2, count=6).start()
logger.info(f'6th research finished at: {self._research_finished_index}') skip_first_screenshot = True
success = self.research_receive() while 1:
if not success: if skip_first_screenshot:
return False skip_first_screenshot = False
else:
logger.info('No research has finished')
# Check if it's waiting or running
status = self.get_research_status(self.device.image)
if 'waiting' in status:
if self.get_queue_slot() > 0:
self.research_project_start(status.index('waiting'))
else: else:
logger.info('Queue full, stop appending waiting research') self.device.screenshot()
if 'running' in status:
if self.get_queue_slot() > 0: if timeout.reached():
self.research_project_start(status.index('running')) logger.warning('receive_6th_research timeout')
break
# Check if it's finished
if self.research_has_finished():
logger.info(f'6th research finished at: {self._research_finished_index}')
success = self.research_receive()
if not success:
return False
else: else:
logger.info('Queue full, stop appending running research') logger.info('No research has finished')
# Check if it's waiting or running
status = self.get_research_status(self.device.image)
if 'waiting' in status:
if self.get_queue_slot() > 0:
self.research_project_start(status.index('waiting'))
else:
logger.info('Queue full, stop appending waiting research')
break
if 'running' in status:
if self.get_queue_slot() > 0:
self.research_project_start(status.index('running'))
else:
logger.info('Queue full, stop appending running research')
break
if 'unknown' in status:
continue
return True return True

View File

@@ -5,8 +5,9 @@ from module.combat.assets import GET_ITEMS_1, GET_SHIP
from module.exception import (GameNotRunningError, GamePageUnknownError, from module.exception import (GameNotRunningError, GamePageUnknownError,
RequestHumanTakeover) RequestHumanTakeover)
from module.handler.assets import (AUTO_SEARCH_MENU_EXIT, BATTLE_PASS_NOTICE, from module.handler.assets import (AUTO_SEARCH_MENU_EXIT, BATTLE_PASS_NOTICE,
GAME_TIPS, LOGIN_ANNOUNCE, LOGIN_CHECK, GAME_TIPS, GET_MISSION, LOGIN_ANNOUNCE,
LOGIN_RETURN_SIGN, MONTHLY_PASS_NOTICE) LOGIN_CHECK, LOGIN_RETURN_SIGN,
MONTHLY_PASS_NOTICE)
from module.handler.info_handler import InfoHandler from module.handler.info_handler import InfoHandler
from module.logger import logger from module.logger import logger
from module.map.assets import (FLEET_PREPARATION, MAP_PREPARATION, from module.map.assets import (FLEET_PREPARATION, MAP_PREPARATION,
@@ -14,6 +15,7 @@ from module.map.assets import (FLEET_PREPARATION, MAP_PREPARATION,
from module.ocr.ocr import Ocr from module.ocr.ocr import Ocr
from module.os_handler.assets import (EXCHANGE_CHECK, RESET_FLEET_PREPARATION, from module.os_handler.assets import (EXCHANGE_CHECK, RESET_FLEET_PREPARATION,
RESET_TICKET_POPUP) RESET_TICKET_POPUP)
from module.battle_pass.assets import PURCHASE_POPUP
from module.raid.assets import RAID_FLEET_PREPARATION from module.raid.assets import RAID_FLEET_PREPARATION
from module.ui.assets import (BACK_ARROW, DORM_FEED_CANCEL, DORM_INFO, from module.ui.assets import (BACK_ARROW, DORM_FEED_CANCEL, DORM_INFO,
DORM_TROPHY_CONFIRM, EVENT_LIST_CHECK, GOTO_MAIN, DORM_TROPHY_CONFIRM, EVENT_LIST_CHECK, GOTO_MAIN,
@@ -399,6 +401,11 @@ class UI(InfoHandler):
# Battle pass is about to expire and player has uncollected battle pass rewards # Battle pass is about to expire and player has uncollected battle pass rewards
if self.appear_then_click(BATTLE_PASS_NOTICE, offset=(30, 30), interval=3): if self.appear_then_click(BATTLE_PASS_NOTICE, offset=(30, 30), interval=3):
return True return True
if self.appear_then_click(PURCHASE_POPUP, offset=(44, -77, 84, -37), interval=3):
return True
# Item expired offset=(37, 72), skin expired, offset=(24, 68)
if self.appear_then_click(GET_MISSION, offset=(-6, 48, 54, 88), interval=3):
return True
return False return False
@@ -421,6 +428,7 @@ class UI(InfoHandler):
if self.appear_then_click(RESET_FLEET_PREPARATION, offset=(30, 30), interval=3): if self.appear_then_click(RESET_FLEET_PREPARATION, offset=(30, 30), interval=3):
self._opsi_reset_fleet_preparation_click += 1 self._opsi_reset_fleet_preparation_click += 1
self.interval_reset(FLEET_PREPARATION) self.interval_reset(FLEET_PREPARATION)
self.interval_reset(RESET_TICKET_POPUP)
return True return True
if self.appear(EXCHANGE_CHECK, offset=(30, 30), interval=3): if self.appear(EXCHANGE_CHECK, offset=(30, 30), interval=3):
logger.info(f'UI additional: {EXCHANGE_CHECK} -> {GOTO_MAIN}') logger.info(f'UI additional: {EXCHANGE_CHECK} -> {GOTO_MAIN}')