-
Notifications
You must be signed in to change notification settings - Fork 1
/
role.carrier.js
36 lines (33 loc) · 1.22 KB
/
role.carrier.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
let roles = {
builder: require('role.builder'),
};
var roleCarrier = {
/** @param {Creep} creep **/
run: function (creep) {
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);
}
}
} else {
let targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType === STRUCTURE_EXTENSION
|| structure.structureType === STRUCTURE_SPAWN
|| structure.structureType === STRUCTURE_CONTAINER) &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
}
});
if (targets.length > 0) {
if (creep.transfer(targets[0], RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
}
} else {
roles.builder.run(creep);
}
}
}
};
module.exports = roleCarrier;