This repository has been archived by the owner on Jul 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
afk-daily.sh
1996 lines (1838 loc) · 84.5 KB
/
afk-daily.sh
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
995
996
997
998
999
1000
#!/system/bin/sh
# ##############################################################################
# Script Name : afk-daily.sh
# Description : Script automating daily
# Args : [-c] [-e EVENT] [-f] [-g] [-i INI] [-l LOCATION]
# [-s TOTEST] [-t] [-v DEBUG] [-w]
# GitHub : https://github.com/zebscripts/AFK-Daily
# License : MIT
# ##############################################################################
# ##############################################################################
# Section : Variables
# ##############################################################################
# Probably you don't need to modify this. Do it if you know what you're doing, I won't blame you (unless you blame me).
DEVICEWIDTH=1080
DEBUG=0
# DEBUG = 0 Show no debug
# DEBUG >= 1 Show getColor calls > $HEX value
# DEBUG >= 2 Show test calls
# DEBUG >= 3 Show all core functions calls
# DEBUG >= 4 Show all functions calls
# DEBUG >= 9 Show tap calls
DEFAULT_DELTA=3 # Default delta for colors
DEFAULT_SLEEP=2 # equivalent to wait (default 2)
eventHoe=false # Set to `true` if "Heroes of Esperia" event is live
eventTs=false # Set to `true` if "Treasure Scramble" event is live
totalAmountOakRewards=3
# Do not modify
activeTab="Start"
activeEvents=""
currentPos="default"
dayofweek=$(TZ=UTC date +%u)
forceFightCampaign=false
forceWeekly=false
hasEnded=false
HEX=00000000
INILOCATION="/storage/emulated/0/scripts/afk-arena/"
INIFILE="config.ini"
oakRes=0
screenshotRequired=true
testServer=false
SCREENSHOTLOCATION="/storage/emulated/0/scripts/afk-arena/screen.dump"
withColors=true
hexdumpSu=false
# Colors
cNc="\033[0m" # Text Reset
cRed="\033[0;91m" # [ERROR]
cGreen="\033[0;92m" # [OK]
cYellow="\033[0;93m" # [WARN]
cBlue="\033[0;94m" # Values
cPurple="\033[0;95m" # [DEBUG]
cCyan="\033[0;96m" # [INFO]
while getopts "ce:fgi:l:s:tv:w" opt; do
case $opt in
c)
withColors=false
;;
e)
buIFS=$IFS
# Explication: https://stackoverflow.com/a/7718539/7295428
IFS=','
for i in $OPTARG; do
case "$i" in
"hoe") eventHoe=true ;; # Heroes of Esperia
"ts") eventTs=true ;; # Treasure Scramble (same problem as HoE atm)
esac
done
IFS=$buIFS
;;
f)
forceFightCampaign=true
;;
g)
hexdumpSu=true
;;
i)
INIFILE="${OPTARG#config/}"
;;
l)
SCREENSHOTLOCATION="/$OPTARG/scripts/afk-arena/screen.dump"
INILOCATION="/$OPTARG/scripts/afk-arena/"
;;
s)
totest=$OPTARG
;;
t)
testServer=true
;;
v)
DEBUG=$OPTARG
;;
w)
forceWeekly=true
;;
\?)
echo "$OPTARG : Invalid option"
exit 1
;;
esac
done
. "$INILOCATION$INIFILE"
doLootAfkChest2="$doLootAfkChest"
# ##############################################################################
# Section : Core Functions
# Description : It's like a library of useful functions
# ##############################################################################
# ##############################################################################
# Function Name : checkToDo
# Description : Check if argument is ToDo
# Args : <TODO>: name of the variable containing the boolean
# Output : return 0/1
# ##############################################################################
checkToDo() {
if [ "$(eval echo \$"$1")" = false ]; then
return 1
fi
if [ "$1" = "$currentPos" ]; then
tries=$((tries + 1))
printInColor "DEBUG" "checkToDo > $currentPos [$tries]"
else
eval "$currentPos=false"
currentPos="$1"
tries=0
fi
if [ $tries -lt 3 ]; then
return 0
else
eval "$1=false"
return 1
fi
}
# ##############################################################################
# Function Name : closeApp
# Descripton : Closes AFK Arena
# ##############################################################################
closeApp() {
if [ "$testServer" = true ]; then
am force-stop com.lilithgames.hgame.gp.id >/dev/null 2>/dev/null
else
am force-stop com.lilithgame.hgame.gp >/dev/null 2>/dev/null
fi
}
# ##############################################################################
# Function Name : disableOrientation
# Descripton : Disables automatic orientation
# ##############################################################################
disableOrientation() {
content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
}
# ##############################################################################
# Function Name : getColor
# Descripton : Sets $HEX, <-f> to force the screenshot
# Args : [<-f>] <X> <Y>
# ##############################################################################
getColor() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "getColor ${cPurple}$*${cNc}" >&2; fi
for arg in "$@"; do
shift
case "$arg" in
-f) screenshotRequired=true ;;
*) set -- "$@" "$arg" ;;
esac
done
takeScreenshot
readHEX "$1" "$2"
if [ "$DEBUG" -ge 1 ]; then printInColor "DEBUG" "getColor ${cPurple}$*${cNc} > HEX: ${cCyan}$HEX${cNc}" >&2; fi
}
# ##############################################################################
# Function Name : getCounterInColor
# Descripton : Print counter in color
# Args : <TYPE> <COUNTER>
# ##############################################################################
getCounterInColor() {
if [ "$#" -ne 2 ]; then
echo "Usage: getCounterInColor <TYPE> <COUNTER>" >&2
echo " <TYPE>: L, W" >&2
return
fi
if [ "$2" -eq 0 ]; then
echo "${cYellow}$2 $1${cNc}"
else
if [ "$1" = "L" ]; then
echo "${cRed}$2 $1${cNc}"
elif [ "$1" = "W" ]; then
echo "${cGreen}$2 $1${cNc}"
fi
fi
}
# ##############################################################################
# Function Name : getCountersInColor
# Descripton : Print counters in color
# Args : <COUNTER_WIN> [<COUNTER_LOOSE>]
# ##############################################################################
getCountersInColor() {
if [ "$#" -lt 1 ]; then
echo "Usage: getCountersInColor <COUNTER_WIN> [<COUNTER_LOOSE>]" >&2
return
fi
if [ "$#" -eq 1 ]; then
echo "[$(getCounterInColor W "$1")]"
elif [ "$#" -eq 2 ]; then
echo "[$(getCounterInColor W "$1") / $(getCounterInColor L "$2")]"
fi
}
# ##############################################################################
# Function Name : HEXColorDelta
# Args : <COLOR1> <COLOR2>
# Output : stdout [0 means similar colors, 100 means opposite colors]
# Source : https://github.com/kevingrillet/ShellUtils/blob/main/utils/utils_colors.sh
# ##############################################################################
HEXColorDelta() {
if [ "$#" -ne 2 ]; then
echo "Usage: HEXColorDelta <COLOR1> <COLOR2>" >&2
echo " 0 means similar colors, 100 means opposite colors" >&2
return
fi
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "HEXColorDelta ${cPurple}$*${cNc}" >&2; fi
r=$((0x${1:0:2} - 0x${2:0:2}))
g=$((0x${1:2:2} - 0x${2:2:2}))
b=$((0x${1:4:2} - 0x${2:4:2}))
d=$((((765 - (${r#-} + ${g#-} + ${b#-})) * 100) / 765)) # 765 = 3 * 255
d=$((100 - d)) # Delta is a distance... 0=same, 100=opposite need to reverse it
echo $d
}
# ##############################################################################
# Function Name : inputSwipe
# Descripton : Swipe
# Args : <X> <Y> <XEND> <YEND> <TIME>
# ##############################################################################
inputSwipe() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "inputSwipe ${cPurple}$*${cNc}" >&2; fi
input swipe "$1" "$2" "$3" "$4" "$5"
screenshotRequired=true
}
# ##############################################################################
# Function Name : inputTapSleep
# Descripton : input tap <X> <Y>, then SLEEP with default value DEFAULT_SLEEP
# Args : <X> <Y> [<SLEEP>]
# ##############################################################################
inputTapSleep() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "inputTapSleep ${cPurple}$*${cNc}" >&2; fi
input tap "$1" "$2" # tap
sleep "${3:-$DEFAULT_SLEEP}" # sleep
screenshotRequired=true
}
# ##############################################################################
# Function Name : loopUntilNotRGB
# Descripton : Loops until HEX is not equal
# Args : <SLEEP> <X> <Y> <COLOR> [<COLOR> ...]
# ##############################################################################
loopUntilNotRGB() {
if [ "$DEBUG" -ge 2 ]; then printInColor "DEBUG" "loopUntilNotRGB ${cPurple}$*${cNc}" >&2; fi
sleep "$1"
shift
until testColorNAND -f "$@"; do
sleep 1
done
}
# ##############################################################################
# Function Name : loopUntilRGB
# Descripton : Loops until HEX is equal
# Args : <SLEEP> <X> <Y> <COLOR> [<COLOR> ...]
# ##############################################################################
loopUntilRGB() {
if [ "$DEBUG" -ge 2 ]; then printInColor "DEBUG" "loopUntilRGB ${cPurple}$*${cNc}" >&2; fi
sleep "$1"
shift
until testColorOR -f "$@"; do
sleep 1
done
}
# ##############################################################################
# Function Name : printInColor
# Descripton : Print message in color
# Args : <TYPE> <MESSAGE>
# ##############################################################################
printInColor() {
if [ "$#" -ne 2 ]; then
echo "Usage: printInColor <TYPE> <MESSAGE>" >&2
echo " <TYPE>: DEBUG, DONE, ERROR, INFO, TEST, WARN" >&2
return
fi
if [ "$1" = "DEBUG" ]; then
msg="${cPurple}[DEBUG]${cNc} "
elif [ "$1" = "DONE" ]; then
msg="${cGreen}[DONE]${cNc} "
elif [ "$1" = "ERROR" ]; then
msg="${cRed}[ERROR]${cNc} "
elif [ "$1" = "INFO" ]; then
msg="${cBlue}[INFO]${cNc} "
elif [ "$1" = "WARN" ]; then
msg="${cYellow}[WARN]${cNc} "
else
msg=" "
fi
shift
msg="$msg$1${cNc}" # The ${cNc} is a security if we forgot to reset color at the end of our message
if [ "$withColors" = false ]; then
msg=$(echo "$msg" | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g') # Source: https://stackoverflow.com/a/54648447
fi
echo "$msg"
}
# ##############################################################################
# Function Name : readHEX
# Descripton : Gets pixel color
# Args : <X> <Y>
# Output : $HEX
# ##############################################################################
readHEX() {
offset=$((DEVICEWIDTH * $2 + $1 + 3))
if [ "$hexdumpSu" = true ]; then
HEX=$(dd if="$SCREENSHOTLOCATION" bs=4 skip="$offset" count=1 2>/dev/null | su -c hexdump -C)
else
HEX=$(dd if="$SCREENSHOTLOCATION" bs=4 skip="$offset" count=1 2>/dev/null | hexdump -C)
fi
HEX=${HEX:9:9}
HEX="${HEX// /}"
}
# ##############################################################################
# Function Name : startApp
# Descripton : Starts AFK Arena
# ##############################################################################
startApp() {
if [ "$testServer" = true ]; then
monkey -p com.lilithgames.hgame.gp.id 1 >/dev/null 2>/dev/null
else
monkey -p com.lilithgame.hgame.gp 1 >/dev/null 2>/dev/null
fi
sleep 1
disableOrientation
}
# ##############################################################################
# Function Name : takeScreenshot
# Descripton : Takes a screenshot and saves it if screenshotRequired=true
# Output : $SCREENSHOTLOCATION
# ##############################################################################
takeScreenshot() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "takeScreenshot [screenshotRequired=${cCyan}$screenshotRequired${cNc}]" >&2; fi
if [ $screenshotRequired = false ]; then return; fi
screencap "$SCREENSHOTLOCATION"
screenshotRequired=false
}
# ##############################################################################
# Function Name : testColorNAND
# Descripton : Equivalent to:
# if getColor <X> <Y> && [ "$HEX" != <COLOR> ] && [ "$HEX" != <COLOR> ]; then
# Args : [-f] [-d <DELTA>] <X> <Y> <COLOR> [<COLOR> ...]
# Output : if true, return 0, else 1
# ##############################################################################
testColorNAND() {
if [ "$DEBUG" -ge 2 ]; then printInColor "DEBUG" "testColorNAND ${cPurple}$*${cNc}" >&2; fi
_testColorNAND_max_delta=0
for arg in "$@"; do
shift
case "$arg" in
-d)
_testColorNAND_max_delta=$1
shift
;;
-f) screenshotRequired=true ;;
*) set -- "$@" "$arg" ;;
esac
done
getColor "$1" "$2" # looking for color
shift
shift # ignore arg
for i in "$@"; do # loop in colors
if [ "$HEX" = "$i" ]; then # color found?
if [ "$DEBUG" -ge 2 ]; then
printInColor "DEBUG" "testColorNAND ${cCyan}$HEX${cNc} = ${cCyan}$i${cNc}" >&2
fi
return 1 # At the first color found NAND is break, return 1
else
if [ "$DEBUG" -ge 2 ] || [ "$_testColorNAND_max_delta" -gt "0" ]; then
_testColorNAND_delta=$(HEXColorDelta "$HEX" "$i")
if [ "$DEBUG" -ge 2 ]; then
printInColor "DEBUG" "testColorNAND ${cCyan}$HEX${cNc} != ${cCyan}$i${cNc} [Δ ${cCyan}$_testColorNAND_delta${cNc}%]" >&2
fi
if [ "$_testColorNAND_delta" -le "$_testColorNAND_max_delta" ]; then
return 1
fi
fi
fi
done
return 0 # If no result > return 0
}
# ##############################################################################
# Function Name : testColorOR
# Descripton : Equivalent to:
# if getColor <X> <Y> && { [ "$HEX" = <COLOR> ] || [ "$HEX" = <COLOR> ]; }; then
# Args : [-f] [-d <DELTA>] <X> <Y> <COLOR> [<COLOR> ...]
# Output : if true, return 0, else 1
# ##############################################################################
testColorOR() {
if [ "$DEBUG" -ge 2 ]; then printInColor "DEBUG" "testColorOR ${cPurple}$*${cNc}" >&2; fi
_testColorOR_max_delta=0
for arg in "$@"; do
shift
case "$arg" in
-d)
_testColorOR_max_delta=$1
shift
;;
-f) screenshotRequired=true ;;
*) set -- "$@" "$arg" ;;
esac
done
getColor "$1" "$2" # looking for color
shift
shift # ignore arg
for i in "$@"; do # loop in colors
if [ "$HEX" = "$i" ]; then # color found?
if [ "$DEBUG" -ge 2 ]; then
printInColor "DEBUG" "testColorOR ${cCyan}$HEX${cNc} = ${cCyan}$i${cNc}" >&2
fi
return 0 # At the first color found OR is break, return 0
else
if [ "$DEBUG" -ge 2 ] || [ "$_testColorOR_max_delta" -gt "0" ]; then
_testColorOR_delta=$(HEXColorDelta "$HEX" "$i")
if [ "$DEBUG" -ge 2 ]; then
printInColor "DEBUG" "testColorOR ${cCyan}$HEX${cNc} != ${cCyan}$i${cNc} [Δ ${cCyan}$_testColorOR_delta${cNc}%]" >&2
fi
if [ "$_testColorOR_delta" -le "$_testColorOR_max_delta" ]; then
return 0
fi
fi
fi
done
return 1 # if no result > return 1
}
# ##############################################################################
# Function Name : testColorORTapSleep
# Descripton : Equivalent to:
# if testColorOR <X> <Y> <COLOR>; then
# inputTapSleep <X> <Y> <SLEEP>
# fi
# Args : <X> <Y> <COLOR> <SLEEP>
# ##############################################################################
testColorORTapSleep() {
if [ "$DEBUG" -ge 2 ]; then printInColor "DEBUG" "testColorORTapSleep ${cPurple}$*${cNc}" >&2; fi
if testColorOR "$1" "$2" "$3"; then # if color found
inputTapSleep "$1" "$2" "${4:-$DEFAULT_SLEEP}" # tap & sleep
fi
}
# ##############################################################################
# Function Name : verifyHEX
# Descripton : Verifies if <X> and <Y> have specific HEX then print <MESSAGE_*>
# Args : <X> <Y> <HEX> <MESSAGE_SUCCESS> <MESSAGE_FAILURE>
# Output : stdout MessageSuccess, stderr MessageFailure
# ##############################################################################
verifyHEX() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "verifyHEX ${cPurple}$*${cNc}" >&2; fi
getColor "$1" "$2"
if [ "$HEX" != "$3" ]; then
printInColor "ERROR" "verifyHEX: Failure! Expected ${cCyan}$3${cNc}, but got ${cCyan}$HEX${cNc} instead. [Δ ${cCyan}$(HEXColorDelta "$HEX" "$3")${cNc}%]" >&2
printInColor "ERROR" "$5" >&2
# WARN: The counter sometimes goes wrong. I did leave a print when tries > 0. Need to see if this bug comes back.
printInColor "WARN" "Restarting for the ${cCyan}$((tries + 1))${cNc} time."
init
run
else
printInColor "DONE" "$4"
fi
}
# ##############################################################################
# Function Name : wait
# Descripton : Default wait time for actions
# ##############################################################################
wait() {
sleep $DEFAULT_SLEEP
}
# ##############################################################################
# Section : Game SubFunctions
# Description : It's the extension of the Core for this specific game
# ##############################################################################
# ##############################################################################
# Function Name : doAuto
# Descripton : Click on auto if not already enabled
# ##############################################################################
doAuto() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "doAuto" >&2; fi
testColorORTapSleep 760 1440 332b2b 0 # On:743b29 Off:332b2b
}
# ##############################################################################
# Function Name : doSpeed
# Descripton : Click on x4 if not already enabled
# ##############################################################################
doSpeed() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "doSpeed" >&2; fi
testColorORTapSleep 990 1440 332b2b 0 # On:[x2: 753b29, x4: 743b29] Off:332b2b
}
# ##############################################################################
# Function Name : doSkip
# Descripton : Click on skip if avaible
# ##############################################################################
doSkip() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "doSkip" >&2; fi
testColorORTapSleep 760 1440 502e1d 0 # Exists: 502e1d
}
# ##############################################################################
# Function Name : switchTab
# Descripton : Switches to another tab if required by config.
# Args : <TAB_NAME> [<FORCE>]
# <TAB_NAME>: Campaign / Dark Forest / Ranhorn / Chat
# <FORCE>: true / false, default false
# ##############################################################################
switchTab() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "switchTab ${cPurple}$*${cNc} [activeTab=${cCyan}$activeTab${cNc}]" >&2; fi
if [ "$1" = "$activeTab" ]; then
return
fi
case "$1" in
"Campaign")
if [ "${2:-false}" = true ] ||
[ "$doLootAfkChest" = true ] ||
[ "$doChallengeBoss" = true ] ||
[ "$doFastRewards" = true ] ||
[ "$doCollectFriendsAndMercenaries" = true ] ||
[ "$doLootAfkChest" = true ]; then
inputTapSleep 550 1850 2
inputTapSleep 550 1850
activeTab="$1"
verifyHEX 450 1775 cc9261 "Switched to the Campaign Tab." "Failed to switch to the Campaign Tab."
fi
;;
"Dark Forest")
if [ "${2:-false}" = true ] ||
[ "$doSoloBounties" = true ] ||
[ "$doTeamBounties" = true ] ||
[ "$doArenaOfHeroes" = true ] ||
[ "$doLegendsTournament" = true ] ||
[ "$doKingsTower" = true ]; then
inputTapSleep 300 1850 2
inputTapSleep 300 1850
activeTab="$1"
verifyHEX 240 1775 d49a61 "Switched to the Dark Forest Tab." "Failed to switch to the Dark Forest Tab."
fi
;;
"Ranhorn")
if [ "${2:-false}" = true ] ||
[ "$doGuildHunts" = true ] ||
[ "$doTwistedRealmBoss" = true ] ||
[ "$doBuyFromStore" = true ] ||
[ "$doStrengthenCrystal" = true ] ||
[ "$doTempleOfAscension" = true ] ||
[ "$doCompanionPointsSummon" = true ] ||
[ "$doCollectOakPresents" = true ] ||
[ "$doCollectQuestChests" = true ] ||
[ "$doCollectMail" = true ] ||
[ "$doCollectMerchantFreebies" = true ]; then
inputTapSleep 110 1850 2
inputTapSleep 110 1850
activeTab="$1"
verifyHEX 20 1775 d49a61 "Switched to the Ranhorn Tab." "Failed to switch to the Ranhorn Tab."
fi
;;
"Chat")
inputTapSleep 970 1850
activeTab="$1"
verifyHEX 550 1690 ffffff "Switched to the Chat Tab." "Failed to switch to the Chat Tab."
;;
esac
}
# ##############################################################################
# Function Name : waitBattleFinish
# Descripton : Waits until a battle has ended after <SECONDS>
# Args : <SECONDS>
# ##############################################################################
waitBattleFinish() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "waitBattleFinish ${cPurple}$*${cNc}" >&2; fi
sleep "$1"
finished=false
until [ $finished = true ]; do
# First HEX local device, second bluestacks
if testColorOR -f 560 350 b8894d b7894c; then # Victory
battleFailed=false
finished=true
elif [ "$HEX" = '171932' ] || [ "$HEX" = "171d3c" ]; then # Failed & Failed in Challenger Tournament
battleFailed=true
finished=true
# First HEX local device, second bluestacks
elif [ "$HEX" = "45331d" ] || [ "$HEX" = "44331c" ]; then # Victory with reward
battleFailed=false
finished=true
fi
sleep 1
done
}
# ##############################################################################
# Function Name : waitBattleStart
# Descripton : Waits until battle starts
# ##############################################################################
waitBattleStart() {
if [ "$DEBUG" -ge 3 ]; then printInColor "DEBUG" "waitBattleStart" >&2; fi
_waitBattleStart_count=0 # Max loops = 10 (10x.5s=5s max)
# Check if pause button is present && less than 10 tries
until testColorOR -f 110 1465 482f1f || [ $_waitBattleStart_count -ge 10 ]; do
# Maybe pause button doesn't exist, so instead check for a skip button
if testColorOR 760 1440 502e1d; then return; fi
_waitBattleStart_count=$((_waitBattleStart_count + 1)) # Increment
sleep .5
# In case none were found, try again starting with the pause button
done
sleep 1
}
# ##############################################################################
# Section : Campaign
# ##############################################################################
# ##############################################################################
# Function Name : challengeBoss
# Descripton : Challenges a boss in the campaign
# Remark : Limited offers might screw this up.
# ##############################################################################
challengeBoss() {
if [ "$DEBUG" -ge 4 ]; then printInColor "DEBUG" "challengeBoss" >&2; fi
inputTapSleep 550 1650 3 # Begin
if testColorOR 550 740 f2d79f; then # Check if boss
inputTapSleep 550 1450 3 # Begin
fi
if [ "$forceFightCampaign" = "true" ]; then # Fight battle or not
# Fight in the campaign because of Mythic Trick
printInColor "INFO" "Fighting in the campaign until ${cCyan}$maxCampaignFights${cNc} defeat(s) because of Mythic Trick."
_challengeBoss_LOOSE=0
_challengeBoss_WIN=0
# Check for battle screen
until testColorNAND -d "$DEFAULT_DELTA" -f 495 95 f8e28b || [ "$maxCampaignFights" -le 0 ]; do
inputTapSleep 550 1850 .5 # Battle
waitBattleStart
doAuto
doSpeed
waitBattleFinish 10 # Wait until battle is over
# Check battle result
if [ "$battleFailed" = false ]; then # Win
if testColorOR 550 1670 e2dddc; then # Check for next stage
inputTapSleep 550 1670 6 # Next Stage
sleep 6
# WARN: Limited offers will fuck this part of the script up. I'm yet to find a way to close any possible offers.
# Tap top of the screen to close any possible Limited Offers
# inputTapSleep 550 75
if testColorOR 550 740 f2d79f; then # Check if boss
inputTapSleep 550 1450 5
fi
else
inputTapSleep 550 1670 3 # Continue to next battle
if testColorNAND -d "$DEFAULT_DELTA" -f 200 1850 2b1a12; then # For low levels, does not exists (before stage 4)
inputTapSleep 550 1650 3 # Begin
if testColorOR 550 740 f2d79f; then # Check if boss
inputTapSleep 550 1450 3 # Begin
fi
fi
fi
_challengeBoss_WIN=$((_challengeBoss_WIN + 1)) # Increment
else # Loose
inputTapSleep 550 1720 5 # Try again
if testColorNAND -d "$DEFAULT_DELTA" -f 200 1850 2b1a12; then # For low levels, does not exists (before stage 4)
inputTapSleep 550 1650 3 # Begin
if testColorOR 550 740 f2d79f; then # Check if boss
inputTapSleep 550 1450 3 # Begin
fi
fi
_challengeBoss_LOOSE=$((_challengeBoss_LOOSE + 1)) # Increment
maxCampaignFights=$((maxCampaignFights - 1)) # Dicrement
fi
done
# Return to campaign
if testColorNAND 450 1775 cc9261; then # For low levels, you are automatically kicked out (before stage 4)
inputTapSleep 60 1850 # Return
fi
testColorORTapSleep 715 1260 fefffe # Check for confirm to exit button
else
# Quick exit battle
inputTapSleep 550 1850 1 # Battle
inputTapSleep 80 1460 # Pause
inputTapSleep 230 960 1 # Exit
if testColorNAND 450 1775 cc9261; then # Check for multi-battle
inputTapSleep 70 1810
fi
fi
wait
if [ "$forceFightCampaign" = "true" ]; then
verifyHEX 450 1775 cc9261 \
"Challenged boss in campaign. $(getCountersInColor $_challengeBoss_WIN $_challengeBoss_LOOSE)" \
"Failed to fight boss in Campaign. $(getCountersInColor $_challengeBoss_WIN $_challengeBoss_LOOSE)"
else
verifyHEX 450 1775 cc9261 "Challenged boss in campaign." "Failed to fight boss in Campaign."
fi
}
# ##############################################################################
# Function Name : collectFriendsAndMercenaries
# Descripton : Collects and sends companion points, as well as auto lending mercenaries
# ##############################################################################
collectFriendsAndMercenaries() {
if [ "$DEBUG" -ge 4 ]; then printInColor "DEBUG" "collectFriendsAndMercenaries" >&2; fi
inputTapSleep 970 810 1 # Friends
inputTapSleep 930 1600 # Send & Recieve
if testColorOR -d "$DEFAULT_DELTA" 825 1750 df1909; then # Check if its necessary to send mercenaries
inputTapSleep 720 1760 # Short-Term
inputTapSleep 990 190 # Manage
inputTapSleep 630 1590 # Apply
inputTapSleep 750 1410 1 # Auto Lend
inputTapSleep 70 1810 0 # Return
else
printInColor "INFO" "No mercenaries to lend..."
fi
inputTapSleep 70 1810 0 # Return
wait
verifyHEX 450 1775 cc9261 "Sent and recieved companion points, as well as auto lending mercenaries." "Failed to collect/send companion points or failed to auto lend mercenaries."
}
# ##############################################################################
# Function Name : fastRewards
# Descripton : Collects fast rewards
# ##############################################################################
fastRewards() {
if [ "$DEBUG" -ge 4 ]; then printInColor "DEBUG" "fastRewards" >&2; fi
if testColorOR -d "$DEFAULT_DELTA" 980 1620 ef1e05; then # check red dot to see if free fast reward is avaible
inputTapSleep 950 1660 1
inputTapSleep 710 1260
inputTapSleep 560 1800 1
inputTapSleep 400 1250
else
printInColor "INFO" "Fast Rewards collected already, not collecting..."
fi
verifyHEX 450 1775 cc9261 "Fast rewards checked." "Failed to check fast rewards."
}
# ##############################################################################
# Function Name : lootAfkChest
# Descripton : Loots afk chest
# ##############################################################################
lootAfkChest() {
if [ "$DEBUG" -ge 4 ]; then printInColor "DEBUG" "lootAfkChest" >&2; fi
inputTapSleep 550 1500 1
inputTapSleep 750 1350 3
inputTapSleep 550 1850 1 # Tap campaign in case of level up
wait
verifyHEX 450 1775 cc9261 "AFK Chest looted." "Failed to loot AFK Chest."
}
# ##############################################################################
# Section : Dark Forest
# ##############################################################################
# ##############################################################################
# Function Name : arenaOfHeroes
# Descripton : Does the daily arena of heroes battles
# ##############################################################################
arenaOfHeroes() {
if [ "$DEBUG" -ge 4 ]; then printInColor "DEBUG" "arenaOfHeroes" >&2; fi
inputTapSleep 740 1050 3
if [ "$eventHoe" = false ] && [ "$eventTs" = false ]; then
inputTapSleep 550 450 3
else
inputTapSleep 550 900 3
fi
if testColorOR -d "$DEFAULT_DELTA" 1050 1770 e72707; then # Red mark? old value: e52505 (d=5), fb1e0d (d=5)
inputTapSleep 1000 1800 # Record
inputTapSleep 980 410 # Close
fi
inputTapSleep 540 1800 # Challenge
if testColorNAND 200 1800 382314 382214; then # Check for new season
_arenaOfHeroes_LOOSE=0
_arenaOfHeroes_WIN=0
printInColor "INFO" "Fighting in the Arena Of Heroes ${cCyan}$totalAmountArenaTries${cNc} time(s)."
until [ "$totalAmountArenaTries" -le 0 ]; do # Repeat a battle for as long as totalAmountArenaTries
# Refresh
# inputTapSleep 815 540
# Fight specific opponent
# Free x1
# Opponent 1: 820 700 -> acf0bd
# Opponent 2: 820 870 -> 2eaab4 aff3be
# Opponent 3: 820 1050 -> acf0bd
# Opponent 4: 820 1220 -> 2daab4 aff1b8
# Opponent 5: 820 1400 -> adf1be
case $arenaHeroesOpponent in
1)
if testColorOR -d "$DEFAULT_DELTA" 820 700 a7f1b7; then # Check if opponent exists
inputTapSleep 820 700 0 # Fight opponent
else
# Refresh opponents and try to fight opponent $arenaHeroesOpponent
arenaOfHeroes_tapClosestOpponent 1
fi
;;
2)
if testColorOR -d "$DEFAULT_DELTA" 820 870 2daab4 aff3c0; then # Check if opponent exists
inputTapSleep 820 870 0 # Fight opponent
else
arenaOfHeroes_tapClosestOpponent 2 # Try to fight the closest opponent to 2
fi
;;
3)
if testColorOR -d "$DEFAULT_DELTA" 820 1050 a7f1b7; then # Check if opponent exists
inputTapSleep 820 1050 0 # Fight opponent
else
arenaOfHeroes_tapClosestOpponent 3 # Try to fight the closest opponent to 3
fi
;;
4)
if testColorOR -d "$DEFAULT_DELTA" 820 1220 2daab4 aff3c0; then # Check if opponent exists
inputTapSleep 820 1220 0 # Fight opponent
else
arenaOfHeroes_tapClosestOpponent 4 # Try to fight the closest opponent to 4
fi
;;
5)
if testColorOR -d "$DEFAULT_DELTA" 820 1400 aaf2bb; then # Check if opponent exists
inputTapSleep 820 1400 0 # Fight opponent
else
arenaOfHeroes_tapClosestOpponent 5 # Try to fight the closest opponent to 5
fi
;;
*)
# Invalid option
echo "[WARN] Invalid arenaHeroesOpponent option in config, skipping..."
break
;;
esac
# Check if return value of tapClosesopponent is 0. If it is 0, then it means a battle has been found.
res=$?
if [ $res = 0 ]; then
wait
if testColorOR -d "$DEFAULT_DELTA" 20 1200 eaca95; then
inputTapSleep 550 1850 0 # Battle
waitBattleStart
doSkip
waitBattleFinish 2
if [ "$battleFailed" = false ]; then
inputTapSleep 550 1550 # Collect
_arenaOfHeroes_WIN=$((_arenaOfHeroes_WIN + 1)) # Increment
else
_arenaOfHeroes_LOOSE=$((_arenaOfHeroes_LOOSE + 1)) # Increment
fi
inputTapSleep 550 1550 3 # Finish battle
else
printInColor "WARN" "Failed to enter battle in the Arena of Heroes."
fi
fi
totalAmountArenaTries=$((totalAmountArenaTries - 1)) # Dicrement
done
inputTapSleep 1000 380
sleep 4
else
printInColor "INFO" "Unable to fight in the Arena of Heroes because a new season is soon launching." >&2
fi
if [ "$doLegendsTournament" = false ]; then # Return to Tab if $doLegendsTournament = false
inputTapSleep 70 1810
inputTapSleep 70 1810
verifyHEX 240 1775 d49a61 \
"Checked the Arena of Heroes out. $(getCountersInColor $_arenaOfHeroes_WIN $_arenaOfHeroes_LOOSE)" \
"Failed to check the Arena of Heroes out. $(getCountersInColor $_arenaOfHeroes_WIN $_arenaOfHeroes_LOOSE)"
else
inputTapSleep 70 1810
verifyHEX 760 70 1f2d3a \
"Checked the Arena of Heroes out. $(getCountersInColor $_arenaOfHeroes_WIN $_arenaOfHeroes_LOOSE)" \
"Failed to check the Arena of Heroes out. $(getCountersInColor $_arenaOfHeroes_WIN $_arenaOfHeroes_LOOSE)"
fi
}
# ##############################################################################
# Function Name : arenaOfHeroes_tapClosestOpponent
# Descripton : Attempts to tap the closest Arena of Heroes opponent
# Args : <OPPONENT>: 1/2/3/4/5
# Output : If failed, return 1
# ##############################################################################
arenaOfHeroes_tapClosestOpponent() {
if [ "$DEBUG" -ge 4 ]; then printInColor "DEBUG" "arenaOfHeroes_tapClosestOpponent ${cPurple}$*${cNc}" >&2; fi
# Depending on the opponent number sent as a parameter ($1), this function
# would attempt to check if there's an opponent above the one sent.
# If there isn't, check the one above that one and so on until one is found.
# When found, tap on the opponent and exit function.
case $1 in
1)
# Refresh
inputTapSleep 815 540
# Attempt to fight $arenaHeroesOpponent opponent, and if not present, skip battle
case $arenaHeroesOpponent in
1)
# Check if opponent 1 exists and fight if true
if testColorOR -d "$DEFAULT_DELTA" 820 700 a7f1b7; then inputTapSleep 820 700 0; else return 1; fi
;;
2)
# Check if opponent 2 exists and fight if true
if testColorOR -d "$DEFAULT_DELTA" 820 870 2daab4 aff3c0; then inputTapSleep 820 870 0; else return 1; fi
;;
3)
# Check if opponent 3 exists and fight if true
if testColorOR -d "$DEFAULT_DELTA" 820 1050 a7f1b7; then inputTapSleep 820 1050 0; else return 1; fi
;;
4)
# Check if opponent 4 exists and fight if true
if testColorOR -d "$DEFAULT_DELTA" 820 1220 2daab4 aff3c0; then inputTapSleep 820 1220 0; else return 1; fi
;;
5)
# Check if opponent 5 exists and fight if true
if testColorOR -d "$DEFAULT_DELTA" 820 1400 aaf2bb; then inputTapSleep 820 1400 0; else return 1; fi
;;
esac
;;
2)
if testColorOR -d "$DEFAULT_DELTA" 820 700 a7f1b7; then # Check if opponent 1 exists
inputTapSleep 820 700 0 # Fight opponent
else
arenaOfHeroes_tapClosestOpponent 1 # Try to fight the closest opponent to 2
fi
;;
3)
if testColorOR -d "$DEFAULT_DELTA" 820 870 2daab4 aff3c0; then # Check if opponent 2 exists
inputTapSleep 820 870 0 # Fight opponent
else
arenaOfHeroes_tapClosestOpponent 2 # Try to fight the closest opponent to 3
fi
;;
4)
if testColorOR -d "$DEFAULT_DELTA" 820 1050 a7f1b7; then # Check if opponent 3 exists
inputTapSleep 820 1050 0 # Fight opponent
else
arenaOfHeroes_tapClosestOpponent 3 # Try to fight the closest opponent to 4
fi
;;
5)
if testColorOR -d "$DEFAULT_DELTA" 820 1220 2daab4 aff3c0; then # Check if opponent 4 exists
inputTapSleep 820 1220 0 # Fight opponent
else
arenaOfHeroes_tapClosestOpponent 4 # Try to fight the closest opponent to 5
fi
;;
esac
}
# ##############################################################################
# Function Name : kingsTower
# Descripton : Try to battle in every Kings Tower
# ##############################################################################
kingsTower() {
if [ "$DEBUG" -ge 4 ]; then printInColor "DEBUG" "kingsTower" >&2; fi
inputTapSleep 500 870 5 # King's Tower
printInColor "INFO" "Fighting King's Tower until ${cCyan}$maxKingsTowerFights${cNc} defeat(s)."
if testColorOR 550 150 1a1212; then
# King's Tower without Towers of Esperia unlocked (between stage 2-12 and 15-1)
if [ "$doMainTower" = true ]; then
printInColor "DONE" "Main Tower $(kingsTower_battle -1 -1)" # Main Tower
fi
else
# King's Tower with Towers of Esperia unlocked (after stage 15-1)