def findTeamSelectButton(team_id: int):
    aim_dir = os.path.join(template_dir, "teamSelect")
    pos = imagesearch.imagesearcharea(os.path.join(aim_dir, "%d.png"%(team_id)), window_func.NOX_window_rect[0], window_func.NOX_window_rect[1], window_func.NOX_window_rect[2], window_func.NOX_window_rect[3], precision=0.9)
    if pos[0] == -1:
        pos = imagesearch.imagesearcharea(os.path.join(aim_dir, "%s_s.png"%(team_id)), window_func.NOX_window_rect[0], window_func.NOX_window_rect[1], window_func.NOX_window_rect[2], window_func.NOX_window_rect[3], precision=0.9)
    
    if pos[0] == -1:
        raise ButtonNotFoundException("select team %d"%team_id)
    pos = (pos[0] + window_func.NOX_window_rect[0], pos[1] + window_func.NOX_window_rect[1])
    return pos
def isDisconnected():
    pos = imagesearch.imagesearcharea(
        os.path.join(template_dir, "disconnect.png"), *window.game_window_rect)
    if pos[0] != -1:
        return True

    pos = imagesearch.imagesearcharea(
        os.path.join(template_dir, "resetGameFlag.png"),
        *window.game_window_rect)
    if pos[0] != -1:
        return True

    return False
def findAdventureButton():
    aim_dir = os.path.join(template_dir, "adventure")
    pos = imagesearch.imagesearcharea(os.path.join(aim_dir, "adventure.png"), window_func.NOX_window_rect[0], window_func.NOX_window_rect[1], window_func.NOX_window_rect[2], window_func.NOX_window_rect[3])
    if pos[0] == -1:
        pos = imagesearch.imagesearcharea(os.path.join(aim_dir, "adventure2.png"), window_func.NOX_window_rect[0], window_func.NOX_window_rect[1], window_func.NOX_window_rect[2], window_func.NOX_window_rect[3])
    if pos[0] == -1:
        # 在"冒险"按钮被选中时,会以0.75s左右的频率上下跳动,有可能一次检测不到
        delay.standard_delay(1.0)
        pos = imagesearch.imagesearcharea(os.path.join(aim_dir, "adventure2.png"), window_func.NOX_window_rect[0], window_func.NOX_window_rect[1], window_func.NOX_window_rect[2], window_func.NOX_window_rect[3])
    
    if pos[0] == -1:
        raise ButtonNotFoundException("adventure")
    pos = (pos[0] + window_func.NOX_window_rect[0], pos[1] + window_func.NOX_window_rect[1])
    return pos
Beispiel #4
0
def search_for_collectible_window(max_res: Tuple[int, int, int, int]):
    im = region_grabber(max_res)
    pos = imagesearcharea("images/crafting/yes_no_collectible.png", max_res[0], max_res[1], max_res[2], max_res[3], .95, im)
    if pos[0] != -1:
        return True, pos
    else:
        return False, None
Beispiel #5
0
def search_for_crafting_window(max_res: Tuple[int, int, int, int], timeout: int = 2, sleep_time: int = .1, crafting: bool = False):
    print('making sure crafting window is up')
    c = 0
    t1 = datetime.now()
    t2 = datetime.now()
    while (t2 - t1).seconds < timeout:
        im = region_grabber(max_res)
        pos = imagesearcharea("images/crafting/crafting_window.png", max_res[0], max_res[1], max_res[2], max_res[3], .8, im)
        if pos[0] != -1:
            if crafting:
                # print('Since crafting sleeping and checking again')
                sleep(sleep_time)
                collectible_window = search_for_collectible_window(max_res=max_res)
                if collectible_window[0]:
                    pos2 = collectible_window[1]
                    click_pos = (pos2[0] + 40, pos2[1] + 20)
                    print(click_pos)
                    pyautogui.moveTo(click_pos[0], click_pos[1], duration=.05)
                    pyautogui.mouseDown()
                    sleep(.01)
                    pyautogui.mouseUp()
                t2 = datetime.now()
            else:
                return True
        else:
            if crafting:
                return False
            sleep(sleep_time)
            c += 1
            t2 = datetime.now()
    print(f'Crafting window not found after {t2 - t1} seconds')
    return False
