-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.towers.js
40 lines (40 loc) · 1.64 KB
/
task.towers.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
let taskTowers = module.exports;
taskTowers.run = function(spawns) {
let spawn1 = spawns[0];
let towers = _.filter(Game.structures, (s) => (s.structureType == STRUCTURE_TOWER && s.room.name == spawn1.room.name));
let mult = 1.0;
if(Memory.roomData[spawn1.room.name].power) {
mult = 0.55;
}
let repairTargets = spawn1.room.find(FIND_STRUCTURES, {
filter: (s) => ((
(s.structureType == STRUCTURE_WALL || s.structureType == STRUCTURE_RAMPART) && s.hits < 1000) ||
((s.structureType != STRUCTURE_WALL && s.structureType != STRUCTURE_RAMPART &&
s.structureType != STRUCTURE_ROAD) && s.hits < 0.8 * s.hitsMax) ||
(s.structureType == STRUCTURE_ROAD && s.hits < s.hitsMax * 0.5 &&
Memory.roomData[spawn1.room.name].travelData[JSON.stringify({x:s.pos.x,y:s.pos.y})] > 25))
});
let hostileTargets = spawn1.room.find(FIND_HOSTILE_CREEPS);
let healTargets = spawn1.room.find(FIND_MY_CREEPS, {
filter: (c) => (c.hits < mult * c.hitsMax)});
for(let tower of towers) {
if(tower.energy >= 10) {
let target = tower.pos.findClosestByRange(hostileTargets);
if(target) {
tower.attack(target);
continue;
}
target = tower.pos.findClosestByRange(healTargets);
if(target) {
tower.heal(target);
continue;
}
target = tower.pos.findClosestByRange(repairTargets);
if(target) {
tower.repair(target);
continue;
}
}
}
};
taskTowers.name = "towers";