forked from shryme/Screeps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsourceHealer.js
49 lines (40 loc) · 1.6 KB
/
sourceHealer.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
module.exports = function (creep) {
//Find the closest source_destroyer
var sourceDestroyer = creep.pos.findClosest(Game.MY_CREEPS, {filter: function(object) {return object.memory.role === 'source_destroyer'} });
if (sourceDestroyer) {
if (Game.spawns.Spawn1.memory.keeper_neutralized === true) {
//When the source destroyer is finished, move healer below it to start healing everything
healLowestCreep(creep, sourceDestroyer);
}
else {
//If the source destroyer is destroying the source keeper, let the source destroyer destroy the source keeper
healSourceDestroyer(creep, sourceDestroyer);
}
}
}
function healSourceDestroyer(creep, sourceDestroyer) {
if (creep.room.lookAt(sourceDestroyer.pos.x, sourceDestroyer.pos.y - 1).length === 1)
creep.moveTo(sourceDestroyer.pos.x, sourceDestroyer.pos.y - 1);
else
creep.moveTo(sourceDestroyer.pos.x + 1, sourceDestroyer.pos.y - 1);
creep.heal(sourceDestroyer);
}
function healLowestCreep(creep, sourceDestroyer) {
if (creep.room.lookAt(sourceDestroyer.pos.x, sourceDestroyer.pos.y + 2).length === 1)
creep.moveTo(sourceDestroyer.pos.x, sourceDestroyer.pos.y + 2);
else
creep.moveTo(sourceDestroyer.pos.x, sourceDestroyer.pos.y + 1);
var targets = creep.pos.findInRange(Game.MY_CREEPS, 3);
var lowestCreep;
for (var i = 0; i < targets.length; i++) {
if (targets[i].id !== creep.id && (lowestCreep === undefined || targets[i].hits < lowestCreep.hits))
lowestCreep = targets[i];
}
if (lowestCreep) {
var range = creep.pos.getRangeTo(lowestCreep);
if (range > 1)
creep.rangedHeal(lowestCreep);
else
creep.heal(lowestCreep);
}
}