Guest User

21s W/ Cellar Check

a guest
Jun 28th, 2012
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 27.63 KB | None | 0 0
  1. ;=========== DO NOT TOUCH ===========;
  2. #RequireAdmin
  3. #include <GUIConstantsEx.au3>
  4. #include <StaticConstants.au3>
  5. #include <WindowsConstants.au3>
  6. #include <SimpleTesseractColor.au3>
  7. #include <ScreenCapture.au3>
  8. Opt('MouseCoordMode', 2)
  9. Opt('PixelCoordMode', 2)
  10. Global $size = WinGetClientSize("[CLASS:D3 Main Window Class]"), $Kill = ProcessList("AutoIt3_x64.exe"), $ver = "2.0.0", $ini = "25s.ini", $dps = 18500, $hFont = 0, $title, $Paused, $Go = 0, $i = 0, $gX = 0, $gY = 0, $LegendaryCount = 0, $SetCount = 0, $RareCount = 0, $deathCount = 0, $repairCount = 0, $closedcellarCount = 0, $cellarCount = 0, $t = TimerInit(), $rt = 0, $run = 0, $yellow = 0xFFF000, $red = 0xD90000, $lblRun, $lblLocation, $lblStatus, $lblLast, $lblRuntime, $lblGear, $lblItems,$lblGold, $lblFailed, $StartingGold = 0,$AccumulatedGold = 0,$GPH = 0, $OpenCellarAvg = 0, $OpenCellarSec = 0,$ClosedCellarAvg, $ClosedCellarSec = 0,$CellCoord = -1, $c = 0
  11.  
  12. For $i = 1 To $Kill[0][0]
  13.     $CurrentPID = @AutoItPID
  14.     If $CurrentPID < $Kill[$i][1] or $CurrentPID > $Kill[$i][1] Then
  15.     ProcessClose($Kill[$i][1])
  16.     EndIf
  17. Next
  18.  
  19. For $i = 0 To Random(0, 7, 1)
  20.     $title &= Chr(Random(97, 122, 1))
  21. Next
  22. For $i = 0 To Random(5, 10, 1)
  23.     $title &= Chr(Random(65, 90, 1))
  24. Next
  25. $title &= " "
  26. Global $gems[8] = ["Ru1.png", "Ru2.png", "Em1.png", "Em2.png", "To1.png", "To2.png", "Am1.png", "Am2.png"]
  27. If @OSArch = "X64" Then DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)
  28. If @OSArch = "X64" And Not @AutoItX64 Then MsgBox(16, "ERROR", "Why aren't you running the 64-bit AutoIt??? Expect bugs!")
  29. If @OSArch = "X64" And Not @AutoItX64 Then MsgBox(16, "ERROR", "Why aren't you running the 64-bit AutoIt??? Expect bugs!")
  30.  
  31. ;====================================;
  32.  
  33.  
  34. ;============= SETTINGS: DONT CHANGE HERE, CHANGE WZD.INI =============;
  35. HotKeySet("=", "Begin") ;script toggled on/off by pressing =
  36. HotKeySet("{PAUSE}", "TogglePause") ;script toggle pause by pressing Pause/Break key
  37. HotKeySet("x", "Stop") ;script stopped by pressing x
  38.  
  39. ;Cellar Check Coords HERE
  40. Global $cellarCoordx[6] = [255, 600, 175, 315, 265, 280]
  41. Global $cellarCoordy[6] = [290, 435, 305, 314, 340, 302]
  42.  
  43. ;Change to match your abilities (1-4 by default)z
  44. $DiamondSkin = "1"
  45. $MirrorImage = "2"
  46. $Teleport = "3"
  47. $MagicWeapon = "4"
  48.  
  49. $movementSpeed = 0 ;This is the % increase movement speed you have. 25 = 25%, 0 = 0% (25% is the movement cap but SS + Displacement avg = 32%)
  50.  
  51. ;Custom Loot
  52. $pngLoc = @ScriptDir & "\pics\" & @DesktopWidth & "x" & @DesktopHeight& "\"
  53.  
  54.  
  55. ;Looting
  56. $LootSets = 1 ;1 if you want to pick up Sets
  57. $LootLegendaries = 1;1 if you want to pick up Legendaries
  58. $LootRares = 1 ;1 if you want to pick up Rares
  59. $LootTomes = 1 ;1 if you want to pick up Tome of Secrets
  60.  
  61. $mLoot = 250;Nuber of successful runs until Stash and Vendor
  62. $mLootOff = 2 ;Stash and Vendor after mLoot +- X number of runs (Variability)
  63.  
  64. $StashLoot = 1
  65. $StashLegendary = 1 ;1 if you want to store Legendary items in the stash
  66. $StashRare = 1 ;1 if you want to store Rare items in the stash
  67. $StashTomes = 1 ;1 if you want to store Tomes items in the stash
  68.  
  69. ;Variability ==NEW SETTINGS==
  70. $walktime = 3600 ;Time (in ms) the script waits for you to enter and load the cellar. Slow this down for slower move speeds and loading times
  71. $loadtime = 4500 ;Time (in ms) the script waits for the game to load before it starts pathfinding. Slow this down for slower hard drives
  72. $tptime = 4700;Time (in ms) the script waits for teleport before exiting the game
  73. ;====================================;
  74. If FileExists($ini) Then
  75.     Call("ReadINI")
  76.     Call("CreateINI")
  77. Else
  78.     Call("CreateINI")
  79.  EndIf
  80.  
  81. $dps = $dps * 3
  82. $attackTime = (170000 / $dps) * 1000
  83.  
  84. If $size = 0 Then
  85.         MsgBox(16, "Error", "Diablo III is not running, cannot grab resolution!" & @CRLF & "Exiting...")
  86.         Exit
  87. EndIf
  88. $x_ratio = $size[0] / 1920
  89. $y_ratio = $size[1] / 1080
  90.  
  91. $mLootIn = $mLoot
  92. $movementSpeed = 1 + ($movementSpeed / 100)
  93. $VersionsInfo = "http://bit.ly/LF1Rp6"
  94. $oldVersion = IniRead("updater.ini", "Version", "Version", $ver)
  95. $newVersion = "0.0"
  96.  
  97. If Not FileExists($pngLoc & "MainMenu.png") Then
  98.     MsgBox(16, "Fatal Error", "FATAL ERROR: Cannot find: " & $pngLoc & "MainMenu.png" & @CRLF & "Make sure your desktop resolution is either 1600x900 or 1920x1080")
  99.     Exit
  100. EndIf
  101.  
  102. Call("DoUpdate")
  103. Call("SetupGUI")
  104.  
  105. While 1
  106.     Call("RestartRun")
  107. WEnd
  108.  
  109. Func RestartRun()
  110.     If ($Go) Then
  111.         $i = 0
  112.         WinSetTitle($title, "", $title & $ver & " - Running")
  113.         MouseMove(Round(Random(0, 400) * $x_ratio), Round(Random(700, 1080) * $y_ratio), 1) ;Moves mouse out of the way
  114.         ;Checks if the player is Dead/Logout/Window, then if in Main Menu, etc.
  115.         If CheckDead() Then
  116.             Return
  117.         ElseIf CheckFor("ExitGame", "", Round(860 * $x_ratio), Round(400 * $y_ratio), Round(1040 * $x_ratio), Round(450 * $y_ratio), 0.5, 140) Then
  118.             GUICtrlSetData($lblStatus, "Status: Exit window up")
  119.             MouseClick("left", Round(1064 * $x_ratio), Round(632 * $y_ratio))
  120.             Sleep(100)
  121.             Send("{SPACE}")
  122.             Return
  123.         ElseIf CheckFor("MainMenu", "", Round(40 * $x_ratio), Round(300 * $y_ratio), Round(400 * $x_ratio), Round(450 * $y_ratio)) Then
  124.             GUICtrlSetData($lblRun, "Run Number: " & $run & " - Runs till vendor: " & $mLootIn)
  125.             GUICtrlSetData($lblLocation, "Location: Main Menu")
  126.             GUICtrlSetData($lblStatus, "Status: Starting Game")
  127.             RandClick("left", Round(230 * $x_ratio), Round(416 * $y_ratio), 120, 20, 1, 1) ;Random Click on the resume button
  128.             Sleep($loadtime)
  129.             $rt = TimerInit()
  130.             $run += 1
  131.         ElseIf CheckFor("OldRuins", "Area") Or CheckFor("NewTristram", "Area") Or CheckFor("DankCellar", "Area") Then
  132.             Call("TownPortal")
  133.             Call("LeaveGame")
  134.             Return
  135.         ElseIf CheckFor("Disconnect", "", Round(700 * $x_ratio), Round(340 * $y_ratio), Round(1200 * $x_ratio), Round(600 * $y_ratio), 1, 140) Then
  136.             GUICtrlSetData($lblStatus, "Status: Network Disconnect window up")
  137.             MouseClick("left", Round(960 * $x_ratio), Round(632 * $y_ratio),1)
  138.             Sleep(100)
  139.             Send("{SPACE}")
  140.             Return
  141.         ElseIf CheckFor("LimitError", "", Round(700 * $x_ratio), Round(340 * $y_ratio), Round(1200 * $x_ratio), Round(600 * $y_ratio), 1, 140) Then
  142.             MouseClick("left", Round(960 * $y_ratio), Round(635 * $x_ratio),1)
  143.             $rand = Random(40000, 80000)
  144.             GUICtrlSetData($lblStatus, "Status: Input Limit - Waiting " & Round($rand / 1000) & " seconds.")
  145.             Sleep($rand)
  146.             Send("{SPACE}")
  147.             Return
  148.         Else
  149.             GUICtrlSetData($lblStatus, "ERROR: Cannot find Resume button")
  150.             Return
  151.          EndIf
  152.          
  153.         ;Make sure we are in the right area before beginning run
  154.         If CheckFor("OldRuins", "Area") Then
  155.             Sleep(100)
  156.             GUICtrlSetData($lblLocation, "Location: Old Ruins")
  157.             Call("CheckRepair")
  158.             If $StartingGold = 0 Then Call("GoldPerHour")
  159.             ;Start Run
  160.             MouseClick("middle", Round(0 * $x_ratio),Round(250 * $y_ratio),1) ;starts the main run
  161.             Send("{3 down}")
  162.             Sleep(2000)
  163.             Send("{3 up}")
  164.             SLEEP(100)
  165.             send($DiamondSkin)
  166.             Moving(100)
  167.              If FindCellar() = 1 Then
  168.                 If CheckDead() Then
  169.                   Return
  170.                EndIf
  171.                GUICtrlSetData($lblStatus, "Status: Cellar - Found")
  172.                MouseClick("left",$cellarCoordx[$CellCoord],$cellarCoordy[$CellCoord],1)
  173.                Moving($walktime)
  174.              Else ;ABORT RUN
  175.                ;_ScreenCapture_SetBMPFormat(0)
  176.                ;_ScreenCapture_Capture(@ScriptDir & "\shots\Shot"& $run & ".bmp")
  177.                 GUICtrlSetData($lblStatus, "Status: Cellar - Not Found" & @CRLF)
  178.                 Send($MirrorImage)
  179.                 Sleep(300)
  180.                 send("{SHIFTDOWN}")
  181.                 sleep(200)
  182.                 Mouseclick("left")
  183.                 sleep(300)
  184.                 send("{SHIFTUP}")
  185.                 sleep(400)
  186.                 Call("TownPortal")
  187.                 If Not CheckDead() Then
  188.                    Call("ClosedCellar")
  189.                     Call("LeaveGame")
  190.                 EndIf
  191.                 Return
  192.             EndIf
  193.         Else
  194.             Call("TownPortal")
  195.             If Not CheckDead() Then
  196.                Call("ClosedCellar")
  197.                 Call("LeaveGame")
  198.             EndIf
  199.             Return
  200.         EndIf
  201.  
  202.         ;Checks that the player is in the Dank Cellar
  203.         If CheckFor("DankCellar", "Area") Then
  204.             GUICtrlSetData($lblLocation, "Location: Dank Cellar")
  205.             RandClick("middle", Round(20 * $x_ratio),Round(708 * $y_ratio), 1, 1) ;moves to doorway leading to rare inside cellar
  206.             Sleep(Random(2200, 2500))
  207.             RandMove(Round(440 * $x_ratio),Round(80 * $y_ratio), 1, 1) ;hovers over the rare Sarkoth
  208.             sleep(150)
  209.             Send($MagicWeapon)
  210.             sleep(200)
  211.             Send("{SHIFTDOWN}")
  212.             GUICtrlSetData($lblStatus, "Status: Attacking Sarkoth")
  213.             MouseDown("right") ;ATTACK
  214.             Sleep($attackTime)
  215.             MouseUp("right")
  216.             Sleep(150)
  217.             Send("{SHIFTUP}")
  218.             sleep(1450)
  219.             Send("2") ;archon teleport
  220.             MouseClick("right",Round(755*$x_ratio),Round(936* $y_ratio),1) ;cancel archon
  221.             send("{SHIFTDOWN}")
  222.             sleep(200)
  223.             Mouseclick("left")
  224.             sleep(200)
  225.             send("{SHIFTUP}")
  226.             GUICtrlSetData($lblStatus, "Status: Looting")
  227.             Call("Loot")
  228.             Call("TownPortal")
  229.          Else
  230.                ;_ScreenCapture_SetBMPFormat(0)
  231.                ;_ScreenCapture_Capture(@ScriptDir & "\shots\Shot"& $run & ".bmp")
  232.                 Send($MirrorImage)
  233.                 Sleep(300)
  234.                 send("{SHIFTDOWN}")
  235.                 sleep(200)
  236.                 Mouseclick("left")
  237.                 sleep(300)
  238.                 send("{SHIFTUP}")
  239.                 sleep(400)
  240.                 Call("TownPortal")
  241.             If Not CheckDead() Then
  242.                 Call("ClosedCellar")
  243.                 Call("LeaveGame")
  244.             EndIf
  245.             Return
  246.         EndIf
  247.         ;After successful run
  248.         If Not CheckDead() Then
  249.             Sleep(300)
  250.             If $mLootIn = 1 And CheckFor("NewTristram", "Area") Then ;If its time to manage loot and we are in town
  251.                 If $StashLoot == 1 Then
  252.                     Call("StashLoot")
  253.                 EndIf
  254.                 $mLootIn = Round(Random($mLoot - $mLootOff, $mLoot + $mLootOff)) ;Reset Counter
  255.             ElseIf Not CheckFor("NewTristram", "Area") Then
  256.                 GUICtrlSetData($lblStatus, "Status: Skipping vendor, not in New Tristram")
  257.                 Sleep(3000)
  258.             ElseIf $mLootIn <= 0 Then
  259.                 $mLootIn = 1
  260.             Else
  261.                 $mLootIn -= 1
  262.             EndIf
  263.             If Not CheckDead() Then
  264.                 Call("OpenCellar")
  265.                 Call("LeaveGame")
  266.             EndIf
  267.             Return
  268.         Else
  269.             Return
  270.         EndIf
  271.     EndIf
  272. EndFunc   ;==>RestartRun
  273.  
  274. Func SetupGUI()
  275.     $frmBot = GUICreate($title & $ver & " - Updating", 280, 110, Round(0 * $x_ratio), Round(0 * $y_ratio), -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW), 0)
  276.     GUISetBkColor(0xC0C0C0)
  277.     $lblRun = GUICtrlCreateLabel("Run Number: 0 - Runs till stash: 0", 4, 0, 280, 24)
  278.     GUICtrlSetFont(-1, 10, 600, 0, "Segoe UI")
  279.     GUICtrlSetColor(-1, 0xFF0000)
  280.     $lblLocation = GUICtrlCreateLabel("Location: Main Menu", 12, 20, 240, 17)
  281.     $lblStatus = GUICtrlCreateLabel("Status: ", 12, 35, 240, 17)
  282.     $lblRuntime = GUICtrlCreateLabel("Total Runtime: 0 hours, 0 minutes", 12, 50, 240, 17)
  283.     $lblLast = GUICtrlCreateLabel("Open Cellar Avg: 0s - Closed Cellar Avg: 0s", 12, 65, 240, 17)
  284.     $lblGear = GUICtrlCreateLabel("Legendary: 0 - Set: 0 - Rare: 0", 12, 80, 240, 17)
  285.     $lblGold = GUICtrlCreateLabel("0 Per Hour - Accumulated Gold: 0", 12, 95, 240, 17)
  286.  
  287.     GUISetState(@SW_SHOW)
  288. EndFunc   ;==>SetupGUI
  289.  
  290. Func CheckDead()
  291.     $LogoutTimerCancel = PixelSearch(Round(900 * $x_ratio), Round(240 * $y_ratio), Round(1010 * $x_ratio), Round(290 * $y_ratio), 0x993827) ; checks for cancel button on logout timer
  292.     If Not @error Then
  293.         GUICtrlSetData($lblStatus, "Status: Logging out")
  294.         Sleep(11000)
  295.         Sleep($loadtime)
  296.         Return 1
  297.     EndIf
  298.  
  299.     $CloseButton = PixelSearch(Round(1570 * $x_ratio), Round(110 * $y_ratio), Round(1590 * $x_ratio), Round(120 * $y_ratio), 0x8C2300) ; checks for the red color of the "X" on an open window
  300.     If Not @error Then
  301.         GUICtrlSetData($lblStatus, "Status: Open Window")
  302.         Sleep(200)
  303.         Send("{SPACE}") ;close any open windows
  304.         Return 1
  305.     EndIf
  306.  
  307.     $YouHaveDied = PixelSearch(Round(620 * $x_ratio), Round(325 * $y_ratio), Round(625 * $x_ratio), Round(330 * $y_ratio), 0xFFFFFF) ; checks for white text "YOU HAVE DIED"
  308.     If Not @error Then
  309.         GUICtrlSetData($lblStatus, "Status: Dead")
  310.         $deathCount += 1
  311.         Call("LeaveGame")
  312.         Sleep(11000)
  313.         Sleep($loadtime)
  314.         Return 1
  315.     Else
  316.         Return 0
  317.     EndIf
  318. EndFunc   ;==>CheckDead
  319.  
  320. Func CheckRepair()
  321.     $RepairArea = PixelSearch(Round(1480 * $x_ratio), 0, Round(1570 * $x_ratio), Round(100 * $y_ratio), $yellow)
  322.     If Not @error Then
  323.         Call("DoRepair")
  324.     EndIf
  325.     $RepairAreaRed = PixelSearch(Round(1480 * $x_ratio), 0, Round(1570 * $x_ratio), Round(100 * $y_ratio), $red)
  326.     If Not @error Then
  327.         Call("DoRepair")
  328.     EndIf
  329. EndFunc   ;==>CheckRepair
  330.  
  331. Func DoRepair()
  332.     Call("TownPortal")
  333.     sleep(2000)
  334.     $repairCount += 1
  335.     If CheckDead() Then
  336.         Return
  337.     EndIf
  338.     If CheckFor("NewTristram", "Area") Then
  339.         RandMove(Round(1530 * $x_ratio), Round(0 * $y_ratio), 1, 1) ;begin movement towards merchant
  340.         Send("{3 down}")
  341.         Sleep(1200)
  342.         Send("{3 up}")
  343.         RandClick("left", Round(796 * $x_ratio), Round(474 * $y_ratio), 1, 1) ;NPC Merchant to the right of cain's home
  344.         Sleep(1200)
  345.         RandClick("left", Round(521 * $x_ratio), Round(506 * $y_ratio), 1, 1) ;button to open up repair menu
  346.         Sleep(400)
  347.         RandClick("left", Round(260 * $x_ratio), Round(595 * $y_ratio), 1, 1) ;button to pay for repairs
  348.         Sleep(200)
  349.         Send("{Escape}")
  350.         If Not CheckDead() Then
  351.             Call("LeaveGame")
  352.         EndIf
  353.     EndIf
  354. EndFunc   ;==>DoRepair
  355. Func ClosedCellar()
  356.        $closedcellarCount += 1
  357.        $srt = TimerDiff($rt)
  358.        $ClosedCellarSec = $ClosedCellarSec + Round($srt / 1000, 2)
  359.        $ClosedCellarAvg = $ClosedCellarSec / $closedcellarCount
  360.     EndFunc
  361.    
  362. Func OpenCellar()
  363.        $cellarCount += 1
  364.        $srt = TimerDiff($rt)
  365.        $OpenCellarSec = $OpenCellarSec + Round($srt / 1000, 2)
  366.        $OpenCellarAvg = $OpenCellarSec / $cellarCount
  367.    EndFunc
  368. Func CalcTime()
  369.     GUICtrlSetData($lblLast, "Open Cellar Avg: " & Round($OpenCellarAvg,1) & "s - " & "Closed Cellar Avg: " & Round($ClosedCellarAvg,1) & "s")
  370.     $trt = TimerDiff($t)
  371.     $total = Round((($trt / 1000) / 60) / 60, 4)
  372.     ;Total runtime calculation.
  373.     $hours = Floor((($trt / 1000) / 60) / 60)
  374.     $minutes = (($trt / 1000) / 60)
  375.     ;trim minutes if runtime is more then 1 hour.
  376.     If $minutes > 60 Then
  377.         While $minutes > 60
  378.             $minutes -= 60
  379.         WEnd
  380.     EndIf
  381.     GUICtrlSetData($lblRuntime, "Total Runtime: " & $hours & " hours, " & Ceiling($minutes) & " minutes")
  382. EndFunc   ;==>CalcTime
  383.  
  384. Func CheckFor($img, $type = "", $startX = 0, $startY = 0, $endX = @DesktopWidth, $endY = @DesktopHeight, $seconds = 6, $tolerance = 140)
  385.     If $type = "Area" Then
  386.         $startX = 1500 * $x_ratio
  387.         $startY = 0 * $y_ratio
  388.         $endX = 1920 * $x_ratio
  389.         $endY = 90 * $y_ratio
  390.         $seconds = 2.5
  391.     EndIf
  392.     $c = 0
  393.     $string = $pngLoc & $img & ".png"
  394.     Do
  395.         $c += 1
  396.         Sleep(100)
  397.         If $c > ($seconds * 10) Then ;Make sure we never get stuck here for infinity.
  398.             If $type = "Area" Then
  399.                 GUICtrlSetData($lblStatus, "Status: Area not found - " & $img)
  400.             EndIf
  401.             Return 0
  402.         EndIf
  403.     Until _ImageSearchArea($string, 1, $startX, $startY, $endX, $endY, $gX, $gY, $tolerance)
  404.     Return 1
  405. EndFunc   ;==>CheckFor
  406.  
  407. Func Loot()
  408.     Sleep(Random(100, 300))
  409.     MouseMove(Round(Random(0, 400) * $x_ratio), Round(Random(700, 1080) * $y_ratio), 3) ;Moves mouse out of the way
  410.     If $LootSets == 1 Then
  411.         $SetCount += LootGear(0x02CE01)
  412.     EndIf
  413.     If $LootLegendaries == 1 Then
  414.         $LegendaryCount += LootGear(0xBF642F, 0)
  415.     EndIf
  416.     If $LootRares == 1 Then
  417.         $RareCount += LootGear(0xBBBB00)
  418.     EndIf
  419.     If $LootTomes == 1 Then
  420.         Call("LootTomes")
  421.     EndIf
  422.     Call("ShowLoot")
  423. EndFunc   ;==>Loot
  424.  
  425. Func LootGear($color, $tolerance = 2)
  426.     $count = 0
  427.     $Loot = PixelSearch(Round(400 * $x_ratio), 0, Round(1690 * $x_ratio), Round(900 * $y_ratio), $color, $tolerance)
  428.     If Not @error Then
  429.         While Not @error
  430.             $count += 1
  431.             MouseClick('left', $Loot[0], $Loot[1], 1, 3)
  432.             Sleep(50)
  433.             MouseMove(Round(Random(0, 400) * $x_ratio), Round(Random(700, 1080) * $y_ratio), 1) ;Moves mouse out of the way
  434.             sleep(500)
  435.             ;Run at max 10 times per quality
  436.             If $count >= 10 Then
  437.                 ExitLoop
  438.             EndIf
  439.             $Loot = PixelSearch(Round(400 * $x_ratio), 0, Round(1690 * $x_ratio), Round(900 * $y_ratio), $color, $tolerance)
  440.         WEnd
  441.     EndIf
  442.     Return $count
  443. EndFunc   ;==>LootGear
  444.  
  445. Func LootTomes()
  446.     $count = 0
  447.     $gX = 0
  448.     $gY = 0
  449.     While _ImageSearchArea($pngLoc & "tome.png", 1, 0, 0, @DesktopWidth, @DesktopHeight, $gX, $gY, 90)
  450.         $count += 1
  451.         MouseClick("left", $gX, $gY - 3, 1, 3)
  452.         Sleep(50)
  453.         MouseMove(Round(Random(0, 400) * $x_ratio), Round(Random(700, 1080) * $y_ratio), 3) ;Moves mouse out of the way
  454.         Sleep(1000)
  455.         If $count >= 10 Then
  456.             ExitLoop
  457.         EndIf
  458.     WEnd
  459. EndFunc   ;==>LootTomes
  460.  
  461. Func StashLoot()
  462.     GUICtrlSetData($lblStatus, "Status: Putting Items in Stash")
  463.     MouseClick("left", 1064 * $x_ratio, 256 * $y_ratio)
  464.     Moving(1600)
  465.  
  466.     ;Tomes
  467.     While $StashTomes == 1
  468.         Sleep(Random(100, 300))
  469.         If _ImageSearchArea($pngLoc & "TomeIcon.png", 1, 1400 * $x_ratio, 580 * $y_ratio, 1914 * $x_ratio, 888 * $y_ratio, $gX, $gY, 140) Then
  470.             GUICtrlSetData($lblStatus, "Status: Stashing Tomes")
  471.             MouseClick("left", 500 * $x_ratio, 360 * $y_ratio, 1, 4)
  472.             MouseClick("right", $gX, $gY, 1, 4)
  473.             Sleep(80)
  474.             MouseClick("left", 500 * $x_ratio, 200 * $y_ratio, 1, 4)
  475.         Else
  476.             ExitLoop
  477.         EndIf
  478.     WEnd
  479.  
  480.     If $StashLegendary == 1 Then
  481.         StashItems(0xFF7F00, 0)
  482.         StashItems(0x8F5C25, 1)
  483.     EndIf
  484.  
  485.     If $StashRare == 1 Then
  486.         StashItems(0x4A3C0B, 1)
  487.     EndIf
  488.  
  489.     Sleep(Random(200, 800))
  490.     Send("{SPACE}")
  491. EndFunc   ;==>StashLoot
  492.  
  493. Func StashItems($color, $tolerance)
  494.     $c = 0
  495.     While $c <= 20
  496.         Sleep(Random(20, 100))
  497.         $StashPixel = PixelSearch(1400 * $x_ratio, 580 * $y_ratio, 1914 * $x_ratio, 888 * $y_ratio, $color, $tolerance)
  498.         If Not @error Then
  499.             MouseClick("right", $StashPixel[0] + 4, $StashPixel[1], 1, 4)
  500.             $c += 1
  501.         Else
  502.             ExitLoop
  503.         EndIf
  504.     WEnd
  505. EndFunc   ;==>StashItems
  506.  
  507. Func DoUpdate()
  508.     $ini = InetGet($VersionsInfo, @ScriptDir & "\version.ini") ;download version.ini
  509.     If $ini = 0 Then ;was the download of version.ini successful?
  510.         MsgBox(16, "Fatal Error", "The server seems to be offline. No update will be done.")
  511.     Else
  512.         $newVersion = IniRead(@ScriptDir & "\version.ini", "Version", "Version", "") ;reads the new version out of version.ini
  513.         If $newVersion = $oldVersion Then ;compare old and new
  514.             ;MsgBox (0,"No update","There is no update available!")
  515.             FileDelete(@ScriptDir & "\version.ini")
  516.         Else
  517.             $msg = MsgBox(68, "Update", "A new version is available: " & $newVersion & "! Current version: " & $oldVersion & @CRLF & "Do you want to download the new version?")
  518.             If $msg = 7 Then ;No was pressed
  519.                 FileDelete(@ScriptDir & "\version.ini")
  520.             ElseIf $msg = 6 Then ;OK was pressed
  521.                 $downloadLink = IniRead(@ScriptDir & "\version.ini", "Version", "download", "NotFound")
  522.                 $dlhandle = InetGet($downloadLink, @ScriptDir & "\Update_" & $newVersion & ".zip", 1, 1)
  523.                 ProgressOn("Update", "Downloading Updates", "", -1, -1, 16) ;creates a progressbar
  524.  
  525.                 $size = InetGetSize($downloadLink, 1) ;get the size of the update
  526.                 While Not InetGetInfo($dlhandle, 2)
  527.                     $Percent = Round((InetGetInfo($dlhandle, 0) / $size) * 100)
  528.                     ProgressSet($Percent, $Percent & "%") ;update progressbar
  529.                     Sleep(1)
  530.                 WEnd
  531.                 ProgressSet(100, "Done", "Complete") ;show complete progressbar
  532.                 Sleep(500)
  533.                 ProgressOff() ;close progress window
  534.                 IniWrite("updater.ini", "version", "version", $newVersion)
  535.                 InetClose($dlhandle)
  536.                 $iniMsg = IniRead(@ScriptDir & "\version.ini", "Version", "message", "Exiting...")
  537.                 MsgBox(64, "Success", "Download Complete!" & @CRLF & "Please restart the bot by extracting the Au3 from Update_" & $newVersion & ".zip" & @CRLF & $iniMsg)
  538.                 FileDelete(@ScriptDir & "\version.ini")
  539.                 Exit
  540.             EndIf
  541.         EndIf
  542.     EndIf
  543.     WinSetTitle($title, "", $title & $ver & " - Waiting")
  544. EndFunc   ;==>DoUpdate
  545. Func ReadINI()
  546.     $DPS = IniRead($ini, "DPS", "DPS", $DPS)
  547.     $DiamondSkin = IniRead($ini, "Skills", "DiamondSkin", $DiamondSkin)
  548.     $MirrorImage = IniRead($ini, "Skills", "MirrorImage", $MirrorImage)
  549.     $Teleport = IniRead($ini, "Skills", "Teleport", $Teleport)
  550.     $MagicWeapon = IniRead($ini, "Skills", "Magic Weapon", $MagicWeapon)
  551.     $movementSpeed = IniRead($ini, "Additional", "Movement Speed", $movementSpeed)
  552.     $walktime = IniRead($ini, "Additional", "Walk Time", $walktime)
  553.     $loadtime = IniRead($ini, "Additional", "Load Time", $loadtime)
  554.     $tptime = IniRead($ini, "Additional", "Teleport Time", $tptime)
  555.     $LootSets = IniRead($ini, "Looting", "Sets", $LootSets)
  556.     $LootLegendaries = IniRead($ini, "Looting", "Legendaries", $LootLegendaries)
  557.     $LootRares = IniRead($ini, "Looting", "Rares", $LootRares)
  558.     $LootTomes = IniRead($ini, "Looting", "Tomes", $LootTomes)
  559.     $mLoot = IniRead($ini, "ManageLoot", "Every", $mLoot)
  560.     $StashLegendary = IniRead($ini, "Stashing", "Legendaries", $StashLegendary)
  561.     $StashRare = IniRead($ini, "Stashing", "Rares", $StashRare)
  562.     $StashTomes = IniRead($ini, "Stashing", "Tomes", $StashTomes)
  563.     $mLootOff = IniRead($ini, "Variability", "Manage Off By", $mLootOff)
  564. EndFunc   ;==>ReadINI
  565. Func CreateINI()
  566.     IniWrite($ini, "DPS", "DPS", $DPS)
  567.     IniWrite($ini, "Skills", "DiamondSkin", $DiamondSkin)
  568.     IniWrite($ini, "Skills", "MirrorImage", $MirrorImage)
  569.     IniWrite($ini, "Skills", "Teleport", $Teleport)
  570.     IniWrite($ini, "Skills", "Magic Weapon", $MagicWeapon)
  571.     IniWrite($ini, "Additional", "Movement Speed", $movementSpeed)
  572.     IniWrite($ini, "Additional", "Walk Time", $walktime)
  573.     IniWrite($ini, "Additional", "Load Time", $loadtime)
  574.     IniWrite($ini, "Additional", "Teleport Time", $tptime)
  575.     IniWrite($ini, "Looting", "Sets", $LootSets)
  576.     IniWrite($ini, "Looting", "Legendaries", $LootLegendaries)
  577.     IniWrite($ini, "Looting", "Rares", $LootRares)
  578.     IniWrite($ini, "Looting", "Tomes", $LootTomes)
  579.     IniWrite($ini, "ManageLoot", "Every", $mLoot)
  580.     IniWrite($ini, "Stashing", "Legendaries", $StashLegendary)
  581.     IniWrite($ini, "Stashing", "Rares", $StashRare)
  582.     IniWrite($ini, "Stashing", "Tomes", $StashTomes)
  583.     IniWrite($ini, "Variability", "Manage Off By", $mLootOff)
  584. EndFunc   ;==>CreateINI
  585.  
  586. Func _ImageSearchArea($findImage, $resultPosition, $x1, $y1, $right, $bottom, ByRef $x, ByRef $y, $tolerance)
  587.     If $tolerance > 0 Then $findImage = "*" & $tolerance & " " & $findImage
  588.     $findImage = "*TRANSBLACK " & $findImage
  589.     If @AutoItX64 Then
  590.         $result = DllCall("ImageSearchDLL_x64.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)
  591.     Else
  592.         $result = DllCall("ImageSearchDLL.dll", "str", "ImageSearch", "int", $x1, "int", $y1, "int", $right, "int", $bottom, "str", $findImage)
  593.     EndIf
  594.     If $result = "0" Then
  595.         Return 0
  596.     EndIf
  597.  
  598.     ; Otherwise get the x,y location of the match and the size of the image to
  599.     ; compute the centre of search
  600.     $array = StringSplit($result[0], "|")
  601.     If (UBound($array) >= 4) Then
  602.         $x = Int(Number($array[2]))
  603.         $y = Int(Number($array[3]))
  604.         If $resultPosition = 1 Then
  605.             $x = $x + Int(Number($array[4]) / 2)
  606.             $y = $y + Int(Number($array[5]) / 2)
  607.         EndIf
  608.         Return 1
  609.     EndIf
  610.  EndFunc   ;==>_ImageSearchArea
  611.  
  612.  Func FindCellar()
  613.    $CellCoord = -1
  614.    $c = 0
  615.    Do
  616.         If $c >= Ubound($cellarCoordx) Then ;Make sure we never get stuck here for infinity.
  617.            If $CellCoord = -1 Then $CellCoord = 0
  618.            Return 0
  619.         EndIf
  620.         sleep(50)
  621.    RandMove(Round($cellarCoordx[$c] * $x_ratio), Round($cellarCoordy[$c] * $y_ratio), 1, 1) ;moves cursor over to the cellar
  622.    $mousePos = MouseGetPos()
  623.    sleep(50)
  624.    If $c = 1 then
  625.       $Pixel2 = PixelSearch($mousePos[0] - 71 * $x_ratio,$mousePos[1] - 148 * $y_ratio,$mousePos[0] + 139 * $x_ratio,$mousePos[1] + 22 * $y_ratio, 0x007CB7F8, 3) ;checks for open cellar (in a 600x400 box from the top left - where it should always be)
  626.       Else
  627.    $Pixel2 = PixelSearch($mousePos[0] - 71 * $x_ratio,$mousePos[1] - 148 * $y_ratio,$mousePos[0] + 139 * $x_ratio,$mousePos[1] + 22 * $y_ratio, 0x334FB7, 3) ;checks for open cellar (in a 600x400 box from the top left - where it should always be)
  628.       EndIf
  629.       If Not @Error Then
  630.          $CellCoord = $c
  631.          Return 1
  632.      EndIf
  633.       $c += 1
  634.    Until $CellCoord >= 0
  635.    If $CellCoord = -1 Then $CellCoord = 0
  636.    Return 1
  637. EndFunc
  638.  
  639. Func GoldPerHour()
  640. Send("i")
  641. Sleep(200)
  642. $CurrentGold = _TesseractScreenCapture(0, "", 1,  2, 1450*$x_ratio, 504*$y_ratio, 1570*$x_ratio, 530*$y_ratio, 0)
  643. Sleep(200)
  644. Send("i")
  645.  
  646. $CurrentGold = StringRegExpReplace($CurrentGold, "[^0-9]", "")
  647.  
  648. $trt = TimerDiff($t)
  649.  
  650. If $StartingGold <= 0 Then $StartingGold = $CurrentGold
  651. If $StartingGold > 0 Then $AccumulatedGold = $CurrentGold - $StartingGold
  652. $GPH = $AccumulatedGold / ($trt / 1000) * 3600
  653.  
  654. If $GPH >= 0 and $AccumulatedGold >=0 then
  655.     If $GPH > 1000000 Then
  656.         $GPH = Round($GPH/1000000,2) & "M"
  657.     ElseIf $GPH > 1000 Then
  658.         $GPH = Round($GPH/1000) & "K"
  659.     EndIF
  660.     If $AccumulatedGold > 1000000 Then
  661.         $AccumulatedGold = Round($AccumulatedGold/1000000,2) & "M"
  662.     ElseIf $AccumulatedGold > 1000 Then
  663.         $AccumulatedGold = Round($AccumulatedGold/1000) & "K"
  664.     EndIF
  665.     GUICtrlSetData($lblGold,$GPH & " Per Hour - Accumulated Gold: " & $AccumulatedGold)
  666. EndIf
  667. EndFunc ;==>GoldPerHour
  668.  
  669.  
  670. Func LeaveGame()
  671.     GUICtrlSetData($lblStatus, "Status: Leaving Game")
  672.     Send("{SPACE}")
  673.     sleep(200)
  674.     Send("{Escape}")
  675.     RandClick("left", Round(956 * $x_ratio), Round(579 * $y_ratio), 120, 1) ;Random Click on the leave button
  676.     Call("CalcTime")
  677.     Sleep($loadtime)
  678. EndFunc   ;==>LeaveGame
  679.  
  680. Func TownPortal()
  681.     GUICtrlSetData($lblStatus, "Status: Returning to Town")
  682.     Send("t")
  683.     Call("GoldPerHour")
  684.     Sleep($tptime)
  685. EndFunc   ;==>TownPortal
  686.  
  687. Func Moving($time)
  688.     Sleep($time / $movementSpeed)
  689. EndFunc   ;==>Moving
  690.  
  691. Func RandClick($clickType, $xPos, $yPos, $xOff = 10, $yOff = 10, $clicks = 1, $speed = 1)
  692.     If $xOff < 1 Then $xOff = 1
  693.     If $yOff < 1 Then $yOff = 1
  694.     $randX = Round(Random($xPos - ($xOff * $x_ratio), $xPos + ($xOff * $x_ratio)))
  695.     $randY = Round(Random($yPos - ($yOff * $y_ratio), $yPos + ($yOff * $y_ratio)))
  696.     MouseClick($clickType, $randX, $randY, $clicks, $speed)
  697. EndFunc   ;==>RandClick
  698.  
  699. Func RandMove($xPos, $yPos, $xOff = 10, $yOff = 10, $speed = 1)
  700.     $randX = Round(Random($xPos - ($xOff * $x_ratio), $xPos + ($xOff * $x_ratio)))
  701.     $randY = Round(Random($yPos - ($yOff * $y_ratio), $yPos + ($yOff * $y_ratio)))
  702.     MouseMove($randX, $randY, $speed)
  703. EndFunc   ;==>RandMove
  704.  
  705.  
  706. Func Begin()
  707.     $Go = Not $Go
  708.     If Not $Go Then WinSetTitle($title, "", $title & $ver & " - Halted")
  709. EndFunc   ;==>Begin
  710.  
  711. Func TogglePause()
  712.     $Paused = Not $Paused
  713.     While $Paused
  714.         Sleep(100)
  715.         WinSetTitle($title, "", $title & $ver & " - Paused")
  716.         ToolTip('[PAUSED] - Deaths: ' & $deathCount & ' | Cellars: ' & $cellarCount, 0, 0)
  717.     WEnd
  718.     WinSetTitle($title, "", $title & $ver & " - Running")
  719.     ToolTip("")
  720. EndFunc   ;==>TogglePause
  721.  
  722. Func ShowLoot()
  723.     GUICtrlSetData($lblGear, "Legendary: " & $LegendaryCount & " - Set: " & $SetCount & " - Rare: " & $RareCount)
  724. EndFunc   ;==>ShowLoot
  725.  
  726. Func StopLog()
  727. $repairCountPercent = $repairCount / $run
  728. $deathsCountPercent = $deathCount / $run
  729. $cellarCountPercent = $cellarCount /  $run
  730. $closedCellarCountPercent = ($run - $cellarCount) / $run
  731. $trt = TimerDiff($t)
  732. ;Total runtime calculation.
  733. $hours = Floor((($trt / 1000) / 60) / 60)
  734. $minutes = (($trt / 1000) / 60)
  735. If $minutes > 60 Then
  736.     While $minutes > 60
  737.         $minutes -= 60
  738.     WEnd
  739. EndIf
  740.  
  741. _FileWriteLog("Dank Cellar Log.txt",  @CRLF & "************************************************" & @CRLF & _
  742. "Chancity's Dank Celler" & @CRLF & @CRLF & "Stats:" & @CRLF &  _
  743. "Total Runtime: " & $hours & " hours, " & Ceiling($minutes) & " minutes" & @CRLF & _
  744. "Total Cellars Found: " & $cellarCount & " (" & Round($cellarCountPercent * 100,.00) & "%" & ")" & @CRLF & _
  745. "Total Cellars Not Found: " & $run - $cellarCount & " (" & Round($closedCellarCountPercent * 100,.00) & "%" & ")" & @CRLF & _
  746. "Total Deaths: " & $deathCount &  " (" & Round($deathsCountPercent * 100,.00) & "%" & ")" & @CRLF & _
  747. "Total Repairs: " & $repairCount &  " (" & Round($repairCountPercent * 100,.00) & "%" & ")" & @CRLF & @CRLF & "Loot:" & @CRLF & _
  748. "Legendary: " & $LegendaryCount & " - Set: " & $SetCount & " - Rare: " & $RareCount & @CRLF & _
  749.  $GPH & " Per Hour - Accumulated Gold: " & $AccumulatedGold & @CRLF & _
  750. "************************************************")
  751. EndFunc
  752.  
  753.  
  754.  
  755. Func Stop() ;to allow the script to stop
  756.     Call("StopLog")
  757.     Exit
  758. EndFunc   ;==>Stop
Advertisement
Add Comment
Please, Sign In to add comment