forked from tellomichmich/PokeNoxBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PokeNoxBot.py
994 lines (881 loc) · 29.7 KB
/
PokeNoxBot.py
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
# -*- coding: utf-8 -*-
import json
import time
import io
import random
import sys
import os.path
import base64
import datetime
import traceback
from PIL import Image, ImageOps, ImageDraw, ImageChops
from math import ceil, radians, cos, sin, asin, sqrt
import re
assert sys.version_info >= (2,7)
assert sys.version_info < (3,0)
EvolveList = ["Pidgey", "Rattata", "Weedle", "Caterpie"]
#Rotate a python list
def rotate_list(l,n):
return l[-n:] + l[:-n]
def geo_distance(lat1, lon1, lat2, lon2):
lat1, lon1, lat2, lon2 = map(radians, [lat1, lon1, lat2, lon2])
dlat = lat2 - lat1
dlon = lon2 - lon1
a = sin(dlon/2)**2 + cos(lon1) * cos(lon2) * sin(dlat/2)**2
c = 2 * asin(sqrt(a))
r = 6371
return (c * r)*1000
def geo_walk_to(speed, lat1, lon1, alt1, lat2, lon2, alt2):
new_lat = lat1
new_lon = lon1
new_alt = alt1
travel_geo_points = []
dist = geo_distance(lat1, lon1, lat2, lon2)
steps = (float(dist))/(float(speed))
if steps >= 1:
dLat = (lat2 - lat1) / steps
dLon = (lon2 - lon1) / steps
dAlt = (alt2 - alt1) / steps
for i in range(0, int(steps)):
new_lat = lat1 + (dLat * (i+1))
new_lon = lon1 + (dLon * (i+1))
new_alt = alt1 + (dAlt * (i+1))
#print "%f, %f, %f" % (new_lat, new_lon, new_alt)
travel_geo_points.append([new_lat, new_lon, new_alt])
#else:
#print "%f, %f, %f" % (new_lat, new_lon, new_alt)
# travel_geo_points.append([new_lat, new_lon, new_alt])
return travel_geo_points
def geo_point_from_kml(kml_filename, speed):
geo_points = []
f = open(kml_filename)
for line in f:
if re.match("[-+]?[0-9]*\.?[0-9]+,[-+]?[0-9]*\.?[0-9]+,[-+]?[0-9]*\.?[0-9]+", line):
geo_point = line.strip().split(',')
geo_points.append([float(geo_point[0]), float(geo_point[1]), float(geo_point[2])])
f.close()
loop_geo_points = []
last_geo_point = None
for cur_geo_point in geo_points:
if not last_geo_point is None:
loop_geo_points = loop_geo_points + geo_walk_to(speed, last_geo_point[0], last_geo_point[1], last_geo_point[2], cur_geo_point[0], cur_geo_point[1], cur_geo_point[2])
last_geo_point = cur_geo_point
loop_geo_points = loop_geo_points + geo_walk_to(speed, last_geo_point[0], last_geo_point[1], last_geo_point[2], geo_points[0][0], geo_points[0][1], geo_points[0][2])
return loop_geo_points
def Tap(x, y):
Command = "bin\\adb.exe shell input tap %d %d" % (x, y)
os.system(Command)
def Swipe(x1, y1, x2, y2):
Command = "bin\\adb.exe shell input swipe %d %d %d %d " % (x1, y1, x2, y2)
os.system(Command)
def SwipeTime(x1, y1, x2, y2, t):
Command = "bin\\adb.exe shell input swipe %d %d %d %d %d" % (x1, y1, x2, y2, t)
os.system(Command)
def TakePngScreenshot():
while True:
try:
Command = "bin\\adb.exe shell \"screencap -p | busybox base64\""
PngScreenshotData = os.popen(Command).read()
PngScreenshotData = base64.b64decode(PngScreenshotData)
break;
except KeyboardInterrupt:
sys.exit(0)
except:
print "[!] Failed to get screen"
return PngScreenshotData
def IsColorInCeil(ColorToCheck, RefColor, Ceil):
if (RefColor[0]+(255*Ceil)) > ColorToCheck[0] > (RefColor[0]-(255*Ceil)):
if (RefColor[1]+(255*Ceil)) > ColorToCheck[1] > (RefColor[1]-(255*Ceil)):
if (RefColor[2]+(255*Ceil)) > ColorToCheck[2] > (RefColor[2]-(255*Ceil)):
return True
return False
def RemoveColor(img, Color, Ceil):
pixdata = img.load()
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if IsColorInCeil(pixdata[x, y], Color, Ceil):
pixdata[x, y] = (255, 255, 255)
def RemoveBlue(img, Limit):
pixdata = img.load()
for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if pixdata[x, y][2] > Limit:
pixdata[x, y] = (255, 255, 255)
def RemoveInSquare(img, x, y, xs, ys):
pixdata = img.load()
for yr in xrange(img.size[1]):
for xr in xrange(img.size[0]):
if (x+xs >= xr >= x) and (y+ys >= yr >= y):
pixdata[xr, yr] = (255, 255, 255)
def RemoveNotInSquare(img, x, y, xs, ys):
pixdata = img.load()
for yr in xrange(img.size[1]):
for xr in xrange(img.size[0]):
if not((x+xs >= xr >= x) and (y+ys >= yr >= y)):
pixdata[xr, yr] = (255, 255, 255)
def GetMeanColor(img, x, y, size=10):
MeanColor = [0, 0, 0]
pixdata = img.load()
for xr in range(x-(size/2), x+(size/2)):
for yr in range(y-(size/2), y+(size/2)):
MeanColor[0] = MeanColor[0] + pixdata[xr, yr][0]
MeanColor[1] = MeanColor[1] + pixdata[xr, yr][1]
MeanColor[2] = MeanColor[2] + pixdata[xr, yr][2]
MeanColor[0] = MeanColor[0]/(size**2)
MeanColor[1] = MeanColor[1]/(size**2)
MeanColor[2] = MeanColor[2]/(size**2)
return MeanColor
ScreenShotCount = 0
def GetImgFromScreenShot():
global ScreenShotCount
ScreenShotCount += 1
Screenshot = TakePngScreenshot()
img = Image.open(io.BytesIO(Screenshot))
img = img.convert("RGB")
#img.save("tmp/%04d.png" % (ScreenShotCount))
return img
def GetImgFromFile(File):
img = Image.open(File)
img = img.convert("RGB")
return img
#TODO: class !!!
img = None
#TODO: We really need class !!
TotalExperience = 0
def AddExperience(ExperienceCount):
global TotalExperience
TotalExperience += ExperienceCount
def GetExperience():
global TotalExperience
return TotalExperience
def GetScreen():
global img
if img == None:
img = GetImgFromScreenShot()
return img
def ClearScreen():
global img
img = None
def IsOpenPokestop():
img = GetScreen()
#Outer
MeanColor = GetMeanColor(img, 234, 780)
print MeanColor
if MeanColor[0] < 150 and MeanColor[1] < 230 and MeanColor[2] > 240:
return True
#Inner border
MeanColor = GetMeanColor(img, 180, 745)
#print MeanColor
if MeanColor[0] < 150 and MeanColor[1] < 230 and MeanColor[2] > 240:
return True
return False
def SpinPokestop():
Swipe(432, 424, 109, 432)
time.sleep(0.2)
ClearScreen()
def IsSpinnedPokestop():
img = GetScreen()
#Outer
MeanColor = GetMeanColor(img, 234, 780)
if MeanColor[0] > 150 and MeanColor[1] < 150 and MeanColor[2] > 200:
return True
#Inner border
MeanColor = GetMeanColor(img, 180, 745)
#print MeanColor
if MeanColor[0] > 150 and MeanColor[1] < 150 and MeanColor[2] > 200:
return True
return False
def ClosePokestop():
Tap(236, 736)
time.sleep(1)
ClearScreen()
def CloseGym():
Tap(236, 736)
time.sleep(0.2)
ClearScreen()
def FindPokestop():
ReturnToMap()
img = GetScreen().copy()
#Apply a mask to keep only "Pokestop zone"
PokeStopZone = (140, 420, 200, 180)
mask = Image.new('L', (480, 800), 255)
draw = ImageDraw.Draw(mask)
draw.ellipse((PokeStopZone[0],PokeStopZone[1],PokeStopZone[0]+PokeStopZone[2],PokeStopZone[1]+PokeStopZone[3]) , fill=0)
img.paste((255, 255, 255), mask=mask)
img.save("OUT_POKESTOP.png")
x, y, xs, ys = PokeStopZone
#Remove Lured pokestop circle
Frame = img.crop(((x, y, x+xs, y+ys)))
RemoveColor(Frame, (179, 250, 255), 0.05)
Frame.save("OUT_POKESTOP.png")
pixdata = Frame.load()
SquareSize = 8
for xr in range((SquareSize/2), xs-(SquareSize/2)):
for yr in range((SquareSize/2), ys-(SquareSize/2)):
#Only on blue like pixel
if pixdata[xr, yr] != (255, 255, 255) and pixdata[xr, yr][2] > 230:
MeanColor = GetMeanColor(Frame, xr, yr, SquareSize)
if IsColorInCeil(MeanColor, [87, 255, 255], 0.05):
return [xr+(SquareSize/2)+x, yr+(SquareSize/2)+y]
if IsColorInCeil(MeanColor, [64, 227, 252], 0.15):
return [xr+(SquareSize/2)+x, yr+(SquareSize/2)+y]
return None
def BlackOrWhite(img):
BlackCount = 0.0
pixdata = img.load()
for xr in xrange(img.size[0]):
for yr in xrange(img.size[1]):
if pixdata[xr, yr] != (255, 255, 255):
pixdata[xr, yr] = (0, 0, 0)
BlackCount += 1
return (BlackCount/(img.size[0]*img.size[1]))*100
def IsDay():
Hour = datetime.datetime.now().hour
if Hour > 7 and Hour < 19:
return True
return False
def RemoveColorList(img, ColorList):
pixdata = img.load()
for x in xrange(img.size[0]):
for y in xrange(img.size[1]):
if pixdata[x, y] in ColorList:
pixdata[x, y] = (255, 255, 255)
def FindPokemonPosition(img, SquareSize=4):
pixdata = img.load()
for xr in range(SquareSize/2, img.size[0]-(SquareSize/2)):
for yr in range(SquareSize/2, img.size[1]-(SquareSize/2)):
if pixdata[xr, yr] == (0, 0, 0):
FalsePositiv = GetMeanColor(img, xr, yr, SquareSize)
Score = (FalsePositiv[0]+FalsePositiv[1]+FalsePositiv[2])/3
if Score < 40:
return [xr, yr]
return None
def FindPokemon():
ReturnToMap();
#TestFindPokemon()
img = GetScreen().copy()
#Remove the player
RemoveInSquare(img, 227, 482, 22, 40)
#Remove the Experience notification
RemoveInSquare(img, 24, 600, 115, 70)
#Apply amask to keep only "Pokemon zone"
mask = Image.new('L', (480, 800), 255)
draw = ImageDraw.Draw(mask)
PokemonZone = (65, 420, 135+300, 438+250)
draw.ellipse(PokemonZone, fill=0)
img.paste((255, 255, 255), mask=mask)
Frame = img.crop((PokemonZone))
Frame = ImageOps.posterize(Frame, 2)
ColorBlackList = []
if IsDay():
#Day Road
ColorBlackList.append((64, 128, 128))
ColorBlackList.append((0, 128, 128))
#Green
ColorBlackList.append((0, 192, 128))
ColorBlackList.append((128, 192, 128))
ColorBlackList.append((128, 192, 64))
ColorBlackList.append((64, 192, 128))
ColorBlackList.append((64, 192, 64))
#Day Road Boarder
ColorBlackList.append((192, 192, 128))
else:
#Road
ColorBlackList.append((64, 128, 192))
#Green
ColorBlackList.append((64, 128, 128))
ColorBlackList.append((0, 128, 128))
ColorBlackList.append((0, 64, 128))
ColorBlackList.append((0, 64, 64))
ColorBlackList.append((64, 128, 64))
#Night Road Boarder
ColorBlackList.append((128, 128, 128))
#Spinned Pokestop
ColorBlackList.append((192, 128, 192))
ColorBlackList.append((64, 64, 192))
ColorBlackList.append((128, 64, 192))
#Lured Pokestop
ColorBlackList.append((192, 64, 192))
#Pokestop
ColorBlackList.append((0, 128, 192))
ColorBlackList.append((64, 192, 192))
ColorBlackList.append((0, 192, 192))
ColorBlackList.append((0, 64, 192))
#Lured Pokestop Circle
ColorBlackList.append((128, 192, 192))
#Lured Pokestop Flowers
ColorBlackList.append((192, 192, 192))
#Green rustles
ColorBlackList.append((0, 128, 64))
ColorBlackList.append((128, 128, 64))
ColorBlackList.append((128, 192, 128))
ColorBlackList.append((0, 192, 0))
ColorBlackList.append((128, 192, 0))
ColorBlackList.append((0, 64, 0))
ColorBlackList.append((64, 192, 0))
ColorBlackList.append((64, 192, 128))
ColorBlackList.append((0, 128, 0))
RemoveColorList(Frame, ColorBlackList)
Frame.save("OUT_COLOR.png")
BlackRatio = BlackOrWhite(Frame)
Frame.save("OUT_BW.png")
#Search for big Pokemon before small one
for i in range(10, 2, -2):
PokemonPosition = FindPokemonPosition(Frame, i)
if not PokemonPosition is None:
PokemonPosition[0] += PokemonZone[0]
PokemonPosition[1] += PokemonZone[1]
return PokemonPosition
return None
def ThrowPokeball(Power):
#Far 100
#Near 400
print "[!] Throw a Pokeball (%d)" % (100+Power)
SwipeTime(236, 780, 236, 30+Power, 200)
ClearScreen()
def IsPokemonFightOpen():
img = GetScreen()
pixdata = img.load()
return IsColorInCeil(pixdata[426, 67], (241, 249, 241), 0.01)
def IsGymOpen():
img = GetScreen()
pixdata = img.load()
#White part of the "plateau"
if IsColorInCeil(pixdata[403, 560], (255, 255, 255), 0.01) == False:
return False
#Close cross
if IsColorInCeil(pixdata[240, 740], (34, 136, 153), 0.01) == False:
return False
return True
def IsOnMap():
img = GetScreen()
pixdata = img.load()
return IsColorInCeil(pixdata[237, 703], (255, 57, 69), 0.01)
def IsCatchSucess():
img = GetScreen()
#img = GetImgFromFile("CatchSuccess.png")
pixdata = img.load()
if IsColorInCeil(pixdata[44, 227], (254, 255, 254), 0.005) and IsColorInCeil(pixdata[22, 518], (247, 255, 245), 0.01):
return True
return False
def PokemonWorker(PokemonPosition):
print "[!] Going to fight with %d %d !" % (PokemonPosition[0], PokemonPosition[1])
Tap(PokemonPosition[0], PokemonPosition[1])
ClearScreen()
time.sleep(0.3)
bIsPokemonFightOpened = False
#Check if the click successed
if IsOnMap() == True:
print "[!] Click failed !"
return None
#Wait for fight
for i in range(0, 5):
#time.sleep(1)
if IsPokemonFightOpen() == True:
bIsPokemonFightOpened = True
break;
if IsGymOpen() == True:
print "[!] Holy... This is a Gym"
CloseGym()
break
#We maybe clicked on a PokeStop...
if IsOpenPokestop() == True:
print "[!] Holy... This is a Pokestop"
PokestopWorker([0,0])
break
if IsSpinnedPokestop() == True:
print "[!] Holy... This is a Spinned Pokestop"
ClosePokestop()
break
if IsPokeBoxFull() == True:
print "[!] The PokeBox is full !"
#Close the pop-up
Tap(345, 419)
time.sleep(0.5)
ClearScreen()
TransferLowCPPokemons(10)
#Return true to refight the pokemon
return True
print "[!] Wait for Pokemon fight..."
time.sleep(0.5)
ClearScreen()
if bIsPokemonFightOpened == False:
#This is a big fail maybe a gym detected as Pokemon
return None
bIsPokemonHitted = False
ThrowCount = 0
while True:
if bIsPokemonHitted == False:
LastPower = random.randint(0,500)
else:
print "[!] Using last pokeball power"
if ThrowCount > 30 :
print "[!] Pokemon too hard, exiting the fight !"
ClosePokemonFight()
#Return false to avoid refight this pokemon
return False
#TODO Detect pokemon distance
ThrowPokeball(LastPower)
ThrowCount += 1
time.sleep(1)
bIsPokemonFightOpened = False
bIsCatchSuccess = False
bIsOnMap = False
StressCount = 0
while True:
if IsPokemonFightOpen() == True:
bIsPokemonFightOpened = True
break
if IsCatchSucess() == True:
bIsCatchSuccess = True
break
if IsOnMap() == True:
bIsOnMap = True
break
print "[!] #STRESS..."
StressCount += 1
ClearScreen()
if bIsCatchSuccess == True:
print "[!] Pokemon captured !"
break
if bIsOnMap == True:
print "[!] Pokemon flee !"
return False
if StressCount == 0:
print "[!] No more pokeball !"
ClosePokemonFight()
return None
if StressCount >= 4:
bIsPokemonHitted = True
else:
bIsPokemonHitted = False
#Close "sucess" Pop-up
Tap(239, 526)
ClearScreen()
time.sleep(0.2)
while IsPokemonOpen() == False:
time.sleep(0.5)
ClearScreen()
#We are here on the pokemon statistics
PokemonName = GetPokemonName()
print "[!] This is a %s" % (PokemonName)
if PokemonName in EvolveList:
EvolvePokemon()
TransferPokemon()
else:
ClosePokemon()
AddExperience(100)
#while IsOnMap() == False:
# print "[!] Waiting return to the map"
# time.sleep(1)
# ClearScreen()
ReturnToMap()
return True
def ClosePokemon():
Tap(239, 740)
ClearScreen()
def CleanInventory():
print "[!] Clean inventory..."
if IsOnMap() == False:
print "[!] Not on the map !"
return False
Tap(236, 736)
time.sleep(1)
Tap(372, 651)
time.sleep(1)
ClearScreen()
while True:
img = GetScreen()
FirstObjectColor = GetMeanColor(img, 80, 200)
print FirstObjectColor
if IsColorInCeil(FirstObjectColor, [240, 79, 238], 0.01):
print "[!] Lot of Potions will be dropped !"
elif IsColorInCeil(FirstObjectColor, [253, 217, 55], 0.01):
print "[!] Lot of Super Potions will be dropped !"
elif IsColorInCeil(FirstObjectColor, [251, 228, 218], 0.01):
print "[!] Lot of Hyper Potions will be dropped !"
elif IsColorInCeil(FirstObjectColor, [14, 157, 239], 0.01):
print "[!] Lot of Max Potions will be dropped !"
elif IsColorInCeil(FirstObjectColor, [254, 224, 96], 0.01):
print "[!] Lot of Revives will be dropped !"
else:
print "[!] Nothing to drop !"
break
#Remove this object
Tap(438, 150)
time.sleep(1)
#1sec for 20 elements
SwipeTime(351, 355, 351, 355, 2000)
Tap(236, 511)
time.sleep(0.5)
ClearScreen()
#Close Inventory
Tap(236, 736)
ClearScreen()
def PokestopWorker(PokeStopPosition):
print "[!] Working on Pokestop %d %d" % (PokeStopPosition[0], PokeStopPosition[1])
Tap(PokeStopPosition[0], PokeStopPosition[1])
time.sleep(0.2)
ClearScreen()
if IsOnMap() == True:
print "[!] Click failed !"
return False
bOpenPokestopSuccess = False
for i in range(5):
if IsPokestopTooFar() == True:
print "[!] Pokestop is too far !"
ClosePokestop()
break
if IsOpenPokestop() == True:
bOpenPokestopSuccess = True
break
if IsSpinnedPokestop() == True:
print "[!] Pokestop already spinned... Something wrong..."
ClosePokestop()
break
if IsPokemonFightOpen():
print "[!] Holy... This is a pokemon !"
PokemonWorker([0,0])
break
if IsGymOpen():
print "[!] Holy... This is a Gym"
CloseGym()
print "[!] Wait for open pokestop"
ClearScreen()
if bOpenPokestopSuccess == True:
SpinPokestop()
bIsSpinnedPokestop = False
for i in range(3):
time.sleep(0.3)
if IsSpinnedPokestop() == True:
bIsSpinnedPokestop = True
break
print "[!] Wait for spinned pokestop"
ClearScreen()
bIsBagFull = IsBagFull()
ClosePokestop()
while IsOnMap() == False:
print "[!] Waiting return to the map"
ClearScreen()
if bIsBagFull == True:
print "[!] The bag is full..."
CleanInventory()
if bIsSpinnedPokestop == True:
AddExperience(50)
bOpenPokestopSuccess = bIsSpinnedPokestop
return bOpenPokestopSuccess
def SetPosition(Position):
Command = "bin\\adb.exe shell \"setprop persist.nox.gps.longitude %f && setprop persist.nox.gps.latitude %f && setprop persist.nox.gps.altitude %f\"" % (Position[0], Position[1], Position[2])
#Saved position
f = open("tmp/saved_position.txt", "w")
f.write("%f,%f,%f" % (Position[1], Position[0], Position[2]))
f.close()
os.system(Command)
ClearScreen()
def TransferPokemon():
if IsPokemonOpen() == False:
return False
#Options
Tap(418, 741)
time.sleep(0.1)
#Tap Transfert
Tap(423, 651)
time.sleep(0.1)
#Validation
#Tap(236,452) #0.31
Tap(240, 500) #0.33
time.sleep(1)
def TransferLowCPPokemons(Number):
print "[!] Low CP pokemon will be transfered..."
if IsOnMap() == False:
print "[!] Not on the map !"
return False
#Open Menu
Tap(236, 736)
time.sleep(0.1)
Tap(104, 659)
time.sleep(0.2)
#Tap CP
Tap(415, 742)
time.sleep(0.1)
#Select CP
#Tap(414, 631)#0.310
Tap(415, 650) #0.33.0
time.sleep(0.1)
#ScrollDown
SwipeTime(461, 123, 461, 12000, 300)
for i in range(0, Number):
print "[!] Transfering a low CP pokemon (%d/%d)" % (i+1, Number)
#Tap Down Left pokemon
Tap(83,619)
time.sleep(0.5)
ClearScreen()
if GetPokemonName() in EvolveList:
EvolvePokemon()
# ClosePokemon()
#else:
TransferPokemon()
#Close Menu
Tap(236, 736)
#Wait to be on the map
time.sleep(1)
def IsGameCrashed():
img = GetScreen()
pixdata = img.load()
if IsColorInCeil(pixdata[112, 451], (0, 0, 0), 0.01) and IsColorInCeil(pixdata[372, 449], (0, 0, 0), 0.01):
return True
if IsColorInCeil(pixdata[112, 451], (40, 40, 40), 0.01) and IsColorInCeil(pixdata[372, 449], (40, 40, 40), 0.01):
return True
MeanColor = GetMeanColor(img, 334, 291, 10)
if IsColorInCeil(MeanColor, [159, 156, 155], 0.01):
return True
return False
def IsPokeBoxFull():
img = GetScreen()
pixdata = img.load()
return IsColorInCeil(pixdata[345, 419], (54, 206, 167), 0.005)
#TODO: This shit is language dependent !
def IsPokestopTooFar():
img = GetScreen()
pixdata = img.load()
return IsColorInCeil(pixdata[379,653], (229, 127, 179), 0.005)
def IsBagFull():
img = GetScreen()
pixdata = img.load()
return IsColorInCeil(pixdata[310, 398], (228, 127, 177), 0.005)
def ClosePokemonFight():
Tap(53, 65)
ClearScreen()
#Todo: Take a while...
def ZoomOut():
Command = "bin\\adb.exe push bin\\Zoomout.txt /sdcard/Zoomout.txt"
os.system(Command)
Command = "bin\\adb.exe shell sh /sdcard/Zoomout.txt"
os.system(Command)
def RestartApplication():
#Close the game
Command = "bin\\adb shell am force-stop com.nianticlabs.pokemongo"
os.system(Command)
#Start the game
Command = "bin\\adb shell monkey -p com.nianticlabs.pokemongo -c android.intent.category.LAUNCHER 1"
os.system(Command)
#Close the error popup
#Tap(240, 444)
#time.sleep(0.5)
#Start the game
#Tap(334, 291)
while IsOnMap() == False:
Tap(235, 457)
ClearScreen()
print "[!] Waiting for map..."
time.sleep(1)
#Sometime got a "flash" map
time.sleep(2)
ClearScreen()
while IsOnMap() == False:
Tap(235, 457)
ClearScreen()
print "[!] Waiting for map..."
time.sleep(1)
ZoomOut()
ClearScreen()
#TODO !
def ReturnToMap():
for i in range(4):
if IsOnMap() == True:
return True
#Sometime got a crash of pokemongo
if IsGameCrashed():
RestartApplication()
return True
#This is shit !
if IsPokemonFightOpen():
PokemonWorker([0,0])
#No need to close
return True
if IsEggHatched():
Tap(200, 440)
ClearScreen()
while IsPokemonOpen() == False:
print "[!] Waiting end of animation"
ClearScreen()
AddExperience(500)
ClosePokemon()
return True
if IsPokestopTooFar():
ClosePokestop()
return True
if IsSpinnedPokestop():
ClosePokestop()
return True
if IsOpenPokestop():
PokestopWorker([0,0])
#No need to close, this is close by PokestopWorker
return True
if IsGymOpen():
CloseGym()
return True
if IsPokeBoxFull():
#Close the pop-up
Tap(345, 419)
ClearScreen()
time.sleep(0.5)
TransferLowCPPokemons(50)
return True
time.sleep(0.5)
#Last Hope... medals,...
if i == 2:
print "[!] LAST HOPE TO ESCAPE !"
Tap(0, 0)
ClosePokestop()
#Close speed alert
Tap(236, 536)
time.sleep(1)
ClearScreen()
print "[!] Don't know where we are.... Exiting"
img = GetScreen()
img.save("OUT_FAIL.png")
RestartApplication()
return False
def GetPokemonName():
img = GetScreen()
PokeNameZone = (24, 353, 23+430, 353+52)
Frame = img.crop(((PokeNameZone)))
Frame.save("tmp\\ocr.png")
Command = "bin\\tesseract.exe --tessdata-dir bin\\tessdata tmp\\ocr.png tmp\\ocr > nul"
os.system(Command)
f = open("tmp\\ocr.txt")
PokemonName = f.readline().strip()
f.close()
return PokemonName
def IsEvolvable():
img = GetScreen()
pixdata = img.load()
return IsColorInCeil(pixdata[218, 703], (36, 204, 170), 0.005)
def IsPokemonOpen():
img = GetScreen()
pixdata = img.load()
return (pixdata[33, 331] == (250, 250, 250) and pixdata[448, 675] == (250, 250, 250))
def EvolvePokemon():
if IsPokemonOpen() == False:
print "[!] Not on a Pokemon !"
return False
if IsEvolvable() == False:
print "[!] This Pokemon is not evolvable !"
return False
#Evolve !
Tap(144, 707)
time.sleep(0.2)
#Validation
Tap(239, 420)
ClearScreen()
print "[!] Waiting end of evolution..."
time.sleep(10)
while IsPokemonOpen() == False:
ClearScreen()
time.sleep(1)
AddExperience(500)
return True
def IsEggHatched():
img = GetScreen()
pixdata = img.load()
#print pixdata[18, 780]
return IsColorInCeil(pixdata[18, 780], (204, 245, 237), 0.005)
#Core...
#Tap(272, 800)
#Swipe(539, 200, 0, 200)
#Tap(490, 128)
#img = GetImgFromFile("output.png")
#PokemonPosition = FindPokemon()
#PokeStopPosition = FindPokestop(img)
#img = GetImgFromScreenShot()
#FindPokemon()
#print GetMeanColor(img, 251, 478 )
#print FindPokemon(img)
#img.save("OUT.png")
#print PokemonPosition
#print IsCatchSucess()
#CatchPokemon([376, 512])
#CleanInventory()
#print IsCatchSucess()
#TransfertPokemon(30)
#print IsBagFull()
#print IsGymOpen()
#print IsOpenPokestop()
#print IsPokemonOpen()
#print GetPokemonName()
#print IsEvolvable()
#print EvolvePokemon()
#TransferLowCPPokemons(50)
#sys.exit(0)
#7 is a safe value
Speed = 7
loop_geo_points = geo_point_from_kml("Levalois.kml", Speed)
#Searching for the nearest point
if os.path.isfile("tmp/saved_position.txt"):
f = open("tmp/saved_position.txt", 'r')
line = f.read().strip()
if re.match(".*,.*,.*", line):
saved_position = line.split(',')
saved_position[0] = float(saved_position[0])
saved_position[1] = float(saved_position[1])
saved_position[2] = float(saved_position[2])
min_distance = 99999999
min_distance_index = 0
current_index = 0
for geo_point in loop_geo_points:
distance_to_saved_point = geo_distance(saved_position[0], saved_position[1], geo_point[1], geo_point[0])
if distance_to_saved_point < min_distance:
min_distance_index = current_index
min_distance = distance_to_saved_point
current_index += 1
loop_geo_points = rotate_list(loop_geo_points, (-1 * min_distance_index))
#Teleport Security
Count = 0
SpinnedPokeStopCount = 0
#Set Initial position
SetPosition(loop_geo_points[0])
StartTime = time.time()
while True:
for geo_point in loop_geo_points:
if Count%(50/Speed)==0:
ReturnToMap()
SetPosition(geo_point)
#Waiting for end of running...
time.sleep(4.5)
ClearScreen()
print "[!] Looking around..."
#Pokestop first to grab some pokeball
while True:
print "[!] Looking for Pokestop"
PokeStopPosition = FindPokestop()
if PokeStopPosition is None:
print "[!] No more Pokestop found."
break
if PokestopWorker(PokeStopPosition) == False:
print "[!] Something failed..."
break
while True:
print "[!] Looking for pokemon"
#Clearing the screen because PokestopWorker can be long...
ClearScreen()
PokemonPosition = FindPokemon()
if PokemonPosition == False:
print "[!] This place is near a Gym !"
break
if PokemonPosition is None:
print "[!] No more Pokemon not found."
break
PokemonWorkerReturn = PokemonWorker(PokemonPosition)
if PokemonWorkerReturn == None:
print "[!] This place is near a Gym ?"
break
if PokemonWorkerReturn == False:
if IsGymOpen() == True:
CloseGym()
print "[!] This place is near a Gym !"
break
#Print estimated exprience for kikoo-time !
print "[!] ~%d Exp/h" % ((GetExperience()/(time.time()-StartTime))*60*60)
Count += 1
#SetPosition(geo_point)