How I made a python bot to automate a tactical mmorpg

Martin Lees
4 min readOct 31, 2017

--

This may seem like a simple task but it’s really not. I spent hours and hours on this program. And I’d like to share my experience and what I’ve learned with you.

The game

First what is it about ? the game is a 2d mmorpg, Wakfu http://wakfu.com/. I invite you to look it up, it’s honestly a great game, it’s a french game but it has an international server as well.

There are several mechanics in game. I’ll talk mainly about how I automated fights because I spent most of my time automating that game mechanic.

Fighting

The fight system is very close to final fantasy advance, you can have up to 6 players in a fight versus monsters.

For those of you who don’t know final fantasy tactics, it’s pretty simple :

You have a grid where both monsters and players are placed. They can move a fixed number of squares per turn, and have spells that have various effects (heal, damage, apply effects like stun etc) which have various range and area of effect.

Here you can fight a short video of a guy doing a dungeon (so several fights) so you can see how it looks :

https://www.youtube.com/watch?v=6y6V2VWXiN4

(ignore the french commentary)

Also note that each turn is 30 seconds so you can’t take too much time to compute.

Anti bot protection :

There is also a protection against abuse. Which took some time to beat as you can imagine. introducing, the capchat :

You have your character and a cat in front of you, around the cat you see three squares with numbers (ranging from 1 to 8). Around you you have 8 squares with every numbers.

You need to click on the squares around you that matches the squares around the cat.

This is a relatively easy task right ? simply run an image search algorithm and boom you’re done.

Yes except :

  • The grid tilted which means that you have to create squares out of diamonds (which means smaller images to compare and so more imprecisions). Unless you do an imagesearch which handles alpha channels but this adds lots of complexity and see point 2.
  • The numbers are constantly moving. See this small video :

https://www.youtube.com/watch?v=tZ5HmzbWg90

(actual protection starts at 1:13)

This is a 2 :

This is also a 2 taken a few second after :

And this is a 3 :

See where I’m going ? since the numbers are constantly moving and the difference is very subtle it’s almost impossible to classify them using traditional algorithms.

Automation

So we have a pretty complex game, how are we going to automate that ?

first we have to choose a language, I usually code bots in Autoit. It’s a GREAT language for automation, in fact it was designed for it. But I wanted my bot to be cross platform so I opted for python (3 obviously, for the love of god stop starting new project in python 2.7). because it’s pretty versatile, has some machine learning libraries (we’ll come to that later) and I find it pleasing to code with it.

It will take a long time to talk about my whole experience and so I will split that into several articles for an easier reading experience. this will be the summary of all the steps taken. Most of the following articles will be written to be kind of a tutorial or resources so future readers can find value individually in the articles.

You can find them all here if you want to skip ahead :

Part 1 : How I made a python bot to automate a tactical mmorpg Which explains my motivation and the game I’m automating.

Part 2 : How to control the mouse and keyboard with python for automation Which digs into the core functions that are needed for automation.

Part 3 : A wrapper that I made to easily implement image searching within your python program and how to use it : Easy Image recognition for automation with python

Part 4 : Why I had to use machine learning for bypassing the anti-bot security explains why I needed machine learning and how simple image recognition was not enough.

Part 5 : How I made my custom dataset for machine learning is kind of self explanatory.

Part 6 : The theory behind image recognition with ML : A crash course on image recognition with machine learning

part 7 : The practice, Image recognition with machine learning in python and tensorflow

part 8 : How to automate a program that has random bugs, and conclusion of my series

If you like my article, please come check out my blog to see more at https://brokencode.io/ :)

--

--