35 lines
954 B
JavaScript
35 lines
954 B
JavaScript
var body = [ MOVE, MOVE, RANGED_ATTACK, RANGED_ATTACK ];
|
|
var name = 'streltsy'
|
|
|
|
function 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(creep.pos.getRangeTo(currentWaypoint) > 0){
|
|
creep.moveTo(currentWaypoint);
|
|
}
|
|
else{
|
|
creep.memory.currentWaypoint += 1;
|
|
if(creep.memory.currentWaypoint > creep.memory.waypoints.length){
|
|
creep.memory.currentWaypoint = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function 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 = {body,name,run,spawn};
|