Wednesday, December 29, 2010

FarmVille Bot

FarmVille is this "popular" game on Facebook.  In a nutshell, you're a farmer, and you just have to plant and harvest crops to level up.  It's a surprisingly addicting game.  However, the one turnoff is that it takes so long to individually click each field (those who play the game know what I'm talking about).  It can take up to 30 minutes if you have a large enough farm.

This program uses several of the C# classes I posted on my blog earlier:
C# Mouse
C# InputBox
C# FileSystemDialog

It also a class I made up for this program called the Location class.  If you want to look at it, then just download the source code (at the bottom of this post).

I developed a pretty easy to use tool for working on your farm (it works best if you have just a massive square of fields).  Refer to the image below:


What you have to do is tell it how many rows and columns of fields it has to work on and where the four corners of the rectangular region you want to harvest are.  TOP means the top-most field, LEFT means the left-most field, RIGHT means the right-most field, and BOTTOM means the bottom-most field.  I'm pretty sure you could have figured that one out.  To set these values, you have to select one of the boxes, and press space when your cursor is over the respective field.  The program will automatically rotate the selection counterclockwise, so I recommend starting at the TOP box and then going LEFT, BOTTOM, and RIGHT.  Also, I think it's best that you go to the market and select any crop so that you have your actually mouse pointer when you're setting these values.

The program will not click on the field indicated in the exceptions box.  Click "Add" to add an exception to the field given by the row and column in the rectangular region.  Keep in mind that the left-most field is at row and column 0 (ZERO).  For example, you'd use this to skip over the square that my guy is standing in at the center.  By the way, it's best that you fence in your character using hay bales so that he doesn't have to walk over to the fields to work on them.  It saves a lot of time.

Just hit the "Go!" button to begin the operation!  Watch as the program does all the work for you.  However, you can't minimize the FarmVille window until the program is done clicking on all the fields.  If it misses a few fields, you can probably click them yourself and then tweak the corner locations later.  If it totally fails, then you can just minimize the FarmVille window (or show desktop using the Windows Key + D) and then try again.

In the File menu, you can save your farm.  The program will automatically load the file called "Default.fvm" if it exists, so you are going to do the same farm over and over again, save it as "Default.fvm."  You can also load existing farms.  Also, just in case you forgot to save your farm, it creates a file called "LastFarm.fvm" automatically.  It will be overwritten the next time you exit the program, so make sure that rename this file to something else if you want to keep it.  Keep in mind that the program can only read and write .FVM files.

A hint to those who have irregularly shaped farms (that aren't rectangular or square).  You should divide your farm into as few rectangles as possible, and make a save file for each of those rectangles.

You can download the program here ("FarmVille Master.exe").
You can also get the C# source code here ("FarmVille Master.zip").

Have fun winning at FarmVille!

No comments:

Post a Comment