Add: reward module routine collect mail items; filter based on displayed icon
BIN
assets/cn/reward/MAIL_COLLECT.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
assets/cn/reward/MAIL_COLLECTED.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
assets/cn/reward/MAIL_DELETE.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
assets/cn/reward/MAIL_ENTER.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
assets/en/reward/MAIL_COLLECT.png
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
assets/en/reward/MAIL_COLLECTED.png
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
assets/en/reward/MAIL_DELETE.png
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
assets/en/reward/MAIL_ENTER.png
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
assets/stats_basic/Gem.png
Normal file
After Width: | Height: | Size: 18 KiB |
@ -6,6 +6,10 @@ from module.base.template import Template
|
||||
|
||||
COIN = Button(area={'cn': (279, 48, 308, 73), 'en': (272, 53, 317, 73), 'jp': (279, 48, 308, 73), 'tw': (279, 48, 308, 73)}, color={'cn': (228, 175, 73), 'en': (221, 170, 75), 'jp': (228, 175, 73), 'tw': (228, 175, 73)}, button={'cn': (279, 48, 308, 73), 'en': (272, 53, 317, 73), 'jp': (279, 48, 308, 73), 'tw': (279, 48, 308, 73)}, file={'cn': './assets/cn/reward/COIN.png', 'en': './assets/en/reward/COIN.png', 'jp': './assets/jp/reward/COIN.png', 'tw': './assets/tw/reward/COIN.png'})
|
||||
EXP = Button(area={'cn': (449, 31, 477, 49), 'en': (455, 51, 490, 71), 'jp': (449, 31, 477, 49), 'tw': (449, 31, 477, 49)}, color={'cn': (145, 158, 176), 'en': (133, 133, 145), 'jp': (145, 158, 176), 'tw': (145, 158, 176)}, button={'cn': (449, 31, 477, 49), 'en': (455, 51, 490, 71), 'jp': (449, 31, 477, 49), 'tw': (449, 31, 477, 49)}, file={'cn': './assets/cn/reward/EXP.png', 'en': './assets/en/reward/EXP.png', 'jp': './assets/jp/reward/EXP.png', 'tw': './assets/tw/reward/EXP.png'})
|
||||
MAIL_COLLECT = Button(area={'cn': (865, 583, 947, 601), 'en': (865, 583, 947, 601), 'jp': (865, 583, 947, 601), 'tw': (865, 583, 947, 601)}, color={'cn': (151, 180, 216), 'en': (151, 180, 216), 'jp': (151, 180, 216), 'tw': (151, 180, 216)}, button={'cn': (865, 583, 947, 601), 'en': (865, 583, 947, 601), 'jp': (865, 583, 947, 601), 'tw': (865, 583, 947, 601)}, file={'cn': './assets/cn/reward/MAIL_COLLECT.png', 'en': './assets/en/reward/MAIL_COLLECT.png', 'jp': './assets/cn/reward/MAIL_COLLECT.png', 'tw': './assets/cn/reward/MAIL_COLLECT.png'})
|
||||
MAIL_COLLECTED = Button(area={'cn': (835, 578, 975, 606), 'en': (835, 578, 975, 606), 'jp': (835, 578, 975, 606), 'tw': (835, 578, 975, 606)}, color={'cn': (54, 63, 71), 'en': (54, 63, 71), 'jp': (54, 63, 71), 'tw': (54, 63, 71)}, button={'cn': (835, 578, 975, 606), 'en': (835, 578, 975, 606), 'jp': (835, 578, 975, 606), 'tw': (835, 578, 975, 606)}, file={'cn': './assets/cn/reward/MAIL_COLLECTED.png', 'en': './assets/en/reward/MAIL_COLLECTED.png', 'jp': './assets/cn/reward/MAIL_COLLECTED.png', 'tw': './assets/cn/reward/MAIL_COLLECTED.png'})
|
||||
MAIL_DELETE = Button(area={'cn': (428, 567, 500, 584), 'en': (428, 567, 500, 584), 'jp': (428, 567, 500, 584), 'tw': (428, 567, 500, 584)}, color={'cn': (216, 173, 169), 'en': (216, 173, 169), 'jp': (216, 173, 169), 'tw': (216, 173, 169)}, button={'cn': (428, 567, 500, 584), 'en': (428, 567, 500, 584), 'jp': (428, 567, 500, 584), 'tw': (428, 567, 500, 584)}, file={'cn': './assets/cn/reward/MAIL_DELETE.png', 'en': './assets/en/reward/MAIL_DELETE.png', 'jp': './assets/cn/reward/MAIL_DELETE.png', 'tw': './assets/cn/reward/MAIL_DELETE.png'})
|
||||
MAIL_ENTER = Button(area={'cn': (1207, 393, 1253, 429), 'en': (1207, 393, 1253, 429), 'jp': (1207, 393, 1253, 429), 'tw': (1207, 393, 1253, 429)}, color={'cn': (109, 107, 95), 'en': (109, 107, 95), 'jp': (109, 107, 95), 'tw': (109, 107, 95)}, button={'cn': (1207, 393, 1253, 429), 'en': (1207, 393, 1253, 429), 'jp': (1207, 393, 1253, 429), 'tw': (1207, 393, 1253, 429)}, file={'cn': './assets/cn/reward/MAIL_ENTER.png', 'en': './assets/en/reward/MAIL_ENTER.png', 'jp': './assets/cn/reward/MAIL_ENTER.png', 'tw': './assets/cn/reward/MAIL_ENTER.png'})
|
||||
MISSION_MULTI = Button(area={'cn': (1041, 8, 1101, 39), 'en': (1041, 8, 1101, 39), 'jp': (1041, 7, 1102, 36), 'tw': (1040, 6, 1102, 39)}, color={'cn': (226, 192, 142), 'en': (221, 179, 96), 'jp': (219, 178, 110), 'tw': (223, 184, 121)}, button={'cn': (1041, 8, 1101, 39), 'en': (1041, 8, 1101, 39), 'jp': (1041, 7, 1102, 36), 'tw': (1040, 6, 1102, 39)}, file={'cn': './assets/cn/reward/MISSION_MULTI.png', 'en': './assets/en/reward/MISSION_MULTI.png', 'jp': './assets/jp/reward/MISSION_MULTI.png', 'tw': './assets/tw/reward/MISSION_MULTI.png'})
|
||||
MISSION_NOTICE = Button(area={'cn': (940, 670, 945, 681), 'en': (940, 670, 945, 681), 'jp': (940, 670, 945, 681), 'tw': (940, 670, 945, 681)}, color={'cn': (183, 83, 66), 'en': (183, 83, 66), 'jp': (183, 83, 66), 'tw': (183, 83, 66)}, button={'cn': (940, 670, 945, 681), 'en': (940, 670, 945, 681), 'jp': (940, 670, 945, 681), 'tw': (940, 670, 945, 681)}, file={'cn': './assets/cn/reward/MISSION_NOTICE.png', 'en': './assets/en/reward/MISSION_NOTICE.png', 'jp': './assets/jp/reward/MISSION_NOTICE.png', 'tw': './assets/tw/reward/MISSION_NOTICE.png'})
|
||||
MISSION_SINGLE = Button(area={'cn': (1093, 118, 1179, 177), 'en': (1093, 118, 1179, 177), 'jp': (1102, 120, 1166, 149), 'tw': (1090, 115, 1181, 166)}, color={'cn': (115, 155, 218), 'en': (106, 147, 215), 'jp': (136, 176, 226), 'tw': (108, 149, 216)}, button={'cn': (1093, 118, 1179, 177), 'en': (1093, 118, 1179, 177), 'jp': (1102, 120, 1166, 149), 'tw': (1090, 115, 1181, 166)}, file={'cn': './assets/cn/reward/MISSION_SINGLE.png', 'en': './assets/en/reward/MISSION_SINGLE.png', 'jp': './assets/jp/reward/MISSION_SINGLE.png', 'tw': './assets/tw/reward/MISSION_SINGLE.png'})
|
||||
|
@ -1,13 +1,28 @@
|
||||
import numpy as np
|
||||
import re
|
||||
|
||||
from module.base.button import ButtonGrid
|
||||
from module.base.decorator import cached_property
|
||||
from module.base.filter import Filter
|
||||
from module.base.timer import Timer
|
||||
from module.base.utils import crop, rgb2gray
|
||||
from module.combat.assets import *
|
||||
from module.logger import logger
|
||||
from module.reward.assets import *
|
||||
from module.statistics.item import ItemGrid
|
||||
from module.ui.navbar import Navbar
|
||||
from module.ui.page import *
|
||||
from module.ui.ui import UI
|
||||
|
||||
MAIL_BUTTON_GRID = ButtonGrid(
|
||||
origin=(137, 207), delta=(0, 97),
|
||||
button_shape=(64, 64), grid_shape=(1, 3),
|
||||
name='MAIL_BUTTON_GRID')
|
||||
FILTER_REGEX = re.compile(
|
||||
'^(cube|coin|oil|merit|gem)$',
|
||||
flags=re.IGNORECASE)
|
||||
FILTER_ATTR = ['name']
|
||||
FILTER = Filter(FILTER_REGEX, FILTER_ATTR)
|
||||
|
||||
class Reward(UI):
|
||||
def reward_receive(self, oil, coin, exp, skip_first_screenshot=True):
|
||||
@ -72,7 +87,9 @@ class Reward(UI):
|
||||
bool, if encountered at least 1 GET_ITEMS_*
|
||||
"""
|
||||
# Reset any existing interval for the following assets
|
||||
[self.interval_clear(asset) for asset in [GET_ITEMS_1, GET_ITEMS_2, MISSION_MULTI, MISSION_SINGLE, GET_SHIP]]
|
||||
self.interval_clear([GET_ITEMS_1, GET_ITEMS_2,
|
||||
MISSION_MULTI, MISSION_SINGLE,
|
||||
GET_SHIP])
|
||||
|
||||
# Basic timers for certain scenarios
|
||||
exit_timer = Timer(2)
|
||||
@ -181,9 +198,10 @@ class Reward(UI):
|
||||
def reward_mission(self, daily=True, weekly=True):
|
||||
"""
|
||||
Collects mission rewards
|
||||
|
||||
Args:
|
||||
daily: If collect daily rewards
|
||||
weekly: If collect weekly rewards
|
||||
daily (bool): If collect daily rewards
|
||||
weekly (bool): If collect weekly rewards
|
||||
|
||||
Returns:
|
||||
bool: If rewarded.
|
||||
@ -211,6 +229,186 @@ class Reward(UI):
|
||||
|
||||
return reward
|
||||
|
||||
def _reward_mail_enter(self, skip_first_screenshot=True):
|
||||
"""
|
||||
Goes to mail page
|
||||
Also deletes viewed mails to ensure the relevant
|
||||
row entries are in view
|
||||
|
||||
Args:
|
||||
skip_first_screenshot (bool):
|
||||
"""
|
||||
deleted = False
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
self.device.screenshot()
|
||||
|
||||
if self.appear(page_main.check_button, offset=(30, 30), interval=3):
|
||||
self.device.click(MAIL_ENTER)
|
||||
continue
|
||||
if not deleted:
|
||||
if self.appear_then_click(MAIL_DELETE, offset=(350, 20), interval=3):
|
||||
continue
|
||||
if self.handle_popup_confirm('MAIL_DELETE'):
|
||||
deleted = True
|
||||
continue
|
||||
else:
|
||||
if self.appear(MAIL_DELETE, offset=(350, 20), interval=3):
|
||||
btn = MAIL_BUTTON_GRID.buttons[-1].move((350, 0))
|
||||
self.device.click(btn)
|
||||
continue
|
||||
if self.handle_info_bar():
|
||||
continue
|
||||
|
||||
# End
|
||||
if deleted and self.appear(MAIL_COLLECT, offset=(20, 20)):
|
||||
break
|
||||
|
||||
def _reward_mail_exit(self, skip_first_screenshot=True):
|
||||
"""
|
||||
Exits from mail page back into page_main
|
||||
|
||||
Args:
|
||||
skip_first_screenshot (bool):
|
||||
"""
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
self.device.screenshot()
|
||||
|
||||
if self.appear(MAIL_DELETE, offset=(350, 20), interval=3):
|
||||
self.device.click(MAIL_ENTER)
|
||||
continue
|
||||
|
||||
# End
|
||||
if self.appear(page_main.check_button, offset=(30, 30)):
|
||||
break
|
||||
|
||||
@cached_property
|
||||
def _reward_mail_grid(self):
|
||||
"""
|
||||
This grid only comprises the top 3 mail rows
|
||||
|
||||
Returns:
|
||||
ItemGrid
|
||||
"""
|
||||
mail_item_grid = ItemGrid(MAIL_BUTTON_GRID, templates={},
|
||||
amount_area=(60, 74, 96, 95))
|
||||
mail_item_grid.load_template_folder('./assets/stats_basic')
|
||||
return mail_item_grid
|
||||
|
||||
def _reward_mail_get_collectable(self):
|
||||
"""
|
||||
Loads filter and scans the items in the mail grid
|
||||
then returns a subset of those that are collectable
|
||||
|
||||
Returns:
|
||||
list[Item]
|
||||
"""
|
||||
FILTER.load(self.config.Reward_MailFilter.strip())
|
||||
items = self._reward_mail_grid.predict(
|
||||
self.device.image,
|
||||
name=True,
|
||||
amount=False,
|
||||
cost=False,
|
||||
price=False,
|
||||
tag=False
|
||||
)
|
||||
filtered = FILTER.apply(items, None)
|
||||
logger.attr('Item_sort', ' > '.join([str(item) for item in filtered]))
|
||||
return filtered
|
||||
|
||||
def _reward_mail_selected(self, button, image):
|
||||
"""
|
||||
Check if mail (button) is selected i.e.
|
||||
has bottom yellow border
|
||||
|
||||
Args:
|
||||
button (Button):
|
||||
image (np.ndarray): Screenshot
|
||||
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
area = button.area
|
||||
check_area = tuple([area[0], area[3] + 3, area[2], area[3] + 5])
|
||||
im = rgb2gray(crop(image, check_area))
|
||||
return True if np.mean(im) < 182 else False
|
||||
|
||||
def _reward_mail_collect(self, skip_first_screenshot=True):
|
||||
"""
|
||||
Executes the mail collect sequence
|
||||
|
||||
Args:
|
||||
skip_first_screenshot (bool):
|
||||
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
collectable = self._reward_mail_get_collectable()
|
||||
if not collectable:
|
||||
logger.info('No mail to collect')
|
||||
return False
|
||||
|
||||
click_timer = Timer(1.5, count=3)
|
||||
while 1:
|
||||
if skip_first_screenshot:
|
||||
skip_first_screenshot = False
|
||||
else:
|
||||
self.device.screenshot()
|
||||
|
||||
# End
|
||||
if not collectable:
|
||||
break
|
||||
else:
|
||||
btn = collectable[-1]._button
|
||||
if not self._reward_mail_selected(btn, self.device.image) and \
|
||||
click_timer.reached():
|
||||
self.device.click(btn.move((350, 0)))
|
||||
self.device.sleep((0.3, 0.5))
|
||||
click_timer.reset()
|
||||
continue
|
||||
|
||||
if self.appear_then_click(MAIL_COLLECT, offset=(20, 20), interval=3):
|
||||
click_timer.reset()
|
||||
continue
|
||||
if self.appear(MAIL_COLLECTED, offset=(20, 20), interval=3):
|
||||
collectable.pop()
|
||||
click_timer.reset()
|
||||
continue
|
||||
if self.appear_then_click(GET_ITEMS_1, offset=(30, 30), interval=1):
|
||||
click_timer.reset()
|
||||
continue
|
||||
if self.appear_then_click(GET_ITEMS_2, offset=(30, 30), interval=1):
|
||||
click_timer.reset()
|
||||
continue
|
||||
|
||||
logger.info('Finished collecting valid mail rewards')
|
||||
return True
|
||||
|
||||
def reward_mail(self, collect):
|
||||
"""
|
||||
Collects mail rewards
|
||||
|
||||
Args:
|
||||
collect (bool):
|
||||
|
||||
Returns:
|
||||
bool
|
||||
"""
|
||||
if not collect:
|
||||
return False
|
||||
logger.info('Mail reward')
|
||||
|
||||
self._reward_mail_enter()
|
||||
result = self._reward_mail_collect()
|
||||
self._reward_mail_exit()
|
||||
return result
|
||||
|
||||
|
||||
@cached_property
|
||||
def _reward_side_navbar(self):
|
||||
"""
|
||||
@ -274,4 +472,6 @@ class Reward(UI):
|
||||
self.ui_goto(page_main)
|
||||
self.reward_mission(daily=self.config.Reward_CollectMission,
|
||||
weekly=self.config.Reward_CollectWeeklyMission)
|
||||
self.ui_goto(page_main)
|
||||
self.reward_mail(collect=self.config.Reward_CollectMail)
|
||||
self.config.task_delay(success=True)
|
||||
|