예제 #1
0
def jiaorenwu(hwnd, x, y):
    button_renwu_img = cv2.cvtColor(cv2.imread("src/gzlj/button_renwu.png"), cv2.COLOR_BGR2GRAY)
    button_quanbushouqu_img = cv2.cvtColor(cv2.imread("src/gzlj/button_quanbushouqu.png"), cv2.COLOR_BGR2GRAY)
    shouqubaochou_img = cv2.cvtColor(cv2.imread("src/gzlj/shouqubaochou.png"), cv2.COLOR_BGR2GRAY)
    level_up_img = cv2.cvtColor(cv2.imread("src/gzlj/level_up.png"), cv2.COLOR_BGR2GRAY)

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_renwu_img)
    if points:
        pos = (2754 - 1927, 579 - 156)
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)
    else:
        # 点主页
        pos = (2006 - 1927, 661 - 156)
        randint_x = random.randint(0, 50)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(4.8, 5.2))
        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, button_renwu_img)
        if points:
            pos = (2754 - 1927, 579 - 156)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
        else:
            print("未找到任务按钮,退出。")
            return

    time.sleep(random.uniform(4.8, 5.2))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_quanbushouqu_img)
    if points:
        pos = (2736 - 1927, 585 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(2.8, 3.2))

        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, shouqubaochou_img)
        if points:
            pos = (2378 - 1927, 630 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(2.8, 3.2))

        src_img = window_capture(hwnd, x, y)
        # 升级了,点ok
        points = get_match_points(src_img, level_up_img, threshold=0.95)
        if points:
            # 这里用窗口4抓的坐标
            pos = (3330 - 2881, 1066 - 705)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
예제 #2
0
def enter_game(hwnd, x, y):
    app_pcr_img = cv2.cvtColor(cv2.imread("src/gzlj/app_pcr.png"), cv2.COLOR_BGR2GRAY)
    button_zhucaidan_img = cv2.cvtColor(cv2.imread("src/gzlj/button_zhucaidan.png"), cv2.COLOR_BGR2GRAY)
    tongzhi_img = cv2.cvtColor(cv2.imread("src/gzlj/tongzhi.png"), cv2.COLOR_BGR2GRAY)
    button_skip_img = cv2.cvtColor(cv2.imread("src/gzlj/button_skip.png"), cv2.COLOR_BGR2GRAY)
    denglujiangli_img = cv2.cvtColor(cv2.imread("src/gzlj/denglujiangli.png"), cv2.COLOR_BGR2GRAY)

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, app_pcr_img)
    if points:
        pos = points[0]
        randint_x = random.randint(10, 15)
        randint_y = random.randint(10, 15)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(7.8, 8.2))

        is_in = False
        for i in range(30):
            time.sleep(random.uniform(settings.inverval_min, settings.inverval_max))

            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_zhucaidan_img)
            if points:
                is_in = True
                pos = (2263 - 1927, 338 - 156)
                randint_x = random.randint(0, 100)
                randint_y = random.randint(0, 100)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(1.8, 2.2))
                continue
            else:
                if is_in:
                    break

        if is_in:
            for i in range(30):
                time.sleep(random.uniform(settings.inverval_min, settings.inverval_max))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_skip_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(5, 15)
                    randint_y = random.randint(5, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    continue
                points = get_match_points(src_img, denglujiangli_img, threshold=0.8)
                if points:
                    pos = points[0]
                    randint_x = random.randint(20, 50)
                    randint_y = random.randint(20, 50)
                    window_click(hwnd, pos, randint_x, randint_y)
                    continue
                points = get_match_points(src_img, tongzhi_img)
                if points:
                    pos = (2366 - 1927, 625 - 156)
                    randint_x = random.randint(0, 30)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    return
예제 #3
0
def jianxueren(hwnd, x, y):
    xiaoxueren_img = cv2.cvtColor(cv2.imread("src/xiaoxueren.png"),
                                  cv2.COLOR_BGR2GRAY)
    xiaoxueren2_img = cv2.cvtColor(cv2.imread("src/xiaoxueren2.png"),
                                   cv2.COLOR_BGR2GRAY)
    duidie_close_img = cv2.cvtColor(cv2.imread("src/duidie_close.png"),
                                    cv2.COLOR_BGR2GRAY)

    src_img = window_capture(hwnd, x, y)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y, src_img)

    num = 0
    while True:
        time.sleep(random.uniform(settings.inverval_min,
                                  settings.inverval_max))

        num += 1
        if num >= 600:
            # 点下任务栏,避免锁屏
            pos = (2863 - 1927, 303 - 193)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.8, 1.2))
            pos = (2863 - 1927, 303 - 193)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            num = 0

        src_img = window_capture(hwnd, x, y)

        # 目标堆叠,选中第一个目标
        points = get_match_points(src_img, duidie_close_img)
        if points:
            pos = points[0]
            randint_x = random.randint(-100, -80)
            randint_y = random.randint(0, 15)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        points = get_match_points(src_img, xiaoxueren_img, threshold=0.85)
        if not points:
            points = get_match_points(src_img, xiaoxueren2_img, threshold=0.85)
        if points:
            pos = points[0]
            randint_x = random.randint(5, 10)
            randint_y = random.randint(5, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue
예제 #4
0
def gonghui(hwnd, x, y):
    button_shouqu_img = cv2.cvtColor(cv2.imread("src/gzlj/button_shouqu.png"), cv2.COLOR_BGR2GRAY)
    quanbushouqu_img = cv2.cvtColor(cv2.imread("src/gzlj/quanbushouqu.png"), cv2.COLOR_BGR2GRAY)

    # 点公会之家
    pos = (2525 - 1927, 661 - 156)
    randint_x = random.randint(0, 50)
    randint_y = random.randint(0, 10)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(4.8, 5.2))

    # 点全部收取
    pos = (2808 - 1927, 563 - 156)
    randint_x = random.randint(0, 25)
    randint_y = random.randint(0, 25)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(2.4, 2.6))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, quanbushouqu_img)
    if points:
        # 点OK
        pos = (2367 - 1927, 625 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
예제 #5
0
def niudan(hwnd, x, y):
    button_mianfei_img = cv2.cvtColor(cv2.imread("src/gzlj/button_mianfei.png"), cv2.COLOR_BGR2GRAY)
    putongniudan_img = cv2.cvtColor(cv2.imread("src/gzlj/putongniudan.png"), cv2.COLOR_BGR2GRAY)

    # 点扭蛋
    pos = (2655 - 1927, 661 - 156)
    randint_x = random.randint(0, 50)
    randint_y = random.randint(0, 10)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(4.8, 5.2))

    # 点普通
    pos = (2779 - 1927, 222 - 156)
    randint_x = random.randint(0, 30)
    randint_y = random.randint(0, 10)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(2.4, 2.6))

    # 点免费
    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_mianfei_img)
    if points:
        pos = (2607 - 1927, 492 - 156)
        randint_x = random.randint(0, 50)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(2.4, 2.6))

        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, putongniudan_img)
        if points:
            # 点ok
            pos = (2485 - 1927, 515 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(4.8, 5.2))
            # 点ok
            pos = (2373 - 1927, 588 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
예제 #6
0
def yanhui(hwnd, x, y, jianlihua=False):
    # 初始化变量,分中午跟晚上
    button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                    cv2.COLOR_BGR2GRAY)
    button_wanchengliaoli_img = cv2.cvtColor(
        cv2.imread("src/button_wanchengliaoli.png"), cv2.COLOR_BGR2GRAY)
    button_pinchang_img_color = cv2.cvtColor(
        cv2.imread("src/button_pinchang.png"), cv2.IMREAD_COLOR)
    button_pinchang_gray_img_color = cv2.cvtColor(
        cv2.imread("src/button_pinchang_gray.png"), cv2.IMREAD_COLOR)
    biaoqing_chaoren_img_color = cv2.cvtColor(
        cv2.imread("src/biaoqing_chaoren.png"), cv2.IMREAD_COLOR)
    lihua_rest_img = cv2.cvtColor(cv2.imread("src/lihua_rest.png"),
                                  cv2.COLOR_BGR2GRAY)
    lihua_end_img = cv2.cvtColor(cv2.imread("src/lihua_end.png"),
                                 cv2.COLOR_BGR2GRAY)
    duiwu_yincang_img = cv2.cvtColor(cv2.imread("src/duiwu_yincang.png"),
                                     cv2.COLOR_BGR2GRAY)
    zhuozi_choice_img = cv2.cvtColor(cv2.imread("src/zhuozi_choice.png"),
                                     cv2.COLOR_BGR2GRAY)
    xinxi_close_img = cv2.cvtColor(cv2.imread("src/xinxi_close.png"),
                                   cv2.COLOR_BGR2GRAY)
    yanhui_clock_img = cv2.cvtColor(cv2.imread("src/yanhui_clock.png"),
                                    cv2.COLOR_BGR2GRAY)

    if jianlihua:
        lihua_img_color = cv2.cvtColor(cv2.imread("src/lihua.png"),
                                       cv2.IMREAD_COLOR)
        lower = np.array([24, 160, 180], dtype="uint8")
        upper = np.array([67, 230, 255], dtype="uint8")
        mask = cv2.inRange(lihua_img_color, lower, upper)
        lihua_img_color = cv2.bitwise_and(lihua_img_color,
                                          lihua_img_color,
                                          mask=mask)
        lihua_img = cv2.cvtColor(lihua_img_color, cv2.COLOR_BGR2GRAY)

        lihua_choice_img = cv2.cvtColor(cv2.imread("src/lihua_choice.png"),
                                        cv2.COLOR_BGR2GRAY)

    while True:
        hour = time.localtime().tm_hour
        minute = time.localtime().tm_min
        if hour == 12:
            if minute <= 20:
                print("还未到20分,等待2-3分钟。")
                time.sleep(random.uniform(120.0, 180.0))
                continue
            yanhuirenwu_img_color = cv2.cvtColor(
                cv2.imread("src/yanhuirenwu_zhongwu.png"), cv2.IMREAD_COLOR)
            duihua_woyaoquyanhui_img = cv2.cvtColor(
                cv2.imread("src/duihua_woyaoquyanhui.png"), cv2.COLOR_BGR2GRAY)
            duihua_kaishizhunbeishicai_img = cv2.cvtColor(
                cv2.imread("src/duihua_kaishizhunbeishicai.png"),
                cv2.COLOR_BGR2GRAY)
            ditu_yanhui_img = cv2.cvtColor(
                cv2.imread("src/ditu_yanhui_zhongwu.png"), cv2.COLOR_BGR2GRAY)
            # 分别为待机的位置和要点的桌子的坐标
            pos_list = [
                ((2427 - 1927, 435 - 156), (2174 - 1927, 443 - 156)),
                ((2409 - 1927, 416 - 156), (2210 - 1927, 491 - 156)),
                ((2339 - 1927, 388 - 156), (2403 - 1927, 567 - 156)),
                ((2309 - 1927, 396 - 156), (2474 - 1927, 551 - 156)),
                ((2282 - 1927, 436 - 156), (2539 - 1927, 446 - 156)),
            ]
            break
        elif hour == 19:
            if minute <= 20:
                print("还未到20分,等待2-3分钟。")
                time.sleep(random.uniform(120.0, 180.0))
                continue
            yanhuirenwu_img_color = cv2.cvtColor(
                cv2.imread("src/yanhuirenwu.png"), cv2.IMREAD_COLOR)
            #yanhuirenwu_img_color = cv2.cvtColor(cv2.imread("src/yanhuirenwu_chunjie.png"), cv2.IMREAD_COLOR)
            duihua_woyaoquyanhui_img = cv2.cvtColor(
                cv2.imread("src/duihua_woyaoquyanhui.png"), cv2.COLOR_BGR2GRAY)
            #duihua_woyaoquyanhui_img = cv2.cvtColor(cv2.imread("src/duihua_woyaoquyanhui_chunjie.png"), cv2.COLOR_BGR2GRAY)
            duihua_kaishizhunbeishicai_img = cv2.cvtColor(
                cv2.imread("src/duihua_kaishizhunbeishicai.png"),
                cv2.COLOR_BGR2GRAY)
            ditu_yanhui_img = cv2.cvtColor(cv2.imread("src/ditu_yanhui.png"),
                                           cv2.COLOR_BGR2GRAY)
            # 分别为待机的位置和要点的桌子的坐标
            pos_list = [
                ((2491 - 1927, 472 - 156), (2147 - 1927, 395 - 156)),
                ((2465 - 1927, 442 - 156), (2252 - 1927, 504 - 156)),
                ((2424 - 1927, 425 - 156), (2417 - 1927, 577 - 156)),
                ((2384 - 1927, 436 - 156), (2574 - 1927, 540 - 156)),
                ((2374 - 1927, 463 - 156), (2617 - 1927, 427 - 156)),
            ]
            break
        else:
            # 等待30分钟
            print("还未到12点或19点,等待5分钟。")
            time.sleep(300)
            continue

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    num_error = 0
    while True:
        if num_error >= 5:
            print("错误次数过多,退出")
            return

        time.sleep(random.uniform(settings.inverval_min,
                                  settings.inverval_max))

        result = public.open_window_richeng(hwnd, x, y)
        if not result:
            print("未能打开日程窗口")
            num_error += 1
            continue
        else:
            num_error = 0

        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        points = get_match_points(src_img,
                                  yanhuirenwu_img_color,
                                  threshold=0.9)
        if not points:
            # 等待字幕消失
            time.sleep(random.uniform(2.8, 3.2))
            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            points = get_match_points(src_img,
                                      yanhuirenwu_img_color,
                                      threshold=0.9)
            if not points:
                print("错误,宴会未开始,退出。")
                public.close_window_richeng(hwnd, x, y)
                return

        # 点前往参加
        pos = points[0]
        randint_x = random.randint(15, 30)
        randint_y = random.randint(68, 78)
        window_click(hwnd, pos, randint_x, randint_y)

        for i in range(5):
            time.sleep(
                random.uniform(settings.inverval_min, settings.inverval_max))
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, duihua_woyaoquyanhui_img)
            if points:
                time.sleep(
                    random.uniform(settings.inverval_min,
                                   settings.inverval_max))
                px, py = points[0]
                pos = (px + 50, py + 20)
                randint_x = random.randint(0, 80)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                for i in range(2):
                    time.sleep(
                        random.uniform(settings.inverval_min * 2,
                                       settings.inverval_max * 2))
                    src_img = window_capture(hwnd, x, y)
                    points = get_match_points(src_img,
                                              duihua_woyaoquyanhui_img)
                    if points:
                        px, py = points[0]
                        pos = (px + 50, py + 20)
                        randint_x = random.randint(0, 80)
                        randint_y = random.randint(0, 5)
                        window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(2.8, 3.2))
                break
        break

    time.sleep(random.uniform(1.8, 2.2))
    # 关闭未知对话
    points = get_match_points(src_img, button_close_img)
    if points:
        pos = (2856 - 1927, 233 - 193)
        randint_x = random.randint(0, 10)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)

    time.sleep(random.uniform(1.8, 2.2))

    # 隐藏任务列表
    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, duiwu_yincang_img)
    if points:
        pos = points[0]
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.6, 0.8))

    # 打开地图
    pos = (1997 - 1927, 178 - 156)
    randint_x = random.randint(0, 5)
    randint_y = random.randint(0, 10)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(1.4, 1.6))
    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_close_img)
    if not points:
        # 未点开地图?,重新点开,重新截图
        print("场景切换?未能点开地图,重新点开")
        time.sleep(random.uniform(4.8, 5.2))
        pos = (1997 - 1927, 178 - 156)
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(1.4, 1.6))
        src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, ditu_yanhui_img)
    if not points:
        print("进入宴会失败,退出")
        return
    else:
        # 随机取一对坐标
        r = random.randint(0, len(pos_list) - 1)
        pos_wait, pos_target = pos_list[r]
        print("#######################")
        print(hwnd)
        print(pos_wait, pos_target)
        print("#######################")
        # 去待机位置
        randint_x = random.randint(0, 1)
        randint_y = random.randint(0, 1)
        window_click(hwnd, pos_wait, randint_x, randint_y)
        time.sleep(random.uniform(0.8, 1.0))

        # 关闭地图
        pos = (1997 - 1927, 178 - 156)
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(1.0, 1.2))
        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, button_close_img)
        if points:
            # 地图未能关闭?重新关闭。
            print("场景切换?未能关闭地图,重新关闭。")
            time.sleep(random.uniform(4.8, 5.2))
            pos = (1997 - 1927, 178 - 156)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)

        time.sleep(random.uniform(9.8, 10.2))

        # 点桌子,做菜
        randint_x = random.randint(0, 1)
        randint_y = random.randint(0, 1)
        window_click(hwnd, pos_target, randint_x, randint_y)
        time.sleep(random.uniform(1.0, 1.2))
        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, zhuozi_choice_img, threshold=0.98)
        if points:
            # 在一起了,需要选择
            pos = points[0]
            randint_x = random.randint(5, 90)
            randint_y = random.randint(5, 20)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.0, 1.2))

        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, duihua_kaishizhunbeishicai_img)
        if points:
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            for i in range(2):
                time.sleep(
                    random.uniform(settings.inverval_min * 2,
                                   settings.inverval_max * 2))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img,
                                          duihua_kaishizhunbeishicai_img)
                if points:
                    px, py = points[0]
                    pos = (px + 50, py + 20)
                    randint_x = random.randint(0, 80)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(2.8, 3.2))

            # 等待完成料理
            while True:
                time.sleep(
                    random.uniform(settings.inverval_min * 3,
                                   settings.inverval_max * 3))
                print("等待完成料理...")
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_wanchengliaoli_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(25, 65)
                    randint_y = random.randint(5, 15)
                    window_click(hwnd, pos, randint_x, randint_y)
                    for i in range(2):
                        time.sleep(
                            random.uniform(settings.inverval_min * 2,
                                           settings.inverval_max * 2))
                        src_img = window_capture(hwnd, x, y)
                        points = get_match_points(src_img,
                                                  button_wanchengliaoli_img)
                        if points:
                            pos = points[0]
                            randint_x = random.randint(25, 65)
                            randint_y = random.randint(5, 15)
                            window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(1.6, 1.8))
                    break
            # 退出做菜循环,避免未知移动,回到原位置
            pos = (1997 - 1927, 178 - 156)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.0, 1.2))
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_close_img)
            if not points:
                # 未点开地图?,重新点开,重新截图
                print("场景切换?未能点开地图,重新点开")
                time.sleep(random.uniform(4.8, 5.2))
                pos = (1997 - 1927, 178 - 156)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(1.0, 1.2))

            # 去待机位置
            randint_x = random.randint(0, 1)
            randint_y = random.randint(0, 1)
            window_click(hwnd, pos_wait, randint_x, randint_y)
            time.sleep(random.uniform(0.5, 0.6))

            # 关闭地图
            pos = (1997 - 1927, 178 - 156)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.0, 1.2))
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_close_img)
            if points:
                # 地图未能关闭?重新关闭。
                print("场景切换?未能关闭地图,重新关闭。")
                time.sleep(random.uniform(4.8, 5.2))
                pos = (1997 - 1927, 178 - 156)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(1.0, 1.2))

            time.sleep(random.uniform(1.8, 2.2))

            print("完成料理.")
        else:
            # 未知对话,关闭对话
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_close_img)
            if points:
                pos = points[0]
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.4, 0.6))
            print("未知,做菜失败.")

    waiting_num = 0
    already_huanqing = False
    index = 0
    is_lihua_end = False
    while True:
        # 循环次数
        index += 1
        # 吃菜循环
        time.sleep(
            random.uniform(settings.inverval_min * 2,
                           settings.inverval_max * 2))
        if waiting_num >= 30:
            # 5分钟点桌子都没反映,点开地图看下
            pos = (1997 - 1927, 178 - 156)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.0, 1.2))
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_close_img)
            if not points:
                # 未点开地图?,重新点开,重新截图
                print("场景切换?未能点开地图,重新点开")
                time.sleep(random.uniform(4.8, 5.2))
                pos = (1997 - 1927, 178 - 156)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(1.0, 1.2))
                src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, ditu_yanhui_img)
            if not points:
                pos = (1997 - 1927, 178 - 156)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                print("帮派宴会已结束,退出")
                return
            else:
                pos = (1997 - 1927, 178 - 156)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                waiting_num = 0
                continue

        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        # 欢庆神武4
        left = 0
        top = 0
        w = 970
        h = 400
        opponent_img = src_img[top:top + h, left:left + w]
        points = get_match_points(opponent_img,
                                  biaoqing_chaoren_img_color,
                                  threshold=0.8)
        if points:
            if not already_huanqing:
                px, py = points[0]
                pos = (px + 87, py)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                already_huanqing = True
                continue
        else:
            already_huanqing = False

        if jianlihua and not is_lihua_end:
            is_move = False
            while True:
                time.sleep(
                    random.uniform(settings.inverval_min,
                                   settings.inverval_max))

                if is_lihua_end:
                    break

                src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
                left = 151
                top = 115
                w = 740
                h = 280
                opponent_img = src_img[top:top + h, left:left + w]

                lower = np.array([24, 160, 180], dtype="uint8")
                upper = np.array([67, 230, 255], dtype="uint8")
                mask = cv2.inRange(opponent_img, lower, upper)
                opponent_img = cv2.bitwise_and(opponent_img,
                                               opponent_img,
                                               mask=mask)
                opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

                points = get_match_points(opponent_img,
                                          lihua_img,
                                          threshold=0.6)
                if points:
                    is_move = True
                    px, py = points[0]
                    # px, py是相对于opponent_img的坐标,所以还要加上left和top
                    pos = (px + 151 + 10, py + 115 - 25)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)

                    # 最多等待5秒
                    for i in range(20):
                        time.sleep(random.uniform(0.2, 0.3))
                        src_img = window_capture(hwnd, x, y)
                        points = get_match_points(src_img,
                                                  lihua_choice_img,
                                                  threshold=0.98)
                        if points:
                            # 在一起了,需要选择
                            pos = points[0]
                            randint_x = random.randint(5, 90)
                            randint_y = random.randint(5, 20)
                            window_click(hwnd, pos, randint_x, randint_y)
                            continue
                        points = get_match_points(src_img,
                                                  lihua_end_img,
                                                  threshold=0.8)
                        if points:
                            is_lihua_end = True
                            print("礼花拾取完毕。")
                            break
                        points = get_match_points(src_img,
                                                  lihua_rest_img,
                                                  threshold=0.8)
                        if points:
                            print("CD中,继续点礼花。")
                            break

                    # 五秒未能拾取,卡住了,直接去吃饭
                    index = 5
                    break
                else:
                    break

            if is_move:
                # 回到餐桌旁边
                pos = (1997 - 1927, 178 - 156)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(1.0, 1.2))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_close_img)
                if not points:
                    # 未点开地图?,重新点开,重新截图
                    print("场景切换?未能点开地图,重新点开")
                    time.sleep(random.uniform(4.8, 5.2))
                    pos = (1997 - 1927, 178 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(1.0, 1.2))

                # 去待机位置
                randint_x = random.randint(0, 1)
                randint_y = random.randint(0, 1)
                window_click(hwnd, pos_wait, randint_x, randint_y)
                time.sleep(random.uniform(0.5, 0.6))

                # 关闭地图
                pos = (1997 - 1927, 178 - 156)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(1.0, 1.2))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_close_img)
                if points:
                    # 地图未能关闭?重新关闭。
                    print("场景切换?未能关闭地图,重新关闭。")
                    time.sleep(random.uniform(4.8, 5.2))
                    pos = (1997 - 1927, 178 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(1.0, 1.2))

                time.sleep(random.uniform(4.8, 5.2))

        if index >= 5:
            # 每五次循环,点一下桌子
            index = 0
            # 关闭其它窗口
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, xinxi_close_img, threshold=0.8)
            if points:
                pos = points[0]
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.8, 1.0))
            # 点桌子前,先关闭对话
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_close_img)
            if points:
                pos = points[0]
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.8, 1.0))
            """
            # 点桌子
            randint_x = random.randint(0, 1)
            randint_y = random.randint(0, 1)
            window_click(hwnd, pos_target, randint_x, randint_y)
            time.sleep(random.uniform(1.0, 1.2))
            """
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, yanhui_clock_img, threshold=0.8)
            if points:
                px, py = points[0]
                pos = (px + 33, py + 100)
                randint_x = random.randint(0, 2)
                randint_y = random.randint(0, 2)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(1.0, 1.2))
            else:
                print("未能发现倒计时。")
                # 不用处理,继续往下判断
                #waiting_num += 1
                #continue

            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img,
                                      zhuozi_choice_img,
                                      threshold=0.98)
            if points:
                # 在一起了,需要选择
                pos = points[0]
                randint_x = random.randint(5, 90)
                randint_y = random.randint(5, 20)
                window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.0, 1.2))

            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            points1 = get_match_points(src_img, button_pinchang_gray_img_color)
            points2 = get_match_points(src_img, button_pinchang_img_color)
            if points1:
                # 点下任务栏,取消吃菜窗口
                waiting_num = 0
                pos = (2863 - 1927, 303 - 193)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.8, 1.2))
                pos = (2863 - 1927, 303 - 193)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue
            elif points2:
                # 点吃菜
                waiting_num = 0
                pos = points2[0]
                randint_x = random.randint(10, 80)
                randint_y = random.randint(5, 15)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(5.0, 6.0))
                continue
            else:
                # 未知对话,关闭对话
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_close_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                waiting_num += 1
                continue
