forked from Fortigate/AutoAFK
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain.py
More file actions
1430 lines (1192 loc) · 57.5 KB
/
Copy pathmain.py
File metadata and controls
1430 lines (1192 loc) · 57.5 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
"""
AutoAFK - Modern modular architecture
Uses new modular backend with full functionality
"""
import os
import sys
import threading
import datetime
import logging
import argparse
import subprocess
from pathlib import Path
# Version - Update this when releasing new version
VERSION = "2.0.6"
# GitHub Repository
GITHUB_REPO = "Hammanek/AutoAFK"
GITHUB_API_URL = f"https://api.github.com/repos/{GITHUB_REPO}/releases/latest"
try:
import customtkinter as ctk
except ImportError:
print("Installing customtkinter...")
os.system("pip install customtkinter")
import customtkinter as ctk
from src.core.config import Config
from src.core.device_manager import DeviceManager
from src.core.image_recognition import ImageRecognition
from src.core.game_controller import GameController
from src.core.activity_manager import ActivityManager
from src.core.dailies_runner import execute_dailies
from src.activities.tower_activities import TowerPusher
from src.utils.logger import Logger
from src.utils.notifications import NotificationManager
from src.utils.version_checker import VersionChecker
# Set appearance - Modern dark theme
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("dark-blue") # Modern blue theme
logger = Logger.get_logger(__name__)
# Global args variable
args = None
def initialize_core_modules(config: Config) -> tuple:
"""Initialize core modules (device, image recognition, game controller)
Args:
config: Configuration instance
Returns:
tuple: (device_manager, image_recognition, game_controller) or (None, None, None) on failure
"""
device_manager = DeviceManager(config)
if not device_manager.connect():
logger.error("Failed to connect to device")
return None, None, None
image_recognition = ImageRecognition(device_manager, config)
game_controller = GameController(device_manager, image_recognition, config)
# Enable automatic screenshots on errors
from src.utils.logger import set_device_manager
set_device_manager(device_manager)
return device_manager, image_recognition, game_controller
class App(ctk.CTk):
"""Main application window - original style"""
def __init__(self):
super().__init__()
# Window setup
self.title(f"AutoAFK {VERSION}")
self.geometry("800x540")
self.resizable(False, False) # Disable window resizing
# Try to set icon
icon_paths = [
Path("img/auto.ico"),
Path("_internal/img/auto.ico"),
Path(sys._MEIPASS) / "img" / "auto.ico" if getattr(sys, 'frozen', False) else None
]
for icon_path in icon_paths:
if icon_path and icon_path.exists():
try:
self.iconbitmap(str(icon_path))
break
except:
pass
# Config and core modules
self.config = Config('settings.ini')
# Initialize Logger
from src.utils.logger import Logger as LoggerClass
LoggerClass() # Initialize logger singleton
self.device_manager = None
self.image_recognition = None
self.game_controller = None
self.daily_activities = None
self.arena_activities = None
self.legacy_activities = None
self.notification_manager = None
# Thread state
self.dailies_thread_running = False
self.activity_thread_running = False
self.push_thread_running = False
self.dailies_thread = None
self.activity_thread = None
self.push_thread = None
self.dailies_stop_event = threading.Event()
self.activity_stop_event = threading.Event()
self.push_stop_event = threading.Event()
self.dailies_pause_event = threading.Event()
self.activity_pause_event = threading.Event()
self.push_pause_event = threading.Event()
# Windows
self.shop_window = None
self.activity_window = None
self.advanced_window = None
self._create_widgets()
def _check_for_updates(self) -> None:
"""Check for updates in background thread to avoid blocking UI"""
def check():
try:
update_available, current, latest = VersionChecker.check_for_updates()
notes = VersionChecker.get_release_notes(latest) if (latest and update_available) else None
def update_ui():
if not latest:
self.textbox.insert('end', '⚠️ Could not check for updates\n\n', 'warning')
return
if not update_available:
return
self.textbox.insert('end', '⚠️ UPDATE AVAILABLE!\n', 'yellow')
self.textbox.insert('end', f'Current version: {current}\n', 'warning')
self.textbox.insert('end', f'Latest version: {latest}\n\n', 'yellow')
if notes:
self.textbox.insert('end', f'Version {latest} changes:\n', 'yellow')
self.textbox.insert('end', f'{notes[:500]}{"..." if len(notes) > 500 else ""}\n\n', 'warning')
if self.config.getboolean('ADVANCED', 'autoupdate', fallback=False):
self.textbox.insert('end', '🔄 Auto-update enabled, starting updater...\n\n', 'orange')
self.after(2000, self._run_updater)
else:
self.textbox.insert('end', '💡 Run update.bat to update or download from:\n', 'blue')
self.textbox.insert('end', f'{VersionChecker.get_download_url()}\n\n', 'blue')
self.after(0, update_ui)
except Exception as e:
logger.debug(f"Version check failed: {e}")
threading.Thread(target=check, daemon=True).start()
def _open_link(self, event) -> None:
"""Open URL in browser when clicked"""
import webbrowser
# Get all tags at click position
tags = self.textbox.tag_names(f"@{event.x},{event.y}")
# Find URL from stored links
for tag in tags:
if tag in self.link_urls:
webbrowser.open(self.link_urls[tag])
break
def _get_tower_options_for_today(self) -> list:
"""Get available tower options based on day of week (UTC timezone)"""
from datetime import datetime, timezone
# Get current day in UTC (1=Monday, 7=Sunday)
# Game uses UTC timezone for tower resets
current_day = datetime.now(timezone.utc).isoweekday()
# Tower availability by day
tower_days = {
1: ["Campaign", "King's Tower", "Lightbearer Tower"],
2: ["Campaign", "King's Tower", "Mauler Tower"],
3: ["Campaign", "King's Tower", "Wilder Tower", "Celestial Tower"],
4: ["Campaign", "King's Tower", "Graveborn Tower", "Hypogean Tower"],
5: ["Campaign", "King's Tower", "Lightbearer Tower", "Mauler Tower", "Celestial Tower"],
6: ["Campaign", "King's Tower", "Wilder Tower", "Graveborn Tower", "Hypogean Tower"],
7: ["Campaign", "King's Tower", "Lightbearer Tower", "Wilder Tower", "Mauler Tower",
"Graveborn Tower", "Hypogean Tower", "Celestial Tower"]
}
return tower_days.get(current_day, ["Campaign", "King's Tower"])
def _run_updater(self) -> None:
"""Launch updater as a detached process with its own visible console window"""
try:
# Resolve base directory (works for both frozen exe and script)
if getattr(sys, 'frozen', False):
base_dir = os.path.dirname(sys.executable)
else:
base_dir = os.path.dirname(os.path.abspath(__file__))
updater_exe = os.path.join(base_dir, '_internal', 'AutoAFKUpdater.exe')
updater_py = os.path.join(base_dir, 'AutoAFKUpdater.py')
if os.path.exists(updater_exe):
cmd = [updater_exe, '--auto']
elif os.path.exists(updater_py):
cmd = ['python', updater_py, '--auto']
else:
self.textbox.insert('end', '❌ Updater not found\n', 'error')
return
# Launch in a new visible console window, fully detached from this process
# CREATE_NEW_CONSOLE gives user a window to see progress
# CREATE_NEW_PROCESS_GROUP ensures it survives when AutoAFK.exe is killed
subprocess.Popen(
cmd,
creationflags=subprocess.CREATE_NEW_CONSOLE | subprocess.CREATE_NEW_PROCESS_GROUP
)
self.textbox.insert('end', '🔄 Updater started in separate window\n', 'orange')
self.textbox.insert('end', '⏳ Bot will close in 5 seconds...\n', 'orange')
self.textbox.see('end')
self.after(5000, self.quit)
except Exception as e:
self.textbox.insert('end', f'❌ Failed to run updater: {e}\n', 'error')
def _create_widgets(self) -> None:
"""Create all widgets - original layout"""
# Dailies Frame
self.dailiesFrame = ctk.CTkFrame(master=self, height=170, width=180)
self.dailiesFrame.place(x=10, y=20)
self.dailiesButton = ctk.CTkButton(
master=self.dailiesFrame,
text="Run Dailies",
command=self.start_dailies_thread
)
self.dailiesButton.place(x=20, y=10)
self.activitiesButton = ctk.CTkButton(
master=self.dailiesFrame,
text="Configure Dailies",
fg_color=["#343638", "#343638"], # Match dropdown menu color
hover_color=["#3E4042", "#3E4042"],
width=120,
command=self.open_activitywindow
)
self.activitiesButton.place(x=30, y=50)
self.dailiesShopButton = ctk.CTkButton(
master=self.dailiesFrame,
text="Store Options",
fg_color=["#343638", "#343638"], # Match dropdown menu color
hover_color=["#3E4042", "#3E4042"],
width=120,
command=self.open_shopwindow
)
self.dailiesShopButton.place(x=30, y=90)
self.advancedButton = ctk.CTkButton(
master=self.dailiesFrame,
text="Advanced Options",
fg_color=["#343638", "#343638"], # Match dropdown menu color
hover_color=["#3E4042", "#3E4042"],
width=120,
command=self.open_advancedwindow
)
self.advancedButton.place(x=30, y=130)
# PvP Frame
self.arenaFrame = ctk.CTkFrame(master=self, height=130, width=180)
self.arenaFrame.place(x=10, y=200)
self.arenaButton = ctk.CTkButton(
master=self.arenaFrame,
text="Run Activity",
command=self.start_activity_thread
)
self.arenaButton.place(x=20, y=15)
self.activityFormationDropdown = ctk.CTkComboBox(
master=self.arenaFrame,
values=[
"Arena of Heroes",
"Arcane Labyrinth",
"Fight of Fates",
"Battle of Blood",
"Heroes of Esperia",
"Guild Hunts"
],
width=160
)
self.activityFormationDropdown.place(x=10, y=55)
self.pvpLabel = ctk.CTkLabel(
master=self.arenaFrame,
text='How many battles?'
)
self.pvpLabel.place(x=10, y=90)
self.pvpEntry = ctk.CTkEntry(master=self.arenaFrame, height=20, width=40)
self.pvpEntry.insert('end', self.config.get('ACTIVITIES', 'arena_battles', fallback='5'))
self.pvpEntry.place(x=130, y=92)
# Push Frame
self.pushFrame = ctk.CTkFrame(master=self, height=180, width=180)
self.pushFrame.place(x=10, y=340)
self.pushButton = ctk.CTkButton(
master=self.pushFrame,
text="Auto Push",
command=self.start_push_thread
)
self.pushButton.place(x=20, y=10)
# Set tower options based on day of week
tower_values = self._get_tower_options_for_today()
self.pushLocationDropdown = ctk.CTkComboBox(
master=self.pushFrame,
values=tower_values,
width=160
)
self.pushLocationDropdown.place(x=10, y=50)
self.pushLabel = ctk.CTkLabel(
master=self.pushFrame,
text='Which formation?'
)
self.pushLabel.place(x=10, y=80)
self.pushFormationDropdown = ctk.CTkComboBox(
master=self.pushFrame,
values=["1st", "2nd", "3rd", "4th", "5th"],
width=80
)
# Load saved formation from config
saved_formation_str = self.config.get('PUSH', 'formation', fallback='3')
# Parse formation - handle both "3" and "3rd" formats
if saved_formation_str.isdigit():
saved_formation = int(saved_formation_str)
else:
# Extract number from "3rd" format
saved_formation = int(saved_formation_str[0])
formation_map = {1: "1st", 2: "2nd", 3: "3rd", 4: "4th", 5: "5th"}
self.pushFormationDropdown.set(formation_map.get(saved_formation, "3rd"))
self.pushFormationDropdown.place(x=10, y=110)
# Textbox - Modern styling
self.textbox = ctk.CTkTextbox(master=self, width=580, height=500)
self.textbox.place(x=200, y=20)
self.textbox.configure(
text_color='#E8E8E8', # Soft white
fg_color='#1E1E1E', # Dark background
font=('Segoe UI', 13), # Modern font
border_width=2,
border_color='#3A3A3A' # Subtle border
)
# Configure tags - Modern minimalist color scheme
self.textbox.tag_config("error", foreground="#EF4444") # Bright red
self.textbox.tag_config('warning', foreground="#F59E0B") # Amber
self.textbox.tag_config('green', foreground="#10B981") # Emerald green
self.textbox.tag_config('blue', foreground="#3B82F6") # Blue
self.textbox.tag_config('purple', foreground="#A855F7") # Purple
self.textbox.tag_config('yellow', foreground="#F59E0B") # Amber
self.textbox.tag_config('orange', foreground="#F97316") # Orange
# Configure clickable link tags
self.textbox.tag_config('link', foreground="#3B82F6", underline=True)
self.textbox.tag_bind('link', '<Button-1>', self._open_link)
self.textbox.tag_bind('link', '<Enter>', lambda e: self.textbox.configure(cursor='hand2'))
self.textbox.tag_bind('link', '<Leave>', lambda e: self.textbox.configure(cursor=''))
# Store URLs for links
self.link_urls = {}
# Welcome message
self.textbox.insert('end', f'AutoAFK {VERSION}\n', 'green')
self.textbox.insert('end', '🔗 GitHub: ', 'info')
# GitHub link (clickable)
github_url = f'https://github.com/{GITHUB_REPO}'
start_idx = self.textbox.index('end-1c')
self.textbox.insert('end', f'{github_url}\n', 'link')
end_idx = self.textbox.index('end-1c')
github_tag = f'github_link_{id(github_url)}'
self.textbox.tag_add(github_tag, start_idx, end_idx)
self.link_urls[github_tag] = github_url
self.textbox.insert('end', '☕ Support: ', 'info')
# Ko-fi link (clickable)
kofi_url = 'https://ko-fi.com/afksupporter'
start_idx = self.textbox.index('end-1c')
self.textbox.insert('end', f'{kofi_url}\n\n', 'link')
end_idx = self.textbox.index('end-1c')
kofi_tag = f'kofi_link_{id(kofi_url)}'
self.textbox.tag_add(kofi_tag, start_idx, end_idx)
self.link_urls[kofi_tag] = kofi_url
# Check for updates
self._check_for_updates()
# Pause/Stop buttons
self.pauseButton = ctk.CTkButton(
master=self,
text="⏸️",
bg_color="#3B3B3B",
fg_color="#1F6AA5",
width=40,
command=self.pause_all_thread,
state="disabled",
hover=False
)
self.pauseButton.place(x=690, y=25)
self.pauseButton.place_forget()
self.quitButton = ctk.CTkButton(
master=self,
text="⏹️",
bg_color="#3B3B3B",
fg_color=["#B60003", "#C03335"],
width=40,
command=self.stop_all_threads,
state="disabled",
hover=False
)
self.quitButton.place(x=735, y=25)
self.quitButton.place_forget()
# Setup logging redirect
sys.stdout = STDOutRedirector(self.textbox)
sys.stderr = STDOutRedirector(self.textbox) # Also redirect errors
# Redirect logger to GUI
self._setup_logger_redirect()
# Setup cleanup on close
self.protocol("WM_DELETE_WINDOW", self._on_closing)
def _setup_logger_redirect(self) -> None:
"""Redirect logger output to GUI"""
class GUIHandler(logging.Handler):
def __init__(self, app):
super().__init__()
self.app = app
def emit(self, record):
try:
msg = self.format(record)
timestamp = '[' + datetime.datetime.now().strftime("%H:%M:%S") + '] '
# Import custom levels
from src.utils.logger import BLUE, GREEN, PURPLE
# Color based on level - check custom levels first
if record.levelno == GREEN:
self.app.textbox.insert('end', timestamp + msg + '\n', 'green')
elif record.levelno == BLUE:
self.app.textbox.insert('end', timestamp + msg + '\n', 'blue')
elif record.levelno == PURPLE:
self.app.textbox.insert('end', timestamp + msg + '\n', 'purple')
elif record.levelno >= logging.ERROR:
self.app.textbox.insert('end', timestamp + msg + '\n', 'error')
elif record.levelno >= logging.WARNING:
self.app.textbox.insert('end', timestamp + msg + '\n', 'warning')
elif record.levelno >= logging.INFO:
# Color INFO messages based on content
if 'collected' in msg.lower() or 'completed' in msg.lower() or 'success' in msg.lower():
self.app.textbox.insert('end', timestamp + msg + '\n', 'green')
elif 'starting' in msg.lower() or 'attempting' in msg.lower():
self.app.textbox.insert('end', timestamp + msg + '\n', 'blue')
else:
self.app.textbox.insert('end', timestamp + msg + '\n')
else:
self.app.textbox.insert('end', timestamp + msg + '\n')
self.app.textbox.see('end')
self.app.update_idletasks()
# Send to Discord if enabled
if hasattr(self.app, 'notification_manager') and self.app.notification_manager:
level_name = logging.getLevelName(record.levelno)
self.app.notification_manager.send(msg, level_name)
except:
pass # Ignore errors during logging
# Add handler to root logger
handler = GUIHandler(self)
handler.setFormatter(logging.Formatter('%(message)s'))
logging.getLogger().addHandler(handler)
logging.getLogger().setLevel(logging.INFO)
def _on_closing(self) -> None:
"""Cleanup when closing the application"""
try:
# Stop all threads
self.stop_all_threads()
# Cleanup ADB synchronously to ensure it completes
try:
if self.device_manager:
logger.info("Disconnecting and cleaning up ADB...")
self.device_manager.disconnect()
self.device_manager._kill_adb_processes()
# Give it a moment to complete
import time
time.sleep(0.5)
except Exception as e:
logger.debug(f"Cleanup error: {e}")
except Exception as e:
logger.debug(f"Cleanup error: {e}")
finally:
# Close the window
self.destroy()
def start_dailies_thread(self) -> None:
"""Start dailies thread"""
if not self.dailies_thread_running:
self.dailies_thread_running = True
self.dailies_stop_event.clear()
self.dailies_pause_event.clear()
self.dailies_thread = threading.Thread(target=self.dailies)
self.dailies_thread.start()
self.button_state('disabled')
self.stop_button_state('normal')
def start_activity_thread(self) -> None:
"""Start activity thread"""
if not self.activity_thread_running:
self.activity_thread_running = True
self.activity_stop_event.clear()
self.activity_pause_event.clear()
self.activity_thread = threading.Thread(target=self.activity_manager)
self.activity_thread.start()
self.button_state('disabled')
self.stop_button_state('normal')
def start_push_thread(self) -> None:
"""Start push thread"""
if not self.push_thread_running:
self.push_thread_running = True
self.push_stop_event.clear()
self.push_pause_event.clear()
self.push_thread = threading.Thread(target=self.push)
self.push_thread.start()
self.button_state('disabled')
self.stop_button_state('normal')
def stop_all_threads(self) -> None:
"""Stop all threads"""
print('WAR' + "Stop pressed, stopping after current action")
self.dailies_thread_running = False
self.activity_thread_running = False
self.push_thread_running = False
self.dailies_stop_event.set()
self.activity_stop_event.set()
self.push_stop_event.set()
def pause_all_thread(self) -> None:
"""Pause all threads"""
print('WAR' + "Pause pressed, pausing after current action")
self.dailies_pause_event.set()
self.activity_pause_event.set()
self.push_pause_event.set()
self.pauseButton.configure(text="▶️", command=self.resume_all_thread, fg_color="green")
self.quitButton.configure(state='disabled')
def resume_all_thread(self) -> None:
"""Resume all threads"""
self.dailies_pause_event.clear()
self.activity_pause_event.clear()
self.push_pause_event.clear()
self.pauseButton.configure(text="⏸️", command=self.pause_all_thread, fg_color="#1F6AA5")
self.quitButton.configure(state='normal')
def button_state(self, state: str) -> None:
"""Set button states"""
self.dailiesButton.configure(state=state)
self.arenaButton.configure(state=state)
self.pushButton.configure(state=state)
if state == 'normal':
self.pauseButton.configure(state='disabled')
self.quitButton.configure(state='disabled')
self.pauseButton.place_forget()
self.quitButton.place_forget()
def stop_button_state(self, state: str) -> None:
"""Set stop button state"""
if state == "normal":
self.pauseButton.place(x=690, y=25)
self.quitButton.place(x=735, y=25)
self.pauseButton.lift()
self.quitButton.lift()
self.pauseButton.configure(state=state)
self.quitButton.configure(state=state)
def dailies(self) -> None:
"""Run dailies"""
try:
logger.info("Starting dailies...")
# Initialize notification manager
self.notification_manager = NotificationManager(self.config)
# Initialize core modules
self.device_manager, self.image_recognition, self.game_controller = \
initialize_core_modules(self.config)
if not self.device_manager:
return
# Initialize activity manager
self.activity_manager = ActivityManager(
self.device_manager, self.image_recognition, self.game_controller,
self.config, self.notification_manager
)
# Execute dailies using shared function
execute_dailies(self.activity_manager, self.dailies_pause_event, self.dailies_stop_event)
except Exception as e:
logger.error(f"Dailies error: {e}", exc_info=True)
finally:
self.dailies_thread_running = False
self.button_state('normal')
def activity_manager(self) -> None:
"""Run selected activity"""
try:
activity = self.activityFormationDropdown.get()
battles = int(self.pvpEntry.get())
# Save battles count to config
self.config.set('ACTIVITIES', 'arena_battles', str(battles))
self.config.save()
logger.info(f"Starting {activity} ({battles} battles)...")
# Initialize modules if not already done
if not self.device_manager:
self.notification_manager = NotificationManager(self.config)
# Initialize core modules
self.device_manager, self.image_recognition, self.game_controller = \
initialize_core_modules(self.config)
if not self.device_manager:
logger.error("Failed to connect to device")
return
# Initialize activity manager with all modules
activity_mgr = ActivityManager(
self.device_manager, self.image_recognition, self.game_controller,
self.config, self.notification_manager
)
# Expand menus and wait for game
self.game_controller.expand_menus()
self.game_controller.wait_until_game_active()
logger.info("Device connected, running activity...")
# Run specific activity
if activity == "Arena of Heroes":
activity_mgr.arena.battle_arena_of_heroes(battles, 1,
self.activity_pause_event,
self.activity_stop_event)
elif activity == "Arcane Labyrinth":
activity_mgr.labyrinth.handle_labyrinth()
elif activity == "Fight of Fates":
activity_mgr.misc.handle_fight_of_fates(battles)
elif activity == "Battle of Blood":
activity_mgr.misc.handle_battle_of_blood(battles)
elif activity == "Heroes of Esperia":
activity_mgr.misc.handle_heroes_of_esperia(battles, 4)
elif activity == "Guild Hunts":
activity_mgr.guild.handle_guild_hunts()
logger.info("Activity completed!")
except Exception as e:
logger.error(f"Activity error: {e}", exc_info=True)
finally:
self.activity_thread_running = False
self.button_state('normal')
def push(self) -> None:
"""Run push"""
try:
location = self.pushLocationDropdown.get()
formation = int(self.pushFormationDropdown.get()[0])
# Save formation to config
self.config.set('PUSH', 'formation', str(formation))
self.config.save()
logger.info(f"Auto-Pushing {location} using formation {formation}")
# Initialize modules if not already done
if not self.device_manager:
self.notification_manager = NotificationManager(self.config)
# Initialize core modules
self.device_manager, self.image_recognition, self.game_controller = \
initialize_core_modules(self.config)
if not self.device_manager:
logger.error("Failed to connect to device")
return
# Expand menus and wait for game
self.game_controller.expand_menus()
self.game_controller.wait_until_game_active()
logger.info("Device connected, starting push...")
# Get duration from config
duration = self.config.getint('PUSH', 'victoryCheck', fallback=1)
# Create TowerPusher and run
from src.activities.tower_activities import TowerPusher
pusher = TowerPusher(self.device_manager, self.image_recognition,
self.game_controller, self.config, self.notification_manager)
if "Tower" in location:
# Push tower
pusher.push_tower(location, formation, duration,
pause_event=self.push_pause_event,
stop_event=self.push_stop_event)
else:
# Push campaign
pusher.push_campaign(formation, duration,
pause_event=self.push_pause_event,
stop_event=self.push_stop_event)
logger.info("Push completed!")
except Exception as e:
logger.error(f"Push error: {e}", exc_info=True)
finally:
self.push_thread_running = False
self.button_state('normal')
def open_advancedwindow(self) -> None:
"""Open advanced window"""
if self.advanced_window is None or not self.advanced_window.winfo_exists():
self.advanced_window = AdvancedWindow(self)
self.advanced_window.focus()
else:
self.advanced_window.focus()
def open_shopwindow(self) -> None:
"""Open shop window"""
if self.shop_window is None or not self.shop_window.winfo_exists():
self.shop_window = ShopWindow(self)
self.shop_window.focus()
else:
self.shop_window.focus()
def open_activitywindow(self) -> None:
"""Open activity window"""
if self.activity_window is None or not self.activity_window.winfo_exists():
self.activity_window = ActivityWindow(self)
self.activity_window.focus()
else:
self.activity_window.focus()
class ActivityWindow(ctk.CTkToplevel):
"""Activity configuration window - original style"""
def __init__(self, parent):
super().__init__(parent)
self.geometry("745x560")
self.resizable(False, False) # Disable window resizing
self.title('Dailies Configuration')
self.attributes("-topmost", True)
self.config = parent.config
self.activity_widgets = {}
self.arena_widgets = {}
self.events_widgets = {}
self.bounties_widgets = {}
# Activities Frame
self.activityFrame = ctk.CTkFrame(master=self, width=235, height=500)
self.activityFrame.place(x=10, y=10)
ctk.CTkLabel(master=self.activityFrame, text="Activities:", font=("Arial", 15, 'bold')).place(x=10, y=5)
activities = [
("Collect AFK Rewards", "checkbox", "collectRewards", "DAILIES"),
("Collect Mail", "checkbox", "collectMail", "DAILIES"),
("Companion Points", "checkbox", "companionPoints", "DAILIES"),
("Auto lend mercs?", "checkbox", "lendMercs", "DAILIES", 40),
("Fast Rewards", "entry", "fastrewards", "DAILIES"),
("Attempt Campaign", "checkbox", "attemptCampaign", "DAILIES"),
("Fountain of Time", "checkbox", "fountainOfTime", "DAILIES"),
("King's Tower", "checkbox", "kingsTower", "DAILIES"),
("Collect Inn Gifts", "checkbox", "collectInn", "DAILIES"),
("Guild Hunts", "checkbox", "guildHunt", "DAILIES"),
("Store Purchases", "checkbox", "storePurchases", "DAILIES"),
("Shop Refreshes", "entry", "shoprefreshes", "DAILIES", 40),
("Twisted Realm", "checkbox", "twistedRealm", "DAILIES"),
("Run Lab", "checkbox", "runLab", "DAILIES"),
("Collect Quests", "checkbox", "collectQuests", "DAILIES"),
("Collect Merchants", "checkbox", "collectMerchants", "DAILIES"),
("Use Bag Consumables", "checkbox", "useBagConsumables", "DAILIES"),
]
y_offset = 30
start_y = 40
y = start_y
for item in activities:
label_text, widget_type, config_key, section = item[:4]
x_offset = item[4] if len(item) > 4 else 10
label = ctk.CTkLabel(master=self.activityFrame, text=label_text)
label.place(x=x_offset, y=y)
if widget_type == "checkbox":
cb = ctk.CTkCheckBox(master=self.activityFrame, text=None, onvalue=True, offvalue=False)
cb.place(x=200, y=y)
self.activity_widgets[config_key] = cb
if self.config.getboolean(section, config_key, fallback=False):
cb.select()
elif widget_type == "entry":
entry = ctk.CTkEntry(master=self.activityFrame, height=20, width=25)
entry.insert('end', self.config.get(section, config_key, fallback='0'))
entry.place(x=200, y=y)
self.activity_widgets[config_key] = entry
y += y_offset
# Arena Frame
self.ArenaFrame = ctk.CTkFrame(master=self, width=235, height=280)
self.ArenaFrame.place(x=255, y=10)
ctk.CTkLabel(master=self.ArenaFrame, text="Arena:", font=("Arial", 15, 'bold')).place(x=10, y=5)
arena_items = [
("Battle Arena of Heroes", "checkbox", "battleArena", "ARENA"),
("Number of Battles", "entry", "arenaBattles", "ARENA", 40),
("Which Opponent", "entry", "arenaOpponent", "ARENA", 40),
("Collect Daily TS loot", "checkbox", "tsCollect", "ARENA"),
("Collect Gladiator Coins", "checkbox", "gladiatorCollect", "ARENA"),
]
y = 40
for item in arena_items:
label_text, widget_type, config_key, section = item[:4]
x_offset = item[4] if len(item) > 4 else 10
label = ctk.CTkLabel(master=self.ArenaFrame, text=label_text)
label.place(x=x_offset, y=y)
if widget_type == "checkbox":
cb = ctk.CTkCheckBox(master=self.ArenaFrame, text=None, onvalue=True, offvalue=False)
cb.place(x=200, y=y)
self.arena_widgets[config_key] = cb
if self.config.getboolean(section, config_key, fallback=False):
cb.select()
elif widget_type == "entry":
entry = ctk.CTkEntry(master=self.ArenaFrame, height=20, width=25)
entry.insert('end', self.config.get(section, config_key, fallback='5'))
entry.place(x=198, y=y)
self.arena_widgets[config_key] = entry
y += y_offset
# Events Frame
self.eventsFrame = ctk.CTkFrame(master=self, width=235, height=210)
self.eventsFrame.place(x=255, y=300)
ctk.CTkLabel(master=self.eventsFrame, text="Events:", font=("Arial", 15, 'bold')).place(x=10, y=5)
events_items = [
("Fight of Fates", "checkbox", "fightOfFates", "EVENTS"),
("Battle of Blood", "checkbox", "battleOfBlood", "EVENTS"),
("Circus Tour", "checkbox", "circusTour", "EVENTS"),
("Heroes of Esperia", "checkbox", "heroesOfEsperia", "EVENTS"),
]
y = 40
for label_text, widget_type, config_key, section in events_items:
label = ctk.CTkLabel(master=self.eventsFrame, text=label_text)
label.place(x=10, y=y)
cb = ctk.CTkCheckBox(master=self.eventsFrame, text=None, onvalue=True, offvalue=False)
cb.place(x=200, y=y)
self.events_widgets[config_key] = cb
if self.config.getboolean(section, config_key, fallback=False):
cb.select()
y += y_offset
# Bounties Frame
self.BountiesFrame = ctk.CTkFrame(master=self, width=235, height=310)
self.BountiesFrame.place(x=500, y=10)
ctk.CTkLabel(master=self.BountiesFrame, text="Bounties:", font=("Arial", 15, 'bold')).place(x=10, y=5)
bounties_items = [
("Enable solo bounties", "checkbox", "dispatchSoloBounties", "BOUNTIES"),
("Enable team bounties", "checkbox", "dispatchTeamBounties", "BOUNTIES"),
("Dispatch Dust", "checkbox", "dispatchDust", "BOUNTIES"),
("Dispatch Diamonds", "checkbox", "dispatchDiamonds", "BOUNTIES"),
("Dispatch Shards", "checkbox", "dispatchShards", "BOUNTIES"),
("Dispatch Juice", "checkbox", "dispatchJuice", "BOUNTIES"),
("Number of Refreshes", "entry", "refreshes", "BOUNTIES"),
("# Remaining to Dispatch All", "entry", "remaining", "BOUNTIES"),
("Enable event bounties", "checkbox", "dispatchEventBounties", "BOUNTIES"),
]
y = 40
for label_text, widget_type, config_key, section in bounties_items:
label = ctk.CTkLabel(master=self.BountiesFrame, text=label_text)
label.place(x=10, y=y)
if widget_type == "checkbox":
cb = ctk.CTkCheckBox(master=self.BountiesFrame, text=None, onvalue=True, offvalue=False)
cb.place(x=200, y=y)
self.bounties_widgets[config_key] = cb
if self.config.getboolean(section, config_key, fallback=False):
cb.select()
elif widget_type == "entry":
entry = ctk.CTkEntry(master=self.BountiesFrame, height=20, width=25)
entry.insert('end', self.config.get(section, config_key, fallback='0'))
entry.place(x=200, y=y)
self.bounties_widgets[config_key] = entry
y += y_offset
# Misc Frame
self.MiscFrame = ctk.CTkFrame(master=self, width=235, height=180)
self.MiscFrame.place(x=500, y=330)
ctk.CTkLabel(master=self.MiscFrame, text="Misc:", font=("Arial", 15, 'bold')).place(x=10, y=5)
misc_items = [
("Delay start by x minutes", "entry", "delayedstart", "DAILIES"),
("Hibernate system when done", "checkbox", "hibernate", "DAILIES"),
]
y = 40
for label_text, widget_type, config_key, section in misc_items:
label = ctk.CTkLabel(master=self.MiscFrame, text=label_text)
label.place(x=10, y=y)
if widget_type == "checkbox":
cb = ctk.CTkCheckBox(master=self.MiscFrame, text=None, onvalue=True, offvalue=False)
cb.place(x=200, y=y)
self.activity_widgets[config_key] = cb
if self.config.getboolean(section, config_key, fallback=False):
cb.select()
elif widget_type == "entry":
entry = ctk.CTkEntry(master=self.MiscFrame, height=20, width=25)
entry.insert('end', self.config.get(section, config_key, fallback='0'))
entry.place(x=200, y=y)
self.activity_widgets[config_key] = entry
y += y_offset
# Save button
self.activitySaveButton = ctk.CTkButton(
master=self,
text="Save",
fg_color=["#10B981", "#059669"],
hover_color=["#059669", "#047857"],
width=120,
command=self.activity_save
)
self.activitySaveButton.place(x=320, y=520)
def activity_save(self) -> None:
"""Save all settings"""
for config_key, widget in self.activity_widgets.items():
if isinstance(widget, ctk.CTkCheckBox):
self.config.set('DAILIES', config_key, 'True' if widget.get() else 'False')
else:
self.config.set('DAILIES', config_key, widget.get())
for config_key, widget in self.arena_widgets.items():
if isinstance(widget, ctk.CTkCheckBox):
self.config.set('ARENA', config_key, 'True' if widget.get() else 'False')
else:
self.config.set('ARENA', config_key, widget.get())
for config_key, cb in self.events_widgets.items():
self.config.set('EVENTS', config_key, 'True' if cb.get() else 'False')