Adding source code to respository.
This commit is contained in:
36
towers.js
Normal file
36
towers.js
Normal file
@@ -0,0 +1,36 @@
|
||||
module.exports = {
|
||||
|
||||
run: function(){
|
||||
for(var spawn in Game.spawns){
|
||||
var room = Game.spawns[spawn].room;
|
||||
var towers = room.find(FIND_MY_STRUCTURES,
|
||||
{filter: {structureType: STRUCTURE_TOWER}});
|
||||
|
||||
for(var tower in towers){
|
||||
tower = towers[tower];
|
||||
var enemy = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
|
||||
if(enemy != null) tower.attack(enemy);
|
||||
else {
|
||||
var healt_creep = false;
|
||||
for(var creep in Game.creeps){
|
||||
creep = Game.creeps[creep];
|
||||
if(creep.hits < creep.hitsMax) {
|
||||
tower.heal(creep);
|
||||
healt_creep = true;
|
||||
}
|
||||
}
|
||||
if(!healt_creep && 500 < tower.energy){
|
||||
var structure = tower.pos.findClosestByPath(FIND_STRUCTURES,
|
||||
{filter: (s)=>(s.structureType != STRUCTURE_RAMPART && s.structureType != STRUCTURE_WALL && s.hits < s.hitsMax)});
|
||||
if(750 < tower.energy && structure == null) {
|
||||
var structures = tower.room.find(FIND_STRUCTURES, {filter: { structureType: STRUCTURE_RAMPART, structureType: STRUCTURE_WALL }});
|
||||
structures.sort(function(a,b){return a.hits - b.hits});
|
||||
structure = structures[0];
|
||||
}
|
||||
tower.repair(structure);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user