-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.miner.js
More file actions
54 lines (49 loc) · 1.43 KB
/
role.miner.js
File metadata and controls
54 lines (49 loc) · 1.43 KB
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
let styles = require('styles')
module.exports = class {
constructor(creep){
this.creep = creep
}
find(){
return _.reduce(Game.creeps, function(workers, creep, key) {
if(creep.memory.role == "miner"){
workers.push(creep)
}
return workers
}, [])
}
wanted(){
return _.first(_.values(Game.rooms)).allSources().length
}
run(){
let sources = _.sortBy(this.creep.room.allSources(), source => source.pos.getRangeTo(this.creep.pos))
for(let source of sources) {
if(source.targeted().length == 0 || (source.targeted().length == 1 && source.targeted()[0].id == this.creep.id)){
this.creep.memory.target = source.id
break
}
}
let source = Game.getObjectById(this.creep.memory.target)
let container = source.pos.findInRange(FIND_STRUCTURES, 1, {
filter: (s) => {
return s.structureType == STRUCTURE_CONTAINER
}
})
if(container.length > 0){
this.moveTo(container[0])
}
if(this.creep.harvest(source) == ERR_NOT_IN_RANGE){
if(this.creep.pos.findInRange(FIND_STRUCTURES, 0, {
filter: s => {
return s.structureType == STRUCTURE_CONTAINER
}
})){
//this.creep.pos.createConstructionSite(STRUCTURE_CONTAINER)
}
this.moveTo(source)
}
}
moveTo(dest){
this.creep.moveTo(dest, {visualizePathStyle: styles.repair})
//Memory.towQueue[this.creep.id] = dest.pos
}
}