-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrole.healer.js
37 lines (37 loc) · 1.1 KB
/
role.healer.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
module.exports = {
// a function to run the logic for this role
/** @param {Creep} creep */
run: function(creep) {
if (creep.memory.target != undefined && 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;
}
if (creep.memory.partner == undefined) {
creep.memory.partner = creep.pos.findClosestByRange(FIND_MY_CREEPS, {
filter: function(otherCreep) {
return otherCreep.memory.role == 'attacker' ||
otherCreep.memory.role == 'dismantler';
}
});
}
else
{
partner = Game.getObjectById(creep.memory.partner.id);
if (partner.hits < partner.hitsMax) {
if (creep.heal(partner) == ERR_NOT_IN_RANGE) {
creep.travelTo(partner);
}
}
else if(creep.hits < creep.hitsMax){
creep.heal(creep);
}
else{
creep.travelTo(partner.pos);
}
}
}
};