-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRole_Miner.js
37 lines (36 loc) · 1.34 KB
/
Role_Miner.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
const logger = require('utils.log').getLogger("Miner");
module.exports = ({
// 采集矿物
source: creep => {
const source = Game.getObjectById(creep.room.getMineral())
if (creep.harvest(source) === ERR_NOT_IN_RANGE) {
creep.say("⛏");
creep.moveTo(source);
}
},
// 存储矿物逻辑
target: creep => {
let target;
target = creep.room.storage;
if (target) {
if (creep.transfer(target, Game.getObjectById(creep.room.getMineral()).mineralType) === ERR_NOT_IN_RANGE) {
creep.say("🔼");
creep.moveTo(target);
}
} else {
logger.info(creep.name + "找不到可以储存矿物的建筑!");
}
},
// 状态切换条件
switch: creep => {
//creep 身上没有矿物 && creep 之前的状态为“工作”
if (creep.store[Game.getObjectById(creep.room.getMineral()).mineralType] === 0 && creep.memory.working) {
creep.memory.working = false
}
//creep 身上矿物满了 && creep 之前的状态为“不工作”
if (creep.store[Game.getObjectById(creep.room.getMineral()).mineralType] === creep.store.getCapacity() && !creep.memory.working) {
creep.memory.working = true
}
return creep.memory.working
}
})