-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrole.tower.js
More file actions
51 lines (47 loc) · 1.64 KB
/
Copy pathrole.tower.js
File metadata and controls
51 lines (47 loc) · 1.64 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
45
46
47
48
49
50
51
var roleTower = {
getPriority: function(structure) {
if (structure.structureType == STRUCTURE_TOWER) {
return 100;
} else if (structure.structureType == STRUCTURE_RAMPART) {
return -1;
} else if (structure.structureType == STRUCTURE_ROAD) {
return 20;
} else if (structure.structureType == STRUCTURE_CONTAINER) {
return 0;
} else if (structure.structureType == STRUCTURE_STORAGE) {
return 0;
} else {
return 0;
}
},
run: function(tower) {
// attack nearest hostile creep
var target = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if (target) {
tower.attack(target);
return;
}
if (tower.energy < tower.energyCapacity * 0.3) {
return;
}
// repair damaged structure
var damagedStructure = tower.room.find(FIND_STRUCTURES, {
filter: (structure) => (structure.hits <= structure.hitsMax - 500 &&
(structure.structureType != STRUCTURE_RAMPART || structure.hits < 10000 ||
structure.hits >= structure.hitsMax - 10000) &&
structure.structureType != STRUCTURE_WALL)
});
target = damagedStructure[0];
// find the one with largest priority
for (var i in damagedStructure) {
if (this.getPriority(damagedStructure[i]) > this.getPriority(target)) {
target = damagedStructure[i];
}
}
if (target) {
tower.repair(target);
return;
}
}
};
module.exports = roleTower;