mirror of
https://github.com/LmeSzinc/StarRailCopilot.git
synced 2024-11-22 08:37:42 +00:00
Fix: Handle reward on complex background
This commit is contained in:
parent
4adfa00148
commit
e1468db85d
BIN
assets/share/base/popup/GET_REWARD.2.png
Normal file
BIN
assets/share/base/popup/GET_REWARD.2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.4 KiB After Width: | Height: | Size: 2.3 KiB |
@ -32,13 +32,22 @@ GET_LIGHT_CONE = ButtonWrapper(
|
|||||||
)
|
)
|
||||||
GET_REWARD = ButtonWrapper(
|
GET_REWARD = ButtonWrapper(
|
||||||
name='GET_REWARD',
|
name='GET_REWARD',
|
||||||
share=Button(
|
share=[
|
||||||
|
Button(
|
||||||
file='./assets/share/base/popup/GET_REWARD.png',
|
file='./assets/share/base/popup/GET_REWARD.png',
|
||||||
area=(623, 95, 657, 119),
|
area=(625, 95, 655, 119),
|
||||||
search=(603, 75, 677, 139),
|
search=(605, 75, 675, 139),
|
||||||
color=(145, 131, 99),
|
color=(213, 0, 0),
|
||||||
button=(741, 495, 1071, 644),
|
button=(741, 495, 1071, 644),
|
||||||
),
|
),
|
||||||
|
Button(
|
||||||
|
file='./assets/share/base/popup/GET_REWARD.2.png',
|
||||||
|
area=(625, 144, 655, 168),
|
||||||
|
search=(605, 124, 675, 188),
|
||||||
|
color=(226, 0, 0),
|
||||||
|
button=(625, 144, 655, 168),
|
||||||
|
),
|
||||||
|
],
|
||||||
)
|
)
|
||||||
MONTHLY_CARD_GET_ITEM = ButtonWrapper(
|
MONTHLY_CARD_GET_ITEM = ButtonWrapper(
|
||||||
name='MONTHLY_CARD_GET_ITEM',
|
name='MONTHLY_CARD_GET_ITEM',
|
||||||
|
@ -1,10 +1,22 @@
|
|||||||
|
from typing import Callable
|
||||||
|
|
||||||
from module.base.base import ModuleBase
|
from module.base.base import ModuleBase
|
||||||
|
from module.base.utils import color_similarity_2d
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
|
from tasks.base.assets.assets_base_page import BACK, CLOSE
|
||||||
from tasks.base.assets.assets_base_popup import *
|
from tasks.base.assets.assets_base_popup import *
|
||||||
|
|
||||||
|
|
||||||
class PopupHandler(ModuleBase):
|
class PopupHandler(ModuleBase):
|
||||||
def handle_reward(self, interval=5, click_button=None) -> bool:
|
def reward_appear(self) -> bool:
|
||||||
|
for button in GET_REWARD.buttons:
|
||||||
|
image = self.image_crop(button.search, copy=False)
|
||||||
|
image = color_similarity_2d(image, color=(203, 181, 132))
|
||||||
|
if button.match_template(image, direct_match=True):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def handle_reward(self, interval=5, click_button: ButtonWrapper = None) -> bool:
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
interval:
|
interval:
|
||||||
@ -13,16 +25,26 @@ class PopupHandler(ModuleBase):
|
|||||||
Returns:
|
Returns:
|
||||||
If handled.
|
If handled.
|
||||||
"""
|
"""
|
||||||
|
# Same as ModuleBase.match_template()
|
||||||
|
self.device.stuck_record_add(GET_REWARD)
|
||||||
|
|
||||||
|
if interval and not self.interval_is_reached(GET_REWARD, interval=interval):
|
||||||
|
return False
|
||||||
|
|
||||||
|
appear = self.reward_appear()
|
||||||
|
|
||||||
if click_button is None:
|
if click_button is None:
|
||||||
if self.appear_then_click(GET_REWARD, interval=interval):
|
if appear:
|
||||||
return True
|
self.device.click(GET_REWARD)
|
||||||
else:
|
else:
|
||||||
if self.appear(GET_REWARD, interval=interval):
|
if appear:
|
||||||
logger.info(f'{GET_REWARD} -> {click_button}')
|
logger.info(f'{GET_REWARD} -> {click_button}')
|
||||||
self.device.click(click_button)
|
self.device.click(click_button)
|
||||||
return True
|
|
||||||
|
|
||||||
return False
|
if appear and interval:
|
||||||
|
self.interval_reset(GET_REWARD, interval=interval)
|
||||||
|
|
||||||
|
return appear
|
||||||
|
|
||||||
def handle_battle_pass_notification(self, interval=5) -> bool:
|
def handle_battle_pass_notification(self, interval=5) -> bool:
|
||||||
"""
|
"""
|
||||||
@ -113,3 +135,66 @@ class PopupHandler(ModuleBase):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def handle_get_character(self, interval=2) -> bool:
|
||||||
|
"""
|
||||||
|
Popup when getting a character from rogue rewards.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
interval:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
If handled.
|
||||||
|
"""
|
||||||
|
if self.appear(GET_CHARACTER, interval=interval):
|
||||||
|
logger.info(f'{GET_CHARACTER} -> {GET_REWARD}')
|
||||||
|
self.device.click(GET_REWARD)
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def handle_ui_close(self, appear_button: ButtonWrapper | Callable, interval=2) -> bool:
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
appear_button: Click if button appears
|
||||||
|
interval:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
If handled.
|
||||||
|
"""
|
||||||
|
if callable(appear_button):
|
||||||
|
if self.interval_is_reached(appear_button, interval=interval) and appear_button():
|
||||||
|
logger.info(f'{appear_button.__name__} -> {CLOSE}')
|
||||||
|
self.device.click(CLOSE)
|
||||||
|
self.interval_reset(appear_button, interval=interval)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
if self.appear(appear_button, interval=interval):
|
||||||
|
logger.info(f'{appear_button} -> {CLOSE}')
|
||||||
|
self.device.click(CLOSE)
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def handle_ui_back(self, appear_button: ButtonWrapper | Callable, interval=2) -> bool:
|
||||||
|
"""
|
||||||
|
Args:
|
||||||
|
appear_button: Click if button appears
|
||||||
|
interval:
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
If handled.
|
||||||
|
"""
|
||||||
|
if callable(appear_button):
|
||||||
|
if self.interval_is_reached(appear_button, interval=interval) and appear_button():
|
||||||
|
logger.info(f'{appear_button.__name__} -> {BACK}')
|
||||||
|
self.device.click(BACK)
|
||||||
|
self.interval_reset(appear_button, interval=interval)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
if self.appear(appear_button, interval=interval):
|
||||||
|
logger.info(f'{appear_button} -> {BACK}')
|
||||||
|
self.device.click(BACK)
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
@ -12,7 +12,6 @@ from module.ocr.utils import split_and_pair_buttons
|
|||||||
from module.ui.scroll import Scroll
|
from module.ui.scroll import Scroll
|
||||||
from module.ui.switch import Switch
|
from module.ui.switch import Switch
|
||||||
from tasks.base.assets.assets_base_page import BATTLE_PASS_CHECK, MAIN_GOTO_BATTLE_PASS
|
from tasks.base.assets.assets_base_page import BATTLE_PASS_CHECK, MAIN_GOTO_BATTLE_PASS
|
||||||
from tasks.base.assets.assets_base_popup import GET_REWARD
|
|
||||||
from tasks.base.page import page_battle_pass, page_main
|
from tasks.base.page import page_battle_pass, page_main
|
||||||
from tasks.base.ui import UI
|
from tasks.base.ui import UI
|
||||||
from tasks.battle_pass.assets.assets_battle_pass import *
|
from tasks.battle_pass.assets.assets_battle_pass import *
|
||||||
@ -187,7 +186,7 @@ class BattlePassUI(UI):
|
|||||||
else:
|
else:
|
||||||
self.device.screenshot()
|
self.device.screenshot()
|
||||||
|
|
||||||
if self.appear(GET_REWARD):
|
if self.reward_appear():
|
||||||
logger.info('Get reward')
|
logger.info('Get reward')
|
||||||
break
|
break
|
||||||
if self.appear(CLOSE_CHOOSE_GIFT):
|
if self.appear(CLOSE_CHOOSE_GIFT):
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
from module.ocr.ocr import *
|
from module.ocr.ocr import *
|
||||||
from module.ui.scroll import Scroll
|
from module.ui.scroll import Scroll
|
||||||
from tasks.base.assets.assets_base_page import MENU_CHECK, SYNTHESIZE_CHECK
|
from tasks.base.assets.assets_base_page import MENU_CHECK, MENU_SCROLL, SYNTHESIZE_CHECK
|
||||||
from tasks.base.assets.assets_base_popup import GET_REWARD
|
from tasks.base.assets.assets_base_popup import POPUP_CONFIRM
|
||||||
from tasks.base.page import Page, page_menu, page_synthesize
|
from tasks.base.page import Page, page_menu, page_synthesize
|
||||||
from tasks.base.ui import UI
|
from tasks.base.ui import UI
|
||||||
from tasks.base.assets.assets_base_page import MENU_SCROLL
|
|
||||||
from tasks.base.assets.assets_base_popup import POPUP_CONFIRM
|
|
||||||
from tasks.daily.assets.assets_daily_synthesize_consumable import *
|
from tasks.daily.assets.assets_daily_synthesize_consumable import *
|
||||||
from tasks.daily.assets.assets_daily_synthesize_material import *
|
from tasks.daily.assets.assets_daily_synthesize_material import *
|
||||||
|
|
||||||
@ -157,7 +155,7 @@ class SynthesizeUI(UI):
|
|||||||
else:
|
else:
|
||||||
self.device.screenshot()
|
self.device.screenshot()
|
||||||
|
|
||||||
if self.appear(GET_REWARD):
|
if self.reward_appear():
|
||||||
logger.info('Synthesize consumable completed')
|
logger.info('Synthesize consumable completed')
|
||||||
break
|
break
|
||||||
# Synthesize confirm
|
# Synthesize confirm
|
||||||
@ -175,7 +173,7 @@ class SynthesizeUI(UI):
|
|||||||
logger.info('Synthesize consumables page appear')
|
logger.info('Synthesize consumables page appear')
|
||||||
break
|
break
|
||||||
# Go back to the previous page
|
# Go back to the previous page
|
||||||
if self.appear_then_click(GET_REWARD):
|
if self.handle_reward(interval=2):
|
||||||
logger.info('Click on the blank space to back to synthesize page')
|
logger.info('Click on the blank space to back to synthesize page')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from module.base.timer import Timer
|
from module.base.timer import Timer
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
from tasks.base.assets.assets_base_page import CLOSE, MENU_CHECK
|
from tasks.base.assets.assets_base_page import MENU_CHECK
|
||||||
from tasks.base.assets.assets_base_popup import GET_REWARD
|
|
||||||
from tasks.base.page import page_menu
|
from tasks.base.page import page_menu
|
||||||
from tasks.base.ui import UI
|
from tasks.base.ui import UI
|
||||||
from tasks.freebies.assets.assets_freebies_support_reward import (
|
from tasks.freebies.assets.assets_freebies_support_reward import (
|
||||||
@ -53,7 +52,7 @@ class SupportReward(UI):
|
|||||||
"""
|
"""
|
||||||
Pages:
|
Pages:
|
||||||
in: PROFILE
|
in: PROFILE
|
||||||
out: GET_REWARD
|
out: reward_appear()
|
||||||
"""
|
"""
|
||||||
logger.info('Getting reward')
|
logger.info('Getting reward')
|
||||||
claimed = False
|
claimed = False
|
||||||
@ -68,7 +67,7 @@ class SupportReward(UI):
|
|||||||
if not claimed and empty.reached():
|
if not claimed and empty.reached():
|
||||||
logger.info('No reward')
|
logger.info('No reward')
|
||||||
break
|
break
|
||||||
if self.appear(GET_REWARD):
|
if self.reward_appear():
|
||||||
logger.info('Got reward')
|
logger.info('Got reward')
|
||||||
break
|
break
|
||||||
if timeout.reached():
|
if timeout.reached():
|
||||||
@ -83,7 +82,7 @@ class SupportReward(UI):
|
|||||||
def _goto_menu(self):
|
def _goto_menu(self):
|
||||||
"""
|
"""
|
||||||
Pages:
|
Pages:
|
||||||
in: PROFILE or GET_REWARD
|
in: PROFILE or reward_appear
|
||||||
out: MENU
|
out: MENU
|
||||||
"""
|
"""
|
||||||
skip_first_screenshot = False
|
skip_first_screenshot = False
|
||||||
@ -97,9 +96,7 @@ class SupportReward(UI):
|
|||||||
if self.appear(MENU_CHECK):
|
if self.appear(MENU_CHECK):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if self.appear(IN_PROFILE, interval=2):
|
if self.handle_ui_close(IN_PROFILE, interval=2):
|
||||||
logger.info(f'{IN_PROFILE} -> {CLOSE}')
|
|
||||||
self.device.click(CLOSE)
|
|
||||||
continue
|
continue
|
||||||
if self.handle_reward(click_button=CAN_GET_REWARD):
|
if self.handle_reward(click_button=CAN_GET_REWARD):
|
||||||
# # Avoid clicking on some other buttons
|
# # Avoid clicking on some other buttons
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
from module.base.timer import Timer
|
from module.base.timer import Timer
|
||||||
from module.logger import logger
|
from module.logger import logger
|
||||||
from tasks.base.assets.assets_base_page import CLOSE
|
from tasks.base.assets.assets_base_page import CLOSE
|
||||||
from tasks.base.assets.assets_base_popup import GET_REWARD
|
|
||||||
from tasks.item.assets.assets_item_relics import *
|
from tasks.item.assets.assets_item_relics import *
|
||||||
from tasks.item.keywords import KEYWORD_ITEM_TAB
|
from tasks.item.keywords import KEYWORD_ITEM_TAB
|
||||||
from tasks.item.ui import ItemUI
|
from tasks.item.ui import ItemUI
|
||||||
@ -96,7 +95,7 @@ class RelicsUI(ItemUI):
|
|||||||
else:
|
else:
|
||||||
self.device.screenshot()
|
self.device.screenshot()
|
||||||
|
|
||||||
if self.appear(GET_REWARD):
|
if self.reward_appear():
|
||||||
logger.info("Relic salvaged")
|
logger.info("Relic salvaged")
|
||||||
break
|
break
|
||||||
if self.appear_then_click(SALVAGE, interval=2):
|
if self.appear_then_click(SALVAGE, interval=2):
|
||||||
|
Loading…
Reference in New Issue
Block a user