-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkManager.js
57 lines (44 loc) · 1.71 KB
/
linkManager.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
var roomsManager = require('roomsManager');
var linkManager = {
/** @param {Creep} creep **/
run: function(creep) {
for(var room_it in Game.rooms) {
var targets = Game.rooms[room_it].find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_LINK);
}
});
if(targets.length > 0) {
for(var linkStructure in targets) {
linkManager.workLink(linkStructure, targets, Game.rooms[room_it]);
}
}
}
},
workLink: function(linkNo, linkObjects, room) {
// look to see if it has more energy than it is supposed to maintain, if it does, send it to the TO address
// if it is set to maintain energy, see if there is a from and pull energy in the amount to keep it at that level
var toVar = roomsManager.getLinkTo(room.name, linkNo);
var maintainValue = roomsManager.getLinkMaintain(room.name, linkNo);
var fromVar = roomsManager.getLinkFrom(room.name, linkNo);
if (toVar == -1)
return;
if (toVar <= 10) {
linkO = linkObjects[toVar];
} else {
linkO = Game.getObjectById(toVar);
}
if (linkObjects[linkNo].energy > maintainValue) {
var transferAmount = linkObjects[linkNo].energy - maintainValue;
if (linkObjects[linkNo].cooldown == 0)
linkObjects[linkNo].transferEnergy(linkO, transferAmount);
} else if (linkObjects[linkNo].energy < maintainValue && fromVar != NONE) {
var transferAmount = maintainValue - linkObjects[linkNo].energy;
linkObjects[linkNo].transferEnergy(linkO, transferAmount);
}
},
handleLink: function(link, tolink) {
link.transferEnergy(tolink);
}
};
module.exports = linkManager;