2016-06-30 01:02:49 +00:00
|
|
|
var battle = require('battle')
|
2016-06-29 17:21:09 +00:00
|
|
|
|
|
|
|
var roleGuard = {
|
2016-06-30 00:52:07 +00:00
|
|
|
getLastFlag: function(){
|
2016-06-30 01:02:49 +00:00
|
|
|
|
|
|
|
return 4; // TODO. calculate me.
|
2016-06-30 00:52:07 +00:00
|
|
|
},
|
2016-06-29 17:21:09 +00:00
|
|
|
run: function(creep){
|
2016-06-30 01:02:49 +00:00
|
|
|
console.log(creep, 'running Guard')
|
2016-06-30 00:56:10 +00:00
|
|
|
// Reset creep to 1
|
|
|
|
creep.memory.patrolDestination = creep.memory.patrolDestination || 1;
|
|
|
|
|
2016-06-29 17:21:09 +00:00
|
|
|
var target = battle.findEnemy(creep);
|
2016-06-30 00:52:07 +00:00
|
|
|
if(target != creep.room.controller && creep.hits > creep.hitsMax - 500 /* no more attack */) {
|
2016-06-30 01:02:49 +00:00
|
|
|
console.log('\t', creep, 'attacking:',target)
|
2016-06-29 17:21:09 +00:00
|
|
|
creep.moveTo(target);
|
|
|
|
creep.attack(target);
|
|
|
|
} else {
|
2016-06-30 01:02:49 +00:00
|
|
|
var destinationFlag = Game.flags['patrol_' + creep.memory.patrolDestination];
|
2016-06-30 00:52:07 +00:00
|
|
|
|
|
|
|
if (creep.pos.isEqualTo(destinationFlag)){
|
|
|
|
creep.memory.patrolDestination += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (creep.memory.patrolDestination > this.getLastFlag()){
|
2016-06-30 00:56:10 +00:00
|
|
|
creep.memory.patrolDestination = 1;
|
2016-06-30 00:52:07 +00:00
|
|
|
}
|
2016-06-30 01:02:49 +00:00
|
|
|
destinationFlag = Game.flags['patrol_' + creep.memory.patrolDestination];
|
|
|
|
console.log('\tMoving to Patrol leg:', creep.memory.patrolDestination);
|
2016-06-30 00:52:07 +00:00
|
|
|
creep.moveTo(destinationFlag);
|
2016-06-29 17:21:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = roleGuard;
|