Beispiel #6
0
    def do_record_temperature(self):
        mode = "down"
        im = pyautogui.screenshot()

        if self.is_approximate(im.getpixel((1439, 636)), (214, 100, 126), 3):
            mode = "up"

        keep_going = True
        tries_left = 32

        if mode == "up":
            pyautogui.moveTo(635, 360)
        else:
            pyautogui.moveTo(635, 645)

        pyautogui.mouseDown()

        while keep_going and tries_left > 0:
            pos = imagesearcharea(
                self.main_path + "\\task_images\\record_temperature\\done.jpg",
                666, 509, 875, 641)

            if pos[0] != -1:
                keep_going = False

        pyautogui.mouseUp()
def checkStage():
    pos = imagesearch.imagesearcharea(os.path.join(template_dir,
                                                   "duelStageM2B.png"),
                                      *pos_rel2abs(STAGE_CHECK_RECT),
                                      precision=0.7)
    if pos[0] != -1:
        return 0  # main stage now

    pos = imagesearch.imagesearcharea(os.path.join(template_dir,
                                                   "duelStageB2E.png"),
                                      *pos_rel2abs(STAGE_CHECK_RECT),
                                      precision=0.7)
    if pos[0] != -1:
        return 1  # battle stage now

    return -1  # unknown stage
def findMyTeamButton():
    pos = imagesearch.imagesearcharea(os.path.join(template_dir, "myTeam.png"), window_func.NOX_window_rect[0], window_func.NOX_window_rect[1], window_func.NOX_window_rect[2], window_func.NOX_window_rect[3])
    
    if pos[0] == -1:
        raise ButtonNotFoundException("my team")
    pos = (pos[0] + window_func.NOX_window_rect[0], pos[1] + window_func.NOX_window_rect[1])
    return pos
def findPrincessArenaButton():
    pos = imagesearch.imagesearcharea(os.path.join(template_dir, "princessArena.png"), window_func.NOX_window_rect[0], window_func.NOX_window_rect[1], window_func.NOX_window_rect[2], window_func.NOX_window_rect[3])
    
    if pos[0] == -1:
        raise ButtonNotFoundException("princess arena")
    pos = (pos[0] + window_func.NOX_window_rect[0], pos[1] + window_func.NOX_window_rect[1])
    return pos
def imagesearcharea_example():
    for file in os.listdir(os.path.curdir):
        if file.lower().endswith('.png'):
            pos = imagesearcharea(file, x1=0, y1=0, x2=490, y2=800)
            if type(pos) is tuple:
                print("position : ", pos[0], pos[1])
            else:
                print("image not found")
def getMyMonsterSeatsList():
    seats_list = []
    for seat_id in range(1, 4):
        pos = imagesearch.imagesearcharea(
            os.path.join(template_dir, "emptySeatMyMon%d.png" % (seat_id)),
            *pos_rel2abs(MY_MONSTER_SEATS_RECT[seat_id - 1]),
            precision=0.8)
        seats_list.append(pos[0] == -1)

    return seats_list
Beispiel #12
0
def search_for_replay(start_x, start_y, end_x, end_y):
    global is_in_menu
    print('thread started')
    print(start_x, start_y, end_x, end_y)
    while not is_in_menu:
        pos = imagesearcharea('./references/Replay.png', start_x, start_y,
                              end_x, end_y)
        if pos[0] != -1:
            is_in_menu = True
        time.sleep(random.randint(5, 11) / 10)
