-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.upgrader.js
More file actions
32 lines (26 loc) · 1.11 KB
/
Copy pathrole.upgrader.js
File metadata and controls
32 lines (26 loc) · 1.11 KB
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
const configuration = require('configuration');
const config = new configuration.Config();
const workersBasic = require('workers.basic');
var roleUpgrader = {
/** @param {Creep} creep **/
run: function(creep) {
if(creep.memory.upgrading && creep.store[RESOURCE_ENERGY] == 0) { // 升级状态&&能量不足的时候,变为采集者
creep.memory.upgrading = false;
creep.say('🔄 harvest');
}
if(!creep.memory.upgrading && creep.store.getFreeCapacity() == 0) { // 非升级状态&&能量满的时候,变为升级状态
creep.memory.upgrading = true;
creep.say('⚡ upgrade');
}
if(creep.memory.upgrading) { // 升级状态,找到控制器并升级 + 可视化
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.memory.resting = false;
creep.moveTo(creep.room.controller, {visualizePathStyle: {stroke: '#ffffff'}});
}
}
else { // 采集状态 + 可视化
workersBasic.workerMine(creep);
}
}
};
module.exports = roleUpgrader;