Refactor: Daily module

- Delete daily fleet equipment change
This commit is contained in:
LmeSzinc 2021-09-22 21:49:36 +08:00
parent 4f0c07d1df
commit 62211b2af4
7 changed files with 170 additions and 58 deletions

View File

@ -22,6 +22,7 @@ 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:
@ -123,6 +124,9 @@ class AzurLaneAutoScript:
def meowfficer(self):
RewardMeowfficer(config=self.config, device=self.device).run()
def daily(self):
Daily(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

@ -276,7 +276,7 @@ Meowfficer:
Scheduler:
Enable: false
NextRun: 2020-01-01 00:00:00
Command: Reward
Command: Meowfficer
SuccessInterval: 120
FailureInterval: 120
ServerUpdate: 00:00
@ -284,3 +284,22 @@ Meowfficer:
BuyAmount: 1
TrainMeowfficer: false
FortChoreMeowfficer: true
Daily:
Scheduler:
Enable: false
NextRun: 2020-01-01 00:00:00
Command: Daily
SuccessInterval: 120
FailureInterval: 120
ServerUpdate: 00:00
Daily:
UseDailySkip: true
EscortMission: first
EscortMissionFleet: 5
AdvanceMission: first
AdvanceMissionFleet: 5
FierceAssault: first
FierceAssaultFleet: 5
TacticalTraining: second
TacticalTrainingFleet: 5
SupplyLineDisruption: second

View File

@ -396,3 +396,42 @@ Meowfficer:
BuyAmount: 1
TrainMeowfficer: false
FortChoreMeowfficer: true
Daily:
_info:
Menu: Reward
Scheduler:
Enable: false
NextRun: 2020-01-01 00:00:00
Command: Daily
SuccessInterval: 120
FailureInterval: 120
ServerUpdate: 00:00
Daily:
UseDailySkip: true
EscortMission:
value: 'first'
option: ['no', 'first', 'second', 'third']
EscortMissionFleet:
value: 5
option: [1, 2, 3, 4, 5, 6]
AdvanceMission:
value: 'first'
option: ['no', 'first', 'second', 'third']
AdvanceMissionFleet:
value: 5
option: [1, 2, 3, 4, 5, 6]
FierceAssault:
value: 'first'
option: ['no', 'first', 'second', 'third']
FierceAssaultFleet:
value: 5
option: [1, 2, 3, 4, 5, 6]
TacticalTraining:
value: 'second'
option: ['no', 'first', 'second', 'third']
TacticalTrainingFleet:
value: 5
option: [1, 2, 3, 4, 5, 6]
SupplyLineDisruption:
value: 'second'
option: ['no', 'first', 'second', 'third']

View File

@ -137,3 +137,15 @@ class GeneratedConfig:
Meowfficer_BuyAmount = 1
Meowfficer_TrainMeowfficer = False
Meowfficer_FortChoreMeowfficer = True
# Func `Daily`
Daily_UseDailySkip = True
Daily_EscortMission = 'first' # no, first, second, third
Daily_EscortMissionFleet = 5 # 1, 2, 3, 4, 5, 6
Daily_AdvanceMission = 'first' # no, first, second, third
Daily_AdvanceMissionFleet = 5 # 1, 2, 3, 4, 5, 6
Daily_FierceAssault = 'first' # no, first, second, third
Daily_FierceAssaultFleet = 5 # 1, 2, 3, 4, 5, 6
Daily_TacticalTraining = 'second' # no, first, second, third
Daily_TacticalTrainingFleet = 5 # 1, 2, 3, 4, 5, 6
Daily_SupplyLineDisruption = 'second' # no, first, second, third

View File

@ -377,8 +377,17 @@ def random_id(length=32):
return ''.join(random.sample(string.ascii_lowercase + string.digits, length))
def to_list(text):
def to_list(text, length=1):
"""
Args:
text (str): Such as `1, 2, 3`
length (int): If there's only one digit, return a list expanded to given length,
i.e. text='3', length=5, returns `[3, 3, 3, 3, 3]`
Returns:
list[int]:
"""
if text.isdigit():
return []
return [int(text)] * length
out = [int(letter.strip()) for letter in text.split(',')]
return out

View File

@ -2,11 +2,11 @@ import numpy as np
from module.base.utils import get_color
from module.combat.assets import BATTLE_PREPARATION
from module.combat.combat import Combat
from module.daily.assets import *
from module.equipment.fleet_equipment import DailyEquipment
from module.logger import logger
from module.ocr.ocr import Digit
from module.reward.reward import Reward
from module.ui.ui import page_daily, page_campaign_menu, BACK_ARROW, DAILY_CHECK
DAILY_MISSION_LIST = [DAILY_MISSION_1, DAILY_MISSION_2, DAILY_MISSION_3]
@ -16,7 +16,7 @@ RECORD_OPTION = ('DailyRecord', 'daily')
RECORD_SINCE = (0,)
class Daily(Reward, DailyEquipment):
class Daily(Combat, DailyEquipment):
daily_current: int
daily_checked: list
@ -53,10 +53,52 @@ class Daily(Reward, DailyEquipment):
return True
return False
def daily_execute(self, remain, fleet):
def get_daily_stage_and_fleet(self):
"""
Returns:
int: Stage index, 0 to 3
int: Fleet index, 1 to 6
"""
# Meaning of daily_current
# 1 Tactical Training, 2 Fierce Assault, 3 Supply Line Disruption, 4 Escort Mission, 5 Advance Mission
# 1 战术研修, 2 斩首行动, 3 破交作战, 4 商船护送, 5 海域突进
fleets = [
0,
self.config.Daily_TacticalTrainingFleet,
self.config.Daily_FierceAssaultFleet,
0, # Supply Line Disruption, which needs to be done manually or to be done by daily skip
self.config.Daily_EscortMissionFleet,
self.config.Daily_AdvanceMissionFleet,
0
]
stages = [
0,
self.config.Daily_TacticalTraining,
self.config.Daily_FierceAssault,
self.config.Daily_SupplyLineDisruption,
self.config.Daily_EscortMission,
self.config.Daily_AdvanceMission,
0
]
dic = {
'no': 0,
'first': 1,
'second': 2,
'third': 3,
}
fleet = fleets[self.daily_current]
stage = stages[self.daily_current]
if stage not in dic:
logger.warning(f'Unknown daily stage `{stage}` from fleet_current_index={self.daily_current}')
stage = dic.get(stage, 0)
return int(stage), int(fleet)
def daily_execute(self, remain=3, stage=1, fleet=1):
"""
Args:
remain (int): Remain daily challenge count.
stage (int): Index of stage counted from top, 1 to 3.
fleet (int): Index of fleet to use.
Returns:
@ -67,7 +109,7 @@ class Daily(Reward, DailyEquipment):
out: page_daily
"""
logger.hr(f'Daily {self.daily_current}')
logger.attr('Fleet', fleet)
logger.info(f'remain={remain}, stage={stage}, fleet={fleet}')
def daily_enter_check():
return self.appear(DAILY_ENTER_CHECK)
@ -85,7 +127,7 @@ class Daily(Reward, DailyEquipment):
self.device.sleep((1, 1.2))
return False
button = DAILY_MISSION_LIST[self.config.DAILY_CHOOSE[self.daily_current] - 1]
button = DAILY_MISSION_LIST[stage - 1]
for n in range(remain):
logger.hr(f'Count {n + 1}')
result = self.daily_enter(button)
@ -128,10 +170,10 @@ class Daily(Reward, DailyEquipment):
if self.appear(DAILY_ENTER_CHECK, interval=5):
self.device.click(button)
continue
if self.handle_get_items(save_get_items=False):
if self.handle_get_items():
reward_received = True
continue
if self.config.USE_DAILY_SKIP:
if self.config.Daily_UseDailySkip:
if self.appear_then_click(DAILY_SKIP, offset=(20, 20), interval=5):
continue
else:
@ -164,20 +206,12 @@ class Daily(Reward, DailyEquipment):
logger.info(f'Checked_list: {self.daily_checked}')
def daily_run_one(self):
logger.hr('Daily run one', level=1)
self.ui_ensure(page_daily)
self.device.sleep(0.2)
self.device.screenshot()
self.daily_current = 1
# Order of FLEET_DAILY
# 0 商船护送, 1 海域突进, 2 斩首行动, 3 战术研修, 4 破交作战
# 0 Escort Mission, 1 Advance Mission, 2 Fierce Assault, 3 Tactical Training, 4 Supply Line Disruption
fleets = self.config.FLEET_DAILY
# Order of fleets
# 1 Tactical Training, 2 Fierce Assault, 3 Supply Line Disruption, 4 Escort Mission, 5 Advance Mission
# 1 战术研修, 2 斩首行动, 3 破交作战, 4 商船护送, 5 海域突进
fleets = [0, fleets[3], fleets[2], fleets[4], fleets[0], fleets[1], 0]
logger.info(f'Checked_list: {self.daily_checked}')
for _ in range(max(self.daily_checked)):
self.next()
@ -188,12 +222,18 @@ class Daily(Reward, DailyEquipment):
# 1 战术研修, 2 斩首行动, 3 破交作战, 4 商船护送, 5 海域突进
if self.daily_current > 5:
break
# if self.daily_current == 3:
# logger.info('Skip submarine daily.')
# self.daily_check()
# self.next()
# continue
if not fleets[self.daily_current] and self.daily_current != 3:
stage, fleet = self.get_daily_stage_and_fleet()
if self.daily_current == 3 and not self.config.Daily_UseDailySkip:
logger.info('Skip supply line disruption if UseDailySkip disabled')
self.daily_check()
self.next()
continue
if not stage:
logger.info(f'No stage set on daily_current: {self.daily_current}, skip')
self.daily_check()
self.next()
continue
if self.daily_current != 3 and not fleet:
logger.info(f'No fleet set on daily_current: {self.daily_current}, skip')
self.daily_check()
self.next()
@ -208,11 +248,11 @@ class Daily(Reward, DailyEquipment):
self.next()
continue
else:
self.daily_execute(remain=remain, fleet=fleets[self.daily_current])
self.daily_execute(remain=remain, stage=stage, fleet=fleet)
self.daily_check()
# The order of daily tasks will be disordered after execute a daily, exit and re-enter to reset.
# 打完一次之后每日任务的顺序会乱掉, 退出再进入来重置顺序.
self.ui_ensure(page_campaign_menu)
self.ui_goto(page_campaign_menu)
break
def daily_run(self):
@ -226,18 +266,14 @@ class Daily(Reward, DailyEquipment):
break
def run(self):
self.equipment_take_on()
self.reward_backup_daily_reward_settings()
"""
Pages:
in: Any page
out: page_daily
"""
# self.equipment_take_on()
self.daily_run()
# self.equipment_take_off()
self.reward_recover_daily_reward_settings()
self.equipment_take_off()
self.ui_goto_main()
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)
# Cannot stay in page_daily, because order is disordered.
self.config.task_delay(server_update=True)

