Created
December 7, 2019 13:00
-
-
Save oduvan/c95881c249a40b936ac8032ffdeb0eac to your computer and use it in GitHub Desktop.
basic attack code for JS in EmpireofCode.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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