-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfarm.py
99 lines (78 loc) · 3.56 KB
/
farm.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
import cv2
import sys
import pyautogui
from mss import mss
from constants import *
from utils import *
from telegram import *
character = sys.argv[1]
print("Farming Lair ({})".format(character))
wave_model = load_artifact("models\\{}_model.pkl".format(character))
wave_scaler = load_artifact("models\\{}_scaler.pkl".format(character))
drop_model = load_artifact("models\\drop_model.pkl")
drop_scaler = load_artifact("models\\drop_scaler.pkl")
retry_counter = 0
preparation_counter = 0
wave_counter = 0
drop_counter = 0
no_drop_counter = 0
state = "preparation"
def log(retry_counter, state, counter, limit, message):
print("[{}][{}][{}%] {}".format(retry_counter, state, round(counter/limit*100, 1), message))
if (counter == limit - 10 or counter >= limit):# and state == "menu":
telegram_log("\[{}]\[{}] {}".format(retry_counter, state, message))
with mss() as sct:
while "Screen capturing":
if retry_counter > RETRY_LIMIT:
log(retry_counter, state, retry_counter, RETRY_LIMIT, "RETRY_LIMIT reached. Exiting")
exit()
if state == "preparation":
preparation_counter += 1
log(retry_counter, state, preparation_counter, PREPARATION_LIMIT, "Preparing for battle")
if preparation_counter > PREPARATION_LIMIT:
pyautogui.click(x=930, y=300, interval=2)
pyautogui.click(x=930, y=900)
log(retry_counter, state, preparation_counter, PREPARATION_LIMIT, "Battle starts")
state = "battle"
preparation_counter = 0
wave = capture_wave(sct, WAVE_BOUNDARY)
if state == "battle":
height, width = wave.shape
wave_prediction = wave_model.predict(wave_scaler.transform([wave.reshape(height*width,)]))[0]
if wave_prediction == 1:
log(retry_counter, state, wave_counter, WAVE_LIMIT, "Wave 3 Detected")
wave_counter += 1
if wave_counter > WAVE_LIMIT:
log(retry_counter, state, wave_counter, WAVE_LIMIT, "Pressing 'ESC' now.")
pyautogui.click(x=930, y=300, interval=0.5)
pyautogui.press('escape')
state = "menu"
wave_counter = 0
drop = capture_drop(sct, DROP_BOUNDARY)
if state == "menu":
height, width = drop.shape
drop_prediction = drop_model.predict(drop_scaler.transform([drop.reshape(height*width,)]))[0]
if drop_prediction == 1:
log(retry_counter, state, drop_counter, DROP_LIMIT, "PURPLE DROP DETECTED!")
drop_counter += 1
if drop_counter > DROP_LIMIT:
log(retry_counter, state, drop_counter, DROP_LIMIT, "PURPLE DROP FOUND! Exiting.")
state == "battle"
no_drop_counter = 0
drop_counter = 0
exit()
if drop_prediction == 0:
log(retry_counter, state, no_drop_counter, DROP_LIMIT, "No Purple Drop.")
no_drop_counter += 1
if no_drop_counter > DROP_LIMIT:
log(retry_counter, state, no_drop_counter, DROP_LIMIT, "No Purple Drop. Quitting Battle")
pyautogui.click(x=930, y=775, interval=2)
pyautogui.click(x=930, y=775)
retry_counter += 1
state = "preparation"
no_drop_counter = 0
drop_counter = 0
# Press "q" to quit
if cv2.waitKey(25) & 0xFF == ord("q"):
cv2.destroyAllWindows()
break