forked from Egoistically/ALAuto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALAuto.py
169 lines (150 loc) · 5.68 KB
/
ALAuto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import sys
import argparse
from modules.combat import CombatModule
from modules.commission import CommissionModule
from modules.enhancement import EnhancementModule
from modules.mission import MissionModule
from modules.retirement import RetirementModule
from modules.event import EventModule
from datetime import datetime, timedelta
from util.adb import Adb
from util.config import Config
from util.logger import Logger
from util.stats import Stats
from util.utils import Utils, Region
class ALAuto(object):
modules = {
'combat': None,
'commissions': None,
'enhancement': None,
'missions': None,
'retirement': None,
'event': None
}
def __init__(self, config):
"""Initializes the primary azurlane-auto instance with the passed in
Config instance; creates the Stats instance and resets scheduled sleep
timers.
Args:
config (Config): azurlane-auto Config instance
"""
self.config = config
self.stats = Stats(config)
if self.config.combat['enabled']:
self.modules['combat'] = CombatModule(self.config, self.stats)
if self.config.commissions['enabled']:
self.modules['commissions'] = CommissionModule(self.config, self.stats)
if self.config.enhancement['enabled']:
self.modules['enhancement'] = EnhancementModule(self.config, self.stats)
if self.config.missions['enabled']:
self.modules['missions'] = MissionModule(self.config, self.stats)
if self.config.retirement['enabled']:
self.modules['retirement'] = RetirementModule(self.config, self.stats)
if self.config.events['enabled']:
self.modules['event'] = EventModule(self.config, self.stats)
self.print_stats_check = True
self.next_combat = datetime.now()
def run_combat_cycle(self):
"""Method to run the combat cycle.
"""
if self.modules['combat']:
result = self.modules['combat'].combat_logic_wrapper()
if result == 1:
# if boss is defeated
self.print_stats_check = True
if result == 2:
# if morale is too low
self.next_combat = datetime.now() + timedelta(hours=1)
self.print_stats_check = False
if result == 3:
# if dock is full
if self.modules['retirement']:
self.modules['retirement'].retirement_logic_wrapper(True)
else:
Logger.log_error("Retirement isn't enabled, exiting.")
sys.exit()
else:
self.next_combat = 0
def run_commission_cycle(self):
"""Method to run the expedition cycle.
"""
if self.modules['commissions']:
self.modules['commissions'].commission_logic_wrapper()
def run_enhancement_cycle(self):
"""Method to run the enhancement cycle.
"""
if self.modules['enhancement']:
self.modules['enhancement'].enhancement_logic_wrapper()
def run_mission_cycle(self):
"""Method to run the mission cycle
"""
if self.modules['missions']:
self.modules['missions'].mission_logic_wrapper()
def run_retirement_cycle(self):
"""Method to run the retirement cycle
"""
if self.modules['retirement']:
self.modules['retirement'].retirement_logic_wrapper()
def run_event_cycle(self):
"""Method to run the event cycle
"""
if self.modules['event']:
self.modules['event'].event_logic_wrapper()
def print_cycle_stats(self):
"""Method to print the cycle stats"
"""
if self.print_stats_check:
self.stats.print_stats()
self.print_stats_check = False
# check run-time args
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--config',
metavar=('CONFIG_FILE'),
help='Use the specified configuration file instead ' +
'of the default config.ini')
parser.add_argument('-d', '--debug',
help='Enables debugging logs.', action='store_true')
parser.add_argument('-l', '--legacy',
help='Enables sed usage.', action='store_true')
args = parser.parse_args()
config = Config('config.ini')
# check args, and if none provided, load default config
if args:
if args.config:
config = Config(args.config)
if args.debug:
Logger.log_info("Enabled debugging.")
Logger.enable_debugging(Logger)
if args.legacy:
Logger.log_info("Enabled sed usage.")
Adb.enable_legacy(Adb)
script = ALAuto(config)
Adb.service = config.network['service']
adb = Adb()
if adb.init():
Logger.log_msg('Sucessfully connected to the service.')
else:
Logger.log_error('Unable to connect to the service.')
sys.exit()
while True:
Utils.update_screen()
# temporal solution to event alerts
if not Utils.find("menu/button_battle"):
Utils.touch_randomly(Region(54, 57, 67, 67))
Utils.script_sleep(1)
continue
if Utils.find("commission/alert_completed"):
script.run_commission_cycle()
script.print_cycle_stats()
if Utils.find("mission/alert_completed"):
script.run_mission_cycle()
if script.next_combat != 0 and script.next_combat < datetime.now():
script.run_event_cycle()
script.run_combat_cycle()
script.run_enhancement_cycle()
script.run_retirement_cycle()
script.print_cycle_stats()
else:
Logger.log_msg("Nothing to do, will check again in a few minutes.")
Utils.script_sleep(300)
continue