From fa0a243df1562e182dca29c54264b0641b1fb4df Mon Sep 17 00:00:00 2001 From: LmeSzinc Date: Fri, 15 May 2020 14:18:14 +0800 Subject: [PATCH] =?UTF-8?q?Refactor:=20=E5=90=88=E5=B9=B6=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=B6=88=E6=81=AF=E7=9A=84=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/combat/combat.py | 5 +- module/daemon/daemon.py | 5 +- module/equipment/equipment.py | 5 +- module/handler/enemy_searching.py | 5 +- module/handler/info_bar.py | 33 --------- module/handler/info_handler.py | 109 ++++++++++++++++++++++++++++ module/handler/login.py | 4 +- module/handler/low_emotion.py | 9 --- module/handler/popup.py | 22 ------ module/handler/story.py | 24 ------ module/handler/strategy.py | 7 +- module/handler/urgent_commission.py | 25 ------- module/map/camera.py | 6 +- module/map/fleet.py | 2 +- module/map/map_operation.py | 5 +- module/map/perspective.py | 2 +- module/retire/retirement.py | 7 +- module/reward/commission.py | 5 +- module/reward/tactical_class.py | 4 +- 19 files changed, 134 insertions(+), 150 deletions(-) delete mode 100644 module/handler/info_bar.py create mode 100644 module/handler/info_handler.py delete mode 100644 module/handler/low_emotion.py delete mode 100644 module/handler/popup.py delete mode 100644 module/handler/story.py delete mode 100644 module/handler/urgent_commission.py diff --git a/module/combat/combat.py b/module/combat/combat.py index ce51c9886..d2f33947b 100644 --- a/module/combat/combat.py +++ b/module/combat/combat.py @@ -9,16 +9,13 @@ from module.combat.emotion import Emotion from module.combat.hp_balancer import HPBalancer from module.combat.submarine import SubmarineCall from module.handler.enemy_searching import EnemySearchingHandler -from module.handler.low_emotion import LowEmotionHandler -from module.handler.urgent_commission import UrgentCommissionHandler from module.logger import logger from module.map.assets import MAP_OFFENSIVE from module.retire.retirement import Retirement from module.ui.assets import BACK_ARROW -class Combat(HPBalancer, UrgentCommissionHandler, EnemySearchingHandler, Retirement, SubmarineCall, LowEmotionHandler, - CombatAuto, CombatManual): +class Combat(HPBalancer, EnemySearchingHandler, Retirement, SubmarineCall, CombatAuto, CombatManual): _automation_set_timer = Timer(1) _emotion: Emotion battle_status_click_interval = 0 diff --git a/module/daemon/daemon.py b/module/daemon/daemon.py index ca3694c27..cb0c7bcce 100644 --- a/module/daemon/daemon.py +++ b/module/daemon/daemon.py @@ -2,13 +2,10 @@ from module.combat.combat import Combat from module.daemon.assets import * from module.handler.ambush import MAP_AMBUSH_EVADE from module.handler.mystery import MysteryHandler -from module.handler.story import StoryHandler -from module.handler.urgent_commission import UrgentCommissionHandler from module.map.map_fleet_preparation import FleetPreparation -class AzurLaneDaemon(FleetPreparation, Combat, UrgentCommissionHandler, MysteryHandler, - StoryHandler): +class AzurLaneDaemon(FleetPreparation, Combat, MysteryHandler): def daemon(self): while 1: diff --git a/module/equipment/equipment.py b/module/equipment/equipment.py index 6e1236081..303fe1f6c 100644 --- a/module/equipment/equipment.py +++ b/module/equipment/equipment.py @@ -1,7 +1,6 @@ from module.base.timer import Timer from module.equipment.assets import * -from module.handler.info_bar import InfoBarHandler -from module.handler.popup import PopupHandler +from module.handler.info_handler import InfoHandler from module.logger import logger from module.ui.assets import BACK_ARROW @@ -9,7 +8,7 @@ SWIPE_DISTANCE = 250 SWIPE_RANDOM_RANGE = (-40, -20, 40, 20) -class Equipment(InfoBarHandler, PopupHandler): +class Equipment(InfoHandler): equipment_has_take_on = False def _view_swipe(self, distance): diff --git a/module/handler/enemy_searching.py b/module/handler/enemy_searching.py index 055f2978a..43bc81c5d 100644 --- a/module/handler/enemy_searching.py +++ b/module/handler/enemy_searching.py @@ -2,12 +2,11 @@ from module.base.timer import Timer from module.base.utils import red_overlay_transparency, get_color from module.exception import CampaignEnd from module.handler.assets import * -from module.handler.info_bar import InfoBarHandler -from module.handler.story import StoryHandler +from module.handler.info_handler import InfoHandler from module.logger import logger -class EnemySearchingHandler(InfoBarHandler, StoryHandler): +class EnemySearchingHandler(InfoHandler): MAP_ENEMY_SEARCHING_OVERLAY_TRANSPARENCY_THRESHOLD = 0.5 # Usually (0.70, 0.80). MAP_ENEMY_SEARCHING_TIMEOUT_SECOND = 5 in_stage_timer = Timer(1, count=2) diff --git a/module/handler/info_bar.py b/module/handler/info_bar.py deleted file mode 100644 index a98285c16..000000000 --- a/module/handler/info_bar.py +++ /dev/null @@ -1,33 +0,0 @@ -from module.base.base import ModuleBase -from module.base.timer import Timer -from module.handler.assets import * - - -class InfoBarHandler(ModuleBase): - def info_bar_count(self): - if self.appear(INFO_BAR_3): - return 3 - elif self.appear(INFO_BAR_2): - return 2 - elif self.appear(INFO_BAR_1): - return 1 - else: - return 0 - - def handle_info_bar(self): - if self.info_bar_count(): - self.wait_until_disappear(INFO_BAR_1) - return True - else: - return False - # self.sleep(1) - - def ensure_no_info_bar(self, timeout=0.6): - timeout = Timer(timeout) - timeout.start() - while 1: - self.device.screenshot() - self.handle_info_bar() - - if timeout.reached(): - break diff --git a/module/handler/info_handler.py b/module/handler/info_handler.py new file mode 100644 index 000000000..31a01134d --- /dev/null +++ b/module/handler/info_handler.py @@ -0,0 +1,109 @@ +from module.base.base import ModuleBase +from module.base.timer import Timer +from module.handler.assets import * +from module.logger import logger + + +class InfoHandler(ModuleBase): + """ + Class to handle all kinds of message. + """ + """ + Info bar + """ + def info_bar_count(self): + if self.appear(INFO_BAR_3): + return 3 + elif self.appear(INFO_BAR_2): + return 2 + elif self.appear(INFO_BAR_1): + return 1 + else: + return 0 + + def handle_info_bar(self): + if self.info_bar_count(): + self.wait_until_disappear(INFO_BAR_1) + return True + else: + return False + + def ensure_no_info_bar(self, timeout=0.6): + timeout = Timer(timeout) + timeout.start() + while 1: + self.device.screenshot() + self.handle_info_bar() + + if timeout.reached(): + break + + """ + Popup info + """ + _popup_offset = (3, 30) + + def handle_popup_confirm(self): + if self.appear(POPUP_CANCEL, offset=self._popup_offset) \ + and self.appear(POPUP_CONFIRM, offset=self._popup_offset, interval=2): + self.device.click(POPUP_CONFIRM) + return True + else: + return False + + def handle_popup_cancel(self): + if self.appear(POPUP_CONFIRM, offset=self._popup_offset) \ + and self.appear(POPUP_CANCEL, offset=self._popup_offset, interval=2): + self.device.click(POPUP_CANCEL) + return True + else: + return False + + def handle_urgent_commission(self, save_get_items=None): + """ + Args: + save_get_items (bool): + + Returns: + bool: + """ + if save_get_items is None: + save_get_items = self.config.ENABLE_SAVE_GET_ITEMS + + appear = self.appear(GET_MISSION, offset=True, interval=2) + if appear: + logger.info('Get urgent commission') + if save_get_items: + self.handle_info_bar() + self.device.save_screenshot('get_mission') + self.device.click(GET_MISSION) + return appear + + def handle_combat_low_emotion(self): + if not self.config.IGNORE_LOW_EMOTION_WARN: + return False + + return self.handle_popup_confirm() + + """ + Story + """ + def story_skip(self): + if self.handle_popup_confirm(): + return True + if self.appear_then_click(STORY_SKIP, offset=True, interval=2): + return True + if self.appear(STORY_LETTER_BLACK) and self.appear_then_click(STORY_LETTERS_ONLY, offset=True, interval=2): + return True + if self.appear_then_click(STORY_CHOOSE, offset=True, interval=2): + return True + if self.appear_then_click(STORY_CHOOSE_2, offset=True, interval=2): + return True + + return False + + def handle_story_skip(self): + if not self.config.ENABLE_MAP_CLEAR_MODE: + return False + + return self.story_skip() diff --git a/module/handler/login.py b/module/handler/login.py index 2e64c9716..077bc3746 100644 --- a/module/handler/login.py +++ b/module/handler/login.py @@ -1,7 +1,7 @@ -from module.combat.combat import Combat -from module.logger import logger from module.base.timer import Timer +from module.combat.combat import Combat from module.handler.assets import * +from module.logger import logger from module.ui.ui import MAIN_CHECK, EVENT_LIST_CHECK, BACK_ARROW diff --git a/module/handler/low_emotion.py b/module/handler/low_emotion.py deleted file mode 100644 index ebf4285f0..000000000 --- a/module/handler/low_emotion.py +++ /dev/null @@ -1,9 +0,0 @@ -from module.handler.popup import PopupHandler - - -class LowEmotionHandler(PopupHandler): - def handle_combat_low_emotion(self): - if not self.config.IGNORE_LOW_EMOTION_WARN: - return False - - return self.handle_popup_confirm() diff --git a/module/handler/popup.py b/module/handler/popup.py deleted file mode 100644 index 0c97c263a..000000000 --- a/module/handler/popup.py +++ /dev/null @@ -1,22 +0,0 @@ -from module.base.base import ModuleBase -from module.handler.assets import POPUP_CANCEL, POPUP_CONFIRM - - -class PopupHandler(ModuleBase): - _popup_offset = (3, 30) - - def handle_popup_confirm(self): - if self.appear(POPUP_CANCEL, offset=self._popup_offset) \ - and self.appear(POPUP_CONFIRM, offset=self._popup_offset, interval=2): - self.device.click(POPUP_CONFIRM) - return True - else: - return False - - def handle_popup_cancel(self): - if self.appear(POPUP_CONFIRM, offset=self._popup_offset) \ - and self.appear(POPUP_CANCEL, offset=self._popup_offset, interval=2): - self.device.click(POPUP_CANCEL) - return True - else: - return False diff --git a/module/handler/story.py b/module/handler/story.py deleted file mode 100644 index 5c758e90e..000000000 --- a/module/handler/story.py +++ /dev/null @@ -1,24 +0,0 @@ -from module.handler.assets import * -from module.handler.popup import PopupHandler - - -class StoryHandler(PopupHandler): - def story_skip(self): - if self.handle_popup_confirm(): - return True - if self.appear_then_click(STORY_SKIP, offset=True, interval=2): - return True - if self.appear(STORY_LETTER_BLACK) and self.appear_then_click(STORY_LETTERS_ONLY, offset=True, interval=2): - return True - if self.appear_then_click(STORY_CHOOSE, offset=True, interval=2): - return True - if self.appear_then_click(STORY_CHOOSE_2, offset=True, interval=2): - return True - - return False - - def handle_story_skip(self): - if not self.config.ENABLE_MAP_CLEAR_MODE: - return False - - return self.story_skip() \ No newline at end of file diff --git a/module/handler/strategy.py b/module/handler/strategy.py index 6a324f45a..e9aeff7eb 100644 --- a/module/handler/strategy.py +++ b/module/handler/strategy.py @@ -1,9 +1,10 @@ import numpy as np + from module.base.switch import Switch from module.handler.assets import * -from module.template.assets import TEMPLATE_FORMATION_1, TEMPLATE_FORMATION_2, TEMPLATE_FORMATION_3 -from module.handler.info_bar import InfoBarHandler +from module.handler.info_handler import InfoHandler from module.logger import logger +from module.template.assets import TEMPLATE_FORMATION_1, TEMPLATE_FORMATION_2, TEMPLATE_FORMATION_3 formation = Switch('Formation') formation.add_status('1', check_button=FORMATION_1, offset=120) @@ -19,7 +20,7 @@ submarine_hunt.add_status('on', check_button=SUBMARINE_HUNT_ON, offset=120) submarine_hunt.add_status('off', check_button=SUBMARINE_HUNT_OFF, offset=120) -class StrategyHandler(InfoBarHandler): +class StrategyHandler(InfoHandler): fleet_1_formation_fixed = False fleet_2_formation_fixed = False diff --git a/module/handler/urgent_commission.py b/module/handler/urgent_commission.py deleted file mode 100644 index 296ef04a8..000000000 --- a/module/handler/urgent_commission.py +++ /dev/null @@ -1,25 +0,0 @@ -from module.handler.assets import * -from module.handler.info_bar import InfoBarHandler -from module.logger import logger - - -class UrgentCommissionHandler(InfoBarHandler): - def handle_urgent_commission(self, save_get_items=None): - """ - Args: - save_get_items (bool): - - Returns: - bool: - """ - if save_get_items is None: - save_get_items = self.config.ENABLE_SAVE_GET_ITEMS - - appear = self.appear(GET_MISSION, offset=True, interval=2) - if appear: - logger.info('Get urgent commission') - if save_get_items: - self.handle_info_bar() - self.device.save_screenshot('get_mission') - self.device.click(GET_MISSION) - return appear diff --git a/module/map/camera.py b/module/map/camera.py index 63f88f539..1b2038ff2 100644 --- a/module/map/camera.py +++ b/module/map/camera.py @@ -1,8 +1,8 @@ import numpy as np -from module.handler.info_bar import InfoBarHandler -from module.logger import logger from module.exception import PerspectiveError +from module.handler.info_handler import InfoHandler +from module.logger import logger from module.map.grids import Grids, Grid from module.map.map_base import CampaignMap, location2node, location_ensure @@ -29,7 +29,7 @@ def swipe_multiply_2d(x, y): return x, y -class Camera(InfoBarHandler): +class Camera(InfoHandler): map: CampaignMap camera = (0, 0) diff --git a/module/map/fleet.py b/module/map/fleet.py index ce822647e..f9bdce0f1 100644 --- a/module/map/fleet.py +++ b/module/map/fleet.py @@ -1,10 +1,10 @@ import itertools from module.base.timer import Timer +from module.exception import MapWalkError from module.handler.ambush import AmbushHandler from module.logger import logger from module.map.camera import Camera -from module.exception import MapWalkError from module.map.grids import Grids from module.map.map_base import SelectedGrids from module.map.map_base import location2node, location_ensure diff --git a/module/map/map_operation.py b/module/map/map_operation.py index 41cf77936..008f801a6 100644 --- a/module/map/map_operation.py +++ b/module/map/map_operation.py @@ -5,17 +5,14 @@ from module.base.utils import color_similarity_2d from module.exception import CampaignEnd from module.exception import ScriptEnd from module.handler.fast_forward import FastForwardHandler -from module.handler.low_emotion import LowEmotionHandler from module.handler.mystery import MysteryHandler -from module.handler.urgent_commission import UrgentCommissionHandler from module.logger import logger from module.map.assets import * from module.map.map_fleet_preparation import FleetPreparation from module.retire.retirement import Retirement -class MapOperation(UrgentCommissionHandler, MysteryHandler, FleetPreparation, Retirement, FastForwardHandler, - LowEmotionHandler): +class MapOperation(MysteryHandler, FleetPreparation, Retirement, FastForwardHandler): map_cat_attack_timer = Timer(2) def fleet_switch_click(self): diff --git a/module/map/perspective.py b/module/map/perspective.py index a4fcd46a3..19b58891b 100644 --- a/module/map/perspective.py +++ b/module/map/perspective.py @@ -8,8 +8,8 @@ from PIL import Image, ImageOps, ImageDraw from scipy import signal, optimize from module.config.config import AzurLaneConfig -from module.logger import logger from module.exception import PerspectiveError +from module.logger import logger from module.map.perspective_items import Points, Lines warnings.filterwarnings("ignore") diff --git a/module/retire/retirement.py b/module/retire/retirement.py index 9bb0cd313..94b690724 100644 --- a/module/retire/retirement.py +++ b/module/retire/retirement.py @@ -2,10 +2,9 @@ from module.base.button import ButtonGrid from module.base.decorator import Config from module.base.utils import get_color, color_similar from module.combat.assets import GET_ITEMS_1 -from module.handler.info_bar import InfoBarHandler -from module.handler.popup import PopupHandler -from module.logger import logger from module.exception import ScriptError +from module.handler.info_handler import InfoHandler +from module.logger import logger from module.retire.assets import * from module.ui.ui import UI @@ -21,7 +20,7 @@ CARD_RARITY_COLORS = { } -class Retirement(UI, InfoBarHandler, PopupHandler): +class Retirement(UI, InfoHandler): def _handle_retirement_cards_loading(self): self.device.sleep((1, 1.5)) diff --git a/module/reward/commission.py b/module/reward/commission.py index fba635ec2..953095b8b 100644 --- a/module/reward/commission.py +++ b/module/reward/commission.py @@ -8,8 +8,7 @@ from scipy import signal from module.base.ocr import Ocr from module.base.timer import Timer from module.base.utils import area_offset, get_color, random_rectangle_vector -from module.handler.info_bar import InfoBarHandler -from module.handler.popup import PopupHandler +from module.handler.info_handler import InfoHandler from module.logger import logger from module.reward.assets import * from module.ui.page import page_reward, page_commission, CAMPAIGN_CHECK @@ -267,7 +266,7 @@ def commission_choose(daily, urgent, priority, time_limit=None): return daily_choose, urgent_choose -class RewardCommission(UI, InfoBarHandler, PopupHandler): +class RewardCommission(UI, InfoHandler): daily: CommissionGroup urgent: CommissionGroup daily_choose: CommissionGroup diff --git a/module/reward/tactical_class.py b/module/reward/tactical_class.py index 2f031f75b..4b5776169 100644 --- a/module/reward/tactical_class.py +++ b/module/reward/tactical_class.py @@ -4,7 +4,7 @@ from scipy import signal from module.base.button import Button, ButtonGrid from module.base.timer import Timer, time_range_active from module.base.utils import area_offset, get_color, color_similar, color_similarity_2d -from module.handler.popup import PopupHandler +from module.handler.info_handler import InfoHandler from module.logger import logger from module.reward.assets import * from module.ui.assets import TACTICAL_CHECK @@ -146,7 +146,7 @@ class BookGroup: return self[0] -class RewardTacticalClass(UI, PopupHandler): +class RewardTacticalClass(UI, InfoHandler): tactical_animation_timer = Timer(2, count=3) def _tactical_animation_running(self):