-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrole.builder.js
57 lines (54 loc) · 2.06 KB
/
role.builder.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
57
let roles = {
upgrader: require('role.upgrader'),
};
var roleBuilder = {
/** @param {Creep} creep **/
run: function (creep) {
// Building, out of energy
if (creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.building = false;
creep.say('🔄 harvest');
}
// Not builiding, full
if (!creep.memory.building && creep.store.getFreeCapacity() == 0) {
creep.memory.building = true;
creep.say('🚧 build');
}
// Building
if (creep.memory.building) {
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
//targets = _.sortBy(targets, s => creep.pos.getRangeTo(s))
if (targets.length > 0) {
if (creep.build(targets[0]) === ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#0000ff'}});
}
}
// If no build target than repair
else {
let repairTargets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return structure.hits < 4000 && structure.hitsMax > 4000;
}
});
if (repairTargets.length > 0) {
if (creep.repair(repairTargets[0]) === ERR_NOT_IN_RANGE) {
creep.moveTo(repairTargets[0], {visualizePathStyle: {stroke: '#00ffff'}});
}
}
// If no build targets and repairs then ugrade
else {
//console.log(creep.name + ' doing upgrade');
roles.upgrader.run(creep);
}
}
} else if (creep.store.getFreeCapacity() > 0) {
const target = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES);
if(target) {
if(creep.pickup(target) === ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
}
}
};
module.exports = roleBuilder;