forked from VladThePaler/screeps.behaviour-action-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creep.action.fueling.js
23 lines (23 loc) · 913 Bytes
/
creep.action.fueling.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let action = new Creep.Action('fueling');
module.exports = action;
action.maxPerTarget = 1;
action.maxPerAction = 1;
action.isValidAction = function(creep){
return ( creep.carry.energy > 0 && creep.room.towerFreeCapacity > 0 );
};
action.isValidTarget = function(target){
return ( (target != null) && (target.energy != null) && (target.energy < target.energyCapacity) );
};
action.isAddableTarget = function(target){
return ( target.my &&
(!target.targetOf || target.targetOf.length < this.maxPerTarget));
};
action.newTarget = function(creep){
return creep.room.structures.fuelable.length > 0 ? creep.pos.findClosestByRange(creep.room.structures.fuelable) : null;
};
action.work = function(creep){
let response = creep.transfer(creep.target, RESOURCE_ENERGY);
if( creep.target.energyCapacity - creep.target.energy < 20 )
creep.data.targetId = null;
return response;
};