-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.basic_harvester.js
More file actions
38 lines (34 loc) · 1.17 KB
/
Copy pathrole.basic_harvester.js
File metadata and controls
38 lines (34 loc) · 1.17 KB
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
var util = require('util');
module.exports = (args) => ({
// args: {sourceRoom, sourceId, targetId}
prepare: null,
source: creep => {
if (creep.store[RESOURCE_ENERGY] == creep.store.getCapacity()) {
return true;
}
const s_room = Game.rooms[args.sourceRoom];
if (creep.room != s_room) {
creep.moveTo(new RoomPosition(25, 25, args.sourceRoom), {visualizePathStyle: {stroke: '#ffaa00', range: 10}});
return false;
}
const source = Game.getObjectById(args.sourceId);
if (creep.pos.inRangeTo(source, 1)) {
creep.harvest(source);
} else {
creep.moveTo(source, {visualizePathStyle: {stroke: '#ffaa00', range: 1}});
}
return false;
},
target: creep => {
if (creep.store[RESOURCE_ENERGY] == 0) {
return true;
}
const target = Game.getObjectById(args.targetId);
if (creep.pos.inRangeTo(target, 1)) {
creep.transfer(target, RESOURCE_ENERGY);
} else {
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff', range: 1}});
}
return false;
},
});