-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrole.attacker.js
42 lines (42 loc) · 1.45 KB
/
role.attacker.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
37
38
39
40
41
42
module.exports = {
run: function(creep) {
if (Game.time % 10 === 0) {
creep.memory.targetLocation[0] = Game.flags['Rally1'].pos.x;
creep.memory.targetLocation[1] = Game.flags['Rally1'].pos.y;
}
if (creep.spawning === false) {
if (creep.memory.mode === 'defending') {
var targets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 1);
if (targets.length > 0) {
creep.attack(targets[0]);
} else {
var targets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 3);
if (targets.length > 0) {
creep.rangedAttack(targets[0]);
} else {
var targets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 999);
if (targets.length > 0) {
creep.moveTo(targets[0]);
} else {
creep.moveTo(creep.memory.targetLocation[0], creep.memory.targetLocation[1]);
}
}
}
} else if (creep.memory.mode === 'attacking') {
var targets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 1);
if (targets.length > 0) {
creep.attack(targets[0]);
} else {
var targets = creep.pos.findInRange(FIND_HOSTILE_CREEPS, 3);
if (targets.length > 0) {
creep.rangedAttack(targets[0]);
}
}
var targets = creep.pos.findInRange(FIND_HOSTILE_SPAWNS, 3);
if (targets.length > 0) {
creep.attack(targets[0]);
}
}
}
}
};