StarRailCopilot/tasks/rogue/blessing/ui.py

84 lines
2.9 KiB
Python
Raw Normal View History

import re
2023-08-22 19:00:45 +00:00
from module.base.utils import area_offset
from module.logger import logger
2023-08-22 19:00:45 +00:00
from module.ocr.ocr import Digit, Ocr, OcrResultButton
2023-08-10 09:12:17 +00:00
from tasks.base.ui import UI
from tasks.rogue.assets.assets_rogue_ui import *
from tasks.rogue.assets.assets_rogue_weekly import REWARD_ENTER
2023-10-05 10:52:55 +00:00
from tasks.rogue.keywords import RoguePath
class RogueBonusOcr(Ocr):
def after_process(self, result):
result = super().after_process(result)
2023-09-12 10:39:23 +00:00
if self.lang == 'cn':
replace_pattern_dict = {
"[宇宝][宙审]": "宇宙",
}
for pat, replace in replace_pattern_dict.items():
result = re.sub(pat, replace, result)
return result
2023-08-10 09:12:17 +00:00
class RogueUI(UI):
path: RoguePath
@property
def cosmic_fragment(self):
2023-08-20 16:05:50 +00:00
"""
Return valid result only when template appear
"""
if self.appear(COSMIC_FRAGMENT):
2023-08-20 16:05:50 +00:00
return Digit(OCR_COSMIC_FRAGMENT).ocr_single_line(self.device.image)
return 0
2023-08-10 09:12:17 +00:00
def is_page_choose_blessing(self):
return (self.image_color_count(PAGE_CHOOSE_BUFF, (245, 245, 245), count=200)
and self.appear(CHECK_BLESSING))
2023-08-10 09:12:17 +00:00
def is_page_choose_curio(self):
2023-08-12 07:15:25 +00:00
return self.appear(PAGE_CHOOSE_CURIO)
def is_page_choose_bonus(self):
return self.appear(PAGE_CHOOSE_BONUS)
2023-08-14 20:16:31 +00:00
def is_page_event(self):
return self.appear(PAGE_EVENT)
2023-08-22 19:00:45 +00:00
2023-10-14 16:32:40 +00:00
def is_page_rogue_main(self):
2023-10-14 20:20:25 +00:00
return self.match_template_color(REWARD_ENTER)
def is_page_rogue_launch(self):
return self.match_template_color(ROGUE_LAUNCH)
2023-10-14 16:32:40 +00:00
2023-08-22 19:00:45 +00:00
def is_unrecorded(self, target: OcrResultButton, relative_area):
"""
To check a rogue keyword is not record in game index by finding template
"""
FLAG_UNRECORD.matched_button.search = area_offset(relative_area, target.area[:2])
return self.appear(FLAG_UNRECORD)
def handle_blessing_popup(self):
# Obtained a free blessing from curio
if self.appear(BLESSING_OBTAINED, interval=2):
logger.info(f'{BLESSING_OBTAINED} -> {BLESSING_CONFIRM}')
self.device.click(BLESSING_CONFIRM)
return True
# Enhanced a blessing from occurrence
if self.appear(BLESSING_ENHANCED, interval=2):
logger.info(f'{BLESSING_ENHANCED} -> {BLESSING_CONFIRM}')
self.device.click(BLESSING_CONFIRM)
return True
# Lost and re-obtain blessing, randomized by curio
if self.appear(BLESSING_LOST, interval=2):
logger.info(f'{BLESSING_LOST} -> {BLESSING_CONFIRM}')
self.device.click(BLESSING_CONFIRM)
return True
# Obtain a curio from occurrence
if self.appear(CURIO_OBTAINED, interval=2):
logger.info(f'{CURIO_OBTAINED} -> {BLESSING_CONFIRM}')
self.device.click(BLESSING_CONFIRM)
return True
return False