2020-10-23 22:19:47 +08:00
|
|
|
const utils = require('utils')
|
2020-10-18 22:00:22 +08:00
|
|
|
module.exports = {
|
|
|
|
|
run(creep) {
|
2020-10-24 15:24:24 +08:00
|
|
|
creep.say('builder')
|
2020-10-23 20:55:20 +08:00
|
|
|
if (creep.working_target_id) {
|
|
|
|
|
let working_target_id = creep.working_target_id;
|
|
|
|
|
let working_target = Game.getObjectById(working_target_id);
|
2020-10-23 22:19:47 +08:00
|
|
|
if (utils.distance(creep.pos, working_target.pos) > 1.5) {
|
2020-10-23 20:55:20 +08:00
|
|
|
creep.moveTo(working_target);
|
2020-10-23 22:19:47 +08:00
|
|
|
} else {
|
|
|
|
|
let all_dropped_resource = creep.room.find(FIND_DROPPED_RESOURCES)
|
|
|
|
|
let nearest_dropped_enengy = _.filter(all_dropped_resource, function (energy) {
|
|
|
|
|
return energy.resourceType == RESOURCE_ENERGY & utils.distance(energy.pos, creep.pos) < 1.5
|
|
|
|
|
})
|
|
|
|
|
if (nearest_dropped_enengy.length > 0) {
|
|
|
|
|
let Re_code_pickup = creep.pickup(nearest_dropped_enengy[0]);
|
|
|
|
|
if (OK == Re_code_pickup) {
|
|
|
|
|
//TODO:需要适应不同的建筑
|
|
|
|
|
let Re_code = creep.upgradeController(working_target)
|
|
|
|
|
if (OK == Re_code) {
|
2020-10-24 15:24:24 +08:00
|
|
|
} else if(Re_code!=ERR_NOT_ENOUGH_RESOURCES && Re_code!=ERR_NOT_IN_RANGE){
|
2020-10-23 22:19:47 +08:00
|
|
|
console.log(`${creep.name} failed to upgrade room controller:err ${Re_code}`)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 22:00:22 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|