This repository has been archived by the owner on May 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
tft.py
222 lines (170 loc) · 5.94 KB
/
tft.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
# Detergent's TFT Bot
# Branch: main
import pkg_resources
import pyautogui as auto
from python_imagesearch.imagesearch import imagesearch as search
import time
from printy import printy
pkg_resources.require("PyAutoGUI==0.9.50")
pkg_resources.require("opencv-python==4.5.1.48")
pkg_resources.require("python-imageseach-drov0==1.0.6")
auto.FAILSAFE = False
global gamecount
gamecount = 0
global Version
Version = "10.0.01"
# Start utility methods
def onscreen(path, precision=0.8):
return search(path, precision)[0] != -1
def search_to(path):
pos = search(path)
if onscreen(path):
auto.moveTo(pos)
return pos
def click_key(key, delay=.1):
auto.keyDown(key)
time.sleep(delay)
auto.keyUp(key)
def click_left(delay=.1):
auto.mouseDown()
time.sleep(delay)
auto.mouseUp()
def click_right(delay=.1):
auto.mouseDown(button='right')
time.sleep(delay)
auto.mouseUp(button='right')
def click_to(path, delay=.1):
if onscreen(path):
auto.moveTo(search(path))
click_left(delay)
# End utility methods
# Start main process
def queue():
if onscreen("./captures/tft logo.png"):
click_to("./captures/find match ready.png")
while not onscreen("./captures/loading.png"):
time.sleep(1)
click_to("./captures/accept.png")
global starttimer
starttimer = time.time()
print("Loading!")
loading()
def loading():
while not onscreen("./captures/1-1.png"):
time.sleep(1)
print("Match starting!")
start()
def start():
while onscreen("./captures/1-1.png"):
auto.moveTo(888, 376)
click_right()
print("In the match now!")
main()
def buy(iterations):
for i in range(iterations):
click_to("./captures/trait/dragonlord.png")
click_to("./captures/trait/invoker.png")
def checks(): # checks to see if game was interrupted
if onscreen("./captures/play again.png"):
won_match()
if onscreen("./captures/dead.PNG"): # check for loss
click_to("./captures/dead.PNG")
won_match()
if onscreen("./captures/reconnect.png"):
print("reconnecting!")
time.sleep(0.5)
click_to("./captures/reconnect.png")
def main():
while not onscreen("./captures/2-4.png"):
buy(5)
time.sleep(1)
checks()
while onscreen("./captures/2-4.png"):
auto.moveTo(928, 396)
click_right()
time.sleep(0.25)
time.sleep(5)
if onscreen("./captures/2-5.png"):
while not onscreen("./captures/3-2.png"): # change this if you want to surrender at a different stage, also the image recognition struggles with 5 being it sees it as 3 so i had to do 6 as that's seen as a 5
buy(5)
click_to("./captures/reroll.png")
time.sleep(1)
checks()
print("Surrendering now!")
surrender()
def end_match():
while not onscreen("./captures/find match ready.png"): # added a main loop for the end match function to ensure you make it to the find match button.
while onscreen("./captures/missions ok.png"):
click_to("./captures/missions ok.png")
time.sleep(2)
while onscreen("./captures/skip waiting for stats.png"):
click_to("./captures/skip waiting for stats.png")
time.sleep(5)
while onscreen("./captures/play again.png"):
click_to("./captures/play again.png")
while onscreen("./captures/play.png"):
click_to("./captures/play.png")
time.sleep(5)
while onscreen("./captures/confirm.png"):
click_to("./captures/confirm.png")
time.sleep(5)
def won_match():
print_timer()
time.sleep(3)
end_match()
time.sleep(5)
print("Queuing up again!")
queue()
def surrender():
click_to("./captures/settings.png")
while not onscreen("./captures/surrender 1.png"):
click_to("./captures/settings.png") # just in case it gets interrupted or misses
time.sleep(1)
while not onscreen("./captures/surrender 2.png"):
click_to("./captures/surrender 1.png")
checks()
time.sleep(1)
click_to("./captures/surrender 2.png")
time.sleep(10)
time.sleep(1)
end_match()
time.sleep(5)
print_timer()
print("Queuing up again! (Surrender)")
queue()
def print_timer():
global gamecount
global endtimer
endtimer = time.time()
gamecount += 1
sec = (endtimer - starttimer)
hours = sec // 3600
sec = sec - hours*3600
mu = sec // 60
ss = sec - mu*60
gamecount2 = str(gamecount)
#result_list = str(datetime.timedelta(seconds=sec)).split(".")
print("-------------------------------------")
print("Game End")
print("Play Time : ", int(float(hours)), "Hour", int(float(mu)), "Min", int(float(ss)), "Sec")
print("Gamecount : ", gamecount2)
print("-------------------------------------")
print("Queuing up again!")
# End main process
# Start auth + main script
print("Developed by:")
printy(r"""
[c>] _____ _ _ @
[c>]| __ \ | | | | @
[c>]| | | | ___| |_ ___ _ __ __ _ ___ _ __ | |_ @
[c>]| | | |/ _ \ __/ _ \ '__/ _` |/ _ \ '_ \| __|@
[c>]| |__| | __/ || __/ | | (_| | __/ | | | |_ @
[c>]|_____/ \___|\__\___|_| \__, |\___|_| |_|\__|@
[c>] __/ | @
[c>] |___/ @
""")
printy(f"Welcome! You're running Detergent's TFT bot.\nPlease feel free to ask questions or contribute at https://github.com/Detergent13/tft-bot", "nB")
auto.alert("Press OK when you're in a TFT lobby!\n")
print("Bot started, queuing up!")
queue()
# End auth + main script