1 Star 0 Fork 0

Leviaton/Screeps

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
role.harvester.js 2.05 KB
一键复制 编辑 原始数据 按行查看 历史
Lev 提交于 2020-02-17 12:50 . first commit
module.exports = {
run: function(creep){
if(creep.store[RESOURCE_ENERGY] < creep.store.getCapacity() || 1) {
creep.say('欧拉!');
var tar = creep.pos.findClosestByPath(FIND_SOURCES);
if(!tar){ creep.say('Confused :('); return -1; }
if(creep.room.name == 'W35N28'){
creep.say('dd');
if(creep.pos.isEqualTo(Game.flags['Source1R1'])) creep.harvest(tar);
else creep.moveTo(Game.flags['Source1R1'],{visualizePathStyle: {stroke: '#ffaa00'}});
}else{
creep.say('dd');
if(creep.pos.isEqualTo(Game.flags['Source1R2'])) creep.harvest(tar);
else creep.moveTo(Game.flags['Source1R2'],{visualizePathStyle: {stroke: '#ffaa00'}});
}
if(creep.pos.isEqualTo(Game.flags['Source1R1'])) creep.drop(RESOURCE_ENERGY);
if(creep.pos.isEqualTo(Game.flags['Source1R2'])) creep.drop(RESOURCE_ENERGY);
}else{
//creep.drop(RESOURCE_ENERGY);
//return;
var targets = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (structure) => {
return (
structure.structureType == STRUCTURE_EXTENSION ||
structure.structureType == STRUCTURE_SPAWN ||
structure.structureType == STRUCTURE_TOWER) && structure.store[RESOURCE_ENERGY] < structure.energyCapacity;
}
});
if(creep.room.energyAvailable >= 1000) targets = creep.pos.findClosestByPath(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType == STRUCTURE_TOWER) && structure.store[RESOURCE_ENERGY] < structure.energyCapacity;
}
});
if(targets) {
if(creep.transfer(targets, RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets, {visualizePathStyle: {stroke: '#ffffff'}});
}
}else console.log("CRY!");
}
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/Chorolop/Screeps.git
git@gitee.com:Chorolop/Screeps.git
Chorolop
Screeps
Screeps
master

搜索帮助