-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrole.harvester.js
56 lines (49 loc) · 2.47 KB
/
role.harvester.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
var roleHarvester = {
/** @param {Creep} creep **/
run: function (creep) {
var filler = _.filter(Game.creeps, (creep) => creep.memory.role === 'filler');
var sources = creep.pos.findClosestByPath(FIND_SOURCES);
if (creep.store.getUsedCapacity([RESOURCE_ENERGY]) < creep.store.getCapacity([RESOURCE_ENERGY])) {
creep.say("⛏")
if (creep.harvest(sources) === ERR_NOT_IN_RANGE) {
creep.moveTo(sources, {visualizePathStyle: {stroke: '#ffaa00'}});
}
}
else {
var target = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType === STRUCTURE_LINK || structure.structureType === STRUCTURE_SPAWN
|| structure.structureType === STRUCTURE_EXTENSION || structure.structureType === STRUCTURE_TOWER)
&& structure.store.getUsedCapacity([RESOURCE_ENERGY]) < structure.store.getCapacity([RESOURCE_ENERGY]);
}
});
var tower = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (structure) => {
return structure.structureType === STRUCTURE_TOWER;
}
});
var enemy = creep.room.find(FIND_HOSTILE_CREEPS);
for (var i in filler) {
if(creep.pos.isNearTo(filler[i])) {
creep.transfer(filler[i], RESOURCE_ENERGY)
}
}
if (tower != null && enemy.length > 0) {
if (creep.transfer(tower, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(tower, {visualizePathStyle: {stroke: '#ffffff'}});
}
} else if (creep.room.storage && _.sum(creep.room.storage.store) < creep.room.storage.storeCapacity && !target) {
if (creep.transfer(creep.room.storage, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(creep.room.storage, {visualizePathStyle: {stroke: '#ffffff'}});
}
} else if (target) {
if (creep.transfer(target, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
}
} else {
creep.moveTo(25, 25, {visualizePathStyle: {stroke: '#ffffff'}});
}
}
}
};
module.exports = roleHarvester;