-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathPyAutoRaid.py
More file actions
1337 lines (1227 loc) · 60.7 KB
/
Copy pathPyAutoRaid.py
File metadata and controls
1337 lines (1227 loc) · 60.7 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
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
import pyautogui
import platform
import tkinter
import logging
import os
import sys
import subprocess
import time
import configparser
import pygetwindow
import datetime
import threading
from screeninfo import get_monitors
from tkinter import messagebox
from tkinter import scrolledtext
from tkinter import ttk
from tkinter import *
from ttkthemes import ThemedTk
import pyscreeze
from faction_wars.FactionWars import FactionWarsCommand
from dungeons.IronTwins import IronTwinsCommand
from doom_tower.DoomTower import DoomTowerCommand
pyscreeze.USE_IMAGE_NOT_FOUND_EXCEPTION = False
# Configure logging
logging.basicConfig(
filename='PyAutoRaid.log',
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
filemode='w',
level=logging.DEBUG
)
logger = logging.getLogger(__name__)
# Base Command class
class Command:
def execute(self):
pass
# Command classes for each task
class DailyGemMineCommand(Command):
def __init__(self, app):
self.app = app
def execute(self):
try:
logger.info("Starting Daily Gem Mine task.")
# Gem Mine
pyautogui.click(583, 595)
time.sleep(2)
pyautogui.hotkey("esc") # Escape gem mine
time.sleep(2)
self.app.steps["Gem_mine"] = "True"
self.app.delete_popup()
logger.info("Completed Daily Gem Mine task.")
except Exception as e:
logger.error(f"Error in DailyGemMineCommand: {e}")
self.app.back_to_bastion()
self.app.delete_popup()
class DailyMarketPurchaseCommand(Command):
def __init__(self, app):
self.app = app
self.AS_bought = 0
self.MS_bought = 0
def execute(self):
try:
logger.info("Starting Daily Market Purchase task.")
self.app.delete_popup()
time.sleep(5)
market_image = os.path.join(self.app.asset_path, "theMarket.png")
if pyautogui.locateOnScreen(market_image, confidence=0.8):
theMarketx, theMarkety = pyautogui.locateCenterOnScreen(
market_image, confidence=0.8
)
pyautogui.click(theMarketx, theMarkety)
time.sleep(2)
shop_shard_image = os.path.join(self.app.asset_path, "shopShard.png")
get_shard_image = os.path.join(self.app.asset_path, "getShard.png")
market_AS_image = os.path.join(self.app.asset_path, "marketAS.png")
get_AS_image = os.path.join(self.app.asset_path, "getAS.png")
# Purchase Mystery Shards
while pyautogui.locateOnScreen(shop_shard_image, confidence=0.8):
shopShardx, shopShardy = pyautogui.locateCenterOnScreen(
shop_shard_image, confidence=0.8
)
pyautogui.click(shopShardx, shopShardy)
time.sleep(2)
self.app.steps["Market"] = "Opened"
self.app.steps["Market_purchases"] = "None"
while pyautogui.locateOnScreen(get_shard_image, confidence=0.8):
getShardx, getShardy = pyautogui.locateCenterOnScreen(
get_shard_image, confidence=0.8
)
pyautogui.click(getShardx, getShardy, duration=2)
self.MS_bought += 1
logger.info(f"Purchased a Mystery Shard. Total purchased: {self.MS_bought}")
time.sleep(1)
time.sleep(2)
# Purchase Ancient Shards
while pyautogui.locateOnScreen(market_AS_image, confidence=0.8):
marketASx, marketASy = pyautogui.locateCenterOnScreen(
market_AS_image, confidence=0.8
)
pyautogui.click(marketASx, marketASy)
time.sleep(2)
while pyautogui.locateOnScreen(get_AS_image, confidence=0.8):
getASx, getASy = pyautogui.locateCenterOnScreen(
get_AS_image, confidence=0.8
)
pyautogui.click(getASx, getASy)
self.AS_bought += 1
logger.info(f"Purchased an Ancient Shard. Total purchased: {self.AS_bought}")
time.sleep(1)
time.sleep(2)
self.app.steps[
"Market_purchases"
] = f"{self.MS_bought} mystery shards purchased, and {self.AS_bought} ancient shards purchased"
self.app.back_to_bastion()
self.app.delete_popup()
logger.info("Completed Daily Market Purchase task.")
else:
logger.warning("Market button not found on screen.")
except Exception as e:
logger.error(f"Error in DailyMarketPurchaseCommand: {e}")
self.app.back_to_bastion()
self.app.delete_popup()
class DailyShopCommand(Command):
def __init__(self, app):
self.app = app
def execute(self):
try:
logger.info("Starting Daily Shop task.")
self.app.steps["Shop_claimed"] = []
shop_btn_image = os.path.join(self.app.asset_path, "shopBTN.png")
claim_AS_image = os.path.join(self.app.asset_path, "claimAS.png")
default_claim_image = os.path.join(self.app.asset_path, "defaultClaim.png")
claim_MS_image = os.path.join(self.app.asset_path, "claimMS.png")
offers_image = os.path.join(self.app.asset_path, "offers.png")
claim_free_gift_image = os.path.join(self.app.asset_path, "claimFreeGift.png")
if pyautogui.locateOnScreen(shop_btn_image, confidence=0.8):
shopBTNx, shopBTNy = pyautogui.locateCenterOnScreen(
shop_btn_image, confidence=0.8
)
pyautogui.click(shopBTNx, shopBTNy)
time.sleep(2)
# Claim Ancient Shard
while pyautogui.locateOnScreen(claim_AS_image, confidence=0.8):
claimASx, claimASy = pyautogui.locateCenterOnScreen(
claim_AS_image, confidence=0.8
)
pyautogui.click(claimASx, claimASy)
time.sleep(2)
while pyautogui.locateOnScreen(default_claim_image, confidence=0.8):
defaultClaimx, defaultClaimy = pyautogui.locateCenterOnScreen(
default_claim_image, confidence=0.8
)
pyautogui.click(defaultClaimx, defaultClaimy)
self.app.steps["Shop_claimed"].append("Ancient Shard")
logger.info("Claimed Ancient Shard from shop.")
time.sleep(3)
# Claim Mystery Shard
while pyautogui.locateOnScreen(claim_MS_image, confidence=0.8):
claimMSx, claimMSy = pyautogui.locateCenterOnScreen(
claim_MS_image, confidence=0.8
)
pyautogui.click(claimMSx, claimMSy)
time.sleep(5)
while pyautogui.locateOnScreen(default_claim_image, confidence=0.8):
defaultClaimx, defaultClaimy = pyautogui.locateCenterOnScreen(
default_claim_image, confidence=0.8
)
pyautogui.click(defaultClaimx, defaultClaimy)
self.app.steps["Shop_claimed"].append("Mystery Shard")
logger.info("Claimed Mystery Shard from shop.")
time.sleep(3)
# Claim Free Gifts from offers
while pyautogui.locateOnScreen(offers_image, confidence=0.9):
offersx, offersy = pyautogui.locateCenterOnScreen(
offers_image, confidence=0.8
)
pyautogui.click(offersx, offersy)
time.sleep(3)
# Click through all offers
for i in range(724, 1400, 50):
pyautogui.click(i, 333)
if pyautogui.locateOnScreen(claim_free_gift_image, confidence=0.8):
freegiftx, freegifty = pyautogui.locateCenterOnScreen(
claim_free_gift_image, confidence=0.8
)
pyautogui.click(freegiftx, freegifty)
self.app.steps["Shop_claimed"].append("Free Gift")
logger.info("Claimed Free Gift from offers.")
time.sleep(1)
time.sleep(1.5)
self.app.back_to_bastion()
self.app.delete_popup()
logger.info("Completed Daily Shop task.")
else:
logger.warning("Shop button not found on screen.")
except Exception as e:
logger.error(f"Error in DailyShopCommand: {e}")
self.app.back_to_bastion()
self.app.delete_popup()
class DailyGuardianRingCommand(Command):
def __init__(self, app):
self.app = app
self.GR_upgrades = 0
def execute(self):
try:
logger.info("Starting Daily Guardian Ring task.")
guardian_ring_image = os.path.join(self.app.asset_path, "guardianRing.png")
GR_upgrade_image = os.path.join(self.app.asset_path, "GRupgrade.png")
if pyautogui.locateOnScreen(guardian_ring_image, confidence=0.8):
guardianRingx, guardianRingy = pyautogui.locateCenterOnScreen(
guardian_ring_image, confidence=0.8
)
pyautogui.click(guardianRingx, guardianRingy)
time.sleep(4)
while pyautogui.locateOnScreen(GR_upgrade_image, confidence=0.8):
GRupgradex, GRupgradey = pyautogui.locateCenterOnScreen(
GR_upgrade_image, confidence=0.8
)
pyautogui.click(GRupgradex, GRupgradey)
self.GR_upgrades += 1
logger.info(f"Performed Guardian Ring upgrade. Total upgrades: {self.GR_upgrades}")
time.sleep(2)
self.app.steps["GR_upgrades"] = self.GR_upgrades
self.app.back_to_bastion()
self.app.delete_popup()
logger.info("Completed Daily Guardian Ring task.")
else:
logger.warning("Guardian Ring button not found on screen.")
except Exception as e:
logger.error(f"Error in DailyGuardianRingCommand: {e}")
self.app.back_to_bastion()
self.app.delete_popup()
class DailyTimedRewardsCommand(Command):
def __init__(self, app):
self.app = app
def execute(self):
try:
logger.info("Starting Daily Timed Rewards task.")
time_rewards_image = os.path.join(self.app.asset_path, "timeRewards.png")
red_dot_image = os.path.join(self.app.asset_path, "redNotificationDot.png")
if pyautogui.locateOnScreen(time_rewards_image, confidence=0.8):
timeRewardsx, timeRewardsy = pyautogui.locateCenterOnScreen(
time_rewards_image, confidence=0.8
)
pyautogui.click(timeRewardsx, timeRewardsy)
time.sleep(2)
while pyautogui.locateOnScreen(red_dot_image, confidence=0.8):
redx, redy = pyautogui.locateCenterOnScreen(
red_dot_image, confidence=0.8
)
pyautogui.click(redx, redy)
time.sleep(1)
for i in range(669, 1269, 100):
time.sleep(0.2)
pyautogui.click(i, 500)
time.sleep(1)
pyautogui.click(1269, 500)
pyautogui.click(1269, 500)
self.app.steps["Timed_rewards"] = "Collected"
self.app.back_to_bastion()
self.app.delete_popup()
logger.info("Completed Daily Timed Rewards task.")
else:
logger.warning("Timed Rewards button not found on screen.")
self.app.steps["7_campaign_battles"] = "Not Collected"
except Exception as e:
logger.error(f"Error in DailyTimedRewardsCommand: {e}")
self.app.back_to_bastion()
self.app.delete_popup()
class DailyClanCommand(Command):
def __init__(self, app):
self.app = app
def execute(self):
try:
logger.info("Starting Daily Clan task.")
clan_btn_image = os.path.join(self.app.asset_path, "clanBTN.png")
clan_members_image = os.path.join(self.app.asset_path, "clanMembers.png")
clan_check_in_image = os.path.join(self.app.asset_path, "clanCheckIn.png")
clan_treasure_image = os.path.join(self.app.asset_path, "clanTreasure.png")
red_dot_image = os.path.join(self.app.asset_path, "redNotificationDot.png")
if pyautogui.locateOnScreen(clan_btn_image, confidence=0.8):
clanBTNx, clanBTNy = pyautogui.locateCenterOnScreen(
clan_btn_image, confidence=0.8
)
pyautogui.click(clanBTNx, clanBTNy)
time.sleep(1)
if pyautogui.locateOnScreen(clan_members_image, confidence=0.8):
clanMembersx, clanMembersy = pyautogui.locateCenterOnScreen(
clan_members_image, confidence=0.8
)
pyautogui.click(clanMembersx, clanMembersy)
time.sleep(2)
while pyautogui.locateOnScreen(clan_check_in_image, confidence=0.8):
clanCheckInx, clanCheckIny = pyautogui.locateCenterOnScreen(
clan_check_in_image, confidence=0.8
)
pyautogui.click(clanCheckInx, clanCheckIny)
time.sleep(1)
if pyautogui.locateOnScreen(clan_treasure_image, confidence=0.8):
clanTreasurex, clanTreasurey = pyautogui.locateCenterOnScreen(
clan_treasure_image, confidence=0.8
)
pyautogui.click(clanTreasurex, clanTreasurey)
time.sleep(1)
if pyautogui.locateAllOnScreen(red_dot_image, confidence=0.8):
for dotsx, doty, z, c in pyautogui.locateAllOnScreen(
red_dot_image, confidence=0.8
):
pyautogui.click(dotsx, doty + 10)
time.sleep(3)
self.app.steps["Daily_clan"] = "Accessed"
self.app.back_to_bastion()
logger.info("Completed Daily Clan task.")
else:
logger.warning("Clan button not found on screen.")
except Exception as e:
logger.error(f"Error in DailyClanCommand: {e}")
self.app.back_to_bastion()
self.app.delete_popup()
class DailyQuestClaimsCommand(Command):
def __init__(self, app):
self.app = app
self.quests_completed = 0
def execute(self):
try:
logger.info("Starting Daily Quest Claims task.")
quests_image = os.path.join(self.app.asset_path, "quests.png")
quest_claim_image = os.path.join(self.app.asset_path, "questClaim.png")
advanced_quests_image = os.path.join(self.app.asset_path, "advancedQuests.png")
if pyautogui.locateOnScreen(quests_image, confidence=0.8):
questsx, questsy = pyautogui.locateCenterOnScreen(
quests_image, confidence=0.8
)
pyautogui.click(questsx, questsy)
time.sleep(2)
while pyautogui.locateOnScreen(quest_claim_image, confidence=0.8):
questClaimx, questClaimy = pyautogui.locateCenterOnScreen(
quest_claim_image, confidence=0.8
)
pyautogui.click(questClaimx, questClaimy)
self.quests_completed += 1
logger.info(f"Claimed a quest reward. Total claimed: {self.quests_completed}")
time.sleep(1)
if pyautogui.locateOnScreen(advanced_quests_image, confidence=0.8):
advancedQuestsx, advancedQuestsy = pyautogui.locateCenterOnScreen(
advanced_quests_image, confidence=0.8
)
pyautogui.click(advancedQuestsx, advancedQuestsy)
time.sleep(1)
if pyautogui.locateOnScreen(quest_claim_image, confidence=0.9):
questClaimx, questClaimy = pyautogui.locateCenterOnScreen(
quest_claim_image, confidence=0.8
)
pyautogui.click(questClaimx, questClaimy)
self.quests_completed += 1
logger.info(f"Claimed an advanced quest reward. Total claimed: {self.quests_completed}")
time.sleep(1)
self.app.steps["Quests_completed"] = self.quests_completed
self.app.back_to_bastion()
self.app.delete_popup()
logger.info("Completed Daily Quest Claims task.")
else:
logger.warning("Quests button not found on screen.")
self.app.steps["Quests_Completed"] = "Not Accessed"
except Exception as e:
logger.error(f"Error in DailyQuestClaimsCommand: {e}")
self.app.back_to_bastion()
self.app.delete_popup()
class DailyInboxCommand(Command):
def __init__(self, app):
self.app = app
def execute(self):
try:
logger.info("Starting Daily Inbox task.")
time.sleep(1)
pyautogui.hotkey("i")
inbox_items = [
"inbox_energy",
"inbox_brew",
"inbox_purple_forge",
"inbox_yellow_forge",
"inbox_coin",
"inbox_potion",
]
for i in inbox_items:
png = os.path.join(self.app.asset_path, f"{i}.png")
time.sleep(0.3)
while pyautogui.locateOnScreen(png, confidence=0.8):
energy = pyautogui.locateOnScreen(png, confidence=0.8)
pyautogui.moveTo(energy)
pyautogui.moveRel(250, 0)
pyautogui.click()
time.sleep(2)
logger.info(f"Collected inbox item: {i}")
self.app.steps["daily_inbox"] = "Accessed"
self.app.back_to_bastion()
self.app.delete_popup()
logger.info("Completed Daily Inbox task.")
except Exception as e:
logger.error(f"Error in DailyInboxCommand: {e}")
self.app.back_to_bastion()
self.app.delete_popup()
class RewardsCommand(Command):
def __init__(self, app):
self.app = app
def execute(self):
logger.info("Starting Rewards tasks.")
commands = [
DailyGemMineCommand(self.app),
DailyMarketPurchaseCommand(self.app),
DailyShopCommand(self.app),
DailyGuardianRingCommand(self.app),
DailyTimedRewardsCommand(self.app),
DailyClanCommand(self.app),
DailyQuestClaimsCommand(self.app),
DailyInboxCommand(self.app),
]
for command in commands:
command.execute()
logger.info("Completed Rewards tasks.")
class DailyTenClassicArenaCommand(Command):
def __init__(self, app):
self.app = app
self.classic_battles = 0
def execute(self):
try:
logger.info("Starting Daily Ten Classic Arena task.")
self.app.delete_popup()
battle_btn_image = os.path.join(self.app.asset_path, "battleBTN.png")
arena_tab_image = os.path.join(self.app.asset_path, "arenaTab.png")
classic_arena_image = os.path.join(self.app.asset_path, "classicArena.png")
arena_refresh_image = os.path.join(self.app.asset_path, "arenaRefresh.png")
arena_battle_image = os.path.join(self.app.asset_path, "arenaBattle.png")
arena_confirm_image = os.path.join(self.app.asset_path, "arenaConfirm.png")
classic_arena_refill_image = os.path.join(self.app.asset_path, "classicArenaRefill.png")
arena_start_image = os.path.join(self.app.asset_path, "arenaStart.png")
tap_to_continue_image = os.path.join(self.app.asset_path, "tapToContinue.png")
while pyautogui.locateOnScreen(battle_btn_image, confidence=0.8):
battlex, battley = pyautogui.locateCenterOnScreen(
battle_btn_image, confidence=0.9
)
pyautogui.click(battlex, battley)
time.sleep(2)
while pyautogui.locateOnScreen(arena_tab_image, confidence=0.8):
battlex, battley = pyautogui.locateCenterOnScreen(
arena_tab_image, confidence=0.9
)
pyautogui.click(battlex, battley)
time.sleep(2)
while pyautogui.locateOnScreen(classic_arena_image, confidence=0.8):
battlex, battley = pyautogui.locateCenterOnScreen(
classic_arena_image, confidence=0.9
)
pyautogui.click(battlex, battley)
time.sleep(2)
regions = [
[1215, 423, 167, 58, [1304, 457]],
[1215, 508, 167, 58, [1304, 540]],
[1215, 596, 167, 58, [1303, 625]],
[1215, 681, 167, 58, [1304, 711]],
[1208, 762, 190, 68, [1304, 800]],
]
for j in range(0, 2):
while pyautogui.locateOnScreen(arena_refresh_image, confidence=0.8):
battlex, battley = pyautogui.locateCenterOnScreen(
arena_refresh_image, confidence=0.9
)
pyautogui.click(battlex, battley)
time.sleep(2)
for i in regions:
if pyautogui.locateOnScreen(
arena_battle_image,
region=(i[0], i[1], i[2], i[3]),
confidence=0.6,
):
pyautogui.click(i[4][0], i[4][1])
time.sleep(3)
# Replenish tokens or quit if out of them
while pyautogui.locateOnScreen(arena_confirm_image, confidence=0.8):
battlex, battley = pyautogui.locateCenterOnScreen(
arena_confirm_image, confidence=0.9
)
pyautogui.click(battlex, battley)
logger.info("Confirmed arena tokens.")
time.sleep(5)
pyautogui.click(i[4][0], i[4][1])
if pyautogui.locateOnScreen(classic_arena_refill_image, confidence=0.8):
self.app.steps["Classic_Arena"] = "Ran out of coins"
self.app.steps[
"classic_arena_battles"
] = f"{self.classic_battles} total classic arena battles fought"
self.app.back_to_bastion()
self.app.delete_popup()
logger.info("Ran out of arena coins. Exiting task.")
return
time.sleep(4)
if pyautogui.locateOnScreen(arena_start_image, confidence=0.8):
battlex, battley = pyautogui.locateCenterOnScreen(
arena_start_image, confidence=0.9
)
pyautogui.click(battlex, battley)
# First battle
logger.debug("Waiting for 'Tap to Continue' screen.")
while not pyautogui.locateOnScreen(tap_to_continue_image, confidence=0.8):
time.sleep(1)
while pyautogui.locateOnScreen(tap_to_continue_image, confidence=0.8):
time.sleep(1)
goBackx, goBacky = pyautogui.locateCenterOnScreen(
tap_to_continue_image, confidence=0.8
)
pyautogui.click(goBackx, goBacky)
self.classic_battles += 1
logger.info(f"Completed an arena battle. Total battles: {self.classic_battles}")
time.sleep(1)
pyautogui.click(goBackx, goBacky)
time.sleep(3)
if j == 1:
pyautogui.doubleClick(969, 788, interval=1)
pyautogui.dragRel(0, -381, duration=2)
time.sleep(3)
time.sleep(1)
pyautogui.doubleClick(969, 788, interval=1)
time.sleep(1)
if j == 0:
pyautogui.doubleClick(969, 788, interval=1)
pyautogui.dragRel(0, -380, duration=2)
time.sleep(3)
time.sleep(3)
self.app.steps[
"classic_arena_battles"
] = f"{self.classic_battles} total classic arena battles fought"
self.app.back_to_bastion()
self.app.delete_popup()
logger.info(f"{self.classic_battles} total classic arena battles fought")
logger.info("Completed Daily Ten Classic Arena task.")
except Exception as e:
logger.error(f"Error in DailyTenClassicArenaCommand: {e}")
class ClanBossCommand(Command):
def __init__(self, app):
self.app = app
def execute(self):
try:
logger.info("Starting Clan Boss task.")
CBDIFFICULTYS = [
"ultra-nightmare",
"nightmare",
"brutal",
"hard",
"normal",
"easy",
]
time.sleep(1.5)
logger.debug(f"self.app is an instance of {type(self.app)}")
self.app.delete_popup()
# Construct image paths
battle_btn_image = os.path.join(self.app.asset_path, "battleBTN.png")
demon_lord2_image = os.path.join(self.app.asset_path, "demonLord2.png")
CB_card_image = os.path.join(self.app.asset_path, "CB.png")
CB_reward_image = os.path.join(self.app.asset_path, "CBreward.png")
nightmare_claimed_image = os.path.join(self.app.asset_path, "nightmareClaimed.png")
CB_claim_image = os.path.join(self.app.asset_path, "CBclaim.png")
CB_hard_image = os.path.join(self.app.asset_path, "CBhard.png")
CB_battle_image = os.path.join(self.app.asset_path, "CBbattle.png")
CB_no_key_image = os.path.join(self.app.asset_path, "CBnokey.png")
CB_start_image = os.path.join(self.app.asset_path, "CBstart.png")
# CB_continue_image = os.path.join(self.app.asset_path, "CBcontinue.png")
goto_bastion_image = os.path.join(self.app.asset_path, "gotoBastion.png")
# Navigate to battle screen
while pyautogui.locateOnScreen(battle_btn_image, confidence=0.8):
battlex, battley = pyautogui.locateCenterOnScreen(
battle_btn_image, confidence=0.8
)
pyautogui.click(battlex, battley)
time.sleep(2)
while pyautogui.locateOnScreen(CB_card_image, confidence=0.8):
battlex, battley = pyautogui.locateCenterOnScreen(
CB_card_image, confidence=0.8
)
pyautogui.click(battlex, battley)
time.sleep(2)
# Navigate to demon lord
while pyautogui.locateOnScreen(demon_lord2_image, confidence=0.8):
demonLord2x, demonLord2y = pyautogui.locateCenterOnScreen(
demon_lord2_image, confidence=0.8
)
pyautogui.click(demonLord2x, demonLord2y)
time.sleep(4)
# Scroll and collect rewards
pyautogui.click(1080, 724)
pyautogui.drag(0, -200, duration=1)
while pyautogui.locateOnScreen(CB_reward_image, confidence=0.8):
for CBreward in pyautogui.locateAllOnScreen(CB_reward_image, confidence=0.8):
CBrewardx, CBrewardy = pyautogui.center(CBreward)
pyautogui.click(CBrewardx, CBrewardy)
time.sleep(2)
for ClaimButton in pyautogui.locateAllOnScreen(CB_claim_image, confidence=0.8):
Claimx, Claimy = pyautogui.center(ClaimButton)
pyautogui.click(Claimx, Claimy)
time.sleep(3)
pyautogui.click(Claimx, Claimy)
# Collect claimed rewards
while pyautogui.locateOnScreen(nightmare_claimed_image, confidence=0.8):
nightmareClaimedx, nightmareClaimedy = pyautogui.locateCenterOnScreen(
CB_claim_image, confidence=0.8
)
pyautogui.click(nightmareClaimedx, nightmareClaimedy)
time.sleep(1)
pyautogui.click()
time.sleep(1)
pyautogui.click()
logger.info("Collected claimed reward.")
while pyautogui.locateOnScreen(CB_claim_image, confidence=0.8):
CBclaimx, CBclaimy = pyautogui.locateCenterOnScreen(
CB_claim_image, confidence=0.8
)
pyautogui.click(CBclaimx, CBclaimy)
time.sleep(1)
pyautogui.click()
logger.info("Collected Clan Boss claim.")
time.sleep(2)
pyautogui.click(1080, 724)
pyautogui.drag(0, +200, duration=1)
time.sleep(1)
# Begin fighting clan boss
while pyautogui.locateOnScreen(CB_hard_image, confidence=0.8):
yCB = 690
xCB = 1080
difficulty = ''
for diff in CBDIFFICULTYS:
ac = int(self.app.config["ActualClanBossFightsToday"][diff])
plan = int(self.app.config["PlannedClanBossFightsToday"][diff])
if ac < plan:
yCB = int(self.app.config["XYclanbossCoordinates"][diff + 'Y'])
xCB = int(self.app.config["XYclanbossCoordinates"][diff + 'X'])
difficulty = diff
break
if yCB == 690:
pyautogui.click(1080, 724)
pyautogui.drag(0, -200, duration=1)
pyautogui.click(1080, 690)
if difficulty == '':
logger.info("No Clan Boss fights planned or available.")
break
logger.info(f"Preparing to fight Clan Boss at difficulty: {difficulty}")
pyautogui.click(xCB, yCB)
while pyautogui.locateOnScreen(CB_battle_image, confidence=0.8):
CBbattlex, CBbattley = pyautogui.locateCenterOnScreen(
CB_battle_image, confidence=0.8
)
time.sleep(2)
pyautogui.click(CBbattlex, CBbattley)
time.sleep(1)
if pyautogui.locateOnScreen(CB_no_key_image, confidence=0.8):
logger.warning("No keys available for Clan Boss battle.")
break
time.sleep(1)
time.sleep(5)
if pyautogui.locateOnScreen(CB_start_image, confidence=0.8):
CBstartx, CBstarty = pyautogui.locateCenterOnScreen(
CB_start_image, confidence=0.8
)
time.sleep(2)
pyautogui.click(CBstartx, CBstarty)
logger.info("Started Clan Boss battle.")
time.sleep(1)
# Wait for battle to finish
# battle_in_progress = True
# while battle_in_progress:
# if pyautogui.locateOnScreen(CB_continue_image, confidence=0.8):
# CBcontinuex, CBcontinuey = pyautogui.locateCenterOnScreen(
# CB_continue_image, confidence=0.8
# )
# pyautogui.click(CBcontinuex, CBcontinuey)
# logger.info("Clan Boss battle finished.")
# battle_in_progress = False
# else:
# time.sleep(10) # Wait before checking again
# Return to Bastion
while not pyautogui.locateOnScreen(goto_bastion_image, confidence=0.8):
time.sleep(1)
gotoBastionx, gotoBastiony = pyautogui.locateCenterOnScreen(
goto_bastion_image, confidence=0.8
)
pyautogui.click(gotoBastionx, gotoBastiony)
time.sleep(1)
logger.info("Returned to Bastion.")
# Update config with new fight count
new_actual = int(self.app.config['ActualClanBossFightsToday'][difficulty]) + 1
self.app.config['ActualClanBossFightsToday'][difficulty] = str(new_actual)
with open('PARconfig.ini', 'w') as configfile:
self.app.config.write(configfile)
logger.info(f"Updated Clan Boss fights for {difficulty}: {new_actual}")
self.app.delete_popup()
self.app.back_to_bastion()
self.app.delete_popup()
return f"{difficulty.capitalize()} Clan Boss fought"
else:
logger.warning("No Clan Boss battle available to start.")
self.app.back_to_bastion()
return "No Clan Boss battle started."
except Exception as e:
logger.error(f"Error in ClanBossCommand: {e}", exc_info=True)
self.app.back_to_bastion()
self.app.delete_popup()
# Main Daily class
class Daily:
def __init__(self, master):
self.running = True
self.master = master
logging.basicConfig(filename='Logging.log', format='%(levelname)s:%(message)s', encoding='utf-8', level=logging.DEBUG)
with open('Logging.log', 'w'):
pass
self.steps = {}
self.resetCBDay()
self.OS = self.Check_os()
self.raidLoc = self.find_raid_path()
self.asset_path = self.get_asset_path()
self.folders_for_exe()
if len(pygetwindow.getWindowsWithTitle("Raid: Shadow Legends")) < 1:
self.open_raid()
else:
self.initiate_raid(False)
os.system("taskkill /f /im PlariumPlay.exe")
self.width = 0
self.height = 0
self.classic_battles = 0
self.GR_upgrades = 0
self.quests_completed = 0
self.AS_bought = 0
self.MS_bought = 0
self.manual_run_triggered = False
self.command_registry = {
'rewards': RewardsCommand(self),
'daily_ten_classic_arena': DailyTenClassicArenaCommand(self),
'clanboss': ClanBossCommand(self),
'faction_wars': FactionWarsCommand(self, logger),
'iron_twins': IronTwinsCommand(self, logger),
'doom_tower': DoomTowerCommand(self, logger)
# Add other commands as needed
}
# Initialization methods with error handling and logging
def resetCBDay(self):
try:
self.config = configparser.ConfigParser()
self.utc_now = datetime.datetime.now(datetime.timezone.utc)
self.check_previous_days()
logger.info("Reset CB Day successfully.")
except Exception as e:
logger.error(f"Error in resetCBDay: {e}")
def check_previous_days(self):
try:
today_date_str = self.utc_now.strftime("%d/%m/%Y")
self.config_file(today_date_str)
self.settings_config = dict(self.config.items("Settings"))
self.config.read('PARconfig.ini')
configdate = self.config.get('Settings', 'UTC_today')
days_to_check = 60 # Example: Check up to 60 days in the past
for day in range(1, days_to_check + 1):
past_date = self.utc_now - datetime.timedelta(days=day)
past_date_str = past_date.strftime("%d/%m/%Y")
if past_date_str == configdate and self.utc_now.hour >= 10:
self.config_file(today_date_str, True)
logger.info("Previous day config adjusted.")
return True
except Exception as e:
logger.error(f"Error in check_previous_days: {e}")
def config_file(self, day, adjust=False):
try:
if os.path.exists("PARconfig.ini"):
self.config.read('PARconfig.ini')
else:
self.config['Settings'] = {'UTC_today': day, 'rewards': True, 'clanboss': True, 'automated_mode': True, 'daily_ten_classic_arena': True}
self.config['PlannedClanBossFightsToday'] = {'Easy': 0, 'Normal': 0, 'Hard': 0, 'Brutal': 0, 'Nightmare': 1, 'Ultra-Nightmare': 3}
self.config['ActualClanBossFightsToday'] = {'Easy': 0, 'Normal': 0, 'Hard': 0, 'Brutal': 0, 'Nightmare': 0, 'Ultra-Nightmare': 0}
self.config['XYclanbossCoordinates'] = {'EasyX': 1080, 'EasyY': 'IDK Coords yet', 'NormalX': 1080, 'NormalY': 'IDK Coords yet', 'HardX': 1080, 'HardY': 'IDK Coords yet', 'BrutalX': 1080, 'BrutalY': 647, 'NightmareX': 1080, 'NightmareY': 724, 'Ultra-NightmareX': 1080, 'Ultra-NightmareY': 690}
with open('PARconfig.ini', 'w') as configfile:
self.config.write(configfile)
if adjust:
self.config['Settings'] = {'UTC_today': day, 'rewards': self.settings_config['rewards'], 'clanboss': self.settings_config['clanboss'], 'automated_mode': self.settings_config['automated_mode'], 'daily_ten_classic_arena': self.settings_config['daily_ten_classic_arena']}
self.config['ActualClanBossFightsToday'] = {'Easy': 0, 'Normal': 0, 'Hard': 0, 'Brutal': 0, 'Nightmare': 0, 'Ultra-Nightmare': 0}
with open('PARconfig.ini', 'w') as configfile:
self.config.write(configfile)
logger.info("Configuration file set up successfully.")
except Exception as e:
logger.error(f"Error in config_file: {e}")
def trigger_manual_run(self, TF):
self.manual_run_triggered = TF
logger.info(f"Manual run triggered: {TF}")
def folders_for_exe(self):
try:
if getattr(sys, 'frozen', False):
# The application is frozen
self.asset_path = os.path.join(sys._MEIPASS, 'assets')
self.steps["Exe_path"] = "True"
return True
else:
self.steps["Exe_path"] = "False"
return False
except Exception as e:
logger.error(f"Error in folders_for_exe: {e}")
def Check_os(self):
try:
operating_system = platform.system()
if operating_system == "Windows":
self.steps["OS"] = "True"
return operating_system
else:
tkinter.messagebox.showerror(
"Error",
"Unrecognized operating system (WINDOWS ONLY)",
)
logging.error("Identified this computer as something other than Windows operating system. This program only works with Windows.")
sys.exit(1)
except Exception as e:
logger.error(f"Error in Check_os: {e}")
def find_raid_path(self):
try:
logger.info("Starting focused search for Raid.exe...")
appdata_local = os.path.join(os.environ['LOCALAPPDATA'])
raid_feature = "Raid.exe"
# Most specific likely path
current_path = os.path.join(appdata_local, "PlariumPlay", "StandAloneApps", "raid-shadow-legends")
# Step 1: Check if the likely path exists; move backward if it doesn't
while not os.path.exists(current_path) and current_path != appdata_local:
logger.debug(f"Path not found: {current_path}. Moving to parent directory.")
current_path = os.path.dirname(current_path)
if not os.path.exists(current_path):
logger.error("No valid path found starting from likely paths.")
self.steps["Raid_path"] = "False"
sys.exit(1)
logger.debug(f"Valid path found: {current_path}. Starting recursive search here.")
# Step 2: Perform a recursive search starting from the valid path
for root, dirs, files in os.walk(current_path, topdown=True):
# Check for the target file
if raid_feature in files:
raidloc = os.path.join(root, raid_feature)
logger.debug(f"Found Raid.exe at {raidloc}")
self.steps["Raid_path"] = "True"
return raidloc
# Step 3: If not found, log an error
self.steps["Raid_path"] = "False"
logger.error("Raid.exe was not found after recursive search.")
sys.exit(1)
except Exception as e:
logger.error(f"Error in find_raid_path: {e}")
def get_asset_path(self):
try:
# Start with the directory of the current script
current_dir = os.path.dirname(os.path.abspath(__file__))
while True:
# Construct the path to the assets folder
self.asset_path = os.path.join(current_dir, 'assets')
# Check if the assets path exists
if os.path.exists(self.asset_path):
self.steps["Asset_path"] = "True"
logger.info(f"Assets folder found at {self.asset_path}")
return self.asset_path
# Move up one directory level
new_dir = os.path.dirname(current_dir)
if new_dir == current_dir:
# We are at the root directory and didn't find the assets folder
logger.error("Assets folder not found.")
self.steps["Asset_path"] = "False"
if self.folders_for_exe() == False:
logging.error("Could not find the assets folder. This folder contains all of the images needed for this program to use. It must be in the same folder as this program.")
sys.exit(1)
return None
else:
current_dir = new_dir
except Exception as e:
logger.error(f"Error in get_asset_path: {e}")
sys.exit(1)
def open_raid(self):
try:
logger.info("Attempting to open Raid: Shadow Legends.")
subprocess.Popen(
[
os.path.join(os.getenv("LOCALAPPDATA"), "PlariumPlay\\PlariumPlay.exe"),
"--args",
"-gameid=101",
"-tray-start",
]
)
self.wait_for_game_window(title="Raid: Shadow Legends", timeout=100)
except Exception as e:
logger.error(f"Error in open_raid: {e}")
def wait_for_game_window(self, title, timeout):
try:
logger.info("Waiting for game window to appear.")
start_time = time.time()
while time.time() - start_time < timeout:
if pyautogui.getWindowsWithTitle(title):
logging.debug("Game window found, game should be loading in now.")
self.steps["Open_raid"] = "True"
self.initiate_raid(True)
return
time.sleep(5)
self.steps["Open_raid"] = "False"
logging.error("Raid took too long to open, game window not found.")
sys.exit(1)
except Exception as e:
logger.error(f"Error in wait_for_game_window: {e}")
# Utility methods with error handling and logging
def delete_popup(self):
logger.info("Attempting to close any pop-up ads.")
exit_add_image = os.path.join(self.asset_path, "exitAdd.png")
logger.debug(f"Looking for exitAdd.png at: {exit_add_image}")
max_attempts = 5
attempts = 0
while attempts < max_attempts:
try:
location = pyautogui.locateOnScreen(exit_add_image, confidence=0.8)
if location:
adx, ady = pyautogui.center(location)
pyautogui.click(adx, ady)
time.sleep(4)
attempts += 1
logger.debug(f"Closed a pop-up ad. Attempt {attempts}.")
else:
logger.info("No pop-up ads found.")
break # Exit the loop since no ad is found
except Exception as e:
break # Exit the loop or handle as needed
if attempts >= max_attempts:
logger.warning("Reached maximum attempts to close pop-up ads.")
else:
logger.info("No pop-up ads found or all ads closed.")