From eb7886df61ab4c8380349a2ab5e6bdab1f763d23 Mon Sep 17 00:00:00 2001 From: LmeSzinc <37934724+LmeSzinc@users.noreply.github.com> Date: Thu, 23 Sep 2021 01:03:39 +0800 Subject: [PATCH] Refactor: Hard module - Add config override - Delete hard equipment change --- alas.py | 6 +++- campaign/campaign_hard/campaign_hard.py | 4 +-- config/template.yaml | 11 +++++++ module/config/args.yaml | 15 +++++++++ module/config/config.py | 19 ++++++++++- module/config/config_generated.py | 4 +++ module/hard/hard.py | 43 +++++++++++-------------- 7 files changed, 73 insertions(+), 29 deletions(-) diff --git a/alas.py b/alas.py index 8e901b8b5..1f3fb7eef 100644 --- a/alas.py +++ b/alas.py @@ -11,18 +11,19 @@ from module.campaign.run import CampaignRun from module.commission.commission import RewardCommission from module.config.config import AzurLaneConfig, TaskEnd from module.config.db import Database +from module.daily.daily import Daily from module.device.device import Device from module.dorm.dorm import RewardDorm from module.exception import * from module.guild.guild_reward import RewardGuild from module.handler.login import LoginHandler from module.handler.sensitive_info import handle_sensitive_image, handle_sensitive_logs +from module.hard.hard import CampaignHard from module.logger import logger, log_file from module.meowfficer.meowfficer import RewardMeowfficer from module.research.research import RewardResearch from module.reward.reward import Reward from module.tactical.tactical_class import RewardTacticalClass -from module.daily.daily import Daily class AzurLaneAutoScript: @@ -127,6 +128,9 @@ class AzurLaneAutoScript: def daily(self): Daily(config=self.config, device=self.device).run() + def hard(self): + CampaignHard(config=self.config, device=self.device).run() + def main(self): CampaignRun(config=self.config, device=self.device).run( name=self.config.Campaign_Name, diff --git a/campaign/campaign_hard/campaign_hard.py b/campaign/campaign_hard/campaign_hard.py index 7a8cb1fe1..ce6ec2c09 100644 --- a/campaign/campaign_hard/campaign_hard.py +++ b/campaign/campaign_hard/campaign_hard.py @@ -36,8 +36,8 @@ class Campaign(CampaignBase, HardEquipment): # except CampaignEnd: # logger.hr('Campaign end') - def fleet_preparation(self): - self.equipment_take_on() + # def fleet_preparation(self): + # self.equipment_take_on() def _expected_combat_end(self, expected): return 'in_stage' diff --git a/config/template.yaml b/config/template.yaml index 4c19f2a26..86909d201 100644 --- a/config/template.yaml +++ b/config/template.yaml @@ -303,3 +303,14 @@ Daily: TacticalTraining: second TacticalTrainingFleet: 5 SupplyLineDisruption: second +Hard: + Scheduler: + Enable: false + NextRun: 2020-01-01 00:00:00 + Command: Hard + SuccessInterval: 120 + FailureInterval: 120 + ServerUpdate: 00:00 + Hard: + HardStage: 11-4 + HardFleet: 1 diff --git a/module/config/args.yaml b/module/config/args.yaml index 3f9e4cede..e63301d3d 100644 --- a/module/config/args.yaml +++ b/module/config/args.yaml @@ -435,3 +435,18 @@ Daily: SupplyLineDisruption: value: 'second' option: ['no', 'first', 'second', 'third'] +Hard: + _info: + Menu: Reward + Scheduler: + Enable: false + NextRun: 2020-01-01 00:00:00 + Command: Hard + SuccessInterval: 120 + FailureInterval: 120 + ServerUpdate: 00:00 + Hard: + HardStage: 11-4 + HardFleet: + value: 1 + option: [1, 2] diff --git a/module/config/config.py b/module/config/config.py index 4a06abb16..8e2623922 100644 --- a/module/config/config.py +++ b/module/config/config.py @@ -38,6 +38,9 @@ class AzurLaneConfig(ManualConfig, GeneratedConfig): bound = {} # If write after every variable modification. auto_update = True + # Force override variables + # Key: Argument name in GeneratedConfig. Value: Modified value. + overridden = {} def __setattr__(self, key, value): if key in self.bound: @@ -78,10 +81,14 @@ class AzurLaneConfig(ManualConfig, GeneratedConfig): if path in visited: continue arg = path_to_arg(path) - self.__setattr__(arg, value) + super().__setattr__(arg, value) self.bound[arg] = f'{func}.{path}' visited.add(path) + # Override arguments + for arg, value in self.overridden.items(): + super().__setattr__(arg, value) + def _func_check(self, function): """ Args: @@ -144,6 +151,16 @@ class AzurLaneConfig(ManualConfig, GeneratedConfig): self.bind(self.task) self.save() + def override(self, **kwargs): + """ + Override anything you want. + Variables stall remain overridden even config is reloaded from yaml file. + Note that this method is irreversible. + """ + for arg, value in kwargs.items(): + self.overridden[arg] = value + super().__setattr__(arg, value) + def task_delay(self, success=None, server_update=None, target=None, minute=None): """ Set Scheduler.NextRun diff --git a/module/config/config_generated.py b/module/config/config_generated.py index bcc8ad303..ec948f4fa 100644 --- a/module/config/config_generated.py +++ b/module/config/config_generated.py @@ -149,3 +149,7 @@ class GeneratedConfig: Daily_TacticalTraining = 'second' # no, first, second, third Daily_TacticalTrainingFleet = 5 # 1, 2, 3, 4, 5, 6 Daily_SupplyLineDisruption = 'second' # no, first, second, third + + # Func `Hard` + Hard_HardStage = '11-4' + Hard_HardFleet = 1 diff --git a/module/hard/hard.py b/module/hard/hard.py index aa9224918..68038348f 100644 --- a/module/hard/hard.py +++ b/module/hard/hard.py @@ -7,8 +7,6 @@ from module.logger import logger from module.ocr.ocr import Digit OCR_HARD_REMAIN = Digit(OCR_HARD_REMAIN, letter=(123, 227, 66), threshold=128, alphabet='0123') -RECORD_OPTION = ('DailyRecord', 'hard') -RECORD_SINCE = (0,) class CampaignHard(CampaignRun): @@ -17,27 +15,30 @@ class CampaignHard(CampaignRun): def run(self): logger.hr('Campaign hard', level=1) - chapter, stage = self.config.HARD_CAMPAIGN.split('-') + chapter, stage = self.config.Hard_HardStage.split('-') name = f'campaign_{chapter}_{stage}' - self.reward_backup_daily_reward_settings() - hard_config = self.config.cover( - CAMPAIGN_MODE='hard', - ENABLE_MAP_FLEET_LOCK=True, - ENABLE_AUTO_SEARCH=True, - AUTO_SEARCH_SETTING='fleet1_all_fleet2_standby' if self.config.FLEET_HARD == 1 else 'fleet1_standby_fleet2_all', + self.config.override( + Campaign_Mode='hard', + Campaign_UseFleetLock=True, + Campaign_UseAutoSearch=True, + Fleet_AutoSearchFleetOrder='fleet1_all_fleet2_standby' if self.config.Hard_HardFleet == 1 else 'fleet1_standby_fleet2_all', + Emotion_CalculateEmotion=False, ) + # Equipment take on + # campaign/campaign_hard/campaign_hard.py Campaign.fleet_preparation() # Initial self.load_campaign(name='campaign_hard', folder='campaign_hard') # Load campaign file module = importlib.import_module('.' + name, 'campaign.campaign_main') # Load map from normal mode. self.campaign.MAP = module.MAP - backups = self.campaign_name_set(name + '_HARD') - if self.equipment_has_take_on: - self.campaign.equipment_has_take_on = True # UI ensure - self.ui_weigh_anchor() - self.campaign.ensure_campaign_ui(self.config.HARD_CAMPAIGN, mode='hard') + self.device.screenshot() + self.campaign.device.image = self.device.image + self.campaign.ensure_campaign_ui( + name=self.config.Hard_HardStage, + mode='hard' + ) # Run remain = OCR_HARD_REMAIN.ocr(self.device.image) @@ -46,15 +47,7 @@ class CampaignHard(CampaignRun): self.campaign.run() self.campaign.ensure_auto_search_exit() + # self.campaign.equipment_take_off_when_finished() - for backup in backups: - backup.recover() - self.campaign.equipment_take_off_when_finished() - hard_config.recover() - self.reward_recover_daily_reward_settings() - - def record_executed_since(self): - return self.config.record_executed_since(option=RECORD_OPTION, since=RECORD_SINCE) - - def record_save(self): - return self.config.record_save(option=RECORD_OPTION) + # Scheduler + self.config.task_delay(server_update=True)