forked from VladThePaler/screeps.behaviour-action-pattern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
creep.behaviour.remoteMiner.js
49 lines (48 loc) · 1.65 KB
/
creep.behaviour.remoteMiner.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
41
42
43
44
45
46
47
48
49
let mod = {};
module.exports = mod;
mod.name = 'remoteMiner';
mod.run = function(creep) {
if (Creep.action.avoiding.run(creep)) {
return;
}
if (!creep.action || creep.action.name === 'idle') {
// assign Action
if( creep.room.name === creep.data.destiny.room || creep.data.determinatedTarget ){
// if we're there (or have been), be a miner.
this.mine(creep);
return;
} else {
// else go there
this.gotoTargetRoom(creep);
}
}
// Do some work
if( creep.action && creep.target ) {
creep.action.step(creep);
} else {
logError('Creep without action/activity!\nCreep: ' + creep.name + '\ndata: ' + JSON.stringify(creep.data));
}
};
mod.mine = function(creep) {
return Creep.behaviour.miner.run(creep, {remote:true, approach:mod.approach});
};
mod.approach = function(creep){
let targetPos = new RoomPosition(creep.data.determinatedSpot.x, creep.data.determinatedSpot.y, creep.data.destiny.room);
let range = creep.pos.getRangeTo(targetPos);
if( range > 0 ) {
creep.travelTo( targetPos, {range:0} );
if( range <= 2 && !creep.data.predictedRenewal ) {
creep.data.predictedRenewal = _.min([500, 1500 - creep.ticksToLive + creep.data.spawningTime]);
}
}
return range;
};
mod.gotoTargetRoom = function(creep){
const targetFlag = creep.data.destiny ? Game.flags[creep.data.destiny.targetName] : null;
if (targetFlag) return Creep.action.travelling.assignRoom(creep, targetFlag.pos.roomName);
};
mod.strategies = {
defaultStrategy: {
name: `default-${mod.name}`,
},
};