예제 #7
0
def baotu(hwnd, x, y, skill_order=None, eat_food=False):
    icon_baotu_img_color = cv2.cvtColor(cv2.imread("src/icon_baotu.png"),
                                        cv2.IMREAD_COLOR)
    duihua_datingcangbaotu_img = cv2.cvtColor(
        cv2.imread("src/duihua_datingcangbaotu.png"), cv2.COLOR_BGR2GRAY)
    baotu_duihua_img = cv2.cvtColor(cv2.imread("src/baotu_duihua.png"),
                                    cv2.COLOR_BGR2GRAY)
    baotu_finished_img = cv2.cvtColor(cv2.imread("src/baotu_finished.png"),
                                      cv2.COLOR_BGR2GRAY)

    lower = np.array([20, 150, 140], dtype="uint8")
    upper = np.array([80, 240, 255], dtype="uint8")

    renwu_baotu_img_color = cv2.cvtColor(cv2.imread("src/renwu_baotu.png"),
                                         cv2.IMREAD_COLOR)
    mask = cv2.inRange(renwu_baotu_img_color, lower, upper)
    renwu_baotu_img_color = cv2.bitwise_and(renwu_baotu_img_color,
                                            renwu_baotu_img_color,
                                            mask=mask)
    renwu_baotu_img = cv2.cvtColor(renwu_baotu_img_color, cv2.COLOR_BGR2GRAY)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    if eat_food:
        public.eat_food(hwnd, x, y, "baotu")

    # 切换挂机技能
    if skill_order is not None:
        public.change_skill(hwnd, x, y, skill_order)

    num_error = 0
    num_get = 0
    while True:
        if num_error >= 5:
            print("错误次数过多,退出")
            return

        time.sleep(random.uniform(settings.inverval_min,
                                  settings.inverval_max))

        src_img = window_capture(hwnd, x, y)

        # 对话,选“打听藏宝图”
        points = get_match_points(src_img, duihua_datingcangbaotu_img)
        if points:
            if num_get >= 1:
                # 关闭NPC对话框
                pos = (2856 - 1927, 233 - 193)
                randint_x = random.randint(0, 10)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                print("无法领取宝图任务,退出")
                return
            else:
                num_get += 1
                px, py = points[0]
                pos = (px + 50, py + 20)
                randint_x = random.randint(0, 80)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(3.8, 4.2))
                continue
        # 宝图对话,交任务
        points = get_match_points(src_img, baotu_duihua_img)
        if points:
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 对话,已完成任务
        points = get_match_points(src_img, baotu_finished_img)
        if points:
            # 关闭NPC对话框
            pos = (2856 - 1927, 233 - 193)
            randint_x = random.randint(0, 10)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            print("宝图任务已完成")
            return

        # 是否在移动中?
        status = public.get_status(hwnd, x, y, src_img)

        if status != "standing":
            continue

        public.show_menu_renwu(hwnd, x, y)

        # 优先查找任务栏显示
        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        left = 770
        top = 140
        w = 100
        h = 250
        opponent_img = src_img[top:top + h, left:left + w]
        mask = cv2.inRange(opponent_img, lower, upper)
        opponent_img = cv2.bitwise_and(opponent_img, opponent_img, mask=mask)
        opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

        #cv2.namedWindow("Image")
        #cv2.imshow("Image", opponent_img)
        #cv2.waitKey(0)
        #sys.exit(1)

        points = get_match_points(opponent_img, renwu_baotu_img, threshold=0.7)
        if points:
            # 点击任务栏任务
            px, py = points[0]
            # px, py是相对于opponent_img的坐标,所以还要加上left和top
            pos = (px + 770 + 70, py + 140 + 15)
            randint_x = random.randint(0, 20)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        result = public.open_window_richeng(hwnd, x, y)
        if not result:
            print("未能打开日程窗口")
            num_error += 1
            continue
        else:
            num_error = 0

        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        points = get_match_points(src_img,
                                  icon_baotu_img_color,
                                  threshold=0.95)
        if not points:
            # 等待字幕消失
            time.sleep(random.uniform(2.8, 3.2))
            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            points = get_match_points(src_img,
                                      icon_baotu_img_color,
                                      threshold=0.95)
            if not points:
                print("宝图任务已完成")
                public.close_window_richeng(hwnd, x, y)
                return

        pos = (2224 - 1927, 294 - 193)
        randint_x = random.randint(0, 40)
        randint_y = random.randint(0, 40)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(3.8, 4.2))
        continue
예제 #8
0
def tansuo(hwnd, x, y):
    button_tansuo_img = cv2.cvtColor(cv2.imread("src/gzlj/button_tansuo.png"), cv2.COLOR_BGR2GRAY)
    three_stars_img = cv2.cvtColor(cv2.imread("src/gzlj/three_stars.png"), cv2.COLOR_BGR2GRAY)
    button_shiyongliangzhang_img = cv2.cvtColor(cv2.imread("src/gzlj/button_shiyongliangzhang.png"), cv2.COLOR_BGR2GRAY)
    saodangquanqueren_img = cv2.cvtColor(cv2.imread("src/gzlj/saodangquanqueren.png"), cv2.COLOR_BGR2GRAY)
    button_jinrutansuoshouye_img_color = cv2.cvtColor(cv2.imread("src/gzlj/button_jinrutansuoshouye.png"), cv2.IMREAD_COLOR)

    # 点冒险
    pos = (2376 - 1927, 661 - 156)
    randint_x = random.randint(0, 50)
    randint_y = random.randint(0, 10)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(4.8, 5.2))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_tansuo_img)
    if points:
        pos = (2644 - 1927, 264 - 156)
        randint_x = random.randint(0, 50)
        randint_y = random.randint(0, 50)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(4.8, 5.2))
    else:
        print("未能找到探索按钮.")
        return

    for i in range(2):
        # 进入关卡
        pos = (2476 - 1927 + i * 220, 337 - 156)
        randint_x = random.randint(0, 80)
        randint_y = random.randint(0, 80)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(2.8, 3.2))

        # 找最上面的3星通关的关卡
        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, three_stars_img)
        if points:
            target_x, target_y = points.pop(0)
            for x, y in points:
                if y < target_y:
                    target_x = x
                    target_y = y
            target_pos = (target_x, target_y)
            randint_x = random.randint(0, 150)
            randint_y = random.randint(-30, 0)
            # 点击最上方三星
            window_click(hwnd, target_pos, randint_x, randint_y)
            time.sleep(random.uniform(2.4, 2.6))

            # 点+号
            pos = (2798 - 1927, 479 - 156)
            randint_x = random.randint(0, 15)
            randint_y = random.randint(0, 15)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.8, 2.2))

            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_shiyongliangzhang_img)
            if points:
                # 点使用2张
                pos = (2660 - 1927, 479 - 156)
                randint_x = random.randint(0, 30)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(2.4, 2.6))

                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, saodangquanqueren_img)
                if points:
                    # 点ok
                    pos = (2490 - 1927, 515 - 156)
                    randint_x = random.randint(0, 30)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(2.4, 2.6))

                    for i in range(10):
                        time.sleep(random.uniform(settings.inverval_min, settings.inverval_max))

                        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
                        points = get_match_points(src_img, button_jinrutansuoshouye_img_color, threshold=0.9)
                        if points:
                            pos = (2381 - 1927, 623 - 156)
                            randint_x = random.randint(0, 30)
                            randint_y = random.randint(0, 10)
                            window_click(hwnd, pos, randint_x, randint_y)
                            time.sleep(random.uniform(2.8, 3.2))
                            break
            else:
                # 扫荡券不够,或已完成
                # 点取消
                pos = (2565 - 1927, 602 - 156)
                randint_x = random.randint(0, 30)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(2.4, 2.6))
                # 点返回
                pos = (1950 - 1927, 177 - 156)
                randint_x = random.randint(0, 10)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(2.8, 3.2))
예제 #9
0
def fengyao(hwnd, x, y, is_leader, skill_order=None, eat_food=False):
    if is_leader:
        yuangu_img_color = cv2.cvtColor(cv2.imread("src/yuangu.png"),
                                        cv2.IMREAD_COLOR)
        lower = np.array([24, 160, 180], dtype="uint8")
        upper = np.array([67, 230, 255], dtype="uint8")
        mask = cv2.inRange(yuangu_img_color, lower, upper)
        yuangu_img_color = cv2.bitwise_and(yuangu_img_color,
                                           yuangu_img_color,
                                           mask=mask)
        yuangu_img = cv2.cvtColor(yuangu_img_color, cv2.COLOR_BGR2GRAY)

        duihua_fengyao_img = cv2.cvtColor(cv2.imread("src/duihua_fengyao.png"),
                                          cv2.COLOR_BGR2GRAY)
        duiwu_yincang_img = cv2.cvtColor(cv2.imread("src/duiwu_yincang.png"),
                                         cv2.COLOR_BGR2GRAY)
        fengyao_end_img = cv2.cvtColor(cv2.imread("src/fengyao_end.png"),
                                       cv2.COLOR_BGR2GRAY)
        yuangu_choice_img = cv2.cvtColor(cv2.imread("src/yuangu_choice.png"),
                                         cv2.COLOR_BGR2GRAY)
        button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                        cv2.COLOR_BGR2GRAY)
        fengyao_bielaidarao_img = cv2.cvtColor(
            cv2.imread("src/fengyao_bielaidarao.png"), cv2.COLOR_BGR2GRAY)

        # 若锁屏,则解锁
        public.jiesuo(hwnd, x, y)

        if eat_food:
            public.eat_food(hwnd, x, y, "fengyao")

        # 切换挂机技能
        if skill_order is not None:
            public.change_skill(hwnd, x, y, skill_order)
        else:
            time.sleep(2.0)

        src_img = window_capture(hwnd, x, y)

        # 隐藏任务列表
        points = get_match_points(src_img, duiwu_yincang_img)
        if points:
            pos = points[0]
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.6, 0.8))

        # 去倒数第二个地图
        result = public.goto_yewai(hwnd, x, y, qumo=True)
        if not result:
            print("前往野外失败,退出")
            return

        has_battle = False
        num_standing = 0
        while True:
            time.sleep(
                random.uniform(settings.inverval_min, settings.inverval_max))

            src_img = window_capture(hwnd, x, y)

            status = public.get_status(hwnd,
                                       x,
                                       y,
                                       src_img,
                                       with_standing=False,
                                       npc_jiaohu=False)

            if status == "yanzheng_failed":
                senddata("窗口:{}验证失败,退出。".format(hwnd), "")
                return

            if status == "in_battle":
                continue

            # 隐藏任务列表
            points = get_match_points(src_img, duiwu_yincang_img)
            if points:
                pos = points[0]
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            if has_battle:
                points = get_match_points(src_img,
                                          fengyao_end_img,
                                          threshold=0.8)
                if points:
                    # 你今天已经很累了
                    print("封妖任务结束,退出")
                    return

            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            # 注意点怪的时候,Y最多向上移25-30个像素,不然会点开人物界面

            left = 151
            top = 115
            w = 740
            h = 280
            opponent_img = src_img[top:top + h, left:left + w]

            #cv2.namedWindow("Image")
            #cv2.imshow("Image", opponent_img)
            #cv2.waitKey(0)
            #sys.exit(1)

            lower = np.array([24, 160, 180], dtype="uint8")
            upper = np.array([67, 230, 255], dtype="uint8")
            mask = cv2.inRange(opponent_img, lower, upper)
            opponent_img = cv2.bitwise_and(opponent_img,
                                           opponent_img,
                                           mask=mask)
            opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

            points = get_match_points(opponent_img, yuangu_img, threshold=0.5)
            if points:
                # 计数重置
                num = 0
                px, py = points[0]
                # px, py是相对于opponent_img的坐标,所以还要加上left和top
                pos = (px + 151 + 35, py + 115 - 25)
                randint_x = random.randint(0, 2)
                randint_y = random.randint(0, 2)
                window_click(hwnd, pos, randint_x, randint_y)

                has_battle = True

                # 最多等待2.5秒
                for i in range(10):
                    time.sleep(random.uniform(0.2, 0.3))
                    src_img = window_capture(hwnd, x, y)
                    points = get_match_points(src_img,
                                              yuangu_choice_img,
                                              threshold=0.98)
                    if points:
                        # 怪站一起了,需要选择
                        pos = points[0]
                        randint_x = random.randint(5, 90)
                        randint_y = random.randint(5, 20)
                        window_click(hwnd, pos, randint_x, randint_y)
                        continue
                    points = get_match_points(src_img, duihua_fengyao_img)
                    if points:
                        # 开打
                        pos = (2604 - 1927, 522 - 193)
                        randint_x = random.randint(0, 80)
                        randint_y = random.randint(0, 20)
                        window_click(hwnd, pos, randint_x, randint_y)
                        break

                for i in range(4):
                    time.sleep(random.uniform(0.2, 0.3))
                    src_img = window_capture(hwnd, x, y)
                    points = get_match_points(src_img, fengyao_bielaidarao_img)
                    if points:
                        pos = (2856 - 1927, 233 - 193)
                        randint_x = random.randint(0, 10)
                        randint_y = random.randint(0, 10)
                        window_click(hwnd, pos, randint_x, randint_y)
                        print("进入战斗失败")
                        has_battle = False
                        break
            else:
                has_battle = False
                # 是否在移动中?
                src_img = window_capture(hwnd, x, y)
                status = public.get_status(hwnd,
                                           x,
                                           y,
                                           src_img,
                                           npc_jiaohu=False)

                if status == "yanzheng_failed":
                    senddata("窗口:{}验证失败,退出。".format(hwnd), "")
                    return

                if status != "standing":
                    num_standing = 0
                    continue
                else:
                    num_standing += 1
                    if num_standing <= 1:
                        continue

                # 开始巡逻
                result = public.xunluo(hwnd, x, y)
                if not result:
                    print("巡逻失败,退出")
                    return
    else:
        # 若锁屏,则解锁
        public.jiesuo(hwnd, x, y)

        if eat_food:
            public.eat_food(hwnd, x, y, "fengyao")

        # 切换挂机技能
        if skill_order is not None:
            public.change_skill(hwnd, x, y, skill_order)

        wait_num = 0
        num = 0
        while True:
            time.sleep(
                random.uniform(settings.inverval_min * 5,
                               settings.inverval_max * 5))
            num += 1
            # 是否在移动中?
            status = public.get_status(hwnd, x, y, npc_jiaohu=False)
            if status == "standing":
                wait_num += 1
            else:
                wait_num = 0

            if wait_num >= 15:
                print("挂机时间过长,退出")
                return

            if num >= 60:
                # 点下任务栏,避免锁屏
                pos = (2863 - 1927, 303 - 193)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                num = 0
