def get_level(image): """ Args: image: Screenshot in EXERCISE_PREPARATION. Returns: list[int]: Fleet level, such as [120, 120, 120, 120, 120, 120]. """ level = [] level += ButtonGrid(origin=(130, 259), delta=(168, 0), button_shape=(58, 21), grid_shape=(3, 1), name='LEVEL').buttons() level += ButtonGrid(origin=(832, 259), delta=(168, 0), button_shape=(58, 21), grid_shape=(3, 1), name='LEVEL').buttons() level = Level(level, name='LEVEL', letter=(255, 255, 255), threshold=128) result = level.ocr(image) return result
def get_level(self, image): level = [] level += ButtonGrid(origin=(130, 259), delta=(168, 0), button_shape=(57, 21), grid_shape=(3, 1), name='LEVEL').buttons() level += ButtonGrid(origin=(832, 259), delta=(168, 0), button_shape=(57, 21), grid_shape=(3, 1), name='LEVEL').buttons() level = Digit(level, letter=(255, 255, 255), back=(102, 102, 102), limit=120, threshold=127, additional_preprocess=self.process, name='LEVEL') result = level.ocr(image) return result
def _stats_get_items_load(self, image): ITEM_GROUP.item_class = BonusItem ITEM_GROUP.similarity = 0.85 ITEM_GROUP.amount_area = (35, 51, 63, 63) origin = area_offset(CAMPAIGN_BONUS.button, offset=(-7, 34))[:2] grids = ButtonGrid(origin=origin, button_shape=(64, 64), grid_shape=(7, 2), delta=(72 + 2 / 3, 75)) reward_bottom = AUTO_SEARCH_MENU_EXIT.button[1] grids.buttons = [button for button in grids.buttons if button.area[3] < reward_bottom] ITEM_GROUP.grids = grids
def _guild_operations_get_dispatch(self): """ Get the button to switch available dispatch In previous version, this function detects the red dot on the switch. But the red dot may not shows for unknown reason sometimes, so we detect the switch itself. Returns: Button: Button to switch available dispatch. None if already reach the most right fleet. Pages: in: page_guild, guild operation, operation dispatch preparation (GUILD_DISPATCH_RECOMMEND) """ # Fleet switch, for 4 situation # | 1 | # | 1 | | 2 | # | 1 | | 2 | | 3 | # | 1 | | 2 | | 3 | | 4 | # 0 1 2 3 4 5 6 buttons in switch_grid switch_grid = ButtonGrid(origin=(573.5, 381), delta=(20.5, 0), button_shape=(11, 24), grid_shape=(7, 1)) # Color of inactive fleet switch color_active = (74, 117, 222) # Color of current fleet color_inactive = (33, 48, 66) text = [] index = 0 button = None for switch in switch_grid.buttons(): if self.image_color_count(switch, color=color_inactive, threshold=235, count=30): index += 1 text.append(f'| {index} |') button = switch elif self.image_color_count(switch, color=color_active, threshold=235, count=30): index += 1 text.append(f'[ {index} ]') button = switch # log example: | 1 | | 2 | [ 3 ] text = ' '.join(text) logger.attr('Dispatch_fleet', text) if text.endswith(']'): logger.info('Already at the most right fleet') return None else: return button
def _dorm_food(self): # 14px lower return ButtonGrid(origin=(298, 389), delta=(156, 0), button_shape=(112, 66), grid_shape=(6, 1), name='FOOD')
def _equip_side_navbar(self): """ pry_sidebar 3 options research. equipment. detail. regular_sidebar 4 options enhancement. limit break. equipment. detail. retrofit_sidebar 5 options retrofit. enhancement. limit break. equipment. detail. """ equip_side_navbar = ButtonGrid(origin=(21, 118), delta=(0, 94.5), button_shape=(60, 75), grid_shape=(1, 5), name='DETAIL_SIDE_NAVBAR') return Navbar(grids=equip_side_navbar, active_color=(247, 255, 173), active_threshold=221, inactive_color=(140, 162, 181), inactive_threshold=221)
def _guild_side_navbar(self): """ leader_sidebar 6 options lobby. members. apply. logistics. tech. operations. member_sidebar 5 options lobby. members. logistics. tech. operations. """ guild_side_navbar = ButtonGrid(origin=(21, 118), delta=(0, 94.5), button_shape=(60, 75), grid_shape=(1, 6), name='GUILD_SIDE_NAVBAR') return Navbar(grids=guild_side_navbar, active_color=(247, 255, 173), inactive_color=(140, 162, 181))
def get_power(self, image): grids = ButtonGrid(origin=(222, 266), delta=(244, 30), button_shape=(72, 15), grid_shape=(4, 2), name='POWER') power = [grids[self.index, 0], grids[self.index, 1]] power = Digit(power, letter=(255, 223, 57), back=(74, 109, 156), threshold=221, limit=17000, name='POWER') result = power.ocr(image) return result
def _dorm_food(self): # 14px lower return ButtonGrid(origin=(279, 375), delta=(159, 0), button_shape=(134, 96), grid_shape=(6, 1), name='FOOD')
def _tactical_get_finish(self): """ Get the future finish time. """ logger.hr('Tactical get finish') grids = ButtonGrid(origin=(421, 596), delta=(223, 0), button_shape=(139, 27), grid_shape=(4, 1), name='TACTICAL_REMAIN') is_running = [ self.image_color_count(button, color=(148, 255, 99), count=50) for button in grids.buttons ] logger.info( f'Tactical status: {["running" if s else "empty" for s in is_running]}' ) buttons = [b for b, s in zip(grids.buttons, is_running) if s] ocr = Duration(buttons, letter=(148, 255, 99), name='TACTICAL_REMAIN') remains = ocr.ocr(self.device.image) remains = [remains] if not isinstance(remains, list) else remains now = datetime.now() self.tactical_finish = [(now + remain).replace(microsecond=0) for remain in remains if remain.total_seconds()] logger.info( f'Tactical finish: {[str(f) for f in self.tactical_finish]}')
def shop_medal_grid(self): """ Returns: ButtonGrid: """ shop_grid = ButtonGrid( origin=(197, 193), delta=(223, 190), button_shape=(100.5, 101.5), grid_shape=(3, 2), name='SHOP_MEDAL_GRID') return shop_grid
def shop_grid(self): """ Returns: ButtonGrid: """ shop_grid = ButtonGrid( origin=(477, 152), delta=(156, 214), button_shape=(96, 96), grid_shape=(5, 2), name='SHOP_GRID') return shop_grid
def queue_status_grids(self): """ Status icons on the left """ return ButtonGrid(origin=(18, 259), delta=(0, 40.5), button_shape=(25, 25), grid_shape=(1, 5), name='QUEUE_STATUS')
def get_level(image): level = [] level += ButtonGrid(origin=(130, 259), delta=(168, 0), button_shape=(58, 21), grid_shape=(3, 1), name='LEVEL').buttons() level += ButtonGrid(origin=(832, 259), delta=(168, 0), button_shape=(58, 21), grid_shape=(3, 1), name='LEVEL').buttons() level = Level(level, name='LEVEL', letter=(255, 255, 255), threshold=128) result = level.ocr(image) return result
def os_shop_items(self): """ Returns: ItemGrid: """ shop_grid = ButtonGrid( origin=(237, 219), delta=(189, 224), button_shape=(98, 98), grid_shape=(4, 2), name='SHOP_GRID') shop_items = ItemGrid(shop_grid, templates={}, amount_area=(60, 74, 96, 95)) shop_items.load_template_folder('./assets/shop/os') shop_items.load_cost_template_folder('./assets/shop/os_cost') return shop_items
def _exchange_bottom_navbar(self): """ 2 options ships. items. """ exchange_bottom_navbar = ButtonGrid( origin=(569, 637), delta=(208, 0), button_shape=(70, 49), grid_shape=(2, 1), name='EXCHANGE_BOTTOM_NAVBAR') return Navbar(grids=exchange_bottom_navbar, active_color=(247, 227, 148), inactive_color=(189, 231, 247))
def get_power(self, image): grids = ButtonGrid(origin=(222, 257), delta=(244, 30), button_shape=(72, 28), grid_shape=(4, 2), name='POWER') power = [grids[self.index, 0], grids[self.index, 1]] power = Digit(power, name='POWER', letter=(255, 223, 57), threshold=128) result = power.ocr(image) return result
def _hp_grid(self): hp_grid = super()._hp_grid() # Location of six HP bar, according to respective server for os if self.config.SERVER == 'en': hp_grid = ButtonGrid(origin=(35, 205), delta=(0, 100), button_shape=(66, 3), grid_shape=(1, 6)) elif self.config.SERVER == 'jp': pass else: pass return hp_grid
def _shop_bottom_navbar(self): """ shop_bottom_navbar 5 options guild. prototype. core. merit. general. """ shop_bottom_navbar = ButtonGrid(origin=(399, 619), delta=(182, 0), button_shape=(56, 42), grid_shape=(5, 1), name='SHOP_BOTTOM_NAVBAR') return Navbar(grids=shop_bottom_navbar, active_color=(33, 195, 239), inactive_color=(181, 178, 181))
def shop_grid(self): """ Returns: ButtonGrid: """ medals = self._get_medals() count = len(medals) if count == 0: logger.warning( 'Unable to find medal icon, assume item list is at top') origin_y = 152 delta_y = 213 row = 2 elif count == 1: y_list = medals[:, 1] # +256, to location on screen # -125, from the top of medal icon to the top of shop item origin_y = y_list[0] + 256 - 125 delta_y = 213 row = 1 elif count == 2: y_list = medals[:, 1] y1, y2 = y_list[0], y_list[1] origin_y = min(y1, y2) + 256 - 125 delta_y = abs(y1 - y2) row = 2 else: logger.warning( f'Unexpected medal icon match result: {[m.area for m in medals]}' ) origin_y = 152 delta_y = 213 row = 2 # Make up a ButtonGrid # Original grid is: # shop_grid = ButtonGrid( # origin=(489, 152), delta=(156, 213), button_shape=(96, 96), grid_shape=(5, 2), name='SHOP_GRID') shop_grid = ButtonGrid(origin=(477, origin_y), delta=(156, delta_y), button_shape=(96, 96), grid_shape=(5, row), name='SHOP_GRID') return shop_grid
def _shop_bottom_navbar(self): """ Below information relative to after shop_swipe shop_bottom_navbar 5 options medal guild. prototype. core. merit. """ shop_bottom_navbar = ButtonGrid( origin=(399, 619), delta=(182, 0), button_shape=(56, 42), grid_shape=(5, 1), name='SHOP_BOTTOM_NAVBAR') return Navbar(grids=shop_bottom_navbar, active_color=(33, 195, 239), inactive_color=(181, 178, 181))
def _reward_side_navbar(self): """ side_navbar options: all. main. side. daily. weekly. event. """ reward_side_navbar = ButtonGrid(origin=(21, 118), delta=(0, 94.5), button_shape=(60, 75), grid_shape=(1, 6), name='REWARD_SIDE_NAVBAR') return Navbar(grids=reward_side_navbar, active_color=(247, 255, 173), inactive_color=(140, 162, 181))
def get_power(self, image): """ Args: image: Screenshot in page_exercise. Returns: list[int]: Fleet power, such as [14848, 13477]. """ grids = ButtonGrid(origin=(222, 257), delta=(244, 30), button_shape=(72, 28), grid_shape=(4, 2), name='POWER') power = [grids[self.index, 0], grids[self.index, 1]] power = Digit(power, name='POWER', letter=(255, 223, 57), threshold=128) result = power.ocr(image) return result
def _tactical_get_finish(self): """ Get the future finish time. """ logger.hr('Tactical get finish') grids = ButtonGrid(origin=(421, 596), delta=(223, 0), button_shape=(139, 27), grid_shape=(4, 1), name='TACTICAL_REMAIN') # tactical cards can't be loaded that fast, confirm if it's empty. confirm_timer = Timer(0.6, count=2).start() while 1: is_running = [ self.image_color_count(button, color=(148, 255, 99), count=50) for button in grids.buttons ] logger.info( f'Tactical status: {["running" if s else "empty" for s in is_running]}' ) if any(is_running): break if confirm_timer.reached(): break self.device.screenshot() buttons = [b for b, s in zip(grids.buttons, is_running) if s] ocr = Duration(buttons, letter=(148, 255, 99), name='TACTICAL_REMAIN') remains = ocr.ocr(self.device.image) remains = [remains] if not isinstance(remains, list) else remains now = datetime.now() self.tactical_finish = [(now + remain).replace(microsecond=0) for remain in remains if remain.total_seconds()] logger.info( f'Tactical finish: {[str(f) for f in self.tactical_finish]}')
def _gacha_side_navbar(self): """ limited_sidebar 5 options build. limited_build. orders. shop. retire. regular_sidebar 4 options build. orders. shop. retire. """ gacha_side_navbar = ButtonGrid( origin=(21, 126), delta=(0, 98), button_shape=(60, 80), grid_shape=(1, 5), name='GACHA_SIDE_NAVBAR') return Navbar(grids=gacha_side_navbar, active_color=(247, 255, 173), active_threshold=221, inactive_color=(140, 162, 181), inactive_threshold=221)
def _construct_bottom_navbar(self): """ limited 4 options build. limited_build. orders. shop. retire. regular 3 options build. orders. shop. retire. """ construct_bottom_navbar = ButtonGrid( origin=(262, 615), delta=(209, 0), button_shape=(70, 49), grid_shape=(4, 1), name='CONSTRUCT_BOTTOM_NAVBAR') return Navbar(grids=construct_bottom_navbar, active_color=(247, 227, 148), inactive_color=(189, 231, 247))
from module.base.button import Button, ButtonGrid from module.base.timer import Timer, time_range_active from module.base.utils import area_offset, get_color, color_similar, color_similarity_2d from module.exception import ScriptError from module.logger import logger from module.reward.assets import * from module.ui.assets import TACTICAL_CHECK from module.ui.ui import UI, page_tactical, page_reward GENRE_NAME_DICT = { 1: 'Offensive', # red 2: 'Defensive', # blue 3: 'Support', # yellow } BOOKS_GRID = ButtonGrid(origin=(239, 288), delta=(140, 120), button_shape=(98, 98), grid_shape=(6, 2)) class Book: color_genre = { 1: (214, 69, 74), # Offensive, red 2: (115, 178, 255), # Defensive, blue 3: (247, 190, 99), # Support, yellow } color_tier = { 1: (104, 181, 238), # T1, blue 2: (151, 129, 203), # T2, purple 3: (235, 208, 120), # T3, gold } def __init__(self, image, button):
from module.base.button import ButtonGrid from module.base.utils import * from module.logger import logger from module.ui.ui import UI GUILD_SIDEBAR = ButtonGrid(origin=(21, 118), delta=(0, 94.5), button_shape=(60, 75), grid_shape=(1, 6), name='GUILD_SIDEBAR') class GuildBase(UI): def _guild_sidebar_click(self, index): """ Performs the calculations necessary to determine the index location on sidebar and then click at that location Args: index (int): leader sidebar 6 for lobby. 5 for members. 4 apply. 3 for logistics. 2 for tech. 1 for operations. member sidebar 6 for lobby.
def _fleet_sidebar(self): return ButtonGrid(origin=(1177, 139), delta=(0, 110.5), button_shape=(55, 104), grid_shape=(1, 3), name='FLEET_SIDEBAR')
from module.base.button import ButtonGrid from module.base.timer import Timer from module.base.utils import get_color, color_similar from module.combat.assets import GET_ITEMS_1 from module.exception import RequestHumanTakeover, ScriptError from module.logger import logger from module.retire.assets import * from module.retire.enhancement import Enhancement CARD_GRIDS = ButtonGrid(origin=(93, 76), delta=(164 + 2 / 3, 227), button_shape=(138, 204), grid_shape=(7, 2), name='CARD') CARD_RARITY_GRIDS = ButtonGrid(origin=(93, 76), delta=(164 + 2 / 3, 227), button_shape=(138, 5), grid_shape=(7, 2), name='RARITY') CARD_RARITY_COLORS = { 'N': (174, 176, 187), 'R': (106, 195, 248), 'SR': (151, 134, 254), 'SSR': (248, 223, 107) # Not support marriage cards. } class Retirement(Enhancement): _unable_to_enhance = False