-
Notifications
You must be signed in to change notification settings - Fork 0
/
tower.js
28 lines (26 loc) · 935 Bytes
/
tower.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
module.exports = class {
constructor(tower){
this.tower = tower
}
run(){
var closestHostile = this.tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(closestHostile) {
this.tower.attack(closestHostile);
}
var structs = this.tower.room.find(FIND_STRUCTURES, {
filter: (structure) => structure.hits < structure.hitsMax
})
var closestDamagedStructure = this.tower.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => structure.hits < structure.hitsMax
});
for(let i=0; i<structs.length; i++){
if((structs[i].structureType != STRUCTURE_WALL && structs[i].structureType != STRUCTURE_RAMPART) &&
structs[i].hits/structs[i].hitsMax < .75 ||
structs[i].structureType == STRUCTURE_WALL && structs[i].hits < 1000 ||
structs[i].structureType == STRUCTURE_RAMPART && structs[i].hits < 1000){
this.tower.repair(structs[i]);
break
}
}
}
}