예제 #10
0
파일: zudui.py 프로젝트: ulimit65535/sw4
def leave(hwnd, x, y, is_leader):
    #duiwu_zhankai_img = cv2.cvtColor(cv2.imread("src/duiwu_zhankai.png"), cv2.COLOR_BGR2GRAY)
    button_renwu_img = cv2.cvtColor(cv2.imread("src/button_renwu.png"),
                                    cv2.COLOR_BGR2GRAY)
    chuangjianduiwu_img = cv2.cvtColor(cv2.imread("src/chuangjianduiwu.png"),
                                       cv2.COLOR_BGR2GRAY)
    button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                    cv2.COLOR_BGR2GRAY)
    xinxi_close_img = cv2.cvtColor(cv2.imread("src/xinxi_close.png"),
                                   cv2.COLOR_BGR2GRAY)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    src_img = window_capture(hwnd, x, y)

    points = get_match_points(src_img, button_close_img)
    if points:
        # 误点到战备,或者NPC对话,关闭
        pos = points[0]
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.5, 0.6))
        src_img = window_capture(hwnd, x, y)

    points = get_match_points(src_img, button_renwu_img, threshold=0.8)
    if not points:
        # 展开任务列表
        pos = (2863 - 1927, 303 - 193)
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.6, 0.8))

    # 打开队伍界面
    pos = (2800 - 1927, 265 - 156)
    randint_x = random.randint(0, 20)
    randint_y = random.randint(0, 10)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(0.8, 1.0))

    src_img = window_capture(hwnd, x, y)

    if is_leader:
        # 如果已在队伍中,离开队伍
        points = get_match_points(src_img, chuangjianduiwu_img)
        if not points:
            # 让队友先离队
            time.sleep(random.uniform(2.8, 3.2))
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, chuangjianduiwu_img)
            if not points:
                # 如果未能离开,则离开队伍
                pos = (2091 - 1927, 217 - 156)
                randint_x = random.randint(25, 60)
                randint_y = random.randint(5, 15)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.8, 1.0))
            # 关闭队伍窗口
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, xinxi_close_img, threshold=0.8)
            if points:
                pos = points[0]
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.5, 0.6))
                pos = (2725 - 1927, 270 - 156)
                randint_x = random.randint(0, 10)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
        return
    else:
        # 找不到创建队伍按键,直接点离开队伍,避免喇叭干扰
        points = get_match_points(src_img, chuangjianduiwu_img)
        if not points:
            pos = (2091 - 1927, 217 - 156)
            randint_x = random.randint(25, 60)
            randint_y = random.randint(5, 15)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.8, 1.0))
            # 关闭队伍窗口
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, xinxi_close_img, threshold=0.8)
            if points:
                pos = points[0]
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.5, 0.6))
                pos = (2725 - 1927, 270 - 156)
                randint_x = random.randint(0, 10)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
        return
예제 #11
0
def wabao(hwnd, x, y):
    icon_wupin_img = cv2.cvtColor(cv2.imread("src/icon_wupin.png"),
                                  cv2.COLOR_BGR2GRAY)
    baotu_img = cv2.cvtColor(cv2.imread("src/baotu.png"), cv2.COLOR_BGR2GRAY)
    #button_shiyong_img = cv2.cvtColor(cv2.imread("src/button_shiyong.png"), cv2.COLOR_BGR2GRAY)
    button_luopan_img = cv2.cvtColor(cv2.imread("src/button_luopan.png"),
                                     cv2.COLOR_BGR2GRAY)
    baotu_shiyong_img = cv2.cvtColor(cv2.imread("src/baotu_shiyong.png"),
                                     cv2.COLOR_BGR2GRAY)
    #wuping_close_img = cv2.cvtColor(cv2.imread("src/wuping_close.png"), cv2.COLOR_BGR2GRAY)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    src_img = window_capture(hwnd, x, y)

    points = get_match_points(src_img, icon_wupin_img)
    if points:
        pos = points[0]
        randint_x = random.randint(5, 15)
        randint_y = random.randint(5, 15)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.8, 1.2))
    else:
        print("未能打开背包,退出.")
        return

    has_baotu = False
    for i in range(3):
        # 切换物品栏
        pos = (2445 - 1927 + i * 65, 217 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(1.4, 1.6))
        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, baotu_img)
        if points:
            has_baotu = True
            pos = points[0]
            randint_x = random.randint(10, 15)
            randint_y = random.randint(20, 25)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.8, 1.2))

            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_luopan_img)
            if points:
                pos = points[0]
                randint_x = random.randint(5 + 143, 80 + 143)
                randint_y = random.randint(5, 20)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.8, 1.2))

                # 关闭背包
                #src_img = window_capture(hwnd, x, y)
                #points = get_match_points(src_img, wuping_close_img)
                #if points:
                pos = (2766 - 1927, 180 - 156)
                randint_x = random.randint(5, 15)
                randint_y = random.randint(5, 15)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.6, 0.8))

                break
            else:
                print("使用宝图失败,退出")
                return

    if not has_baotu:
        pos = (2766 - 1927, 180 - 156)
        randint_x = random.randint(5, 15)
        randint_y = random.randint(5, 15)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.6, 0.8))
        print("背包中未发现宝图,退出")
        return

    wait_num = 0
    while True:
        if wait_num >= 60:
            # 再次查看背包
            wait_num = 0

            src_img = window_capture(hwnd, x, y)

            points = get_match_points(src_img, icon_wupin_img)
            if points:
                pos = points[0]
                randint_x = random.randint(5, 15)
                randint_y = random.randint(5, 15)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.8, 1.2))
            else:
                print("未能打开背包,退出.")
                return

            has_baotu = False
            for i in range(3):
                # 切换物品栏
                pos = (2445 - 1927 + i * 65, 217 - 156)
                randint_x = random.randint(0, 30)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(1.4, 1.6))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, baotu_img)
                if points:
                    has_baotu = True
                    pos = points[0]
                    randint_x = random.randint(10, 15)
                    randint_y = random.randint(20, 25)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.8, 1.2))

                    src_img = window_capture(hwnd, x, y)
                    points = get_match_points(src_img, button_luopan_img)
                    if points:
                        pos = points[0]
                        randint_x = random.randint(5 + 143, 80 + 143)
                        randint_y = random.randint(5, 20)
                        window_click(hwnd, pos, randint_x, randint_y)
                        time.sleep(random.uniform(0.8, 1.2))

                        # 关闭背包
                        pos = (2766 - 1927, 180 - 156)
                        randint_x = random.randint(5, 15)
                        randint_y = random.randint(5, 15)
                        window_click(hwnd, pos, randint_x, randint_y)
                        time.sleep(random.uniform(0.6, 0.8))

                        break
                    else:
                        print("使用宝图失败,退出")
                        return

            if not has_baotu:
                pos = (2766 - 1927, 180 - 156)
                randint_x = random.randint(5, 15)
                randint_y = random.randint(5, 15)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.6, 0.8))
                print("背包中未发现宝图,挖宝结束")
                return

        time.sleep(random.uniform(settings.inverval_min,
                                  settings.inverval_max))

        src_img = window_capture(hwnd, x, y)

        # 点使用
        points = get_match_points(src_img, baotu_shiyong_img)
        if points:
            wait_num = 0
            pos = points[0]
            randint_x = random.randint(10, 50)
            randint_y = random.randint(5, 15)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.4, 1.6))
            continue
        else:
            wait_num += 1
            continue
예제 #12
0
def menpai(hwnd, x, y, is_leader, skill_order=None):
    while True:
        hour = time.localtime().tm_hour
        if hour != 21 and hour != 22:
            # 等待10分钟
            print("还未到21点或22点,等待10分钟。")
            time.sleep(600)
            continue
        else:
            break
    if hour == 21:
        while True:
            minute = time.localtime().tm_min
            if minute <= 40:
                print("还未开始,等待10秒。")
                time.sleep(10)
                continue
            else:
                break

    if is_leader:
        menpaichuangguan_img_color = cv2.cvtColor(
            cv2.imread("src/menpaichuangguan.png"), cv2.IMREAD_COLOR)
        duihua_canjiachuangguan_img = cv2.cvtColor(
            cv2.imread("src/duihua_canjiachuangguan.png"), cv2.COLOR_BGR2GRAY)
        duihua_songwoguoqu_img = cv2.cvtColor(
            cv2.imread("src/duihua_songwoguoqu.png"), cv2.COLOR_BGR2GRAY)
        duihua_tiaozhanyixing_img = cv2.cvtColor(
            cv2.imread("src/duihua_tiaozhanyixing.png"), cv2.COLOR_BGR2GRAY)

        lower = np.array([20, 150, 140], dtype="uint8")
        upper = np.array([80, 240, 255], dtype="uint8")

        renwu_menpaichuangguan_img_color = cv2.cvtColor(
            cv2.imread("src/renwu_menpaichuangguan.png"), cv2.IMREAD_COLOR)
        mask = cv2.inRange(renwu_menpaichuangguan_img_color, lower, upper)
        renwu_menpaichuangguan_img_color = cv2.bitwise_and(
            renwu_menpaichuangguan_img_color,
            renwu_menpaichuangguan_img_color,
            mask=mask)
        renwu_menpaichuangguan_img = cv2.cvtColor(
            renwu_menpaichuangguan_img_color, cv2.COLOR_BGR2GRAY)

        #cv2.namedWindow("Image")
        #cv2.imshow("Image", renwu_huoban_img)
        #cv2.waitKey(0)
        #sys.exit(1)

        # 若锁屏,则解锁
        public.jiesuo(hwnd, x, y)

        # 切换挂机技能
        if skill_order is not None:
            public.change_skill(hwnd, x, y, skill_order)
        else:
            time.sleep(2.0)

        num_error = 0
        while True:
            if num_error >= 5:
                print("错误次数过多,退出")
                return

            time.sleep(
                random.uniform(settings.inverval_min * 3,
                               settings.inverval_max * 3))

            src_img = window_capture(hwnd, x, y)

            # 对话,参加闯关
            points = get_match_points(src_img, duihua_canjiachuangguan_img)
            if points:
                px, py = points[0]
                pos = (px + 50, py + 20)
                randint_x = random.randint(0, 80)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            # 对话,送我过去
            points = get_match_points(src_img, duihua_songwoguoqu_img)
            if points:
                px, py = points[0]
                pos = (px + 50, py + 20)
                randint_x = random.randint(0, 80)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            # 对话,挑战一星
            points = get_match_points(src_img, duihua_tiaozhanyixing_img)
            if points:
                px, py = points[0]
                pos = (px + 50, py + 20)
                randint_x = random.randint(0, 80)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            # 是否在移动中?
            src_img = window_capture(hwnd, x, y)
            status = public.get_status(hwnd,
                                       x,
                                       y,
                                       src_img,
                                       npc_jiaohu=False,
                                       call_pet=True)

            if status != "standing":
                continue

            public.show_menu_renwu(hwnd, x, y)

            # 优先查找任务栏显示
            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            # 注意点怪的时候,Y最多向上移25-30个像素,不然会点开人物界面
            left = 770
            top = 140
            w = 100
            h = 250
            opponent_img = src_img[top:top + h, left:left + w]
            mask = cv2.inRange(opponent_img, lower, upper)
            opponent_img = cv2.bitwise_and(opponent_img,
                                           opponent_img,
                                           mask=mask)
            opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

            points = get_match_points(opponent_img,
                                      renwu_menpaichuangguan_img,
                                      threshold=0.7)
            if points:
                # 点击任务栏任务
                px, py = points[0]
                # px, py是相对于opponent_img的坐标,所以还要加上left和top
                pos = (px + 770 + 70, py + 140 + 15)
                randint_x = random.randint(0, 20)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            result = public.open_window_richeng(hwnd, x, y)
            if not result:
                print("未能打开日程窗口")
                num_error += 1
                continue
            else:
                num_error = 0

            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            points = get_match_points(src_img,
                                      menpaichuangguan_img_color,
                                      threshold=0.9)
            if not points:
                # 等待字幕消失
                time.sleep(random.uniform(2.8, 3.2))
                src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
                points = get_match_points(src_img,
                                          menpaichuangguan_img_color,
                                          threshold=0.9)
                if not points:
                    print("门派闯关已完成")
                    public.close_window_richeng(hwnd, x, y)
                    return

            # 点前往参加
            pos = points[0]
            randint_x = random.randint(15, 30)
            randint_y = random.randint(68, 78)
            window_click(hwnd, pos, randint_x, randint_y)
            continue
    else:
        button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                        cv2.COLOR_BGR2GRAY)

        # 若锁屏,则解锁
        public.jiesuo(hwnd, x, y)

        # 切换挂机技能
        if skill_order is not None:
            public.change_skill(hwnd, x, y, skill_order)

        wait_num = 0
        num = 0
        while True:
            time.sleep(
                random.uniform(settings.inverval_min, settings.inverval_max))
            num += 1

            src_img = window_capture(hwnd, x, y)

            points = get_match_points(src_img, button_close_img)
            if points:
                # 误点到战备,或者NPC对话,关闭
                pos = points[0]
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            # 是否在移动中?
            status = public.get_status(hwnd,
                                       x,
                                       y,
                                       npc_jiaohu=False,
                                       call_pet=True)
            if status == "standing":
                wait_num += 1
            else:
                wait_num = 0

            if wait_num >= 10:
                print("挂机时间过长,退出")
                return

            if num >= 300:
                # 点下任务栏,避免锁屏
                pos = (2863 - 1927, 303 - 193)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                num = 0
예제 #13
0
def huoban(hwnd, x, y, skill_order=None):
    huobanrenwu_img_color = cv2.cvtColor(cv2.imread("src/huobanrenwu.png"),
                                         cv2.IMREAD_COLOR)
    duihua_lingquhuobanrenwu_img = cv2.cvtColor(
        cv2.imread("src/duihua_lingquhuobanrenwu.png"), cv2.COLOR_BGR2GRAY)
    lingqurenwu_gold_img_color = cv2.cvtColor(
        cv2.imread("src/lingqurenwu_gold.png"), cv2.IMREAD_COLOR)
    lingqurenwu_blue_img_color = cv2.cvtColor(
        cv2.imread("src/lingqurenwu_blue.png"), cv2.IMREAD_COLOR)
    duihua_jinxingrenwu_img = cv2.cvtColor(
        cv2.imread("src/duihua_jinxingrenwu.png"), cv2.COLOR_BGR2GRAY)
    duihua_jiyuchongwu_img = cv2.cvtColor(
        cv2.imread("src/duihua_jiyuchongwu.png"), cv2.COLOR_BGR2GRAY)
    duihua_jinruzhandou_img = cv2.cvtColor(
        cv2.imread("src/duihua_jinruzhandou.png"), cv2.COLOR_BGR2GRAY)
    jinruzhandou_img = cv2.cvtColor(cv2.imread("src/jinruzhandou.png"),
                                    cv2.COLOR_BGR2GRAY)
    duihua_img = cv2.cvtColor(cv2.imread("src/duihua.png"), cv2.COLOR_BGR2GRAY)
    duihua_huoban_img = cv2.cvtColor(cv2.imread("src/duihua_huoban.png"),
                                     cv2.COLOR_BGR2GRAY)
    duihua_any_img = cv2.cvtColor(cv2.imread("src/duihua_any.png"),
                                  cv2.COLOR_BGR2GRAY)

    lower = np.array([20, 150, 140], dtype="uint8")
    upper = np.array([80, 240, 255], dtype="uint8")

    renwu_huoban_img_color = cv2.cvtColor(cv2.imread("src/renwu_huoban.png"),
                                          cv2.IMREAD_COLOR)
    mask = cv2.inRange(renwu_huoban_img_color, lower, upper)
    renwu_huoban_img_color = cv2.bitwise_and(renwu_huoban_img_color,
                                             renwu_huoban_img_color,
                                             mask=mask)
    renwu_huoban_img = cv2.cvtColor(renwu_huoban_img_color, cv2.COLOR_BGR2GRAY)

    #cv2.namedWindow("Image")
    #cv2.imshow("Image", renwu_huoban_img)
    #cv2.waitKey(0)
    #sys.exit(1)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    # 切换挂机技能
    if skill_order is not None:
        public.change_skill(hwnd, x, y, skill_order)

    num_error = 0
    duihua_any_num = 0
    while True:
        if num_error >= 5:
            print("错误次数过多,退出")
            return
        if duihua_any_num >= 10:
            print("未知对话过多,退出")
            return

        time.sleep(random.uniform(settings.inverval_min,
                                  settings.inverval_max))

        src_img = window_capture(hwnd, x, y)

        # 对话,选“领取伙伴任务”
        points = get_match_points(src_img, duihua_lingquhuobanrenwu_img)
        if points:
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 对话,选进行任务
        points = get_match_points(src_img, duihua_jinxingrenwu_img)
        if points:
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 对话,给予宠物
        points = get_match_points(src_img, duihua_jiyuchongwu_img)
        if points:
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 对话,进入战斗
        points = get_match_points(src_img, duihua_jinruzhandou_img)
        if points:
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 对话,伙伴-
        points = get_match_points(src_img, duihua_huoban_img)
        if points:
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 未知对话,选第一个
        points = get_match_points(src_img, duihua_any_img)
        if points:
            duihua_any_num += 1
            min_y = 1000
            for point in points:
                x, y = point
                if y < min_y:
                    pos_duihua = point
                    min_y = y

            px, py = pos_duihua
            pos = (px - 80, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 点击对话
        points = get_match_points(src_img, duihua_img, threshold=0.95)
        if points:
            pos = (812, 154)
            randint_x = random.randint(0, 100)
            randint_y = random.randint(0, 30)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 小BOSS。进入战斗
        points = get_match_points(src_img, jinruzhandou_img, threshold=0.8)
        if points:
            pos = points[0]
            randint_x = random.randint(5, 105)
            randint_y = random.randint(5, 15)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        # 优先领取金色任务
        points = get_match_points(src_img,
                                  lingqurenwu_gold_img_color,
                                  threshold=0.95)
        if points:
            duihua_any_num = 0
            pos = points[0]
            randint_x = random.randint(10, 80)
            randint_y = random.randint(5, 20)
            window_click(hwnd, pos, randint_x, randint_y)
            continue
        # 其次领取蓝色任务
        points = get_match_points(src_img,
                                  lingqurenwu_blue_img_color,
                                  threshold=0.95)
        if points:
            duihua_any_num = 0
            pos = points[0]
            randint_x = random.randint(10, 80)
            randint_y = random.randint(5, 20)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 是否在移动中?
        status = public.get_status(hwnd, x, y)

        if status != "standing":
            continue

        public.show_menu_renwu(hwnd, x, y)

        # 优先查找任务栏显示
        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        # 注意点怪的时候,Y最多向上移25-30个像素,不然会点开人物界面
        left = 770
        top = 140
        w = 100
        h = 250
        opponent_img = src_img[top:top + h, left:left + w]
        mask = cv2.inRange(opponent_img, lower, upper)
        opponent_img = cv2.bitwise_and(opponent_img, opponent_img, mask=mask)
        opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

        points = get_match_points(opponent_img,
                                  renwu_huoban_img,
                                  threshold=0.7)
        if points:
            # 点击任务栏任务
            px, py = points[0]
            # px, py是相对于opponent_img的坐标,所以还要加上left和top
            pos = (px + 770 + 70, py + 140 + 15)
            randint_x = random.randint(0, 20)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        result = public.open_window_richeng(hwnd, x, y)
        if not result:
            print("未能打开日程窗口")
            num_error += 1
            continue
        else:
            num_error = 0

        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        points = get_match_points(src_img,
                                  huobanrenwu_img_color,
                                  threshold=0.95)
        if not points:
            # 等待字幕消失
            time.sleep(random.uniform(2.8, 3.2))
            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            points = get_match_points(src_img,
                                      huobanrenwu_img_color,
                                      threshold=0.95)
            if not points:
                print("伙伴任务已完成")
                public.close_window_richeng(hwnd, x, y)
                return

        # 点前往参加
        pos = points[0]
        randint_x = random.randint(15, 30)
        randint_y = random.randint(68, 78)
        window_click(hwnd, pos, randint_x, randint_y)
        continue
예제 #14
0
def yanhui1(hwnd, x, y):
    yanhui_pighead_img_color = cv2.cvtColor(
        cv2.imread("src/yanhui_pighead.png"), cv2.IMREAD_COLOR)
    yanhui_tao_img_color = cv2.cvtColor(cv2.imread("src/yanhui_tao.png"),
                                        cv2.IMREAD_COLOR)
    button_pinchang_img_color = cv2.cvtColor(
        cv2.imread("src/button_pinchang.png"), cv2.IMREAD_COLOR)
    button_pinchang_gray_img_color = cv2.cvtColor(
        cv2.imread("src/button_pinchang_gray.png"), cv2.IMREAD_COLOR)
    button_close_img_color = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                          cv2.IMREAD_COLOR)
    biaoqing_chaoren_img_color = cv2.cvtColor(
        cv2.imread("src/biaoqing_chaoren.png"), cv2.IMREAD_COLOR)
    #icon_huanqingshenwu_img_color = cv2.cvtColor(cv2.imread("src/icon_huanqingshenwu.png"), cv2.IMREAD_COLOR)

    already_eaten = False
    #already_huanqing = False
    while True:
        time.sleep(
            random.uniform(settings.inverval_min * 3,
                           settings.inverval_max * 3))

        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        """
        left = 0
        top = 0
        w = 970
        h = 400
        opponent_img = src_img[top:top + h, left:left + w]
        points = get_match_points(opponent_img, biaoqing_chaoren_img_color, threshold=0.8)
        if points:
            if not already_huanqing:
                px, py = points[0]
                pos = (px + 87, py)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                already_huanqing = True
                continue
        else:
            already_huanqing = False
        """

        points = get_match_points(src_img, button_close_img_color)
        if points:
            # 还未开始
            pos = points[0]
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(10.0, 12.0))
            continue

        points = get_match_points(src_img, button_pinchang_gray_img_color)
        if points:
            already_eaten = True
            # 点下任务栏,取消吃菜窗口
            pos = (2863 - 1927, 303 - 193)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.8, 1.2))
            pos = (2863 - 1927, 303 - 193)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        points = get_match_points(src_img, button_pinchang_img_color)
        if points:
            already_eaten = True
            # 点吃菜
            pos = points[0]
            randint_x = random.randint(10, 80)
            randint_y = random.randint(5, 15)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(5.0, 6.0))
            continue

        points = get_match_points(src_img, yanhui_pighead_img_color)
        if not points:
            points = get_match_points(src_img, yanhui_tao_img_color)
        if points:
            # 新菜上桌
            if already_eaten:
                continue
            else:
                # 没吃过这道菜,开吃
                pos = points[0]
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue
        else:
            already_eaten = False
            continue