View File

@ -7,21 +7,14 @@ from module.logger import logger
from module.ui.scroll import Scroll
EQUIP_INFO_BAR = ButtonGrid(
origin=(723, 111), delta=(94, 0), button_shape=(76, 76), grid_shape=(5, 1), name="EQUIP_INFO_BAR"
)
origin=(723, 111), delta=(94, 0), button_shape=(76, 76), grid_shape=(5, 1), name="EQUIP_INFO_BAR")
EQUIPMENT_GRID = ButtonGrid(
origin=(725, 155), delta=(95, 0), button_shape=(31, 31), grid_shape=(5, 1),
name='EQUIPMENT_GRID')
EQUIPMENT_SCROLL = Scroll(EQUIP_SCROLL, color=(
247, 211, 66), name='EQUIP_SCROLL')
origin=(725, 155), delta=(95, 0), button_shape=(31, 31), grid_shape=(5, 1), name='EQUIPMENT_GRID')
EQUIPMENT_SCROLL = Scroll(EQUIP_SCROLL, color=(247, 211, 66), name='EQUIP_SCROLL')
SIM_VALUE = 0.90
class EquipmentChange(Equipment):
equip_list = {}
equipping_list = [0, 1, 2, 3, 4]
@ -38,7 +31,7 @@ class EquipmentChange(Equipment):
index = 0
for button in EQUIPMENT_GRID.buttons:
crop_image = np.array(self.device.image.crop(button.area))
edge_value = abs(np.mean(cv2.Sobel(crop_image,3, 1, 1)))
edge_value = abs(np.mean(cv2.Sobel(crop_image, 3, 1, 1)))
if edge_value < 0.1:
self.equipping_list.remove(index)
index += 1
@ -66,7 +59,8 @@ class EquipmentChange(Equipment):
self.equip_list[index] = self.image_area(EQUIP_SAVE)
logger.info('Quit upgrade inform')
self.ui_click(
click_button=UPGRADE_QUIT, check_button=EQUIPMENT_OPEN, appear_button=UPGRADE_ENTER_CHECK, skip_first_screenshot=True)
click_button=UPGRADE_QUIT, check_button=EQUIPMENT_OPEN, appear_button=UPGRADE_ENTER_CHECK,
skip_first_screenshot=True)
def equipment_take_on(self, index_list=range(0, 5), skip_first_screenshot=True):
'''
@ -118,11 +112,11 @@ class EquipmentChange(Equipment):
out: SHIP_SIDEBAR_EQUIPMENT
'''
logger.info('Equip equipment')
self.ui_click(appear_button=EQUIPPING_OFF, click_button=Button(button=(
point[0], point[1], point[0]+offset[0], point[1]+offset[1]), color=None, area=None), check_button=EQUIP_CONFIRM)
button = Button(area=(), color=(), button=(point[0], point[1], point[0] + offset[0], point[1] + offset[1]),
name='EQUIPMENT')
self.ui_click(appear_button=EQUIPPING_OFF, click_button=button, check_button=EQUIP_CONFIRM)
logger.info('Equip confirm')
self.ui_click(click_button=EQUIP_CONFIRM,
check_button=SHIP_INFO_EQUIPMENT_CHECK)
self.ui_click(click_button=EQUIP_CONFIRM, check_button=SHIP_INFO_EQUIPMENT_CHECK)
def _find_equip(self, index):
'''
@ -153,8 +147,7 @@ class EquipmentChange(Equipment):
break
if self.appear(EQUIPMENT_SCROLL_BOTTOM):
logger.warning('No recorded equipment was found.')
self.ui_back(check_button=globals()[
f'EQUIP_TAKE_ON_{index}'], appear_button=EQUIPPING_OFF)
self.ui_back(check_button=globals()[f'EQUIP_TAKE_ON_{index}'], appear_button=EQUIPPING_OFF)
break
return