forked from VladThePaler/screeps.behaviour-action-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreep.action.travelling.js
26 lines (26 loc) · 1.01 KB
/
creep.action.travelling.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
let action = new Creep.Action('travelling');
module.exports = action;
action.isValidTarget = function(target){ return target != null; };
action.isAddableAction = function(){ return true; };
action.isAddableTarget = function(){ return true; };
action.newTarget = function(creep){ return null; }
action.step = function(creep){
if(CHATTY) creep.say(this.name, SAY_PUBLIC);
if( creep.target ){
let pos;
if( creep.target.id == creep.id ) pos = new RoomPosition(25, 25, creep.data.travelRoom);
else pos = creep.target.pos;
creep.drive( pos, this.reachedRange, this.targetRange, Infinity );
}
if( !creep.target || creep.target.pos.roomName == creep.pos.roomName ){
// unregister
delete creep.action;
delete creep.target;
delete creep.data.actionName;
delete creep.data.targetId;
delete creep.data.travelRoom;
}
}
action.onAssignment = function(creep, target) {
if( SAY_ASSIGNMENT ) creep.say(String.fromCharCode(9784), SAY_PUBLIC);
};