예제 #15
0
def battle_loop(hwnd, x, y):
    #button_normal_img = cv2.cvtColor(cv2.imread("src/gzlj/button_normal.png"), cv2.COLOR_BGR2GRAY)
    button_tiaozhan_img = cv2.cvtColor(cv2.imread("src/gzlj/button_tiaozhan.png"), cv2.COLOR_BGR2GRAY)
    button_zhandoukaishi_img = cv2.cvtColor(cv2.imread("src/gzlj/button_zhandoukaishi.png"), cv2.COLOR_BGR2GRAY)
    button_xiayibu_img = cv2.cvtColor(cv2.imread("src/gzlj/button_xiayibu.png"), cv2.COLOR_BGR2GRAY)
    #button_xiayibu_small_img = cv2.cvtColor(cv2.imread("src/gzlj/button_xiayibu_small.png"), cv2.COLOR_BGR2GRAY)
    #button_quxiao_img = cv2.cvtColor(cv2.imread("src/gzlj/button_quxiao.png"), cv2.COLOR_BGR2GRAY)
    button_skip_img = cv2.cvtColor(cv2.imread("src/gzlj/button_skip.png"), cv2.COLOR_BGR2GRAY)
    #user_img = cv2.cvtColor(cv2.imread("src/gzlj/user.png"), cv2.COLOR_BGR2GRAY)
    level_up_img = cv2.cvtColor(cv2.imread("src/gzlj/level_up.png"), cv2.COLOR_BGR2GRAY)
    no_tili_img = cv2.cvtColor(cv2.imread("src/gzlj/no_tili.png"), cv2.COLOR_BGR2GRAY)
    button_caidan_img = cv2.cvtColor(cv2.imread("src/gzlj/button_caidan.png"), cv2.COLOR_BGR2GRAY)
    button_zaicitiaozhan_img = cv2.cvtColor(cv2.imread("src/gzlj/button_zaicitiaozhan.png"), cv2.COLOR_BGR2GRAY)
    guanqiachongshi_img = cv2.cvtColor(cv2.imread("src/gzlj/guanqiachongshi.png"), cv2.COLOR_BGR2GRAY)
    xiandingchuxian_img = cv2.cvtColor(cv2.imread("src/gzlj/xiandingchuxian.png"), cv2.COLOR_BGR2GRAY)

    waiting_num = 0
    while True:
        time.sleep(random.uniform(settings.inverval_min * 2, settings.inverval_max * 2))

        src_img = window_capture(hwnd, x, y)

        points = get_match_points(src_img, button_caidan_img)
        if points:
            # 战斗中
            print("战斗中...")
            waiting_num = 0
            continue

        if waiting_num >= 10:
            print("等待时间过长,退出。")
            return

        # 结束
        points = get_match_points(src_img, no_tili_img, threshold=0.8)
        if points:
            print("体力不足,退出。")
            return

        # 升级了,点ok
        points = get_match_points(src_img, level_up_img,threshold=0.95)
        if points:
            # 这里用窗口4抓的坐标
            pos = (3330 - 2881, 1066 - 705)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 跳过
        points = get_match_points(src_img, button_skip_img)
        if points:
            pos = points[0]
            randint_x = random.randint(5, 15)
            randint_y = random.randint(5, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        """
        # 点关卡
        points = get_match_points(src_img, user_img, threshold=0.7)
        if points:
            pos = points[0]
            randint_x = random.randint(5, 10)
            randint_y = random.randint(55, 60)
            window_click(hwnd, pos, randint_x, randint_y)
            continue
        """

        # 挑战
        points = get_match_points(src_img, button_tiaozhan_img)
        if points:
            pos = (2729 - 1927, 602 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(2)
            continue

        # 战斗开始
        points = get_match_points(src_img, button_zhandoukaishi_img)
        if points:
            pos = (2736 - 1927, 602 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 下一步
        points = get_match_points(src_img, button_xiayibu_img)
        if points:
            pos = (2731 - 1927, 641 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 再次挑战
        points = get_match_points(src_img, button_zaicitiaozhan_img)
        if points:
            pos = (2551 - 1927, 639 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 关卡重试,点OK
        points = get_match_points(src_img, guanqiachongshi_img)
        if points:
            pos = (2476 - 1927, 516 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 限定出现,取消
        points = get_match_points(src_img, xiandingchuxian_img)
        if points:
            pos = (2264 - 1927, 518 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        """
        # 下一步
        points = get_match_points(src_img, button_xiayibu_small_img)
        if points:
            pos = (2731 - 1927, 641 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 取消
        points = get_match_points(src_img, button_quxiao_img)
        if points:
            pos = (2264 - 1927, 516 - 156)
            randint_x = random.randint(0, 50)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue
        """

        waiting_num += 1
예제 #16
0
def zhuzhan(hwnd, x, y):
    button_dixiacheng_img = cv2.cvtColor(cv2.imread("src/gzlj/button_dixiacheng.png"), cv2.COLOR_BGR2GRAY)
    mubaoxiang_img = cv2.cvtColor(cv2.imread("src/gzlj/mubaoxiang.png"), cv2.COLOR_BGR2GRAY)
    jinbaoxiang_img = cv2.cvtColor(cv2.imread("src/gzlj/jinbaoxiang.png"), cv2.COLOR_BGR2GRAY)
    xianzaidecengsu_img = cv2.cvtColor(cv2.imread("src/gzlj/xianzaidecengsu.png"), cv2.COLOR_BGR2GRAY)
    button_caidan_img = cv2.cvtColor(cv2.imread("src/gzlj/button_caidan.png"), cv2.COLOR_BGR2GRAY)
    duiwubianzu_img = cv2.cvtColor(cv2.imread("src/gzlj/duiwubianzu.png"), cv2.COLOR_BGR2GRAY)
    zhuzhan_choice_img = cv2.cvtColor(cv2.imread("src/gzlj/replace/zhuzhan_choice.png"), cv2.COLOR_BGR2GRAY)
    button_tiaozhan_img = cv2.cvtColor(cv2.imread("src/gzlj/button_tiaozhan.png"), cv2.COLOR_BGR2GRAY)
    button_zhandoukaishi_img_color = cv2.cvtColor(cv2.imread("src/gzlj/button_zhandoukaishi.png"), cv2.IMREAD_COLOR)
    button_xiayibu_img = cv2.cvtColor(cv2.imread("src/gzlj/button_xiayibu.png"), cv2.COLOR_BGR2GRAY)
    shouqubaochou_img = cv2.cvtColor(cv2.imread("src/gzlj/shouqubaochou.png"), cv2.COLOR_BGR2GRAY)
    button_qianwangdixiacheng_img = cv2.cvtColor(cv2.imread("src/gzlj/button_qianwangdixiacheng.png"), cv2.COLOR_BGR2GRAY)
    chetuiqueren_img = cv2.cvtColor(cv2.imread("src/gzlj/chetuiqueren.png"), cv2.COLOR_BGR2GRAY)

    # 点冒险
    pos = (2376 - 1927, 661 - 156)
    randint_x = random.randint(0, 50)
    randint_y = random.randint(0, 10)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(2.8, 3.2))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_dixiacheng_img)
    if points:
        pos = (2781 - 1927, 264 - 156)
        randint_x = random.randint(0, 50)
        randint_y = random.randint(0, 50)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(3.8, 4.2))
    else:
        print("未能找到地下城按钮.")
        return

    # 未选择地下城
    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, xianzaidecengsu_img)
    if not points:
        # 选择地下城,第一个是0
        i = 0
        pos = (2131 - 1927 + i * 2, 337 - 156)
        randint_x = random.randint(0, 50)
        randint_y = random.randint(0, 50)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(1.4, 1.6))
        # 点OK
        pos = (2483 - 1927, 514 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(1.4, 1.6))

    waiting_num = 0
    while True:
        waiting_num += 1
        time.sleep(random.uniform(settings.inverval_min * 2, settings.inverval_max * 2))

        src_img = window_capture(hwnd, x, y)

        points = get_match_points(src_img, button_caidan_img)
        if points:
            # 战斗中
            print("战斗中...")
            waiting_num = 0
            continue

        if waiting_num >= 15:
            print("等待时间过长,退出。")
            return

        # 战斗失败
        points = get_match_points(src_img, button_qianwangdixiacheng_img)
        if points:
            pos = (2695 - 1927, 638 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(2.8, 3.2))
            # 点撤退
            pos = (2700 - 1927, 581 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.4, 1.6))
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, chetuiqueren_img)
            if points:
                # 点OK
                pos = (2490 - 1927, 518 - 156)
                randint_x = random.randint(0, 30)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
            return

        # 挑战
        points = get_match_points(src_img, button_tiaozhan_img)
        if points:
            pos = (2729 - 1927, 602 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.0, 1.2))
            continue

        # 下一步
        points = get_match_points(src_img, button_xiayibu_img)
        if points:
            pos = (2731 - 1927, 641 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 收取报酬
        points = get_match_points(src_img, shouqubaochou_img)
        if points:
            pos = (2378 - 1927, 630 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 队伍编组
        points = get_match_points(src_img, duiwubianzu_img)
        if points:
            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            # 战斗开始
            points = get_match_points(src_img, button_zhandoukaishi_img_color, threshold=0.98)
            if points:
                pos = (2736 - 1927, 602 - 156)
                randint_x = random.randint(0, 30)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                continue
            else:
                for i in range(4):
                    pos = (2021 - 1927 + i * 106, 312 - 156)
                    randint_x = random.randint(0, 10)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(1.0, 1.2))

                # 点协助
                pos = (2383 - 1927, 236 - 156)
                randint_x = random.randint(0, 30)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(1.0, 1.2))

                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, zhuzhan_choice_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(10, 30)
                    randint_y = random.randint(0, 20)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(1.0, 1.2))
                    # 点战斗开始
                    pos = (2736 - 1927, 602 - 156)
                    randint_x = random.randint(0, 30)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(1.8, 2.2))
                    # 点OK
                    pos = (2479 - 1927, 623 - 156)
                    randint_x = random.randint(0, 30)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    continue
                else:
                    print("未能找到助战对象")
                    return

        # 在地下城中,选择挑战对象
        points = get_match_points(src_img, xianzaidecengsu_img)
        if points:
            pos_list = []

            points = get_match_points(src_img, mubaoxiang_img, threshold=0.8)
            if points:
                pos_list += points
            points = get_match_points(src_img, jinbaoxiang_img, threshold=0.8)
            if points:
                pos_list += points

            if pos_list:
                target_x, target_y = pos_list.pop(0)
                for x, y in pos_list:
                    if y > target_y:
                        target_x = x
                        target_y = y
                target_pos = (target_x, target_y)
                randint_x = random.randint(32, 35)
                randint_y = random.randint(10, 15)
                # 点击战斗目标,等待弹窗
                window_click(hwnd, target_pos, randint_x, randint_y)
                continue
            else:
                print("未发现宝箱")
                continue
예제 #17
0
def lingliwu(hwnd, x, y):
    button_liwu_img = cv2.cvtColor(cv2.imread("src/gzlj/button_liwu.png"), cv2.COLOR_BGR2GRAY)
    button_quanbushouqu_img = cv2.cvtColor(cv2.imread("src/gzlj/button_quanbushouqu.png"), cv2.COLOR_BGR2GRAY)
    shouquliwu_img = cv2.cvtColor(cv2.imread("src/gzlj/shouquliwu.png"), cv2.COLOR_BGR2GRAY)

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_liwu_img)
    if points:
        pos = (2822 - 1927, 579 - 156)
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)
    else:
        # 点主页
        pos = (2006 - 1927, 661 - 156)
        randint_x = random.randint(0, 50)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(4.8, 5.2))
        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, button_liwu_img)
        if points:
            pos = (2822 - 1927, 579 - 156)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
        else:
            print("未找到礼物按钮,退出。")
            return

    time.sleep(random.uniform(2.8, 3.2))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_quanbushouqu_img)
    if points:
        pos = (2695 - 1927, 622 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(2.8, 3.2))

        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, shouquliwu_img)
        if points:
            pos = (2483 - 1927, 625 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(2.4, 2.6))
            # 点Ok
            pos = (2378 - 1927, 630 - 156)
            randint_x = random.randint(0, 30)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(2.4, 2.6))

    # 点取消
    pos = (2484 - 1927, 625 - 156)
    randint_x = random.randint(0, 30)
    randint_y = random.randint(0, 10)
    window_click(hwnd, pos, randint_x, randint_y)
예제 #18
0
def juanzeng(hwnd, x, y):
    dianzanqueren_img = cv2.cvtColor(cv2.imread("src/gzlj/dianzanqueren.png"), cv2.COLOR_BGR2GRAY)
    button_hanghui_img = cv2.cvtColor(cv2.imread("src/gzlj/button_hanghui.png"), cv2.COLOR_BGR2GRAY)
    button_juanzeng_img = cv2.cvtColor(cv2.imread("src/gzlj/button_juanzeng.png"), cv2.COLOR_BGR2GRAY)
    querenjuanzeng_img = cv2.cvtColor(cv2.imread("src/gzlj/querenjuanzeng.png"), cv2.COLOR_BGR2GRAY)
    button_ok_img_color = cv2.cvtColor(cv2.imread("src/gzlj/button_ok.png"), cv2.IMREAD_COLOR)
    button_chengyuan_img = cv2.cvtColor(cv2.imread("src/gzlj/button_chengyuan.png"), cv2.COLOR_BGR2GRAY)
    juanzengwanbi_img = cv2.cvtColor(cv2.imread("src/gzlj/juanzengwanbi.png"), cv2.COLOR_BGR2GRAY)
    dianzanwancheng_img = cv2.cvtColor(cv2.imread("src/gzlj/dianzanwancheng.png"), cv2.COLOR_BGR2GRAY)

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_hanghui_img)
    if points:
        pos = (2610 - 1927, 579 - 156)
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)
    else:
        # 点主页
        pos = (2006 - 1927, 661 - 156)
        randint_x = random.randint(0, 50)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(3.8, 4.2))
        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, button_hanghui_img)
        if points:
            pos = (2610 - 1927, 579 - 156)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
        else:
            print("未找到行会按钮,退出。")
            return

    time.sleep(random.uniform(2.8, 3.2))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, dianzanqueren_img)
    if points:
        pos = (2370 - 1927, 517 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(1.4, 1.6))

    # 定位捐赠按钮
    pos = (2286 - 1927, 191 - 156)
    randint_x = random.randint(0, 5)
    randint_y = random.randint(0, 5)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(1.0, 1.2))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_juanzeng_img)
    if points:
        target_x, target_y = points.pop(0)
        for x, y in points:
            if y > target_y:
                target_x = x
                target_y = y
        target_pos = (target_x, target_y)
        randint_x = random.randint(40, 60)
        randint_y = random.randint(0, 10)
        # 点击最下方的捐赠
        window_click(hwnd, target_pos, randint_x, randint_y)
        time.sleep(random.uniform(1.4, 1.6))

        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, querenjuanzeng_img)
        if points:
            # 点max
            pos = (2553 - 1927, 534 - 156)
            randint_x = random.randint(0, 15)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.4, 1.6))
            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            points = get_match_points(src_img, button_ok_img_color, threshold=0.98)
            if points:
                # 点OK
                pos = (2485 - 1927, 624 - 156)
                randint_x = random.randint(0, 30)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
            else:
                # 未持有物品?点取消
                pos = (2262 - 1927, 624 - 156)
                randint_x = random.randint(0, 30)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.4, 1.6))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, juanzengwanbi_img)
    if points:
        # 点OK
        pos = (2371 - 1927, 515 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(1.4, 1.6))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_chengyuan_img)
    if points:
        pos = (2144 - 1927, 489 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.8, 1.2))
        pos = (2144 - 1927, 489 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.8, 1.2))
        pos = (2144 - 1927, 489 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.8, 1.2))
        # 点第二个人,点赞
        pos = (2749 - 1927, 460 - 156)
        randint_x = random.randint(0, 25)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(1.4, 1.6))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, dianzanwancheng_img)
    if points:
        # 点OK
        pos = (2371 - 1927, 515 - 156)
        randint_x = random.randint(0, 30)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
예제 #19
0
파일: hunshi.py 프로젝트: ulimit65535/sw4
def hunshi(hwnd, x, y):
    lower = np.array([29, 29, 141], dtype="uint8")
    upper = np.array([90, 98, 240], dtype="uint8")

    xianfeng_img_color = cv2.cvtColor(cv2.imread("src/xianfeng.png"),
                                      cv2.IMREAD_COLOR)
    mask = cv2.inRange(xianfeng_img_color, lower, upper)
    xianfeng_img_color = cv2.bitwise_and(xianfeng_img_color,
                                         xianfeng_img_color,
                                         mask=mask)
    xianfeng_img = cv2.cvtColor(xianfeng_img_color, cv2.COLOR_BGR2GRAY)

    zhanjiang_img_color = cv2.cvtColor(cv2.imread("src/zhanjiang.png"),
                                       cv2.IMREAD_COLOR)
    mask = cv2.inRange(zhanjiang_img_color, lower, upper)
    zhanjiang_img_color = cv2.bitwise_and(zhanjiang_img_color,
                                          zhanjiang_img_color,
                                          mask=mask)
    zhanjiang_img = cv2.cvtColor(zhanjiang_img_color, cv2.COLOR_BGR2GRAY)

    duiwu_yincang_img = cv2.cvtColor(cv2.imread("src/duiwu_yincang.png"),
                                     cv2.COLOR_BGR2GRAY)
    duihua_any_img = cv2.cvtColor(cv2.imread("src/duihua_any.png"),
                                  cv2.COLOR_BGR2GRAY)
    button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                    cv2.COLOR_BGR2GRAY)
    duidie_close_img = cv2.cvtColor(cv2.imread("src/duidie_close.png"),
                                    cv2.COLOR_BGR2GRAY)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    src_img = window_capture(hwnd, x, y)

    # 隐藏任务列表
    points = get_match_points(src_img, duiwu_yincang_img)
    if points:
        pos = points[0]
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.6, 0.8))

    num_standing = 0
    while True:
        time.sleep(random.uniform(settings.inverval_min,
                                  settings.inverval_max))

        src_img = window_capture(hwnd, x, y)

        status = public.get_status(hwnd,
                                   x,
                                   y,
                                   src_img,
                                   with_standing=False,
                                   npc_jiaohu=False)
        if status == "in_battle":
            continue

        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        # 注意点怪的时候,Y最多向上移25-30个像素,不然会点开人物界面

        left = 151
        top = 115
        w = 740
        h = 280
        opponent_img = src_img[top:top + h, left:left + w]

        mask = cv2.inRange(opponent_img, lower, upper)
        opponent_img = cv2.bitwise_and(opponent_img, opponent_img, mask=mask)
        opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

        points = get_match_points(opponent_img, zhanjiang_img, threshold=0.6)
        if not points:
            points = get_match_points(opponent_img,
                                      xianfeng_img,
                                      threshold=0.6)
        if points:
            # 计数重置
            num = 0
            px, py = points[0]
            # px, py是相对于opponent_img的坐标,所以还要加上left和top
            pos = (px + 151 + 30, py + 115 - 25)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)

            has_battle = True

            # 最多等待5秒
            for i in range(20):
                time.sleep(random.uniform(0.2, 0.3))
                src_img = window_capture(hwnd, x, y)
                # 目标堆叠,选中第一个目标
                points = get_match_points(src_img, duidie_close_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(-100, -80)
                    randint_y = random.randint(0, 15)
                    window_click(hwnd, pos, randint_x, randint_y)
                    continue
                # 未知对话,选第一个,开打
                points = get_match_points(src_img, duihua_any_img)
                if points:
                    min_y = 1000
                    for point in points:
                        x, y = point
                        if y < min_y:
                            pos_duihua = point
                            min_y = y

                    px, py = pos_duihua
                    pos = (px - 80, py + 20)
                    randint_x = random.randint(0, 80)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.8, 1.2))
                    break

            for i in range(10):
                time.sleep(random.uniform(0.4, 0.6))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_close_img)
                if points:
                    # 关闭对话
                    pos = (2856 - 1927, 233 - 193)
                    randint_x = random.randint(0, 10)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    print("进入战斗失败")
                    break
        else:
            # 是否在移动中?
            src_img = window_capture(hwnd, x, y)
            status = public.get_status(hwnd, x, y, src_img, npc_jiaohu=False)
            if status != "standing":
                num_standing = 0
                continue
            else:
                num_standing += 1
                if num_standing <= 1:
                    continue

            # 开始巡逻
            result = public.xunluo(hwnd, x, y)
            if not result:
                print("巡逻失败,退出")
                return
