-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathstructure.tower.js
33 lines (26 loc) · 1.2 KB
/
structure.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
const ff = require("helper.friendFoeRecognition");
module.exports = {
run: function(tower) {
let friends = tower.room.find(FIND_MY_CREEPS, { filter: (creep) => creep.hits < creep.hitsMax && creep.memory.role !== "hopper" });
let warriors = _.filter(friends, (f) => _.some(f.body, (p) => p.type === ATTACK || p.type === RANGED_ATTACK));
if(warriors.length > 0) {
tower.heal(_.sortBy(warriors, (w) => w.pos.getRangeTo(tower))[0]);
return;
}
let hostiles = _.sortBy(ff.findHostiles(tower.room), (h) => h.hits - h.hitsMax);
if(hostiles.length > 0) {
tower.attack(hostiles[0]);
return;
}
if(friends.length > 0) {
tower.heal(_.sortBy(friends, (f) => f.pos.getRangeTo(tower))[0]);
return;
}
let closestDamagedStructure = tower.pos.findClosestByRange(FIND_MY_STRUCTURES, { filter: (s) => s.hits < s.hitsMax && s.hits < 5000 });
if(closestDamagedStructure) {
tower.repair(closestDamagedStructure);
}
}
};
const profiler = require("screeps-profiler");
profiler.registerObject(module.exports, 'tower');