watch 01:36
We're Getting Mutants in the MCU - The Loop
Do you like this video?
Play Sound
function (target, amount) {
if (!this.my) {
return C.ERR_NOT_OWNER;
}
if (data(this.id).spawning) {
return C.ERR_BUSY;
}
if (amount < 0) {
return C.ERR_INVALID_ARGS;
}
if (!target || !target.id || (!register.spawns[target.id] && !register.creeps[target.id] && !register.structures[target.id]) || !(target instanceof globals.Spawn) && !(target instanceof globals.Structure) && !(target instanceof globals.Creep)) {
return C.ERR_INVALID_TARGET;
}
if (register.structures[target.id] && register.structures[target.id].structureType != 'extension' && register.structures[target.id].structureType != 'spawn' && register.structures[target.id].structureType != 'link' && (register.structures[target.id].structureType != 'portal' || !/^arena/.test(data(this.id).room))) {
return C.ERR_INVALID_TARGET;
}
if (!data(this.id).energy) {
return C.ERR_NOT_ENOUGH_ENERGY;
}
if (!amount) {
if (target.energyCapacity) {
amount = Math.min(data(this.id).energy, target.energyCapacity - target.energy);
} else {
amount = data(this.id).energy;
}
}
if (this.energy < amount) {
return C.ERR_NOT_ENOUGH_ENERGY;
}
if (target.energyCapacity && (!amount || target.energy + amount > target.energyCapacity)) {
return C.ERR_FULL;
}
if (!target.pos.isNearTo(this.pos)) {
return C.ERR_NOT_IN_RANGE;
}
intents[this.id] = intents[this.id] || {};
intents[this.id].transferEnergy = {
id: target.id,
amount: amount
};
return C.OK;
}