def toggleAuto():
	global manualOn, manualFirst
	manualOn = not manualOn
	if manualFirst:
		manualOn = not manualOn
	if manualOn:
		if not manualFirst:
			manualOn = 0
			time.sleep(random.uniform(1,1.3))
			#keyPress('p', random.uniform(0.3,0.7))
			keyPress('p', random.uniform(0.7,1.2))
			time.sleep(random.uniform(0.3,0.7))
			#keyPress('esc', random.uniform(0.3,0.7))
			manualOn = 1
			# time.sleep(random.uniform(0.1,0.3))
			print ("'" + str(autoMacroDur) + "'" + " seconds until next Auto Battle")
		else:
			manualFirst = 0
		threading.Timer(autoMacroDur, toggleAuto).start()
	else:
		manualOn = 0
		time.sleep(random.uniform(1.1,1.3))
		keyPress('p', random.uniform(0.1,0.3))
		time.sleep(random.uniform(0.9,1.3))
		mouseClick(autoX, autoY)
		manualOn = 0
		print ("'" + str(autoDuration) + "'" + " seconds until next Macro")
		threading.Timer(autoDuration, toggleAuto).start()
def castSkill():
	if manualOn:
		if buffEnabled:
			if buffNow:
				castBuffNow()
				castBuff()
				rand = random.choice(random.sample(range(buffWaitMin,buffWaitMax),1))
				print ("'" + str(rand) + "'" + " seconds until next castBuff()")
				threading.Timer(rand, castBuffNow).start()

		if summonEnabled:
			if summonNow:
				castSummonNow()
				castSummon()
				rand = random.choice(random.sample(range(summonWaitMin,summonWaitMax),7))
				print ("'" + str(rand) + "'" + " seconds until next castSummon()")
				threading.Timer(rand, castSummonNow).start()

		for x in range(random.choice(skillRand)):
			keyPress(random.choice(skillButton), random.uniform(0.1,0.3))
			time.sleep(random.uniform(skillSlpMin,skillSlpMax))
def castBuff():
	if buffSwitch:
		keyPress(buffButtonSwitch, random.uniform(0.1,0.3))
	for keyValue in buffButton:
		keyPress(keyValue, random.uniform(0.1,0.3))
		time.sleep(random.uniform(buffSlpMin,buffSlpMax))
	if buffSwitch:
		keyPress(buffButtonSwitch, random.uniform(0.1,0.3))
def charMove():
	if manualOn:
		global movementDirection, movementDuration, movementCount
		duration = random.uniform(movementDistMin,movementDistMax)
		if movementDirection:
			movementDuration += duration
			keyPress('right', duration)
		else:
			movementDuration -= duration
			keyPress('left', duration)

		if movementCount <= 0:
			if movementDuration > 0:
				keyPress('left', movementDuration)
			else:
				keyPress('right', movementDuration * -1)

			print ("Zero-ing character to starting point")
			movementCount = random.choice(range(movementCountMin,movementCountMax,1))
			movementDuration = 0.0

		movementDirection = not movementDirection
		movementCount -= 1
def castSummon():
	for keyValue in summonButton:
		keyPress(keyValue, random.uniform(0.1,0.3))
		time.sleep(random.uniform(summonSlpMin,summonSlpMax))