-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.move.js
50 lines (42 loc) · 1.07 KB
/
action.move.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
48
49
50
'use strict'
const store = (creep, room) => {
let target = [];
if (room.hostiles.length){
target = _.filter(room.towers, (structure) => {
if (structure.energy > 250) return false;
return true;
});
}
if (!target.length){
target = _.filter(room.spawns, (structure) => {
if (structure.energy === structure.energyCapacity) return false;
return true;
});
}
if (!target.length){
target = _.filter(room.extensions, (structure) => {
if (structure.energy === structure.energyCapacity) return false;
return true;
});
}
if (!target.length){
target = _.filter(room.towers, (structure) => {
if (structure.energy > 250) return false;
return true;
});
}
if (!target.length){
target = _.filter(room.towers, (structure) => {
if (structure.energy > structure.energyCapacity) return false;
return true;
});
}
if (target.length){
if (creep.transfer(target[0], RESOURCE_ENERGY) === ERR_NOT_IN_RANGE){
creep.moveTo(target[0]);
}
return 'store';
}
return false;
}
module.exports = store;