-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.butler.js
75 lines (72 loc) · 3.13 KB
/
role.butler.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
const jobWorker = require('job.worker');
const roleButler = {
/** @param {Creep} creep **/
run: function (creep) {
if (creep.carry.energy < creep.carryCapacity) {
creep.memory.targetId = null;
jobWorker.jobCollectEnergy(creep);
/*let source = Game.getObjectById(creep.memory.sourceId);
if (!source) {
source = creep.pos.findClosestByPath(FIND_SOURCES);
if (!source || source.id) {
source = creep.pos.findClosestByRange(FIND_SOURCES);
}
creep.memory.sourceId = source.id;
}
if (creep.harvest(source) === ERR_NOT_IN_RANGE) {
let moved = creep.moveTo(source, {visualizePathStyle: {stroke: '#ffaa00'}});
if (moved === ERR_NO_PATH) {
source = null;
}
}*/
}
else {
creep.memory.sourceId = null;
let target = Game.getObjectById(creep.memory.targetId);
if (!target) {
/*target = creep.pos.findClosestByPath(FIND_TOMBSTONES, {
filter: (structure) => {
return (_.sum(structure.store) > 0);
}
});
if (!target) {
target = creep.pos.findClosestByPath(FIND_DROPPED_RESOURCES, /!*{
filter: (structure) => {
return (_.sum(structure.store) > 0);
}
}*!/);
}*/
//if (!target) {
target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (structure) => {
return ((structure.structureType === STRUCTURE_EXTENSION
|| structure.structureType === STRUCTURE_SPAWN) && structure.energy < structure.energyCapacity)
|| (structure.structureType === STRUCTURE_TOWER && structure.energy < structure.energyCapacity * 0.25);
}
});
// }
if (!target) {
target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType === STRUCTURE_TOWER) && structure.energy < structure.energyCapacity;
}
});
}
creep.memory.targetId = target && target.id ? target.id : null;
}
if (target) {
let transfer = creep.transfer(target, RESOURCE_ENERGY);
if (transfer === ERR_NOT_IN_RANGE) {
let moved = creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
if (moved === ERR_NO_PATH) {
target = null;
}
}
if ([ERR_FULL, ERR_INVALID_ARGS, ERR_INVALID_TARGET, ERR_NOT_ENOUGH_RESOURCES].indexOf(transfer)) {
creep.memory.targetId = null;
}
}
}
}
};
module.exports = roleButler;