-
Notifications
You must be signed in to change notification settings - Fork 0
/
healer.js
134 lines (126 loc) · 4.52 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
* "The Guard hasn't been improved in a while, I've mostly just moved on to archers for now. I'll come back and
* work on this one later"
* Thus spake Zaratustra
* @param creep
*/
find = require('find');
/*
var heal_targets_all;
var urgent_heal_targets_all;
var heal_targets;
var urgent_heal_targets;
var warriors;
var flag_warriors;
*/
Creep.prototype.healer_action = function()
{
let hostiles = this.room.find(FIND_HOSTILE_CREEPS);
let close_hostiles = _.filter(hostiles, function(c){
return this.pos.inRangeTo(c,1);
});
let closest;
if (urgent_heal_targets_all.length){
closest = this.pos.findClosestByRange(urgent_heal_targets_all) ||
(urgent_heal_targets_all.length && urgent_heal_targets_all[0]);
this.moveTo(closest);
if (closest){
this.heal(closest);
this.rangedHeal(closest);
}
return
} else if (heal_targets_all.length){
closest = this.pos.findClosestByRange(heal_targets_all) ||
(heal_targets_all.length && heal_targets_all[0]);
this.moveTo(closest);
this.heal(this);
if (closest){
this.heal(closest);
this.rangedHeal(closest);
}
return
/*
} else if (flag_warriors.length){
let closest = this.pos.findClosestByRange(flag_warriors);
if (closest){
this.moveTo(closest);
} else if (flag_warriors.length){
this.moveTo(flag_warriors[0]);
}*/
//console.log('this.rest();');
} else if (warriors.length){
//var closest = this.pos.findClosestByRange(warriors);
closest = _.sortBy(warriors, c => c.body.length);
closest = closest[closest.length - 1];
if (closest){
this.moveTo(closest);
} else if (warriors.length){
this.moveTo(warriors[0]);
}
return
//console.log('this.rest();');
} else {
flag = Game.flags.Flag2;
if (!this.pos.inRangeTo(flag,2)){
this.moveTo(flag);
}
}
if (close_hostiles.length || this.room.find(FIND_HOSTILE_STRUCTURES, {
filter: s => s.structureType == STRUCTURE_TOWER,
}).length) {
this.moveTo(Game.spawns.Spawn1);
}
}
var healer = {
heal_targets: function(){ return heal_targets; },
urgent_heal_targets: function(){ return urgent_heal_targets; },
heal_targets_all: function(){ return heal_targets_all; },
urgent_heal_targets_all: function(){ return urgent_heal_targets_all; },
parts: [
//[Game.TOUGH, Game.MOVE, , Game.ATTACK]
[TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, HEAL],
[TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, HEAL, HEAL],
[TOUGH, TOUGH, TOUGH, TOUGH, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, HEAL, HEAL, HEAL],
[TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, HEAL, HEAL],
[TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE, HEAL, HEAL, HEAL],
[TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, HEAL, HEAL, HEAL, HEAL],
[TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, TOUGH, MOVE, MOVE, MOVE, MOVE, MOVE,
MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, HEAL, HEAL, HEAL, HEAL, HEAL],
],
update: function()
{
heal_targets_all = find(FIND_MY_CREEPS, {
filter: function (c){
return c.hits < c.hitsMax;
}
});
urgent_heal_targets_all = find(FIND_MY_CREEPS, {
filter: function (c){
return c.hits < c.hitsMax / 2;
}
});
heal_targets = {};
urgent_heal_targets = {};
let filter = room => (c => c.pos.roomName == room);
for (let room in Game.rooms){
heal_targets[room] = heal_targets_all.filter(filter(room));
urgent_heal_targets[room] = urgent_heal_targets_all.filter(filter(room));
}
/*
flag_warriors = find(FIND_MY_CREEPS,{
filter: function(c){
return c && c.has(ATTACK) && c.pos.inRangeTo(Game.flags.Flag6,6);
}
});
*/
warriors = find(FIND_MY_CREEPS,{
filter: function(c){
return c.has(ATTACK);
}
});
},
};
module.exports = healer;