-
Notifications
You must be signed in to change notification settings - Fork 0
/
guard.js
58 lines (52 loc) · 1.86 KB
/
guard.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Guard module to controll attacking creeps
*
*
*/
module.exports = function(creep) {
var squad = Memory.squad[creep.memory.squad]
for (var i in squad) {
if (squad[i].role == "leader" ) {
var leader = Game.getObjectById(squad[i].id)
if (leader) {
var target = leader.memory.target
} else {
var target = creep.pos.findClosestByPath(FIND_HOSTILE_CREEPS, {
filter: function(obj) {
if( obj.owner.username != 'Source Keeper' && Game.flags.RallyPoint.pos.getRangeTo(obj) < 20 ) {
return obj
}
}});
}
}
}
var closeEnemies = creep.pos.findInRange(FIND_HOSTILE_CREEPS,3)
if (closeEnemies.length != 0 && creep.pos.getRangeTo(target) > 3) {
target = closeEnemies[0]
}
var rallyPoint = Game.flags.RallyPoint
if (target && leader){
if (creep.attack(target) == ERR_NOT_IN_RANGE &&
creep.pos.getRangeTo(rallyPoint) < 8 &&
creep.pos.getRangeTo(leader) < 10) {
creep.moveTo(target)
} else if (creep.attack(target) == ERR_NOT_IN_RANGE && creep.pos.getRangeTo(target) <= 3 ) {
creep.moveTo(target)
} else {
creep.moveTo(leader)
}
} else if (target) {
if (creep.attack(target) == ERR_NOT_IN_RANGE && creep.pos.getRangeTo(rallyPoint) < 8) {
creep.moveTo(target)
} else if (creep.attack(target) == ERR_NOT_IN_RANGE && creep.pos.getRangeTo(target) <= 3 ) {
creep.moveTo(target)
}
}
else {
if (leader && creep.pos.getRangeTo(rallyPoint) < 9) {
creep.moveTo(leader)
}
else{
creep.moveTo(rallyPoint)
}
}
}