Files
Litcraft_Python_B/craft_table/main_craft.py

338 lines
12 KiB
Python

from time import time
import sys
import cv2 as cv
import keyboard
from utils import get_click_point, dig_point, check_for_craft_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(1000)
elif overlay.run_mode == 'init':
cv.waitKey(1)
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)
check_for_craft_ok_button(capture_window2, vision_stun)
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()