You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
screeps/default/role.remoteHarvester.js

57 lines
2.1 KiB

8 months ago
let common = require('common')
module.exports = {
name: 'remoteHarvester',
prio: 10,
8 months ago
minRcl: 3,
8 months ago
bodies: [
[WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE],
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE],
[WORK, WORK, WORK, WORK, WORK, WORK, CARRY, CARRY, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE, MOVE],
],
tick (creep) {
let dropped = creep.pos.findInRange(FIND_DROPPED_RESOURCES, 1);
if (dropped.length > 0) {
creep.pickup(dropped[0])
}
let repairTargets = creep.pos.findInRange(
FIND_STRUCTURES,
3,
{filter: s => s.structureType === STRUCTURE_CONTAINER && s.hits + creep.getActiveBodyparts(WORK) * 100 <= s.hitsMax});
if (repairTargets.length > 0) {
if (creep.store[RESOURCE_ENERGY] >= creep.getActiveBodyparts(WORK) * 10 && creep.repair(repairTargets[0]) === OK) {
return
}
} else {
8 months ago
let targets = creep.pos.findInRange(FIND_STRUCTURES, 1, {
filter: (structure) => structure.store && structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0
8 months ago
});
8 months ago
if (targets.length > 0) {
creep.transfer(_.min(targets, el => el.store[RESOURCE_ENERGY]), RESOURCE_ENERGY)
8 months ago
} else {
8 months ago
let targetCreeps = creep.pos.findInRange(FIND_MY_CREEPS, 1, {
filter: tc => tc.store.getFreeCapacity(RESOURCE_ENERGY) && tc.memory.role !== 'remoteHarvester'
8 months ago
});
8 months ago
if (targetCreeps.length > 0) {
creep.transfer(targetCreeps[0], RESOURCE_ENERGY)
} else if (creep.store[RESOURCE_ENERGY] >= creep.getActiveBodyparts(WORK) * 5) {
let buildTargets = creep.pos.findInRange(FIND_MY_CONSTRUCTION_SITES, 1);
if (buildTargets.length > 0 && creep.build(buildTargets[0]) === OK) {
return
8 months ago
}
}
}
}
let target = Game.getObjectById(creep.memory.source)
let actionResult = creep.harvest(target)
if (actionResult === ERR_NOT_IN_RANGE) {
8 months ago
creep.moveTo(target, {visualizePathStyle: {stroke: '#ffaa00'}})
}
else if (actionResult === ERR_INVALID_TARGET) {
moveToRoom(creep, creep.memory.room)
8 months ago
}
}
};