-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.lorry.js
72 lines (62 loc) · 2.94 KB
/
role.lorry.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
module.exports = {
/** @param {Creep} creep **/
run: function(creep) {
if(creep.memory.isTransporting && creep.store[RESOURCE_ENERGY] == 0) {
creep.memory.isTransporting = false;
creep.say('🔄 Reload');
}
if(!creep.memory.isTransporting && creep.store.getFreeCapacity() == 0) {
creep.memory.isTransporting = true;
creep.say('⚡ Move');
}
if(creep.memory.isTransporting) {
var closestTarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => (s.structureType == STRUCTURE_EXTENSION || s.structureType == STRUCTURE_SPAWN) &&
s.store.getFreeCapacity(RESOURCE_ENERGY) > 0
});
if(closestTarget) {
if(creep.transfer(closestTarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(closestTarget, {visualizePathStyle: {stroke: '#ffffff'}});
}
} else {
var closestTarget = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => (s.structureType == STRUCTURE_STORAGE) &&
s.store.getFreeCapacity(RESOURCE_ENERGY) > 0
});
if(closestTarget){
if(creep.transfer(closestTarget, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(closestTarget, {visualizePathStyle: {stroke: '#ffffff'}});
}
if(creep.transfer(closestTarget, RESOURCE_ZYNTHIUM) == ERR_NOT_IN_RANGE) {
creep.moveTo(closestTarget, {visualizePathStyle: {stroke: '#ffffff'}});
}
}else{
//Look for Towers that need fill up
var towerInNeedofFIllUp = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (s) => s.structureType == STRUCTURE_TOWER && s.needsFillUp() && s.room == creep.room
}) ;
if(towerInNeedofFIllUp){
if(creep.transfer(towerInNeedofFIllUp, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(towerInNeedofFIllUp, {visualizePathStyle: {stroke: '#ffffff'}});
}
}
}
}
}
else {
let droppedEnergy = creep.pos.findClosestByPath(FIND_DROPPED_RESOURCES);
if(droppedEnergy){
if(creep.pickup(droppedEnergy) == ERR_NOT_IN_RANGE){
creep.moveTo(droppedEnergy, {visualizePathStyle: {stroke: '#ffffff'}});
}
return true;
}
/** @type {StructureContainer} */
let container = Game.getObjectById(creep.memory.container);
if(creep.withdraw(container, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE){
creep.moveTo(container);
}
}
return true;
}
};