-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.newUpgrader.js
46 lines (37 loc) · 1.35 KB
/
role.newUpgrader.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
var roleNewUprader = {
//var testvar = "test";
/** @param {Creep} creep **/
run: function(creep) {
if(creep.memory.upgrading && creep.carry.energy == 0) {
creep.memory.upgrading = false;
creep.say('harvesting');
}
if(!creep.memory.upgrading && creep.carry.energy == creep.carryCapacity) {
creep.memory.upgrading = true;
creep.say('upgrading');
}
if(creep.memory.upgrading) {
// Check to make sure we are in the correct room first
if (creep.pos.roomName == creep.memory.home) {
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
} else {
var exit = creep.room.findExitTo(creep.memory.home);
creep.moveTo(creep.pos.findClosestByRange(exit));
}
}
else {
if (creep.pos.roomName == creep.memory.remote) {
var sources = creep.pos.findClosestByPath(FIND_SOURCES);
if(creep.harvest(sources) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources);
}
} else {
var exit = creep.room.findExitTo(creep.memory.home);
creep.moveTo(creep.pos.findClosestByRange(exit));
}
}
}
};
module.exports = roleNewUprader;