Пример #1
0
def _connect_adb(args):
    from connector.ADBConnector import ADBConnector, ensure_adb_alive
    ensure_adb_alive()
    global device
    if len(args) == 0:
        try:
            device = ADBConnector.auto_connect()
        except IndexError:
            print("检测到多台设备")
            devices = ADBConnector.available_devices()
            for i, (serial, status) in enumerate(devices):
                print("%2d. %s\t[%s]" % (i, serial, status))
            num = 0
            while True:
                try:
                    num = int(input("请输入序号选择设备: "))
                    if not 0 <= num < len(devices):
                        raise ValueError()
                    break
                except ValueError:
                    print("输入不合法,请重新输入")
            device_name = devices[num][0]
            device = ADBConnector(device_name)
    else:
        serial = args[0]
        device = ADBConnector(serial)
Пример #2
0
 def __init__(
         self,
         current_strength=None,  # 当前理智
         adb_host=None,  # 当前绑定到的设备
         out_put=True,  # 是否有命令行输出
         call_by_gui=False):  # 是否为从 GUI 程序调用
     ensure_adb_alive()
     self.adb = ADBConnector(adb_serial=adb_host)
     self.__is_game_active = False
     self.__call_by_gui = call_by_gui
     self.is_called_by_gui = call_by_gui
     self.viewport = self.adb.screenshot().size
     self.operation_time = []
     self.delay_impl = sleep
     if DEBUG_LEVEL >= 1:
         self.__print_info()
     self.refill_with_item = config.get('behavior/refill_ap_with_item',
                                        False)
     self.refill_with_originium = config.get(
         'behavior/refill_ap_with_originium', False)
     self.use_refill = self.refill_with_item or self.refill_with_originium
     self.loots = {}
     self.use_penguin_report = config.get('reporting/enabled', False)
     if self.use_penguin_report:
         self.penguin_reporter = penguin_stats.reporter.PenguinStatsReporter(
         )
     self.refill_count = 0
     self.max_refill_count = None
     logger.debug("成功初始化模块")
Пример #3
0
 def connect_device(self, connector=None, *, adb_serial=None):
     if connector is not None:
         self.adb = connector
     elif adb_serial is not None:
         self.adb = ADBConnector(adb_serial)
     else:
         self.adb = None
         return
     self.viewport = self.adb.screen_size
     if self.adb.screenshot_rotate %180:
         self.viewport = (self.viewport[1], self.viewport[0])
     if self.viewport[1] < 720 or Fraction(self.viewport[0], self.viewport[1]) < Fraction(16, 9):
         title = '设备当前分辨率(%dx%d)不符合要求' % (self.viewport[0], self.viewport[1])
         body = '需要宽高比等于或大于 16∶9,且渲染高度不小于 720。'
         details = None
         if Fraction(self.viewport[1], self.viewport[0]) >= Fraction(16, 9):
             body = '屏幕截图可能需要旋转,请尝试在 device-config 中指定旋转角度。'
             img = self.adb.screenshot()
             imgfile = os.path.join(config.SCREEN_SHOOT_SAVE_PATH, 'orientation-diagnose-%s.png' % time.strftime("%Y%m%d-%H%M%S"))
             img.save(imgfile)
             import json
             details = '参考 %s 以更正 device-config.json[%s]["screenshot_rotate"]' % (imgfile, json.dumps(self.adb.config_key))
         for msg in [title, body, details]:
             if msg is not None:
                 logger.warn(msg)
         frontend.alert(title, body, 'warn', details)
Пример #4
0
 def web_connect(self, dev:str):
     print(dev.split(':', 1))
     connector_type, cookie = dev.split(':', 1)
     if connector_type != 'adb':
         raise KeyError("unknown connector type " + connector_type)
     new_connector = ADBConnector(cookie)
     connector_str = str(new_connector)
     self.helper.connect_device(new_connector)
     self.notify("web:current-device", connector_str)
Пример #5
0
def _connect_adb(args):
    from connector.ADBConnector import ADBConnector, ensure_adb_alive
    ensure_adb_alive()
    global device
    if len(args) == 0:
        try:
            device = ADBConnector.auto_connect()
        except IndexError:
            print("检测到多台设备")
            devices = ADBConnector.available_devices()
            for i, (serial, status) in enumerate(devices):
                print("%2d. %s\t[%s]" % (i, serial, status))
            num = 0
            while True:
                try:
                    num = int(input("请输入序号选择设备: "))
                    if not 0 <= num < len(devices):
                        raise ValueError()
                    break
                except ValueError:
                    print("输入不合法,请重新输入")
            device_name = devices[num][0]
            device = ADBConnector(device_name)
    else:
        serial = args[0]
        try:
            device = ADBConnector(serial)
        except RuntimeError as e:
            if e.args and isinstance(e.args[0],
                                     bytes) and b'not found' in e.args[0]:
                if ':' in serial and serial.split(':')[-1].isdigit():
                    print('adb connect', serial)
                    ADBConnector.paranoid_connect(serial)
                    device = ADBConnector(serial)
                    return
            raise
