-
Notifications
You must be signed in to change notification settings - Fork 75
/
fletching.py
603 lines (565 loc) · 19.9 KB
/
fletching.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
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
import os
import win32gui
import numpy as np
import cv2
import pyautogui
import random
import time
import win32gui
global hwnd
global iflag
global icoord
import core
import yaml
iflag = False
icoord = []
import functions
from functions import bank_ready, exit_bank, find_Object, pick_item, deposit_secondItem
def gfindWindow(data): # find window name returns PID of the window
global hwnd
hwnd = win32gui.FindWindow(None, data)
# hwnd = win32gui.GetForegroundWindow()860
#print('findWindow:', hwnd)
win32gui.SetActiveWindow(hwnd)
# win32gui.ShowWindow(hwnd)
win32gui.MoveWindow(hwnd, 0, 0, 865, 830, True)
with open("pybot-config.yaml", "r") as yamlfile:
data = yaml.load(yamlfile, Loader=yaml.FullLoader)
try:
gfindWindow(data[0]['Config']['client_title'])
except BaseException:
print("Unable to find window:", data[0]['Config']['client_title'], "| Please see list of window names below:")
core.printWindows()
pass
try:
x_win, y_win, w_win, h_win = core.getWindow(data[0]['Config']['client_title'])
except BaseException:
print("Unable to find window:", data[0]['Config']['client_title'], "| Please see list of window names below:")
core.printWindows()
pass
def wood_inv(wood):
counter = 0
myScreenshot = pyautogui.screenshot()
myScreenshot.save(r"screen.png")
img_rgb = cv2.imread('screen.png')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(str(wood), 0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
counter += 1
#cv2.imwrite('res.png', img_rgb)
return counter
# cv2.waitKey(0)
def Image_Single_clicker(image, event, threshold, clicker):
global icoord
global iflag
myScreenshot = pyautogui.screenshot()
#print('getting screenshot')
myScreenshot.save(r"screen.png")
img_rgb = cv2.imread('screen.png')
#print('screenshot taken')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(image, 0)
w, h = template.shape[::-1]
pt = None
#print('getting match requirements')
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = threshold
loc = np.where(res >= threshold)
#print('determine loc and threshold')
#if len(loc[0]) == 0:
#exit()
iflag = False
event = event
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
#print('result of pt')
if pt is None:
iflag = False
return None
#print(event, 'Not Found...')
else:
iflag = True
x = random.randrange(5, 20)
y = random.randrange(5, 20)
#cv2.imwrite('res.png', img_rgb)
#print(event, 'Found...')
icoord = pt[0] + x
icoord = (icoord, pt[1] + y)
b = random.uniform(0.01, 0.2)
pyautogui.moveTo(icoord, duration=b)
b = random.uniform(0.01, 0.13)
pyautogui.click(icoord, duration=b, button=clicker)
return icoord
def Image_Rec_clicker(image, event, threshold, clicker):
global icoord
global iflag
myScreenshot = pyautogui.screenshot()
#print('getting screenshot')
myScreenshot.save(r"screen.png")
img_rgb = cv2.imread('screen.png')
#print('screenshot taken')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(image, 0)
w, h = template.shape[::-1]
pt = None
#print('getting match requirements')
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = threshold
loc = np.where(res >= threshold)
#print('determine loc and threshold')
#if len(loc[0]) == 0:
#exit()
iflag = False
event = event
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
#print('result of pt')
if pt is None:
iflag = False
#print(event, 'Not Found...')
else:
iflag = True
x = random.randrange(5, 30)
y = random.randrange(5, 30)
#cv2.imwrite('res.png', img_rgb)
#print(event, 'Found...')
icoord = pt[0] + x
icoord = (icoord, pt[1] + y)
b = random.uniform(0.1, 0.17)
pyautogui.moveTo(icoord,duration=b)
b = random.uniform(0.01, 0.2)
pyautogui.click(icoord, duration=b, button=clicker)
return iflag
def Image_Rec_clicker2(image, event, iheight, iwidth, threshold, clicker):
global icoord
global iflag
myScreenshot = pyautogui.screenshot()
# print('getting screenshot')
myScreenshot.save(r"screen.png")
img_rgb = cv2.imread('screen.png')
# print('screenshot taken')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(image, 0)
w, h = template.shape[::-1]
pt = None
# print('getting match requirements')
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = threshold
loc = np.where(res >= threshold)
# print('determine loc and threshold')
# if len(loc[0]) == 0:
# exit()
iflag = False
event = event
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
# print('result of pt')
if pt is None:
iflag = False
# print(event, 'Not Found...')
else:
iflag = True
# cv2.imwrite('res.png', img_rgb)
# print(event, 'Found...')
icoord = pt[0] + iheight
icoord = (icoord, pt[1] + iwidth)
b = random.uniform(0.1, 0.7)
pyautogui.moveTo(icoord, duration=b)
b = random.uniform(0.01, 0.3)
pyautogui.click(icoord, duration=b, button=clicker)
return iflag
def pick_string_bow_bank():
c = random.uniform(0.1, 0.9)
d = random.uniform(0.01, 0.15)
x = random.randrange(170, 195)
print('x: ', x)
y = random.randrange(150, 170)
b = random.uniform(0.1, 1.2)
pyautogui.moveTo(x, y, duration=b)
time.sleep(d)
pyautogui.click(button='right')
time.sleep(c)
w = random.randrange(0, 10) + x
print('x: ', x)
z = random.randrange(55, 60) + y
print('y: ', y)
pyautogui.moveTo(w, z, duration=b)
b = random.uniform(0.01, 0.19)
pyautogui.click(duration=b)
c = random.uniform(0.1, 2.6)
time.sleep(c)
c = random.uniform(0.1, 0.9)
d = random.uniform(0.05, 0.15)
x = random.randrange(460, 490)
print('x: ', x)
y = random.randrange(120, 130)
b = random.uniform(0.1, 1.2)
pyautogui.moveTo(x, y, duration=b)
time.sleep(d)
pyautogui.click(button='right')
time.sleep(c)
w = random.randrange(0, 10) + x
print('x: ', x)
z = random.randrange(55, 60) + y
print('y: ', y)
pyautogui.moveTo(w, z, duration=b)
b = random.uniform(0.01, 0.19)
pyautogui.click(duration=b)
c = random.uniform(0.1, 2.6)
time.sleep(c)
def pick_flecting_wood_bank():
c = random.uniform(0.1, 0.9)
d = random.uniform(0.01, 0.15)
x = random.randrange(125, 145)
print('x: ', x)
y = random.randrange(120, 130)
b = random.uniform(0.1, 1.2)
pyautogui.moveTo(x, y, duration=b)
time.sleep(d)
pyautogui.click(button='right')
time.sleep(c)
w = random.randrange(0, 10) + x
print('x: ', x)
z = random.randrange(68, 72) + y
print('y: ', y)
pyautogui.moveTo(w, z, duration=b)
b = random.uniform(0.01, 0.19)
pyautogui.click(duration=b)
c = random.uniform(0.1, 2.6)
time.sleep(c)
def pick_roots_bank():
c = random.uniform(0.1, 0.9)
d = random.uniform(0.01, 0.15)
x = random.randrange(125, 145)
print('x: ', x)
y = random.randrange(120, 130)
b = random.uniform(0.1, 1.2)
pyautogui.moveTo(x, y, duration=b)
time.sleep(d)
pyautogui.click(button='right')
time.sleep(c)
w = random.randrange(0, 10) + x
print('x: ', x)
z = random.randrange(68, 72) + y
print('y: ', y)
pyautogui.moveTo(w, z, duration=b)
b = random.uniform(0.1, 0.19)
pyautogui.click(duration=b)
c = random.uniform(0.1, 2.6)
time.sleep(c)
def skill_lvl_up():
counter = 0
myScreenshot = pyautogui.screenshot()
myScreenshot.save(r"screen.png")
img_rgb = cv2.imread('screen.png')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('images/Congrats_flag.png', 0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where(res >= threshold)
for pt in zip(*loc[::-1]):
#cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
counter += 1
#cv2.imwrite('res.png', img_rgb)
return counter
def make_crossbow_lumb_climbstairs_down():
c = random.uniform(6,8)
d = random.uniform(0.01, 0.15)
x = random.randrange(730, 750)
print('x: ', x)
y = random.randrange(170, 180)
print('y: ', y)
b = random.uniform(0.1, 0.7)
pyautogui.moveTo(x, y, duration=b)
time.sleep(d)
pyautogui.click(button='left')
time.sleep(c)
c = random.uniform(0.1, 2)
d = random.uniform(0.01, 0.15)
x = random.randrange(360, 390)
print('x: ', x)
y = random.randrange(425, 445)
print('y: ', y)
b = random.uniform(0.1, 0.7)
pyautogui.moveTo(x, y, duration=b)
time.sleep(d)
pyautogui.click(button='left')
time.sleep(c)
def make_crossbow_lumb_climbstairs_up():
c = random.uniform(8, 10)
d = random.uniform(0.01, 0.15)
x = random.randrange(200, 240)
print('x: ', x)
y = random.randrange(620, 650)
print('y: ', y)
b = random.uniform(0.1, 0.7)
pyautogui.moveTo(x, y, duration=b)
time.sleep(d)
pyautogui.click(button='left')
time.sleep(c)
pyautogui.press('1')
def make_crossbow_crafting_lumb():
c = random.uniform(8, 10)
d = random.uniform(0.01, 0.15)
x = random.randrange(490, 540)
print('x: ', x)
y = random.randrange(70, 115)
print('y: ', y)
b = random.uniform(0.1, 0.7)
pyautogui.moveTo(x, y, duration=b)
time.sleep(d)
pyautogui.click(button='left')
time.sleep(c)
pyautogui.press('1')
def make_crossbow_string_bank_lumb():
c = random.uniform(8, 10)
d = random.uniform(0.01, 0.15)
x = random.randrange(490, 540)
print('x: ', x)
y = random.randrange(70, 115)
print('y: ', y)
b = random.uniform(0.1, 0.7)
pyautogui.moveTo(x, y, duration=b)
time.sleep(d)
pyautogui.click(button='left')
time.sleep(c)
pyautogui.press('1')
def fletch_darts():
c = random.uniform(0.01, 0.1)
b = random.uniform(0.01, 0.05)
x = random.randrange(645, 665) # 950,960
y = random.randrange(495, 515) # 490,500
pyautogui.moveTo(x, y, duration=b)
b = random.uniform(0.01, 0.06)
pyautogui.click(duration=b)
time.sleep(c)
c = random.uniform(0.01, 0.10)
b = random.uniform(0.01, 0.05)
x = random.randrange(685, 705) # 950,960
y = random.randrange(495, 515) # 490,500
pyautogui.moveTo(x, y, duration=b)
b = random.uniform(0.01, 0.05)
pyautogui.click(duration=b)
time.sleep(c)
def fletch_bolts():
c = random.uniform(0.01, 0.13)
b = random.uniform(0.01, 0.091)
x = random.randrange(645, 665) # 950,960
y = random.randrange(495, 515) # 490,500
pyautogui.moveTo(x, y, duration=b)
b = random.uniform(0.01, 0.06)
pyautogui.click(duration=b)
time.sleep(c)
c = random.uniform(0.1, 1.2)
b = random.uniform(0.01, 0.12)
x = random.randrange(695, 715) # 950,960
y = random.randrange(495, 515) # 490,500
pyautogui.moveTo(x, y, duration=b)
b = random.uniform(0.01, 0.09)
pyautogui.click(duration=b)
time.sleep(c)
pyautogui.press('space')
time_start = time.time()
time_end = 0
c = random.uniform(12.5, 14.5)
while time_end < c:
if functions.make_enabled('make_how.png') == 1:
pyautogui.press('space')
time_end = time.time() - time_start
if skill_lvl_up() == 1:
break
time.sleep(0.1)
def string_bow(bow):
c = random.uniform(0.1, 1.5)
b = random.uniform(0.1, 0.44)
x = random.randrange(690, 715) # 950,960
y = random.randrange(495, 515) # 490,500
pyautogui.moveTo(x, y, duration=b)
b = random.uniform(0.01, 0.09)
pyautogui.click(duration=b)
time.sleep(c)
c = random.uniform(0.1, 1.5)
b = random.uniform(0.01, 0.12)
x = random.randrange(775, 795) # 950,960
y = random.randrange(570, 590) # 490,500
pyautogui.moveTo(x, y, duration=b)
b = random.uniform(0.01, 0.09)
pyautogui.click(duration=b)
time.sleep(c)
pyautogui.press(bow)
#c = random.uniform(6, 14.5)
#time.sleep(c)
def string_bows(name, x, y, x2, y2):
c = random.uniform(0.1, 6)
e = random.uniform(0.1, 0.9)
error_c = 0
while bank_ready(False) == False:
if error_c > 3:
exit()
find_Object(1)
c = random.uniform(1, 3)
time.sleep(c)
functions.deposit_all_Bank()
error_c += 1
pick_item(x, y)
pick_item(x2, y2)
exit_bank()
invent = functions.invent_enabled()
print(invent)
if invent == 0:
pyautogui.press('esc')
time_start = time.time()
time_end = 0
x = random.uniform(40, 45)
while wood_inv('images/stringbow_icon.png') > 0 or time_end < x:
Image_Rec_single_closest('images/stringbow_icon.png', 0.7, 'left')
e = random.uniform(0.1, 0.9)
time.sleep(e)
Image_Rec_single_closest(name, 0.95, 'left')
e = random.uniform(0.1, 0.9)
time.sleep(e)
pyautogui.press('space')
while skill_lvl_up() == 0:
time_end = time.time() - time_start
e = random.uniform(0.1, 0.4)
time.sleep(e)
while functions.make_enabled('make_string.png') == 1:
pyautogui.press('space')
e = random.uniform(0.1, 0.9)
time.sleep(e)
print('skills are: ', skill_lvl_up())
print('wood left: ', wood_inv('images/stringbow_icon.png'))
print('keep making money!!!')
if wood_inv('images/stringbow_icon.png') == 0:
break
if wood_inv('images/stringbow_icon.png') == 0:
break
if skill_lvl_up() == 1:
Image_Rec_single_closest('images/stringbow_icon.png', 0.7, 'left')
e = random.uniform(0.1, 0.9)
time.sleep(e)
Image_Rec_single_closest(name, 0.7, 'left')
e = random.uniform(0.1, 0.9)
time.sleep(e)
pyautogui.press('space')
time.sleep(c)
def Image_Rec_single_closest(image, threshold=0.7, clicker='left'):
functions.screen_Image(620, 480, 820, 750, 'closest.png')
img_rgb = cv2.imread('images/closest.png')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread(image, 0)
w, h = template.shape[::-1]
pt = None
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshold = threshold
loc = np.where(res >= threshold)
close_list = []
close_points = []
pos = pyautogui.position()
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0, 0, 255), 2)
close_list.append(abs(abs(pos[0] - pt[0]) + abs(pos[1] - pt[1])))
close_points.append(pt)
if pt is None:
print('not found')
return False
#cv2.imwrite('res.png', img_rgb)
pick_random_item = random.randrange(0, len(close_points))
#print(close_points)
#print("list: ", str(len(close_points)))
#min_value = min(close_list)
#min_index = close_list.index(min_value)
#coords = close_points[min_index]
coords = close_points[pick_random_item]
print(coords)
#print('min_value:', min_value, '| min_index:', min_index)
x = random.randrange(5, 20) + 620
y = random.randrange(5, 20) + 480
icoord = coords[0] + x
icoord = (icoord, coords[1] + y)
b = random.uniform(0.1, 0.7)
pyautogui.moveTo(icoord, duration=b)
b = random.uniform(0.01, 0.3)
pyautogui.click(icoord, duration=b, button=clicker)
return close_points
def fletch_bows(name, x_i, y_i, number, i=55):
error_c = 0
while bank_ready() == False:
if error_c > 3:
exit()
find_Object(1)
c = random.uniform(1, 3)
time.sleep(c)
error_c += 1
pick_item(x_i, y_i)
exit_bank()
invent = functions.invent_enabled()
print(invent)
if invent == 0:
pyautogui.press('esc')
time_start = time.time()
time_end = 0
x = random.uniform(i, i+5)
while wood_inv(name) > 0 and time_end < x:
invent = functions.invent_enabled()
print(invent)
if invent == 0:
pyautogui.press('esc')
e = random.uniform(0.1, 0.4)
time.sleep(e)
if Image_Single_clicker('images/knife.png', 'fletching bows', 0.7, 'left') is None:
Image_Single_clicker('images/chisel.png', 'fletching bows', 0.7, 'left')
e = random.uniform(0.1, 0.9)
time.sleep(e)
Image_Rec_single_closest(name, 0.7, 'left')
e = random.uniform(0.1, 1.1)
time.sleep(e)
pyautogui.press(number)
while skill_lvl_up() == 0 and time_end < x:
time_end = time.time() - time_start
print('time delay:', time_end)
print('wood left: ', wood_inv(name))
while functions.make_enabled() == 1:
pyautogui.press(number)
e = random.uniform(0.1, 0.9)
time.sleep(e)
if wood_inv(name) == 0:
break
if skill_lvl_up() == 1:
if Image_Single_clicker('images/knife.png', 'fletching bows', 0.7, 'left') is None:
Image_Single_clicker('images/chisel.png', 'fletching bows', 0.7, 'left')
e = random.uniform(0.1, 0.9)
time.sleep(e)
Image_Rec_single_closest(name, 0.7, 'left')
e = random.uniform(0.1, 0.4)
time.sleep(e)
pyautogui.press(number)
time.sleep(c)
j = round(6800/14)
while j > 0:
# string_bows used to string bows variables for function is:
# file path for the bows image, #images/magic_longbow.png #images/oak_longbow.png #images/maple_longbow.png
# the x and y for the bow item in the bank inventory
# the x and y for the bow string in the bank inventory
string_bows('images/magic_longbow.png', 327, 336, 378, 269)
# fletch_bows is used to fletch wood into shafts or bows. can also be used to cut gems into bolt tips.
# fletch bows variables are: # file path for the gem or the wood type: #ruby_icon #sapphire_icon #diamond_icon #wood_icon #oak_icon #maple_icon
# the x and y for the item in the bank inventory
# the number or space to press to make the type of bow, shafts or bolt tips.
# use 80 for making bolt tips else use 55 due to the timing of fletching items
#fletch_bows('images/ruby_icon.png', 330, 126, 'space', 80)
print('actions left:', j)
# fletch_bolts is used for adding feathers to shafts, bolt tips to bolts or arrow tips to shafts.
#fletch_bolts()
# fletch_darts are used to make unfinished dart tips with feathers or unfinished bolts with feathers
#fletch_darts()
j -= 1
#os.system('shutdown -s -f')
# use in idle pyautogui.displayMousePosition()
#import pyautogui