-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.upgrader.js
48 lines (43 loc) · 1.22 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
39
40
41
42
43
44
45
46
47
48
var collect = require("collect")
var linksMgr = require("mgr.links");
var roleUpgrader = {
/** @param {Creep} creep **/
run: function (creep) {
var room = creep.room;
var roomName = room.name;
//check if links exist
var links = linksMgr.findLinksInRoom(room);
if (links.length > 1 && creep.memory.role === "upgrader") {
//if less than 2 links in a room, become a regular upgrader
creep.memory.role = "linkUpgrader";
}
//Upgrading Controller
if (creep.memory.upgrading) {
//changing status
if (creep.store.energy == 0) {
creep.memory.upgrading = false;
creep.say('⚡');
} else {
//Try to upgrade, move closer if needed
if (creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller,
{ visualizePathStyle: { stroke: '#ffa' } });
} else {
//console.log(creep.upgradeController(creep.room.controller));
}
}
//finding energy
} else {
//makes sure memory created
creep.memory.upgrading = false;
//changing status
if (creep.store.getFreeCapacity() == 0) {
creep.memory.upgrading = true;
creep.say('📈🔼');
} else {
collect.containers(creep);
}
}
}
};
module.exports = roleUpgrader;