# https://pyautogui.readthedocs.io/en/latest/
import pyautogui
import time

import keyboard
import sys

DOING_POINT_FINDING = False
SLEEP_BETWEEN_CLICKS_S = 0.05

# Replay, Next, Auto
POWER_BATTLE_ITEM_POINTS = [(868, 808), (930, 808), (990, 808), (1063, 808)]
POWER_HERO_POINTS = [(785, 881), (869, 881), (960, 881), (1049, 881), (1129, 881)]
FIRE_BATTLE_ITEM = (962, 662)
POWER_CENTER_ENEMY = (961, 294)

battle_item_points = POWER_BATTLE_ITEM_POINTS
hero_points = POWER_HERO_POINTS
center_enemy = POWER_CENTER_ENEMY
fire_battle_item = FIRE_BATTLE_ITEM
# Assumes you have Medium Mana, Minor Mana, Axes, then Arrows (3 Star challenge event, or Bombs, Axes 4 star event)

# 100% mana
MANA_100_3STAR_PERSON1 = [battle_item_points[1], hero_points[0],  # Little to person #1
                      battle_item_points[0], hero_points[0],  # Big
                      battle_item_points[1], hero_points[0]]  # Little
MANA_100_3STAR_PERSON2 = [battle_item_points[1], hero_points[1],  # Little to person #1
                      battle_item_points[0], hero_points[1],  # Big
                      battle_item_points[1], hero_points[1]]  # Little
MANA_100_3STAR_PERSON3 = [battle_item_points[1], hero_points[2],  # Little to person #1
                      battle_item_points[0], hero_points[2],  # Big
                      battle_item_points[1], hero_points[2]]  # Little
MANA_100_3STAR_PERSON4 = [battle_item_points[1], hero_points[3],  # Little to person #1
                      battle_item_points[0], hero_points[3],  # Big
                      battle_item_points[1], hero_points[3]]  # Little
MANA_100_3STAR_PERSON5 = [battle_item_points[1], hero_points[4],  # Little to person #1
                      battle_item_points[0], hero_points[4],  # Big
                      battle_item_points[1], hero_points[4]]  # Little

#
# 75% mana to the far lefth hero
MANA_75_3STAR_PERSON1 = [battle_item_points[1], hero_points[0],  # Little to person #1
                      battle_item_points[1], hero_points[0],  # Big
                      battle_item_points[1], hero_points[0]]  # Little
MANA_75_3STAR_PERSON2 = [battle_item_points[1], hero_points[1],  # Little to person #1
                      battle_item_points[1], hero_points[1],  # Big
                      battle_item_points[1], hero_points[1]]  # Little
MANA_75_3STAR_PERSON3 = [battle_item_points[1], hero_points[2],  # Little to person #1
                      battle_item_points[1], hero_points[2],  # Big
                      battle_item_points[1], hero_points[2]]  # Little
MANA_75_3STAR_PERSON4 = [battle_item_points[1], hero_points[3],  # Little to person #1
                      battle_item_points[1], hero_points[3],  # Big
                      battle_item_points[1], hero_points[3]]  # Little
MANA_75_3STAR_PERSON5 = [battle_item_points[1], hero_points[4],  # Little to person #1
                      battle_item_points[1], hero_points[4],  # Big
                      battle_item_points[1], hero_points[4]]  # Little

BATTLE_ITEM_3_5_TIMES = [battle_item_points[2], fire_battle_item,  # All of the big item
                         battle_item_points[2], fire_battle_item,
                         battle_item_points[2], fire_battle_item,
                         battle_item_points[2], fire_battle_item,
                         battle_item_points[2], fire_battle_item]

BATTLE_ITEM_4_5_TIMES = [battle_item_points[3], fire_battle_item,  # All of the little item
                         battle_item_points[3], fire_battle_item,
                         battle_item_points[3], fire_battle_item,
                         battle_item_points[3], fire_battle_item,
                         battle_item_points[3], fire_battle_item]


def y_key():
    run_script(MANA_100_3STAR_PERSON1)


def u_key():
    run_script(MANA_100_3STAR_PERSON2)


def i_key():
    run_script(MANA_100_3STAR_PERSON3)


def o_key():
    run_script(MANA_100_3STAR_PERSON4)

def p_key():
    run_script(MANA_100_3STAR_PERSON5)


def h_key():
    run_script(MANA_75_3STAR_PERSON1)


def j_key():
    run_script(MANA_75_3STAR_PERSON2)


def k_key():
    run_script(MANA_75_3STAR_PERSON3)


def l_key():
    run_script(MANA_75_3STAR_PERSON4)


def semicolon_key():
    run_script(MANA_75_3STAR_PERSON5)


def b_key():
    run_script(MANA_100_3STAR_PERSON1)
    time.sleep(0.5)
    run_script(MANA_100_3STAR_PERSON2)


def n_key():
    run_script(BATTLE_ITEM_3_5_TIMES)


