#NoEnv

SetWorkingDir %A_ScriptDir%

;Sets the working directory to be where the script is located.

CoordMode, Mouse, Window

;Lets the finding of X and Y to be determined by the mouse's coordinates on the functions below.

SendMode Input

#SingleInstance Force

SetTitleMatchMode 2

#WinActivateForce

SetControlDelay 1

SetWinDelay 0

SetKeyDelay -1

SetMouseDelay -1

SetBatchLines -1

F1::

;Press F1 to start your macro.

Macro1:

CoordMode, Pixel, Window

WinActivate, NoxPlayer ahk_class Qt5QWindowIcon

Sleep, 350

Loop

{

mainloopstart:

FoundX := 0

FoundY := 0

ConfirmPixel(FoundX, FoundY, 860, 390, 860, 390, "0x0D2910", 10, "Fast")

If ErrorLevel >= 1

return

;Finds the color "0x0D2910" within the square that starts from X:374 Y:478 to X:374 Y:478,

;with 10 shade color variation,

;and then saves the resulting pixel to FoundX and FoundY.

;This is done to ensure that the screen has changed and confirm the color you passed exist within

;this pixel at this particular time.

;If the color is not found, the error count will be incremented to 1, resulting in the confirmation to re-run.

;It takes into account any possible lag so it won't proceed until the correct screen is confirmed.

;This check is for the Green Shinra's finest event box.

;The rest of the script follows the same logic. Optimize as you see fit.

;The ConfirmPixel function is defined down below.

Sleep, 250

Click, 860, 390 Left, 1

Sleep, 250

;Left Mouse clicks on the Shinra Finest event button.

ConfirmPixel(FoundX, FoundY, 1032, 783, 1032, 783, "0xF7961D", 10, "Fast")

If ErrorLevel >= 1

return

;This check is for the Blue Enter Dungeon button.

Sleep, 250

Click, %FoundX%, %FoundY% Left, 1

Sleep, 250

;Clicks the Enter Dungeon button.

ConfirmPixel(FoundX, FoundY, 999, 860, 999, 860, "0xE84A20", 10, "Fast")

If ErrorLevel >= 1

return

;This check is for the Next on the Party Select screen button.

Sleep, 1000

Click, %FoundX%, %FoundY% Left, 1

Sleep, 250

;Clicks the Next button.

ConfirmPixel(FoundX, FoundY, 993, 862, 993, 862, "0xDD3F18", 10, "Fast")

If ErrorLevel >= 1

return

;This check is for the GO! button in the RW select screen.

Sleep, 500

Click, 993, 862 Left, 1

Sleep, 1000

;Clicks the GO! button.

ConfirmPixel(FoundX, FoundY, 1127, 459, 1127, 459, "0xC3BBBB", 10, "Fast")

If ErrorLevel >= 1

return

;This check is for the white edges of the boss platform button.

Click, 1127, 459 Left, 1

Sleep, 250

;Clicks the white edge of the boss platform.

ConfirmPixel(FoundX, FoundY, 1059, 685, 1059, 685, "0x9A2911", 30, "Fast")

If ErrorLevel >= 1

return

;This check is for the begin battle button.

Sleep, 250

Click, 1059, 685 Left, 1

Sleep, 250

;Clicks the begin battle button.

;ConfirmPixel(FoundX, FoundY, 595, 922, 595, 922, "0x203ED8", 10, "Fast")

;If ErrorLevel >= 1

; return

;Sleep, 250

;Click, %FoundX%, %FoundY% Left, 1

;Sleep, 2000

WorthyBoss := 0

Loop

{

battleloop:

PixelSearch, FoundX, FoundY, 990, 296, 990, 296, 0x6A1405, 10, Fast

If ErrorLevel = 0

{

Goto, resultsloop

}

;Checks if the fight has ended and you are in the champion screen.

;If it is, it will click and check whether it should return to the beginning of the loop.

If ErrorLevel >= 1

PixelSearch, FoundX, FoundY, 979, 810, 979, 810, 0xC8C8C8, 10, Fast

;Checks if your turn available by ensuring the 2nd ability slot includes the color white that is on the outer ring of the ability.

If ErrorLevel = 0

{

;If the turn is available..

PixelSearch, FoundX, FoundY, 827, 830, 827, 830, 0xAD210F, 10, Fast

;Checks if the CMD2 is blue colored for attack/defend, meaning burst mode is inactive

If ErrorLevel = 0

;If it is blue..

{

Click, 1131, 816 Left, 1

;Click the BSB button

Sleep, 300

Goto, battleloop

;Left click on bsb. Repeat the loop.

}

Else If ErrorLevel >= 1

;If it is not blue, meaning the cmd2 exists..

;PixelSearch, FoundX, FoundY, 847, 480, 847, 480, 0x0F0A0A, 10, Fast

;Check tank

;If ErrorLevel = 0

;{

; WorthyBoss += 1

;}

PixelSearch, FoundX, FoundY, 780, 496, 780, 496, 0x0A0E15, 10, Fast

;Check Guard Scorpion

If ErrorLevel = 0

{

WorthyBoss += 1

}

;First we check if it is a worthy boss. There is a static spot on this boss.

;You can add one more counter if you want to do it for the other bosses as well, just have to find a good pixel.

If WorthyBoss > 0

;If we confirmed it is this boss..

{

Click, 726, 840 Left, 1

Sleep, 300

WorthyBoss := 0

Goto, battleloop

;Left click on cmd1. Repeat the loop.

}

Else

;Otherwise we will use cmd2.

{

Click, 827, 830 Left, 1

Sleep, 300

Goto, battleloop

;Left click on cmd2. Repeat the loop.

}

}

}

resultsloop:

Loop

{

Sleep, 100

ConfirmPixel(FoundX, FoundY, 1007, 660, 1007, 660, "0x3ADAFE", 10, "Fast")

If ErrorLevel >= 1

return

;Checks on the mastery screen.

Sleep, 1000

;Sleep is important so that the macro knows to wait before running the next command.

Click, 1007, 660, Left, 2

ConfirmPixel(FoundX, FoundY, 867, 848, 867, 848, "0xCC511E", 10, "Fast")

If ErrorLevel >= 1

return

Sleep, 1000

Click, 867, 848, Left, 2

Sleep, 1000

;Click on the mastery screen to ensure your window focus has changed.

ConfirmPixel(FoundX, FoundY, 977, 330, 977, 330, "0x1261FF", 10, "Fast")

;Checks on the Next button on the mastery screen.

If ErrorLevel >= 1

return

Sleep, 1000

Click, 946, 740, Left, 2

Sleep, 1000

ConfirmPixel(FoundX, FoundY, 867, 848, 867, 848, "0xCC511E", 10, "Fast")

;Checks on the Next button on the mastery screen.

If ErrorLevel >= 1

return

Sleep, 300

Click, 867, 848, Left, 2

Sleep, 500

ConfirmPixel(FoundX, FoundY, 993, 736, 993, 736, "0xE1491E", 10, "Fast")

;Checks on the Next button on the magicite screen.

If ErrorLevel >= 1

return

Sleep, 1000

Click, 993, 736, Left, 2

Sleep, 500

ConfirmPixel(FoundX, FoundY, 993, 736, 993, 736, "0xE1491E", 10, "Fast")

;Checks on the Next button on the Greater Dark Orb screen.

If ErrorLevel >= 1

return

Sleep, 1000

Click, 867, 848, Left, 2

Click, 867, 848, Left, 2

Click, 867, 848, Left, 2

Sleep, 500

ConfirmPixel(FoundX, FoundY, 930, 852, 930, 852, "0xFFFFFF", 10, "Fast")

;Checks on the Next button on the Major Dark Orb screen.

If ErrorLevel >= 1

Sleep, 1000

Click, 930, 852, Left, 2

Click, 930, 852, Left, 2

Click, 930, 852, Left, 2

;Clicks the next button

Sleep, 500

ConfirmPixel(FoundX, FoundY, 740, 424, 740, 424, "0x20B9EA", 10, "Fast")

;Checks the dungeon complete next screen

If ErrorLevel >= 1

return

Sleep, 500

Click, 930, 852, Left, 2

ConfirmPixel(FoundX, FoundY, 827, 830, 827, 830, "0x9B5E45", 10, "Fast")

;Checks the dungeon complete next button

If ErrorLevel >= 1

return

Sleep, 1000

Click, 827, 830, Left, 2

;Clicks the next button

Sleep, 1000

ConfirmPixel(FoundX, FoundY, 860, 390, 860, 390, "0x0D2910", 10, "Fast")

;Checks the shinra screen

If ErrorLevel >= 1

return

Sleep, 500

Goto, mainloopstart

}

}

