-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.builder.js
More file actions
58 lines (51 loc) · 2 KB
/
Copy pathrole.builder.js
File metadata and controls
58 lines (51 loc) · 2 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
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
const configuration = require('configuration');
const config = new configuration.Config();
const workersBasic = require('workers.basic');
var roleBuilder = {
/** @param {Creep} creep **/
run: function(creep) {
if(creep.memory.building && creep.store[RESOURCE_ENERGY] == 0) { // building && 背包为空
creep.memory.building = false; // 变为 非building状态
creep.say('🔄 harvest');
}
if(!creep.memory.building && creep.store.getFreeCapacity() == 0) { // 非building状态 && 背包满(空余为0)
creep.memory.building = true; // 变为 building状态
creep.say('🚧 build');
}
var droppedEnergy = creep.pos.findClosestByRange(FIND_DROPPED_RESOURCES);
if(creep.memory.building) { // building状态的时候
var targets = creep.room.find(FIND_CONSTRUCTION_SITES); // 寻找建筑位
var restPoints = creep.room.find(FIND_FLAGS, { //找出休息点
filter: (structure) => {
return (structure.name == 'RestPoint');
}
});
if(targets.length) { // targets.length > 0 || 建筑位 > 0
creep.memory.resting = false;
var target = targets[0];
for (let i = 0; i < targets.length; i++) {
if (targets[i].structureType == STRUCTURE_EXTENSION) {
target = targets[i];
break;
}
}
if(creep.build(target) == ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}}); // 绘制路径
}
}
else if (droppedEnergy) {
creep.memory.resting = false;
creep.moveTo(droppedEnergy, {visualizePathStyle: {stroke: '#ffaa00'}});
creep.pickup(droppedEnergy);
}
else{
creep.moveTo(restPoints[0], {visualizePathStyle: {stroke: '#ffffff'}});
creep.memory.resting = true;
}
}
else { // 非building状态的时候, 到source旁边并采集
workersBasic.workerMine(creep);
}
}
};
module.exports = roleBuilder;