def afterDuelActivityNextFlag():
    pos = imagesearch.imagesearcharea(
        os.path.join(template_dir, "afterDuelActivityNext.png"),
        *pos_rel2abs(AFTER_DUEL_ACTIVITY_NEXT_RECT))
    if pos[0] != -1:
        return pos_rel2abs(pos)

    pos = imagesearch.imagesearcharea(
        os.path.join(template_dir, "afterDuelActivityNext2.png"),
        *pos_rel2abs(AFTER_DUEL_ACTIVITY_NEXT_RECT))
    if pos[0] != -1:
        return pos_rel2abs(pos)

    pos = imagesearch.imagesearcharea(
        os.path.join(template_dir, "afterDuelActivityNext3.png"),
        *pos_rel2abs(AFTER_DUEL_ACTIVITY_NEXT_RECT))
    if pos[0] != -1:
        return pos_rel2abs(pos)

    return None
Beispiel #14
0
def find_image_area(image_path, x1, y1, x2, y2, print_suppression = False):
    pos = imagesearcharea(image_path, x1, y1, x2, y2)
    
    if pos[0] != -1:
        if print_suppression == False:
            txt_var = "Image Found:" + get_img_name(image_path)
            log("INFO", "wrapper.find_image", txt_var)
        return True
    else:
        if print_suppression == False:
            txt_var = "Image Not Found - " + get_img_name(image_path)
            log("WARNING", "wrapper.find_image", txt_var)
        return False
Beispiel #15
0
def search_crafting_log(max_res: Tuple[int, int, int, int], timeout: int = 5):
    print('looking if crafting log is up')
    c = 0
    t1 = datetime.now()
    t2 = datetime.now()
    while (t2 - t1).seconds < timeout:
        im = region_grabber(max_res)
        pos = imagesearcharea("images/crafting/crafting_log.png", max_res[0], max_res[1], max_res[2], max_res[3], .8, im)
        if pos[0] != -1:
            print('crafting log window found')
            return True
        sleep(.1)
        c += 1
        t2 = datetime.now()
    return False
def region_grabber_example():
    image_region = region_grabber(region=(0, 0, 800, 600))
    for file in os.listdir(os.path.curdir):
        if file.lower().endswith('.png'):
            pos = imagesearcharea(file,
                                  x1=0,
                                  y1=0,
                                  x2=800,
                                  y2=600,
                                  precision=0.8,
                                  im=image_region)
            if type(pos) is tuple:
                print("position : ", pos[0], pos[1])
            else:
                print("image not found")
def findGate():
    gate_template_dir = os.path.join(template_dir, "gate")
    gate_list = [
        "gatedm.png", "gatedsod.png", "gategx.png", "gate5ds.png",
        "gatezexal.png"
    ]
    for gate_name in gate_list:
        pos = imagesearch.imagesearcharea(os.path.join(gate_template_dir,
                                                       gate_name),
                                          *window.game_window_rect,
                                          precision=0.6)
        if pos[0] != -1:
            break
    if pos[0] == -1:
        raise ButtonNotFoundException("gate")

    return pos_rel2abs(pos)
Beispiel #18
0
    def do_sort_samples(self):
        types = ("fossils", "gems", "plants")

        bins = ((970, 200), (625, 580), (1295, 600))
        area = ((400, 770), (1540, 1080))

        for index, sample in enumerate(types):
            for i in range(2):
                pos = imagesearcharea(
                    self.main_path + "\\task_images\\sort_samples\\" + sample +
                    "\\" + str(i) + ".jpg", area[0][0], area[0][1], area[1][0],
                    area[1][1])

                pyautogui.moveTo(pos[0] + area[0][0], pos[1] + area[0][1])
                pyautogui.mouseDown()

                pyautogui.moveTo(bins[index][0], bins[index][1])
                pyautogui.mouseUp()
Beispiel #19
0
def escape(max_res: Tuple[int, int, int, int]):
    print('escaping')
    c = 0
    escape_window = False
    while c < 20:
        im = region_grabber(max_res)
        pos = imagesearcharea("images/escape_window.png", max_res[0], max_res[1], max_res[2], max_res[3], .8, im)
        if pos[0] != -1:
            escape_window = True
            pyautogui.press('esc')
        elif escape_window:
            print('escape window found and closed')
            return True
        else:
            print(f'escape window not found {c} times - pressing esc')
            pyautogui.press('esc')
        sleep(.5)
        c += 1
    return False
