StarRailCopilot/module/handler/enemy_searching.py
LmeSzinc bea05d396e Add: 适配复刻苍红的回响AB图
- 开荒模式移动至出击设置
- 增加开荒模式自动启用, 无脑开就完事了
- 将透视识别参数放到了config里, 这样就可以用地图config覆盖了
- 适配小地图模式, 参数抄A1就行了
- 修复了章节名OCR的识别位置
- 修复了开荒会把BOSS当作精英打问题
- 增加战斗中的剧情跳过
- 注释掉了截图和点击的retry
- 增加了捕捉目标点超出移动范围
2020-04-24 15:26:11 +08:00

73 lines
2.3 KiB
Python

from module.base.timer import Timer
from module.base.utils import red_overlay_transparency, get_color
from module.handler.assets import *
from module.handler.info_bar import InfoBarHandler
from module.logger import logger
from module.map.exception import CampaignEnd
class EnemySearchingHandler(InfoBarHandler):
MAP_ENEMY_SEARCHING_OVERLAY_TRANSPARENCY_THRESHOLD = 0.5 # Usually (0.70, 0.80).
MAP_ENEMY_SEARCHING_TIMEOUT_SECOND = 4.5
def enemy_searching_color_initial(self):
MAP_ENEMY_SEARCHING.load_color(self.device.image)
def enemy_searching_appear(self):
return red_overlay_transparency(
MAP_ENEMY_SEARCHING.color, get_color(self.device.image, MAP_ENEMY_SEARCHING.area)
) > self.MAP_ENEMY_SEARCHING_OVERLAY_TRANSPARENCY_THRESHOLD
def handle_enemy_flashing(self):
self.device.sleep(1.2)
def handle_in_stage(self):
if self.is_in_stage():
logger.info('In stage.')
# self.device.sleep(0.5)
self.ensure_no_info_bar(timeout=1.2)
raise CampaignEnd('In stage.')
else:
return False
def is_in_stage(self):
return self.appear(IN_STAGE_RED) or self.appear(IN_STAGE_BLUE)
def is_in_map(self):
return self.appear(IN_MAP)
def handle_in_map_with_enemy_searching(self):
if not self.is_in_map():
return False
timeout = Timer(self.MAP_ENEMY_SEARCHING_TIMEOUT_SECOND)
appeared = False
while 1:
timeout.start()
if self.handle_in_stage():
return True
if self.enemy_searching_appear():
appeared = True
else:
if appeared:
self.handle_enemy_flashing()
self.device.sleep(0.3)
logger.info('In map.')
break
self.enemy_searching_color_initial()
if timeout.reached():
# logger.warning('Enemy searching timeout.')
logger.info('Enemy searching timeout.')
break
self.device.screenshot()
return True
def handle_in_map(self):
if not self.is_in_map():
return False
self.device.sleep((1, 1.2))
return True