Ejemplo n.º 1
0
def select_overview_tab(tab):
    """Switches to the specified overview tab. If the specified tab is already
    selected, this function does nothing. Assumes the default overview
    configuration."""
    logging.debug('focusing ' + (str(tab)) + ' tab')

    # Requires very high confidence since the overview tab buttons look only
    # slightly different when selected.
    selected = lo.mlocate('./img/overview/' + (str(tab)) +
                          '_overview_tab_selected.bmp',
                          conf=0.998,
                          grayscale=True)

    if selected != 0:
        logging.debug('tab ' + (str(tab)) + ' already selected')
        return 1

    elif selected == 0:
        unselected = lo.mlocate('./img/overview/' + (str(tab)) +
                                '_overview_tab.bmp',
                                loctype='co',
                                grayscale=True)

        if unselected != 0:
            (x, y) = unselected
            pag.moveTo((x + (random.randint(-12, 12))),
                       (y + (random.randint(-6, 6))), mouse.duration(),
                       mouse.path())
            mouse.click()
            return 1
        elif unselected == 0:
            logging.error('unable to find overview tabs')
            return 0
Ejemplo n.º 2
0
def set_dest():
    """Issues a 'set destination' command for the lowest-numbered bookmark that
    isn't blacklisted."""
    target_dest = 1
    dest = lo.mlocate('./img/dest/dest' + (str(target_dest)) + '.bmp',
                      conf=0.98,
                      loctype='c')

    while dest == 0:
        target_dest += 1
        logging.debug('looking for dest ' + (str(target_dest)))
        dest = lo.mlocate('./img/dest/dest' + (str(target_dest)) + '.bmp',
                          conf=0.98,
                          loctype='c')

    if dest != 0:
        logging.debug('setting destination waypoint')
        (x, y) = dest
        pag.moveTo(
            (x + (random.randint(-1, 200))), (y + (random.randint(-3, 3))),
            mouse.duration(), mouse.path())
        mouse.click_right()
        pag.moveRel((0 + (random.randint(10, 80))),
                    (0 + (random.randint(20, 25))), mouse.duration(),
                    mouse.path())
        mouse.click()
        time.sleep(float(random.randint(1000, 2000)) / 1000)
        return
Ejemplo n.º 3
0
def focus_client():
    """Clicks on a blank area in the left half of the client window,
    assuming user has properly configured the UI."""
    logging.debug('focusing client')
    pag.moveTo((originx + (random.randint(50, 300))),
               (originy + (random.randint(300, 500))), mouse.duration(),
               mouse.path())

    mouse.click()
    return 1
Ejemplo n.º 4
0
def focus_overview():
    """Clicks somewhere on the lower half of the overview
    (assuming it's on the rightmost quarter of the client window)
    to focus the client. If ship is docked, this click whill occur
    somewhere in the station services window below all the buttons."""
    logging.debug('focusing overview')

    x = (originx + (windowx - (int(windowx / 4.5))))
    y = originy
    randx = (random.randint(0, (int(windowx / 4.5) - 30)))
    randy = (random.randint((int(windowx / 2)), (windowy - 10)))
    pag.moveTo((x + randx), (y + randy), mouse.duration(), mouse.path())

    mouse.click()
    return 1
Ejemplo n.º 5
0
def text_input(hwnd, rect, value):
    mouse.click(hwnd, rect)
    time.sleep(0.3)
    # 删除坐标内容
    time.sleep(0.1)
    keyboard.press_key(hwnd, keyboard.backspace)
    time.sleep(0.1)
    keyboard.press_key(hwnd, keyboard.backspace)
    time.sleep(0.1)
    keyboard.press_key(hwnd, keyboard.backspace)
    time.sleep(0.1)
    keyboard.press_key(hwnd, keyboard.backspace)
    time.sleep(0.2)
    # 输入坐标
    keyboard.type_string(hwnd, value)
    time.sleep(0.5)
