-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.upgrader.js
40 lines (32 loc) · 1.06 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
var commonFun = require('functions.common');
var baseCreep = require('role.creep');
var roleUpgrader = {
/** @param {Creep} creep **/
run: function(creep) {
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 {
if(creep.memory.energySource){
if(creep.memory.energySource.structureType == STRUCTURE_SPAWN){
baseCreep.locateAndCollectEnergy(creep);
}
else{
baseCreep.harvest(creep);
}
}
else{
baseCreep.locateAndCollectEnergy(creep);
}
}
}
};
module.exports = roleUpgrader;