Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ScreenCapture.au3>
- #include <File.au3>
- TitleMatch('winter_stronghold.png')
- global $map = 0 ;name of current map
- global $ini = @scriptdir & '\data.ini'
- global $tx = 0
- global $ty = 0
- global $skips = 0
- sleep(4000)
- Note('bot started')
- while 1
- Init()
- ClaimReward()
- WalkToGame(Orient())
- if IdentifyMap() then
- Sleep(40000)
- PlayGame()
- else
- Reset()
- endif
- wend
- func Init()
- $map = 0 ;name of current map
- $ini = @scriptdir & '\data.ini'
- $tx = 0
- $ty = 0
- $skips = 0
- endfunc
- func ClaimReward()
- sleep(500)
- mouseclick('left', 960, 660)
- sleep(500)
- endfunc
- func Orient()
- local $left = 1000, $top = 20, $right = 1400, $bottom = 120, $color = 0xFFE469
- PixelSearch($left, $top, $right, $bottom, $color, 10)
- if not @error then return 1
- local $left = 120, $top = 0, $right = 700, $bottom = 140, $color = 0xFFE469
- PixelSearch($left, $top, $right, $bottom, $color, 10)
- if not @error then return 2
- local $left = 1640, $top = 150, $right = 1800, $bottom = 330, $color = 0x42F257
- PixelSearch($left, $top, $right, $bottom, $color, 10)
- if not @error then return 3
- local $left = 850, $top = 200, $right = 1130, $bottom = 330, $color = 0x42F257
- PixelSearch($left, $top, $right, $bottom, $color, 10)
- if not @error then return 4
- local $left = 1120, $top = 200, $right = 1440, $bottom = 420, $color = 0xF2C2F1
- PixelSearch($left, $top, $right, $bottom, $color, 10)
- if not @error then return 5
- local $left = 570, $top = 200, $right = 780, $bottom = 430, $color = 0xF2C2F1
- PixelSearch($left, $top, $right, $bottom, $color, 10)
- if not @error then return 6
- local $left = 500, $top = 0, $right = 890, $bottom = 140, $color = 0xC0FEBE
- PixelSearch($left, $top, $right, $bottom, $color, 5)
- if not @error then return 7
- local $left = 500, $top = 0, $right = 890, $bottom = 140, $color = 0xC0FEBE
- PixelSearch($left, $top, $right, $bottom, $color, 5)
- if not @error then return 8
- local $left = 500, $top = 0, $right = 890, $bottom = 140, $color = 0x547DBD
- PixelSearch($left, $top, $right, $bottom, $color, 7)
- if not @error then return 7
- local $left = 570, $top = 392, $right = 605, $bottom = 430, $color = 0x66464A
- PixelSearch($left, $top, $right, $bottom, $color, 7)
- if not @error then return 8
- return 0
- endfunc
- func WalkToGame($direction)
- Note('finding a lobby')
- switch $direction
- case 1
- ; walk D
- send('{d down}')
- sleep(8250)
- send('{d up}')
- ;walk S
- send('{s down}')
- sleep(1000)
- send('{s up}')
- case 2
- ; walk WD
- send('{w down}')
- send('{d down}')
- sleep(7250)
- ; walk D
- send('{w up}')
- sleep(1000)
- send('{d up}')
- case 3
- ;walk A
- send('{a down}')
- sleep(1000)
- send('{a up}')
- ;walk W
- send('{w down}')
- sleep(7500)
- send('{w up}')
- ;walk D
- send('{d down}')
- sleep(1250)
- send('{d up}')
- case 4
- ;walk s
- send('{s down}')
- sleep(3000)
- send('{s up}')
- ;walk wa
- send('{w down}')
- send('{a down}')
- sleep(9750)
- send('{w up}')
- send('{a up}')
- ;walk wd
- send('{w down}')
- send('{d down}')
- sleep(1500)
- send('{d up}')
- send('{w up}')
- case 5
- ;walk s
- send('{s down}')
- sleep(2200)
- send('{s up}')
- ;walk a
- send('{a down}')
- sleep(8300)
- send('{a up}')
- ;walk w
- send('{w down}')
- sleep(1100)
- send('{w up}')
- case 6
- ;walk s
- send('{s down}')
- sleep(3500)
- send('{s up}')
- ;walk as
- send('{a down}')
- send('{s down}')
- sleep(6500)
- send('{a up}')
- send('{s up}')
- ;walk aw
- send('{a down}')
- send('{w down}')
- sleep(1700)
- send('{a up}')
- send('{w up}')
- case 7
- ;walk SD
- send('{s down}')
- send('{d down}')
- sleep(3500)
- send('{d up}')
- ;walk S
- sleep(6750)
- send('{s up}')
- ;walk A
- send('{a down}')
- sleep(2500)
- send('{a up}')
- case 8
- ;walk D
- send('{d down}')
- sleep(2250)
- ;walk SD
- send('{s down}')
- sleep(7250)
- send('{d up}')
- ;walk AS
- send('{a down}')
- sleep(2500)
- send('{a up}')
- send('{s up}')
- endswitch
- sleep(500)
- endfunc
- func Reset()
- send("{ESC}")
- sleep(1000)
- send("{r}")
- sleep(500)
- send("{ENTER}")
- sleep(7000)
- endfunc
- func IdentifyMap()
- Local $bitmap = _ScreenCapture_Capture(@scriptdir & "\title.png", 715, 749, 1160, 786)
- local $size = FileGetSize(@scriptdir & "\title.png")
- local $path = @scriptdir & "\titles"
- local $titles = _FileListToArray($path)
- local $sizes[0]
- ;iterate through titles to find a match
- For $i = 1 To $titles[0] step 1
- if TitleMatch($path & "\" & $titles[$i]) then
- $map = stringtrimright($titles[$i], 4)
- Note('map: ' & $map)
- return true
- endif
- Next
- return false
- endfunc
- func TitleMatch($imagepath)
- $pixels = 16948
- $command = 'magick compare -fuzz 10%% -metric AE title.png ' & $imagepath & ' null: 2>info.txt'
- runwait(@ComSpec & " /c " & $command, "", @SW_HIDE)
- $changed = Int(filereadline('info.txt'))
- $difference = $changed / $pixels
- if $difference < 0.25 then
- return true
- else
- return false
- endif
- endfunc
- func PlayGame()
- SelectDifficulty()
- PlaceTower()
- While StillAlive()
- SkipLevel()
- UpgradeTower()
- wend
- LeaveGame()
- RejoinServer()
- endfunc
- func SelectDifficulty()
- MouseClick("left", 960, 580)
- Note("selected difficulty")
- sleep(15000)
- endfunc
- func PlaceTower()
- $ini = @scriptdir & '\data.ini'
- $tx = IniRead($ini, $map, 'tx', 0)
- $ty = IniRead($ini, $map, 'ty', 0)
- if $tx = 0 and $ty = 0 then
- Note('something messed up')
- exit
- endif
- if $map = 'grass_isles' then
- ;walk S for 2 seconds
- send('{s down}')
- sleep(2000)
- send('{s up}')
- endif
- Send('{1}')
- sleep(2000)
- Note("placed tower at " & $tx & "," & $ty)
- MouseClick("left", $tx, $ty)
- sleep(10000)
- endfunc
- func StillAlive()
- ;check for red button
- local $left = 885, $top = 715, $right = 1035, $bottom = 750, $color = 0xFF0000
- PixelSearch($left, $top, $right, $bottom, $color, 2)
- if not @error then
- Note("defeated")
- return false
- else
- return true
- endif
- endfunc
- func SkipLevel()
- ;check for green yes button
- local $left = 850, $top = 200, $right = 940, $bottom = 230, $color = 0x00FF00
- PixelSearch($left, $top, $right, $bottom, $color, 2)
- if not @error then
- mouseclick("left", 900, 215)
- $skips += 1
- Note('skipped level')
- sleep(1000)
- MouseClick("left", $tx, $ty)
- endif
- endfunc
- func UpgradeTower()
- MouseClick("left", $tx + 90, $ty - 95)
- sleep(20000)
- endfunc
- func LeaveGame()
- sleep(500)
- send("{ESC}")
- sleep(500)
- send("{l}")
- sleep(500)
- send("{ENTER}")
- Note('leaving match')
- sleep(10000)
- endfunc
- func RejoinServer()
- local $x =
- local $y =
- Note('rejoining private server')
- mouseclick("left", $x, $y)
- sleep(20000)
- endfunc
- func Note($entry)
- $log = FileOpen(@scriptdir & '\log.txt', 1)
- $timestamp = @HOUR & ":" & @MIN & ":" & @SEC
- FileWriteLine($log, $entry)
- fileclose($log)
- endfunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement