Add: Daily task 'Consumable usage' (#14)
BIN
assets/cn/base/popup/CANCEL_POPUP.SEARCH.png
Normal file
After Width: | Height: | Size: 24 KiB |
BIN
assets/cn/base/popup/CANCEL_POPUP.png
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
assets/cn/base/popup/CONFIRM_POPUP.SEARCH.png
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
assets/cn/base/popup/CONFIRM_POPUP.png
Normal file
After Width: | Height: | Size: 7.3 KiB |
BIN
assets/cn/daily/consumable_usage/ITEM_CONSUMABLE_SCROLL.png
Normal file
After Width: | Height: | Size: 9.5 KiB |
BIN
assets/cn/daily/consumable_usage/USE_CONSUMABLE.png
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
assets/share/daily/consumable_usage/ITEM_CONSUMABLE_CHECK.png
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
assets/share/daily/consumable_usage/ITEM_GOTO_CONSUMABLE.png
Normal file
After Width: | Height: | Size: 6.3 KiB |
After Width: | Height: | Size: 373 KiB |
BIN
assets/share/daily/consumable_usage/SIMPLE_PROTECTIVE_GEAR.png
Normal file
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 27 KiB |
@ -13,6 +13,26 @@ BATTLE_PASS_NOTIFICATION = ButtonWrapper(
|
||||
button=(895, 595, 1180, 630),
|
||||
),
|
||||
)
|
||||
CANCEL_POPUP = ButtonWrapper(
|
||||
name='CANCEL_POPUP',
|
||||
cn=Button(
|
||||
file='./assets/cn/base/popup/CANCEL_POPUP.png',
|
||||
area=(427, 536, 503, 562),
|
||||
search=(321, 432, 661, 668),
|
||||
color=(157, 156, 152),
|
||||
button=(427, 536, 503, 562),
|
||||
),
|
||||
)
|
||||
CONFIRM_POPUP = ButtonWrapper(
|
||||
name='CONFIRM_POPUP',
|
||||
cn=Button(
|
||||
file='./assets/cn/base/popup/CONFIRM_POPUP.png',
|
||||
area=(774, 534, 855, 563),
|
||||
search=(617, 434, 966, 652),
|
||||
color=(170, 169, 166),
|
||||
button=(774, 534, 855, 563),
|
||||
),
|
||||
)
|
||||
GET_REWARD = ButtonWrapper(
|
||||
name='GET_REWARD',
|
||||
share=Button(
|
||||
|
65
tasks/daily/assets/assets_daily_consumable_usage.py
Normal file
@ -0,0 +1,65 @@
|
||||
from module.base.button import Button, ButtonWrapper
|
||||
|
||||
# This file was auto-generated, do not modify it manually. To generate:
|
||||
# ``` python -m dev_tools.button_extract ```
|
||||
|
||||
ITEM_CONSUMABLE_CHECK = ButtonWrapper(
|
||||
name='ITEM_CONSUMABLE_CHECK',
|
||||
share=Button(
|
||||
file='./assets/share/daily/consumable_usage/ITEM_CONSUMABLE_CHECK.png',
|
||||
area=(39, 476, 78, 499),
|
||||
search=(19, 456, 98, 519),
|
||||
color=(137, 138, 139),
|
||||
button=(39, 476, 78, 499),
|
||||
),
|
||||
)
|
||||
ITEM_CONSUMABLE_SCROLL = ButtonWrapper(
|
||||
name='ITEM_CONSUMABLE_SCROLL',
|
||||
cn=Button(
|
||||
file='./assets/cn/daily/consumable_usage/ITEM_CONSUMABLE_SCROLL.png',
|
||||
area=(837, 89, 843, 615),
|
||||
search=(817, 69, 863, 635),
|
||||
color=(118, 117, 121),
|
||||
button=(837, 89, 843, 615),
|
||||
),
|
||||
)
|
||||
ITEM_GOTO_CONSUMABLE = ButtonWrapper(
|
||||
name='ITEM_GOTO_CONSUMABLE',
|
||||
share=Button(
|
||||
file='./assets/share/daily/consumable_usage/ITEM_GOTO_CONSUMABLE.png',
|
||||
area=(38, 476, 80, 499),
|
||||
search=(18, 456, 100, 519),
|
||||
color=(104, 106, 117),
|
||||
button=(38, 476, 80, 499),
|
||||
),
|
||||
)
|
||||
SIMPLE_PROTECTIVE_GEAR = ButtonWrapper(
|
||||
name='SIMPLE_PROTECTIVE_GEAR',
|
||||
share=Button(
|
||||
file='./assets/share/daily/consumable_usage/SIMPLE_PROTECTIVE_GEAR.png',
|
||||
area=(164, 496, 236, 552),
|
||||
search=(148, 87, 770, 579),
|
||||
color=(93, 110, 115),
|
||||
button=(164, 496, 236, 552),
|
||||
),
|
||||
)
|
||||
SIMPLE_PROTECTIVE_GEAR_CHECK = ButtonWrapper(
|
||||
name='SIMPLE_PROTECTIVE_GEAR_CHECK',
|
||||
share=Button(
|
||||
file='./assets/share/daily/consumable_usage/SIMPLE_PROTECTIVE_GEAR_CHECK.png',
|
||||
area=(1059, 190, 1177, 278),
|
||||
search=(1039, 170, 1197, 298),
|
||||
color=(94, 114, 121),
|
||||
button=(1059, 190, 1177, 278),
|
||||
),
|
||||
)
|
||||
USE_CONSUMABLE = ButtonWrapper(
|
||||
name='USE_CONSUMABLE',
|
||||
cn=Button(
|
||||
file='./assets/cn/daily/consumable_usage/USE_CONSUMABLE.png',
|
||||
area=(1042, 647, 1084, 669),
|
||||
search=(1022, 627, 1104, 689),
|
||||
color=(158, 158, 159),
|
||||
button=(1042, 647, 1084, 669),
|
||||
),
|
||||
)
|
130
tasks/daily/consumable_usage.py
Normal file
@ -0,0 +1,130 @@
|
||||
from module.ocr.ocr import *
|
||||
from module.ui.scroll import Scroll
|
||||
from tasks.base.page import page_item
|
||||
from tasks.base.ui import UI
|
||||
from tasks.base.assets.assets_base_popup import CONFIRM_POPUP
|
||||
from tasks.daily.assets.assets_daily_consumable_usage import *
|
||||
|
||||
|
||||
class ConsumableUsageUI(UI):
|
||||
def use_consumable(self) -> bool:
|
||||
"""
|
||||
Returns:
|
||||
bool:
|
||||
|
||||
Examples:
|
||||
self = ConsumableUsageUI('alas')
|
||||
self.device.screenshot()
|
||||
result = self.use_consumable()
|
||||
"""
|
||||
self.ui_ensure(page_item)
|
||||
self._switch_tag_to_consumables()
|
||||
if self._search_and_select_consumable():
|
||||
self._click_use()
|
||||
self._confirm_use()
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def _switch_tag_to_consumables(self, skip_first_screenshot=True):
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
self.device.screenshot()
|
||||
|
||||
# Scroll bar delay appears, need an interval here
|
||||
if self.appear(ITEM_CONSUMABLE_CHECK, interval=1):
|
||||
logger.info('Item consumables page appear')
|
||||
break
|
||||
# Switch to consumables subpage
|
||||
if self.appear_then_click(ITEM_GOTO_CONSUMABLE):
|
||||
logger.info('Switch to consumables subpage')
|
||||
continue
|
||||
|
||||
def _search_and_select_consumable(self, skip_first_screenshot=True) -> bool:
|
||||
# If the default subpage is the consumables page, it is necessary to screenshot and check subpage again,
|
||||
# because in this scenario, scroll bar delay appears and the previous screenshot was
|
||||
# taken after clicking on the "item" to determine whether to enter the "item", which may be inaccurate
|
||||
self._switch_tag_to_consumables(False)
|
||||
|
||||
# Determine if there is a scroll bar. If there is a scroll bar,
|
||||
# pull it down and check if the consumable to be used can be found
|
||||
scroll = Scroll(area=ITEM_CONSUMABLE_SCROLL.button, color=(200, 200, 200), name=ITEM_CONSUMABLE_SCROLL.name)
|
||||
if scroll.appear(main=self):
|
||||
if not scroll.at_top(main=self):
|
||||
scroll.set_top(main=self)
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
self.device.screenshot()
|
||||
|
||||
# Determine if the specified consumable can be found
|
||||
if self.appear(SIMPLE_PROTECTIVE_GEAR_CHECK):
|
||||
logger.info('The consumable to be used have been selected')
|
||||
return True
|
||||
if scroll.at_bottom(main=self) and not self.appear(SIMPLE_PROTECTIVE_GEAR, similarity=0.7):
|
||||
logger.info('Can not find the consumable which to be used, just skip')
|
||||
return False
|
||||
if self.appear_then_click(SIMPLE_PROTECTIVE_GEAR, similarity=0.7):
|
||||
logger.info('Select the consumable which to be used')
|
||||
continue
|
||||
# Scroll bar flipping
|
||||
if not scroll.at_bottom(main=self):
|
||||
scroll.next_page(main=self)
|
||||
continue
|
||||
else:
|
||||
# Determine if the specified consumable can be found
|
||||
if self.appear(SIMPLE_PROTECTIVE_GEAR, similarity=0.7):
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
self.device.screenshot()
|
||||
|
||||
if self.appear(SIMPLE_PROTECTIVE_GEAR_CHECK):
|
||||
logger.info('The consumable to be used have been selected')
|
||||
return True
|
||||
if self.appear_then_click(SIMPLE_PROTECTIVE_GEAR, similarity=0.7):
|
||||
logger.info('Select the consumable which to be used')
|
||||
continue
|
||||
else:
|
||||
logger.info('Can not find the consumable which to be used, just skip')
|
||||
return False
|
||||
|
||||
def _click_use(self, skip_first_screenshot=True):
|
||||
"""
|
||||
Description:
|
||||
Because after executing "using consumable",
|
||||
there will be a brief animation that will directly return to the consumables page,
|
||||
so "click to use" and "confirm to use" have been split into two steps
|
||||
"""
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
self.device.screenshot()
|
||||
|
||||
if self.appear(CONFIRM_POPUP):
|
||||
logger.info('Item consumable usage popup appear')
|
||||
break
|
||||
if self.appear_then_click(USE_CONSUMABLE):
|
||||
logger.info('Click the "use" button')
|
||||
continue
|
||||
|
||||
def _confirm_use(self, skip_first_screenshot=True):
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
self.device.screenshot()
|
||||
|
||||
if self.appear(ITEM_CONSUMABLE_CHECK):
|
||||
logger.info('Complete using consumables')
|
||||
break
|
||||
# If there is already consumable effect, a confirmation box will pop up again,
|
||||
# so shorten the judgment interval of the confirmation box
|
||||
if self.appear_then_click(CONFIRM_POPUP, interval=1):
|
||||
logger.info('Confirm the use of consumable')
|
||||
continue
|