Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var roleHarvester = {
- /** @param {Creep} creep **/
- run: function(creep)
- {
- // console.log(creep.memory.building)
- var targets = creep.room.find(FIND_STRUCTURES,
- {
- filter: (structure) =>
- {
- return (structure.structureType == STRUCTURE_EXTENSION ||
- structure.structureType == STRUCTURE_SPAWN ||
- structure.structureType == STRUCTURE_TOWER) && structure.energy < structure.energyCapacity;
- }
- });
- if (targets.length > 0)
- {
- if(creep.carry.energy < creep.carryCapacity) {
- var sources = creep.room.find(FIND_SOURCES);
- if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
- creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
- }
- }
- else {
- var targets = creep.room.find(FIND_STRUCTURES, {
- filter: (structure) => {
- return (structure.structureType == STRUCTURE_EXTENSION ||
- structure.structureType == STRUCTURE_SPAWN ||
- structure.structureType == STRUCTURE_TOWER) && structure.energy < structure.energyCapacity;
- }
- });
- if(targets.length > 0) {
- if(creep.transfer(targets[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
- creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#ffffff'}});
- }
- }
- }
- }
- else
- {
- if(creep.carry.energy == 0)
- {
- creep.memory.building = false;
- }
- else if (creep.carry.energy >= creep.carryCapacity)
- {
- creep.memory.building = true;
- }
- if(creep.memory.building)
- {
- var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
- if(targets.length)
- {
- if(targets[0].structureType == STRUCTURE_EXTENSION)
- {
- if(creep.build(targets[0]) == ERR_NOT_IN_RANGE)
- {
- creep.moveTo(targets[0], {visualizePathStyle: {stroke: '#33ff33'}});
- }
- }
- }
- }
- else
- {
- var sources = creep.room.find(FIND_SOURCES);
- if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
- creep.moveTo(sources[0], {visualizePathStyle: {stroke: '#ffaa00'}});
- }
- }
- }
- }
- };
- module.exports = roleHarvester;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement