-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreep.mineralMiner.js
48 lines (41 loc) · 1.67 KB
/
creep.mineralMiner.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
const { pathSets } = require("./constants");
const CreepManager = require("./manager.creepManager");
const Task = require("./data.task");
const { markWorkingPosition } = require("./extension.betterPathing");
class MineralMinerManager extends CreepManager {
createTask(creep, colony) {
const actionStack = [];
actionStack.push(function (creep, mineralSite) {
// Move to mining site
const sitePos = new RoomPosition(
mineralSite.pos.x,
mineralSite.pos.y,
mineralSite.pos.roomName
);
if (creep.pos.getRangeTo(sitePos) > 0) {
creep.betterMoveTo(sitePos, {
range: 0,
pathSet: pathSets.default,
});
}
// Mine our mineral
const extractor = Game.getObjectById(mineralSite.extractorID);
if (creep.pos.getRangeTo(extractor) <= 1 && !extractor.cooldown) {
const mineral = Game.getObjectById(mineralSite.mineralID);
creep.harvest(mineral);
// We'll also mark this position to discourage creeps from walking through it
markWorkingPosition(creep.pos);
}
// Always return false since miners can never finish their task
return false;
});
if (creep.memory.miningSite) {
return new Task(creep.memory.miningSite, "mine", actionStack);
}
// Memorize this site
const site = colony.getMineralSites()[0];
creep.memory.miningSite = site;
return new Task(site, "mine", actionStack);
}
}
module.exports = MineralMinerManager;