def m_key():
    run_script(BATTLE_ITEM_4_5_TIMES)


def less_than_key():
    run_script(BATTLE_ITEM_3_5_TIMES)
    run_script(BATTLE_ITEM_4_5_TIMES)


def greater_than_key():
    run_script(BATTLE_ITEM_3_5_TIMES)
    run_script(BATTLE_ITEM_4_5_TIMES)


def run_script(points):
    for point in points:
        pyautogui.click(point[0], point[1])
        # print("Clicked ({}, {})".format(point[0], point[1]))
        time.sleep(SLEEP_BETWEEN_CLICKS_S)


keyboard.on_press_key('y', lambda event: y_key())
keyboard.on_press_key('u', lambda event: u_key())
keyboard.on_press_key('i', lambda event: i_key())
keyboard.on_press_key('o', lambda event: o_key())
keyboard.on_press_key('p', lambda event: p_key())

keyboard.on_press_key('h', lambda event: h_key())
keyboard.on_press_key('j', lambda event: j_key())
keyboard.on_press_key('k', lambda event: k_key())
keyboard.on_press_key('l', lambda event: l_key())
keyboard.on_press_key(';', lambda event: semicolon_key())

keyboard.on_press_key('n', lambda event: n_key())
keyboard.on_press_key('m', lambda event: m_key())
keyboard.on_press_key('b', lambda event: b_key())
keyboard.on_press_key(',', lambda event: less_than_key())
keyboard.on_press_key('.', lambda event: greater_than_key())

while True:
    time.sleep(0.0001)
    if DOING_POINT_FINDING:
        currentMouseX, currentMouseY = pyautogui.position() # Get the XY position of the mouse.
        print("({:2}, {:2})".format(currentMouseX, currentMouseY))
        continue

    if keyboard.is_pressed(' '):
        print('Exit')
        sys.exit()


# pyautogui.click(100, 200)  # Move the mouse to XY coordinates and click it.
# pyautogui.doubleClick()    # Double click the mouse.

# https://pyautogui.readthedocs.io/en/latest/
import pyautogui
import time

import keyboard
import sys

DOING_POINT_FINDING = False
SLEEP_BETWEEN_CLICKS_S = 0.05

# Replay, Next, Auto
POWER_BATTLE_ITEM_POINTS = [(868, 808), (930, 808), (990, 808), (1063, 808)]
POWER_HERO_POINTS = [(785, 881), (869, 881), (960, 881), (1049, 881), (1129, 881)]
FIRE_BATTLE_ITEM = (962, 662)
POWER_CENTER_ENEMY = (961, 294)

battle_item_points = POWER_BATTLE_ITEM_POINTS
hero_points = POWER_HERO_POINTS
center_enemy = POWER_CENTER_ENEMY
fire_battle_item = FIRE_BATTLE_ITEM
# Assumes you have Medium Mana, Minor Mana, Axes, then Arrows (3 Star challenge event, or Bombs, Axes 4 star event)

# 100% mana
MANA_100_3STAR_PERSON1 = [battle_item_points[1], hero_points[0],  # Little to person #1
                      battle_item_points[0], hero_points[0],  # Big
                      battle_item_points[1], hero_points[0]]  # Little
MANA_100_3STAR_PERSON2 = [battle_item_points[1], hero_points[1],  # Little to person #1
                      battle_item_points[0], hero_points[1],  # Big
                      battle_item_points[1], hero_points[1]]  # Little
MANA_100_3STAR_PERSON3 = [battle_item_points[1], hero_points[2],  # Little to person #1
                      battle_item_points[0], hero_points[2],  # Big
                      battle_item_points[1], hero_points[2]]  # Little
MANA_100_3STAR_PERSON4 = [battle_item_points[1], hero_points[3],  # Little to person #1
                      battle_item_points[0], hero_points[3],  # Big
                      battle_item_points[1], hero_points[3]]  # Little
MANA_100_3STAR_PERSON5 = [battle_item_points[1], hero_points[4],  # Little to person #1
                      battle_item_points[0], hero_points[4],  # Big
                      battle_item_points[1], hero_points[4]]  # Little

#
# 75% mana to the far lefth hero
MANA_75_3STAR_PERSON1 = [battle_item_points[1], hero_points[0],  # Little to person #1
                      battle_item_points[1], hero_points[0],  # Big
                      battle_item_points[1], hero_points[0]]  # Little
MANA_75_3STAR_PERSON2 = [battle_item_points[1], hero_points[1],  # Little to person #1
                      battle_item_points[1], hero_points[1],  # Big
                      battle_item_points[1], hero_points[1]]  # Little
MANA_75_3STAR_PERSON3 = [battle_item_points[1], hero_points[2],  # Little to person #1
                      battle_item_points[1], hero_points[2],  # Big
                      battle_item_points[1], hero_points[2]]  # Little
