代码拉取完成,页面将自动刷新
var B = require('behaviors');
module.exports = {
run: function(creep){
const room = creep.room.name;
if(creep.ticksToLive < 100){
if(creep.pos.isNearTo(creep.room.storage)) creep.transfer(creep.room.storage, RESOURCE_ENERGY);
else creep.moveTo(creep.room.storage);
return;
}
if(creep.memory.target == undefined) creep.memory.target = 0;
var target = Game.getObjectById(creep.memory.target);
if(creep.memory.target == 0 || target == null){
var tmptarget = creep.pos.findClosestByPath(FIND_STRUCTURES,{
filter: function(s){
return ((s.structureType != STRUCTURE_WALL &&
s.structureType != STRUCTURE_RAMPART) &&
s.hits < 0.9*s.hitsMax);
}
});
if(tmptarget != null) creep.memory.target = tmptarget.id;
else creep.memory.target = 0;
return;
}
target = Game.getObjectById(creep.memory.target);
if(target.hits == target.hitsMax){
creep.memory.target = 0;
return;
}
//正式开工
if(creep.store.getUsedCapacity() == 0){
const pos1 = new RoomPosition(Memory.rooms[room].Source1.x, Memory.rooms[room].Source1.y, room);
const pos2 = new RoomPosition(Memory.rooms[room].Source2.x, Memory.rooms[room].Source2.y, room);
const pos3 = new RoomPosition(Memory.rooms[room].Mineral.x, Memory.rooms[room].Mineral.y, room);
var target = pos1;
if(B.DetectResource(pos1,'energy') < B.DetectResource(pos2,'energy')) target = pos2;
if(Memory.rooms[room].storage) target = creep.room.storage.pos;
if(creep.pos.isNearTo(target)) B.GetResource(creep, target, 'energy');
else creep.moveTo(target, {visualizePathStyle: {stroke: '#ffffff'},reuse:200});
}else{
creep.say('move on!');
if(creep.pos.inRangeTo(target,3)) creep.repair(target);
else creep.moveTo(target);
}
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。