forked from VladThePaler/screeps.behaviour-action-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtower.js
50 lines (49 loc) · 1.74 KB
/
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
let mod = {};
module.exports = mod;
mod.loop = function(room){
var run = tower => this.run(tower);
_.forEach(room.structures.towers, run);
};
mod.run = function(tower){
if(tower) {
// TODO: convert to action pattern
if( tower.room.casualties.length > 0) {
// Heal
var target = tower.room.casualties[0];
if(target.hitsMax - target.hits >= 400 || !tower.room.situation.invasion) {
tower.heal(target);
if( target.towers === undefined )
target.towers = [];
target.towers.push(tower.id);
return;
}
}
if( tower.room.structures.urgentRepairable.length > 0 ) {
// urgent Repair
var target = tower.room.structures.urgentRepairable[0];
tower.repair(target);
if( target.towers === undefined )
target.towers = [];
target.towers.push(tower.id);
return;
}
var closestHostile = tower.pos.findClosestByRange(tower.room.hostiles);
if(closestHostile) {
// Attack
tower.attack(closestHostile);
}
/*
else if( (tower.room.structures.repairable.length > 0) && (tower.energy > (tower.energyCapacity * 0.8)) ) {
// Repair
var isAddable = target => (target.towers === undefined || target.towers.length == 0);
var target = _.find(tower.room.structures.repairable, isAddable);
if( !_.isUndefined(target) ){
tower.repair(target);
if( target.towers === undefined )
target.towers = [];
target.towers.push(tower.id);
}
}
*/
}
};