Refactor: Hard module

- Add config override
- Delete hard equipment change
This commit is contained in:
LmeSzinc 2021-09-23 01:03:39 +08:00
parent 7c34d4598f
commit eb7886df61
7 changed files with 73 additions and 29 deletions

View File

@ -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,

View File

@ -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'

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -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

View File

@ -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)