-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.rangeharvester.js
76 lines (74 loc) · 3.07 KB
/
role.rangeharvester.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
76
let rangeharvester = module.exports;
rangeharvester.run = function(creep) {
let spawn1 = Game.rooms[creep.memory.home].find(FIND_MY_SPAWNS)[0];
let energy = creep.pos.findInRange(FIND_DROPPED_RESOURCES,1);
if (energy.length) {
creep.pickup(energy[0]);
}
if(typeof(creep.memory.job) == 'undefined') {
creep.memory.job = 'HARVESTING';
}
if(creep.memory.job === 'HARVESTING') {
if(typeof(creep.memory.opt) == 'undefined') {
creep.memory.opt = 1;
}
let flag = 'farSource' + creep.memory.opt;
creep.moveTo(Game.flags[flag]);
let source = creep.pos.findClosestByPath(FIND_SOURCES);
if(source) {
creep.harvest(source);
}
if(creep.carry.energy == creep.carryCapacity) {
creep.memory.job = 'TRANSFERING';
}
} else {
if(creep.room !== Game.rooms['E99N62']) {
if(creep.room.controller.ticksToDowngrade < 10000)
creep.upgradeController(creep.room.controller);
creep.moveTo(Game.rooms['E99N62'].controller);
} else {
let target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (s) => (s.structureType == STRUCTURE_CONTAINER && s.store[RESOURCE_ENERGY] < s.storeCapacity)});
if(target) {
let result = creep.transfer(target, RESOURCE_ENERGY);
if(result == ERR_NOT_IN_RANGE) {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'}});
} else if(result == OK) {
if(typeof(Memory.rangeHarvesters) == 'undefined') {
Memory.rangeHarvesters = {};
}
let name = creep.name;
if(typeof(Memory.rangeHarvesters[name]) == 'undefined') {
Memory.rangeHarvesters[name] = creep.carryCapacity;
} else {
Memory.rangeHarvesters[name] += creep.carryCapacity;
}
}
} else {
let result = creep.transfer(spawn1, RESOURCE_ENERGY);
if(result == ERR_NOT_IN_RANGE) {
creep.moveTo(spawn1, {visualizePathStyle: {stroke: '#ff0000 '}});
} else if(result == OK) {
if(typeof(Memory.rangeHarvesters) == 'undefined') {
Memory.rangeHarvesters = {};
}
let name = creep.name;
if(typeof(Memory.rangeHarvesters[name]) == 'undefined') {
Memory.rangeHarvesters[name] = creep.carryCapacity;
} else {
Memory.rangeHarvesters[name] += creep.carryCapacity;
}
}
}
if(creep.carry.energy == 0) {
creep.memory.job = 'HARVESTING';
}
}
}
};
rangeharvester.base = [WORK,CARRY,MOVE],
rangeharvester.add = {
0: { type: WORK, amt: 5},
1: { type: CARRY, amt: 5},
1: { type: MOVE, amt: 11},
};