2016-06-30 01:02:49 +00:00
|
|
|
var battle = require('battle')
|
2016-06-30 01:26:39 +00:00
|
|
|
var helpers = require('helpers');
|
2016-06-29 17:21:09 +00:00
|
|
|
|
|
|
|
var roleGuard = {
|
2016-06-30 01:22:31 +00:00
|
|
|
getDestinationFlag: function(){
|
|
|
|
return Game.flags['patrol_' + this.creep.memory.patrolDestination];
|
2016-06-30 00:52:07 +00:00
|
|
|
},
|
2016-06-30 01:37:58 +00:00
|
|
|
patrol: function(){
|
2016-06-30 01:26:39 +00:00
|
|
|
if (this.creep.pos.isEqualTo(this.getDestinationFlag())){
|
|
|
|
this.creep.memory.patrolDestination += 1;
|
|
|
|
}
|
2016-06-30 01:53:45 +00:00
|
|
|
if (this.creep.memory.patrolDestination > this.lastFlag){
|
2016-06-30 01:26:39 +00:00
|
|
|
this.creep.memory.patrolDestination = 1;
|
|
|
|
}
|
|
|
|
this.creep.moveTo(this.getDestinationFlag());
|
|
|
|
},
|
2016-06-29 17:21:09 +00:00
|
|
|
run: function(creep){
|
2016-06-30 01:22:31 +00:00
|
|
|
this.creep = creep;
|
2016-06-30 01:53:45 +00:00
|
|
|
this.lastFlag = helpers.getLastFlag("patrol_");
|
2016-06-30 01:02:49 +00:00
|
|
|
console.log(creep, 'running Guard')
|
2016-06-30 00:56:10 +00:00
|
|
|
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:53:45 +00:00
|
|
|
if (this.lastFlag > 0){
|
|
|
|
this.patrol();
|
|
|
|
} else {
|
|
|
|
this.creep.moveTo(creep.room.controller)
|
|
|
|
}
|
2016-06-29 17:21:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = roleGuard;
|