-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.upgrader.js
38 lines (32 loc) · 1.16 KB
/
role.upgrader.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
let ScrumMaster = require("scrum.master");
let Digger = require("digger");
var roleUpgrader = {
/** @param {Creep} creep **/
run: function (creep) {
let scrumMasters = _.filter(Game.creeps, (creep) => creep.memory.role == "scrum_master");
let diggers = _.filter(Game.creeps, (creep) => creep.memory.role == 'digger');
if (diggers == 0) {
Digger.run(creep);
}
else if (scrumMasters.length == 0) {
ScrumMaster.scrumMaster.run(creep);
}
else {
if (creep.memory.upgrading && creep.carry.energy == 0) {
creep.memory.upgrading = false;
}
if (!creep.memory.upgrading && creep.carry.energy == creep.carryCapacity) {
creep.memory.upgrading = true;
}
if (creep.memory.upgrading) {
if (creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller, {});
}
}
else {
ScrumMaster.findEnergy(creep);
}
}
}
};
module.exports = roleUpgrader;