-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.miner.js
46 lines (42 loc) · 1.29 KB
/
role.miner.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
const roleMiner = {
/** @param {Creep} creep **/
run: function (creep) {
creep.identify();
creep.memory.home = creep.room.name;
if (!creep.memory.source) {
let assignSource = function () {
let sources = creep.room.find(FIND_SOURCES);
console.log(sources);
if (_.filter(Game.creeps, (creep) => creep.memory.source === sources[0].id).length === 0) {
return sources[0].id;
} else if (_.filter(Game.creeps, (creep) => creep.memory.source === sources[1].id).length === 0) {
return sources[1].id;
}
};
creep.memory.source = assignSource();
}
let source = Game.getObjectById(creep.memory.source);
console.log(source);
let container;
// find container next to source
let containers = source.pos.findInRange(FIND_STRUCTURES, 1, {
filter: s => s.structureType === STRUCTURE_CONTAINER
});
//TODO: let miners build their own container
if (containers.length === 0) {
container = source.pos.findInRange(FIND_CONSTRUCTION_SITES, 1, {
filter: s => s.structureType === STRUCTURE_CONTAINER
})[0];
} else {
container = containers[0];
}
if (container) {
if (creep.pos.isEqualTo(container.pos)) {
creep.harvest(source);
} else {
creep.moveTo(container);
}
}
}
};
module.exports = roleMiner;