-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrole.repair.js
50 lines (43 loc) · 1.79 KB
/
role.repair.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
49
50
var target_count = 0;
var hitsRepair_2 = 50000;
var roleBuilder = {
run: function (creep) {
if (creep.memory.building && creep.store.getUsedCapacity([RESOURCE_ENERGY]) === 0) {
creep.memory.building = false;
}
if (!creep.memory.building && creep.store.getUsedCapacity([RESOURCE_ENERGY]) === creep.store.getCapacity([RESOURCE_ENERGY])) {
creep.memory.building = true;
}
if (creep.memory.building) {
var targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType === STRUCTURE_WALL || structure.structureType === STRUCTURE_CONTAINER || structure.structureType === STRUCTURE_RAMPART) &&
structure.hits < structure.hitsMax;
}
});
if (targets.length) {
if (targets[target_count].hits < hitsRepair_2) {
if (creep.repair(targets[target_count]) === ERR_NOT_IN_RANGE) {
creep.moveTo(targets[target_count]);
}
} else {
target_count += 1;
if (target_count === targets.length) {
target_count = 0;
}
}
} else {
var flag = Game.flags.Flag1;
creep.moveTo(flag);
}
} else {
var sources = creep.room.find(FIND_SOURCES);
if (creep.harvest(sources[0]) === ERR_NOT_IN_RANGE && creep.harvest(sources[0]) !== ERR_NO_PATH) {
creep.moveTo(sources[0]);
} else if (creep.harvest(sources[1]) === ERR_NOT_IN_RANGE) {
creep.moveTo(sources[1]);
}
}
}
};
module.exports = roleBuilder;