screep/harvester.js

19 lines
682 B
JavaScript
Raw Normal View History

2020-10-23 20:55:20 +08:00
const path=require('path')
2020-10-18 22:00:22 +08:00
module.exports = {
run(creep) {
//分配source
if (creep.carry.energy < creep.carryCapacity) {
let sources = creep.room.find(FIND_SOURCES);
2020-10-23 20:55:20 +08:00
//TODO:只去一个地方
2020-10-18 22:00:22 +08:00
if (creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0]);
2020-10-23 20:55:20 +08:00
path.visualPath(creep.pos,sources[0].pos);
2020-10-18 22:00:22 +08:00
}
} else {
if (creep.transfer(Game.spawns['Spawn1'], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(Game.spawns['Spawn1']);
2020-10-23 20:55:20 +08:00
path.visualPath(creep.pos,Game.spawns['Spawn1'].pos);
2020-10-18 22:00:22 +08:00
}
}
}
}