-
Notifications
You must be signed in to change notification settings - Fork 0
/
role.drainer.js
57 lines (57 loc) · 1.69 KB
/
role.drainer.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
module.exports = {
// a function to run the logic for this role
/** @param {Creep} creep */
run: function(creep) {
if (creep.memory.retreating == true) {
if (creep.room.name == creep.memory.retreatTarget) {
var exit = creep.room.findExitTo(creep.memory.target);
var exitPos = creep.pos.findClosestByRange(exit);
var distanceFromTargetRoom = creep.pos.getRangeTo(exitPos);
if (distanceFromTargetRoom < 2) {
var exit = creep.room.findExitTo(creep.memory.home);
// move to exit
creep.travelTo(creep.pos.findClosestByRange(exit));
} else {
creep.memory.retreating = false;
}
} else {
var exit = creep.room.findExitTo(creep.memory.retreatTarget);
// move to exit
creep.travelTo(creep.pos.findClosestByRange(exit));
return
}
}
else
{
if (creep.hits < creep.hitsMax)
{
creep.heal(creep);
creep.memory.retreating = true;
}
else
{
const target = creep.pos.findClosestByRange(FIND_MY_CREEPS, {
filter: function(object) {
return object.hits < object.hitsMax;
}
});
if (target && creep.heal(target) != ERR_NOT_IN_RANGE)
{
creep.heal(target)
}
else
{
if (creep.room.name != creep.memory.target)
{
// find exit to target room
var exit = creep.room.findExitTo(creep.memory.target);
// move to exit
creep.travelTo(creep.pos.findClosestByRange(exit));
// return the function to not do anything else
return;
}
}
}
}
}
};