Ejemplo n.º 6
0
def warp_to_local_bookmark(target_site_num):
    """Tries warping to the provided target bookmark, assuming the bookmark
    is in the current system. If the ship is already at or near the
    requested bookmark, return the function."""
    # Confidence must be >0.95 because script will confuse 6 with 0.
    target_site_bookmark = lo.mlocate('./img/dest/at_dest' +
                                      (str(target_site_num)) + '.bmp',
                                      conf=0.98,
                                      loctype='c')

    if target_site_bookmark != 0:
        (x, y) = target_site_bookmark
        pag.moveTo(
            (x + (random.randint(10, 200))), (y + (random.randint(-3, 3))),
            mouse.duration(), mouse.path())
        mouse.click_right()
        approach_location = lo.mlocate(
            './img/buttons/detect_warp_to_bookmark.bmp', conf=0.90)

        # If the 'approach location' option is found in the right-click
        # menu, the ship is already near the bookmark.
        if approach_location != 0:
            logging.debug('already at bookmark ' + (str(target_site_bookmark)))
            key.keypress('esc')  # Close right-click menu.
            return 0

        # If the 'approach location' option is not found, look for a 'warp
        # to' option and select it.
        elif approach_location == 0:
            warp_to_site = lo.mlocate('./img/buttons/warp_to_bookmark.bmp',
                                      conf=0.90,
                                      loctype='c')

            if warp_to_site != 0:
                logging.info('warping to bookmark ' +
                             (str(target_site_bookmark)))
                pag.moveRel((0 + (random.randint(10, 80))),
                            (0 + (random.randint(10, 15))), mouse.duration(),
                            mouse.path())
                mouse.click()
                time.sleep(float(random.randint(1500, 1800)) / 1000)
                return 1
            elif warp_to_site == 0:
                logging.error('unable to warp to target site, is ship docked?')
                return 0
Ejemplo n.º 7
0
def set_home():
    """Sets destination to the first bookmark beginning with '000'."""
    home = lo.mlocate('./img/dest/dest0.bmp', loctype='c')
    if home != 0:
        logging.debug('setting home waypoint')
        (x, y) = home
        pag.moveTo(
            (x + (random.randint(-1, 200))), (y + (random.randint(-3, 3))),
            mouse.duration(), mouse.path())
        mouse.click_right()
        pag.moveRel((0 + (random.randint(10, 80))),
                    (0 + (random.randint(20, 25))), mouse.duration(),
                    mouse.path())
        mouse.click()
        return 1
    else:
        logging.error('could not find home waypoint!')
        return 0
Ejemplo n.º 8
0
def warp_to_waypoint():
    """Clicks on the current waypoint and uses the warp hotkey to warp to
    waypoint. Currently only supports warping to stargate and station
    waypoints."""
    # TODO: add support for warping to citadels and engineering complexes
    logging.debug('looking for waypoints')
    # Speed up image searching by looking within overview only. This
    # obviously requires the user to place the overview on the right side of
    # the client window.

    for tries in range(1, 15):
        stargate = lo.mlocate('./img/overview/stargate_waypoint.bmp', conf=0.96)
        if stargate != 0:
            logging.debug('found stargate waypoint')
            (x, y) = stargate
            pag.moveTo((x + (random.randint(-8, 30)))), \
                      (y + (random.randint(-8, 8))), \
                mouse.duration(), mouse.path()
            mouse.click()
            key.keypress('d')  # 'dock / jump' hotkey.
            # Move mouse to the left side of the client to prevent
            # tooltips from interfering with image searches.
            mouse.move_to_neutral()
            return 2

        station = lo.mlocate('./img/overview/station_waypoint.bmp', conf=0.96)
        if station != 0:
            logging.debug('found station waypoint')
            (x, y) = station
            pag.moveTo((x + (random.randint(-8, 30))),
                       (y + (random.randint(-8, 8))),
                       mouse.duration(), mouse.path())
            mouse.click()
            key.keypress('d')
            mouse.move_to_neutral()
            return 2

        if stargate == 0 and station == 0:
            time.sleep(float(random.randint(500, 1500)) / 1000)
            logging.debug('looking for waypoints ' + (str(tries)))

    logging.error('no waypoints found')
    return 0