Beispiel #20
0
    def do_assemble_artifact(self):
        x_loc = 950
        y_locs = (185, 300, 423, 550, 665)

        search_area = (420, 890, 1500, 1030)

        for i in range(5):
            pos = imagesearcharea(
                self.main_path + "\\task_images\\assemble_artifact\\pieces\\" +
                str(i) + ".jpg", search_area[0], search_area[1],
                search_area[2], search_area[3])

            print(pos[0] + search_area[0], pos[1] + search_area[1])

            pyautogui.moveTo(
                (pos[0] + search_area[0] + 30, pos[1] + search_area[1] + 30))
            pyautogui.mouseDown()
            pyautogui.moveTo((x_loc, y_locs[i]))
            pyautogui.mouseUp()
Beispiel #21
0
def click_image_relative_to_window(img_path,
                                   start_x,
                                   start_y,
                                   end_x,
                                   end_y,
                                   offset=7,
                                   precision=.8,
                                   im=None):
    pos = imagesearcharea(img_path,
                          start_x,
                          start_y,
                          end_x,
                          end_y,
                          precision=precision,
                          im=im)
    if pos[0] != -1:
        position_for_window = [0, 0]
        position_for_window[0] = pos[0] + start_x
        position_for_window[1] = pos[1] + start_y
        click_image(img_path, position_for_window, 'left', .2, offset=offset)
Beispiel #22
0
def click_synthesize(max_res: Tuple[int, int, int, int], timeout: int = 2):

    c = 0
    t1 = datetime.now()
    t2 = datetime.now()
    while (t2 - t1).seconds < timeout:
        im = region_grabber(max_res)
        pos = imagesearcharea("images/crafting/synthesize.png", max_res[0], max_res[1], max_res[2], max_res[3], .8, im)
        if pos[0] != -1:
            print('clicking synthesis')
            click_pos = (pos[0] + 40, pos[1] + 20)
            pyautogui.moveTo(click_pos[0], click_pos[1], duration=.05)
            sleep(.1)
            #pyautogui.leftClick(duration=.05)
            pyautogui.mouseDown()
            sleep(.01)
            pyautogui.mouseUp()
            return True
        sleep(.1)
        c += 1
    return False
Beispiel #23
0
    def do_run_diagnostics(self):
        button_loc = (777, 945)
        red = (255, 0, 0)
        selection_locs = ((756, 246), (670, 355), (702, 454), (813, 414))

        im = pyautogui.screenshot()
        pos = imagesearcharea(
            self.main_path + "\\task_images\\run_diagnostics\\begin.jpg", 535,
            585, 993, 683)

        if pos[0] == -1:
            for i in selection_locs:
                if self.is_approximate(red, im.getpixel(i), 4):
                    pyautogui.moveTo(i[0], i[1] + 20)
                    pyautogui.mouseDown()
                    pyautogui.mouseUp()
                    break
        else:
            pyautogui.moveTo(button_loc[0], button_loc[1])
            pyautogui.mouseDown()
            pyautogui.mouseUp()
def isGateOpen():
    pos = imagesearch.imagesearcharea(
        os.path.join(template_dir, "gateBeginDuel.png"),
        *window.game_window_rect)
    return pos[0] != -1
def talkingEnd():
    pos = imagesearch.imagesearcharea(
        os.path.join(template_dir, "duelRealBegin.png"),
        *window.game_window_rect)
    return pos[0] != -1
def duelAnimationEnd():
    pos = imagesearch.imagesearcharea(
        os.path.join(template_dir, "duelStageSwitch.png"),
        *pos_rel2abs(DUEL_STAGE_SWITCH_RECT))
    return pos[0] != -1
def isEmptyTeam():
    pos = imagesearch.imagesearcharea(os.path.join(template_dir, "emptyTeam.png"), window_func.NOX_window_rect[0], window_func.NOX_window_rect[1], window_func.NOX_window_rect[2], window_func.NOX_window_rect[3])
    return pos[0] != -1
