32 lines
740 B
JavaScript
32 lines
740 B
JavaScript
var energyUtils = require('utils.energy');
|
|
|
|
const body = [
|
|
MOVE, RANGED_ATTACK
|
|
];
|
|
|
|
var roleGuard = {
|
|
/** @param {Creep} creep **/
|
|
run: function(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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = roleGuard;
|