Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Sacred seasons grind script.
- ; It's an autoit v3 script. Assumes your browser is in the top right of the screen.
- ; You will need to edit this to get it working for you but not too much.
- ; See sample videos at http://www.youtube.com/user/rbrbran277
- ; Last updated Jan 30 2010.
- AdlibEnable("pause"); this keeps running at all times till you exit.
- HotKeySet("{ESC}", "Terminate")
- HotKeySet("{pause}","pauseset"); uses the pause key to change the value of $Pause
- $Pause = 1
- Func pauseset()
- $Pause = $Pause * -1
- EndFunc
- Func pause()
- While $Pause = -1
- Sleep(500)
- Wend
- EndFunc
- ; Screen dimensions.
- Global $topLeftFull[2]
- Global $bottomRightFull[2]
- GetGameDimensions()
- $screenWidth = $bottomRightFull[0] - $topLeftFull[0]
- $screenHeight = $bottomRightFull[1] - $topLeftFull[1]
- $okOffsetXAbs = $topLeftFull[0] + ($screenWidth * 0.5)
- $okOffsetYAbs = $topLeftFull[1] + ($screenHeight * 0.76)
- $attackOffset = 0.051 * $screenHeight
- $skillOffset = 0.11 * $screenHeight
- ; Game colors.
- $battlePadColor = 0xFB4743
- $battleClearColor = 0x5AE3FF
- $battleClearColor = 0x25DAFF
- $menuColor = 0xFF003C
- $bluePadColor = 0x6DFBF6
- ; Timing settings.
- ; Unattended mode runs slower but is less likely to suffer lag related problems.
- $attended = 0
- $unattended = 1
- $mode = $attended
- ; $mode = $unattended
- If $mode == $attended Then
- $mouseSpeed = 1
- $medSleep = 250
- $quickSleep = 10
- $walkFactor = 3
- $roomLoadDelay = 2000
- Else
- $mouseSpeed = 3
- $medSleep = 250
- $quickSleep = 10
- $walkFactor = 3
- $roomLoadDelay = 2000
- EndIf
- $buffAt = 0
- ; These are various programs you can run.
- ; GrindTsulas()
- ; GrindSubTsulas()
- ; GrindPonies()
- ; GrindMushrooms()
- ; GrindOctogum()
- ; GrindBubblers()
- ; GrindElementals()
- ; GrindJustElementals()
- ; GrindOctogum2()
- ; GrindFto1()
- ; ClearArena()
- ; GrindCave()
- ; GrindChoppers()
- ; GrindChoppersAdvanced()
- ; GrindSkeletons()
- ; GrindSkeletons2()
- GrindSkeletonsAdvanced()
- ; For testing
- ; ClearBattle(0, 0, 1)
- ; ClearBattle(0, 1, 0)
- ; ClearBattle(0, 1, 1)
- ; FindMenu()
- ; GrindBra()
- ; GoCenter()
- ; $x = NeedHeal()
- ; MsgBox(8192, $x, $x, 1)
- ; DismissUserWindow()
- ; $inb = InBattle()
- ; MsgBox(8192, $inb, $inb, 1)
- Func GetGameDimensions()
- $var = WinList()
- $searchFor = "Sacred Seasons MMORPG"
- For $i = 1 to $var[0][0]
- If StringRegExp($var[$i][0], $searchFor) Then
- ;$window = $var[$i][1]
- ;$controlPos = ControlGetPos($window, "", "[CLASS:MacromediaFlashPlayerActiveX]")
- ;$windowPos = WinGetPos($window, "")
- ;$x = $windowPos[0] + $controlPos[0]
- ;$y = $windowPos[1] + $controlPos[1] + 20
- ;$topLeftFull[0] = $x
- ;$topLeftFull[1] = $y
- ;$bottomRightFull[0] = $x + $controlPos[2]
- ;$bottomRightFull[1] = $y + $controlPos[3]
- ; XXX: temporary hack.
- ;$bottomRightFull[1] -= 120
- $topLeftFull[0] = 5
- $topLeftFull[1] = 115
- $bottomRightFull[0] = 750
- $bottomRightFull[1] = 590
- ;MsgBox(8192, $topLeftFull[0], $topLeftFull[0], 5)
- ;MsgBox(8192, $topLeftFull[1], $topLeftFull[1], 5)
- ;MsgBox(8192, $bottomRightFull[0], $bottomRightFull[0], 5)
- ;MsgBox(8192, $bottomRightFull[1], $bottomRightFull[1], 5)
- EndIf
- Next
- EndFunc
- ; To grind you have to step off the pad when you're done. There are 4 ways to do that.
- Global $upAndToTheLeft[2]
- Global $upAndToTheRight[2]
- Global $downAndToTheLeft[2]
- Global $downAndToTheRight[2]
- Func GrindTsulas()
- GrindSubCave($bottomRightFull, $topLeftFull, -45, -25, 0, 0)
- EndFunc
- Func GrindSubTsulas()
- Local $altCoords1[2]
- $altCoords1[0] = $topLeftFull[0] + ($screenWidth * 0.36)
- $altCoords1[1] = $topLeftFull[1] + ($screenHeight * 0.3)
- GrindSubCave($bottomRightFull, $altCoords1, -45, -25, 0, 0)
- EndFunc
- Func GrindPonies()
- GrindSubCave($topLeftFull, $bottomRightFull, 45, 25, 0, 0)
- EndFunc
- Func GrindChoppers()
- ; GrindSubCave($topLeftFull, $bottomRightFull, -65, -15, 0, 2)
- $buffAt = 3
- $buffAt = 7
- GrindSubCave($topLeftFull, $bottomRightFull, -35, 0, 0, 0)
- EndFunc
- Func GrindSkeletons()
- $buffAt = 6
- ;$buffAt = 14
- GrindSubCave($topLeftFull, $bottomRightFull, -35, 0, 0, 0)
- EndFunc
- Func GrindSkeletons2()
- $buffAt = 7
- GrindSubCave($topLeftFull, $bottomRightFull, 35, 25, 0, 0)
- EndFunc
- Func GrindElementals()
- GrindSubCave($topLeftFull, $bottomRightFull, 25, -35, 0, 1)
- EndFunc
- Func GrindOctogum2()
- GrindSubCave($topLeftFull, $bottomRightFull, -45, -30, 0, 0)
- EndFunc
- Func GrindFto1()
- GrindSubCave($topLeftFull, $bottomRightFull, -45, 30, 0, 0)
- EndFunc
- Func GrindJustElementals()
- Local $altCoords1[2]
- Local $altCoords2[2]
- $altCoords1[0] = $topLeftFull[0] + ($screenWidth * 0.3)
- $altCoords1[1] = $topLeftFull[1] + ($screenHeight * 0.6)
- $altCoords2[0] = $topLeftFull[0]
- $altCoords2[1] = $bottomRightFull[1]
- GrindSubCave($altCoords1, $bottomRightFull, 25, -35, 0, 0)
- EndFunc
- Func GrindBubblers()
- Local $altCoords1[2]
- Local $altCoords2[2]
- $altCoords1[0] = $bottomRightFull[0]
- $altCoords1[1] = $topLeftFull[1]
- $altCoords2[0] = $topLeftFull[0]
- $altCoords2[1] = $bottomRightFull[1]
- GrindSubCave($altCoords1, $altCoords2, 45, 30, 0, 1)
- EndFunc
- ; Grind BRA starting from center of town.
- Func GrindBra()
- ; Navigate there.
- GoSouth()
- GoEast()
- GoEast()
- GoEast()
- GoEast()
- GoEast()
- GoCenter()
- ; Enter the arena.
- $entrance = findBattle($topLeftFull, $bottomRightFull, 5)
- goToBattle($entrance)
- ClearArena()
- ; XXX need to do something here
- EndFunc
- ; Grind a whole arena. Oh yeah.
- Func ClearArena()
- Local $altBottomRight[2]
- $altBottomRight[0] = $topLeftFull[0] + ($screenWidth * 1)
- $altBottomRight[1] = $topLeftFull[1] + ($screenHeight * 0.9)
- While 1
- Local $oldPad[2]
- $oldPad[0] = 0
- $oldPad[1] = 0
- $entryPad = findWhitePad($topLeftFull, $bottomRightFull, $oldPad)
- ClearCave($topLeftFull, $altBottomRight, 0, 0, 0)
- ; This version heals.
- ; ClearCave($topLeftFull, $altBottomRight, 0, 0, 1)
- If @error Then
- SetError(1)
- return
- EndIf
- $exitPad = findWhitePad($topLeftFull, $bottomRightFull, $entryPad)
- ;MouseMove($exitPad[0], $exitPad[1], 0)
- ;Sleep(5000)
- goToBattle($exitPad)
- WEnd
- EndFunc
- ; Grind just mushrooms in the mushroom grinding spot.
- Func GrindMushrooms()
- GrindSubCave($topLeftFull, $bottomRightFull, -45, 30, 0, 0)
- EndFunc
- ; Grind just octogums in the octogum grinding spot.
- Func GrindOctogum()
- Local $top[2]
- Local $bottom[2]
- ; Grind the left half of the screen. Step away to the upper left.
- $top[0] = $topLeftFull[0]
- $top[1] = $topLeftFull[1]
- $bottom[0] = $topLeftFull[0] + ($screenWidth * 0.5)
- $bottom[1] = $bottomRightFull[1]
- GrindSubCave($top, $bottom, -45, -30, 500)
- EndFunc
- Func GrindChoppersAdvanced()
- Local $exitBox[4]
- Local $battleBox[4]
- $exitBox[0] = $topLeftFull[0] + ($screenWidth * 0.1)
- $exitBox[1] = $topLeftFull[1] + ($screenHeight * 0.7)
- $exitBox[2] = $topLeftFull[0] + ($screenWidth * 0.4)
- $exitBox[3] = $topLeftFull[1] + ($screenHeight * 0.9)
- $battleBox[0] = $topLeftFull[0] + ($screenWidth * 0.5)
- $battleBox[1] = $topLeftFull[1] + ($screenHeight * 0.3)
- $battleBox[2] = $topLeftFull[0] + ($screenWidth)
- $battleBox[3] = $topLeftFull[1] + ($screenHeight * 0.8)
- $buffAt = 7
- $nFights = 3
- GrindSubCaveAdvanced($battleBox, $exitBox, -35, 0, 0, $nFights)
- EndFunc
- Func GrindSkeletonsAdvanced()
- Local $exitBox[4]
- Local $battleBox[4]
- $exitBox[0] = $topLeftFull[0] + ($screenWidth * 0.7)
- $exitBox[1] = $topLeftFull[1] + ($screenHeight * 0.8)
- $exitBox[2] = $topLeftFull[0] + ($screenWidth * 0.9)
- $exitBox[3] = $topLeftFull[1] + ($screenHeight * 0.9)
- $battleBox[0] = $topLeftFull[0] + ($screenWidth * 0.25)
- $battleBox[1] = $topLeftFull[1] + ($screenHeight * 0.3)
- $battleBox[2] = $topLeftFull[0] + ($screenWidth * 0.8)
- $battleBox[3] = $topLeftFull[1] + ($screenHeight * 0.82)
- $buffAt = 15
- $nFights = 4
- GrindSubCaveAdvanced($battleBox, $exitBox, 55, 35, 0, $nFights)
- EndFunc
- Func GrindSubCaveAdvanced($battleBox, $exitBox, $adjustX, $adjustY, $useMagic, $nBattles)
- $errorCount = 0
- $entrance = findBattle($topLeftFull, $bottomRightFull, 5)
- If @error Then
- MsgBox(8192, "Can't find a battle to go to", "Can't find a battle to go to", 1)
- return
- EndIf
- Local $adjusted[2]
- $adjusted[0] = $entrance[0] + $adjustX
- $adjusted[1] = $entrance[1] + $adjustY
- While 1
- goToBattle($entrance)
- If @error Then
- RecoverError(0, 0)
- MsgBox(8192, "go to entrance failed", "go to entrance failed", 1)
- $anyBattle = findBattle($topLeftFull, $bottomRightFull, 5)
- If @error Then
- SetError(1)
- return
- EndIf
- EndIf
- ; DismissUserWindow()
- ClearCaveAdvanced($battleBox, $exitBox, $useMagic, $nBattles)
- If @error Then
- ; Restart.
- RecoverError(0, 0)
- $exit = findBattle2($exitBox, 5)
- If Not @error Then
- ; Restart
- GoToBattle($exit)
- Else
- SetError(1)
- return
- EndIf
- EndIf
- ; Step away from the pad
- ; MsgBox(8192, "moving away", $adjustY, 1)
- goToPosition($adjusted)
- Sleep(100)
- WEnd
- EndFunc
- Func GrindSubCave($topLeft, $bottomRight, $adjustX, $adjustY, $extraDelay, $useMagic)
- $errorCount = 0
- $entrance = findBattle($topLeftFull, $bottomRightFull, 5)
- If @error Then
- MsgBox(8192, "Can't find a battle to go to", "Can't find a battle to go to", 5)
- EndIf
- Local $adjusted[2]
- $adjusted[0] = $entrance[0] + $adjustX
- $adjusted[1] = $entrance[1] + $adjustY
- While 1
- goToBattle($entrance)
- If @error Then
- RecoverError(0, 0)
- MsgBox(8192, "go to entrance failed", "go to entrance failed", 1)
- $anyBattle = findBattle($topLeftFull, $bottomRightFull, 5)
- If @error Then
- SetError(1)
- return
- EndIf
- EndIf
- DismissUserWindow()
- ClearCave($topLeft, $bottomRight, $extraDelay, $useMagic, 0)
- If @error Then
- RecoverError(0, 0)
- ;$nBattles = 0
- ;RecoverError($nBattles, $adjusted)
- ;ClearCave($topLeft, $bottomRight, $extraDelay, $useMagic, 0)
- EndIf
- ; Step away from the pad
- ; MsgBox(8192, "moving away", $adjustY, 1)
- goToPosition($adjusted)
- Sleep(100)
- WEnd
- EndFunc
- ; Generic cave grinder.
- Func GrindCave()
- ; The offset bit needs to be fixed.
- GrindSubCave($topLeftFull, $bottomRightFull, -45, 30, 0, 0)
- EndFunc
- Func findWhitePadQuick($topLeft, $bottomRight)
- Local $oldPad[2]
- $oldPad[0] = 0
- $oldPad[1] = 0
- return findWhitePad($topLeft, $bottomRight, $oldPad)
- EndFunc
- Func GoSouth()
- Local $altTopLeft[2]
- $altTopLeft[0] = $topLeftFull[0]
- $altTopLeft[1] = $topLeftFull[1] + ($screenHeight * 0.75)
- $pad = findWhitePadQuick($altTopLeft, $bottomRightFull)
- goToBattle($pad)
- EndFunc
- Func GoEast()
- Local $altTopLeft[2]
- $altTopLeft[0] = $topLeftFull[0] + ($screenWidth * 0.75)
- $altTopLeft[1] = $topLeftFull[1]
- $pad = findWhitePadQuick($altTopLeft, $bottomRightFull)
- $pad[1] += 5
- goToBattle($pad)
- EndFunc
- Func GoCenter()
- Local $altTopLeft[2]
- Local $altBottomRight[2]
- $altTopLeft[0] = $topLeftFull[0] + ($screenWidth * 0.20)
- $altTopLeft[1] = $topLeftFull[1] + ($screenHeight * 0.35)
- $altBottomRight[0] = $bottomRightFull[0] + ($screenWidth * 0.80)
- $altBottomRight[1] = $bottomRightFull[1] + ($screenHeight * 0.80)
- $pad = findWhitePadQuick($altTopLeft, $altBottomRight)
- $pad[1] += 5
- goToBattle($pad)
- EndFunc
- Func RecoverError($nBattles, $stepOffPosition)
- ;MsgBox(8192, "RecoverError called", "RecoverError called", 1)
- If InBattle() Then
- ClearBattle(0, 0, 0)
- EndIf
- ;DismissUserWindow()
- ;SayOK()
- ;PressCancel()
- EndFunc
- Func ClearCaveAdvanced($battleBox, $exitBox, $heal, $nBattles)
- $buffNow = $buffAt
- $seenBattles = 0
- $nErrors = 0
- While $seenBattles < $nBattles
- ; DismissUserWindow()
- $nowBattle = findBattle2($battleBox, 1)
- If Not @error Then
- goToBattle($nowBattle)
- If @error Then
- $nowBattle = findBattle2($battleBox, 1)
- goToBattle($nowBattle)
- EndIf
- If Mod($buffNow, 2) == 0 Then
- $buffThisTime = 0
- Else
- $buffThisTime = 1
- EndIf
- Sleep(500)
- ClearBattle(0, $heal, $buffThisTime)
- If @error Then
- If InBattle() Then
- ClearBattle(0, 0, 0)
- Else
- ; Need to recover at the higher level.
- SetError($seenBattles + 1)
- return
- EndIf
- EndIf
- $seenBattles += 1
- $buffNow = BitShift($buffNow, 1)
- ; Enable chatting
- EnableChat()
- Else
- $nErrors += 1
- If $nErrors > 7 Then
- MsgBox(8192, "Giving up!", "Giving up!", 1)
- SetError($seenBattles + 1)
- return
- EndIf
- Sleep(1000)
- EndIf
- WEnd
- ; Exit may be red or blue.
- $exit = findBattle2($exitBox, 1)
- If @error Then
- $exit = findBluePad2($exitBox)
- If @error Then
- MsgBox(8192, "No exit!", "No exit!", 1)
- SetError($seenBattles + 1)
- return
- EndIf
- EndIf
- goToBattle($exit)
- EndFunc
- Func ClearCave($topLeft, $bottomRight, $extraDelay, $useMagic, $heal)
- ; MsgBox(8192, $useMagic, $useMagic, 1)
- $buffNow = $buffAt
- $nBattles = 0
- $nowMagic = $useMagic
- Local $nowBattle[2]
- $nowBattle[0] = $topLeftFull[0]
- $nowBattle[1] = $topLeftFull[1]
- Do
- $oldBattle = $nowBattle
- ; DismissUserWindow()
- $nowBattle = findBattle($topLeft, $bottomRight, 1)
- If Not @error Then
- goToBattle($nowBattle)
- If @error Then
- $nowBattle = findBattle($bottomRight, $topLeft, 1)
- goToBattle($nowBattle)
- EndIf
- If Mod($buffNow, 2) == 0 Then
- $buffThisTime = 0
- Else
- $buffThisTime = 1
- EndIf
- Sleep(400)
- ClearBattle($nowMagic, $heal, $buffThisTime)
- If @error Then
- ; Need to recover at the higher level.
- SetError($nBattles + 1)
- return
- EndIf
- $nBattles += 1
- $nowMagic -= 1
- $buffNow = BitShift($buffNow, 1)
- ; $buffNow -= 1
- ; Enable chatting
- EnableChat()
- EndIf
- Until @error
- ; Look for a blue exit pad.
- $bluePad = findBluePad($topLeftFull, $bottomRightFull)
- If Not @error Then
- goToBattle($bluePad)
- EndIf
- EndFunc
- Func findBattle2($box, $maxTries)
- $tries = 0
- While $tries < $maxTries
- $coord = PixelSearch($box[0], $box[1], $box[2], $box[3], $battlePadColor, 0)
- If Not @error Then
- $coord[1] += 3
- return $coord
- Else
- If $maxTries > 1 Then
- MsgBox(8192, "Can't find a battle, waiting a while", "Can't find a battle, waiting a while", 3)
- EndIf
- EndIf
- $tries = $tries + 1
- WEnd
- SetError(1)
- EndFunc
- Func findBattle($topLeft, $bottomRight, $maxTries)
- $tries = 0
- While $tries < $maxTries
- $coord = PixelSearch($topLeft[0], $topLeft[1], $bottomRight[0], $bottomRight[1], $battlePadColor, 0)
- If Not @error Then
- $coord[1] += 3
- return $coord
- Else
- If $maxTries > 1 Then
- MsgBox(8192, "Can't find a battle, waiting a while", "Can't find a battle, waiting a while", 3)
- EndIf
- EndIf
- $tries = $tries + 1
- WEnd
- SetError(1)
- EndFunc
- Func findWhitePad($topLeft, $bottomRight, $oldPad)
- Local $default[2]
- $default[0] = 0
- $default[1] = 0
- $whitePadColor = 0xF5F1E8
- $fudge = 5
- ; Top left to bottom right.
- $coord = PixelSearch($topLeft[0], $topLeft[1], $bottomRight[0], $bottomRight[1], $whitePadColor, 0)
- If Not @error Then
- If $coord[0] <> $oldPad[0] Then
- $coord[1] += $fudge
- return $coord
- EndIf
- EndIf
- ; BR to TL.
- $coord = PixelSearch($bottomRight[0], $bottomRight[1], $topLeft[0], $topLeft[1], $whitePadColor, 0)
- If Not @error Then
- If $coord[0] <> $oldPad[0] Then
- $coord[1] += $fudge
- return $coord
- Else
- SetError(1)
- return $oldPad
- EndIf
- Else
- SetError(1)
- return $default
- EndIf
- EndFunc
- Func findBluePad2($box)
- ;MsgBox(8192, "findBluePad", "findBluePad called", 10)
- $coord = PixelSearch($box[0], $box[1], $box[2], $box[3], $bluePadColor, 0)
- If Not @error Then
- $coord[0] += 10
- $coord[1] += 6
- return $coord
- Else
- SetError(1)
- EndIf
- EndFunc
- Func findBluePad($topLeft, $bottomRight)
- ;MsgBox(8192, "findBluePad", "findBluePad called", 10)
- $coord = PixelSearch($topLeft[0], $topLeft[1], $bottomRight[0], $bottomRight[1], $bluePadColor, 0)
- ; Blue pads don't have a unique center color so we need to fudge a bit.
- ; XXX need relative values here
- If Not @error Then
- $coord[0] += 10
- $coord[1] += 6
- return $coord
- Else
- SetError(1)
- EndIf
- EndFunc
- Func NeedHeal()
- $healthBarX = $topLeftFull[0] + ($screenWidth * 0.235)
- $healthBarY = $topLeftFull[1] + ($screenHeight * 0.965)
- $healthColor = 0xECB72E
- $coord = PixelSearch($healthBarX, $healthBarY, $healthBarX+5, $healthBarY+2, $healthColor, 10)
- If @error Then
- return 1
- EndIf
- return 0
- EndFunc
- Func ClickOn($x, $y, $speed)
- MouseMove($x, $y, $speed)
- MouseClick("left")
- EndFunc
- Func EnableChat()
- If $mode == $attended Then
- $chatBoxXAbsolute = $topLeftFull[0] + ($screenWidth * 0.60)
- $chatBoxYAbsolute = $topLeftFull[1] + ($screenHeight * 1.23)
- $yReset = $topLeftFull[1] + ($screenHeight * 0.2)
- ClickOn($chatBoxXAbsolute, $chatBoxYAbsolute, $mouseSpeed)
- MouseMove(0, $yReset, 0)
- EndIf
- EndFunc
- Func NJ3($menu)
- $x = $menu[0]
- $y = $menu[1] + $skillOffset
- MouseMove($menu[0], $menu[1]+$skillOffset, $mouseSpeed)
- ClickMenu($x, $y)
- $nj3XPos = $topLeftFull[0] + ($screenWidth * 0.82)
- $nj3YPos = $topLeftFull[1] + ($screenHeight * 0.55)
- MouseMove($nj3XPos, $nj3YPos, $mouseSpeed)
- Sleep($medSleep)
- MouseClick("left")
- AttackGrid($menu)
- EndFunc
- Func Heal($menu)
- $x = $menu[0]
- $y = $menu[1] + $skillOffset
- MouseMove($menu[0], $menu[1]+$skillOffset, $mouseSpeed)
- ClickMenu($x, $y)
- $healXPos = $topLeftFull[0] + ($screenWidth * 0.63)
- $healYPos = $topLeftFull[1] + ($screenHeight * 0.65)
- MouseMove($healXPos, $healYPos, $mouseSpeed)
- Sleep($medSleep)
- MouseClick("left")
- ClickSelf()
- EndFunc
- Func BuffPlayer($menu)
- $x = $menu[0]
- $y = $menu[1] + $skillOffset
- MouseMove($menu[0], $menu[1]+$skillOffset, $mouseSpeed)
- Sleep(25)
- ClickMenu($x, $y)
- $at2XPos = $topLeftFull[0] + ($screenWidth * 0.75)
- $at2YPos = $topLeftFull[1] + ($screenHeight * 0.51)
- MouseMove($at2XPos, $at2YPos, $mouseSpeed)
- Sleep(25)
- MouseClick("left")
- Sleep(10)
- ClickSelf()
- EndFunc
- Func ClickSelf()
- $selfXPos = $topLeftFull[0] + ($screenWidth * 0.34)
- $selfYPos = $topLeftFull[1] + ($screenHeight * 0.31)
- MouseMove($selfXPos, $selfYPos, $mouseSpeed)
- ;Sleep($medSleep)
- Sleep(25)
- MouseClick("left")
- EndFunc
- Func ClickMenu($x, $y)
- $clickMenuSpeed = 2
- MouseMove($x-10, $y, $clickMenuSpeed)
- MouseClick("left")
- EndFunc
- Func AttackGrid($menu)
- ; Attack(0.755, 0.83)
- ; Attack(0.715, 0.83)
- ;; Attack(0.690, 0.66)
- Attack(0.640, 0.41)
- Attack(0.665, 0.52)
- Attack(0.690, 0.66)
- ; Attack(0.715, 0.83)
- ; Attack(0.755, 0.83)
- ;Attack(0.810, 0.41)
- ;Attack(0.835, 0.52)
- ;Attack(0.860, 0.66)
- ;Attack(0.895, 0.83)
- Attack(0.900, 0.41)
- Attack(0.925, 0.52)
- Attack(0.950, 0.66)
- Attack(0.965, 0.83)
- EndFunc
- Func Attack($x, $y)
- $xPos = $topLeftFull[0] + ($screenWidth * $x)
- $yPos = $topLeftFull[1] + ($screenHeight * $y)
- MouseMove($xPos, $yPos, 0)
- $reallyQuickSleep = 2
- MouseClick("left")
- EndFunc
- Func ClearBattle($useMagic, $heal, $buff)
- $cancelled = 0
- $maxBackoff = 50
- ; Enable chatting
- EnableChat()
- $coord = findMenu()
- If @error Then
- SetError(1)
- return
- EndIf
- $coord[0] -= 10
- ; Apply buff if set to do so.
- If $buff == 1 Then
- BuffPlayer($coord)
- $sleepTime = 50
- $waitTime = 50
- Else
- $sleepTime = 2500
- $waitTime = 50
- EndIf
- $cancelAfter = ((4500 - $sleepTime) / ($waitTime + ($maxBackoff/3)))
- $clear = 0
- $extra = 0
- While $clear < 1
- ; See if we should heal.
- If $heal Then
- $needHeal = NeedHeal()
- ; $haveMagic = HaveMagic()
- $haveMagic = 1
- If $needHeal == 1 Then
- Heal($coord)
- EndIf
- EndIf
- If $useMagic == 1 Then
- NJ3($coord)
- $useMagic = 0
- Else
- $y = $coord[1]+$attackOffset
- MouseMove($coord[0], $y, $mouseSpeed)
- ; Attack every possible position.
- ClickMenu($coord[0], $y)
- AttackGrid($coord)
- EndIf
- ; Determine next move.
- MouseMove($coord[0], $coord[1]+$attackOffset, $mouseSpeed)
- $waiting = 1
- Sleep($sleepTime)
- $waited = 0
- $backoff = 0
- While $waiting > 0
- Sleep($waitTime + $backoff)
- MouseMove($coord[0], $coord[1]+$attackOffset, $mouseSpeed)
- $clear = IsBattleClear()
- If $clear == 1 Then
- SayOK()
- return
- ElseIf IsAttackReady($coord) Then
- $backoff = 0
- $waiting = 0
- EndIf
- $waited = $waited + 1
- $backoff += 5
- If $backoff > $maxBackoff Then
- $backoff = 50
- EndIf
- # Seem to have gotten stuck, unstick.
- If $waited > $cancelAfter Then
- PressCancel()
- $cancelled = $cancelled + 1
- If $cancelled == 2 Then
- $coord = findMenu()
- If @error Then
- SetError(1)
- return 1
- EndIf
- ElseIf $cancelled > 5 Then
- ; Assume we died in battle.
- SetError(1)
- return
- EndIf
- $waited = 0
- $backoff = 0
- EndIf
- WEnd
- WEnd
- EndFunc
- Func PressCancel()
- $cancelX = $topLeftFull[0] + ($screenWidth * 0.5)
- $cancelY = $topLeftFull[1] + ($screenHeight * 0.89)
- MouseMove($cancelX, $cancelY, $mouseSpeed)
- MouseClick("left")
- EndFunc
- Func IsAttackReady($coord)
- $coord = PixelSearch($coord[0], $coord[1], $coord[0]+2, $coord[1]+40, $menuColor, 3)
- If Not @error Then
- return 1
- Else
- return 0
- EndIf
- EndFunc
- Func SayOK()
- MouseMove($okOffsetXAbs, $okOffsetYAbs, $mouseSpeed)
- Sleep(50)
- MouseClick("left")
- If $mode == $attended Then
- Sleep(500)
- Else
- Sleep(1500)
- EndIf
- EndFunc
- Func goToPosition($coord)
- MouseMove($coord[0], $coord[1], $mouseSpeed)
- If $mode = $unattended Then
- Sleep(150)
- EndIf
- DoubleClick()
- EndFunc
- Func ResetCursor()
- $xReset = $topLeftFull[0] + ($screenWidth * 0.5)
- $yReset = $topLeftFull[1] + ($screenHeight * 0.2)
- MouseMove($xReset, $yReset, 0)
- EndFunc
- Func goToBattle($coord)
- $maxTries = 4
- $tries = 0
- $extraWait = 1100
- $constantFactor = -300
- $initValue = -1
- While $tries < $maxTries
- MouseMove($coord[0], $coord[1], $mouseSpeed)
- If $mode = $unattended Then
- Sleep(150)
- EndIf
- DoubleClick()
- ResetCursor()
- $initValue = WaitForRoomChange($extraWait + $constantFactor, $initValue)
- If Not @error Then
- return
- EndIf
- $tries = $tries + 1
- $extraWait *= 2
- If $tries > 2 Then
- DismissUserWindow()
- EndIf
- WEnd
- MsgBox(8192, "goToBattle failed", "goToBattle failed", 1)
- SetError(1)
- EndFunc
- Func DoubleClick()
- $doubleClickTime = 150
- MouseClick("left")
- Sleep($doubleClickTime)
- MouseClick("left")
- EndFunc
- Func IsBattleClear()
- $xMin = $topLeftFull[0] + ($screenWidth * 0.49)
- $xMax = $topLeftFull[0] + ($screenWidth * 0.51)
- $yMin = $topLeftFull[1] + ($screenHeight * 0.3)
- $yMax = $topLeftFull[1] + ($screenHeight * 0.5)
- $coord = PixelSearch($xMin, $yMin, $xMax, $yMax, $battleClearColor, 3)
- If Not @error Then
- return 1
- Else
- return 0
- EndIf
- EndFunc
- Func findMenu()
- $maxTries = 5
- If $mode == $unattended Then
- Sleep(250)
- EndIf
- If Not InBattle() Then
- SetError(2)
- return
- EndIf
- $tries = 0
- While $tries < $maxTries
- $coord = findMenuInner()
- If Not @error Then
- return $coord
- EndIf
- ; Wait a moment.
- $tries = $tries + 1
- Sleep(250 * $tries)
- WEnd
- SetError(1)
- EndFunc
- Func findMenuInner()
- $menuOffsetPercent = 0.51
- $menuOffsetXAbs = $topLeftFull[0] + ($screenWidth * $menuOffsetPercent)
- $menuOffsetYMin = $topLeftFull[1] + ($screenHeight * 0.3)
- $menuOffsetYMax = $topLeftFull[1] + ($screenHeight * 0.8)
- $boxWidth = 20
- $boxHeight = 20
- $xPos = $menuOffsetXAbs
- $yPos = $menuOffsetYMin
- If $mode == $attended Then
- $menuSearchWaitTime = 0
- $moveSleep = 2
- $boxSize = 8
- Else
- $menuSearchWaitTime = 250
- $moveSleep = 3
- $boxSize = 5
- EndIf
- While $yPos < $menuOffsetYMax
- MouseMove($xPos, $yPos, 0)
- Sleep($moveSleep)
- $coord = PixelSearch($xPos, $yPos-25, $xPos+$boxWidth, $yPos+$boxHeight, $menuColor, 3)
- If Not @error Then
- ; Now scan up.
- While 1
- $oldCoord = $coord
- $yPos -= 5
- MouseMove($xPos, $yPos, 1)
- Sleep(10)
- $coord = PixelSearch($xPos, $yPos-$boxHeight, $xPos+$boxWidth, $yPos+$boxHeight, $menuColor, 3)
- If @error Then
- Sleep($menuSearchWaitTime)
- EndIf
- $coord = PixelSearch($xPos, $yPos-$boxHeight, $xPos+$boxWidth, $yPos+$boxHeight, $menuColor, 3)
- If @error Then
- return $oldCoord
- EndIf
- WEnd
- Else
- $yPos += $boxSize
- EndIf
- WEnd
- SetError(1)
- EndFunc
- Func WaitForRoomChange($milliSeconds, $initValue)
- $left = $topLeftFull[0] + ($screenWidth*0.92)
- $right = $topLeftFull[0] + ($screenWidth*0.94)
- $top = $topLeftFull[1] + ($screenHeight*0.03)
- $bottom = $topLeftFull[1] + ($screenHeight*0.05)
- $decay = 200
- If $initValue == -1 Then
- $start = PixelChecksum($left, $top, $right, $bottom)
- Else
- $start = $initValue
- EndIf
- $count = 0
- $maxCount = $milliSeconds / 100
- While 1
- $count = $count + 1
- If $count > $maxCount Then
- ; Assume some sort of problem.
- SetError(1)
- return $start
- EndIf
- Sleep(100 + $decay)
- $end = PixelCheckSum($left, $top, $right, $bottom)
- If $end <> $start Then
- ; MsgBox(8192, "screen has changed", "screen has changed", 1)
- If $mode == $attended Then
- Sleep(300)
- Else
- Sleep(1500)
- EndIf
- return $start
- EndIf
- $decay /= 2
- WEnd
- EndFunc
- Func Terminate()
- Exit
- EndFunc
- ; Close the annoying box that pops up when you click a player.
- Func DismissUserWindow()
- $disable = 1
- If $disable <> 1 Then
- $x = $topLeftFull[0] + ($screenWidth * 0.43)
- $y = $topLeftFull[1] + ($screenHeight * 0.22)
- MouseMove($x, $y, 0)
- MouseClick("left")
- sleep(150)
- EndIf
- return
- EndFunc
- ; Switch to a given class.
- Func SwitchClass($class)
- return
- EndFunc
- ; Leave a battle.
- Func LeaveBattle($menu)
- return
- EndFunc
- Func InBattle()
- $menuActiveColor = 0xAF3E32
- $menuInactiveColor = 0x9E6660
- $menuX = $topLeftFull[0] + ($screenWidth * 0.93)
- $menuY = $topLeftFull[1] + ($screenHeight * 0.05)
- ResetCursor()
- If $mode == $unattended Then
- Sleep(200)
- EndIf
- ; $coord = PixelSearch($menuX, $menuY, $menuX+20, $menuY+50, $menuInactiveColor, 30)
- $coord = PixelSearch($menuX, $menuY, $menuX+20, $menuY+50, $menuInactiveColor, 10)
- If @error Then
- return 1
- EndIf
- return 0
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement