-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.manager.js
32 lines (29 loc) · 1.01 KB
/
role.manager.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
const ScrumMaster = require('scrum.master');
let roleManager = {
run: function(creep) {
if (creep.memory.working && creep.carry.energy == 0) {
creep.memory.working = false;
}
if (!creep.memory.working && creep.carry.energy == creep.carryCapacity) {
creep.memory.working = true;
}
if (creep.memory.working == false) {
ScrumMaster.findEnergy(creep);
}
else {
creep.memory.working = true;
const buildings = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_TOWER) &&
structure.energy < structure.energyCapacity;
}
});
if (buildings.length > 0) {
if (creep.transfer(buildings[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(buildings[0], {});
}
}
}
}
}
module.exports = roleManager;