Advertisement
Guest User

Untitled

a guest
Mar 27th, 2010
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.82 KB | None | 0 0
  1. ; Sacred seasons grind script.
  2. ; It's an autoit v3 script. Assumes your browser is in the top right of the screen.
  3. ; You will need to edit this to get it working for you but not too much.
  4. ; See sample videos at http://www.youtube.com/user/rbrbran277
  5. ; Last updated Jan 30 2010.
  6.  
  7. AdlibEnable("pause"); this keeps running at all times till you exit.
  8. HotKeySet("{ESC}", "Terminate")
  9. HotKeySet("{pause}","pauseset"); uses the pause key to change the value of $Pause
  10. $Pause = 1
  11. Func pauseset()
  12. $Pause = $Pause * -1
  13. EndFunc
  14. Func pause()
  15. While $Pause = -1
  16. Sleep(500)
  17. Wend
  18. EndFunc
  19.  
  20. ; Screen dimensions.
  21. Global $topLeftFull[2]
  22. Global $bottomRightFull[2]
  23. GetGameDimensions()
  24. $screenWidth = $bottomRightFull[0] - $topLeftFull[0]
  25. $screenHeight = $bottomRightFull[1] - $topLeftFull[1]
  26. $okOffsetXAbs = $topLeftFull[0] + ($screenWidth * 0.5)
  27. $okOffsetYAbs = $topLeftFull[1] + ($screenHeight * 0.76)
  28. $attackOffset = 0.051 * $screenHeight
  29. $skillOffset = 0.11 * $screenHeight
  30.  
  31. ; Game colors.
  32. $battlePadColor = 0xFB4743
  33. $battleClearColor = 0x5AE3FF
  34. $battleClearColor = 0x25DAFF
  35. $menuColor = 0xFF003C
  36. $bluePadColor = 0x6DFBF6
  37.  
  38. ; Timing settings.
  39. ; Unattended mode runs slower but is less likely to suffer lag related problems.
  40. $attended = 0
  41. $unattended = 1
  42. $mode = $attended
  43. ; $mode = $unattended
  44. If $mode == $attended Then
  45. $mouseSpeed = 1
  46. $medSleep = 250
  47. $quickSleep = 10
  48. $walkFactor = 3
  49. $roomLoadDelay = 2000
  50. Else
  51. $mouseSpeed = 3
  52. $medSleep = 250
  53. $quickSleep = 10
  54. $walkFactor = 3
  55. $roomLoadDelay = 2000
  56. EndIf
  57. $buffAt = 0
  58.  
  59. ; These are various programs you can run.
  60. ; GrindTsulas()
  61. ; GrindSubTsulas()
  62. ; GrindPonies()
  63. ; GrindMushrooms()
  64. ; GrindOctogum()
  65. ; GrindBubblers()
  66. ; GrindElementals()
  67. ; GrindJustElementals()
  68. ; GrindOctogum2()
  69. ; GrindFto1()
  70. ; ClearArena()
  71. ; GrindCave()
  72. ; GrindChoppers()
  73. ; GrindChoppersAdvanced()
  74. ; GrindSkeletons()
  75. ; GrindSkeletons2()
  76. GrindSkeletonsAdvanced()
  77.  
  78. ; For testing
  79. ; ClearBattle(0, 0, 1)
  80. ; ClearBattle(0, 1, 0)
  81. ; ClearBattle(0, 1, 1)
  82. ; FindMenu()
  83. ; GrindBra()
  84. ; GoCenter()
  85. ; $x = NeedHeal()
  86. ; MsgBox(8192, $x, $x, 1)
  87. ; DismissUserWindow()
  88. ; $inb = InBattle()
  89. ; MsgBox(8192, $inb, $inb, 1)
  90.  
  91. Func GetGameDimensions()
  92. $var = WinList()
  93. $searchFor = "Sacred Seasons MMORPG"
  94. For $i = 1 to $var[0][0]
  95. If StringRegExp($var[$i][0], $searchFor) Then
  96. ;$window = $var[$i][1]
  97. ;$controlPos = ControlGetPos($window, "", "[CLASS:MacromediaFlashPlayerActiveX]")
  98. ;$windowPos = WinGetPos($window, "")
  99. ;$x = $windowPos[0] + $controlPos[0]
  100. ;$y = $windowPos[1] + $controlPos[1] + 20
  101. ;$topLeftFull[0] = $x
  102. ;$topLeftFull[1] = $y
  103. ;$bottomRightFull[0] = $x + $controlPos[2]
  104. ;$bottomRightFull[1] = $y + $controlPos[3]
  105. ; XXX: temporary hack.
  106. ;$bottomRightFull[1] -= 120
  107.  
  108. $topLeftFull[0] = 5
  109. $topLeftFull[1] = 115
  110. $bottomRightFull[0] = 750
  111. $bottomRightFull[1] = 590
  112. ;MsgBox(8192, $topLeftFull[0], $topLeftFull[0], 5)
  113. ;MsgBox(8192, $topLeftFull[1], $topLeftFull[1], 5)
  114. ;MsgBox(8192, $bottomRightFull[0], $bottomRightFull[0], 5)
  115. ;MsgBox(8192, $bottomRightFull[1], $bottomRightFull[1], 5)
  116. EndIf
  117. Next
  118. EndFunc
  119.  
  120. ; To grind you have to step off the pad when you're done. There are 4 ways to do that.
  121. Global $upAndToTheLeft[2]
  122. Global $upAndToTheRight[2]
  123. Global $downAndToTheLeft[2]
  124. Global $downAndToTheRight[2]
  125.  
  126. Func GrindTsulas()
  127. GrindSubCave($bottomRightFull, $topLeftFull, -45, -25, 0, 0)
  128. EndFunc
  129.  
  130. Func GrindSubTsulas()
  131. Local $altCoords1[2]
  132. $altCoords1[0] = $topLeftFull[0] + ($screenWidth * 0.36)
  133. $altCoords1[1] = $topLeftFull[1] + ($screenHeight * 0.3)
  134.  
  135. GrindSubCave($bottomRightFull, $altCoords1, -45, -25, 0, 0)
  136. EndFunc
  137.  
  138. Func GrindPonies()
  139. GrindSubCave($topLeftFull, $bottomRightFull, 45, 25, 0, 0)
  140. EndFunc
  141.  
  142. Func GrindChoppers()
  143. ; GrindSubCave($topLeftFull, $bottomRightFull, -65, -15, 0, 2)
  144. $buffAt = 3
  145. $buffAt = 7
  146. GrindSubCave($topLeftFull, $bottomRightFull, -35, 0, 0, 0)
  147. EndFunc
  148.  
  149. Func GrindSkeletons()
  150. $buffAt = 6
  151. ;$buffAt = 14
  152. GrindSubCave($topLeftFull, $bottomRightFull, -35, 0, 0, 0)
  153. EndFunc
  154.  
  155. Func GrindSkeletons2()
  156. $buffAt = 7
  157. GrindSubCave($topLeftFull, $bottomRightFull, 35, 25, 0, 0)
  158. EndFunc
  159.  
  160. Func GrindElementals()
  161. GrindSubCave($topLeftFull, $bottomRightFull, 25, -35, 0, 1)
  162. EndFunc
  163.  
  164. Func GrindOctogum2()
  165. GrindSubCave($topLeftFull, $bottomRightFull, -45, -30, 0, 0)
  166. EndFunc
  167.  
  168. Func GrindFto1()
  169. GrindSubCave($topLeftFull, $bottomRightFull, -45, 30, 0, 0)
  170. EndFunc
  171.  
  172. Func GrindJustElementals()
  173. Local $altCoords1[2]
  174. Local $altCoords2[2]
  175. $altCoords1[0] = $topLeftFull[0] + ($screenWidth * 0.3)
  176. $altCoords1[1] = $topLeftFull[1] + ($screenHeight * 0.6)
  177. $altCoords2[0] = $topLeftFull[0]
  178. $altCoords2[1] = $bottomRightFull[1]
  179.  
  180. GrindSubCave($altCoords1, $bottomRightFull, 25, -35, 0, 0)
  181. EndFunc
  182.  
  183. Func GrindBubblers()
  184. Local $altCoords1[2]
  185. Local $altCoords2[2]
  186. $altCoords1[0] = $bottomRightFull[0]
  187. $altCoords1[1] = $topLeftFull[1]
  188. $altCoords2[0] = $topLeftFull[0]
  189. $altCoords2[1] = $bottomRightFull[1]
  190.  
  191. GrindSubCave($altCoords1, $altCoords2, 45, 30, 0, 1)
  192. EndFunc
  193.  
  194. ; Grind BRA starting from center of town.
  195. Func GrindBra()
  196. ; Navigate there.
  197. GoSouth()
  198. GoEast()
  199. GoEast()
  200. GoEast()
  201. GoEast()
  202. GoEast()
  203. GoCenter()
  204.  
  205. ; Enter the arena.
  206. $entrance = findBattle($topLeftFull, $bottomRightFull, 5)
  207. goToBattle($entrance)
  208.  
  209. ClearArena()
  210. ; XXX need to do something here
  211. EndFunc
  212.  
  213. ; Grind a whole arena. Oh yeah.
  214. Func ClearArena()
  215. Local $altBottomRight[2]
  216. $altBottomRight[0] = $topLeftFull[0] + ($screenWidth * 1)
  217. $altBottomRight[1] = $topLeftFull[1] + ($screenHeight * 0.9)
  218.  
  219. While 1
  220. Local $oldPad[2]
  221. $oldPad[0] = 0
  222. $oldPad[1] = 0
  223.  
  224. $entryPad = findWhitePad($topLeftFull, $bottomRightFull, $oldPad)
  225. ClearCave($topLeftFull, $altBottomRight, 0, 0, 0)
  226. ; This version heals.
  227. ; ClearCave($topLeftFull, $altBottomRight, 0, 0, 1)
  228. If @error Then
  229. SetError(1)
  230. return
  231. EndIf
  232. $exitPad = findWhitePad($topLeftFull, $bottomRightFull, $entryPad)
  233. ;MouseMove($exitPad[0], $exitPad[1], 0)
  234. ;Sleep(5000)
  235. goToBattle($exitPad)
  236. WEnd
  237. EndFunc
  238.  
  239. ; Grind just mushrooms in the mushroom grinding spot.
  240. Func GrindMushrooms()
  241. GrindSubCave($topLeftFull, $bottomRightFull, -45, 30, 0, 0)
  242. EndFunc
  243.  
  244. ; Grind just octogums in the octogum grinding spot.
  245. Func GrindOctogum()
  246. Local $top[2]
  247. Local $bottom[2]
  248.  
  249. ; Grind the left half of the screen. Step away to the upper left.
  250. $top[0] = $topLeftFull[0]
  251. $top[1] = $topLeftFull[1]
  252. $bottom[0] = $topLeftFull[0] + ($screenWidth * 0.5)
  253. $bottom[1] = $bottomRightFull[1]
  254.  
  255. GrindSubCave($top, $bottom, -45, -30, 500)
  256. EndFunc
  257.  
  258. Func GrindChoppersAdvanced()
  259. Local $exitBox[4]
  260. Local $battleBox[4]
  261. $exitBox[0] = $topLeftFull[0] + ($screenWidth * 0.1)
  262. $exitBox[1] = $topLeftFull[1] + ($screenHeight * 0.7)
  263. $exitBox[2] = $topLeftFull[0] + ($screenWidth * 0.4)
  264. $exitBox[3] = $topLeftFull[1] + ($screenHeight * 0.9)
  265. $battleBox[0] = $topLeftFull[0] + ($screenWidth * 0.5)
  266. $battleBox[1] = $topLeftFull[1] + ($screenHeight * 0.3)
  267. $battleBox[2] = $topLeftFull[0] + ($screenWidth)
  268. $battleBox[3] = $topLeftFull[1] + ($screenHeight * 0.8)
  269.  
  270. $buffAt = 7
  271. $nFights = 3
  272. GrindSubCaveAdvanced($battleBox, $exitBox, -35, 0, 0, $nFights)
  273. EndFunc
  274.  
  275. Func GrindSkeletonsAdvanced()
  276. Local $exitBox[4]
  277. Local $battleBox[4]
  278. $exitBox[0] = $topLeftFull[0] + ($screenWidth * 0.7)
  279. $exitBox[1] = $topLeftFull[1] + ($screenHeight * 0.8)
  280. $exitBox[2] = $topLeftFull[0] + ($screenWidth * 0.9)
  281. $exitBox[3] = $topLeftFull[1] + ($screenHeight * 0.9)
  282. $battleBox[0] = $topLeftFull[0] + ($screenWidth * 0.25)
  283. $battleBox[1] = $topLeftFull[1] + ($screenHeight * 0.3)
  284. $battleBox[2] = $topLeftFull[0] + ($screenWidth * 0.8)
  285. $battleBox[3] = $topLeftFull[1] + ($screenHeight * 0.82)
  286.  
  287. $buffAt = 15
  288. $nFights = 4
  289. GrindSubCaveAdvanced($battleBox, $exitBox, 55, 35, 0, $nFights)
  290. EndFunc
  291.  
  292. Func GrindSubCaveAdvanced($battleBox, $exitBox, $adjustX, $adjustY, $useMagic, $nBattles)
  293. $errorCount = 0
  294.  
  295. $entrance = findBattle($topLeftFull, $bottomRightFull, 5)
  296. If @error Then
  297. MsgBox(8192, "Can't find a battle to go to", "Can't find a battle to go to", 1)
  298. return
  299. EndIf
  300.  
  301. Local $adjusted[2]
  302. $adjusted[0] = $entrance[0] + $adjustX
  303. $adjusted[1] = $entrance[1] + $adjustY
  304. While 1
  305. goToBattle($entrance)
  306. If @error Then
  307. RecoverError(0, 0)
  308. MsgBox(8192, "go to entrance failed", "go to entrance failed", 1)
  309. $anyBattle = findBattle($topLeftFull, $bottomRightFull, 5)
  310. If @error Then
  311. SetError(1)
  312. return
  313. EndIf
  314. EndIf
  315. ; DismissUserWindow()
  316. ClearCaveAdvanced($battleBox, $exitBox, $useMagic, $nBattles)
  317. If @error Then
  318. ; Restart.
  319. RecoverError(0, 0)
  320. $exit = findBattle2($exitBox, 5)
  321. If Not @error Then
  322. ; Restart
  323. GoToBattle($exit)
  324. Else
  325. SetError(1)
  326. return
  327. EndIf
  328. EndIf
  329.  
  330. ; Step away from the pad
  331. ; MsgBox(8192, "moving away", $adjustY, 1)
  332. goToPosition($adjusted)
  333. Sleep(100)
  334. WEnd
  335. EndFunc
  336.  
  337. Func GrindSubCave($topLeft, $bottomRight, $adjustX, $adjustY, $extraDelay, $useMagic)
  338. $errorCount = 0
  339.  
  340. $entrance = findBattle($topLeftFull, $bottomRightFull, 5)
  341. If @error Then
  342. MsgBox(8192, "Can't find a battle to go to", "Can't find a battle to go to", 5)
  343. EndIf
  344.  
  345. Local $adjusted[2]
  346. $adjusted[0] = $entrance[0] + $adjustX
  347. $adjusted[1] = $entrance[1] + $adjustY
  348. While 1
  349. goToBattle($entrance)
  350. If @error Then
  351. RecoverError(0, 0)
  352. MsgBox(8192, "go to entrance failed", "go to entrance failed", 1)
  353. $anyBattle = findBattle($topLeftFull, $bottomRightFull, 5)
  354. If @error Then
  355. SetError(1)
  356. return
  357. EndIf
  358. EndIf
  359. DismissUserWindow()
  360. ClearCave($topLeft, $bottomRight, $extraDelay, $useMagic, 0)
  361. If @error Then
  362. RecoverError(0, 0)
  363. ;$nBattles = 0
  364. ;RecoverError($nBattles, $adjusted)
  365. ;ClearCave($topLeft, $bottomRight, $extraDelay, $useMagic, 0)
  366. EndIf
  367.  
  368. ; Step away from the pad
  369. ; MsgBox(8192, "moving away", $adjustY, 1)
  370. goToPosition($adjusted)
  371. Sleep(100)
  372. WEnd
  373. EndFunc
  374.  
  375. ; Generic cave grinder.
  376. Func GrindCave()
  377. ; The offset bit needs to be fixed.
  378. GrindSubCave($topLeftFull, $bottomRightFull, -45, 30, 0, 0)
  379. EndFunc
  380.  
  381. Func findWhitePadQuick($topLeft, $bottomRight)
  382. Local $oldPad[2]
  383. $oldPad[0] = 0
  384. $oldPad[1] = 0
  385. return findWhitePad($topLeft, $bottomRight, $oldPad)
  386. EndFunc
  387.  
  388. Func GoSouth()
  389. Local $altTopLeft[2]
  390. $altTopLeft[0] = $topLeftFull[0]
  391. $altTopLeft[1] = $topLeftFull[1] + ($screenHeight * 0.75)
  392. $pad = findWhitePadQuick($altTopLeft, $bottomRightFull)
  393. goToBattle($pad)
  394. EndFunc
  395.  
  396. Func GoEast()
  397. Local $altTopLeft[2]
  398. $altTopLeft[0] = $topLeftFull[0] + ($screenWidth * 0.75)
  399. $altTopLeft[1] = $topLeftFull[1]
  400. $pad = findWhitePadQuick($altTopLeft, $bottomRightFull)
  401. $pad[1] += 5
  402. goToBattle($pad)
  403. EndFunc
  404.  
  405. Func GoCenter()
  406. Local $altTopLeft[2]
  407. Local $altBottomRight[2]
  408. $altTopLeft[0] = $topLeftFull[0] + ($screenWidth * 0.20)
  409. $altTopLeft[1] = $topLeftFull[1] + ($screenHeight * 0.35)
  410. $altBottomRight[0] = $bottomRightFull[0] + ($screenWidth * 0.80)
  411. $altBottomRight[1] = $bottomRightFull[1] + ($screenHeight * 0.80)
  412. $pad = findWhitePadQuick($altTopLeft, $altBottomRight)
  413. $pad[1] += 5
  414. goToBattle($pad)
  415. EndFunc
  416.  
  417. Func RecoverError($nBattles, $stepOffPosition)
  418. ;MsgBox(8192, "RecoverError called", "RecoverError called", 1)
  419. If InBattle() Then
  420. ClearBattle(0, 0, 0)
  421. EndIf
  422.  
  423. ;DismissUserWindow()
  424. ;SayOK()
  425. ;PressCancel()
  426. EndFunc
  427.  
  428. Func ClearCaveAdvanced($battleBox, $exitBox, $heal, $nBattles)
  429. $buffNow = $buffAt
  430. $seenBattles = 0
  431. $nErrors = 0
  432. While $seenBattles < $nBattles
  433. ; DismissUserWindow()
  434. $nowBattle = findBattle2($battleBox, 1)
  435. If Not @error Then
  436. goToBattle($nowBattle)
  437. If @error Then
  438. $nowBattle = findBattle2($battleBox, 1)
  439. goToBattle($nowBattle)
  440. EndIf
  441. If Mod($buffNow, 2) == 0 Then
  442. $buffThisTime = 0
  443. Else
  444. $buffThisTime = 1
  445. EndIf
  446. Sleep(500)
  447. ClearBattle(0, $heal, $buffThisTime)
  448. If @error Then
  449. If InBattle() Then
  450. ClearBattle(0, 0, 0)
  451. Else
  452. ; Need to recover at the higher level.
  453. SetError($seenBattles + 1)
  454. return
  455. EndIf
  456. EndIf
  457. $seenBattles += 1
  458. $buffNow = BitShift($buffNow, 1)
  459.  
  460. ; Enable chatting
  461. EnableChat()
  462. Else
  463. $nErrors += 1
  464. If $nErrors > 7 Then
  465. MsgBox(8192, "Giving up!", "Giving up!", 1)
  466. SetError($seenBattles + 1)
  467. return
  468. EndIf
  469. Sleep(1000)
  470. EndIf
  471. WEnd
  472.  
  473. ; Exit may be red or blue.
  474. $exit = findBattle2($exitBox, 1)
  475. If @error Then
  476. $exit = findBluePad2($exitBox)
  477. If @error Then
  478. MsgBox(8192, "No exit!", "No exit!", 1)
  479. SetError($seenBattles + 1)
  480. return
  481. EndIf
  482. EndIf
  483. goToBattle($exit)
  484. EndFunc
  485.  
  486. Func ClearCave($topLeft, $bottomRight, $extraDelay, $useMagic, $heal)
  487. ; MsgBox(8192, $useMagic, $useMagic, 1)
  488.  
  489. $buffNow = $buffAt
  490. $nBattles = 0
  491. $nowMagic = $useMagic
  492. Local $nowBattle[2]
  493. $nowBattle[0] = $topLeftFull[0]
  494. $nowBattle[1] = $topLeftFull[1]
  495. Do
  496. $oldBattle = $nowBattle
  497. ; DismissUserWindow()
  498. $nowBattle = findBattle($topLeft, $bottomRight, 1)
  499. If Not @error Then
  500. goToBattle($nowBattle)
  501. If @error Then
  502. $nowBattle = findBattle($bottomRight, $topLeft, 1)
  503. goToBattle($nowBattle)
  504. EndIf
  505. If Mod($buffNow, 2) == 0 Then
  506. $buffThisTime = 0
  507. Else
  508. $buffThisTime = 1
  509. EndIf
  510. Sleep(400)
  511. ClearBattle($nowMagic, $heal, $buffThisTime)
  512. If @error Then
  513. ; Need to recover at the higher level.
  514. SetError($nBattles + 1)
  515. return
  516. EndIf
  517. $nBattles += 1
  518. $nowMagic -= 1
  519. $buffNow = BitShift($buffNow, 1)
  520. ; $buffNow -= 1
  521.  
  522. ; Enable chatting
  523. EnableChat()
  524. EndIf
  525. Until @error
  526.  
  527. ; Look for a blue exit pad.
  528. $bluePad = findBluePad($topLeftFull, $bottomRightFull)
  529. If Not @error Then
  530. goToBattle($bluePad)
  531. EndIf
  532. EndFunc
  533.  
  534. Func findBattle2($box, $maxTries)
  535. $tries = 0
  536. While $tries < $maxTries
  537. $coord = PixelSearch($box[0], $box[1], $box[2], $box[3], $battlePadColor, 0)
  538. If Not @error Then
  539. $coord[1] += 3
  540. return $coord
  541. Else
  542. If $maxTries > 1 Then
  543. MsgBox(8192, "Can't find a battle, waiting a while", "Can't find a battle, waiting a while", 3)
  544. EndIf
  545. EndIf
  546. $tries = $tries + 1
  547. WEnd
  548. SetError(1)
  549. EndFunc
  550.  
  551. Func findBattle($topLeft, $bottomRight, $maxTries)
  552. $tries = 0
  553. While $tries < $maxTries
  554. $coord = PixelSearch($topLeft[0], $topLeft[1], $bottomRight[0], $bottomRight[1], $battlePadColor, 0)
  555. If Not @error Then
  556. $coord[1] += 3
  557. return $coord
  558. Else
  559. If $maxTries > 1 Then
  560. MsgBox(8192, "Can't find a battle, waiting a while", "Can't find a battle, waiting a while", 3)
  561. EndIf
  562. EndIf
  563. $tries = $tries + 1
  564. WEnd
  565. SetError(1)
  566. EndFunc
  567.  
  568. Func findWhitePad($topLeft, $bottomRight, $oldPad)
  569. Local $default[2]
  570. $default[0] = 0
  571. $default[1] = 0
  572. $whitePadColor = 0xF5F1E8
  573. $fudge = 5
  574.  
  575. ; Top left to bottom right.
  576. $coord = PixelSearch($topLeft[0], $topLeft[1], $bottomRight[0], $bottomRight[1], $whitePadColor, 0)
  577. If Not @error Then
  578. If $coord[0] <> $oldPad[0] Then
  579. $coord[1] += $fudge
  580. return $coord
  581. EndIf
  582. EndIf
  583.  
  584. ; BR to TL.
  585. $coord = PixelSearch($bottomRight[0], $bottomRight[1], $topLeft[0], $topLeft[1], $whitePadColor, 0)
  586. If Not @error Then
  587. If $coord[0] <> $oldPad[0] Then
  588. $coord[1] += $fudge
  589. return $coord
  590. Else
  591. SetError(1)
  592. return $oldPad
  593. EndIf
  594. Else
  595. SetError(1)
  596. return $default
  597. EndIf
  598. EndFunc
  599.  
  600. Func findBluePad2($box)
  601. ;MsgBox(8192, "findBluePad", "findBluePad called", 10)
  602.  
  603. $coord = PixelSearch($box[0], $box[1], $box[2], $box[3], $bluePadColor, 0)
  604. If Not @error Then
  605. $coord[0] += 10
  606. $coord[1] += 6
  607. return $coord
  608. Else
  609. SetError(1)
  610. EndIf
  611. EndFunc
  612.  
  613. Func findBluePad($topLeft, $bottomRight)
  614. ;MsgBox(8192, "findBluePad", "findBluePad called", 10)
  615.  
  616. $coord = PixelSearch($topLeft[0], $topLeft[1], $bottomRight[0], $bottomRight[1], $bluePadColor, 0)
  617. ; Blue pads don't have a unique center color so we need to fudge a bit.
  618. ; XXX need relative values here
  619.  
  620. If Not @error Then
  621. $coord[0] += 10
  622. $coord[1] += 6
  623. return $coord
  624. Else
  625. SetError(1)
  626. EndIf
  627. EndFunc
  628.  
  629. Func NeedHeal()
  630. $healthBarX = $topLeftFull[0] + ($screenWidth * 0.235)
  631. $healthBarY = $topLeftFull[1] + ($screenHeight * 0.965)
  632. $healthColor = 0xECB72E
  633. $coord = PixelSearch($healthBarX, $healthBarY, $healthBarX+5, $healthBarY+2, $healthColor, 10)
  634. If @error Then
  635. return 1
  636. EndIf
  637. return 0
  638. EndFunc
  639.  
  640. Func ClickOn($x, $y, $speed)
  641. MouseMove($x, $y, $speed)
  642. MouseClick("left")
  643. EndFunc
  644.  
  645. Func EnableChat()
  646. If $mode == $attended Then
  647. $chatBoxXAbsolute = $topLeftFull[0] + ($screenWidth * 0.60)
  648. $chatBoxYAbsolute = $topLeftFull[1] + ($screenHeight * 1.23)
  649. $yReset = $topLeftFull[1] + ($screenHeight * 0.2)
  650. ClickOn($chatBoxXAbsolute, $chatBoxYAbsolute, $mouseSpeed)
  651. MouseMove(0, $yReset, 0)
  652. EndIf
  653. EndFunc
  654.  
  655. Func NJ3($menu)
  656. $x = $menu[0]
  657. $y = $menu[1] + $skillOffset
  658. MouseMove($menu[0], $menu[1]+$skillOffset, $mouseSpeed)
  659. ClickMenu($x, $y)
  660.  
  661. $nj3XPos = $topLeftFull[0] + ($screenWidth * 0.82)
  662. $nj3YPos = $topLeftFull[1] + ($screenHeight * 0.55)
  663. MouseMove($nj3XPos, $nj3YPos, $mouseSpeed)
  664. Sleep($medSleep)
  665. MouseClick("left")
  666. AttackGrid($menu)
  667. EndFunc
  668.  
  669. Func Heal($menu)
  670. $x = $menu[0]
  671. $y = $menu[1] + $skillOffset
  672. MouseMove($menu[0], $menu[1]+$skillOffset, $mouseSpeed)
  673. ClickMenu($x, $y)
  674.  
  675. $healXPos = $topLeftFull[0] + ($screenWidth * 0.63)
  676. $healYPos = $topLeftFull[1] + ($screenHeight * 0.65)
  677. MouseMove($healXPos, $healYPos, $mouseSpeed)
  678. Sleep($medSleep)
  679. MouseClick("left")
  680. ClickSelf()
  681. EndFunc
  682.  
  683. Func BuffPlayer($menu)
  684. $x = $menu[0]
  685. $y = $menu[1] + $skillOffset
  686. MouseMove($menu[0], $menu[1]+$skillOffset, $mouseSpeed)
  687. Sleep(25)
  688. ClickMenu($x, $y)
  689.  
  690. $at2XPos = $topLeftFull[0] + ($screenWidth * 0.75)
  691. $at2YPos = $topLeftFull[1] + ($screenHeight * 0.51)
  692. MouseMove($at2XPos, $at2YPos, $mouseSpeed)
  693. Sleep(25)
  694. MouseClick("left")
  695. Sleep(10)
  696. ClickSelf()
  697. EndFunc
  698.  
  699. Func ClickSelf()
  700. $selfXPos = $topLeftFull[0] + ($screenWidth * 0.34)
  701. $selfYPos = $topLeftFull[1] + ($screenHeight * 0.31)
  702. MouseMove($selfXPos, $selfYPos, $mouseSpeed)
  703. ;Sleep($medSleep)
  704. Sleep(25)
  705. MouseClick("left")
  706. EndFunc
  707.  
  708. Func ClickMenu($x, $y)
  709. $clickMenuSpeed = 2
  710. MouseMove($x-10, $y, $clickMenuSpeed)
  711. MouseClick("left")
  712. EndFunc
  713.  
  714. Func AttackGrid($menu)
  715. ; Attack(0.755, 0.83)
  716. ; Attack(0.715, 0.83)
  717. ;; Attack(0.690, 0.66)
  718. Attack(0.640, 0.41)
  719. Attack(0.665, 0.52)
  720. Attack(0.690, 0.66)
  721. ; Attack(0.715, 0.83)
  722. ; Attack(0.755, 0.83)
  723.  
  724. ;Attack(0.810, 0.41)
  725. ;Attack(0.835, 0.52)
  726. ;Attack(0.860, 0.66)
  727. ;Attack(0.895, 0.83)
  728.  
  729. Attack(0.900, 0.41)
  730. Attack(0.925, 0.52)
  731. Attack(0.950, 0.66)
  732. Attack(0.965, 0.83)
  733. EndFunc
  734.  
  735. Func Attack($x, $y)
  736. $xPos = $topLeftFull[0] + ($screenWidth * $x)
  737. $yPos = $topLeftFull[1] + ($screenHeight * $y)
  738. MouseMove($xPos, $yPos, 0)
  739. $reallyQuickSleep = 2
  740. MouseClick("left")
  741. EndFunc
  742.  
  743. Func ClearBattle($useMagic, $heal, $buff)
  744. $cancelled = 0
  745. $maxBackoff = 50
  746.  
  747. ; Enable chatting
  748. EnableChat()
  749.  
  750. $coord = findMenu()
  751. If @error Then
  752. SetError(1)
  753. return
  754. EndIf
  755. $coord[0] -= 10
  756.  
  757. ; Apply buff if set to do so.
  758. If $buff == 1 Then
  759. BuffPlayer($coord)
  760. $sleepTime = 50
  761. $waitTime = 50
  762. Else
  763. $sleepTime = 2500
  764. $waitTime = 50
  765. EndIf
  766. $cancelAfter = ((4500 - $sleepTime) / ($waitTime + ($maxBackoff/3)))
  767.  
  768. $clear = 0
  769. $extra = 0
  770. While $clear < 1
  771. ; See if we should heal.
  772. If $heal Then
  773. $needHeal = NeedHeal()
  774. ; $haveMagic = HaveMagic()
  775. $haveMagic = 1
  776. If $needHeal == 1 Then
  777. Heal($coord)
  778. EndIf
  779. EndIf
  780.  
  781. If $useMagic == 1 Then
  782. NJ3($coord)
  783. $useMagic = 0
  784. Else
  785. $y = $coord[1]+$attackOffset
  786. MouseMove($coord[0], $y, $mouseSpeed)
  787.  
  788. ; Attack every possible position.
  789. ClickMenu($coord[0], $y)
  790. AttackGrid($coord)
  791. EndIf
  792.  
  793. ; Determine next move.
  794. MouseMove($coord[0], $coord[1]+$attackOffset, $mouseSpeed)
  795. $waiting = 1
  796. Sleep($sleepTime)
  797. $waited = 0
  798. $backoff = 0
  799. While $waiting > 0
  800. Sleep($waitTime + $backoff)
  801. MouseMove($coord[0], $coord[1]+$attackOffset, $mouseSpeed)
  802. $clear = IsBattleClear()
  803. If $clear == 1 Then
  804. SayOK()
  805. return
  806. ElseIf IsAttackReady($coord) Then
  807. $backoff = 0
  808. $waiting = 0
  809. EndIf
  810.  
  811. $waited = $waited + 1
  812. $backoff += 5
  813. If $backoff > $maxBackoff Then
  814. $backoff = 50
  815. EndIf
  816.  
  817. # Seem to have gotten stuck, unstick.
  818. If $waited > $cancelAfter Then
  819. PressCancel()
  820. $cancelled = $cancelled + 1
  821. If $cancelled == 2 Then
  822. $coord = findMenu()
  823. If @error Then
  824. SetError(1)
  825. return 1
  826. EndIf
  827. ElseIf $cancelled > 5 Then
  828. ; Assume we died in battle.
  829. SetError(1)
  830. return
  831. EndIf
  832. $waited = 0
  833. $backoff = 0
  834. EndIf
  835. WEnd
  836. WEnd
  837. EndFunc
  838.  
  839. Func PressCancel()
  840. $cancelX = $topLeftFull[0] + ($screenWidth * 0.5)
  841. $cancelY = $topLeftFull[1] + ($screenHeight * 0.89)
  842. MouseMove($cancelX, $cancelY, $mouseSpeed)
  843. MouseClick("left")
  844. EndFunc
  845.  
  846. Func IsAttackReady($coord)
  847. $coord = PixelSearch($coord[0], $coord[1], $coord[0]+2, $coord[1]+40, $menuColor, 3)
  848. If Not @error Then
  849. return 1
  850. Else
  851. return 0
  852. EndIf
  853. EndFunc
  854.  
  855. Func SayOK()
  856. MouseMove($okOffsetXAbs, $okOffsetYAbs, $mouseSpeed)
  857. Sleep(50)
  858. MouseClick("left")
  859. If $mode == $attended Then
  860. Sleep(500)
  861. Else
  862. Sleep(1500)
  863. EndIf
  864. EndFunc
  865.  
  866. Func goToPosition($coord)
  867. MouseMove($coord[0], $coord[1], $mouseSpeed)
  868. If $mode = $unattended Then
  869. Sleep(150)
  870. EndIf
  871. DoubleClick()
  872. EndFunc
  873.  
  874. Func ResetCursor()
  875. $xReset = $topLeftFull[0] + ($screenWidth * 0.5)
  876. $yReset = $topLeftFull[1] + ($screenHeight * 0.2)
  877. MouseMove($xReset, $yReset, 0)
  878. EndFunc
  879.  
  880. Func goToBattle($coord)
  881. $maxTries = 4
  882. $tries = 0
  883. $extraWait = 1100
  884. $constantFactor = -300
  885. $initValue = -1
  886. While $tries < $maxTries
  887. MouseMove($coord[0], $coord[1], $mouseSpeed)
  888. If $mode = $unattended Then
  889. Sleep(150)
  890. EndIf
  891. DoubleClick()
  892. ResetCursor()
  893. $initValue = WaitForRoomChange($extraWait + $constantFactor, $initValue)
  894. If Not @error Then
  895. return
  896. EndIf
  897. $tries = $tries + 1
  898. $extraWait *= 2
  899. If $tries > 2 Then
  900. DismissUserWindow()
  901. EndIf
  902. WEnd
  903.  
  904. MsgBox(8192, "goToBattle failed", "goToBattle failed", 1)
  905. SetError(1)
  906. EndFunc
  907.  
  908. Func DoubleClick()
  909. $doubleClickTime = 150
  910. MouseClick("left")
  911. Sleep($doubleClickTime)
  912. MouseClick("left")
  913. EndFunc
  914.  
  915. Func IsBattleClear()
  916. $xMin = $topLeftFull[0] + ($screenWidth * 0.49)
  917. $xMax = $topLeftFull[0] + ($screenWidth * 0.51)
  918. $yMin = $topLeftFull[1] + ($screenHeight * 0.3)
  919. $yMax = $topLeftFull[1] + ($screenHeight * 0.5)
  920. $coord = PixelSearch($xMin, $yMin, $xMax, $yMax, $battleClearColor, 3)
  921. If Not @error Then
  922. return 1
  923. Else
  924. return 0
  925. EndIf
  926. EndFunc
  927.  
  928. Func findMenu()
  929. $maxTries = 5
  930.  
  931. If $mode == $unattended Then
  932. Sleep(250)
  933. EndIf
  934. If Not InBattle() Then
  935. SetError(2)
  936. return
  937. EndIf
  938.  
  939. $tries = 0
  940. While $tries < $maxTries
  941. $coord = findMenuInner()
  942. If Not @error Then
  943. return $coord
  944. EndIf
  945.  
  946. ; Wait a moment.
  947. $tries = $tries + 1
  948. Sleep(250 * $tries)
  949. WEnd
  950. SetError(1)
  951. EndFunc
  952.  
  953. Func findMenuInner()
  954. $menuOffsetPercent = 0.51
  955. $menuOffsetXAbs = $topLeftFull[0] + ($screenWidth * $menuOffsetPercent)
  956. $menuOffsetYMin = $topLeftFull[1] + ($screenHeight * 0.3)
  957. $menuOffsetYMax = $topLeftFull[1] + ($screenHeight * 0.8)
  958. $boxWidth = 20
  959. $boxHeight = 20
  960.  
  961. $xPos = $menuOffsetXAbs
  962. $yPos = $menuOffsetYMin
  963.  
  964. If $mode == $attended Then
  965. $menuSearchWaitTime = 0
  966. $moveSleep = 2
  967. $boxSize = 8
  968. Else
  969. $menuSearchWaitTime = 250
  970. $moveSleep = 3
  971. $boxSize = 5
  972. EndIf
  973.  
  974. While $yPos < $menuOffsetYMax
  975. MouseMove($xPos, $yPos, 0)
  976. Sleep($moveSleep)
  977. $coord = PixelSearch($xPos, $yPos-25, $xPos+$boxWidth, $yPos+$boxHeight, $menuColor, 3)
  978. If Not @error Then
  979. ; Now scan up.
  980. While 1
  981. $oldCoord = $coord
  982. $yPos -= 5
  983. MouseMove($xPos, $yPos, 1)
  984. Sleep(10)
  985. $coord = PixelSearch($xPos, $yPos-$boxHeight, $xPos+$boxWidth, $yPos+$boxHeight, $menuColor, 3)
  986. If @error Then
  987. Sleep($menuSearchWaitTime)
  988. EndIf
  989. $coord = PixelSearch($xPos, $yPos-$boxHeight, $xPos+$boxWidth, $yPos+$boxHeight, $menuColor, 3)
  990. If @error Then
  991. return $oldCoord
  992. EndIf
  993. WEnd
  994. Else
  995. $yPos += $boxSize
  996. EndIf
  997. WEnd
  998. SetError(1)
  999. EndFunc
  1000.  
  1001. Func WaitForRoomChange($milliSeconds, $initValue)
  1002. $left = $topLeftFull[0] + ($screenWidth*0.92)
  1003. $right = $topLeftFull[0] + ($screenWidth*0.94)
  1004. $top = $topLeftFull[1] + ($screenHeight*0.03)
  1005. $bottom = $topLeftFull[1] + ($screenHeight*0.05)
  1006.  
  1007. $decay = 200
  1008. If $initValue == -1 Then
  1009. $start = PixelChecksum($left, $top, $right, $bottom)
  1010. Else
  1011. $start = $initValue
  1012. EndIf
  1013. $count = 0
  1014. $maxCount = $milliSeconds / 100
  1015. While 1
  1016. $count = $count + 1
  1017. If $count > $maxCount Then
  1018. ; Assume some sort of problem.
  1019. SetError(1)
  1020. return $start
  1021. EndIf
  1022. Sleep(100 + $decay)
  1023. $end = PixelCheckSum($left, $top, $right, $bottom)
  1024. If $end <> $start Then
  1025. ; MsgBox(8192, "screen has changed", "screen has changed", 1)
  1026. If $mode == $attended Then
  1027. Sleep(300)
  1028. Else
  1029. Sleep(1500)
  1030. EndIf
  1031. return $start
  1032. EndIf
  1033. $decay /= 2
  1034. WEnd
  1035. EndFunc
  1036.  
  1037. Func Terminate()
  1038. Exit
  1039. EndFunc
  1040.  
  1041. ; Close the annoying box that pops up when you click a player.
  1042. Func DismissUserWindow()
  1043. $disable = 1
  1044. If $disable <> 1 Then
  1045. $x = $topLeftFull[0] + ($screenWidth * 0.43)
  1046. $y = $topLeftFull[1] + ($screenHeight * 0.22)
  1047. MouseMove($x, $y, 0)
  1048. MouseClick("left")
  1049. sleep(150)
  1050. EndIf
  1051. return
  1052. EndFunc
  1053.  
  1054. ; Switch to a given class.
  1055. Func SwitchClass($class)
  1056. return
  1057. EndFunc
  1058.  
  1059. ; Leave a battle.
  1060. Func LeaveBattle($menu)
  1061. return
  1062. EndFunc
  1063.  
  1064. Func InBattle()
  1065. $menuActiveColor = 0xAF3E32
  1066. $menuInactiveColor = 0x9E6660
  1067.  
  1068. $menuX = $topLeftFull[0] + ($screenWidth * 0.93)
  1069. $menuY = $topLeftFull[1] + ($screenHeight * 0.05)
  1070. ResetCursor()
  1071. If $mode == $unattended Then
  1072. Sleep(200)
  1073. EndIf
  1074. ; $coord = PixelSearch($menuX, $menuY, $menuX+20, $menuY+50, $menuInactiveColor, 30)
  1075. $coord = PixelSearch($menuX, $menuY, $menuX+20, $menuY+50, $menuInactiveColor, 10)
  1076. If @error Then
  1077. return 1
  1078. EndIf
  1079. return 0
  1080. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement