-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.upgrader.js
92 lines (86 loc) · 3.1 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
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
let config = require('config');
let upgrader = module.exports;
upgrader.run = function(creep) {
let spawn1 = Game.rooms[creep.memory.home].find(FIND_MY_SPAWNS)[0];
if(creep.memory.working && creep.carry.energy == 0) {
creep.memory.working = false;
}
if(!creep.memory.working && creep.carry.energy == creep.carryCapacity) {
creep.memory.working = true;
}
let goClaim = false;
let targetR;
if(Memory.roomData[spawn1.room.name].claiming) {
targetR = Memory.roomData[spawn1.room.name].claiming;
if(Game.rooms[targetR]) {
let spawns = Game.rooms[targetR].find(FIND_CONSTRUCTION_SITES, {
filter: (c) => (c.structureType == STRUCTURE_SPAWN)
});
if(spawns.length > 0) {
goClaim = true;
}
}
}
if(creep.memory.working) {
// creep.say('upgrading');
if(goClaim && creep.memory.role == 'upgrader' && !(creep.room.name == targetR)) {
creep.moveTo(creep.pos.findClosestByRange(creep.room.findExitTo(targetR)));
return;
}
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.controller);
}
}
else {
// creep.say('collecting');
if(goClaim && creep.memory.role == 'upgrader') {
if(!(creep.room.name == targetR)) {
creep.moveTo(creep.pos.findClosestByPath(creep.room.findExitTo(targetR)));
return;
}
let source = creep.pos.findClosestByPath(FIND_SOURCES, {
filter: (s) => {
return s.room.name == targetR;
}
});
if(creep.harvest(source) == ERR_NOT_IN_RANGE) {
if(creep.moveTo(source) == ERR_NO_PATH) {
}
}
return;
}
if(creep.room.controller.level == 8 && creep.room.energyAvailable < 3000 && creep.room.controller.ticksToDowngrade > 50000) {
creep.moveTo(creep.room.controller);
return;
}
let store = spawn1.room.storage;
let target = false;
if(store && store.store.energy >= 50) {
target = store;
}
if(!store) {
target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => (s.structureType == STRUCTURE_CONTAINER && s.store[RESOURCE_ENERGY] >= 50)});
}
if(target) {
if(creep.withdraw(target, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
} else {
if(global.util.pickupEnergyInRange(creep,20)) return;
if(creep.carry.energy > 0)
creep.memory.working = true;
else
creep.moveTo(spawn1.room.controller);
}
}
};
upgrader.base = [WORK,CARRY,MOVE];
upgrader.add = {
0: { type: WORK, amt: 14 },
1: { type: CARRY, amt: 14 },
2: { type: MOVE, amt: 14 }
// 3: { type: MOVE, amt: 23 }
// 3: { type: TOUGH, amt: 5 },
// 4: { type: TOUGH, amt: 5 }
};