Part 3: Our first bot (WIP)

Our first bot (WIP)

1. The bot structure

The entry point for a bot (hereinafter “main class”) is the class which inherits from AbstractBot. There can only be one main class and it is responsible for fulfilling the contract of AbstractBot which means implementing the following methods:

  • Task<int> OnBotLoop – called repeatedly as long as the bot is running. Main logic goes here
  • List<AbstractModule> InitializeModules – should return all main/root modules of your bot

Optionally it may override the following:

  • Task<bool> OnBotStart – called when the bot gets started. Returns false if the bot for some reason shouldn’t start
  • void OnBotStop – called when the bot gets stopped

Additionally, the main class should be annotated by the Manifest attribute which specifies basic information about the bot such as its name, version, author etc.

Code for reference
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SkyBots.API.Framework;

namespace BotForGameX
{
    [Manifest("Hello World", 1.00, "com.sample.app", 0, 720, 1280)]
    class HelloWorld : AbstractBot
    {
        public override List<AbstractModule> InitializeModules()
        {
            throw new NotImplementedException();
        }

        public override async Task<int> OnBotLoop()
        {
            throw new NotImplementedException();
        }
    }
}

2. The GUI


3. The SkyBots developer tool

Our developer tool aids your bot development. It allows you to easily extract relevant data from the Android emulator:

  • RGB colors
  • Bitmaps
  • Coordinates
  • Colors

Additionally, you can test and run various algorithms:

  • Template matching
  • RGB finding
  • RGB distribution
  • OCR

You can launch it by pressing the “Developer” menu item.


4. Implementing an action

A bot can perform all in-game actions so in terms of code structure it would make sense to separate the code that performs separate actions. No clear separation = spaghetti code (we do not like spaghetti code) :spaghetti:.

A simple but powerful module based structure can help us implement and structure our actions.

What is a "module"?

A single bot module is in charge of performing a single action (e.g. collecting in-game resources)

Dictionary definition:

Modules inherit from either AbstractModule or TimeoutModule:

  • AbstractModule – general purpose modules
  • TimeoutModule – modules with some sort of timed behavior (e.g. do X action every Y minutes or don’t do action X until Y minutes have elapsed)

Any module must implement the following three methods:

  • Task<bool> Activate(Bitmap screenshot) – determines whether or not the module should run based on the screenshot
  • Task<bool> Run() – the actual module logic
  • string ToString() – the module name as shown to the user in the UI
Code for reference
using System.Drawing;
using System.Threading.Tasks;
using SkyBots.API.Execution;
using SkyBots.API.Framework;

namespace BotForGameX
{
    public class ClickRGB : AbstractModule
    {
        public ClickRGB(int priority, BotContext ctx) : base(priority, ctx)
        {
        }

        public override async Task<bool> Run()
        {
            throw new System.NotImplementedException();
        }

        public override async Task<bool> Activate(Bitmap screenshot)
        {
            throw new System.NotImplementedException();
        }

        public override string ToString() => throw new System.NotImplementedException();
    }
}

5. Testing the action


6. Finishing up

Pro tip: Use Git in conjunction with GitHub or GitLab for free version and release control.