Create trader.py
This commit is contained in:
42
trader.py
Normal file
42
trader.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import pyautogui
|
||||
import cv2
|
||||
import numpy as np
|
||||
import time
|
||||
|
||||
def capture_screen():
|
||||
# Capture the entire screen
|
||||
return pyautogui.screenshot()
|
||||
|
||||
def find_item(template_path):
|
||||
# Find an item in the screenshot based on a template image
|
||||
screenshot = np.array(capture_screen())
|
||||
template = cv2.imread(template_path, cv2.IMREAD_UNCHANGED)
|
||||
result = cv2.matchTemplate(screenshot, template, cv2.TM_CCOEFF_NORMED)
|
||||
_, max_val, _, max_loc = cv2.minMaxLoc(result)
|
||||
if max_val > 0.8: # Threshold for template matching
|
||||
return max_loc
|
||||
return None
|
||||
|
||||
def move_item(start_pos, end_pos):
|
||||
# Move an item from start_pos to end_pos
|
||||
pyautogui.moveTo(start_pos)
|
||||
pyautogui.mouseDown()
|
||||
pyautogui.moveTo(end_pos, duration=1)
|
||||
pyautogui.mouseUp()
|
||||
|
||||
def navigate_with_keys(keys, duration):
|
||||
# Navigate using keyboard keys
|
||||
for key in keys:
|
||||
pyautogui.keyDown(key)
|
||||
time.sleep(duration)
|
||||
for key in keys:
|
||||
pyautogui.keyUp(key)
|
||||
|
||||
# Example usage
|
||||
while True:
|
||||
emerald_pos = find_item('emerald_template.png')
|
||||
trade_pos = (200, 200) # Example position for the trade button
|
||||
if emerald_pos:
|
||||
move_item(emerald_pos, trade_pos)
|
||||
navigate_with_keys(['w', 'a'], 2) # Move forward and left for 2 seconds
|
||||
time.sleep(1) # Wait for a second before next iteration
|
||||
Reference in New Issue
Block a user