Ejemplo n.º 9
0
def dock_at_local_bookmark():
    """Docks at the first bookmark beginning with a '0' in its name,
    assuming it's in the same system as you and the bookmark is a station."""
    dock = lo.mlocate('./img/dest/at_dest0.bmp', loctype='c')
    if dock != 0:
        (x, y) = dock
        pag.moveTo(
            (x + (random.randint(-1, 200))), (y + (random.randint(-3, 3))),
            mouse.duration(), mouse.path())
        mouse.click_right()

        pag.moveRel((0 + (random.randint(10, 80))),
                    (0 + (random.randint(35, 40))), mouse.duration(),
                    mouse.path())
        # Sleep used to fix bug in which client doesn't immediately
        # highlight 'dock' after opening right-click menu.
        # (see video 2019-07-06_13-26-14 at 33m50s for bug).
        time.sleep(float(random.randint(700, 1000)) / 1000)
        mouse.click()
        wait_for_dock()
Ejemplo n.º 10
0
def open_ship_inv():
    """Clicks on the ship's inventory button within the inventory window.
    Assumes the ship is docked and the inventory window is already open."""
    logging.debug('opening ship inventory')
    for tries in range(1, 25):
        ship_inv = lo.mlocate('./img/buttons/ship_inv.bmp', loctype='c')
        if ship_inv != 0:
            (x, y) = ship_inv
            pag.moveTo((x + (random.randint(-4, 50))),
                       (y + (random.randint(-6, 6))), mouse.duration(),
                       mouse.path())
            mouse.click()
            return 1

        elif ship_inv == 0:
            logging.error('cannot find ship inventory ' + (str(tries)))
            time.sleep(float(random.randint(500, 2000)) / 1000)

    logging.error('timed out looking for ship inventory')
    return 0
Ejemplo n.º 11
0
def blacklist_set_bookmark(target_site):
    """Blacklist a specific bookmark by changing its name."""
    # TODO: possibly blacklist bookmarks instead by deleting them, which
    # could lead to fewer bugs as sometimes the 'rename bookmark' window
    # does not behave consistently.
    logging.debug('blacklisting bookmark ' + (str(target_site)))
    bookmark_to_blacklist = pag.locateCenterOnScreen(
        ('./img/dest/at_dest' + (str(target_site)) + '.bmp'),
        confidence=conf,
        region=(originx, originy, windowx, windowy))

    (bookmark_to_blacklistx), (bookmark_to_blacklisty) = bookmark_to_blacklist
    pag.moveTo((bookmark_to_blacklistx + (random.randint(-1, 200))),
               (bookmark_to_blacklisty + (random.randint(-3, 3))),
               mouse.duration(), mouse.path())

    time.sleep(float(random.randint(1000, 2000)) / 1000)
    # Multiple clicks to focus the text input field.
    mouse.click()
    time.sleep(float(random.randint(1000, 2000)) / 1000)
    mouse.click()
    time.sleep(float(random.randint(5, 50)) / 1000)
    mouse.click()
    time.sleep(float(random.randint(3000, 4000)) / 1000)
    key.keypress('home')
    key.keypress('b')
    time.sleep(float(random.randint(0, 1000)) / 1000)
    key.keypress('enter')
    return 1
Ejemplo n.º 12
0
def open_specinv(invtype):
    """Opens the ship's specified special inventory
    (for storing ore, minerals, planetary products etc.)
    Assumes the ship is docked and the inventory window is already open."""
    logging.debug('opening ' + invtype + ' inventory')
    for tries in range(1, 25):
        spec_inv = lo.mlocate('./img/buttons/spec_inv_' + invtype + '.bmp',
                              loctype='c')
        if spec_inv != 0:
            (x, y) = spec_inv
            pag.moveTo((x + (random.randint(-4, 50))),
                       (y + (random.randint(-3, 3))), mouse.duration(),
                       mouse.path())
            mouse.click()
            return 1

        if spec_inv == 0:
            logging.error('cannot find ' + invtype + ' inventory ' +
                          (str(tries)))
            time.sleep(float(random.randint(500, 2000)) / 1000)

    logging.error('timed out looking for ' + invtype + ' inventory')
    return 0
