Ejemplo n.º 1
0
def main():
    start_time = time.time()
    f = open('Kakilog.log', 'a+', encoding='utf-8')
    now = datetime.now()
    print("Log started: ", now, file=f)
    # read config file
    config = configparser.ConfigParser()
    try:
        config.read('config.ini', encoding='utf-8')
    except:
        config.read('config.ini', encoding='utf-8-sig')

    title = 'KakiRaid'
    if int(config['DEFAULT']['AdjustWindow']) == 1:
        General.adjust_window(title, [0, 0])
        time.sleep(0.2)
    elif int(config['DEFAULT']['AdjustWindow']) == 2:
        General.adjust_window(title, [245, 123])
        time.sleep(0.2)
    window = General.get_window_coordinate(title)  # x, y, w, h
    time.sleep(0.2)
    window.append(start_time)  # index 4

    auto_legend_count = int(config['DEFAULT']['AutoLegendCount'])
    if int(config['DEFAULT']['ModeSelection']) == 0:
        count = 0
        max_count = int(config['DEFAULT']['MainLoopCount'])
        current_floor = 0
        stat = dict()
        stat['Total_Resources'] = 0
        stat['Total_Monster'] = 0
        stat['Total_Loot_Curse'] = 0
        stat['Total_Loot_Other'] = 0
        stat['Total_Camp'] = 0
        stat['Total_Ruin'] = 0
        window.append(stat)  # index 5
        window.append(config)  # index 6
        window.append(f)
        keys = [
            window[6]['Baidu_API']['API_ID'],
            window[6]['Baidu_API']['API_KEY'],
            window[6]['Baidu_API']['SECRET_KEY']
        ]
        # while count < max_count:
        thread_1 = threading.Thread(target=General.click_continue,
                                    args=(window, ))
        thread_1.start()
        while True:
            print('\n', file=f)
            f.flush()
            temp_start_time = time.time()
            General.failure_detect(window)  # thread
            curse_page_result = General.curse_page_detect(window,
                                                          400)  # thread
            if not curse_page_result:
                while General.confirm_detect(window):
                    time.sleep(1)
                time.sleep(0.5)
            else:
                curse_images = General.get_curse_image(window)
                curses = General.parse_curse_image(curse_images, keys)
                if curses != [0, 0, 0]:
                    General.select_curse(window, curses)
                    time.sleep(2.5)
                    while General.resource_completion_detect(window):
                        time.sleep(1.5)
                        General.resource_completion_click(window)
                else:
                    print("Baidu ocr failed!", file=f)
                    sys.exit()
            time.sleep(0.2)

            if General.start_floor_detect(window):
                # General.map_page_detect(window)  # thread
                # while General.resource_completion_detect(window):
                #     time.sleep(1)
                General.map_management(window)
                General.toggle_auto_path_finding(window)
                General.map_page_detect(window)
                elapsed_time = time.time() - temp_start_time
                print("Curse " + str(count) + " selected!", file=f)
                print('time elapsed: ' + str(elapsed_time) + ' seconds.',
                      file=f)
                time.sleep(7)
            General.map_page_detect(window, 2)
            if not General.auto_route_detect(window):
                time.sleep(1.5)
                if not General.auto_route_detect(window):
                    General.toggle_auto_path_finding(window)

            count += 1

            if current_floor == 0:
                current_floor = General.floor_detection(window)
            else:
                current_floor += 5
                print('Current Floor: ' + str(current_floor) + '\n', file=f)
                f.flush()
            time.sleep(1)
    elif int(config['DEFAULT']['ModeSelection']) == 1:
        General.auto_legend(window, auto_legend_count)
    elif int(config['DEFAULT']['ModeSelection']) == 2:
        thread_1 = threading.Thread(target=General.click_continue,
                                    args=(window, ))
        thread_1.start()
        grind_count = int(config['Void_Island']['Count'])
        if grind_count == 0:
            grind_count = 9999
        window.append(f)
        while grind_count > 0:
            General.void_island_grind(window)
            print('Void Island Completed', file=f)
            f.flush()
            grind_count -= 1
