-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.worker.js
68 lines (63 loc) · 2.14 KB
/
role.worker.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
var role_worker = {
/** @param {Creep} creep **/
run: function (creep) {
/*
console.log(creep.store[RESOURCE_ENERGY], creep.store.getCapacity());
if (creep.store[RESOURCE_ENERGY] < creep.store.getCapacity()) {
var sources = creep.room.find(FIND_SOURCES_ACTIVE);
if (creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0]);
}
}
*/
console.log(creep.store[RESOURCE_ENERGY], creep.store.getCapacity());
if (creep.memory.working && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.working = false;
creep.say("collecting!");
}
if (!creep.memory.working && creep.store[RESOURCE_ENERGY] == 50) {
creep.memory.working = true;
creep.say("Energizing!");
}
if (creep.memory.working) {
var targets = creep.room.find(FIND_MY_STRUCTURES, {
filter: (structure) => {
return (
structure.structureType == STRUCTURE_CONTROLLER &&
structure.progress < structure.progressTotal
);
//structure.structureType == STRUCTURE_EXTENSION
//structure.structureType == STRUCTURE_CONTAINER ||
//structure.structureType == STRUCTURE_SPAWN ||
//structure.structureType == STRUCTURE_TOWER
},
});
console.log(targets);
if (targets.length > 0) {
if (creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0], {
visualizePathStyle: {
stroke: "green",
strokeWidth: "0.3",
opacity: "1.0",
lineStyle: "dotted",
},
});
}
}
} else {
var sources = creep.room.find(FIND_SOURCES_ACTIVE);
if (creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0], {
visualizePathStyle: {
stroke: "blue",
strokeWidth: "0.3",
opacity: "1.0",
lineStyle: "dotted",
},
});
}
}
},
};
module.exports = role_worker;