Azymoove Help

Helpers: the Drone

A drone that flies with your robot and shoots, guards or repairs.

Pass helpers to the constructor with super({ helpers: [new Drone()] }). The drone flies around your robot, has 15 health, is downed by any shot that crosses its path and falls along with you.

Helpers and items share the 3 slots. The first drone costs 3 points, and each extra one costs 1 more (2 drones = 7 points).

Modes

new Drone() decides what to do by its mode, which you change on the instance (this.helpers[0].mode = "guard"). The change applies right away:

  • follow (default): stays with you and shoots the nearest enemy (2 damage every 2 s, range 18), aiming ahead of it.
  • attack: chases the enemy in target and shoots it; while it can’t see it, it does the same as follow.
  • guard: stays between you and the nearest enemy, with a shield, without shooting.
  • repair: doesn’t shoot; gives back 0.4 health per second, using 3 of your energy per point.

How the Drone works

This is the code new Drone() runs, exactly. To change it, create a class that extends Drone and override only the method you want (followOwner, attackTarget, guardOwner, repairOwner or aim; in Python, Ruby and Lua, follow_owner…). For example, to aim without leading the target:

class MyDrone extends Drone {
  aim(state, enemy) { this.fireAt(enemy.x, enemy.z); }
}

To change everything, copy the whole class and rename it.

// Como o Drone funciona: este é o código que new Drone() executa.
// Para mudar, crie class MeuDrone extends Drone e reescreva só o método
// que quiser (followOwner, attackTarget, guardOwner, repairOwner ou aim).
class Drone extends Helper {
  get kind() { return "drone"; }

  // O loop do drone: a cada turno, o programa do modo que o robô escolheu.
  run() {
    while (true) {
      const state = this.scan();
      if (this.mode === "attack") this.attackTarget(state);
      else if (this.mode === "guard") this.guardOwner(state);
      else if (this.mode === "repair") this.repairOwner(state);
      else this.followOwner(state);
    }
  }

  // Orbita o dono e atira no inimigo mais próximo que estiver no alcance.
  followOwner(state) {
    this.follow(4);
    const enemy = state.enemies.find(e => e.distance <= state.me.limits.range);
    if (enemy) this.aim(state, enemy);
  }

  // Fica a 8 do alvo (this.target) e atira nele; sem vê-lo, segue o dono.
  attackTarget(state) {
    const target = state.enemies.find(e => e.id === this.target);
    if (!target) return this.followOwner(state);
    const dx = state.me.x - target.x, dz = state.me.z - target.z;
    const distance = Math.max(Math.sqrt(dx * dx + dz * dz), 1e-9);
    this.goTo(target.x + dx / distance * 8, target.z + dz / distance * 8);
    if (target.distance <= state.me.limits.range) this.aim(state, target);
  }

  // Fica entre o dono e o inimigo mais perto dele, com escudo (não atira).
  guardOwner(state) {
    let threat = null;
    for (const e of state.enemies) {
      if (!threat || e.ownerDistance < threat.ownerDistance || (e.ownerDistance === threat.ownerDistance && e.id < threat.id)) threat = e;
    }
    if (threat) {
      // Vários drones protegendo se abrem em leque na linha de tiro.
      const spread = (state.me.index - (state.me.count - 1) / 2) * 0.55;
      const angle = Math.atan2(threat.x - state.owner.x, threat.z - state.owner.z) + spread;
      this.goTo(state.owner.x + Math.sin(angle) * 2.9, state.owner.z + Math.cos(angle) * 2.9);
    } else {
      this.follow(2.9);
    }
    this.shield();
  }

  // Fica perto do dono e devolve vida a ele (gasta a energia do dono).
  repairOwner(state) {
    this.follow(2.6);
    if (state.owner.health < state.owner.maxHealth) this.repair();
  }

  // Atira onde o inimigo vai estar quando o tiro chegar.
  aim(state, enemy) {
    let x = enemy.x, z = enemy.z;
    for (let i = 0; i < 2; i++) {
      const dx = x - state.me.x, dz = z - state.me.z;
      const flight = Math.sqrt(dx * dx + dz * dz) / state.me.limits.bulletSpeed;
      x = enemy.x + Math.sin(enemy.heading) * enemy.velocity * flight;
      z = enemy.z + Math.cos(enemy.heading) * enemy.velocity * flight;
    }
    this.fireAt(x, z);
  }
}

A drone with your own code

The helper follows the robot’s pattern: a run() called once, with its own loop, and scan() every turn.

  • state.me is the drone (position, health and limits: speed, range, bulletSpeed…), state.owner is your robot and state.enemies has the enemies it can see.
  • Commands: goTo(x, z), follow(), fireAt(x, z), shield() and repair() (Python, Ruby and Lua: go_to, fire_at…).
  • A turn with no command leaves the drone still. super.run() (Python super().run(), Ruby super, Lua Drone.run(self)) uses the ready-made program.
  • Each drone runs apart from the robot: the two talk through mode and target. The game applies the drone’s limits (speed, range, rate of fire) to any code, and each drone has its own processing limit per turn.

In battle

this.helpers keeps the instances in the declared order; a destroyed drone stays in the list with alive false. Enemy drones the radar sees are in state.helpers (with owner, mode, distance and bearing); they don’t go into state.scanned. Events: hitHelper (your shot hit a drone) and helperDestroyed (one of your drones went down).