var roleBase = require('role_base'); class roleGuard extends roleBase{ static body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ]; static name = 'streltsy' /** @param {Creep} creep **/ static run(creep) { const target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS); if(target) { if(creep.rangedAttack(target) == ERR_NOT_IN_RANGE) { creep.moveTo(target); } } else { var currentWaypoint = Game.flags[creep.memory.waypoints[creep.memory.currentWaypoint]]; if(getRangeTo(currentWaypoint) > 0){ creep.moveTo(currentWaypoint); } else{ creep.memory.currentWaypoint += 1; if(creep.memory.currentWaypoint > creep.memory.waypoints.length){ creep.memory.currentWaypoint = 0; } } } } static spawn(spawnPoint, newWaypoints){ if(typeof newWaypoints === 'undefined') newWaypoints = ['A','B']; spawnPoint.spawnCreep(this.body, this.name + Game.time, {memory : {role : this.name, waypoints : newWaypoints, currentWaypoint : 0} }); } }; module.exports = roleGuard;