var battle = require('battle') //var helpers = require('helpers'); var structureTower= { run: function(structure){ this.structure = structure; console.log(structure, 'running Tower') var target = battle.findEnemy(this.structure); if(target != structure.room.controller) { console.log('\t', this.structure, 'attacking:',target) this.structure.attack(target); } else { var damagedStructure = this.findDamagedStructure(); if(damagedStructure){ console.log("repairing", damagedStructure); this.structure.repair(damagedStructure); } } }, findDamagedStructure: function(searcher){ var targets = searcher.room.find(FIND_STRUCTURES, { filter: function(s){ if(s.structureType == STRUCTURE_TOWER){ return false; } if (s.hits < s.hitsMax){ return true; } return false; } }); return searcher.pos.findClosestByPath(targets); } } module.exports = structureTower;