-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.waller.js
56 lines (44 loc) · 1.22 KB
/
role.waller.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
51
52
53
54
55
56
const Utils = require("utils");
const repairTargets = [STRUCTURE_WALL];
const ratios = [0.001, 0.01, 0.05, 0.1];
const findWalls = creep => {
let walls = [];
for (const ratio of ratios) {
walls = creep.room.find(FIND_STRUCTURES, {
filter: structure =>
repairTargets.includes(structure.structureType) &&
structure.hits < structure.hitsMax * ratio
});
if (walls.length > 0) break;
}
return walls;
};
/**
* Basically a fixer solely for walls
*/
const roleWaller = {
test: creep => findWalls(creep),
run: creep => {
if (creep.memory.walling && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.walling = false;
creep.say("🔄 harvest");
}
if (!creep.memory.walling && creep.store.getFreeCapacity() == 0) {
creep.memory.walling = true;
creep.say("🚧 walling");
}
if (creep.memory.walling) {
const walls = findWalls(creep);
if (!walls.length) return;
if (creep.repair(walls[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(walls[0], {
visualizePathStyle: { stroke: "#ffffff" }
});
}
return;
}
// Harvesting
Utils.withdrawFromStorageOrHarvest(creep);
}
};
module.exports = roleWaller;