-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathroomaspect.manualOperations.js
29 lines (26 loc) · 1.04 KB
/
roomaspect.manualOperations.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
const spawnFlagRegex = /^spawn([A-Za-z]+)([0-9]+)$/;
const operations = {
deposits: require("operation.farmDeposits"),
power: require("operation.farmPower"),
ranger: require("operation.ranger")
};
module.exports = class ManualOperationsAspect {
constructor(roomai) {
this.roomai = roomai;
this.room = roomai.room;
}
run() {
let results = _.filter(_.map(this.room.find(FIND_FLAGS), (f) => ({ match: spawnFlagRegex.exec(f.name), flag: f })), (m) => m.match);
for(let result of results) {
let opName = result.match[1].toLowerCase();
let opId = result.match[2];
let targetFlag = Game.flags[opName + opId];
let operation = operations[opName];
if(operation && (targetFlag || operation.canSkipFlag)) {
new operation(this.roomai, targetFlag, result.flag.color, result.flag.secondaryColor).run();
}
}
}
}
const profiler = require("screeps-profiler");
profiler.registerClass(module.exports, 'ManualOperationsAspect');