-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheca.py
344 lines (265 loc) · 9.03 KB
/
eca.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
import controller
import keyboard
import os
import pyautogui
import pydirectinput
import threading
import time
run_combat_thread = True
run_main_loop = True
pause_event = threading.Event()
internal_pause_event = threading.Event()
pyautogui.FAILSAFE = False
def stop(reason: str, code: int):
print(f"Exiting with code {code}. Reason {reason}")
os._exit(code)
def stop_all(_event=None):
stop("Stop button pressed", 0)
def pause_all(_event=None):
if pause_event.is_set():
print("PAUSING...")
pause_event.clear()
else:
pause_event.set()
print("UNPAUSING...")
def init():
internal_pause_event.wait()
print("init...")
pydirectinput.press("f4")
def start():
internal_pause_event.wait()
print("start...")
start_time = time.time()
while not controller.image_on_screen("pics/dungeon_window.png", 0.9):
if time.time() - start_time >= 15:
stop("cannot find dungeon entry", -1)
pyautogui.click(button="left", x=1065, y=583)
time.sleep(0.5)
if not controller.image_click("pics/enter_button.png", 0.9):
stop("failed to find enter button", -3)
time.sleep(0.5)
pyautogui.moveTo(1, 1)
if not controller.image_on_screen("pics/challenge_screen.png", 0.9):
stop("failed to find challenge screen", -4)
time.sleep(0.5)
if not controller.image_click("pics/challenge_button.png", 0.9):
stop("failed to find challenge button", -5)
time.sleep(0.5)
def run_to_gate():
internal_pause_event.wait()
print("run to gate...")
pyautogui.moveTo(x=41, y=876)
pydirectinput.press("1", interval=0.6)
pydirectinput.press("2", interval=0.4)
pydirectinput.press("1", interval=0.6)
pydirectinput.press("2", interval=0.4)
pydirectinput.press("1", interval=0.6)
pyautogui.dragTo(x=800, y=864, button="right", duration=0.5)
time.sleep(0.5)
pyautogui.moveTo(x=1250, y=60)
pydirectinput.press("1", interval=0.6)
pydirectinput.press("2", interval=0.4)
pydirectinput.press("1", interval=0.6)
pydirectinput.press("2", interval=0.4)
pydirectinput.press("1", interval=0.6)
def kill_gate() -> bool:
internal_pause_event.wait()
print("kill gate...")
start_time = time.time()
while not controller.image_on_screen("pics/gate_hp_bar.png", 0.9):
if time.time() - start_time > 15:
print("failed to find gates")
return False
pyautogui.click(button="middle")
time.sleep(0.1)
start_time = time.time()
while controller.image_on_screen("pics/gate_hp_bar.png", 0.9):
if time.time() - start_time > 30:
print("failed to kill gates")
return False
controller.press_skillbar("3")
controller.press_skillbar("4")
controller.press_skillbar("5")
controller.press_skillbar("6")
time.sleep(0.1)
return True
def run_to_center():
internal_pause_event.wait()
print("run to center...")
pyautogui.moveTo(x=1200, y=51)
pydirectinput.press("1", interval=0.6)
pydirectinput.press("2", interval=0.4)
pydirectinput.press("1", interval=0.6)
pydirectinput.press("2", interval=0.4)
pydirectinput.press("1", interval=0.6)
def dead() -> bool:
return controller.image_on_screen("pics/death_window.png", confidence=0.9)
def resurrect() -> bool:
if not controller.image_click("pics/normal_resurrect.png", 0.9):
return False
time.sleep(0.5)
return controller.image_click("pics/confirmation.png", 0.9)
def exit_dungeon() -> bool:
if not controller.image_click("pics/exit_button.png", 0.9):
return False
time.sleep(0.5)
return controller.image_click("pics/exit_confirmation_button.png", 0.9)
def failed() -> bool:
return controller.image_on_screen("pics/dungeon_failed.png", 0.9)
def dungeon_failed() -> bool:
return controller.image_click("pics/ok_button.png", 0.9)
def cleared() -> bool:
return controller.image_on_screen("pics/cleared.png", 0.9)
def exit_after_clear() -> bool:
if not controller.image_click("pics/clear_confirmation.png", 0.9):
return False
time.sleep(0.5)
if not controller.image_click("pics/roll_dice.png", 0.9):
return False
time.sleep(0.5)
return controller.image_click("pics/exit_after_clear.png", 0.9)
def disconnected() -> bool:
return controller.image_on_screen(
"pics/disconnected.png", 0.9
) or controller.image_on_screen("pics/account_login.png", 0.9)
def cancel_bm():
print("canceling bm")
time.sleep(0.1)
pyautogui.click(button="right", x=196, y=122)
time.sleep(0.1)
pyautogui.click(button="right", x=196, y=122)
time.sleep(0.1)
pyautogui.click(button="right", x=196, y=122)
time.sleep(0.1)
def protection_thread_func(
main_pause: threading.Event, internal_pause: threading.Event
):
print("starting protection thread")
global run_combat_thread
while run_main_loop:
internal_pause.wait()
main_pause.wait()
if cleared():
run_combat_thread = False
pydirectinput.press("space")
pydirectinput.press("space")
pydirectinput.press("space")
pydirectinput.press("space")
pydirectinput.press("space")
print("cleared!")
cancel_bm()
exit_after_clear()
if failed():
run_combat_thread = False
print("failed!")
dungeon_failed()
if dead():
run_combat_thread = False
print("dead!")
resurrect()
time.sleep(0.5)
if failed():
print("failed!")
dungeon_failed()
else:
exit_dungeon()
time.sleep(0.1)
def mercenary_thread(main_pause: threading.Event, internal_pause: threading.Event):
print("starting mercenary thread")
mercs = ["alt_1", "alt_2"]
print("calling mercs")
for merc in mercs:
controller.press_skillbar(merc)
time.sleep(15)
start_time = time.time()
while run_combat_thread:
internal_pause.wait()
main_pause.wait()
if (time.time() - start_time) > 940:
print("calling mercs")
for merc in mercs:
controller.press_skillbar(merc)
time.sleep(15)
break
time.sleep(0.1)
def combat_thread(main_pause: threading.Event, internal_pause: threading.Event):
print("starting combat thread")
global run_combat_thread
start_time = time.time()
counter = 0
run_combat_thread = True
while run_combat_thread and run_main_loop:
internal_pause.wait()
main_pause.wait()
diff = time.time() - start_time
controller.press_skillbar("3")
controller.press_skillbar("4")
controller.press_skillbar("5")
controller.press_skillbar("6")
controller.press_skillbar("8")
controller.press_skillbar("9")
controller.press_skillbar("alt_3")
controller.press_skillbar("alt_4")
controller.press_skillbar("alt_5")
controller.press_skillbar("alt_6")
controller.press_skillbar("alt_7")
if diff > 300:
controller.press_skillbar("7")
if counter % 10 == 0:
if diff > 1080:
if not controller.image_on_screen("pics/boss_icon.png", 0.9):
pyautogui.click(button="middle")
else:
pyautogui.click(button="middle")
counter = counter + 1
time.sleep(0.1)
def main():
print("starting...")
keyboard.on_press_key("f10", pause_all)
keyboard.on_press_key("f12", stop_all)
controller.focus_cabal()
pause_event.set()
internal_pause_event.set()
protection_thread = threading.Thread(
target=protection_thread_func, args=(pause_event, internal_pause_event)
)
protection_thread.start()
while run_main_loop:
pause_event.wait()
internal_pause_event.wait()
pyautogui.PAUSE = 0.1
pyautogui.click(button="right", x=1065, y=583)
if disconnected():
internal_pause_event.clear()
stop("Disconnected!", -6)
init()
start()
run_to_gate()
if not kill_gate():
exit_dungeon()
continue
run_to_center()
pyautogui.PAUSE = 0.001
print("start threads...")
combat_thread_joins = []
for thread in [combat_thread, mercenary_thread]:
t = threading.Thread(
target=thread, args=(pause_event, internal_pause_event)
)
t.start()
combat_thread_joins.append(t)
for thread_join in combat_thread_joins:
thread_join.join()
print("after threads...")
time.sleep(5)
print("refilling sp...")
counter = 0
while run_main_loop and counter < 6:
controller.press_skillbar("ctrl_8")
time.sleep(6)
counter = counter + 1
time.sleep(3)
cancel_bm()
time.sleep(3)
protection_thread.join()
main()