From 87602935e2958ecb42ff293d9ed8bb953a7f7570 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 15 Dec 2023 12:54:29 +0100 Subject: [PATCH] fff --- trader_win.py | 87 ++++++++++++++------------------------------------- 1 file changed, 23 insertions(+), 64 deletions(-) diff --git a/trader_win.py b/trader_win.py index 9a6c72a..d153035 100644 --- a/trader_win.py +++ b/trader_win.py @@ -4,9 +4,6 @@ import time from PIL import ImageGrab import logging -pyautogui.FAILSAFE = False - - # Setup logging logging.basicConfig(filename='minecraft_automation_log.txt', level=logging.INFO, format='%(asctime)s: %(message)s') @@ -15,33 +12,29 @@ def log_and_print(message): logging.info(message) def post_to_discord(message): - webhook_url = 'https://discord.com/api/webhooks/1171735460729606145/Fyls4_uD7it29TNo7LktQFynb3k1K-BHLx9Y4WqzDK806o1_bVTNz94JNc996kDi-jE6' + webhook_url = 'https://discord.com/api/webhooks/1185180105287422052/Abdomr4QNsegWAg6so4vpdW8ohn6Y9Pnpk2debQRHCIeYsc8BSP3jKrDGM74Lxn7dTvF' data = {"content": message} response = requests.post(webhook_url, json=data) log_and_print(f"Posted to Discord: {message}") def right_click(x, y): - # Ensure the coordinates are safe and within your screen bounds - safe_x = min(max(x, 0), pyautogui.size().width - 1) - safe_y = min(max(y, 0), pyautogui.size().height - 1) - - pyautogui.moveTo(safe_x, safe_y) - log_and_print(f"Performing right click at ({safe_x}, {safe_y}).") + pyautogui.moveTo(x, y) + log_and_print(f"Performing right click at ({x}, {y}).") pyautogui.rightClick() def drag_slider(start_x, start_y, end_x, end_y): - log_and_print("Dragging slider.") + log_and_print(f"Dragging slider from ({start_x}, {start_y}) to ({end_x}, {end_y}).") pyautogui.mouseDown(start_x, start_y, button='left') pyautogui.moveTo(end_x, end_y, duration=2) pyautogui.mouseUp(button='left') def click(x, y): pyautogui.moveTo(x, y) - log_and_print("Performing left click.") + log_and_print(f"Performing left click at ({x}, {y}).") pyautogui.click() def shift_click(x, y): - log_and_print("Performing shift click.") + log_and_print(f"Performing shift click at ({x}, {y}).") pyautogui.keyDown('shift') click(x, y) pyautogui.keyUp('shift') @@ -56,73 +49,39 @@ def find_color_in_image(target_color, image): def check_trade_window(): log_and_print("Checking for trade window...") - trade_window_area = (2314, 974, 3124, 1455) + # Using the captured coordinates for the trade window check + trade_window_area = (835, 372, 836, 712) # Adjust as needed screenshot = ImageGrab.grab(trade_window_area) - r, g, b = screenshot.getpixel((51, 69))[:3] - if (r, g, b) == (137, 51, 24): + r, g, b = screenshot.getpixel((51, 69))[:3] # Adjust as needed for color check + if (r, g, b) == (137, 51, 24): # Update the color as per your requirement log_and_print("Trade window detected.") return True else: - log_and_print("Trade window not detected. Adjusting position.") - adjustment_combinations = [('a', 0.1), ('d', 0.1), ('a', 0.2), ('d', 0.2)] - for _ in range(5): # Try up to five times - for key, duration in adjustment_combinations: - pyautogui.keyDown(key) - time.sleep(duration) - pyautogui.keyUp(key) - time.sleep(0.1) - right_click(2725, 1203) # Right-click without moving the mouse - time.sleep(3) - screenshot = ImageGrab.grab(trade_window_area) - r, g, b = screenshot.getpixel((51, 69))[:3] - if (r, g, b) == (137, 51, 24): - log_and_print("Trade window detected after adjustment.") - return True - - log_and_print("Trade window not found after adjustments.") + log_and_print("Trade window not detected.") post_to_discord("Trade window not found.") return False def trade_actions(): - right_click(2725, 1203) + # Using the captured coordinates for actions + middle_x, middle_y = 960, 531 + slider_top_x, slider_top_y = 835, 372 + slider_bottom_x, slider_bottom_y = 836, 712 + xp_x, xp_y = 787, 721 + + right_click(middle_x, middle_y) # Right-click at the middle time.sleep(1) if not check_trade_window(): - log_and_print("Trade window not detected after adjustments. Stopping script.") + log_and_print("Trade window not detected. Stopping script.") return False - drag_slider(2600, 1399, 2600, 1408) + drag_slider(slider_top_x, slider_top_y, slider_bottom_x, slider_bottom_y) # Drag the slider time.sleep(3) - log_and_print("Taking a screenshot for color search...") - screenshot = ImageGrab.grab() - target_color = (222, 227, 114) # The color to search for - found_x, found_y = find_color_in_image(target_color, screenshot) + # Add your logic for interacting with the XP point or any other actions needed - for _ in range(2): - if found_x is not None and found_y is not None: - log_and_print(f"Color found at ({found_x}, {found_y}). Clicking at this position.") - click(found_x, found_y) - else: - log_and_print("Color not found on the screen. Using fallback coordinates.") - click(2535, 1421) - time.sleep(1) - - for _ in range(2): - click(found_x, found_y) - shift_click(2994, 1105) - time.sleep(1) - post_to_discord("Potion clicked.") - - log_and_print("Pressing 'Esc' key.") - pyautogui.press('esc') - time.sleep(1) - - log_and_print("Holding 'D' key for a step.") - pyautogui.keyDown('d') - time.sleep(0.45) # Hold 'D' for 0.45 seconds - pyautogui.keyUp('d') - time.sleep(1) + log_and_print("Completing trade actions.") + # Add any additional trade actions here return True # Indicate that the trade action was successful