mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-11 23:18:22 +08:00
Opt: Lazy load ambush and enhancement templates
- Opt: move letter preprocess functions to info_bar.py
This commit is contained in:
@@ -1,39 +1,31 @@
|
||||
import numpy as np
|
||||
|
||||
from module.base.decorator import cached_property
|
||||
from module.base.timer import Timer
|
||||
from module.base.utils import red_overlay_transparency, get_color
|
||||
from module.combat.combat import Combat
|
||||
from module.handler.assets import *
|
||||
from module.handler.info_handler import info_letter_preprocess
|
||||
from module.logger import logger
|
||||
from module.template.assets import *
|
||||
|
||||
|
||||
def ambush_letter_preprocess(image):
|
||||
"""
|
||||
Args:
|
||||
image (np.ndarray):
|
||||
|
||||
Returns:
|
||||
np.ndarray
|
||||
"""
|
||||
image = image.astype(float)
|
||||
image = (image - 64) / 0.75
|
||||
image[image > 255] = 255
|
||||
image[image < 0] = 0
|
||||
image = image.astype('uint8')
|
||||
return image
|
||||
|
||||
|
||||
TEMPLATE_AMBUSH_EVADE_SUCCESS.image = ambush_letter_preprocess(TEMPLATE_AMBUSH_EVADE_SUCCESS.image)
|
||||
TEMPLATE_AMBUSH_EVADE_FAILED.image = ambush_letter_preprocess(TEMPLATE_AMBUSH_EVADE_FAILED.image)
|
||||
TEMPLATE_MAP_WALK_OUT_OF_STEP.image = ambush_letter_preprocess(TEMPLATE_MAP_WALK_OUT_OF_STEP.image)
|
||||
|
||||
|
||||
class AmbushHandler(Combat):
|
||||
MAP_AMBUSH_OVERLAY_TRANSPARENCY_THRESHOLD = 0.40
|
||||
MAP_AIR_RAID_OVERLAY_TRANSPARENCY_THRESHOLD = 0.35 # Usually (0.50, 0.53)
|
||||
MAP_AIR_RAID_CONFIRM_SECOND = 0.5
|
||||
|
||||
@cached_property
|
||||
def _load_ambush_template(self):
|
||||
TEMPLATE_AMBUSH_EVADE_SUCCESS.image = info_letter_preprocess(TEMPLATE_AMBUSH_EVADE_SUCCESS.image)
|
||||
TEMPLATE_AMBUSH_EVADE_FAILED.image = info_letter_preprocess(TEMPLATE_AMBUSH_EVADE_FAILED.image)
|
||||
return True
|
||||
|
||||
@cached_property
|
||||
def _load_walk_template(self):
|
||||
TEMPLATE_MAP_WALK_OUT_OF_STEP.image = info_letter_preprocess(TEMPLATE_MAP_WALK_OUT_OF_STEP.image)
|
||||
return True
|
||||
|
||||
def ambush_color_initial(self):
|
||||
MAP_AMBUSH.load_color(self.device.image)
|
||||
MAP_AIR_RAID.load_color(self.device.image)
|
||||
@@ -60,10 +52,11 @@ class AmbushHandler(Combat):
|
||||
|
||||
def _handle_ambush_evade(self):
|
||||
logger.info('Map ambushed')
|
||||
_ = self._load_ambush_template
|
||||
self.wait_until_appear_then_click(MAP_AMBUSH_EVADE)
|
||||
|
||||
self.wait_until_appear(INFO_BAR_1)
|
||||
image = ambush_letter_preprocess(np.array(self.device.image.crop(INFO_BAR_DETECT.area)))
|
||||
image = info_letter_preprocess(np.array(self.device.image.crop(INFO_BAR_DETECT.area)))
|
||||
|
||||
if TEMPLATE_AMBUSH_EVADE_SUCCESS.match(image):
|
||||
logger.attr('Ambush_evade', 'success')
|
||||
@@ -126,7 +119,8 @@ class AmbushHandler(Combat):
|
||||
if not self.appear(INFO_BAR_1):
|
||||
return False
|
||||
|
||||
image = ambush_letter_preprocess(np.array(self.device.image.crop(INFO_BAR_DETECT.area)))
|
||||
_ = self._load_walk_template
|
||||
image = info_letter_preprocess(np.array(self.device.image.crop(INFO_BAR_DETECT.area)))
|
||||
if TEMPLATE_MAP_WALK_OUT_OF_STEP.match(image):
|
||||
logger.warning('Map walk out of step.')
|
||||
self.handle_info_bar()
|
||||
|
||||
@@ -4,6 +4,22 @@ from module.handler.assets import *
|
||||
from module.logger import logger
|
||||
|
||||
|
||||
def info_letter_preprocess(image):
|
||||
"""
|
||||
Args:
|
||||
image (np.ndarray):
|
||||
|
||||
Returns:
|
||||
np.ndarray
|
||||
"""
|
||||
image = image.astype(float)
|
||||
image = (image - 64) / 0.75
|
||||
image[image > 255] = 255
|
||||
image[image < 0] = 0
|
||||
image = image.astype('uint8')
|
||||
return image
|
||||
|
||||
|
||||
class InfoHandler(ModuleBase):
|
||||
"""
|
||||
Class to handle all kinds of message.
|
||||
|
||||
Reference in New Issue
Block a user