Return

F2::ExitApp

F3::Pause

ConfirmImage(byRef Out1, byRef Out2, X1, Y1, X2, Y2, ImageFile)

{

CoordMode, Pixel, Window

myImg = %A_ScriptDir%\img\%ImageFile%

Loop, 3000

{

ImageSearch, Out1, Out2, X1, Y1, X2, Y2, %myImg%

; MsgBox, 1,, %ErrorLevel% %ImageFile%

CenterImgSrchCoords(myImg, Out1, Out2)

If ErrorLevel = 0

Break

Sleep, 100

}

; MsgBox, 1,, %Out1% %Out2%

}

ConfirmPixel(byRef Out1, byRef Out2, X1, Y1, X2, Y2, color, tol, opt)

{

Loop, 3000

{

PixelSearch, Out1, Out2, X1, Y1, X1, Y1, %color%, tol, %opt%

if ErrorLevel = 0

Break

Sleep, 100

}

}

CenterImgSrchCoords(File, ByRef CoordX, ByRef CoordY)

{

static LoadedPic

LastEL := ErrorLevel

Gui, Add, Pic, vLoadedPic, %File%

GuiControlGet, LoadedPic, Pos

Gui, Destroy

CoordX += LoadedPicW // 2

CoordY += LoadedPicH // 2

ErrorLevel := LastEL

}