예제 #20
0
파일: sanjie.py 프로젝트: ulimit65535/sw4
def sanjie(hwnd, x, y, is_leader, skill_order=None):
    if is_leader:
        duihua_jixuzhuiji_img = cv2.cvtColor(
            cv2.imread("src/duihua_jixuzhuiji.png"), cv2.COLOR_BGR2GRAY)
        duihua_xiangshoumaiwo_img = cv2.cvtColor(
            cv2.imread("src/duihua_xiangshoumaiwo.png"), cv2.COLOR_BGR2GRAY)
        duihua_sanjie_end_img = cv2.cvtColor(
            cv2.imread("src/duihua_sanjie_end.png"), cv2.COLOR_BGR2GRAY)

        lower = np.array([20, 150, 140], dtype="uint8")
        upper = np.array([80, 240, 255], dtype="uint8")

        renwu_sanjiexuanshang_img_color = cv2.cvtColor(
            cv2.imread("src/renwu_sanjiexuanshang.png"), cv2.IMREAD_COLOR)
        mask = cv2.inRange(renwu_sanjiexuanshang_img_color, lower, upper)
        renwu_sanjiexuanshang_img_color = cv2.bitwise_and(
            renwu_sanjiexuanshang_img_color,
            renwu_sanjiexuanshang_img_color,
            mask=mask)
        renwu_sanjiexuanshang_img = cv2.cvtColor(
            renwu_sanjiexuanshang_img_color, cv2.COLOR_BGR2GRAY)

        #cv2.namedWindow("Image")
        #cv2.imshow("Image", renwu_huoban_img)
        #cv2.waitKey(0)
        #sys.exit(1)

        # 若锁屏,则解锁
        public.jiesuo(hwnd, x, y)

        # 切换挂机技能
        if skill_order is not None:
            public.change_skill(hwnd, x, y, skill_order)
        else:
            time.sleep(2.0)

        num_error = 0
        while True:
            if num_error >= 5:
                print("错误次数过多,退出")
                return

            time.sleep(
                random.uniform(settings.inverval_min, settings.inverval_max))

            src_img = window_capture(hwnd, x, y)

            # 对话
            points = get_match_points(src_img, duihua_jixuzhuiji_img)
            if points:
                px, py = points[0]
                pos = (px + 50, py + 20)
                randint_x = random.randint(0, 80)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            # 对话
            points = get_match_points(src_img,
                                      duihua_xiangshoumaiwo_img,
                                      threshold=0.85)
            if points:
                px, py = points[0]
                pos = (px + 50, py + 20)
                randint_x = random.randint(0, 80)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            # 对话
            points = get_match_points(src_img, duihua_sanjie_end_img)
            if points:
                pos = (2856 - 1927, 233 - 193)
                randint_x = random.randint(0, 10)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                print("三界悬赏结束.")
                return

            # 是否在移动中?
            src_img = window_capture(hwnd, x, y)
            status = public.get_status(hwnd,
                                       x,
                                       y,
                                       src_img,
                                       npc_jiaohu=False,
                                       call_pet=True)

            if status != "standing":
                continue

            public.show_menu_renwu(hwnd, x, y)

            # 优先查找任务栏显示
            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            # 注意点怪的时候,Y最多向上移25-30个像素,不然会点开人物界面
            left = 770
            top = 140
            w = 100
            h = 250
            opponent_img = src_img[top:top + h, left:left + w]
            mask = cv2.inRange(opponent_img, lower, upper)
            opponent_img = cv2.bitwise_and(opponent_img,
                                           opponent_img,
                                           mask=mask)
            opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

            points = get_match_points(opponent_img,
                                      renwu_sanjiexuanshang_img,
                                      threshold=0.7)
            if points:
                # 点击任务栏任务
                px, py = points[0]
                # px, py是相对于opponent_img的坐标,所以还要加上left和top
                pos = (px + 770 + 70, py + 140 + 15)
                randint_x = random.randint(0, 20)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                continue
    else:
        button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                        cv2.COLOR_BGR2GRAY)

        # 若锁屏,则解锁
        public.jiesuo(hwnd, x, y)

        # 切换挂机技能
        if skill_order is not None:
            public.change_skill(hwnd, x, y, skill_order)

        wait_num = 0
        num = 0
        while True:
            time.sleep(
                random.uniform(settings.inverval_min, settings.inverval_max))
            num += 1

            src_img = window_capture(hwnd, x, y)

            points = get_match_points(src_img, button_close_img)
            if points:
                # 误点到战备,或者NPC对话,关闭
                time.sleep(random.uniform(3.8, 4.2))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_close_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                    continue

            # 是否在移动中?
            status = public.get_status(hwnd,
                                       x,
                                       y,
                                       src_img,
                                       npc_jiaohu=False,
                                       call_pet=True)
            if status == "standing":
                wait_num += 1
            else:
                wait_num = 0

            if wait_num >= 10:
                print("挂机时间过长,退出")
                return

            if num >= 300:
                # 点下任务栏,避免锁屏
                pos = (2863 - 1927, 303 - 193)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                num = 0
예제 #21
0
파일: keju.py 프로젝트: ulimit65535/sw4
def keju(hwnd, x, y):
    kejudati_img_color = cv2.cvtColor(cv2.imread("src/kejudati.png"),
                                      cv2.IMREAD_COLOR)
    window_keju_img = cv2.cvtColor(cv2.imread("src/window_keju.png"),
                                   cv2.COLOR_BGR2GRAY)
    fuben_jianglibaoxiang_img = cv2.cvtColor(
        cv2.imread("src/fuben_jianglibaoxiang.png"), cv2.COLOR_BGR2GRAY)
    window_kaiqibaoxiang_img = cv2.cvtColor(
        cv2.imread("src/window_kaiqibaoxiang.png"), cv2.COLOR_BGR2GRAY)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    num_error = 0
    num_keju = 0
    while True:
        if num_error >= 5:
            print("错误次数过多,退出")
            return
        if num_keju >= 2:
            print("无法参与科举,退出")
            return

        time.sleep(random.uniform(settings.inverval_min,
                                  settings.inverval_max))

        src_img = window_capture(hwnd, x, y)

        # 点奖励
        points = get_match_points(src_img, fuben_jianglibaoxiang_img)
        if points:
            px, py = points[0]
            pos = (px + 10, py + 10)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue
        else:
            points = get_match_points(src_img, window_kaiqibaoxiang_img)
            if points:
                px, py = points[0]
                pos = (px + 25, py + 10)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

        points = get_match_points(src_img, window_keju_img, threshold=0.8)
        if points:
            num_keju = 0
            # 点第三个答案
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(2.4, 2.6))
            continue

        result = public.open_window_richeng(hwnd, x, y)
        if not result:
            print("未能打开日程窗口")
            num_error += 1
            continue
        else:
            num_error = 0

        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        points = get_match_points(src_img, kejudati_img_color, threshold=0.98)
        if not points:
            # 等待字幕消失
            time.sleep(random.uniform(2.8, 3.2))
            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            points = get_match_points(src_img,
                                      kejudati_img_color,
                                      threshold=0.98)
            if not points:
                print("科举答题已完成")
                public.close_window_richeng(hwnd, x, y)
                return

        # 点前往参加
        num_keju += 1
        pos = points[0]
        randint_x = random.randint(15, 30)
        randint_y = random.randint(68, 78)
        window_click(hwnd, pos, randint_x, randint_y)
        continue
예제 #22
0
def zhuogui(hwnd, x, y, is_leader, skill_order=None, eat_food=False):
    #huangzitao_choice_img = cv2.cvtColor(cv2.imread("src/huangzitao_choice.png"), cv2.COLOR_BGR2GRAY)
    if is_leader:
        zhuogui_duihua_img = cv2.cvtColor(cv2.imread("src/zhuogui_duihua.png"), cv2.COLOR_BGR2GRAY)
        wobangniquzhuo_img = cv2.cvtColor(cv2.imread("src/wobangniquzhuo.png"), cv2.COLOR_BGR2GRAY)
        zhuogui_finished_img = cv2.cvtColor(cv2.imread("src/zhuogui_finished.png"), cv2.COLOR_BGR2GRAY)
        #duihua_lingquputian_img = cv2.cvtColor(cv2.imread("src/duihua_lingquputian.png"), cv2.COLOR_BGR2GRAY)
        #button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"), cv2.COLOR_BGR2GRAY)

        # 若锁屏,则解锁
        public.jiesuo(hwnd, x, y)

        if eat_food:
            public.eat_food(hwnd, x, y, "zhuogui")

        # 切换挂机技能
        if skill_order is not None:
            public.change_skill(hwnd, x, y, skill_order)
        else:
            time.sleep(4.0)

        result = public.open_window_richeng(hwnd, x, y)
        if not result:
            print("未能打开日程窗口")
            return

        pos = (2432 - 1927, 295 - 193)
        randint_x = random.randint(0, 40)
        randint_y = random.randint(0, 40)
        window_click(hwnd, pos, randint_x, randint_y)

        # 等待传送
        time.sleep(random.uniform(2.8, 3.2))

        num_error = 0
        while True:
            if num_error >= 5:
                print("错误次数过多,退出")
                return

            time.sleep(random.uniform(settings.inverval_min, settings.inverval_max))

            src_img = window_capture(hwnd, x, y)

            # 钟馗对话,接任务
            points = get_match_points(src_img, wobangniquzhuo_img)
            if points:
                px, py = points[0]
                pos = (px + 50, py + 20)
                randint_x = random.randint(0, 80)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            # 捉鬼,交任务
            points = get_match_points(src_img, zhuogui_duihua_img)
            if points:
                px, py = points[0]
                pos = (px + 50, py + 20)
                randint_x = random.randint(0, 80)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            # 钟馗对话,已完成任务
            points = get_match_points(src_img, zhuogui_finished_img)
            if points:
                # 关闭NPC对话框
                pos = (2856 - 1927, 233 - 193)
                randint_x = random.randint(0, 10)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                print("捉鬼任务已完成")
                return

            # 是否在移动中?
            status = public.get_status(hwnd, x, y, src_img)

            if status == "yanzheng_failed":
                senddata("窗口:{}验证失败,退出。".format(hwnd), "")
                return

            if status != "standing":
                continue

            result = public.open_window_richeng(hwnd, x, y)
            if not result:
                print("未能打开日程窗口")
                num_error += 1
                continue
            else:
                num_error = 0

            pos = (2432 - 1927, 295 - 193)
            randint_x = random.randint(0, 40)
            randint_y = random.randint(0, 40)
            window_click(hwnd, pos, randint_x, randint_y)
            continue
    else:
        # 若锁屏,则解锁
        public.jiesuo(hwnd, x, y)

        if eat_food:
            public.eat_food(hwnd, x, y, "zhuogui")

        # 切换挂机技能
        if skill_order is not None:
            public.change_skill(hwnd, x, y, skill_order)
        else:
            time.sleep(4.0)

        wait_num = 0
        num = 0
        while True:
            time.sleep(random.uniform(settings.inverval_min * 5, settings.inverval_max * 5))
            num += 1
            # 是否在移动中?
            status = public.get_status(hwnd, x, y, npc_jiaohu=False)
            if status == "standing":
                wait_num += 1
            else:
                wait_num = 0

            if wait_num >= 15:
                print("挂机时间过长,退出")
                return

            if num >= 60:
                # 点下任务栏,避免锁屏
                pos = (2863 - 1927, 303 - 193)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                num = 0
