From d9cec4134ecb28cacdf8b05cc6675e0c4aac7314 Mon Sep 17 00:00:00 2001 From: nEEtdo0d Date: Sun, 10 Oct 2021 23:38:10 -0400 Subject: [PATCH] Add: war archives support for app --- alas.py | 5 ++++ .../campaign_war_archives/campaign_base.py | 8 +++--- module/campaign/campaign_ui.py | 4 +-- module/handler/info_handler.py | 19 +++++++++++-- module/ui/ui.py | 6 +++++ module/war_archives/war_archives.py | 27 +++---------------- 6 files changed, 37 insertions(+), 32 deletions(-) diff --git a/alas.py b/alas.py index 86ad80d77..a1c5d53ab 100644 --- a/alas.py +++ b/alas.py @@ -153,6 +153,11 @@ class AzurLaneAutoScript: from module.sos.sos import CampaignSos CampaignSos(config=self.config, device=self.device).run() + def war_archives(self): + from module.war_archives.war_archives import CampaignWarArchives + CampaignWarArchives(config=self.config, device=self.device).run( + name=self.config.Campaign_Name, folder=self.config.Campaign_Event, mode=self.config.Campaign_Mode) + def event_ab(self): from module.event.campaign_ab import CampaignAB CampaignAB(config=self.config, device=self.device).run() diff --git a/campaign/campaign_war_archives/campaign_base.py b/campaign/campaign_war_archives/campaign_base.py index 3967a1773..8274797b4 100644 --- a/campaign/campaign_war_archives/campaign_base.py +++ b/campaign/campaign_war_archives/campaign_base.py @@ -58,11 +58,11 @@ class CampaignBase(CampaignBase_): if entrance is not None: return entrance - backup = self.config.cover(DEVICE_CONTROL_METHOD='minitouch') + # backup = self.config.cover(DEVICE_CONTROL_METHOD='minitouch') p1, p2 = random_rectangle_vector( (0, -275), box=detection_area, random_range=(-50, -50, 50, 50), padding=20) self.device.drag(p1, p2, segments=2, shake=(0, 25), point_random=(0, 0, 0, 0), shake_random=(0, -5, 0, 5)) - backup.recover() + # backup.recover() self.device.sleep(0.3) logger.warning('Failed to find archives entrance') @@ -82,13 +82,11 @@ class CampaignBase(CampaignBase_): result = self.ui_ensure(destination=page_archives) WAR_ARCHIVES_SWITCH.set(mode, main=self) - self.handle_stage_icon_spawn() - entrance = self._search_archives_entrance(self.config.WAR_ARCHIVES_NAME) + entrance = self._search_archives_entrance(self.config.Campaign_Event) if entrance is not None: self.ui_click(entrance, appear_button=WAR_ARCHIVES_CHECK, check_button=WAR_ARCHIVES_CAMPAIGN_CHECK, skip_first_screenshot=True) - self.handle_stage_icon_spawn() else: logger.critical('Respective server may not yet support the chosen War Archives campaign, ' 'check back in the next app update') diff --git a/module/campaign/campaign_ui.py b/module/campaign/campaign_ui.py index ef011b18e..5d0fab19d 100644 --- a/module/campaign/campaign_ui.py +++ b/module/campaign/campaign_ui.py @@ -93,7 +93,7 @@ class CampaignUI(UI, CampaignOcr): self.campaign_ensure_chapter(index=chapter) elif chapter in ['a', 'b', 'c', 'd', 'ex_sp', 'as', 'bs', 'cs', 'ds']: - self.ui_goto(page_event) + self.ui_goto_event() if chapter in ['a', 'b', 'as', 'bs']: self.campaign_ensure_mode('normal') elif chapter in ['c', 'd', 'cs', 'ds']: @@ -103,7 +103,7 @@ class CampaignUI(UI, CampaignOcr): self.campaign_ensure_chapter(index=chapter) elif chapter == 'sp': - self.ui_goto(page_sp) + self.ui_goto_sp() self.campaign_ensure_chapter(index=chapter) else: diff --git a/module/handler/info_handler.py b/module/handler/info_handler.py index befce7059..04075c9c8 100644 --- a/module/handler/info_handler.py +++ b/module/handler/info_handler.py @@ -144,8 +144,23 @@ class InfoHandler(ModuleBase): return False if self.appear(USE_DATA_KEY, offset=(20, 20)): - self.device.click(USE_DATA_KEY_NOTIFIED) - self.device.sleep((0.5, 0.8)) + skip_first_screenshot = True + while 1: + if skip_first_screenshot: + skip_first_screenshot = False + else: + self.device.screenshot() + + enabled = self.image_color_count(USE_DATA_KEY_NOTIFIED, + color=(140, 207, 66), threshold=180, count=10) + if enabled: + break + + if self.appear(USE_DATA_KEY, interval=5): + self.device.click(USE_DATA_KEY_NOTIFIED) + continue + + self.config.USE_DATA_KEY = False # Reset on success as task can be stopped before can be recovered return self.handle_popup_confirm('USE_DATA_KEY') return False diff --git a/module/ui/ui.py b/module/ui/ui.py index 56b181ce9..90ca31869 100644 --- a/module/ui/ui.py +++ b/module/ui/ui.py @@ -211,6 +211,12 @@ class UI(InfoHandler): def ui_goto_main(self): return self.ui_ensure(destination=page_main) + def ui_goto_event(self): + return self.ui_ensure(destination=page_event) + + def ui_goto_sp(self): + return self.ui_ensure(destination=page_sp) + def ui_ensure_index(self, index, letter, next_button, prev_button, skip_first_screenshot=False, fast=True, interval=(0.2, 0.3), step_sleep=(0.2, 0.3), finish_sleep=(0.5, 0.8)): """ diff --git a/module/war_archives/war_archives.py b/module/war_archives/war_archives.py index 031ecbcdd..65af71bba 100644 --- a/module/war_archives/war_archives.py +++ b/module/war_archives/war_archives.py @@ -5,8 +5,6 @@ from module.ocr.ocr import DigitCounter from module.war_archives.assets import OCR_DATA_KEY_CAMPAIGN, WAR_ARCHIVES_CAMPAIGN_CHECK DATA_KEY_CAMPAIGN = DigitCounter(OCR_DATA_KEY_CAMPAIGN, letter=(255, 247, 247), threshold=64) -RECORD_SINCE = (0,) -RECORD_OPTION = ('DailyRecord', 'war_archives') class CampaignWarArchives(CampaignRun, CampaignBase): def triggered_stop_condition(self, oil_check=True): @@ -22,25 +20,8 @@ class CampaignWarArchives(CampaignRun, CampaignBase): # Else, check other stop conditions return super().triggered_stop_condition(oil_check) - def run_war_archives_daily(self): - """ - Returns: - bool: If executed. - """ - self.reward_backup_daily_reward_settings() - backup = self.config.cover(STOP_IF_COUNT_GREATER_THAN=4) # 4 data keys daily - if not self.config.record_executed_since(option=RECORD_OPTION, since=RECORD_SINCE): - self.run(self.config.WAR_ARCHIVES_STAGE, folder=self.config.WAR_ARCHIVES_NAME) - self.config.record_save(option=RECORD_OPTION) - executed = True - else: - executed = False - - backup.recover() - self.reward_recover_daily_reward_settings() - return executed - - def run(self, name=None, folder='campaign_main', total=0): - backup = self.config.cover(USE_DATA_KEY=True) - super().run(name, folder, total) + def run(self, name=None, folder='campaign_main', mode='normal', total=0): + backup = self.config.temporary(USE_DATA_KEY=True) + super().run(name, folder, mode, total) backup.recover() + self.ui_goto_main() # Go to main, as remaining in page can throw off Event task