-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.runner.js
More file actions
51 lines (47 loc) · 1.3 KB
/
role.runner.js
File metadata and controls
51 lines (47 loc) · 1.3 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
module.exports = class {
constructor(creep){
this.creep = creep
}
find(){
return util.findCreepsByRole("runner")
}
wanted(){
return CREEP_TYPES["carry"]["object"].find().length
}
run(creep){
let currentTarget = Game.getObjectById(creep.memory.target)
if(currentTarget && !currentTarget.memory.dest){
creep.memory.target = ""
}
if(!creep.memory.target){
let target = creep.pos.findClosestByPath(FIND_MY_CREEPS, {
filter: (towCreep) => {
return (!util.isTargeted(towCreep) &&
towCreep.memory.dest
)
}
})
if(target){
creep.memory.target = target.id
}
}
if(creep.memory.target){
let target = Game.getObjectById(creep.memory.target)
if(!target){
creep.memory.target = ""
return
}
if(creep.pull(target) == ERR_NOT_IN_RANGE){
creep.moveTo(target);
} else {
let targetDest = new RoomPosition(target.memory.dest.x, target.memory.dest.y, target.memory.dest.roomName)
target.move(creep)
if((targetDest.occupied() && creep.pos.isNearTo(targetDest)) || (!targetDest.occupied() && creep.pos.getRangeTo(targetDest) == 0)) {
creep.move(creep.pos.getDirectionTo(target));
} else {
creep.moveTo(targetDest);
}
}
}
}
}