Refactor: 合并处理消息的类

This commit is contained in:
LmeSzinc 2020-05-15 14:18:14 +08:00
parent 10b43b44fa
commit fa0a243df1
19 changed files with 134 additions and 150 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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