diff --git a/traderv2.py b/traderv2.py index c0a2fbb..75979a2 100644 --- a/traderv2.py +++ b/traderv2.py @@ -52,6 +52,17 @@ def shift_click(x, y): time.sleep(0.5) # Added delay before releasing shift subprocess.run(['xdotool', 'keyup', 'shift']) +def hold_key_for_duration(key, duration): + log_and_print(f"Waiting 5 seconds before holding '{key}' key for {duration} seconds.") + time.sleep(5) # Delay for 5 seconds + log_and_print(f"Holding '{key}' key.") + subprocess.run(['xdotool', 'keydown', key]) + time.sleep(duration) + subprocess.run(['xdotool', 'keyup', key]) + log_and_print(f"Released '{key}' key.") + + + def move_mouse(x, y): subprocess.run(['xdotool', 'mousemove', str(x), str(y)]) @@ -61,69 +72,29 @@ def shift_double_click(x, y): subprocess.run(['xdotool', 'click', '--repeat', '2', '--delay', '100', '1']) subprocess.run(['xdotool', 'keyup', 'shift']) -def find_and_interact_with_chest(chest_x, chest_y, action_function): - """General function for interacting with a chest and performing an action.""" - click(chest_x, chest_y) # Adjust these coordinates to the chest's position - time.sleep(2) # Wait for the chest to open - action_function() # Perform the defined action (fill or dump) - subprocess.run(['xdotool', 'key', 'Escape']) # Close chest +def fill_inventory_with_emeralds(): + log_and_print("Opening emerald chest...") + right_click(1168, 306) + time.sleep(2) # Wait a moment for the chest to open + cord1 = (2507, 977) + cord2 = (2561, 975) + log_and_print("Selecting emeralds...") + click(cord1[0], cord1[1]) # Move to cord1 and left-click to select emeralds + + log_and_print("Transferring emeralds to inventory...") + shift_double_click(cord2[0], cord2[1]) # Move to cord2 and shift-left-click to transfer emeralds + + log_and_print("Closing chest...") + subprocess.run(['xdotool', 'key', 'Escape']) # Press Esc to exit the chest time.sleep(1) -def fill_up_emeralds(): - """Function to be passed to find_and_interact_with_chest for filling up on emeralds.""" - log_and_print("Filling up on emeralds...") - # Implement your logic here for filling up on emeralds - # For example, shift_double_click on the emerald stack position - shift_double_click(2506, 978, 2561, 978) # Adjust coordinates to your setup - -first_run = True # Flag to check if it's the first run - -def focus_minecraft_window(): - global first_run - log_and_print("Focusing Minecraft window...") - subprocess.run(['xdotool', 'search', '--name', 'Minecraft*3.20.2 - Multiplayer (3rd-party-Server)', 'windowactivate', '--sync']) - time.sleep(2) - - if first_run: - log_and_print("Pressing Esc (first run only)...") - subprocess.run(['xdotool', 'key', 'Escape']) - time.sleep(2) - first_run = False # Set the flag to False after the first run - -def check_trade_window(): - log_and_print("Checking for trade window...") - trade_window_area = (2317, 994, 3126, 1472) # Defined area - screenshot = ImageGrab.grab(trade_window_area) - target_color = (178, 67, 32) # Target color for trade window - - for x in range(screenshot.width): - for y in range(screenshot.height): - if screenshot.getpixel((x, y))[:3] == target_color: - log_and_print("Trade window detected.") - return True - - 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): - for key, duration in adjustment_combinations: - subprocess.run(['xdotool', 'keydown', key]) - time.sleep(duration) - subprocess.run(['xdotool', 'keyup', key]) - time.sleep(0.1) - subprocess.run(['xdotool', 'click', '3']) - time.sleep(3) - screenshot = ImageGrab.grab(trade_window_area) - for x in range(screenshot.width): - for y in range(screenshot.height): - if screenshot.getpixel((x, y))[:3] == target_color: - log_and_print("Trade window detected after adjustment.") - return True - - log_and_print("Trade window not found after adjustments.") - post_to_discord("Trade window not found.") - return False - -successful_trades = 0 +def move_first_trade(): + log_and_print("Moveing to first trade") + # Prepare for the first trade + subprocess.run(['xdotool', 'keydown', 'a']) + time.sleep(0.25) + subprocess.run(['xdotool', 'keyup', 'a']) + time.sleep(1) # main function doing the trades and looking for red x as blocked trades def trade_actions(): @@ -131,7 +102,6 @@ def trade_actions(): trader_blocked = False # Initialize as False found_x, found_y = None, None # Initialize coordinates for XP potion - right_click(1168, 306) time.sleep(1) if not check_trade_window(): @@ -168,6 +138,7 @@ def trade_actions(): global_y = found_y + 994 # Add the top offset of the screenshot area click(global_x, global_y) shift_click(2990, 1119) + log_and_print("xp potion bought") break if found_x is not None: break @@ -177,33 +148,95 @@ def trade_actions(): shift_click(2990, 1119) click(2551, 1365) shift_click(2552, 1433) + log_and_print("xp potion boght with fallback") # Exiting trade window and moving to next trade log_and_print("Exiting trade window.") subprocess.run(['xdotool', 'key', 'Escape']) time.sleep(1) - - if trader_blocked: - log_and_print("Trader was blocked. Moving to the next trader.") - else: - log_and_print("Trade successful. Moving to the next trader.") - successful_trades += 1 # Increment only if trade was successful + log_and_print("Trade successful. Moving to the next trader.") + successful_trades += 1 # Increment only if trade was successful # Prepare for the next trade subprocess.run(['xdotool', 'keydown', 'a']) - time.sleep(0.45) + time.sleep(0.35) subprocess.run(['xdotool', 'keyup', 'a']) time.sleep(1) return not trader_blocked # Return True if trade was successful, False otherwise -def hold_key_for_duration(key, duration): - log_and_print(f"Waiting 5 seconds before holding '{key}' key for {duration} seconds.") - time.sleep(5) # Delay for 5 seconds - log_and_print(f"Holding '{key}' key.") - subprocess.run(['xdotool', 'keydown', key]) - time.sleep(duration) - subprocess.run(['xdotool', 'keyup', key]) - log_and_print(f"Released '{key}' key.") + +def check_trade_window(): + log_and_print("Checking for trade window...") + trade_window_area = (2317, 994, 3126, 1472) # Defined area + screenshot = ImageGrab.grab(trade_window_area) + target_color = (178, 67, 32) # Target color for trade window + + #use right click to check for trade window + log_and_print("useing right click to check for trade window") + right_click(1168, 306) + + for x in range(screenshot.width): + for y in range(screenshot.height): + if screenshot.getpixel((x, y))[:3] == target_color: + log_and_print("Trade window detected.") + return True + + 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): + for key, duration in adjustment_combinations: + subprocess.run(['xdotool', 'keydown', key]) + time.sleep(duration) + subprocess.run(['xdotool', 'keyup', key]) + time.sleep(0.1) + subprocess.run(['xdotool', 'click', '3']) + time.sleep(3) + screenshot = ImageGrab.grab(trade_window_area) + for x in range(screenshot.width): + for y in range(screenshot.height): + if screenshot.getpixel((x, y))[:3] == target_color: + log_and_print("Trade window detected after adjustment.") + return True + + log_and_print("Trade window not found after adjustments.") + post_to_discord("Trade window not found.") + return False + +successful_trades = 0 + + +def dump_xp_potions(): + log_and_print("Dumping XP potions into dump chest...") + right_click(1168, 306) + time.sleep(2) # Wait a moment for the chest to open + cord1 = (2937, 1515) + cord2 = (2881, 1514) + log_and_print("Selecting xp potions...") + click(cord1[0], cord1[1]) # Move to cord1 and left-click to select emeralds + + log_and_print("Transferring xp potions to dump cehst...") + shift_double_click(cord2[0], cord2[1]) # Move to cord2 and shift-left-click to transfer emeralds + + log_and_print("Closing chest...") + subprocess.run(['xdotool', 'key', 'Escape']) # Press Esc to exit the chest + time.sleep(1) + + +first_run = True # Flag to check if it's the first run + +def focus_minecraft_window(): + global first_run + log_and_print("Focusing Minecraft window...") + subprocess.run(['xdotool', 'search', '--name', 'Minecraft*3.20.2 - Multiplayer (3rd-party-Server)', 'windowactivate', '--sync']) + time.sleep(2) + + if first_run: + log_and_print("Pressing Esc (first run only)...") + subprocess.run(['xdotool', 'key', 'Escape']) + time.sleep(2) + first_run = False # Set the flag to False after the first run + + # Function to perform a cycle of trading actions def perform_trading_cycle(): @@ -211,12 +244,15 @@ def perform_trading_cycle(): successful_trades = 0 focus_minecraft_window() + fill_inventory_with_emeralds() # Fill up on emeralds before starting trades + move_first_trade() for _ in range(50): # Number of trades to perform if not trade_actions(): break # Stop the script if trade window is not detected - + dump_xp_potions() # Dump XP potions after completing trades + trade_summary = f"Trading session completed. Trades performed: {successful_trades}" post_to_discord(trade_summary)