-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.linkUpgrader.js
95 lines (85 loc) · 2.67 KB
/
role.linkUpgrader.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
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 = creep.room.find(FIND_STRUCTURES, { filter: (i) => i.structureType == STRUCTURE_LINK })
var links = linksMgr.findLinksInRoom(room);
//console.log( roomName + " " + links)
if (links.length < 2) {
//if less than 2 links in a room, become a regular upgrader
creep.memory.role = "upgrader";
} else {
//console.log(Memory[roomName].links.upgradeLink)
}
//Upgrading Controller
if (creep.memory.upgrading) {
//changing status
if (creep.store.energy == 0) {
creep.memory.upgrading = false;
creep.say('⚡');
} else {
//console.log(creep);
//console.log(links.length)
//assign upgradeLink in memory
if (links.length > 2 && (Memory[roomName].links.upgradeLink == null || Memory[roomName].links.upgradeLink == -1)) {
//var links = creep.room.find(FIND_STRUCTURES, { filter: (i) => i.structureType == STRUCTURE_LINK })
//console.log(roomName + " " + links);
//sort by closest
this.setUpgradeLink(links, creep, roomName)
} else {
switch (creep.upgradeController(creep.room.controller)) {
case 0:
if (links.length > 1 && (Memory[roomName].links.upgradeLink == null || Memory[roomName].links.upgradeLink == -1)) {
this.setUpgradeLink(links, creep, roomName)
}
break;
case -1:
console.log("not my controller")
break;
case -4:
break;
case -9:
creep.moveTo(creep.room.controller, { visualizePathStyle: { stroke: '#ffaa00' } });
break;
case -12:
creep.memory.role = "filler";
break;
default:
console.log(creep.upgradeController(creep.room.controller));
console.log("Uknown error in Link Upgrader");
break;
}
}
}
//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 {
if (Memory[roomName].links.upgradeLink != -1) {
creep.memory.link = Memory[roomName].links.upgradeLink;
collect.links(creep);
} else {
collect.containers(creep)
}
//console.log(links);
}
}
}
,
setUpgradeLink: function (links, creep, roomName) {
links.sort((a, b) => creep.pos.getRangeTo(a) - creep.pos.getRangeTo(b));
console.log(roomName + " " + links);
var upgradeLink = links[0];
Memory[roomName].links.upgradeLink = upgradeLink.id;
}
};
module.exports = roleUpgrader;