-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.repairer.js
34 lines (31 loc) · 1.2 KB
/
role.repairer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
module.exports = {
/** @param {Creep} creep **/
run: function(creep) {
if(creep.memory.repairing && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.repairing = false;
creep.say('🔄 harvest');
}
if(!creep.memory.repairing && creep.store.getFreeCapacity() == 0) {
creep.memory.repairing = true;
creep.say('🚧 repair');
}
if(creep.memory.repairing) {
var target = creep.pos.findClosestByPath(FIND_STRUCTURES, { //Tower repair walls & ramparts.
filter: (structure) => (structure.structureType != STRUCTURE_WALL && structure.structureType != STRUCTURE_RAMPART && structure.hits < structure.hitsMax)
|| (structure.structureType == STRUCTURE_RAMPART && structure.hits < 1000) //ramparts decay, thus need at least some repair
});
if(target) {
if(creep.repair(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
}
return true;
} else {
return false;
}
}
else {
creep.getEnergy();
return true;
}
}
};