1 Star 0 Fork 0

Leviaton/Screeps

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
role.maintainer.js 2.08 KB
一键复制 编辑 原始数据 按行查看 历史
Lev 提交于 2020-02-17 12:50 . first commit
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);
}
}
};
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/Chorolop/Screeps.git
git@gitee.com:Chorolop/Screeps.git
Chorolop
Screeps
Screeps
master

搜索帮助