为什么我的守卫不攻击敌人



所以我创建了一个守卫蠕变;

Game.spawns.Spawn1.createCreep([Game.ATTACK, Game.ATTACK, Game.TOUGH, Game.TOUGH, Game.MOVE], "guard1", {role:"guard"});

然后我把这个作为我的主要:

var harvester = require('harvester');
var guard = require('guard');
for(var nam in Game.creeps) {
    var creep = Game.creeps[nam];
    if(creep.memory.role == 'guard') {
        guard(creep);
    }
    if(creep.memory.role == 'harvester') {
        harvester(creep);
    }
    if(creep.memory.role == 'builder') {
        if(creep.energy === 0) {
            creep.moveTo(Game.spawns.Spawn1);
            Game.spawns.Spawn1.transferEnergy(creep);
        }
        else {
            var targets = creep.room.find(Game.CONSTRUCTION_SITES);
            if(targets.length) {
                creep.moveTo(targets[0]);
                creep.build(targets[0]);
            }
        }
    }
}

然后是守卫脚本

module.exports = function (creep) {
    var targets = creep.room.find(Game.HOSTILE_CREEPS);
        if(targets.length) {
            creep.moveTo(targets[0]);
            creep.attack(targets[0]);
        }else{
            creep.moveTo(Game.spawns.Spawn1);
        }
}

它在教程中工作正常,但现在在实际模拟中,它不起作用。

我测试了你的脚本,它们实际上在生存模式下工作得很好。具体问题是什么?您是否检查过 CPU 时间是否用完?

最新更新