-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPokeBot.ahk
More file actions
440 lines (287 loc) · 11.3 KB
/
PokeBot.ahk
File metadata and controls
440 lines (287 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
;----------------------------PokéBot Script------------------------------------------------------------------
#NoEnv
#Warn
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
;---------------------------- About -------------------------
/*
Name : PokéBot
Version : 0.1.4
Last update : 14/09/2016
Author : Undershell
Repository : https://github.com/undershell/pokebot
*/
;---------------------------- TODO --------------------------
;---------------------------- Var ---------------------------
; You can edit the variables here
;------------
; Series of move's keys. For example : ["w", "s"] or ["a", "d"] or ["w", "a", "s", "d"]
moves := ["a", "d"]
;------------
; Pokemon Recognation
Pokemons_colors := [ ]
Pokemons_names := [ ]
;------------
;End of editable Vars
;------------------------ Load Data ------------------------
IsPaused := false
nbrWindows = 0 ; in case you want to play/switch many windows
Walk = false ; walk or fish
xpSecond = false ; Exp the 1st pokemon using the 2nd
IniRead, win_Title, config.ini, Settings, Win_Title
IniRead, RefreshButtonX, config.ini, Settings, RefreshButtonX
IniRead, RefreshButtonY, config.ini, Settings, RefreshButtonY
IniRead, enable_bug_refresh, config.ini, Settings, enable_bug_refresh
; Principle Button coordinates "Fight"
IniRead, ButtonPixelColor, config.ini, Fight Button, ButtonPixelColor
IniRead, ButtonPixelX, config.ini, Fight Button, ButtonPixelX
IniRead, ButtonPixelY, config.ini, Fight Button, ButtonPixelY
; Pokemon Recognation
IniRead, enable_pokemon_recognation, config.ini, Pokemon Recognation, enable_pokemon_recognation
IniRead, PokemonPixelX, config.ini, Pokemon Recognation, PokemonPixelX
IniRead, PokemonPixelY, config.ini, Pokemon Recognation, PokemonPixelY
;---------------------------------------------------------------------------------------------------------
;---------------------------- GUI ---------------------------
Menu Tray, Icon, icons\UltraBall.ico
Gui PokeBot: New, -MaximizeBox +AlwaysOnTop
Gui Add, Tab2, x2 y1 w205 h180, Game|Config|Help
Gui,Tab, Game
Gui Add, Text, x16 y33 w95 h23, Multi Windows :
Gui Add, Edit, x118 y30 w41 h21 vnbrWindows, 0
Gui Add, CheckBox, x13 y55 w188 h23 vXpSecond, Exp the 1st pokemon using the 2nd
Gui Add, CheckBox, x13 y75 w120 h23 vWalk, Walk
Gui Add, CheckBox, x13 y95 w180 h23 venable_pokemon_recognation, Pokemon Recognation
Gui Add, CheckBox, x13 y115 w180 h23 venable_bug_refresh, Bug Refresh
Gui Add, Text, x8 y142 w198 h2 0x10
Gui Add, Button, x40 y150 w60 h23 gRun, Run
;Gui Add, Button, x85 y130 w48 h23 gPauseB vPauseButton, Pause
Gui Add, Button, x110 y150 w60 h23 gOpen, Open
Gui,Tab, Config
Gui Add, Button, x30 y30 w160 h23 gLocalizeFightButton, Localize Fight button
Gui Add, Button, x30 y60 w160 h23 gLocalizePokemon, Localize Pokemon's Pixel
Gui Add, Button, x30 y90 w160 h23 gLocalizeRefreshButton, Localize Refresh Button
Gui Add, Text, x8 y142 w198 h2 0x10
Gui Add, Button, x30 y150 w160 h23 gSaveLocations, Save Locations
;Gui Add, Button, x30 y80 w150 h23 gCapture, Capture color
Gui Show, w481 h381, Window
Gui,Tab, Help
Gui Add, Text, x9 y50 w198 h2 0x10
Gui Show, w209 h200, PokeBot
Return
PokeBotGuiEscape:
PokeBotGuiClose:
ExitApp
; End of the GUI section
;---------------------------------------------------------------------------------------------------------
;------------
Run:
Gui, Submit ;,NoHide
play(walk, xpSecond, Win_Title, nbrWindows, ButtonPixelColor, ButtonPixelX, ButtonPixelY, PokemonPixelX, PokemonPixelY, moves, enable_pokemon_recognation, Pokemons_colors, Pokemons_names, RefreshButtonX, RefreshButtonY, enable_bug_refresh)
return
;------------
Open:
run http://pokemon-planet.com/gameFullscreen.php
return
;------------
PauseB:
;clear tooltips
controlSend,, {ctrl down}f{ctrl up}, Win_Title
sleep 5000
SetTitleMatchMode, 2
controlSend,, {ctrl down}F5{ctrl up}, Chrome
if IsPaused
{
;Pause Off
IsPaused := false
GuiControl,, PauseButton, Pause
ToolTip, Bot Paused
}
else{
;Pause On
IsPaused := true
GuiControl,, PauseButton, Resume
}
return
;------------
LocalizeFightButton:
KeyWait, LButton, D ; Wait for the left mouse button to be pressed down.
MouseGetPos, ButtonPixelX, ButtonPixelY
KeyWait, LButton, U ; Wait for the left mouse button to be pressed down.
WinGetTitle, Win_Title, A
ToolTip, Button Center defined at : {%ButtonPixelX%.%ButtonPixelY%} - {%Win_Title%}, %ButtonPixelX%, %ButtonPixelY%,
return
;------------
LocalizePokemon:
KeyWait, LButton, D ; Wait for the left mouse button to be pressed down.
MouseGetPos, PokemonPixelX, PokemonPixelY
KeyWait, LButton, U ; Wait for the left mouse button to be pressed down.
ToolTip, Pokemon Pixel defined at : {%PokemonPixelX%.%PokemonPixelY%}, %PokemonPixelX%, %PokemonPixelY%,
return
;------------
LocalizeRefreshButton:
KeyWait, LButton, D ; Wait for the left mouse button to be pressed down.
MouseGetPos, RefreshButtonX, RefreshButtonY
KeyWait, LButton, U ; Wait for the left mouse button to be pressed down.
ToolTip, Pokemon Pixel defined at : {%RefreshButtonX%.%PokemonPixelY%}, %RefreshButtonX%, %RefreshButtonY%,
return
;------------
SaveLocations: ; Save Data
IniWrite, %Win_Title%, config.ini, Settings, Win_Title
; Principle Button coordinates "Fight"
IniWrite, %ButtonPixelX%, config.ini, Fight Button, ButtonPixelX
IniWrite, %ButtonPixelY%, config.ini, Fight Button, ButtonPixelY
; Pokemon Recognation
IniWrite, %PokemonPixelX%, config.ini, Pokemon Recognation, PokemonPixelX
IniWrite, %PokemonPixelY%, config.ini, Pokemon Recognation, PokemonPixelY
; Browser refresh button
IniWrite, %RefreshButtonX%, config.ini, Settings, RefreshButtonX
IniWrite, %RefreshButtonY%, config.ini, Settings, RefreshButtonY
return
;------------
Capture:
PixelGetColor, ButtonPixelColor, ButtonPixelX, ButtonPixelY
ToolTip, Captured color : {%ButtonPixelColor%} %ButtonPixelX% %ButtonPixelY% , %ButtonPixelX%, %ButtonPixelY%,
return
;---------------------------------------------------------------------------------------------------------
;---------------------------------------------------------------------------------------------------------
;-------------------------- Pokemon Recognation ------------------------
pokemonRecognation(PokemonPixelX, PokemonPixelY, Pokemons_colors, Pokemons_names){
PixelGetColor, PColor, PokemonPixelX, PokemonPixelY
toretrun := false
for key, value in Pokemons_colors{
if( value = PColor )
toretrun := Pokemons_names[key]
}
ToolTip, Pokemon Recognation : %PColor% - %toretrun%, 846, 413
return toretrun
}
;---------------------------- Function Play ---------------------------
play(walk, xpSecond, Win_Title, nbrWindows, ButtonPixelColor, ButtonPixelX, ButtonPixelY, PokemonPixelX, PokemonPixelY, moves, enable_pokemon_recognation, Pokemons_colors, Pokemons_names, RefreshButtonX, RefreshButtonY, enable_bug_refresh){
index := 0
checked = 1
refreshed = 0
;-------------------------------------------------------------------------------------------------
Loop
{
if(nbrWindows>0)
switchWindows(nbrWindows)
if(walk = 0)
Sleep % rand(2000, 4000)
PixelGetColor, Color, ButtonPixelX, ButtonPixelY
ToolTip, Check Pixel Color, ButtonPixelX, ButtonPixelY
if (Color = ButtonPixelColor)
{
refreshed = 0
if (enable_pokemon_recognation>0) && (pokemonRecognation(PokemonPixelX, PokemonPixelY, Pokemons_colors, Pokemons_names) = false){
Pause
}
Sleep % rand(1200, 1500)
ToolTip, %a_index%- Pixel Checking : Affirmative, ButtonPixelX, ButtonPixelY
checked++
Sleep % rand(800, 1000)
;---------------------------- XP Second -------------------------
if(xpSecond){
Sleep % rand(1500, 2000)
LOOP, 2 {
SetMouseDelay % rand(30, 300)
ControlClick, x363 y674, %Win_Title%
ToolTip, Switch pokemon : Click %a_index%, 363, 674
Sleep % rand(3000, 4000)
}
ToolTip, Switch done, 363, 674
Sleep % rand(4500, 6000)
}
;---------------------------- Fight ------------------------------
;If you want autofight & avoid missings & other problems,
;you can check the color here as well
; PixelGetColor, Color, ButtonPixelX, ButtonPixelY ;if (Color= ButtonPixelColor){ }else{}
Loop, ; %nbrAttacks% max nbr of attacks needed
{
PixelGetColor, Color, ButtonPixelX, ButtonPixelY
if (Color= ButtonPixelColor){
Loop, 2{
RX := rand(ButtonPixelX-5, ButtonPixelX+5)
RY := rand(ButtonPixelY-5, ButtonPixelY+5)
ToolTip, Fighting : Click %a_index%, RX, RY
SetMouseDelay % rand(30, 300)
ControlClick, x%RX% y%RY%, %Win_Title%
}
Sleep % rand(1500, 2000)
ToolTip, Fighting done, RX, RY
;Sleep % rand(4500, 6000)
}else{
ToolTip, Fighting done, ButtonPixelX, ButtonPixelY
;Sleep % rand(4500, 6000)
break
}
}
}else{
if(enable_bug_refresh>0)
checkBug(walk, refreshed,RefreshButtonX, RefreshButtonY, ButtonPixelX-20, ButtonPixelY-50, Win_Title)
ToolTip, %a_index%- Pixel Checking : Negative, ButtonPixelX, ButtonPixelY
checked--
if walk{
Loop, {
move := moves[index]
ToolTip, Move %a_index% : %move%, 300, 300
PixelGetColor, Color, ButtonPixelX, ButtonPixelY
if (Color = ButtonPixelColor){
ToolTip, Attack, 300, 300
break
}else{
if(enable_bug_refresh>0)
checkBug(walk, refreshed,RefreshButtonX, RefreshButtonY, ButtonPixelX-20, ButtonPixelY-50, Win_Title)
Send {%move% down} ;ControlSend
Sleep % rand(1000, 2000)
Send {%move% up} ;ControlSend
}
Sleep % rand(10, 60)
if index = 2 ;lengh if moves
index = 1
else
index++
}
}else{
; removed temporarily
}
}
}
}
;---------------------------------------------------------------------------------------------------------
;---------------------------- Helpers ---------------------------
rand(x,y){
Random, value, %x%, %y%
Return value
}
switchWindows(num)
{
send {alt down}
loop, %num%{
send {tab down}{tab up}
sleep , 25
}
send {alt up}
ControlClick, x410 y500, Win_Title
sleep, 500
}
; if a bug on the browser or connection turned the flash screen on dark or white
checkBug(walk, refreshed, RefreshButtonX, RefreshButtonY, x, y, Win_Title){
PixelGetColor, Color, x-30, y+10
; check x-i / y+i to be sure
if (Color= 0x000000) || (Color= 0xFFFFFF){
ToolTip, Bug : Refresh the page and sleep, x, y
if(refreshed = 0) || (refreshed > 4){
ControlClick, x%RefreshButtonX% y%RefreshButtonY%, %Win_Title%
; Send {F5} / shortkeys don't work with flash objects
refreshed ++
}
Sleep % rand(30000, 60000)
ControlClick, x%x% y%y%, %Win_Title%
if(walk = 0){
send {f} ; fish
}else{
send {b} ; ride the bike
}
}
}
;---------------------------------------------------------------------------------------------------------