-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.turret.js
41 lines (38 loc) · 1.33 KB
/
role.turret.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
41
var utilsRoom = require('utils.room');
var roleTurret = {
/** @param {StructureTower} tower **/
run: function(tower) {
var target = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS, {
filter: (c) => {
return (Memory.friends.indexOf(c.owner.username) == -1); //TODO FIXME THIS IS AWFUL
}
});
if(target && (tower.attack(target) == OK)) {
//Yay, murder!
}
else {
//Try the healz?
target = tower.pos.findClosestByRange(FIND_MY_CREEPS, {
filter: (creep) => {
return creep.hits < creep.hitsMax;
}
});
if(target && (tower.heal(target) == OK)) {
//Yay, anti-murder!
}
else {
var targets = utilsRoom.getMyDamagedStructures(tower.room);
if(targets.length && tower.repair(targets[0]) == OK) {
//Yay, anti-murder!
}
else {
var targets = utilsRoom.getUnownedDamagedStructures(tower.room);
if(targets.length && tower.repair(targets[0]) == OK) {
//Yay, anti-murder!
}
}
}
}
}
};
module.exports = roleTurret;