-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.builder.js
53 lines (50 loc) · 1.66 KB
/
role.builder.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
/**
*
* @type {Object}
*/
module.exports = {
/**
*
* @param {Creep} creep
*/
standardAction: function (creep) {
if (creep.carry[RESOURCE_ENERGY] === 0) {
creep.memory.status = "work"
}
else if (_.sum(creep.carry) === creep.carryCapacity) {
creep.memory.status = "return";
}
if (creep.memory.status === "work") {
let source = creep.pos.findClosestByPath(FIND_SOURCES_ACTIVE);
if (source && creep.harvest(source) === ERR_NOT_IN_RANGE) {
creep.moveTo(source.pos);
}
}
else if (creep.memory.status === "return") {
let site = creep.pos.findClosestByPath(FIND_MY_CONSTRUCTION_SITES);
let repair = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: function (structure) {
return structure.hits < structure.hitsMax;
}
});
let controller = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: function (structure) {
return structure.structureType === STRUCTURE_CONTROLLER;
}
});
if (site) {
if (creep.build(site) === ERR_NOT_IN_RANGE) {
creep.moveTo(site.pos);
}
}
else if (repair) {
if (creep.repair(repair) === ERR_NOT_IN_RANGE) {
creep.moveTo(repair.pos);
}
}
else if (creep.upgradeController(controller) === ERR_NOT_IN_RANGE){
creep.moveTo(controller.pos);
}
}
}
};