Upd: synthesize consumables optimization

This commit is contained in:
Driver-C 2023-06-19 23:12:36 +08:00
parent 9b05002be6
commit f160949d15
9 changed files with 85 additions and 25 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 259 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -233,6 +233,16 @@ MENU_GOTO_SYNTHESIZE = ButtonWrapper(
button=(994, 389, 1035, 424), button=(994, 389, 1035, 424),
), ),
) )
MENU_SCROLL = ButtonWrapper(
name='MENU_SCROLL',
share=Button(
file='./assets/share/base/page/MENU_SCROLL.png',
area=(1178, 261, 1184, 681),
search=(1158, 241, 1204, 701),
color=(100, 100, 105),
button=(1178, 261, 1184, 681),
),
)
MESSAGE_CLOSE = ButtonWrapper( MESSAGE_CLOSE = ButtonWrapper(
name='MESSAGE_CLOSE', name='MESSAGE_CLOSE',
share=Button( share=Button(

View File

@ -73,6 +73,26 @@ RECIPE_UNLOCK = ButtonWrapper(
button=(836, 647, 913, 668), button=(836, 647, 913, 668),
), ),
) )
SIMPLE_PROTECTIVE_GEAR = ButtonWrapper(
name='SIMPLE_PROTECTIVE_GEAR',
share=Button(
file='./assets/share/daily/synthesize_consumable/SIMPLE_PROTECTIVE_GEAR.png',
area=(244, 356, 316, 409),
search=(119, 84, 437, 573),
color=(94, 110, 115),
button=(244, 356, 316, 409),
),
)
SIMPLE_PROTECTIVE_GEAR_CHECK = ButtonWrapper(
name='SIMPLE_PROTECTIVE_GEAR_CHECK',
share=Button(
file='./assets/share/daily/synthesize_consumable/SIMPLE_PROTECTIVE_GEAR_CHECK.png',
area=(578, 196, 692, 256),
search=(558, 176, 712, 276),
color=(107, 106, 108),
button=(578, 196, 692, 256),
),
)
SYNTHESIZE_CONFIRM = ButtonWrapper( SYNTHESIZE_CONFIRM = ButtonWrapper(
name='SYNTHESIZE_CONFIRM', name='SYNTHESIZE_CONFIRM',
cn=Button( cn=Button(
@ -83,16 +103,6 @@ SYNTHESIZE_CONFIRM = ButtonWrapper(
button=(847, 645, 895, 672), button=(847, 645, 895, 672),
), ),
) )
SYNTHESIZE_CONFIRM_POPUP = ButtonWrapper(
name='SYNTHESIZE_CONFIRM_POPUP',
cn=Button(
file='./assets/cn/daily/synthesize_consumable/SYNTHESIZE_CONFIRM_POPUP.png',
area=(770, 476, 857, 506),
search=(750, 456, 877, 526),
color=(176, 175, 172),
button=(770, 476, 857, 506),
),
)
SYNTHESIZE_CONSUMABLES_CHECK = ButtonWrapper( SYNTHESIZE_CONSUMABLES_CHECK = ButtonWrapper(
name='SYNTHESIZE_CONSUMABLES_CHECK', name='SYNTHESIZE_CONSUMABLES_CHECK',
share=Button( share=Button(
@ -113,3 +123,13 @@ SYNTHESIZE_GOTO_CONSUMABLES = ButtonWrapper(
button=(38, 120, 78, 141), button=(38, 120, 78, 141),
), ),
) )
SYNTHESIZE_SCROLL = ButtonWrapper(
name='SYNTHESIZE_SCROLL',
cn=Button(
file='./assets/cn/daily/synthesize_consumable/SYNTHESIZE_SCROLL.png',
area=(458, 80, 464, 628),
search=(438, 60, 484, 648),
color=(134, 130, 144),
button=(458, 80, 464, 628),
),
)

View File

@ -4,6 +4,8 @@ from tasks.base.assets.assets_base_page import MENU_CHECK, SYNTHESIZE_CHECK
from tasks.base.assets.assets_base_popup import GET_REWARD from tasks.base.assets.assets_base_popup import GET_REWARD
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 CONFIRM_POPUP
from tasks.daily.assets.assets_daily_synthesize_consumable import * from tasks.daily.assets.assets_daily_synthesize_consumable import *
@ -25,10 +27,10 @@ class SynthesizeUI(UI):
match page: match page:
case page_menu.name: case page_menu.name:
check_image = MENU_CHECK check_image = MENU_CHECK
scroll = Scroll((1177, 261, 1183, 682), color=(191, 191, 191), name='MENU_SCROLL') scroll = Scroll(MENU_SCROLL.button, color=(191, 191, 191), name=MENU_SCROLL.name)
case page_synthesize.name: case page_synthesize.name:
check_image = SYNTHESIZE_CHECK check_image = SYNTHESIZE_CHECK
scroll = Scroll((458, 80, 463, 662), color=(210, 210, 210), name='SYNTHESIZE_SCROLL') scroll = Scroll(SYNTHESIZE_SCROLL.button, color=(210, 210, 210), name=SYNTHESIZE_SCROLL.name)
case _: case _:
logger.info(f'No page matched, just skip') logger.info(f'No page matched, just skip')
return return
@ -57,8 +59,13 @@ class SynthesizeUI(UI):
class SynthesizeConsumablesUI(SynthesizeUI): class SynthesizeConsumablesUI(SynthesizeUI):
def synthesize_consumables(self) -> bool: def synthesize_consumables(self, target_button: ButtonWrapper = None,
target_button_check: ButtonWrapper = None) -> bool:
""" """
Args:
target_button(ButtonWrapper):
target_button_check(ButtonWrapper):
Returns: Returns:
bool: bool:
@ -67,6 +74,7 @@ class SynthesizeConsumablesUI(SynthesizeUI):
self.device.screenshot() self.device.screenshot()
result = self.synthesize_consumables() result = self.synthesize_consumables()
""" """
logger.hr('Synthesize consumables', level=2) logger.hr('Synthesize consumables', level=2)
# If the current page is not the menu page, # If the current page is not the menu page,
# the menu scroll bar must be at the top when opening the menu page from other page, # the menu scroll bar must be at the top when opening the menu page from other page,
@ -76,7 +84,7 @@ class SynthesizeConsumablesUI(SynthesizeUI):
self.ui_ensure(page_synthesize) self.ui_ensure(page_synthesize)
self._switch_tag_to_consumables() self._switch_tag_to_consumables()
self.ensure_scroll_top(page=page_synthesize) self.ensure_scroll_top(page=page_synthesize)
if self._select_items(): if self._search_and_select_items(target_button, target_button_check):
self._open_synthesize_popup() self._open_synthesize_popup()
self._synthesize_confirm() self._synthesize_confirm()
self._back_to_synthesize_page() self._back_to_synthesize_page()
@ -99,15 +107,10 @@ class SynthesizeConsumablesUI(SynthesizeUI):
logger.info('Switch to consumables subpage') logger.info('Switch to consumables subpage')
continue continue
def _select_items(self) -> bool: def _select_items(self, candidate_items: dict[ButtonWrapper, ButtonWrapper]) -> bool:
candidate_items = {
CONSUMABLES_TRICK_SNACK: CONSUMABLES_TRICK_SNACK_CHECK,
CONSUMABLES_COMFORT_FOOD: CONSUMABLES_COMFORT_FOOD_CHECK,
CONSUMABLES_SIMPLE_AED: CONSUMABLES_SIMPLE_AED_CHECK
}
for item, item_check in candidate_items.items(): for item, item_check in candidate_items.items():
# Determine if the "item" can be found and synthesized in the left item column # Determine if the "item" can be found and synthesized in the left item column
if item.match_template_color(self.device.image): if item.match_template_color(self.device.image, similarity=0.7):
logger.info('Find an item that can be synthesized') logger.info('Find an item that can be synthesized')
# Ensure that item is selected # Ensure that item is selected
skip_first_screenshot = True skip_first_screenshot = True
@ -119,12 +122,39 @@ class SynthesizeConsumablesUI(SynthesizeUI):
if self.appear(item_check): if self.appear(item_check):
logger.info('Consumables that can be synthesized have been selected') logger.info('Consumables that can be synthesized have been selected')
return True return True
if self.appear_then_click(item): if self.appear_then_click(item, similarity=0.7):
continue continue
else: else:
logger.info('There are no suitable items to synthesize')
return False return False
def _search_and_select_items(self, target_button: ButtonWrapper = None,
target_button_check: ButtonWrapper = None) -> bool:
candidate_items = {target_button: target_button_check} if target_button and target_button_check else {
CONSUMABLES_TRICK_SNACK: CONSUMABLES_TRICK_SNACK_CHECK,
CONSUMABLES_COMFORT_FOOD: CONSUMABLES_COMFORT_FOOD_CHECK,
CONSUMABLES_SIMPLE_AED: CONSUMABLES_SIMPLE_AED_CHECK
}
# Search target button from top to bottom
scroll = Scroll(SYNTHESIZE_SCROLL.button, color=(210, 210, 210), name=SYNTHESIZE_SCROLL.name)
if scroll.appear(main=self):
skip_first_screenshot = True
while 1:
if skip_first_screenshot:
skip_first_screenshot = False
else:
self.device.screenshot()
if self._select_items(candidate_items):
return True
if scroll.at_bottom(main=self):
logger.info('There are no suitable items to synthesize')
return False
if not scroll.at_bottom(main=self):
scroll.next_page(main=self)
continue
else:
return self._select_items(candidate_items)
def _open_synthesize_popup(self, skip_first_screenshot=True): def _open_synthesize_popup(self, skip_first_screenshot=True):
while 1: while 1:
if skip_first_screenshot: if skip_first_screenshot:
@ -132,7 +162,7 @@ class SynthesizeConsumablesUI(SynthesizeUI):
else: else:
self.device.screenshot() self.device.screenshot()
if self.appear(SYNTHESIZE_CONFIRM_POPUP): if self.appear(CONFIRM_POPUP):
logger.info('Synthesize confirm popup window appear') logger.info('Synthesize confirm popup window appear')
break break
# The recipe of the item has not been unlocked yet, but it can be unlocked now # The recipe of the item has not been unlocked yet, but it can be unlocked now
@ -156,7 +186,7 @@ class SynthesizeConsumablesUI(SynthesizeUI):
logger.info('Synthesize consumable completed') logger.info('Synthesize consumable completed')
break break
# Synthesize confirm # Synthesize confirm
if self.appear_then_click(SYNTHESIZE_CONFIRM_POPUP): if self.appear_then_click(CONFIRM_POPUP):
logger.info('Click the confirm button') logger.info('Click the confirm button')
continue continue