-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathactionUpgrader.js
51 lines (43 loc) · 1.62 KB
/
actionUpgrader.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
var harvester = require('actionHarvest');
module.exports = {
run:function(creep){
let startCpu = Game.cpu.getUsed();
let elapsed;
if(creep.room.name !== creep.memory.roomID){
let actRes = creep.moveTo(new RoomPosition(25,25,creep.memory.roomID));
if (actRes === OK) {
creep.memory.action= 'traveling back ';
}
return;
}
if(creep.room.controller) {
if(creep.carry.energy === creep.carryCapacity){
creep.memory.working = true;
}
if(creep.carry.energy>0 && creep.memory.working){
creep.memory.working = creep.doUpgrade();
}
else{
let container = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: s => (s.structureType === STRUCTURE_CONTAINER || s.structureType === STRUCTURE_STORAGE ) && s.store[RESOURCE_ENERGY] > 0
});
let actRes;
if (container !== undefined) {
actRes = creep.withdraw(container, RESOURCE_ENERGY);
if (actRes === ERR_NOT_IN_RANGE) {
creep.moveTo(container);
}
else if(actRes === ERR_NOT_ENOUGH_RESOURCES || actRes === ERR_INVALID_TARGET){
creep.memory.working = creep.mineEnergy();
}
}
else{
creep.memory.working = creep.mineEnergy();
}
}
}
else{
harvester.run(creep);
}
}
};