-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.hauler.js
47 lines (44 loc) · 1.48 KB
/
role.hauler.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
var roleBuilder = require("role.builder");
module.exports = {
run: function (creep) {
if(creep.memory.isWorking == true && creep.store[RESOURCE_ENERGY] == 0){
creep.memory.isWorking = false;
}
else if(creep.memory.isWorking == false && creep.store[RESOURCE_ENERGY] == creep.store.getCapacity()){
creep.memory.isWorking = true;
}
if (!creep.memory.isWorking) {
if(creep.pos.findClosestByPath(FIND_DROPPED_RESOURCES) == undefined){
var target = creep.pos.findClosestByPath(FIND_MY_STRUCTURES, {
filter: (s) => s.structureType == STRUCTURE_CONTAINER
|| s.structureType == STRUCTURE_STORAGE
&& s.store[RESOURCE_ENERGY] < s.store.getCapacity(RESOURCE_ENERGY)
});
if (creep.withdraw(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
else {
if(creep.pickup(FIND_DROPPED_RESOURCES) == ERR_NOT_IN_RANGE){
creep.moveTo(FIND_DROPPED_RESOURCES);
}
}
}
else {
var structure = creep.pos.findClosestByPath(FIND_MY_STRUCTURES, {
filter: (s) => (s.structureType == STRUCTURE_TOWER
|| s.structureType == STRUCTURE_EXTENSION
|| s.structureType == STRUCTURE_SPAWN)
&& s.store[RESOURCE_ENERGY] < s.store.getCapacity(RESOURCE_ENERGY)
});
if (creep.transfer(structure, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(structure);
}
if(structure != undefined){
if(structure.store[RESOURCE_ENERGY] == structure.store.getCapacity()){
roleBuilder.run(creep);
}
}
}
}
};