Ejemplo n.º 13
0
def focus_inv_window():
    """Clicks somewhere inside the station inventory window to focus it.
    Looks for the sorting buttons in top right corner
    of the inventory window and positions the mouse cursor relative to those
    buttons to click an inavtive area within the inventory window."""
    tries = 0
    window = lo.mlocate('./img/buttons/station_sorting.bmp', loctype='c')

    while window == 0 and tries <= 25:
        logging.error('cannot find sorting icon ' + (str(tries)))
        tries += 1
        time.sleep(float(random.randint(500, 2000)) / 1000)
        window = lo.mlocate('./img/buttons/station_sorting.bmp', loctype='c')

    if window != 0 and tries <= 25:
        (x, y) = window
        pag.moveTo((x - (random.randint(0, 250))),
                   (y + (random.randint(60, 300))), mouse.duration(),
                   mouse.path())
        mouse.click()
        return 1
    elif tries > 25:
        logging.error('timed out looking for sorting buttons')
        return 0
Ejemplo n.º 14
0
def blacklist_station():
    """Blacklists the first green bookmark by editing its name.
    This will prevent other functions from identifying the bookmark
    as a potential site."""
    at_dest = detect_bookmark_location()
    if at_dest != 0:
        logging.debug('blacklisting station')
        at_dest = pag.locateCenterOnScreen(
            ('./img/dest/at_dest' + (str(n)) + '.bmp'),
            confidence=conf,
            region=(originx, originy, windowx, windowy))

        (at_destx), (at_desty) = at_dest
        pag.moveTo((at_destx + (random.randint(-1, 200))),
                   (at_desty + (random.randint(-3, 3))), mouse.duration(),
                   mouse.path())

        time.sleep(float(random.randint(1000, 2000)) / 1000)
        mouse.click()
        # Click once to focus entry, then double-click the entry to edit.
        time.sleep(float(random.randint(1000, 2000)) / 1000)
        mouse.click()
        time.sleep(float(random.randint(5, 50)) / 1000)
        mouse.click()
        time.sleep(float(random.randint(3000, 4000)) / 1000)
        pag.keyDown('home')
        time.sleep(float(random.randint(0, 500)) / 1000)
        pag.keyUp('home')
        time.sleep(float(random.randint(0, 1000)) / 1000)
        pag.keyDown('b')
        # Add a 'b' to beginning of the name indicating site is blacklisted.
        pag.keyUp('b')
        time.sleep(float(random.randint(0, 1000)) / 1000)
        pag.keyDown('enter')
        time.sleep((random.randint(0, 200)) / 100)
        pag.keyUp('enter')
        return
Ejemplo n.º 15
0
def click_page_close(hwnd):
    mouse.click(hwnd, position.page_close_rect)
    time.sleep(2)
Ejemplo n.º 16
0
def click_hero_force_expedition(hwnd):
    mouse.click(hwnd, position.hero_force_expedition_rect)
    time.sleep(1)
Ejemplo n.º 17
0
def click_wipe_out_button(hwnd):
    mouse.click(hwnd, position.wipe_out_button_rect)
    time.sleep(1)
Ejemplo n.º 18
0
def click_army_hero(hwnd, hero_index):
    mouse.click(hwnd, position.army_hero_rect_list[hero_index])
    time.sleep(0.5)
Ejemplo n.º 19
0
def click_expedition_army_even(hwnd, army_index):
    mouse.click(hwnd, position.expedition_army_even_rect_list[army_index])
    time.sleep(1)
Ejemplo n.º 20
0
def click_city_army_even(hwnd, army_index):
    mouse.click(hwnd, position.city_army_even_list[army_index])
    time.sleep(0.5)
Ejemplo n.º 21
0
def click_city_menu(hwnd):
    mouse.click(hwnd, position.city_menu_rect)
    time.sleep(1.5)
    assert_right.assert_enter_city_page(hwnd)
