/*
	Dreamless AFK Farm with Jinhsi
	Tested resolution - 720p, 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 "Dreamless Farm w/ Jinhsi Script Active`n`nCTRL + Z to start the script`nCTRL + X to stop the script`n`nMake sure you have at least 60 waveplate!"

^z::
{
	if WinExist("ahk_class UnrealWindow"){
		MsgBox "The script will run after you press OK`n`nPress CTRL + X to cancel"
		Loop {
			WinActivate  
			SendInput "{w down}"
			SendInput "{LShift down}"
			Sleep 1500 ; Sprint to the entry point
			SendInput "{w up}"
			SendInput "{LShift up}"
			ControlSend "f", , "Wuthering Waves"
			Sleep 2100
			
			/*
				1. This is the location of the difficulty button. Change the number so it's 2 ranks below your current team.
				LV 50 = 315, 274
				LV 60 = 315, 364
				LV 70 = 315, 444
			*/
			MouseClick "Left",  315,  274 ; <- Change the value number based on what you need 
			
			Sleep 500
			MouseClick "Left",  1555,  1000	; 2. This is the location of the start button.
			Sleep 1000
			MouseClick "Left",  1555,  1000	; 3. Same coordinate as no. 2
			Sleep 5500 ; This is the loading time for entering the fight (Default = 5500). 

			; Prep the flow state
			Loop 5 {
				MouseClick 
				Sleep 500
			}
			ControlSend "t", , "Wuthering Waves" ; Dodge the swing
			Sleep 1000
			ControlSend "e", , "Wuthering Waves"
			Sleep 2200
			ControlSend "e", , "Wuthering Waves"
			ControlSend "q", , "Wuthering Waves"
			
			Loop 10 {
				MouseClick 
				Sleep 500
			}
			Sleep 500
			; If your Jinhsi Res Lib doesn't break Dreamless then you need to raise her better!
			ControlSend "e", , "Wuthering Waves"

			Sleep 4000 ; Long sleep because Jinhsi skill is long AF

			; Smack Dreamless a few more times just in case 
			Loop 15 {
				MouseClick 
				Sleep 500
			}
			ControlSend "{LShift}", , "Wuthering Waves"
			Sleep 1500

			; Go Forward a bit
			SendInput "{w down}"
			SendInput "{LShift down}"
			Loop 5 {
				ControlSend "f", , "Wuthering Waves"
				Sleep 300
			}
			SendInput "{w up}"
			SendInput "{LShift up}"
			Sleep 200

			; Exit the Domain
			ControlSend "{ESC}", , "Wuthering Waves"
			Sleep 500
			MouseClick "Left",  1285, 670 ; 4. This is the exit confirmation button for leaving the domain.
			Sleep 10000	; This is the loading time to exit the fight. You can increase this to delay the next run if you so desire (Default = 10000)

			; Heal with Verina in Slot 2
			; Dreamless attack pattern is quite random so your Jinhsi WILL get hit a few times here and there
			; This short heal rotation makes sure you Jinhsi stay healthy forever
			ControlSend "2", , "Wuthering Waves"
			Sleep 200
			ControlSend "e", , "Wuthering Waves"
			Sleep 1000
			ControlSend "{Space}", , "Wuthering Waves"
			Sleep 300
			MouseClick
			Sleep 1000
			ControlSend "r", , "Wuthering Waves"
			Sleep 4800

			; Use Cruisewing Echo on 2nd slot for extra healing
			; It's the four winged 1 cost echo
			; Jinhsi might need this to survive indefinitely
			ControlSend "q", , "Wuthering Waves" 
			Sleep 200

			ControlSend "1", , "Wuthering Waves"
			Sleep 200
			; End of Heal with Verina

		}
	}
}	

^x::
{
	MsgBox "Dreamless Farm script stopped"
	ExitApp
}

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



; Version 1280 x 720 ==========================

/*
 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 "Dreamless Farm w/ Jinhsi Script Active`n`nCTRL + Z to start the script`nCTRL + X to stop the script`n`nMake sure you have at least 60 waveplate!"

^z::
{
	if WinExist("ahk_class UnrealWindow"){
		MsgBox "The script will run after you press OK`n`nPress CTRL + X to cancel"
		Loop {
			WinActivate  
			SendInput "{w down}"
			SendInput "{LShift down}"
			Sleep 1500 ; Sprint to the entry point
			SendInput "{w up}"
			SendInput "{LShift up}"
			ControlSend "f", , "Wuthering Waves"
			Sleep 2100
			
			/*
				1. This is the location of the difficulty button. Change the number so it's 2 ranks below your current team.
				LV 50 = 200, 185
				LV 60 = 200, 235
				LV 70 = 200, 285
			*/
			MouseClick "Left",  200,  185 ; <- Change the value number based on what you need 
			
			Sleep 500
			MouseClick "Left",  1000, 645	; 2. This is the location of the start button.
			Sleep 1000
			MouseClick "Left",  1000, 645	; 3. Same coordinate as no. 2

			; Prep the flow state
			Loop 5 {
				MouseClick 
				Sleep 500
			}
			ControlSend "t", , "Wuthering Waves" ; Dodge the swing
			Sleep 1000
			ControlSend "e", , "Wuthering Waves"
			Sleep 2200
			ControlSend "e", , "Wuthering Waves"
			ControlSend "q", , "Wuthering Waves"
			
			Loop 10 {
				MouseClick 
				Sleep 500
			}
			Sleep 500
			; If your Jinhsi Res Lib doesn't break Dreamless then you need to raise her better!
			ControlSend "e", , "Wuthering Waves"

			Sleep 4000 ; Long sleep because Jinhsi skill is long AF

			; Smack Dreamless a few more times just in case 
			Loop 15 {
				MouseClick 
				Sleep 500
			}
			ControlSend "{LShift}", , "Wuthering Waves"
			Sleep 1500

			; Go Forward a bit
			SendInput "{w down}"
			SendInput "{LShift down}"
			Loop 5 {
				ControlSend "f", , "Wuthering Waves"
				Sleep 300
			}
			SendInput "{w up}"
			SendInput "{LShift up}"
			Sleep 200

			; Exit the Domain
			ControlSend "{ESC}", , "Wuthering Waves"
			Sleep 500
			MouseClick "Left",  840, 444 ; 4. This is the exit confirmation button for leaving the domain.
			Sleep 10000	; This is the loading time to exit the fight. You can increase this to delay the next run if you so desire (Default = 10000)

			; Heal with Verina in Slot 2
			; Dreamless attack pattern is quite random so your Jinhsi WILL get hit a few times here and there
			; This short heal rotation makes sure you Jinhsi stay healthy forever
			ControlSend "2", , "Wuthering Waves"
			Sleep 200
			ControlSend "e", , "Wuthering Waves"
			Sleep 1000
			ControlSend "{Space}", , "Wuthering Waves"
			Sleep 300
			MouseClick
			Sleep 1000
			ControlSend "r", , "Wuthering Waves"
			Sleep 4800

			; Use Cruisewing Echo on 2nd slot for extra healing
			; It's the four winged 1 cost echo
			; Jinhsi might need this to survive indefinitely
			ControlSend "q", , "Wuthering Waves" 
			Sleep 200

			ControlSend "1", , "Wuthering Waves"
			Sleep 200
			; End of Heal with Verina

		}
	}
}	

^x::
{
	MsgBox "Dreamless Farm script stopped"
	ExitApp
}

; End of Version 1280 x 720 ==========================