2020-04-16 14:05:37 +08:00
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import time
|
2020-04-17 23:35:20 +08:00
|
|
|
from datetime import datetime
|
2020-04-16 14:05:37 +08:00
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
from module.config.config import AzurLaneConfig
|
2020-04-16 14:05:37 +08:00
|
|
|
from module.logger import logger, pyw_name, log_file
|
2020-06-17 00:36:05 +08:00
|
|
|
|
2020-06-16 08:14:47 +08:00
|
|
|
from module.device.device import Device
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
|
2020-06-22 05:14:16 +08:00
|
|
|
class AzurLaneAutoScript:
|
2020-04-08 00:50:39 +08:00
|
|
|
def __init__(self, ini_name=''):
|
|
|
|
if not ini_name:
|
|
|
|
ini_name = pyw_name
|
|
|
|
ini_name = ini_name.lower()
|
|
|
|
self.config = AzurLaneConfig(ini_name)
|
2020-06-16 08:14:47 +08:00
|
|
|
self.device = None
|
2020-03-29 01:22:46 +08:00
|
|
|
|
2020-04-16 14:05:37 +08:00
|
|
|
def run(self, command):
|
2020-06-06 21:53:31 +08:00
|
|
|
self.config.start_time = datetime.now()
|
2020-04-16 14:05:37 +08:00
|
|
|
try:
|
2020-06-16 08:14:47 +08:00
|
|
|
self.device = Device(config=self.config)
|
2020-04-16 14:05:37 +08:00
|
|
|
self.__getattribute__(command.lower())()
|
|
|
|
except Exception as e:
|
|
|
|
logger.exception(e)
|
|
|
|
|
|
|
|
if self.config.ENABLE_ERROR_LOG_AND_SCREENSHOT_SAVE:
|
|
|
|
folder = f'./log/error/{int(time.time() * 1000)}'
|
|
|
|
logger.info(f'Saving error: {folder}')
|
|
|
|
os.mkdir(folder)
|
2020-04-17 16:20:53 +08:00
|
|
|
for data in logger.screenshot_deque:
|
2020-04-17 23:35:20 +08:00
|
|
|
image_time = datetime.strftime(data['time'], '%Y-%m-%d_%H-%M-%S-%f')
|
|
|
|
data['image'].save(f'{folder}/{image_time}.png')
|
2020-04-16 14:05:37 +08:00
|
|
|
with open(log_file, 'r') as f:
|
|
|
|
start = 0
|
|
|
|
for index, line in enumerate(f.readlines()):
|
|
|
|
if re.search('\+-{15,}\+', line):
|
|
|
|
start = index
|
|
|
|
with open(log_file, 'r') as f:
|
|
|
|
text = f.readlines()[start - 2:]
|
|
|
|
with open(f'{folder}/log.txt', 'w') as f:
|
|
|
|
f.writelines(text)
|
|
|
|
|
2020-06-05 10:54:29 +08:00
|
|
|
def reward_when_finished(self):
|
|
|
|
from module.reward.reward import Reward
|
2020-06-16 08:14:47 +08:00
|
|
|
az = Reward(self.config, device=self.device)
|
2020-06-05 10:54:29 +08:00
|
|
|
az.reward_loop()
|
2020-06-22 05:29:26 +08:00
|
|
|
self.update_check()
|
2020-06-05 10:54:29 +08:00
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
def setting(self):
|
|
|
|
for key, value in self.config.config['Setting'].items():
|
|
|
|
print(f'{key} = {value}')
|
|
|
|
|
|
|
|
logger.hr('Settings saved')
|
2020-06-22 05:14:16 +08:00
|
|
|
self.update_check()
|
2020-06-03 02:39:03 +08:00
|
|
|
self.config.config_check()
|
2020-03-29 01:22:46 +08:00
|
|
|
|
2020-06-22 05:14:16 +08:00
|
|
|
def update_check(self):
|
|
|
|
from module.update import Update
|
|
|
|
ad = Update(self.config)
|
|
|
|
if self.config.UPDATE_CHECK:
|
|
|
|
ad.get_local_commit()
|
2020-06-16 11:30:50 +08:00
|
|
|
|
2020-04-01 22:40:21 +08:00
|
|
|
def reward(self):
|
|
|
|
for key, value in self.config.config['Reward'].items():
|
|
|
|
print(f'{key} = {value}')
|
|
|
|
|
|
|
|
logger.hr('Reward Settings saved')
|
2020-06-22 05:14:16 +08:00
|
|
|
self.update_check()
|
2020-06-05 10:54:29 +08:00
|
|
|
self.reward_when_finished()
|
2020-04-01 22:40:21 +08:00
|
|
|
|
2020-04-01 02:53:28 +08:00
|
|
|
def emulator(self):
|
|
|
|
for key, value in self.config.config['Emulator'].items():
|
|
|
|
print(f'{key} = {value}')
|
|
|
|
|
|
|
|
logger.hr('Emulator saved')
|
2020-06-22 05:14:16 +08:00
|
|
|
self.update_check()
|
2020-04-10 14:18:10 +08:00
|
|
|
from module.handler.login import LoginHandler
|
2020-06-16 08:14:47 +08:00
|
|
|
az = LoginHandler(self.config, device=self.device)
|
2020-05-06 23:53:25 +08:00
|
|
|
if az.app_ensure_start():
|
|
|
|
from module.reward.reward import Reward
|
2020-06-16 08:14:47 +08:00
|
|
|
az = Reward(self.config, device=self.device)
|
2020-05-06 23:53:25 +08:00
|
|
|
az.reward()
|
2020-04-01 02:53:28 +08:00
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
def main(self):
|
|
|
|
"""
|
|
|
|
Method to run main chapter.
|
|
|
|
"""
|
|
|
|
from module.campaign.run import CampaignRun
|
2020-06-16 08:14:47 +08:00
|
|
|
az = CampaignRun(self.config, device=self.device)
|
2020-03-29 01:22:46 +08:00
|
|
|
az.run(self.config.CAMPAIGN_NAME)
|
2020-06-05 10:54:29 +08:00
|
|
|
self.reward_when_finished()
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
def daily(self):
|
|
|
|
"""
|
|
|
|
Method to run daily missions.
|
|
|
|
"""
|
|
|
|
if self.config.ENABLE_DAILY_MISSION:
|
|
|
|
from module.daily.daily import Daily
|
2020-06-16 08:14:47 +08:00
|
|
|
az = Daily(self.config, device=self.device)
|
2020-03-29 01:22:46 +08:00
|
|
|
if not az.record_executed_since():
|
|
|
|
az.run()
|
|
|
|
az.record_save()
|
|
|
|
|
|
|
|
if self.config.ENABLE_HARD_CAMPAIGN:
|
|
|
|
from module.hard.hard import CampaignHard
|
2020-06-16 08:14:47 +08:00
|
|
|
az = CampaignHard(self.config, device=self.device)
|
2020-03-29 01:22:46 +08:00
|
|
|
if not az.record_executed_since():
|
|
|
|
az.run()
|
|
|
|
az.record_save()
|
|
|
|
|
2020-06-22 05:14:16 +08:00
|
|
|
if self.config.ENABLE_EVENT_NAME_AB:
|
|
|
|
from module.event.campaign_ab import CampaignAB
|
|
|
|
az = CampaignAB(self.config, device=self.device)
|
|
|
|
az.run_event_daily()
|
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
if self.config.ENABLE_EXERCISE:
|
|
|
|
from module.exercise.exercise import Exercise
|
2020-06-16 08:14:47 +08:00
|
|
|
az = Exercise(self.config, device=self.device)
|
2020-03-29 01:22:46 +08:00
|
|
|
if not az.record_executed_since():
|
|
|
|
az.run()
|
|
|
|
az.record_save()
|
|
|
|
|
2020-06-05 10:54:29 +08:00
|
|
|
self.reward_when_finished()
|
2020-04-10 15:19:02 +08:00
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
def event(self):
|
|
|
|
"""
|
|
|
|
Method to run event.
|
|
|
|
"""
|
|
|
|
from module.campaign.run import CampaignRun
|
2020-06-16 08:14:47 +08:00
|
|
|
az = CampaignRun(self.config, device=self.device)
|
2020-06-16 20:49:29 +08:00
|
|
|
az.run(self.config.CAMPAIGN_EVENT, folder=self.config.EVENT_NAME)
|
2020-06-05 10:54:29 +08:00
|
|
|
self.reward_when_finished()
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
def event_daily_ab(self):
|
|
|
|
from module.event.campaign_ab import CampaignAB
|
2020-06-16 08:14:47 +08:00
|
|
|
az = CampaignAB(self.config, device=self.device)
|
2020-03-29 01:22:46 +08:00
|
|
|
az.run_event_daily()
|
2020-06-05 10:54:29 +08:00
|
|
|
self.reward_when_finished()
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
def semi_auto(self):
|
|
|
|
from module.daemon.daemon import AzurLaneDaemon
|
2020-06-16 08:14:47 +08:00
|
|
|
az = AzurLaneDaemon(self.config, device=self.device)
|
2020-03-29 01:22:46 +08:00
|
|
|
az.daemon()
|
|
|
|
|
|
|
|
def c72_mystery_farming(self):
|
|
|
|
from module.campaign.run import CampaignRun
|
2020-06-16 08:14:47 +08:00
|
|
|
az = CampaignRun(self.config, device=self.device)
|
2020-03-29 01:22:46 +08:00
|
|
|
az.run('campaign_7_2_mystery_farming')
|
2020-06-05 10:54:29 +08:00
|
|
|
self.reward_when_finished()
|
2020-03-29 01:22:46 +08:00
|
|
|
|
|
|
|
def c124_leveling(self):
|
|
|
|
from module.campaign.run import CampaignRun
|
2020-06-16 08:14:47 +08:00
|
|
|
az = CampaignRun(self.config, device=self.device)
|
2020-03-29 01:22:46 +08:00
|
|
|
az.run('campaign_12_4_leveling')
|
2020-06-05 10:54:29 +08:00
|
|
|
self.reward_when_finished()
|
2020-03-29 01:22:46 +08:00
|
|
|
|
2020-05-04 21:48:52 +08:00
|
|
|
def c122_leveling(self):
|
|
|
|
from module.campaign.run import CampaignRun
|
2020-06-16 08:14:47 +08:00
|
|
|
az = CampaignRun(self.config, device=self.device)
|
2020-05-04 21:48:52 +08:00
|
|
|
az.run('campaign_12_2_leveling')
|
2020-06-05 10:54:29 +08:00
|
|
|
self.reward_when_finished()
|
2020-05-04 21:48:52 +08:00
|
|
|
|
2020-03-29 01:22:46 +08:00
|
|
|
def retire(self):
|
|
|
|
from module.retire.retirement import Retirement
|
2020-06-16 08:14:47 +08:00
|
|
|
az = Retirement(self.config, device=self.device)
|
|
|
|
az.device.screenshot()
|
2020-03-29 01:22:46 +08:00
|
|
|
az.retire_ships(amount=2000)
|
|
|
|
|
|
|
|
|
2020-03-31 14:21:55 +08:00
|
|
|
# alas = AzurLaneAutoScript()
|
|
|
|
# alas.reward()
|