forked from zfmarkham/screeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.defend.js
36 lines (27 loc) · 1.01 KB
/
task.defend.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
/**
* Created by zmark_000 on 29/12/2016.
*/
let utils = require('utils');
let defend = {
defend: function(creep) {
if (creep.memory.archerSpot)
{
let flag = Game.flags[creep.memory.archerSpot];
if (creep.moveTo(flag.pos.x, flag.pos.y, {noPathFinding: true}) == ERR_NOT_FOUND)
{
creep.moveTo(flag.pos.x, flag.pos.y);
}
let target = creep.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
if (target) {
creep.rangedAttack(target);
}
}
else
{
let occupiedArcherSpots = _.filter(Game.creeps, (creep) => creep.memory.role == 'defender').map((el) => el.memory.archerSpot);
let closestFlag = creep.pos.findClosestByRange(FIND_FLAGS, {filter: (flag) => flag.name.includes("ArcherSpot") && occupiedArcherSpots.indexOf(flag.name) == -1});
if (closestFlag) creep.memory.archerSpot = closestFlag.name;
}
}
};
module.exports = defend;