Skip to content

Commit

Permalink
Merge pull request #2451 from LmeSzinc/dev
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
LmeSzinc authored Apr 4, 2023
2 parents 929f649 + 61c4502 commit ac41f1c
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 28 deletions.
Binary file modified assets/tw/handler/MAP_AMBUSH_EVADE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions module/coalition/coalition.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def coalition_execute_once(self, event, stage, fleet):
Campaign_UseAutoSearch=False,
Fleet_FleetOrder='fleet1_all_fleet2_standby',
)
if self.config.Coalition_Fleet == 'single' and self.config.Emotion_Fleet1Control == 'prevent_red_face':
logger.warning('AL does not allow single coalition with emotion < 30, '
'emotion control is forced to prevent_yellow_face')
self.config.override(Emotion_Fleet1Control='prevent_yellow_face')
if stage == 'sp':
# Multiple fleets are required in SP
self.config.override(
Expand Down
1 change: 1 addition & 0 deletions module/daemon/uncensored.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def run(self):
# Back to root folder
os.chdir(prev)
logger.hr('Restart AzurLane', level=1)
self.config.override(Error_HandleError=True)
self.device.app_stop()
self.device.app_start()
self.handle_app_login()
Expand Down
2 changes: 1 addition & 1 deletion module/daily/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def daily_end():
result = self.daily_enter(button)
if not result:
break
if self.daily_current == 2:
if self.daily_current == self.supply_line_disruption_index:
logger.info('Submarine daily skip not unlocked, skip')
self.ui_click(click_button=BACK_ARROW, check_button=daily_enter_check, skip_first_screenshot=True)
break
Expand Down
36 changes: 27 additions & 9 deletions module/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,22 @@ def __init__(self, *args, **kwargs):

# Auto-select the fastest screenshot method
if not self.config.is_template_config and self.config.Emulator_ScreenshotMethod == 'auto':
# Check resolution first
self.resolution_check_uiautomator2()
# Perform benchmark
from module.daemon.benchmark import Benchmark
bench = Benchmark(config=self.config, device=self)
method = bench.run_simple_screenshot_benchmark()
# Set
self.config.Emulator_ScreenshotMethod = method
self.run_simple_screenshot_benchmark()

def run_simple_screenshot_benchmark(self):
"""
Perform a screenshot method benchmark, test 3 times on each method.
The fastest one will be set into config.
"""
logger.info('run_simple_screenshot_benchmark')
# Check resolution first
self.resolution_check_uiautomator2()
# Perform benchmark
from module.daemon.benchmark import Benchmark
bench = Benchmark(config=self.config, device=self)
method = bench.run_simple_screenshot_benchmark()
# Set
self.config.Emulator_ScreenshotMethod = method

def handle_night_commission(self, daily_trigger='21:00', threshold=30):
"""
Expand Down Expand Up @@ -70,7 +78,17 @@ def screenshot(self):
np.ndarray:
"""
self.stuck_record_check()
super().screenshot()

try:
super().screenshot()
except RequestHumanTakeover:
if not self.ascreencap_available:
logger.error('aScreenCap unavailable on current device, fallback to auto')
self.run_simple_screenshot_benchmark()
super().screenshot()
else:
raise

if self.handle_night_commission():
super().screenshot()

Expand Down
7 changes: 5 additions & 2 deletions module/device/method/ascreencap.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@ class AScreenCap(Connection):
__screenshot_method = [0, 1, 2]
__screenshot_method_fixed = [0, 1, 2]
__bytepointer = 0
ascreencap_available = True

def ascreencap_init(self):
logger.hr('aScreenCap init')
self.__bytepointer = 0
self.ascreencap_available = True

arc = self.cpu_abi
sdk = self.sdk_ver
Expand All @@ -94,8 +96,9 @@ def ascreencap_init(self):
ver = "0"
filepath = os.path.join(self.config.ASCREENCAP_FILEPATH_LOCAL, ver, arc, 'ascreencap')
if not os.path.exists(filepath):
logger.critical('No suitable version of aScreenCap lib available for this device')
logger.critical('Please use ADB or uiautomator2 for screenshots instead')
self.ascreencap_available = False
logger.error('No suitable version of aScreenCap lib available for this device, '
'please use other screenshot methods instead')
raise RequestHumanTakeover

logger.info(f'pushing {filepath}')
Expand Down
24 changes: 17 additions & 7 deletions module/equipment/equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from module.base.timer import Timer
from module.equipment.assets import *
from module.logger import logger
from module.retire.assets import DOCK_CHECK
from module.retire.assets import EQUIP_CONFIRM as RETIRE_EQUIP_CONFIRM
from module.storage.storage import StorageHandler
from module.ui.assets import BACK_ARROW
from module.ui.navbar import Navbar
from module.ui.switch import Switch

Expand Down Expand Up @@ -59,23 +61,31 @@ def equip_view_next(self, check_button=EQUIPMENT_OPEN):
def equip_view_prev(self, check_button=EQUIPMENT_OPEN):
return self._equip_view_swipe(distance=SWIPE_DISTANCE, check_button=check_button)

def equip_enter(self, click_button, check_button=EQUIPMENT_OPEN, long_click=True):
def equip_enter(self, click_button, check_button=EQUIPMENT_OPEN, long_click=True, skil_first_screenshot=True):
enter_timer = Timer(10)

while 1:
if skil_first_screenshot:
skil_first_screenshot = False
else:
self.device.screenshot()

# End
if self.appear(check_button):
break

# Long click accidentally became normal click, exit from dock
if self.appear(DOCK_CHECK, offset=(20, 20), interval=3):
logger.info(f'equip_enter {DOCK_CHECK} -> {BACK_ARROW}')
self.device.click(BACK_ARROW)
continue
if enter_timer.reached():
if long_click:
self.device.long_click(click_button, duration=(1.5, 1.7))
else:
self.device.click(click_button)
enter_timer.reset()

self.device.screenshot()

# End
if self.appear(check_button):
break

@cached_property
def _equip_side_navbar(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion module/handler/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
MAP_AIR_RAID = Button(area={'cn': (350, 447, 1280, 472), 'en': (350, 447, 1280, 472), 'jp': (350, 447, 1280, 472), 'tw': (350, 447, 1280, 472)}, color={'cn': (154, 43, 46), 'en': (154, 43, 46), 'jp': (154, 43, 46), 'tw': (154, 43, 46)}, button={'cn': (350, 447, 1280, 472), 'en': (350, 447, 1280, 472), 'jp': (350, 447, 1280, 472), 'tw': (350, 447, 1280, 472)}, file={'cn': './assets/cn/handler/MAP_AIR_RAID.png', 'en': './assets/en/handler/MAP_AIR_RAID.png', 'jp': './assets/jp/handler/MAP_AIR_RAID.png', 'tw': './assets/tw/handler/MAP_AIR_RAID.png'})
MAP_AMBUSH = Button(area={'cn': (261, 433, 1280, 449), 'en': (261, 433, 1280, 449), 'jp': (261, 433, 1280, 449), 'tw': (261, 433, 1280, 449)}, color={'cn': (161, 41, 43), 'en': (161, 41, 43), 'jp': (161, 41, 43), 'tw': (161, 41, 43)}, button={'cn': (261, 433, 1280, 449), 'en': (261, 433, 1280, 449), 'jp': (261, 433, 1280, 449), 'tw': (261, 433, 1280, 449)}, file={'cn': './assets/cn/handler/MAP_AMBUSH.png', 'en': './assets/en/handler/MAP_AMBUSH.png', 'jp': './assets/jp/handler/MAP_AMBUSH.png', 'tw': './assets/tw/handler/MAP_AMBUSH.png'})
MAP_AMBUSH_ATTACK = Button(area={'cn': (804, 457, 876, 488), 'en': (791, 463, 888, 485), 'jp': (804, 457, 876, 488), 'tw': (804, 455, 876, 486)}, color={'cn': (139, 168, 210), 'en': (164, 187, 221), 'jp': (150, 175, 212), 'tw': (149, 175, 213)}, button={'cn': (755, 446, 925, 501), 'en': (753, 443, 927, 503), 'jp': (757, 447, 925, 501), 'tw': (762, 443, 927, 499)}, file={'cn': './assets/cn/handler/MAP_AMBUSH_ATTACK.png', 'en': './assets/en/handler/MAP_AMBUSH_ATTACK.png', 'jp': './assets/jp/handler/MAP_AMBUSH_ATTACK.png', 'tw': './assets/tw/handler/MAP_AMBUSH_ATTACK.png'})
MAP_AMBUSH_EVADE = Button(area={'cn': (1029, 457, 1101, 487), 'en': (1021, 459, 1110, 483), 'jp': (1031, 458, 1101, 487), 'tw': (1029, 457, 1101, 487)}, color={'cn': (199, 195, 196), 'en': (200, 197, 198), 'jp': (239, 194, 138), 'tw': (199, 195, 196)}, button={'cn': (979, 444, 1152, 502), 'en': (978, 443, 1153, 503), 'jp': (979, 444, 1151, 502), 'tw': (979, 444, 1152, 502)}, file={'cn': './assets/cn/handler/MAP_AMBUSH_EVADE.png', 'en': './assets/en/handler/MAP_AMBUSH_EVADE.png', 'jp': './assets/jp/handler/MAP_AMBUSH_EVADE.png', 'tw': './assets/tw/handler/MAP_AMBUSH_EVADE.png'})
MAP_AMBUSH_EVADE = Button(area={'cn': (1029, 457, 1101, 487), 'en': (1021, 459, 1110, 483), 'jp': (1031, 458, 1101, 487), 'tw': (1071, 457, 1101, 487)}, color={'cn': (199, 195, 196), 'en': (200, 197, 198), 'jp': (239, 194, 138), 'tw': (247, 209, 164)}, button={'cn': (979, 444, 1152, 502), 'en': (978, 443, 1153, 503), 'jp': (979, 444, 1151, 502), 'tw': (979, 444, 1152, 502)}, file={'cn': './assets/cn/handler/MAP_AMBUSH_EVADE.png', 'en': './assets/en/handler/MAP_AMBUSH_EVADE.png', 'jp': './assets/jp/handler/MAP_AMBUSH_EVADE.png', 'tw': './assets/tw/handler/MAP_AMBUSH_EVADE.png'})
MAP_BUFF = Button(area={'cn': (145, 115, 437, 159), 'en': (145, 115, 437, 159), 'jp': (145, 115, 437, 159), 'tw': (145, 115, 437, 159)}, color={'cn': (103, 118, 118), 'en': (103, 118, 118), 'jp': (103, 118, 118), 'tw': (103, 118, 118)}, button={'cn': (145, 115, 437, 159), 'en': (145, 115, 437, 159), 'jp': (145, 115, 437, 159), 'tw': (145, 115, 437, 159)}, file={'cn': './assets/cn/handler/MAP_BUFF.png', 'en': './assets/en/handler/MAP_BUFF.png', 'jp': './assets/jp/handler/MAP_BUFF.png', 'tw': './assets/tw/handler/MAP_BUFF.png'})
MAP_CLEAR_PERCENTAGE = Button(area={'cn': (626, 185, 970, 190), 'en': (626, 185, 970, 190), 'jp': (626, 185, 970, 190), 'tw': (626, 185, 970, 190)}, color={'cn': (245, 213, 88), 'en': (245, 213, 88), 'jp': (245, 213, 88), 'tw': (245, 213, 88)}, button={'cn': (626, 185, 970, 190), 'en': (626, 185, 970, 190), 'jp': (626, 185, 970, 190), 'tw': (626, 185, 970, 190)}, file={'cn': './assets/cn/handler/MAP_CLEAR_PERCENTAGE.png', 'en': './assets/en/handler/MAP_CLEAR_PERCENTAGE.png', 'jp': './assets/jp/handler/MAP_CLEAR_PERCENTAGE.png', 'tw': './assets/tw/handler/MAP_CLEAR_PERCENTAGE.png'})
MAP_ENEMY_SEARCHING = Button(area={'cn': (617, 359, 651, 373), 'en': (589, 348, 602, 358), 'jp': (678, 358, 719, 368), 'tw': (678, 358, 719, 368)}, color={'cn': (237, 163, 159), 'en': (187, 130, 116), 'jp': (245, 172, 171), 'tw': (245, 172, 171)}, button={'cn': (617, 359, 651, 373), 'en': (589, 348, 602, 358), 'jp': (678, 358, 719, 368), 'tw': (678, 358, 719, 368)}, file={'cn': './assets/cn/handler/MAP_ENEMY_SEARCHING.png', 'en': './assets/en/handler/MAP_ENEMY_SEARCHING.png', 'jp': './assets/jp/handler/MAP_ENEMY_SEARCHING.png', 'tw': './assets/tw/handler/MAP_ENEMY_SEARCHING.png'})
Expand Down
2 changes: 1 addition & 1 deletion module/handler/info_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def handle_urgent_commission(self, drop=None):
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')
logger.error('Detected hot fixes from game server, game died')
raise GameNotRunningError
self._hot_fix_check_wait.clear()

Expand Down
6 changes: 5 additions & 1 deletion module/map/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from module.base.timer import Timer
from module.base.utils import area_offset
from module.combat.assets import GET_ITEMS_1, GET_ITEMS_1_RYZA
from module.exception import CampaignEnd, MapDetectionError
from module.exception import CampaignEnd, GameNotRunningError, MapDetectionError
from module.handler.assets import AUTO_SEARCH_MENU_CONTINUE, GAME_TIPS
from module.logger import logger
from module.map.map_base import CampaignMap, location2node
Expand Down Expand Up @@ -179,6 +179,10 @@ def _update(self, camera=True):
logger.warning(string)
x, y = string.split('=')[1].strip('() ').split(',')
self._map_swipe((-int(x.strip()), -int(y.strip())))
# Finally check if game is alive
elif not self.device.app_is_running():
logger.error('Trying to update camera but game died')
raise GameNotRunningError
else:
raise e

Expand Down
10 changes: 8 additions & 2 deletions module/os/globe_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from module.os.globe_detection import GLOBE_MAP_SHAPE, GlobeDetection
from module.os.globe_operation import GlobeOperation
from module.os.globe_zone import Zone, ZoneManager
from module.os_ash.assets import ASH_SHOWDOWN, ASH_QUIT
from module.os_handler.assets import AUTO_SEARCH_REWARD


Expand Down Expand Up @@ -37,9 +38,9 @@ def globe_update(self):
self.appear(MAP_GOTO_GLOBE_FOG, interval=3)
timeout.reset()
continue
# Encountered only in strongholds; AL will not prevent
# zone exit even with left over exploration rewards in map
if self.appear_then_click(MAP_GOTO_GLOBE_FOG, interval=3):
# Encountered only in strongholds; AL will not prevent
# zone exit even with left over exploration rewards in map
self.interval_reset(MAP_GOTO_GLOBE)
timeout.reset()
continue
Expand All @@ -56,6 +57,11 @@ def globe_update(self):
if self.handle_popup_confirm('GOTO_GLOBE'):
timeout.reset()
continue
# Don't know why but AL just entered META page
if self.appear(ASH_SHOWDOWN, offset=(20, 20), interval=3):
self.device.click(ASH_QUIT)
timeout.reset()
continue

if self.is_in_globe():
break
Expand Down
3 changes: 3 additions & 0 deletions module/os_handler/map_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def order_enter(self, skip_first_screenshot=True):
# A game bug that AUTO_SEARCH_REWARD from the last cleared zone popups
if self.appear_then_click(AUTO_SEARCH_REWARD, offset=(50, 50), interval=3):
continue
# Skip TB guidance if user didn't have their game settings correctly set
if self.handle_map_event():
continue

def order_quit(self):
"""
Expand Down
14 changes: 12 additions & 2 deletions module/os_handler/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from module.base.utils import rgb2gray
from module.combat.assets import GET_ITEMS_1, GET_ITEMS_2
from module.exception import ScriptError
from module.handler.assets import GET_MISSION
from module.logger import logger
from module.os.globe_operation import GlobeOperation
from module.os.globe_zone import ZoneManager
Expand Down Expand Up @@ -65,16 +66,21 @@ def _storage_item_use(self, button, skip_first_screenshot=True):
self.interval_clear(GET_ITEMS_1)
self.interval_clear(GET_ITEMS_2)
self.interval_clear(GET_ADAPTABILITY)
self.interval_clear(GET_MISSION)

while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()

if self.appear(STORAGE_CHECK, offset=(20, 20), interval=5):
self.device.click(button)
# Accidentally clicked on an item, having popups for its info
if self.appear(GET_MISSION, offset=True, interval=2):
logger.info(f'_storage_item_use item info -> {GET_MISSION}')
self.device.click(GET_MISSION)
self.interval_reset(STORAGE_CHECK)
continue
# Item rewards
if self.appear_then_click(STORAGE_USE, offset=(180, 30), interval=5):
self.interval_reset(STORAGE_CHECK)
continue
Expand All @@ -90,6 +96,10 @@ def _storage_item_use(self, button, skip_first_screenshot=True):
self.device.click(CLICK_SAFE_AREA)
success = True
continue
# Use item
if self.appear(STORAGE_CHECK, offset=(20, 20), interval=5):
self.device.click(button)
continue

# End
if success and self.appear(STORAGE_CHECK, offset=(20, 20)):
Expand Down
6 changes: 4 additions & 2 deletions module/ui/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from module.base.decorator import run_once
from module.base.timer import Timer
from module.coalition.assets import FLEET_PREPARATION as COALITION_FLEET_PREPARATION
from module.combat.assets import GET_ITEMS_1, GET_SHIP
from module.combat.assets import GET_ITEMS_1, GET_ITEMS_2, GET_SHIP
from module.exception import (GameNotRunningError, GamePageUnknownError,
RequestHumanTakeover)
from module.exercise.assets import EXERCISE_PREPARATION
Expand Down Expand Up @@ -405,7 +405,9 @@ def ui_page_main_popups(self, get_ship=True):
# Daily reset
if self.appear_then_click(LOGIN_ANNOUNCE, offset=(30, 30), interval=3):
return True
if self.appear_then_click(GET_ITEMS_1, offset=(30, 30), interval=3):
if self.appear_then_click(GET_ITEMS_1, offset=True, interval=3):
return True
if self.appear_then_click(GET_ITEMS_2, offset=True, interval=3):
return True
if get_ship:
if self.appear_then_click(GET_SHIP, interval=5):
Expand Down

0 comments on commit ac41f1c

Please sign in to comment.