Exemplo n.º 1
0
def main():
    image_path = './temp/screen.png'
    feature_path = './azurelane/assets/scenes_feature/fallback_and_switch_btn.png'

    c = wda.Client()
    _ = c.screenshot(image_path)
    screen = cv2.imread(image_path)  # 加载图片
    screen_gray = cv2.cvtColor(screen, cv2.COLOR_BGR2GRAY)  # 灰度转换
    # screen_gray = cv2.imread(image_path, 0)

    feature = cv2.imread(feature_path, 0)
    feature_w, feature_h = feature.shape[::-1]
    logger.info('feature size: {0}x{1}'.format(feature_w, feature_h))

    res = cv2.matchTemplate(screen_gray, feature, cv2.TM_CCOEFF_NORMED)

    # 使用灰度图像中的坐标对原始RGB图像进行标记
    loc = np.where(res >= 0.6)
    for pt in zip(*loc[::-1]):
        cv2.rectangle(screen, pt, (pt[0] + feature_w, pt[1] + feature_h),
                      (7, 249, 151), 2)

    # 红色方框框出不可点击区域
    red_zones = EnemySearch.red_zones
    for i in range(len(red_zones)):
        zone = red_zones[i]
        cv2.rectangle(screen, zone[0], zone[1], (0, 0, 255), 3)

    # 显示图像
    cv2.imshow('Detected', screen)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
Exemplo n.º 2
0
def main():
    device = AndroidDevice()
    screen = np.asarray(device.screen_capture_as_image())  # 实时截取并加载图片
    # screen = np.asarray(Image.open('./temp/screen.png'))  # 加载本地图片
    # screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)  # 翻转RGB顺序
    gray = cv2.cvtColor(screen, cv2.COLOR_RGB2GRAY)  # 灰度转换
    feature_path = './azurelane/assets/scenes_feature/map_ship_type_2.png'
    feature = cv2.imread(feature_path, 0)
    feature_w, feature_h = feature.shape[::-1]
    logger.info('scenes_feature size:', feature_w, 'x', feature_h)

    res = cv2.matchTemplate(gray, feature, cv2.TM_CCOEFF_NORMED)

    # 使用灰度图像中的坐标对原始RGB图像进行标记
    loc = np.where(res >= 0.8)
    for pt in zip(*loc[::-1]):
        cv2.rectangle(screen, pt, (pt[0] + feature_w, pt[1] + feature_h), (7, 249, 151), 2)

    s = EnemySearch('', None, None, None)
    red_zones = s.red_zones
    for i in range(len(red_zones)):
        zone = red_zones[i]
        cv2.rectangle(screen, zone[0], zone[1], (0, 0, 255), 3)

    # 显示图像
    cv2.imshow('Detected', screen)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
Exemplo n.º 3
0
 def before_action(_1, _2):
     if 0 <= config.repeat_count_max <= context.repeated_count:
         print()
         cause = '预设的复读次数已完成'
         logger.info(cause)
         program_exit_alert(cause)
         exit(0)
     context.repeated_count += 1
     logger.info('第 %03d 次副本' % context.repeated_count)
Exemplo n.º 4
0
 def before_action(_1, _2):
     if 0 <= config.repeat_count_max <= context.repeated_count:
         print()
         logger.info('预设的复读次数已完成')
         exit(0)
     context.repeated_count += 1
     context.round_count = 0
     context.swipe_mode = config.default_swipe_direction
     print('')
     logger.info('第 %03d 次副本' % context.repeated_count)
Exemplo n.º 5
0
 def before_action(_1, _2):
     if config.use_stone_max > 0:
         if context.stone_used >= config.use_stone_max:
             logger.info('已到达预设的可用源石上限, 脚本将退出')
             exit(0)
         else:
             context.stone_used += 1
     else:
         logger.info('理智不足,自动退出脚本')
         exit(0)
Exemplo n.º 6
0
 def before_action(_1, _2):
     if config.use_pharmacy_max > 0:
         if context.pharmacy_used >= config.use_pharmacy_max:
             logger.info('已到达预设的可用药剂上限, 脚本将退出')
             exit(0)
         else:
             context.pharmacy_used += 1
     else:
         logger.info('理智不足,自动退出脚本')
         exit(0)
Exemplo n.º 7
0
 def before_action(_1, _2):
     if config.use_pharmacy_max > 0:
         if context.pharmacy_used >= config.use_pharmacy_max:
             cause = '已到达预设的可用药剂上限, 脚本将退出'
             logger.info(cause)
             program_exit_alert(cause)
             exit(0)
     else:
         cause = '理智不足,自动退出脚本'
         logger.info(cause)
         program_exit_alert(cause)
         exit(0)