MANA_75_3STAR_PERSON4 = [battle_item_points[1], hero_points[3],  # Little to person #1
                      battle_item_points[1], hero_points[3],  # Big
                      battle_item_points[1], hero_points[3]]  # Little
MANA_75_3STAR_PERSON5 = [battle_item_points[1], hero_points[4],  # Little to person #1
                      battle_item_points[1], hero_points[4],  # Big
                      battle_item_points[1], hero_points[4]]  # Little

BATTLE_ITEM_3_5_TIMES = [battle_item_points[2], fire_battle_item,  # All of the big item
                         battle_item_points[2], fire_battle_item,
                         battle_item_points[2], fire_battle_item,
                         battle_item_points[2], fire_battle_item,
                         battle_item_points[2], fire_battle_item]

BATTLE_ITEM_4_5_TIMES = [battle_item_points[3], fire_battle_item,  # All of the little item
                         battle_item_points[3], fire_battle_item,
                         battle_item_points[3], fire_battle_item,
                         battle_item_points[3], fire_battle_item,
                         battle_item_points[3], fire_battle_item]


def y_key():
    run_script(MANA_100_3STAR_PERSON1)


def u_key():
    run_script(MANA_100_3STAR_PERSON2)


def i_key():
    run_script(MANA_100_3STAR_PERSON3)


def o_key():
    run_script(MANA_100_3STAR_PERSON4)

def p_key():
    run_script(MANA_100_3STAR_PERSON5)


def h_key():
    run_script(MANA_75_3STAR_PERSON1)


def j_key():
    run_script(MANA_75_3STAR_PERSON2)


def k_key():
    run_script(MANA_75_3STAR_PERSON3)


def l_key():
    run_script(MANA_75_3STAR_PERSON4)


def semicolon_key():
    run_script(MANA_75_3STAR_PERSON5)


def b_key():
    run_script(MANA_100_3STAR_PERSON1)
    time.sleep(0.5)
    run_script(MANA_100_3STAR_PERSON2)


def n_key():
    run_script(BATTLE_ITEM_3_5_TIMES)


def m_key():
    run_script(BATTLE_ITEM_4_5_TIMES)


def less_than_key():
    run_script(BATTLE_ITEM_3_5_TIMES)
    run_script(BATTLE_ITEM_4_5_TIMES)


def greater_than_key():
    run_script(BATTLE_ITEM_3_5_TIMES)
    run_script(BATTLE_ITEM_4_5_TIMES)


def run_script(points):
    for point in points:
        pyautogui.click(point[0], point[1])
        # print("Clicked ({}, {})".format(point[0], point[1]))
        time.sleep(SLEEP_BETWEEN_CLICKS_S)


keyboard.on_press_key('y', lambda event: y_key())
keyboard.on_press_key('u', lambda event: u_key())
keyboard.on_press_key('i', lambda event: i_key())
keyboard.on_press_key('o', lambda event: o_key())
keyboard.on_press_key('p', lambda event: p_key())

keyboard.on_press_key('h', lambda event: h_key())
keyboard.on_press_key('j', lambda event: j_key())
keyboard.on_press_key('k', lambda event: k_key())
keyboard.on_press_key('l', lambda event: l_key())
keyboard.on_press_key(';', lambda event: semicolon_key())

keyboard.on_press_key('n', lambda event: n_key())
keyboard.on_press_key('m', lambda event: m_key())
keyboard.on_press_key('b', lambda event: b_key())
keyboard.on_press_key(',', lambda event: less_than_key())
keyboard.on_press_key('.', lambda event: greater_than_key())

while True:
    time.sleep(0.0001)
    if DOING_POINT_FINDING:
        currentMouseX, currentMouseY = pyautogui.position() # Get the XY position of the mouse.
        print("({:2}, {:2})".format(currentMouseX, currentMouseY))
        continue

    if keyboard.is_pressed(' '):
        print('Exit')
        sys.exit()


# pyautogui.click(100, 200)  # Move the mouse to XY coordinates and click it.
# pyautogui.doubleClick()    # Double click the mouse.

# https://pyautogui.readthedocs.io/en/latest/ # Replay, Next, Auto # Assumes you have Medium Mana, Minor Mana, Axes, then Arrows (3 Star challenge event, or Bombs, Axes 4 star event) # 100% mana # Little to person #1 # Big # Little # Little to person #1 # Big # Little # Little to person #1 # Big # Little # Little to person #1 # Big # Little # Little to person #1 # Big # Little # # 75% mana to the far lefth hero # Little to person #1 # Big # Little # Little to person #1 # Big # Little # Little to person #1 # Big # Little # Little to person #1 # Big # Little # Little to person #1 # Big # Little # All of the big item # All of the little item # print("Clicked ({}, {})".format(point[0], point[1])) # Get the XY position of the mouse. # pyautogui.click(100, 200)  # Move the mouse to XY coordinates and click it. # pyautogui.doubleClick()    # Double click the mouse.