forked from VladThePaler/screeps.behaviour-action-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreep.action.upgrading.js
40 lines (40 loc) · 1.61 KB
/
creep.action.upgrading.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
let action = new Creep.Action('upgrading');
module.exports = action;
action.targetRange = 3;
action.isAddableAction = function(creep){
// no storage
return !creep.room.storage
// storage has surplus
|| (creep.room.storage.store.energy > MAX_STORAGE_ENERGY[creep.room.controller.level])
// storage is leftover from invasion and has usable energy
|| (!creep.room.storage.my && creep.room.storage.store.energy > 0);
};
action.isAddableTarget = function(target){ return true; };
action.isValidAction = function(creep){
return creep.carry.energy > 0;
};
action.isValidTarget = function(target){
return (target != null ) && target.structureType == 'controller' && target.my;
};
action.newTarget = function(creep){
return ( creep.room.controller && creep.room.controller.my) ? creep.room.controller : null;
};
action.work = function(creep, range){
if( range && range < 2 ) creep.controllerSign();
return creep.upgradeController(creep.room.controller);
};
action.step = function(creep){
if(CHATTY) creep.say(this.name, SAY_PUBLIC);
let range = creep.pos.getRangeTo(creep.target);
if( range <= this.targetRange ) {
let workResult = this.work(creep, range);
if( workResult != OK ) {
creep.handleError({errorCode: workResult, action: this, target: creep.target, range, creep});
}
}
creep.drive( creep.target.pos, this.reachedRange, this.targetRange, range );
};
action.onAssignment = function(creep, target) {
//if( SAY_ASSIGNMENT ) creep.say(String.fromCharCode(9962), SAY_PUBLIC);
if( SAY_ASSIGNMENT ) creep.say('\u{26EA}\u{FE0E}', SAY_PUBLIC);
};