Skip to content

Instantly share code, notes, and snippets.

@oduvan
Created December 7, 2019 13:00
Show Gist options
  • Save oduvan/c95881c249a40b936ac8032ffdeb0eac to your computer and use it in GitHub Desktop.
Save oduvan/c95881c249a40b936ac8032ffdeb0eac to your computer and use it in GitHub Desktop.
basic attack code for JS in EmpireofCode.com
var commander = require("battle/commander.js");
// create craft object
var craftClient = new commander.CraftClient();
// command to craft - start landing units
craftClient.doLandUnits();
function unitLanded(data) {
// create unit object
var unitClient = new commander.UnitClient(data['id']);
function searchAndDestroy() {
// get the nearest enemy
var enemy = unitClient.askNearestEnemy();
// command to unit - attack unit by id
unitClient.doAttack(enemy['id']);
// subscribe on even - when unit has nothing todo
unitClient.whenImIdle().then(searchAndDestroy);
};
searchAndDestroy();
}
// subscribe on event when new unit is landed
craftClient.whenUnitLanded(unitLanded);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment