コード例 #1
0
def help_ally():
    pos = coords.ally_help.visible_in(
        coords.bot_window)  # check if ally needs help
    if pos is not None:
        pos = pyautogui.center(pos)
        adb.tap([pos[0], pos[1] + coords.bot_window[1]])
        log('Help ally complete')
コード例 #2
0
def repair_wall():
    go_kingdom()
    go_castle()
    for island in coords.wall_repair_islands:
        adb.tap(island)
    adb.tap(coords.back[0])
    go_kingdom_direct()
コード例 #3
0
def PLAY(n):  #there is n lines and n rols
    adb.screencap("test.png")
    im = Image.open("test.png")
    x0, y0 = 41, 535
    box = (x0, y0, 1041, 1535)
    part = im.crop(box)
    #part.show()
    #print part.size[0],part.size[1]

    line = rol = n
    array = [['*' for i in range(line)] for i in range(rol)]

    dl = 500 / line

    for i in range(line):
        for j in range(rol):
            color = RGBAtoH(part.getpixel(
                ((2 * j + 1) * dl, (2 * i + 1) * dl)))
            array[i][j] = color
    print array

    if (array[0][0] == array[0][1]): color = array[0][0]
    else: color = array[1][1]

    for i in range(line):  #find and tap
        for j in range(rol):
            temp = RGBAtoH(part.getpixel(((2 * j + 1) * dl, (2 * i + 1) * dl)))
            if temp != color:
                adb.tap(x0 + (2 * j + 1) * dl, y0 + (2 * i + 1) * dl)
                print "tap:", (2 * j + 1) * dl, (2 * i + 1) * dl
                break
            if temp != color: break

    im.close()
    part.close()
コード例 #4
0
def go_kingdom_direct():
    for _ in range(5):  # try 5 times then abort
        if coords.back.visible():
            adb.tap(coords.back[0])
        else:
            break
    adb.tap(coords.kingdom[0])
    wait(coords.castle, area=coords.bot_window, timeout=60)
    log('Go kingdom directly')
コード例 #5
0
ファイル: game_actions.py プロジェクト: Norne9/AzurBot
def checked_tap(x, y):
    before = adb.screenshot()[58:101, 10:53]
    adb.tap(x, y)
    time.sleep(0.5)
    after = adb.screenshot()[58:101, 10:53]

    # if switch disappeared it's ok
    if not Btn.switch.on_screen(after):
        return
    # if ship icon changed -> change it back
    if img.mean_square(before, after) > 0.001:
        swap()
コード例 #6
0
def go_castle():
    for _ in range(5):  # try 5 times then abort
        if coords.back.visible():
            adb.tap(coords.back[0])
        else:
            break
    try:
        wait(coords.kingdom, area=coords.bot_window, timeout=5)
    except TimeoutError:
        adb.tap(coords.castle[0])
        wait(coords.kingdom, area=coords.bot_window, timeout=60)
        log('go_castle complete')
コード例 #7
0
ファイル: game_actions.py プロジェクト: Norne9/AzurBot
def click_boss() -> str:
    log(f"Searching boss")
    for sw in swipes:
        sw()  # swipe in some direction
        time.sleep(1.0)
        click_question()
        screen = utils.screenshot()

        for boss_pic in [Img.boss, Img.boss2, Img.boss_mini]:
            boss_point = img.find_best(screen, boss_pic, 0.7)
            if boss_point is not None:
                boss_point = boss_point[0] + boss_pic.shape[1] // 2, boss_point[1] + boss_pic.shape[0] // 2
                break
        else:
            continue

        x, y = boss_point
        point = None
        for _ in range(2):  # 2 click try's
            point = enemy_finder.get_safe_point(x * 3, y * 3)
            if point is None:
                continue
            bx, by = point

            log(f"Tap boss [{bx}, {by}]")
            adb.tap(bx, by)
            if detect_info():  # don't try second click
                break
            if wait_for_battle(8.0):  # success if switch disappeared
                return "boss"

        if point is None:  # don't attack ships if boss not clickable
            continue

        # failed
        log(f"Searching ships near boss")
        ships = []
        screen = adb.screenshot(False)
        for yellow in [True, False]:
            ships.extend(enemy_finder.find_triangles(screen, yellow))
        sort_near(ships, (x * 3, y * 3))  # ships near boss

        if tap_ships(ships):
            return "ship"

    return "none"
コード例 #8
0
ファイル: game_actions.py プロジェクト: Norne9/AzurBot
def click_question(clicks_before: int = 0):
    screen = utils.screenshot()
    zones = img.find_zones(screen, Img.question0, 0.8)
    zones.extend(img.find_zones(screen, Img.question1, 0.8))
    for x, y, w, h in zones:
        x, y = x + w / 2, y + h / 2 + 30
        point = enemy_finder.get_safe_point(int(x) * 3, int(y) * 3)
        if point is None:
            continue
        x, y = point
        log(f"Click question [{x}, {y}]")
        adb.tap(x, y)
        if detect_info():
            continue

        time.sleep(7.0)
        if clicks_before < 4:
            click_question(clicks_before + 1)
        break
