-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.storage.js
45 lines (38 loc) · 1.68 KB
/
role.storage.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
var roleStorage = {
/** @param {Creep} creep **/
run: function(creep) {
var targets = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_STORAGE ) //&&
//structure.energy < structure.energyCapacity;
}
});
//console.log(targets.length);
if(targets.length > 0) {
//console.log('Creep ' + creep.name + ' delivering:' + creep.memory.delivering + ' on board:' + creep.carry.energy);
if(creep.memory.delivering != true) {
if (creep.memory.source == undefined || creep.memory.source == "") {
source = creep.pos.findClosestByRange(FIND_SOURCES);
if (source != null)
creep.memory.source = source.id;
}
if (creep.memory.source != undefined && creep.memory.source != "")
if(creep.harvest(Game.getObjectById(creep.memory.source)) == ERR_NOT_IN_RANGE)
creep.moveTo(Game.getObjectById(creep.memory.source));
if(creep.carry.energy == creep.carryCapacity) {
creep.memory.delivering = true;
creep.memory.source = "";
}
}
else {
if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
}
if(creep.carry.energy == 0) {
creep.memory.delivering = false;
}
}
}
}
};
module.exports = roleStorage;