-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimmobile.tower.js
62 lines (58 loc) · 2.37 KB
/
immobile.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
var s = require('shared');
var towerLoop = function towerLoop(room, tower) {
var targets = [];
var err = OK;
targets = room.find(FIND_CREEPS, {filter: (cre) => !cre.my && cre.getActiveBodyparts(HEAL) > 0});
if (targets.length === 0 ) {
targets = room.find(FIND_HOSTILE_CREEPS);
}
if (targets.length === 0 ) {
targets = room.find(FIND_HOSTILE_STRUCTURES);
}
if (targets.length === 0) {
targets = room.find(FIND_HOSTILE_CONSTRUCTION_SITES);
}
if (targets.length !== 0) {
err = tower.attack(targets[0]);
} else {
if (targets.length === 0) {
targets = room.find(FIND_MY_STRUCTURES, {filter: (str) => str.hits < str.hitsMax && str.structureType != STRUCTURE_RAMPART});
}
if (targets.length === 0) {
targets = room.find(FIND_STRUCTURES, {filter: (str) => str.hits < str.hitsMax && str.structureType != STRUCTURE_RAMPART && str.structureType != STRUCTURE_WALL});
}
if (targets.length === 0) {
targets = room.find(FIND_STRUCTURES, {filter: (str) => str.structureType == STRUCTURE_RAMPART && str.hits < str.hitsMax && str.hits < 100000 });
}
if (targets.length === 0) {
targets = room.find(FIND_STRUCTURES, {filter: (str) => str.hits < str.hitsMax && str.hits < 10000 });
}
if (targets.length === 0 && tower.energy > tower.energyCapacity / 2) {
if (targets.length === 0) {
targets = room.find(FIND_STRUCTURES, {filter: (str) => str.hits < str.hitsMax && str.hits < 250000 });
}
if (targets.length === 0) {
targets = room.find(FIND_STRUCTURES, {filter: (str) => str.structureType == STRUCTURE_RAMPART && str.hits < str.hitsMax && str.hits < 400000 });
}
if (targets.length === 0) {
targets = room.find(FIND_STRUCTURES, {filter: (str) => str.hits < str.hitsMax && str.hits < 1000000});
}
}
if (targets.length !== 0) {
targets.sort((a, b) => a.hits - b.hits);
err = tower.repair(targets[0]);
}
}
switch(err) {
case OK:
break;
case ERR_NOT_ENOUGH_ENERGY:
break;
default:
console.log('tower had error ' + err + ' with target ' + targets[0]);
}
return;
};
module.exports = {
run: towerLoop
};