2020-04-16 14:05:37 +08:00
|
|
|
import time
|
|
|
|
|
2021-09-14 17:32:23 +08:00
|
|
|
import inflection
|
|
|
|
from cached_property import cached_property
|
|
|
|
|
2021-09-16 00:43:05 +08:00
|
|
|
from module.campaign.gems_farming import GemsFarming
|
2021-09-15 21:33:11 +08:00
|
|
|
from module.campaign.run import CampaignRun
|
2021-09-14 17:32:23 +08:00
|
|
|
from module.commission.commission import RewardCommission
|
|
|
|
from module.config.config import AzurLaneConfig, TaskEnd
|
|
|
|
from module.config.db import Database
|
2020-06-22 07:23:16 +08:00
|
|
|
from module.device.device import Device
|
2020-08-01 17:53:00 +08:00
|
|
|
from module.exception import *
|
|
|
|
from module.handler.login import LoginHandler
|
2021-09-14 17:32:23 +08:00
|
|
|
from module.logger import logger
|
|
|
|
from module.research.research import RewardResearch
|
|
|
|
from module.tactical.tactical_class import RewardTacticalClass
|
2021-09-15 21:33:11 +08:00
|
|
|
from module.ui.ui import UI, page_main
|
2020-06-17 00:36:05 +08:00
|
|
|
|
2020-06-22 07:23:16 +08:00
|
|
|
|
2020-06-22 05:14:16 +08:00
|
|
|
class AzurLaneAutoScript:
|
2021-09-14 17:32:23 +08:00
|
|
|
def __init__(self, config_name='alas'):
|
|
|
|
self.config_name = config_name
|
|
|
|
Database().update_config(config_name)
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def config(self):
|
|
|
|
config = AzurLaneConfig(config_name=self.config_name)
|
|
|
|
return config
|
|
|
|
|
|
|
|
@cached_property
|
|
|
|
def device(self):
|
|
|
|
device = Device(config=self.config)
|
|
|
|
return device
|
2020-03-29 01:22:46 +08:00
|
|
|
|
2020-04-16 14:05:37 +08:00
|
|
|
def run(self, command):
|
2020-08-01 17:53:00 +08:00
|
|
|
while 1:
|
|
|
|
try:
|
2021-09-14 17:32:23 +08:00
|
|
|
self.__getattribute__(command)()
|
2021-09-15 21:33:11 +08:00
|
|
|
UI(config=self.config, device=self.device).ui_ensure(page_main)
|
2021-09-14 17:32:23 +08:00
|
|
|
return True
|
|
|
|
except TaskEnd:
|
|
|
|
return True
|
2020-08-01 17:53:00 +08:00
|
|
|
except GameNotRunningError as e:
|
|
|
|
logger.warning(e)
|
|
|
|
az = LoginHandler(self.config, device=self.device)
|
|
|
|
az.app_restart()
|
2020-11-26 09:49:35 +08:00
|
|
|
az.ensure_no_unfinished_campaign()
|
|
|
|
continue
|
|
|
|
except GameTooManyClickError as e:
|
|
|
|
logger.warning(e)
|
2020-12-30 20:57:01 +08:00
|
|
|
self.save_error_log()
|
2020-11-26 09:49:35 +08:00
|
|
|
az = LoginHandler(self.config, device=self.device)
|
2020-12-30 20:57:01 +08:00
|
|
|
az.handle_game_stuck()
|
2020-08-01 17:53:00 +08:00
|
|
|
continue
|
|
|
|
except GameStuckError as e:
|
|
|
|
logger.warning(e)
|
|
|
|
self.save_error_log()
|
|
|
|
az = LoginHandler(self.config, device=self.device)
|
|
|
|
az.handle_game_stuck()
|
|
|
|
continue
|
2021-02-20 07:09:11 +08:00
|
|
|
except LogisticsRefreshBugHandler as e:
|
|
|
|
logger.warning(e)
|
|
|
|
self.save_error_log()
|
|
|
|
az = LoginHandler(self.config, device=self.device)
|
|
|
|
az.device.app_stop()
|
|
|
|
time.sleep(600)
|
|
|
|
az.app_ensure_start()
|
|
|
|
continue
|
2020-08-01 17:53:00 +08:00
|
|
|
except Exception as e:
|
|
|
|
logger.exception(e)
|
|
|
|
self.save_error_log()
|
2021-09-14 17:32:23 +08:00
|
|
|
return False
|
2020-04-16 14:05:37 +08:00
|
|
|
|
2020-08-01 17:53:00 +08:00
|
|
|
def save_error_log(self):
|
|
|
|
"""
|
|
|
|
Save last 60 screenshots in ./log/error/<timestamp>
|
|
|
|
Save logs to ./log/error/<timestamp>/log.txt
|
|
|
|
"""
|
2021-09-14 17:32:23 +08:00
|
|
|
pass
|
2020-04-01 22:40:21 +08:00
|
|
|
|
2021-09-14 17:32:23 +08:00
|
|
|
def research(self):
|
|
|
|
RewardResearch(config=self.config, device=self.device).run()
|
2020-04-01 22:40:21 +08:00
|
|
|
|
2021-09-14 17:32:23 +08:00
|
|
|
def commission(self):
|
|
|
|
RewardCommission(config=self.config, device=self.device).run()
|
2020-04-01 02:53:28 +08:00
|
|
|
|
2021-09-14 17:32:23 +08:00
|
|
|
def tactical(self):
|
|
|
|
RewardTacticalClass(config=self.config, device=self.device).run()
|
2020-04-01 02:53:28 +08:00
|
|
|
|
2021-09-15 21:33:11 +08:00
|
|
|
def main(self):
|
|
|
|
CampaignRun(config=self.config, device=self.device).run(
|
2021-09-16 00:43:05 +08:00
|
|
|
name=self.config.Campaign_Name,
|
|
|
|
folder=self.config.Campaign_Event,
|
|
|
|
mode=self.config.Campaign_Mode)
|
|
|
|
|
|
|
|
def gems_farming(self):
|
|
|
|
GemsFarming(config=self.config, device=self.device).run(
|
|
|
|
name=self.config.Campaign_Name,
|
|
|
|
folder=self.config.Campaign_Event,
|
2021-09-15 21:33:11 +08:00
|
|
|
mode=self.config.Campaign_Mode)
|
|
|
|
|
2021-09-14 17:32:23 +08:00
|
|
|
def loop(self):
|
|
|
|
while 1:
|
|
|
|
logger.info(f'Scheduler: Start task `{self.config.task}`')
|
|
|
|
success = self.run(inflection.underscore(self.config.task))
|
2020-12-23 18:48:41 +08:00
|
|
|
|
2021-09-14 17:32:23 +08:00
|
|
|
logger.info(f'Scheduler: End task `{self.config.task}`')
|
|
|
|
del self.__dict__['config']
|
2020-12-23 18:48:41 +08:00
|
|
|
|
2021-09-14 17:32:23 +08:00
|
|
|
if not success:
|
|
|
|
break
|
2021-05-15 04:19:55 +08:00
|
|
|
|
2021-04-17 22:20:21 +08:00
|
|
|
|
2021-09-14 17:32:23 +08:00
|
|
|
if __name__ == '__main__':
|
|
|
|
alas = AzurLaneAutoScript()
|
|
|
|
alas.loop()
|