-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRemoteHarvester.js
48 lines (47 loc) · 1.78 KB
/
RemoteHarvester.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const logger = require('utils.log').getLogger("RemoteHarvester");
const SYS_CONFIG = require('config.system.setting');
module.exports = config => ({
// 去目标房间挖矿
source: creep => {
if (creep.moveToOtherRoom(config.transferRoom, config.targetRoomName)) {
const target = creep.pos.findClosestByRange(FIND_SOURCES_ACTIVE);
if (target) {
if (creep.harvest(target) === ERR_NOT_IN_RANGE) {
creep.moveTo(target);
}
}
}
},
//填充Spawn\Extension
target: creep => {
var target = creep.pos.findClosestByRange(FIND_STRUCTURES, {
filter: (structure) => {
return (structure.structureType === STRUCTURE_EXTENSION || structure.structureType === STRUCTURE_SPAWN) &&
structure.store.getFreeCapacity(RESOURCE_ENERGY) > 0;
}
});
if (!target) {
const towerList = creep.room.getTowerList();
if (towerList) {
for (let i = 0; i < towerList.length; i++) {
let tower = Game.getObjectById(towerList[i]);
if (tower.store[RESOURCE_ENERGY] / TOWER_CAPACITY <= SYS_CONFIG.TOWER_ENERGY_NEED) {
target = tower;
}
}
}
}
if (target) {
if (creep.transfer(target, RESOURCE_ENERGY) === ERR_NOT_IN_RANGE) {
creep.say("🔼");
creep.moveTo(target);
}
} else {
//房间能量恢复正常,停止重生
logger.warn(`${creep.name} 任务已完成!`);
creep.memory.RebornFlag = "No";
}
},
// 状态切换条件
switch: creep => creep.updateState()
})