/*
	Nightmare Inferno Rider AFK Farm
	Tested resolution - 1080p
	Only copy the code for your resolution
*/

; Version 1920 x 1080 ==========================

/*
 Ask the user to run the script as Admin via UAC 
 This is required to make sure all keystrokes goes thru  
*/
full_command_line := DllCall("GetCommandLine", "str")
if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run '*RunAs "' A_ScriptFullPath '" /restart'
        else
            Run '*RunAs "' A_AhkPath '" /restart "' A_ScriptFullPath '"'
    }
    ExitApp
}

#Requires AutoHotkey v2.0

MsgBox "CTRL + Z to start the script`nCTRL + X to stop the script"

; ============================================
; THESE ARE THE NUMBERS YOU CAN CHANGE
; ============================================

waitMapLoad()
{
	; Modify this value in case you have a long load time because of ping or something
	; Increase it if you have high ping so the moves still register
	; Default - 10000 (equals to 10 sec, works well in 60ms ping)
	Sleep 10000
}

waitMapLoadAix()
{
	; This value should be around 2000-3000 lower than whatever sleep value set in waitMapLoad()
	; Increase this if the four backdash doesn't register
	; Decrease if Mourning Aix still aggro after the four backdash
	; Default - 7500 
	Sleep 7500
}

waitMenu()
{
	; Lower this value if your computer can navigate the menu quickly
	; Not recommended to go lower than 2300 since Sentry might not respawn after one loop
	; Default - 2500 (equals to 2.5 sec) 
	Sleep 2500 
}

;================================================

^z::
{
	if WinExist("ahk_class UnrealWindow"){
		MsgBox "The script will run after you press OK`n`nPress CTRL + X to cancel"
		Loop {
			WinActivate

			; =============================================================================================================
			; MAKE SURE CARLOTTA CAN PERFORM THE ENHANCED HOLD ATTACK + RES LIB AT LEAST 25% IF YOU HAVE LESS THAN 115 ER
			; =============================================================================================================

			; Teleport to Mourning Aix
			openEchoHuntingMenu(1)
			waitMapLoadAix()  

			; Four Dash Back to Avoid Mourning Aix Aggro
			doCarlottaTripleDash()
			; Another dash to make sure Mourning Aix de-aggro
			ControlSend "{LShift}", , "Wuthering Waves"
			Sleep 4000

			doHealerRotation()
			
			SendInput "{w down}"
			SendInput "{LShift down}"
			Sleep 5000 
			
			SendInput "{w up}"
			SendInput "{LShift up}"
			
			; Full Forte Hold Attack 1
			Click "Down Left"
			Sleep 1000
			Click "Up Left"
			Sleep 1000
			
			; Make Carlotta target Mourning Aix
			ControlSend "{MButton}", , "Wuthering Waves"
			Sleep 500

			; Perform Carlotta Skill combo 
			ControlSend "e", , "Wuthering Waves"
			Sleep 1000
			doCarlottaHoldAttack()
			ControlSend "e", , "Wuthering Waves"
			Sleep 1000
			
			; Switch to Rover 
			ControlSend "1", , "Wuthering Waves"
			Sleep 100
			MouseClick
			Sleep 500
			ControlSend "e", , "Wuthering Waves"
			
			; Perform Basic Attack, repeat 5 times
			Loop 5 {
				Loop 5 {
					MouseClick 
					Sleep 400
				}
				ControlSend "e", , "Wuthering Waves"
				Sleep 400
			}

			; Switch to Carlotta, she could be doing Intro Attack here
			ControlSend "2", , "Wuthering Waves"		
			Sleep 1800
			doCarlottaQuickLeap()

			; Teleport to #3
			openEchoHuntingMenu(3)
			waitMapLoad() 

			SendInput "{w down}"
			SendInput "{LShift down}"
			Sleep 2000 
			
			SendInput "{w up}"
			SendInput "{LShift up}"			

			; Full Forte Hold Attack 2
			Click "Down Left"
			Sleep 1000
			Click "Up Left"
			Sleep 1500
			
			doCarlottaQuickLeap()

			; Teleport to #2
			openEchoHuntingMenu(2)

			; Wait 10 sec to make sure everything ready
			waitMapLoad()

			doHealerRotation()

			SendInput "{w down}"
			SendInput "{LShift down}"
			Sleep 5000  
			
			SendInput "{w up}"
			SendInput "{LShift up}"
			ControlSend "{MButton}", , "Wuthering Waves"

			doCarlottaQuickLeap()

			; Full Forte Hold Attack
			Click "Down Left"
			Sleep 1000
			Click "Up Left"
			Sleep 2000
			
			; BY THIS POINT YOUR CARLOTTA NEED TO HAVE HER ULT READY!
			; IF NOT THEN EAT SOME ENERGY REGEN FOOD AND STOP THE SCRIPT
			doCarlottaUltCombo()
			
			ControlSend "1", , "Wuthering Waves"
			Sleep 1500
			doRoverBasicAttackRotation()
			
			; Switch back to Carlotta to Fill Forte for Next Rotation
			doCarlottaForteRefill()
		}
	}
}	