Beispiel #28
0
        x1 = min(x1, pos[0])
        x2 = max(x2, pos[0])

        y1 = min(y1, pos[1])
        y2 = max(y2, pos[1])
    else:
        print(f"Failed to find {i}")
        exit(0)


print("playing")
grabs = [25, 29, 50]

clicks = []
im = region_grabber((x1, y1, x2 + 100, y2 + 100))
for i in range(1, 51):
    pos = imagesearcharea(f"./imgs/{i}.png", x1, y1, x2 + 200, y2 + 200, im=im)
    if pos[0] != -1:
        #pyautogui.click(pos[0] + 10 + x1, pos[1] + 10 + y1)
        clicks.append([pos[0] + 10 + x1, pos[1] + 10 + y1])
    else:
        print(f"Failed to find {i}")
        exit

    if i in grabs:
        for c in clicks:
            pyautogui.click(c[0], c[1])
        clicks = []
        im = region_grabber((x1, y1, x2 + 100, y2 + 100))

Beispiel #29
0
    def do_enter_id_code(self):
        pyautogui.moveTo(800, 910)
        pyautogui.mouseDown()
        pyautogui.mouseUp()

        search_region = [[788, 710], [824, 770]]
        region_shift = 28
        number_list = []

        sleep(.7)
        im = region_grabber((0, 0, 1920, 1080))

        for i in range(5):
            for number in range(10):
                if len(number_list) == i:
                    temp_search = [
                        search_region[0][0], search_region[0][1],
                        search_region[1][0], search_region[1][1]
                    ]

                    pos = imagesearcharea(
                        self.main_path +
                        "\\task_images\\enter_id_code\\numbers\\" +
                        str(number) + ".jpg", temp_search[0], temp_search[1],
                        temp_search[2], temp_search[3])

                    if pos[0] != -1:
                        number_list.append(number)

                        search_region[0][
                            0] = search_region[0][0] + region_shift
                        search_region[1][
                            0] = search_region[1][0] + region_shift

                        if number_list[-1] == 1:
                            search_region[0][0] = search_region[0][0] - 6
                            search_region[1][0] = search_region[1][0] - 6

                        if self.debug:
                            print(f"found {number}!")

        if self.debug:
            print(f"ID code is {number_list}")

        x_locs = (836, 960, 1075)
        y_locs = (130, 240, 350, 460)

        for number in number_list:

            if number == 0:
                temp_x = x_locs[1]
                temp_y = y_locs[3]
            else:
                if number < 4:
                    temp_y = y_locs[0]
                elif number < 7:
                    temp_y = y_locs[1]
                else:
                    temp_y = y_locs[2]

                if (number - 1) % 3 == 0:
                    temp_x = x_locs[0]
                elif (number - 2) % 3 == 0:
                    temp_x = x_locs[1]
                else:
                    temp_x = x_locs[2]

            pyautogui.moveTo((temp_x, temp_y))
            pyautogui.mouseDown()
            pyautogui.mouseUp()

        pyautogui.moveTo((x_locs[2], y_locs[3]))
        pyautogui.mouseDown()
        pyautogui.mouseUp()
Beispiel #30
0
import pyautogui
import time
#im = pyautogui.screenshot(region=(0,0, 300, 400))
#im.save('./aaa.png')
#cards = imagesearch_from_folder('./assets/downCards/', 0.8)
time1 = time.process_time()
path = "./assets/downNameCards/"
print(path)
i = 0
cards = {}
path = path if path[-1] == '/' or '\\' else path + '/'
valid_images = [".jpg", ".gif", ".png", ".jpeg"]
files = [
    f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))
    and os.path.splitext(f)[1].lower() in valid_images
]
for file in files:
    pos = imagesearcharea(path + file, 450, 900, 1080, 1920, 0.8)
    #pos = imagesearch(path+file, 0.8)
    if pos[0] != -1:
        cards[i] = [file, pos]
        i = i + 1

print("----------------")
print(cards)
print("----------------")
for i in cards:
    print("name: " + cards[i][0])
    print(cards[i][1])

print(str(time.process_time() - time1) + " seconds (optimized)")