2020-10-26 16:15:52 +08:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
|
/* eslint-disable func-names */
|
|
|
|
|
/* eslint-disable no-undef */
|
|
|
|
|
/* eslint-disable camelcase */
|
|
|
|
|
const utils = require("./utils");
|
2020-10-26 12:58:15 +08:00
|
|
|
|
|
|
|
|
function upgradeController_job(creep) {
|
2020-10-26 16:45:02 +08:00
|
|
|
const { working_target_id } = creep;
|
|
|
|
|
const working_target = Game.getObjectById(working_target_id);
|
|
|
|
|
if (utils.distance(creep.pos, working_target.pos) > 1.5) {
|
|
|
|
|
creep.moveTo(working_target);
|
|
|
|
|
} else {
|
|
|
|
|
const all_dropped_resource = creep.room.find(FIND_DROPPED_RESOURCES);
|
|
|
|
|
const nearest_dropped_enengy = _.filter(all_dropped_resource, function (
|
|
|
|
|
energy
|
2020-10-26 16:15:52 +08:00
|
|
|
) {
|
2020-10-26 16:45:02 +08:00
|
|
|
return (
|
|
|
|
|
energy.resourceType === RESOURCE_ENERGY &&
|
|
|
|
|
utils.distance(energy.pos, creep.pos) < 1.5
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
if (nearest_dropped_enengy.length > 0) {
|
|
|
|
|
const Re_code_pickup = creep.pickup(nearest_dropped_enengy[0]);
|
|
|
|
|
if (OK === Re_code_pickup || ERR_FULL === Re_code_pickup) {
|
|
|
|
|
// TODO:需要适应不同的建筑
|
|
|
|
|
const Re_code = creep.upgradeController(working_target);
|
|
|
|
|
// eslint-disable-next-line no-empty
|
|
|
|
|
if (OK === Re_code) {
|
|
|
|
|
} else if (
|
|
|
|
|
Re_code !== ERR_NOT_ENOUGH_RESOURCES &&
|
|
|
|
|
Re_code !== ERR_NOT_IN_RANGE
|
|
|
|
|
) {
|
|
|
|
|
console.log(
|
|
|
|
|
`${creep.name} failed to upgrade room controller:err ${Re_code}`
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
console.log(
|
|
|
|
|
`${creep.name} failed to pickup: err ${Re_code_pickup}`
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-10-26 12:58:15 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function build_construction(creep) {
|
2020-10-26 16:45:02 +08:00
|
|
|
const { working_target_id } = creep;
|
|
|
|
|
const working_target = Game.getObjectById(working_target_id);
|
|
|
|
|
if (utils.distance(creep.pos, working_target.pos) > 1.5) {
|
|
|
|
|
creep.moveTo(working_target);
|
|
|
|
|
} else {
|
|
|
|
|
const all_dropped_resource = creep.room.find(FIND_DROPPED_RESOURCES);
|
|
|
|
|
const nearest_dropped_enengy = _.filter(all_dropped_resource, function (
|
|
|
|
|
energy
|
2020-10-26 16:15:52 +08:00
|
|
|
) {
|
2020-10-26 16:45:02 +08:00
|
|
|
return (
|
|
|
|
|
energy.resourceType === RESOURCE_ENERGY &&
|
|
|
|
|
utils.distance(energy.pos, creep.pos) < 1.5
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
if (nearest_dropped_enengy.length > 0) {
|
|
|
|
|
const Re_code_pickup = creep.pickup(nearest_dropped_enengy[0]);
|
|
|
|
|
if (OK === Re_code_pickup || ERR_FULL === Re_code_pickup) {
|
|
|
|
|
// TODO:需要适应不同的建筑
|
|
|
|
|
const Re_code = creep.build(working_target);
|
|
|
|
|
// eslint-disable-next-line no-empty
|
|
|
|
|
if (OK === Re_code) {
|
|
|
|
|
} else if (
|
|
|
|
|
Re_code !== ERR_NOT_ENOUGH_RESOURCES &&
|
|
|
|
|
Re_code !== ERR_NOT_IN_RANGE
|
|
|
|
|
) {
|
|
|
|
|
console.log(`${creep.name} failed to build:err ${Re_code}`);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
console.log(
|
|
|
|
|
`${creep.name} failed to pickup: err ${Re_code_pickup}`
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-10-18 22:00:22 +08:00
|
|
|
}
|
2020-10-26 16:15:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-26 12:58:15 +08:00
|
|
|
|
2020-10-26 16:15:52 +08:00
|
|
|
module.exports = {
|
2020-10-26 16:45:02 +08:00
|
|
|
run(creep) {
|
|
|
|
|
if (creep.working_target_id) {
|
|
|
|
|
const { working_target_id } = creep;
|
|
|
|
|
const working_target = Game.getObjectById(working_target_id);
|
|
|
|
|
if (!working_target) {
|
|
|
|
|
// creep.working_target_id=undefined//目标已经完成,转为空闲状态
|
|
|
|
|
// _.each(Memery.WorkingTarget[creep.name].working_creep_names,creep_name=>Game.creeps[creep_name].working_target_id=undefined)
|
|
|
|
|
// delete Memery.WorkingTarget[creep.name]
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (working_target.structureType === STRUCTURE_CONTROLLER) {
|
|
|
|
|
creep.say("ug");
|
|
|
|
|
upgradeController_job(creep);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
creep.say("bd");
|
|
|
|
|
build_construction(creep);
|
|
|
|
|
} else {
|
|
|
|
|
creep.say("SB");
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-10-26 16:15:52 +08:00
|
|
|
};
|