Skip to content

Instantly share code, notes, and snippets.

@netfeed
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save netfeed/f4cd11b6637c50f75421 to your computer and use it in GitHub Desktop.

Select an option

Save netfeed/f4cd11b6637c50f75421 to your computer and use it in GitHub Desktop.
Clicker Heroes (http://www.clickerheroes.com/) click bot
# the goal of the bot is to do as many clicks as possible and collect gold from candy when it appears
# works better in chrome than firefox (firefox might hang)
#
# > virtualenv venv
# > source venv/bin/activate
# > pip install PyUserInput python3-xlib
# > python chbot.py
#
# change GAME_UPPER_LEFT_X / Y to fit the game is located in your version
import logging
import sys
import time
from datetime import datetime, timedelta
from pymouse import PyMouse
FIRE_COUNTER = 5
GAME_UPPER_LEFT_X = 85
GAME_UPPER_LEFT_Y = 197
m = PyMouse()
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
ch.setFormatter(logging.Formatter('%(asctime)s - %(message)s'))
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
log.addHandler(ch)
def click(x,y):
m.click(GAME_UPPER_LEFT_X + x, GAME_UPPER_LEFT_Y + y)
class Skill(object):
def __init__(self, name, x, y, delta, fifth=False, pre=[], post=[]):
self.name = name
self.x = x
self.y = y
self.delta = delta
self.future = None
self.fifth = fifth
self.counter = 0
self.pre = pre
self.post = post
def is_ready(self):
return self.future == None or self.future < datetime.now()
def fire(self):
if not self.is_ready():
return
for skill in self.pre:
skill.fire()
click(self.x, self.y)
self.future = datetime.now() + timedelta(minutes = self.delta)
time.sleep(0.1) # might be needed, not sure yet
if not self.fifth or self.counter > FIRE_COUNTER:
log.debug("%s - next turn %s", self.name, self.future.strftime('%H:%M:%S'))
self.counter = 0
self.counter += 1
for skill in self.post:
skill.fire()
metal = Skill('Metal Detector', 605, 313, 40)
energize = Skill('Energize', 605, 553, 60)
skills = [
Skill('Change progression mode', 1115, 253, 0.08, fifth=True),
Skill('Dark Ritual', 605, 413, 480, pre=[energize]),
Skill('Clickstorm', 605, 163, 10),
Skill('Powersurge', 605, 213, 10),
Skill('Lucky Strikes', 605, 253, 30),
Skill('Golden Clicks', 605, 363, 60, post=[metal]),
Skill('Super clicks', 605, 463, 60, pre=[energize]),
]
while True:
for skill in skills:
skill.fire()
for i in range(10):
for j in range(125):
click(815 + (j % (i+1)), (253 + (j % (i+1)) * 10))
time.sleep(0.25)
# check for items
click(721, 397)
click(883, 413)
click(1045, 413)
click(525, 453)
click(525, 473)
click(735, 343)
click(735, 373)
click(735, 433)
click(855, 483)
# move the mouse somewhere so we can see that there's a pause
click(615, 103)
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment