-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.tower.js
More file actions
44 lines (41 loc) · 1.44 KB
/
role.tower.js
File metadata and controls
44 lines (41 loc) · 1.44 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
34
35
36
37
38
39
40
41
42
43
44
var roleTower = {
/** @param {Creep} tower **/
run: function(tower) {
var creepsInRoom = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(creepsInRoom!==null) {
tower.attack(creepsInRoom);
}
else
{
creepsInRoom = tower.pos.findClosestByRange(FIND_MY_CREEPS,
{
filter: function (object) {return (object.hits < object.hitsMax)
}
});
if(creepsInRoom !== null) {
tower.heal(creepsInRoom);
}
else
{
if(tower.energy>600) {
var toRepair =null;
toRepair = tower.pos.findClosestByRange(FIND_STRUCTURES, {
filter: function (object) {
return (object.hits < object.hitsMax*0.95 && object.structureType !== STRUCTURE_WALL && object.structureType !== STRUCTURE_RAMPART);
}
});
if(toRepair === null)
{
toRepair = tower.pos.findClosestByRange(FIND_STRUCTURES, {
filter: function (object) {
return (object.hits < object.hitsMax*0.95);
}
});
}
tower.repair(toRepair);
}
}
}
}
};
module.exports = roleTower;