added craft bot
This commit is contained in:
93
craft_table/craft_overlay.py
Normal file
93
craft_table/craft_overlay.py
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
# Run tkinter code in another thread
|
||||||
|
import threading
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import ttk
|
||||||
|
|
||||||
|
|
||||||
|
class CraftOverlay(threading.Thread):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
threading.Thread.__init__(self)
|
||||||
|
|
||||||
|
self.run_mode = 'init'
|
||||||
|
|
||||||
|
self.root = tk.Tk
|
||||||
|
|
||||||
|
self.crafts_use = tk.StringVar
|
||||||
|
self.mode_use = tk.StringVar
|
||||||
|
|
||||||
|
self.CraftsLabel = tk.Label
|
||||||
|
self.CraftsEntry = tk.Entry
|
||||||
|
self.ModeLabel = tk.Label
|
||||||
|
self.Mode_Box = ttk.Combobox
|
||||||
|
self.ButtonFrame = tk.Frame
|
||||||
|
|
||||||
|
self.StartButton = tk.Button
|
||||||
|
self.StopButton = tk.Button
|
||||||
|
self.TkPosition = '133x92+60+600'
|
||||||
|
|
||||||
|
self.StatusLabel = tk.Label
|
||||||
|
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.root = tk.Tk()
|
||||||
|
|
||||||
|
self.crafts_use = tk.StringVar(self.root, value='100')
|
||||||
|
self.mode_use = tk.StringVar(self.root, value='m25x1')
|
||||||
|
|
||||||
|
self.CraftsLabel = tk.Label(self.root, text="Crafts:", font=("Helvetica", 10, "bold"),
|
||||||
|
background="grey")
|
||||||
|
self.CraftsLabel.grid(row=0, column=0, sticky='w')
|
||||||
|
self.CraftsEntry = tk.Entry(self.root, textvariable=self.crafts_use, font=("Helvetica", 10, "bold"), width='12')
|
||||||
|
|
||||||
|
self.CraftsEntry.grid(row=0, column=1, columnspan=2)
|
||||||
|
|
||||||
|
self.ModeLabel = tk.Label(self.root, text="Mode:", font=("Helvetica", 10, "bold"),
|
||||||
|
background="grey")
|
||||||
|
self.ModeLabel.grid(row=2, column=0, sticky='w')
|
||||||
|
self.Mode_Box = ttk.Combobox(self.root, textvariable=self.mode_use, font=("Helvetica", 8, "bold"),
|
||||||
|
width='11')
|
||||||
|
self.Mode_Box['values'] = ('m25x1', 'm10x2', 'm5x3', 'simple', 'm1x5_T', 'm1x5_X', 'house')
|
||||||
|
|
||||||
|
self.Mode_Box.grid(row=2, column=1, columnspan=2, sticky='w')
|
||||||
|
|
||||||
|
self.ButtonFrame = tk.Frame(self.root)
|
||||||
|
self.StartButton = tk.Button(self.ButtonFrame, text="Start", command=self.start_button_callback, width='8')
|
||||||
|
self.StartButton.grid(row=0, column=0)
|
||||||
|
self.StopButton = tk.Button(self.ButtonFrame, text="Stop", command=self.stop_button_callback, width='8',
|
||||||
|
state=tk.DISABLED)
|
||||||
|
self.StopButton.grid(row=0, column=1)
|
||||||
|
|
||||||
|
self.ButtonFrame.grid(row=3, column=0, columnspan=2)
|
||||||
|
|
||||||
|
self.StatusLabel = tk.Label(self.root, text="", font=("Helvetica", 10, "bold"),
|
||||||
|
background="grey")
|
||||||
|
self.StatusLabel.grid(row=4, column=0, columnspan=2)
|
||||||
|
|
||||||
|
# self.ClearButton.pack(side="top")
|
||||||
|
self.root.geometry(self.TkPosition)
|
||||||
|
self.root.overrideredirect(1) # fenster ohne aussen rum :-)
|
||||||
|
# self.root.attributes('-alpha', 0.7) # fenster transparent
|
||||||
|
self.root.attributes('-topmost', 1) # fenster immer im vordergrund
|
||||||
|
# self.root.wm_attributes("-disabled", True)
|
||||||
|
self.root.configure(background='black')
|
||||||
|
self.root.mainloop()
|
||||||
|
|
||||||
|
def start_button_callback(self):
|
||||||
|
self.StartButton.configure(state=tk.DISABLED)
|
||||||
|
self.StopButton.configure(state=tk.NORMAL)
|
||||||
|
self.StatusLabel.configure(text='')
|
||||||
|
self.run_mode = 'started'
|
||||||
|
|
||||||
|
def stop_button_callback(self):
|
||||||
|
self.StartButton.configure(state=tk.NORMAL)
|
||||||
|
self.StopButton.configure(state=tk.DISABLED)
|
||||||
|
self.run_mode = 'stopped'
|
||||||
|
|
||||||
|
def get_run_mode(self):
|
||||||
|
return self.run_mode
|
||||||
|
|
||||||
|
def update_status_label(self, mode, energy_to_go):
|
||||||
|
text = mode + ": " + str(energy_to_go)
|
||||||
|
self.StatusLabel.configure(text=text)
|
||||||
335
craft_table/main_craft.py
Normal file
335
craft_table/main_craft.py
Normal file
@@ -0,0 +1,335 @@
|
|||||||
|
from time import time
|
||||||
|
import sys
|
||||||
|
import cv2 as cv
|
||||||
|
import keyboard
|
||||||
|
from utils import get_click_point, dig_point, check_for_ok_button, check_for_craft_button
|
||||||
|
import pydirectinput
|
||||||
|
from craft_overlay import CraftOverlay
|
||||||
|
from config_file import UserConfigs
|
||||||
|
from window_capture import WindowCapture
|
||||||
|
from vision import Vision
|
||||||
|
|
||||||
|
MODE25X1 = "m25x1"
|
||||||
|
MODE10X2 = "m10x2"
|
||||||
|
MODE5X3 = "m5x3"
|
||||||
|
MODE_SIMPLE_STACK = "simple"
|
||||||
|
MODE1X5_T = "m1x5_T"
|
||||||
|
MODE1X5_X = "m1x5_X"
|
||||||
|
MODE_HOUSE = "house"
|
||||||
|
|
||||||
|
def run():
|
||||||
|
overlay = CraftOverlay()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
overlay.update_status_label("stopped", "0")
|
||||||
|
overlay.run_mode = 'init'
|
||||||
|
continue
|
||||||
|
elif overlay.run_mode == 'started':
|
||||||
|
cv.waitKey(500)
|
||||||
|
elif overlay.run_mode == 'init':
|
||||||
|
continue
|
||||||
|
elif overlay.run_mode == 'finished':
|
||||||
|
overlay.update_status_label("finished", "0")
|
||||||
|
overlay.run_mode = 'init'
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
#boelk
|
||||||
|
pass
|
||||||
|
|
||||||
|
mode = str(overlay.mode_use.get())
|
||||||
|
run_target = int(overlay.crafts_use.get())
|
||||||
|
|
||||||
|
run_counter = 0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
if run_counter >= run_target:
|
||||||
|
run_counter = 0
|
||||||
|
overlay.run_mode = 'finished'
|
||||||
|
break
|
||||||
|
|
||||||
|
ab1 = [420, 1180, 142, 142]
|
||||||
|
ab2 = [562, 1180, 142, 142]
|
||||||
|
ab3 = [704, 1180, 142, 142]
|
||||||
|
ab4 = [846, 1180, 142, 142]
|
||||||
|
ab5 = [986, 1180, 142, 142]
|
||||||
|
ab6 = [1128, 1180, 142, 142]
|
||||||
|
ab10 = [1698, 1180, 142, 142]
|
||||||
|
|
||||||
|
if mode == MODE25X1:
|
||||||
|
click_square_center(ab1)
|
||||||
|
|
||||||
|
# grid 770 1630 160 1020 172 o
|
||||||
|
dim = 172
|
||||||
|
for i in range(0, 5, 1):
|
||||||
|
for e in range(0, 5, 1):
|
||||||
|
click_square_center([770 + (i * dim), 160 + (e * dim), dim, dim])
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_craft_button()
|
||||||
|
|
||||||
|
for i in range(0, 5, 1):
|
||||||
|
for e in range(0, 5, 1):
|
||||||
|
collect_grid_reverse_click([770 + (i * dim), 160 + (e * dim), dim, dim])
|
||||||
|
run_counter = run_counter + 1
|
||||||
|
overlay.update_status_label(mode, run_target - run_counter)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
click_square_center(ab10)
|
||||||
|
elif mode == MODE10X2:
|
||||||
|
for r in range(0, 2, 1):
|
||||||
|
# grid 770 1630 160 1020 172
|
||||||
|
dim = 172
|
||||||
|
if r == 0:
|
||||||
|
click_square_center(ab1)
|
||||||
|
start = 0
|
||||||
|
target = 3
|
||||||
|
else:
|
||||||
|
click_square_center(ab2)
|
||||||
|
start = 1
|
||||||
|
target = 4
|
||||||
|
|
||||||
|
for i in range(start, target, 2):
|
||||||
|
for e in range(0, 5, 1):
|
||||||
|
click_square_center([770 + (i * dim), 160 + (e * dim), dim, dim])
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_craft_button()
|
||||||
|
|
||||||
|
for i in range(0, 4, 2):
|
||||||
|
for e in range(0, 5, 1):
|
||||||
|
collect_grid_reverse_click([770 + (i * dim), 160 + (e * dim), dim, dim])
|
||||||
|
run_counter = run_counter + 1
|
||||||
|
overlay.update_status_label(mode, run_target - run_counter)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
click_square_center(ab10)
|
||||||
|
elif mode == MODE5X3:
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
for r in range(0, 3, 1):
|
||||||
|
# grid 770 1630 160 1020 172oo
|
||||||
|
dim = 172
|
||||||
|
if r == 0:
|
||||||
|
click_square_center(ab1)
|
||||||
|
start = 0
|
||||||
|
target = 1
|
||||||
|
elif r == 1:
|
||||||
|
click_square_center(ab2)
|
||||||
|
start = 1
|
||||||
|
target = 2
|
||||||
|
else:
|
||||||
|
click_square_center(ab3)
|
||||||
|
start = 2
|
||||||
|
target = 3
|
||||||
|
|
||||||
|
for i in range(start, target, 1):
|
||||||
|
for e in range(0, 5, 1):
|
||||||
|
click_square_center([770 + (i * dim), 160 + (e * dim), dim, dim])
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_craft_button()
|
||||||
|
|
||||||
|
for i in range(0, 1, 1):
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
for e in range(0, 5, 1):
|
||||||
|
collect_grid_reverse_click([770 + (i * dim), 160 + (e * dim), dim, dim])
|
||||||
|
run_counter = run_counter + 1
|
||||||
|
overlay.update_status_label(mode, run_target - run_counter)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
click_square_center(ab10)
|
||||||
|
elif mode == MODE1X5_T:
|
||||||
|
dim = 172
|
||||||
|
|
||||||
|
tps = []
|
||||||
|
tps.append(ab1)
|
||||||
|
tps.append([770 + (0 * dim), 160 + (2 * dim), dim, dim])
|
||||||
|
tps.append([770 + (1 * dim), 160 + (2 * dim), dim, dim])
|
||||||
|
tps.append(ab2)
|
||||||
|
tps.append([770 + (2 * dim), 160 + (1 * dim), dim, dim])
|
||||||
|
tps.append([770 + (2 * dim), 160 + (2 * dim), dim, dim])
|
||||||
|
tps.append([770 + (2 * dim), 160 + (3 * dim), dim, dim])
|
||||||
|
|
||||||
|
result_tp = [770 + (0 * dim), 160 + (3 * dim), dim, dim]
|
||||||
|
|
||||||
|
for tp in tps:
|
||||||
|
click_square_center(tp)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_craft_button()
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
click_square_center(result_tp)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
click_square_center(ab10)
|
||||||
|
|
||||||
|
run_counter = run_counter + 1
|
||||||
|
overlay.update_status_label(mode, run_target - run_counter)
|
||||||
|
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
elif mode == MODE1X5_X:
|
||||||
|
dim = 172
|
||||||
|
|
||||||
|
tps = []
|
||||||
|
tps.append(ab1)
|
||||||
|
tps.append([770 + (0 * dim), 160 + (3 * dim), dim, dim])
|
||||||
|
tps.append([770 + (1 * dim), 160 + (3 * dim), dim, dim])
|
||||||
|
tps.append([770 + (2 * dim), 160 + (3 * dim), dim, dim])
|
||||||
|
tps.append([770 + (1 * dim), 160 + (4 * dim), dim, dim])
|
||||||
|
tps.append([770 + (1 * dim), 160 + (2 * dim), dim, dim])
|
||||||
|
|
||||||
|
result_tp = [770 + (0 * dim), 160 + (4 * dim), dim, dim]
|
||||||
|
|
||||||
|
for tp in tps:
|
||||||
|
click_square_center(tp)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_craft_button()
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
click_square_center(result_tp)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
click_square_center(ab10)
|
||||||
|
|
||||||
|
run_counter = run_counter + 1
|
||||||
|
overlay.update_status_label(mode, run_target - run_counter)
|
||||||
|
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
elif mode == MODE_HOUSE:
|
||||||
|
dim = 172
|
||||||
|
|
||||||
|
cements = []
|
||||||
|
cements.append([770 + (0 * dim), 160 + (4 * dim), dim, dim])
|
||||||
|
cements.append([770 + (1 * dim), 160 + (4 * dim), dim, dim])
|
||||||
|
cements.append([770 + (2 * dim), 160 + (4 * dim), dim, dim])
|
||||||
|
cements.append([770 + (3 * dim), 160 + (4 * dim), dim, dim])
|
||||||
|
cements.append([770 + (4 * dim), 160 + (4 * dim), dim, dim])
|
||||||
|
|
||||||
|
bricks = []
|
||||||
|
bricks.append([770 + (0 * dim), 160 + (3 * dim), dim, dim])
|
||||||
|
bricks.append([770 + (1 * dim), 160 + (3 * dim), dim, dim])
|
||||||
|
bricks.append([770 + (3 * dim), 160 + (3 * dim), dim, dim])
|
||||||
|
bricks.append([770 + (4 * dim), 160 + (3 * dim), dim, dim])
|
||||||
|
bricks.append([770 + (0 * dim), 160 + (2 * dim), dim, dim])
|
||||||
|
bricks.append([770 + (2 * dim), 160 + (2 * dim), dim, dim])
|
||||||
|
bricks.append([770 + (4 * dim), 160 + (2 * dim), dim, dim])
|
||||||
|
|
||||||
|
boards = []
|
||||||
|
boards.append([770 + (2 * dim), 160 + (3 * dim), dim, dim])
|
||||||
|
boards.append([770 + (0 * dim), 160 + (1 * dim), dim, dim])
|
||||||
|
boards.append([770 + (1 * dim), 160 + (1 * dim), dim, dim])
|
||||||
|
boards.append([770 + (2 * dim), 160 + (1 * dim), dim, dim])
|
||||||
|
boards.append([770 + (3 * dim), 160 + (1 * dim), dim, dim])
|
||||||
|
boards.append([770 + (4 * dim), 160 + (1 * dim), dim, dim])
|
||||||
|
boards.append([770 + (2 * dim), 160 + (0 * dim), dim, dim])
|
||||||
|
|
||||||
|
glasses = []
|
||||||
|
glasses.append([770 + (1 * dim), 160 + (2 * dim), dim, dim])
|
||||||
|
glasses.append([770 + (3 * dim), 160 + (2 * dim), dim, dim])
|
||||||
|
|
||||||
|
tp_hammer = [770 + (1 * dim), 160 + (0 * dim), dim, dim]
|
||||||
|
tp_nails = [770 + (3 * dim), 160 + (0 * dim), dim, dim]
|
||||||
|
tp_result = [770 + (0 * dim), 160 + (4 * dim), dim, dim]
|
||||||
|
|
||||||
|
click_square_center(ab1)
|
||||||
|
|
||||||
|
for cement in cements:
|
||||||
|
click_square_center(cement)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_square_center(ab2)
|
||||||
|
|
||||||
|
for brick in bricks:
|
||||||
|
click_square_center(brick)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_square_center(ab3)
|
||||||
|
|
||||||
|
for board in boards:
|
||||||
|
click_square_center(board)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_square_center(ab4)
|
||||||
|
|
||||||
|
for glass in glasses:
|
||||||
|
click_square_center(glass)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_square_center(ab5)
|
||||||
|
click_square_center(tp_hammer)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_square_center(ab6)
|
||||||
|
click_square_center(tp_nails)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_craft_button()
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
click_square_center(tp_result)
|
||||||
|
click_square_center(ab10)
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
|
||||||
|
run_counter = run_counter + 1
|
||||||
|
overlay.update_status_label(mode, run_target - run_counter)
|
||||||
|
|
||||||
|
if overlay.run_mode == 'stopped':
|
||||||
|
break
|
||||||
|
elif mode == MODE_SIMPLE_STACK:
|
||||||
|
# initialize the StunWindowCapture class
|
||||||
|
capture_config = UserConfigs()
|
||||||
|
#capture_window = WindowCapture(None, "screen_conf", capture_config)
|
||||||
|
|
||||||
|
capture_window2 = WindowCapture(None, "bla", capture_config)
|
||||||
|
|
||||||
|
# initialize the StunVision class
|
||||||
|
vision_stun = Vision()
|
||||||
|
# odig_overlay = DiggingOverlay(config)
|
||||||
|
check_for_craft_button(capture_window2, vision_stun, capture_config)
|
||||||
|
run_counter = run_counter + 1
|
||||||
|
overlay.update_status_label(mode, run_target - run_counter)
|
||||||
|
#check_for_ok_button(capture_window, vision_stun, capture_config)
|
||||||
|
|
||||||
|
def collect_grid_reverse_click(square):
|
||||||
|
pydirectinput.moveTo(get_click_point(square)[0], get_click_point(square)[1])
|
||||||
|
cv.waitKey(50)
|
||||||
|
pydirectinput.mouseUp()
|
||||||
|
cv.waitKey(50)
|
||||||
|
pydirectinput.mouseDown()
|
||||||
|
cv.waitKey(100)
|
||||||
|
|
||||||
|
def click_craft_button():
|
||||||
|
dig_point(1910, 330, 100)
|
||||||
|
cv.waitKey(1500)
|
||||||
|
|
||||||
|
|
||||||
|
def click_square_center(square):
|
||||||
|
cp = get_click_point(square)
|
||||||
|
dig_point(cp[0], cp[1], 100)
|
||||||
|
cv.waitKey(100)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run()
|
||||||
|
sys.exit()
|
||||||
BIN
craft_table/ok_button.jpg
Normal file
BIN
craft_table/ok_button.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
BIN
craft_table/play.jpg
Normal file
BIN
craft_table/play.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
BIN
craft_table/screen_panel.jpg
Normal file
BIN
craft_table/screen_panel.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 659 KiB |
Reference in New Issue
Block a user