mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-27 02:27:12 +00:00
Optimize: Reuse device instance in the same function
- Speed up retire confirm - Set default server to CN - Improve log appearance of aScreenCap init
This commit is contained in:
parent
2e26d0a1e1
commit
d0867262e2
34
alas.py
34
alas.py
@ -5,6 +5,7 @@ from datetime import datetime
|
||||
|
||||
from module.config.config import AzurLaneConfig
|
||||
from module.logger import logger, pyw_name, log_file
|
||||
from module.device.device import Device
|
||||
|
||||
|
||||
class AzurLaneAutoScript:
|
||||
@ -13,10 +14,12 @@ class AzurLaneAutoScript:
|
||||
ini_name = pyw_name
|
||||
ini_name = ini_name.lower()
|
||||
self.config = AzurLaneConfig(ini_name)
|
||||
self.device = None
|
||||
|
||||
def run(self, command):
|
||||
self.config.start_time = datetime.now()
|
||||
try:
|
||||
self.device = Device(config=self.config)
|
||||
self.__getattribute__(command.lower())()
|
||||
except Exception as e:
|
||||
logger.exception(e)
|
||||
@ -40,7 +43,7 @@ class AzurLaneAutoScript:
|
||||
|
||||
def reward_when_finished(self):
|
||||
from module.reward.reward import Reward
|
||||
az = Reward(self.config)
|
||||
az = Reward(self.config, device=self.device)
|
||||
az.reward_loop()
|
||||
|
||||
def setting(self):
|
||||
@ -63,10 +66,10 @@ class AzurLaneAutoScript:
|
||||
|
||||
logger.hr('Emulator saved')
|
||||
from module.handler.login import LoginHandler
|
||||
az = LoginHandler(self.config)
|
||||
az = LoginHandler(self.config, device=self.device)
|
||||
if az.app_ensure_start():
|
||||
from module.reward.reward import Reward
|
||||
az = Reward(self.config)
|
||||
az = Reward(self.config, device=self.device)
|
||||
az.reward()
|
||||
|
||||
def main(self):
|
||||
@ -74,7 +77,7 @@ class AzurLaneAutoScript:
|
||||
Method to run main chapter.
|
||||
"""
|
||||
from module.campaign.run import CampaignRun
|
||||
az = CampaignRun(self.config)
|
||||
az = CampaignRun(self.config, device=self.device)
|
||||
az.run(self.config.CAMPAIGN_NAME)
|
||||
self.reward_when_finished()
|
||||
|
||||
@ -84,21 +87,21 @@ class AzurLaneAutoScript:
|
||||
"""
|
||||
if self.config.ENABLE_DAILY_MISSION:
|
||||
from module.daily.daily import Daily
|
||||
az = Daily(self.config)
|
||||
az = Daily(self.config, device=self.device)
|
||||
if not az.record_executed_since():
|
||||
az.run()
|
||||
az.record_save()
|
||||
|
||||
if self.config.ENABLE_HARD_CAMPAIGN:
|
||||
from module.hard.hard import CampaignHard
|
||||
az = CampaignHard(self.config)
|
||||
az = CampaignHard(self.config, device=self.device)
|
||||
if not az.record_executed_since():
|
||||
az.run()
|
||||
az.record_save()
|
||||
|
||||
if self.config.ENABLE_EXERCISE:
|
||||
from module.exercise.exercise import Exercise
|
||||
az = Exercise(self.config)
|
||||
az = Exercise(self.config, device=self.device)
|
||||
if not az.record_executed_since():
|
||||
az.run()
|
||||
az.record_save()
|
||||
@ -110,42 +113,43 @@ class AzurLaneAutoScript:
|
||||
Method to run event.
|
||||
"""
|
||||
from module.campaign.run import CampaignRun
|
||||
az = CampaignRun(self.config)
|
||||
az.run(self.config.CAMPAIGN_EVENT, folder=self.config.EVENT_NAME)
|
||||
az = CampaignRun(self.config, device=self.device)
|
||||
az.run(self.config.CAMPAIGN_EVENT)
|
||||
self.reward_when_finished()
|
||||
|
||||
def event_daily_ab(self):
|
||||
from module.event.campaign_ab import CampaignAB
|
||||
az = CampaignAB(self.config)
|
||||
az = CampaignAB(self.config, device=self.device)
|
||||
az.run_event_daily()
|
||||
self.reward_when_finished()
|
||||
|
||||
def semi_auto(self):
|
||||
from module.daemon.daemon import AzurLaneDaemon
|
||||
az = AzurLaneDaemon(self.config)
|
||||
az = AzurLaneDaemon(self.config, device=self.device)
|
||||
az.daemon()
|
||||
|
||||
def c72_mystery_farming(self):
|
||||
from module.campaign.run import CampaignRun
|
||||
az = CampaignRun(self.config)
|
||||
az = CampaignRun(self.config, device=self.device)
|
||||
az.run('campaign_7_2_mystery_farming')
|
||||
self.reward_when_finished()
|
||||
|
||||
def c124_leveling(self):
|
||||
from module.campaign.run import CampaignRun
|
||||
az = CampaignRun(self.config)
|
||||
az = CampaignRun(self.config, device=self.device)
|
||||
az.run('campaign_12_4_leveling')
|
||||
self.reward_when_finished()
|
||||
|
||||
def c122_leveling(self):
|
||||
from module.campaign.run import CampaignRun
|
||||
az = CampaignRun(self.config)
|
||||
az = CampaignRun(self.config, device=self.device)
|
||||
az.run('campaign_12_2_leveling')
|
||||
self.reward_when_finished()
|
||||
|
||||
def retire(self):
|
||||
from module.retire.retirement import Retirement
|
||||
az = Retirement(self.config)
|
||||
az = Retirement(self.config, device=self.device)
|
||||
az.device.screenshot()
|
||||
az.retire_ships(amount=2000)
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@ enable_fast_forward = yes
|
||||
if_count_greater_than = 0
|
||||
if_time_reach = 0
|
||||
if_oil_lower_than = 2000
|
||||
if_trigger_emotion_control = yes
|
||||
if_trigger_emotion_control = no
|
||||
if_dock_full = no
|
||||
enable_fleet_control = yes
|
||||
enable_map_fleet_lock = yes
|
||||
|
@ -2,4 +2,4 @@
|
||||
This file stores server, such as 'cn', 'en'.
|
||||
Use 'import module.config.server as server' to import, don't use 'from xxx import xxx'.
|
||||
"""
|
||||
server = 'default'
|
||||
server = 'cn' # Setting default to cn, will avoid errors when using dev_tools
|
||||
|
@ -74,15 +74,14 @@ class Connection:
|
||||
|
||||
arc = self.adb_exec_out(['getprop', 'ro.product.cpu.abi'], serial=self.serial).decode('utf-8').strip()
|
||||
sdk = self.adb_exec_out(['getprop', 'ro.build.version.sdk'], serial=self.serial).decode('utf-8').strip()
|
||||
logger.attr('CPU_Architecture', arc)
|
||||
logger.attr('Android_SDK_version', sdk)
|
||||
logger.info(f'cpu_arc: {arc}, sdk_ver: {sdk}')
|
||||
|
||||
if int(sdk) not in range(21, 26) or not os.path.exists(f'./ascreencap/{arc}'):
|
||||
logger.warning('No suitable version of aScreenCap lib is available locally')
|
||||
exit(1)
|
||||
|
||||
filepath = f'./ascreencap/{arc}/ascreencap'
|
||||
logger.info(f'Pushing {filepath} to {self.config.ASCREENCAP_FILEPATH}')
|
||||
logger.info(f'pushing {filepath}')
|
||||
self.adb_command(['push', filepath, self.config.ASCREENCAP_FILEPATH], serial=self.serial)
|
||||
|
||||
logger.info(f'chmod 0777 {self.config.ASCREENCAP_FILEPATH}')
|
||||
|
@ -128,7 +128,7 @@ class Retirement(Enhancement):
|
||||
if self.appear_then_click(EQUIP_CONFIRM_2, offset=30, interval=2):
|
||||
executed = True
|
||||
continue
|
||||
if self.appear(GET_ITEMS_1, interval=2):
|
||||
if self.appear(GET_ITEMS_1, interval=0.5):
|
||||
self.device.click(GET_ITEMS_1_RETIREMENT_SAVE)
|
||||
self.interval_reset(SHIP_CONFIRM)
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user