Last active
March 12, 2017 18:29
-
-
Save Neoklosch/d9336ad112437130aa8ceac8dc5b901a to your computer and use it in GitHub Desktop.
Simple Forge of Empires Collect Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import sys | |
import signal | |
import time | |
import pyscreenshot as ImageGrab | |
import ImageOps | |
from numpy import * | |
SLEEP_TIME = 1.2 | |
def click_left(x, y): | |
os.system('xdotool mousemove %d %d click 1' % (x, y)) | |
# coordinates = x, y, xdelta, ydelta | |
def get_pixel_color(coordinates): | |
im = ImageOps.grayscale(ImageGrab.grab(bbox=coordinates)) | |
a = array(im.getcolors()) | |
a = a.sum() | |
return a | |
def is_menu_opened(): | |
return get_pixel_color((244, 957, 245, 958)) == 187 | |
def is_active_help(coordinates): | |
return get_pixel_color(coordinates) == 10632 | |
def is_active_tavern(coordinates): | |
return get_pixel_color(coordinates) == 8759 | |
def is_loading(): | |
return get_pixel_color((600, 100, 650, 115)) != 1620 | |
def is_tavern_close_button_visible(): | |
return get_pixel_color((877, 835, 1044, 856)) == 23388 | |
def is_blueprint_overlay_visible(): | |
return get_pixel_color((968, 770, 1135, 789)) == 26414 | |
def collect_help(): | |
for pages in range(20): | |
for i in range(5): | |
xposition=264+(i*107) | |
xposition_delta=361+(i*107) | |
if is_active_help((xposition, 1040, xposition_delta, 1044)): | |
click_left(xposition + 10, 1040) | |
time.sleep(0.2) | |
while is_loading(): | |
while is_blueprint_overlay_visible(): | |
click_blueprint_close_button() | |
time.sleep(0.2) | |
click_next() | |
time.sleep(SLEEP_TIME) | |
def collect_taverns(): | |
for pages in range(20): | |
for i in range(5): | |
xposition=339+(i*107) | |
xposition_delta=361+(i*107) | |
if is_active_tavern((xposition, 1009, xposition_delta, 1031)): | |
click_left(xposition + 10, 1015) | |
while not is_tavern_close_button_visible(): | |
time.sleep(0.2) | |
click_tavern_close_button() | |
time.sleep(0.5) | |
click_next() | |
time.sleep(SLEEP_TIME) | |
def close_menu(): | |
if is_menu_opened(): | |
click_left(288, 910) | |
def open_menu(): | |
if not is_menu_opened(): | |
click_left(276, 1030) | |
def click_next(): | |
click_left(910, 990) | |
def click_beginning(): | |
click_left(240, 1025) | |
def click_friends(): | |
click_left(870, 910) | |
def click_strangers(): | |
click_left(740, 910) | |
def click_tavern_close_button(): | |
click_left(900, 845) | |
def click_blueprint_close_button(): | |
click_left(1025, 780) | |
def signal_handler(signal, frame): | |
print('Done...') | |
sys.exit(0) | |
def main(): | |
signal.signal(signal.SIGINT, signal_handler) | |
time.sleep(2) | |
open_menu() | |
time.sleep(SLEEP_TIME) | |
click_strangers() | |
time.sleep(SLEEP_TIME) | |
click_beginning() | |
time.sleep(SLEEP_TIME) | |
collect_help() | |
click_friends() | |
time.sleep(SLEEP_TIME) | |
click_beginning() | |
time.sleep(SLEEP_TIME) | |
collect_help() | |
click_beginning() | |
time.sleep(SLEEP_TIME) | |
collect_taverns() | |
time.sleep(SLEEP_TIME) | |
close_menu() | |
sys.exit(0) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment