forked from VladThePaler/screeps.behaviour-action-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creep.action.repairing.js
35 lines (35 loc) · 1.21 KB
/
creep.action.repairing.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
let action = new Creep.Action('repairing');
module.exports = action;
action.targetRange = 3;
action.maxPerTarget = 1;
action.isValidAction = function(creep){
return (creep.carry.energy > 0 );
};
action.isValidTarget = function(target){
return ( target != null && target.hits &&
target.hits < target.hitsMax);
};
action.isAddableTarget = function(target, creep){
return (
(target instanceof OwnedStructure && target.my) ||
(
(!creep.room.controller ||
(
(!creep.room.controller.owner || creep.room.controller.my) &&
(!creep.room.controller.reservation || creep.room.controller.reservation.username == creep.owner.username)
)
)
)
) && (!target.targetOf || target.targetOf.length < this.maxPerTarget);
};
action.newTarget = function(creep){
var that = this;
var isAddable = target => that.isAddableTarget(target, creep);
return _.find(creep.room.structures.urgentRepairable, isAddable);
};
action.work = function(creep){
return creep.repair(creep.target);
};
action.onAssignment = function(creep, target) {
if( SAY_ASSIGNMENT ) creep.say(String.fromCharCode(9874), SAY_PUBLIC);
};