Example #1
0
def check_ap(hWnd, op_delay, n):
    if game.has_select_box(hWnd):
        # 点击确定
        while not game.press_button_ok(hWnd):
            win32_helper.wait(op_delay)

        # 吃4次AP药
        nsucceed = 0
        for i in range(n):
            if not game.press_button_use_ap(hWnd):
                break

            while not game.has_select_box(hWnd):
                game.press_button_use_ap(hWnd)
                win32_helper.wait(op_delay)

            while not game.press_button_ok(hWnd):
                win32_helper.wait(op_delay)

            nsucceed = nsucceed + 1

        # 点击交叉
        while not game.press_button_cross(hWnd):
            win32_helper.wait(op_delay)

        return nsucceed
    else:
        return -1
Example #2
0
def press_button_aux(hWnd, name, bcheck, thr=k_thr, op_delay=k_op_delay):
    if name not in k_button_img:
        k_button_img[name] = cv2.imread(k_button_path[name])
    template = k_button_img[name]
    while 1:
        ret, val = press_button(hWnd, template, thr)
        win32_helper.wait(op_delay)
        if not bcheck or not has_button(hWnd, template, thr)[0]:
            break
    if ret:
        print('press button {0}, val = {1}'.format(name, val))
    else:
        print('no find button {0}, val = {1}'.format(name, val))
    return ret
Example #3
0
def press_button_use_ap(hWnd, thr=k_thr, op_delay=k_op_delay):
    name = 'use'
    if name not in k_button_img:
        k_button_img[name] = cv2.imread(k_button_path[name])
    button_img = k_button_img[name]

    old_hWnd = win32gui.GetForegroundWindow()

    img = win32_helper.screenshot(hWnd)
    proposal = dip.template_match(img, button_img, n=4)

    button_use = []
    for i in range(4):
        if proposal[i][0] >= k_thr:
            button_use.append(proposal[i])

    def get_third(elem):
        return elem[2]

    button_use.sort(key=get_third, reverse=True)

    n = len(button_use)
    if n == 0:
        return False, proposal[0][0]

    i = button_use[0][1]
    j = button_use[0][2]
    win32_helper.send_lbutton_clk_to_window(hWnd, i + button_img.shape[1] / 2,
                                            j + button_img.shape[0] / 2)

    try:
        win32gui.SetForegroundWindow(old_hWnd)
    except:
        pass

    win32_helper.wait(op_delay)

    return True, button_use[0][0]
Example #4
0
# 使用方法 python ./tower.py 30
# 输入参为战斗时间(秒)

import sys
import game
import win32_helper

if len(sys.argv) != 2:
    print('format: python ./tower.py 战斗时间')
    exit()

hWnd = win32_helper.find_window_handle('MuMu', None, None)
hWnd = win32_helper.find_first_child_window(hWnd)

op_delay = 3

i = 0
while True:
    print('\nloop {0}'.format(i))
    i += 1

    win32_helper.send_key_to_window(hWnd, win32_helper.VK_Y)

    win32_helper.wait(op_delay)
    if game.has_select_box(hWnd):
        game.press_button_cancel(hWnd)
        continue

    game.battle(hWnd, battle_cost_times=int(sys.argv[1]))
    win32_helper.wait(14.5 * 60)
Example #5
0
def battle(hWnd, battle_cost_times, op_delay=3, battle_end_delay=6):
    # 点击挑战
    win32_helper.wait(op_delay)
    while not game.press_button_battle_start(hWnd, False):
        win32_helper.wait(battle_end_delay)

    # 吃4次AP药
    n = check_ap(hWnd, op_delay=op_delay, n=4)
    if n == 0:
        print('ap not enough!')
        return False
    elif n > 0:
        print('use ap {0} times'.format(n))
        return battle(hWnd, battle_cost_times, op_delay, battle_end_delay)
    win32_helper.wait(op_delay)

    # 等待战斗结束
    win32_helper.wait(battle_cost_times)

    # 判断是否失败
    if not is_win():
        win32_helper.wait(battle_end_delay)
        print('lost the battle!')
        return True

    # 点击略过
    while not game.press_button_skip(hWnd):
        win32_helper.wait(op_delay)
        win32_helper.wait(op_delay)

    # 点击确认
    win32_helper.wait(battle_end_delay)
    while not game.press_button_reward_check(hWnd):
        win32_helper.wait(op_delay)

        # 若没有奖励, 跳出
        if game.has_mainui_sign(hWnd):
            print('No reward')
            break

    return True
Example #6
0
def run(hWnd, key):
    for i in range(3):
        win32_helper.wait(3)
        win32_helper.send_key_to_window(hWnd, key)
        game.battle(hWnd, 40)
Example #7
0
    for i in range(3):
        win32_helper.wait(3)
        win32_helper.send_key_to_window(hWnd, key)
        game.battle(hWnd, 40)


if len(sys.argv) > 1:
    # 定时明天7点启动
    now = datetime.datetime.now()
    if int(sys.argv[1]) == 1:
        tommorow = now + datetime.timedelta(days=1, hours=31 - now.hour)
    else:
        tommorow = now + datetime.timedelta(hours=7 - now.hour)
    print('start time: {0}'.format(tommorow.strftime('%Y-%m-%d %H:%M:%S')))
    seconds = (tommorow - now).seconds
    win32_helper.wait(seconds)

hWnd = win32_helper.find_window_handle('MuMu', None, None)
hWnd = win32_helper.find_first_child_window(hWnd)

print("start...")

print("\nbattle 1")
run(hWnd, win32_helper.VK_A)
print("\nbattle 2")
run(hWnd, win32_helper.VK_B)
print("\nbattle 3")
run(hWnd, win32_helper.VK_C)
print("\nbattle 4")
run(hWnd, win32_helper.VK_D)
Example #8
0
# 自动刷本
# 使用方法 python ./auto.py 10 1000
# 输入参数两个,第一个为战斗时间(秒),第二个为循环次数

import sys
import game
import win32_helper

if len(sys.argv) != 3:
    print('format: python ./auto.py 战斗时间 循环次数')
    exit()

hWnd = win32_helper.find_window_handle('MuMu', None, None)
hWnd = win32_helper.find_first_child_window(hWnd)

for i in range(int(sys.argv[2])):
    print('\nloop {0}'.format(i))
    i += 1

    win32_helper.wait(3)
    win32_helper.send_key_to_window(hWnd, win32_helper.VK_X)

    game.battle(hWnd, battle_cost_times=int(sys.argv[1]))