Ejemplo n.º 2
0
def main():
    start_time = time.time()
    f = open('Kakilog.log', 'a+', encoding='utf-8')
    now = datetime.now()
    print("Log started: ", now, file=f)
    # read config file
    config = configparser.ConfigParser()
    try:
        config.read('config.ini', encoding='utf-8')
    except:
        config.read('config.ini', encoding='utf-8-sig')

    title = 'KakiRaid'
    if int(config['DEFAULT']['AdjustWindow']) == 1:
        General.adjust_window(title, [0, 0])
    elif int(config['DEFAULT']['AdjustWindow']) == 2:
        General.adjust_window(title, [245, 123])
    window = General.get_window_coordinate(title)  # x, y, w, h
    window.append(start_time)  # index 4

    auto_legend_count = int(config['DEFAULT']['AutoLegendCount'])
    if int(config['DEFAULT']['ModeSelection']) == 0:
        count = 0
        max_count = int(config['DEFAULT']['MainLoopCount'])
        current_floor = 0
        stat = dict()
        stat['Total_Resources'] = 0
        stat['Total_Monster'] = 0
        stat['Total_Loot_Curse'] = 0
        stat['Total_Loot_Other'] = 0
        stat['Total_Camp'] = 0
        stat['Total_Ruin'] = 0
        window.append(stat)  # index 5
        window.append(config)  # index 6
        window.append(f)
        keys = [
            window[6]['Baidu_API']['API_ID'],
            window[6]['Baidu_API']['API_KEY'],
            window[6]['Baidu_API']['SECRET_KEY']
        ]
        while count < max_count:
            print('\n', file=f)
            f.flush()
            temp_start_time = time.time()
            if count != 0:
                if current_floor > 500:
                    time.sleep(130)
                elif current_floor > 400:
                    time.sleep(120)
                elif current_floor > 300:
                    time.sleep(95)
                elif current_floor > 200:
                    time.sleep(85)
                else:
                    time.sleep(75)
            General.failure_detect(window)
            curse_page_result = General.curse_page_detect(window)
            if not curse_page_result:
                stuck_result = General.stuck_detect(window)
                curse_page_result = General.curse_page_detect(
                    window, 400)  # 400 as count to bypass repeated detect
                while stuck_result != 0 and not curse_page_result:
                    if stuck_result == 1:
                        # To add support for network turbulence and portal stuck?
                        print('Progress stuck at unknown, quitting program..',
                              file=f)
                        f.close()
                        General.send_email('Kaki script stuck, quit program.')
                        sys.exit()
                    elif stuck_result == 2:
                        print(
                            'Progress stuck at relic augmentation, try resolving..',
                            file=f)
                        pyautogui.click(x=window[0] + (320 - 245),
                                        y=window[1] + (213 - 123),
                                        duration=0.1)
                        stuck_result = General.stuck_detect(window)
                        if stuck_result == 1:
                            General.toggle_auto_path_finding(window)
                            stuck_result = General.stuck_detect(window)
                        else:
                            stuck_result = 0
            else:
                curse_images = General.get_curse_image(window)
                curses = General.parse_curse_image(curse_images, keys)
                General.select_curse(window, curses)
            General.resource_completion_detect(window)
            General.map_management(window)
            elapsed_time = time.time() - temp_start_time
            count += 1
            print("Curse " + str(count) + " selected!", file=f)
            print('time elapsed: ' + str(elapsed_time) + ' seconds.', file=f)
            time.sleep(10)
            if current_floor == 0:
                current_floor = General.floor_detection(window)
            else:
                current_floor += 5
                print('Current Floor: ' + str(current_floor) + '\n', file=f)
        f.close()
        General.send_email('Kaki script quit with time out')
        print('Quit with time out')
    elif int(config['DEFAULT']['ModeSelection']) == 1:
        General.auto_legend(window, auto_legend_count)
    elif int(config['DEFAULT']['ModeSelection']) == 2:
        grind_count = int(config['Void_Island']['Count'])
        if grind_count == 0:
            grind_count = 9999
        while grind_count > 0:
            General.void_island_grind(window)
            print('Void Island Completed', file=f)
            f.flush()
            grind_count -= 1