def storage_logger_use_all(self, skip_first_screenshot=True): """ Args: skip_first_screenshot: Pages: in: STORAGE_CHECK out: STORAGE_CHECK, scroll to bottom """ logger.hr('Storage logger use all') while 1: if skip_first_screenshot: skip_first_screenshot = False else: self.device.screenshot() if SCROLL_STORAGE.appear(main=self): SCROLL_STORAGE.set_bottom(main=self, skip_first_screenshot=True) image = rgb2gray(self.device.image) items = TEMPLATE_STORAGE_LOGGER.match_multi(image, similarity=0.5) logger.attr('Storage_logger', len(items)) if len(items): self._storage_item_use(items[0]) continue else: logger.info('All loggers in storage have been used') break
def research_project_start(self, project, skip_first_screenshot=True): """ Args: project (ResearchProject): skip_first_screenshot: Returns: bool: If start success. """ logger.info(f'Research project: {project}') if project in self.projects: index = self.projects.index(project) else: logger.warning( f'The project to start: {project} is not in known projects') return False logger.info(f'Research project: {index}') available = False click_timer = Timer(10) while 1: if skip_first_screenshot: skip_first_screenshot = False else: self.device.screenshot() max_rgb = np.max( rgb2gray(np.array(self.image_area(RESEARCH_UNAVAILABLE)))) # Don't use interval here, RESEARCH_CHECK already appeared 5 seconds ago if click_timer.reached() and self.appear(RESEARCH_CHECK, offset=(20, 20)): i = (index - self._research_project_offset) % 5 logger.info( f'Project offset: {self._research_project_offset}, project {index} is at {i}' ) self.device.click(RESEARCH_ENTRANCE[i]) self._research_project_offset = (index - 2) % 5 self.ensure_research_stable() click_timer.reset() continue if max_rgb > 235 and self.appear_then_click( RESEARCH_START, offset=(5, 20), interval=10): available = True continue if self.handle_popup_confirm('RESEARCH_START'): continue # End if self.appear(RESEARCH_STOP, offset=(20, 20)): # RESEARCH_STOP is a semi-transparent button, color will vary depending on the background. self.research_detail_quit() # self.ensure_no_info_bar(timeout=3) # Research started self.research_project_started = project return True if not available and max_rgb <= 235 and self.appear( RESEARCH_UNAVAILABLE, offset=(5, 20)): logger.info('Not enough resources to start this project') self.research_detail_quit() self.research_project_started = None return False
def storage_sample_use_all(self, skip_first_screenshot=True): """ Args: skip_first_screenshot: Pages: in: STORAGE_CHECK out: STORAGE_CHECK, scroll to bottom """ sample_types = [ TEMPLATE_STORAGE_OFFENSE, TEMPLATE_STORAGE_SURVIVAL, TEMPLATE_STORAGE_COMBAT, TEMPLATE_STORAGE_QUALITY_OFFENSE, TEMPLATE_STORAGE_QUALITY_SURVIVAL, TEMPLATE_STORAGE_QUALITY_COMBAT ] for sample_type in sample_types: while 1: if skip_first_screenshot: skip_first_screenshot = False else: self.device.screenshot() image = rgb2gray(self.device.image) items = sample_type.match_multi(image, similarity=0.75) logger.attr('Storage_sample', len(items)) if len(items): self._storage_item_use(items[0]) else: break logger.info('All samples in storage have been used')
def storage_checkout_item(self, item, skip_first_screenshot=True): """ Args: item (str): 'OBSCURE' or 'ABYSSAL'. skip_first_screenshot: Returns: bool: If checkout Pages: in: STORAGE_CHECK out: is_in_map, in an obscure/abyssal zone if checkout. is_in_map, in previous zone if no more obscure/abyssal coordinates. """ logger.hr(f'Storage checkout item {item}') if SCROLL_STORAGE.appear(main=self): SCROLL_STORAGE.set_top(main=self, skip_first_screenshot=skip_first_screenshot) image = rgb2gray(np.array(self.device.image)) items = self._storage_item_to_template(item).match_multi( image, similarity=0.75) logger.attr(f'Storage_{item}', len(items)) if not len(items): logger.info(f'No more {item} items in storage') self.storage_quit() return False self._storage_checkout(items[0], types=(item, )) return True
def image(self): if self._image is None: image = load_image(self.file) if image_channel(image) == 3: image = rgb2gray(image) self._image = image return self._image
def bar_opened(self): """ Returns: bool: If dropdown menu appears. """ # Check the brightness of the rightest column of the bar area. luma = rgb2gray(np.array(self.main.image_area(self._bar)))[:, -1] return np.sum(luma > 127) / luma.size > 0.5
def in_use(self): """ Returns: bool: If has selected to any fleet. """ # Handle the info bar of auto search info. # if area_cross_area(self._in_use.area, INFO_BAR_1.area): # self.main.handle_info_bar() # Cropping FLEET_*_IN_USE to avoid detecting info_bar, also do the trick. # It also avoids wasting time on handling the info_bar. image = rgb2gray(np.array(self.main.image_area(self._in_use))) return np.std(image.flatten(), ddof=1) > self.FLEET_IN_USE_STD
def research_project_start(self, index, skip_first_screenshot=True): """ Args: index (int): 0 to 4. skip_first_screenshot: Returns: bool: If start success. """ logger.info(f'Research project: {index}') available = False click_timer = Timer(10) while 1: if skip_first_screenshot: skip_first_screenshot = False else: self.device.screenshot() max_rgb = np.max( rgb2gray(np.array(self.image_area(RESEARCH_UNAVAILABLE)))) # Don't use interval here, RESEARCH_CHECK already appeared 5 seconds ago if click_timer.reached() and self.appear(RESEARCH_CHECK, offset=(20, 20)): i = (index - self._research_project_offset) % 5 logger.info( f'Project offset: {self._research_project_offset}, project {index} is at {i}' ) self.device.click(RESEARCH_ENTRANCE[i]) self._research_project_offset = (index - 2) % 5 self.ensure_research_stable() click_timer.reset() continue if max_rgb > 235 and self.appear_then_click( RESEARCH_START, offset=(5, 20), interval=10): available = True continue if self.handle_popup_confirm('RESEARCH_START'): continue # End if self.appear(RESEARCH_STOP): self.research_detail_quit() self.ensure_no_info_bar(timeout=3) # Research started return True if not available and max_rgb <= 235 and self.appear( RESEARCH_UNAVAILABLE, offset=(5, 20)): logger.info('Not enough resources to start this project') self.research_detail_quit() return False
def get_research_status(self, image): """ Args: image: Screenshot Returns: list[str]: List of project status """ out = [] for index, status, scaling in zip(range(5), RESEARCH_STATUS, TEMPLATE_SCALING): info = status.crop((0, -40, 200, 0)) piece = rgb2gray(crop(image, info.area)) if TEMPLATE_WAITING.match(piece, scaling=scaling): out.append('waiting') elif TEMPLATE_RUNNING.match(piece, scaling=scaling): out.append('running') elif TEMPLATE_DETAIL.match(piece, scaling=scaling): out.append('detail') else: out.append('unknown') logger.info(f'Research status: {out}') return out
def research_project_start(self, project, add_queue=True, skip_first_screenshot=True): """ Start a given project and add it into research queue. Args: project (ResearchProject, int): Project or index of project 0 to 4. add_queue (bool): Whether to add into queue. The 6th project can't be added into queue, so here's the toggle. skip_first_screenshot: Returns: bool: If start success. None: If The project to start is not in known projects. Pages: in: is_in_research out: is_in_research """ logger.hr('Research project start') logger.info(f'Research project: {project}') if isinstance(project, int): index = project elif project in self.projects: index = self.projects.index(project) else: logger.warning( f'The project to start: {project} is not in known projects') return None logger.info(f'Research project: {index}') self.interval_clear([RESEARCH_START]) self.popup_interval_clear() available = False click_timer = Timer(10) while 1: if skip_first_screenshot: skip_first_screenshot = False else: self.device.screenshot() max_rgb = np.max(rgb2gray(self.image_crop(RESEARCH_UNAVAILABLE))) # Don't use interval here, RESEARCH_CHECK already appeared 5 seconds ago if click_timer.reached() and self.is_in_research(): i = (index - self._research_project_offset) % 5 logger.info( f'Project offset: {self._research_project_offset}, project {index} is at {i}' ) self.device.click(RESEARCH_ENTRANCE[i]) self._research_project_offset = (index - 2) % 5 self.ensure_research_stable() click_timer.reset() continue if max_rgb > 235 and self.appear_then_click( RESEARCH_START, offset=(5, 20), interval=10): available = True continue if self.handle_popup_confirm('RESEARCH_START'): continue # End if self.appear(RESEARCH_STOP, offset=(20, 20)): # RESEARCH_STOP is a semi-transparent button, # color will vary depending on the background. if add_queue: self.research_queue_add() else: self.research_detail_quit() # self.ensure_no_info_bar(timeout=3) # Research started self.research_project_started = project return True if not available and max_rgb <= 235 \ and self.appear(RESEARCH_UNAVAILABLE, offset=(5, 20)): logger.info('Not enough resources to start this project') self.research_detail_quit() self.research_project_started = None return False