コード例 #9
0
ファイル: btn.py プロジェクト: Norne9/AzurBot
 def __click(self, screen: np.ndarray, image: np.ndarray) -> bool:
     if self.x < 0:  # find mode
         zones = img.find_zones(screen, image, 0.8)
         if len(zones) == 0:
             return False
         x, y, w, h = random.choice(zones)
         x, y = x + self.offset_x, y + self.offset_y
         x, y = x * 3 + random.randint(0, w * 3), y * 3 + random.randint(
             0, h * 3)
     else:
         if img.check_zone(screen, image, self.x, self.y) < 0.9:
             return False
         x, y = self.x + self.offset_x, self.y + self.offset_y
         x, y = (
             x * 3 + random.randint(0, image.shape[1] * 3),
             y * 3 + random.randint(0, image.shape[0] * 3),
         )
     adb.tap(x, y)
     return True
コード例 #10
0
def collect_gift():
    adb.tap(coords.alliance)
    adb.tap(coords.alliance_gift)
    for _ in range(10):
        im = adb.screenshot()
        if im.getpixel(
            (coords.gift_collect[0], coords.gift_collect[1]))[0] < 30:
            break
        adb.tap(coords.gift_collect)
    for _ in range(5):  # try 5 times then abort
        if coords.back.visible_in(coords.top_window):
            adb.tap(coords.back[0])
        else:
            break
コード例 #11
0
def collect_tribute():
    go_kingdom()
    go_castle()
    for island in coords.tribute_islands:
        adb.tap(island)
    adb.tap(coords.msg_confirm)
    time.sleep(3)
    countdown = tribute_countdown()
    if countdown is None:
        countdown = tribute_countdown()  # try one more time
    adb.tap(coords.empty_space)
    go_kingdom_direct()
    return countdown
コード例 #12
0
def go_gathering(res, mode='ordinary'):
    res_coord = {
        'food': coords.farm,
        'wood': coords.sawmill,
        'iron': coords.iron_mine,
        'silver': coords.silver_mine
    }
    go_kingdom()
    adb.tap(coords.magnifier)
    time.sleep(3)
    adb.tap(res_coord[res])
    adb.tap(coords.res_lvl_up, 2)
    adb.tap(coords.res_lvl_dn, 2)
    adb.tap(coords.search)
    time.sleep(5)
    adb.tap(coords.screen_center)
    time.sleep(3)
    adb.tap(coords.gather[0])
    time.sleep(3)
    if coords.train.visible_in(coords.mid_window):
        adb.tap(coords.back[0])
        log('No troops for gathering')
    else:
        if mode == 'half':
            adb.tap(coords.half_troop)
        elif mode == 'ordinary':
            adb.tap(coords.slot_preferred)
            adb.tap(coords.ordinary_slot)
        adb.tap(coords.march)
        wait(coords.castle)
        log('Troops go gathering {}'.format(res))
コード例 #13
0
ファイル: utils.py プロジェクト: Norne9/AzurBot
def click(x: int, y: int, w: int, h: int, delay: float):
    x, y = random.randint(x * 3,
                          x * 3 + w * 3), random.randint(y * 3, y * 3 + h * 3)
    adb.tap(x, y)
    time.sleep(delay)
コード例 #14
0
ファイル: utils.py プロジェクト: Norne9/AzurBot
def do_nothing():
    x1, y1 = random.randint(174, 514) * 3, random.randint(57, 77) * 3
    adb.tap(x1, y1)
    time.sleep(1.0)
コード例 #15
0
def collect_resource():
    go_kingdom()
    go_castle()
    for island in coords.resource_islands:
        adb.tap(island)
    go_kingdom()
コード例 #16
0
def donation(donation_group):
    adb.tap(coords.alliance)
    adb.tap(coords.donation)
    adb.tap(donation_group)
    adb.tap(coords.donation_item)
    adb.tap(coords.donation_1click)
    adb.tap(coords.donation_confirm)

    for _ in range(5):  # try 5 times then abort
        if coords.back.visible_in(coords.top_window):
            adb.tap(coords.back[0])
        else:
            break
コード例 #17
0
def gather_super_mine(mode='ordinary'):
    adb.tap(coords.alliance)
    adb.tap(coords.territory)
    adb.tap(coords.super_mine)

    screenshot = adb.screenshot()
    for loc in coords.super_mine_coord_locations:
        im = screenshot.crop(loc)
        im = PIL.ImageOps.invert(im)
        result = img2str(im, config=None)
        if 'Coordinate' in result:
            x = (loc[0] + loc[2]) // 2
            y = (loc[1] + loc[3]) // 2
            adb.tap((x, y))
            break
    else:
        log('No super mine available')
        return False

    adb.tap(coords.screen_center)
    time.sleep(3)

    if coords.gather.visible_in(coords.mid_window):
        adb.tap(coords.gather[0])
        time.sleep(3)
    else:
        log('Troop in super mine already')
        return False

    if coords.train.visible_in(coords.mid_window):
        adb.tap(coords.back[0])
        log('No troops for gathering')
    else:
        if mode == 'half':
            adb.tap(coords.half_troop)
        elif mode == 'ordinary':
            adb.tap(coords.slot_preferred)
            adb.tap(coords.ordinary_slot)
        elif mode == 'superior':
            adb.tap(coords.slot_preferred)
            adb.tap(coords.superior_slot)
        adb.tap(coords.march)
        wait(coords.castle)
        log('Go gathering super mine complete')
    return True