screeps/role.upgrader.js

49 lines
2.3 KiB
JavaScript
Raw Normal View History

2017-06-06 13:17:26 -05:00
let buildparts=require('bodypartbuilder')
2016-09-28 08:37:28 -05:00
let roleUpgrader = {
2016-09-23 00:12:42 -05:00
run: function(creep) {
2016-09-28 08:37:28 -05:00
if(creep.memory.originroom === undefined){
creep.memory.originroom = creep.room.name
}
2016-09-23 00:12:42 -05:00
if(creep.memory.upgrading==undefined){creep.memory.upgrading=true}
if(creep.memory.upgrading && creep.carry.energy == 0) {
2016-09-15 00:30:24 -05:00
creep.memory.upgrading = false;
creep.say('harvesting');
}
if(!creep.memory.upgrading && creep.carry.energy == creep.carryCapacity) {
creep.memory.upgrading = true;
creep.say('upgrading');
}
if(creep.memory.upgrading) {
2017-06-06 13:17:26 -05:00
if(creep.room.memory.containerstoragepercent>creep.room.memory.minupgradepct || !(creep.room.memory.containerstoragepercent) ){
2016-09-23 00:12:42 -05:00
if(creep.upgradeController(creep.room.controller) == ERR_NOT_IN_RANGE) {
creep.say('MTRC')
creep.moveTo(creep.room.controller);
}
2016-09-23 00:12:42 -05:00
} else { creep.moveTo(creep.room.memory.upgraderparkx,creep.room.memory.upgraderparky,creep.room.roomName) }
} else {
2016-09-28 08:37:28 -05:00
let container = creep.pos.findClosestByRange(FIND_STRUCTURES, {
2016-09-23 00:12:42 -05:00
filter: (structure) => {
return ((structure.structureType == STRUCTURE_CONTAINER|| structure.structureType == STRUCTURE_STORAGE) && structure.store[RESOURCE_ENERGY] > 0) ;
}});
2017-06-06 13:17:26 -05:00
let allcontainers = creep.room.find(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_CONTAINER || structure.structureType == STRUCTURE_STORAGE ) ;
}});
if(allcontainers.length==0){
let droppedenergy = creep.room.find(FIND_DROPPED_RESOURCES, {filter: {resourceType: RESOURCE_ENERGY}});
2016-09-15 00:30:24 -05:00
if(creep.pickup(droppedenergy[0]) == ERR_NOT_IN_RANGE) {
2016-09-23 00:12:42 -05:00
creep.say("MTDE");
creep.moveTo(droppedenergy[0]);
}
2017-06-06 13:17:26 -05:00
}else{
if(creep.withdraw(container,RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.say("MTSC");
creep.moveTo(container);
}
2016-09-15 00:30:24 -05:00
}
}
2016-09-23 00:12:42 -05:00
}
2016-09-15 00:30:24 -05:00
};
module.exports = roleUpgrader;