by Jackard » Mon Jan 24, 2011 6:06 am
#include <WindowsConstants.au3>
;#include <ScreenCapture.au3>
Opt("WinWaitDelay",500)
Opt("WinTitleMatchMode",3)
Opt("WinDetectHiddenText",1)
Opt("MouseCoordMode",2)
Opt("PixelCoordMode",2)
$apple_button_checksum = 2863521757
$apple_inventory_checksum = 3191904032
$inventory_title_checksum = 2395311228
HotKeySet("{ESCAPE}", "escape")
Func escape()
Exit
EndFunc
$instructions = "Version 3.2" & @CRLF & @CRLF & "This script is a bit more clever than it used to be" & @CRLF & @CRLF & "Some requirements:" & @CRLF & @CRLF & " - Stand close to a tree by left clicking on its base" & @CRLF & " - Center the camera on the tree by middle clicking its base" & @CRLF & " - Make sure the first slot in your bag is empty!" & @CRLF & @CRLF & "Do these things before clicking OK!"
$instructionsbutton = MsgBox(1,"Important instructions!",$instructions)
; Quit if Cancel is pressed
if $instructionsbutton = 2 Then
Exit
EndIf
Do
$totalloops = inputbox ("How many apples?", "Enter number of apples:", "10","",150,150)
; Keep prompting until a number is entered.
Until number($totalloops) <> 0
;$inventorybuttonclicked = msgbox(4,"Inventory Check", "Is the inventory window open already?")
;$win_handle = WinGetHandle("Haven and Hearth")
WinWait("Haven and Hearth","")
If Not WinActive("Haven and Hearth","") Then WinActivate("Haven and Hearth","")
WinWaitActive("Haven and Hearth","")
;if $inventorybuttonclicked = 6 Then
; Yes, inventory is open
; Close inventory so we can open
; in default posistion again
; Send("{CTRLDOWN}i{CTRLUP}")
; sleep(500)
;EndIf
; Open Inventory
Send("{CTRLDOWN}i{CTRLUP}")
sleep(300)
$inventory_title_x = 182
$inventory_title_y = 105
$checksum = PixelChecksum($inventory_title_x - 15, $inventory_title_y -5, $inventory_title_x +15, $inventory_title_y+5)
;_ScreenCapture_CaptureWnd(@MyDocumentsDir & "\eatapple_cap_inv.bmp", $win_handle, $inventory_title_x - 15, $inventory_title_y -5, $inventory_title_x +15, $inventory_title_y+5, False)
if $checksum <> $inventory_title_checksum Then
; We must have closed it above, but it was in wrong position
; Open again in default position
Send("{CTRLDOWN}i{CTRLUP}")
EndIf
func update_status ($j)
Global $status_text_ctrl
Global $totalloops
GUICtrlSetData($status_text_ctrl,$totalloops - $j & " apples remaining...")
EndFunc
$game_client = WinGetPos("Haven and Hearth")
GUICreate("Macro status",200,40,$game_client[0],$game_client[1],$WS_CAPTION,$WS_EX_TOPMOST)
GUICtrlCreateLabel("Press ESCAPE to stop the macro!", 5, 5)
$status_text_ctrl = GUICtrlCreateLabel($totalloops & " apples remaining...", 5,20)
GUISetState() ; display the GUI
For $i = 1 to $totalloops Step 1
; Right click tree in middle of screen
MouseMove(397,251)
MouseClick("right")
Sleep(500)
; Pick apple
;MouseMove(462,275) ; If the tree doesn't have bark?
$apple_button_x = 447
$apple_button_y = 305
$checksum = PixelChecksum($apple_button_x - 20, $apple_button_y -10, $apple_button_x +20, $apple_button_y+10)
;_ScreenCapture_CaptureWnd(@MyDocumentsDir & "\eatapple_cap_pick.bmp", $win_handle, $apple_button_x - 20, $apple_button_y -10, $apple_button_x +20, $apple_button_y+10, False)
if $checksum <> $apple_button_checksum Then
msgbox(0,"Error!", "'Pick apple' button is not where it should be." & @CRLF & @CRLF & "Make sure you have the camera centered on the base of the tree, and the tree can provide bark (so the Pick Apple button is the 4th button)" & @CRLF & @CRLF & "Quitting...")
Exit
EndIf
MouseMove($apple_button_x,$apple_button_y)
MouseClick("left")
sleep(1800)
; Right click apple in first box in inventory
$apple_inventory_x = 137
$apple_inventory_y = 135
$checksum = PixelChecksum($apple_inventory_x - 10, $apple_inventory_y - 10, $apple_inventory_x +10, $apple_inventory_y+10)
if $checksum <> $apple_inventory_checksum Then
msgbox(0,"Error!", "There is no apple in the first slot in your inventory!" & @CRLF & @CRLF & "Empty the first slot and try again" & @CRLF & @CRLF & "Quitting...")
Exit
EndIf
MouseMove($apple_inventory_x,$apple_inventory_y)
MouseClick("right")
Sleep(500)
; Eat apple
MouseMove(137,60)
MouseClick("left")
sleep(800)
; Drop apple
MouseMove(137,135) ; Middle of first slot in bag
Send("{CTRLDOWN}")
MouseClick("left")
Send("{CTRLUP}")
update_status($i)
Next