2023-07-14 04:35:56 +00:00
|
|
|
from module.base.timer import Timer
|
|
|
|
from module.logger import logger
|
|
|
|
from tasks.base.assets.assets_base_page import CLOSE
|
2023-09-16 21:00:16 +00:00
|
|
|
from tasks.base.assets.assets_base_popup import GET_REWARD
|
2023-07-14 04:35:56 +00:00
|
|
|
from tasks.item.assets.assets_item_relics import *
|
|
|
|
from tasks.item.keywords import KEYWORD_ITEM_TAB
|
|
|
|
from tasks.item.ui import ItemUI
|
|
|
|
|
|
|
|
|
|
|
|
class RelicsUI(ItemUI):
|
2023-07-14 17:26:00 +00:00
|
|
|
def _is_in_salvage(self) -> bool:
|
|
|
|
return self.appear(ORDER_ASCENDING) or self.appear(ORDER_DESCENDING)
|
|
|
|
|
2023-10-09 04:33:33 +00:00
|
|
|
def salvage_exit(self, skip_first_screenshot=True):
|
|
|
|
"""
|
|
|
|
Pages:
|
|
|
|
in: rewards claimed
|
|
|
|
or _is_in_salvage()
|
|
|
|
out: GOTO_SALVAGE
|
|
|
|
"""
|
|
|
|
interval = Timer(1)
|
|
|
|
while 1:
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
|
|
|
if self.appear(GOTO_SALVAGE):
|
|
|
|
logger.info("Salvage page exited")
|
|
|
|
break
|
|
|
|
if self.handle_reward(interval=2):
|
|
|
|
continue
|
|
|
|
if interval.reached() and self._is_in_salvage():
|
|
|
|
logger.info(f'_is_in_salvage -> {CLOSE}')
|
|
|
|
self.device.click(CLOSE)
|
|
|
|
interval.reset()
|
|
|
|
continue
|
|
|
|
|
2023-07-14 04:35:56 +00:00
|
|
|
def salvage_relic(self, skip_first_screenshot=True) -> bool:
|
2023-10-09 04:33:33 +00:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
skip_first_screenshot:
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
bool: If success
|
|
|
|
|
|
|
|
Pages:
|
|
|
|
in: Any
|
|
|
|
out: page_item, GOTO_SALVAGE
|
|
|
|
"""
|
2023-07-14 04:35:56 +00:00
|
|
|
logger.hr('Salvage Relic', level=2)
|
|
|
|
self.item_goto(KEYWORD_ITEM_TAB.Relics, wait_until_stable=False)
|
|
|
|
while 1: # relic tab -> salvage
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
2023-07-14 17:26:00 +00:00
|
|
|
if self._is_in_salvage():
|
2023-07-24 15:53:59 +00:00
|
|
|
logger.info('_is_in_salvage')
|
2023-07-14 04:35:56 +00:00
|
|
|
break
|
2023-07-14 17:26:00 +00:00
|
|
|
if self.appear_then_click(GOTO_SALVAGE, interval=2):
|
2023-07-14 04:35:56 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
skip_first_screenshot = True
|
2023-07-14 17:26:00 +00:00
|
|
|
interval = Timer(1)
|
2023-10-02 04:28:31 +00:00
|
|
|
timeout = Timer(5, count=3).start()
|
2023-07-14 04:35:56 +00:00
|
|
|
while 1: # salvage -> first relic selected
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
2023-10-02 04:28:31 +00:00
|
|
|
if timeout.reached():
|
|
|
|
logger.warning('Timeout when selecting first relic')
|
2023-10-09 04:33:33 +00:00
|
|
|
self.salvage_exit()
|
2023-10-02 04:28:31 +00:00
|
|
|
return False
|
2023-07-24 15:53:59 +00:00
|
|
|
# The first frame entering relic page, SALVAGE is a white button as it's the default state.
|
|
|
|
# At the second frame, SALVAGE is disabled since no items are selected.
|
|
|
|
# So here uses the minus button on the first relic.
|
2023-10-02 04:28:31 +00:00
|
|
|
if self.image_color_count(FIRST_RELIC_SELECTED, color=(245, 245, 245), threshold=221, count=300):
|
2023-07-24 15:53:59 +00:00
|
|
|
logger.info('First relic selected')
|
2023-07-14 04:35:56 +00:00
|
|
|
break
|
2023-07-14 17:26:00 +00:00
|
|
|
if self.appear_then_click(ORDER_DESCENDING, interval=2):
|
|
|
|
continue
|
2023-07-24 15:53:59 +00:00
|
|
|
if interval.reached() and self.appear(ORDER_ASCENDING) \
|
|
|
|
and self.image_color_count(FIRST_RELIC, (233, 192, 108)):
|
2023-07-14 04:35:56 +00:00
|
|
|
self.device.click(FIRST_RELIC)
|
|
|
|
interval.reset()
|
|
|
|
continue
|
|
|
|
|
|
|
|
skip_first_screenshot = True
|
|
|
|
while 1: # selected -> rewards claimed
|
|
|
|
if skip_first_screenshot:
|
|
|
|
skip_first_screenshot = False
|
|
|
|
else:
|
|
|
|
self.device.screenshot()
|
|
|
|
|
2023-07-14 17:26:00 +00:00
|
|
|
if self.appear(GET_REWARD):
|
2023-07-14 04:35:56 +00:00
|
|
|
logger.info("Relic salvaged")
|
|
|
|
break
|
2023-07-14 17:26:00 +00:00
|
|
|
if self.appear_then_click(SALVAGE, interval=2):
|
2023-07-14 04:35:56 +00:00
|
|
|
continue
|
2023-09-16 21:00:16 +00:00
|
|
|
if self.handle_popup_confirm():
|
2023-07-14 04:35:56 +00:00
|
|
|
continue
|
|
|
|
|
2023-10-09 04:33:33 +00:00
|
|
|
self.salvage_exit()
|
2023-07-14 04:35:56 +00:00
|
|
|
return True
|