Untitled
Anonymous
Plain Text
09/17/2025 4:53 PM
10.3 KB
21
Indexable
Never
import pyautogui
import datetime
import keyboard
import time
from PIL import Image
import random
import math
# Colors (in hex, converted to RGB tuples)
JUMP_COLOR = (60, 0, 200) # Confirmed jump color (3C00C8)
COIN_COLOR = (255, 0, 255) # Pink coin color (FF00FF)
# Color tolerance for pixelated areas
COLOR_TOLERANCE = 40 # ±40 for each RGB channel to ensure detection
# Screen resolution (1440p)
SCREEN_WIDTH, SCREEN_HEIGHT = 2560, 1440 # Updated for 2560x1440
# Define regions based on 1440p (scaled coordinates)
COIN_SEARCH_REGION = (933, 533, 800, 533) # Central area for coins (left, top, width, height)
TREE_SEARCH_REGION = (640, 360, 1280, 720) # Reduced to central 1280x720 area for jumps
# Recovery click coordinates
RECOVERY_X, RECOVERY_Y = 2307, 57
# Routine2 fixed coordinates (approx)
ROUTINE2_X, ROUTINE2_Y = 2104, 1348
# Human-like mouse movement settings
pyautogui.MINIMUM_DURATION = 0.01 # Reduced for faster response
pyautogui.MINIMUM_SLEEP = 0.01 # Reduced for faster response
pyautogui.PAUSE = 0.05 # Reduced pause after each action
# Time thresholds (in seconds)
RECOVERY_THRESHOLD = 15 # Time to wait before recovery click
JUMP_TIMEOUT = 6 # Time to wait before retrying jump click
def human_move_to(x, y, fast=False):
"""Move mouse to (x, y) with minimal human-like randomness and varied speed."""
duration = 0.001 if fast else random.uniform(0.05, 0.15)
pyautogui.moveTo(x, y, duration=duration)
time.sleep(0.001 if fast else random.uniform(0.04, 0.2))
def human_click_random(x=None, y=None, fast=False):
"""Ihmismäisempi klikkaus isommalla satunnaisuudella ja logituksella."""
if x is None or y is None:
pos = pyautogui.position()
x, y = pos.x, pos.y
if fast:
dx = random.randint(-3, 3) # Minimal randomness for JUMP_COLOR
dy = random.randint(-3, 3)
x_final = x + dx
y_final = y + dy
else:
dx = random.randint(-12, 12)
dy = random.randint(-10, 1)
x_final = x + dx
y_final = y + dy
if random.random() < 0.3:
mid_x = x_final + random.randint(-5, 5)
mid_y = y_final + random.randint(-5, 5)
human_move_to(mid_x, mid_y, fast=fast)
time.sleep(random.uniform(0.05, 0.2))
human_move_to(x_final, y_final, fast=fast)
pyautogui.mouseDown()
time.sleep(0.001 if fast else random.uniform(0.05, 0.35))
pyautogui.mouseUp()
time.sleep(0.001 if fast else random.uniform(0.1, 1.0))
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"[{ts}] [CLICK] Klikattu kohtaan ({x_final},{y_final})")
def is_color_within_tolerance(pixel, target_color, tolerance):
return all(abs(pixel[i] - target_color[i]) <= tolerance for i in range(3))
def find_color_center(color, region=None):
screenshot = pyautogui.screenshot(region=region)
img = screenshot
matching_pixels = []
for x in range(img.width):
for y in range(img.height):
pixel = img.getpixel((x, y))
if is_color_within_tolerance(pixel, color, COLOR_TOLERANCE):
matching_pixels.append((x, y))
if not matching_pixels:
return None
avg_x = sum(x for x, _ in matching_pixels) // len(matching_pixels)
avg_y = sum(y for _, y in matching_pixels) // len(matching_pixels)
if region:
return avg_x + region[0], avg_y + region[1]
return avg_x, avg_y
def verify_color_at_position(color, x, y, region=None):
if region:
rel_x, rel_y = x - region[0], y - region[1]
if 0 <= rel_x < region[2] and 0 <= rel_y < region[3]:
screenshot = pyautogui.screenshot(region=region)
pixel = screenshot.getpixel((rel_x, rel_y))
return is_color_within_tolerance(pixel, color, COLOR_TOLERANCE)
else:
pixel = pyautogui.pixel(x, y)
return is_color_within_tolerance(pixel, color, COLOR_TOLERANCE)
return False
def shift_click(x, y):
keyboard.press('shift')
time.sleep(random.uniform(0.05, 0.1))
human_move_to(x, y)
human_click_random()
keyboard.release('shift')
def perform_random_right_click():
random_x = random.randint(0, SCREEN_WIDTH - 1)
random_y = random.randint(0, SCREEN_HEIGHT - 1)
human_move_to(random_x, random_y)
time.sleep(random.uniform(0.1, 0.3))
pyautogui.rightClick()
time.sleep(random.uniform(0.1, 0.3))
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"[{ts}] [RANDOM_RIGHT_CLICK] Suoritettu, seuraava {next_right_click_interval/60:.1f} min päästä")
def perform_routine():
clicks = random.randint(1, 3)
print(f"Performing routine with {clicks} random right-clicks...")
for _ in range(clicks):
x = random.randint(0, SCREEN_WIDTH - 1)
y = random.randint(0, SCREEN_HEIGHT - 1)
human_move_to(x, y)
pyautogui.rightClick()
delay = random.uniform(2, 10)
print(f"Routine click at ({x},{y}), waiting {delay:.2f}s")
time.sleep(delay)
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"[{ts}] [ROUTINE] Suoritettu, seuraava {next_routine_interval/60:.1f} min päästä")
def perform_routine2():
"""Routine2: click fixed area (2104, 1348) ± random offset, every 15–25 minutes."""
x = ROUTINE2_X + random.randint(-10, 10)
y = ROUTINE2_Y + random.randint(-10, 10)
print(f"Performing Routine2 click at ({x}, {y})")
human_move_to(x, y)
human_click_random()
ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print(f"[{ts}] [ROUTINE2] Suoritettu, seuraava {next_routine2_interval/60:.1f} min päästä")
def main():
print("Starting agility bot. Press 'q' to quit.")
time.sleep(3)
recovery_attempts = 0
max_recovery_attempts = 4
last_jump_time = time.time()
last_jump_pos = None
global last_right_click_time, next_right_click_interval
last_right_click_time = time.time()
next_right_click_interval = random.uniform(300, 1500) # 5–25 min
# Routine timers
global last_routine_time, next_routine_interval
last_routine_time = time.time()
next_routine_interval = random.uniform(300, 900) # 5–15 min
global last_routine2_time, next_routine2_interval
last_routine2_time = time.time()
next_routine2_interval = random.uniform(900, 1500) # 15–25 min
failed_coin_attempts = 0
while not keyboard.is_pressed('q'):
current_time = time.time()
# --- Routine check (5–15 min) ---
if current_time - last_routine_time >= next_routine_interval:
perform_routine()
last_routine_time = current_time
next_routine_interval = random.uniform(300, 900)
# --- Routine2 check (15–25 min) ---
if current_time - last_routine2_time >= next_routine2_interval:
perform_routine2()
last_routine2_time = current_time
next_routine2_interval = random.uniform(900, 1500)
# --- Random right-click check (5–25 min) ---
if current_time - last_right_click_time >= next_right_click_interval:
perform_random_right_click()
last_right_click_time = current_time
next_right_click_interval = random.uniform(300, 1500)
# --- Coin detection ---
coin_pos = find_color_center(COIN_COLOR, region=COIN_SEARCH_REGION)
if coin_pos:
if failed_coin_attempts < 2:
if verify_color_at_position(COIN_COLOR, coin_pos[0], coin_pos[1], COIN_SEARCH_REGION):
human_move_to(coin_pos[0], coin_pos[1])
human_click_random()
time.sleep(random.uniform(5, 7))
post_coin_pos = find_color_center(COIN_COLOR, region=COIN_SEARCH_REGION)
if post_coin_pos:
failed_coin_attempts += 1
print(f"Coin still present after click, attempts: {failed_coin_attempts}")
else:
failed_coin_attempts = 0
print("Coin collected successfully")
last_jump_time = time.time()
time.sleep(random.uniform(0.5, 1.5)) # Normal delay after coin
continue
else:
failed_coin_attempts = 0
# --- Jump detection ---
search_region = TREE_SEARCH_REGION if last_jump_pos else None
jump_pos = find_color_center(JUMP_COLOR, region=search_region)
if jump_pos:
if verify_color_at_position(JUMP_COLOR, jump_pos[0], jump_pos[1], TREE_SEARCH_REGION):
human_move_to(jump_pos[0], jump_pos[1], fast=True)
human_click_random(fast=True)
click_time = time.time()
while find_color_center(JUMP_COLOR, region=search_region):
if time.time() - click_time >= JUMP_TIMEOUT:
jump_pos = find_color_center(JUMP_COLOR, region=search_region)
if jump_pos:
human_move_to(jump_pos[0], jump_pos[1], fast=True)
human_click_random(fast=True)
click_time = time.time()
time.sleep(0.01) # Minimal delay in jump loop
if keyboard.is_pressed('q'):
break
last_jump_time = time.time()
last_jump_pos = jump_pos
recovery_attempts = 0
time.sleep(0.01) # Minimal delay after jump
continue
else:
if time.time() - last_jump_time >= RECOVERY_THRESHOLD:
if recovery_attempts < max_recovery_attempts:
shift_click(RECOVERY_X, RECOVERY_Y)
time.sleep(10)
recovery_attempts += 1
if find_color_center(JUMP_COLOR):
recovery_attempts = 0
last_jump_time = time.time()
last_jump_pos = None
continue
else:
break
time.sleep(random.uniform(0.05, 0.2)) # Main loop delay
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("Bot stopped by user.")
except Exception as e:
print(f"An error occurred: {e}")Editor is loading...
Leave a Comment