Пример #6
0
    def __init__(
            self,
            current_strength=None,  # 当前理智
            adb_host=None,  # 当前绑定到的设备
            out_put=True,  # 是否有命令行输出
            call_by_gui=False):  # 是否为从 GUI 程序调用
        ensure_adb_alive()
        self.adb = ADBConnector(adb_serial=adb_host)
        self.__is_game_active = False
        self.__call_by_gui = call_by_gui
        self.is_called_by_gui = call_by_gui
        self.viewport = self.adb.screen_size
        self.operation_time = []
        self.delay_impl = sleep
        if DEBUG_LEVEL >= 1:
            self.__print_info()
        self.refill_with_item = config.get('behavior/refill_ap_with_item',
                                           False)
        self.refill_with_originium = config.get(
            'behavior/refill_ap_with_originium', False)
        self.use_refill = self.refill_with_item or self.refill_with_originium
        self.loots = {}
        self.use_penguin_report = config.get('reporting/enabled', False)
        if self.use_penguin_report:
            self.penguin_reporter = penguin_stats.reporter.PenguinStatsReporter(
            )
        self.refill_count = 0
        self.max_refill_count = None
        if Fraction(self.viewport[0], self.viewport[1]) < Fraction(16, 9):
            logger.warn('当前分辨率(%dx%d)不符合要求', self.viewport[0],
                        self.viewport[1])
            if Fraction(self.viewport[1], self.viewport[0]) >= Fraction(16, 9):
                logger.info('屏幕截图可能需要旋转,请尝试在 device-config 中指定旋转角度')
                img = self.adb.screenshot()
                imgfile = os.path.join(
                    config.SCREEN_SHOOT_SAVE_PATH,
                    'orientation-diagnose-%s.png' %
                    time.strftime("%Y%m%d-%H%M%S"))
                img.save(imgfile)
                import json
                logger.info(
                    '参考 %s 以更正 device-config.json[%s]["screenshot_rotate"]',
                    imgfile, json.dumps(self.adb.config_key))

        logger.debug("成功初始化模块")
Пример #7
0
 def restart_adb(self, kill=False):
     logger.notice("关闭adb中...", flush=False)
     try:
         del self.adb
     except AttributeError:
         pass
     if kill:
         self._kill_adb()
     logger.notice("关闭adb中...完成。正在重启adb")
     ensure_adb_alive()
     self.adb = ADBConnector(adb_serial=self.__adb_host)
     # mumu_handler.regetgame()
     self.reGetGame()
     if self.handler[1] != -1:
         if self.handler[0][4] == 1280 and self.handler[0][5] == 809:
             logger.system("检测到Mumu模拟器,已开启快速图像采集")
             self.getScreenShot = getscreenshot
         else:
             logger.notice("检测到Mumu模拟器,请使用1280x720模式以开启快速图像采集!")
Пример #8
0
 def __init__(self, adb_host=None, gui_enabled=False, with_commander=False):
     os.system("cls")
     ensure_adb_alive()
     self.Thread = Job()
     self.after_finish_Thread = Job()
     self.has_after_finish_Thread = False
     self.__adb_host = adb_host
     self.adb = ADBConnector(adb_serial=adb_host)
     self.root = Path(__file__).parent
     self.gui_enabled = gui_enabled
     self.gameTemp = GameTemplate("./imgReco/img/")
     RootData.set("gameTempGlobal", self.gameTemp)
     self.handler = mumu_handler.getSelectGameNow()
     self.getScreenShot = self.adb.screenshot
     self.reconizerC, self.reconizerE, self.reconizerN, self.reconizerN2 = getReconizer(
     )
     self.time_sleep = time_sleep
     self.clicker = Clicker(self.adb)
     self.mapper = Mapping.Mapping("./ArkMapping/MapData2.dat")
     self.material_planner = MaterialPlanning()
     self.playerInfo = None
     self.in_attack = False
     self.total_itemStack = ItemStack()
     self.current_itemStack = ItemStack()
     self._force_stop = False
     self.mapData = ArkMap(self)
     self.dropLinker = ItemDropLinker()
     if with_commander:
         self.commander = commander()
         self.commandRegister(self.commander)
         self.commander.StartTrack()
     if self.handler[1] != -1:
         if self.handler[0][4] == 1280 and self.handler[0][5] == 809:
             logger.system("检测到Mumu模拟器,已开启快速图像采集")
             self.getScreenShot = getscreenshot
         else:
             logger.notice("检测到Mumu模拟器,请使用1280x720模式以开启快速图像采集!")