screeps/role.nrminer.js
2017-07-13 23:24:42 -05:00

26 lines
1.0 KiB
JavaScript

let assignMiners=require('sproc')
let rolenrMiner = {
run: function(creep) {
if(Game.flags.nrbuild.pos.isEqualTo(creep.pos) && creep.room == Game.flags.nrbuild.room){
if(creep.memory.destsource===undefined){
console.log("changing role from nrminer to miner")
creep.memory.role='miner'
assignMiners(creep.roomName)
}
if(creep.memory.originroom === undefined){
creep.memory.originroom = creep.room.name
creep.moveTo(Game.flags.nrbuild)
creep.memory.role='miner'
}
if(Game.getObjectById(creep.memory.destsource.id)==undefined){creep.memory.destsource=undefined}
let mysource=Game.getObjectById(creep.memory.destsource.id)
if(creep.harvest(mysource) == ERR_NOT_IN_RANGE) {
creep.moveTo(mysource);
}
} else {
creep.moveTo(Game.flags.nrbuild)
}
}
};
module.exports = rolenrMiner;