-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRun.Tower.js
More file actions
55 lines (50 loc) · 2.38 KB
/
Copy pathRun.Tower.js
File metadata and controls
55 lines (50 loc) · 2.38 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
52
53
54
55
var towers = {
/** @param {Game} game **/
tick: function(roomname) {
towers = Game.rooms[roomname].find(FIND_MY_STRUCTURES, {
filter: { structureType: STRUCTURE_TOWER }
})
_.forEach(towers, function(tower){
let myclosestDamagedStructure = tower.room.find(FIND_STRUCTURES, {
filter: (structure) => structure.structureType != STRUCTURE_WALL && structure.structureType != STRUCTURE_RAMPART && structure.hits < structure.hitsMax
});
let closestDamagedStructure = _.first(_.sortBy(myclosestDamagedStructure, (s)=>s.hits / s.hitsMax));
let allcontainers = tower.room.find(FIND_STRUCTURES, {
filter: (s) => {
return ( s.structureType == STRUCTURE_CONTAINER)
}
});
let closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if(closestHostile) {
tower.attack(closestHostile);
} else
{
if(tower.energy > tower.energyCapacity * .7 ){
let importantstructures = tower.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_CONTAINER && structure.hits < structure.hitsMax) ;
}});
importantstructures = _.sortBy(importantstructures, (s)=>s.hits / s.hitsMax)
if(importantstructures.length > 0){
tower.repair(importantstructures[0]);
} else
{
if(closestDamagedStructure) {
if(tower.energy > tower.energyCapacity * 1.8 ){
if(global.verbosity>0){
console.log("tower repairing. Currently at: " + Game.rooms[roomname].memory.containerstoragepercent)
}
tower.repair(closestDamagedStructure);
} else {
if(global.verbosity>0){
console.log("tower waiting for more storage. Currently at: " + Game.rooms[roomname].memory.containerstoragepercent)
}
}
}
}
}
}
})
}
};
module.exports = towers;