예제 #23
0
파일: guixu.py 프로젝트: ulimit65535/sw4
def guixu(hwnd, x, y, is_leader):
    lower = np.array([29, 29, 141], dtype="uint8")
    upper = np.array([90, 98, 240], dtype="uint8")

    duiwu_yincang_img = cv2.cvtColor(cv2.imread("src/duiwu_yincang.png"),
                                     cv2.COLOR_BGR2GRAY)
    duihua_any_img = cv2.cvtColor(cv2.imread("src/duihua_any.png"),
                                  cv2.COLOR_BGR2GRAY)
    button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                    cv2.COLOR_BGR2GRAY)
    duidie_close_img = cv2.cvtColor(cv2.imread("src/duidie_close.png"),
                                    cv2.COLOR_BGR2GRAY)

    #guixu_pipeiting_img = cv2.cvtColor(cv2.imread("src/guixu_pipeiting.png"), cv2.COLOR_BGR2GRAY)
    icon_wenda_img = cv2.cvtColor(cv2.imread("src/guixu_pipeiting.png"),
                                  cv2.COLOR_BGR2GRAY)
    duiwu_zhankai_img = cv2.cvtColor(cv2.imread("src/duiwu_zhankai.png"),
                                     cv2.COLOR_BGR2GRAY)
    guidui_img = cv2.cvtColor(cv2.imread("src/guidui.png"), cv2.COLOR_BGR2GRAY)
    button_queren_img = cv2.cvtColor(cv2.imread("src/button_queren.png"),
                                     cv2.COLOR_BGR2GRAY)
    guixu_close_img = cv2.cvtColor(cv2.imread("src/guixu_close.png"),
                                   cv2.COLOR_BGR2GRAY)
    button_querenxuanze_img = cv2.cvtColor(
        cv2.imread("src/button_querenxuanze.png"), cv2.COLOR_BGR2GRAY)

    guixu_jineng_img_color = cv2.cvtColor(cv2.imread("src/guixu_jineng.png"),
                                          cv2.IMREAD_COLOR)
    lower = np.array([24, 160, 180], dtype="uint8")
    upper = np.array([67, 230, 255], dtype="uint8")
    mask = cv2.inRange(guixu_jineng_img_color, lower, upper)
    guixu_jineng_img_color = cv2.bitwise_and(guixu_jineng_img_color,
                                             guixu_jineng_img_color,
                                             mask=mask)
    guixu_jineng_img = cv2.cvtColor(guixu_jineng_img_color, cv2.COLOR_BGR2GRAY)

    guixu_zhuangbei_img_color = cv2.cvtColor(
        cv2.imread("src/guixu_zhuangbei.png"), cv2.IMREAD_COLOR)
    lower = np.array([24, 160, 180], dtype="uint8")
    upper = np.array([67, 230, 255], dtype="uint8")
    mask = cv2.inRange(guixu_zhuangbei_img_color, lower, upper)
    guixu_zhuangbei_img_color = cv2.bitwise_and(guixu_zhuangbei_img_color,
                                                guixu_zhuangbei_img_color,
                                                mask=mask)
    guixu_zhuangbei_img = cv2.cvtColor(guixu_zhuangbei_img_color,
                                       cv2.COLOR_BGR2GRAY)

    guixu_chongwu_img_color = cv2.cvtColor(cv2.imread("src/guixu_chongwu.png"),
                                           cv2.IMREAD_COLOR)
    lower = np.array([24, 160, 180], dtype="uint8")
    upper = np.array([67, 230, 255], dtype="uint8")
    mask = cv2.inRange(guixu_chongwu_img_color, lower, upper)
    guixu_chongwu_img_color = cv2.bitwise_and(guixu_chongwu_img_color,
                                              guixu_chongwu_img_color,
                                              mask=mask)
    guixu_chongwu_img = cv2.cvtColor(guixu_chongwu_img_color,
                                     cv2.COLOR_BGR2GRAY)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    while True:
        time.sleep(random.uniform(settings.inverval_min,
                                  settings.inverval_max))

        src_img = window_capture(hwnd, x, y)

        status = public.get_status(hwnd,
                                   x,
                                   y,
                                   src_img,
                                   with_standing=False,
                                   npc_jiaohu=False)
        if status == "in_battle":
            continue

        points = get_match_points(src_img, icon_wenda_img, threshold=0.92)
        if points:
            if is_leader:
                # 打开地图
                pos = (1997 - 1927, 178 - 156)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(1.0, 1.2))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_close_img)
                if not points:
                    # 未点开地图?,重新点开,重新截图
                    print("场景切换?未能点开地图,重新点开")
                    time.sleep(random.uniform(4.8, 5.2))
                    pos = (1997 - 1927, 178 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(1.0, 1.2))
                # 点乱斗之王
                pos = (2399 - 1927, 435 - 156)
                randint_x = random.randint(0, 2)
                randint_y = random.randint(0, 2)
                window_click(hwnd, pos, randint_x, randint_y)
                # 等队员归队
                time.sleep(random.uniform(4.8, 5.2))

                while True:
                    time.sleep(
                        random.uniform(settings.inverval_min,
                                       settings.inverval_max))
                    src_img = window_capture(hwnd, x, y)
                    # 点确认
                    points = get_match_points(src_img, button_queren_img)
                    if points:
                        pos = points[0]
                        randint_x = random.randint(10, 80)
                        randint_y = random.randint(5, 20)
                        window_click(hwnd, pos, randint_x, randint_y)
                        break

                    points = get_match_points(src_img, duihua_any_img)
                    if points:
                        min_y = 1000
                        for point in points:
                            x, y = point
                            if y < min_y:
                                pos_duihua = point
                                min_y = y

                        px, py = pos_duihua
                        pos = (px - 80, py + 20)
                        randint_x = random.randint(0, 80)
                        randint_y = random.randint(0, 5)
                        window_click(hwnd, pos, randint_x, randint_y)
                        continue

                    points = get_match_points(src_img, button_close_img)
                    if points:
                        # 误点到战备,或者NPC对话,关闭
                        pos = points[0]
                        randint_x = random.randint(0, 5)
                        randint_y = random.randint(0, 5)
                        window_click(hwnd, pos, randint_x, randint_y)
                        time.sleep(random.uniform(1.0, 1.2))
                        # 点乱斗之王
                        pos = (2399 - 1927, 435 - 156)
                        randint_x = random.randint(0, 2)
                        randint_y = random.randint(0, 2)
                        window_click(hwnd, pos, randint_x, randint_y)
                        time.sleep(random.uniform(1.0, 1.2))
                        continue
            else:
                while True:
                    time.sleep(
                        random.uniform(settings.inverval_min,
                                       settings.inverval_max))
                    src_img = window_capture(hwnd, x, y)

                    # 点确认
                    points = get_match_points(src_img, button_queren_img)
                    if points:
                        pos = points[0]
                        randint_x = random.randint(10, 80)
                        randint_y = random.randint(5, 20)
                        window_click(hwnd, pos, randint_x, randint_y)
                        break

                    # 展开队伍列表
                    points = get_match_points(src_img, duiwu_zhankai_img)
                    if points:
                        pos = points[0]
                        randint_x = random.randint(0, 5)
                        randint_y = random.randint(0, 5)
                        window_click(hwnd, pos, randint_x, randint_y)
                        time.sleep(random.uniform(0.6, 0.8))

                    # 开关队伍界面
                    pos = (2792 - 1927, 302 - 193)
                    randint_x = random.randint(0, 50)
                    randint_y = random.randint(0, 20)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.8, 1.0))

                    src_img = window_capture(hwnd, x, y)
                    points = get_match_points(src_img, guidui_img)
                    if points:
                        pos = points[0]
                        randint_x = random.randint(5, 70)
                        randint_y = random.randint(5, 20)
                        window_click(hwnd, pos, randint_x, randint_y)
                        time.sleep(random.uniform(0.6, 0.8))

        points = get_match_points(src_img, button_querenxuanze_img)
        if points:
            time.sleep(15)
            # 进入战斗循环
            while True:
                time.sleep(
                    random.uniform(settings.inverval_min,
                                   settings.inverval_max))
                src_img = window_capture(hwnd, x, y)

                status = public.get_status(hwnd,
                                           x,
                                           y,
                                           src_img,
                                           with_standing=False,
                                           npc_jiaohu=False)
                if status == "in_battle":
                    continue

                # 隐藏任务列表
                points = get_match_points(src_img, duiwu_yincang_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                    continue

                # 点确认
                points = get_match_points(src_img, button_queren_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(10, 80)
                    randint_y = random.randint(5, 20)
                    window_click(hwnd, pos, randint_x, randint_y)
                    continue

                points = get_match_points(src_img, guixu_close_img)
                if points:
                    # 退出归墟乱斗
                    pos = points[0]
                    randint_x = random.randint(5, 10)
                    randint_y = random.randint(5, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(4.8, 5.2))
                    break

                src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
                # 注意点怪的时候,Y最多向上移25-30个像素,不然会点开人物界面

                left = 151
                top = 115
                w = 740
                h = 280
                opponent_img = src_img[top:top + h, left:left + w]

                # cv2.namedWindow("Image")
                # cv2.imshow("Image", opponent_img)
                # cv2.waitKey(0)
                # sys.exit(1)

                lower = np.array([24, 160, 180], dtype="uint8")
                upper = np.array([67, 230, 255], dtype="uint8")
                mask = cv2.inRange(opponent_img, lower, upper)
                opponent_img = cv2.bitwise_and(opponent_img,
                                               opponent_img,
                                               mask=mask)
                opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

                points = get_match_points(opponent_img,
                                          guixu_jineng_img,
                                          threshold=0.6)
                if not points:
                    points = get_match_points(opponent_img,
                                              guixu_zhuangbei_img,
                                              threshold=0.6)
                    if not points:
                        points = get_match_points(opponent_img,
                                                  guixu_chongwu_img,
                                                  threshold=0.6)

                if points:
                    px, py = points[0]
                    # px, py是相对于opponent_img的坐标,所以还要加上left和top
                    pos = (px + 151 + 10, py + 115 - 25)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.5, 0.6))
                    src_img = window_capture(hwnd, x, y)
                    # 目标堆叠,选中第一个目标
                    points = get_match_points(src_img, duidie_close_img)
                    if points:
                        pos = points[0]
                        randint_x = random.randint(-100, -80)
                        randint_y = random.randint(0, 15)
                        window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(3.8, 4.2))
                    # 选第一个物品
                    pos = (2269 - 1927, 511 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.5, 0.6))
                    # 点确定
                    pos = (2218 - 1927, 516 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                else:
                    status = public.get_status(hwnd,
                                               x,
                                               y,
                                               with_standing=True,
                                               npc_jiaohu=False)
                    if status == "standing":
                        status = public.get_status(hwnd,
                                                   x,
                                                   y,
                                                   with_standing=True,
                                                   npc_jiaohu=False)
                        if status == "standing":
                            pos_list = [
                                (2142 - 1927, 305 - 156),
                                (2685 - 1927, 591 - 156),
                                (2682 - 1927, 283 - 156),
                                (2099 - 1927, 601 - 156),
                            ]
                            r = random.randint(0, len(pos_list) - 1)
                            pos_target = pos_list[r]
                            # 点开大地图
                            pos = (1949 - 1927, 232 - 156)
                            randint_x = random.randint(0, 5)
                            randint_y = random.randint(0, 5)
                            window_click(hwnd, pos, randint_x, randint_y)
                            time.sleep(random.uniform(0.5, 0.6))
                            randint_x = random.randint(0, 1)
                            randint_y = random.randint(0, 1)
                            window_click(hwnd, pos_target, randint_x,
                                         randint_y)
                            time.sleep(random.uniform(0.5, 0.6))
                            # 关闭大地图
                            pos = (1949 - 1927, 232 - 156)
                            randint_x = random.randint(0, 5)
                            randint_y = random.randint(0, 5)
                            window_click(hwnd, pos, randint_x, randint_y)
예제 #24
0
def wuqiguo(hwnd, x, y):
    wuqiguo_img_color = cv2.cvtColor(cv2.imread("src/wuqiguo.png"),
                                     cv2.IMREAD_COLOR)
    duihua_putonglixian_img = cv2.cvtColor(
        cv2.imread("src/duihua_putonglixian.png"), cv2.COLOR_BGR2GRAY)
    duihua_tiaozhan_wuqiguo_img = cv2.cvtColor(
        cv2.imread("src/duihua_tiaozhan_wuqiguo.png"), cv2.COLOR_BGR2GRAY)
    duihua_qianwangxiayiguan_img = cv2.cvtColor(
        cv2.imread("src/duihua_qianwangxiayiguan.png"), cv2.COLOR_BGR2GRAY)

    lower = np.array([20, 150, 140], dtype="uint8")
    upper = np.array([80, 240, 255], dtype="uint8")

    renwu_wuqiguo_img_color = cv2.cvtColor(cv2.imread("src/renwu_wuqiguo.png"),
                                           cv2.IMREAD_COLOR)
    mask = cv2.inRange(renwu_wuqiguo_img_color, lower, upper)
    renwu_wuqiguo_img_color = cv2.bitwise_and(renwu_wuqiguo_img_color,
                                              renwu_wuqiguo_img_color,
                                              mask=mask)
    renwu_wuqiguo_img = cv2.cvtColor(renwu_wuqiguo_img_color,
                                     cv2.COLOR_BGR2GRAY)

    #cv2.namedWindow("Image")
    #cv2.imshow("Image", renwu_huoban_img)
    #cv2.waitKey(0)
    #sys.exit(1)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    num_error = 0
    while True:
        if num_error >= 5:
            print("错误次数过多,退出")
            return

        time.sleep(
            random.uniform(settings.inverval_min * 3,
                           settings.inverval_max * 3))

        src_img = window_capture(hwnd, x, y)

        # 对话,参加
        points = get_match_points(src_img, duihua_putonglixian_img)
        if points:
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 对话,挑战
        points = get_match_points(src_img, duihua_tiaozhan_wuqiguo_img)
        if points:
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 对话,前往下一关
        points = get_match_points(src_img, duihua_qianwangxiayiguan_img)
        if points:
            px, py = points[0]
            pos = (px + 50, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 是否在移动中?
        src_img = window_capture(hwnd, x, y)
        status = public.get_status(hwnd, x, y, src_img)

        if status != "standing":
            continue

        public.show_menu_renwu(hwnd, x, y)

        # 优先查找任务栏显示
        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        # 注意点怪的时候,Y最多向上移25-30个像素,不然会点开人物界面
        left = 770
        top = 140
        w = 100
        h = 250
        opponent_img = src_img[top:top + h, left:left + w]
        mask = cv2.inRange(opponent_img, lower, upper)
        opponent_img = cv2.bitwise_and(opponent_img, opponent_img, mask=mask)
        opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

        points = get_match_points(opponent_img,
                                  renwu_wuqiguo_img,
                                  threshold=0.7)
        if points:
            # 点击任务栏任务
            px, py = points[0]
            # px, py是相对于opponent_img的坐标,所以还要加上left和top
            pos = (px + 770 + 70, py + 140 + 15)
            randint_x = random.randint(0, 20)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        result = public.open_window_richeng(hwnd, x, y)
        if not result:
            print("未能打开日程窗口")
            num_error += 1
            continue
        else:
            num_error = 0

        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        points = get_match_points(src_img, wuqiguo_img_color, threshold=0.98)
        if not points:
            # 等待字幕消失
            time.sleep(random.uniform(2.8, 3.2))
            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            points = get_match_points(src_img,
                                      wuqiguo_img_color,
                                      threshold=0.98)
            if not points:
                print("无启国已完成")
                return

        # 点前往参加
        pos = points[0]
        randint_x = random.randint(15, 30)
        randint_y = random.randint(68, 78)
        window_click(hwnd, pos, randint_x, randint_y)
        continue
예제 #25
0
파일: shaxing.py 프로젝트: ulimit65535/sw4
def shaxing(hwnd, x, y, target):

    lower = np.array([29, 29, 141], dtype="uint8")
    upper = np.array([90, 98, 240], dtype="uint8")

    target28_img_color = cv2.cvtColor(cv2.imread("src/target28.png"),
                                      cv2.IMREAD_COLOR)
    mask = cv2.inRange(target28_img_color, lower, upper)
    target28_img_color = cv2.bitwise_and(target28_img_color,
                                         target28_img_color,
                                         mask=mask)
    target28_img = cv2.cvtColor(target28_img_color, cv2.COLOR_BGR2GRAY)

    duihua_tiaozhan_img = cv2.cvtColor(cv2.imread("src/duihua_tiaozhan.png"),
                                       cv2.COLOR_BGR2GRAY)
    duihua_xianlaihoudao_img = cv2.cvtColor(
        cv2.imread("src/duihua_xianlaihoudao.png"), cv2.COLOR_BGR2GRAY)
    zidong_img = cv2.cvtColor(cv2.imread("src/zidong.png"), cv2.COLOR_BGR2GRAY)

    targetyaowang_img_color = cv2.cvtColor(cv2.imread("src/targetyaowang.png"),
                                           cv2.IMREAD_COLOR)
    mask = cv2.inRange(targetyaowang_img_color, lower, upper)
    targetyaowang_img_color = cv2.bitwise_and(targetyaowang_img_color,
                                              targetyaowang_img_color,
                                              mask=mask)
    targetyaowang_img = cv2.cvtColor(targetyaowang_img_color,
                                     cv2.COLOR_BGR2GRAY)

    targetshenqi_img_color = cv2.cvtColor(cv2.imread("src/targetshenqi.png"),
                                          cv2.IMREAD_COLOR)
    mask = cv2.inRange(targetshenqi_img_color, lower, upper)
    targetshenqi_img_color = cv2.bitwise_and(targetshenqi_img_color,
                                             targetshenqi_img_color,
                                             mask=mask)
    targetshenqi_img = cv2.cvtColor(targetshenqi_img_color, cv2.COLOR_BGR2GRAY)

    duihua_jinruzhandou_img = cv2.cvtColor(
        cv2.imread("src/duihua_jinruzhandou.png"), cv2.COLOR_BGR2GRAY)
    duihua_qingwudarao_img = cv2.cvtColor(
        cv2.imread("src/duihua_qingwudarao.png"), cv2.COLOR_BGR2GRAY)

    target36_img_color = cv2.cvtColor(cv2.imread("src/target36.png"),
                                      cv2.IMREAD_COLOR)
    mask = cv2.inRange(target36_img_color, lower, upper)
    target36_img_color = cv2.bitwise_and(target36_img_color,
                                         target36_img_color,
                                         mask=mask)
    target36_img = cv2.cvtColor(target36_img_color, cv2.COLOR_BGR2GRAY)

    duihua_buhuidecheng_img = cv2.cvtColor(
        cv2.imread("src/duihua_buhuidecheng.png"), cv2.COLOR_BGR2GRAY)
    duihua_xianlaihoudao_36_img = cv2.cvtColor(
        cv2.imread("src/duihua_xianlaihoudao_36.png"), cv2.COLOR_BGR2GRAY)

    duihua_guanzhan_img = cv2.cvtColor(cv2.imread("src/duihua_guanzhan.png"),
                                       cv2.COLOR_BGR2GRAY)
    duihua_woyaoguanzhan_img = cv2.cvtColor(
        cv2.imread("src/duihua_woyaoguanzhan.png"), cv2.COLOR_BGR2GRAY)
    duidie_close_img = cv2.cvtColor(cv2.imread("src/duidie_close.png"),
                                    cv2.COLOR_BGR2GRAY)

    if target == "":
        print("开始抢灭,请注意人物不要移动")
        # 不点选目标,抢灭
        target_pos = None
        target = ""
        for i in range(1, 10):
            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            mask = cv2.inRange(src_img, lower, upper)
            src_img = cv2.bitwise_and(src_img, src_img, mask=mask)
            src_img = cv2.cvtColor(src_img, cv2.COLOR_BGR2GRAY)

            left = 480 - 48 * i
            top = 270 - 27 * i
            w = 48 * 2 * i
            h = 27 * 2 * i
            opponent_img = src_img[top:top + h, left:left + w]

            points = get_match_points(opponent_img,
                                      targetyaowang_img,
                                      threshold=0.5)
            if not points:
                points = get_match_points(opponent_img,
                                          targetshenqi_img,
                                          threshold=0.5)
            if points:
                px, py = points[0]
                target_pos = (px + 35 + left, py - 30 + top)
                target = "妖王神器"
                break
            points = get_match_points(opponent_img,
                                      target36_img,
                                      threshold=0.5)
            if points:
                px, py = points[0]
                target_pos = (px + 40 + left, py - 30 + top)
                target = "36天罡"
                break
            points = get_match_points(opponent_img,
                                      target28_img,
                                      threshold=0.5)
            if points:
                px, py = points[0]
                target_pos = (px + 40 + left, py - 30 + top)
                target = "28星宿"
                break
        print(target_pos)
        print(target)
        if target_pos:
            window_click(hwnd, target_pos, 0, 0)
            time.sleep(random.uniform(1.0, 1.2))

            if target == "28星宿":
                duihua_start_img = duihua_tiaozhan_img
                duihua_wait_img = duihua_woyaoguanzhan_img
            elif target == "妖王神器":
                duihua_start_img = duihua_jinruzhandou_img
                duihua_wait_img = duihua_guanzhan_img
            elif target == "36天罡":
                duihua_start_img = duihua_buhuidecheng_img
                duihua_wait_img = duihua_woyaoguanzhan_img
            while True:
                time.sleep(0.2)
                src_img = window_capture(hwnd, x, y)
                left = 595
                top = 270
                w = 345
                h = 250
                opponent_img = src_img[top:top + h, left:left + w]
                points = get_match_points(opponent_img, duihua_start_img)
                if points:
                    px, py = points[0]
                    pos = (px + 50 + left, py + 20 + top)
                    randint_x = random.randint(0, 80)
                    randint_y = random.randint(0, 5)

                    points = get_match_points(opponent_img, duihua_wait_img)
                    if points:
                        # 还能观点,无法进入战斗,继续点怪刷新
                        window_click(hwnd, target_pos, 0, 0)
                        continue
                    else:
                        # 不存在观战按钮,进入战斗
                        window_click(hwnd, pos, randint_x, randint_y)
                        return
    else:
        while True:
            time.sleep(0.2)

            src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
            mask = cv2.inRange(src_img, lower, upper)
            src_img = cv2.bitwise_and(src_img, src_img, mask=mask)
            src_img = cv2.cvtColor(src_img, cv2.COLOR_BGR2GRAY)

            #cv2.namedWindow("Image")
            #cv2.imshow("Image", targetyaowang_img)
            #cv2.waitKey(0)
            #sys.exit(1)

            if target == "28星宿":
                points = get_match_points(src_img, target28_img, threshold=0.6)
                if points:
                    px, py = points[0]
                    pos = (px + 35, py - 35)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)

                    # 这里死循环,除非手动关闭进程,或进入战斗
                    is_first = True
                    while True:
                        time.sleep(0.1)
                        src_img = window_capture(hwnd, x, y)
                        points = get_match_points(src_img, duihua_tiaozhan_img)
                        if points:
                            # 开打
                            px, py = points[0]
                            pos = (px + 50, py + 20)
                            randint_x = random.randint(0, 80)
                            randint_y = random.randint(0, 5)
                            window_click(hwnd, pos, randint_x, randint_y)
                            continue
                        if is_first:
                            # 目标堆叠,选中第一个目标
                            points = get_match_points(src_img,
                                                      duidie_close_img)
                            if points:
                                pos = points[0]
                                randint_x = random.randint(-100, -80)
                                randint_y = random.randint(0, 15)
                                window_click(hwnd, pos, randint_x, randint_y)
                                continue
                        points = get_match_points(src_img,
                                                  duihua_xianlaihoudao_img)
                        if points:
                            is_first = False
                            # 未抢到,关闭NPC对话
                            pos = (2856 - 1927, 233 - 193)
                            randint_x = random.randint(0, 10)
                            randint_y = random.randint(0, 10)
                            window_click(hwnd, pos, randint_x, randint_y)
                            print("未能成功进入战斗")
                            continue
                        points = get_match_points(src_img, zidong_img)
                        if points:
                            print("已成功进入战斗,退出.")
                            return
            elif target == "妖王神器":
                points = get_match_points(src_img,
                                          targetyaowang_img,
                                          threshold=0.6)
                if not points:
                    points = get_match_points(src_img,
                                              targetshenqi_img,
                                              threshold=0.6)
                if points:
                    px, py = points[0]
                    pos = (px + 30, py - 35)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)

                    # 这里死循环,除非手动关闭进程,或进入战斗
                    is_first = True
                    while True:
                        time.sleep(0.1)
                        src_img = window_capture(hwnd, x, y)
                        points = get_match_points(src_img,
                                                  duihua_jinruzhandou_img)
                        if points:
                            # 开打
                            px, py = points[0]
                            pos = (px + 50, py + 20)
                            randint_x = random.randint(0, 80)
                            randint_y = random.randint(0, 5)
                            window_click(hwnd, pos, randint_x, randint_y)
                            continue
                        if is_first:
                            # 目标堆叠,选中第一个目标
                            points = get_match_points(src_img,
                                                      duidie_close_img)
                            if points:
                                pos = points[0]
                                randint_x = random.randint(-100, -80)
                                randint_y = random.randint(0, 15)
                                window_click(hwnd, pos, randint_x, randint_y)
                                continue
                        points = get_match_points(src_img,
                                                  duihua_qingwudarao_img)
                        if points:
                            is_first = False
                            # 未抢到,关闭NPC对话
                            pos = (2856 - 1927, 233 - 193)
                            randint_x = random.randint(0, 10)
                            randint_y = random.randint(0, 10)
                            window_click(hwnd, pos, randint_x, randint_y)
                            print("未能成功进入战斗")
                            continue
                        points = get_match_points(src_img, zidong_img)
                        if points:
                            print("已成功进入战斗,退出.")
                            return
            elif target == "36天罡":
                points = get_match_points(src_img, target36_img, threshold=0.6)
                if points:
                    px, py = points[0]
                    pos = (px + 35, py - 35)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)

                    # 这里死循环,除非手动关闭进程,或进入战斗
                    is_first = True
                    while True:
                        time.sleep(0.1)
                        src_img = window_capture(hwnd, x, y)
                        points = get_match_points(src_img,
                                                  duihua_buhuidecheng_img)
                        if points:
                            # 开打
                            px, py = points[0]
                            pos = (px + 50, py + 20)
                            randint_x = random.randint(0, 80)
                            randint_y = random.randint(0, 5)
                            window_click(hwnd, pos, randint_x, randint_y)
                            continue
                        if is_first:
                            # 目标堆叠,选中第一个目标
                            points = get_match_points(src_img,
                                                      duidie_close_img)
                            if points:
                                pos = points[0]
                                randint_x = random.randint(-100, -80)
                                randint_y = random.randint(0, 15)
                                window_click(hwnd, pos, randint_x, randint_y)
                                continue
                        points = get_match_points(src_img,
                                                  duihua_xianlaihoudao_36_img)
                        if points:
                            is_first = False
                            # 未抢到,关闭NPC对话
                            pos = (2856 - 1927, 233 - 193)
                            randint_x = random.randint(0, 10)
                            randint_y = random.randint(0, 10)
                            window_click(hwnd, pos, randint_x, randint_y)
                            print("未能成功进入战斗")
                            continue
                        points = get_match_points(src_img, zidong_img)
                        if points:
                            print("已成功进入战斗,退出.")
                            return
