-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.miner.js
47 lines (41 loc) · 1.23 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
47
// Export module
module.exports =
{
/**
* Run
* Action miner performs every tick
* @param {Creep} creep
**/
run: function(creep)
{
if (!creep.memory.container)
{
// Get list of already occupied containers being mined
var occupiedContainers = _.filter(Game.creeps, (creep) => creep.memory.role == 'miner' && creep.memory.container)
.map(function(creep) {
return creep.memory.container.id;
});
var containers = creep.room.find(FIND_STRUCTURES, {
filter: (container) => {
return (container.structureType == STRUCTURE_CONTAINER && !occupiedContainers.includes(container.id));
}
});
if(containers.length > 0) {
creep.memory.container = containers[0];
}
else {
creep.say('No unoccupied containers');
}
console.log(containers);
}
// Mine or move?
if (creep.pos.getRangeTo(Game.getObjectById(creep.memory.container.id)) == 0)
{
var source = creep.pos.findClosestByPath(FIND_SOURCES);
creep.harvest(source);
}
else {
creep.moveTo(Game.getObjectById(creep.memory.container.id));
}
}
};