-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtowers.js
More file actions
33 lines (31 loc) · 1.2 KB
/
Copy pathtowers.js
File metadata and controls
33 lines (31 loc) · 1.2 KB
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
var towers = {
run: function() {
for(var room in Game.rooms){
var towers = Game.rooms[room].find(FIND_MY_STRUCTURES, {
filter: { structureType: STRUCTURE_TOWER }
});
for(var i = 0; i < towers.length; i++){
var tower = towers[i];
var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
var closestDamagedStructure = tower.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => structure.hits < structure.hitsMax
});
var closestInjuredCreep = tower.pos.findClosestByRange(FIND_MY_CREEPS, {
filter: (creep) => {
return (creep.hits < creep.hitsMax);
}
});
if(closestHostile) {
tower.attack(closestHostile);
}
else if(closestInjuredCreep){
tower.heal(closestInjuredCreep);
}
else if(closestDamagedStructure) {
tower.repair(closestDamagedStructure);
}
}
}
}
};
module.exports = towers;