Untitled
unknown
plain_text
10 months ago
12 kB
12
Indexable
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 = (0, 0, 2560, 1440) # Full screen for jump (left, top, width, height)
# 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.05 # Reduced for faster response
pyautogui.MINIMUM_SLEEP = 0.02 # Reduced for faster response
pyautogui.PAUSE = 0.1 # 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."""
current_x, current_y = pyautogui.position()
# Faster movement for JUMP_COLOR
duration = random.uniform(0.01, 0.03) if fast else random.uniform(0.05, 0.15)
pyautogui.moveTo(x + random.randint(-1, 1), y + random.randint(-1, 1), duration=duration)
time.sleep(random.uniform(0.002, 0.01) 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
dx = random.randint(-8, 8) if fast else random.randint(-12, 12)
dy = random.randint(-5, 1) if fast else 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.01, 0.05) if fast else random.uniform(0.05, 0.2))
human_move_to(x_final, y_final, fast=fast)
pyautogui.mouseDown()
time.sleep(random.uniform(0.005, 0.02) if fast else random.uniform(0.05, 0.35))
pyautogui.mouseUp()
time.sleep(random.uniform(0.01, 0.05) 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}), offset: ({dx:+d},{dy:+d})")
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)
for dx in [-1, 0, 1]:
for dy in [-1, 0, 1]:
px = rel_x + dx
py = rel_y + dy
if 0 <= px < region[2] and 0 <= py < region[3]:
pixel = screenshot.getpixel((px, py))
if is_color_within_tolerance(pixel, color, COLOR_TOLERANCE):
return True
return False
else:
for dx in [-1, 0, 1]:
for dy in [-1, 0, 1]:
pixel = pyautogui.pixel(x + dx, y + dy)
if is_color_within_tolerance(pixel, color, COLOR_TOLERANCE):
return True
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))
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)
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()
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
last_right_click_time = time.time()
next_right_click_interval = random.uniform(300, 1500) # 5–25 min
# Routine timers
last_routine_time = time.time()
next_routine_interval = random.uniform(300, 900) # 5–15 min
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)
else:
for dx, dy in [(5, 0), (-5, 0), (0, 5), (0, -5)]:
offset_pos = (jump_pos[0] + dx, jump_pos[1] + dy)
if verify_color_at_position(JUMP_COLOR, offset_pos[0], offset_pos[1], TREE_SEARCH_REGION):
human_move_to(offset_pos[0], offset_pos[1], fast=True)
human_click_random(fast=True)
break
click_time = time.time()
while find_color_center(JUMP_COLOR, region=search_region):
if time.time() - click_time >= JUMP_TIMEOUT:
new_jump_pos = find_color_center(JUMP_COLOR, region=search_region)
if new_jump_pos:
jump_pos = new_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)
else:
for dx, dy in [(5, 0), (-12, 0), (0, 5), (0, -12)]:
offset_pos = (jump_pos[0] + dx, jump_pos[1] + dy)
if verify_color_at_position(JUMP_COLOR, offset_pos[0], offset_pos[1], TREE_SEARCH_REGION):
human_move_to(offset_pos[0], offset_pos[1], fast=True)
human_click_random(fast=True)
break
click_time = time.time()
time.sleep(0.02) # Reduced 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(random.uniform(0.02, 0.1)) # Faster loop 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)) # Faster 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