Skip to main content

A Python package to write bots for the game Antorum!

Project description

Antorum Bot

Antorum Bot is a package that allows you to create a bot for the game Antorum. It is made by reverse engineering the game's network activity and is not officially supported by the game's developers.

Usage

To use the bot, you need to install the package and create a new bot instance.

from antorum import multiplayer
import asyncio


async def main():  # The bot must be ran asynchronously
    client = multiplayer.Client()

    await client.connect()  # Establish a connection to the game server

    await client.login("username", "password")  # Log in to the game with your credentials

    while not client.logged_in:
        await asyncio.sleep(0.1)  # Wait for the client to log in

    await client.load_game()  # Load all the entities in the game

    print("Playing as " + client.game.local_player.username)

Actions

I came up with the concept of actions. The idea is that you can use existing actions, or create your own. Here's an example of how to use an action:

from antorum import multiplayer, actions
import asyncio

async def main():
    # See the previous example for the setup

    while True:
        forage = actions.ForageWeeds(client)
        await forage.run() # Run the action

        await forage.wait_to_finish() # Wait for the action to finish, this will run until the inventory is full

        sell = actions.SellInventory(client, "skartweed") # Sell all skartweed (the item it foraged) in the inventory
        await sell.run()

        await sell.wait_to_finish()

Custom Actions

You can create your own actions by subclassing actions.Action and implementing the _run method. Here's an example of a custom action that follows a player:

class FollowPlayer(Action):
    def __init__(self, client: "multiplayer.Client", username: str):
        super().__init__(client)
        self.username = username # The username of the player to follow

    async def follow(self, network_id: int):
        logging.debug(f"Following entity {network_id}")
        
        # Get the player's position, if it's moving it will grab the final destination
        original_position = utils.get_future_position_from_entity(network_id, self.client.game)

        if original_position != self.client.game.local_player.position: # Move to the player if we're not already there
            await self.client.move(*original_position)

        while True:
            if original_position != utils.get_future_position_from_entity(network_id, self.client.game):
                original_position = utils.get_future_position_from_entity(network_id, self.client.game)
                await self.client.move(*original_position)

            await asyncio.sleep(0.01)

    async def _run(self):
        logging.info(f"Following player {self.username}")
        player = utils.get_entity_from_player_id(
            utils.get_player_id_from_username(self.username, self.client.game),
            list(self.client.game.entities.values())) # Get the player entity

        if player:
            await self.follow(player.network_id)
        else:
            logging.error(f"Player {self.username} not found")

As you can see it's quite simple to create your own actions. There are a few helper functions in the utils module that can help you with making your own actions.

Logging

The bot uses the logging module to log information. You can configure the logger to log to a file or change the log level. It can be very helpful while debugging to use the DEBUG log level. The INFO log level is the default and will provide useful information for a regular user.

2024-04-28 00:09:26 [INFO] Connecting to antorum.game.ratwizard.dev:7667
2024-04-28 00:09:26 [INFO] Connected!
2024-04-28 00:09:26 [INFO] Sending handshake
2024-04-28 00:09:26 [INFO] Handshake accepted, 0 players online. Latest news:
Thanks for playing Antorum Isles!

Please report any bugs using the in-game bug reporting tool (Accessed via the F5 key), or to the #bug_report channel in the Discord.

- Declan (@dooskington)

2024-04-28 00:09:26 [INFO] Logging in as ******
2024-04-28 00:09:27 [INFO] Logged in as player 3
2024-04-28 00:09:27 [INFO] Loading game
2024-04-28 00:09:28 [INFO] (SYSTEM) : Welcome to Antorum!
2024-04-28 00:09:28 [INFO] Game loaded!
2024-04-28 00:09:29 [INFO] Starting forage action
2024-04-28 00:09:29 [INFO] Attempting to forage entity Skartweed (382)
2024-04-28 00:09:37 [INFO] (SYSTEM) : You harvest some Skartweed.
2024-04-28 00:09:37 [INFO] +9 HERBOLOGY experience (648282)
2024-04-28 00:09:37 [INFO] Adding 1 Skartweed to inventory (index 0)
2024-04-28 00:09:37 [INFO] Successfully foraged entity Skartweed (382)
2024-04-28 00:09:38 [INFO] Attempting to forage entity Skartweed (735)

Contributing

As of now we don't support all packet types that the game has. You can add one by creating a new file in the packets directory and subclassing Packet. I recommend looking at the different packet types in the game's source code to see how they work. It will automatically be detected by the bot and used when the game sends that packet type.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

Antorum-0.0.1-py3-none-any.whl (34.2 kB view details)

Uploaded Python 3

File details

Details for the file Antorum-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: Antorum-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 34.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for Antorum-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 661a6321c0a901856f613ab2ef572c8ed57d6ba10973c166d5482ed2a987fbc7
MD5 80e7ba123c16cc26ed34ea9add5f0e85
BLAKE2b-256 a9a3b153c4fb94cb2f04ab1735673f73b767aa7df7907794fbc503162cda6920

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page