Refactor: Reward receive, oil, coins and missions

This commit is contained in:
LmeSzinc 2021-09-20 20:35:10 +08:00
parent 9f47fb9bc2
commit 121dbd694c
6 changed files with 86 additions and 273 deletions

View File

@ -17,6 +17,7 @@ from module.handler.login import LoginHandler
from module.handler.sensitive_info import handle_sensitive_image, handle_sensitive_logs
from module.logger import logger, log_file
from module.research.research import RewardResearch
from module.reward.reward import Reward
from module.tactical.tactical_class import RewardTacticalClass
@ -107,6 +108,9 @@ class AzurLaneAutoScript:
def tactical(self):
RewardTacticalClass(config=self.config, device=self.device).run()
def reward(self):
Reward(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

@ -228,3 +228,15 @@ Research:
UsePart: true
PresetFilter: series_4
CustomFilter: 0.5 > reset > shortest
Reward:
Scheduler:
Enable: true
NextRun: 2020-01-01 00:00:00
Command: Reward
SuccessInterval: 40-60
FailureInterval: 40-60
ServerUpdate: 00:00
Reward:
CollectOil: true
CollectCoin: true
CollectMission: true

View File

@ -332,3 +332,17 @@ Research:
- series_3
- series_3_than_2
CustomFilter: 0.5 > reset > shortest
Reward:
_info:
Menu: Reward
Scheduler:
Enable: true
NextRun: 2020-01-01 00:00:00
Command: Reward
SuccessInterval: 40-60
FailureInterval: 40-60
ServerUpdate: 00:00
Reward:
CollectOil: true
CollectCoin: true
CollectMission: true

View File

@ -114,3 +114,8 @@ class GeneratedConfig:
Research_UsePart = True
Research_PresetFilter = 'series_4' # custom, series_4, series_3, series_3_than_2
Research_CustomFilter = '0.5 > reset > shortest'
# Func `Reward`
Reward_CollectOil = True
Reward_CollectCoin = True
Reward_CollectMission = True

View File

@ -6,7 +6,7 @@ class ManualConfig:
SCHEDULER_PRIORITY = """
Restart
> Research > Commission > Tactical > Dorm > Task
> Research > Commission > Tactical > Dorm > Reward
> GuildLogistics > GuildOperation
> Meowfficer > Gacha > Shop
> OpsiObscure

View File

@ -1,158 +1,54 @@
from datetime import datetime, timedelta
from module.base.button import ButtonGrid
from module.base.decorator import cached_property
from module.base.timer import Timer
from module.base.utils import ensure_time
from module.combat.assets import *
from module.guild.guild_reward import RewardGuild
from module.handler.login import LoginHandler
from module.logger import logger
from module.research.research import RewardResearch
from module.reward.assets import *
from module.reward.commission import RewardCommission
from module.reward.data_key import RewardDataKey
from module.reward.dorm import RewardDorm
from module.reward.meowfficer import RewardMeowfficer
from module.reward.tactical_class import RewardTacticalClass
from module.shipyard.shipyard_reward import RewardShipyard
from module.shop.shop_reward import RewardShop
from module.ui.navbar import Navbar
from module.ui.page import *
from module.update import Update
from module.ui.ui import UI
class Reward(RewardCommission, RewardTacticalClass, RewardResearch, RewardDorm, RewardMeowfficer, RewardDataKey,
RewardGuild, RewardShop, RewardShipyard, LoginHandler, Update):
@cached_property
def reward_interval(self):
class Reward(UI):
def reward_receive(self, oil, coin, skip_first_screenshot=True):
"""
REWARD_INTERVAL should be string in minutes, such as '20', '10, 40'.
If it's a time range, should separated with ','
Args:
oil (bool):
coin (bool):
skip_first_screenshot (bool):
Returns:
int: Reward interval in seconds.
"""
return int(ensure_time(self.config.REWARD_INTERVAL, precision=3) * 60)
def reward_interval_reset(self):
""" Call this method after script sleep ends """
del self.__dict__['reward_interval']
def reward(self):
if not self.config.ENABLE_REWARD:
return False
logger.hr('Reward start')
self.ui_goto_main()
self.ui_goto(page_reward, skip_first_screenshot=True)
rewards_handled = False
research_num = 1
tactical_num = 3
commission_num = 4
research_count = tactical_count = commission_count = 0
for _ in range(research_num + tactical_num + commission_num):
if rewards_handled:
break
self._reward_receive()
self.handle_info_bar()
if research_count < research_num:
if self.handle_research_reward():
research_count += 1
continue
if tactical_count < tactical_num:
if self.handle_tactical_class():
tactical_count += 1
continue
if commission_count < commission_num:
if self.handle_commission_start():
commission_count += 1
continue
rewards_handled = True
self.ui_goto(page_main, skip_first_screenshot=True)
self.handle_dorm()
self.handle_meowfficer()
self.handle_data_key()
self.handle_guild()
self.handle_shop()
self.handle_shipyard()
self._reward_mission()
self.config.REWARD_LAST_TIME = datetime.now()
logger.hr('Reward end')
if self.config.ENABLE_DAILY_REWARD:
logger.hr('Daily reward')
count = self.daily_wrapper_run()
if count > 0:
return self.reward()
return True
def handle_reward(self):
if datetime.now() - self.config.REWARD_LAST_TIME < timedelta(seconds=self.reward_interval):
return False
self.ensure_auto_search_exit()
flag = self.reward()
return flag
def _reward_receive(self):
"""
Returns:
bool: If rewarded.
Pages:
in: page_reward
out: page_reward, with info_bar if received
"""
if not oil and not coin:
return False
logger.hr('Reward receive')
reward = False
exit_timer = Timer(1, count=3).start()
click_timer = Timer(1)
logger.info(f'oil={oil}, coin={coin}')
confirm_timer = Timer(1, count=3).start()
while 1:
self.device.screenshot()
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
for button in [EXP_INFO_S_REWARD, GET_ITEMS_1, GET_ITEMS_2, GET_ITEMS_3, GET_SHIP]:
if self.appear(button, interval=1):
self.ensure_no_info_bar(timeout=1)
if self.config.ENABLE_SAVE_GET_ITEMS:
self.device.save_screenshot('commission_items', to_base_folder=True, interval=0)
self.stat.add(self.device.image)
REWARD_SAVE_CLICK.name = button.name
self.device.click(REWARD_SAVE_CLICK)
click_timer.reset()
exit_timer.reset()
reward = True
continue
if click_timer.reached() and (
(self.config.ENABLE_OIL_REWARD and self.appear_then_click(OIL, interval=60))
or (self.config.ENABLE_COIN_REWARD and self.appear_then_click(COIN, interval=60))
or (self.config.ENABLE_COMMISSION_REWARD and self.appear_then_click(REWARD_1, interval=1))
or (self.config.ENABLE_RESEARCH_REWARD
and not self.config.ENABLE_SAVE_GET_ITEMS
and not self.config.ENABLE_AZURSTAT
and self.appear_then_click(REWARD_3, interval=1))
):
exit_timer.reset()
click_timer.reset()
reward = True
if oil and self.appear_then_click(OIL, interval=60):
confirm_timer.reset()
continue
if not self.appear(page_reward.check_button) or self.info_bar_count():
exit_timer.reset()
if coin and self.appear_then_click(COIN, interval=60):
confirm_timer.reset()
continue
# End
if exit_timer.reached():
if confirm_timer.reached():
break
self.stat.upload()
return reward
logger.info('Reward receive end')
return True
def _reward_mission_collect(self, interval=1):
"""
@ -190,7 +86,8 @@ class Reward(RewardCommission, RewardTacticalClass, RewardResearch, RewardDorm,
for button in [MISSION_MULTI, MISSION_SINGLE]:
if not click_timer.reached():
continue
if self.appear(button, offset=(0, 200), interval=interval) and button.match_appear_on(self.device.image):
if self.appear(button, offset=(0, 200), interval=interval) \
and button.match_appear_on(self.device.image):
self.device.click(button)
exit_timer.reset()
click_timer.reset()
@ -241,7 +138,7 @@ class Reward(RewardCommission, RewardTacticalClass, RewardResearch, RewardDorm,
self.reward_side_navbar_ensure(upper=1)
if not self.appear(MISSION_MULTI) and \
not self.appear(MISSION_SINGLE):
not self.appear(MISSION_SINGLE):
return False
# Uses default interval to account for
@ -266,18 +163,21 @@ class Reward(RewardCommission, RewardTacticalClass, RewardResearch, RewardDorm,
# premature exit
return self._reward_mission_collect(interval=0)
def _reward_mission(self):
def reward_mission(self):
"""
Returns:
bool: If rewarded.
"""
if not self.config.ENABLE_MISSION_REWARD:
return False
Pages:
in: page_main
out: page_mission
"""
logger.hr('Mission reward')
if not self.appear(MISSION_NOTICE):
logger.info('No mission reward')
return False
else:
logger.info('Found mission reward notice')
self.ui_goto(page_mission, skip_first_screenshot=True)
@ -286,143 +186,8 @@ class Reward(RewardCommission, RewardTacticalClass, RewardResearch, RewardDorm,
reward = self._reward_mission_all()
reward |= self._reward_mission_weekly()
self.ui_goto(page_main, skip_first_screenshot=True)
return reward
def reward_loop(self):
logger.hr('Reward loop')
while 1:
if self.config.triggered_app_restart():
self.app_restart()
self.reward()
logger.info('Reward loop wait')
logger.attr('Reward_loop_wait', f'{self.reward_interval // 60} min {self.reward_interval % 60} sec')
if self.config.REWARD_STOP_GAME_DURING_INTERVAL:
interval = ensure_time((10, 30))
logger.info(f'{self.config.PACKAGE_NAME} will stop in {interval} seconds')
logger.info('If you are playing by hand, please stop Alas')
self.device.sleep(interval)
self.device.app_stop()
self.device.sleep(self.reward_interval)
self.reward_interval_reset()
self.device.stuck_record_clear()
if self.config.REWARD_STOP_GAME_DURING_INTERVAL:
self.app_ensure_start()
def daily_wrapper_run(self):
count = 0
total = 6
if self.config.ENABLE_OS_OBSCURE_FINISH:
from module.campaign.os_run import OSCampaignRun
az = OSCampaignRun(self.config, device=self.device)
az.run_obscure_clear()
if self.config.ENABLE_EXERCISE:
from module.exercise.exercise import Exercise
az = Exercise(self.config, device=self.device)
if not az.record_executed_since():
az.run()
az.record_save()
count += 1
self.device.send_notification('Daily Exercises', 'Exercise daily finished.')
if self.config.ENABLE_DAILY_MISSION:
from module.daily.daily import Daily
az = Daily(self.config, device=self.device)
if not az.record_executed_since():
az.run()
az.record_save()
count += 1
self.device.send_notification('Daily Mission', 'Daily raid finished.')
if self.config.ENABLE_HARD_CAMPAIGN:
from module.hard.hard import CampaignHard
az = CampaignHard(self.config, device=self.device)
if not az.record_executed_since():
az.run()
az.record_save()
count += 1
self.device.send_notification('Daily Hard', 'Daily hard campaign finished.')
if self.config.DO_SOS_IN_DAILY:
from module.sos.sos import CampaignSos
az = CampaignSos(self.config, device=self.device)
if not az.record_executed_since():
az.run()
az.record_save()
count += 1
self.device.send_notification('Daily Sos', 'Daily sos campaign finished.')
if self.config.ENABLE_EVENT_SP:
from module.event.campaign_sp import CampaignSP
az = CampaignSP(self.config, device=self.device)
if az.run_event_daily_sp():
count += 1
self.device.send_notification('Daily Event SP', 'Daily event SP finished.')
if self.config.ENABLE_EVENT_AB:
from module.event.campaign_ab import CampaignAB
az = CampaignAB(self.config, device=self.device)
if az.run_event_daily():
count += 1
self.device.send_notification('Daily Event AB', 'Daily event AB finished.')
if self.config.DO_WAR_ARCHIVES_IN_DAILY:
from module.war_archives.war_archives import CampaignWarArchives
az = CampaignWarArchives(self.config, device=self.device)
if az.run_war_archives_daily():
self.device.send_notification('Daily War Archives', 'Daily war archives campaigns finished.')
if self.config.ENABLE_RAID_DAILY:
from module.raid.daily import RaidDaily
az = RaidDaily(self.config, device=self.device)
if not az.record_executed_since():
az.run()
az.record_save()
count += 1
self.device.send_notification('Daily Event RAID', 'Daily event RAID finished.')
if self.config.ENABLE_OS_ASH_ASSIST:
from module.os_ash.ash import AshDaily
az = AshDaily(self.config, device=self.device)
if not az.record_executed_since():
az.run()
az.record_save()
# Ash assist doesn't finish any daily mission, so not counted in.
# count += 1
if self.config.DO_OS_IN_DAILY:
from module.campaign.os_run import OSCampaignRun
az = OSCampaignRun(self.config, device=self.device)
if not az.record_executed_since():
az.run_daily()
logger.attr('Daily_executed', f'{count}/{total}')
return count
_daily_reward_setting_backup = None
def reward_backup_daily_reward_settings(self):
"""
Method to avoid event_daily_ab and sos calls reward, and reward calls event_daily_ab or daily_sos itself again.
"""
self._daily_reward_setting_backup = self.config.cover(
ENABLE_DAILY_REWARD=False,
FLEET_1_AUTO_MODE='combat_auto',
FLEET_2_AUTO_MODE='combat_auto',
ENABLE_FAST_FORWARD=True,
STOP_IF_MAP_REACH='no',
STOP_IF_OIL_LOWER_THAN=0,
)
def reward_recover_daily_reward_settings(self):
self._daily_reward_setting_backup.recover()
@cached_property
def _reward_side_navbar(self):
"""
@ -471,3 +236,16 @@ class Reward(RewardCommission, RewardTacticalClass, RewardResearch, RewardDorm,
if self._reward_side_navbar.set(self, upper=upper, bottom=bottom):
return True
return False
def run(self):
"""
Pages:
in: Any page
out: page_main or page_mission, may have info_bar
"""
self.ui_ensure(page_reward)
self.reward_receive(oil=self.config.Reward_CollectOil, coin=self.config.Reward_CollectCoin)
self.ui_goto(page_main)
self.reward_mission()
self.config.task_delay(success=True)