-
Notifications
You must be signed in to change notification settings - Fork 7
/
operation.ranger.js
34 lines (27 loc) · 1.21 KB
/
operation.ranger.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
const spawnHelper = require("helper.spawning");
const ranger = require("role.ranger");
module.exports = class RangerOperation {
constructor(roomai, targetFlag, count, attackSetup) {
this.roomai = roomai;
this.room = roomai.room;
this.targetFlag = targetFlag;
this.rangerCount = count;
this.useBoost = attackSetup > 1;
}
run() {
if(this.useBoost) this.requestBoosts();
if(!this.roomai.canSpawn()) return;
let parts = spawnHelper.bestAvailableParts(this.room, ranger.configs());
let leadTime = spawnHelper.spawnDuration(parts) + 50; // 50 ticks to be able to move at least one room
let rangers = _.filter(spawnHelper.globalCreepsWithRole(ranger.name), (c) => c.memory.flag == this.targetFlag.name && (!c.ticksToLive || c.ticksToLive > leadTime));
if(rangers.length < this.rangerCount) {
this.roomai.spawn(parts, { role: ranger.name, flag: this.targetFlag.name });
}
}
requestBoosts() {
this.roomai.labs.requestBoost("XKHO2", 40);
this.roomai.labs.requestBoost("XLHO2", 50);
}
}
const profiler = require("screeps-profiler");
profiler.registerClass(module.exports, 'RangerOperation');