Ejemplo n.º 1
0
 def _upgrade_to(self, target_level):
     """
     target_level: 目标等级
     升至 target_level 级
     利用 Tesseract 识别当前等级后点击升级按钮 target_level - 当前等级次
     """
     screen = self._safe_screenshot()
     screen = UIMatcher.pre_building_panel(screen)
     tmp = UIMatcher.cut(screen, prop.BUILDING_INFO_PANEL_LEVEL_POS,
                         (120, 50))
     # import cv2
     # cv2.imwrite("./tmp/screen.jpg", screen)
     tmp = UIMatcher.plain(tmp)
     tmp = UIMatcher.fill_color(tmp)
     tmp = UIMatcher.plain(tmp)
     txt = UIMatcher.image_to_txt(tmp, plus='-l chi_sim --psm 7')
     txt = UIMatcher.normalize_txt(txt)
     try:
         cur_level = int(txt)
         logger.info(f'Current level -> {cur_level}')
     except Exception:
         logger.warning(f'Current level -> {txt}')
         return
     click_times = target_level - cur_level
     self._upgrade_times(click_times)
Ejemplo n.º 2
0
    def _select_min_building(self):
        screen = self.d.screenshot(format="opencv")
        screen = UIMatcher.pre(screen)
        min_level = float('inf')
        min_building_seq = None
        for key in self.__find_selected_building_seq():
            pos = prop.BUILDING_LEVEL_POS[key]
            tmp = UIMatcher.cut(screen, pos)
            tmp = UIMatcher.plain(tmp)
            tmp = UIMatcher.fill_color(tmp)
            tmp = UIMatcher.plain(tmp)
            txt = UIMatcher.image_to_txt(tmp, plus='-l chi_sim --psm 7')
            txt = UIMatcher.normalize_txt(txt)
            try:
                level = int(txt)
                logger.info(f'{self.config.building_pos[key - 1]} tesser -> {level}')
            except Exception:
                logger.warning(f'{self.config.building_pos[key - 1]} tesser -> {txt}')
                continue
            if level < min_level:
                min_level = level
                min_building_seq = key

        # 一个屋子的等级都没拿到
        if min_building_seq is None:
            res = choice(list(prop.BUILDING_POS.keys()))
            logger.warning(f'No tesseract result, random to {self.config.building_pos[res - 1]}')
            return res
        else:
            logger.info(f'Minimum level is {min_level} from {self.config.building_pos[min_building_seq - 1]}')
            return min_building_seq