TsarBot/role_guard.js

37 lines
942 B
JavaScript

var roleBase = require('role_base');
class roleGuard extends roleBase{
/** @param {Creep} creep **/
constructor(){
this.body = [ MOVE, RANGED_ATTACK ];
this.name = 'Streltsy'
}
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;
}
}
}
}
spawn(spawnPoint, newWaypoints){
spawnPoint.spawnCreep(this.body, this.name + Game.time,
{memory : {role : this.name, waypoints : newWaypoints}
});
}
};
module.exports = roleGuard;