forked from VladThePaler/screeps.behaviour-action-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creep.action.healing.js
32 lines (32 loc) · 948 Bytes
/
creep.action.healing.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
let action = new Creep.Action('healing');
module.exports = action;
action.targetRange = 3;
action.isAddableAction = function(){ return true; };
action.isAddableTarget = function(){ return true; };
action.isValidTarget = function(target){
return ( target != null &&
target.hits != null &&
target.hits < target.hitsMax &&
target.my );
};
action.newTarget = function(creep){
if(creep.room.casualties.length > 0){
for (const target of creep.room.casualties) {
if (target.name !== creep.name) {
return target;
}
}
}
return null;
};
action.work = function(creep){
if( creep.target.hits < creep.target.hitsMax ){
if( creep.pos.isNearTo(creep.target) ){
return creep.heal(creep.target);
}
if(creep.pos.inRangeTo(creep.target, 3)) {
return creep.rangedHeal(creep.target);
}
return OK;
}
};