Ejemplo n.º 22
0
def click_mark_location_main_city(hwnd):
    mouse.click(hwnd, position.mark_location_menu_main_city_rect)
    time.sleep(2)
    assert_right.assert_click_mark_location_main_city(hwnd)
Ejemplo n.º 23
0
def click_map_menu(hwnd):
    mouse.click(hwnd, position.map_menu_rect)
    time.sleep(0.5)
Ejemplo n.º 24
0
def click_hero_screen_star_item(hwnd, star):
    mouse.click(
        hwnd, position.hero_screen_star_item_rect_list[const.hero_dict[star]])
    time.sleep(1)
Ejemplo n.º 25
0
def click_hero_screen_camp_reset(hwnd):
    mouse.click(hwnd, position.hero_screen_camp_reset_rect)
    time.sleep(1)
Ejemplo n.º 26
0
def click_hero_screen_button(hwnd):
    mouse.click(hwnd, position.hero_screen_button_rect)
    time.sleep(1)
Ejemplo n.º 27
0
def click_hero_screen_arms_item(hwnd, arms):
    mouse.click(
        hwnd, position.hero_screen_arms_item_rect_list[const.hero_dict[arms]])
    time.sleep(1)
Ejemplo n.º 28
0
def click_mark_location_menu(hwnd):
    mouse.click(hwnd, position.mark_location_menu_rect)
    time.sleep(0.5)
    assert_right.assert_click_mark_location_menu(hwnd)
Ejemplo n.º 29
0
def initiate_target_lock(target):
    """Selects topmost user-defined target on the overview. Approaches the
    selected target and attempts to lock the target once ship is close
    enough. Tries multiple times to lock the target before giving up. Checks
    for jamming attempts while approaching the target."""
    if target != 0:
        # Break apart tuple into coordinates.
        (x, y, l, w) = target
        # Adjust coordinates for screen.
        x = (x + (originx + (windowx - (int(windowx / 3.8)))))
        y = (y + originy)
        pag.moveTo(
            (x + (random.randint(-100, 20))), (y + (random.randint(-3, 3))),
            mouse.duration(), mouse.path())
        mouse.click()
        # Press 'keep at range' hotkey. This is used instead
        # 'orbit' because if another mining ship depletes the asteroid,
        # your ship will continue flying forever in a straight line.
        key.keypress('e')
        # Change to the general tab to detect jamming.
        select_overview_tab('general')

        # Try 5 times to get a target lock.
        for tries in range(1, 6):
            # Limit how long the ship spends approaching its target before
            # giving up
            for approachtime in range(1, 50):

                # Once target is in range, attempt to lock it.
                if is_target_lockable() == 1 and is_jammed(1) == 0:
                    logging.debug('try #' + (str(tries)) + ' to lock target')
                    lock_icon = lo.mlocate(
                        './img/indicators/target_lock_available.bmp',
                        loctype='c',
                        grayscale=True)
                    (x, y) = lock_icon
                    pag.moveTo((x + (random.randint(-10, 10))),
                               (y + (random.randint(-10, 10))),
                               mouse.duration(), mouse.path())
                    mouse.click()
                    mouse.move_to_neutral()
                    target_locked = wait_for_target_lock()
                    if target_locked == 1:
                        return 1
                    elif target_locked == 0:
                        # if wait_for_target_lock() times out, continue the
                        # outer 'for' loop and try locking
                        # target again
                        break

                elif is_target_lockable() == 0 and is_jammed(1) == 0:
                    logging.debug('target not yet within range ' +
                                  (str(approachtime)))
                    time.sleep(float(random.randint(10, 20)) / 10)

                elif is_jammed(1) == 1:
                    logging.warning('jammed while approaching target')
                    return 0

            logging.warning(
                'timed out waiting for target to get within range!')
            return 0

        logging.warning('lock target failed')
        return 0

    else:
        logging.info('no targets available')
        return 0
Ejemplo n.º 30
0
def click_hero_screen_camp_item(hwnd, camp):
    mouse.click(
        hwnd, position.hero_screen_camp_item_rect_list[const.hero_dict[camp]])
    time.sleep(1)