예제 #26
0
파일: shilian.py 프로젝트: ulimit65535/sw4
def shilian(hwnd, x, y, skill_order=None, eat_food=False):
    icon_shilian_img_color = cv2.cvtColor(cv2.imread("src/icon_shilian.png"), cv2.IMREAD_COLOR)
    duihua_jieshoushilian_img = cv2.cvtColor(cv2.imread("src/duihua_jieshoushilian.png"), cv2.COLOR_BGR2GRAY)
    button_xuanze_img = cv2.cvtColor(cv2.imread("src/button_xuanze.png"), cv2.COLOR_BGR2GRAY)
    button_tiaozhan_shilian_img = cv2.cvtColor(cv2.imread("src/button_tiaozhan_shilian.png"), cv2.COLOR_BGR2GRAY)
    quxiaozidong_img = cv2.cvtColor(cv2.imread("src/quxiaozidong.png"), cv2.COLOR_BGR2GRAY)
    zidong_img = cv2.cvtColor(cv2.imread("src/zidong.png"), cv2.COLOR_BGR2GRAY)
    lingqu_huoyue_img = cv2.cvtColor(cv2.imread("src/lingqu_huoyue.png"), cv2.COLOR_BGR2GRAY)
    jineng_huoba_img = cv2.cvtColor(cv2.imread("src/jineng_huoba.png"), cv2.COLOR_BGR2GRAY)
    biaoqing_wenhao_img = cv2.cvtColor(cv2.imread("src/biaoqing_wenhao.png"), cv2.COLOR_BGR2GRAY)
    shilian_baoxiang_img = cv2.cvtColor(cv2.imread("src/shilian_baoxiang.png"), cv2.COLOR_BGR2GRAY)
    shilian_yiyu_img = cv2.cvtColor(cv2.imread("src/shilian_yiyu.png"), cv2.COLOR_BGR2GRAY)
    shilian_ruqinzhe_img = cv2.cvtColor(cv2.imread("src/shilian_ruqinzhe.png"), cv2.COLOR_BGR2GRAY)
    window_zhuanzhuanle_img = cv2.cvtColor(cv2.imread("src/window_zhuanzhuanle.png"), cv2.COLOR_BGR2GRAY)
    button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"), cv2.COLOR_BGR2GRAY)
    tiaoguo_img = cv2.cvtColor(cv2.imread("src/tiaoguo.png"), cv2.COLOR_BGR2GRAY)

    """
    shilian_judian1_img_color = cv2.cvtColor(cv2.imread("src/shilian_judian1.png"), cv2.IMREAD_COLOR)
    shilian_judian2_img_color = cv2.cvtColor(cv2.imread("src/shilian_judian2.png"), cv2.IMREAD_COLOR)
    shilian_judian3_img_color = cv2.cvtColor(cv2.imread("src/shilian_judian3.png"), cv2.IMREAD_COLOR)
    shilian_judian4_img_color = cv2.cvtColor(cv2.imread("src/shilian_judian4.png"), cv2.IMREAD_COLOR)
    shilian_judian5_img_color = cv2.cvtColor(cv2.imread("src/shilian_judian5.png"), cv2.IMREAD_COLOR)
    shilian_judian6_img_color = cv2.cvtColor(cv2.imread("src/shilian_judian6.png"), cv2.IMREAD_COLOR)
    shilian_judian7_img_color = cv2.cvtColor(cv2.imread("src/shilian_judian7.png"), cv2.IMREAD_COLOR)

    shilian_judian_img_list = []
    shilian_judian_img_list.append(shilian_judian1_img_color)
    shilian_judian_img_list.append(shilian_judian2_img_color)
    shilian_judian_img_list.append(shilian_judian3_img_color)
    shilian_judian_img_list.append(shilian_judian4_img_color)
    shilian_judian_img_list.append(shilian_judian5_img_color)
    shilian_judian_img_list.append(shilian_judian6_img_color)
    shilian_judian_img_list.append(shilian_judian7_img_color)
    """

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    if eat_food:
        public.eat_food(hwnd, x, y, "shilian")

    # 切换挂机技能
    if skill_order is not None:
        public.change_skill(hwnd, x, y, skill_order)

    for i in range(10):
        result = public.open_window_richeng(hwnd, x, y)
        if not result:
            time.sleep(random.uniform(settings.inverval_min, settings.inverval_max))
        else:
            break
    if not result:
        print("未能打开日程窗口")
        return

    src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
    points = get_match_points(src_img, icon_shilian_img_color, threshold=0.95)
    if not points:
        # 等待字幕消失
        time.sleep(random.uniform(1.8, 2.2))
        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        points = get_match_points(src_img, icon_shilian_img_color, threshold=0.95)
        if not points:
            print("英雄试炼任务已完成")
            public.close_window_richeng(hwnd, x, y)
            return

    px, py = points[0]
    pos = (px, py - 36)
    randint_x = random.randint(0, 40)
    randint_y = random.randint(0, 40)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(1.2, 1.4))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, duihua_jieshoushilian_img)
    if points:
        px, py = points[0]
        pos = (px + 50, py + 20)
        randint_x = random.randint(0, 80)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(1.8, 2.2))
    else:
        print("进入试炼失败.")
        return

    # 点跳过
    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, tiaoguo_img, threshold=0.8)
    if points:
        pos = points[0]
        randint_x = random.randint(20, 50)
        randint_y = random.randint(10, 20)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(1.8, 2.2))

    # 进入据点
    src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
    pos = None
    judian_num = None
    for i in range(7):
        judian_num = i
        left = 1993 - 1927 + i * 62
        top = 191 - 156
        w = 1
        h = 1
        opponent_img = src_img[top:top + h, left:left + w]
        r = opponent_img[0, 0, 0]
        g = opponent_img[0, 0, 1]
        b = opponent_img[0, 0, 2]

        if r == g == b:
            # 未打过的据点
            pos = (1993 - 1927 + i * 62, 191 - 156)
            break

    if not pos:
        print("未找到未占领据点,退出。")
        return
    randint_x = random.randint(0, 1)
    randint_y = random.randint(0, 1)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(4.8, 5.2))

    # 点屏幕中间的据点
    pos = (2452 - 1927, 453 - 193)
    randint_x = random.randint(0, 5)
    randint_y = random.randint(0, 5)
    window_click(hwnd, pos, randint_x, randint_y)
    time.sleep(random.uniform(1.2, 1.4))

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_xuanze_img)
    if points:
        pos = points[0]
        randint_x = random.randint(10, 80)
        randint_y = random.randint(5, 20)
        window_click(hwnd, pos, randint_x, randint_y)
    else:
        # 可能已经选择过了,点一下最左上角的太阳,取消窗口
        pos = (1948 - 1927, 221 - 193)
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)

    time.sleep(random.uniform(1.2, 1.4))

    if judian_num == 0:
        target_pos_list = [
            # y坐标上移了,所以抓取的时候留意减156而非193
            (2150 - 1927, 544 - 156),
            (2289 - 1927, 591 - 156),
            (2288 - 1927, 451 - 156),
            (2487 - 1927, 565 - 156),
            (2600 - 1927, 448 - 156)
        ]
    elif judian_num == 1:
        target_pos_list = [
            (2246 - 1927, 507 - 193),
            (2597 - 1927, 469 - 193),
            (2702 - 1927, 572 - 193),
            (2338 - 1927, 618 - 193),
            (2642 - 1927, 680 - 193)
        ]
    elif judian_num == 2:
        target_pos_list = [
            (2278 - 1927, 410 - 193),
            (2558 - 1927, 478 - 193),
            (2209 - 1927, 512 - 193),
            (2436 - 1927, 635 - 193),
            (2318 - 1927, 592 - 193)
        ]
    elif judian_num == 3:
        target_pos_list = [
            (2312 - 1927, 404 - 156),
            (2557 - 1927, 332 - 156),
            (2484 - 1927, 572 - 156),
            (2662 - 1927, 483 - 156),
            (2299 - 1927, 521 - 156)
        ]
    elif judian_num == 4:
        target_pos_list = [
            (2240 - 1927, 290 - 156),
            (2545 - 1927, 261 - 156),
            (2736 - 1927, 313 - 156),
            (2205 - 1927, 433 - 156),
            (2343 - 1927, 491 - 156)
        ]
    elif judian_num == 5:
        target_pos_list = [
            (2257 - 1927, 373 - 156),
            (2586 - 1927, 372 - 156),
            (2326 - 1927, 522 - 156),
            (2657 - 1927, 489 - 156),
            (2618 - 1927, 584 - 156)
        ]
    elif judian_num == 6:
        target_pos_list = [
            (2233 - 1927, 424 - 156),
            (2630 - 1927, 440 - 156),
            (2315 - 1927, 536 - 156),
            (2467 - 1927, 622 - 156),
            (2652 - 1927, 545 - 156)
        ]

    for target_pos in target_pos_list:
        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, lingqu_huoyue_img)
        if points:
            # 直接领取活跃
            pos = points[0]
            randint_x = random.randint(5, 50)
            randint_y = random.randint(5, 15)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(3.8, 4.2))

            # 转转乐
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, window_zhuanzhuanle_img, threshold=0.85)
            if points:
                pos = (2272 - 1927, 420 - 156)
                randint_x = random.randint(0, 20)
                randint_y = random.randint(0, 20)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(4.8, 5.2))
                for i in range(10):
                    time.sleep(random.uniform(2.8, 3.2))
                    src_img = window_capture(hwnd, x, y)
                    points = get_match_points(src_img, window_zhuanzhuanle_img, threshold=0.85)
                    if points:
                        # 直接关闭
                        pos = (2735 - 1927, 192 - 156)
                        randint_x = random.randint(0, 10)
                        randint_y = random.randint(0, 10)
                        window_click(hwnd, pos, randint_x, randint_y)
                        continue
                    else:
                        break

        points = get_match_points(src_img, button_close_img)
        if points:
            # 战斗失败,提升窗口,关闭
            pos = points[0]
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.4, 0.6))

        # 点选目标,因为对手可能刷新,故尝试多次
        for i in range(2):
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, zidong_img)
            if points:
                # 已进入战斗
                break
            # 点选目标
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, target_pos, randint_x, randint_y)
            time.sleep(random.uniform(1.6, 1.8))

            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_tiaozhan_shilian_img)
            if points:
                pos = points[0]
                randint_x = random.randint(10, 80)
                randint_y = random.randint(5, 20)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(2.2, 2.4))

        while True:
            time.sleep(random.uniform(settings.inverval_min, settings.inverval_max))
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, jineng_huoba_img)
            if points:
                pos_huoba = points[0]
                for i in range(60):
                    time.sleep(random.uniform(0.2, 0.3))
                    src_img = window_capture(hwnd, x, y)
                    left = 0
                    top = 0
                    w = 970
                    h = 400
                    opponent_img = src_img[top:top + h, left:left + w]
                    points = get_match_points(opponent_img, biaoqing_wenhao_img, threshold=0.8)
                    if points:
                        pos_biaoqing = points[0]
                        # 点火把技能
                        randint_x = random.randint(0, 5)
                        randint_y = random.randint(0, 5)
                        window_click(hwnd, pos_huoba, randint_x, randint_y)
                        time.sleep(random.uniform(1.2, 1.4))
                        # 点目标怪物
                        px, py = pos_biaoqing
                        pos = (px - 75, py + 80)
                        randint_x = random.randint(0, 1)
                        randint_y = random.randint(0, 1)
                        window_click(hwnd, pos, randint_x, randint_y)
                        time.sleep(random.uniform(1.2, 1.4))
                        # 点自动战斗
                        pos = (2846 - 1927, 682 - 193)
                        randint_x = random.randint(0, 10)
                        randint_y = random.randint(0, 10)
                        window_click(hwnd, pos, randint_x, randint_y)
                        break

            points = get_match_points(src_img, quxiaozidong_img)
            if points:
                continue
            points = get_match_points(src_img, zidong_img)
            if points:
                pos = points[0]
                randint_x = random.randint(0, 10)
                randint_y = random.randint(0, 10)
                window_click(hwnd, pos, randint_x, randint_y)
                continue

            # 等待字幕消失,避免出现领取活跃窗口遮挡
            time.sleep(random.uniform(3.8, 4.2))
            break

    # 5次战斗结束
    for i in range(5):
        time.sleep(random.uniform(settings.inverval_min, settings.inverval_max))
        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, shilian_baoxiang_img)
        if points:
            pos = points[0]
            randint_x = random.randint(5, 15)
            randint_y = random.randint(5, 15)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(4.8, 5.2))
            break

    if judian_num == 6:
        # 七次完成,领取宝箱
        pos = (1992 - 1927 + 7 * 61, 223 - 193)
        randint_x = random.randint(0, 10)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.8, 1.2))

    # 是否还有入侵者?
    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, button_close_img)
    if points:
        # 战斗失败,提升窗口,关闭
        pos = points[0]
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.4, 0.6))
        src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, shilian_ruqinzhe_img)
    if points:
        pos = points[0]
        randint_x = random.randint(15, 25)
        randint_y = random.randint(15, 25)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(2.6, 2.8))

        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, button_tiaozhan_shilian_img)
        if points:
            pos = points[0]
            randint_x = random.randint(10, 80)
            randint_y = random.randint(5, 20)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(2.2, 2.4))

            while True:
                time.sleep(random.uniform(settings.inverval_min, settings.inverval_max))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, jineng_huoba_img)
                if points:
                    pos_huoba = points[0]
                    for i in range(60):
                        time.sleep(random.uniform(0.2, 0.3))
                        src_img = window_capture(hwnd, x, y)
                        left = 0
                        top = 0
                        w = 970
                        h = 400
                        opponent_img = src_img[top:top + h, left:left + w]
                        points = get_match_points(opponent_img, biaoqing_wenhao_img, threshold=0.8)
                        if points:
                            pos_biaoqing = points[0]
                            # 点火把技能
                            randint_x = random.randint(0, 5)
                            randint_y = random.randint(0, 5)
                            window_click(hwnd, pos_huoba, randint_x, randint_y)
                            time.sleep(random.uniform(1.2, 1.4))
                            # 点目标怪物
                            px, py = pos_biaoqing
                            pos = (px - 75, py + 80)
                            randint_x = random.randint(0, 1)
                            randint_y = random.randint(0, 1)
                            window_click(hwnd, pos, randint_x, randint_y)
                            time.sleep(random.uniform(1.2, 1.4))
                            # 点自动战斗
                            pos = (2846 - 1927, 682 - 193)
                            randint_x = random.randint(0, 10)
                            randint_y = random.randint(0, 10)
                            window_click(hwnd, pos, randint_x, randint_y)
                            break

                points = get_match_points(src_img, quxiaozidong_img)
                if points:
                    continue
                points = get_match_points(src_img, zidong_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(0, 10)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    continue
                time.sleep(random.uniform(1.2, 1.4))
                break

    src_img = window_capture(hwnd, x, y)
    points = get_match_points(src_img, shilian_yiyu_img)
    if points:
        pos = points[0]
        randint_x = random.randint(0, 10)
        randint_y = random.randint(5, 15)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(2.6, 2.8))

        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, button_tiaozhan_shilian_img)
        if points:
            pos = points[0]
            randint_x = random.randint(10, 80)
            randint_y = random.randint(5, 20)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(2.2, 2.4))

            while True:
                time.sleep(random.uniform(settings.inverval_min, settings.inverval_max))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, jineng_huoba_img)
                if points:
                    pos_huoba = points[0]
                    for i in range(60):
                        time.sleep(random.uniform(0.2, 0.3))
                        src_img = window_capture(hwnd, x, y)
                        left = 0
                        top = 0
                        w = 970
                        h = 400
                        opponent_img = src_img[top:top + h, left:left + w]
                        points = get_match_points(opponent_img, biaoqing_wenhao_img, threshold=0.8)
                        if points:
                            pos_biaoqing = points[0]
                            # 点火把技能
                            randint_x = random.randint(0, 5)
                            randint_y = random.randint(0, 5)
                            window_click(hwnd, pos_huoba, randint_x, randint_y)
                            time.sleep(random.uniform(1.2, 1.4))
                            # 点目标怪物
                            px, py = pos_biaoqing
                            pos = (px - 75, py + 80)
                            randint_x = random.randint(0, 1)
                            randint_y = random.randint(0, 1)
                            window_click(hwnd, pos, randint_x, randint_y)
                            time.sleep(random.uniform(1.2, 1.4))
                            # 点自动战斗
                            pos = (2846 - 1927, 682 - 193)
                            randint_x = random.randint(0, 10)
                            randint_y = random.randint(0, 10)
                            window_click(hwnd, pos, randint_x, randint_y)
                            break

                points = get_match_points(src_img, quxiaozidong_img)
                if points:
                    continue
                points = get_match_points(src_img, zidong_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(0, 10)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    continue
                time.sleep(random.uniform(1.2, 1.4))
                break

    # 退出
    time.sleep(random.uniform(4.8, 5.2))
    pos = (2836 - 1927, 649 - 156)
    randint_x = random.randint(0, 5)
    randint_y = random.randint(0, 5)
    window_click(hwnd, pos, randint_x, randint_y)
예제 #27
0
파일: zudui.py 프로젝트: ulimit65535/sw4
def join(hwnd, x, y, is_leader, member_waiting=80):
    if is_leader:
        # duiwu_zhankai_img = cv2.cvtColor(cv2.imread("src/duiwu_zhankai.png"), cv2.COLOR_BGR2GRAY)
        button_renwu_img = cv2.cvtColor(cv2.imread("src/button_renwu.png"),
                                        cv2.COLOR_BGR2GRAY)
        chuangjianduiwu_img = cv2.cvtColor(
            cv2.imread("src/chuangjianduiwu.png"), cv2.COLOR_BGR2GRAY)
        button_yaoqing_img = cv2.cvtColor(cv2.imread("src/button_yaoqing.png"),
                                          cv2.COLOR_BGR2GRAY)
        member1_img = cv2.cvtColor(cv2.imread("src/replace/member1.png"),
                                   cv2.COLOR_BGR2GRAY)
        member2_img = cv2.cvtColor(cv2.imread("src/replace/member2.png"),
                                   cv2.COLOR_BGR2GRAY)
        member3_img = cv2.cvtColor(cv2.imread("src/replace/member3.png"),
                                   cv2.COLOR_BGR2GRAY)
        member4_img = cv2.cvtColor(cv2.imread("src/replace/member4.png"),
                                   cv2.COLOR_BGR2GRAY)
        button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                        cv2.COLOR_BGR2GRAY)
        xinxi_close_img = cv2.cvtColor(cv2.imread("src/xinxi_close.png"),
                                       cv2.COLOR_BGR2GRAY)
        icon_member_invite_img = cv2.cvtColor(
            cv2.imread("src/icon_member_invite.png"), cv2.COLOR_BGR2GRAY)

        # 若锁屏,则解锁
        public.jiesuo(hwnd, x, y)

        src_img = window_capture(hwnd, x, y)

        points = get_match_points(src_img, button_close_img)
        if points:
            # 误点到战备,或者NPC对话,关闭
            pos = points[0]
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.5, 0.6))
            src_img = window_capture(hwnd, x, y)

        points = get_match_points(src_img, button_renwu_img, threshold=0.8)
        if not points:
            # 展开任务列表
            pos = (2863 - 1927, 303 - 193)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.6, 0.8))

        # 打开队伍界面
        pos = (2800 - 1927, 265 - 156)
        randint_x = random.randint(0, 20)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.8, 1.0))

        src_img = window_capture(hwnd, x, y)

        points = get_match_points(src_img, chuangjianduiwu_img)
        if points:
            pos = points[0]
            randint_x = random.randint(25, 60)
            randint_y = random.randint(-10, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.8, 1.2))
            has_invite = False
            # 邀请队员
            pos = (2137 - 1927, 392 - 193)
            randint_x = random.randint(0, 50)
            randint_y = random.randint(0, 20)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.4, 1.6))
            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_yaoqing_img)
            if points:
                has_invite = True
                # # 合区后卡,多等待一断时间
                time.sleep(waiting_for_refresh * 2)
                src_img = window_capture(hwnd, x, y)
                points1 = get_match_points(src_img,
                                           member1_img,
                                           threshold=0.85)
                points2 = get_match_points(src_img,
                                           member2_img,
                                           threshold=0.85)
                points3 = get_match_points(src_img,
                                           member3_img,
                                           threshold=0.85)
                points4 = get_match_points(src_img,
                                           member4_img,
                                           threshold=0.85)
                if points1:
                    px, py = points1[0]
                    pos = (px + 95, py + 13)
                    randint_x = random.randint(0, 40)
                    randint_y = random.randint(0, 20)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.1, 0.15))
                if points3:
                    px, py = points3[0]
                    pos = (px + 95, py + 13)
                    randint_x = random.randint(0, 40)
                    randint_y = random.randint(0, 20)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.1, 0.15))
                if points4:
                    points_before = []
                    for px, py in points4:
                        is_exist = False
                        for point_before in points_before:
                            px_before, py_before = point_before
                            if abs(px - px_before) <= 10 and abs(
                                    py - py_before) <= 10:
                                is_exist = True
                                break
                        if not is_exist:
                            points_before.append((px, py))
                            pos = (px + 95, py + 13)
                            randint_x = random.randint(0, 40)
                            randint_y = random.randint(0, 20)
                            window_click(hwnd, pos, randint_x, randint_y)
                            time.sleep(random.uniform(0.1, 0.15))
                if points2:
                    if points3 or points4:
                        # 保证第三个大号,最后一个进队.龙阵五号位
                        time.sleep(random.uniform(2.8, 3.2))
                    px, py = points2[0]
                    pos = (px + 95, py + 13)
                    randint_x = random.randint(0, 40)
                    randint_y = random.randint(0, 20)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.1, 0.15))
                time.sleep(random.uniform(0.2, 0.3))
                # 关闭邀请窗口
                pos = (2639 - 1927, 294 - 193)
                randint_x = random.randint(0, 15)
                randint_y = random.randint(0, 15)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.5, 0.6))

                if settings.zudui_zhenfa_num > 0:
                    # 切换到阵法选择
                    pos = (2668 - 1927, 225 - 156)
                    randint_x = random.randint(0, 50)
                    randint_y = random.randint(0, 15)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.5, 0.6))
                    # 切换到对应阵法
                    pos = (2687 - 1927,
                           297 - 156 + 34 * settings.zudui_zhenfa_num)
                    randint_x = random.randint(0, 50)
                    randint_y = random.randint(0, 15)
                    window_click(hwnd, pos, randint_x, randint_y)
                    """
                    # 跨服等待时间
                    time.sleep(random.uniform(2.8, 3.2))
                    # 龙飞阵调位置
                    pos = (2550 - 1927, 480 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.4, 0.5))
                    pos = (2605 - 1927, 401 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                    """
                    time.sleep(random.uniform(1.4, 1.6))
            else:
                # 关闭邀请窗口
                pos = (2639 - 1927, 294 - 193)
                randint_x = random.randint(0, 15)
                randint_y = random.randint(0, 15)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.5, 0.6))

            if not has_invite:
                # 未邀请到任何队员,退出队伍
                pos = (2091 - 1927, 217 - 156)
                randint_x = random.randint(25, 60)
                randint_y = random.randint(5, 15)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.8, 1.0))
        else:
            print("已在队伍中,无需创建队伍.")
            time.sleep(random.uniform(0.5, 0.6))

        # 关闭队伍窗口
        src_img = window_capture(hwnd, x, y)

        # 查看队伍中的人数
        points = get_match_points(src_img, icon_member_invite_img)
        team_num = 0
        if points:
            x, y = points[0]
            if y < 374 - 156:
                team_num = 1
            elif y < 453 - 156:
                team_num = 2
            elif y < 532 - 156:
                team_num = 3
            else:
                team_num = 4
        else:
            team_num = 5

        points = get_match_points(src_img, xinxi_close_img, threshold=0.8)
        if points:
            pos = points[0]
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.5, 0.6))
            pos = (2725 - 1927, 270 - 156)
            randint_x = random.randint(0, 10)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
        return team_num
    else:
        #duiwu_zhankai_img = cv2.cvtColor(cv2.imread("src/duiwu_zhankai.png"), cv2.COLOR_BGR2GRAY)
        guidui_img = cv2.cvtColor(cv2.imread("src/guidui.png"),
                                  cv2.COLOR_BGR2GRAY)
        likaiduiwu_img = cv2.cvtColor(cv2.imread("src/likaiduiwu.png"),
                                      cv2.COLOR_BGR2GRAY)
        leader_img = cv2.cvtColor(cv2.imread("src/replace/leader.png"),
                                  cv2.COLOR_BGR2GRAY)
        button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                        cv2.COLOR_BGR2GRAY)
        xinxi_close_img = cv2.cvtColor(cv2.imread("src/xinxi_close.png"),
                                       cv2.COLOR_BGR2GRAY)
        button_renwu_img = cv2.cvtColor(cv2.imread("src/button_renwu.png"),
                                        cv2.COLOR_BGR2GRAY)

        # 若锁屏,则解锁
        public.jiesuo(hwnd, x, y)

        src_img = window_capture(hwnd, x, y)

        points = get_match_points(src_img, button_close_img)
        if points:
            # 误点到战备,或者NPC对话,关闭
            pos = points[0]
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.5, 0.6))
            src_img = window_capture(hwnd, x, y)

        points = get_match_points(src_img, button_renwu_img, threshold=0.8)
        if not points:
            # 展开任务列表
            pos = (2863 - 1927, 303 - 193)
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.6, 0.8))

        # 打开队伍界面
        pos = (2800 - 1927, 265 - 156)
        randint_x = random.randint(0, 20)
        randint_y = random.randint(0, 10)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.8, 1.0))

        src_img = window_capture(hwnd, x, y)

        # 如果已在队伍中,离开队伍
        points = get_match_points(src_img, likaiduiwu_img)
        if not points:
            # 点队伍信息
            pos = (2566 - 1927, 259 - 193)
            randint_x = random.randint(0, 50)
            randint_y = random.randint(0, 20)
            window_click(hwnd, pos, randint_x, randint_y)

            for i in range(member_waiting):
                time.sleep(0.2)
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, leader_img)
                if points:
                    px, py = points[0]
                    pos = (px + 95, py + 11)
                    randint_x = random.randint(5, 50)
                    randint_y = random.randint(5, 20)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(1.0, 1.2))
                    # 如需归队,归队
                    src_img = window_capture(hwnd, x, y)
                    points = get_match_points(src_img, guidui_img)
                    if points:
                        pos = points[0]
                        randint_x = random.randint(5, 70)
                        randint_y = random.randint(5, 20)
                        window_click(hwnd, pos, randint_x, randint_y)
                        time.sleep(random.uniform(0.8, 1.0))
                    break

        # 关闭队伍窗口
        src_img = window_capture(hwnd, x, y)
        points = get_match_points(src_img, xinxi_close_img, threshold=0.8)
        if points:
            pos = points[0]
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(0.5, 0.6))
            pos = (2725 - 1927, 270 - 156)
            randint_x = random.randint(0, 10)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
        return