Exemplo n.º 8
0
 def __check_screenshot(self):
     while True:
         if self.SCREENSHOT_WAY < 0:
             logger.error('暂不支持当前设备')
             sys.exit()
         try:
             im = self.__pull_screenshot()
             im.load()
             im.close()
             logger.info('采用方式 {} 获取截图'.format(self.SCREENSHOT_WAY))
             break
         except Exception as pssEx:
             logger.error(pssEx)
             self.SCREENSHOT_WAY -= 1
Exemplo n.º 9
0
 def before_action(_1, _2):
     if config.use_stone_max > 0:
         if context.stone_used >= config.use_stone_max:
             cause = "已到达预设的可用源石上限, 脚本将退出"
             logger.info(cause)
             program_exit_alert(cause)
             exit(0)
         else:
             context.stone_used += 1
     else:
         cause = '理智不足,自动退出脚本'
         logger.info(cause)
         program_exit_alert(cause)
         exit(0)
Exemplo n.º 10
0
def battle_finished_lock_new_character(prefix):
    s = Scene('检测锁定新角色提示',
              identify_image=load_resource("lock_ship_detection.png", prefix),
              tap_image=load_resource("ship_lock_yes_button.png", prefix),
              tap_offset_y=-100)
    s.after_action = lambda _1, _2: logger.info("  new character locked!")
    return s
Exemplo n.º 11
0
    def __init__(self):
        try:
            # 从配置文件读取配置
            cfg = self.__load_configuration_file()
            self.device_type = cfg.get('global', 'device_type')
            self.device_dpi = cfg.getint('global', 'device_dpi')
            self.game_name = cfg.get('global', 'game_name')
            self.repeat_count_max = cfg.getint('global', 'repeat_count_max')
            self.use_stone_max = cfg.getint('arknights', 'use_stone_max')
            self.use_pharmacy_max = cfg.getint('arknights', 'use_pharmacy_max')
            self.battle_no = cfg.get('azurelane', 'battle_no')
            self.default_swipe_direction = cfg.getint(
                'azurelane', 'default_swipe_direction')

            # 如果有命令行参数,更新覆盖配置
            self.__override_from_command_line()

            logger.info(self)
        except Exception as ex:
            logger.error(ex)
Exemplo n.º 12
0
 def test_device(self):
     logger.info('检查设备是否连接...')
     command_list = [self.adb_path, 'devices']
     process = subprocess.Popen(command_list,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.PIPE)
     output = process.communicate()
     device_list = output[0].decode('utf-8')\
         .replace('\r', '')\
         .strip('\n')\
         .split("\n")
     if len(device_list) == 1:  # first one is: 'List of devices attached'
         logger.warn('未找到设备')
         exit(1)
     logger.info('设备已连接')
     logger.info('adb 输出:')
     for i in range(1, len(device_list)):
         if device_list[i] != '':
             logger.info('\t' + device_list[i])
Exemplo n.º 13
0
 def before_action(_1, _2):
     if context.like_friend_dormitory_count >= config.max_like_dormitory:
         logger.info('点赞数达成')
         exit(0)
     context.like_friend_dormitory_count += 1
Exemplo n.º 14
0
 def before_action(_1, _2):
     if 0 <= config.repeat_count_max <= context.repeated_count:
         logger.info('\n\n预设的复读次数已完成')
         exit(0)
     context.repeated_count += 1
     logger.info('第 %03d 次副本' % context.repeated_count)
Exemplo n.º 15
0
 def before_action(_1, _2):
     print()
     logger.info('船坞满了,指挥官清理一下喵')
     exit(0)
Exemplo n.º 16
0
 def before_action(_1, _2):
     print()
     logger.info('队伍存在舰娘心情警告,指挥官休息一下吧')
     exit(0)
Exemplo n.º 17
0
    try:
        # 1. init config
        cfg = Config()
        ctx = Context()

        # 2. init scenes
        scenes = load_scenes(cfg, ctx)

        # 3. init device
        if cfg.device_type == 'ios':
            device = IOSDevice(cfg.device_dpi, address='http://127.0.0.1:8100')
        elif cfg.device_type == 'android':
            device = AndroidDevice(address='127.0.0.1:7555')
        else:
            raise EnvironmentError("未知的设备类型")
        ctx.screen_width = device.screen_x
        ctx.screen_height = device.screen_y

        # 4. init event loop and start.
        worker = EventLoop(scenes, device, ctx)
        worker.start()
    except KeyboardInterrupt:
        print()
        logger.info('Ctrl+C 被按下, 程序即将退出.')
        exit()
    except Exception as unknown:
        print()
        logger.error("Unexcepted/Unkonwn Exception occurred")
        logger.exception(unknown)
        exit()
Exemplo n.º 18
0
def goodbye():
    logger.info("You are now leaving the Python sector. Goodbye~ \n\n\n")