-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.mender.js
48 lines (43 loc) · 1.6 KB
/
role.mender.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var roleFunctions = require('roleFunctions');
var roleMender = {
/** @param {Creep} creep **/
run: function(creep) {
if(creep.memory.mending && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.mending = false;
creep.say('📥 gather');
}
if(!creep.memory.mending && creep.store.getFreeCapacity() == 0) {
creep.memory.mending = true;
creep.say('🚧 repair');
}
if(creep.memory.mending) {
var target = creep.pos.findClosestByRange(
FIND_STRUCTURES,
{ filter: (structure) =>
structure.hits < (structure.hitsMax / 3) &&
structure.structureType != STRUCTURE_WALL
}
);
//console.log(creep.name);
if(target) {
if(creep.repair(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
}
}
else {
var waitFlag = Game.flags['Wait' + creep.memory.source];
if (!creep.pos.isEqualTo(waitFlag)) {
creep.moveTo(waitFlag);
}
}
}
else {
creep.getResources(true);
/*var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
}*/
}
}
};
module.exports = roleMender;