예제 #28
0
def zhuxian(hwnd, x, y):
    duihua_img = cv2.cvtColor(cv2.imread("src/duihua.png"), cv2.COLOR_BGR2GRAY)
    duihua_any_img = cv2.cvtColor(cv2.imread("src/duihua_any.png"),
                                  cv2.COLOR_BGR2GRAY)
    choice_any_img = cv2.cvtColor(cv2.imread("src/choice_any.png"),
                                  cv2.COLOR_BGR2GRAY)
    tiaoguo_img = cv2.cvtColor(cv2.imread("src/tiaoguo.png"),
                               cv2.COLOR_BGR2GRAY)
    button_yijianxuexi_img = cv2.cvtColor(
        cv2.imread("src/button_yijianxuexi.png"), cv2.COLOR_BGR2GRAY)
    close_shouchong_img = cv2.cvtColor(cv2.imread("src/close_shouchong.png"),
                                       cv2.COLOR_BGR2GRAY)
    qitian_close_img = cv2.cvtColor(cv2.imread("src/qitian_close.png"),
                                    cv2.COLOR_BGR2GRAY)
    button_qianwang_img = cv2.cvtColor(cv2.imread("src/button_qianwang.png"),
                                       cv2.COLOR_BGR2GRAY)

    lower = np.array([20, 150, 140], dtype="uint8")
    upper = np.array([80, 240, 255], dtype="uint8")

    renwu_zhuxian_img_color = cv2.cvtColor(cv2.imread("src/renwu_zhuxian.png"),
                                           cv2.IMREAD_COLOR)
    mask = cv2.inRange(renwu_zhuxian_img_color, lower, upper)
    renwu_zhuxian_img_color = cv2.bitwise_and(renwu_zhuxian_img_color,
                                              renwu_zhuxian_img_color,
                                              mask=mask)
    renwu_zhuxian_img = cv2.cvtColor(renwu_zhuxian_img_color,
                                     cv2.COLOR_BGR2GRAY)

    renwu_yindao_img_color = cv2.cvtColor(cv2.imread("src/renwu_yindao.png"),
                                          cv2.IMREAD_COLOR)
    mask = cv2.inRange(renwu_yindao_img_color, lower, upper)
    renwu_yindao_img_color = cv2.bitwise_and(renwu_yindao_img_color,
                                             renwu_yindao_img_color,
                                             mask=mask)
    renwu_yindao_img = cv2.cvtColor(renwu_yindao_img_color, cv2.COLOR_BGR2GRAY)

    renwu_shimen_img_color = cv2.cvtColor(cv2.imread("src/renwu_shimen.png"),
                                          cv2.IMREAD_COLOR)
    mask = cv2.inRange(renwu_shimen_img_color, lower, upper)
    renwu_shimen_img_color = cv2.bitwise_and(renwu_shimen_img_color,
                                             renwu_shimen_img_color,
                                             mask=mask)
    renwu_shimen_img = cv2.cvtColor(renwu_shimen_img_color, cv2.COLOR_BGR2GRAY)

    #cv2.namedWindow("Image")
    #cv2.imshow("Image", renwu_huoban_img)
    #cv2.waitKey(0)
    #sys.exit(1)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    while True:

        time.sleep(random.uniform(settings.inverval_min,
                                  settings.inverval_max))

        src_img = window_capture(hwnd, x, y)

        # 未知选项,选第一个
        points = get_match_points(src_img, choice_any_img)
        if points:
            min_y = 1000
            for point in points:
                x, y = point
                if y < min_y:
                    pos_choice = point
                    min_y = y

            randint_x = random.randint(5, 25)
            randint_y = random.randint(5, 15)
            window_click(hwnd, pos_choice, randint_x, randint_y)
            continue

        # 未知对话,选第一个
        points = get_match_points(src_img, duihua_any_img)
        if points:
            min_y = 1000
            for point in points:
                x, y = point
                if y < min_y:
                    pos_duihua = point
                    min_y = y

            px, py = pos_duihua
            pos = (px - 80, py + 20)
            randint_x = random.randint(0, 80)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 点一键学习
        points = get_match_points(src_img, button_yijianxuexi_img)
        if points:
            pos = points[0]
            randint_x = random.randint(20, 50)
            randint_y = random.randint(5, 15)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 点前往
        points = get_match_points(src_img, button_qianwang_img)
        if points:
            pos = points[0]
            randint_x = random.randint(20, 50)
            randint_y = random.randint(5, 15)
            window_click(hwnd, pos, randint_x, randint_y)
            print("20级,结束主线。")
            return

        # 关闭首充
        points = get_match_points(src_img, close_shouchong_img)
        if points:
            pos = points[0]
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 7天奖励,关闭
        points = get_match_points(src_img, qitian_close_img)
        if points:
            pos = points[0]
            randint_x = random.randint(2, 7)
            randint_y = random.randint(5, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 点跳过
        points = get_match_points(src_img, tiaoguo_img, threshold=0.8)
        if points:
            pos = points[0]
            randint_x = random.randint(20, 50)
            randint_y = random.randint(10, 20)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 点击对话
        points = get_match_points(src_img, duihua_img, threshold=0.95)
        if points:
            pos = (812, 154)
            randint_x = random.randint(0, 100)
            randint_y = random.randint(0, 30)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 是否在移动中?
        status = public.get_status(hwnd, x, y, src_img)

        if status != "standing":
            continue

        public.show_menu_renwu(hwnd, x, y)

        # 优先查找任务栏显示
        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        # 注意点怪的时候,Y最多向上移25-30个像素,不然会点开人物界面
        left = 770
        top = 140
        w = 100
        h = 250
        opponent_img = src_img[top:top + h, left:left + w]
        mask = cv2.inRange(opponent_img, lower, upper)
        opponent_img = cv2.bitwise_and(opponent_img, opponent_img, mask=mask)
        opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

        points = get_match_points(opponent_img,
                                  renwu_shimen_img,
                                  threshold=0.7)
        if points:
            # 点击任务栏任务
            px, py = points[0]
            # px, py是相对于opponent_img的坐标,所以还要加上left和top
            pos = (px + 770 + 70, py + 140 + 15)
            randint_x = random.randint(0, 20)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        points = get_match_points(opponent_img,
                                  renwu_yindao_img,
                                  threshold=0.7)
        if points:
            # 点击任务栏任务
            px, py = points[0]
            # px, py是相对于opponent_img的坐标,所以还要加上left和top
            pos = (px + 770 + 70, py + 140 + 15)
            randint_x = random.randint(0, 20)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        points = get_match_points(opponent_img,
                                  renwu_zhuxian_img,
                                  threshold=0.7)
        if points:
            # 点击任务栏任务
            px, py = points[0]
            # px, py是相对于opponent_img的坐标,所以还要加上left和top
            pos = (px + 770 + 70, py + 140 + 15)
            randint_x = random.randint(0, 20)
            randint_y = random.randint(0, 10)
            window_click(hwnd, pos, randint_x, randint_y)
            continue
예제 #29
0
def fengyao_unlimited(hwnd, x, y):
    yuangu_img_color = cv2.cvtColor(cv2.imread("src/yuangu.png"),
                                    cv2.IMREAD_COLOR)
    lower = np.array([24, 160, 180], dtype="uint8")
    upper = np.array([67, 230, 255], dtype="uint8")
    mask = cv2.inRange(yuangu_img_color, lower, upper)
    yuangu_img_color = cv2.bitwise_and(yuangu_img_color,
                                       yuangu_img_color,
                                       mask=mask)
    yuangu_img = cv2.cvtColor(yuangu_img_color, cv2.COLOR_BGR2GRAY)

    duihua_fengyao_img = cv2.cvtColor(cv2.imread("src/duihua_fengyao.png"),
                                      cv2.COLOR_BGR2GRAY)
    duiwu_yincang_img = cv2.cvtColor(cv2.imread("src/duiwu_yincang.png"),
                                     cv2.COLOR_BGR2GRAY)
    #fengyao_end_img = cv2.cvtColor(cv2.imread("src/fengyao_end.png"), cv2.COLOR_BGR2GRAY)
    yuangu_choice_img = cv2.cvtColor(cv2.imread("src/yuangu_choice.png"),
                                     cv2.COLOR_BGR2GRAY)
    #button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"), cv2.COLOR_BGR2GRAY)
    fengyao_bielaidarao_img = cv2.cvtColor(
        cv2.imread("src/fengyao_bielaidarao.png"), cv2.COLOR_BGR2GRAY)

    button_queding_img = cv2.cvtColor(cv2.imread("src/button_queding.png"),
                                      cv2.COLOR_BGR2GRAY)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    src_img = window_capture(hwnd, x, y)

    # 隐藏任务列表
    points = get_match_points(src_img, duiwu_yincang_img)
    if points:
        pos = points[0]
        randint_x = random.randint(0, 5)
        randint_y = random.randint(0, 5)
        window_click(hwnd, pos, randint_x, randint_y)
        time.sleep(random.uniform(0.6, 0.8))

    num_standing = 0
    while True:
        time.sleep(random.uniform(settings.inverval_min,
                                  settings.inverval_max))

        src_img = window_capture(hwnd, x, y)

        status = public.get_status(hwnd,
                                   x,
                                   y,
                                   src_img,
                                   with_standing=False,
                                   npc_jiaohu=False)
        if status == "in_battle":
            continue

        # 隐藏任务列表
        points = get_match_points(src_img, duiwu_yincang_img)
        if points:
            pos = points[0]
            randint_x = random.randint(0, 5)
            randint_y = random.randint(0, 5)
            window_click(hwnd, pos, randint_x, randint_y)
            continue

        # 继续点香
        points = get_match_points(src_img, button_queding_img)
        if points:
            pos = points[0]
            randint_x = random.randint(10, 80)
            randint_y = random.randint(5, 20)
            window_click(hwnd, pos, randint_x, randint_y)
            time.sleep(random.uniform(1.8, 2.2))
            continue

        src_img = window_capture(hwnd, x, y, color=cv2.IMREAD_COLOR)
        # 注意点怪的时候,Y最多向上移25-30个像素,不然会点开人物界面

        left = 151
        top = 115
        w = 740
        h = 280
        opponent_img = src_img[top:top + h, left:left + w]

        #cv2.namedWindow("Image")
        #cv2.imshow("Image", opponent_img)
        #cv2.waitKey(0)
        #sys.exit(1)

        lower = np.array([24, 160, 180], dtype="uint8")
        upper = np.array([67, 230, 255], dtype="uint8")
        mask = cv2.inRange(opponent_img, lower, upper)
        opponent_img = cv2.bitwise_and(opponent_img, opponent_img, mask=mask)
        opponent_img = cv2.cvtColor(opponent_img, cv2.COLOR_BGR2GRAY)

        points = get_match_points(opponent_img, yuangu_img, threshold=0.4)
        if points:
            # 计数重置
            num = 0
            px, py = points[0]
            # px, py是相对于opponent_img的坐标,所以还要加上left和top
            pos = (px + 151 + 35, py + 115 - 25)
            randint_x = random.randint(0, 2)
            randint_y = random.randint(0, 2)
            window_click(hwnd, pos, randint_x, randint_y)

            # 最多等待2.5秒
            for i in range(10):
                time.sleep(random.uniform(0.2, 0.3))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img,
                                          yuangu_choice_img,
                                          threshold=0.98)
                if points:
                    # 怪站一起了,需要选择
                    pos = points[0]
                    randint_x = random.randint(5, 90)
                    randint_y = random.randint(5, 20)
                    window_click(hwnd, pos, randint_x, randint_y)
                    continue
                points = get_match_points(src_img, duihua_fengyao_img)
                if points:
                    # 开打
                    pos = (2604 - 1927, 522 - 193)
                    randint_x = random.randint(0, 80)
                    randint_y = random.randint(0, 20)
                    window_click(hwnd, pos, randint_x, randint_y)
                    break

            for i in range(4):
                time.sleep(random.uniform(0.2, 0.3))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, fengyao_bielaidarao_img)
                if points:
                    pos = (2856 - 1927, 233 - 193)
                    randint_x = random.randint(0, 10)
                    randint_y = random.randint(0, 10)
                    window_click(hwnd, pos, randint_x, randint_y)
                    print("进入战斗失败")
                    break
        else:
            # 是否在移动中?
            src_img = window_capture(hwnd, x, y)
            status = public.get_status(hwnd, x, y, src_img, npc_jiaohu=False)

            if status == "yanzheng_failed":
                senddata("窗口:{}验证失败,退出。".format(hwnd), "")
                return

            if status != "standing":
                num_standing = 0
                continue
            else:
                num_standing += 1
                if num_standing <= 1:
                    continue

            # 开始巡逻
            result = public.xunluo(hwnd, x, y)
            if not result:
                print("巡逻失败,退出")
                return
예제 #30
0
def huanjing_kaixiang(hwnd, x, y, is_leader):
    button_queding_huanjing_img = cv2.cvtColor(
        cv2.imread("src/button_queding_huanjing.png"), cv2.COLOR_BGR2GRAY)
    button_zanli_img = cv2.cvtColor(cv2.imread("src/button_zanli.png"),
                                    cv2.COLOR_BGR2GRAY)
    button_guidui_img = cv2.cvtColor(cv2.imread("src/button_guidui.png"),
                                     cv2.COLOR_BGR2GRAY)
    button_close_img = cv2.cvtColor(cv2.imread("src/button_close.png"),
                                    cv2.COLOR_BGR2GRAY)

    # 若锁屏,则解锁
    public.jiesuo(hwnd, x, y)

    if is_leader:
        while True:
            time.sleep(
                random.uniform(settings.inverval_min, settings.inverval_max))

            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_queding_huanjing_img)
            if points:
                time.sleep(random.uniform(3.8, 4.2))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_close_img)
                if points:
                    pos = points[0]
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
    else:
        # 切换到队伍显示
        public.show_menu_duiwu(hwnd, x, y)

        # 开箱时队员暂离,注意需要任务列表需要切换到队伍界面,方便离队归队
        while True:
            time.sleep(
                random.uniform(settings.inverval_min, settings.inverval_max))

            src_img = window_capture(hwnd, x, y)
            points = get_match_points(src_img, button_queding_huanjing_img)
            if points:
                # 取消弹窗
                pos = (2852 - 1927, 339 - 156)
                randint_x = random.randint(0, 5)
                randint_y = random.randint(0, 5)
                window_click(hwnd, pos, randint_x, randint_y)
                time.sleep(random.uniform(0.8, 1.2))
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_zanli_img)
                if points:
                    pos = (2852 - 1927, 339 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(4.8, 5.2))
                else:
                    # 点下队伍
                    pos = (2852 - 1927, 339 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.8, 1.2))
                    src_img = window_capture(hwnd, x, y)
                    points = get_match_points(src_img, button_zanli_img)
                    if points:
                        pos = (2852 - 1927, 339 - 156)
                        randint_x = random.randint(0, 5)
                        randint_y = random.randint(0, 5)
                        window_click(hwnd, pos, randint_x, randint_y)
                        time.sleep(random.uniform(4.8, 5.2))
                    else:
                        print("暂离失败,退出")
                        return
                src_img = window_capture(hwnd, x, y)
                points = get_match_points(src_img, button_guidui_img)
                if points:
                    pos = (2852 - 1927, 339 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                else:
                    # 点下队伍
                    pos = (2852 - 1927, 339 - 156)
                    randint_x = random.randint(0, 5)
                    randint_y = random.randint(0, 5)
                    window_click(hwnd, pos, randint_x, randint_y)
                    time.sleep(random.uniform(0.8, 1.2))
                    src_img = window_capture(hwnd, x, y)
                    points = get_match_points(src_img, button_guidui_img)
                    if points:
                        pos = (2852 - 1927, 339 - 156)
                        randint_x = random.randint(0, 5)
                        randint_y = random.randint(0, 5)
                        window_click(hwnd, pos, randint_x, randint_y)
                    else:
                        print("归队失败,退出")
                        return