^x::
{
	MsgBox "Script stopped"
	ExitApp
}

doCarlottaUltCombo()
{
	ControlSend "r", , "Wuthering Waves"
	Sleep 3200
	ControlSend "q", , "Wuthering Waves"
	Sleep 3200
	ControlSend "e", , "Wuthering Waves"
	Sleep 800
	MouseClick
	Sleep 1200
	MouseClick
	Sleep 1200
	MouseClick
	Sleep 1200
	MouseClick
	Sleep 1200
	MouseClick
	Sleep 8000
}

doCarlottaForteRefill()
{
	ControlSend "2", , "Wuthering Waves"
	Loop 2 {
		doCarlottaHoldAttack()
		Loop 3 {
			MouseClick 
			Sleep 400
		}
		MouseClick
		Sleep 1800
	}
	doCarlottaQuickLeap()
}

doCarlottaQuickLeap()
{
	ControlSend "e", , "Wuthering Waves"
	Sleep 800
	doCarlottaHoldAttack()
	ControlSend "e", , "Wuthering Waves"
	Sleep 2200
}

doCarlottaHoldAttack()
{
	Click "Down Left"
	Sleep 1000
	Click "Up Left"
	Sleep 100
}

doCarlottaTripleDash()
{
	ControlSend "{LShift}", , "Wuthering Waves"
	Sleep 800
	ControlSend "{LShift}", , "Wuthering Waves"
	Sleep 800
	ControlSend "{LShift}", , "Wuthering Waves"
	Sleep 800
}

doHealerRotation()
{
	; A short heal from your healer in the 3rd slot
	Sleep 500
	ControlSend "3", , "Wuthering Waves"
	Sleep 500
	ControlSend "e", , "Wuthering Waves"
	Sleep 1000
	ControlSend "2", , "Wuthering Waves"
	Sleep 500
}

doRoverBasicAttackRotation()
{
	Loop 3 {
		ControlSend "f", , "Wuthering Waves"
		Loop 5 {
			ControlSend "f", , "Wuthering Waves"
			MouseClick 
			Sleep 400
		}
		ControlSend "f", , "Wuthering Waves"
		ControlSend "e", , "Wuthering Waves"
		Sleep 500
	}
}

openEchoHuntingMenu(TargetEcho)
{
	SendInput "{F2}"
	waitMenu()
	MouseClick "Left", 75, 570
	waitMenu()
	MouseClick "Left",  853, 339 ; Scroll to specific menu
	waitMenu()

	; Select which Echo to teleport
	; 1 = Nightmare Mourning Aix
	; 2 = Nightmare Rider
	; 3 = Nightmare Crownless
	switch TargetEcho
	{
		case 1:
			MouseClick "Left",  470, 580 
		case 2:
			MouseClick "Left",  470, 480 
		case 3:
			MouseClick "Left",  470, 380
	}

	; Perform teleport to target Echo
	waitMenu()
	clickTeleportButton()
	Sleep 3000
	clickTeleportButton() 
}

clickTeleportButton()
{
	MouseClick "Left",  1700, 1000  
}

; End of Version 1920 x 1080 ==========================