A script is the JavaScript code inside a package. When a bot plays a package, Asterobot runs that code for the bot, right next to the bot's connection to the game. Read this before your first script: it saves you from looking for things that don't exist.
One copy per bot
Every bot that plays a package runs its own copy of the script. Two bots playing the same package share no variables, a script can't see or control another bot, and stopping one bot's script leaves the others running.
The code runs inside Asterobot, on the computer where Asterobot runs. Asteroboard only shows you what happens, so closing it doesn't stop a script.
What a script can do
Everything a script can do comes from the built-in modules it imports:
| To | Use | From |
|---|---|---|
| React to messages the game server sends | on(), wait() |
asterobot:protocol |
| See every message, in both directions | onTraffic() |
asterobot:protocol |
| Send messages | send(), request() |
asterobot:protocol |
| Change or block messages on their way through | intercept() |
asterobot:protocol |
| Read game data: items, monsters, maps, game texts | text(), record(), table(), find(), search(), query() |
asterobot:gamedata |
| Show settings on the bot's page and read them | export const parameters, values, onChange() |
Your index.js, and asterobot:parameters |
| Show buttons on the bot's page | export const actions |
Your index.js |
| Write to the bot's console | botDebug(), botInfo(), botWarn(), botError() |
asterobot:bot |
| Write to Asterobot's own log | debug(), log(), info(), warn(), error() |
asterobot:console |
| Read the session: game ticket, server, language, why the script started | session |
asterobot:bot |
| Know where the character stands: its map, its cell and the actors around it | currentMap() |
asterobot:bot |
| Find the route the Dofus client would walk to a cell of a map, and how long walking it takes | findPath() |
asterobot:pathfinding |
| Work out a cell's grid position, or the distance and the direction between two cells | cellToPoint(), pointToCell(), distance(), direction() |
asterobot:pathfinding |
| Walk the character to a cell of its map, and wait for the end of the walk | move() |
asterobot:movement |
| Pause for a while | sleep() |
asterobot:timers |
| Close the bot's game connection | disconnect() |
asterobot:bot |
| Read the name, version and permissions of your package or of one of its dependencies | packages.info() |
asterobot:runtime |
In MITM mode (man-in-the-middle: the bot relays the game session of a Dofus client that someone plays), the same functions work on that session. A script sees what the Dofus client sends and what the server answers. It can send messages to the server as if the client had sent them, or to the client as if the server had, and it can change or drop messages before they reach the other side.
The reference describes every function, one page per module.
What a script can't do
Some things you'd expect from JavaScript elsewhere aren't there, and a package can't add them.
| Not available | Use instead |
|---|---|
| Reading or writing files | Nothing. A script only has the modules of its own package and of the packages it depends on. |
The internet: fetch(), sockets, HTTP requests |
Nothing. The bot's game connection is the only connection a script talks through. |
npm packages and require() |
import from the asterobot: modules, from your package's own files, or from library packages your package declares as dependencies. |
setTimeout() and setInterval() |
await sleep(milliseconds) from asterobot:timers. |
The global console |
The console functions of asterobot:bot or asterobot:console, imported like anything else. |
window, document, process and the other browser or Node.js globals |
Nothing. |
Scripts also run within limits. For example, code that runs for more than 250 ms without awaiting anything ends the script. Limits lists them all.
No built-in moves or fights
There's no built-in function that walks to another map, harvests a resource or plays a fight. A script plays Dofus the way the Dofus client does: it sends the messages the client would send and reacts to what the server sends back. The Dofus protocol reference describes those messages, and How bots talk to Dofus explains how they work.
Walking inside a map is built in. move() walks the character to a cell of its map and waits for the end of the walk, on both kinds of bot. currentMap() says where the character and the other actors stand, and findPath() gives the route the Dofus client would take and how long the walk lasts.
Full socket scripts identify the bot
In Full socket mode, Asterobot signs in with the Ankama account, picks the game server and opens the game connection. Then it stops. It doesn't identify the bot on the game server and doesn't choose a character: that's the script's job. Its first message on a new connection must be IdentificationRequest, and Identify and run shows the few lines that send it. Every sample in these docs includes them, so each one works in both modes.
A MITM bot doesn't need them. The Dofus client has already identified the session when the script starts, and the same lines skip the identification there.
Note
Coming soon. Ready-made basic and full connection scripts will take a Full socket bot into the game for you. Until they're available, a Full socket bot goes only as far as your own script takes it.
Next, read The JavaScript you need, or go straight to Create a package if you'd rather start typing.
Aucun avis à afficher.