Fix: Handle rogue blessing popup at login

This commit is contained in:
LmeSzinc 2024-11-12 19:28:37 +08:00
parent 1b10d1bef3
commit 423f639ce6
5 changed files with 49 additions and 49 deletions

View File

@ -2,12 +2,12 @@ from module.base.timer import Timer
from module.exception import GameNotRunningError
from module.logger import logger
from tasks.base.page import page_main
from tasks.base.ui import UI
from tasks.login.assets.assets_login import *
from tasks.login.cloud import LoginAndroidCloud
from tasks.rogue.blessing.ui import RogueUI
class Login(UI, LoginAndroidCloud):
class Login(LoginAndroidCloud, RogueUI):
def _handle_app_login(self):
"""
Pages:
@ -71,6 +71,8 @@ class Login(UI, LoginAndroidCloud):
continue
if self.ui_additional():
continue
if self.handle_blessing():
continue
return True

View File

@ -1,16 +1,29 @@
import re
import numpy as np
from module.base.timer import Timer
from module.logger import logger
from module.ocr.ocr import OcrResultButton
from module.ocr.ocr import Ocr, OcrResultButton
from tasks.rogue.assets.assets_rogue_blessing import OCR_ROGUE_BUFF
from tasks.rogue.assets.assets_rogue_bonus import BONUS_BOTTOM_WHITE_BAR, BONUS_CONFIRM
from tasks.rogue.blessing.selector import RogueSelector
from tasks.rogue.blessing.ui import RogueBonusOcr
from tasks.rogue.blessing.utils import is_card_selected
from tasks.rogue.keywords import RogueBonus
class RogueBonusOcr(Ocr):
def after_process(self, result):
result = super().after_process(result)
if self.lang == 'cn':
replace_pattern_dict = {
"[宇宝][宙审]": "宇宙",
}
for pat, replace in replace_pattern_dict.items():
result = re.sub(pat, replace, result)
return result
class RogueBonusSelector(RogueSelector):
def _wait_bonus_page_loaded(self, timer=Timer(0.3, count=1), timeout=Timer(5, count=10)):
timer.reset()

View File

@ -3,7 +3,6 @@ import numpy as np
from module.logger import logger
from module.ocr.keyword import Keyword
from module.ocr.ocr import OcrResultButton
from tasks.rogue.blessing.ui import RogueUI
class RogueSelector:
@ -11,7 +10,7 @@ class RogueSelector:
An Interface used in blessing, curio, and other ui selection in rogue
"""
def __init__(self, main: RogueUI):
def __init__(self, main: "RogueUI"):
self.main = main
self.filter_ = None
self.ocr_results = []

View File

@ -1,26 +1,15 @@
import re
from module.base.utils import area_offset
from module.logger import logger
from module.ocr.ocr import Digit, Ocr, OcrResultButton
from module.ocr.ocr import Digit, OcrResultButton
from tasks.base.ui import UI
from tasks.rogue.assets.assets_rogue_ui import *
from tasks.rogue.assets.assets_rogue_weekly import REWARD_ENTER
from tasks.rogue.blessing.blessing import RogueBlessingSelector
from tasks.rogue.blessing.bonus import RogueBonusSelector
from tasks.rogue.blessing.curio import RogueCurioSelector
from tasks.rogue.keywords import RoguePath
class RogueBonusOcr(Ocr):
def after_process(self, result):
result = super().after_process(result)
if self.lang == 'cn':
replace_pattern_dict = {
"[宇宝][宙审]": "宇宙",
}
for pat, replace in replace_pattern_dict.items():
result = re.sub(pat, replace, result)
return result
class RogueUI(UI):
path: RoguePath
@ -86,3 +75,28 @@ class RogueUI(UI):
self.device.click(BLESSING_CONFIRM)
return True
return False
def handle_blessing(self):
"""
Returns:
bool: If handled
"""
if self.is_page_choose_blessing():
logger.hr('Choose blessing', level=2)
selector = RogueBlessingSelector(self)
selector.recognize_and_select()
return True
if self.is_page_choose_curio():
logger.hr('Choose curio', level=2)
selector = RogueCurioSelector(self)
selector.recognize_and_select()
return True
if self.is_page_choose_bonus():
logger.hr('Choose bonus', level=2)
selector = RogueBonusSelector(self)
selector.recognize_and_select()
return True
if self.handle_blessing_popup():
return True
return False

View File

@ -7,9 +7,6 @@ from tasks.map.control.waypoint import Waypoint, ensure_waypoints
from tasks.map.route.base import RouteBase as RouteBase_
from tasks.rogue.assets.assets_rogue_ui import BLESSING_CONFIRM
from tasks.rogue.assets.assets_rogue_weekly import ROGUE_REPORT
from tasks.rogue.blessing.blessing import RogueBlessingSelector
from tasks.rogue.blessing.bonus import RogueBonusSelector
from tasks.rogue.blessing.curio import RogueCurioSelector
from tasks.rogue.event.event import RogueEvent
from tasks.rogue.event.reward import RogueReward
from tasks.rogue.route.exit import RogueExit
@ -45,31 +42,6 @@ class RouteBase(RouteBase_, RogueExit, RogueEvent, RogueReward):
return True
return super().walk_additional()
def handle_blessing(self):
"""
Returns:
bool: If handled
"""
if self.is_page_choose_blessing():
logger.hr('Choose blessing', level=2)
selector = RogueBlessingSelector(self)
selector.recognize_and_select()
return True
if self.is_page_choose_curio():
logger.hr('Choose curio', level=2)
selector = RogueCurioSelector(self)
selector.recognize_and_select()
return True
if self.is_page_choose_bonus():
logger.hr('Choose bonus', level=2)
selector = RogueBonusSelector(self)
selector.recognize_and_select()
return True
if self.handle_blessing_popup():
return True
return False
def clear_blessing(self, skip_first_screenshot=True):
"""
Pages: